From nobody Fri Dec 19 17:09:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.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=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1610920643; cv=none; d=zohomail.com; s=zohoarc; b=PovsG+hO3PjW+wDdPdfcDlW0+5lw2dTVjBp7lPWrGyA5lujHgO5z6xpyPPl4W/YBVLlvI/PvjXrud9THu4vQG9niiGCffaEE2czObQwxGEYMjCOBW9YT0Lx0X2mdBobRxcAS57YHx5J41cKvyhv9bwZ89MVeZXYPyqH0hQ6dPNs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610920643; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4O5ny+dolsj5ZdkJuEvBhPHZitTgUk3HeibdciF2s38=; b=QkIgVHquzEVxpEYjIYGgMsVYwIucUuPODfyCOLouKS/NZs5hMqiE8baRO0VB6SAdcy7ClCXHuJaAKT6mS1UArpyjEto2m8ACUf/oXRzm3F3sVRU5U/7DkFKW/nxP6LNQKvz2x7jBqL1sfcvfmcHBwqxGYqa8eRnD4wOe1ntKD/s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1610920643378570.3141407260929; Sun, 17 Jan 2021 13:57:23 -0800 (PST) Received: from localhost ([::1]:50546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1G30-000224-3b for importer@patchew.org; Sun, 17 Jan 2021 16:57:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59106) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1Fzy-0005hk-2D for qemu-devel@nongnu.org; Sun, 17 Jan 2021 16:54:15 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:21692) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1Fzw-0005Ux-9A for qemu-devel@nongnu.org; Sun, 17 Jan 2021 16:54:13 -0500 Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 18 Jan 2021 05:54:06 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2021 13:38:45 -0800 Received: from 7l95g12.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.62.251]) by uls-op-cesaip01.wdc.com with ESMTP; 17 Jan 2021 13:54:06 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1610920452; x=1642456452; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OyqeSrK4z3EFuRbBI4aHmMrvzd1dz/TK7VvfkMHCx74=; b=Vm4wz+0cTkCNzT27QGytQiUx9ZtY0Lt9jkmeEvuV3mglri+JNfwSW1PF +pNBi1J/wr/ke5NTRnuulBAPj944Bz6D6W6S79/hH3Jye1eAjs1kviRxg FRLyUvWAHMenVPYIVxGM3D7THmsG842LIe/RjjFdRfW8+LJJuCGr37FNk MkdYOhpymxXVXiG2O4q3TKwLuUZWSTdBMvSqfPNQMPkjIf2yeBLhvMvKu b1/MmTusR5LyLJxglwoRQ8y/lu1DOVRDlUvqO65rlaEmU7LDYugWY3E/u uGq4rKiaPEA/DgI/f4x5RpQ9X+5QCAQpqP3F3YXLLTbR9EKMmPG3McBxb w==; IronPort-SDR: oaDauIXVWrxrfA8M4VtiG/V932QsrSWVNdl1PAdwQMTClCvQZKJjoKlCKvONCBGs8DQBdtIEop +EimJKcUIPcIpylMuuALfHBi6grLr0+w6RCKUJlKbRd0IWLnUgYpsV/dGqg5o6IkXYkXfjNQYf +WDc21HzEd09s5kaXZOyuOgjOkQZ1eWc+xTcXgMjMdi/TD2S4oeVSK8jtJMfHSJrHi4wXIfDFE yXzPOSb2oRlQ7CptBLUPSCqtXJKv/vUum4rn8YIu9y8ePPJDDKZTM/qliCfeWS5RStuFPMf/nP aWY= X-IronPort-AV: E=Sophos;i="5.79,355,1602518400"; d="scan'208";a="157645966" IronPort-SDR: b0EytWAACbQJ1125opEEjxHbdXznI+YviRsUjjPzufMDD3IOSMK5dufz7HZT7cEg4D+0HGGBm0 rrt9dGYrLEvcb1KTb4rX/z244iy+UR7ot6/B2Ty+gAOU3fA/9lKJmoApo5dFziVMYJrdVPMGn3 EH1uPDG0HNzTtsUsGM/N6mry6wfnZnSytwAFHukDeQ0SebvAwbJU00DeISfbxKqyAK5ZfKNR59 tRlxfM3gh6vschzUcWfO7MkuBJBK6jgNJhP6+Lm5v8IjaCmvPULsnFNmjYHZaDjoDzKLBovU6A RiVh4m89yRJ9C2o2VM/4KrYZ IronPort-SDR: 3uOnDKeC9eNnzcgt5wLWts8Y1fxsmGnzvCab8ddZJM4qd2KtktcpKkMw3qD2JNRKw0dL7mt64v +b4+L17I53YVsoTe4CreqjqGRy8JQJNl1tYEf2F5j7ioMADWTLhvGIGfwpiwnqx4XFeVcNUDDR jLXow+OVpfaoYEK6UVIrm3SERBKMlNb92luItsR8oSUVoyWw74a8pmFUYa5bNvbdy5qB2/UdYd Qzh5Se7VsThbAvNqgckbD4xOGOjTK20crR8avwenQLWGOIN/wmmRzUFTenJ4a8GEk/0YBZOrLr 9xA= WDCIronportException: Internal From: Alistair Francis To: peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 05/12] target/riscv/pmp: Raise exception if no PMP entry is configured Date: Sun, 17 Jan 2021 13:53:56 -0800 Message-Id: <20210117215403.2277103-6-alistair.francis@wdc.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210117215403.2277103-1-alistair.francis@wdc.com> References: <20210117215403.2277103-1-alistair.francis@wdc.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=216.71.153.144; envelope-from=prvs=64494dccb=alistair.francis@wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Atish Patra , Alistair Francis Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Atish Patra As per the privilege specification, any access from S/U mode should fail if no pmp region is configured. Signed-off-by: Atish Patra Reviewed-by: Alistair Francis Message-id: 20201223192553.332508-1-atish.patra@wdc.com Signed-off-by: Alistair Francis --- target/riscv/pmp.h | 1 + target/riscv/op_helper.c | 5 +++++ target/riscv/pmp.c | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h index 6c6b4c9bef..c8d5ef4a69 100644 --- a/target/riscv/pmp.h +++ b/target/riscv/pmp.h @@ -64,5 +64,6 @@ bool pmp_is_range_in_tlb(CPURISCVState *env, hwaddr tlb_s= a, target_ulong *tlb_size); void pmp_update_rule_addr(CPURISCVState *env, uint32_t pmp_index); void pmp_update_rule_nums(CPURISCVState *env); +uint32_t pmp_get_num_rules(CPURISCVState *env); =20 #endif diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index d55def76cf..1eddcb94de 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -150,6 +150,11 @@ target_ulong helper_mret(CPURISCVState *env, target_ul= ong cpu_pc_deb) =20 uint64_t mstatus =3D env->mstatus; target_ulong prev_priv =3D get_field(mstatus, MSTATUS_MPP); + + if (!pmp_get_num_rules(env) && (prev_priv !=3D PRV_M)) { + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); + } + target_ulong prev_virt =3D get_field(env->mstatus, MSTATUS_MPV); mstatus =3D set_field(mstatus, MSTATUS_MIE, get_field(mstatus, MSTATUS_MPIE)); diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index 2eda8e1e2f..80d0334e1b 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -74,7 +74,7 @@ static inline int pmp_is_locked(CPURISCVState *env, uint3= 2_t pmp_index) /* * Count the number of active rules. */ -static inline uint32_t pmp_get_num_rules(CPURISCVState *env) +uint32_t pmp_get_num_rules(CPURISCVState *env) { return env->pmp_state.num_rules; } @@ -237,7 +237,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulon= g addr, =20 /* Short cut if no rules */ if (0 =3D=3D pmp_get_num_rules(env)) { - return true; + return (env->priv =3D=3D PRV_M) ? true : false; } =20 if (size =3D=3D 0) { --=20 2.29.2