Re: [PATCH v2] KVM: arm64: Restore the VM's feature bitmap when kvm_setup_vcpu() fails

From: Lorenzo Stoakes (ARM)

Date: Mon Sep 21 2026 - 09:41:40 EST


On Mon, Sep 21, 2026 at 08:24:56AM +0100, Fuad Tabba wrote:
> Hi Oliver,
>
> On Mon, 21 Sep 2026 00:09:17 -0700, Oliver Upton <oupton@xxxxxxxxxx> wrote:
> [...]
> > > Nothing in the tree loads a vCPU whose init failed, so this is latent.
> > > The upcoming series that enables KVM_PRE_FAULT_MEMORY for arm64 exposes
> > > it: the generic kvm_vcpu_pre_fault_memory() calls vcpu_load() whether
> > > or not the vCPU has been initialised.
> >
> > That's a bug, not a feature. We should require an initialized vcpu for
> > the ioctl.
>
> That one is for Lorenzo then :) I'll reword the message so the stale
> bitmap comes first and the pre-fault crash is just how it showed up.

In general this is the behaviour of _generic_ KVM code
(kvm_vcpu_pre_fault_memory()), which itself does not require an initialised
vCPU, and no other arch seems to requires that either in the arch-specific
pre-fault code.

The actual pre-faulting implementation intentionally only targets the
canonical MMU to fault in S2 page tables, which doesn't need initialisation
to have taken place AFAICT.

However I could add:

if (!kvm_vcpu_initialized(vcpu))
return -ENOEXEC;

To kvm_arch_vcpu_pre_fault_memory(), which would make this a requirement,
though that would bring us out of line with other archs.

OTOH, I don't see why anybody would pre-fault BEFORE init, feels like
something that should be done later on in VMM bring up right?

So I doubt doing this would really break any sane user.

Let me know if you want that change in the series and I can respin it.

--
Cheers, Lorenzo