Re: [PATCH 2/6] x86/entry_64: Add VERW just before userspace transition

From: Pawan Gupta
Date: Mon Oct 23 2023 - 18:31:16 EST


On Mon, Oct 23, 2023 at 02:47:52PM -0700, Josh Poimboeuf wrote:
> > > > /*
> > > > * RSP now points to an ordinary IRET frame, except that the page
> > > > * is read-only and RSP[31:16] are preloaded with the userspace
> > > > @@ -1502,6 +1511,9 @@ nmi_restore:
> > > > std
> > > > movq $0, 5*8(%rsp) /* clear "NMI executing" */
> > > >
> > > > + /* Mitigate CPU data sampling attacks .e.g. MDS */
> > > > + USER_CLEAR_CPU_BUFFERS
> > > > +
> > > > /*
> > > > * iretq reads the "iret" frame and exits the NMI stack in a
> > > > * single instruction. We are returning to kernel mode, so this
> > >
> > > This isn't needed here. This is the NMI return-to-kernel path.
> >
> > Yes, the VERW here can be omitted. But probably need to check if an NMI
> > occuring between VERW and ring transition will still execute VERW after
> > the NMI.
>
> That window does exist, though I'm not sure it's worth worrying about.

I am in favor of omitting the VERW here, unless someone objects with a
rationale. IMO, precisely timing the NMIs in such a narrow window is
impractical.