xref: /linux/arch/riscv/include/asm/kfence.h (revision 88872790923e2d80edf29a00b4e440f1473fa8f5)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef _ASM_RISCV_KFENCE_H
4 #define _ASM_RISCV_KFENCE_H
5 
6 #include <linux/kfence.h>
7 #include <linux/pfn.h>
8 #include <asm-generic/pgalloc.h>
9 #include <asm/pgtable.h>
10 
11 static inline bool arch_kfence_init_pool(void)
12 {
13 	return true;
14 }
15 
16 static inline bool kfence_protect_page(unsigned long addr, bool protect)
17 {
18 	pte_t *pte = virt_to_kpte(addr);
19 
20 	if (protect)
21 		set_pte(pte, __pte(pte_val(*pte) & ~_PAGE_PRESENT));
22 	else
23 		set_pte(pte, __pte(pte_val(*pte) | _PAGE_PRESENT));
24 
25 	flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
26 
27 	return true;
28 }
29 
30 #endif /* _ASM_RISCV_KFENCE_H */
31