.. | .. |
---|
30 | 30 | #define STATIC static |
---|
31 | 31 | |
---|
32 | 32 | /* |
---|
33 | | - * Use normal definitions of mem*() from string.c. There are already |
---|
34 | | - * included header files which expect a definition of memset() and by |
---|
35 | | - * the time we define memset macro, it is too late. |
---|
| 33 | + * Provide definitions of memzero and memmove as some of the decompressors will |
---|
| 34 | + * try to define their own functions if these are not defined as macros. |
---|
36 | 35 | */ |
---|
37 | | -#undef memcpy |
---|
38 | | -#undef memset |
---|
39 | 36 | #define memzero(s, n) memset((s), 0, (n)) |
---|
40 | 37 | #define memmove memmove |
---|
41 | 38 | |
---|
.. | .. |
---|
76 | 73 | |
---|
77 | 74 | #ifdef CONFIG_KERNEL_LZ4 |
---|
78 | 75 | #include "../../../../lib/decompress_unlz4.c" |
---|
| 76 | +#endif |
---|
| 77 | + |
---|
| 78 | +#ifdef CONFIG_KERNEL_ZSTD |
---|
| 79 | +#include "../../../../lib/decompress_unzstd.c" |
---|
79 | 80 | #endif |
---|
80 | 81 | /* |
---|
81 | 82 | * NOTE: When adding a new decompressor, please update the analysis in |
---|
.. | .. |
---|
345 | 346 | { |
---|
346 | 347 | const unsigned long kernel_total_size = VO__end - VO__text; |
---|
347 | 348 | unsigned long virt_addr = LOAD_PHYSICAL_ADDR; |
---|
| 349 | + unsigned long needed_size; |
---|
348 | 350 | |
---|
349 | 351 | /* Retain x86 boot parameters pointer passed from startup_32/64. */ |
---|
350 | 352 | boot_params = rmode; |
---|
.. | .. |
---|
366 | 368 | cols = boot_params->screen_info.orig_video_cols; |
---|
367 | 369 | |
---|
368 | 370 | console_init(); |
---|
| 371 | + |
---|
| 372 | + /* |
---|
| 373 | + * Save RSDP address for later use. Have this after console_init() |
---|
| 374 | + * so that early debugging output from the RSDP parsing code can be |
---|
| 375 | + * collected. |
---|
| 376 | + */ |
---|
| 377 | + boot_params->acpi_rsdp_addr = get_rsdp_addr(); |
---|
| 378 | + |
---|
369 | 379 | debug_putstr("early console in extract_kernel\n"); |
---|
370 | 380 | |
---|
371 | 381 | free_mem_ptr = heap; /* Heap */ |
---|
372 | 382 | free_mem_end_ptr = heap + BOOT_HEAP_SIZE; |
---|
| 383 | + |
---|
| 384 | + /* |
---|
| 385 | + * The memory hole needed for the kernel is the larger of either |
---|
| 386 | + * the entire decompressed kernel plus relocation table, or the |
---|
| 387 | + * entire decompressed kernel plus .bss and .brk sections. |
---|
| 388 | + * |
---|
| 389 | + * On X86_64, the memory is mapped with PMD pages. Round the |
---|
| 390 | + * size up so that the full extent of PMD pages mapped is |
---|
| 391 | + * included in the check against the valid memory table |
---|
| 392 | + * entries. This ensures the full mapped area is usable RAM |
---|
| 393 | + * and doesn't include any reserved areas. |
---|
| 394 | + */ |
---|
| 395 | + needed_size = max(output_len, kernel_total_size); |
---|
| 396 | +#ifdef CONFIG_X86_64 |
---|
| 397 | + needed_size = ALIGN(needed_size, MIN_KERNEL_ALIGN); |
---|
| 398 | +#endif |
---|
373 | 399 | |
---|
374 | 400 | /* Report initial kernel position details. */ |
---|
375 | 401 | debug_putaddr(input_data); |
---|
.. | .. |
---|
377 | 403 | debug_putaddr(output); |
---|
378 | 404 | debug_putaddr(output_len); |
---|
379 | 405 | debug_putaddr(kernel_total_size); |
---|
| 406 | + debug_putaddr(needed_size); |
---|
380 | 407 | |
---|
381 | 408 | #ifdef CONFIG_X86_64 |
---|
382 | 409 | /* Report address of 32-bit trampoline */ |
---|
383 | 410 | debug_putaddr(trampoline_32bit); |
---|
384 | 411 | #endif |
---|
385 | 412 | |
---|
386 | | - /* |
---|
387 | | - * The memory hole needed for the kernel is the larger of either |
---|
388 | | - * the entire decompressed kernel plus relocation table, or the |
---|
389 | | - * entire decompressed kernel plus .bss and .brk sections. |
---|
390 | | - */ |
---|
391 | 413 | choose_random_location((unsigned long)input_data, input_len, |
---|
392 | 414 | (unsigned long *)&output, |
---|
393 | | - max(output_len, kernel_total_size), |
---|
| 415 | + needed_size, |
---|
394 | 416 | &virt_addr); |
---|
395 | 417 | |
---|
396 | 418 | /* Validate memory location choices. */ |
---|
.. | .. |
---|
420 | 442 | parse_elf(output); |
---|
421 | 443 | handle_relocations(output, output_len, virt_addr); |
---|
422 | 444 | debug_putstr("done.\nBooting the kernel.\n"); |
---|
| 445 | + |
---|
| 446 | + /* |
---|
| 447 | + * Flush GHCB from cache and map it encrypted again when running as |
---|
| 448 | + * SEV-ES guest. |
---|
| 449 | + */ |
---|
| 450 | + sev_es_shutdown_ghcb(); |
---|
| 451 | + |
---|
423 | 452 | return output; |
---|
424 | 453 | } |
---|
425 | 454 | |
---|