提交 2135a6ec 编写于 作者: M Michael Ellerman

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.
...@@ -250,11 +250,6 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma, ...@@ -250,11 +250,6 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,
#define thread_pkey_regs_restore(new_thread, old_thread) #define thread_pkey_regs_restore(new_thread, old_thread)
#define thread_pkey_regs_init(thread) #define thread_pkey_regs_init(thread)
static inline int vma_pkey(struct vm_area_struct *vma)
{
return 0;
}
static inline u64 pte_to_hpte_pkey_bits(u64 pteflags) static inline u64 pte_to_hpte_pkey_bits(u64 pteflags)
{ {
return 0x0UL; return 0x0UL;
......
...@@ -15,19 +15,6 @@ DECLARE_STATIC_KEY_TRUE(pkey_disabled); ...@@ -15,19 +15,6 @@ DECLARE_STATIC_KEY_TRUE(pkey_disabled);
extern int pkeys_total; /* total pkeys as per device tree */ extern int pkeys_total; /* total pkeys as per device tree */
extern u32 initial_allocation_mask; /* bits set for reserved keys */ extern u32 initial_allocation_mask; /* bits set for reserved keys */
/*
* Define these here temporarily so we're not dependent on patching linux/mm.h.
* Once it's updated we can drop these.
*/
#ifndef VM_PKEY_BIT0
# define VM_PKEY_SHIFT VM_HIGH_ARCH_BIT_0
# define VM_PKEY_BIT0 VM_HIGH_ARCH_0
# define VM_PKEY_BIT1 VM_HIGH_ARCH_1
# define VM_PKEY_BIT2 VM_HIGH_ARCH_2
# define VM_PKEY_BIT3 VM_HIGH_ARCH_3
# define VM_PKEY_BIT4 VM_HIGH_ARCH_4
#endif
#define ARCH_VM_PKEY_FLAGS (VM_PKEY_BIT0 | VM_PKEY_BIT1 | VM_PKEY_BIT2 | \ #define ARCH_VM_PKEY_FLAGS (VM_PKEY_BIT0 | VM_PKEY_BIT1 | VM_PKEY_BIT2 | \
VM_PKEY_BIT3 | VM_PKEY_BIT4) VM_PKEY_BIT3 | VM_PKEY_BIT4)
......
...@@ -288,21 +288,6 @@ static inline void arch_unmap(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -288,21 +288,6 @@ static inline void arch_unmap(struct mm_struct *mm, struct vm_area_struct *vma,
mpx_notify_unmap(mm, vma, start, end); mpx_notify_unmap(mm, vma, start, end);
} }
#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
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;
}
#else
static inline int vma_pkey(struct vm_area_struct *vma)
{
return 0;
}
#endif
/* /*
* We only want to enforce protection keys on the current process * We only want to enforce protection keys on the current process
* because we effectively have no access to PKRU for other * because we effectively have no access to PKRU for other
......
...@@ -7,6 +7,11 @@ ...@@ -7,6 +7,11 @@
extern int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, extern int arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
unsigned long init_val); 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 * Try to dedicate one of the protection keys to be used as an
* execute-only protection key. * execute-only protection key.
...@@ -106,4 +111,12 @@ extern int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey, ...@@ -106,4 +111,12 @@ extern int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
unsigned long init_val); unsigned long init_val);
extern void copy_init_pkru_to_fpregs(void); 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 */ #endif /*_ASM_X86_PKEYS_H */
...@@ -1312,11 +1312,3 @@ static int __init register_kernel_offset_dumper(void) ...@@ -1312,11 +1312,3 @@ static int __init register_kernel_offset_dumper(void)
return 0; return 0;
} }
__initcall(register_kernel_offset_dumper); __initcall(register_kernel_offset_dumper);
void arch_show_smap(struct seq_file *m, struct vm_area_struct *vma)
{
if (!boot_cpu_has(X86_FEATURE_OSPKE))
return;
seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma));
}
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/page_idle.h> #include <linux/page_idle.h>
#include <linux/shmem_fs.h> #include <linux/shmem_fs.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/pkeys.h>
#include <asm/elf.h> #include <asm/elf.h>
#include <asm/tlb.h> #include <asm/tlb.h>
...@@ -673,13 +674,16 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma) ...@@ -673,13 +674,16 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
[ilog2(VM_MERGEABLE)] = "mg", [ilog2(VM_MERGEABLE)] = "mg",
[ilog2(VM_UFFD_MISSING)]= "um", [ilog2(VM_UFFD_MISSING)]= "um",
[ilog2(VM_UFFD_WP)] = "uw", [ilog2(VM_UFFD_WP)] = "uw",
#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS #ifdef CONFIG_ARCH_HAS_PKEYS
/* These come out via ProtectionKey: */ /* These come out via ProtectionKey: */
[ilog2(VM_PKEY_BIT0)] = "", [ilog2(VM_PKEY_BIT0)] = "",
[ilog2(VM_PKEY_BIT1)] = "", [ilog2(VM_PKEY_BIT1)] = "",
[ilog2(VM_PKEY_BIT2)] = "", [ilog2(VM_PKEY_BIT2)] = "",
[ilog2(VM_PKEY_BIT3)] = "", [ilog2(VM_PKEY_BIT3)] = "",
#if VM_PKEY_BIT4
[ilog2(VM_PKEY_BIT4)] = "",
#endif #endif
#endif /* CONFIG_ARCH_HAS_PKEYS */
}; };
size_t i; size_t i;
...@@ -727,10 +731,6 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned long hmask, ...@@ -727,10 +731,6 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned long hmask,
} }
#endif /* HUGETLB_PAGE */ #endif /* HUGETLB_PAGE */
void __weak arch_show_smap(struct seq_file *m, struct vm_area_struct *vma)
{
}
#define SEQ_PUT_DEC(str, val) \ #define SEQ_PUT_DEC(str, val) \
seq_put_decimal_ull_width(m, str, (val) >> 10, 8) seq_put_decimal_ull_width(m, str, (val) >> 10, 8)
static int show_smap(struct seq_file *m, void *v, int is_pid) static int show_smap(struct seq_file *m, void *v, int is_pid)
...@@ -835,7 +835,8 @@ static int show_smap(struct seq_file *m, void *v, int is_pid) ...@@ -835,7 +835,8 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
seq_puts(m, " kB\n"); seq_puts(m, " kB\n");
} }
if (!rollup_mode) { if (!rollup_mode) {
arch_show_smap(m, vma); if (arch_pkeys_enabled())
seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma));
show_smap_vma_flags(m, vma); show_smap_vma_flags(m, vma);
} }
m_cache_vma(m, vma); m_cache_vma(m, vma);
......
...@@ -228,15 +228,21 @@ extern unsigned int kobjsize(const void *objp); ...@@ -228,15 +228,21 @@ extern unsigned int kobjsize(const void *objp);
#define VM_HIGH_ARCH_4 BIT(VM_HIGH_ARCH_BIT_4) #define VM_HIGH_ARCH_4 BIT(VM_HIGH_ARCH_BIT_4)
#endif /* CONFIG_ARCH_USES_HIGH_VMA_FLAGS */ #endif /* CONFIG_ARCH_USES_HIGH_VMA_FLAGS */
#if defined(CONFIG_X86) #ifdef CONFIG_ARCH_HAS_PKEYS
# define VM_PAT VM_ARCH_1 /* PAT reserves whole VMA at once (x86) */
#if defined (CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS)
# define VM_PKEY_SHIFT VM_HIGH_ARCH_BIT_0 # define VM_PKEY_SHIFT VM_HIGH_ARCH_BIT_0
# define VM_PKEY_BIT0 VM_HIGH_ARCH_0 /* A protection key is a 4-bit value */ # define VM_PKEY_BIT0 VM_HIGH_ARCH_0 /* A protection key is a 4-bit value */
# define VM_PKEY_BIT1 VM_HIGH_ARCH_1 # define VM_PKEY_BIT1 VM_HIGH_ARCH_1 /* on x86 and 5-bit value on ppc64 */
# define VM_PKEY_BIT2 VM_HIGH_ARCH_2 # define VM_PKEY_BIT2 VM_HIGH_ARCH_2
# define VM_PKEY_BIT3 VM_HIGH_ARCH_3 # define VM_PKEY_BIT3 VM_HIGH_ARCH_3
#ifdef CONFIG_PPC
# define VM_PKEY_BIT4 VM_HIGH_ARCH_4
#else
# define VM_PKEY_BIT4 0
#endif #endif
#endif /* CONFIG_ARCH_HAS_PKEYS */
#if defined(CONFIG_X86)
# define VM_PAT VM_ARCH_1 /* PAT reserves whole VMA at once (x86) */
#elif defined(CONFIG_PPC) #elif defined(CONFIG_PPC)
# define VM_SAO VM_ARCH_1 /* Strong Access Ordering (powerpc) */ # define VM_SAO VM_ARCH_1 /* Strong Access Ordering (powerpc) */
#elif defined(CONFIG_PARISC) #elif defined(CONFIG_PARISC)
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
#ifndef _LINUX_PKEYS_H #ifndef _LINUX_PKEYS_H
#define _LINUX_PKEYS_H #define _LINUX_PKEYS_H
#include <linux/mm_types.h> #include <linux/mm.h>
#include <asm/mmu_context.h>
#ifdef CONFIG_ARCH_HAS_PKEYS #ifdef CONFIG_ARCH_HAS_PKEYS
#include <asm/pkeys.h> #include <asm/pkeys.h>
...@@ -14,6 +13,11 @@ ...@@ -14,6 +13,11 @@
#define PKEY_DEDICATED_EXECUTE_ONLY 0 #define PKEY_DEDICATED_EXECUTE_ONLY 0
#define ARCH_VM_PKEY_FLAGS 0 #define ARCH_VM_PKEY_FLAGS 0
static inline int vma_pkey(struct vm_area_struct *vma)
{
return 0;
}
static inline bool mm_pkey_is_allocated(struct mm_struct *mm, int pkey) static inline bool mm_pkey_is_allocated(struct mm_struct *mm, int pkey)
{ {
return (pkey == 0); return (pkey == 0);
...@@ -35,6 +39,11 @@ static inline int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, ...@@ -35,6 +39,11 @@ static inline int arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
return 0; return 0;
} }
static inline bool arch_pkeys_enabled(void)
{
return false;
}
static inline void copy_init_pkru_to_fpregs(void) static inline void copy_init_pkru_to_fpregs(void)
{ {
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册