Christophe Leroy | 69795ca | 2019-04-18 16:51:18 +1000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | #ifndef _ASM_POWERPC_KUP_H_ |
| 3 | #define _ASM_POWERPC_KUP_H_ |
| 4 | |
Michael Ellerman | 890274c | 2019-04-18 16:51:24 +1000 | [diff] [blame] | 5 | #ifdef CONFIG_PPC64 |
| 6 | #include <asm/book3s/64/kup-radix.h> |
| 7 | #endif |
| 8 | |
Christophe Leroy | e2fb9f5 | 2019-03-11 08:30:31 +0000 | [diff] [blame^] | 9 | #ifdef __ASSEMBLY__ |
| 10 | #ifndef CONFIG_PPC_KUAP |
| 11 | .macro kuap_save_and_lock sp, thread, gpr1, gpr2, gpr3 |
| 12 | .endm |
| 13 | |
| 14 | .macro kuap_restore sp, current, gpr1, gpr2, gpr3 |
| 15 | .endm |
| 16 | |
| 17 | .macro kuap_check current, gpr |
| 18 | .endm |
| 19 | |
| 20 | #endif |
| 21 | |
| 22 | #else /* !__ASSEMBLY__ */ |
Christophe Leroy | 69795ca | 2019-04-18 16:51:18 +1000 | [diff] [blame] | 23 | |
Christophe Leroy | de78a9c | 2019-04-18 16:51:20 +1000 | [diff] [blame] | 24 | #include <asm/pgtable.h> |
| 25 | |
Christophe Leroy | 69795ca | 2019-04-18 16:51:18 +1000 | [diff] [blame] | 26 | void setup_kup(void); |
| 27 | |
Christophe Leroy | 0fb1c25 | 2019-04-18 16:51:19 +1000 | [diff] [blame] | 28 | #ifdef CONFIG_PPC_KUEP |
| 29 | void setup_kuep(bool disabled); |
| 30 | #else |
| 31 | static inline void setup_kuep(bool disabled) { } |
| 32 | #endif /* CONFIG_PPC_KUEP */ |
| 33 | |
Christophe Leroy | de78a9c | 2019-04-18 16:51:20 +1000 | [diff] [blame] | 34 | #ifdef CONFIG_PPC_KUAP |
| 35 | void setup_kuap(bool disabled); |
| 36 | #else |
| 37 | static inline void setup_kuap(bool disabled) { } |
| 38 | static inline void allow_user_access(void __user *to, const void __user *from, |
| 39 | unsigned long size) { } |
| 40 | static inline void prevent_user_access(void __user *to, const void __user *from, |
| 41 | unsigned long size) { } |
Michael Ellerman | 5e5be3a | 2019-04-18 16:51:25 +1000 | [diff] [blame] | 42 | static inline bool bad_kuap_fault(struct pt_regs *regs, bool is_write) { return false; } |
Christophe Leroy | de78a9c | 2019-04-18 16:51:20 +1000 | [diff] [blame] | 43 | #endif /* CONFIG_PPC_KUAP */ |
| 44 | |
| 45 | static inline void allow_read_from_user(const void __user *from, unsigned long size) |
| 46 | { |
| 47 | allow_user_access(NULL, from, size); |
| 48 | } |
| 49 | |
| 50 | static inline void allow_write_to_user(void __user *to, unsigned long size) |
| 51 | { |
| 52 | allow_user_access(to, NULL, size); |
| 53 | } |
| 54 | |
| 55 | static inline void prevent_read_from_user(const void __user *from, unsigned long size) |
| 56 | { |
| 57 | prevent_user_access(NULL, from, size); |
| 58 | } |
| 59 | |
| 60 | static inline void prevent_write_to_user(void __user *to, unsigned long size) |
| 61 | { |
| 62 | prevent_user_access(to, NULL, size); |
| 63 | } |
| 64 | |
Christophe Leroy | 69795ca | 2019-04-18 16:51:18 +1000 | [diff] [blame] | 65 | #endif /* !__ASSEMBLY__ */ |
| 66 | |
| 67 | #endif /* _ASM_POWERPC_KUP_H_ */ |