From nobody Tue Feb 10 12:27:08 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 C557030DECE for ; Wed, 22 Oct 2025 23:29:53 +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=1761175797; cv=none; b=NXe+304drFV1uDEiAMraXtpliIPB9ykCcfWrLze41EwSW+UM+bzwRS9QsdHczfxLujE5p7xTYbk+XD7BBaEIt7vhiF/3xSWythmrMXhFBLH65FIL6cbAnTEGD9XIFkFNwGtAV2U7tSRFikK5Jp/9K3/WEnDH8WuDDIz2AgjZe8I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761175797; c=relaxed/simple; bh=9AtWvDKQ9q5op9YLRgkrDiWaHEAhrRbEgloHu05lQww=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=I6ThzgyCHzFUj0lNYE9jvg57fOvEefOjXipsQ0qSdgDTu8P6LbxI7yMxk1CTBGdDHuMYK1/VAO2piHHOHHoF+iumekiG6U4zqpKURVK9HN+Hn1jn0APSVPPuiUi5hCk9OjT0Jygk0TH/9/Dz6Z6CxaqjqQ4Z3WuB2np7Qzc4RGo= 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=Prbll6mU; 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="Prbll6mU" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-7a226a0798cso150616b3a.2 for ; Wed, 22 Oct 2025 16:29:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc.com; s=google; t=1761175793; x=1761780593; 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=Prbll6mU1vI2MIpiqqmRiIMlDhiQcn+TUaFuVhmIhP9Km349sm77sL5AchQZcY5TAR xvHg/0tFiWpuZkcaFGtF2pN4qUVVyNc91wZNE6/8yTuVQVIE6aAHdYuMD3QYF9hDeMZY x7FnR3eUvoggqvZjevW7xrtHIJ8MIZ2P2yb08axLCQzV+8Lj0J0pyQtXRzhHb1QHdbIA ldxf/lzEE5AuLENUCZIrNQ3R3fptlDCGVGMoDNrcD0S1qv7yOoTFdKE+kXdxMb2BwwP/ u5QayRieaRlGqiy5HcMDfXS8tM6OK6duQ5tAEMfP2Y5SgoXEqv5EE92YK4IiZaH3sKmI qKwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761175793; x=1761780593; 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=O7f3Bd033xfocStdBP3m7+47FhxPlTKWXf3XHD5EB9FEv0JQsIiMT3JVFintbmOT9r V/ExMq0/2LT+y+krv3sFKGsygmzgSbX+6GjivFoEMEkYb1iv4T8nXj8+rIh1Qff9DH/L 6kG0qP/ElJqaw/kW/89nm86xIx8OvVoFNIgGUs3bHhU+J2fvYtfvFnMZWhMtUkI9Ta1F v+3yF5uKoE7fwkpYYiQIcj1g4U4eAGgu638ObG8H0z/DnCj8w6jHHksd/iFSnTTP7Ehi iF27ivp7GFy5I7HkIqyaxYrCKcj9VKE1eCVhTyCajjF3jncrBmBn549rkrZCjWS5NtB0 Z0bQ== X-Gm-Message-State: AOJu0Yw+HoNdxZBzg4uxa9lWZ2xqwVPAe/uvMF73XOh8yU3KIcc6SbEc MMdsoLuBQ8S1zbsF5t3C/GO7H+h/iPs67chh/ZeVQIom9O/ohXs4PZBUsddRKFrjttg= X-Gm-Gg: ASbGncuY7latBJlkREip+sMz77FTpqV2Zz3IRfX7G5LiKdgyvG/fi0jfI+6D+bX/aRS DlWVdIAqPdCmDREnjGtFJICY+wQwaUHkI+kNQPQr4DRBr1s6UGiGealbqZSZxhASTR88bvtmuye W5UzHXyA4ge3AnskjIkrOZYsRBkFU3W5ECVIyd+QTUq/W/Q2TNjJ3hYTUzyYKLd5M1mMc+tbT+m OwYQbK/tLEb3yyCiYaXrH9q9Mx2I4vhPBrtNKr44iikmwexEq4tQZa2HqBXSPTBB4WJzNiXllSa p3RIdq0tLMldqUE2ST8esWJGnDc9cC8V8WkNodsLfVHYRq+8L+7DNivFwBWzgOr5VPQ7B1rWelK 5K+sx+ryjkEZb2UvjfNu4oF2TsmaZHfc3R+IIOpGUNigGq5Wewq6e9UEkjDQR56Dq1amfVs3P8T lMJKBmGrnJFw== X-Google-Smtp-Source: AGHT+IEyYaBVYRUloskvUCZ/yxzw7bPY2t7mEI/bU4QrTEjElNpmobT/VekcDiyMNALIqBN5WCBgDg== X-Received: by 2002:a05:6a00:2e1b:b0:7a2:7157:6d95 with SMTP id d2e1a72fcca58-7a2715777f0mr2234795b3a.14.1761175792856; Wed, 22 Oct 2025 16:29:52 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7a274dc12b2sm392646b3a.67.2025.10.22.16.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Oct 2025 16:29:52 -0700 (PDT) From: Deepak Gupta Date: Wed, 22 Oct 2025 16:29:33 -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: <20251022-v5_user_cfi_series-v22-7-fdaa7e4022aa@rivosinc.com> References: <20251022-v5_user_cfi_series-v22-0-fdaa7e4022aa@rivosinc.com> In-Reply-To: <20251022-v5_user_cfi_series-v22-0-fdaa7e4022aa@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