xref: /openbmc/linux/arch/parisc/include/asm/kfence.h (revision 7b7090b4)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * PA-RISC KFENCE support.
4  *
5  * Copyright (C) 2021, Helge Deller <deller@gmx.de>
6  */
7 
8 #ifndef _ASM_PARISC_KFENCE_H
9 #define _ASM_PARISC_KFENCE_H
10 
11 #include <linux/kfence.h>
12 
13 #include <asm/pgtable.h>
14 #include <asm/tlbflush.h>
15 
16 static inline bool arch_kfence_init_pool(void)
17 {
18 	return true;
19 }
20 
21 /* Protect the given page and flush TLB. */
22 static inline bool kfence_protect_page(unsigned long addr, bool protect)
23 {
24 	pte_t *pte = virt_to_kpte(addr);
25 
26 	if (WARN_ON(!pte))
27 		return false;
28 
29 	/*
30 	 * We need to avoid IPIs, as we may get KFENCE allocations or faults
31 	 * with interrupts disabled.
32 	 */
33 
34 	if (protect)
35 		set_pte(pte, __pte(pte_val(*pte) & ~_PAGE_PRESENT));
36 	else
37 		set_pte(pte, __pte(pte_val(*pte) | _PAGE_PRESENT));
38 
39 	flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
40 
41 	return true;
42 }
43 
44 #endif /* _ASM_PARISC_KFENCE_H */
45