Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

riscv/mm: teach pte_mkwrite to manufacture shadow stack PTEs

pte_mkwrite() creates PTEs with WRITE encodings for the underlying
architecture. The underlying architecture can have two types of
writeable mappings: one that can be written using regular store
instructions, and another one that can only be written using
specialized store instructions (like shadow stack stores).
pte_mkwrite can select write PTE encoding based on VMA range (i.e.
VM_SHADOW_STACK)

Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Reviewed-by: Zong Li <zong.li@sifive.com>
Signed-off-by: Deepak Gupta <debug@rivosinc.com>
Tested-by: Andreas Korb <andreas.korb@aisec.fraunhofer.de> # QEMU, custom CVA6
Tested-by: Valentin Haudiquet <valentin.haudiquet@canonical.com>
Link: https://patch.msgid.link/20251112-v5_user_cfi_series-v23-8-b55691eacf4f@rivosinc.com
[pjw@kernel.org: cleaned up patch description]
Signed-off-by: Paul Walmsley <pjw@kernel.org>

authored by

Deepak Gupta and committed by
Paul Walmsley
c68c2ef9 f56ffb8a

+23
+7
arch/riscv/include/asm/pgtable.h
··· 451 451 452 452 /* static inline pte_t pte_mkread(pte_t pte) */ 453 453 454 + struct vm_area_struct; 455 + pte_t pte_mkwrite(pte_t pte, struct vm_area_struct *vma); 456 + #define pte_mkwrite pte_mkwrite 457 + 454 458 static inline pte_t pte_mkwrite_novma(pte_t pte) 455 459 { 456 460 return __pte(pte_val(pte) | _PAGE_WRITE); ··· 842 838 { 843 839 return pte_pmd(pte_mkyoung(pmd_pte(pmd))); 844 840 } 841 + 842 + pmd_t pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma); 843 + #define pmd_mkwrite pmd_mkwrite 845 844 846 845 static inline pmd_t pmd_mkwrite_novma(pmd_t pmd) 847 846 {
+16
arch/riscv/mm/pgtable.c
··· 163 163 return old; 164 164 } 165 165 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ 166 + 167 + pte_t pte_mkwrite(pte_t pte, struct vm_area_struct *vma) 168 + { 169 + if (vma->vm_flags & VM_SHADOW_STACK) 170 + return pte_mkwrite_shstk(pte); 171 + 172 + return pte_mkwrite_novma(pte); 173 + } 174 + 175 + pmd_t pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma) 176 + { 177 + if (vma->vm_flags & VM_SHADOW_STACK) 178 + return pmd_mkwrite_shstk(pmd); 179 + 180 + return pmd_mkwrite_novma(pmd); 181 + }