kup.h 1.6 KB
Newer Older
1 2 3 4
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_POWERPC_KUP_H_
#define _ASM_POWERPC_KUP_H_

5 6 7
#ifdef CONFIG_PPC64
#include <asm/book3s/64/kup-radix.h>
#endif
8 9 10
#ifdef CONFIG_PPC_8xx
#include <asm/nohash/32/kup-8xx.h>
#endif
11

12 13 14 15 16 17 18 19 20 21 22 23 24 25
#ifdef __ASSEMBLY__
#ifndef CONFIG_PPC_KUAP
.macro kuap_save_and_lock	sp, thread, gpr1, gpr2, gpr3
.endm

.macro kuap_restore	sp, current, gpr1, gpr2, gpr3
.endm

.macro kuap_check	current, gpr
.endm

#endif

#else /* !__ASSEMBLY__ */
26

27 28
#include <asm/pgtable.h>

29 30
void setup_kup(void);

31 32 33 34 35 36
#ifdef CONFIG_PPC_KUEP
void setup_kuep(bool disabled);
#else
static inline void setup_kuep(bool disabled) { }
#endif /* CONFIG_PPC_KUEP */

37 38 39 40 41 42 43 44
#ifdef CONFIG_PPC_KUAP
void setup_kuap(bool disabled);
#else
static inline void setup_kuap(bool disabled) { }
static inline void allow_user_access(void __user *to, const void __user *from,
				     unsigned long size) { }
static inline void prevent_user_access(void __user *to, const void __user *from,
				       unsigned long size) { }
45
static inline bool bad_kuap_fault(struct pt_regs *regs, bool is_write) { return false; }
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
#endif /* CONFIG_PPC_KUAP */

static inline void allow_read_from_user(const void __user *from, unsigned long size)
{
	allow_user_access(NULL, from, size);
}

static inline void allow_write_to_user(void __user *to, unsigned long size)
{
	allow_user_access(to, NULL, size);
}

static inline void prevent_read_from_user(const void __user *from, unsigned long size)
{
	prevent_user_access(NULL, from, size);
}

static inline void prevent_write_to_user(void __user *to, unsigned long size)
{
	prevent_user_access(to, NULL, size);
}

68 69 70
#endif /* !__ASSEMBLY__ */

#endif /* _ASM_POWERPC_KUP_H_ */