hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/arch/x86/boot/compressed/misc.c
....@@ -30,12 +30,9 @@
3030 #define STATIC static
3131
3232 /*
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.
3635 */
37
-#undef memcpy
38
-#undef memset
3936 #define memzero(s, n) memset((s), 0, (n))
4037 #define memmove memmove
4138
....@@ -76,6 +73,10 @@
7673
7774 #ifdef CONFIG_KERNEL_LZ4
7875 #include "../../../../lib/decompress_unlz4.c"
76
+#endif
77
+
78
+#ifdef CONFIG_KERNEL_ZSTD
79
+#include "../../../../lib/decompress_unzstd.c"
7980 #endif
8081 /*
8182 * NOTE: When adding a new decompressor, please update the analysis in
....@@ -345,6 +346,7 @@
345346 {
346347 const unsigned long kernel_total_size = VO__end - VO__text;
347348 unsigned long virt_addr = LOAD_PHYSICAL_ADDR;
349
+ unsigned long needed_size;
348350
349351 /* Retain x86 boot parameters pointer passed from startup_32/64. */
350352 boot_params = rmode;
....@@ -366,10 +368,34 @@
366368 cols = boot_params->screen_info.orig_video_cols;
367369
368370 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
+
369379 debug_putstr("early console in extract_kernel\n");
370380
371381 free_mem_ptr = heap; /* Heap */
372382 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
373399
374400 /* Report initial kernel position details. */
375401 debug_putaddr(input_data);
....@@ -377,20 +403,16 @@
377403 debug_putaddr(output);
378404 debug_putaddr(output_len);
379405 debug_putaddr(kernel_total_size);
406
+ debug_putaddr(needed_size);
380407
381408 #ifdef CONFIG_X86_64
382409 /* Report address of 32-bit trampoline */
383410 debug_putaddr(trampoline_32bit);
384411 #endif
385412
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
- */
391413 choose_random_location((unsigned long)input_data, input_len,
392414 (unsigned long *)&output,
393
- max(output_len, kernel_total_size),
415
+ needed_size,
394416 &virt_addr);
395417
396418 /* Validate memory location choices. */
....@@ -420,6 +442,13 @@
420442 parse_elf(output);
421443 handle_relocations(output, output_len, virt_addr);
422444 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
+
423452 return output;
424453 }
425454