From: Marc Zyngier <maz@kernel.org>
To: Dan Carpenter <dan@pereq.eu>
Cc: Oliver Upton <oupton@kernel.org>,
kvmarm@lists.linux.dev, sashiko-reviews@lists.linux.dev
Subject: Re: [PATCH v2 1/2] KVM: arm64: Load the vcpu in KVM_SET_VCPU_EVENTS
Date: Thu, 19 Nov 2026 09:53:15 +0000 [thread overview]
Message-ID: <86y0apywok.wl-maz@kernel.org> (raw)
In-Reply-To: <av6wypzwAJxIyKOU@stanley.mountain>
On Thu, 19 Nov 2026 08:18:18 +0000,
Dan Carpenter <dan@pereq.eu> wrote:
>
> On Wed, Nov 18, 2026 at 05:44:06PM +0000, Marc Zyngier wrote:
> > On Wed, 18 Nov 2026 13:45:34 +0000,
> > sashiko-bot@kernel.org wrote:
> > >
> > > Thank you for your contribution! Sashiko AI review found 1 potential
> > > issue to consider:
> > > - [Medium] KVM: arm64: stale mmio_needed after kvm_inject_nested() in
> > > KVM_SET_VCPU_EVENTS
> > > --
> > >
> > > commit 178d0de7451612b8ddf14a943cb82094efbd77d1
> > > Author: Dan Carpenter <dan@pereq.eu>
> > >
> > > KVM: arm64: Load the vcpu in KVM_SET_VCPU_EVENTS
> > >
> > > This commit wraps __kvm_arm_vcpu_set_events() in vcpu_load() and vcpu_put()
> > > so that kvm_inject_nested() operates on a loaded vCPU during
> > > KVM_SET_VCPU_EVENTS.
> > >
> > > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> > > > index 84a52e27ed859..a148e80d0aef7 100644
> > > > --- a/arch/arm64/kvm/arm.c
> > > > +++ b/arch/arm64/kvm/arm.c
> > > > @@ -2002,7 +2002,7 @@ static int kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,
> > > > static int kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
> > > > struct kvm_vcpu_events *events)
> > > > {
> > > > - int i;
> > > > + int i, ret;
> > > >
> > > > /* check whether the reserved field is zero */
> > > > for (i = 0; i < ARRAY_SIZE(events->reserved); i++)
> > > > @@ -2014,7 +2014,11 @@ static int kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
> > > > if (events->exception.pad[i])
> > > > return -EINVAL;
> > > >
> > > > - return __kvm_arm_vcpu_set_events(vcpu, events);
> > > > + vcpu_load(vcpu);
> > > > + ret = __kvm_arm_vcpu_set_events(vcpu, events);
> > > > + vcpu_put(vcpu);
> > > > +
> > > > + return ret;
> > > > }
> > >
> > > [Severity: Medium]
> > > Does vcpu->mmio_needed remain set when KVM_SET_VCPU_EVENTS injects an
> > > exception from L2 that routes to L1 EL2?
> > >
> > > When an L2 guest exits with KVM_EXIT_MMIO and userspace aborts the access via
> > > KVM_SET_VCPU_EVENTS (for example with ext_dabt_pending = 1 while HCR_EL2.TEA
> > > is set), kvm_inject_sea_dabt() -> kvm_inject_nested() commits the EL2
> > > exception entry directly via __kvm_adjust_pc(), which clears
> > > PENDING_EXCEPTION. When __kvm_arm_vcpu_set_events() then calls
> > > commit_pending_events(), PENDING_EXCEPTION is already clear, so it returns
> > > early without clearing vcpu->mmio_needed:
> > >
> > > arch/arm64/kvm/guest.c:commit_pending_events() {
> > > if (!vcpu_get_flag(vcpu, PENDING_EXCEPTION))
> > > return;
> > >
> > > vcpu->mmio_needed = false;
> > > kvm_call_hyp(__kvm_adjust_pc, vcpu);
> > > }
> > >
> > > On the next KVM_RUN, kvm_handle_mmio_return() sees vcpu->mmio_needed still
> > > set, writes the MMIO read value into L1 EL2's destination register and
> > > advances L1 EL2's exception vector PC by 4 bytes via kvm_incr_pc().
> >
> > I think this is a separate issue, which doesn't intersect with the
> > current patch.
>
> Yep.
>
> > The problem is that we have multiple ways to "commit'
> > the state on exception delivery, and that we miss MMIO handling in the
> > EL1->EL2 path.
> >
> > Oliver, WDYT?
> >
>
> I have a reproducer for the bug Sashiko found and this patch doesn't
> work. Attached. Claude wanted to just set vcpu->mmio_needed = false;
> but I told it to call commit_pending_events() instead.
Duh, yes. I had the wrong __adjust_pc()... :-( We need to replace the
one that triggers the exception delivery, rather than the one that
performs a previous instruction skip in the original context...
Please send this, and I'll queue it immediately.
Thanks a lot for making it easy to understand the issue!
M.
--
Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2026-11-19 9:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 13:05 [PATCH v2 0/2] KVM: arm64: nv: Fix a couple NULL dereferences in kvm_inject_nested() Dan Carpenter
2026-11-18 13:05 ` [PATCH v2 1/2] KVM: arm64: Load the vcpu in KVM_SET_VCPU_EVENTS Dan Carpenter
2026-11-18 13:45 ` sashiko-bot
2026-11-18 17:44 ` Marc Zyngier
2026-11-19 8:18 ` Dan Carpenter
2026-11-19 9:53 ` Marc Zyngier [this message]
2026-11-18 13:05 ` [PATCH v2 2/2] KVM: arm64: nv: Fix NULL dereference in kvm_pmu_nested_transition() Dan Carpenter
2026-11-19 12:43 ` [PATCH v2 0/2] KVM: arm64: nv: Fix a couple NULL dereferences in kvm_inject_nested() Marc Zyngier
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=86y0apywok.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=dan@pereq.eu \
--cc=kvmarm@lists.linux.dev \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.