From: sashiko-bot@kernel.org
To: "Jia He" <justin.he@arm.com>
Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org,
"Oliver Upton" <oupton@kernel.org>,
"Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH v2 1/2] KVM: arm64: Don't load hardware vCPU state before first run
Date: Fri, 04 Dec 2026 09:38:45 +0000 [thread overview]
Message-ID: <sashiko-outbox-249528@kernel.org> (raw)
In-Reply-To: <20261204090914.459990-2-justin.he@arm.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] KVM: arm64: kvm_inject_nested() leaks VHE PMU state before
first KVM_RUN
--
commit f447e42779fe8bcecaa4f6aa6298f73ee8e89cf9
Author: Jia He <justin.he@arm.com>
KVM: arm64: Don't load hardware vCPU state before first run
This commit skips the arch vcpu_load() and vcpu_put() callbacks until
vcpu_has_run_once() is true, and updates VHE's enter_vmid_context() to
check host_ctxt->__hyp_running_vcpu instead of kvm_get_running_vcpu().
> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> index 157bf4b812020..720367868f6c8 100644
> --- a/arch/arm64/kvm/arm.c
> +++ b/arch/arm64/kvm/arm.c
[ ... ]
> @@ -862,8 +872,11 @@ static void pkvm_vcpu_put(struct kvm_vcpu *vcpu)
>
> void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
> {
> - vcpu->arch.vcpu_ops->vcpu_put(vcpu);
> - vcpu_clear_on_unsupported_cpu(vcpu);
> + if (likely(vcpu_has_run_once(vcpu))) {
> + vcpu->arch.vcpu_ops->vcpu_put(vcpu);
> + vcpu_clear_on_unsupported_cpu(vcpu);
> + }
> +
> vcpu->cpu = -1;
> }
[Severity: High]
Can skipping vcpu_ops->vcpu_put() here leak VHE PMU EL0 counter filtering
on the host CPU when KVM_SET_VCPU_EVENTS injects a nested exception before
the first KVM_RUN?
When KVM_SET_VCPU_EVENTS injects a nested SError (e.g. from L2 EL1h with
HCR_EL2.AMO and the cycle counter enabled in PMCNTENSET_EL0),
kvm_inject_nested() still calls kvm_pmu_nested_transition() unconditionally
whenever kvm_vcpu_has_pmu(vcpu) is true.
kvm_pmu_nested_transition() calls kvm_pmu_create_perf_event() and
kvm_vcpu_pmu_restore_guest(), modifying the physical VHE PMU EL0 filter
registers. Because kvm_arch_vcpu_put() now skips vcpu_ops->vcpu_put() and
kvm_vcpu_pmu_restore_host(), host EL0 PMU filtering is never restored.
In addition, kvm_pmu_create_perf_event() runs before kvm_arm_pmu_v3_init()
initializes vcpu->arch.pmu.overflow_work, so an NMI overflow on the leaked
event makes kvm_pmu_perf_overflow() queue an uninitialized irq_work and
trigger a NULL pointer dereference in irq_work_single().
Guarding kvm_pmu_nested_transition() on vcpu_has_run_once(vcpu) would avoid
touching PMU hardware or creating perf events before the first KVM_RUN.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204090914.459990-1-justin.he@arm.com?part=1
next prev parent reply other threads:[~2026-12-04 9:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=sashiko-outbox-249528@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=justin.he@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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