Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'topic/pkey' into next

This is a branch with a mixture of mm, x86 and powerpc commits all
relating to some minor cross-arch pkeys consolidation. The x86/mm
changes have been reviewed by Ingo & Dave Hansen and the tree has been
in linux-next for some weeks without issue.

+41 -53
-5
arch/powerpc/include/asm/mmu_context.h
··· 250 250 #define thread_pkey_regs_restore(new_thread, old_thread) 251 251 #define thread_pkey_regs_init(thread) 252 252 253 - static inline int vma_pkey(struct vm_area_struct *vma) 254 - { 255 - return 0; 256 - } 257 - 258 253 static inline u64 pte_to_hpte_pkey_bits(u64 pteflags) 259 254 { 260 255 return 0x0UL;
-13
arch/powerpc/include/asm/pkeys.h
··· 15 15 extern int pkeys_total; /* total pkeys as per device tree */ 16 16 extern u32 initial_allocation_mask; /* bits set for reserved keys */ 17 17 18 - /* 19 - * Define these here temporarily so we're not dependent on patching linux/mm.h. 20 - * Once it's updated we can drop these. 21 - */ 22 - #ifndef VM_PKEY_BIT0 23 - # define VM_PKEY_SHIFT VM_HIGH_ARCH_BIT_0 24 - # define VM_PKEY_BIT0 VM_HIGH_ARCH_0 25 - # define VM_PKEY_BIT1 VM_HIGH_ARCH_1 26 - # define VM_PKEY_BIT2 VM_HIGH_ARCH_2 27 - # define VM_PKEY_BIT3 VM_HIGH_ARCH_3 28 - # define VM_PKEY_BIT4 VM_HIGH_ARCH_4 29 - #endif 30 - 31 18 #define ARCH_VM_PKEY_FLAGS (VM_PKEY_BIT0 | VM_PKEY_BIT1 | VM_PKEY_BIT2 | \ 32 19 VM_PKEY_BIT3 | VM_PKEY_BIT4) 33 20
-15
arch/x86/include/asm/mmu_context.h
··· 288 288 mpx_notify_unmap(mm, vma, start, end); 289 289 } 290 290 291 - #ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS 292 - static inline int vma_pkey(struct vm_area_struct *vma) 293 - { 294 - unsigned long vma_pkey_mask = VM_PKEY_BIT0 | VM_PKEY_BIT1 | 295 - VM_PKEY_BIT2 | VM_PKEY_BIT3; 296 - 297 - return (vma->vm_flags & vma_pkey_mask) >> VM_PKEY_SHIFT; 298 - } 299 - #else 300 - static inline int vma_pkey(struct vm_area_struct *vma) 301 - { 302 - return 0; 303 - } 304 - #endif 305 - 306 291 /* 307 292 * We only want to enforce protection keys on the current process 308 293 * because we effectively have no access to PKRU for other
+13
arch/x86/include/asm/pkeys.h
··· 7 7 extern int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, 8 8 unsigned long init_val); 9 9 10 + static inline bool arch_pkeys_enabled(void) 11 + { 12 + return boot_cpu_has(X86_FEATURE_OSPKE); 13 + } 14 + 10 15 /* 11 16 * Try to dedicate one of the protection keys to be used as an 12 17 * execute-only protection key. ··· 110 105 extern int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey, 111 106 unsigned long init_val); 112 107 extern void copy_init_pkru_to_fpregs(void); 108 + 109 + static inline int vma_pkey(struct vm_area_struct *vma) 110 + { 111 + unsigned long vma_pkey_mask = VM_PKEY_BIT0 | VM_PKEY_BIT1 | 112 + VM_PKEY_BIT2 | VM_PKEY_BIT3; 113 + 114 + return (vma->vm_flags & vma_pkey_mask) >> VM_PKEY_SHIFT; 115 + } 113 116 114 117 #endif /*_ASM_X86_PKEYS_H */
-8
arch/x86/kernel/setup.c
··· 1312 1312 return 0; 1313 1313 } 1314 1314 __initcall(register_kernel_offset_dumper); 1315 - 1316 - void arch_show_smap(struct seq_file *m, struct vm_area_struct *vma) 1317 - { 1318 - if (!boot_cpu_has(X86_FEATURE_OSPKE)) 1319 - return; 1320 - 1321 - seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma)); 1322 - }
+7 -6
fs/proc/task_mmu.c
··· 18 18 #include <linux/page_idle.h> 19 19 #include <linux/shmem_fs.h> 20 20 #include <linux/uaccess.h> 21 + #include <linux/pkeys.h> 21 22 22 23 #include <asm/elf.h> 23 24 #include <asm/tlb.h> ··· 674 673 [ilog2(VM_MERGEABLE)] = "mg", 675 674 [ilog2(VM_UFFD_MISSING)]= "um", 676 675 [ilog2(VM_UFFD_WP)] = "uw", 677 - #ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS 676 + #ifdef CONFIG_ARCH_HAS_PKEYS 678 677 /* These come out via ProtectionKey: */ 679 678 [ilog2(VM_PKEY_BIT0)] = "", 680 679 [ilog2(VM_PKEY_BIT1)] = "", 681 680 [ilog2(VM_PKEY_BIT2)] = "", 682 681 [ilog2(VM_PKEY_BIT3)] = "", 682 + #if VM_PKEY_BIT4 683 + [ilog2(VM_PKEY_BIT4)] = "", 683 684 #endif 685 + #endif /* CONFIG_ARCH_HAS_PKEYS */ 684 686 }; 685 687 size_t i; 686 688 ··· 730 726 return 0; 731 727 } 732 728 #endif /* HUGETLB_PAGE */ 733 - 734 - void __weak arch_show_smap(struct seq_file *m, struct vm_area_struct *vma) 735 - { 736 - } 737 729 738 730 #define SEQ_PUT_DEC(str, val) \ 739 731 seq_put_decimal_ull_width(m, str, (val) >> 10, 8) ··· 835 835 seq_puts(m, " kB\n"); 836 836 } 837 837 if (!rollup_mode) { 838 - arch_show_smap(m, vma); 838 + if (arch_pkeys_enabled()) 839 + seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma)); 839 840 show_smap_vma_flags(m, vma); 840 841 } 841 842 m_cache_vma(m, vma);
+10 -4
include/linux/mm.h
··· 228 228 #define VM_HIGH_ARCH_4 BIT(VM_HIGH_ARCH_BIT_4) 229 229 #endif /* CONFIG_ARCH_USES_HIGH_VMA_FLAGS */ 230 230 231 - #if defined(CONFIG_X86) 232 - # define VM_PAT VM_ARCH_1 /* PAT reserves whole VMA at once (x86) */ 233 - #if defined (CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS) 231 + #ifdef CONFIG_ARCH_HAS_PKEYS 234 232 # define VM_PKEY_SHIFT VM_HIGH_ARCH_BIT_0 235 233 # define VM_PKEY_BIT0 VM_HIGH_ARCH_0 /* A protection key is a 4-bit value */ 236 - # define VM_PKEY_BIT1 VM_HIGH_ARCH_1 234 + # define VM_PKEY_BIT1 VM_HIGH_ARCH_1 /* on x86 and 5-bit value on ppc64 */ 237 235 # define VM_PKEY_BIT2 VM_HIGH_ARCH_2 238 236 # define VM_PKEY_BIT3 VM_HIGH_ARCH_3 237 + #ifdef CONFIG_PPC 238 + # define VM_PKEY_BIT4 VM_HIGH_ARCH_4 239 + #else 240 + # define VM_PKEY_BIT4 0 239 241 #endif 242 + #endif /* CONFIG_ARCH_HAS_PKEYS */ 243 + 244 + #if defined(CONFIG_X86) 245 + # define VM_PAT VM_ARCH_1 /* PAT reserves whole VMA at once (x86) */ 240 246 #elif defined(CONFIG_PPC) 241 247 # define VM_SAO VM_ARCH_1 /* Strong Access Ordering (powerpc) */ 242 248 #elif defined(CONFIG_PARISC)
+11 -2
include/linux/pkeys.h
··· 2 2 #ifndef _LINUX_PKEYS_H 3 3 #define _LINUX_PKEYS_H 4 4 5 - #include <linux/mm_types.h> 6 - #include <asm/mmu_context.h> 5 + #include <linux/mm.h> 7 6 8 7 #ifdef CONFIG_ARCH_HAS_PKEYS 9 8 #include <asm/pkeys.h> ··· 12 13 #define arch_override_mprotect_pkey(vma, prot, pkey) (0) 13 14 #define PKEY_DEDICATED_EXECUTE_ONLY 0 14 15 #define ARCH_VM_PKEY_FLAGS 0 16 + 17 + static inline int vma_pkey(struct vm_area_struct *vma) 18 + { 19 + return 0; 20 + } 15 21 16 22 static inline bool mm_pkey_is_allocated(struct mm_struct *mm, int pkey) 17 23 { ··· 37 33 unsigned long init_val) 38 34 { 39 35 return 0; 36 + } 37 + 38 + static inline bool arch_pkeys_enabled(void) 39 + { 40 + return false; 40 41 } 41 42 42 43 static inline void copy_init_pkru_to_fpregs(void)