diff options
author | Xiaoyao Li <xiaoyao.li@intel.com> | 2024-03-20 03:39:03 -0500 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2024-04-23 17:35:25 +0200 |
commit | 37662d85b0b7dded0ebdf6747bef6c3bb7ed6a0c (patch) | |
tree | b5d8be3492b7aa7e3df4d1ec71a44180255077fb /backends/hostmem-memfd.c | |
parent | bd3bcf6962b664ca3bf9c60fdcc4534e8e3d0641 (diff) |
HostMem: Add mechanism to opt in kvm guest memfd via MachineState
Add a new member "guest_memfd" to memory backends. When it's set
to true, it enables RAM_GUEST_MEMFD in ram_flags, thus private kvm
guest_memfd will be allocated during RAMBlock allocation.
Memory backend's @guest_memfd is wired with @require_guest_memfd
field of MachineState. It avoid looking up the machine in phymem.c.
MachineState::require_guest_memfd is supposed to be set by any VMs
that requires KVM guest memfd as private memory, e.g., TDX VM.
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Message-ID: <20240320083945.991426-8-michael.roth@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'backends/hostmem-memfd.c')
-rw-r--r-- | backends/hostmem-memfd.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c index 3923ea9364..745ead0034 100644 --- a/backends/hostmem-memfd.c +++ b/backends/hostmem-memfd.c @@ -55,6 +55,7 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) name = host_memory_backend_get_name(backend); ram_flags = backend->share ? RAM_SHARED : 0; ram_flags |= backend->reserve ? 0 : RAM_NORESERVE; + ram_flags |= backend->guest_memfd ? RAM_GUEST_MEMFD : 0; return memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), name, backend->size, ram_flags, fd, 0, errp); } |