1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_KUP_BOOKE_H_
3 #define _ASM_POWERPC_KUP_BOOKE_H_
12 .macro kuap_check_amr gpr1, gpr2
17 #include <linux/sched.h>
21 static __always_inline void __kuap_lock(void)
26 #define __kuap_lock __kuap_lock
28 static __always_inline void __kuap_save_and_lock(struct pt_regs *regs)
30 regs->kuap = mfspr(SPRN_PID);
34 #define __kuap_save_and_lock __kuap_save_and_lock
36 static __always_inline void kuap_user_restore(struct pt_regs *regs)
38 if (kuap_is_disabled())
41 mtspr(SPRN_PID, current->thread.pid);
43 /* Context synchronisation is performed by rfi */
46 static __always_inline void __kuap_kernel_restore(struct pt_regs *regs, unsigned long kuap)
49 mtspr(SPRN_PID, current->thread.pid);
51 /* Context synchronisation is performed by rfi */
54 #ifdef CONFIG_PPC_KUAP_DEBUG
55 static __always_inline unsigned long __kuap_get_and_assert_locked(void)
57 WARN_ON_ONCE(mfspr(SPRN_PID));
61 #define __kuap_get_and_assert_locked __kuap_get_and_assert_locked
64 static __always_inline void uaccess_begin_booke(unsigned long val)
66 asm(ASM_MMU_FTR_IFSET("mtspr %0, %1; isync", "", %2) : :
67 "i"(SPRN_PID), "r"(val), "i"(MMU_FTR_KUAP) : "memory");
70 static __always_inline void uaccess_end_booke(void)
72 asm(ASM_MMU_FTR_IFSET("mtspr %0, %1; isync", "", %2) : :
73 "i"(SPRN_PID), "r"(0), "i"(MMU_FTR_KUAP) : "memory");
76 static __always_inline void allow_user_access(void __user *to, const void __user *from,
77 unsigned long size, unsigned long dir)
79 uaccess_begin_booke(current->thread.pid);
82 static __always_inline void prevent_user_access(unsigned long dir)
87 static __always_inline unsigned long prevent_user_access_return(void)
89 unsigned long flags = mfspr(SPRN_PID);
96 static __always_inline void restore_user_access(unsigned long flags)
99 uaccess_begin_booke(current->thread.pid);
102 static __always_inline bool
103 __bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
108 #endif /* !__ASSEMBLY__ */
110 #endif /* CONFIG_PPC_KUAP */
112 #endif /* _ASM_POWERPC_KUP_BOOKE_H_ */