From patchwork Wed Aug 21 23:55:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 1975151 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=ApUCO9R/; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=VMq+M5MI; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wq3Bb4Ksrz1ygy for ; Thu, 22 Aug 2024 09:56:06 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xjufBCYN5dl4qxlemWml799XyPA6/pMJokMOHqhWdmE=; b=ApUCO9R/XhnYuk O5NAanCEPkWG1rm8OY51jMhxw1L+rFZN28orsIQ3ZCsQbrUOpiEXgFxu//JnJYmt5ttxUvEfGNCGy UQlg6dvTO7BjCC8AwJx/9NlTuT/IA9F1+iWu5OHhuR87QvNDlEPt9Uf8PFumUk9kmyRN1gW9YCFVo p/Ilt4RKqsh3jRSCo0mflhq1u3gv1Sg8fAAE5m/BHXGrmNVLkriNvUB+G3vb/uP9AGh3amBSstE0z TAaOP4bJMUrk+kG6y0NvXWNjIP/qUFd2GwNfUy+eRf4cv+FpvpQFP7l7qReUCXVyogKc4S7HbUX6m MYwd011HQihZuxNzNMUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgvBD-0000000AiBZ-1a0j; Wed, 21 Aug 2024 23:55:55 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgvB9-0000000AiA9-41fN for opensbi@lists.infradead.org; Wed, 21 Aug 2024 23:55:53 +0000 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-201ee6b084bso2154945ad.2 for ; Wed, 21 Aug 2024 16:55:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724284551; x=1724889351; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yt/ja22AZlw8G8xLQ8KXWBxub4Dabw1+saL7fWD69mo=; b=VMq+M5MI/DSVljC4hL8OIZpFtEIyFoe4Rg6ymSa176NNVpaWcJh7OX+RinGcQrExOI Budk/Z7UCjkw8oq9BJPk/xsSOc6rfeSz4yODUX+/fhpXdNrePY7r5OrqSLycTOsy8yct GcxxOByirRCn2WdKqWWYPh/gSIMaWB1woCsuBLpcsYPlz6sHbs1JzgAXGcWOEWqnvweY /WL4p/OyMGnZTR9o7xFPTBfwidzGWdHneNVdDOwbrghI3Q0Vdufhh1ZkO/lcbfsRfpsH qqwCbbLPPtgcS/FYsZU0T8t00rRCNYR+TsGgzdkyVW1xI6xbKCXsnQ/ys6YegMa0mFds d7FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724284551; x=1724889351; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yt/ja22AZlw8G8xLQ8KXWBxub4Dabw1+saL7fWD69mo=; b=RPlfajo7b85f1oKoS6SpuBl6zD17I334dwCpJAO4isu6PcEqBGWat6UYup5YBEs6EY I9kqnnxuIMuOvX4vTHD/36ncMAA1WU9h8TEyPZG0ywnL43kztr4kcpl4ojOKcSXff+B7 NbpMbm+7J8xQc6ml6VfQ0x+YX1lsbQ6ZZcCvOb7ce9DnKHyXr+aaPk2RKQBKWgtqb+/k WdWCG0z9ihezz+J0sBw+Z2jLQkO5ghNdlir4+ECqX5rqdHhB6sa32G1lxrpjvDjZlw95 Ff9N8AIEM8FdkK2VQhxDDkSLR3a1cwLkpIgWPPQlIvnzr4MzAr1vpKgM0H07L64rdUPZ 9c7g== X-Gm-Message-State: AOJu0YzeKQAFfjL0bj+7O9UJh4epCVaaljVMO6DboUprUCNzbxJAKEKv dZ8a7lEdwlMSSSQ/ev2Om3xtAkzS7MSpHRbib2thoxGTdYw0X6lpnS1rL7QN+a6gNjjX8FNoRFk D X-Google-Smtp-Source: AGHT+IHf+Cqj6SdTghrzaty85bha5/dp/NdazIb3pK3EIaXpU457tlzOXBweVEghGy7bYs9mSsMztA== X-Received: by 2002:a17:903:22c7:b0:1fd:aa8d:acde with SMTP id d9443c01a7336-20367d48109mr58035815ad.36.1724284550725; Wed, 21 Aug 2024 16:55:50 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2038556661csm1515495ad.24.2024.08.21.16.55.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 16:55:50 -0700 (PDT) From: Deepak Gupta To: opensbi@lists.infradead.org Cc: atishp@rivosinc.com, apatel@ventanamicro.com, Deepak Gupta Subject: [PATCH 1/3] include: adding support for Zicfilp / Zicfiss encodings Date: Wed, 21 Aug 2024 16:55:44 -0700 Message-ID: <20240821235546.3876172-2-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240821235546.3876172-1-debug@rivosinc.com> References: <20240821235546.3876172-1-debug@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_165552_021039_A6B55155 X-CRM114-Status: UNSURE ( 8.72 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.9 (-) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Zicfilp / Zicfiss extension (see link) introduces b2 (LPE) in menvcfg CSR to enable landing pads and b3 (SSE) in menvcfg CSR to enable shadow stack and landing pad for privilege less than M. Additiona [...] Content analysis details: (-1.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:632 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Zicfilp / Zicfiss extension (see link) introduces b2 (LPE) in menvcfg CSR to enable landing pads and b3 (SSE) in menvcfg CSR to enable shadow stack and landing pad for privilege less than M. Additionally extension introduces new bits in *status for recording landing pad state and a new exception type `software check exception` with cause=0x12. Link: https://github.com/riscv/riscv-cfi Signed-off-by: Deepak Gupta --- include/sbi/riscv_encoding.h | 6 ++++++ include/sbi/sbi_hart.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h index 2ed05f2..64cd9ab 100644 --- a/include/sbi/riscv_encoding.h +++ b/include/sbi/riscv_encoding.h @@ -32,6 +32,8 @@ #define MSTATUS_TVM _UL(0x00100000) #define MSTATUS_TW _UL(0x00200000) #define MSTATUS_TSR _UL(0x00400000) +#define MSTATUS_SPELP _UL(0x00800000) +#define MSTATUS_MPELP _UL(0x020000000000) #define MSTATUS32_SD _UL(0x80000000) #if __riscv_xlen == 64 #define MSTATUS_UXL _ULL(0x0000000300000000) @@ -213,6 +215,8 @@ #define ENVCFG_PBMTE (_ULL(1) << 62) #define ENVCFG_ADUE (_ULL(1) << 61) #define ENVCFG_CDE (_ULL(1) << 60) +#define ENVCFG_SSE (_ULL(1) << 3) +#define ENVCFG_LPE (_ULL(1) << 2) #define ENVCFG_CBZE (_UL(1) << 7) #define ENVCFG_CBCFE (_UL(1) << 6) #define ENVCFG_CBIE_SHIFT 4 @@ -228,6 +232,7 @@ #define CSR_USTATUS 0x000 #define CSR_UIE 0x004 #define CSR_UTVEC 0x005 +#define CSR_SSP 0x011 /* User Trap Handling (N-extension) */ #define CSR_USCRATCH 0x040 @@ -763,6 +768,7 @@ #define CAUSE_FETCH_PAGE_FAULT 0xc #define CAUSE_LOAD_PAGE_FAULT 0xd #define CAUSE_STORE_PAGE_FAULT 0xf +#define CAUSE_SW_CHECK_EXCP 0x12 #define CAUSE_FETCH_GUEST_PAGE_FAULT 0x14 #define CAUSE_LOAD_GUEST_PAGE_FAULT 0x15 #define CAUSE_VIRTUAL_INST_FAULT 0x16 diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index 81ec061..2aa6867 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -67,6 +67,9 @@ enum sbi_hart_extensions { SBI_HART_EXT_SVADE, /** Hart has Svadu extension */ SBI_HART_EXT_SVADU, + /** HART has zicfiss & zicfilp extension */ + SBI_HART_EXT_ZICFILP, + SBI_HART_EXT_ZICFISS, /** Maximum index of Hart extension */ SBI_HART_EXT_MAX, From patchwork Wed Aug 21 23:55:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 1975152 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Qnw2y7pk; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=cyu/rJa1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wq3Bb3hYyz1yf6 for ; Thu, 22 Aug 2024 09:56:06 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=nE67adIXMtv7aD/ygsPbU5HRyphQgPOTN0cR/pPaQN8=; b=Qnw2y7pkkuinJb cmR+FI/qXAMiGLzc3FU1DuPxuCoHDnk1VF2LQqRWVXYg2n8nhktS39XBYRtssZDQi1bfezhfX85rX N8+25h6nccMjqPy36TwCOWzDvKVKd4Xz+5aqXWz0aqo5Nouoojp0A/s9UO9sEcpU7toNv/uhUokNM lieS3pnTGHXBCCApPPKIeb+saKb+NeATdwGjHx16ToM9fMJGgEQf9XJnCKJ58yw985VHzMPhWsJYL mqeydmNL1RmglS+tlEReUGuVvR+084Ihr/h1P55DmpzutK9dxxMeDivRVC/iT9wh0R4WB45M1Z42G 3fJJX5awVm2DEdCA7O4g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgvBE-0000000AiBu-45fJ; Wed, 21 Aug 2024 23:55:56 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgvBA-0000000AiAY-3gyg for opensbi@lists.infradead.org; Wed, 21 Aug 2024 23:55:54 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-2020b730049so2038995ad.3 for ; Wed, 21 Aug 2024 16:55:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724284552; x=1724889352; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8CO802vhzJx96HkKfaI0kRI4b3sWztye8jLUO3nHSpw=; b=cyu/rJa1bxVtTdCdFehT6LI5P0ParqqVnCh0Ll80dtRrY6lG8UdHFhZczkwaKuQNS+ 6lwV/Xe1Xg6Ab5tUx1Uqrr0rs/6hitVMDtiwjtAbYxhHRKk9WCbQHBA8l/9QT5zUEfVy aHU4w/whcva9AEYL3/O3e/OqLrml3zoibXieI+M8ClFCXoxFb981D1BexCx5lHRAkgvm 9PA/AAZhL/jbUnQ4JjkMU+XPy1NmysPfbyZFOtsfaHxY9gS1+eyOTW1c9RqqYZzo7rIH GqbLgtqVwhXgcpv2i33QeXjsnbCLL0M8lfI6BKLgoO/XathmSdIn42Tp/0xbRoojsJzt TP7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724284552; x=1724889352; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8CO802vhzJx96HkKfaI0kRI4b3sWztye8jLUO3nHSpw=; b=K80GTJcllnHhP4H707l2Y93Es2pWBh4HTPyf8rPIMPDaRHw7Qcx084jOXUUp6mNZvV xwY8SZA6b73hWceMSvbb1rsai8P50ddFCHD7dr4s9FYcRJUNbwa6Jbzd/B9Hair464/I YuF0uK6d+Qik312e6QrBRP76rOWE0tDnfaWM3vSxk5agTuf+TRSfcrGZNPqy7UeHbzI0 RGB+/KdvEEKX5wOJQKSNJfkURedrhonzBFmhrV8X+cI63nsygUeMql8h+hdHVdvW5c3g 4lC62SN9jF071smhJsdt8UC6VpPi1g679ZBoXj3lnE9TrZDIodxPzIx0dGGKyvc7Hkus TUWA== X-Gm-Message-State: AOJu0YygHGiEJcM0rRxsq4iCkwXEP9WZ4dmlV9tlm6y+l2zxihZ/AbVI KJ+p7ND2pt4Owkd499YT1JbI6aWtU3J0rhTwnx0D+DK+1T4DwX0ZnoPhxpHTD6TkMfHmgcwt+vU 7 X-Google-Smtp-Source: AGHT+IFsEEuvdr1qO2YVT20EX+p6YOd7ouL6m3qwDLDMmQnJ9RMncW004ZvKIMJcvKwxXls+m+Xr1Q== X-Received: by 2002:a17:902:e891:b0:1fd:672f:2b34 with SMTP id d9443c01a7336-2038824f0efmr1999225ad.33.1724284551599; Wed, 21 Aug 2024 16:55:51 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2038556661csm1515495ad.24.2024.08.21.16.55.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 16:55:51 -0700 (PDT) From: Deepak Gupta To: opensbi@lists.infradead.org Cc: atishp@rivosinc.com, apatel@ventanamicro.com, Deepak Gupta Subject: [PATCH 2/3] lib: sbi: Zicfilp/Zicfiss detection and elp cfi state reflect back in status Date: Wed, 21 Aug 2024 16:55:45 -0700 Message-ID: <20240821235546.3876172-3-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240821235546.3876172-1-debug@rivosinc.com> References: <20240821235546.3876172-1-debug@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_165552_941805_9190A739 X-CRM114-Status: GOOD ( 13.25 ) X-Spam-Score: -1.9 (-) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This patch adds support for zicfilp / zicfiss detection in sbi_hart.c If zicfilp and zicfiss are detected, this patch turns on menvcfg.LPE and menvcfg.SSE Zicfilp records status of hart's ELP state in *status csr. Missing landing pad sets MPELP in mstatus. When SBI is redirecting back to S/VS/HS, SPELP is set in sstatus/vsstatus. Content analysis details: (-1.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:62c listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This patch adds support for zicfilp / zicfiss detection in sbi_hart.c If zicfilp and zicfiss are detected, this patch turns on menvcfg.LPE and menvcfg.SSE Zicfilp records status of hart's ELP state in *status csr. Missing landing pad sets MPELP in mstatus. When SBI is redirecting back to S/VS/HS, SPELP is set in sstatus/vsstatus. Signed-off-by: Deepak Gupta --- lib/sbi/sbi_hart.c | 28 ++++++++++++++++++++++++++++ lib/sbi/sbi_trap.c | 16 ++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index c366701..67a2e42 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -148,6 +148,16 @@ static void mstatus_init(struct sbi_scratch *scratch) if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SVADE)) menvcfg_val &= ~ENVCFG_ADUE; + /* + * By default allow shadow stack opreations in S/HS mode + * don't enable landing pad because supervisor may keep faulting + * due to missing landing pad. Open up a SBI interface to enable + * landing pad + */ + if (sbi_hart_has_extension(scratch, SBI_HART_EXT_ZICFISS)) { + menvcfg_val |= ENVCFG_SSE; + } + csr_write(CSR_MENVCFG, menvcfg_val); #if __riscv_xlen == 32 csr_write(CSR_MENVCFGH, menvcfg_val >> 32); @@ -680,6 +690,8 @@ const struct sbi_hart_ext_data sbi_hart_ext[] = { __SBI_HART_EXT_DATA(ssccfg, SBI_HART_EXT_SSCCFG), __SBI_HART_EXT_DATA(svade, SBI_HART_EXT_SVADE), __SBI_HART_EXT_DATA(svadu, SBI_HART_EXT_SVADU), + __SBI_HART_EXT_DATA(zicfilp, SBI_HART_EXT_ZICFILP), + __SBI_HART_EXT_DATA(zicfiss, SBI_HART_EXT_ZICFISS), }; _Static_assert(SBI_HART_EXT_MAX == array_size(sbi_hart_ext), @@ -776,6 +788,7 @@ static int hart_detect_features(struct sbi_scratch *scratch) unsigned long val, oldval; bool has_zicntr = false; int rc; + bool ssp_exist, elp_exist; /* If hart features already detected then do nothing */ if (hfeatures->detected) @@ -933,6 +946,21 @@ __pmp_skip: /* Save trap based detection of Zicntr */ has_zicntr = sbi_hart_has_extension(scratch, SBI_HART_EXT_ZICNTR); + if (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) { + val = csr_read_allowed(CSR_SSP, (unsigned long)&trap); + ssp_exist = trap.cause == 0; + if (ssp_exist) + __sbi_hart_update_extension(hfeatures, + SBI_HART_EXT_ZICFISS, true); + + csr_set(CSR_MSTATUS, MSTATUS_MPELP); + val = csr_read_clear(CSR_MSTATUS, MSTATUS_MPELP); + elp_exist = val & MSTATUS_MPELP; + if (elp_exist) + __sbi_hart_update_extension(hfeatures, + SBI_HART_EXT_ZICFILP, true); + } + /* Let platform populate extensions */ rc = sbi_platform_extensions_init(sbi_platform_thishart_ptr(), hfeatures); diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index b4f3a17..2273b3a 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -103,6 +103,7 @@ int sbi_trap_redirect(struct sbi_trap_regs *regs, const struct sbi_trap_info *trap) { ulong hstatus, vsstatus, prev_mode; + bool elp = false; #if __riscv_xlen == 32 bool prev_virt = (regs->mstatusH & MSTATUSH_MPV) ? true : false; #else @@ -116,6 +117,13 @@ int sbi_trap_redirect(struct sbi_trap_regs *regs, if (prev_mode != PRV_S && prev_mode != PRV_U) return SBI_ENOTSUPP; + /* If extension has support for CFI, clear MPELP because redirecting to VS or (H)S */ + if (sbi_hart_has_extension(sbi_scratch_thishart_ptr(), SBI_HART_EXT_ZICFILP)) { + elp = (regs->mstatus & MSTATUS_MPELP)? true: false; + /* Since redirecting, clear mpelp unconditionally */ + regs->mstatus &= ~MSTATUS_MPELP; + } + /* If exceptions came from VS/VU-mode, redirect to VS-mode if * delegated in hedeleg */ @@ -169,6 +177,10 @@ int sbi_trap_redirect(struct sbi_trap_regs *regs, /* Get VS-mode SSTATUS CSR */ vsstatus = csr_read(CSR_VSSTATUS); + /*if elp was set, set it back in vsstatus */ + if (elp) + vsstatus |= MSTATUS_SPELP; + /* Set SPP for VS-mode */ vsstatus &= ~SSTATUS_SPP; if (prev_mode == PRV_S) @@ -209,6 +221,10 @@ int sbi_trap_redirect(struct sbi_trap_regs *regs, /* Clear SIE for S-mode */ regs->mstatus &= ~MSTATUS_SIE; + + /* if elp was set, set it back in mstatus */ + if (elp) + regs->mstatus |= MSTATUS_SPELP; } return 0; From patchwork Wed Aug 21 23:55:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 1975153 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Bc/u/nIt; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=yKfLCs8l; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wq3Bb3Cksz1ydn for ; Thu, 22 Aug 2024 09:56:06 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jK/P5jVM/e6g41g8OG5NpCB45gssaiR77QAKnHUFFMo=; b=Bc/u/nItIriTv2 bZuFXRgJ3R+K6KN0X3XgxUP75pSJd7iXSkiDBeXv87/kin3xmB+rLZEE9uoPdD8UXTHphIDHukJpU 9r/4uzGIc391Dr17Y7s0jd4NZSSWwO3+opCG57UEC2Wb2RlrI4U8XdGUVVJFj4ZtJkoyNRp+6KrJt wQidPeIxXszyn8kgz9AizPBsnp23gNqYEjHEK8jMiQ/WbPXq12yrDfcn6B8YG4UxcLMOck7nNOVzz QqUqVWa+2K/WGu3UxaiOfDzeQba4Z7/g8k6yJ8ZOQI8axPuSCsJ1YQMzUXrluJuMu7gaHEegoHWGd Yo+VlMeePcROl9vTM1rA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgvBF-0000000AiCA-246A; Wed, 21 Aug 2024 23:55:57 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgvBB-0000000AiAo-3Udz for opensbi@lists.infradead.org; Wed, 21 Aug 2024 23:55:55 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-201ee6b084bso2155045ad.2 for ; Wed, 21 Aug 2024 16:55:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724284553; x=1724889353; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kAnRzds/0fIkle4p/LKrX8gORwQJ1UpA2Pk7QEuREtk=; b=yKfLCs8lQdvC4TIUBGciFdpvNkWbpngaoQVcz9DTnUNZWntLOG/OEbZijiGpRvh/uE 8hEY2dtNRQJCgUv+Y/NmXY3qh3eXXGwaOrZulOGqpkaCFL602MvDSnnUvGKyX6RTLeg8 I34R5KQ1zdA8k+aSSy9EF48Is7qri3qvddIfq4HtXNuZbwsueyqr87mjPSlG8YV6bzbk f8ZfwjEo64LHiA6mXd6PgzPkvLdR4JO6Fyc7g6Q2L1H4ostkNJfB11op0rtje95FR9UY R3LvPK/gSU7IO9VaGRySAGRQJreQ0TV8Wd9uZHay7UikShQ9YJ50UJb5f5tjZgWRJqgD lfbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724284553; x=1724889353; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kAnRzds/0fIkle4p/LKrX8gORwQJ1UpA2Pk7QEuREtk=; b=ETGJmtvdPNYtEzZ56tBf0ZjbCtmFNtB+wgmUKu7z94MZNh9/mz31gAL8mrKRLfD4bt zJSXSZXYBUwrlOoUA87qtRCghMyQqxF8+yS6lV7yA0FTN8GB3v81vDMBscMN1xco8DZb TijdgEsHEPZh4MtVv9c+S07yEPaaupM+6iqLPujAr9f2OJ7gFi7PqEN90lh0E29KKSdQ PWWCIX8D2bZHw0Lu1Frzg6yqHoTa5TTlYmZJtrS7PipU7Ux64WfoJ+7dezuMIsEV2W8B M5J+3lGr7CMx2fxjjxRCMU3a2x/hCtYCmsJ1oow8etuuwVPkPplYec+wruhdj1uCsydx xspQ== X-Gm-Message-State: AOJu0Yyiphp4FVzQYFusX3wwDtyRA/j7ytzdYMBJhZsprqOpk4D/Sczw XiDERF+QMfd7FUi4lEi24pojwPjmEBTE6HsKCR1vKYkopjaYiBinFJeTwLuh9uJAjV+JV5wyqs+ m X-Google-Smtp-Source: AGHT+IHt1fGLifGXateoZFvAgWQCmz7FXurxyMmvdojTj8oTW2N+Xd+81WouI6LHW6y5HzWOePssWw== X-Received: by 2002:a17:903:41d0:b0:1fa:2b89:f549 with SMTP id d9443c01a7336-20367bfeac6mr50689955ad.10.1724284552593; Wed, 21 Aug 2024 16:55:52 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2038556661csm1515495ad.24.2024.08.21.16.55.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 16:55:52 -0700 (PDT) From: Deepak Gupta To: opensbi@lists.infradead.org Cc: atishp@rivosinc.com, apatel@ventanamicro.com, Deepak Gupta Subject: [PATCH 3/3] lib: sbi: sw check exception delegation Date: Wed, 21 Aug 2024 16:55:46 -0700 Message-ID: <20240821235546.3876172-4-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240821235546.3876172-1-debug@rivosinc.com> References: <20240821235546.3876172-1-debug@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_165553_918297_4F3DA5EB X-CRM114-Status: UNSURE ( 7.67 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.9 (-) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: zicfiss and zicfilp introduces new exception (cause=18). Delegate this exception to S mode because cfi violations in U / S will be reported via this exception. Signed-off-by: Deepak Gupta --- lib/sbi/sbi_hart.c | 3 +++ 1 file changed, 3 insertions(+) Content analysis details: (-1.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:633 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org zicfiss and zicfilp introduces new exception (cause=18). Delegate this exception to S mode because cfi violations in U / S will be reported via this exception. Signed-off-by: Deepak Gupta Reviewed-by: Samuel Holland --- lib/sbi/sbi_hart.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 67a2e42..5bc02a1 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -234,6 +234,9 @@ static int delegate_traps(struct sbi_scratch *scratch) exceptions |= (1U << CAUSE_STORE_GUEST_PAGE_FAULT); } + /* delegate sw check exception to S */ + exceptions |= (1U << CAUSE_SW_CHECK_EXCP); + csr_write(CSR_MIDELEG, interrupts); csr_write(CSR_MEDELEG, exceptions);