Re: [PATCH v3 7/7] KVM: x86: SVM: allow AVIC to co-exist with a nested guest running

From: Maxim Levitsky
Date: Wed Mar 09 2022 - 13:14:24 EST


On Wed, 2022-03-09 at 14:50 +0100, Paolo Bonzini wrote:
> On 3/1/22 15:36, Maxim Levitsky wrote:
> > bool activate;
> > @@ -9690,7 +9695,9 @@ void kvm_vcpu_update_apicv(struct kvm_vcpu *vcpu)
> >
> > down_read(&vcpu->kvm->arch.apicv_update_lock);
> >
> > - activate = kvm_apicv_activated(vcpu->kvm);
> > + activate = kvm_apicv_activated(vcpu->kvm) &&
> > + !vcpu_has_apicv_inhibit_condition(vcpu);
> > +
> > if (vcpu->arch.apicv_active == activate)
> > goto out;
> >
>
> Perhaps the callback could be named vcpu_apicv_inhibit_reasons, and it would
> return APICV_INHIBIT_REASON_NESTED? Then instead of the new function
> vcpu_has_apicv_inhibit_condition(), you would have
>
> bool kvm_vcpu_apicv_activated(struct vcpu_kvm *kvm)
> {
> ulong vm_reasons = READ_ONCE(vcpu->kvm->arch.apicv_inhibit_reasons);
> ulong vcpu_reasons = static_call(kvm_x86_vcpu_apicv_inhibit_reasons)(vcpu);
> return (vm_reasons | vcpu_reasons) == 0;
> }
> EXPORT_SYMBOL_GPL(kvm_cpu_apicv_activated);
>
> It's mostly aesthetics, but it would also be a bit more self explanatory I think.
>
> Paolo
>

This is a great idea, I will do it in next version.
Thanks!

Best regards,
Maxim Levitsky