[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 49/49] hw/i386: Add support for loading BIOS using guest_memfd
From: |
Michael Roth |
Subject: |
[PATCH v3 49/49] hw/i386: Add support for loading BIOS using guest_memfd |
Date: |
Wed, 20 Mar 2024 03:39:45 -0500 |
TODO: - Add proper handling for non-64K-aligned BIOS images.
- Add proper handling for BIOS pflash area which should be
initially mapped as shared, resulting in unecessary
KVM_EXIT_MEMORY_FAULTs
When guest_memfd is enabled, the BIOS is generally part of the initial
encrypted guest image and will be accessed as private guest memory. Add
the necessary changes to set up the associated RAM region with a
guest_memfd backend to allow for this.
Current support centers around using -bios to load the BIOS data.
Support for loading the BIOS via pflash requires additional enablement
since those interfaces rely on the use of ROM memory regions which make
use of the KVM_MEM_READONLY memslot flag, which is not supported for
guest_memfd-backed memslots.
Signed-off-by: Michael Roth <michael.roth@amd.com>
---
hw/i386/x86.c | 36 +++++++++++++++++++++++-------------
1 file changed, 23 insertions(+), 13 deletions(-)
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index e3ddc39133..ea2d03cc02 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -1147,10 +1147,18 @@ void x86_bios_rom_init(MachineState *ms, const char
*default_firmware,
}
if (bios_size <= 0 ||
(bios_size % 65536) != 0) {
- goto bios_error;
+ g_warning("%s: Unaligned BIOS size %d", __func__, bios_size);
+ if (!machine_require_guest_memfd(ms)) {
+ goto bios_error;
+ }
}
bios = g_malloc(sizeof(*bios));
- memory_region_init_ram(bios, NULL, "pc.bios", bios_size, &error_fatal);
+ if (machine_require_guest_memfd(ms)) {
+ memory_region_init_ram_guest_memfd(bios, NULL, "pc.bios", bios_size,
+ &error_fatal);
+ } else {
+ memory_region_init_ram(bios, NULL, "pc.bios", bios_size, &error_fatal);
+ }
if (sev_enabled()) {
/*
* The concept of a "reset" simply doesn't exist for
@@ -1173,17 +1181,19 @@ void x86_bios_rom_init(MachineState *ms, const char
*default_firmware,
}
g_free(filename);
- /* map the last 128KB of the BIOS in ISA space */
- isa_bios_size = MIN(bios_size, 128 * KiB);
- isa_bios = g_malloc(sizeof(*isa_bios));
- memory_region_init_alias(isa_bios, NULL, "isa-bios", bios,
- bios_size - isa_bios_size, isa_bios_size);
- memory_region_add_subregion_overlap(rom_memory,
- 0x100000 - isa_bios_size,
- isa_bios,
- 1);
- if (!isapc_ram_fw) {
- memory_region_set_readonly(isa_bios, true);
+ if (!machine_require_guest_memfd(ms)) {
+ /* map the last 128KB of the BIOS in ISA space */
+ isa_bios_size = MIN(bios_size, 128 * KiB);
+ isa_bios = g_malloc(sizeof(*isa_bios));
+ memory_region_init_alias(isa_bios, NULL, "isa-bios", bios,
+ bios_size - isa_bios_size, isa_bios_size);
+ memory_region_add_subregion_overlap(rom_memory,
+ 0x100000 - isa_bios_size,
+ isa_bios,
+ 1);
+ if (!isapc_ram_fw) {
+ memory_region_set_readonly(isa_bios, true);
+ }
}
/* map all the bios at the top of memory */
--
2.25.1
- Re: [PATCH v3 43/49] qapi, i386: Move kernel-hashes to SevCommonProperties, (continued)
- [PATCH v3 44/49] i386/sev: Extract build_kernel_loader_hashes, Michael Roth, 2024/03/20
- [PATCH v3 45/49] i386/sev: Reorder struct declarations, Michael Roth, 2024/03/20
- [PATCH v3 46/49] i386/sev: Allow measured direct kernel boot on SNP, Michael Roth, 2024/03/20
- [PATCH v3 47/49] hw/i386/sev: Add support to encrypt BIOS when SEV-SNP is enabled, Michael Roth, 2024/03/20
- [PATCH v3 48/49] hw/i386/sev: Use guest_memfd for legacy ROMs, Michael Roth, 2024/03/20
- [PATCH v3 49/49] hw/i386: Add support for loading BIOS using guest_memfd,
Michael Roth <=
- [PATCH v3 04/49] [HACK] linux-headers: Update headers for 6.8 + kvm-coco-queue + SNP, Michael Roth, 2024/03/20
- [PATCH v3 05/49] [TEMP] hw/i386: Remove redeclaration of struct setup_data, Michael Roth, 2024/03/20
- [PATCH v3 06/49] RAMBlock: Add support of KVM private guest memfd, Michael Roth, 2024/03/20
- [PATCH v3 07/49] HostMem: Add mechanism to opt in kvm guest memfd via MachineState, Michael Roth, 2024/03/20
- [PATCH v3 08/49] trace/kvm: Split address space and slot id in trace_kvm_set_user_memory(), Michael Roth, 2024/03/20
- Re: [PATCH RFC v3 00/49] Add AMD Secure Nested Paging (SEV-SNP) support, Paolo Bonzini, 2024/03/20
- Re: [PATCH RFC v3 00/49] Add AMD Secure Nested Paging (SEV-SNP) support, Michael Roth, 2024/03/21