147513f24SLiu Shixin /* SPDX-License-Identifier: GPL-2.0 */ 247513f24SLiu Shixin 347513f24SLiu Shixin #ifndef _ASM_RISCV_KFENCE_H 447513f24SLiu Shixin #define _ASM_RISCV_KFENCE_H 547513f24SLiu Shixin 647513f24SLiu Shixin #include <linux/kfence.h> 747513f24SLiu Shixin #include <linux/pfn.h> 847513f24SLiu Shixin #include <asm-generic/pgalloc.h> 947513f24SLiu Shixin #include <asm/pgtable.h> 1047513f24SLiu Shixin arch_kfence_init_pool(void)1147513f24SLiu Shixinstatic inline bool arch_kfence_init_pool(void) 1247513f24SLiu Shixin { 1347513f24SLiu Shixin return true; 1447513f24SLiu Shixin } 1547513f24SLiu Shixin kfence_protect_page(unsigned long addr,bool protect)1647513f24SLiu Shixinstatic inline bool kfence_protect_page(unsigned long addr, bool protect) 1747513f24SLiu Shixin { 1847513f24SLiu Shixin pte_t *pte = virt_to_kpte(addr); 1947513f24SLiu Shixin 2047513f24SLiu Shixin if (protect) 21e0316069SAlexandre Ghiti set_pte(pte, __pte(pte_val(ptep_get(pte)) & ~_PAGE_PRESENT)); 2247513f24SLiu Shixin else 23e0316069SAlexandre Ghiti set_pte(pte, __pte(pte_val(ptep_get(pte)) | _PAGE_PRESENT)); 2447513f24SLiu Shixin 25*6f796a6aSAlexandre Ghiti preempt_disable(); 26*6f796a6aSAlexandre Ghiti local_flush_tlb_kernel_range(addr, addr + PAGE_SIZE); 27*6f796a6aSAlexandre Ghiti preempt_enable(); 2847513f24SLiu Shixin 2947513f24SLiu Shixin return true; 3047513f24SLiu Shixin } 3147513f24SLiu Shixin 3247513f24SLiu Shixin #endif /* _ASM_RISCV_KFENCE_H */ 33