1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_KUP_8XX_H_
3 #define _ASM_POWERPC_KUP_8XX_H_
12 .macro kuap_save_and_lock sp, thread, gpr1, gpr2, gpr3
13 lis \gpr2, MD_APG_KUAP@h /* only APG0 and APG1 are used */
14 mfspr \gpr1, SPRN_MD_AP
15 mtspr SPRN_MD_AP, \gpr2
16 stw \gpr1, STACK_REGS_KUAP(\sp)
19 .macro kuap_restore sp, current, gpr1, gpr2, gpr3
20 lwz \gpr1, STACK_REGS_KUAP(\sp)
21 mtspr SPRN_MD_AP, \gpr1
24 .macro kuap_check current, gpr
25 #ifdef CONFIG_PPC_KUAP_DEBUG
26 mfspr \gpr, SPRN_MD_AP
27 rlwinm \gpr, \gpr, 16, 0xffff
28 999: twnei \gpr, MD_APG_KUAP@h
29 EMIT_BUG_ENTRY 999b, __FILE__, __LINE__, (BUGFLAG_WARNING | BUGFLAG_ONCE)
33 #else /* !__ASSEMBLY__ */
37 static inline void allow_user_access(void __user *to, const void __user *from,
38 unsigned long size, unsigned long dir)
40 mtspr(SPRN_MD_AP, MD_APG_INIT);
43 static inline void prevent_user_access(void __user *to, const void __user *from,
44 unsigned long size, unsigned long dir)
46 mtspr(SPRN_MD_AP, MD_APG_KUAP);
49 static inline unsigned long prevent_user_access_return(void)
51 unsigned long flags = mfspr(SPRN_MD_AP);
53 mtspr(SPRN_MD_AP, MD_APG_KUAP);
58 static inline void restore_user_access(unsigned long flags)
60 mtspr(SPRN_MD_AP, flags);
64 bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
66 return WARN(!((regs->kuap ^ MD_APG_KUAP) & 0xf0000000),
67 "Bug: fault blocked by AP register !");
70 #endif /* !__ASSEMBLY__ */
72 #endif /* CONFIG_PPC_KUAP */
74 #endif /* _ASM_POWERPC_KUP_8XX_H_ */