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