@samitouri / QOSamiQemu / commits / d6c5855c76

target/riscv/insn_trans/trans_rvzicbo.c.inc: save opcode before helpers

All helpers from this file can trigger ILLEGAL_INSN exceptions via check_zicbo_envcfg() directly, bypassing the usual exception code from translate.c. If we don't save the opcode before each helper, riscv_raise_exception() is triggered and env->bins won't be unwind during cpu_loop_exit_restore() (code path cpu_restore_state -> cpu_restore_state_from_tb() -> restore_state_to_opc()). And finally, in riscv_cpu_do_interrupt(), we will set (m)tval = 0 when we can, instead, set it to the cbo opcode that generated the exception. Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3380 Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Message-ID: <20260520214704.1943652-1-daniel.barboza@oss.qualcomm.com> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

Daniel Henrique Barboza committed May 20, 2026 at 18:47 UTC d6c5855c76b2ea849adb0fb91379dbb1e5a94dca
1 file changed +8
target/riscv/insn_trans/trans_rvzicbo.c.inc
+8
@@ -33,6 +33,8 @@ static bool trans_cbo_clean(DisasContext *ctx, arg_cbo_clean *a)
33 REQUIRE_ZICBOM(ctx);
34 TCGv src = get_address(ctx, a->rs1, 0);
35
36 + /* The helper may raise ILLEGAL_INSN -- record binv for unwind. */
37 + decode_save_opc(ctx, 0);
38 gen_helper_cbo_clean_flush(tcg_env, src);
39 return true;
40 }
@@ -42,6 +44,8 @@ static bool trans_cbo_flush(DisasContext *ctx, arg_cbo_flush *a)
44 REQUIRE_ZICBOM(ctx);
45 TCGv src = get_address(ctx, a->rs1, 0);
46
47 + /* The helper may raise ILLEGAL_INSN -- record binv for unwind. */
48 + decode_save_opc(ctx, 0);
49 gen_helper_cbo_clean_flush(tcg_env, src);
50 return true;
51 }
@@ -51,6 +55,8 @@ static bool trans_cbo_inval(DisasContext *ctx, arg_cbo_inval *a)
55 REQUIRE_ZICBOM(ctx);
56 TCGv src = get_address(ctx, a->rs1, 0);
57
58 + /* The helper may raise ILLEGAL_INSN -- record binv for unwind. */
59 + decode_save_opc(ctx, 0);
60 gen_helper_cbo_inval(tcg_env, src);
61 return true;
62 }
@@ -60,6 +66,8 @@ static bool trans_cbo_zero(DisasContext *ctx, arg_cbo_zero *a)
66 REQUIRE_ZICBOZ(ctx);
67 TCGv src = get_address(ctx, a->rs1, 0);
68
69 + /* The helper may raise ILLEGAL_INSN -- record binv for unwind. */
70 + decode_save_opc(ctx, 0);
71 gen_helper_cbo_zero(tcg_env, src);
72 return true;
73 }