hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/arch/powerpc/include/asm/pkeys.h
....@@ -11,9 +11,7 @@
1111 #include <linux/jump_label.h>
1212 #include <asm/firmware.h>
1313
14
-DECLARE_STATIC_KEY_TRUE(pkey_disabled);
15
-extern int pkeys_total; /* total pkeys as per device tree */
16
-extern u32 initial_allocation_mask; /* bits set for the initially allocated keys */
14
+extern int num_pkey;
1715 extern u32 reserved_allocation_mask; /* bits set for reserved keys */
1816
1917 #define ARCH_VM_PKEY_FLAGS (VM_PKEY_BIT0 | VM_PKEY_BIT1 | VM_PKEY_BIT2 | \
....@@ -25,48 +23,28 @@
2523 PKEY_DISABLE_WRITE | \
2624 PKEY_DISABLE_EXECUTE)
2725
26
+#ifdef CONFIG_PPC_BOOK3S_64
27
+#include <asm/book3s/64/pkeys.h>
28
+#else
29
+#error "Not supported"
30
+#endif
31
+
32
+
2833 static inline u64 pkey_to_vmflag_bits(u16 pkey)
2934 {
3035 return (((u64)pkey << VM_PKEY_SHIFT) & ARCH_VM_PKEY_FLAGS);
3136 }
3237
33
-static inline u64 vmflag_to_pte_pkey_bits(u64 vm_flags)
34
-{
35
- if (static_branch_likely(&pkey_disabled))
36
- return 0x0UL;
37
-
38
- return (((vm_flags & VM_PKEY_BIT0) ? H_PTE_PKEY_BIT4 : 0x0UL) |
39
- ((vm_flags & VM_PKEY_BIT1) ? H_PTE_PKEY_BIT3 : 0x0UL) |
40
- ((vm_flags & VM_PKEY_BIT2) ? H_PTE_PKEY_BIT2 : 0x0UL) |
41
- ((vm_flags & VM_PKEY_BIT3) ? H_PTE_PKEY_BIT1 : 0x0UL) |
42
- ((vm_flags & VM_PKEY_BIT4) ? H_PTE_PKEY_BIT0 : 0x0UL));
43
-}
44
-
4538 static inline int vma_pkey(struct vm_area_struct *vma)
4639 {
47
- if (static_branch_likely(&pkey_disabled))
40
+ if (!mmu_has_feature(MMU_FTR_PKEY))
4841 return 0;
4942 return (vma->vm_flags & ARCH_VM_PKEY_FLAGS) >> VM_PKEY_SHIFT;
5043 }
5144
52
-#define arch_max_pkey() pkeys_total
53
-
54
-static inline u64 pte_to_hpte_pkey_bits(u64 pteflags)
45
+static inline int arch_max_pkey(void)
5546 {
56
- return (((pteflags & H_PTE_PKEY_BIT0) ? HPTE_R_KEY_BIT0 : 0x0UL) |
57
- ((pteflags & H_PTE_PKEY_BIT1) ? HPTE_R_KEY_BIT1 : 0x0UL) |
58
- ((pteflags & H_PTE_PKEY_BIT2) ? HPTE_R_KEY_BIT2 : 0x0UL) |
59
- ((pteflags & H_PTE_PKEY_BIT3) ? HPTE_R_KEY_BIT3 : 0x0UL) |
60
- ((pteflags & H_PTE_PKEY_BIT4) ? HPTE_R_KEY_BIT4 : 0x0UL));
61
-}
62
-
63
-static inline u16 pte_to_pkey_bits(u64 pteflags)
64
-{
65
- return (((pteflags & H_PTE_PKEY_BIT0) ? 0x10 : 0x0UL) |
66
- ((pteflags & H_PTE_PKEY_BIT1) ? 0x8 : 0x0UL) |
67
- ((pteflags & H_PTE_PKEY_BIT2) ? 0x4 : 0x0UL) |
68
- ((pteflags & H_PTE_PKEY_BIT3) ? 0x2 : 0x0UL) |
69
- ((pteflags & H_PTE_PKEY_BIT4) ? 0x1 : 0x0UL));
47
+ return num_pkey;
7048 }
7149
7250 #define pkey_alloc_mask(pkey) (0x1 << pkey)
....@@ -101,7 +79,7 @@
10179
10280 /*
10381 * Returns a positive, 5-bit key on success, or -1 on failure.
104
- * Relies on the mmap_sem to protect against concurrency in mm_pkey_alloc() and
82
+ * Relies on the mmap_lock to protect against concurrency in mm_pkey_alloc() and
10583 * mm_pkey_free().
10684 */
10785 static inline int mm_pkey_alloc(struct mm_struct *mm)
....@@ -114,9 +92,8 @@
11492 u32 all_pkeys_mask = (u32)(~(0x0));
11593 int ret;
11694
117
- if (static_branch_likely(&pkey_disabled))
95
+ if (!mmu_has_feature(MMU_FTR_PKEY))
11896 return -1;
119
-
12097 /*
12198 * Are we out of pkeys? We must handle this specially because ffz()
12299 * behavior is undefined if there are no zeros.
....@@ -132,7 +109,7 @@
132109
133110 static inline int mm_pkey_free(struct mm_struct *mm, int pkey)
134111 {
135
- if (static_branch_likely(&pkey_disabled))
112
+ if (!mmu_has_feature(MMU_FTR_PKEY))
136113 return -1;
137114
138115 if (!mm_pkey_is_allocated(mm, pkey))
....@@ -147,21 +124,13 @@
147124 * Try to dedicate one of the protection keys to be used as an
148125 * execute-only protection key.
149126 */
150
-extern int __execute_only_pkey(struct mm_struct *mm);
151
-static inline int execute_only_pkey(struct mm_struct *mm)
152
-{
153
- if (static_branch_likely(&pkey_disabled))
154
- return -1;
155
-
156
- return __execute_only_pkey(mm);
157
-}
158
-
127
+extern int execute_only_pkey(struct mm_struct *mm);
159128 extern int __arch_override_mprotect_pkey(struct vm_area_struct *vma,
160129 int prot, int pkey);
161130 static inline int arch_override_mprotect_pkey(struct vm_area_struct *vma,
162131 int prot, int pkey)
163132 {
164
- if (static_branch_likely(&pkey_disabled))
133
+ if (!mmu_has_feature(MMU_FTR_PKEY))
165134 return 0;
166135
167136 /*
....@@ -179,7 +148,7 @@
179148 static inline int arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
180149 unsigned long init_val)
181150 {
182
- if (static_branch_likely(&pkey_disabled))
151
+ if (!mmu_has_feature(MMU_FTR_PKEY))
183152 return -EINVAL;
184153
185154 /*
....@@ -196,7 +165,7 @@
196165
197166 static inline bool arch_pkeys_enabled(void)
198167 {
199
- return !static_branch_likely(&pkey_disabled);
168
+ return mmu_has_feature(MMU_FTR_PKEY);
200169 }
201170
202171 extern void pkey_mm_init(struct mm_struct *mm);