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 |
Christophe Leroy | 2679f9b | 2019-03-11 08:30:34 +0000 | [diff] [blame] | 8 | #ifdef CONFIG_PPC_8xx |
| 9 | #include <asm/nohash/32/kup-8xx.h> |
| 10 | #endif |
Christophe Leroy | 31ed2b1 | 2019-03-11 08:30:35 +0000 | [diff] [blame] | 11 | #ifdef CONFIG_PPC_BOOK3S_32 |
| 12 | #include <asm/book3s/32/kup.h> |
| 13 | #endif |
Michael Ellerman | 890274c | 2019-04-18 16:51:24 +1000 | [diff] [blame] | 14 | |
Christophe Leroy | e2fb9f5 | 2019-03-11 08:30:31 +0000 | [diff] [blame] | 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__ */ |
Christophe Leroy | 69795ca | 2019-04-18 16:51:18 +1000 | [diff] [blame] | 29 | |
Christophe Leroy | de78a9c | 2019-04-18 16:51:20 +1000 | [diff] [blame] | 30 | #include <asm/pgtable.h> |
| 31 | |
Christophe Leroy | 69795ca | 2019-04-18 16:51:18 +1000 | [diff] [blame] | 32 | void setup_kup(void); |
| 33 | |
Christophe Leroy | 0fb1c25 | 2019-04-18 16:51:19 +1000 | [diff] [blame] | 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 | |
Christophe Leroy | de78a9c | 2019-04-18 16:51:20 +1000 | [diff] [blame] | 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) { } |
Michael Ellerman | 5e5be3a | 2019-04-18 16:51:25 +1000 | [diff] [blame] | 48 | 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] | 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 | |
Christophe Leroy | 69795ca | 2019-04-18 16:51:18 +1000 | [diff] [blame] | 71 | #endif /* !__ASSEMBLY__ */ |
| 72 | |
| 73 | #endif /* _ASM_POWERPC_KUP_H_ */ |