Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] KVM: arm64: Fix pre-first-run KVM_PRE_FAULT_MEMORY vcpu_load() issues
@ 2026-11-23 15:09 Jia He
  2026-11-23 15:09 ` [PATCH 1/3] KVM: arm64: Don't load hardware vCPU state before first run Jia He
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Jia He @ 2026-11-23 15:09 UTC (permalink / raw)
  To: Marc Zyngier, Oliver Upton, Fuad Tabba
  Cc: Joey Gouly, Steffen Eiden, Suzuki K Poulose, Zenghui Yu,
	Catalin Marinas, Will Deacon, Mark Rutland, Paolo Bonzini,
	Sean Christopherson, Shuah Khan, Sascha Bischoff,
	linux-arm-kernel, kvmarm, linux-kernel, kvm, linux-kselftest,
	Jia He

KVM_PRE_FAULT_MEMORY calls vcpu_load() as soon as KVM_ARM_VCPU_INIT has
completed. On arm64, VM and vCPU state such as kvm->arch.sysreg_masks,
trap controls, vncr_tlb and nested vGIC setup is only initialised on the
first KVM_RUN in kvm_arch_vcpu_run_pid_change().

Running the full arch vcpu_load() path before then reads unsanitised
guest sysregs and touches uninitialised nested state. In particular, if
a VMM creates an EL2 vCPU with ID_AA64MMFR4_EL1.NV_frac cleared to 0,
sets HCR_EL2.NV=1 and an EL1 PSTATE, and calls KVM_PRE_FAULT_MEMORY,
kvm_vcpu_load_hw_mmu() queues KVM_REQ_MAP_L1_VNCR_EL2 without a
vncr_tlb. The next KVM_RUN then dereferences NULL in kvm_map_l1_vncr()
with preemption disabled and kvm->mmu_lock held for read.

Patch 1 skips the arch vcpu_load()/vcpu_put() callbacks until
vcpu_has_run_once() is true, and adjusts VHE enter_vmid_context() and
vgic_maintenance_handler() accordingly. Generic vcpu_load() still sets
kvm_running_vcpu for dirty-ring tracking, and pre-faulting only populates
&kvm->arch.mmu.

Patch 2 checks that vncr_tlb is allocated before setting
KVM_REQ_MAP_L1_VNCR_EL2 and adds a WARN_ON_ONCE(!vt) check in
kvm_map_l1_vncr().

Patch 3 extends nv_pre_fault_memory_test to cover pre-first-run
pre-faulting. The cases that do not need EL2 run on all hosts. On an
unfixed kernel, the staged nested context case triggers the "Separate
virtual IRQ/FIQ settings not supported" WARN while the test still
passes, so the kernel log must be checked as well.

Jia He (3):
  KVM: arm64: Don't load hardware vCPU state before first run
  KVM: arm64: nv: Don't request or attempt L1 VNCR mapping without
    vncr_tlb
  KVM: selftests: arm64: Test KVM_PRE_FAULT_MEMORY before first KVM_RUN

 arch/arm64/kvm/arm.c                          |  17 +-
 arch/arm64/kvm/hyp/vhe/tlb.c                  |   3 +-
 arch/arm64/kvm/nested.c                       |   6 +-
 arch/arm64/kvm/vgic/vgic-init.c               |   2 +-
 .../kvm/arm64/nv_pre_fault_memory_test.c      | 335 ++++++++++++++++--
 5 files changed, 321 insertions(+), 42 deletions(-)


base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
-- 
2.34.1



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-23 17:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 15:09 [PATCH 0/3] KVM: arm64: Fix pre-first-run KVM_PRE_FAULT_MEMORY vcpu_load() issues Jia He
2026-11-23 15:09 ` [PATCH 1/3] KVM: arm64: Don't load hardware vCPU state before first run Jia He
2026-11-23 17:20   ` Marc Zyngier
2026-11-23 17:50     ` Lorenzo Stoakes (ARM)
2026-11-23 15:09 ` [PATCH 2/3] KVM: arm64: nv: Don't request or attempt L1 VNCR mapping without vncr_tlb Jia He
2026-11-23 17:36   ` Marc Zyngier
2026-11-23 15:09 ` [PATCH 3/3] KVM: selftests: arm64: Test KVM_PRE_FAULT_MEMORY before first KVM_RUN Jia He

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox