.. | .. |
---|
11 | 11 | #include <linux/jump_label.h> |
---|
12 | 12 | #include <asm/firmware.h> |
---|
13 | 13 | |
---|
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; |
---|
17 | 15 | extern u32 reserved_allocation_mask; /* bits set for reserved keys */ |
---|
18 | 16 | |
---|
19 | 17 | #define ARCH_VM_PKEY_FLAGS (VM_PKEY_BIT0 | VM_PKEY_BIT1 | VM_PKEY_BIT2 | \ |
---|
.. | .. |
---|
25 | 23 | PKEY_DISABLE_WRITE | \ |
---|
26 | 24 | PKEY_DISABLE_EXECUTE) |
---|
27 | 25 | |
---|
| 26 | +#ifdef CONFIG_PPC_BOOK3S_64 |
---|
| 27 | +#include <asm/book3s/64/pkeys.h> |
---|
| 28 | +#else |
---|
| 29 | +#error "Not supported" |
---|
| 30 | +#endif |
---|
| 31 | + |
---|
| 32 | + |
---|
28 | 33 | static inline u64 pkey_to_vmflag_bits(u16 pkey) |
---|
29 | 34 | { |
---|
30 | 35 | return (((u64)pkey << VM_PKEY_SHIFT) & ARCH_VM_PKEY_FLAGS); |
---|
31 | 36 | } |
---|
32 | 37 | |
---|
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 | | - |
---|
45 | 38 | static inline int vma_pkey(struct vm_area_struct *vma) |
---|
46 | 39 | { |
---|
47 | | - if (static_branch_likely(&pkey_disabled)) |
---|
| 40 | + if (!mmu_has_feature(MMU_FTR_PKEY)) |
---|
48 | 41 | return 0; |
---|
49 | 42 | return (vma->vm_flags & ARCH_VM_PKEY_FLAGS) >> VM_PKEY_SHIFT; |
---|
50 | 43 | } |
---|
51 | 44 | |
---|
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) |
---|
55 | 46 | { |
---|
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; |
---|
70 | 48 | } |
---|
71 | 49 | |
---|
72 | 50 | #define pkey_alloc_mask(pkey) (0x1 << pkey) |
---|
.. | .. |
---|
101 | 79 | |
---|
102 | 80 | /* |
---|
103 | 81 | * 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 |
---|
105 | 83 | * mm_pkey_free(). |
---|
106 | 84 | */ |
---|
107 | 85 | static inline int mm_pkey_alloc(struct mm_struct *mm) |
---|
.. | .. |
---|
114 | 92 | u32 all_pkeys_mask = (u32)(~(0x0)); |
---|
115 | 93 | int ret; |
---|
116 | 94 | |
---|
117 | | - if (static_branch_likely(&pkey_disabled)) |
---|
| 95 | + if (!mmu_has_feature(MMU_FTR_PKEY)) |
---|
118 | 96 | return -1; |
---|
119 | | - |
---|
120 | 97 | /* |
---|
121 | 98 | * Are we out of pkeys? We must handle this specially because ffz() |
---|
122 | 99 | * behavior is undefined if there are no zeros. |
---|
.. | .. |
---|
132 | 109 | |
---|
133 | 110 | static inline int mm_pkey_free(struct mm_struct *mm, int pkey) |
---|
134 | 111 | { |
---|
135 | | - if (static_branch_likely(&pkey_disabled)) |
---|
| 112 | + if (!mmu_has_feature(MMU_FTR_PKEY)) |
---|
136 | 113 | return -1; |
---|
137 | 114 | |
---|
138 | 115 | if (!mm_pkey_is_allocated(mm, pkey)) |
---|
.. | .. |
---|
147 | 124 | * Try to dedicate one of the protection keys to be used as an |
---|
148 | 125 | * execute-only protection key. |
---|
149 | 126 | */ |
---|
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); |
---|
159 | 128 | extern int __arch_override_mprotect_pkey(struct vm_area_struct *vma, |
---|
160 | 129 | int prot, int pkey); |
---|
161 | 130 | static inline int arch_override_mprotect_pkey(struct vm_area_struct *vma, |
---|
162 | 131 | int prot, int pkey) |
---|
163 | 132 | { |
---|
164 | | - if (static_branch_likely(&pkey_disabled)) |
---|
| 133 | + if (!mmu_has_feature(MMU_FTR_PKEY)) |
---|
165 | 134 | return 0; |
---|
166 | 135 | |
---|
167 | 136 | /* |
---|
.. | .. |
---|
179 | 148 | static inline int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, |
---|
180 | 149 | unsigned long init_val) |
---|
181 | 150 | { |
---|
182 | | - if (static_branch_likely(&pkey_disabled)) |
---|
| 151 | + if (!mmu_has_feature(MMU_FTR_PKEY)) |
---|
183 | 152 | return -EINVAL; |
---|
184 | 153 | |
---|
185 | 154 | /* |
---|
.. | .. |
---|
196 | 165 | |
---|
197 | 166 | static inline bool arch_pkeys_enabled(void) |
---|
198 | 167 | { |
---|
199 | | - return !static_branch_likely(&pkey_disabled); |
---|
| 168 | + return mmu_has_feature(MMU_FTR_PKEY); |
---|
200 | 169 | } |
---|
201 | 170 | |
---|
202 | 171 | extern void pkey_mm_init(struct mm_struct *mm); |
---|