All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dan Carpenter" <dan@pereq.eu>
Cc: kvmarm@lists.linux.dev, "Oliver Upton" <oupton@kernel.org>,
	"Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH v2 1/2] KVM: arm64: Load the vcpu in KVM_SET_VCPU_EVENTS
Date: Wed, 18 Nov 2026 13:45:34 +0000	[thread overview]
Message-ID: <sashiko-outbox-221074@kernel.org> (raw)
In-Reply-To: <033a2d49e0f48426281b46eb1131ae64012aba18.1795006659.git.dan@pereq.eu>

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().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795006659.git.dan@pereq.eu?part=1

  reply	other threads:[~2026-11-18 13:45 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 [this message]
2026-11-18 17:44     ` Marc Zyngier
2026-11-19  8:18       ` Dan Carpenter
2026-11-19  9:53         ` Marc Zyngier
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=sashiko-outbox-221074@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dan@pereq.eu \
    --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 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.