Skip to contentSkip to conversation

riscv-to-apply queue

GIT PULL Applied [email protected] 2 participants 10 messages Nov 15 – Nov 16

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

From: Alistair Francis <[email protected]>

The following changes since commit e9fa1f66f0d47c74b6766e1b8b87ad7c2a9394d5:

Merge tag 'pull-nbd-2026-11-10-v2' of https://gitlab.com/ebblake/qemu into staging (2026-11-13 08:44:16 -0700)

are available in the Git repository at:

https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20261115

for you to fetch changes up to 57bae3bdbf69777c8bf32f50a85c36283bbeb673:

target/riscv/tcg: clear itrigger_enabled during trigger_reset_hold() (2026-11-15 10:41:59 +1000)

----------------------------------------------------------------
RISC-V PR for 11.2

* Fix minimal RISC-V system builds
* Check RISC-V APLIC config value bounds in realize
* Fix Server Platform Reference mtimer frequency
* Clear itrigger_enabled during trigger_reset_hold

----------------------------------------------------------------
Daniel Henrique Barboza (1):
target/riscv/tcg: clear itrigger_enabled during trigger_reset_hold()

Peter Maydell (1):
hw/intc/riscv_aplic: Check config value bounds in realize

Sunil V L (1):
hw/riscv/server_platform_ref: Fix mtimer frequency

Tan Chi (5):
hw/riscv: Build AIA glue only with APLIC and IMSIC hw/riscv: Build device-common only for its users hw/riscv: Move platform bus FDT creation to machine code hw/riscv: Pass socket topology to KVM AIA hw/riscv: Select SSI for IBEX

 hw/riscv/aia.h                 | 17 ++++++++++++++++-
 include/hw/riscv/fdt-common.h  |  3 +--
 target/riscv/kvm/kvm_riscv.h   |  5 ++++-
 hw/intc/riscv_aplic.c          | 32 ++++++++++++++++++++++++++------
 hw/riscv/aia.c                 | 11 -----------
 hw/riscv/fdt-common.c          | 13 ++-----------
 hw/riscv/server_platform_ref.c | 11 ++++++++---
 hw/riscv/virt.c                | 21 ++++++++++++++++++---
 target/riscv/kvm/kvm-cpu.c     | 10 +++++-----
 target/riscv/kvm/kvm-stub.c    |  3 ++-
 target/riscv/tcg/debug.c       |  1 +
 hw/riscv/Kconfig               |  6 ++++++
 hw/riscv/meson.build           |  5 +++--
 13 files changed, 92 insertions(+), 46 deletions(-)
#1 lore raw

[PULL 1/8] hw/riscv: Build AIA glue only with APLIC and IMSIC

From: Tan Chi <[email protected]>

hw/riscv/aia.c is built unconditionally, but riscv_create_aia() references the APLIC and IMSIC device implementations, which are only built when their respective Kconfig options are enabled.

This causes undefined references to riscv_aplic_create() in minimal RISC-V builds that do not include APLIC.

Build aia.c only when both CONFIG_RISCV_APLIC and CONFIG_RISCV_IMSIC are enabled. Move imsic_num_bits() to aia.h as a static inline helper, since it is also used by FDT and ACPI code independently of the AIA device creation helper.

Message-ID: <[email protected]>

---
 hw/riscv/aia.h       | 12 +++++++++++-
 hw/riscv/aia.c       | 11 -----------
 hw/riscv/meson.build |  3 ++-
 3 files changed, 13 insertions(+), 13 deletions(-)
hw/riscv/aia.h +11 -1
index 5df3292610e9..e4dcc5aae09c 100644
@@ -10,8 +10,18 @@
 #define HW_RISCV_AIA_H
 
 #include "exec/hwaddr.h"
+#include "qemu/bitops.h"
 
-uint32_t imsic_num_bits(uint32_t count);
+static inline uint32_t imsic_num_bits(uint32_t count)
+{
+    uint32_t ret = 0;
+
+    while (BIT(ret) < count) {
+        ret++;
+    }
+
+    return ret;
+}
 
 DeviceState *riscv_create_aia(MemoryRegion *container,
                              bool msimode, int aia_guests,
hw/riscv/aia.c +0 -11
index 56fc06453321..4463ea2be887 100644
@@ -13,17 +13,6 @@
 
 #include "aia.h"
 
-uint32_t imsic_num_bits(uint32_t count)
-{
-    uint32_t ret = 0;
-
-    while (BIT(ret) < count) {
-        ret++;
-    }
-
-    return ret;
-}
-
 DeviceState *riscv_create_aia(MemoryRegion *container,
                              bool msimode, int aia_guests,
                              uint32_t m_imsic_stride,
hw/riscv/meson.build +2 -1
index 6bdabb954473..957031c07d5c 100644
@@ -1,5 +1,6 @@
 riscv_ss = ss.source_set()
-riscv_ss.add(files('aia.c'))
+riscv_ss.add(when: ['CONFIG_RISCV_APLIC', 'CONFIG_RISCV_IMSIC'],
+             if_true: files('aia.c'))
 riscv_ss.add(files('boot.c'))
 riscv_ss.add(files('device-common.c'))
 riscv_ss.add(files('fdt-common.c'))
Signature · 1 line
2.55.0
#2 lore raw

[PULL 2/8] hw/riscv: Build device-common only for its users

In reply to [email protected]

From: Tan Chi <[email protected]>

hw/riscv/device-common.c is built unconditionally, although its helpers are only used by the virt and server reference machines.

In minimal builds without these machines, device-common.c can reference device implementations that are not built, resulting in an undefined reference to gpex_set_irq_num().

Introduce CONFIG_RISCV_DEVICE_COMMON and select it from the two machines that use these helpers. Build device-common.c only when this option is enabled.

Message-ID: <[email protected]>

---
 hw/riscv/Kconfig     | 5 +++++
 hw/riscv/meson.build | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)
hw/riscv/Kconfig +5 -0
index d89fdfcc8671..f3bf8d159cba 100644
@@ -7,6 +7,9 @@ config RISCV_NUMA
 config IBEX
     bool
 
+config RISCV_DEVICE_COMMON
+    bool
+
 # RISC-V machines in alphabetical order
 
 config MICROCHIP_PFSOC
@@ -68,6 +71,7 @@ config RISCV_VIRT
     select PLATFORM_BUS
     select ACPI
     select ACPI_PCI
+    select RISCV_DEVICE_COMMON
 
 config RISCV_SERVER_PLATFORM_REF
     bool
@@ -85,6 +89,7 @@ config RISCV_SERVER_PLATFORM_REF
     select RISCV_IOMMU
     select RISCV_NUMA
     select SERIAL_MM
+    select RISCV_DEVICE_COMMON
 
 config SHAKTI_C
     bool
hw/riscv/meson.build +1 -1
index 957031c07d5c..b60108787dd5 100644
@@ -2,7 +2,7 @@ riscv_ss = ss.source_set()
 riscv_ss.add(when: ['CONFIG_RISCV_APLIC', 'CONFIG_RISCV_IMSIC'],
              if_true: files('aia.c'))
 riscv_ss.add(files('boot.c'))
-riscv_ss.add(files('device-common.c'))
+riscv_ss.add(when: 'CONFIG_RISCV_DEVICE_COMMON', if_true: files('device-common.c'))
 riscv_ss.add(files('fdt-common.c'))
 riscv_ss.add(when: 'CONFIG_RISCV_NUMA', if_true: files('numa.c'))
 riscv_ss.add(files('riscv_hart.c'))
Signature · 1 line
2.55.0
#3 lore raw

[PULL 4/8] hw/riscv: Pass socket topology to KVM AIA

In reply to [email protected]

From: Tan Chi <[email protected]>

KVM AIA initialization uses the RISC-V NUMA helpers to query the socket count and per-socket hart topology.

However, KVM support can be enabled without CONFIG_RISCV_NUMA. In this configuration, kvm-cpu.c is built while numa.c is not, resulting in undefined references to riscv_socket_count(), riscv_socket_hart_count() and riscv_socket_first_hartid().

The virt machine already determines the hart topology when initializing its hart arrays. Pass the socket topology directly to KVM AIA instead of querying the NUMA helpers again.

This removes the build-time dependency on CONFIG_RISCV_NUMA without changing the IMSIC address configuration.

Message-ID: <[email protected]>

---
 hw/riscv/aia.h               |  5 +++++
 target/riscv/kvm/kvm_riscv.h |  5 ++++-
 hw/riscv/virt.c              | 10 +++++++++-
 target/riscv/kvm/kvm-cpu.c   | 10 +++++-----
 target/riscv/kvm/kvm-stub.c  |  3 ++-
 5 files changed, 25 insertions(+), 8 deletions(-)
hw/riscv/aia.h +5 -0
index e4dcc5aae09c..ed9b613f3c80 100644
@@ -12,6 +12,11 @@
 #include "exec/hwaddr.h"
 #include "qemu/bitops.h"
 
+typedef struct RISCVAIASocket {
+    uint32_t hartid_base;
+    uint32_t num_harts;
+} RISCVAIASocket;
+
 static inline uint32_t imsic_num_bits(uint32_t count)
 {
     uint32_t ret = 0;
target/riscv/kvm/kvm_riscv.h +4 -1
index aef681f0a212..bad78e28f453 100644
@@ -21,6 +21,8 @@
 
 #include "target/riscv/cpu-qom.h"
 
+typedef struct RISCVAIASocket RISCVAIASocket;
+
 void kvm_riscv_reset_vcpu(RISCVCPU *cpu);
 /**
  * kvm_riscv_set_irq:
@@ -29,7 +31,8 @@ void kvm_riscv_reset_vcpu(RISCVCPU *cpu);
  * @level: %0 to clear the interrupt, non-zero to set it.
  */
 void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level);
-void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
+void kvm_riscv_aia_create(const RISCVAIASocket *sockets,
+                          uint32_t socket_count, uint64_t group_shift,
                           uint64_t aia_irq_num, uint64_t aia_msi_num,
                           uint64_t aplic_base, uint64_t imsic_base,
                           uint64_t guest_num);
hw/riscv/virt.c +9 -1
index ffd6e8868f70..dceb3ff55e17 100644
@@ -859,7 +859,15 @@ static void virt_machine_init(MachineState *machine)
     }
 
     if (kvm_enabled() && virt_use_kvm_aia_aplic_imsic(s->aia_type)) {
-        kvm_riscv_aia_create(machine, IMSIC_MMIO_GROUP_MIN_SHIFT,
+        g_autofree RISCVAIASocket *aia_sockets =
+                g_new(RISCVAIASocket, socket_count);
+        for (i = 0; i < socket_count; i++) {
+            aia_sockets[i].hartid_base = s->soc[i].hartid_base;
+            aia_sockets[i].num_harts = s->soc[i].num_harts;
+        }
+
+        kvm_riscv_aia_create(aia_sockets, socket_count,
+                             IMSIC_MMIO_GROUP_MIN_SHIFT,
                              VIRT_IRQCHIP_NUM_SOURCES, VIRT_IRQCHIP_NUM_MSIS,
                              s->memmap[VIRT_APLIC_S].base,
                              s->memmap[VIRT_IMSIC_S].base,
target/riscv/kvm/kvm-cpu.c +5 -5
index 5beb60233809..32f18a1589fe 100644
@@ -48,7 +48,7 @@
 #include "sbi_ecall_interface.h"
 #include "chardev/char-fe.h"
 #include "system/runstate.h"
-#include "hw/riscv/numa.h"
+#include "hw/riscv/aia.h"
 
 #define PR_RISCV_V_SET_CONTROL            69
 #define PR_RISCV_V_VSTATE_CTRL_ON          2
@@ -1930,7 +1930,8 @@ void kvm_arch_accel_class_init(ObjectClass *oc)
                                     "auto");
 }
 
-void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
+void kvm_riscv_aia_create(const RISCVAIASocket *sockets,
+                          uint32_t socket_count, uint64_t group_shift,
                           uint64_t aia_irq_num, uint64_t aia_msi_num,
                           uint64_t aplic_base, uint64_t imsic_base,
                           uint64_t guest_num)
@@ -1938,7 +1939,6 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
     int ret, i;
     int aia_fd = -1;
     uint64_t default_aia_mode;
-    uint64_t socket_count = riscv_socket_count(machine);
     uint64_t max_hart_per_socket = 0;
     uint64_t socket, base_hart, hart_count, socket_imsic_base, imsic_addr;
     uint64_t socket_bits, hart_bits, guest_bits;
@@ -2039,8 +2039,8 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
 
     for (socket = 0; socket < socket_count; socket++) {
         socket_imsic_base = imsic_base + socket * (1U << group_shift);
-        hart_count = riscv_socket_hart_count(machine, socket);
-        base_hart = riscv_socket_first_hartid(machine, socket);
+        hart_count = sockets[socket].num_harts;
+        base_hart = sockets[socket].hartid_base;
 
         if (max_hart_per_socket < hart_count) {
             max_hart_per_socket = hart_count;
target/riscv/kvm/kvm-stub.c +2 -1
index 64e39c96d893..f92916162804 100644
@@ -9,7 +9,8 @@
 #include "qemu/osdep.h"
 #include "target/riscv/kvm/kvm_riscv.h"
 
-void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
+void kvm_riscv_aia_create(const RISCVAIASocket *sockets,
+                          uint32_t socket_count, uint64_t group_shift,
                           uint64_t aia_irq_num, uint64_t aia_msi_num,
                           uint64_t aplic_base, uint64_t imsic_base,
                           uint64_t guest_num)
Signature · 1 line
2.55.0
#4 lore raw

[PULL 7/8] hw/riscv/server_platform_ref: Fix mtimer frequency

In reply to [email protected]

From: Sunil V L <[email protected]>

The RISC-V server reference platform requires a 1 GHz timer frequency. Although the timer frequency is advertised as 1 GHz in the device tree, the mtimer device is still created with a 10 MHz frequency. This mismatch causes the OS to boot very slowly.

Use the correct 1 GHz frequency when creating the mtimer device.

Fixes c2fa4320803b ("hw/riscv: server platform reference machine")

Message-ID: <[email protected]>

---
 hw/riscv/server_platform_ref.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/riscv/server_platform_ref.c +1 -1
index 3526c80d7947..22b3149ee8e8 100644
@@ -561,7 +561,7 @@ static void rvserver_ref_machine_init(MachineState *machine)
                 base_hartid, hart_count,
                 RISCV_ACLINT_DEFAULT_MTIMECMP,
                 RISCV_ACLINT_DEFAULT_MTIME,
-                RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, true);
+                RVSERVER_ACLINT_TIMEBASE_FREQ, true);
 
         /* Per-socket interrupt controller */
         s->irqchip[i] = riscv_create_aia(system_memory, true, s->aia_guests,
Signature · 1 line
2.55.0
#5 lore raw

[PULL 5/8] hw/riscv: Select SSI for IBEX

In reply to [email protected]

From: Tan Chi <[email protected]>

The Ibex SPI host controller uses the SSI bus infrastructure, but CONFIG_IBEX does not select CONFIG_SSI.

This causes undefined references to SSI functions, including ssi_transfer(), when building a minimal RV32 OpenTitan target without default devices.

Select SSI from IBEX to ensure that the required bus implementation is built.

Message-ID: <[email protected]>

---
 hw/riscv/Kconfig | 1 +
 1 file changed, 1 insertion(+)
hw/riscv/Kconfig +1 -0
index f3bf8d159cba..807fcaaf280e 100644
@@ -6,6 +6,7 @@ config RISCV_NUMA
 
 config IBEX
     bool
+    select SSI
 
 config RISCV_DEVICE_COMMON
     bool
Signature · 1 line
2.55.0
#6 lore raw

[PULL 8/8] target/riscv/tcg: clear itrigger_enabled during trigger_reset_hold()

In reply to [email protected]

From: Daniel Henrique Barboza <[email protected]>

We're leaving env->itrigger_enabled untouched during reset() while at the same time resetting triggers to AD_MATCH (type 2).

So, in case we reset the CPU during an itrigger session, translation code will enter itrigger_match helper every time (via ctx->itrigger), and the helper will do nothing since there's no type 3 triggers set. And we'll keep doing that until something else clears env->itrigger_enabled. This is a niche case that it's a bit hard to hit but it will cost a bit of performance for no good reason.

Found while reviewing an itrigger related patch.

Fixes 577f02869488 ("target/riscv: Add itrigger_enabled field to CPURISCVState").

Message-ID: <[email protected]>

---
 target/riscv/tcg/debug.c | 1 +
 1 file changed, 1 insertion(+)
target/riscv/tcg/debug.c +1 -0
index 8b58cbd07ab7..988bc815d79c 100644
@@ -1213,4 +1213,5 @@ void riscv_trigger_reset_hold(CPURISCVState *env)
     }
 
     env->mcontext = 0;
+    env->itrigger_enabled = false;
 }
Signature · 1 line
2.55.0
#7 lore raw

[PULL 3/8] hw/riscv: Move platform bus FDT creation to machine code

In reply to [email protected]

From: Tan Chi <[email protected]>

riscv_create_fdt_socket_aplic() contains a direct reference to platform_bus_add_all_fdt_nodes(), even though fdt-common.c is built unconditionally and CONFIG_PLATFORM_BUS may be disabled.

This causes an undefined reference in minimal RISC-V builds without platform bus support.

Move platform bus FDT creation to the virt and server reference machines, which both select CONFIG_PLATFORM_BUS. Export a helper to obtain the APLIC node name and remove the platform bus fields from APLICFdtProps.

This removes the dependency from the common APLIC FDT helper while preserving the platform bus interrupt-parent configuration.

Message-ID: <[email protected]>

---
 include/hw/riscv/fdt-common.h  |  3 +--
 hw/riscv/fdt-common.c          | 13 ++-----------
 hw/riscv/server_platform_ref.c |  9 +++++++--
 hw/riscv/virt.c                | 11 +++++++++--
 4 files changed, 19 insertions(+), 17 deletions(-)
include/hw/riscv/fdt-common.h +1 -2
index eb9db8278d09..b3b14ada0aca 100644
@@ -54,8 +54,6 @@ typedef struct IMSICFdtProps {
 typedef struct APLICFdtProps {
     const MemMapEntry *aplic_m;
     const MemMapEntry *aplic_s;
-    const MemMapEntry *platform_bus;
-    int platform_bus_irq;
     int socket;
     int num_harts;
     bool numa_enabled;
@@ -129,6 +127,7 @@ void riscv_create_fdt_socket_aplic(void *fdt, APLICFdtProps *props,
 void riscv_create_fdt_socket_aclint(void *fdt, ACLINTFdtProps *props,
                                     uint32_t *intc_phandles);
 /* Caller must free the returned string.  */
+char *riscv_fdt_get_aplic_nodename(hwaddr addr);
 char *riscv_fdt_get_uart_nodename(hwaddr addr);
 void riscv_create_fdt_uart(void *fdt, const MemMapEntry *uart_mem,
                            int uart_irq, int aia_type,
hw/riscv/fdt-common.c +2 -11
index ce2dcb43b4fb..e90502b1bc65 100644
@@ -11,7 +11,6 @@
 #include "qemu/error-report.h"
 #include "system/device_tree.h"
 #include "hw/core/boards.h"
-#include "hw/core/sysbus-fdt.h"
 #include "hw/riscv/fdt-common.h"
 #include "target/riscv/cpu_bits.h"
 #include "hw/riscv/riscv-iommu-bits.h"
@@ -599,7 +598,7 @@ void riscv_create_fdt_imsic(void *fdt, IMSICFdtProps *props,
 }
 
 /* Caller must free string after use */
-static char *fdt_get_aplic_nodename(hwaddr aplic_addr)
+char *riscv_fdt_get_aplic_nodename(hwaddr aplic_addr)
 {
     return g_strdup_printf("/soc/interrupt-controller@%"HWADDR_PRIx,
                            aplic_addr);
@@ -613,7 +612,7 @@ static void create_fdt_one_aplic(void *fdt, APLICFdtProps *props,
                                  uint32_t aplic_child_phandle,
                                  bool m_mode)
 {
-    g_autofree char *aplic_name = fdt_get_aplic_nodename(aplic_addr);
+    g_autofree char *aplic_name = riscv_fdt_get_aplic_nodename(aplic_addr);
     g_autofree uint32_t *aplic_cells = g_new0(uint32_t, props->num_harts * 2);
     static const char * const aplic_compat[2] = {
         "qemu,aplic", "riscv,aplic"
@@ -695,14 +694,6 @@ void riscv_create_fdt_socket_aplic(void *fdt, APLICFdtProps *props,
                          aplic_s_phandle, 0,
                          false);
 
-    if (!props->socket && props->platform_bus_irq) {
-        g_autofree char *aplic_name = fdt_get_aplic_nodename(aplic_addr);
-        platform_bus_add_all_fdt_nodes(fdt, aplic_name,
-                                       props->platform_bus->base,
-                                       props->platform_bus->size,
-                                       props->platform_bus_irq);
-    }
-
     aplic_phandles[props->socket] = aplic_s_phandle;
 }
 
hw/riscv/server_platform_ref.c +7 -2
index 5f485b1c79cb..3526c80d7947 100644
@@ -192,6 +192,7 @@ static void create_fdt_sockets(RISCVServerRefMachineState *s,
 {
     int socket, phandle_pos;
     MachineState *ms = MACHINE(s);
+    g_autofree char *aplic_name = NULL;
     uint32_t msi_m_phandle = 0, msi_s_phandle = 0;
     uint32_t xplic_phandles[MAX_NODES];
     g_autofree uint32_t *intc_phandles = NULL;
@@ -251,8 +252,6 @@ static void create_fdt_sockets(RISCVServerRefMachineState *s,
     aplic_fdt_props.aplic_m = !kvm_enabled()
                               ? &memmap[RVSERVER_APLIC_M] : NULL;
     aplic_fdt_props.aplic_s = &memmap[RVSERVER_APLIC_S];
-    aplic_fdt_props.platform_bus = &memmap[RVSERVER_PLATFORM_BUS];
-    aplic_fdt_props.platform_bus_irq = RVSERVER_PLATFORM_BUS_IRQ;
     aplic_fdt_props.num_harts = ms->smp.cpus;
     aplic_fdt_props.numa_enabled = numa_enabled;
     aplic_fdt_props.irqchip_num_sources = RVSERVER_IRQCHIP_NUM_SOURCES;
@@ -270,6 +269,12 @@ static void create_fdt_sockets(RISCVServerRefMachineState *s,
                                       xplic_phandles);
     }
 
+    aplic_name = riscv_fdt_get_aplic_nodename(memmap[RVSERVER_APLIC_S].base);
+    platform_bus_add_all_fdt_nodes(ms->fdt, aplic_name,
+                                   memmap[RVSERVER_PLATFORM_BUS].base,
+                                   memmap[RVSERVER_PLATFORM_BUS].size,
+                                   RVSERVER_PLATFORM_BUS_IRQ);
+
     for (socket = 0; socket < socket_count; socket++) {
         if (socket == 0) {
             *irq_mmio_phandle = xplic_phandles[socket];
hw/riscv/virt.c +9 -2
index 8bc5a7b0728c..ffd6e8868f70 100644
@@ -296,8 +296,6 @@ static void create_fdt_sockets(RISCVVirtState *s,
     if (s->aia_type != VIRT_AIA_TYPE_NONE) {
         aplic_props.aplic_m = !kvm_enabled() ? &s->memmap[VIRT_APLIC_M] : NULL;
         aplic_props.aplic_s = &s->memmap[VIRT_APLIC_S];
-        aplic_props.platform_bus = &s->memmap[VIRT_PLATFORM_BUS];
-        aplic_props.platform_bus_irq = VIRT_PLATFORM_BUS_IRQ;
         aplic_props.socket = 0;
         aplic_props.num_harts = ms->smp.cpus;
         aplic_props.numa_enabled = numa_enabled;
@@ -353,6 +351,15 @@ static void create_fdt_sockets(RISCVVirtState *s,
         }
     }
 
+    if (s->aia_type != VIRT_AIA_TYPE_NONE) {
+        g_autofree char *aplic_name =
+            riscv_fdt_get_aplic_nodename(s->memmap[VIRT_APLIC_S].base);
+        platform_bus_add_all_fdt_nodes(ms->fdt, aplic_name,
+                                       s->memmap[VIRT_PLATFORM_BUS].base,
+                                       s->memmap[VIRT_PLATFORM_BUS].size,
+                                       VIRT_PLATFORM_BUS_IRQ);
+    }
+
     riscv_socket_fdt_write_distance_matrix(ms);
 }
 
Signature · 1 line
2.55.0
#8 lore raw

[PULL 6/8] hw/intc/riscv_aplic: Check config value bounds in realize

In reply to [email protected]

From: Peter Maydell <[email protected]>

The riscv aplic interrupt controller has various configurable properties for things like num-harts and num-irqs, which have architectural upper limits.

Currently these are checked in riscv_aplic_create(), by assert(). QOM devices should check this kind of thing in their realize method, and fail realize for out of range values (which in this case will cause riscv_aplic_create() to make QEMU exit with an error, since it uses &error_fatal). This isn't a problem currently as no SoC creates and configures the TYPE_RISCV_APLIC device itself, but it avoids one for the future.

Move the checks to the realize method. This requires slight adjustments in some cases because:
* property num-irqs is set to num_sources + 1
* property iprio-mask is set to (1U << iprio_bits) - 1

Message-ID: <[email protected]>

---
 hw/intc/riscv_aplic.c | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)
hw/intc/riscv_aplic.c +26 -6
index 03a0852b8b88..b29a22a455a1 100644
@@ -954,6 +954,32 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp)
     uint32_t i;
     RISCVAPLICState *aplic = RISCV_APLIC(dev);
 
+    if (aplic->num_harts >= APLIC_MAX_IDC) {
+        error_setg(errp, "num-harts must be less than %d", (int)APLIC_MAX_IDC);
+        return;
+    }
+    if ((APLIC_IDC_BASE + (aplic->num_harts * APLIC_IDC_SIZE)) >
+        aplic->aperture_size) {
+        error_setg(errp, "aperture-size 0x%x too small for num-harts %d",
+                   aplic->aperture_size, aplic->num_harts);
+        return;
+    }
+    if (aplic->num_irqs > APLIC_MAX_SOURCE) {
+        error_setg(errp, "num-irqs must be less than or equal to %d",
+                   APLIC_MAX_SOURCE);
+        return;
+    }
+    if (!is_power_of_2(aplic->iprio_mask + 1)) {
+        error_setg(errp, "iprio-mask must have all lower bits set");
+        return;
+    }
+    if (aplic->iprio_mask < ((1U << APLIC_MIN_IPRIO_BITS) - 1) ||
+        aplic->iprio_mask > ((1U << APLIC_MAX_IPRIO_BITS) - 1)) {
+        error_setg(errp, "iprio-mask must specify between %d and %d bits of "
+                   "priority", APLIC_MIN_IPRIO_BITS, APLIC_MAX_IPRIO_BITS);
+        return;
+    }
+
     if (riscv_use_emulated_aplic(aplic->msimode)) {
         /* Create output IRQ lines for non-MSI mode */
         if (!aplic->msimode) {
@@ -1119,12 +1145,6 @@ DeviceState *riscv_aplic_create(MemoryRegion *container,
     DeviceState *dev = qdev_new(TYPE_RISCV_APLIC);
     uint32_t i;
 
-    assert(num_harts < APLIC_MAX_IDC);
-    assert((APLIC_IDC_BASE + (num_harts * APLIC_IDC_SIZE)) <= size);
-    assert(num_sources < APLIC_MAX_SOURCE);
-    assert(APLIC_MIN_IPRIO_BITS <= iprio_bits);
-    assert(iprio_bits <= APLIC_MAX_IPRIO_BITS);
-
     qdev_prop_set_uint32(dev, "aperture-size", size);
     qdev_prop_set_uint32(dev, "hartid-base", hartid_base);
     qdev_prop_set_uint32(dev, "num-harts", num_harts);
Signature · 1 line
2.55.0
#9 lore raw
In reply to [email protected]
Quoted 14 lines · On 11/14/26 16:48, [email protected] wrote:

From: Alistair Francis<[email protected]>

The following changes since commit e9fa1f66f0d47c74b6766e1b8b87ad7c2a9394d5:

   Merge tag 'pull-nbd-2026-11-10-v2' ofhttps://gitlab.com/ebblake/qemu into staging (2026-11-13 08:44:16 -0700)

are available in the Git repository at:

   https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20261115

for you to fetch changes up to 57bae3bdbf69777c8bf32f50a85c36283bbeb673:

   target/riscv/tcg: clear itrigger_enabled during trigger_reset_hold() (2026-11-15 10:41:59 +1000)
Quoted 7 lines

----------------------------------------------------------------
RISC-V PR for 11.2

* Fix minimal RISC-V system builds
* Check RISC-V APLIC config value bounds in realize
* Fix Server Platform Reference mtimer frequency
* Clear itrigger_enabled during trigger_reset_hold

Applied, thanks.

r~