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 | 69795ca | 2019-04-18 16:51:18 +1000 | [diff] [blame] | 9 | #ifndef __ASSEMBLY__ |
| 10 | |
Christophe Leroy | de78a9c | 2019-04-18 16:51:20 +1000 | [diff] [blame] | 11 | #include <asm/pgtable.h> |
| 12 | |
Christophe Leroy | 69795ca | 2019-04-18 16:51:18 +1000 | [diff] [blame] | 13 | void setup_kup(void); |
| 14 | |
Christophe Leroy | 0fb1c25 | 2019-04-18 16:51:19 +1000 | [diff] [blame] | 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 | |
Christophe Leroy | de78a9c | 2019-04-18 16:51:20 +1000 | [diff] [blame] | 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) { } |
Michael Ellerman | 5e5be3a | 2019-04-18 16:51:25 +1000 | [diff] [blame^] | 29 | 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] | 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 | |
Christophe Leroy | 69795ca | 2019-04-18 16:51:18 +1000 | [diff] [blame] | 52 | #endif /* !__ASSEMBLY__ */ |
| 53 | |
| 54 | #endif /* _ASM_POWERPC_KUP_H_ */ |