blob: 043c800ec5fbb7df8a9804e90598767641decadb [file] [log] [blame]
Christophe Leroy69795ca2019-04-18 16:51:18 +10001/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _ASM_POWERPC_KUP_H_
3#define _ASM_POWERPC_KUP_H_
4
Michael Ellerman890274c2019-04-18 16:51:24 +10005#ifdef CONFIG_PPC64
6#include <asm/book3s/64/kup-radix.h>
7#endif
Christophe Leroy2679f9b2019-03-11 08:30:34 +00008#ifdef CONFIG_PPC_8xx
9#include <asm/nohash/32/kup-8xx.h>
10#endif
Michael Ellerman890274c2019-04-18 16:51:24 +100011
Christophe Leroye2fb9f52019-03-11 08:30:31 +000012#ifdef __ASSEMBLY__
13#ifndef CONFIG_PPC_KUAP
14.macro kuap_save_and_lock sp, thread, gpr1, gpr2, gpr3
15.endm
16
17.macro kuap_restore sp, current, gpr1, gpr2, gpr3
18.endm
19
20.macro kuap_check current, gpr
21.endm
22
23#endif
24
25#else /* !__ASSEMBLY__ */
Christophe Leroy69795ca2019-04-18 16:51:18 +100026
Christophe Leroyde78a9c2019-04-18 16:51:20 +100027#include <asm/pgtable.h>
28
Christophe Leroy69795ca2019-04-18 16:51:18 +100029void setup_kup(void);
30
Christophe Leroy0fb1c252019-04-18 16:51:19 +100031#ifdef CONFIG_PPC_KUEP
32void setup_kuep(bool disabled);
33#else
34static inline void setup_kuep(bool disabled) { }
35#endif /* CONFIG_PPC_KUEP */
36
Christophe Leroyde78a9c2019-04-18 16:51:20 +100037#ifdef CONFIG_PPC_KUAP
38void setup_kuap(bool disabled);
39#else
40static inline void setup_kuap(bool disabled) { }
41static inline void allow_user_access(void __user *to, const void __user *from,
42 unsigned long size) { }
43static inline void prevent_user_access(void __user *to, const void __user *from,
44 unsigned long size) { }
Michael Ellerman5e5be3a2019-04-18 16:51:25 +100045static inline bool bad_kuap_fault(struct pt_regs *regs, bool is_write) { return false; }
Christophe Leroyde78a9c2019-04-18 16:51:20 +100046#endif /* CONFIG_PPC_KUAP */
47
48static inline void allow_read_from_user(const void __user *from, unsigned long size)
49{
50 allow_user_access(NULL, from, size);
51}
52
53static inline void allow_write_to_user(void __user *to, unsigned long size)
54{
55 allow_user_access(to, NULL, size);
56}
57
58static inline void prevent_read_from_user(const void __user *from, unsigned long size)
59{
60 prevent_user_access(NULL, from, size);
61}
62
63static inline void prevent_write_to_user(void __user *to, unsigned long size)
64{
65 prevent_user_access(to, NULL, size);
66}
67
Christophe Leroy69795ca2019-04-18 16:51:18 +100068#endif /* !__ASSEMBLY__ */
69
70#endif /* _ASM_POWERPC_KUP_H_ */