From nobody Mon Nov 23 04:52:44 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 Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179203397379083.06723397684652; Wed, 14 Oct 2026 20:12:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHBt1-0002qb-VU; Wed, 14 Oct 2026 23:12:08 -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 1xHBst-0002m6-0n; Wed, 14 Oct 2026 23:12:00 -0400 Received: from smtp81.cstnet.cn ([159.226.251.81] helo=cstnet.cn) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1xHBso-00061s-TA; Wed, 14 Oct 2026 23:11:58 -0400 Received: from DESKTOP-7FLBREN (unknown [124.16.137.194]) by APP-03 (Coremail) with SMTP id rQCowABHUkBwRNBqpN_MCg--.64350S7; Thu, 15 Oct 2026 11:11:47 +0800 (CST) From: wangyang To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Palmer Dabbelt , Alistair Francis , Daniel Henrique Barboza , Liu Zhiwei Subject: [PATCH] target/riscv: enforce SSE precedence for ssp CSR access Date: Thu, 15 Oct 2026 11:11:40 +0800 Message-ID: <20261015031140.896-4-wangyang25@otcaix.iscas.ac.cn> X-Mailer: git-send-email 2.55.0.windows.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: rQCowABHUkBwRNBqpN_MCg--.64350S7 X-Coremail-Antispam: 1UD129KBjvJXoW7AryDKF17CFyxXF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Ja73UjIFyTuYvjxUvdMaUUUUU X-Originating-IP: [124.16.137.194] X-CM-SenderInfo: 5zdqw5xdqjjk46rwut1l0ox2xfdvhtffof0/ 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=159.226.251.81; envelope-from=wangyang25@otcaix.iscas.ac.cn; helo=cstnet.cn X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1792033978059158500 Content-Type: text/plain; charset="utf-8" When menvcfg.SSE is clear, ssp access below M mode raises an illegal-instruction exception before virtual-instruction classification. Apply the henvcfg/senvcfg checks for VS/VU and preserve the user-only path. Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4226 Signed-off-by: wangyang --- target/riscv/tcg/csr.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/target/riscv/tcg/csr.c b/target/riscv/tcg/csr.c index 061bc9d..98dcb0e 100644 --- a/target/riscv/tcg/csr.c +++ b/target/riscv/tcg/csr.c @@ -204,15 +204,34 @@ static RISCVException cfi_ss(CPURISCVState *env, int = csrno) return RISCV_EXCP_NONE; } =20 - /* if bcfi not active for current env, access to csr is illegal */ - if (!cpu_get_bcfien(env)) { #if !defined(CONFIG_USER_ONLY) - if (env->debugger) { - return RISCV_EXCP_NONE; - } else if (env->virt_enabled) { + if (env->debugger) { + return RISCV_EXCP_NONE; + } + + /* priv < M and menvcfg.SSE =3D 0 must raise illegal-instruction */ + if (!(env->menvcfg & MENVCFG_SSE)) { + return RISCV_EXCP_ILLEGAL_INST; + } + + if (env->virt_enabled) { + if (env->priv =3D=3D PRV_S) { + if (env->henvcfg & HENVCFG_SSE) { + return RISCV_EXCP_NONE; + } + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + } + if (env->priv =3D=3D PRV_U) { + if ((env->henvcfg & HENVCFG_SSE) && + (env->senvcfg & SENVCFG_SSE)) { + return RISCV_EXCP_NONE; + } return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } + } #endif + + if (!cpu_get_bcfien(env)) { return RISCV_EXCP_ILLEGAL_INST; } =20 --=20 2.43.0