Re: [PATCH v2 10/11] KVM: SVM: implement support for vNMI
From: Sean Christopherson
Date: Tue Jan 31 2023 - 19:39:16 EST
On Wed, Feb 01, 2023, Sean Christopherson wrote:
> On Tue, Nov 29, 2022, Maxim Levitsky wrote:
> > @@ -553,6 +554,15 @@ static inline bool is_x2apic_msrpm_offset(u32 offset)
> > (msr < (APIC_BASE_MSR + 0x100));
> > }
> >
> > +static inline bool is_vnmi_enabled(struct vcpu_svm *svm)
> > +{
> > + /* L1's vNMI is inhibited while nested guest is running */
> > + if (is_guest_mode(&svm->vcpu))
>
> I would rather check the current VMCB. I don't see any value in hardcoding the
> "KVM doesn't support vNMI in L2" in multiple places. And I find the above comment
> about "L1's vNMI is inhibited" confusing. vNMI isn't inhibited/blocked, KVM just
> doesn't utilize vNMI while L2 is active (IIUC, as proposed).
Oof. Scratch that, code is correct as proposed, but the comment and function name
are confusing.
After looking at the nested support, is_vnmi_enabled() actually means "is vNMI
currently enabled _for L1_". And it has less to do with vNMI being "inhibited" and
everything to do with KVM choosing not to utilize vNMI for L1 while running L2.
"inhibited" in quotes because "inhibited" is a synonym of "blocked", i.e. I read
that as L1 NMIs are blocked.
So regardless of whether or not KVM decides to utilize vNMI for L2 if L1's NMIs
are passed through, the function name needs to clarify that it's referring to
L1. E.g. is_vnmi_enabled_for_l1() or so.
And if KVM decides not to use vNMI for L1 while running L2, state that more
explicitly instead of saying it's inhibited.
And if KVM does decide to use vNMI while running L2 if NMIs are passed through,
then the comment goes away and KVM toggles the flag in vmcb01 on nested enter
and exit.
> > + return false;
> > +
> > + return !!(svm->vmcb01.ptr->control.int_ctl & V_NMI_ENABLE);
> > +}
> > +
> > /* svm.c */
> > #define MSR_INVALID 0xffffffffU
> >
> > --
> > 2.26.3
> >