* [PATCH 1/2] target/riscv: apply pointer masking to flh/fsh
2026-12-04 20:17 [PATCH 0/2] target/riscv: apply pointer masking to flh/fsh and Zcmp push/pop Rishab Pradeep
@ 2026-12-04 20:17 ` Rishab Pradeep
2026-12-04 20:17 ` [PATCH 2/2] target/riscv: apply pointer masking to Zcmp push/pop Rishab Pradeep
1 sibling, 0 replies; 3+ messages in thread
From: Rishab Pradeep @ 2026-12-04 20:17 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, palmer, alistair.francis, liwei1518, daniel.barboza,
zhiwei_liu, chao.liu, Rishab Pradeep, Tarun Patanjali,
Christopher Elwood
trans_flh() and trans_fsh() used the base register directly as the
effective address, without get_address(), so with pointer masking
enabled a tagged pointer was used unmasked and raised an access
fault.
Use get_address(), as flw/fsw and fld/fsd do, so the mask is applied
to every explicit memory access.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4967
Co-developed-by: Tarun Patanjali <tarun.patanjali@utexas.edu>
Signed-off-by: Tarun Patanjali <tarun.patanjali@utexas.edu>
Co-developed-by: Christopher Elwood <christopher.elwood2024@gmail.com>
Signed-off-by: Christopher Elwood <christopher.elwood2024@gmail.com>
Signed-off-by: Rishab Pradeep <rishab@rispop.dev>
---
target/riscv/tcg/insn_trans/trans_rvzfh.c.inc | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/target/riscv/tcg/insn_trans/trans_rvzfh.c.inc b/target/riscv/tcg/insn_trans/trans_rvzfh.c.inc
index 4af717ce54..229299ad2b 100644
--- a/target/riscv/tcg/insn_trans/trans_rvzfh.c.inc
+++ b/target/riscv/tcg/insn_trans/trans_rvzfh.c.inc
@@ -54,12 +54,7 @@ static bool trans_flh(DisasContext *ctx, arg_flh *a)
memop |= MO_ALIGN;
}
decode_save_opc(ctx, 0);
- t0 = get_gpr(ctx, a->rs1, EXT_NONE);
- if (a->imm) {
- TCGv temp = tcg_temp_new();
- tcg_gen_addi_tl(temp, t0, a->imm);
- t0 = temp;
- }
+ t0 = get_address(ctx, a->rs1, a->imm);
dest = cpu_fpr[a->rd];
tcg_gen_qemu_ld_i64(dest, t0, ctx->mem_idx, memop);
@@ -82,12 +77,7 @@ static bool trans_fsh(DisasContext *ctx, arg_fsh *a)
memop |= MO_ALIGN;
}
decode_save_opc(ctx, 0);
- t0 = get_gpr(ctx, a->rs1, EXT_NONE);
- if (a->imm) {
- TCGv temp = tcg_temp_new();
- tcg_gen_addi_tl(temp, t0, a->imm);
- t0 = temp;
- }
+ t0 = get_address(ctx, a->rs1, a->imm);
tcg_gen_qemu_st_i64(cpu_fpr[a->rs2], t0, ctx->mem_idx, memop);
--
2.56.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 2/2] target/riscv: apply pointer masking to Zcmp push/pop
2026-12-04 20:17 [PATCH 0/2] target/riscv: apply pointer masking to flh/fsh and Zcmp push/pop Rishab Pradeep
2026-12-04 20:17 ` [PATCH 1/2] target/riscv: apply pointer masking to flh/fsh Rishab Pradeep
@ 2026-12-04 20:17 ` Rishab Pradeep
1 sibling, 0 replies; 3+ messages in thread
From: Rishab Pradeep @ 2026-12-04 20:17 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, palmer, alistair.francis, liwei1518, daniel.barboza,
zhiwei_liu, chao.liu, Rishab Pradeep, Tarun Patanjali,
Christopher Elwood
gen_pop() and trans_cm_push() used the sp-derived address directly
for each stack access, so with pointer masking enabled a tagged sp
raised an access fault. This affects cm.push, cm.pop, cm.popret and
cm.popretz.
Apply gen_pm_adjust_addr() to each access address. sp itself keeps
its tag, and the cm.popret jump target is unchanged, as it is an
instruction fetch rather than an explicit memory access.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4967
Co-developed-by: Tarun Patanjali <tarun.patanjali@utexas.edu>
Signed-off-by: Tarun Patanjali <tarun.patanjali@utexas.edu>
Co-developed-by: Christopher Elwood <christopher.elwood2024@gmail.com>
Signed-off-by: Christopher Elwood <christopher.elwood2024@gmail.com>
Signed-off-by: Rishab Pradeep <rishab@rispop.dev>
---
target/riscv/tcg/insn_trans/trans_rvzce.c.inc | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/target/riscv/tcg/insn_trans/trans_rvzce.c.inc b/target/riscv/tcg/insn_trans/trans_rvzce.c.inc
index 71b4ca5473..2c3680b678 100644
--- a/target/riscv/tcg/insn_trans/trans_rvzce.c.inc
+++ b/target/riscv/tcg/insn_trans/trans_rvzce.c.inc
@@ -181,6 +181,7 @@ static bool gen_pop(DisasContext *ctx, arg_cmpp *a, bool ret, bool ret_val)
a->spimm;
TCGv sp = dest_gpr(ctx, xSP);
TCGv addr = tcg_temp_new();
+ TCGv maddr = tcg_temp_new();
int i;
tcg_gen_addi_tl(addr, sp, stack_adj - reg_size);
@@ -189,7 +190,8 @@ static bool gen_pop(DisasContext *ctx, arg_cmpp *a, bool ret, bool ret_val)
for (i = X_Sn + 11; i >= 0; i--) {
if (reg_bitmap & (1 << i)) {
TCGv dest = dest_gpr(ctx, i);
- tcg_gen_qemu_ld_tl(dest, addr, ctx->mem_idx, memop);
+ gen_pm_adjust_addr(ctx, maddr, addr);
+ tcg_gen_qemu_ld_tl(dest, maddr, ctx->mem_idx, memop);
gen_set_gpr(ctx, i, dest);
tcg_gen_subi_tl(addr, addr, reg_size);
}
@@ -235,6 +237,7 @@ static bool trans_cm_push(DisasContext *ctx, arg_cm_push *a)
a->spimm;
TCGv sp = dest_gpr(ctx, xSP);
TCGv addr = tcg_temp_new();
+ TCGv maddr = tcg_temp_new();
int i;
tcg_gen_subi_tl(addr, sp, reg_size);
@@ -243,7 +246,8 @@ static bool trans_cm_push(DisasContext *ctx, arg_cm_push *a)
for (i = X_Sn + 11; i >= 0; i--) {
if (reg_bitmap & (1 << i)) {
TCGv val = get_gpr(ctx, i, EXT_NONE);
- tcg_gen_qemu_st_tl(val, addr, ctx->mem_idx, memop);
+ gen_pm_adjust_addr(ctx, maddr, addr);
+ tcg_gen_qemu_st_tl(val, maddr, ctx->mem_idx, memop);
tcg_gen_subi_tl(addr, addr, reg_size);
}
}
--
2.56.0
^ permalink raw reply related [flat|nested] 3+ messages in thread