Re: [PATCH v2 3/4] Add support for AMD Core Perf Extension in guest

From: Natarajan, Janakarajan
Date: Wed Dec 06 2017 - 15:19:32 EST


On 12/5/2017 11:56 AM, Radim Krcmar wrote:
2017-12-01 13:30-0600, Natarajan, Janakarajan:
On 11/17/2017 5:44 AM, Borislav Petkov wrote:
On Thu, Nov 16, 2017 at 12:00:11PM -0600, Natarajan, Janakarajan wrote:
Ah my apologies. So when the pmu is initialized the cpuid entries
aren't available then.
So let's see:

... kvm_arch_vcpu_create() ->
svm_create_vcpu() ->
kvm_vcpu_init() ->
kvm_arch_vcpu_init() ->

<--- HERE

kvm_pmu_init()

But at HERE in kvm_arch_vcpu_init() right before kvm_pmu_init() we do already query
cpuid:

vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu);

so it's not like we don't know about cpuid leafs at that point. Which
would mean that the code can be made to set the CPU family earlier,
before kvm_pmu_init() runs so that you have the proper CPU family and
thus have this thing properly designed.

Maybe Paolo and Radim have a better suggestion here...
Paolo, Radim any suggestions about this. I feel that the number of counters
initialized can be 6
This is the best solution with the current framework.

Okay.


and the subsequent code (kvm_pmu_refresh()) takes care of the number of
counters to be used (4 or 6)
based on the vcpu family.
Can't we look only at X86_FEATURE_PERFCTR_CORE and completely ignore the
AMD family?
Using the family would bring problems with compatiblity.

Yeah. We can just use the X86_FEATURE_PERFCTR_CORE flag as a check. I'll send a v3
with the changes.

Thanks.


Thanks.