On 10/23/2026 10:12 AM, Wang Yechao wrote:
Commit d45b9bc65515 ("target/riscv: move TCG only files to tcg subdir")
moved the TCG-only files into the tcg/ subdirectory, so env->tdataX is
now only allocated and valid when TCG is enabled.

However, cfg.debug is always true in riscv_cpu_properties, so
debug_needed() unconditionally returned true and the debug vmstate
subsection was always considered needed. On --disable-tcg builds the
corresponding fields are uninitialized, and attempting to save them
triggers an assertion failure in vmstate_save_state_v:

   qemu-system-riscv64: ../migration/vmstate.c:737:
   vmstate_save_state_v: Assertion `first_elem || !n_elems || !size' failed.

Fix this by making debug_needed() also require tcg_enabled(), so the
debug subsection is only saved when the TCG-only state actually exists.

Fixes: d45b9bc65515 ("target/riscv: move TCG only files to tcg subdir")
Signed-off-by: Wang Yechao <[email protected]>
Reviewed-by: Nutty Liu <[email protected]>

Thanks,
Nutty
---
  target/riscv/machine.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/riscv/machine.c b/target/riscv/machine.c
index 0de06e9588..c5f0261ba7 100644
--- a/target/riscv/machine.c
+++ b/target/riscv/machine.c
@@ -324,7 +324,7 @@ static bool debug_needed(void *opaque)
  {
      RISCVCPU *cpu = opaque;
- return cpu->cfg.debug || cpu->cfg.ext_sdtrig;
+    return tcg_enabled() && (cpu->cfg.debug || cpu->cfg.ext_sdtrig);
  }
static bool sdext_needed(void *opaque)

Reply via email to