[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 24/58] i386/tdx: Create kvm gmem for TD
From: |
Xiaoyao Li |
Subject: |
[PATCH v2 24/58] i386/tdx: Create kvm gmem for TD |
Date: |
Fri, 18 Aug 2023 05:50:07 -0400 |
From: Isaku Yamahata <isaku.yamahata@intel.com>
Allocate private gmem for TD guest, if the MemoryRegion is memory
backend and has private property on.
Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
target/i386/kvm/tdx.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c
index 775110f8bd02..f1305191e939 100644
--- a/target/i386/kvm/tdx.c
+++ b/target/i386/kvm/tdx.c
@@ -19,6 +19,7 @@
#include "sysemu/kvm.h"
#include "sysemu/sysemu.h"
#include "exec/address-spaces.h"
+#include "exec/ramblock.h"
#include "hw/i386/x86.h"
#include "kvm_i386.h"
@@ -582,8 +583,30 @@ out:
static void tdx_guest_region_add(MemoryListener *listener,
MemoryRegionSection *section)
{
- if (memory_region_can_be_private(section->mr)) {
- memory_region_set_default_private(section->mr);
+ MemoryRegion *mr = section->mr;
+ Object *owner = memory_region_owner(mr);
+
+ if (owner && object_dynamic_cast(owner, TYPE_MEMORY_BACKEND) &&
+ object_property_get_bool(owner, "private", NULL) &&
+ mr->ram_block && mr->ram_block->gmem_fd < 0) {
+ struct kvm_create_guest_memfd gmem = {
+ .size = memory_region_size(mr),
+ /* TODO: add property to hostmem backend for huge pmd */
+ .flags = KVM_GUEST_MEMFD_ALLOW_HUGEPAGE,
+ };
+ int fd;
+
+ fd = kvm_vm_ioctl(kvm_state, KVM_CREATE_GUEST_MEMFD, &gmem);
+ if (fd < 0) {
+ fprintf(stderr, "%s: error creating gmem: %s\n", __func__,
+ strerror(-fd));
+ abort();
+ }
+ memory_region_set_gmem_fd(mr, fd);
+ }
+
+ if (memory_region_can_be_private(mr)) {
+ memory_region_set_default_private(mr);
}
}
--
2.34.1
- [PATCH v2 20/58] i386/tdx: Allows mrconfigid/mrowner/mrownerconfig for TDX_INIT_VM, (continued)
- [PATCH v2 20/58] i386/tdx: Allows mrconfigid/mrowner/mrownerconfig for TDX_INIT_VM, Xiaoyao Li, 2023/08/18
- [PATCH v2 21/58] i386/tdx: Implement user specified tsc frequency, Xiaoyao Li, 2023/08/18
- [PATCH v2 25/58] kvm/tdx: Don't complain when converting vMMIO region to shared, Xiaoyao Li, 2023/08/18
- [PATCH v2 28/58] i386/tdx: Parse TDVF metadata for TDX VM, Xiaoyao Li, 2023/08/18
- [PATCH v2 26/58] kvm/tdx: Ignore memory conversion to shared of unassigned region, Xiaoyao Li, 2023/08/18
- [PATCH v2 27/58] i386/tdvf: Introduce function to parse TDVF metadata, Xiaoyao Li, 2023/08/18
- [PATCH v2 24/58] i386/tdx: Create kvm gmem for TD,
Xiaoyao Li <=
- [PATCH v2 23/58] i386/tdx: Make memory type private by default, Xiaoyao Li, 2023/08/18
- [PATCH v2 29/58] i386/tdx: Skip BIOS shadowing setup, Xiaoyao Li, 2023/08/18
- [PATCH v2 30/58] i386/tdx: Don't initialize pc.rom for TDX VMs, Xiaoyao Li, 2023/08/18
- [PATCH v2 31/58] i386/tdx: Track mem_ptr for each firmware entry of TDVF, Xiaoyao Li, 2023/08/18
- [PATCH v2 32/58] i386/tdx: Track RAM entries for TDX VM, Xiaoyao Li, 2023/08/18
- [PATCH v2 33/58] headers: Add definitions from UEFI spec for volumes, resources, etc..., Xiaoyao Li, 2023/08/18