|
47 | 47 | #include "hw/i386/fw_cfg.h"
|
48 | 48 | #include "hw/intc/i8259.h"
|
49 | 49 | #include "hw/rtc/mc146818rtc.h"
|
| 50 | +#include "target/i386/sev_i386.h" |
50 | 51 |
|
51 | 52 | #include "hw/acpi/cpu_hotplug.h"
|
52 | 53 | #include "hw/irq.h"
|
@@ -780,6 +781,7 @@ void x86_load_linux(X86MachineState *x86ms,
|
780 | 781 | const char *initrd_filename = machine->initrd_filename;
|
781 | 782 | const char *dtb_filename = machine->dtb;
|
782 | 783 | const char *kernel_cmdline = machine->kernel_cmdline;
|
| 784 | + SevKernelLoaderContext sev_load_ctx = {}; |
783 | 785 |
|
784 | 786 | /* Align to 16 bytes as a paranoia measure */
|
785 | 787 | cmdline_size = (strlen(kernel_cmdline) + 16) & ~15;
|
@@ -926,6 +928,8 @@ void x86_load_linux(X86MachineState *x86ms,
|
926 | 928 | fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_ADDR, cmdline_addr);
|
927 | 929 | fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, strlen(kernel_cmdline) + 1);
|
928 | 930 | fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline);
|
| 931 | + sev_load_ctx.cmdline_data = (char *)kernel_cmdline; |
| 932 | + sev_load_ctx.cmdline_size = strlen(kernel_cmdline) + 1; |
929 | 933 |
|
930 | 934 | if (protocol >= 0x202) {
|
931 | 935 | stl_p(header + 0x228, cmdline_addr);
|
@@ -1007,6 +1011,8 @@ void x86_load_linux(X86MachineState *x86ms,
|
1007 | 1011 | fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr);
|
1008 | 1012 | fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
|
1009 | 1013 | fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, initrd_data, initrd_size);
|
| 1014 | + sev_load_ctx.initrd_data = initrd_data; |
| 1015 | + sev_load_ctx.initrd_size = initrd_size; |
1010 | 1016 |
|
1011 | 1017 | stl_p(header + 0x218, initrd_addr);
|
1012 | 1018 | stl_p(header + 0x21c, initrd_size);
|
@@ -1065,15 +1071,32 @@ void x86_load_linux(X86MachineState *x86ms,
|
1065 | 1071 | load_image_size(dtb_filename, setup_data->data, dtb_size);
|
1066 | 1072 | }
|
1067 | 1073 |
|
1068 |
| - memcpy(setup, header, MIN(sizeof(header), setup_size)); |
| 1074 | + /* |
| 1075 | + * If we're starting an encrypted VM, it will be OVMF based, which uses the |
| 1076 | + * efi stub for booting and doesn't require any values to be placed in the |
| 1077 | + * kernel header. We therefore don't update the header so the hash of the |
| 1078 | + * kernel on the other side of the fw_cfg interface matches the hash of the |
| 1079 | + * file the user passed in. |
| 1080 | + */ |
| 1081 | + if (!sev_enabled()) { |
| 1082 | + memcpy(setup, header, MIN(sizeof(header), setup_size)); |
| 1083 | + } |
1069 | 1084 |
|
1070 | 1085 | fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, prot_addr);
|
1071 | 1086 | fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
|
1072 | 1087 | fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, kernel, kernel_size);
|
| 1088 | + sev_load_ctx.kernel_data = (char *)kernel; |
| 1089 | + sev_load_ctx.kernel_size = kernel_size; |
1073 | 1090 |
|
1074 | 1091 | fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_ADDR, real_addr);
|
1075 | 1092 | fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_SIZE, setup_size);
|
1076 | 1093 | fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA, setup, setup_size);
|
| 1094 | + sev_load_ctx.setup_data = (char *)setup; |
| 1095 | + sev_load_ctx.setup_size = setup_size; |
| 1096 | + |
| 1097 | + if (sev_enabled()) { |
| 1098 | + sev_add_kernel_loader_hashes(&sev_load_ctx, &error_fatal); |
| 1099 | + } |
1077 | 1100 |
|
1078 | 1101 | option_rom[nb_option_roms].bootindex = 0;
|
1079 | 1102 | option_rom[nb_option_roms].name = "linuxboot.bin";
|
|
0 commit comments