[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 45/65] i386/tdx: Populate TDVF private memory via KVM_MEMORY_M
From: |
Xiaoyao Li |
Subject: |
[PATCH v5 45/65] i386/tdx: Populate TDVF private memory via KVM_MEMORY_MAPPING |
Date: |
Thu, 29 Feb 2024 01:37:06 -0500 |
From: Isaku Yamahata <isaku.yamahata@intel.com>
TDVF firmware (CODE and VARS) needs to be copied to TD's private
memory, as well as TD HOB and TEMP memory.
If the TDVF section has TDVF_SECTION_ATTRIBUTES_MR_EXTEND set in the
flag, calling KVM_TDX_EXTEND_MEMORY to extend the measurement.
After populating the TDVF memory, the original image located in shared
ramblock can be discarded.
Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
---
Changes in v1:
- rename variable @metadata to @flags
---
target/i386/kvm/tdx.c | 47 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c
index fb9c60172fde..dcabe359eda5 100644
--- a/target/i386/kvm/tdx.c
+++ b/target/i386/kvm/tdx.c
@@ -595,6 +595,8 @@ 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();
@@ -620,6 +622,51 @@ static void tdx_finalize_vm(Notifier *notifier, void
*unused)
sizeof(TdxRamEntry), &tdx_ram_entry_compare);
tdvf_hob_create(tdx_guest, tdx_get_hob_entry(tdx_guest));
+
+ for_each_tdx_fw_entry(tdvf, entry) {
+ struct kvm_memory_mapping mapping = {
+ .base_gfn = entry->address >> 12,
+ .nr_pages = entry->size >> 12,
+ .source = (__u64)entry->mem_ptr,
+ };
+
+ do {
+ r = kvm_vcpu_ioctl(first_cpu, KVM_MEMORY_MAPPING, &mapping);
+ } while (r == -EAGAIN);
+
+ if (r < 0) {
+ error_report("KVM_MEMORY_MAPPING failed %s", strerror(-r));
+ exit(1);
+ }
+
+ if (entry->attributes & TDVF_SECTION_ATTRIBUTES_MR_EXTEND) {
+ mapping = (struct kvm_memory_mapping) {
+ .base_gfn = entry->address >> 12,
+ .nr_pages = entry->size >> 12,
+ };
+
+ do {
+ r = tdx_vm_ioctl(KVM_TDX_EXTEND_MEMORY, 0, &mapping);
+ } while (r == -EAGAIN);
+ if (r < 0) {
+ error_report("KVM_TDX_EXTEND_MEMORY failed %s", strerror(-r));
+ exit(1);
+ }
+ }
+
+ if (entry->type == TDVF_SECTION_TYPE_TD_HOB ||
+ entry->type == TDVF_SECTION_TYPE_TEMP_MEM) {
+ qemu_ram_munmap(-1, entry->mem_ptr, entry->size);
+ entry->mem_ptr = NULL;
+ }
+ }
+
+ /*
+ * TDVF image has been copied into private region above via
+ * KVM_MEMORY_MAPPING. It becomes useless.
+ */
+ ram_block = tdx_guest->tdvf_mr->ram_block;
+ ram_block_discard_range(ram_block, 0, ram_block->max_length);
}
static Notifier tdx_machine_done_notify = {
--
2.34.1
- [PATCH v5 28/65] i386/tdx: Disable pmu for TD guest, (continued)
- [PATCH v5 28/65] i386/tdx: Disable pmu for TD guest, Xiaoyao Li, 2024/02/29
- [PATCH v5 37/65] i386/tdvf: Introduce function to parse TDVF metadata, Xiaoyao Li, 2024/02/29
- [PATCH v5 39/65] i386/tdx: Skip BIOS shadowing setup, Xiaoyao Li, 2024/02/29
- [PATCH v5 36/65] i386/tdx: load TDVF for TD guest, Xiaoyao Li, 2024/02/29
- [PATCH v5 38/65] i386/tdx: Parse TDVF metadata for TDX VM, Xiaoyao Li, 2024/02/29
- [PATCH v5 40/65] i386/tdx: Don't initialize pc.rom for TDX VMs, Xiaoyao Li, 2024/02/29
- [PATCH v5 41/65] i386/tdx: Track mem_ptr for each firmware entry of TDVF, Xiaoyao Li, 2024/02/29
- [PATCH v5 42/65] i386/tdx: Track RAM entries for TDX VM, Xiaoyao Li, 2024/02/29
- [PATCH v5 44/65] i386/tdx: Setup the TD HOB list, Xiaoyao Li, 2024/02/29
- [PATCH v5 43/65] headers: Add definitions from UEFI spec for volumes, resources, etc..., Xiaoyao Li, 2024/02/29
- [PATCH v5 45/65] i386/tdx: Populate TDVF private memory via KVM_MEMORY_MAPPING,
Xiaoyao Li <=
- [PATCH v5 46/65] i386/tdx: Call KVM_TDX_INIT_VCPU to initialize TDX vcpu, Xiaoyao Li, 2024/02/29
- [PATCH v5 47/65] i386/tdx: Finalize TDX VM, Xiaoyao Li, 2024/02/29
- [PATCH v5 48/65] i386/tdx: handle TDG.VP.VMCALL<SetupEventNotifyInterrupt>, Xiaoyao Li, 2024/02/29
- [PATCH v5 50/65] i386/tdx: handle TDG.VP.VMCALL<MapGPA> hypercall, Xiaoyao Li, 2024/02/29
- [PATCH v5 49/65] i386/tdx: handle TDG.VP.VMCALL<GetQuote>, Xiaoyao Li, 2024/02/29
- [PATCH v5 51/65] i386/tdx: Handle TDG.VP.VMCALL<REPORT_FATAL_ERROR>, Xiaoyao Li, 2024/02/29
- [PATCH v5 52/65] i386/tdx: Wire TDX_REPORT_FATAL_ERROR with GuestPanic facility, Xiaoyao Li, 2024/02/29