Re: [PATCH v4 45/66] memory: Introduce memory_region_init_ram_guest_memfd()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 25.01.24 04:23, Xiaoyao Li wrote:
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@xxxxxxxxx>
---
  include/exec/memory.h |  6 ++++++
  system/memory.c       | 27 +++++++++++++++++++++++++++
  2 files changed, 33 insertions(+)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index f25959f6d30f..3a7f41b030e8 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -1607,6 +1607,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 74f647f2e56f..41049d3e4c9a 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -3619,6 +3619,33 @@ 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;
+    }
+
+    memory_region_set_default_private(mr);

It would be much cleaner to just pass the flag when initializing the memory region.

Ideally, we can get rid of memory_region_set_default_private().

What you do in patch #33 feels like a layer violation.

--
Cheers,

David / dhildenb





[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux