blob: 7d8ad3d6729d0d0fa06976c3d0a547f44d56191c [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
8
Christophe Leroye2fb9f52019-03-11 08:30:31 +00009#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 Leroy69795ca2019-04-18 16:51:18 +100023
Christophe Leroyde78a9c2019-04-18 16:51:20 +100024#include <asm/pgtable.h>
25
Christophe Leroy69795ca2019-04-18 16:51:18 +100026void setup_kup(void);
27
Christophe Leroy0fb1c252019-04-18 16:51:19 +100028#ifdef CONFIG_PPC_KUEP
29void setup_kuep(bool disabled);
30#else
31static inline void setup_kuep(bool disabled) { }
32#endif /* CONFIG_PPC_KUEP */
33
Christophe Leroyde78a9c2019-04-18 16:51:20 +100034#ifdef CONFIG_PPC_KUAP
35void setup_kuap(bool disabled);
36#else
37static inline void setup_kuap(bool disabled) { }
38static inline void allow_user_access(void __user *to, const void __user *from,
39 unsigned long size) { }
40static inline void prevent_user_access(void __user *to, const void __user *from,
41 unsigned long size) { }
Michael Ellerman5e5be3a2019-04-18 16:51:25 +100042static inline bool bad_kuap_fault(struct pt_regs *regs, bool is_write) { return false; }
Christophe Leroyde78a9c2019-04-18 16:51:20 +100043#endif /* CONFIG_PPC_KUAP */
44
45static inline void allow_read_from_user(const void __user *from, unsigned long size)
46{
47 allow_user_access(NULL, from, size);
48}
49
50static inline void allow_write_to_user(void __user *to, unsigned long size)
51{
52 allow_user_access(to, NULL, size);
53}
54
55static inline void prevent_read_from_user(const void __user *from, unsigned long size)
56{
57 prevent_user_access(NULL, from, size);
58}
59
60static inline void prevent_write_to_user(void __user *to, unsigned long size)
61{
62 prevent_user_access(to, NULL, size);
63}
64
Christophe Leroy69795ca2019-04-18 16:51:18 +100065#endif /* !__ASSEMBLY__ */
66
67#endif /* _ASM_POWERPC_KUP_H_ */