From: guoren@kernel.org
To: guoren@kernel.org
Cc: alex@ghiti.fr, anup@brainfault.org, aou@eecs.berkeley.edu,
atish.patra@linux.dev, cp0613@linux.alibaba.com,
fangyu.yu@linux.alibaba.com, gaohan@iscas.ac.cn,
inochiama@gmail.com, kvm-riscv@lists.infradead.org,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-riscv@lists.infradead.org, me@ziyao.cc, palmer@dabbelt.com,
pjw@kernel.org, tglx@kernel.org
Subject: [PATCH V2 3/4] irqchip/riscv-imsic: Move nr_guest_files to per-HART local config
Date: Sat, 25 Apr 2026 00:59:15 +0000 [thread overview]
Message-ID: <20260425005916.3321811-4-guoren@kernel.org> (raw)
In-Reply-To: <20260425005916.3321811-1-guoren@kernel.org>
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
With the recent KVM AIA per-HART HGEI conversion, the global
nr_guest_files is no longer appropriate. Different HARTs in
heterogeneous SoCs may have different numbers of guest interrupt
files.
Move `nr_guest_files` from `struct imsic_global_config` to
`struct imsic_local_config`, and compute it per-CPU in
imsic_setup_state() based on the actual MMIO guest file region size.
Update the related comment to reflect that KVM now uses the
per-HART value.
This eliminates the last global assumption about guest files and
completes the per-HART conversion series for RISC-V AIA/IMSIC.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
drivers/irqchip/irq-riscv-imsic-state.c | 10 ++++++----
include/linux/irqchip/riscv-imsic.h | 6 +++---
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c
index e3ed874d89e7..f01525362cf7 100644
--- a/drivers/irqchip/irq-riscv-imsic-state.c
+++ b/drivers/irqchip/irq-riscv-imsic-state.c
@@ -878,7 +878,6 @@ 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) {
@@ -910,23 +909,26 @@ int __init imsic_setup_state(struct fwnode_handle *fwnode, void *opaque)
reloff -= ALIGN(resource_size(&mmios[j]),
BIT(global->guest_index_bits) * IMSIC_MMIO_PAGE_SZ);
}
+
+ local = per_cpu_ptr(global->local, cpu);
+ local->nr_guest_files = BIT(global->guest_index_bits) - 1;
+
if (index >= nr_mmios) {
pr_warn("%pfwP: MMIO not found for parent irq%d\n", fwnode, i);
continue;
}
- local = per_cpu_ptr(global->local, cpu);
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
+ * KVM uses local->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);
+ local->nr_guest_files = min(local->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 4b348836de7a..13e8bd7ff4b4 100644
--- a/include/linux/irqchip/riscv-imsic.h
+++ b/include/linux/irqchip/riscv-imsic.h
@@ -40,6 +40,9 @@
struct imsic_local_config {
phys_addr_t msi_pa;
void __iomem *msi_va;
+
+ /* Number of guest interrupt files per core */
+ u32 nr_guest_files;
};
struct imsic_global_config {
@@ -68,9 +71,6 @@ 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.43.0
next prev parent reply other threads:[~2026-04-25 0:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-25 0:59 [PATCH V2 0/4] RISC-V: KVM: AIA: Convert HGEI management to fully per-HART guoren
2026-04-25 0:59 ` [PATCH V2 1/4] RISC-V: KVM: AIA: Make HGEI number and management fully per-CPU guoren
2026-04-25 0:59 ` [PATCH V2 2/4] RISC-V: KVM: AIA: Replace global HGEI count with simple enabled bool guoren
2026-04-25 0:59 ` guoren [this message]
2026-04-25 0:59 ` [PATCH V2 4/4] RISC-V: KVM: AIA: Use per-HART IMSIC guest files to compute final HGEI count guoren
2026-04-25 1:06 ` Re: [PATCH 3/3] irqchip/riscv-imsic: Remove global nr_guest_files after KVM AIA per-HART conversion guoren
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=20260425005916.3321811-4-guoren@kernel.org \
--to=guoren@kernel.org \
--cc=alex@ghiti.fr \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=atish.patra@linux.dev \
--cc=cp0613@linux.alibaba.com \
--cc=fangyu.yu@linux.alibaba.com \
--cc=gaohan@iscas.ac.cn \
--cc=inochiama@gmail.com \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=me@ziyao.cc \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=tglx@kernel.org \
/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