powerpc/mm: Detect bad KUAP faults
[linux-2.6-block.git] / arch / powerpc / include / asm / kup.h
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
9 #ifndef __ASSEMBLY__
10
11 #include <asm/pgtable.h>
12
13 void setup_kup(void);
14
15 #ifdef CONFIG_PPC_KUEP
16 void setup_kuep(bool disabled);
17 #else
18 static inline void setup_kuep(bool disabled) { }
19 #endif /* CONFIG_PPC_KUEP */
20
21 #ifdef CONFIG_PPC_KUAP
22 void setup_kuap(bool disabled);
23 #else
24 static inline void setup_kuap(bool disabled) { }
25 static inline void allow_user_access(void __user *to, const void __user *from,
26                                      unsigned long size) { }
27 static inline void prevent_user_access(void __user *to, const void __user *from,
28                                        unsigned long size) { }
29 static inline bool bad_kuap_fault(struct pt_regs *regs, bool is_write) { return false; }
30 #endif /* CONFIG_PPC_KUAP */
31
32 static inline void allow_read_from_user(const void __user *from, unsigned long size)
33 {
34         allow_user_access(NULL, from, size);
35 }
36
37 static inline void allow_write_to_user(void __user *to, unsigned long size)
38 {
39         allow_user_access(to, NULL, size);
40 }
41
42 static inline void prevent_read_from_user(const void __user *from, unsigned long size)
43 {
44         prevent_user_access(NULL, from, size);
45 }
46
47 static inline void prevent_write_to_user(void __user *to, unsigned long size)
48 {
49         prevent_user_access(to, NULL, size);
50 }
51
52 #endif /* !__ASSEMBLY__ */
53
54 #endif /* _ASM_POWERPC_KUP_H_ */