[PATCH v2] KVM: arm64: gic-v5: Limit IRS_IDR2.ID_BITS to 16 bits

From: Fuad Tabba

Date: Wed Dec 02 2026 - 05:06:17 EST


KVM limits a GICv5 guest to 16 ID bits, but a userspace write to
IRS_IDR2 accepts an ID_BITS as large as the host IRS's. Without
two-level IST support in the host IRS, KVM backs the guest's LPI IST
with a single kzalloc(), which warns and fails once the IST is larger
than KMALLOC_MAX_SIZE.

Reject more than 16 ID bits. Userspace writes to IRS_IDR2 are new in
this cycle, so no release has them.

Fixes: 71091136d1452 ("KVM: arm64: gic-v5: Handle userspace accesses to IRS MMIO region")
Suggested-by: Sascha Bischoff <sascha.bischoff@xxxxxxx>
Signed-off-by: Fuad Tabba <fuad.tabba@xxxxxxxxx>
---

Notes:
v2:
- Reject more than 16 ID bits, as Sascha suggested, and drop v1's
KMALLOC_MAX_SIZE check. With 16 ID bits a linear IST is at most
1MB.

v1: https://lore.kernel.org/r/20261126100023.1286902-1-fuad.tabba@xxxxxxxxx

Tested on FVP, VHE and nVHE hosts, with and without two-level IST
support in the IRS. The vgic_v5 selftest passes. A reproducer that
sets ID_BITS to 24 and restores an IST that wide hits the kzalloc()
warning without this patch. With the patch, the reproducer's
IRS_IDR2 writes with an ID_BITS of 17 or more are rejected.

Based on Linux 7.4-rc3 (aebb727447640).

arch/arm64/kvm/vgic/vgic-irs-v5.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/arch/arm64/kvm/vgic/vgic-irs-v5.c b/arch/arm64/kvm/vgic/vgic-irs-v5.c
index f73349c02656c..7a615895d997d 100644
--- a/arch/arm64/kvm/vgic/vgic-irs-v5.c
+++ b/arch/arm64/kvm/vgic/vgic-irs-v5.c
@@ -648,6 +648,10 @@ static int vgic_v5_mmio_uaccess_write_irs(struct kvm_vcpu *vcpu, gpa_t addr,
vgic_v5_irs_ist_id_bits(&irs_caps))
return -EINVAL;

+ /* We limit the CPU interface to 16 ID bits, so match that here */
+ if (FIELD_GET(GICV5_IRS_IDR2_ID_BITS, val) > 16)
+ return -EINVAL;
+
/* Min LPI ID bits must be greater than or equal to the HW */
if (FIELD_GET(GICV5_IRS_IDR2_MIN_LPI_ID_BITS, val) <
vgic_v5_irs_min_lpi_id_bits(&irs_caps))

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
--
2.47.3