]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/x86/include/asm/pkeys.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_PKEYS_H
3 #define _ASM_X86_PKEYS_H
5 #define arch_max_pkey() (boot_cpu_has(X86_FEATURE_OSPKE) ? 16 : 1)
7 extern int arch_set_user_pkey_access(struct task_struct
*tsk
, int pkey
,
8 unsigned long init_val
);
11 * Try to dedicate one of the protection keys to be used as an
12 * execute-only protection key.
14 extern int __execute_only_pkey(struct mm_struct
*mm
);
15 static inline int execute_only_pkey(struct mm_struct
*mm
)
17 if (!boot_cpu_has(X86_FEATURE_OSPKE
))
20 return __execute_only_pkey(mm
);
23 extern int __arch_override_mprotect_pkey(struct vm_area_struct
*vma
,
25 static inline int arch_override_mprotect_pkey(struct vm_area_struct
*vma
,
28 if (!boot_cpu_has(X86_FEATURE_OSPKE
))
31 return __arch_override_mprotect_pkey(vma
, prot
, pkey
);
34 extern int __arch_set_user_pkey_access(struct task_struct
*tsk
, int pkey
,
35 unsigned long init_val
);
37 #define ARCH_VM_PKEY_FLAGS (VM_PKEY_BIT0 | VM_PKEY_BIT1 | VM_PKEY_BIT2 | VM_PKEY_BIT3)
39 #define mm_pkey_allocation_map(mm) (mm->context.pkey_allocation_map)
40 #define mm_set_pkey_allocated(mm, pkey) do { \
41 mm_pkey_allocation_map(mm) |= (1U << pkey); \
43 #define mm_set_pkey_free(mm, pkey) do { \
44 mm_pkey_allocation_map(mm) &= ~(1U << pkey); \
48 bool mm_pkey_is_allocated(struct mm_struct
*mm
, int pkey
)
51 * "Allocated" pkeys are those that have been returned
52 * from pkey_alloc(). pkey 0 is special, and never
53 * returned from pkey_alloc().
57 if (pkey
>= arch_max_pkey())
59 return mm_pkey_allocation_map(mm
) & (1U << pkey
);
63 * Returns a positive, 4-bit key on success, or -1 on failure.
66 int mm_pkey_alloc(struct mm_struct
*mm
)
69 * Note: this is the one and only place we make sure
70 * that the pkey is valid as far as the hardware is
71 * concerned. The rest of the kernel trusts that
72 * only good, valid pkeys come out of here.
74 u16 all_pkeys_mask
= ((1U << arch_max_pkey()) - 1);
78 * Are we out of pkeys? We must handle this specially
79 * because ffz() behavior is undefined if there are no
82 if (mm_pkey_allocation_map(mm
) == all_pkeys_mask
)
85 ret
= ffz(mm_pkey_allocation_map(mm
));
87 mm_set_pkey_allocated(mm
, ret
);
93 int mm_pkey_free(struct mm_struct
*mm
, int pkey
)
95 if (!mm_pkey_is_allocated(mm
, pkey
))
98 mm_set_pkey_free(mm
, pkey
);
103 extern int arch_set_user_pkey_access(struct task_struct
*tsk
, int pkey
,
104 unsigned long init_val
);
105 extern int __arch_set_user_pkey_access(struct task_struct
*tsk
, int pkey
,
106 unsigned long init_val
);
107 extern void copy_init_pkru_to_fpregs(void);
109 #endif /*_ASM_X86_PKEYS_H */