From: Justin He <Justin.He@arm.com>
To: Marc Zyngier <maz@kernel.org>
Cc: Oliver Upton <oupton@kernel.org>,
Fuad Tabba <fuad.tabba@linux.dev>,
Joey Gouly <Joey.Gouly@arm.com>,
Steffen Eiden <seiden@linux.ibm.com>,
Suzuki 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"
<linux-arm-kernel@lists.infradead.org>,
"kvmarm@lists.linux.dev" <kvmarm@lists.linux.dev>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-kselftest@vger.kernel.org"
<linux-kselftest@vger.kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>, Dan Carpenter <dan@pereq.eu>
Subject: RE: [PATCH 1/3] KVM: arm64: Don't load hardware vCPU state before first run
Date: Tue, 24 Nov 2026 13:18:31 +0000 [thread overview]
Message-ID: <AS2PR08MB9786B94054D2237817356701F7442@AS2PR08MB9786.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <868q2iz94w.wl-maz@kernel.org>
> -----Original Message-----
[...]
> > > > KVM_PRE_FAULT_MEMORY calls vcpu_load() as soon as
> > > KVM_ARM_VCPU_INIT has
> > > > completed. On arm64, however, kvm->arch.sysreg_masks, the trap
> > > > configuration, vncr_tlb and nested vGIC state are only set up on the
> > > > first KVM_RUN in kvm_arch_vcpu_run_pid_change().
> > >
> > > I think I'm going to queue a patch disabling prefaulting immediately,
> > > and then we can fix this crap.
> > >
> > Fine with me. I'll rebase on top of it and have v2 re-enable
> > pre-faulting together with the load/put change.
>
> Don't worry about that. I can fix that myself when applying the
> patches.
>
Thanks. I'll leave the pre-fault enable alone in v2.
>
> > > > Since kvm_running_vcpu can now be set without VHE state on the CPU,
> use
> > > > host_ctxt->__hyp_running_vcpu in VHE enter_vmid_context() (matching
> > > > nVHE)
> > >
> > > Can you clarify under which circumstances we end-up on the TLB
> > > invalidation path? Simply faulting things in should not result in
> > > invalidation. Unless we end-up with MMU notifiers firing?
> > >
> > I found this by code inspection, not from a failure. A TLBI from a stage-2
> > BBM or an MMU notifier can hit this path during pre-faulting, but before
> > the first run hw_mmu is canonical, so it makes no difference. As Lorenzo
> > said, I'll drop this hunk.
>
> vcpu->arch.hw_mmu being the canonical one before the first run doesn't
> hold anymore, since a7602ea542d4e ("KVM: arm64: nv: Initialize hw_mmu
> to NULL for nested vCPUs"), as userspace can configure things for an
> L2, before first run, and bad things happen otherwise.
>
> But the observation remains: if an MMU notifier occurs for any reason
> while pre-faulting (likely a concurrent reclaim), we get the "not
> quite loaded" vcpu in enter_vmid_context(). If vcpu->arch.hw_mmu is a
> valid (non-null) pointer, then we will restore whatever is in that
> structure when reaching exit_vmid_context(), and that's not what is
> intended.
>
> So I think we need that sort of exclusion. Either we track what is
> actually properly loaded (using __hyp_running_vcpu as you did before,
> or by checking whether the vcpu is in a valid state).
>
I'll keep the __hyp_running_vcpu change then. It follows what is
actually loaded on the CPU, and it matches nVHE.
> I think we have a somewhat similar breakage with 5651590be08a6 ("KVM:
> arm64: Load the vcpu in KVM_SET_VCPU_EVENTS"): as vcpu_load() now
> becomes sensitive to vcpu_has_run_once() being true, we can't tell
> anything of the state that is going to be evaluated by the event
> injection helper.
>
Agreed. It already crashes: with pre-faulting disabled, an all-zero
KVM_SET_VCPU_EVENTS before the first KVM_RUN triggers the same NULL vncr_tlb dereference here.
Instead of rejecting it, we could defer the injection to the first
KVM_RUN, once the state is finalised. I can try that as a separate
patch, if that sounds reasonable to you.
___
Best Regards,
Jia He (Justin)
> We could prevent the non-running injection in KVM_SET_VCPU_EVENTS, but
> that's also a change in the API...
>
> M.
>
> --
> Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2026-11-24 13:19 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
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-24 1:39 ` Justin He
2026-11-24 12:50 ` Marc Zyngier
2026-11-24 13:18 ` Justin He [this message]
2026-11-24 9:06 ` Justin He
2026-11-24 13:28 ` Marc Zyngier
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-24 1:42 ` Justin He
2026-11-23 15:09 ` [PATCH 3/3] KVM: selftests: arm64: Test KVM_PRE_FAULT_MEMORY before first KVM_RUN Jia He
2026-11-24 7:11 ` Yao Yuan
2026-11-24 8:12 ` Justin 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=AS2PR08MB9786B94054D2237817356701F7442@AS2PR08MB9786.eurprd08.prod.outlook.com \
--to=justin.he@arm.com \
--cc=Catalin.Marinas@arm.com \
--cc=Joey.Gouly@arm.com \
--cc=Mark.Rutland@arm.com \
--cc=Sascha.Bischoff@arm.com \
--cc=Suzuki.Poulose@arm.com \
--cc=dan@pereq.eu \
--cc=fuad.tabba@linux.dev \
--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=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=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
all inboxes | Powered by JetHome®