From nobody Mon Oct 20 09:41:48 2025 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (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 925C6340D9F for ; Wed, 15 Oct 2025 18:13:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760552041; cv=none; b=VhYiYGxP5XYkjU1MTeV5u+rKi31y1CYb16ZLrmlPfg3yckwE4F0AiENajHXn5smJ0+ecLH8E5Oe7rl1iaEcsqq0+9dtJl4HMjCIjy55Hg/JdQSl52jkRp4HrDlyDPARHy7Dus+3lLiTdZebvXM5DQeMx80y8nwsquSZdjr8eth4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760552041; c=relaxed/simple; bh=9AtWvDKQ9q5op9YLRgkrDiWaHEAhrRbEgloHu05lQww=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iKr+NrSvbvIHQiQvIWIMrzIggtYpdFeML8hXAcDgzkv4SPf2umUkLKeiA4Ke+oEyBYh+dSYM+mMVR7+JCQs+cvZWmEIqGDJrQ/tpFkJONXpD2ecBzFcezbFdBnNTa12w9/SgXlFIdX99sTvhzp82PL5KSvIAPubXFExJX4hvArQ= 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=Exwb/QXP; arc=none smtp.client-ip=209.85.215.170 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="Exwb/QXP" Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-b62e7221351so5671521a12.1 for ; Wed, 15 Oct 2025 11:13:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc.com; s=google; t=1760552039; x=1761156839; 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=Exwb/QXPbXfTOGKP7tu8Nf+GnckXTCgO3BYpd7Cp6ZZmF4JBSu7v65V7OQg5628JQh mrfP5+WbGWFkv8usSO0tOTQksriHHmb5tatsmPN/qWRpuZ0rZBv2ZNzgaURgJ9O8asIX oQqa59/xel+mVz/UP9DgoS3liRs8q3sI8sr8vud2xzFq2GZ9oWJnBa1+Jmj2LCarrFrw +H+ZAu3u2G7oy0u/rAi7yXtNm/xumj99wekv3M6e1Fc7YewqajUcJClxNcSqenB0HZU2 pWYCRNiKDBePIm4hyRYQMOTlANSE8cU3pE8w8EKAQ13buypysM+OTiB333atTIkCOS2O Smgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760552039; x=1761156839; 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=mbwLPydt45obCrR4j+4m28fyCNsyf/sJJb7FussvH1QEt/tIqmLscznkXcWy05M+Y+ moplCkG4Og+Yi5GLZ4HnUKaR/z3ZZzCp40oEUS3ExgWyH6hVvQbApyzldiNADvzaSY5R D3DJLct3eCig4nwYnaCUrbdvvhSCJk+ovF0Z5uS9XFF5CX6xRa1pPbw87X0YrddR+H2j lO/LiIinQ9gkX9zmNozNJhneYNkVAX8vj55nwfOw895njDQO3QfuPS5nz5DjNR96pJD2 9zv+gk0SCnRGJh+dMMHVJK4JOEFGD7o6lVEIsK7xru8tO9C3Q/UHTUweAp5S5EWj2YVw 2wFQ== X-Gm-Message-State: AOJu0YyERqvZQsEYuer31WQrMoviJa75txWiJ9v/7gy5pjrAUw+abOXE 01CQQv5HIaq0tWuDfQLIlnIwIopmSDkZ/WEBtSTT2dboFX3YE9uDtcB7C70lrPsNXfs= X-Gm-Gg: ASbGncsZNpucpwpwxFcySXPKsGVCx2s8x3T2WeeqEqs6zSglYZ2XvZpc/jwHuUGedBr yyTXDnXKcZp7lWdsLjNkTGCoUQesdHs4W9bwyv8RNOAqC0D34con/zWnoTmNXI5v+4grjJfiJAQ RPSdKSrrTWoNCdxwthdHn+mORab6CbuLsYfxjp+rnb4rD+W6KlChJGlIOGKIOrh7n2N/rB+21KE GG7tWUQjfBcyfIV437VhqLxFtFYna3Ma+9HquQdCS90+zUJu9erDR8x5xQKaCFV7XFaFFO6OdqF 8znZMujVVkvwidpLIuEVWdMYrPcw9YvS8qcO36xxTNIiJJES9gwp+524fZxv3k8dkf4uGIgxIiW CsyERyEytvqJ9tFJJ599FGUaRmhRpc0o3wBc+sSj+KzMhpG5XHQI= X-Google-Smtp-Source: AGHT+IF7+0siZoxu9qB67nOXjy9vTyzrCE83G46axDJgPfnYJq92ADj9EdTAyl+KZI2DWODagqgyog== X-Received: by 2002:a17:902:e786:b0:26e:7468:8a99 with SMTP id d9443c01a7336-290272c18e1mr357750345ad.36.1760552038791; Wed, 15 Oct 2025 11:13:58 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2909930a72esm3126625ad.21.2025.10.15.11.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Oct 2025 11:13:58 -0700 (PDT) From: Deepak Gupta Date: Wed, 15 Oct 2025 11:13:39 -0700 Subject: [PATCH v21 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: <20251015-v5_user_cfi_series-v21-7-6a07856e90e7@rivosinc.com> References: <20251015-v5_user_cfi_series-v21-0-6a07856e90e7@rivosinc.com> In-Reply-To: <20251015-v5_user_cfi_series-v21-0-6a07856e90e7@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