Re: [PATCH 06/16] KVM: x86: Widen the plane vCPU fd ioctl allowlist

From: David Woodhouse

Date: Fri Nov 20 2026 - 10:57:07 EST


On Wed, 2026-11-18 at 19:10 +0000, David Woodhouse wrote:
> I've also been looking harder at the completion thing. We *can't*
> (well, I don't want to) enter another plane while there's still a
> completion waiting on the first plane.
>
> Which means any control register or MSR interception which needs to
> be handed to another plane has to completed first.

Aside other things which have been catching fire, I've been playing
with that a little.

I really don't want to mess with user completions remaining pending for
one (or more!) plane while another plane runs.

So in the case where we take an interception in VTL0 and then let VTL1
decide what to do, we need the completion to be done *before* running
VTL1. Which is why my idea of a cancel flag in KVM_SET_VCPU_EVENTS
doesn't actually work once I build it into the full VSM stack. It works
out OK if the VMM is making the decision, but not if we have to run
VTL1.

So Sean was right¹ and we end up with a per-exit field much as he was
asking for.

For the various exits with completions that are affected (RDMSR, WRMSR
plus the new register write filter and forwarded Hyper-V hypercalls) we
therefore want these options as the 'ret' action:

• KVM_INSN_COMPLETE: finish it, as now
• KVM_INSN_GP: inject #GP
• KVM_INSN_UD: inject #UD
• KVM_INSN_RESUME: do nothing; RIP and everything else stay as
userspace left them

So the relatively common cases #GP and #UD are trivial to inject, and
any other exception can be injected by using KVM_SET_VCPU_EVENTS and
then setting KVM_INSN_RESUME to let the exception take its course. The
new VMware hypercall handling could do the same.

Entering KVM_RUN for a new plane would still process the completion for
the previously-running plane.

I'd quite like the UAPI to be consistent, and since the MSR exits
already use a u8 field for 'error', we can retcon this enum into that
field when enabled by the appropriate CAP. (Without the CAP enabled,
all non-zero values cause #GP as they do today.)

None of that depends on planes, so I'm building it in independent
branches which I can post separately.

What planes does add is two bytes in the kvm_run header, on any VM
which enabled KVM_CAP_PLANES:

• the plane which took the exit, on every exit
• the instruction length, for MSR and register write exits

The first means I can drop the 'plane' field I was adding to each new
exit, and makes the existing ones (MSR, PIO, MMIO) usable from any
plane.

The length is always valid for those two. On SVM without NextRIP the
access goes through the emulator, which was going to have to decode it
to skip it anyway. Not sure about SEV; not sure if these exits should
even be enabled there? I also toyed with exposing the insn_length as a
CAP which could then be absent in those cases (and on the ancient AMD
CPUs without NextRIP).

I haven't changed the PIO or MMIO completions. At least in VSM those
are never handed to another plane; what a higher VTL intercepts there
is a memory access, which is a fault before the instruction has done
anything. We could expand those later, if there's a need to.

So for VSM, the VMM answers RESUME and runs VTL1. VTL1 either injects
the fault into VTL0, or does the write and advances VTL0's RIP itself,
which is why it wanted the length.

That boots Windows with VBS on both Intel and AMD, with the VTL switch
in the kernel or in userspace.

The whole stack is in my tree². The planes part is in
vsm3v/planes-uapi; the parts which don't need planes are the
vsm3/exit-insn-v2, vsm3/msr-exit-ret-v4, vsm3/hcall-exit-v7 and
vsm3/regwr-filter-v10 branches there.

¹ https://lore.kernel.org/kvm/avuDUNAU_a933zvp@xxxxxxxxxxxxxxx.internal/
² https://git.infradead.org/?p=users/dwmw2/linux.git;a=shortlog;h=refs/heads/vsm3v/p4-startup

Attachment: smime.p7s
Description: S/MIME cryptographic signature