diff mbox series

[RFC,27/41] KVM: x86/pmu: Clear PERF_METRICS MSR for guest

Message ID 20240126085444.324918-28-xiong.y.zhang@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series KVM: x86/pmu: Introduce passthrough vPM | expand

Commit Message

Xiong Zhang Jan. 26, 2024, 8:54 a.m. UTC
From: Dapeng Mi <dapeng1.mi@linux.intel.com>

Since perf topdown metrics feature is not supported yet, clear
PERF_METRICS MSR for guest.

Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
---
 arch/x86/kvm/vmx/pmu_intel.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Sean Christopherson April 11, 2024, 9:50 p.m. UTC | #1
On Fri, Jan 26, 2024, Xiong Zhang wrote:
> From: Dapeng Mi <dapeng1.mi@linux.intel.com>
> 
> Since perf topdown metrics feature is not supported yet, clear
> PERF_METRICS MSR for guest.

Please rewrite with --verbose, I have no idea what MSR_PERF_METRICS, and thus no
clue why it needs to be zeroed when loading guest context, e.g. it's not passed
through, so why does it matter?

> Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
> ---
>  arch/x86/kvm/vmx/pmu_intel.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c
> index 4b4da7f17895..ad0434646a29 100644
> --- a/arch/x86/kvm/vmx/pmu_intel.c
> +++ b/arch/x86/kvm/vmx/pmu_intel.c
> @@ -916,6 +916,10 @@ static void intel_restore_pmu_context(struct kvm_vcpu *vcpu)
>  	 */
>  	for (i = pmu->nr_arch_fixed_counters; i < kvm_pmu_cap.num_counters_fixed; i++)
>  		wrmsrl(MSR_CORE_PERF_FIXED_CTR0 + i, 0);
> +
> +	/* Clear PERF_METRICS MSR since guest topdown metrics is not supported yet. */
> +	if (kvm_caps.host_perf_cap & PMU_CAP_PERF_METRICS)
> +		wrmsrl(MSR_PERF_METRICS, 0);
>  }
>  
>  struct kvm_pmu_ops intel_pmu_ops __initdata = {
> -- 
> 2.34.1
>
Mi, Dapeng April 13, 2024, 3:29 a.m. UTC | #2
On 4/12/2024 5:50 AM, Sean Christopherson wrote:
> On Fri, Jan 26, 2024, Xiong Zhang wrote:
>> From: Dapeng Mi <dapeng1.mi@linux.intel.com>
>>
>> Since perf topdown metrics feature is not supported yet, clear
>> PERF_METRICS MSR for guest.
> Please rewrite with --verbose, I have no idea what MSR_PERF_METRICS, and thus no
> clue why it needs to be zeroed when loading guest context, e.g. it's not passed
> through, so why does it matter?

Sure. MSR_PERF_METRICS actually reports the perf topdown metrics 
portion. I would add more details.


>
>> Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
>> ---
>>   arch/x86/kvm/vmx/pmu_intel.c | 4 ++++
>>   1 file changed, 4 insertions(+)
>>
>> diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c
>> index 4b4da7f17895..ad0434646a29 100644
>> --- a/arch/x86/kvm/vmx/pmu_intel.c
>> +++ b/arch/x86/kvm/vmx/pmu_intel.c
>> @@ -916,6 +916,10 @@ static void intel_restore_pmu_context(struct kvm_vcpu *vcpu)
>>   	 */
>>   	for (i = pmu->nr_arch_fixed_counters; i < kvm_pmu_cap.num_counters_fixed; i++)
>>   		wrmsrl(MSR_CORE_PERF_FIXED_CTR0 + i, 0);
>> +
>> +	/* Clear PERF_METRICS MSR since guest topdown metrics is not supported yet. */
>> +	if (kvm_caps.host_perf_cap & PMU_CAP_PERF_METRICS)
>> +		wrmsrl(MSR_PERF_METRICS, 0);
>>   }
>>   
>>   struct kvm_pmu_ops intel_pmu_ops __initdata = {
>> -- 
>> 2.34.1
>>
diff mbox series

Patch

diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c
index 4b4da7f17895..ad0434646a29 100644
--- a/arch/x86/kvm/vmx/pmu_intel.c
+++ b/arch/x86/kvm/vmx/pmu_intel.c
@@ -916,6 +916,10 @@  static void intel_restore_pmu_context(struct kvm_vcpu *vcpu)
 	 */
 	for (i = pmu->nr_arch_fixed_counters; i < kvm_pmu_cap.num_counters_fixed; i++)
 		wrmsrl(MSR_CORE_PERF_FIXED_CTR0 + i, 0);
+
+	/* Clear PERF_METRICS MSR since guest topdown metrics is not supported yet. */
+	if (kvm_caps.host_perf_cap & PMU_CAP_PERF_METRICS)
+		wrmsrl(MSR_PERF_METRICS, 0);
 }
 
 struct kvm_pmu_ops intel_pmu_ops __initdata = {