From nobody Tue Feb 10 23:14:54 2026 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83DCA333749 for ; Mon, 20 Oct 2025 20:53:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760993632; cv=none; b=Kk5SxqNGKJonp3T2VsghsZLMFbYfh26yq+WrU0X8cHyfJRYsUbkwVaqBHtTzwTzTej68cHgAARXcLgWf3ou6+IH01g4wk+os8gUG0pDMVlBBS+eTQ8UfsPv7fKOfEJE16Hhc8Gae+Ukmfzl1EX9JrM7F/suiJdRFxKMU+5gVxpE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760993632; c=relaxed/simple; bh=9AtWvDKQ9q5op9YLRgkrDiWaHEAhrRbEgloHu05lQww=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=t1OxEI72N2HGVjzpriZ0G/oJvUqRq18OI679rzAfwZGx5XiZGY5SJeaF3wJ+TpS/IgsCRhcavCDdB+p2pYM3UiIhhgr7+gPn902FBPI2lNelS5EVHTdemOav5iYwFqJA8Pv2EUf7EyJdfm36oHlmhTxjfJxeljl3Myr0I4V9Ca8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc.com header.i=@rivosinc.com header.b=crbd1l7h; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc.com header.i=@rivosinc.com header.b="crbd1l7h" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-7a23208a0c2so1747579b3a.0 for ; Mon, 20 Oct 2025 13:53:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc.com; s=google; t=1760993630; x=1761598430; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=oeDKcuIcO6+2FhxyceVVS2WWiuktyVdq1WpyUni2wlA=; b=crbd1l7hj83HVBsdtXuvzQjL1uuAYwffs6KAY1iIEUqnMfXZ2RzDJA66c/Yg/6c2p5 3oDphni688aLzx4rCr1Tb8tNbSJfNEqR81ilr9l7LTfcK+ueJQDpxNVl/j3E9aklCBxp P/48WK6bnN5kOi3SjzPZ7fKr9WzqaEmBPIHZx8H0/Xsy+12GNXCdfo/ymgN3TOsbiOo1 8sdPuCLb7DSHej6chTQqKkvtKqA3QG8DMUcEQT7a1kXkN/6Aq7Udv9X1dr1d1J6opY7L 9tWRYVKRdWsDbrdQstNM4vBQ19laKAat8XKKOpMMCP7BLV+dRQwCxOOrFe9X7KSiqevp zn1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760993630; x=1761598430; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oeDKcuIcO6+2FhxyceVVS2WWiuktyVdq1WpyUni2wlA=; b=TtKWoe8L8xHe9UtoShLL821VAIGmg2kLds7g1q1mnf4LdHlRtpnPrp9JaK55BDgYDS E+4NxfDWMrVXbCDY21Ko3bT9KTkHmgQkacIt0xD6RTagxv9CRRRV47Vj2TLYJixAxfzz 3ctbp+ZwcyK3EPz4Hy8kKhjGZ1XbX0pqdLy8gjENCBhJTRybW36jOAho0Ap/sKkC5VlC BLYzMNjZmFJQB41GbkwkMI3KahjvqnttfTffdpHnpyA9VIMYIhAhuKUBJNsrOPsB8XUc srUxkhJkt9JKSJK9maI9s/Hm9QMiolhUFQWUY36qwJzoqC7OaRvNNdZ60oE/BXJekcix j5kg== X-Gm-Message-State: AOJu0Ywhn1squXIf+/jneSfbzS5UFte0ZtLwH3XTeLIl564d9kAzIvbD 2tRzUQcvJsgqGQpMaZcFFwucqnKKL8+TOcFBV0+ISfCh0y+QSG0k/f/nAYJ/X+R/B84QMRKcKCz TEhtS X-Gm-Gg: ASbGncuvoDMzQtqHFIv53YA9gfE4GPhIfXXa1uZUpUkRaUbCU05tyDpDXcsy8egIc2L SYY0nrlGS5+brgVQrw/nKsZjCKhskDeX/ILZXCsBlXJc4L0Aa1FVK3ovlumtJGyRECL9Xfa5Uum YYGn/0oEnndrdfH9HzqlYf/2e+wTR1zdcA5tDEjJxLZp5aUZObHmDvqa9hKcWA2QyZamwxiRla4 +aWfyQs9muFk0E5UZ19rVH8NXXzyALXR4SqBs4rgkr9HjrP73FmZTQ5lyPEYR3VAPdfzidlGPP6 vRUpslM9o3j8OsLH1P2IKzART8BH2/AcOVBFtlimuUiYCZxXB2gd3VO/dcyblwU+2RNLbA+JF02 TSBFS+zx7Am9lLC+wmrpABUx7Sa8t1l0r618P/Vv/bRhnBQx41UVh3O0FIHnV0CmLjuobAw8LTX JmrIf0p01qtDkzbREqNsYJ X-Google-Smtp-Source: AGHT+IFyzyRYR8N4pw/RqABJpFBkHAgssztpR2AfShjzj8U9HBjqzgn01yskrDk53sXzLiQsCgAq5A== X-Received: by 2002:a05:6a00:21c4:b0:780:f6db:b1af with SMTP id d2e1a72fcca58-7a220acb6a1mr17244647b3a.16.1760993629790; Mon, 20 Oct 2025 13:53:49 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7a22ff1591dsm9453867b3a.7.2025.10.20.13.53.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Oct 2025 13:53:49 -0700 (PDT) From: Deepak Gupta Date: Mon, 20 Oct 2025 13:53:36 -0700 Subject: [PATCH v22 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: <20251020-v5_user_cfi_series-v22-7-9ae5510d1c6f@rivosinc.com> References: <20251020-v5_user_cfi_series-v22-0-9ae5510d1c6f@rivosinc.com> In-Reply-To: <20251020-v5_user_cfi_series-v22-0-9ae5510d1c6f@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 , Deepak Gupta X-Mailer: b4 0.13.0 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 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