.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * c 2001 PPC 64 Team, IBM Corp |
---|
3 | | - * |
---|
4 | | - * This program is free software; you can redistribute it and/or |
---|
5 | | - * modify it under the terms of the GNU General Public License |
---|
6 | | - * as published by the Free Software Foundation; either version |
---|
7 | | - * 2 of the License, or (at your option) any later version. |
---|
8 | 4 | */ |
---|
9 | 5 | |
---|
10 | 6 | #include <linux/smp.h> |
---|
11 | 7 | #include <linux/export.h> |
---|
12 | 8 | #include <linux/memblock.h> |
---|
13 | 9 | #include <linux/sched/task.h> |
---|
| 10 | +#include <linux/numa.h> |
---|
| 11 | +#include <linux/pgtable.h> |
---|
14 | 12 | |
---|
15 | 13 | #include <asm/lppaca.h> |
---|
16 | 14 | #include <asm/paca.h> |
---|
17 | 15 | #include <asm/sections.h> |
---|
18 | | -#include <asm/pgtable.h> |
---|
19 | 16 | #include <asm/kexec.h> |
---|
| 17 | +#include <asm/svm.h> |
---|
| 18 | +#include <asm/ultravisor.h> |
---|
| 19 | +#include <asm/rtas.h> |
---|
20 | 20 | |
---|
21 | 21 | #include "setup.h" |
---|
22 | 22 | |
---|
.. | .. |
---|
27 | 27 | static void *__init alloc_paca_data(unsigned long size, unsigned long align, |
---|
28 | 28 | unsigned long limit, int cpu) |
---|
29 | 29 | { |
---|
30 | | - unsigned long pa; |
---|
| 30 | + void *ptr; |
---|
31 | 31 | int nid; |
---|
32 | 32 | |
---|
33 | 33 | /* |
---|
.. | .. |
---|
36 | 36 | * which will put its paca in the right place. |
---|
37 | 37 | */ |
---|
38 | 38 | if (cpu == boot_cpuid) { |
---|
39 | | - nid = -1; |
---|
| 39 | + nid = NUMA_NO_NODE; |
---|
40 | 40 | memblock_set_bottom_up(true); |
---|
41 | 41 | } else { |
---|
42 | 42 | nid = early_cpu_to_node(cpu); |
---|
43 | 43 | } |
---|
44 | 44 | |
---|
45 | | - pa = memblock_alloc_base_nid(size, align, limit, nid, MEMBLOCK_NONE); |
---|
46 | | - if (!pa) { |
---|
47 | | - pa = memblock_alloc_base(size, align, limit); |
---|
48 | | - if (!pa) |
---|
49 | | - panic("cannot allocate paca data"); |
---|
50 | | - } |
---|
| 45 | + ptr = memblock_alloc_try_nid(size, align, MEMBLOCK_LOW_LIMIT, |
---|
| 46 | + limit, nid); |
---|
| 47 | + if (!ptr) |
---|
| 48 | + panic("cannot allocate paca data"); |
---|
51 | 49 | |
---|
52 | 50 | if (cpu == boot_cpuid) |
---|
53 | 51 | memblock_set_bottom_up(false); |
---|
54 | 52 | |
---|
55 | | - return __va(pa); |
---|
| 53 | + return ptr; |
---|
56 | 54 | } |
---|
57 | 55 | |
---|
58 | 56 | #ifdef CONFIG_PPC_PSERIES |
---|
| 57 | + |
---|
| 58 | +#define LPPACA_SIZE 0x400 |
---|
| 59 | + |
---|
| 60 | +static void *__init alloc_shared_lppaca(unsigned long size, unsigned long limit, |
---|
| 61 | + int cpu) |
---|
| 62 | +{ |
---|
| 63 | + size_t shared_lppaca_total_size = PAGE_ALIGN(nr_cpu_ids * LPPACA_SIZE); |
---|
| 64 | + static unsigned long shared_lppaca_size; |
---|
| 65 | + static void *shared_lppaca; |
---|
| 66 | + void *ptr; |
---|
| 67 | + |
---|
| 68 | + if (!shared_lppaca) { |
---|
| 69 | + memblock_set_bottom_up(true); |
---|
| 70 | + |
---|
| 71 | + /* |
---|
| 72 | + * See Documentation/powerpc/ultravisor.rst for more details. |
---|
| 73 | + * |
---|
| 74 | + * UV/HV data sharing is in PAGE_SIZE granularity. In order to |
---|
| 75 | + * minimize the number of pages shared, align the allocation to |
---|
| 76 | + * PAGE_SIZE. |
---|
| 77 | + */ |
---|
| 78 | + shared_lppaca = |
---|
| 79 | + memblock_alloc_try_nid(shared_lppaca_total_size, |
---|
| 80 | + PAGE_SIZE, MEMBLOCK_LOW_LIMIT, |
---|
| 81 | + limit, NUMA_NO_NODE); |
---|
| 82 | + if (!shared_lppaca) |
---|
| 83 | + panic("cannot allocate shared data"); |
---|
| 84 | + |
---|
| 85 | + memblock_set_bottom_up(false); |
---|
| 86 | + uv_share_page(PHYS_PFN(__pa(shared_lppaca)), |
---|
| 87 | + shared_lppaca_total_size >> PAGE_SHIFT); |
---|
| 88 | + } |
---|
| 89 | + |
---|
| 90 | + ptr = shared_lppaca + shared_lppaca_size; |
---|
| 91 | + shared_lppaca_size += size; |
---|
| 92 | + |
---|
| 93 | + /* |
---|
| 94 | + * This is very early in boot, so no harm done if the kernel crashes at |
---|
| 95 | + * this point. |
---|
| 96 | + */ |
---|
| 97 | + BUG_ON(shared_lppaca_size > shared_lppaca_total_size); |
---|
| 98 | + |
---|
| 99 | + return ptr; |
---|
| 100 | +} |
---|
59 | 101 | |
---|
60 | 102 | /* |
---|
61 | 103 | * See asm/lppaca.h for more detail. |
---|
.. | .. |
---|
70 | 112 | |
---|
71 | 113 | *lppaca = (struct lppaca) { |
---|
72 | 114 | .desc = cpu_to_be32(0xd397d781), /* "LpPa" */ |
---|
73 | | - .size = cpu_to_be16(0x400), |
---|
| 115 | + .size = cpu_to_be16(LPPACA_SIZE), |
---|
74 | 116 | .fpregs_in_use = 1, |
---|
75 | 117 | .slb_count = cpu_to_be16(64), |
---|
76 | 118 | .vmxregs_in_use = 0, |
---|
.. | .. |
---|
80 | 122 | static struct lppaca * __init new_lppaca(int cpu, unsigned long limit) |
---|
81 | 123 | { |
---|
82 | 124 | struct lppaca *lp; |
---|
83 | | - size_t size = 0x400; |
---|
84 | 125 | |
---|
85 | | - BUILD_BUG_ON(size < sizeof(struct lppaca)); |
---|
| 126 | + BUILD_BUG_ON(sizeof(struct lppaca) > LPPACA_SIZE); |
---|
86 | 127 | |
---|
87 | 128 | if (early_cpu_has_feature(CPU_FTR_HVMODE)) |
---|
88 | 129 | return NULL; |
---|
89 | 130 | |
---|
90 | | - lp = alloc_paca_data(size, 0x400, limit, cpu); |
---|
| 131 | + if (is_secure_guest()) |
---|
| 132 | + lp = alloc_shared_lppaca(LPPACA_SIZE, limit, cpu); |
---|
| 133 | + else |
---|
| 134 | + lp = alloc_paca_data(LPPACA_SIZE, 0x400, limit, cpu); |
---|
| 135 | + |
---|
91 | 136 | init_lppaca(lp); |
---|
92 | 137 | |
---|
93 | 138 | return lp; |
---|
94 | 139 | } |
---|
95 | | -#endif /* CONFIG_PPC_BOOK3S */ |
---|
| 140 | +#endif /* CONFIG_PPC_PSERIES */ |
---|
96 | 141 | |
---|
97 | 142 | #ifdef CONFIG_PPC_BOOK3S_64 |
---|
98 | 143 | |
---|
.. | .. |
---|
118 | 163 | } |
---|
119 | 164 | |
---|
120 | 165 | s = alloc_paca_data(sizeof(*s), L1_CACHE_BYTES, limit, cpu); |
---|
121 | | - memset(s, 0, sizeof(*s)); |
---|
122 | 166 | |
---|
123 | 167 | s->persistent = cpu_to_be32(SLB_NUM_BOLTED); |
---|
124 | 168 | s->buffer_length = cpu_to_be32(sizeof(*s)); |
---|
.. | .. |
---|
127 | 171 | } |
---|
128 | 172 | |
---|
129 | 173 | #endif /* CONFIG_PPC_BOOK3S_64 */ |
---|
| 174 | + |
---|
| 175 | +#ifdef CONFIG_PPC_PSERIES |
---|
| 176 | +/** |
---|
| 177 | + * new_rtas_args() - Allocates rtas args |
---|
| 178 | + * @cpu: CPU number |
---|
| 179 | + * @limit: Memory limit for this allocation |
---|
| 180 | + * |
---|
| 181 | + * Allocates a struct rtas_args and return it's pointer, |
---|
| 182 | + * if not in Hypervisor mode |
---|
| 183 | + * |
---|
| 184 | + * Return: Pointer to allocated rtas_args |
---|
| 185 | + * NULL if CPU in Hypervisor Mode |
---|
| 186 | + */ |
---|
| 187 | +static struct rtas_args * __init new_rtas_args(int cpu, unsigned long limit) |
---|
| 188 | +{ |
---|
| 189 | + limit = min_t(unsigned long, limit, RTAS_INSTANTIATE_MAX); |
---|
| 190 | + |
---|
| 191 | + if (early_cpu_has_feature(CPU_FTR_HVMODE)) |
---|
| 192 | + return NULL; |
---|
| 193 | + |
---|
| 194 | + return alloc_paca_data(sizeof(struct rtas_args), L1_CACHE_BYTES, |
---|
| 195 | + limit, cpu); |
---|
| 196 | +} |
---|
| 197 | +#endif /* CONFIG_PPC_PSERIES */ |
---|
130 | 198 | |
---|
131 | 199 | /* The Paca is an array with one entry per processor. Each contains an |
---|
132 | 200 | * lppaca, which contains the information shared between the |
---|
.. | .. |
---|
166 | 234 | /* For now -- if we have threads this will be adjusted later */ |
---|
167 | 235 | new_paca->tcd_ptr = &new_paca->tcd; |
---|
168 | 236 | #endif |
---|
| 237 | + |
---|
| 238 | +#ifdef CONFIG_PPC_PSERIES |
---|
| 239 | + new_paca->rtas_args_reentrant = NULL; |
---|
| 240 | +#endif |
---|
169 | 241 | } |
---|
170 | 242 | |
---|
171 | 243 | /* Put the paca pointer into r13 and SPRG_PACA */ |
---|
.. | .. |
---|
178 | 250 | /* On Book3E, initialize the TLB miss exception frames */ |
---|
179 | 251 | mtspr(SPRN_SPRG_TLB_EXFRAME, local_paca->extlb); |
---|
180 | 252 | #else |
---|
181 | | - /* In HV mode, we setup both HPACA and PACA to avoid problems |
---|
| 253 | + /* |
---|
| 254 | + * In HV mode, we setup both HPACA and PACA to avoid problems |
---|
182 | 255 | * if we do a GET_PACA() before the feature fixups have been |
---|
183 | | - * applied |
---|
| 256 | + * applied. |
---|
| 257 | + * |
---|
| 258 | + * Normally you should test against CPU_FTR_HVMODE, but CPU features |
---|
| 259 | + * are not yet set up when we first reach here. |
---|
184 | 260 | */ |
---|
185 | | - if (early_cpu_has_feature(CPU_FTR_HVMODE)) |
---|
| 261 | + if (mfmsr() & MSR_HV) |
---|
186 | 262 | mtspr(SPRN_SPRG_HPACA, local_paca); |
---|
187 | 263 | #endif |
---|
188 | 264 | mtspr(SPRN_SPRG_PACA, local_paca); |
---|
.. | .. |
---|
198 | 274 | paca_nr_cpu_ids = nr_cpu_ids; |
---|
199 | 275 | |
---|
200 | 276 | paca_ptrs_size = sizeof(struct paca_struct *) * nr_cpu_ids; |
---|
201 | | - paca_ptrs = __va(memblock_alloc(paca_ptrs_size, 0)); |
---|
| 277 | + paca_ptrs = memblock_alloc_raw(paca_ptrs_size, SMP_CACHE_BYTES); |
---|
| 278 | + if (!paca_ptrs) |
---|
| 279 | + panic("Failed to allocate %d bytes for paca pointers\n", |
---|
| 280 | + paca_ptrs_size); |
---|
| 281 | + |
---|
202 | 282 | memset(paca_ptrs, 0x88, paca_ptrs_size); |
---|
203 | 283 | } |
---|
204 | 284 | |
---|
.. | .. |
---|
222 | 302 | paca = alloc_paca_data(sizeof(struct paca_struct), L1_CACHE_BYTES, |
---|
223 | 303 | limit, cpu); |
---|
224 | 304 | paca_ptrs[cpu] = paca; |
---|
225 | | - memset(paca, 0, sizeof(struct paca_struct)); |
---|
226 | 305 | |
---|
227 | 306 | initialise_paca(paca, cpu); |
---|
228 | 307 | #ifdef CONFIG_PPC_PSERIES |
---|
.. | .. |
---|
230 | 309 | #endif |
---|
231 | 310 | #ifdef CONFIG_PPC_BOOK3S_64 |
---|
232 | 311 | paca->slb_shadow_ptr = new_slb_shadow(cpu, limit); |
---|
| 312 | +#endif |
---|
| 313 | +#ifdef CONFIG_PPC_PSERIES |
---|
| 314 | + paca->rtas_args_reentrant = new_rtas_args(cpu, limit); |
---|
233 | 315 | #endif |
---|
234 | 316 | paca_struct_size += sizeof(struct paca_struct); |
---|
235 | 317 | } |
---|
.. | .. |
---|
266 | 348 | |
---|
267 | 349 | get_paca()->mm_ctx_id = context->id; |
---|
268 | 350 | #ifdef CONFIG_PPC_MM_SLICES |
---|
269 | | - VM_BUG_ON(!mm->context.slb_addr_limit); |
---|
270 | | - get_paca()->mm_ctx_slb_addr_limit = mm->context.slb_addr_limit; |
---|
271 | | - memcpy(&get_paca()->mm_ctx_low_slices_psize, |
---|
272 | | - &context->low_slices_psize, sizeof(context->low_slices_psize)); |
---|
273 | | - memcpy(&get_paca()->mm_ctx_high_slices_psize, |
---|
274 | | - &context->high_slices_psize, TASK_SLICE_ARRAY_SZ(mm)); |
---|
| 351 | + VM_BUG_ON(!mm_ctx_slb_addr_limit(context)); |
---|
| 352 | + get_paca()->mm_ctx_slb_addr_limit = mm_ctx_slb_addr_limit(context); |
---|
| 353 | + memcpy(&get_paca()->mm_ctx_low_slices_psize, mm_ctx_low_slices(context), |
---|
| 354 | + LOW_SLICE_ARRAY_SZ); |
---|
| 355 | + memcpy(&get_paca()->mm_ctx_high_slices_psize, mm_ctx_high_slices(context), |
---|
| 356 | + TASK_SLICE_ARRAY_SZ(context)); |
---|
275 | 357 | #else /* CONFIG_PPC_MM_SLICES */ |
---|
276 | 358 | get_paca()->mm_ctx_user_psize = context->user_psize; |
---|
277 | 359 | get_paca()->mm_ctx_sllp = context->sllp; |
---|