From nobody Mon Nov 23 04:28:02 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=1794922093; cv=none; d=zohomail.com; s=zohoarc; b=kEqk5S5HvzN+g/cYY1nlZUaph8IglVQYmJp1gRVypJQ9fdypx7gfQXdj0ZEwonfjZXaEKId2VqqTZM1htR7PFeHOxrXtsHg7Q8EEwszfMs1eQMLafZIdeIXs+NHo8ETRXJE7e54xGgzI7WC3Wldw9uYBn7AhgsJFzS2nYqaekQY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794922093; h=Content-Type: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=02kQy2hmw7zNhOK9e5Jfphu2KKmG7WsgiKnYVK9vXiM=; b=joiIjFCmFTiweCIrLGIo4WKmqahGlqwI/Xuz++PK8ynPzu87J3MsJUDisQJnSC+bMRQ5goyl8dopgqLFbDH/CtbchXBNsauLDtBwqv+kczNdD0E4j+YGeEWGlj+DPBIMEihzMX0rMXmUARodjfsU5W6U1y1x8fBWLd+PQQYbvbg= 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 179492209336476.2222477524648; Tue, 17 Nov 2026 05:28:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xTJDV-0000YW-Ei; Tue, 17 Nov 2026 08:27:21 -0500 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 1xTJDS-0000Xw-TB for qemu-devel@nongnu.org; Tue, 17 Nov 2026 08:27:18 -0500 Received: from atcsqr.andestech.com ([220.128.198.184]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTJDQ-0003tH-RF for qemu-devel@nongnu.org; Tue, 17 Nov 2026 08:27:18 -0500 Received: from mail.andestech.com (atcpcs55.andestech.com [10.0.1.155]) by Atcsqr.andestech.com with ESMTPS id 6AHDQnNs073909 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 17 Nov 2026 21:26:49 +0800 (+08) (envelope-from alvinga@andestech.com) Received: from ATCPCS34.andestech.com (10.0.1.134) by atcpcs55.andestech.com (10.0.1.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.56; Tue, 17 Nov 2026 21:26:49 +0800 Received: from swlinux02.andestech.com (10.0.15.183) by ATCPCS34.andestech.com (10.0.1.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 17 Nov 2026 21:26:48 +0800 To: , CC: , , , , , Alvin Chang Subject: [PATCH v1 1/2] target/riscv: Write zero into mtinst/htinst for SSAMOSWAP faults Date: Tue, 17 Nov 2026 21:26:37 +0800 Message-ID: <20261117132638.1452474-2-alvinga@andestech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261117132638.1452474-1-alvinga@andestech.com> References: <20261117132638.1452474-1-alvinga@andestech.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.0.15.183] X-ClientProxiedBy: ATCPCS33.andestech.com (10.0.1.100) To ATCPCS34.andestech.com (10.0.1.134) X-DKIM-Results: atcpcs55.andestech.com; dkim=none; X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 6AHDQnNs073909 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=220.128.198.184; envelope-from=alvinga@andestech.com; helo=Atcsqr.andestech.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_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Alvin Chang From: Alvin Chang 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: 1794922096162158500 Content-Type: text/plain; charset="utf-8" The privileged spec defines transformed instructions for standard AMO instructions which do not include SSAMOSWAP. The spec also says: "If a synchronous trap occurs for a standard instruction for which no transformation has been defined, the trap instruction register shall be written with zero". So mtinst and htinst should be zero for SSAMOSWAP faults. The previous implementation only compares opcode which is not enough to distinguish SSAMOSWAP from standard AMO instructions. This commit further compares it with funct5. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4721 Fixes: f06bfe3dc38c ("target/riscv: implement zicfiss instructions") Signed-off-by: Alvin Chang --- target/riscv/instmap.h | 2 ++ target/riscv/tcg/cpu_helper.c | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/target/riscv/instmap.h b/target/riscv/instmap.h index f877530576..bddcf313df 100644 --- a/target/riscv/instmap.h +++ b/target/riscv/instmap.h @@ -165,6 +165,8 @@ enum { OPC_RISC_AMOMAX =3D OPC_RISC_ATOMIC | (0x14 << 27), OPC_RISC_AMOMINU =3D OPC_RISC_ATOMIC | (0x18 << 27), OPC_RISC_AMOMAXU =3D OPC_RISC_ATOMIC | (0x1C << 27), + + OPC_RISC_SSAMOSWAP =3D OPC_RISC_ATOMIC | (0x09 << 27), }; =20 #define MASK_OP_SYSTEM(op) (MASK_OP_MAJOR(op) | (op & (0x7 << 12))) diff --git a/target/riscv/tcg/cpu_helper.c b/target/riscv/tcg/cpu_helper.c index 58e98e975c..94e385261b 100644 --- a/target/riscv/tcg/cpu_helper.c +++ b/target/riscv/tcg/cpu_helper.c @@ -2078,9 +2078,12 @@ static target_ulong riscv_transformed_insn(CPURISCVS= tate *env, /* Transform 32bit (or wider) instructions */ switch (MASK_OP_MAJOR(insn)) { case OPC_RISC_ATOMIC: - xinsn =3D insn; - access_rs1 =3D GET_RS1(insn); - access_size =3D 1 << GET_FUNCT3(insn); + /* Exclude SSAMOSWAP.W and SSAMOSWAP.D */ + if (MASK_OP_ATOMIC_NO_AQ_RL_SZ(insn) !=3D OPC_RISC_SSAMOSWAP) { + xinsn =3D insn; + access_rs1 =3D GET_RS1(insn); + access_size =3D 1 << GET_FUNCT3(insn); + } break; case OPC_RISC_LOAD: case OPC_RISC_FP_LOAD: --=20 2.43.0 From nobody Mon Nov 23 04:28:02 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=1794922089; cv=none; d=zohomail.com; s=zohoarc; b=jgMPbpUKahMyUZnpCiJp+LP5TNncPsVbKXT+vYLurA4dGk+99jNll5HgkKHMunQ/QzlpcFlqbxje+xf+yczF3IoX4d90RxBCU/EngudMPHG9gQZgvYoU+6VJHn8iRFDAIeMgpYB05hlNqxXm84rSkHkIQfqwAd4gHIRfIHSMAaU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794922089; h=Content-Type: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=cdJyfNdWeclu5WcUHVFAyHcmaOO4SV8RX0D9LXtLnlw=; b=MRAUJ2z0vzxn5994wE2zbaD6ff2488+mm9uNY0WS21mFZATNvVYnCBA50gTP+6S/ePSLSmagxJ9fbfWPvNVbvJ59rBwRL0AFUvjH762EhDZ1ZpbNu3bHHkuQsGEYOxSJOOKYRWZum0Ds4pPQehihnhW2qqwqHwoso6s3heEDBa0= 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 1794922089800546.9924190646553; Tue, 17 Nov 2026 05:28:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xTJDT-0000Y9-Sm; Tue, 17 Nov 2026 08:27:19 -0500 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 1xTJDS-0000Xp-Ju for qemu-devel@nongnu.org; Tue, 17 Nov 2026 08:27:18 -0500 Received: from atcsqr.andestech.com ([220.128.198.184]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTJDQ-0003tD-Op for qemu-devel@nongnu.org; Tue, 17 Nov 2026 08:27:18 -0500 Received: from mail.andestech.com (atcpcs54.andestech.com [10.0.1.154]) by Atcsqr.andestech.com with ESMTPS id 6AHDQo8A073911 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 17 Nov 2026 21:26:50 +0800 (+08) (envelope-from alvinga@andestech.com) Received: from ATCPCS34.andestech.com (10.0.1.134) by atcpcs54.andestech.com (10.0.1.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.56; Tue, 17 Nov 2026 21:26:50 +0800 Received: from swlinux02.andestech.com (10.0.15.183) by ATCPCS34.andestech.com (10.0.1.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 17 Nov 2026 21:26:50 +0800 To: , CC: , , , , , Alvin Chang Subject: [PATCH v1 2/2] target/riscv: Write zero into mtinst/htinst for SSPUSH/SSPOPCHK faults Date: Tue, 17 Nov 2026 21:26:38 +0800 Message-ID: <20261117132638.1452474-3-alvinga@andestech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261117132638.1452474-1-alvinga@andestech.com> References: <20261117132638.1452474-1-alvinga@andestech.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.0.15.183] X-ClientProxiedBy: ATCPCS33.andestech.com (10.0.1.100) To ATCPCS34.andestech.com (10.0.1.134) X-DKIM-Results: atcpcs54.andestech.com; dkim=none; X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 6AHDQo8A073911 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=220.128.198.184; envelope-from=alvinga@andestech.com; helo=Atcsqr.andestech.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_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Alvin Chang From: Alvin Chang 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: 1794922096176158500 Content-Type: text/plain; charset="utf-8" The privileged spec defines transformed instructions for standard virtual-machine load/store instructions which do not include SSPUSH and SSPOPCHK. The spec also says: "If a synchronous trap occurs for a standard instruction for which no transformation has been defined, the trap instruction register shall be written with zero". So mtinst and htinst should be zero for SSPUSH and SSPOPCHK faults. The previous implementation only compares opcode and funct3, which is not enough to distinguish SSPUSH and SSPOPCHK from virtual-machine load/store instructions. Now we compare opcode, funct3 and funct7 together. Fixes: f06bfe3dc38c ("target/riscv: implement zicfiss instructions") Signed-off-by: Alvin Chang --- target/riscv/instmap.h | 15 ++++++++++++++- target/riscv/tcg/cpu_helper.c | 14 +++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/target/riscv/instmap.h b/target/riscv/instmap.h index bddcf313df..107e7c5a83 100644 --- a/target/riscv/instmap.h +++ b/target/riscv/instmap.h @@ -170,6 +170,8 @@ enum { }; =20 #define MASK_OP_SYSTEM(op) (MASK_OP_MAJOR(op) | (op & (0x7 << 12))) +#define MASK_OP_SYSTEM_FUNCT3_FUNCT7(op) \ + (MASK_OP_MAJOR(op) | (op & (0x7 << 12)) | (op & (0x7F << 25))) enum { OPC_RISC_ECALL =3D OPC_RISC_SYSTEM | (0x0 << 12), OPC_RISC_EBREAK =3D OPC_RISC_SYSTEM | (0x0 << 12), @@ -187,7 +189,18 @@ enum { OPC_RISC_CSRRSI =3D OPC_RISC_SYSTEM | (0x6 << 12), OPC_RISC_CSRRCI =3D OPC_RISC_SYSTEM | (0x7 << 12), =20 - OPC_RISC_HLVHSV =3D OPC_RISC_SYSTEM | (0x4 << 12), + /* HLV.B and HLV.BU */ + OPC_RISC_HLVB =3D OPC_RISC_SYSTEM | (0x4 << 12) | (0x30 << 25), + /* HLV.H, HLV.HU and HLVX.HU */ + OPC_RISC_HLVH =3D OPC_RISC_SYSTEM | (0x4 << 12) | (0x32 << 25), + /* HLV.W, HLV.WU and HLVX.WU */ + OPC_RISC_HLVW =3D OPC_RISC_SYSTEM | (0x4 << 12) | (0x34 << 25), + OPC_RISC_HLVD =3D OPC_RISC_SYSTEM | (0x4 << 12) | (0x36 << 25), + + OPC_RISC_HSVB =3D OPC_RISC_SYSTEM | (0x4 << 12) | (0x31 << 25), + OPC_RISC_HSVH =3D OPC_RISC_SYSTEM | (0x4 << 12) | (0x33 << 25), + OPC_RISC_HSVW =3D OPC_RISC_SYSTEM | (0x4 << 12) | (0x35 << 25), + OPC_RISC_HSVD =3D OPC_RISC_SYSTEM | (0x4 << 12) | (0x37 << 25), }; =20 #define MASK_OP_FP_LOAD(op) (MASK_OP_MAJOR(op) | (op & (0x7 << 12))) diff --git a/target/riscv/tcg/cpu_helper.c b/target/riscv/tcg/cpu_helper.c index 94e385261b..9a1ce61a2f 100644 --- a/target/riscv/tcg/cpu_helper.c +++ b/target/riscv/tcg/cpu_helper.c @@ -2100,11 +2100,23 @@ static target_ulong riscv_transformed_insn(CPURISCV= State *env, access_size =3D 1 << GET_FUNCT3(insn); break; case OPC_RISC_SYSTEM: - if (MASK_OP_SYSTEM(insn) =3D=3D OPC_RISC_HLVHSV) { + switch (MASK_OP_SYSTEM_FUNCT3_FUNCT7(insn)) { + case OPC_RISC_HLVB: + case OPC_RISC_HLVH: + case OPC_RISC_HLVW: + case OPC_RISC_HLVD: + case OPC_RISC_HSVB: + case OPC_RISC_HSVH: + case OPC_RISC_HSVW: + case OPC_RISC_HSVD: xinsn =3D insn; access_rs1 =3D GET_RS1(insn); access_size =3D 1 << ((GET_FUNCT7(insn) >> 1) & 0x3); access_size =3D 1 << access_size; + break; + default: + /* Not a transformed instruction, e.g., SSPUSH and SSPOPCH= K. */ + break; } break; default: --=20 2.43.0