From: Sascha Bischoff <sascha.bischoff@arm.com>
To: Fuad Tabba <fuad.tabba@linux.dev>, Marc Zyngier <maz@kernel.org>,
Oliver Upton <oupton@kernel.org>
Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Joey Gouly <joey.gouly@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Steffen Eiden <seiden@linux.ibm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Fuad Tabba <tabba@google.com>
Subject: Re: [PATCH] KVM: arm64: gic-v5: Reject an ID_BITS too large for a linear IST
Date: Thu, 26 Nov 2026 12:28:38 +0000 [thread overview]
Message-ID: <06effdad-0a76-4d73-9542-cb628a40d887@arm.com> (raw)
In-Reply-To: <20261126100023.1286902-1-fuad.tabba@linux.dev>
Hi Fuad,
On 26/11/2026 10:00, Fuad Tabba wrote:
> Without two-level IST support in the host IRS, KVM allocates a guest's
> LPI IST with a single kzalloc(). The guest picks the IST's size, up to
> the virtual IRS_IDR2.ID_BITS, which userspace can set as high as the
> host's. With 24 ID bits the IST is at least 64MB, more than
> KMALLOC_MAX_SIZE with 4K or 16K pages, and kzalloc() warns when the
> guest enables the IST.
>
> Reject an ID_BITS for which a linear IST would be larger than
> KMALLOC_MAX_SIZE. This applies even for a Linux guest, which
> configures a much smaller IST. Userspace writes to IRS_IDR2 are new
> in this cycle, so no release has them.
Thanks for catching and fixing this issue. I agree that we shouldn't
allow this to happen, and what you have here is a defensive check.
However, I was surprised that this was reachable in the first place, and
now see the mistake I'd made.
In general, we limit GICv5-based VMs to 16-bits of ID space in both the
CPUIF (see vgic_v5_reset()) and in the emulated IRS (see
kvm_vgic_v5_irs_init()). The userspace write path fails to enforce that
limit, however, and only checks the hardware capabilities. I see no
reason to allow a vIRS that supports more ID bits than the CPUIF.
Maybe something along the lines of the following in
vgic_v5_mmio_uaccess_write_irs()?
/* 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;
Are you happy to add this (or similar) to your patch, or would you
prefer me to fix that up separately?
Long-term I'd like to remove the hard coded 16 in the vIRS code, but
that's a clean up that's not appropriate for this patch.
Thanks,
Sascha
>
> Fixes: 71091136d1452 ("KVM: arm64: gic-v5: Handle userspace accesses to IRS MMIO region")
> Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
> ---
>
> Notes:
> Tested on FVP, on 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 it, the IRS_IDR2 write is rejected.
>
> Based on Linux 7.4-rc3 (aebb727447640).
>
> arch/arm64/kvm/vgic/vgic-irs-v5.c | 4 ++++
> arch/arm64/kvm/vgic/vgic-v5-tables.c | 8 ++++++++
> arch/arm64/kvm/vgic/vgic-v5-tables.h | 1 +
> 3 files changed, 13 insertions(+)
>
> diff --git a/arch/arm64/kvm/vgic/vgic-irs-v5.c b/arch/arm64/kvm/vgic/vgic-irs-v5.c
> index f73349c02656c..97362caef4433 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;
>
> + /* A linear host IST is a single allocation, limited to KMALLOC_MAX_SIZE */
> + if (!vgic_v5_lpi_ist_id_bits_valid(FIELD_GET(GICV5_IRS_IDR2_ID_BITS, val)))
> + 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))
> diff --git a/arch/arm64/kvm/vgic/vgic-v5-tables.c b/arch/arm64/kvm/vgic/vgic-v5-tables.c
> index 8f72704209b0e..ae5f380fa783c 100644
> --- a/arch/arm64/kvm/vgic/vgic-v5-tables.c
> +++ b/arch/arm64/kvm/vgic/vgic-v5-tables.c
> @@ -1207,6 +1207,14 @@ static unsigned int vgic_v5_ist_istsz(unsigned int id_bits)
> return GICV5_IRS_IST_CFGR_ISTSZ_8;
> }
>
> +bool vgic_v5_lpi_ist_id_bits_valid(unsigned int id_bits)
> +{
> + if (vgic_v5_irs_ist_levels(&irs_caps))
> + return true;
> +
> + return GICV5_LINEAR_IST_SIZE(id_bits, vgic_v5_ist_istsz(id_bits)) <= KMALLOC_MAX_SIZE;
> +}
> +
> /*
> * Allocate an IST for SPIs.
> *
> diff --git a/arch/arm64/kvm/vgic/vgic-v5-tables.h b/arch/arm64/kvm/vgic/vgic-v5-tables.h
> index 89096926563f7..ba049978157b1 100644
> --- a/arch/arm64/kvm/vgic/vgic-v5-tables.h
> +++ b/arch/arm64/kvm/vgic/vgic-v5-tables.h
> @@ -123,6 +123,7 @@ int vgic_v5_vmte_free_vpe(struct kvm_vcpu *vcpu);
>
> int vgic_v5_spi_ist_alloc(struct kvm *kvm, unsigned int id_bits);
> int vgic_v5_lpi_ist_exists(struct kvm *kvm);
> +bool vgic_v5_lpi_ist_id_bits_valid(unsigned int id_bits);
> int vgic_v5_lpi_ist_alloc(struct kvm *kvm, unsigned int id_bits);
> int vgic_v5_lpi_ist_free(struct kvm *kvm);
>
>
> base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
prev parent reply other threads:[~2026-11-26 12:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 10:00 [PATCH] KVM: arm64: gic-v5: Reject an ID_BITS too large for a linear IST Fuad Tabba
2026-11-26 12:28 ` Sascha Bischoff [this message]
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=06effdad-0a76-4d73-9542-cb628a40d887@arm.com \
--to=sascha.bischoff@arm.com \
--cc=catalin.marinas@arm.com \
--cc=fuad.tabba@linux.dev \
--cc=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=seiden@linux.ibm.com \
--cc=suzuki.poulose@arm.com \
--cc=tabba@google.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox