On 9/30/26 02:50, Michael Roth wrote:
From: Peter Xu <[email protected]>
Host backends supports guest-memfd now by detecting whether it's a
confidential VM. There's no way to choose it yet from the memory level to
use it fully shared. If we use guest-memfd, it so far always implies we
need two layers of memory backends, while the guest-memfd only provides the
private set of pages.
This patch introduces a way so that QEMU can consume guest memfd as the
only source of memory to back the object (aka, fully shared).
To use the fully shared guest-memfd, one can add a memfd object with:
-object memory-backend-memfd,x-guest-memfd=on,share=on
Note that share=on is required with fully shared guest_memfd.
Since guest-memfd is not yet a drop-in replacement for memfd (e.g. lack
of hugepage support), the option is tagged as experimental for now so
that it can be made available for early enablement/testing without
causing any surprises for other users.
PS: there's a trivial touch-up on fd<0 check, because the stub to create
guest-memfd may return negative but not -1.
Reviewed-by: Xiaoyao Li <[email protected]>
Reviewed-by: Fabiano Rosas <[email protected]>
Reviewed-by: David Hildenbrand <[email protected]>
Signed-off-by: Peter Xu <[email protected]>
[mdr: add accompanying guest-memfd doc, mark as experimental]
Co-developed-by: Michael Roth <[email protected]>
Signed-off-by: Michael Roth <[email protected]>
---
backends/hostmem-memfd.c | 67 ++++++++++++++++++++--
docs/system/confidential-guest-support.rst | 2 +
docs/system/guest-memfd.rst | 60 +++++++++++++++++++
docs/system/index.rst | 1 +
qapi/qom.json | 15 ++++-
5 files changed, 139 insertions(+), 6 deletions(-)
create mode 100644 docs/system/guest-memfd.rst
diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c
index 7a7855aaab..666593ff6c 100644
--- a/backends/hostmem-memfd.c
+++ b/backends/hostmem-memfd.c
@@ -18,6 +18,9 @@
#include "qapi/error.h"
#include "qom/object.h"
#include "migration/cpr.h"
+#include "system/kvm.h"
+#include <linux/kvm.h>
+#include "qapi/qapi-visit-common.h"
Starting with this commit, a build of qemu on sparc64 host. As far as I
remember,
linux on sparc64 does not support kvm, so there's no asm/kvm.h which is included
by linux/kvm.h.
Should this include (and subsequent addiions) be #if-guarded by CONFIG_KVM
perhaps?
Or maybe this whole file (hostmem-memfd.c) or subsystem (hostmem) should be
omitted
if !kvm?
In file included from backends/hostmem-memfd.c:23:
linux-headers/linux/kvm.h:16:10: fatal error: asm/kvm.h: No such file or
directory
16 | #include <asm/kvm.h>
Thanks,
/mjt