From: sashiko-bot@kernel.org
To: "Dan Carpenter" <dan@pereq.eu>
Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org,
"Oliver Upton" <oupton@kernel.org>,
"Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH v2 6/8] KVM: arm64: nv: Don't deliver a pending SError to the wrong guest
Date: Wed, 25 Nov 2026 07:24:38 +0000 [thread overview]
Message-ID: <sashiko-outbox-232776@kernel.org> (raw)
In-Reply-To: <20261125-double_exception-v2-6-224689d8a764@pereq.eu>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] KVM: arm64: nv: sleeping in atomic context via
kvm_nested_flush_hwstate()
--
commit 81f527c7f211ae919b4cadce520f83a546cfd38d
Author: Dan Carpenter <dan@pereq.eu>
KVM: arm64: nv: Don't deliver a pending SError to the wrong guest
This commit stashes a pending HCR_EL2.VSE bit into NESTED_SERROR_PENDING
when switching between L1 and L2 so that kvm_nested_flush_hwstate()
re-evaluates SError routing in the new context.
> diff --git a/arch/arm64/kvm/emulate-nested.c b/arch/arm64/kvm/emulate-nested.c
> index 39136a89d74bb..cccaf02610e87 100644
> --- a/arch/arm64/kvm/emulate-nested.c
> +++ b/arch/arm64/kvm/emulate-nested.c
> @@ -2792,6 +2792,18 @@ static u64 kvm_check_illegal_exception_return(struct kvm_vcpu *vcpu, u64 spsr)
> return spsr;
> }
>
> +/*
> + * HCR_EL2.VSE was set for the context we are leaving. Store the SError
> + * instead, so that kvm_nested_flush_hwstate() routes it in the new context.
> + */
> +static void kvm_nested_stash_serror(struct kvm_vcpu *vcpu)
> +{
> + if (*vcpu_hcr(vcpu) & HCR_EL2_VSE) {
> + *vcpu_hcr(vcpu) &= ~HCR_EL2_VSE;
> + vcpu_set_flag(vcpu, NESTED_SERROR_PENDING);
> + }
> +}
> +
> void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu)
> {
> u64 spsr, elr, esr;
> @@ -2823,6 +2835,7 @@ void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu)
> preempt_disable();
> vcpu_set_flag(vcpu, IN_NESTED_ERET);
> kvm_arch_vcpu_put(vcpu);
> + kvm_nested_stash_serror(vcpu);
[Severity: High]
Can stashing NESTED_SERROR_PENDING here cause sleeping in atomic context
on the next guest entry when a virtual PMU counter is active?
When L1 has a masked pending SError in HCR_EL2_VSE with HCR_EL2.AMO set
and executes ERET into L2, setting NESTED_SERROR_PENDING causes the next
iteration of kvm_arch_vcpu_ioctl_run() to re-inject the SError back to
vEL2 while preemption is disabled:
kvm_arch_vcpu_ioctl_run()
preempt_disable()
kvm_nested_flush_hwstate()
kvm_inject_serror_esr()
kvm_inject_nested_serror()
kvm_inject_nested()
preempt_disable()
...
preempt_enable()
kvm_pmu_nested_transition()
kvm_pmu_create_perf_event()
Because kvm_inject_nested() only balances its own inner preempt_disable(),
the outer preempt_disable() from kvm_arch_vcpu_ioctl_run() is still in
effect when kvm_pmu_nested_transition() recreates perf events for counters
whose EL1 and EL2 filters differ. kvm_pmu_create_perf_event() then calls
perf_event_release_kernel() and perf_event_create_kernel_counter(), which
acquire sleeping mutexes and allocate with GFP_KERNEL while atomic.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-double_exception-v2-0-224689d8a764@pereq.eu?part=6
next prev parent reply other threads:[~2026-11-25 7:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 6:56 [PATCH v2 0/8] KVM: arm64: Fix kvm_reset_vcpu() and SError handling for nested virt Dan Carpenter
2026-11-25 6:56 ` [PATCH v2 1/8] KVM: arm64: Drop an incomplete MMIO access when resetting a vcpu Dan Carpenter
2026-11-25 6:56 ` [PATCH v2 2/8] KVM: arm64: Reset SP_EL1, ELR_EL1 and SPSR_EL1 " Dan Carpenter
2026-11-25 7:15 ` sashiko-bot
2026-11-25 6:56 ` [PATCH v2 3/8] KVM: arm64: Discard a pending SError " Dan Carpenter
2026-11-25 6:56 ` [PATCH v2 4/8] KVM: arm64: nv: Discard nested SError in kvm_reset_vcpu() Dan Carpenter
2026-11-25 6:56 ` [PATCH v2 5/8] KVM: arm64: nv: Replace a pending SError when injecting a new one Dan Carpenter
2026-11-25 6:56 ` [PATCH v2 6/8] KVM: arm64: nv: Don't deliver a pending SError to the wrong guest Dan Carpenter
2026-11-25 7:24 ` sashiko-bot [this message]
2026-11-25 6:56 ` [PATCH v2 7/8] KVM: arm64: nv: Re-inject a stored SError after the exit is handled Dan Carpenter
2026-11-25 6:56 ` [PATCH v2 8/8] KVM: arm64: selftests: Test that a vcpu reset clears the vcpu's state Dan Carpenter
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-232776@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dan@pereq.eu \
--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