xref: /openbmc/linux/arch/powerpc/include/asm/kup.h (revision b8d312aa)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_KUP_H_
3 #define _ASM_POWERPC_KUP_H_
4 
5 #ifdef CONFIG_PPC64
6 #include <asm/book3s/64/kup-radix.h>
7 #endif
8 #ifdef CONFIG_PPC_8xx
9 #include <asm/nohash/32/kup-8xx.h>
10 #endif
11 #ifdef CONFIG_PPC_BOOK3S_32
12 #include <asm/book3s/32/kup.h>
13 #endif
14 
15 #ifdef __ASSEMBLY__
16 #ifndef CONFIG_PPC_KUAP
17 .macro kuap_save_and_lock	sp, thread, gpr1, gpr2, gpr3
18 .endm
19 
20 .macro kuap_restore	sp, current, gpr1, gpr2, gpr3
21 .endm
22 
23 .macro kuap_check	current, gpr
24 .endm
25 
26 #endif
27 
28 #else /* !__ASSEMBLY__ */
29 
30 #include <asm/pgtable.h>
31 
32 void setup_kup(void);
33 
34 #ifdef CONFIG_PPC_KUEP
35 void setup_kuep(bool disabled);
36 #else
37 static inline void setup_kuep(bool disabled) { }
38 #endif /* CONFIG_PPC_KUEP */
39 
40 #ifdef CONFIG_PPC_KUAP
41 void setup_kuap(bool disabled);
42 #else
43 static inline void setup_kuap(bool disabled) { }
44 static inline void allow_user_access(void __user *to, const void __user *from,
45 				     unsigned long size) { }
46 static inline void prevent_user_access(void __user *to, const void __user *from,
47 				       unsigned long size) { }
48 static inline bool bad_kuap_fault(struct pt_regs *regs, bool is_write) { return false; }
49 #endif /* CONFIG_PPC_KUAP */
50 
51 static inline void allow_read_from_user(const void __user *from, unsigned long size)
52 {
53 	allow_user_access(NULL, from, size);
54 }
55 
56 static inline void allow_write_to_user(void __user *to, unsigned long size)
57 {
58 	allow_user_access(to, NULL, size);
59 }
60 
61 static inline void prevent_read_from_user(const void __user *from, unsigned long size)
62 {
63 	prevent_user_access(NULL, from, size);
64 }
65 
66 static inline void prevent_write_to_user(void __user *to, unsigned long size)
67 {
68 	prevent_user_access(to, NULL, size);
69 }
70 
71 #endif /* !__ASSEMBLY__ */
72 
73 #endif /* _ASM_POWERPC_KUP_H_ */
74