powerpc/32: Prepare for Kernel Userspace Access Protection
[linux-2.6-block.git] / arch / powerpc / include / asm / kup.h
CommitLineData
69795cab
CL
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _ASM_POWERPC_KUP_H_
3#define _ASM_POWERPC_KUP_H_
4
890274c2
ME
5#ifdef CONFIG_PPC64
6#include <asm/book3s/64/kup-radix.h>
7#endif
8
e2fb9f54
CL
9#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__ */
69795cab 23
de78a9c4
CL
24#include <asm/pgtable.h>
25
69795cab
CL
26void setup_kup(void);
27
0fb1c25a
CL
28#ifdef CONFIG_PPC_KUEP
29void setup_kuep(bool disabled);
30#else
31static inline void setup_kuep(bool disabled) { }
32#endif /* CONFIG_PPC_KUEP */
33
de78a9c4
CL
34#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) { }
5e5be3ae 42static inline bool bad_kuap_fault(struct pt_regs *regs, bool is_write) { return false; }
de78a9c4
CL
43#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
69795cab
CL
65#endif /* !__ASSEMBLY__ */
66
67#endif /* _ASM_POWERPC_KUP_H_ */