Skip to contentSkip to conversation

hw/loongarch/virt: Don't abort on access to unimplemented IOCSR

PATCH Superseded Yao Zi 3 participants 3 messages Dec 21, 2025 – Dec 22, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yao Zi

author
#0 lore raw

PATCH 1/1 hw/loongarch/virt: Don't abort on access to unimplemented IOCSR

Reading/writing unimplemented IOCSR on real LoongArch hardware doesn't trigger any exceptions, instead, reading always results in zero and writing is simply ignored.

Real-world applications, like memtest86plus, depend on the behavior to run. However, since commit f2e61edb2946 ("hw/loongarch/virt: Use MemTxAttrs interface for misc ops") which adds a call to g_assert_not_reached() in the path of handling unimplemented IOCSRs, QEMU would abort in the case.

Replace the assertion with qemu_log_mask(LOG_UNIMP, ...), so these applications could run. It's still possible to examine unimplemented IOCSR access through "-d unimp" command line arguments.

Fixes f2e61edb2946 ("hw/loongarch/virt: Use MemTxAttrs interface for misc ops")
---
 hw/loongarch/virt.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
hw/loongarch/virt.c +7 -2
index 49434ad1828b..8d7da5fac550 100644
@@ -46,6 +46,7 @@
 #include "hw/block/flash.h"
 #include "hw/virtio/virtio-iommu.h"
 #include "qemu/error-report.h"
+#include "qemu/log.h"
 #include "kvm/kvm_loongarch.h"
 
 static void virt_get_dmsi(Object *obj, Visitor *v, const char *name,
@@ -622,7 +623,9 @@ static MemTxResult virt_iocsr_misc_write(void *opaque, hwaddr addr,
                           features, attrs, NULL);
         break;
     default:
-        g_assert_not_reached();
+        qemu_log_mask(LOG_UNIMP, "%s: Unimplemented IOCSR 0x%" HWADDR_PRIx "\n",
+                      __func__, addr);
+        break;
     }
 
     return MEMTX_OK;
@@ -680,7 +683,9 @@ static MemTxResult virt_iocsr_misc_read(void *opaque, hwaddr addr,
         }
         break;
     default:
-        g_assert_not_reached();
+        qemu_log_mask(LOG_UNIMP, "%s: Unimplemented IOCSR 0x%" HWADDR_PRIx "\n",
+                      __func__, addr);
+        break;
     }
 
     *data = ret;
Signature · 1 line
2.51.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Yao Zi

Reading/writing unimplemented IOCSR on real LoongArch hardware doesn't trigger any exceptions, instead, reading always results in zero and writing is simply ignored.

Real-world applications, like memtest86plus, depend on the behavior to run. However, since commit f2e61edb2946 ("hw/loongarch/virt: Use MemTxAttrs interface for misc ops") which adds a call to g_assert_not_reached() in the path of handling unimplemented IOCSRs, QEMU would abort in the case.

Replace the assertion with qemu_log_mask(LOG_UNIMP, ...), so these applications could run. It's still possible to examine unimplemented IOCSR access through "-d unimp" command line arguments.

Quoted 5 lines
Fixes f2e61edb2946 ("hw/loongarch/virt: Use MemTxAttrs interface for misc ops")
---
  hw/loongarch/virt.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
#2 lore raw
In reply to Yao Zi
Quoted 3 lines · Yao Zi

Reading/writing unimplemented IOCSR on real LoongArch hardware doesn't trigger any exceptions, instead, reading always results in zero and writing is simply ignored.

From my memories, I have communicated with HW guys about IOCSR. They said that IOCSR is different with CPUCFG, the undocumented IOCSR registers may be used by UEFI BIOS or other firmwares. So we cannot suppose reading always results in zero and writing is simply ignored.

However g_assert_not_reached() is actually too serious here, QEMU should not crash anyway.

Quoted 30 lines

Real-world applications, like memtest86plus, depend on the behavior to run. However, since commit f2e61edb2946 ("hw/loongarch/virt: Use MemTxAttrs interface for misc ops") which adds a call to g_assert_not_reached() in the path of handling unimplemented IOCSRs, QEMU would abort in the case.

Replace the assertion with qemu_log_mask(LOG_UNIMP, ...), so these applications could run. It's still possible to examine unimplemented IOCSR access through "-d unimp" command line arguments.

Fixes f2e61edb2946 ("hw/loongarch/virt: Use MemTxAttrs interface for misc ops")
---
  hw/loongarch/virt.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
hw/loongarch/virt.c +1 -0
index 49434ad1828b..8d7da5fac550 100644
@@ -46,6 +46,7 @@
  #include "hw/block/flash.h"
  #include "hw/virtio/virtio-iommu.h"
  #include "qemu/error-report.h"
+#include "qemu/log.h"
  #include "kvm/kvm_loongarch.h"
 
  static void virt_get_dmsi(Object *obj, Visitor *v, const char *name,

hw/loongarch/virt.c static MemTxResult virt_iocsr_misc_write(void *opaque, hwaddr addr, · line 629

Quoted 8 lines
hw/loongarch/virt.c +3 -1
@@ -622,7 +623,9 @@ static MemTxResult virt_iocsr_misc_write(void *opaque, hwaddr addr,
                            features, attrs, NULL);
          break;
      default:
-        g_assert_not_reached();
+        qemu_log_mask(LOG_UNIMP, "%s: Unimplemented IOCSR 0x%" HWADDR_PRIx "\n",
+                      __func__, addr);
+        break;
      }

IOCSR address VERSION_REG/VENDOR_REG/CPUNAME_REG is read-only rather than unimplemented, the others are unimplemented.

The others look good to me.

Regards
Bibo Mao

hw/loongarch/virt.c static MemTxResult virt_iocsr_misc_read(void *opaque, hwaddr addr, · line 688

Quoted 10 lines
hw/loongarch/virt.c +3 -1
      return MEMTX_OK;
@@ -680,7 +683,9 @@ static MemTxResult virt_iocsr_misc_read(void *opaque, hwaddr addr,
          }
          break;
      default:
-        g_assert_not_reached();
+        qemu_log_mask(LOG_UNIMP, "%s: Unimplemented IOCSR 0x%" HWADDR_PRIx "\n",
+                      __func__, addr);
+        break;

Replacing g_assert_not_reached() with with qemu_log_mask() is ok for me.

Quoted 4 lines
hw/loongarch/virt.c +0 -0
      }
 
      *data = ret;