.. | .. |
---|
23 | 23 | #include <linux/mm.h> |
---|
24 | 24 | #include <linux/types.h> |
---|
25 | 25 | #include <linux/spinlock.h> |
---|
26 | | -#include <linux/bootmem.h> |
---|
| 26 | +#include <linux/memblock.h> |
---|
27 | 27 | #include <linux/ioport.h> |
---|
28 | 28 | #include <linux/mc146818rtc.h> |
---|
29 | 29 | #include <linux/efi.h> |
---|
.. | .. |
---|
39 | 39 | #include <asm/setup.h> |
---|
40 | 40 | #include <asm/page.h> |
---|
41 | 41 | #include <asm/e820/api.h> |
---|
42 | | -#include <asm/pgtable.h> |
---|
43 | 42 | #include <asm/tlbflush.h> |
---|
44 | 43 | #include <asm/proto.h> |
---|
45 | 44 | #include <asm/efi.h> |
---|
.. | .. |
---|
48 | 47 | #include <asm/realmode.h> |
---|
49 | 48 | #include <asm/time.h> |
---|
50 | 49 | #include <asm/pgalloc.h> |
---|
| 50 | +#include <asm/sev-es.h> |
---|
51 | 51 | |
---|
52 | 52 | /* |
---|
53 | 53 | * We allocate runtime services regions top-down, starting from -4G, i.e. |
---|
.. | .. |
---|
56 | 56 | static u64 efi_va = EFI_VA_START; |
---|
57 | 57 | |
---|
58 | 58 | struct efi_scratch efi_scratch; |
---|
59 | | - |
---|
60 | | -static void __init early_code_mapping_set_exec(int executable) |
---|
61 | | -{ |
---|
62 | | - efi_memory_desc_t *md; |
---|
63 | | - |
---|
64 | | - if (!(__supported_pte_mask & _PAGE_NX)) |
---|
65 | | - return; |
---|
66 | | - |
---|
67 | | - /* Make EFI service code area executable */ |
---|
68 | | - for_each_efi_memory_desc(md) { |
---|
69 | | - if (md->type == EFI_RUNTIME_SERVICES_CODE || |
---|
70 | | - md->type == EFI_BOOT_SERVICES_CODE) |
---|
71 | | - efi_set_executable(md, executable); |
---|
72 | | - } |
---|
73 | | -} |
---|
74 | | - |
---|
75 | | -pgd_t * __init efi_call_phys_prolog(void) |
---|
76 | | -{ |
---|
77 | | - unsigned long vaddr, addr_pgd, addr_p4d, addr_pud; |
---|
78 | | - pgd_t *save_pgd, *pgd_k, *pgd_efi; |
---|
79 | | - p4d_t *p4d, *p4d_k, *p4d_efi; |
---|
80 | | - pud_t *pud; |
---|
81 | | - |
---|
82 | | - int pgd; |
---|
83 | | - int n_pgds, i, j; |
---|
84 | | - |
---|
85 | | - if (!efi_enabled(EFI_OLD_MEMMAP)) { |
---|
86 | | - efi_switch_mm(&efi_mm); |
---|
87 | | - return NULL; |
---|
88 | | - } |
---|
89 | | - |
---|
90 | | - early_code_mapping_set_exec(1); |
---|
91 | | - |
---|
92 | | - n_pgds = DIV_ROUND_UP((max_pfn << PAGE_SHIFT), PGDIR_SIZE); |
---|
93 | | - save_pgd = kmalloc_array(n_pgds, sizeof(*save_pgd), GFP_KERNEL); |
---|
94 | | - |
---|
95 | | - /* |
---|
96 | | - * Build 1:1 identity mapping for efi=old_map usage. Note that |
---|
97 | | - * PAGE_OFFSET is PGDIR_SIZE aligned when KASLR is disabled, while |
---|
98 | | - * it is PUD_SIZE ALIGNED with KASLR enabled. So for a given physical |
---|
99 | | - * address X, the pud_index(X) != pud_index(__va(X)), we can only copy |
---|
100 | | - * PUD entry of __va(X) to fill in pud entry of X to build 1:1 mapping. |
---|
101 | | - * This means here we can only reuse the PMD tables of the direct mapping. |
---|
102 | | - */ |
---|
103 | | - for (pgd = 0; pgd < n_pgds; pgd++) { |
---|
104 | | - addr_pgd = (unsigned long)(pgd * PGDIR_SIZE); |
---|
105 | | - vaddr = (unsigned long)__va(pgd * PGDIR_SIZE); |
---|
106 | | - pgd_efi = pgd_offset_k(addr_pgd); |
---|
107 | | - save_pgd[pgd] = *pgd_efi; |
---|
108 | | - |
---|
109 | | - p4d = p4d_alloc(&init_mm, pgd_efi, addr_pgd); |
---|
110 | | - if (!p4d) { |
---|
111 | | - pr_err("Failed to allocate p4d table!\n"); |
---|
112 | | - goto out; |
---|
113 | | - } |
---|
114 | | - |
---|
115 | | - for (i = 0; i < PTRS_PER_P4D; i++) { |
---|
116 | | - addr_p4d = addr_pgd + i * P4D_SIZE; |
---|
117 | | - p4d_efi = p4d + p4d_index(addr_p4d); |
---|
118 | | - |
---|
119 | | - pud = pud_alloc(&init_mm, p4d_efi, addr_p4d); |
---|
120 | | - if (!pud) { |
---|
121 | | - pr_err("Failed to allocate pud table!\n"); |
---|
122 | | - goto out; |
---|
123 | | - } |
---|
124 | | - |
---|
125 | | - for (j = 0; j < PTRS_PER_PUD; j++) { |
---|
126 | | - addr_pud = addr_p4d + j * PUD_SIZE; |
---|
127 | | - |
---|
128 | | - if (addr_pud > (max_pfn << PAGE_SHIFT)) |
---|
129 | | - break; |
---|
130 | | - |
---|
131 | | - vaddr = (unsigned long)__va(addr_pud); |
---|
132 | | - |
---|
133 | | - pgd_k = pgd_offset_k(vaddr); |
---|
134 | | - p4d_k = p4d_offset(pgd_k, vaddr); |
---|
135 | | - pud[j] = *pud_offset(p4d_k, vaddr); |
---|
136 | | - } |
---|
137 | | - } |
---|
138 | | - pgd_offset_k(pgd * PGDIR_SIZE)->pgd &= ~_PAGE_NX; |
---|
139 | | - } |
---|
140 | | - |
---|
141 | | -out: |
---|
142 | | - __flush_tlb_all(); |
---|
143 | | - |
---|
144 | | - return save_pgd; |
---|
145 | | -} |
---|
146 | | - |
---|
147 | | -void __init efi_call_phys_epilog(pgd_t *save_pgd) |
---|
148 | | -{ |
---|
149 | | - /* |
---|
150 | | - * After the lock is released, the original page table is restored. |
---|
151 | | - */ |
---|
152 | | - int pgd_idx, i; |
---|
153 | | - int nr_pgds; |
---|
154 | | - pgd_t *pgd; |
---|
155 | | - p4d_t *p4d; |
---|
156 | | - pud_t *pud; |
---|
157 | | - |
---|
158 | | - if (!efi_enabled(EFI_OLD_MEMMAP)) { |
---|
159 | | - efi_switch_mm(efi_scratch.prev_mm); |
---|
160 | | - return; |
---|
161 | | - } |
---|
162 | | - |
---|
163 | | - nr_pgds = DIV_ROUND_UP((max_pfn << PAGE_SHIFT) , PGDIR_SIZE); |
---|
164 | | - |
---|
165 | | - for (pgd_idx = 0; pgd_idx < nr_pgds; pgd_idx++) { |
---|
166 | | - pgd = pgd_offset_k(pgd_idx * PGDIR_SIZE); |
---|
167 | | - set_pgd(pgd_offset_k(pgd_idx * PGDIR_SIZE), save_pgd[pgd_idx]); |
---|
168 | | - |
---|
169 | | - if (!pgd_present(*pgd)) |
---|
170 | | - continue; |
---|
171 | | - |
---|
172 | | - for (i = 0; i < PTRS_PER_P4D; i++) { |
---|
173 | | - p4d = p4d_offset(pgd, |
---|
174 | | - pgd_idx * PGDIR_SIZE + i * P4D_SIZE); |
---|
175 | | - |
---|
176 | | - if (!p4d_present(*p4d)) |
---|
177 | | - continue; |
---|
178 | | - |
---|
179 | | - pud = (pud_t *)p4d_page_vaddr(*p4d); |
---|
180 | | - pud_free(&init_mm, pud); |
---|
181 | | - } |
---|
182 | | - |
---|
183 | | - p4d = (p4d_t *)pgd_page_vaddr(*pgd); |
---|
184 | | - p4d_free(&init_mm, p4d); |
---|
185 | | - } |
---|
186 | | - |
---|
187 | | - kfree(save_pgd); |
---|
188 | | - |
---|
189 | | - __flush_tlb_all(); |
---|
190 | | - early_code_mapping_set_exec(0); |
---|
191 | | -} |
---|
192 | 59 | |
---|
193 | 60 | EXPORT_SYMBOL_GPL(efi_mm); |
---|
194 | 61 | |
---|
.. | .. |
---|
207 | 74 | p4d_t *p4d; |
---|
208 | 75 | pud_t *pud; |
---|
209 | 76 | gfp_t gfp_mask; |
---|
210 | | - |
---|
211 | | - if (efi_enabled(EFI_OLD_MEMMAP)) |
---|
212 | | - return 0; |
---|
213 | 77 | |
---|
214 | 78 | gfp_mask = GFP_KERNEL | __GFP_ZERO; |
---|
215 | 79 | efi_pgd = (pgd_t *)__get_free_pages(gfp_mask, PGD_ALLOCATION_ORDER); |
---|
.. | .. |
---|
251 | 115 | pud_t *pud_k, *pud_efi; |
---|
252 | 116 | pgd_t *efi_pgd = efi_mm.pgd; |
---|
253 | 117 | |
---|
254 | | - if (efi_enabled(EFI_OLD_MEMMAP)) |
---|
255 | | - return; |
---|
256 | | - |
---|
257 | | - /* |
---|
258 | | - * We can share all PGD entries apart from the one entry that |
---|
259 | | - * covers the EFI runtime mapping space. |
---|
260 | | - * |
---|
261 | | - * Make sure the EFI runtime region mappings are guaranteed to |
---|
262 | | - * only span a single PGD entry and that the entry also maps |
---|
263 | | - * other important kernel regions. |
---|
264 | | - */ |
---|
265 | | - MAYBE_BUILD_BUG_ON(pgd_index(EFI_VA_END) != pgd_index(MODULES_END)); |
---|
266 | | - MAYBE_BUILD_BUG_ON((EFI_VA_START & PGDIR_MASK) != |
---|
267 | | - (EFI_VA_END & PGDIR_MASK)); |
---|
268 | | - |
---|
269 | 118 | pgd_efi = efi_pgd + pgd_index(PAGE_OFFSET); |
---|
270 | 119 | pgd_k = pgd_offset_k(PAGE_OFFSET); |
---|
271 | 120 | |
---|
272 | 121 | num_entries = pgd_index(EFI_VA_END) - pgd_index(PAGE_OFFSET); |
---|
273 | 122 | memcpy(pgd_efi, pgd_k, sizeof(pgd_t) * num_entries); |
---|
274 | | - |
---|
275 | | - /* |
---|
276 | | - * As with PGDs, we share all P4D entries apart from the one entry |
---|
277 | | - * that covers the EFI runtime mapping space. |
---|
278 | | - */ |
---|
279 | | - BUILD_BUG_ON(p4d_index(EFI_VA_END) != p4d_index(MODULES_END)); |
---|
280 | | - BUILD_BUG_ON((EFI_VA_START & P4D_MASK) != (EFI_VA_END & P4D_MASK)); |
---|
281 | 123 | |
---|
282 | 124 | pgd_efi = efi_pgd + pgd_index(EFI_VA_END); |
---|
283 | 125 | pgd_k = pgd_offset_k(EFI_VA_END); |
---|
.. | .. |
---|
337 | 179 | |
---|
338 | 180 | int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages) |
---|
339 | 181 | { |
---|
340 | | - unsigned long pfn, text, pf; |
---|
| 182 | + unsigned long pfn, text, pf, rodata; |
---|
341 | 183 | struct page *page; |
---|
342 | 184 | unsigned npages; |
---|
343 | 185 | pgd_t *pgd = efi_mm.pgd; |
---|
344 | | - |
---|
345 | | - if (efi_enabled(EFI_OLD_MEMMAP)) |
---|
346 | | - return 0; |
---|
347 | 186 | |
---|
348 | 187 | /* |
---|
349 | 188 | * It can happen that the physical address of new_memmap lands in memory |
---|
.. | .. |
---|
369 | 208 | * as trim_bios_range() will reserve the first page and isolate it away |
---|
370 | 209 | * from memory allocators anyway. |
---|
371 | 210 | */ |
---|
372 | | - pf = _PAGE_RW; |
---|
373 | | - if (sev_active()) |
---|
374 | | - pf |= _PAGE_ENC; |
---|
375 | | - |
---|
376 | 211 | if (kernel_map_pages_in_pgd(pgd, 0x0, 0x0, 1, pf)) { |
---|
377 | 212 | pr_err("Failed to create 1:1 mapping for the first page!\n"); |
---|
| 213 | + return 1; |
---|
| 214 | + } |
---|
| 215 | + |
---|
| 216 | + /* |
---|
| 217 | + * When SEV-ES is active, the GHCB as set by the kernel will be used |
---|
| 218 | + * by firmware. Create a 1:1 unencrypted mapping for each GHCB. |
---|
| 219 | + */ |
---|
| 220 | + if (sev_es_efi_map_ghcbs(pgd)) { |
---|
| 221 | + pr_err("Failed to create 1:1 mapping for the GHCBs!\n"); |
---|
378 | 222 | return 1; |
---|
379 | 223 | } |
---|
380 | 224 | |
---|
.. | .. |
---|
384 | 228 | * text and allocate a new stack because we can't rely on the |
---|
385 | 229 | * stack pointer being < 4GB. |
---|
386 | 230 | */ |
---|
387 | | - if (!IS_ENABLED(CONFIG_EFI_MIXED) || efi_is_native()) |
---|
| 231 | + if (!efi_is_mixed()) |
---|
388 | 232 | return 0; |
---|
389 | 233 | |
---|
390 | 234 | page = alloc_page(GFP_KERNEL|__GFP_DMA32); |
---|
.. | .. |
---|
399 | 243 | text = __pa(_text); |
---|
400 | 244 | pfn = text >> PAGE_SHIFT; |
---|
401 | 245 | |
---|
402 | | - pf = _PAGE_RW | _PAGE_ENC; |
---|
| 246 | + pf = _PAGE_ENC; |
---|
403 | 247 | if (kernel_map_pages_in_pgd(pgd, pfn, text, npages, pf)) { |
---|
404 | 248 | pr_err("Failed to map kernel text 1:1\n"); |
---|
| 249 | + return 1; |
---|
| 250 | + } |
---|
| 251 | + |
---|
| 252 | + npages = (__end_rodata - __start_rodata) >> PAGE_SHIFT; |
---|
| 253 | + rodata = __pa(__start_rodata); |
---|
| 254 | + pfn = rodata >> PAGE_SHIFT; |
---|
| 255 | + |
---|
| 256 | + pf = _PAGE_NX | _PAGE_ENC; |
---|
| 257 | + if (kernel_map_pages_in_pgd(pgd, pfn, rodata, npages, pf)) { |
---|
| 258 | + pr_err("Failed to map kernel rodata 1:1\n"); |
---|
405 | 259 | return 1; |
---|
406 | 260 | } |
---|
407 | 261 | |
---|
.. | .. |
---|
413 | 267 | unsigned long flags = _PAGE_RW; |
---|
414 | 268 | unsigned long pfn; |
---|
415 | 269 | pgd_t *pgd = efi_mm.pgd; |
---|
| 270 | + |
---|
| 271 | + /* |
---|
| 272 | + * EFI_RUNTIME_SERVICES_CODE regions typically cover PE/COFF |
---|
| 273 | + * executable images in memory that consist of both R-X and |
---|
| 274 | + * RW- sections, so we cannot apply read-only or non-exec |
---|
| 275 | + * permissions just yet. However, modern EFI systems provide |
---|
| 276 | + * a memory attributes table that describes those sections |
---|
| 277 | + * with the appropriate restricted permissions, which are |
---|
| 278 | + * applied in efi_runtime_update_mappings() below. All other |
---|
| 279 | + * regions can be mapped non-executable at this point, with |
---|
| 280 | + * the exception of boot services code regions, but those will |
---|
| 281 | + * be unmapped again entirely in efi_free_boot_services(). |
---|
| 282 | + */ |
---|
| 283 | + if (md->type != EFI_BOOT_SERVICES_CODE && |
---|
| 284 | + md->type != EFI_RUNTIME_SERVICES_CODE) |
---|
| 285 | + flags |= _PAGE_NX; |
---|
416 | 286 | |
---|
417 | 287 | if (!(md->attribute & EFI_MEMORY_WB)) |
---|
418 | 288 | flags |= _PAGE_PCD; |
---|
.. | .. |
---|
431 | 301 | unsigned long size = md->num_pages << PAGE_SHIFT; |
---|
432 | 302 | u64 pa = md->phys_addr; |
---|
433 | 303 | |
---|
434 | | - if (efi_enabled(EFI_OLD_MEMMAP)) |
---|
435 | | - return old_map_region(md); |
---|
436 | | - |
---|
437 | 304 | /* |
---|
438 | 305 | * Make sure the 1:1 mappings are present as a catch-all for b0rked |
---|
439 | 306 | * firmware which doesn't update all internal pointers after switching |
---|
.. | .. |
---|
446 | 313 | * booting in EFI mixed mode, because even though we may be |
---|
447 | 314 | * running a 64-bit kernel, the firmware may only be 32-bit. |
---|
448 | 315 | */ |
---|
449 | | - if (!efi_is_native () && IS_ENABLED(CONFIG_EFI_MIXED)) { |
---|
| 316 | + if (efi_is_mixed()) { |
---|
450 | 317 | md->virt_addr = md->phys_addr; |
---|
451 | 318 | return; |
---|
452 | 319 | } |
---|
.. | .. |
---|
486 | 353 | { |
---|
487 | 354 | __map_region(md, md->phys_addr); |
---|
488 | 355 | __map_region(md, md->virt_addr); |
---|
489 | | -} |
---|
490 | | - |
---|
491 | | -void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size, |
---|
492 | | - u32 type, u64 attribute) |
---|
493 | | -{ |
---|
494 | | - unsigned long last_map_pfn; |
---|
495 | | - |
---|
496 | | - if (type == EFI_MEMORY_MAPPED_IO) |
---|
497 | | - return ioremap(phys_addr, size); |
---|
498 | | - |
---|
499 | | - last_map_pfn = init_memory_mapping(phys_addr, phys_addr + size); |
---|
500 | | - if ((last_map_pfn << PAGE_SHIFT) < phys_addr + size) { |
---|
501 | | - unsigned long top = last_map_pfn << PAGE_SHIFT; |
---|
502 | | - efi_ioremap(top, size - (top - phys_addr), type, attribute); |
---|
503 | | - } |
---|
504 | | - |
---|
505 | | - if (!(attribute & EFI_MEMORY_WB)) |
---|
506 | | - efi_memory_uc((u64)(unsigned long)__va(phys_addr), size); |
---|
507 | | - |
---|
508 | | - return (void __iomem *)__va(phys_addr); |
---|
509 | 356 | } |
---|
510 | 357 | |
---|
511 | 358 | void __init parse_efi_setup(u64 phys_addr, u32 data_len) |
---|
.. | .. |
---|
556 | 403 | { |
---|
557 | 404 | efi_memory_desc_t *md; |
---|
558 | 405 | |
---|
559 | | - if (efi_enabled(EFI_OLD_MEMMAP)) { |
---|
560 | | - if (__supported_pte_mask & _PAGE_NX) |
---|
561 | | - runtime_code_page_mkexec(); |
---|
562 | | - return; |
---|
563 | | - } |
---|
564 | | - |
---|
565 | 406 | /* |
---|
566 | 407 | * Use the EFI Memory Attribute Table for mapping permissions if it |
---|
567 | 408 | * exists, since it is intended to supersede EFI_PROPERTIES_TABLE. |
---|
.. | .. |
---|
610 | 451 | void __init efi_dump_pagetable(void) |
---|
611 | 452 | { |
---|
612 | 453 | #ifdef CONFIG_EFI_PGT_DUMP |
---|
613 | | - if (efi_enabled(EFI_OLD_MEMMAP)) |
---|
614 | | - ptdump_walk_pgd_level(NULL, swapper_pg_dir); |
---|
615 | | - else |
---|
616 | | - ptdump_walk_pgd_level(NULL, efi_mm.pgd); |
---|
| 454 | + ptdump_walk_pgd_level(NULL, &efi_mm); |
---|
617 | 455 | #endif |
---|
618 | 456 | } |
---|
619 | 457 | |
---|
620 | 458 | /* |
---|
621 | 459 | * Makes the calling thread switch to/from efi_mm context. Can be used |
---|
622 | | - * for SetVirtualAddressMap() i.e. current->active_mm == init_mm as well |
---|
623 | | - * as during efi runtime calls i.e current->active_mm == current_mm. |
---|
624 | | - * We are not mm_dropping()/mm_grabbing() any mm, because we are not |
---|
625 | | - * losing/creating any references. |
---|
| 460 | + * in a kernel thread and user context. Preemption needs to remain disabled |
---|
| 461 | + * while the EFI-mm is borrowed. mmgrab()/mmdrop() is not used because the mm |
---|
| 462 | + * can not change under us. |
---|
| 463 | + * It should be ensured that there are no concurent calls to this function. |
---|
626 | 464 | */ |
---|
627 | 465 | void efi_switch_mm(struct mm_struct *mm) |
---|
628 | 466 | { |
---|
629 | | - task_lock(current); |
---|
630 | 467 | efi_scratch.prev_mm = current->active_mm; |
---|
631 | 468 | current->active_mm = mm; |
---|
632 | 469 | switch_mm(efi_scratch.prev_mm, mm, NULL); |
---|
633 | | - task_unlock(current); |
---|
634 | 470 | } |
---|
635 | | - |
---|
636 | | -#ifdef CONFIG_EFI_MIXED |
---|
637 | | -extern efi_status_t efi64_thunk(u32, ...); |
---|
638 | 471 | |
---|
639 | 472 | static DEFINE_SPINLOCK(efi_runtime_lock); |
---|
640 | 473 | |
---|
641 | | -#define runtime_service32(func) \ |
---|
642 | | -({ \ |
---|
643 | | - u32 table = (u32)(unsigned long)efi.systab; \ |
---|
644 | | - u32 *rt, *___f; \ |
---|
645 | | - \ |
---|
646 | | - rt = (u32 *)(table + offsetof(efi_system_table_32_t, runtime)); \ |
---|
647 | | - ___f = (u32 *)(*rt + offsetof(efi_runtime_services_32_t, func)); \ |
---|
648 | | - *___f; \ |
---|
| 474 | +/* |
---|
| 475 | + * DS and ES contain user values. We need to save them. |
---|
| 476 | + * The 32-bit EFI code needs a valid DS, ES, and SS. There's no |
---|
| 477 | + * need to save the old SS: __KERNEL_DS is always acceptable. |
---|
| 478 | + */ |
---|
| 479 | +#define __efi_thunk(func, ...) \ |
---|
| 480 | +({ \ |
---|
| 481 | + unsigned short __ds, __es; \ |
---|
| 482 | + efi_status_t ____s; \ |
---|
| 483 | + \ |
---|
| 484 | + savesegment(ds, __ds); \ |
---|
| 485 | + savesegment(es, __es); \ |
---|
| 486 | + \ |
---|
| 487 | + loadsegment(ss, __KERNEL_DS); \ |
---|
| 488 | + loadsegment(ds, __KERNEL_DS); \ |
---|
| 489 | + loadsegment(es, __KERNEL_DS); \ |
---|
| 490 | + \ |
---|
| 491 | + ____s = efi64_thunk(efi.runtime->mixed_mode.func, __VA_ARGS__); \ |
---|
| 492 | + \ |
---|
| 493 | + loadsegment(ds, __ds); \ |
---|
| 494 | + loadsegment(es, __es); \ |
---|
| 495 | + \ |
---|
| 496 | + ____s ^= (____s & BIT(31)) | (____s & BIT_ULL(31)) << 32; \ |
---|
| 497 | + ____s; \ |
---|
649 | 498 | }) |
---|
650 | 499 | |
---|
651 | 500 | /* |
---|
652 | 501 | * Switch to the EFI page tables early so that we can access the 1:1 |
---|
653 | 502 | * runtime services mappings which are not mapped in any other page |
---|
654 | | - * tables. This function must be called before runtime_service32(). |
---|
| 503 | + * tables. |
---|
655 | 504 | * |
---|
656 | 505 | * Also, disable interrupts because the IDT points to 64-bit handlers, |
---|
657 | 506 | * which aren't going to function correctly when we switch to 32-bit. |
---|
658 | 507 | */ |
---|
659 | | -#define efi_thunk(f, ...) \ |
---|
| 508 | +#define efi_thunk(func...) \ |
---|
660 | 509 | ({ \ |
---|
661 | 510 | efi_status_t __s; \ |
---|
662 | | - u32 __func; \ |
---|
663 | 511 | \ |
---|
664 | 512 | arch_efi_call_virt_setup(); \ |
---|
665 | 513 | \ |
---|
666 | | - __func = runtime_service32(f); \ |
---|
667 | | - __s = efi64_thunk(__func, __VA_ARGS__); \ |
---|
| 514 | + __s = __efi_thunk(func); \ |
---|
668 | 515 | \ |
---|
669 | 516 | arch_efi_call_virt_teardown(); \ |
---|
670 | 517 | \ |
---|
671 | 518 | __s; \ |
---|
672 | 519 | }) |
---|
673 | 520 | |
---|
674 | | -efi_status_t efi_thunk_set_virtual_address_map( |
---|
675 | | - void *phys_set_virtual_address_map, |
---|
676 | | - unsigned long memory_map_size, |
---|
677 | | - unsigned long descriptor_size, |
---|
678 | | - u32 descriptor_version, |
---|
679 | | - efi_memory_desc_t *virtual_map) |
---|
| 521 | +static efi_status_t __init __no_sanitize_address |
---|
| 522 | +efi_thunk_set_virtual_address_map(unsigned long memory_map_size, |
---|
| 523 | + unsigned long descriptor_size, |
---|
| 524 | + u32 descriptor_version, |
---|
| 525 | + efi_memory_desc_t *virtual_map) |
---|
680 | 526 | { |
---|
681 | 527 | efi_status_t status; |
---|
682 | 528 | unsigned long flags; |
---|
683 | | - u32 func; |
---|
684 | 529 | |
---|
685 | 530 | efi_sync_low_kernel_mappings(); |
---|
686 | 531 | local_irq_save(flags); |
---|
687 | 532 | |
---|
688 | 533 | efi_switch_mm(&efi_mm); |
---|
689 | 534 | |
---|
690 | | - func = (u32)(unsigned long)phys_set_virtual_address_map; |
---|
691 | | - status = efi64_thunk(func, memory_map_size, descriptor_size, |
---|
692 | | - descriptor_version, virtual_map); |
---|
| 535 | + status = __efi_thunk(set_virtual_address_map, memory_map_size, |
---|
| 536 | + descriptor_size, descriptor_version, virtual_map); |
---|
693 | 537 | |
---|
694 | 538 | efi_switch_mm(efi_scratch.prev_mm); |
---|
695 | 539 | local_irq_restore(flags); |
---|
.. | .. |
---|
699 | 543 | |
---|
700 | 544 | static efi_status_t efi_thunk_get_time(efi_time_t *tm, efi_time_cap_t *tc) |
---|
701 | 545 | { |
---|
702 | | - efi_status_t status; |
---|
703 | | - u32 phys_tm, phys_tc; |
---|
704 | | - unsigned long flags; |
---|
705 | | - |
---|
706 | | - spin_lock(&rtc_lock); |
---|
707 | | - spin_lock_irqsave(&efi_runtime_lock, flags); |
---|
708 | | - |
---|
709 | | - phys_tm = virt_to_phys_or_null(tm); |
---|
710 | | - phys_tc = virt_to_phys_or_null(tc); |
---|
711 | | - |
---|
712 | | - status = efi_thunk(get_time, phys_tm, phys_tc); |
---|
713 | | - |
---|
714 | | - spin_unlock_irqrestore(&efi_runtime_lock, flags); |
---|
715 | | - spin_unlock(&rtc_lock); |
---|
716 | | - |
---|
717 | | - return status; |
---|
| 546 | + return EFI_UNSUPPORTED; |
---|
718 | 547 | } |
---|
719 | 548 | |
---|
720 | 549 | static efi_status_t efi_thunk_set_time(efi_time_t *tm) |
---|
721 | 550 | { |
---|
722 | | - efi_status_t status; |
---|
723 | | - u32 phys_tm; |
---|
724 | | - unsigned long flags; |
---|
725 | | - |
---|
726 | | - spin_lock(&rtc_lock); |
---|
727 | | - spin_lock_irqsave(&efi_runtime_lock, flags); |
---|
728 | | - |
---|
729 | | - phys_tm = virt_to_phys_or_null(tm); |
---|
730 | | - |
---|
731 | | - status = efi_thunk(set_time, phys_tm); |
---|
732 | | - |
---|
733 | | - spin_unlock_irqrestore(&efi_runtime_lock, flags); |
---|
734 | | - spin_unlock(&rtc_lock); |
---|
735 | | - |
---|
736 | | - return status; |
---|
| 551 | + return EFI_UNSUPPORTED; |
---|
737 | 552 | } |
---|
738 | 553 | |
---|
739 | 554 | static efi_status_t |
---|
740 | 555 | efi_thunk_get_wakeup_time(efi_bool_t *enabled, efi_bool_t *pending, |
---|
741 | 556 | efi_time_t *tm) |
---|
742 | 557 | { |
---|
743 | | - efi_status_t status; |
---|
744 | | - u32 phys_enabled, phys_pending, phys_tm; |
---|
745 | | - unsigned long flags; |
---|
746 | | - |
---|
747 | | - spin_lock(&rtc_lock); |
---|
748 | | - spin_lock_irqsave(&efi_runtime_lock, flags); |
---|
749 | | - |
---|
750 | | - phys_enabled = virt_to_phys_or_null(enabled); |
---|
751 | | - phys_pending = virt_to_phys_or_null(pending); |
---|
752 | | - phys_tm = virt_to_phys_or_null(tm); |
---|
753 | | - |
---|
754 | | - status = efi_thunk(get_wakeup_time, phys_enabled, |
---|
755 | | - phys_pending, phys_tm); |
---|
756 | | - |
---|
757 | | - spin_unlock_irqrestore(&efi_runtime_lock, flags); |
---|
758 | | - spin_unlock(&rtc_lock); |
---|
759 | | - |
---|
760 | | - return status; |
---|
| 558 | + return EFI_UNSUPPORTED; |
---|
761 | 559 | } |
---|
762 | 560 | |
---|
763 | 561 | static efi_status_t |
---|
764 | 562 | efi_thunk_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm) |
---|
765 | 563 | { |
---|
766 | | - efi_status_t status; |
---|
767 | | - u32 phys_tm; |
---|
768 | | - unsigned long flags; |
---|
769 | | - |
---|
770 | | - spin_lock(&rtc_lock); |
---|
771 | | - spin_lock_irqsave(&efi_runtime_lock, flags); |
---|
772 | | - |
---|
773 | | - phys_tm = virt_to_phys_or_null(tm); |
---|
774 | | - |
---|
775 | | - status = efi_thunk(set_wakeup_time, enabled, phys_tm); |
---|
776 | | - |
---|
777 | | - spin_unlock_irqrestore(&efi_runtime_lock, flags); |
---|
778 | | - spin_unlock(&rtc_lock); |
---|
779 | | - |
---|
780 | | - return status; |
---|
| 564 | + return EFI_UNSUPPORTED; |
---|
781 | 565 | } |
---|
782 | 566 | |
---|
783 | 567 | static unsigned long efi_name_size(efi_char16_t *name) |
---|
.. | .. |
---|
911 | 695 | static efi_status_t |
---|
912 | 696 | efi_thunk_get_next_high_mono_count(u32 *count) |
---|
913 | 697 | { |
---|
914 | | - efi_status_t status; |
---|
915 | | - u32 phys_count; |
---|
916 | | - unsigned long flags; |
---|
917 | | - |
---|
918 | | - spin_lock_irqsave(&efi_runtime_lock, flags); |
---|
919 | | - |
---|
920 | | - phys_count = virt_to_phys_or_null(count); |
---|
921 | | - status = efi_thunk(get_next_high_mono_count, phys_count); |
---|
922 | | - |
---|
923 | | - spin_unlock_irqrestore(&efi_runtime_lock, flags); |
---|
924 | | - |
---|
925 | | - return status; |
---|
| 698 | + return EFI_UNSUPPORTED; |
---|
926 | 699 | } |
---|
927 | 700 | |
---|
928 | 701 | static void |
---|
.. | .. |
---|
1019 | 792 | return EFI_UNSUPPORTED; |
---|
1020 | 793 | } |
---|
1021 | 794 | |
---|
1022 | | -void efi_thunk_runtime_setup(void) |
---|
| 795 | +void __init efi_thunk_runtime_setup(void) |
---|
1023 | 796 | { |
---|
| 797 | + if (!IS_ENABLED(CONFIG_EFI_MIXED)) |
---|
| 798 | + return; |
---|
| 799 | + |
---|
1024 | 800 | efi.get_time = efi_thunk_get_time; |
---|
1025 | 801 | efi.set_time = efi_thunk_set_time; |
---|
1026 | 802 | efi.get_wakeup_time = efi_thunk_get_wakeup_time; |
---|
.. | .. |
---|
1036 | 812 | efi.update_capsule = efi_thunk_update_capsule; |
---|
1037 | 813 | efi.query_capsule_caps = efi_thunk_query_capsule_caps; |
---|
1038 | 814 | } |
---|
1039 | | -#endif /* CONFIG_EFI_MIXED */ |
---|
| 815 | + |
---|
| 816 | +efi_status_t __init __no_sanitize_address |
---|
| 817 | +efi_set_virtual_address_map(unsigned long memory_map_size, |
---|
| 818 | + unsigned long descriptor_size, |
---|
| 819 | + u32 descriptor_version, |
---|
| 820 | + efi_memory_desc_t *virtual_map, |
---|
| 821 | + unsigned long systab_phys) |
---|
| 822 | +{ |
---|
| 823 | + const efi_system_table_t *systab = (efi_system_table_t *)systab_phys; |
---|
| 824 | + efi_status_t status; |
---|
| 825 | + unsigned long flags; |
---|
| 826 | + |
---|
| 827 | + if (efi_is_mixed()) |
---|
| 828 | + return efi_thunk_set_virtual_address_map(memory_map_size, |
---|
| 829 | + descriptor_size, |
---|
| 830 | + descriptor_version, |
---|
| 831 | + virtual_map); |
---|
| 832 | + efi_switch_mm(&efi_mm); |
---|
| 833 | + |
---|
| 834 | + kernel_fpu_begin(); |
---|
| 835 | + |
---|
| 836 | + /* Disable interrupts around EFI calls: */ |
---|
| 837 | + local_irq_save(flags); |
---|
| 838 | + status = efi_call(efi.runtime->set_virtual_address_map, |
---|
| 839 | + memory_map_size, descriptor_size, |
---|
| 840 | + descriptor_version, virtual_map); |
---|
| 841 | + local_irq_restore(flags); |
---|
| 842 | + |
---|
| 843 | + kernel_fpu_end(); |
---|
| 844 | + |
---|
| 845 | + /* grab the virtually remapped EFI runtime services table pointer */ |
---|
| 846 | + efi.runtime = READ_ONCE(systab->runtime); |
---|
| 847 | + |
---|
| 848 | + efi_switch_mm(efi_scratch.prev_mm); |
---|
| 849 | + |
---|
| 850 | + return status; |
---|
| 851 | +} |
---|