From nobody Mon Nov 23 04:26:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793303228; cv=none; d=zohomail.com; s=zohoarc; b=K3+HjxKtjoodbPB5Wx17OTYn5+CO6R2ed7yTtL82kwHEF3M5G17BR0VKsbMl0y2CqHkUkYfaIwCTrw7QvKbSrvm9Ur+i23DTQNEYlAmokUrhEifnquRsVfGdtd1li9AOAWWV36MRtoGH5/qM5rPa29PluT1YRT9ZcNpSwi59E+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793303228; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=EjUFUgBuSWPda24Z4nTOkG2uJePWYZhqS5QvmBwcdDM=; b=EUA0S8LFMv61jX5hcXL6faH419nKMSSmWLI5J54mm2GqzkI5d3DcQDB5xQL6HP4JdAOMghZVtPeueBYHrk16U+YKj9gsPoRxdDRn4N9kKHyq6EmEWYEAgJfkF26UesvNgm2lfz6Z9KJzx5oJGTDOTSXXMUm6YmWYu7fCP/6EhqQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793303228977694.9455829639246; Thu, 29 Oct 2026 12:47:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMW4V-0000Qt-6Y; Thu, 29 Oct 2026 15:45:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMV1G-0008Jc-UW; Thu, 29 Oct 2026 14:38:34 -0400 Received: from mail-08.mail-europe.com ([57.129.93.249]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMV1D-00014S-5R; Thu, 29 Oct 2026 14:38:33 -0400 X-Pm-Submission-Id: 4jFtK050Rtz1DFSk To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Chao Liu , Tarun Patanjali , Chris Elwood , Rishab Pradeep Subject: [PATCH 1/2] target/riscv: Factor out pointer-masking address adjustment Date: Thu, 29 Oct 2026 13:37:50 -0500 Message-ID: <20261029183751.11143-2-rishab@rispop.dev> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261029183751.11143-1-rishab@rispop.dev> References: <20261029183751.11143-1-rishab@rispop.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=57.129.93.249; envelope-from=rishab@rispop.dev; helo=mail-08.mail-europe.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 29 Oct 2026 15:45:56 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Rishab Pradeep From: Rishab Pradeep via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793303231299158500 Content-Type: text/plain; charset="utf-8" Move the addr_xl/addr_signed extract, which applies address-width truncation and the pointer-masking ignore transformation, out of get_address() and get_address_indexed() into a new helper, gen_pm_adjust_addr(), so it can be applied to addresses that are not formed from a GPR. No functional change. Co-developed-by: Tarun Patanjali Signed-off-by: Tarun Patanjali Co-developed-by: Chris Elwood Signed-off-by: Chris Elwood Signed-off-by: Rishab Pradeep Reviewed-by: Daniel Henrique Barboza --- target/riscv/tcg/translate.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/target/riscv/tcg/translate.c b/target/riscv/tcg/translate.c index 79b0f444ef..72d36764d8 100644 --- a/target/riscv/tcg/translate.c +++ b/target/riscv/tcg/translate.c @@ -654,6 +654,15 @@ static void gen_jal(DisasContext *ctx, int rd, target_= ulong imm) ctx->base.is_jmp =3D DISAS_NORETURN; } =20 +static void gen_pm_adjust_addr(DisasContext *ctx, TCGv dest, TCGv src) +{ + if (ctx->addr_signed) { + tcg_gen_sextract_tl(dest, src, 0, ctx->addr_xl); + } else { + tcg_gen_extract_tl(dest, src, 0, ctx->addr_xl); + } +} + /* Compute a canonical address from a register plus offset. */ static TCGv get_address(DisasContext *ctx, int rs1, int imm) { @@ -661,11 +670,7 @@ static TCGv get_address(DisasContext *ctx, int rs1, in= t imm) TCGv src1 =3D get_gpr(ctx, rs1, EXT_NONE); =20 tcg_gen_addi_tl(addr, src1, imm); - if (ctx->addr_signed) { - tcg_gen_sextract_tl(addr, addr, 0, ctx->addr_xl); - } else { - tcg_gen_extract_tl(addr, addr, 0, ctx->addr_xl); - } + gen_pm_adjust_addr(ctx, addr, addr); =20 return addr; } @@ -677,11 +682,7 @@ static TCGv get_address_indexed(DisasContext *ctx, int= rs1, TCGv offs) TCGv src1 =3D get_gpr(ctx, rs1, EXT_NONE); =20 tcg_gen_add_tl(addr, src1, offs); - if (ctx->addr_signed) { - tcg_gen_sextract_tl(addr, addr, 0, ctx->addr_xl); - } else { - tcg_gen_extract_tl(addr, addr, 0, ctx->addr_xl); - } + gen_pm_adjust_addr(ctx, addr, addr); =20 return addr; } --=20 2.54.0 (Apple Git-157) From nobody Mon Nov 23 04:26:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793303224; cv=none; d=zohomail.com; s=zohoarc; b=mw4D13ngquzyUtdm8YIIPxm6hsw63eksQDk2QI/4F6m2Xf5YSGTSwg1Nbh1Bo8bizlIJPsdrn8dvjYt98BFTZ7FrhDW0UIusM8sHbmIdqKTcEYgkxYcqYJsn9E5aAqQBnG0AXngQ/UUHCFoYprh4sM/en5spV/42fhq2ML7iQa0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793303224; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=jBgLs18skSt6/+sBQu9SwyFF18rPWU8LbOGUrF4Eqms=; b=hBUYsgRleTpq7GjLokTckvS7KhaQ/XY0LXmgj0XZp7LICKkA71VQDgsi/fo7zcicLyh2hcPRNnTG0UbiRBKKU73cpgg5okQ/Cm8vUr/qvuZn8HsUSKlte/ccO4fvn923Obmr/jIWHetEjpJyjBqL//U4wNJFIv+r6y0jK/QrLQY= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179330322486753.86527011893065; Thu, 29 Oct 2026 12:47:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMW4V-0000RK-TZ; Thu, 29 Oct 2026 15:46:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMV1I-0008RC-TG for qemu-devel@nongnu.org; Thu, 29 Oct 2026 14:38:37 -0400 Received: from mail-07.mail-europe.com ([37.187.220.204]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMV1G-00014m-MA for qemu-devel@nongnu.org; Thu, 29 Oct 2026 14:38:36 -0400 X-Pm-Submission-Id: 4jFtK42DwZz1DFSl To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Chao Liu , Tarun Patanjali , Chris Elwood , Rishab Pradeep Subject: [PATCH 2/2] target/riscv: Apply pointer masking to SSPUSH/SSPOPCHK addresses Date: Thu, 29 Oct 2026 13:37:51 -0500 Message-ID: <20261029183751.11143-3-rishab@rispop.dev> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261029183751.11143-1-rishab@rispop.dev> References: <20261029183751.11143-1-rishab@rispop.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=37.187.220.204; envelope-from=rishab@rispop.dev; helo=mail-07.mail-europe.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 29 Oct 2026 15:45:56 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Rishab Pradeep From: Rishab Pradeep via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793303227005158500 Content-Type: text/plain; charset="utf-8" SSPUSH and SSPOPCHK form their effective address from ssp rather than a GPR, so they bypass get_address() and the pointer-masking ignore transformation is never applied. With pointer masking enabled, a tagged ssp raises a store/AMO page fault, while SSAMOSWAP through the same tagged pointer succeeds. Apply gen_pm_adjust_addr() to the ssp-derived address. ssp itself is still written back unmasked, and the SSPOPCHK comparison of the loaded value against rs1 is unchanged. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4758 Co-developed-by: Tarun Patanjali Signed-off-by: Tarun Patanjali Co-developed-by: Chris Elwood Signed-off-by: Chris Elwood Signed-off-by: Rishab Pradeep --- target/riscv/tcg/insn_trans/trans_rvzicfiss.c.inc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/target/riscv/tcg/insn_trans/trans_rvzicfiss.c.inc b/target/ris= cv/tcg/insn_trans/trans_rvzicfiss.c.inc index d47a9f9c7d..c2dddcc8bb 100644 --- a/target/riscv/tcg/insn_trans/trans_rvzicfiss.c.inc +++ b/target/riscv/tcg/insn_trans/trans_rvzicfiss.c.inc @@ -29,6 +29,7 @@ static bool trans_sspopchk(DisasContext *ctx, arg_sspopch= k *a) } =20 TCGv addr =3D tcg_temp_new(); + TCGv maddr =3D tcg_temp_new(); TCGLabel *skip =3D gen_new_label(); uint32_t tmp =3D (get_xl(ctx) =3D=3D MXL_RV64) ? 8 : 4; TCGv data =3D tcg_temp_new(); @@ -36,8 +37,9 @@ static bool trans_sspopchk(DisasContext *ctx, arg_sspopch= k *a) TCGv_i64 wide_addr =3D tcg_temp_new_i64(); tcg_gen_ld_i64(wide_addr, tcg_env, offsetof(CPURISCVState, ssp)); tcg_gen_trunc_i64_tl(addr, wide_addr); + gen_pm_adjust_addr(ctx, maddr, addr); decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO); - tcg_gen_qemu_ld_tl(data, addr, SS_MMU_INDEX(ctx), + tcg_gen_qemu_ld_tl(data, maddr, SS_MMU_INDEX(ctx), mxl_memop(ctx) | MO_ALIGN); TCGv rs1 =3D get_gpr(ctx, a->rs1, EXT_NONE); tcg_gen_brcond_tl(TCG_COND_EQ, data, rs1, skip); @@ -60,6 +62,7 @@ static bool trans_sspush(DisasContext *ctx, arg_sspush *a) } =20 TCGv addr =3D tcg_temp_new(); + TCGv maddr =3D tcg_temp_new(); int tmp =3D (get_xl(ctx) =3D=3D MXL_RV64) ? -8 : -4; TCGv data =3D get_gpr(ctx, a->rs2, EXT_NONE); TCGv_i64 wide_addr =3D tcg_temp_new_i64(); @@ -67,7 +70,8 @@ static bool trans_sspush(DisasContext *ctx, arg_sspush *a) tcg_gen_ld_i64(wide_addr, tcg_env, offsetof(CPURISCVState, ssp)); tcg_gen_trunc_i64_tl(addr, wide_addr); tcg_gen_addi_tl(addr, addr, tmp); - tcg_gen_qemu_st_tl(data, addr, SS_MMU_INDEX(ctx), + gen_pm_adjust_addr(ctx, maddr, addr); + tcg_gen_qemu_st_tl(data, maddr, SS_MMU_INDEX(ctx), mxl_memop(ctx) | MO_ALIGN); tcg_gen_ext_tl_i64(wide_addr, addr); tcg_gen_st_i64(wide_addr, tcg_env, offsetof(CPURISCVState, ssp)); --=20 2.54.0 (Apple Git-157)