Re: [PATCH v3 13/22] kvm: x86: Intercept #NM for saving IA32_XFD_ERR

From: Sean Christopherson
Date: Wed Dec 29 2021 - 12:37:28 EST


On Wed, Dec 29, 2021, Tian, Kevin wrote:
> > From: Sean Christopherson <seanjc@xxxxxxxxxx>
> > Sent: Wednesday, December 29, 2021 8:10 AM
> >
> > On Wed, Dec 22, 2021, Jing Liu wrote:
> > > Guest IA32_XFD_ERR is generally modified in two places:
> > >
> > > - Set by CPU when #NM is triggered;
> > > - Cleared by guest in its #NM handler;
> > >
> > > Intercept #NM for the first case, if guest writes XFD as nonzero for
> > > the first time which indicates guest is possible to use XFD generating
> > > the exception. #NM is rare if the guest doesn't use dynamic features.
> > > Otherwise, there is at most one exception per guest task given a
> > > dynamic feature.
> > >
> > > Save the current XFD_ERR value to the guest_fpu container in the #NM
> > > VM-exit handler. This must be done with interrupt/preemption disabled,
> >
> > Assuming my below understanding is correct, drop the "preemption" bit, it's
> > misleading.
>
> code-wise yes. In concept we just want to highlight that this operation
> must be completed when both interrupt and preemption are disabled.

No no no no no. Yes, disabling IRQs also disables preemption, but that's not at
all relevant, e.g. KVM could handle preemption via kvm_sched_{in,out}(). Handling
this with IRQs disable is 100% mandatory because MSR_IA32_XFD_ERR can be indirectly
consumed in (soft) IRQ context, end of story.

> But we can also drop preemption if you prefer to, since preemption is
> certainly disabled when interrupt is disabled.