From: Michael Roth <michael.roth@amd.com>
To: <qemu-devel@nongnu.org>
Cc: <jmarcin@redhat.com>, <david@kernel.org>, <pbonzini@redhat.com>,
<chenyi.qiang@intel.com>, <peterx@redhat.com>, <farosas@suse.de>,
<aik@amd.com>, <xiaoyao.li@intel.com>
Subject: [PATCH v4 11/12] tests/migration-test: Support guest-memfd init shared mem type
Date: Wed, 12 Aug 2026 15:16:49 -0500 [thread overview]
Message-ID: <20260812201938.198915-12-michael.roth@amd.com> (raw)
In-Reply-To: <20260812201938.198915-1-michael.roth@amd.com>
From: Peter Xu <peterx@redhat.com>
Support the guest-memfd type when the fd has init share enabled. It means
the gmemfd can be used similarly to memfd.
Signed-off-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Michael Roth <michael.roth@amd.com>
---
tests/qtest/migration/framework.c | 60 +++++++++++++++++++++++++++++++
tests/qtest/migration/framework.h | 4 +++
2 files changed, 64 insertions(+)
diff --git a/tests/qtest/migration/framework.c b/tests/qtest/migration/framework.c
index a830b96f41..b7aef6b21c 100644
--- a/tests/qtest/migration/framework.c
+++ b/tests/qtest/migration/framework.c
@@ -26,6 +26,10 @@
#include "qemu/range.h"
#include "qemu/sockets.h"
+#ifdef CONFIG_LINUX
+#include <linux/kvm.h>
+#include <sys/ioctl.h>
+#endif
#define QEMU_VM_FILE_MAGIC 0x5145564d
#define QEMU_ENV_SRC "QTEST_QEMU_BINARY_SRC"
@@ -296,6 +300,9 @@ static char *migrate_mem_type_get_opts(MemType type, const char *memory_size)
case MEM_TYPE_MEMFD:
backend = g_strdup("-object memory-backend-memfd");
break;
+ case MEM_TYPE_GUEST_MEMFD:
+ backend = g_strdup("-object memory-backend-memfd,guest-memfd=on");
+ break;
default:
g_assert_not_reached();
break;
@@ -444,8 +451,55 @@ int migrate_args(char **from, char **to, MigrateStart *args)
return 0;
}
+static bool kvm_guest_memfd_init_shared_supported(const char **reason)
+{
+ assert(*reason == NULL);
+
+#ifdef CONFIG_LINUX
+ int ret, fd = -1;
+
+ if (!migration_get_env()->has_kvm) {
+ *reason = "KVM is not enabled in the current QEMU build";
+ goto out;
+ }
+
+ fd = open("/dev/kvm", O_RDWR);
+ if (fd < 0) {
+ *reason = "KVM module isn't available or missing permission";
+ goto out;
+ }
+
+ ret = ioctl(fd, KVM_CHECK_EXTENSION, KVM_CAP_GUEST_MEMFD);
+ if (!ret) {
+ *reason = "KVM module doesn't support guest-memfd";
+ goto out;
+ }
+
+ ret = ioctl(fd, KVM_CHECK_EXTENSION, KVM_CAP_GUEST_MEMFD_FLAGS);
+ if (ret < 0) {
+ *reason = "KVM doesn't support KVM_CAP_GUEST_MEMFD_FLAGS";
+ goto out;
+ }
+
+ if (!(ret & GUEST_MEMFD_FLAG_INIT_SHARED)) {
+ *reason = "KVM doesn't support GUEST_MEMFD_FLAG_INIT_SHARED";
+ goto out;
+ }
+out:
+ if (fd >= 0) {
+ close(fd);
+ }
+#else
+ *reason = "KVM not supported on non-Linux OS";
+#endif
+
+ return !*reason;
+}
+
static bool migrate_mem_type_prepare(MemType type)
{
+ const char *reason = NULL;
+
switch (type) {
case MEM_TYPE_SHMEM:
if (!g_file_test("/dev/shm", G_FILE_TEST_IS_DIR)) {
@@ -453,6 +507,12 @@ static bool migrate_mem_type_prepare(MemType type)
return false;
}
break;
+ case MEM_TYPE_GUEST_MEMFD:
+ if (!kvm_guest_memfd_init_shared_supported(&reason)) {
+ g_test_skip(reason);
+ return false;
+ }
+ break;
default:
break;
}
diff --git a/tests/qtest/migration/framework.h b/tests/qtest/migration/framework.h
index 941cbd7102..10761f6e28 100644
--- a/tests/qtest/migration/framework.h
+++ b/tests/qtest/migration/framework.h
@@ -34,6 +34,10 @@ typedef enum {
* but only anonymously allocated.
*/
MEM_TYPE_MEMFD,
+ /*
+ * Use guest-memfd, shared mappings.
+ */
+ MEM_TYPE_GUEST_MEMFD,
MEM_TYPE_NUM,
} MemType;
--
2.43.0
next prev parent reply other threads:[~2026-08-12 20:22 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-12 20:16 [PATCH v4 00/12] KVM/hostmem: Support init-shared guest-memfd as VM backends Michael Roth
2026-08-12 20:16 ` [PATCH v4 01/12] kvm: Decouple memory attribute check from kvm_guest_memfd_supported Michael Roth
2026-08-12 20:16 ` [PATCH v4 02/12] kvm: Detect guest-memfd flags supported Michael Roth
2026-08-12 20:16 ` [PATCH v4 03/12] kvm: Provide explicit error for kvm_create_guest_memfd() Michael Roth
2026-08-12 20:16 ` [PATCH v4 04/12] ramblock: Rename guest_memfd to guest_memfd_private Michael Roth
2026-08-12 20:16 ` [PATCH v4 05/12] memory: Rename RAM_GUEST_MEMFD to RAM_GUEST_MEMFD_PRIVATE Michael Roth
2026-08-12 20:16 ` [PATCH v4 06/12] memory: Rename memory_region_has_guest_memfd() to *_private() Michael Roth
2026-08-12 20:16 ` [PATCH v4 07/12] hostmem: Rename guest_memfd to guest_memfd_private Michael Roth
2026-08-12 20:16 ` [PATCH v4 08/12] hostmem: Support fully shared guest memfd to back a VM Michael Roth
2026-08-12 20:16 ` [PATCH v4 09/12] machine: Rename machine_require_guest_memfd() to *_private() Michael Roth
2026-08-12 20:16 ` [PATCH v4 10/12] memory: Rename memory_region_init_ram_guest_memfd() " Michael Roth
2026-08-12 20:16 ` Michael Roth [this message]
2026-08-12 20:16 ` [PATCH v4 12/12] tests/migration-test: Add a precopy test for guest-memfd Michael Roth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260812201938.198915-12-michael.roth@amd.com \
--to=michael.roth@amd.com \
--cc=aik@amd.com \
--cc=chenyi.qiang@intel.com \
--cc=david@kernel.org \
--cc=farosas@suse.de \
--cc=jmarcin@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=xiaoyao.li@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.