Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [PATCH v2 0/2] KVM: arm64: Don't load hardware vCPU state before first run
@ 2026-12-04  9:09 Jia He
  2026-12-04  9:09 ` [PATCH v2 1/2] " Jia He
  2026-12-04  9:09 ` [PATCH v2 2/2] KVM: selftests: arm64: Test KVM_PRE_FAULT_MEMORY before first KVM_RUN Jia He
  0 siblings, 2 replies; 5+ messages in thread
From: Jia He @ 2026-12-04  9:09 UTC (permalink / raw)
  To: Marc Zyngier, Oliver Upton, Fuad Tabba
  Cc: Jia He, Joey Gouly, Steffen Eiden, Suzuki K Poulose, Zenghui Yu,
	Catalin Marinas, Will Deacon, Mark Rutland, Paolo Bonzini,
	Sean Christopherson, Shuah Khan, Sascha Bischoff, Lorenzo Stoakes,
	Dan Carpenter, Yao Yuan, linux-arm-kernel, kvmarm, linux-kernel,
	kvm, linux-kselftest

KVM_PRE_FAULT_MEMORY and KVM_SET_VCPU_EVENTS call vcpu_load() before
the first KVM_RUN, while arm64 only finalises VM and vCPU state on the
first KVM_RUN. On NV, this lets userspace queue KVM_REQ_MAP_L1_VNCR_EL2
without a vncr_tlb and dereference NULL in kvm_map_l1_vncr() on the
first KVM_RUN. With 5651590be08a ("KVM: arm64: Load the vcpu in
KVM_SET_VCPU_EVENTS"), an all-zero KVM_SET_VCPU_EVENTS before the first
KVM_RUN is enough, even with pre-faulting disabled.

Patch 1 skips the arch vcpu_load()/vcpu_put() callbacks until the vCPU
has run once, and switches VHE enter_vmid_context() to
__hyp_running_vcpu. Patch 2 extends nv_pre_fault_memory_test.

KVM_SET_VCPU_EVENTS before the first run still evaluates injection
against unfinalised state; that is left for a separate change.

Tested on a Neoverse-N2 host (with lockdep enabled):
- With pre-faulting disabled, an all-zero KVM_SET_VCPU_EVENTS before
  the first KVM_RUN reproduces the NULL vncr_tlb dereference.
- With this series applied, neither KVM_PRE_FAULT_MEMORY nor
  KVM_SET_VCPU_EVENTS triggers the oops (10 runs each), and
  nv_pre_fault_memory_test passes.

Based on kvmarm/fixes (kvmarm-fixes-7.4-3).

Changes since v1:
- Rebased on kvmarm/fixes.
- Patch 1: cover KVM_SET_VCPU_EVENTS as well.
- Patch 1: keep the VHE enter_vmid_context() change and explain the
  MMU notifier/reclaim case (Marc, Lorenzo).
- Patch 1: drop the vgic_maintenance_handler() change (Marc, Lorenzo).
- Patch 1: tighten commit message and move test notes to cover letter.
- Drop v1 patch 2 (Marc).
- Patch 2: list the test cases in the commit message, fix two comments
  and a message (Yao Yuan).

v1: https://lore.kernel.org/r/20261123150917.2679600-1-justin.he@arm.com

Jia He (2):
  KVM: arm64: Don't load hardware vCPU state before first run
  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 +-
 .../kvm/arm64/nv_pre_fault_memory_test.c      | 338 ++++++++++++++++--
 3 files changed, 318 insertions(+), 40 deletions(-)

-- 
2.34.1


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

end of thread, other threads:[~2026-12-04  9:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  9:09 [PATCH v2 0/2] KVM: arm64: Don't load hardware vCPU state before first run Jia He
2026-12-04  9:09 ` [PATCH v2 1/2] " Jia He
2026-12-04  9:38   ` sashiko-bot
2026-12-04  9:09 ` [PATCH v2 2/2] KVM: selftests: arm64: Test KVM_PRE_FAULT_MEMORY before first KVM_RUN Jia He
2026-12-04  9:25   ` sashiko-bot

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