irqchip/riscv-imsic: Adjust the number of available guest irq files

JIRA: https://issues.redhat.com/browse/RHEL-174301

commit 376e2f8cca2816c489a9196e65cc904d1a907fd2
Author: Xu Lu <luxu.kernel@bytedance.com>
Date:   Sun, 4 Jan 2026 21:34:57 +0800

    irqchip/riscv-imsic: Adjust the number of available guest irq files

    Currently, KVM assumes the minimum of implemented HGEIE bits and
    "BIT(gc->guest_index_bits) - 1" as the number of guest files available
    across all CPUs. This will not work when CPUs have different number
    of guest files because KVM may incorrectly allocate a guest file on a
    CPU with fewer guest files.

    To address above, during initialization, calculate the number of
    available guest interrupt files according to MMIO resources and
    constrain the number of guest interrupt files that can be allocated
    by KVM.

    Signed-off-by: Xu Lu <luxu.kernel@bytedance.com>
    Reviewed-by: Nutty Liu <nutty.liu@hotmail.com>
    Reviewed-by: Anup Patel <anup@brainfault.org>
    Acked-by: Thomas Gleixner <tglx@kernel.org>
    Link: https://lore.kernel.org/r/20260104133457.57742-1-luxu.kernel@bytedance.com
    Signed-off-by: Anup Patel <anup@brainfault.org>

Signed-off-by: Jennifer Berringer <jberring@redhat.com>
This commit is contained in:
Jennifer Berringer
2026-06-01 23:02:08 -04:00
parent f1ceadf89c
commit 58d7be6860
3 changed files with 15 additions and 2 deletions
+1 -1
View File
@@ -629,7 +629,7 @@ int kvm_riscv_aia_init(void)
*/
if (gc)
kvm_riscv_aia_nr_hgei = min((ulong)kvm_riscv_aia_nr_hgei,
BIT(gc->guest_index_bits) - 1);
gc->nr_guest_files);
else
kvm_riscv_aia_nr_hgei = 0;
+11 -1
View File
@@ -762,7 +762,7 @@ static int __init imsic_parse_fwnode(struct fwnode_handle *fwnode,
int __init imsic_setup_state(struct fwnode_handle *fwnode, void *opaque)
{
u32 i, j, index, nr_parent_irqs, nr_mmios, nr_handlers = 0;
u32 i, j, index, nr_parent_irqs, nr_mmios, nr_guest_files, nr_handlers = 0;
struct imsic_global_config *global;
struct imsic_local_config *local;
void __iomem **mmios_va = NULL;
@@ -856,6 +856,7 @@ int __init imsic_setup_state(struct fwnode_handle *fwnode, void *opaque)
}
/* Configure handlers for target CPUs */
global->nr_guest_files = BIT(global->guest_index_bits) - 1;
for (i = 0; i < nr_parent_irqs; i++) {
rc = imsic_get_parent_hartid(fwnode, i, &hartid);
if (rc) {
@@ -896,6 +897,15 @@ int __init imsic_setup_state(struct fwnode_handle *fwnode, void *opaque)
local->msi_pa = mmios[index].start + reloff;
local->msi_va = mmios_va[index] + reloff;
/*
* KVM uses global->nr_guest_files to determine the available guest
* interrupt files on each CPU. Take the minimum number of guest
* interrupt files across all CPUs to avoid KVM incorrectly allocating
* an unexisted or unmapped guest interrupt file on some CPUs.
*/
nr_guest_files = (resource_size(&mmios[index]) - reloff) / IMSIC_MMIO_PAGE_SZ - 1;
global->nr_guest_files = min(global->nr_guest_files, nr_guest_files);
nr_handlers++;
}
+3
View File
@@ -68,6 +68,9 @@ struct imsic_global_config {
/* Number of guest interrupt identities */
u32 nr_guest_ids;
/* Number of guest interrupt files per core */
u32 nr_guest_files;
/* Per-CPU IMSIC addresses */
struct imsic_local_config __percpu *local;
};