Skip to contentSkip to conversation

hw/riscv: Make s-mode IMSIC stride explicit

PATCH Applied Joel Stanley 3 participants 8 messages Aug 24 – Aug 25 RISC-V

lore
Share & tools
lore
#0 lore raw

cover hw/riscv: Make s-mode IMSIC stride explicit

This adds s_imsic_stride to riscv_create_aia so machines can separate the s-mode IMSIC layout from the guest count. They are related but the layout isn't necessarily defined by the guest count. Doing this means we can fix a bug that was in the Atlantis machine that I wrote.

Joel Stanley (2):
hw/riscv: Make s-mode IMSIC stride explicit
hw/riscv/aia: Check for invalid IMSIC configs

 hw/riscv/aia.h         |  1 +
 hw/riscv/aia.c         |  9 ++++++---
 hw/riscv/tt_atlantis.c | 19 +++++++++++--------
 hw/riscv/virt.c        |  2 ++
 4 files changed, 20 insertions(+), 11 deletions(-)
Signature · 1 line
2.47.3
#1 lore raw

PATCH 1/2 hw/riscv: Make s-mode IMSIC stride explicit

Existing machines tightly coupled s-mode IMSIC stride with the guest bits value. There need to be enough bits to describe the guest in GEILEN, but that's a minimum bound and machines may choose to use a larger stride. This change decouples the two and updates Atlantis and Virt to use the new API.

AIA guest count used by the Atlantis machine was not correct. It looks like a placeholder value was chosen in order to size the stride to 0x40000, but this gives the wrong guest count. From the (currently internal) docs, the guest count is 5:

Quoted 1 line

|NUM_GEILEN|5 (0 - 64)|Number of supported guest index from the S-mode interrupt domain|

Add that value to a define, and add a separate define for the stride, to reduce the opportunity for future confusion.

Fixes 7778f4b27bb1 ("hw/riscv: Add Tenstorrent Atlantis machine")
---
 hw/riscv/aia.h         |  1 +
 hw/riscv/aia.c         |  5 ++---
 hw/riscv/tt_atlantis.c | 19 +++++++++++--------
 hw/riscv/virt.c        |  2 ++
 4 files changed, 16 insertions(+), 11 deletions(-)
hw/riscv/aia.h +1 -0
index 565f91accc09..3b6d7f962506 100644
@@ -15,6 +15,7 @@ uint32_t imsic_num_bits(uint32_t count);
 
 DeviceState *riscv_create_aia(bool msimode, int aia_guests,
                              uint32_t m_imsic_stride,
+                             uint32_t s_imsic_stride,
                              uint16_t num_sources,
                              const MemMapEntry *aplic_m,
                              const MemMapEntry *aplic_s,
hw/riscv/aia.c +2 -3
index ed8916002945..c33a3b32bd45 100644
@@ -26,6 +26,7 @@ uint32_t imsic_num_bits(uint32_t count)
 
 DeviceState *riscv_create_aia(bool msimode, int aia_guests,
                              uint32_t m_imsic_stride,
+                             uint32_t s_imsic_stride,
                              uint16_t num_sources,
                              const MemMapEntry *aplic_m,
                              const MemMapEntry *aplic_s,
@@ -36,7 +37,6 @@ DeviceState *riscv_create_aia(bool msimode, int aia_guests,
 {
     int i;
     hwaddr addr = 0;
-    uint32_t guest_bits;
     DeviceState *aplic_s_dev = NULL;
     DeviceState *aplic_m_dev = NULL;
 
@@ -55,10 +55,9 @@ DeviceState *riscv_create_aia(bool msimode, int aia_guests,
         }
 
         /* Per-socket S-level IMSICs */
-        guest_bits = imsic_num_bits(aia_guests + 1);
         addr = imsic_s->base + socket * (1U << IMSIC_MMIO_GROUP_MIN_SHIFT);
         for (i = 0; i < hart_count; i++) {
-            riscv_imsic_create(addr + i * IMSIC_HART_SIZE(guest_bits),
+            riscv_imsic_create(addr + i * s_imsic_stride,
                                base_hartid + i, false, 1 + aia_guests,
                                num_msis);
         }
hw/riscv/tt_atlantis.c +11 -8
index d808bcc11c34..88c375684412 100644
@@ -37,8 +37,12 @@
 #define TT_IRQCHIP_NUM_MSIS       255
 #define TT_IRQCHIP_NUM_SOURCES    128
 #define TT_IRQCHIP_NUM_PRIO_BITS  3
-#define TT_IRQCHIP_GUESTS         63 /* aia_guests, gives guest_index_bits=6 */
-#define TT_IRQCHIP_MIMSIC_STRIDE  0x40000
+#define TT_IMSIC_GUESTS           5
+#define TT_IMSIC_STRIDE           0x40000 /* Same stride for M and S */
+#define TT_IMSIC_GUEST_BITS       6
+
+/* Stride is fixed by hardware, check it's consistent with guest bits. */
+QEMU_BUILD_BUG_ON(TT_IMSIC_STRIDE != (0x1000 << TT_IMSIC_GUEST_BITS));
 
 #define TT_ACLINT_MTIME_SIZE    0x8050
 #define TT_ACLINT_MTIME         0x0
@@ -231,18 +235,16 @@ static void create_fdt_cpu(TTAtlantisState *s, const MemMapEntry *memmap,
 
     create_fdt_aclint(s, intc_phandles);
 
-    uint32_t imsic_guest_bits = imsic_num_bits(TT_IRQCHIP_GUESTS + 1);
-
     /* M-level IMSIC node */
     uint32_t msi_m_phandle = next_phandle();
     create_fdt_one_imsic(fdt, &s->memmap[TT_ATL_MIMSIC], ms->smp.cpus,
                          intc_phandles, msi_m_phandle,
-                         IRQ_M_EXT, imsic_guest_bits);
+                         IRQ_M_EXT, TT_IMSIC_GUEST_BITS);
 
     /* S-level IMSIC node */
     create_fdt_one_imsic(fdt, &s->memmap[TT_ATL_SIMSIC], ms->smp.cpus,
                          intc_phandles, imsic_s_phandle,
-                         IRQ_S_EXT, imsic_guest_bits);
+                         IRQ_S_EXT, TT_IMSIC_GUEST_BITS);
 
     uint32_t aplic_m_phandle = next_phandle();
 
@@ -493,8 +495,9 @@ static void tt_atlantis_machine_init(MachineState *machine)
                             &error_abort);
     sysbus_realize(SYS_BUS_DEVICE(&s->soc), &error_fatal);
 
-    s->irqchip = riscv_create_aia(true, TT_IRQCHIP_GUESTS,
-                                  TT_IRQCHIP_MIMSIC_STRIDE,
+    s->irqchip = riscv_create_aia(true, TT_IMSIC_GUESTS,
+                                  TT_IMSIC_STRIDE,
+                                  TT_IMSIC_STRIDE,
                                   TT_IRQCHIP_NUM_SOURCES,
                                   &s->memmap[TT_ATL_MAPLIC],
                                   &s->memmap[TT_ATL_SAPLIC],
hw/riscv/virt.c +2 -0
index d58656f70d1b..42d28f4f5a02 100644
@@ -1410,9 +1410,11 @@ static void virt_machine_init(MachineState *machine)
             s->irqchip[i] = virt_create_plic(s->memmap, i,
                                              base_hartid, hart_count);
         } else {
+            int imsic_bits = imsic_num_bits(s->aia_guests + 1);
             s->irqchip[i] = riscv_create_aia(s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC,
                                              s->aia_guests,
                                              IMSIC_HART_SIZE(0),
+                                             IMSIC_HART_SIZE(imsic_bits),
                                              s->num_sources,
                                              &s->memmap[VIRT_APLIC_M],
                                              &s->memmap[VIRT_APLIC_S],
Signature · 1 line
2.47.3
Reviewed-by on v1 1/2
#2 lore raw
Quoted 126 lines · Joel Stanley

Existing machines tightly coupled s-mode IMSIC stride with the guest bits value. There need to be enough bits to describe the guest in GEILEN, but that's a minimum bound and machines may choose to use a larger stride. This change decouples the two and updates Atlantis and Virt to use the new API.

AIA guest count used by the Atlantis machine was not correct. It looks like a placeholder value was chosen in order to size the stride to 0x40000, but this gives the wrong guest count. From the (currently internal) docs, the guest count is 5:

Quoted 1 line

|NUM_GEILEN|5 (0 - 64)|Number of supported guest index from the S-mode interrupt domain|

Add that value to a define, and add a separate define for the stride, to reduce the opportunity for future confusion.

Fixes 7778f4b27bb1 ("hw/riscv: Add Tenstorrent Atlantis machine")
---
  hw/riscv/aia.h         |  1 +
  hw/riscv/aia.c         |  5 ++---
  hw/riscv/tt_atlantis.c | 19 +++++++++++--------
  hw/riscv/virt.c        |  2 ++
  4 files changed, 16 insertions(+), 11 deletions(-)
hw/riscv/aia.h +1 -0
index 565f91accc09..3b6d7f962506 100644
@@ -15,6 +15,7 @@ uint32_t imsic_num_bits(uint32_t count);
 
  DeviceState *riscv_create_aia(bool msimode, int aia_guests,
                               uint32_t m_imsic_stride,
+                             uint32_t s_imsic_stride,
                               uint16_t num_sources,
                               const MemMapEntry *aplic_m,
                               const MemMapEntry *aplic_s,
hw/riscv/aia.c +2 -3
index ed8916002945..c33a3b32bd45 100644
@@ -26,6 +26,7 @@ uint32_t imsic_num_bits(uint32_t count)
 
  DeviceState *riscv_create_aia(bool msimode, int aia_guests,
                               uint32_t m_imsic_stride,
+                             uint32_t s_imsic_stride,
                               uint16_t num_sources,
                               const MemMapEntry *aplic_m,
                               const MemMapEntry *aplic_s,
@@ -36,7 +37,6 @@ DeviceState *riscv_create_aia(bool msimode, int aia_guests,
  {
      int i;
      hwaddr addr = 0;
-    uint32_t guest_bits;
      DeviceState *aplic_s_dev = NULL;
      DeviceState *aplic_m_dev = NULL;
 
@@ -55,10 +55,9 @@ DeviceState *riscv_create_aia(bool msimode, int aia_guests,
          }
 
          /* Per-socket S-level IMSICs */
-        guest_bits = imsic_num_bits(aia_guests + 1);
          addr = imsic_s->base + socket * (1U << IMSIC_MMIO_GROUP_MIN_SHIFT);
          for (i = 0; i < hart_count; i++) {
-            riscv_imsic_create(addr + i * IMSIC_HART_SIZE(guest_bits),
+            riscv_imsic_create(addr + i * s_imsic_stride,
                                 base_hartid + i, false, 1 + aia_guests,
                                 num_msis);
          }
hw/riscv/tt_atlantis.c +11 -8
index d808bcc11c34..88c375684412 100644
@@ -37,8 +37,12 @@
  #define TT_IRQCHIP_NUM_MSIS       255
  #define TT_IRQCHIP_NUM_SOURCES    128
  #define TT_IRQCHIP_NUM_PRIO_BITS  3
-#define TT_IRQCHIP_GUESTS         63 /* aia_guests, gives guest_index_bits=6 */
-#define TT_IRQCHIP_MIMSIC_STRIDE  0x40000
+#define TT_IMSIC_GUESTS           5
+#define TT_IMSIC_STRIDE           0x40000 /* Same stride for M and S */
+#define TT_IMSIC_GUEST_BITS       6
+
+/* Stride is fixed by hardware, check it's consistent with guest bits. */
+QEMU_BUILD_BUG_ON(TT_IMSIC_STRIDE != (0x1000 << TT_IMSIC_GUEST_BITS));
 
  #define TT_ACLINT_MTIME_SIZE    0x8050
  #define TT_ACLINT_MTIME         0x0
@@ -231,18 +235,16 @@ static void create_fdt_cpu(TTAtlantisState *s, const MemMapEntry *memmap,
 
      create_fdt_aclint(s, intc_phandles);
 
-    uint32_t imsic_guest_bits = imsic_num_bits(TT_IRQCHIP_GUESTS + 1);
-
      /* M-level IMSIC node */
      uint32_t msi_m_phandle = next_phandle();
      create_fdt_one_imsic(fdt, &s->memmap[TT_ATL_MIMSIC], ms->smp.cpus,
                           intc_phandles, msi_m_phandle,
-                         IRQ_M_EXT, imsic_guest_bits);
+                         IRQ_M_EXT, TT_IMSIC_GUEST_BITS);
 
      /* S-level IMSIC node */
      create_fdt_one_imsic(fdt, &s->memmap[TT_ATL_SIMSIC], ms->smp.cpus,
                           intc_phandles, imsic_s_phandle,
-                         IRQ_S_EXT, imsic_guest_bits);
+                         IRQ_S_EXT, TT_IMSIC_GUEST_BITS);
 
      uint32_t aplic_m_phandle = next_phandle();
 
@@ -493,8 +495,9 @@ static void tt_atlantis_machine_init(MachineState *machine)
                              &error_abort);
      sysbus_realize(SYS_BUS_DEVICE(&s->soc), &error_fatal);
 
-    s->irqchip = riscv_create_aia(true, TT_IRQCHIP_GUESTS,
-                                  TT_IRQCHIP_MIMSIC_STRIDE,
+    s->irqchip = riscv_create_aia(true, TT_IMSIC_GUESTS,
+                                  TT_IMSIC_STRIDE,
+                                  TT_IMSIC_STRIDE,
                                    TT_IRQCHIP_NUM_SOURCES,
                                    &s->memmap[TT_ATL_MAPLIC],
                                    &s->memmap[TT_ATL_SAPLIC],
hw/riscv/virt.c +0 -0
index d58656f70d1b..42d28f4f5a02 100644
@@ -1410,9 +1410,11 @@ static void virt_machine_init(MachineState *machine)
              s->irqchip[i] = virt_create_plic(s->memmap, i,

hw/riscv/virt.c static void virt_machine_init(MachineState *machine) · line 1420

Quoted 10 lines
hw/riscv/virt.c +2 -0
                                               base_hartid, hart_count);
          } else {
+            int imsic_bits = imsic_num_bits(s->aia_guests + 1);
              s->irqchip[i] = riscv_create_aia(s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC,
                                               s->aia_guests,
                                               IMSIC_HART_SIZE(0),
+                                             IMSIC_HART_SIZE(imsic_bits),
                                               s->num_sources,
                                               &s->memmap[VIRT_APLIC_M],
                                               &s->memmap[VIRT_APLIC_S],
Acked-by on v1 1/2
#3 lore raw
In reply to Joel Stanley
Quoted 15 lines · Joel Stanley

Existing machines tightly coupled s-mode IMSIC stride with the guest bits value. There need to be enough bits to describe the guest in GEILEN, but that's a minimum bound and machines may choose to use a larger stride. This change decouples the two and updates Atlantis and Virt to use the new API.

AIA guest count used by the Atlantis machine was not correct. It looks
like a placeholder value was chosen in order to size the stride to 0x40000, but this gives the wrong guest count. From the (currently internal) docs, the guest count is 5:

Quoted 2 lines
Quoted 2 lines

NUM_GEILEN|5 (0 - 64)|Number of supported guest index from the S- mode interrupt domain|

Quoted 6 lines

Add that value to a define, and add a separate define for the stride, to
reduce the opportunity for future confusion.

Fixes 7778f4b27bb1 ("hw/riscv: Add Tenstorrent Atlantis machine")

Alistair

Quoted 139 lines

---
 hw/riscv/aia.h         |  1 +
 hw/riscv/aia.c         |  5 ++---
 hw/riscv/tt_atlantis.c | 19 +++++++++++--------
 hw/riscv/virt.c        |  2 ++

 4 files changed, 16 insertions(+), 11 deletions(-)
hw/riscv/aia.h +0 -0
index 565f91accc09..3b6d7f962506 100644
@@ -15,6 +15,7 @@ uint32_t imsic_num_bits(uint32_t count);


 DeviceState *riscv_create_aia(bool msimode, int aia_guests, uint32_t m_imsic_stride, +                             uint32_t s_imsic_stride, uint16_t num_sources, const MemMapEntry *aplic_m, const MemMapEntry *aplic_s,

hw/riscv/aia.c +0 -0
index ed8916002945..c33a3b32bd45 100644
@@ -26,6 +26,7 @@ uint32_t imsic_num_bits(uint32_t count)


 DeviceState *riscv_create_aia(bool msimode, int aia_guests, uint32_t m_imsic_stride, +                             uint32_t s_imsic_stride, uint16_t num_sources, const MemMapEntry *aplic_m, const MemMapEntry *aplic_s,

hw/riscv/aia.c +0 -1
@@ -36,7 +37,6 @@ DeviceState *riscv_create_aia(bool msimode, int
 aia_guests,
  {
      int i;
      hwaddr addr = 0;
-    uint32_t guest_bits;
      DeviceState *aplic_s_dev = NULL;
      DeviceState *aplic_m_dev = NULL;

hw/riscv/aia.c +0 -0
@@ -55,10 +55,9 @@ DeviceState *riscv_create_aia(bool msimode, int
 aia_guests,
          }


         /* Per-socket S-level IMSICs */
-        guest_bits = imsic_num_bits(aia_guests + 1); addr = imsic_s->base + socket * (1U << IMSIC_MMIO_GROUP_MIN_SHIFT);
         for (i = 0; i < hart_count; i++) {
-            riscv_imsic_create(addr + i * IMSIC_HART_SIZE(guest_bits),
+            riscv_imsic_create(addr + i * s_imsic_stride, base_hartid + i, false, 1 + aia_guests,
                                num_msis);
         }

hw/riscv/tt_atlantis.c +0 -1
index d808bcc11c34..88c375684412 100644
@@ -37,8 +37,12 @@
  #define TT_IRQCHIP_NUM_MSIS       255
  #define TT_IRQCHIP_NUM_SOURCES    128
  #define TT_IRQCHIP_NUM_PRIO_BITS  3
-#define TT_IRQCHIP_GUESTS         63 /* aia_guests, gives

guest_index_bits=6 */

hw/riscv/tt_atlantis.c +2 -1
-#define TT_IRQCHIP_MIMSIC_STRIDE  0x40000
+#define TT_IMSIC_GUESTS           5
+#define TT_IMSIC_STRIDE           0x40000 /* Same stride for M and S

*/

hw/riscv/tt_atlantis.c +3 -0
+#define TT_IMSIC_GUEST_BITS       6
+
+/* Stride is fixed by hardware, check it's consistent with guest

bits. */
+QEMU_BUILD_BUG_ON(TT_IMSIC_STRIDE != (0x1000 <<
TT_IMSIC_GUEST_BITS));

 #define TT_ACLINT_MTIME_SIZE    0x8050
 #define TT_ACLINT_MTIME         0x0

hw/riscv/tt_atlantis.c +0 -0
@@ -231,18 +235,16 @@ static void create_fdt_cpu(TTAtlantisState *s,
 const MemMapEntry *memmap,


     create_fdt_aclint(s, intc_phandles);

-    uint32_t imsic_guest_bits = imsic_num_bits(TT_IRQCHIP_GUESTS + 1);
-
     /* M-level IMSIC node */
     uint32_t msi_m_phandle = next_phandle(); create_fdt_one_imsic(fdt, &s->memmap[TT_ATL_MIMSIC], ms-

Quoted 1 line

smp.cpus,

                          intc_phandles, msi_m_phandle, -                         IRQ_M_EXT, imsic_guest_bits); +                         IRQ_M_EXT, TT_IMSIC_GUEST_BITS);
     /* S-level IMSIC node */ create_fdt_one_imsic(fdt, &s->memmap[TT_ATL_SIMSIC], ms-

Quoted 1 line

smp.cpus,

                          intc_phandles, imsic_s_phandle, -                         IRQ_S_EXT, imsic_guest_bits); +                         IRQ_S_EXT, TT_IMSIC_GUEST_BITS);
     uint32_t aplic_m_phandle = next_phandle();

hw/riscv/tt_atlantis.c +0 -0
@@ -493,8 +495,9 @@ static void tt_atlantis_machine_init(MachineState
 *machine)
                              &error_abort);
      sysbus_realize(SYS_BUS_DEVICE(&s->soc), &error_fatal);


-    s->irqchip = riscv_create_aia(true, TT_IRQCHIP_GUESTS, -                                  TT_IRQCHIP_MIMSIC_STRIDE, +    s->irqchip = riscv_create_aia(true, TT_IMSIC_GUESTS, +                                  TT_IMSIC_STRIDE, +                                  TT_IMSIC_STRIDE, TT_IRQCHIP_NUM_SOURCES, &s->memmap[TT_ATL_MAPLIC], &s->memmap[TT_ATL_SAPLIC],

hw/riscv/virt.c +1 -0
index d58656f70d1b..42d28f4f5a02 100644
@@ -1410,9 +1410,11 @@ static void virt_machine_init(MachineState
 *machine)
              s->irqchip[i] = virt_create_plic(s->memmap, i,
                                               base_hartid,
 hart_count);
          } else {
+            int imsic_bits = imsic_num_bits(s->aia_guests + 1);

             s->irqchip[i] = riscv_create_aia(s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC,
                                              s->aia_guests, IMSIC_HART_SIZE(0), +
IMSIC_HART_SIZE(imsic_bits),
                                              s->num_sources, &s-

Quoted 1 line

memmap[VIRT_APLIC_M],

                                              &s-

Quoted 1 line

memmap[VIRT_APLIC_S],

#4 lore raw

PATCH 2/2 hw/riscv/aia: Check for invalid IMSIC configs

In reply to Joel Stanley

Assert that the IMSIC layout will be valid before creating the devices.

aia_guests is a command line parameter but the machines that allows it to be set (currently only virt) should be passing the correct stride for a given number of guests. The assert helps catch bugs in future changes and shouldn't be triggerable by an invalid user config.

---
 hw/riscv/aia.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/riscv/aia.c +4 -0
index c33a3b32bd45..c1a5982856c5 100644
@@ -43,6 +43,10 @@ DeviceState *riscv_create_aia(bool msimode, int aia_guests,
     /* The RISC-V Advanced Interrupt Architecture, Chapter 1.2. Limits */
     g_assert(num_sources <= 1023);
 
+    /* Prevent IMSIC MMIO regions from silently overlapping */
+    g_assert(s_imsic_stride >= IMSIC_HART_SIZE(imsic_num_bits(1 + aia_guests)));
+    g_assert(m_imsic_stride >= IMSIC_HART_SIZE(0));
+
     if (msimode) {
         if (!kvm_enabled()) {
             /* Per-socket M-level IMSICs */
Signature · 1 line
2.47.3
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] hw/riscv/aia: Check for invalid IMSIC configs

Quoted 17 lines · Joel Stanley

Assert that the IMSIC layout will be valid before creating the devices.

aia_guests is a command line parameter but the machines that allows it to be set (currently only virt) should be passing the correct stride for a given number of guests. The assert helps catch bugs in future changes and shouldn't be triggerable by an invalid user config.

---
  hw/riscv/aia.c | 4 ++++
  1 file changed, 4 insertions(+)
hw/riscv/aia.c +0 -0
index c33a3b32bd45..c1a5982856c5 100644

hw/riscv/aia.c DeviceState *riscv_create_aia(bool msimode, int aia_guests, · line 52

Quoted 10 lines
hw/riscv/aia.c +4 -0
@@ -43,6 +43,10 @@ DeviceState *riscv_create_aia(bool msimode, int aia_guests,
      /* The RISC-V Advanced Interrupt Architecture, Chapter 1.2. Limits */
      g_assert(num_sources <= 1023);
 
+    /* Prevent IMSIC MMIO regions from silently overlapping */
+    g_assert(s_imsic_stride >= IMSIC_HART_SIZE(imsic_num_bits(1 + aia_guests)));
+    g_assert(m_imsic_stride >= IMSIC_HART_SIZE(0));
+
      if (msimode) {
          if (!kvm_enabled()) {
              /* Per-socket M-level IMSICs */
Acked-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] hw/riscv/aia: Check for invalid IMSIC configs

In reply to Joel Stanley
Quoted 11 lines · Joel Stanley

Assert that the IMSIC layout will be valid before creating the devices.

aia_guests is a command line parameter but the machines that allows it
to be set (currently only virt) should be passing the correct stride for
a given number of guests. The assert helps catch bugs in future changes
and shouldn't be triggerable by an invalid user config.

Quoted 1 line

Alistair

Quoted 22 lines

---
 hw/riscv/aia.c | 4 ++++

 1 file changed, 4 insertions(+)
hw/riscv/aia.c +0 -0
index c33a3b32bd45..c1a5982856c5 100644
@@ -43,6 +43,10 @@ DeviceState *riscv_create_aia(bool msimode, int
 aia_guests,
      /* The RISC-V Advanced Interrupt Architecture, Chapter 1.2.

Limits */
     g_assert(num_sources <= 1023);

+    /* Prevent IMSIC MMIO regions from silently overlapping */ +    g_assert(s_imsic_stride >= IMSIC_HART_SIZE(imsic_num_bits(1 + aia_guests)));
+    g_assert(m_imsic_stride >= IMSIC_HART_SIZE(0));
+
     if (msimode) {
         if (!kvm_enabled()) {
             /* Per-socket M-level IMSICs */

#7 lore raw
In reply to Joel Stanley
Quoted 9 lines · Joel Stanley

This adds s_imsic_stride to riscv_create_aia so machines can separate the s-mode IMSIC layout from the guest count. They are related but the
layout isn't necessarily defined by the guest count. Doing this means we can fix a bug that was in the Atlantis machine that I wrote.

Joel Stanley (2):
  hw/riscv: Make s-mode IMSIC stride explicit
  hw/riscv/aia: Check for invalid IMSIC configs

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 6 lines

 hw/riscv/aia.h         |  1 +
 hw/riscv/aia.c         |  9 ++++++---
 hw/riscv/tt_atlantis.c | 19 +++++++++++--------
 hw/riscv/virt.c        |  2 ++

 4 files changed, 20 insertions(+), 11 deletions(-)