From nobody Thu Dec 11 19:17:23 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1B1B359FB4; Fri, 5 Dec 2025 18:41:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764960111; cv=none; b=Z0Po14qRD5MgOGeig60IMAfiyMWF4jvgLDHScmfMu8odsQBR1ZzoHhvTWmETbEsOjCz+AJ/B0X78nwNFF2k4VKYSvIX0YM9YDuAjhKe7slLR9eNWZvjPnaCjwIuWjFHhfgXE4EGkXD3J7K+Sa/KEkC2vjIwP17ZAv5vMaeUQ+nk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764960111; c=relaxed/simple; bh=LAJf90nF+g60beJiG5QYxHSIluys/8oDXRemvNQeYOw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KnaGCZ0mW5rFFck3FQNer/5nnhKnjUWmZStFUF0Qm1FebrhPREEdLfsuATxtjblOsX7IPCFaJEHDVWrJ9RJFye4SpWzhBn7W+w/WF9Z8YXZqKFWcIHrc/wkZfywxwBD1SnCLIa/1ssTdgBhgiCVt52BUOMod7UBFUFANRHbdrbQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S6M5ZvQh; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S6M5ZvQh" Received: by smtp.kernel.org (Postfix) with ESMTPS id 893E2C4AF0D; Fri, 5 Dec 2025 18:41:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764960110; bh=LAJf90nF+g60beJiG5QYxHSIluys/8oDXRemvNQeYOw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=S6M5ZvQhqvVD5F0QS2ZsaZqG9/Ff5CHSPgQYbRJ23AOcs62IDM8EZVU568dQOzSkt dhiL2Vg39hqQp9mGZhr21Mn5+gr39BQVBtVELnstCb2utX1rYE+k3IsrUUrnvTI6n0 CaoWiTREC7hvqdxcV1QvqEw/Sk2ROdORtByyQJk+J4Rv68dGEiMMaIytRVUwQlyOZM /nJSderYf+Ueu8aUTw2bNmLtDyBp8AKClEvxQAAw9Ez/GwxOV51oktQysEW2I5EKXd u0vgDMnGr+iNevHiAzwdOILAevpdFcbQKd15Z/c21W9JUPCm+WZpPx2yh8g3SRuzFA y3XbLxCjo5XeA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76CA4D2F7F6; Fri, 5 Dec 2025 18:41:50 +0000 (UTC) From: Deepak Gupta via B4 Relay Date: Fri, 05 Dec 2025 10:41:45 -0800 Subject: [PATCH v25 07/28] riscv/mm: manufacture shadow stack pte Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251205-v5_user_cfi_series-v25-7-1a07c0127361@rivosinc.com> References: <20251205-v5_user_cfi_series-v25-0-1a07c0127361@rivosinc.com> In-Reply-To: <20251205-v5_user_cfi_series-v25-0-1a07c0127361@rivosinc.com> To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Lorenzo Stoakes , Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Rob Herring , Krzysztof Kozlowski , Arnd Bergmann , Christian Brauner , Peter Zijlstra , Oleg Nesterov , Eric Biederman , Kees Cook , Jonathan Corbet , Shuah Khan , Jann Horn , Conor Dooley , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Trevor Gross , Benno Lossin Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, alistair.francis@wdc.com, richard.henderson@linaro.org, jim.shu@sifive.com, andybnac@gmail.com, kito.cheng@sifive.com, charlie@rivosinc.com, atishp@rivosinc.com, evan@rivosinc.com, cleger@rivosinc.com, alexghiti@rivosinc.com, samitolvanen@google.com, broonie@kernel.org, rick.p.edgecombe@intel.com, rust-for-linux@vger.kernel.org, Zong Li , Andreas Korb , Valentin Haudiquet , Deepak Gupta X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1764960107; l=1430; i=debug@rivosinc.com; s=20251023; h=from:subject:message-id; bh=xg60sqaex1DpMRqlc6kxZaEeka4CnULn8wlCIX4f9Wk=; b=FeUvykLJrfx/Bx62YVwLSBRd4tiOMI1wQodP4x5CTmbkL5Ei2JxUy9gzi6n8H67+hQBt/aKLb vRuIFYVQ7I6DPsrGaXuPK9GKzxZw3Ry38RV+cpNV9qneCbZdDnsoUhr X-Developer-Key: i=debug@rivosinc.com; a=ed25519; pk=O37GQv1thBhZToXyQKdecPDhtWVbEDRQ0RIndijvpjk= X-Endpoint-Received: by B4 Relay for debug@rivosinc.com/20251023 with auth_id=553 X-Original-From: Deepak Gupta Reply-To: debug@rivosinc.com From: Deepak Gupta This patch implements creating shadow stack pte (on riscv). Creating shadow stack PTE on riscv means that clearing RWX and then setting W=3D1. Reviewed-by: Alexandre Ghiti Reviewed-by: Zong Li Tested-by: Andreas Korb Tested-by: Valentin Haudiquet Signed-off-by: Deepak Gupta --- arch/riscv/include/asm/pgtable.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgta= ble.h index 4c4057a2550e..e4eb4657e1b6 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -425,6 +425,11 @@ static inline pte_t pte_mkwrite_novma(pte_t pte) return __pte(pte_val(pte) | _PAGE_WRITE); } =20 +static inline pte_t pte_mkwrite_shstk(pte_t pte) +{ + return __pte((pte_val(pte) & ~(_PAGE_LEAF)) | _PAGE_WRITE); +} + /* static inline pte_t pte_mkexec(pte_t pte) */ =20 static inline pte_t pte_mkdirty(pte_t pte) @@ -765,6 +770,11 @@ static inline pmd_t pmd_mkwrite_novma(pmd_t pmd) return pte_pmd(pte_mkwrite_novma(pmd_pte(pmd))); } =20 +static inline pmd_t pmd_mkwrite_shstk(pmd_t pte) +{ + return __pmd((pmd_val(pte) & ~(_PAGE_LEAF)) | _PAGE_WRITE); +} + static inline pmd_t pmd_wrprotect(pmd_t pmd) { return pte_pmd(pte_wrprotect(pmd_pte(pmd))); --=20 2.43.0