RE: [RFC PATCH V6 02/14] x86/sev: Add Check of #HV event in path

From: Michael Kelley (LINUX)
Date: Wed May 31 2023 - 11:59:04 EST


From: Peter Zijlstra <peterz@xxxxxxxxxxxxx> Sent: Wednesday, May 31, 2023 8:49 AM
>
> On Wed, May 31, 2023 at 02:50:50PM +0000, Michael Kelley (LINUX) wrote:
>
> > I'm jumping in to answer some of the basic questions here. Yesterday,
> > there was a discussion about nested #HV exceptions, so maybe some of
> > this is already understood, but let me recap at a higher level, provide some
> > references, and suggest the path forward.
>
> > 2) For the Restricted Interrupt Injection code, Tianyu will look at
> > how to absolutely minimize the impact in the hot code paths,
> > particularly when SEV-SNP is not active. Hopefully the impact can
> > be a couple of instructions at most, or even less with the use of
> > other existing kernel techniques. He'll look at the other things you've
> > commented on and get the code into a better state. I'll work with
> > him on writing commit messages and comments that explain what's
> > going on.
>
> So from what I understand of all this SEV-SNP/#HV muck is that it is
> near impossible to get right without ucode/hw changes. Hence my request
> to Tom to look into that.
>
> The feature as specified in the AMD documentation seems fundamentally
> buggered.
>
> Specifically #HV needs to be IST because hypervisor can inject at any
> moment, irrespective of IF or anything else -- even #HV itself. This
> means also in the syscall gap.
>
> Since it is IST, a nested #HV is instant stack corruption -- #HV can
> attempt to play stack games as per the copied #VC crap (which I'm not at
> all convinced about being correct itself), but this doesn't actually fix
> anything, all you need is a single instruction window to wreck things.
>
> Because as stated, the whole premise is that the hypervisor is out to
> get you, you must not leave it room to wiggle. As is, this is security
> through prayer, and we don't do that.
>
> In short; I really want a solid proof that what you propose to implement
> is correct and not wishful thinking.

Fair enough. We will be sync'ing with the AMD folks to make sure that
one way or another this really will work.

Michael