KVM: arm64: Fix pre-first-run KVM_PRE_FAULT_MEMORY vcpu_load() issues
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest3 patches 8 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | KVM: arm64: Don't load hardware vCPU state before first runarch/ arch/ arch/ | +18 | 4 replies | |
| 2/3 | KVM: arm64: nv: Don't request or attempt L1 VNCR mapping without vncr_tlbarch/ | +5 | 2 replies | |
| 3/3 | KVM: selftests: arm64: Test KVM_PRE_FAULT_MEMORY before first KVM_RUNtools/ | +298 | 2 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/3] KVM: arm64: Fix pre-first-run KVM_PRE_FAULT_MEMORY vcpu_load() issues
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
Signature · 1 line
2.34.1