xref: /linux/arch/riscv/include/asm/kfence.h (revision bba2c3615bd6cfee7456d1130f2e6b01b3f4e9ba)
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/cacheflush.h>
10 #include <asm/pgtable.h>
11 
12 static inline bool arch_kfence_init_pool(void)
13 {
14 	return true;
15 }
16 
17 static inline bool kfence_protect_page(unsigned long addr, bool protect)
18 {
19 	pte_t *pte = virt_to_kpte(addr);
20 
21 	if (protect) {
22 		set_pte(pte, __pte(pte_val(ptep_get(pte)) & ~_PAGE_PRESENT));
23 	} else {
24 		set_pte(pte, __pte(pte_val(ptep_get(pte)) | _PAGE_PRESENT));
25 		mark_new_valid_map();
26 	}
27 
28 	preempt_disable();
29 	local_flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
30 	preempt_enable();
31 
32 	return true;
33 }
34 
35 #endif /* _ASM_RISCV_KFENCE_H */
36