On Sun, 2022-02-20 at 20:19 -0600, Suravee Suthikulpanit wrote: > The kvm_x86_ops.vcpu_(un)blocking are needed by AVIC only. > Therefore, set the ops only when AVIC is enabled. > > Suggested-by: Sean Christopherson <seanjc@xxxxxxxxxx> > Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@xxxxxxx> > --- > arch/x86/kvm/svm/avic.c | 12 ++++++++++-- > arch/x86/kvm/svm/svm.c | 7 ------- > arch/x86/kvm/svm/svm.h | 2 -- > 3 files changed, 10 insertions(+), 11 deletions(-) > > diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c > index abde08ca23ab..0040824e4376 100644 > --- a/arch/x86/kvm/svm/avic.c > +++ b/arch/x86/kvm/svm/avic.c > @@ -996,7 +996,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; > @@ -1021,7 +1021,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; > > @@ -1057,6 +1057,14 @@ bool avic_hardware_setup(struct kvm_x86_ops *x86_ops) > pr_info("x2AVIC enabled\n"); > } > > + if (avic_mode) { > + x86_ops->vcpu_blocking = avic_vcpu_blocking; > + x86_ops->vcpu_unblocking = avic_vcpu_unblocking; > + } else { > + x86_ops->vcpu_blocking = NULL; > + x86_ops->vcpu_unblocking = NULL; > + } > + > amd_iommu_register_ga_log_notifier(&avic_ga_log_notifier); > return !!avic_mode; > } > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index 3048f4b758d6..3687026f2859 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c > @@ -4531,8 +4531,6 @@ static struct kvm_x86_ops svm_x86_ops __initdata = { > .prepare_guest_switch = svm_prepare_guest_switch, > .vcpu_load = svm_vcpu_load, > .vcpu_put = svm_vcpu_put, > - .vcpu_blocking = avic_vcpu_blocking, > - .vcpu_unblocking = avic_vcpu_unblocking, > > .update_exception_bitmap = svm_update_exception_bitmap, > .get_msr_feature = svm_get_msr_feature, > @@ -4819,11 +4817,6 @@ static __init int svm_hardware_setup(void) > > enable_apicv = avic = avic && avic_hardware_setup(&svm_x86_ops); > > - if (!enable_apicv) { > - svm_x86_ops.vcpu_blocking = NULL; > - svm_x86_ops.vcpu_unblocking = NULL; > - } Isn't this code already zeros these callbacks when avic is not enabled? I am not sure why this patch is needed to be honest. Best regards, Maxim Levitsky > - > if (vls) { > if (!npt_enabled || > !boot_cpu_has(X86_FEATURE_V_VMSAVE_VMLOAD) || > diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h > index b53c83a44ec2..1a0bf6b853df 100644 > --- a/arch/x86/kvm/svm/svm.h > +++ b/arch/x86/kvm/svm/svm.h > @@ -578,8 +578,6 @@ void svm_hwapic_isr_update(struct kvm_vcpu *vcpu, int max_isr); > bool svm_dy_apicv_has_pending_interrupt(struct kvm_vcpu *vcpu); > int svm_update_pi_irte(struct kvm *kvm, unsigned int host_irq, > uint32_t guest_irq, bool set); > -void avic_vcpu_blocking(struct kvm_vcpu *vcpu); > -void avic_vcpu_unblocking(struct kvm_vcpu *vcpu); > void avic_ring_doorbell(struct kvm_vcpu *vcpu); > > /* sev.c */