Re: [PATCH v4 1/3] KVM: SVM: Only call vcpu_(un)blocking when AVIC is enabled.

From: Suthikulpanit, Suravee
Date: Wed Feb 02 2022 - 01:52:56 EST




On 2/2/2022 11:11 AM, Suravee Suthikulpanit wrote:
The kvm_x86_ops.vcpu_(un)blocking are needed by AVIC only.
Therefore, set the ops only when AVIC is enabled.

Also, refactor AVIC hardware setup logic into helper function
To prepare for upcoming AVIC changes.

Suggested-by: Sean Christopherson <seanjc@xxxxxxxxxx>
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@xxxxxxx>
---
arch/x86/kvm/svm/avic.c | 17 +++++++++++++++--
arch/x86/kvm/svm/svm.c | 10 ++--------
arch/x86/kvm/svm/svm.h | 3 +--
3 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c
index 90364d02f22a..f5c6cab42d74 100644
--- a/arch/x86/kvm/svm/avic.c
+++ b/arch/x86/kvm/svm/avic.c
@@ -1027,7 +1027,7 @@ void avic_vcpu_put(struct kvm_vcpu *vcpu)
WRITE_ONCE(*(svm->avic_physical_id_cache), entry);
}
-void avic_vcpu_blocking(struct kvm_vcpu *vcpu)
+static void avic_vcpu_blocking(struct kvm_vcpu *vcpu)
{
if (!kvm_vcpu_apicv_active(vcpu))
return;
@@ -1052,7 +1052,7 @@ void avic_vcpu_blocking(struct kvm_vcpu *vcpu)
preempt_enable();
}
-void avic_vcpu_unblocking(struct kvm_vcpu *vcpu)
+static void avic_vcpu_unblocking(struct kvm_vcpu *vcpu)
{
int cpu;
@@ -1066,3 +1066,16 @@ void avic_vcpu_unblocking(struct kvm_vcpu *vcpu)
put_cpu();
}
+
+bool avic_hardware_setup(struct kvm_x86_ops *x86_ops)
+{
+ if (!npt_enabled || !boot_cpu_has(X86_FEATURE_AVIC))
+ return false;
+
+ x86_ops->vcpu_blocking = avic_vcpu_blocking,
+ x86_ops->vcpu_unblocking = avic_vcpu_unblocking,

Sorry for confusion, I made a mistake during patch re basing. I'll send out V5.

Suravee