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

TOMOYO Linux Cross Reference
Linux/arch/x86/include/asm/pkeys.h

Version: ~ [ linux-5.2 ] ~ [ linux-5.1.16 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.57 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.132 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.184 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.184 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.69 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #ifndef _ASM_X86_PKEYS_H
  2 #define _ASM_X86_PKEYS_H
  3 
  4 #define arch_max_pkey() (boot_cpu_has(X86_FEATURE_OSPKE) ? 16 : 1)
  5 
  6 extern int arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
  7                 unsigned long init_val);
  8 
  9 /*
 10  * Try to dedicate one of the protection keys to be used as an
 11  * execute-only protection key.
 12  */
 13 extern int __execute_only_pkey(struct mm_struct *mm);
 14 static inline int execute_only_pkey(struct mm_struct *mm)
 15 {
 16         if (!boot_cpu_has(X86_FEATURE_OSPKE))
 17                 return 0;
 18 
 19         return __execute_only_pkey(mm);
 20 }
 21 
 22 extern int __arch_override_mprotect_pkey(struct vm_area_struct *vma,
 23                 int prot, int pkey);
 24 static inline int arch_override_mprotect_pkey(struct vm_area_struct *vma,
 25                 int prot, int pkey)
 26 {
 27         if (!boot_cpu_has(X86_FEATURE_OSPKE))
 28                 return 0;
 29 
 30         return __arch_override_mprotect_pkey(vma, prot, pkey);
 31 }
 32 
 33 extern int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
 34                 unsigned long init_val);
 35 
 36 #define ARCH_VM_PKEY_FLAGS (VM_PKEY_BIT0 | VM_PKEY_BIT1 | VM_PKEY_BIT2 | VM_PKEY_BIT3)
 37 
 38 #define mm_pkey_allocation_map(mm)      (mm->context.pkey_allocation_map)
 39 #define mm_set_pkey_allocated(mm, pkey) do {            \
 40         mm_pkey_allocation_map(mm) |= (1U << pkey);     \
 41 } while (0)
 42 #define mm_set_pkey_free(mm, pkey) do {                 \
 43         mm_pkey_allocation_map(mm) &= ~(1U << pkey);    \
 44 } while (0)
 45 
 46 static inline
 47 bool mm_pkey_is_allocated(struct mm_struct *mm, int pkey)
 48 {
 49         /*
 50          * "Allocated" pkeys are those that have been returned
 51          * from pkey_alloc().  pkey 0 is special, and never
 52          * returned from pkey_alloc().
 53          */
 54         if (pkey <= 0)
 55                 return false;
 56         if (pkey >= arch_max_pkey())
 57                 return false;
 58         return mm_pkey_allocation_map(mm) & (1U << pkey);
 59 }
 60 
 61 /*
 62  * Returns a positive, 4-bit key on success, or -1 on failure.
 63  */
 64 static inline
 65 int mm_pkey_alloc(struct mm_struct *mm)
 66 {
 67         /*
 68          * Note: this is the one and only place we make sure
 69          * that the pkey is valid as far as the hardware is
 70          * concerned.  The rest of the kernel trusts that
 71          * only good, valid pkeys come out of here.
 72          */
 73         u16 all_pkeys_mask = ((1U << arch_max_pkey()) - 1);
 74         int ret;
 75 
 76         /*
 77          * Are we out of pkeys?  We must handle this specially
 78          * because ffz() behavior is undefined if there are no
 79          * zeros.
 80          */
 81         if (mm_pkey_allocation_map(mm) == all_pkeys_mask)
 82                 return -1;
 83 
 84         ret = ffz(mm_pkey_allocation_map(mm));
 85 
 86         mm_set_pkey_allocated(mm, ret);
 87 
 88         return ret;
 89 }
 90 
 91 static inline
 92 int mm_pkey_free(struct mm_struct *mm, int pkey)
 93 {
 94         if (!mm_pkey_is_allocated(mm, pkey))
 95                 return -EINVAL;
 96 
 97         mm_set_pkey_free(mm, pkey);
 98 
 99         return 0;
100 }
101 
102 extern int arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
103                 unsigned long init_val);
104 extern int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
105                 unsigned long init_val);
106 extern void copy_init_pkru_to_fpregs(void);
107 
108 #endif /*_ASM_X86_PKEYS_H */
109 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp