From: Jia He <justin.he@arm.com>
To: Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>,
Fuad Tabba <fuad.tabba@linux.dev>
Cc: Joey Gouly <joey.gouly@arm.com>,
Steffen Eiden <seiden@linux.ibm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
Shuah Khan <shuah@kernel.org>,
Sascha Bischoff <Sascha.Bischoff@arm.com>,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
linux-kselftest@vger.kernel.org, Jia He <justin.he@arm.com>
Subject: [PATCH 0/3] KVM: arm64: Fix pre-first-run KVM_PRE_FAULT_MEMORY vcpu_load() issues
Date: Mon, 23 Nov 2026 15:09:14 +0000 [thread overview]
Message-ID: <20261123150917.2679600-1-justin.he@arm.com> (raw)
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
next reply other threads:[~2026-11-23 15:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 15:09 Jia He [this message]
2026-11-23 15:09 ` [PATCH 1/3] KVM: arm64: Don't load hardware vCPU state before first run Jia He
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 15:09 ` [PATCH 3/3] KVM: selftests: arm64: Test KVM_PRE_FAULT_MEMORY before first KVM_RUN Jia He
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261123150917.2679600-1-justin.he@arm.com \
--to=justin.he@arm.com \
--cc=Sascha.Bischoff@arm.com \
--cc=catalin.marinas@arm.com \
--cc=fuad.tabba@linux.dev \
--cc=joey.gouly@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=seiden@linux.ibm.com \
--cc=shuah@kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox