~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/powerpc/include/asm/nohash/32/kup-8xx.h

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef _ASM_POWERPC_KUP_8XX_H_
  3 #define _ASM_POWERPC_KUP_8XX_H_
  4 
  5 #include <asm/bug.h>
  6 #include <asm/mmu.h>
  7 
  8 #ifdef CONFIG_PPC_KUAP
  9 
 10 #ifndef __ASSEMBLY__
 11 
 12 #include <asm/reg.h>
 13 
 14 static __always_inline void __kuap_save_and_lock(struct pt_regs *regs)
 15 {
 16         regs->kuap = mfspr(SPRN_MD_AP);
 17         mtspr(SPRN_MD_AP, MD_APG_KUAP);
 18 }
 19 #define __kuap_save_and_lock __kuap_save_and_lock
 20 
 21 static __always_inline void kuap_user_restore(struct pt_regs *regs)
 22 {
 23 }
 24 
 25 static __always_inline void __kuap_kernel_restore(struct pt_regs *regs, unsigned long kuap)
 26 {
 27         mtspr(SPRN_MD_AP, regs->kuap);
 28 }
 29 
 30 #ifdef CONFIG_PPC_KUAP_DEBUG
 31 static __always_inline unsigned long __kuap_get_and_assert_locked(void)
 32 {
 33         WARN_ON_ONCE(mfspr(SPRN_MD_AP) >> 16 != MD_APG_KUAP >> 16);
 34 
 35         return 0;
 36 }
 37 #define __kuap_get_and_assert_locked __kuap_get_and_assert_locked
 38 #endif
 39 
 40 static __always_inline void uaccess_begin_8xx(unsigned long val)
 41 {
 42         asm(ASM_MMU_FTR_IFSET("mtspr %0, %1", "", %2) : :
 43             "i"(SPRN_MD_AP), "r"(val), "i"(MMU_FTR_KUAP) : "memory");
 44 }
 45 
 46 static __always_inline void uaccess_end_8xx(void)
 47 {
 48         asm(ASM_MMU_FTR_IFSET("mtspr %0, %1", "", %2) : :
 49             "i"(SPRN_MD_AP), "r"(MD_APG_KUAP), "i"(MMU_FTR_KUAP) : "memory");
 50 }
 51 
 52 static __always_inline void allow_user_access(void __user *to, const void __user *from,
 53                                               unsigned long size, unsigned long dir)
 54 {
 55         uaccess_begin_8xx(MD_APG_INIT);
 56 }
 57 
 58 static __always_inline void prevent_user_access(unsigned long dir)
 59 {
 60         uaccess_end_8xx();
 61 }
 62 
 63 static __always_inline unsigned long prevent_user_access_return(void)
 64 {
 65         unsigned long flags;
 66 
 67         flags = mfspr(SPRN_MD_AP);
 68 
 69         uaccess_end_8xx();
 70 
 71         return flags;
 72 }
 73 
 74 static __always_inline void restore_user_access(unsigned long flags)
 75 {
 76         uaccess_begin_8xx(flags);
 77 }
 78 
 79 static __always_inline bool
 80 __bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
 81 {
 82         return !((regs->kuap ^ MD_APG_KUAP) & 0xff000000);
 83 }
 84 
 85 #endif /* !__ASSEMBLY__ */
 86 
 87 #endif /* CONFIG_PPC_KUAP */
 88 
 89 #endif /* _ASM_POWERPC_KUP_8XX_H_ */
 90 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php