powerpc/book3s64/pkeys: Use MMU_FTR_PKEY instead of pkey_disabled static key
authorAneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Thu, 9 Jul 2020 03:29:39 +0000 (08:59 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 20 Jul 2020 12:57:59 +0000 (22:57 +1000)
Instead of pkey_disabled static key use mmu feature MMU_FTR_PKEY.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200709032946.881753-17-aneesh.kumar@linux.ibm.com
arch/powerpc/include/asm/book3s/64/pkeys.h
arch/powerpc/include/asm/pkeys.h
arch/powerpc/mm/book3s64/pkeys.c

index 8174662a9173136d37a542443266fba69a0ee013..5b178139f3c08a00e84a9571c1919aa72c864b2c 100644 (file)
@@ -7,7 +7,7 @@
 
 static inline u64 vmflag_to_pte_pkey_bits(u64 vm_flags)
 {
-       if (static_branch_likely(&pkey_disabled))
+       if (!mmu_has_feature(MMU_FTR_PKEY))
                return 0x0UL;
 
        if (radix_enabled())
index f44a14d64d47c5478338b6db35b10ada212665c5..a7951049e1299b07cc3e9e304c4ea05f053f03e8 100644 (file)
@@ -11,7 +11,6 @@
 #include <linux/jump_label.h>
 #include <asm/firmware.h>
 
-DECLARE_STATIC_KEY_FALSE(pkey_disabled);
 extern int num_pkey;
 extern u32 reserved_allocation_mask; /* bits set for reserved keys */
 
@@ -38,7 +37,7 @@ static inline u64 pkey_to_vmflag_bits(u16 pkey)
 
 static inline int vma_pkey(struct vm_area_struct *vma)
 {
-       if (static_branch_likely(&pkey_disabled))
+       if (!mmu_has_feature(MMU_FTR_PKEY))
                return 0;
        return (vma->vm_flags & ARCH_VM_PKEY_FLAGS) >> VM_PKEY_SHIFT;
 }
@@ -93,9 +92,8 @@ static inline int mm_pkey_alloc(struct mm_struct *mm)
        u32 all_pkeys_mask = (u32)(~(0x0));
        int ret;
 
-       if (static_branch_likely(&pkey_disabled))
+       if (!mmu_has_feature(MMU_FTR_PKEY))
                return -1;
-
        /*
         * Are we out of pkeys? We must handle this specially because ffz()
         * behavior is undefined if there are no zeros.
@@ -111,7 +109,7 @@ static inline int mm_pkey_alloc(struct mm_struct *mm)
 
 static inline int mm_pkey_free(struct mm_struct *mm, int pkey)
 {
-       if (static_branch_likely(&pkey_disabled))
+       if (!mmu_has_feature(MMU_FTR_PKEY))
                return -1;
 
        if (!mm_pkey_is_allocated(mm, pkey))
@@ -132,7 +130,7 @@ extern int __arch_override_mprotect_pkey(struct vm_area_struct *vma,
 static inline int arch_override_mprotect_pkey(struct vm_area_struct *vma,
                                              int prot, int pkey)
 {
-       if (static_branch_likely(&pkey_disabled))
+       if (!mmu_has_feature(MMU_FTR_PKEY))
                return 0;
 
        /*
@@ -150,7 +148,7 @@ extern int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
 static inline int arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
                                            unsigned long init_val)
 {
-       if (static_branch_likely(&pkey_disabled))
+       if (!mmu_has_feature(MMU_FTR_PKEY))
                return -EINVAL;
 
        /*
@@ -167,7 +165,7 @@ static inline int arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
 
 static inline bool arch_pkeys_enabled(void)
 {
-       return !static_branch_likely(&pkey_disabled);
+       return mmu_has_feature(MMU_FTR_PKEY);
 }
 
 extern void pkey_mm_init(struct mm_struct *mm);
index 9969bc82e2cefa72d552608f1148a5b0315fb3fc..2c1bddccd67b13d3aff2f0ec490e943a604c78b0 100644 (file)
@@ -12,8 +12,6 @@
 #include <linux/pkeys.h>
 #include <linux/of_fdt.h>
 
-
-DEFINE_STATIC_KEY_FALSE(pkey_disabled);
 int  num_pkey;         /* Max number of pkeys supported */
 /*
  *  Keys marked in the reservation list cannot be allocated by  userspace
@@ -126,7 +124,6 @@ void __init pkey_early_init_devtree(void)
        pkeys_total = scan_pkey_feature();
        if (!pkeys_total) {
                /* No support for pkey. Mark it disabled */
-               static_branch_enable(&pkey_disabled);
                return;
        }
 
@@ -216,7 +213,7 @@ void __init pkey_early_init_devtree(void)
 
 void pkey_mm_init(struct mm_struct *mm)
 {
-       if (static_branch_likely(&pkey_disabled))
+       if (!mmu_has_feature(MMU_FTR_PKEY))
                return;
        mm_pkey_allocation_map(mm) = initial_allocation_mask;
        mm->context.execute_only_pkey = execute_only_key;
@@ -320,7 +317,7 @@ int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
 
 void thread_pkey_regs_save(struct thread_struct *thread)
 {
-       if (static_branch_likely(&pkey_disabled))
+       if (!mmu_has_feature(MMU_FTR_PKEY))
                return;
 
        /*
@@ -334,7 +331,7 @@ void thread_pkey_regs_save(struct thread_struct *thread)
 void thread_pkey_regs_restore(struct thread_struct *new_thread,
                              struct thread_struct *old_thread)
 {
-       if (static_branch_likely(&pkey_disabled))
+       if (!mmu_has_feature(MMU_FTR_PKEY))
                return;
 
        if (old_thread->amr != new_thread->amr)
@@ -347,7 +344,7 @@ void thread_pkey_regs_restore(struct thread_struct *new_thread,
 
 void thread_pkey_regs_init(struct thread_struct *thread)
 {
-       if (static_branch_likely(&pkey_disabled))
+       if (!mmu_has_feature(MMU_FTR_PKEY))
                return;
 
        thread->amr   = default_amr;
@@ -418,7 +415,7 @@ static bool pkey_access_permitted(int pkey, bool write, bool execute)
 
 bool arch_pte_access_permitted(u64 pte, bool write, bool execute)
 {
-       if (static_branch_likely(&pkey_disabled))
+       if (!mmu_has_feature(MMU_FTR_PKEY))
                return true;
 
        return pkey_access_permitted(pte_to_pkey_bits(pte), write, execute);
@@ -435,7 +432,7 @@ bool arch_pte_access_permitted(u64 pte, bool write, bool execute)
 bool arch_vma_access_permitted(struct vm_area_struct *vma, bool write,
                               bool execute, bool foreign)
 {
-       if (static_branch_likely(&pkey_disabled))
+       if (!mmu_has_feature(MMU_FTR_PKEY))
                return true;
        /*
         * Do not enforce our key-permissions on a foreign vma.
@@ -448,7 +445,7 @@ bool arch_vma_access_permitted(struct vm_area_struct *vma, bool write,
 
 void arch_dup_pkeys(struct mm_struct *oldmm, struct mm_struct *mm)
 {
-       if (static_branch_likely(&pkey_disabled))
+       if (!mmu_has_feature(MMU_FTR_PKEY))
                return;
 
        /* Duplicate the oldmm pkey state in mm: */