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: Jia He <justin.he@arm.com>, 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>,
Lorenzo Stoakes <ljs@kernel.org>, Dan Carpenter <dan@pereq.eu>,
Yao Yuan <yaoyuan@linux.alibaba.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
Subject: [PATCH v2 0/2] KVM: arm64: Don't load hardware vCPU state before first run
Date: Fri, 4 Dec 2026 09:09:12 +0000 [thread overview]
Message-ID: <20261204090914.459990-1-justin.he@arm.com> (raw)
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
next reply other threads:[~2026-12-04 9:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 9:09 Jia He [this message]
2026-12-04 9:09 ` [PATCH v2 1/2] KVM: arm64: Don't load hardware vCPU state before first run 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
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=20261204090914.459990-1-justin.he@arm.com \
--to=justin.he@arm.com \
--cc=Sascha.Bischoff@arm.com \
--cc=catalin.marinas@arm.com \
--cc=dan@pereq.eu \
--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=ljs@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=yaoyuan@linux.alibaba.com \
--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