1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_KUP_H_
3 #define _ASM_POWERPC_KUP_H_
7 #define KUAP_READ_WRITE (KUAP_READ | KUAP_WRITE)
9 #ifdef CONFIG_PPC_BOOK3S_64
10 #include <asm/book3s/64/kup-radix.h>
13 #include <asm/nohash/32/kup-8xx.h>
15 #ifdef CONFIG_PPC_BOOK3S_32
16 #include <asm/book3s/32/kup.h>
20 #ifndef CONFIG_PPC_KUAP
21 .macro kuap_save_and_lock sp, thread, gpr1, gpr2, gpr3
24 .macro kuap_restore sp, current, gpr1, gpr2, gpr3
27 .macro kuap_restore_amr gpr
30 .macro kuap_check current, gpr
33 .macro kuap_check_amr gpr1, gpr2
38 #else /* !__ASSEMBLY__ */
40 #include <asm/pgtable.h>
44 #ifdef CONFIG_PPC_KUEP
45 void setup_kuep(bool disabled);
47 static inline void setup_kuep(bool disabled) { }
48 #endif /* CONFIG_PPC_KUEP */
50 #ifdef CONFIG_PPC_KUAP
51 void setup_kuap(bool disabled);
53 static inline void setup_kuap(bool disabled) { }
56 bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
61 static inline void kuap_check_amr(void) { }
64 * book3s/64/kup-radix.h defines these functions for the !KUAP case to flush
65 * the L1D cache after user accesses. Only include the empty stubs for other
68 #ifndef CONFIG_PPC_BOOK3S_64
69 static inline void allow_user_access(void __user *to, const void __user *from,
70 unsigned long size, unsigned long dir) { }
71 static inline void prevent_user_access(void __user *to, const void __user *from,
72 unsigned long size, unsigned long dir) { }
73 #endif /* CONFIG_PPC_BOOK3S_64 */
74 #endif /* CONFIG_PPC_KUAP */
76 static inline void allow_read_from_user(const void __user *from, unsigned long size)
78 allow_user_access(NULL, from, size, KUAP_READ);
81 static inline void allow_write_to_user(void __user *to, unsigned long size)
83 allow_user_access(to, NULL, size, KUAP_WRITE);
86 static inline void allow_read_write_user(void __user *to, const void __user *from,
89 allow_user_access(to, from, size, KUAP_READ_WRITE);
92 static inline void prevent_read_from_user(const void __user *from, unsigned long size)
94 prevent_user_access(NULL, from, size, KUAP_READ);
97 static inline void prevent_write_to_user(void __user *to, unsigned long size)
99 prevent_user_access(to, NULL, size, KUAP_WRITE);
102 static inline void prevent_read_write_user(void __user *to, const void __user *from,
105 prevent_user_access(to, from, size, KUAP_READ_WRITE);
108 #endif /* !__ASSEMBLY__ */
110 #endif /* _ASM_POWERPC_KUAP_H_ */