Re: [PATCH 1/3] KVM: arm64: Don't load hardware vCPU state before first run

From: Marc Zyngier

Date: Tue Nov 24 2026 - 08:29:15 EST


On Tue, 24 Nov 2026 09:06:32 +0000,
Justin He <Justin.He@xxxxxxx> wrote:
>
>
>
> > -----Original Message-----
> [...]
> > On Mon, 23 Nov 2026 15:09:15 +0000,
> > Jia He <justin.he@xxxxxxx> wrote:
> > >
> > > KVM_PRE_FAULT_MEMORY calls vcpu_load() as soon as
> > KVM_ARM_VCPU_INIT has
> > > completed. On arm64, however, kvm->arch.sysreg_masks, the trap
> > > configuration, vncr_tlb and nested vGIC state are only set up on the
> > > first KVM_RUN in kvm_arch_vcpu_run_pid_change().
> >
> > I think I'm going to queue a patch disabling prefaulting immediately,
> > and then we can fix this crap.
>
> I can still reproduce the same vncr_tlb NULL dereference with prefaulting
> disabled. On kvmarm/fixes, commit 5651590be08a ("KVM: arm64: Load the vcpu
> in KVM_SET_VCPU_EVENTS") added a vcpu_load() call to KVM_SET_VCPU_EVENTS.
> A single KVM_SET_VCPU_EVENTS with an all-zero struct kvm_vcpu_events,
> issued before the first KVM_RUN, is enough to trigger it.
> For v2, I'll build on your patch and use vcpu_has_run_once() to gate the
> arch load/put paths for both ioctls.

Ah, you spotted that one already. I should have checked the full
thread before replying...

M.

--
Without deviation from the norm, progress is not possible.