[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] xen/riscv: fix out-of-range indexing of the IMSIC per-CPU MSI array
- To: Jan Beulich <jbeulich@xxxxxxxx>
- From: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
- Date: Wed, 2 Sep 2026 10:05:07 +0200
- Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:From:Content-Language:References:Cc:To:Subject:User-Agent:MIME-Version:Date:Message-ID"
- Cc: Romain Caritey <Romain.Caritey@xxxxxxxxxxxxx>, Baptiste Le Duc <baptiste.le-duc@xxxxxxxxxx>, Zheng Zhang <zhangzheng@xxxxxxxxxxx>, Alistair Francis <alistair.francis@xxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
- Delivery-date: Wed, 02 Sep 2026 08:05:12 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 9/1/26 5:59 PM, Jan Beulich wrote:
On 01.09.2026 17:50, Oleksii Kurochko wrote:
--- a/xen/arch/riscv/imsic.c
+++ b/xen/arch/riscv/imsic.c
@@ -326,6 +326,8 @@ int __init imsic_init(const struct dt_device_node *node)
unsigned int nr_parent_irqs, index, nr_handlers = 0;
paddr_t base_addr;
unsigned int nr_mmios;
+ /* imsic_cfg.msi[] is indexed by Xen CPU id, so size it accordingly. */
+ unsigned int nr_msi = num_possible_cpus();
The possible-CPUs-map may be sparse, so num_possible_cpus() may still yield
too small a value to use here. The thing to use likely is nr_cpu_ids. I notice
that variable is entirely unused so far by arch/riscv/*, though.
IIUC "sparse" means we could have three CPUs with IDs 0, 1 and 12, so
bits 0, 1 and 12 would be set in cpu_possible_map.
In that case num_possible_cpus() returns 3, which is the correct
*number* of CPUs but msi[] is indexed by the Xen CPU ID, not by the
CPU's ordinal position in the mask, so indexing it with ID 12 would need
13 entries. The two only coincide when the mask is dense, so you are
right that num_possible_cpus() is the wrong bound in principle.
That said, cpu_possible_map shouldn't be sparse by construction: the
boot CPU is assigned ID 0 in smp_prepare_boot_cpu(), and the remaining
IDs are handed out sequentially, so the bits are always 0..N-1 (for
RISC-V it is done in such way in downstream). Arm, the other user of
cpu_possible_map, fills it with Xen CPU IDs the same way.
I agree it is better not to depend on that, so I will use nr_cpu_ids for
nr_msi instead.
~ Oleksii
|