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

TOMOYO Linux Cross Reference
Linux/arch/powerpc/include/asm/nohash/kup-booke.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ 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_BOOKE_H_
  3 #define _ASM_POWERPC_KUP_BOOKE_H_
  4 
  5 #include <asm/bug.h>
  6 #include <asm/mmu.h>
  7 
  8 #ifdef CONFIG_PPC_KUAP
  9 
 10 #ifdef __ASSEMBLY__
 11 
 12 .macro kuap_check_amr   gpr1, gpr2
 13 .endm
 14 
 15 #else
 16 
 17 #include <linux/sched.h>
 18 
 19 #include <asm/reg.h>
 20 
 21 static __always_inline void __kuap_lock(void)
 22 {
 23         mtspr(SPRN_PID, 0);
 24         isync();
 25 }
 26 #define __kuap_lock __kuap_lock
 27 
 28 static __always_inline void __kuap_save_and_lock(struct pt_regs *regs)
 29 {
 30         regs->kuap = mfspr(SPRN_PID);
 31         mtspr(SPRN_PID, 0);
 32         isync();
 33 }
 34 #define __kuap_save_and_lock __kuap_save_and_lock
 35 
 36 static __always_inline void kuap_user_restore(struct pt_regs *regs)
 37 {
 38         if (kuap_is_disabled())
 39                 return;
 40 
 41         mtspr(SPRN_PID, current->thread.pid);
 42 
 43         /* Context synchronisation is performed by rfi */
 44 }
 45 
 46 static __always_inline void __kuap_kernel_restore(struct pt_regs *regs, unsigned long kuap)
 47 {
 48         if (regs->kuap)
 49                 mtspr(SPRN_PID, current->thread.pid);
 50 
 51         /* Context synchronisation is performed by rfi */
 52 }
 53 
 54 #ifdef CONFIG_PPC_KUAP_DEBUG
 55 static __always_inline unsigned long __kuap_get_and_assert_locked(void)
 56 {
 57         WARN_ON_ONCE(mfspr(SPRN_PID));
 58 
 59         return 0;
 60 }
 61 #define __kuap_get_and_assert_locked __kuap_get_and_assert_locked
 62 #endif
 63 
 64 static __always_inline void uaccess_begin_booke(unsigned long val)
 65 {
 66         asm(ASM_MMU_FTR_IFSET("mtspr %0, %1; isync", "", %2) : :
 67             "i"(SPRN_PID), "r"(val), "i"(MMU_FTR_KUAP) : "memory");
 68 }
 69 
 70 static __always_inline void uaccess_end_booke(void)
 71 {
 72         asm(ASM_MMU_FTR_IFSET("mtspr %0, %1; isync", "", %2) : :
 73             "i"(SPRN_PID), "r"(0), "i"(MMU_FTR_KUAP) : "memory");
 74 }
 75 
 76 static __always_inline void allow_user_access(void __user *to, const void __user *from,
 77                                               unsigned long size, unsigned long dir)
 78 {
 79         uaccess_begin_booke(current->thread.pid);
 80 }
 81 
 82 static __always_inline void prevent_user_access(unsigned long dir)
 83 {
 84         uaccess_end_booke();
 85 }
 86 
 87 static __always_inline unsigned long prevent_user_access_return(void)
 88 {
 89         unsigned long flags = mfspr(SPRN_PID);
 90 
 91         uaccess_end_booke();
 92 
 93         return flags;
 94 }
 95 
 96 static __always_inline void restore_user_access(unsigned long flags)
 97 {
 98         if (flags)
 99                 uaccess_begin_booke(current->thread.pid);
100 }
101 
102 static __always_inline bool
103 __bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
104 {
105         return !regs->kuap;
106 }
107 
108 #endif /* !__ASSEMBLY__ */
109 
110 #endif /* CONFIG_PPC_KUAP */
111 
112 #endif /* _ASM_POWERPC_KUP_BOOKE_H_ */
113 

~ [ 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