1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_KUP_H_
3 #define _ASM_POWERPC_KUP_H_
7 #define KUAP_READ_WRITE (KUAP_READ | KUAP_WRITE)
9 #ifdef CONFIG_PPC_BOOK3S_64
10 #include <asm/book3s/64/kup.h>
14 #include <asm/nohash/32/kup-8xx.h>
17 #ifdef CONFIG_PPC_BOOK3S_32
18 #include <asm/book3s/32/kup.h>
22 #ifndef CONFIG_PPC_KUAP
23 .macro kuap_check_amr gpr1, gpr2
28 #else /* !__ASSEMBLY__ */
30 extern bool disable_kuep;
31 extern bool disable_kuap;
33 #include <linux/pgtable.h>
35 #ifdef CONFIG_PPC_KUEP
36 void setup_kuep(bool disabled);
38 static inline void setup_kuep(bool disabled) { }
39 #endif /* CONFIG_PPC_KUEP */
41 #ifndef CONFIG_PPC_BOOK3S_32
42 static inline void kuep_lock(void) { }
43 static inline void kuep_unlock(void) { }
46 #ifdef CONFIG_PPC_KUAP
47 void setup_kuap(bool disabled);
49 static inline void setup_kuap(bool disabled) { }
52 bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
57 static inline void kuap_assert_locked(void) { }
58 static inline void kuap_save_and_lock(struct pt_regs *regs) { }
59 static inline void kuap_user_restore(struct pt_regs *regs) { }
60 static inline void kuap_kernel_restore(struct pt_regs *regs, unsigned long amr) { }
62 static inline unsigned long kuap_get_and_assert_locked(void)
68 * book3s/64/kup-radix.h defines these functions for the !KUAP case to flush
69 * the L1D cache after user accesses. Only include the empty stubs for other
72 #ifndef CONFIG_PPC_BOOK3S_64
73 static inline void allow_user_access(void __user *to, const void __user *from,
74 unsigned long size, unsigned long dir) { }
75 static inline void prevent_user_access(unsigned long dir) { }
76 static inline unsigned long prevent_user_access_return(void) { return 0UL; }
77 static inline void restore_user_access(unsigned long flags) { }
78 #endif /* CONFIG_PPC_BOOK3S_64 */
79 #endif /* CONFIG_PPC_KUAP */
81 static __always_inline void setup_kup(void)
83 setup_kuep(disable_kuep);
84 setup_kuap(disable_kuap);
87 static inline void allow_read_from_user(const void __user *from, unsigned long size)
90 allow_user_access(NULL, from, size, KUAP_READ);
93 static inline void allow_write_to_user(void __user *to, unsigned long size)
95 allow_user_access(to, NULL, size, KUAP_WRITE);
98 static inline void allow_read_write_user(void __user *to, const void __user *from,
102 allow_user_access(to, from, size, KUAP_READ_WRITE);
105 static inline void prevent_read_from_user(const void __user *from, unsigned long size)
107 prevent_user_access(KUAP_READ);
110 static inline void prevent_write_to_user(void __user *to, unsigned long size)
112 prevent_user_access(KUAP_WRITE);
115 static inline void prevent_read_write_user(void __user *to, const void __user *from,
118 prevent_user_access(KUAP_READ_WRITE);
121 static inline void prevent_current_access_user(void)
123 prevent_user_access(KUAP_READ_WRITE);
126 static inline void prevent_current_read_from_user(void)
128 prevent_user_access(KUAP_READ);
131 static inline void prevent_current_write_to_user(void)
133 prevent_user_access(KUAP_WRITE);
136 #endif /* !__ASSEMBLY__ */
138 #endif /* _ASM_POWERPC_KUAP_H_ */