From nobody Thu Apr 9 23:26:47 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1775676181; cv=none; d=zohomail.com; s=zohoarc; b=A2p/4UWmfK6OSbfAWypYkCnkApUEXorWdKDe0uW+DbR86+HZQOoyP2a3Pypb8Gdu3/grEH5Xi2KDfF/MFlHM2BPzoNk6LufnAEP9d/wwjIPRlOyMsgRLH/CyGLU8whG4hgQSFSYDpK3DVwqorY369FQ7BPdACcIp6NErjuXnuis= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775676181; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7btD77cTka+EC1KtIs9mPj6vd0anECLAhodJnjQttdc=; b=bJEYkziQLz9fMLzansrrvvCAAVkidglLZj4/uDfXQjoCAC/Dmmcu+n0kU23MZu382+isz9qfR8PX4/2pEiC6N36JOPzsOE3kr4ytFixu9HnM69vITH3LzhYgd1uaIW6duPaq0I15kJ88o2jJcoP98A/xn4tvCUDX+T2KKgtImeI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1775676181672802.0289790809276; Wed, 8 Apr 2026 12:23:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wAYSy-0005iE-EF; Wed, 08 Apr 2026 15:21:32 -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 1wAY3v-0006Bx-Md; Wed, 08 Apr 2026 14:55:39 -0400 Received: from out30-119.freemail.mail.aliyun.com ([115.124.30.119]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wATcO-0001IF-Dt; Wed, 08 Apr 2026 10:10:58 -0400 Received: from localhost.localdomain(mailfrom:zhiwei_liu@linux.alibaba.com fp:SMTPD_---0X0f.zj4_1775657327 cluster:ay36) by smtp.aliyun-inc.com; Wed, 08 Apr 2026 22:08:48 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1775657328; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=7btD77cTka+EC1KtIs9mPj6vd0anECLAhodJnjQttdc=; b=TTSATh8QpBgLjz7ojaxiYOnEiJI+1kmhoXAsBKGzboZxtVCwwqhg82FowFYc36q9BYAt6NGH0e69QNMqzfESECbMBQGjyrTHPcTcVJjZfJyvVE675JwpaX7WxxUiGKqSlX0su/4JfvY65OGQSLnQkzsnef49vZFzt6o5ceXfNAM= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R201e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033032089153; MF=zhiwei_liu@linux.alibaba.com; NM=1; PH=DS; RN=11; SR=0; TI=SMTPD_---0X0f.zj4_1775657327; From: LIU Zhiwei To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, chao.liu.zevorn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com, daniel.barboza@oss.qualcomm.com, liwei1518@gmail.com, LIU Zhiwei , Huang Tao , TANG Tiancheng , Daniel Henrique Barboza Subject: [PATCH v5 4/6] target/riscv: Implement SMMPT fence instructions Date: Wed, 8 Apr 2026 22:06:33 +0800 Message-Id: <20260408140635.42546-5-zhiwei_liu@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20260408140635.42546-1-zhiwei_liu@linux.alibaba.com> References: <20260408140635.42546-1-zhiwei_liu@linux.alibaba.com> 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=lists.gnu.org; Received-SPF: pass client-ip=115.124.30.119; envelope-from=zhiwei_liu@linux.alibaba.com; helo=out30-119.freemail.mail.aliyun.com X-Spam_score_int: -174 X-Spam_score: -17.5 X-Spam_bar: ----------------- X-Spam_report: (-17.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 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-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1775676182895154100 Content-Type: text/plain; charset="utf-8" This patch completes the SMMPT implementation by adding support for the new fence instructions: `mfence.spa` and `minval.spa`. According to the specification, these instructions act as memory ordering fences for MPT updates. In QEMU's TCG model, this is conservatively implemented by flushing the entire TLB, which ensures that any subsequent memory accesses will re-evaluate permissions and see the effects of any pri= or MPT modifications. The instructions are privileged and will cause an illegal instruction exception if executed outside of M-mode. Co-authored-by: Huang Tao Co-authored-by: TANG Tiancheng Signed-off-by: LIU Zhiwei Reviewed-by: Daniel Henrique Barboza --- target/riscv/insn32.decode | 2 ++ .../riscv/insn_trans/trans_privileged.c.inc | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode index 6e35c4b1e6..84cec57daf 100644 --- a/target/riscv/insn32.decode +++ b/target/riscv/insn32.decode @@ -120,6 +120,8 @@ sret 0001000 00010 00000 000 00000 1110011 mret 0011000 00010 00000 000 00000 1110011 wfi 0001000 00101 00000 000 00000 1110011 sfence_vma 0001001 ..... ..... 000 00000 1110011 @sfence_vma +mfence_spa 1000011 ..... ..... 000 00000 1110011 @sfence_vma +minval_spa 0000011 ..... ..... 000 00000 1110011 @sfence_vma =20 # *** NMI *** mnret 0111000 00010 00000 000 00000 1110011 diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/= insn_trans/trans_privileged.c.inc index 8a62b4cfcd..5ec6bf5991 100644 --- a/target/riscv/insn_trans/trans_privileged.c.inc +++ b/target/riscv/insn_trans/trans_privileged.c.inc @@ -160,3 +160,33 @@ static bool trans_sfence_vma(DisasContext *ctx, arg_sf= ence_vma *a) #endif return false; } + +#define REQUIRE_SMSDID(ctx) do { \ + if (!ctx->cfg_ptr->ext_smsdid) { \ + return false; \ + } \ +} while (0) + +static bool do_mfence_spa(DisasContext *ctx) +{ +#ifndef CONFIG_USER_ONLY + REQUIRE_SMSDID(ctx); + if (ctx->priv !=3D PRV_M) { + return false; + } + decode_save_opc(ctx, 0); + gen_helper_tlb_flush_all(tcg_env); + return true; +#endif + return false; +} + +static bool trans_mfence_spa(DisasContext *ctx, arg_mfence_spa *a) +{ + return do_mfence_spa(ctx); +} + +static bool trans_minval_spa(DisasContext *ctx, arg_minval_spa *a) +{ + return do_mfence_spa(ctx); +} --=20 2.43.0