* [PATCH v5] irqchip/riscv-imsic: Adjust the number of available guest irq files
@ 2026-01-04 13:34 Xu Lu
2026-01-19 8:04 ` Nutty.Liu
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Xu Lu @ 2026-01-04 13:34 UTC (permalink / raw)
To: anup, atish.patra, pjw, palmer, aou, alex, tglx
Cc: kvm, kvm-riscv, linux-riscv, linux-kernel, Xu Lu
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>
---
arch/riscv/kvm/aia.c | 2 +-
drivers/irqchip/irq-riscv-imsic-state.c | 12 +++++++++++-
include/linux/irqchip/riscv-imsic.h | 3 +++
3 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/kvm/aia.c b/arch/riscv/kvm/aia.c
index dad3181856600..cac3c2b51d724 100644
--- a/arch/riscv/kvm/aia.c
+++ b/arch/riscv/kvm/aia.c
@@ -630,7 +630,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;
diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c
index dc95ad856d80a..e8f20efb028be 100644
--- a/drivers/irqchip/irq-riscv-imsic-state.c
+++ b/drivers/irqchip/irq-riscv-imsic-state.c
@@ -794,7 +794,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;
@@ -888,6 +888,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) {
@@ -928,6 +929,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++;
}
diff --git a/include/linux/irqchip/riscv-imsic.h b/include/linux/irqchip/riscv-imsic.h
index 7494952c55187..43aed52385008 100644
--- a/include/linux/irqchip/riscv-imsic.h
+++ b/include/linux/irqchip/riscv-imsic.h
@@ -69,6 +69,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;
};
--
2.20.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v5] irqchip/riscv-imsic: Adjust the number of available guest irq files
2026-01-04 13:34 [PATCH v5] irqchip/riscv-imsic: Adjust the number of available guest irq files Xu Lu
@ 2026-01-19 8:04 ` Nutty.Liu
2026-01-26 10:54 ` Anup Patel
2026-02-20 4:11 ` patchwork-bot+linux-riscv
2 siblings, 0 replies; 6+ messages in thread
From: Nutty.Liu @ 2026-01-19 8:04 UTC (permalink / raw)
To: Xu Lu, anup, atish.patra, pjw, palmer, aou, alex, tglx
Cc: kvm, kvm-riscv, linux-riscv, linux-kernel
On 1/4/2026 9:34 PM, Xu Lu wrote:
> 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>
> ---
> arch/riscv/kvm/aia.c | 2 +-
> drivers/irqchip/irq-riscv-imsic-state.c | 12 +++++++++++-
> include/linux/irqchip/riscv-imsic.h | 3 +++
> 3 files changed, 15 insertions(+), 2 deletions(-)
Reviewed-by: Nutty Liu <nutty.liu@hotmail.com>
Thanks,
Nutty
> diff --git a/arch/riscv/kvm/aia.c b/arch/riscv/kvm/aia.c
> index dad3181856600..cac3c2b51d724 100644
> --- a/arch/riscv/kvm/aia.c
> +++ b/arch/riscv/kvm/aia.c
> @@ -630,7 +630,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;
>
> diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c
> index dc95ad856d80a..e8f20efb028be 100644
> --- a/drivers/irqchip/irq-riscv-imsic-state.c
> +++ b/drivers/irqchip/irq-riscv-imsic-state.c
> @@ -794,7 +794,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;
> @@ -888,6 +888,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) {
> @@ -928,6 +929,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++;
> }
>
> diff --git a/include/linux/irqchip/riscv-imsic.h b/include/linux/irqchip/riscv-imsic.h
> index 7494952c55187..43aed52385008 100644
> --- a/include/linux/irqchip/riscv-imsic.h
> +++ b/include/linux/irqchip/riscv-imsic.h
> @@ -69,6 +69,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;
> };
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v5] irqchip/riscv-imsic: Adjust the number of available guest irq files
2026-01-04 13:34 [PATCH v5] irqchip/riscv-imsic: Adjust the number of available guest irq files Xu Lu
2026-01-19 8:04 ` Nutty.Liu
@ 2026-01-26 10:54 ` Anup Patel
2026-01-26 11:07 ` [External] " Xu Lu
2026-02-20 4:11 ` patchwork-bot+linux-riscv
2 siblings, 1 reply; 6+ messages in thread
From: Anup Patel @ 2026-01-26 10:54 UTC (permalink / raw)
To: Xu Lu
Cc: atish.patra, pjw, palmer, aou, alex, tglx, kvm, kvm-riscv,
linux-riscv, linux-kernel
On Sun, Jan 4, 2026 at 7:05 PM Xu Lu <luxu.kernel@bytedance.com> wrote:
>
> 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>
Please carry Reviewed-by and Acked-by tags obtained in previous
revisions. Next time, I will not take the patch if previous tags are
missing.
Queued this patch for Linux-6.20.
Regards,
Anup
> ---
> arch/riscv/kvm/aia.c | 2 +-
> drivers/irqchip/irq-riscv-imsic-state.c | 12 +++++++++++-
> include/linux/irqchip/riscv-imsic.h | 3 +++
> 3 files changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/arch/riscv/kvm/aia.c b/arch/riscv/kvm/aia.c
> index dad3181856600..cac3c2b51d724 100644
> --- a/arch/riscv/kvm/aia.c
> +++ b/arch/riscv/kvm/aia.c
> @@ -630,7 +630,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;
>
> diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c
> index dc95ad856d80a..e8f20efb028be 100644
> --- a/drivers/irqchip/irq-riscv-imsic-state.c
> +++ b/drivers/irqchip/irq-riscv-imsic-state.c
> @@ -794,7 +794,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;
> @@ -888,6 +888,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) {
> @@ -928,6 +929,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++;
> }
>
> diff --git a/include/linux/irqchip/riscv-imsic.h b/include/linux/irqchip/riscv-imsic.h
> index 7494952c55187..43aed52385008 100644
> --- a/include/linux/irqchip/riscv-imsic.h
> +++ b/include/linux/irqchip/riscv-imsic.h
> @@ -69,6 +69,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;
> };
> --
> 2.20.1
>
>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [External] Re: [PATCH v5] irqchip/riscv-imsic: Adjust the number of available guest irq files
2026-01-26 10:54 ` Anup Patel
@ 2026-01-26 11:07 ` Xu Lu
2026-01-26 13:37 ` Anup Patel
0 siblings, 1 reply; 6+ messages in thread
From: Xu Lu @ 2026-01-26 11:07 UTC (permalink / raw)
To: Anup Patel
Cc: atish.patra, pjw, palmer, aou, alex, tglx, kvm, kvm-riscv,
linux-riscv, linux-kernel
On Mon, Jan 26, 2026 at 6:54 PM Anup Patel <anup@brainfault.org> wrote:
>
> On Sun, Jan 4, 2026 at 7:05 PM Xu Lu <luxu.kernel@bytedance.com> wrote:
> >
> > 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>
>
> Please carry Reviewed-by and Acked-by tags obtained in previous
> revisions. Next time, I will not take the patch if previous tags are
> missing.
Sorry about that. I thought the Reviewed-by and Acked-by tags belong
to the previous version so didn't carry them.
>
> Queued this patch for Linux-6.20.
Do I still need to resend the patch with Reviewed-by and Acked-by tags?
Best regards,
Xu Lu
>
> Regards,
> Anup
>
> > ---
> > arch/riscv/kvm/aia.c | 2 +-
> > drivers/irqchip/irq-riscv-imsic-state.c | 12 +++++++++++-
> > include/linux/irqchip/riscv-imsic.h | 3 +++
> > 3 files changed, 15 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/riscv/kvm/aia.c b/arch/riscv/kvm/aia.c
> > index dad3181856600..cac3c2b51d724 100644
> > --- a/arch/riscv/kvm/aia.c
> > +++ b/arch/riscv/kvm/aia.c
> > @@ -630,7 +630,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;
> >
> > diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c
> > index dc95ad856d80a..e8f20efb028be 100644
> > --- a/drivers/irqchip/irq-riscv-imsic-state.c
> > +++ b/drivers/irqchip/irq-riscv-imsic-state.c
> > @@ -794,7 +794,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;
> > @@ -888,6 +888,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) {
> > @@ -928,6 +929,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++;
> > }
> >
> > diff --git a/include/linux/irqchip/riscv-imsic.h b/include/linux/irqchip/riscv-imsic.h
> > index 7494952c55187..43aed52385008 100644
> > --- a/include/linux/irqchip/riscv-imsic.h
> > +++ b/include/linux/irqchip/riscv-imsic.h
> > @@ -69,6 +69,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;
> > };
> > --
> > 2.20.1
> >
> >
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [External] Re: [PATCH v5] irqchip/riscv-imsic: Adjust the number of available guest irq files
2026-01-26 11:07 ` [External] " Xu Lu
@ 2026-01-26 13:37 ` Anup Patel
0 siblings, 0 replies; 6+ messages in thread
From: Anup Patel @ 2026-01-26 13:37 UTC (permalink / raw)
To: Xu Lu
Cc: atish.patra, pjw, palmer, aou, alex, tglx, kvm, kvm-riscv,
linux-riscv, linux-kernel
On Mon, Jan 26, 2026 at 4:37 PM Xu Lu <luxu.kernel@bytedance.com> wrote:
>
> On Mon, Jan 26, 2026 at 6:54 PM Anup Patel <anup@brainfault.org> wrote:
> >
> > On Sun, Jan 4, 2026 at 7:05 PM Xu Lu <luxu.kernel@bytedance.com> wrote:
> > >
> > > 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>
> >
> > Please carry Reviewed-by and Acked-by tags obtained in previous
> > revisions. Next time, I will not take the patch if previous tags are
> > missing.
>
> Sorry about that. I thought the Reviewed-by and Acked-by tags belong
> to the previous version so didn't carry them.
>
> >
> > Queued this patch for Linux-6.20.
>
> Do I still need to resend the patch with Reviewed-by and Acked-by tags?
I have included the tags at the time of the merging patch.
Regards,
Anup
>
> Best regards,
> Xu Lu
>
> >
> > Regards,
> > Anup
> >
> > > ---
> > > arch/riscv/kvm/aia.c | 2 +-
> > > drivers/irqchip/irq-riscv-imsic-state.c | 12 +++++++++++-
> > > include/linux/irqchip/riscv-imsic.h | 3 +++
> > > 3 files changed, 15 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/arch/riscv/kvm/aia.c b/arch/riscv/kvm/aia.c
> > > index dad3181856600..cac3c2b51d724 100644
> > > --- a/arch/riscv/kvm/aia.c
> > > +++ b/arch/riscv/kvm/aia.c
> > > @@ -630,7 +630,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;
> > >
> > > diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c
> > > index dc95ad856d80a..e8f20efb028be 100644
> > > --- a/drivers/irqchip/irq-riscv-imsic-state.c
> > > +++ b/drivers/irqchip/irq-riscv-imsic-state.c
> > > @@ -794,7 +794,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;
> > > @@ -888,6 +888,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) {
> > > @@ -928,6 +929,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++;
> > > }
> > >
> > > diff --git a/include/linux/irqchip/riscv-imsic.h b/include/linux/irqchip/riscv-imsic.h
> > > index 7494952c55187..43aed52385008 100644
> > > --- a/include/linux/irqchip/riscv-imsic.h
> > > +++ b/include/linux/irqchip/riscv-imsic.h
> > > @@ -69,6 +69,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;
> > > };
> > > --
> > > 2.20.1
> > >
> > >
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5] irqchip/riscv-imsic: Adjust the number of available guest irq files
2026-01-04 13:34 [PATCH v5] irqchip/riscv-imsic: Adjust the number of available guest irq files Xu Lu
2026-01-19 8:04 ` Nutty.Liu
2026-01-26 10:54 ` Anup Patel
@ 2026-02-20 4:11 ` patchwork-bot+linux-riscv
2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+linux-riscv @ 2026-02-20 4:11 UTC (permalink / raw)
To: Xu Lu
Cc: linux-riscv, anup, atish.patra, pjw, palmer, aou, alex, tglx, kvm,
kvm-riscv, linux-kernel
Hello:
This patch was applied to riscv/linux.git (fixes)
by Anup Patel <anup@brainfault.org>:
On Sun, 4 Jan 2026 21:34:57 +0800 you wrote:
> 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.
>
> [...]
Here is the summary with links:
- [v5] irqchip/riscv-imsic: Adjust the number of available guest irq files
https://git.kernel.org/riscv/c/376e2f8cca28
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-02-20 4:11 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-04 13:34 [PATCH v5] irqchip/riscv-imsic: Adjust the number of available guest irq files Xu Lu
2026-01-19 8:04 ` Nutty.Liu
2026-01-26 10:54 ` Anup Patel
2026-01-26 11:07 ` [External] " Xu Lu
2026-01-26 13:37 ` Anup Patel
2026-02-20 4:11 ` patchwork-bot+linux-riscv
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox