[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 46/66] i386/tdx: register TDVF as private memory
|
From: |
Xiaoyao Li |
|
Subject: |
[PATCH v4 46/66] i386/tdx: register TDVF as private memory |
|
Date: |
Wed, 24 Jan 2024 22:23:08 -0500 |
From: Chao Peng <chao.p.peng@linux.intel.com>
Allocate private guest memfd memory for BIOS if it's TD VM.
Signed-off-by: Chao Peng <chao.p.peng@linux.intel.com>
Co-developed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
hw/i386/x86.c | 10 +++++++++-
target/i386/kvm/tdx.c | 18 ++++++++++++++++++
target/i386/kvm/tdx.h | 2 ++
3 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index f7352b06c3e6..f13f49069d40 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -1155,8 +1155,16 @@ void x86_bios_rom_init(MachineState *ms, const char
*default_firmware,
(bios_size % 65536) != 0) {
goto bios_error;
}
+
bios = g_malloc(sizeof(*bios));
- memory_region_init_ram(bios, NULL, "pc.bios", bios_size, &error_fatal);
+ if (is_tdx_vm()) {
+ memory_region_init_ram_guest_memfd(bios, NULL, "pc.bios", bios_size,
+ &error_fatal);
+ tdx_set_tdvf_region(bios);
+ } else {
+ memory_region_init_ram(bios, NULL, "pc.bios", bios_size, &error_fatal);
+ }
+
if (sev_enabled() || is_tdx_vm()) {
/*
* The concept of a "reset" simply doesn't exist for
diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c
index af4107514fc9..0f6a6e9bb024 100644
--- a/target/i386/kvm/tdx.c
+++ b/target/i386/kvm/tdx.c
@@ -21,6 +21,7 @@
#include "sysemu/kvm.h"
#include "sysemu/sysemu.h"
#include "exec/address-spaces.h"
+#include "exec/ramblock.h"
#include "hw/i386/e820_memory_layout.h"
#include "hw/i386/x86.h"
@@ -468,6 +469,12 @@ static void update_tdx_cpuid_lookup_by_tdx_caps(void)
(tdx_caps->xfam_fixed1 & CPUID_XSTATE_XSS_MASK) >> 32;
}
+void tdx_set_tdvf_region(MemoryRegion *tdvf_region)
+{
+ assert(!tdx_guest->tdvf_region);
+ tdx_guest->tdvf_region = tdvf_region;
+}
+
static TdxFirmwareEntry *tdx_get_hob_entry(TdxGuest *tdx)
{
TdxFirmwareEntry *entry;
@@ -589,6 +596,7 @@ static void tdx_finalize_vm(Notifier *notifier, void
*unused)
{
TdxFirmware *tdvf = &tdx_guest->tdvf;
TdxFirmwareEntry *entry;
+ RAMBlock *ram_block;
int r;
tdx_init_ram_entries();
@@ -623,6 +631,12 @@ static void tdx_finalize_vm(Notifier *notifier, void
*unused)
.nr_pages = entry->size / 4096,
};
+ r = kvm_set_memory_attributes_private(entry->address, entry->size);
+ if (r < 0) {
+ error_report("Reserve initial private memory failed %s",
strerror(-r));
+ exit(1);
+ }
+
__u32 flags = entry->attributes & TDVF_SECTION_ATTRIBUTES_MR_EXTEND ?
KVM_TDX_MEASURE_MEMORY_REGION : 0;
@@ -638,6 +652,10 @@ static void tdx_finalize_vm(Notifier *notifier, void
*unused)
entry->mem_ptr = NULL;
}
}
+
+ /* Tdvf image was copied into private region above. It becomes
unnecessary. */
+ ram_block = tdx_guest->tdvf_region->ram_block;
+ ram_block_discard_range(ram_block, 0, ram_block->max_length);
}
static Notifier tdx_machine_done_notify = {
diff --git a/target/i386/kvm/tdx.h b/target/i386/kvm/tdx.h
index 3a35a2bc0900..5fb20a5f06bb 100644
--- a/target/i386/kvm/tdx.h
+++ b/target/i386/kvm/tdx.h
@@ -38,6 +38,7 @@ typedef struct TdxGuest {
char *mrownerconfig; /* base64 encoded sha348 digest */
TdxFirmware tdvf;
+ MemoryRegion *tdvf_region;
uint32_t nr_ram_entries;
TdxRamEntry *ram_entries;
@@ -53,6 +54,7 @@ int tdx_kvm_init(MachineState *ms, Error **errp);
void tdx_get_supported_cpuid(uint32_t function, uint32_t index, int reg,
uint32_t *ret);
int tdx_pre_create_vcpu(CPUState *cpu, Error **errp);
+void tdx_set_tdvf_region(MemoryRegion *tdvf_region);
int tdx_parse_tdvf(void *flash_ptr, int size);
#endif /* QEMU_I386_TDX_H */
--
2.34.1
- [PATCH v4 39/66] i386/tdx: Don't initialize pc.rom for TDX VMs, (continued)
- [PATCH v4 39/66] i386/tdx: Don't initialize pc.rom for TDX VMs, Xiaoyao Li, 2024/01/24
- [PATCH v4 40/66] i386/tdx: Track mem_ptr for each firmware entry of TDVF, Xiaoyao Li, 2024/01/24
- [PATCH v4 42/66] headers: Add definitions from UEFI spec for volumes, resources, etc..., Xiaoyao Li, 2024/01/24
- [PATCH v4 41/66] i386/tdx: Track RAM entries for TDX VM, Xiaoyao Li, 2024/01/24
- [PATCH v4 43/66] i386/tdx: Setup the TD HOB list, Xiaoyao Li, 2024/01/24
- [PATCH v4 45/66] memory: Introduce memory_region_init_ram_guest_memfd(), Xiaoyao Li, 2024/01/24
- [PATCH v4 44/66] i386/tdx: Add TDVF memory via KVM_TDX_INIT_MEM_REGION, Xiaoyao Li, 2024/01/24
- [PATCH v4 48/66] i386/tdx: Finalize TDX VM, Xiaoyao Li, 2024/01/24
- [PATCH v4 49/66] i386/tdx: handle TDG.VP.VMCALL<SetupEventNotifyInterrupt>, Xiaoyao Li, 2024/01/24
- [PATCH v4 47/66] i386/tdx: Call KVM_TDX_INIT_VCPU to initialize TDX vcpu, Xiaoyao Li, 2024/01/24
- [PATCH v4 46/66] i386/tdx: register TDVF as private memory,
Xiaoyao Li <=
- [PATCH v4 52/66] i386/tdx: Handle TDG.VP.VMCALL<REPORT_FATAL_ERROR>, Xiaoyao Li, 2024/01/24
- [PATCH v4 51/66] i386/tdx: handle TDG.VP.VMCALL<MapGPA> hypercall, Xiaoyao Li, 2024/01/24
- [PATCH v4 50/66] i386/tdx: handle TDG.VP.VMCALL<GetQuote>, Xiaoyao Li, 2024/01/24
- [PATCH v4 54/66] pci-host/q35: Move PAM initialization above SMRAM initialization, Xiaoyao Li, 2024/01/24
- [PATCH v4 55/66] q35: Introduce smm_ranges property for q35-pci-host, Xiaoyao Li, 2024/01/24
- [PATCH v4 53/66] i386/tdx: Wire TDX_REPORT_FATAL_ERROR with GuestPanic facility, Xiaoyao Li, 2024/01/24
- [PATCH v4 57/66] i386/tdx: Disable PIC for TDX VMs, Xiaoyao Li, 2024/01/24
- [PATCH v4 58/66] i386/tdx: Don't allow system reset for TDX VMs, Xiaoyao Li, 2024/01/24
- [PATCH v4 56/66] i386/tdx: Disable SMM for TDX VMs, Xiaoyao Li, 2024/01/24
- [PATCH v4 59/66] i386/tdx: LMCE is not supported for TDX, Xiaoyao Li, 2024/01/24