All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xuheng Li" <xuheng@cs.columbia.edu>
Cc: kvmarm@lists.linux.dev, "Oliver Upton" <oupton@kernel.org>,
	"Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH] KVM: arm64: vgic-v3: Use the minimal BPR for the emulated active priority
Date: Fri, 04 Dec 2026 17:32:50 +0000	[thread overview]
Message-ID: <sashiko-outbox-250322@kernel.org> (raw)
In-Reply-To: <20261204-vgic-v3-active-priority-v1-1-9ce5187224ce@cs.columbia.edu>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] KVM: arm64: asymmetric BPR masking in __vgic_v3_read_iar()
  preemption check
- [High] KVM: arm64: BPR mask mismatch in __vgic_v3_write_eoir() skips
  LR deactivation
--

commit 4db6cbe64dc25717be9406f747d530f50d9a2d05
Author: Xuheng Li <xuheng@cs.columbia.edu>

KVM: arm64: vgic-v3: Use the minimal BPR for the emulated active priority

This commit stops masking the interrupt priority with the guest's current
BPR in __vgic_v3_set_active_priority(), normalizing the priority directly
with __vgic_v3_bpr_min() before recording it in ICH_AP{0,1}R<n>_EL2.

> diff --git a/arch/arm64/kvm/hyp/vgic-v3-sr.c b/arch/arm64/kvm/hyp/vgic-v3-sr.c
> index 2dfb5ff9db575..ef8f003cd52f9 100644
> --- a/arch/arm64/kvm/hyp/vgic-v3-sr.c
> +++ b/arch/arm64/kvm/hyp/vgic-v3-sr.c
> @@ -669,14 +669,13 @@ static u8 __vgic_v3_pri_to_pre(u8 pri, u32 vmcr, int grp)
>   * matter what the guest does with its BPR, we can always set/get the
>   * same value of a priority.
>   */
> -static void __vgic_v3_set_active_priority(u8 pri, u32 vmcr, int grp)
> +static void __vgic_v3_set_active_priority(u8 pri, int grp)
>  {
> -	u8 pre, ap;
> +	u8 ap;
>  	u32 val;
>  	int apr;
>  
> -	pre = __vgic_v3_pri_to_pre(pri, vmcr, grp);
> -	ap = pre >> __vgic_v3_bpr_min();
> +	ap = pri >> __vgic_v3_bpr_min();
>  	apr = ap / 32;

[Severity: High]
Does removing __vgic_v3_pri_to_pre() here break interrupt deactivation in
__vgic_v3_write_eoir()?

arch/arm64/kvm/hyp/vgic-v3-sr.c:__vgic_v3_write_eoir() {
	...
	act_prio = __vgic_v3_clear_highest_active_priority();
	...
	if (grp != !!(lr_val & ICH_LR_GROUP) ||
	    __vgic_v3_pri_to_pre(lr_prio, vmcr, grp) != act_prio)
		return;

	/* Let's now perform the deactivation */
	__vgic_v3_clear_active_lr(lr, lr_val);
}

__vgic_v3_clear_highest_active_priority() now returns act_prio
normalized only to __vgic_v3_bpr_min().  With ICC_BPR1_EL1 == 7 and
priority 0x78, act_prio is 0x78 while __vgic_v3_pri_to_pre() yields
0x00, so __vgic_v3_write_eoir() returns early before clearing the LR.

For EOImode == 0 interrupts and LPIs in List Registers, this leaves
ICH_LR_ACTIVE_BIT set (and skips gic_write_dir() for ICH_LR_HW
interrupts), wedging the interrupt active even though the APR bit was
already cleared.

[ ... ]

> @@ -752,7 +751,7 @@ static void __vgic_v3_read_iar(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
>  	lr_val &= ~ICH_LR_STATE;
>  	lr_val |= ICH_LR_ACTIVE_BIT;
>  	__gic_v3_set_lr(lr_val, lr);
> -	__vgic_v3_set_active_priority(lr_prio, vmcr, grp);
> +	__vgic_v3_set_active_priority(lr_prio, grp);
>  	vcpu_set_reg(vcpu, rt, lr_val & ICH_LR_VIRTUAL_ID_MASK);
>  	return;

[Severity: High]
Can this asymmetric BPR masking in __vgic_v3_read_iar() let lower- or
equal-priority interrupts preempt an active interrupt?

arch/arm64/kvm/hyp/vgic-v3-sr.c:__vgic_v3_read_iar() {
	...
	if (__vgic_v3_get_highest_active_priority() <= __vgic_v3_pri_to_pre(lr_prio, vmcr, grp))
		goto spurious;
	...
}

__vgic_v3_get_highest_active_priority() now keeps bits below the
current BPR while the right-hand side masks them off.  With 5
preemption bits and ICC_BPR1_EL1 == 7, an active interrupt at 0x40
is preempted by a lower-priority one at 0x78 (masked to 0x00).

That sets a second APR bit so the preempting interrupt's EOI clears the
higher-priority interrupt's bit instead (and equal-priority preemption
aliases the same APR bit).  Masking the active priority with the current
BPR as well needs to preserve GICv3_IDLE_PRIORITY (0xff).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-vgic-v3-active-priority-v1-1-9ce5187224ce@cs.columbia.edu?part=1

  reply	other threads:[~2026-12-04 17:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 17:19 [PATCH] KVM: arm64: vgic-v3: Use the minimal BPR for the emulated active priority Xuheng Li
2026-12-04 17:19 ` Xuheng Li via B4 Relay
2026-12-04 17:32 ` sashiko-bot [this message]
2026-12-04 17:44   ` Xuheng Li
2026-12-05  9:29     ` 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-250322@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xuheng@cs.columbia.edu \
    /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.