diff mbox series

[RFC,v3,41/58] KVM: x86/pmu: Add support for PMU context switch at VM-exit/enter

Message ID 20240801045907.4010984-42-mizhang@google.com (mailing list archive)
State New, archived
Headers show
Series Mediated Passthrough vPMU 3.0 for x86 | expand

Commit Message

Mingwei Zhang Aug. 1, 2024, 4:58 a.m. UTC
From: Xiong Zhang <xiong.y.zhang@linux.intel.com>

Add correct PMU context switch at VM_entry/exit boundary.

Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
Signed-off-by: Xiong Zhang <xiong.y.zhang@linux.intel.com>
Tested-by: Yongwei Ma <yongwei.ma@intel.com>
Signed-off-by: Mingwei Zhang <mizhang@google.com>
---
 arch/x86/kvm/x86.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Chen, Zide Oct. 24, 2024, 7:57 p.m. UTC | #1
On 7/31/2024 9:58 PM, Mingwei Zhang wrote:
> From: Xiong Zhang <xiong.y.zhang@linux.intel.com>
> 
> Add correct PMU context switch at VM_entry/exit boundary.
> 
> Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
> Signed-off-by: Xiong Zhang <xiong.y.zhang@linux.intel.com>
> Tested-by: Yongwei Ma <yongwei.ma@intel.com>
> Signed-off-by: Mingwei Zhang <mizhang@google.com>
> ---
>  arch/x86/kvm/x86.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index dd6d2c334d90..70274c0da017 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -11050,6 +11050,9 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
>  		set_debugreg(0, 7);
>  	}
>  
> +	if (is_passthrough_pmu_enabled(vcpu))
> +		kvm_pmu_restore_pmu_context(vcpu);

Suggest to move is_passthrough_pmu_enabled() into the PMU restore API to
keep x86.c clean. It's up to PMU to decide in what scenarios it needs to
do context switch.

> +
>  	guest_timing_enter_irqoff();
>  
>  	for (;;) {
> @@ -11078,6 +11081,9 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
>  		++vcpu->stat.exits;
>  	}
>  
> +	if (is_passthrough_pmu_enabled(vcpu))
> +		kvm_pmu_save_pmu_context(vcpu);

ditto.

>  	/*
>  	 * Do this here before restoring debug registers on the host.  And
>  	 * since we do this before handling the vmexit, a DR access vmexit
Mi, Dapeng Oct. 25, 2024, 2:55 a.m. UTC | #2
On 10/25/2024 3:57 AM, Chen, Zide wrote:
>
> On 7/31/2024 9:58 PM, Mingwei Zhang wrote:
>> From: Xiong Zhang <xiong.y.zhang@linux.intel.com>
>>
>> Add correct PMU context switch at VM_entry/exit boundary.
>>
>> Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
>> Signed-off-by: Xiong Zhang <xiong.y.zhang@linux.intel.com>
>> Tested-by: Yongwei Ma <yongwei.ma@intel.com>
>> Signed-off-by: Mingwei Zhang <mizhang@google.com>
>> ---
>>  arch/x86/kvm/x86.c | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>> index dd6d2c334d90..70274c0da017 100644
>> --- a/arch/x86/kvm/x86.c
>> +++ b/arch/x86/kvm/x86.c
>> @@ -11050,6 +11050,9 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
>>  		set_debugreg(0, 7);
>>  	}
>>  
>> +	if (is_passthrough_pmu_enabled(vcpu))
>> +		kvm_pmu_restore_pmu_context(vcpu);
> Suggest to move is_passthrough_pmu_enabled() into the PMU restore API to
> keep x86.c clean. It's up to PMU to decide in what scenarios it needs to
> do context switch.

Agree.


>
>> +
>>  	guest_timing_enter_irqoff();
>>  
>>  	for (;;) {
>> @@ -11078,6 +11081,9 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
>>  		++vcpu->stat.exits;
>>  	}
>>  
>> +	if (is_passthrough_pmu_enabled(vcpu))
>> +		kvm_pmu_save_pmu_context(vcpu);
> ditto.
>
>>  	/*
>>  	 * Do this here before restoring debug registers on the host.  And
>>  	 * since we do this before handling the vmexit, a DR access vmexit
diff mbox series

Patch

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index dd6d2c334d90..70274c0da017 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -11050,6 +11050,9 @@  static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
 		set_debugreg(0, 7);
 	}
 
+	if (is_passthrough_pmu_enabled(vcpu))
+		kvm_pmu_restore_pmu_context(vcpu);
+
 	guest_timing_enter_irqoff();
 
 	for (;;) {
@@ -11078,6 +11081,9 @@  static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
 		++vcpu->stat.exits;
 	}
 
+	if (is_passthrough_pmu_enabled(vcpu))
+		kvm_pmu_save_pmu_context(vcpu);
+
 	/*
 	 * Do this here before restoring debug registers on the host.  And
 	 * since we do this before handling the vmexit, a DR access vmexit