From 555934a71bb479ce109722807b374f2d98aefe89 Mon Sep 17 00:00:00 2001 From: Michael Ellerman Date: Thu, 12 Apr 2018 23:54:00 +1000 Subject: x86/pkeys: Move vma_pkey() into asm/pkeys.h Move the last remaining pkey helper, vma_pkey() into asm/pkeys.h Signed-off-by: Michael Ellerman Reviewed-by: Dave Hansen --- arch/x86/include/asm/pkeys.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'arch/x86/include/asm/pkeys.h') diff --git a/arch/x86/include/asm/pkeys.h b/arch/x86/include/asm/pkeys.h index a0ba1ffda0df..0e5f749158e4 100644 --- a/arch/x86/include/asm/pkeys.h +++ b/arch/x86/include/asm/pkeys.h @@ -106,4 +106,12 @@ extern int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey, unsigned long init_val); extern void copy_init_pkru_to_fpregs(void); +static inline int vma_pkey(struct vm_area_struct *vma) +{ + unsigned long vma_pkey_mask = VM_PKEY_BIT0 | VM_PKEY_BIT1 | + VM_PKEY_BIT2 | VM_PKEY_BIT3; + + return (vma->vm_flags & vma_pkey_mask) >> VM_PKEY_SHIFT; +} + #endif /*_ASM_X86_PKEYS_H */ -- cgit v1.2.3 From 3f36c94239658a79a4deeb84a2e0ebf005f083fc Mon Sep 17 00:00:00 2001 From: Michael Ellerman Date: Fri, 13 Apr 2018 23:54:36 +1000 Subject: x86/pkeys: Add arch_pkeys_enabled() This will be used in future patches to check for arch support for pkeys in generic code. Signed-off-by: Michael Ellerman Reviewed-by: Dave Hansen --- arch/x86/include/asm/pkeys.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'arch/x86/include/asm/pkeys.h') diff --git a/arch/x86/include/asm/pkeys.h b/arch/x86/include/asm/pkeys.h index 0e5f749158e4..c1957f8f7c1b 100644 --- a/arch/x86/include/asm/pkeys.h +++ b/arch/x86/include/asm/pkeys.h @@ -7,6 +7,11 @@ extern int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, unsigned long init_val); +static inline bool arch_pkeys_enabled(void) +{ + return boot_cpu_has(X86_FEATURE_OSPKE); +} + /* * Try to dedicate one of the protection keys to be used as an * execute-only protection key. -- cgit v1.2.3