2024-01-26 09:46:54

by Zhang, Xiong Y

[permalink] [raw]
Subject: [RFC PATCH 32/41] KVM: x86/pmu: Add support for PMU context switch at VM-exit/enter

From: Xiong Zhang <[email protected]>

Add correct PMU context switch at VM_entry/exit boundary.

Signed-off-by: Xiong Zhang <[email protected]>
Signed-off-by: Mingwei Zhang <[email protected]>
---
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 074452aa700d..fe7da1a16c3b 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -10898,6 +10898,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 (;;) {
@@ -10926,6 +10929,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
--
2.34.1