[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 16/49] memory: Introduce memory_region_init_ram_guest_memfd()
From: |
Michael Roth |
Subject: |
[PATCH v3 16/49] memory: Introduce memory_region_init_ram_guest_memfd() |
Date: |
Wed, 20 Mar 2024 03:39:12 -0500 |
From: Xiaoyao Li <xiaoyao.li@intel.com>
Introduce memory_region_init_ram_guest_memfd() to allocate private
guset memfd on the MemoryRegion initialization. It's for the use case of
TDVF, which must be private on TDX case.
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
Changes in v5:
- drop memory_region_set_default_private() because this function is
dropped in this v5 series;
Signed-off-by: Michael Roth <michael.roth@amd.com>
---
include/exec/memory.h | 6 ++++++
system/memory.c | 25 +++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 679a847685..1e351f6fc8 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -1603,6 +1603,12 @@ bool memory_region_init_ram(MemoryRegion *mr,
uint64_t size,
Error **errp);
+bool memory_region_init_ram_guest_memfd(MemoryRegion *mr,
+ Object *owner,
+ const char *name,
+ uint64_t size,
+ Error **errp);
+
/**
* memory_region_init_rom: Initialize a ROM memory region.
*
diff --git a/system/memory.c b/system/memory.c
index c756950c0c..85a22408e9 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -3606,6 +3606,31 @@ bool memory_region_init_ram(MemoryRegion *mr,
return true;
}
+bool memory_region_init_ram_guest_memfd(MemoryRegion *mr,
+ Object *owner,
+ const char *name,
+ uint64_t size,
+ Error **errp)
+{
+ DeviceState *owner_dev;
+
+ if (!memory_region_init_ram_flags_nomigrate(mr, owner, name, size,
+ RAM_GUEST_MEMFD, errp)) {
+ return false;
+ }
+
+ /* This will assert if owner is neither NULL nor a DeviceState.
+ * We only want the owner here for the purposes of defining a
+ * unique name for migration. TODO: Ideally we should implement
+ * a naming scheme for Objects which are not DeviceStates, in
+ * which case we can relax this restriction.
+ */
+ owner_dev = DEVICE(owner);
+ vmstate_register_ram(mr, owner_dev);
+
+ return true;
+}
+
bool memory_region_init_rom(MemoryRegion *mr,
Object *owner,
const char *name,
--
2.25.1
- Re: [PATCH v3 11/49] physmem: Introduce ram_block_discard_guest_memfd_range(), (continued)
[PATCH v3 12/49] kvm: handle KVM_EXIT_MEMORY_FAULT, Michael Roth, 2024/03/20
[PATCH v3 13/49] [FIXUP] "kvm: handle KVM_EXIT_MEMORY_FAULT": drop qemu_host_page_size, Michael Roth, 2024/03/20
[PATCH v3 14/49] trace/kvm: Add trace for page convertion between shared and private, Michael Roth, 2024/03/20
[PATCH v3 15/49] kvm/memory: Make memory type private by default if it has guest memfd backend, Michael Roth, 2024/03/20
[PATCH v3 16/49] memory: Introduce memory_region_init_ram_guest_memfd(),
Michael Roth <=
[PATCH v3 17/49] pci-host/q35: Move PAM initialization above SMRAM initialization, Michael Roth, 2024/03/20
[PATCH v3 18/49] q35: Introduce smm_ranges property for q35-pci-host, Michael Roth, 2024/03/20
[PATCH v3 19/49] kvm: Make kvm_convert_memory() obey ram_block_discard_is_enabled(), Michael Roth, 2024/03/20
[PATCH v3 20/49] trace/kvm: Add trace for KVM_EXIT_MEMORY_FAULT, Michael Roth, 2024/03/20
[PATCH v3 01/49] Revert "linux-headers hack" from sevinit2 base tree, Michael Roth, 2024/03/20
[PATCH v3 21/49] i386/sev: Introduce "sev-common" type to encapsulate common SEV state, Michael Roth, 2024/03/20