From: Joel Stanley <[email protected]>

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.

Signed-off-by: Joel Stanley <[email protected]>
Acked-by: Alistair Francis <[email protected]>
Reviewed-by: Portia Stephens <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
---
 hw/riscv/aia.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/hw/riscv/aia.c b/hw/riscv/aia.c
index c33a3b32bd..c1a5982856 100644
--- a/hw/riscv/aia.c
+++ b/hw/riscv/aia.c
@@ -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 */
-- 
2.55.0


Reply via email to