x86/mm/pkeys: Create an x86 arch_calc_vm_prot_bits() for VMA flags
authorDave Hansen <dave.hansen@linux.intel.com>
Fri, 12 Feb 2016 21:02:37 +0000 (13:02 -0800)
committerIngo Molnar <mingo@kernel.org>
Thu, 18 Feb 2016 18:46:32 +0000 (19:46 +0100)
calc_vm_prot_bits() takes PROT_{READ,WRITE,EXECUTE} bits and
turns them in to the vma->vm_flags/VM_* bits.  We need to do a
similar thing for protection keys.

We take a protection key (4 bits) and encode it in to the 4
VM_PKEY_* bits.

Note: this code is not new.  It was simply a part of the
mprotect_pkey() patch in the past.  I broke it out for use
in the execute-only support.

Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dave Hansen <dave@sr71.net>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: linux-mm@kvack.org
Link: http://lkml.kernel.org/r/20160212210237.CFB94AD5@viggo.jf.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/x86/include/uapi/asm/mman.h

index e8562e0a2993f0681309c1fca43964839e42fc34..39bca7fac087098c1f972de4b1468733ffe6220a 100644 (file)
                ((vm_flags) & VM_PKEY_BIT1 ? _PAGE_PKEY_BIT1 : 0) |     \
                ((vm_flags) & VM_PKEY_BIT2 ? _PAGE_PKEY_BIT2 : 0) |     \
                ((vm_flags) & VM_PKEY_BIT3 ? _PAGE_PKEY_BIT3 : 0))
+
+#define arch_calc_vm_prot_bits(prot, key) (            \
+               ((key) & 0x1 ? VM_PKEY_BIT0 : 0) |      \
+               ((key) & 0x2 ? VM_PKEY_BIT1 : 0) |      \
+               ((key) & 0x4 ? VM_PKEY_BIT2 : 0) |      \
+               ((key) & 0x8 ? VM_PKEY_BIT3 : 0))
 #endif
 
 #include <asm-generic/mman.h>