All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: arm64: vgic-v3: Use the minimal BPR for the emulated active priority
@ 2026-12-04 17:19 ` Xuheng Li via B4 Relay
  0 siblings, 0 replies; 5+ messages in thread
From: Xuheng Li @ 2026-12-04 17:19 UTC (permalink / raw)
  To: Marc Zyngier, Oliver Upton, Fuad Tabba, Joey Gouly, Steffen Eiden,
	Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon,
	Mark Rutland, Eric Auger
  Cc: linux-arm-kernel, kvmarm, Xuheng Li

When the ICV_IAR{0,1}_EL1 trap emulation acknowledges an interrupt,
__vgic_v3_set_active_priority() records its priority in
ICH_AP{0,1}R<n>_EL2. It first masks the priority with the group's
current binary point, using __vgic_v3_pri_to_pre(), and only then
normalizes it with the minimal BPR value. The comment above the function
says the priority is normalized using the minimal BPR value, and the
architecture agrees: VirtualReadIAR0/1() set the bit for
VPriorityGroup(Priority), the priority group for the minimum BPR (IHI
0069H.b, 13.1.15 and 13.1.16).

With a guest BPR above the minimum, the emulation therefore sets the
wrong bit. A guest that acknowledges a Group 1 SGI at priority 0x78 with
ICC_BPR1_EL1 = 7 reads ICC_AP1R0_EL1 = 0x1 and ICC_RPR_EL1 = 0x0 with
the trap enabled (kvm-arm.vgic_v3_group1_trap=1), where a GIC-600
without the trap gives 0x8000 and 0x78. While that interrupt is active,
the emulated running priority is the highest possible, so the guest
takes no interrupt that the hardware would let preempt it.

Normalize the priority itself, as the comment describes. The preemption
check in __vgic_v3_read_iar() keeps using the current BPR.

The fix and this message were drafted with an AI assistant (Claude) and
reviewed by the submitter.

Fixes: 132a324ab62f ("KVM: arm64: vgic-v3: Add ICV_IAR1_EL1 handler")
Signed-off-by: Xuheng Li <xuheng@cs.columbia.edu>
---
Tested under QEMU (TCG, nVHE host) with kvm-arm.vgic_v3_group1_trap=1:
the guest above now reads 0x8000 and 0x78, as on the GIC-600, and both
read 0x0 and 0xff again after its EOI.

QEMU's own GICv3 virtual CPU interface, with the trap off, also reports
0x1 and 0x0 for this guest, so it can't serve as the reference here. The
GIC-600 numbers are from an AWS c6g.metal.
---
 arch/arm64/kvm/hyp/vgic-v3-sr.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/arch/arm64/kvm/hyp/vgic-v3-sr.c b/arch/arm64/kvm/hyp/vgic-v3-sr.c
index 2dfb5ff9db57..ef8f003cd52f 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;
 
 	if (!grp) {
@@ -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;
 

---
base-commit: 007722b8211f7b34fdf21b1e6a9c32497633ea29
change-id: 20261204-vgic-v3-active-priority-5301356cb914

Best regards,
-- 
Xuheng Li <xuheng@cs.columbia.edu>


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-05  9:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-12-04 17:44   ` Xuheng Li
2026-12-05  9:29     ` Marc Zyngier

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.