From: Rishab Pradeep <rishab@rispop.dev>
To: qemu-devel@nongnu.org
Cc: qemu-riscv@nongnu.org, palmer@dabbelt.com,
alistair.francis@wdc.com, liwei1518@gmail.com,
daniel.barboza@oss.qualcomm.com, zhiwei_liu@linux.alibaba.com,
chao.liu@processmission.com, Rishab Pradeep <rishab@rispop.dev>,
Tarun Patanjali <tarun.patanjali@utexas.edu>,
Christopher Elwood <christopher.elwood2024@gmail.com>
Subject: [PATCH 2/2] target/riscv: apply pointer masking to Zcmp push/pop
Date: Fri, 4 Dec 2026 14:17:32 -0600 [thread overview]
Message-ID: <20261204201732.254081-3-rishab@rispop.dev> (raw)
In-Reply-To: <20261204201732.254081-1-rishab@rispop.dev>
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
prev parent reply other threads:[~2026-12-04 20:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204201732.254081-3-rishab@rispop.dev \
--to=rishab@rispop.dev \
--cc=alistair.francis@wdc.com \
--cc=chao.liu@processmission.com \
--cc=christopher.elwood2024@gmail.com \
--cc=daniel.barboza@oss.qualcomm.com \
--cc=liwei1518@gmail.com \
--cc=palmer@dabbelt.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=tarun.patanjali@utexas.edu \
--cc=zhiwei_liu@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.