diff mbox series

[v2,8/8] hw/intc/imsic: prevent to use IMSIC when host doesn't support AIA extension

Message ID 20250224082417.31382-9-yongxuan.wang@sifive.com (mailing list archive)
State New
Headers show
Series riscv: AIA: kernel-irqchip=off support | expand

Commit Message

Yong-Xuan Wang Feb. 24, 2025, 8:24 a.m. UTC
Currently QEMU will continue to create the IMSIC devices and enable the
AIA extension for guest OS when the host kernel doesn't support the AIA
extension. This will cause an illegal instruction exception when the
guest OS access the AIA CSRs. Add additional checks to ensure the
guest OS only uses the IMSIC devices when the host kernel supports
the AIA extension.

Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
---
 hw/intc/riscv_imsic.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/hw/intc/riscv_imsic.c b/hw/intc/riscv_imsic.c
index dc8162c0a7c9..8c64f2c21274 100644
--- a/hw/intc/riscv_imsic.c
+++ b/hw/intc/riscv_imsic.c
@@ -375,12 +375,21 @@  static void riscv_imsic_realize(DeviceState *dev, Error **errp)
 
     /* Force select AIA feature and setup CSR read-modify-write callback */
     if (env) {
-        if (!imsic->mmode) {
-            rcpu->cfg.ext_ssaia = true;
-            riscv_cpu_set_geilen(env, imsic->num_pages - 1);
+        if (kvm_enabled()) {
+            if (!rcpu->cfg.ext_ssaia) {
+                error_report("Host machine doesn't support AIA extension. "
+                             "Do not use IMSIC as interrupt controller.");
+                exit(1);
+            }
         } else {
-            rcpu->cfg.ext_smaia = true;
+            if (!imsic->mmode) {
+                rcpu->cfg.ext_ssaia = true;
+                riscv_cpu_set_geilen(env, imsic->num_pages - 1);
+            } else {
+                rcpu->cfg.ext_smaia = true;
+            }
         }
+
         riscv_cpu_set_aia_ireg_rmw_fn(env, (imsic->mmode) ? PRV_M : PRV_S,
                                       riscv_imsic_rmw, imsic);
     }