* [PATCH 1/4] tests/migration-test: Introduce MemType
2025-11-17 22:39 [PATCH 0/4] tests/migration-test: Introduce mem_type Peter Xu
@ 2025-11-17 22:39 ` Peter Xu
2025-11-17 22:39 ` [PATCH 2/4] tests/migration-test: Merge shmem_opts into memory_backend Peter Xu
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Peter Xu @ 2025-11-17 22:39 UTC (permalink / raw)
To: qemu-devel; +Cc: peterx, Juraj Marcin, Fabiano Rosas
Some migration tests need to be run with shmem, the rest by default use
anonymous memory.
Introduce MemType and replace use_shmem with such a enumeration. This
prepares for a 3rd type of memory to be tested for migration.
Careful readers may also already notice that MigrateStart has another field
called memory_backend, which makes the whole "memory type" definition
convoluted. That'll be merged into MemType soon in a follow up patch.
When doing this, introduce some migrate_mem_type_*() helpers to do the
work for each memory type.
Signed-off-by: Peter Xu <peterx@redhat.com>
---
tests/qtest/migration/framework.h | 8 ++-
tests/qtest/migration/cpr-tests.c | 2 +-
tests/qtest/migration/framework.c | 81 ++++++++++++++++++++++--------
tests/qtest/migration/misc-tests.c | 2 +-
4 files changed, 68 insertions(+), 25 deletions(-)
diff --git a/tests/qtest/migration/framework.h b/tests/qtest/migration/framework.h
index 9bb584a6bb..70705725bc 100644
--- a/tests/qtest/migration/framework.h
+++ b/tests/qtest/migration/framework.h
@@ -18,6 +18,12 @@
#define FILE_TEST_OFFSET 0x1000
#define FILE_TEST_MARKER 'X'
+typedef enum {
+ MEM_TYPE_ANON,
+ MEM_TYPE_SHMEM,
+ MEM_TYPE_NUM,
+} MemType;
+
typedef struct MigrationTestEnv {
bool has_kvm;
bool has_tcg;
@@ -102,7 +108,7 @@ typedef struct {
* unconditionally, because it means the user would like to be verbose.
*/
bool hide_stderr;
- bool use_shmem;
+ MemType mem_type;
/* only launch the source process */
bool only_source;
/* only launch the target process */
diff --git a/tests/qtest/migration/cpr-tests.c b/tests/qtest/migration/cpr-tests.c
index 9388ad64be..70f8e69633 100644
--- a/tests/qtest/migration/cpr-tests.c
+++ b/tests/qtest/migration/cpr-tests.c
@@ -32,7 +32,7 @@ static void test_mode_reboot(void)
g_autofree char *uri = g_strdup_printf("file:%s/%s", tmpfs,
FILE_TEST_FILENAME);
MigrateCommon args = {
- .start.use_shmem = true,
+ .start.mem_type = MEM_TYPE_SHMEM,
.connect_uri = uri,
.listen_uri = "defer",
.start_hook = migrate_hook_start_mode_reboot,
diff --git a/tests/qtest/migration/framework.c b/tests/qtest/migration/framework.c
index a9be9c2dbf..8fa39999a1 100644
--- a/tests/qtest/migration/framework.c
+++ b/tests/qtest/migration/framework.c
@@ -260,6 +260,25 @@ static char *test_shmem_path(void)
return g_strdup_printf("/dev/shm/qemu-%d", getpid());
}
+/* NOTE: caller is responsbile to free the string if returned */
+static char *migrate_mem_type_get_opts(MemType type, const char *memory_size)
+{
+ g_autofree char *shmem_path = NULL;
+ char *backend = NULL;
+
+ switch (type) {
+ case MEM_TYPE_SHMEM:
+ shmem_path = test_shmem_path();
+ backend = g_strdup_printf(
+ "-object memory-backend-file,id=mem0,size=%s"
+ ",mem-path=%s,share=on -numa node,memdev=mem0",
+ memory_size, shmem_path);
+ return backend;
+ default:
+ return NULL;
+ }
+}
+
int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
{
/* options for source and target */
@@ -268,7 +287,6 @@ int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
gchar *cmd_target = NULL;
const gchar *ignore_stderr;
g_autofree char *shmem_opts = NULL;
- g_autofree char *shmem_path = NULL;
const char *kvm_opts = NULL;
const char *arch = qtest_get_arch();
const char *memory_size;
@@ -332,13 +350,7 @@ int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
ignore_stderr = "";
}
- if (args->use_shmem) {
- shmem_path = test_shmem_path();
- shmem_opts = g_strdup_printf(
- "-object memory-backend-file,id=mem0,size=%s"
- ",mem-path=%s,share=on -numa node,memdev=mem0",
- memory_size, shmem_path);
- }
+ shmem_opts = migrate_mem_type_get_opts(args->mem_type, memory_size);
if (args->memory_backend) {
memory_backend = g_strdup_printf(args->memory_backend, memory_size);
@@ -403,6 +415,42 @@ int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
return 0;
}
+static bool migrate_mem_type_prepare(MemType type)
+{
+ switch (type) {
+ case MEM_TYPE_SHMEM:
+ if (!g_file_test("/dev/shm", G_FILE_TEST_IS_DIR)) {
+ g_test_skip("/dev/shm is not supported");
+ return false;
+ }
+ break;
+ default:
+ break;
+ }
+
+ return true;
+}
+
+static void migrate_mem_type_cleanup(MemType type)
+{
+ g_autofree char *shmem_path = NULL;
+
+ switch (type) {
+ case MEM_TYPE_SHMEM:
+
+ /*
+ * Remove shmem file immediately to avoid memory leak in test
+ * failed case. It's valid because QEMU has already opened this
+ * file
+ */
+ shmem_path = test_shmem_path();
+ unlink(shmem_path);
+ break;
+ default:
+ break;
+ }
+}
+
int migrate_start(QTestState **from, QTestState **to, const char *uri,
MigrateStart *args)
{
@@ -410,11 +458,8 @@ int migrate_start(QTestState **from, QTestState **to, const char *uri,
g_autofree gchar *cmd_target = NULL;
g_autoptr(QList) capabilities = migrate_start_get_qmp_capabilities(args);
- if (args->use_shmem) {
- if (!g_file_test("/dev/shm", G_FILE_TEST_IS_DIR)) {
- g_test_skip("/dev/shm is not supported");
- return -1;
- }
+ if (!migrate_mem_type_prepare(args->mem_type)) {
+ return -1;
}
dst_state = (QTestMigrationState) { };
@@ -441,15 +486,7 @@ int migrate_start(QTestState **from, QTestState **to, const char *uri,
&dst_state);
}
- /*
- * Remove shmem file immediately to avoid memory leak in test failed case.
- * It's valid because QEMU has already opened this file
- */
- if (args->use_shmem) {
- g_autofree char *shmem_path = test_shmem_path();
- unlink(shmem_path);
- }
-
+ migrate_mem_type_cleanup(args->mem_type);
migrate_start_set_capabilities(*from,
args->only_source ? NULL : *to,
args);
diff --git a/tests/qtest/migration/misc-tests.c b/tests/qtest/migration/misc-tests.c
index 54995256d8..20edaa51f5 100644
--- a/tests/qtest/migration/misc-tests.c
+++ b/tests/qtest/migration/misc-tests.c
@@ -97,7 +97,7 @@ static void test_ignore_shared(void)
g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
QTestState *from, *to;
MigrateStart args = {
- .use_shmem = true,
+ .mem_type = MEM_TYPE_SHMEM,
.caps[MIGRATION_CAPABILITY_X_IGNORE_SHARED] = true,
};
--
2.50.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 2/4] tests/migration-test: Merge shmem_opts into memory_backend
2025-11-17 22:39 [PATCH 0/4] tests/migration-test: Introduce mem_type Peter Xu
2025-11-17 22:39 ` [PATCH 1/4] tests/migration-test: Introduce MemType Peter Xu
@ 2025-11-17 22:39 ` Peter Xu
2025-11-21 12:46 ` Juraj Marcin
2025-11-17 22:39 ` [PATCH 3/4] tests/migration-test: Add MEM_TYPE_SHMEM Peter Xu
` (2 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Peter Xu @ 2025-11-17 22:39 UTC (permalink / raw)
To: qemu-devel; +Cc: peterx, Juraj Marcin, Fabiano Rosas
The two parameters are more or less duplicated in migrate_args(). They all
describe the memory type. When one is used, the other is not.
mem_type currently uses numa parameter to specify the memory backend, while
memory_backend (the two users of such uses "-machine memory-backend=ID").
This patch merges the use of the two variables so that we always generate a
memory object string and put it into "memory_backend" variable. Now we can
drop shmem_opts parameter in the function.
Meanwhile we always use a memory-backend-* no matter which mem type is
used. This brings mem_type to be aligned with memory_backend usage, then
we stick with this as this is flexible enough.
This paves way that we merge mem_type and memory_backend in MigrateStart.
Signed-off-by: Peter Xu <peterx@redhat.com>
---
tests/qtest/migration/framework.c | 41 ++++++++++++++++++++-----------
1 file changed, 26 insertions(+), 15 deletions(-)
diff --git a/tests/qtest/migration/framework.c b/tests/qtest/migration/framework.c
index 8fa39999a1..6df0e56c2a 100644
--- a/tests/qtest/migration/framework.c
+++ b/tests/qtest/migration/framework.c
@@ -260,23 +260,36 @@ static char *test_shmem_path(void)
return g_strdup_printf("/dev/shm/qemu-%d", getpid());
}
+#define MIG_MEM_ID "mig.mem"
+
/* NOTE: caller is responsbile to free the string if returned */
static char *migrate_mem_type_get_opts(MemType type, const char *memory_size)
{
g_autofree char *shmem_path = NULL;
- char *backend = NULL;
+ g_autofree char *backend = NULL;
+ bool share = true;
+ char *opts;
switch (type) {
case MEM_TYPE_SHMEM:
shmem_path = test_shmem_path();
- backend = g_strdup_printf(
- "-object memory-backend-file,id=mem0,size=%s"
- ",mem-path=%s,share=on -numa node,memdev=mem0",
- memory_size, shmem_path);
- return backend;
+ backend = g_strdup_printf("-object memory-backend-file,mem-path=%s",
+ shmem_path);
+ break;
+ case MEM_TYPE_ANON:
+ backend = g_strdup("-object memory-backend-ram");
+ share = false;
+ break;
default:
- return NULL;
+ g_assert_not_reached();
+ break;
}
+
+ opts = g_strdup_printf("%s,id=%s,size=%s,share=%s",
+ backend, MIG_MEM_ID, memory_size,
+ share ? "on" : "off");
+
+ return opts;
}
int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
@@ -286,7 +299,7 @@ int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
gchar *cmd_source = NULL;
gchar *cmd_target = NULL;
const gchar *ignore_stderr;
- g_autofree char *shmem_opts = NULL;
+ g_autofree char *mem_object = NULL;
const char *kvm_opts = NULL;
const char *arch = qtest_get_arch();
const char *memory_size;
@@ -350,12 +363,12 @@ int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
ignore_stderr = "";
}
- shmem_opts = migrate_mem_type_get_opts(args->mem_type, memory_size);
-
if (args->memory_backend) {
memory_backend = g_strdup_printf(args->memory_backend, memory_size);
} else {
- memory_backend = g_strdup_printf("-m %s ", memory_size);
+ mem_object = migrate_mem_type_get_opts(args->mem_type, memory_size);
+ memory_backend = g_strdup_printf("-machine memory-backend=%s %s",
+ MIG_MEM_ID, mem_object);
}
if (args->use_dirty_ring) {
@@ -378,12 +391,11 @@ int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
"-name source,debug-threads=on "
"%s "
"-serial file:%s/src_serial "
- "%s %s %s %s",
+ "%s %s %s",
kvm_opts ? kvm_opts : "",
machine, machine_opts,
memory_backend, tmpfs,
arch_opts ? arch_opts : "",
- shmem_opts ? shmem_opts : "",
args->opts_source ? args->opts_source : "",
ignore_stderr);
@@ -400,13 +412,12 @@ int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
"%s "
"-serial file:%s/dest_serial "
"-incoming %s "
- "%s %s %s %s %s",
+ "%s %s %s %s",
kvm_opts ? kvm_opts : "",
machine, machine_opts,
memory_backend, tmpfs, uri,
events,
arch_opts ? arch_opts : "",
- shmem_opts ? shmem_opts : "",
args->opts_target ? args->opts_target : "",
ignore_stderr);
--
2.50.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 2/4] tests/migration-test: Merge shmem_opts into memory_backend
2025-11-17 22:39 ` [PATCH 2/4] tests/migration-test: Merge shmem_opts into memory_backend Peter Xu
@ 2025-11-21 12:46 ` Juraj Marcin
2025-11-21 15:32 ` Peter Xu
0 siblings, 1 reply; 8+ messages in thread
From: Juraj Marcin @ 2025-11-21 12:46 UTC (permalink / raw)
To: Peter Xu; +Cc: qemu-devel, Fabiano Rosas
Hi Peter,
you can add my R-b to the whole series, I just have a small nitpick
below, but feel free to ignore it.
Reviewed-by: Juraj Marcin <jmarcin@redhat.com>
On 2025-11-17 17:39, Peter Xu wrote:
> The two parameters are more or less duplicated in migrate_args(). They all
> describe the memory type. When one is used, the other is not.
>
> mem_type currently uses numa parameter to specify the memory backend, while
> memory_backend (the two users of such uses "-machine memory-backend=ID").
>
> This patch merges the use of the two variables so that we always generate a
> memory object string and put it into "memory_backend" variable. Now we can
> drop shmem_opts parameter in the function.
>
> Meanwhile we always use a memory-backend-* no matter which mem type is
> used. This brings mem_type to be aligned with memory_backend usage, then
> we stick with this as this is flexible enough.
>
> This paves way that we merge mem_type and memory_backend in MigrateStart.
>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
> tests/qtest/migration/framework.c | 41 ++++++++++++++++++++-----------
> 1 file changed, 26 insertions(+), 15 deletions(-)
>
> diff --git a/tests/qtest/migration/framework.c b/tests/qtest/migration/framework.c
> index 8fa39999a1..6df0e56c2a 100644
> --- a/tests/qtest/migration/framework.c
> +++ b/tests/qtest/migration/framework.c
> @@ -260,23 +260,36 @@ static char *test_shmem_path(void)
> return g_strdup_printf("/dev/shm/qemu-%d", getpid());
> }
>
> +#define MIG_MEM_ID "mig.mem"
> +
> /* NOTE: caller is responsbile to free the string if returned */
> static char *migrate_mem_type_get_opts(MemType type, const char *memory_size)
> {
> g_autofree char *shmem_path = NULL;
> - char *backend = NULL;
> + g_autofree char *backend = NULL;
> + bool share = true;
> + char *opts;
>
> switch (type) {
> case MEM_TYPE_SHMEM:
> shmem_path = test_shmem_path();
> - backend = g_strdup_printf(
> - "-object memory-backend-file,id=mem0,size=%s"
> - ",mem-path=%s,share=on -numa node,memdev=mem0",
> - memory_size, shmem_path);
> - return backend;
> + backend = g_strdup_printf("-object memory-backend-file,mem-path=%s",
> + shmem_path);
> + break;
> + case MEM_TYPE_ANON:
> + backend = g_strdup("-object memory-backend-ram");
> + share = false;
> + break;
Wouldn't it be a bit nicer to add this case before SHMEM, so the order
is the same as in the enum? The patch adding MEMFD follows is by adding
it right after SHMEM (and before ANON).
> default:
> - return NULL;
> + g_assert_not_reached();
> + break;
> }
> +
> + opts = g_strdup_printf("%s,id=%s,size=%s,share=%s",
> + backend, MIG_MEM_ID, memory_size,
> + share ? "on" : "off");
> +
> + return opts;
> }
>
> int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
> @@ -286,7 +299,7 @@ int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
> gchar *cmd_source = NULL;
> gchar *cmd_target = NULL;
> const gchar *ignore_stderr;
> - g_autofree char *shmem_opts = NULL;
> + g_autofree char *mem_object = NULL;
> const char *kvm_opts = NULL;
> const char *arch = qtest_get_arch();
> const char *memory_size;
> @@ -350,12 +363,12 @@ int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
> ignore_stderr = "";
> }
>
> - shmem_opts = migrate_mem_type_get_opts(args->mem_type, memory_size);
> -
> if (args->memory_backend) {
> memory_backend = g_strdup_printf(args->memory_backend, memory_size);
> } else {
> - memory_backend = g_strdup_printf("-m %s ", memory_size);
> + mem_object = migrate_mem_type_get_opts(args->mem_type, memory_size);
> + memory_backend = g_strdup_printf("-machine memory-backend=%s %s",
> + MIG_MEM_ID, mem_object);
> }
>
> if (args->use_dirty_ring) {
> @@ -378,12 +391,11 @@ int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
> "-name source,debug-threads=on "
> "%s "
> "-serial file:%s/src_serial "
> - "%s %s %s %s",
> + "%s %s %s",
> kvm_opts ? kvm_opts : "",
> machine, machine_opts,
> memory_backend, tmpfs,
> arch_opts ? arch_opts : "",
> - shmem_opts ? shmem_opts : "",
> args->opts_source ? args->opts_source : "",
> ignore_stderr);
>
> @@ -400,13 +412,12 @@ int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
> "%s "
> "-serial file:%s/dest_serial "
> "-incoming %s "
> - "%s %s %s %s %s",
> + "%s %s %s %s",
> kvm_opts ? kvm_opts : "",
> machine, machine_opts,
> memory_backend, tmpfs, uri,
> events,
> arch_opts ? arch_opts : "",
> - shmem_opts ? shmem_opts : "",
> args->opts_target ? args->opts_target : "",
> ignore_stderr);
>
> --
> 2.50.1
>
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 2/4] tests/migration-test: Merge shmem_opts into memory_backend
2025-11-21 12:46 ` Juraj Marcin
@ 2025-11-21 15:32 ` Peter Xu
0 siblings, 0 replies; 8+ messages in thread
From: Peter Xu @ 2025-11-21 15:32 UTC (permalink / raw)
To: Juraj Marcin; +Cc: qemu-devel, Fabiano Rosas
On Fri, Nov 21, 2025 at 01:46:31PM +0100, Juraj Marcin wrote:
> Hi Peter,
>
> you can add my R-b to the whole series, I just have a small nitpick
> below, but feel free to ignore it.
>
> Reviewed-by: Juraj Marcin <jmarcin@redhat.com>
Thanks a lot for the quick look. :)
>
> On 2025-11-17 17:39, Peter Xu wrote:
> > The two parameters are more or less duplicated in migrate_args(). They all
> > describe the memory type. When one is used, the other is not.
> >
> > mem_type currently uses numa parameter to specify the memory backend, while
> > memory_backend (the two users of such uses "-machine memory-backend=ID").
> >
> > This patch merges the use of the two variables so that we always generate a
> > memory object string and put it into "memory_backend" variable. Now we can
> > drop shmem_opts parameter in the function.
> >
> > Meanwhile we always use a memory-backend-* no matter which mem type is
> > used. This brings mem_type to be aligned with memory_backend usage, then
> > we stick with this as this is flexible enough.
> >
> > This paves way that we merge mem_type and memory_backend in MigrateStart.
> >
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> > ---
> > tests/qtest/migration/framework.c | 41 ++++++++++++++++++++-----------
> > 1 file changed, 26 insertions(+), 15 deletions(-)
> >
> > diff --git a/tests/qtest/migration/framework.c b/tests/qtest/migration/framework.c
> > index 8fa39999a1..6df0e56c2a 100644
> > --- a/tests/qtest/migration/framework.c
> > +++ b/tests/qtest/migration/framework.c
> > @@ -260,23 +260,36 @@ static char *test_shmem_path(void)
> > return g_strdup_printf("/dev/shm/qemu-%d", getpid());
> > }
> >
> > +#define MIG_MEM_ID "mig.mem"
> > +
> > /* NOTE: caller is responsbile to free the string if returned */
> > static char *migrate_mem_type_get_opts(MemType type, const char *memory_size)
> > {
> > g_autofree char *shmem_path = NULL;
> > - char *backend = NULL;
> > + g_autofree char *backend = NULL;
> > + bool share = true;
> > + char *opts;
> >
> > switch (type) {
> > case MEM_TYPE_SHMEM:
> > shmem_path = test_shmem_path();
> > - backend = g_strdup_printf(
> > - "-object memory-backend-file,id=mem0,size=%s"
> > - ",mem-path=%s,share=on -numa node,memdev=mem0",
> > - memory_size, shmem_path);
> > - return backend;
> > + backend = g_strdup_printf("-object memory-backend-file,mem-path=%s",
> > + shmem_path);
> > + break;
> > + case MEM_TYPE_ANON:
> > + backend = g_strdup("-object memory-backend-ram");
> > + share = false;
> > + break;
>
> Wouldn't it be a bit nicer to add this case before SHMEM, so the order
> is the same as in the enum? The patch adding MEMFD follows is by adding
> it right after SHMEM (and before ANON).
Normally we don't need to order cases in a switch() (especially think about
when fallthrough cases could happen..), but sure I am happy to move it if
that at least makes it easier to read for you.
I'll wait for other comments to see if I'll just move it when merge or
repost.
Thanks,
>
> > default:
> > - return NULL;
> > + g_assert_not_reached();
> > + break;
> > }
> > +
> > + opts = g_strdup_printf("%s,id=%s,size=%s,share=%s",
> > + backend, MIG_MEM_ID, memory_size,
> > + share ? "on" : "off");
> > +
> > + return opts;
> > }
> >
> > int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
> > @@ -286,7 +299,7 @@ int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
> > gchar *cmd_source = NULL;
> > gchar *cmd_target = NULL;
> > const gchar *ignore_stderr;
> > - g_autofree char *shmem_opts = NULL;
> > + g_autofree char *mem_object = NULL;
> > const char *kvm_opts = NULL;
> > const char *arch = qtest_get_arch();
> > const char *memory_size;
> > @@ -350,12 +363,12 @@ int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
> > ignore_stderr = "";
> > }
> >
> > - shmem_opts = migrate_mem_type_get_opts(args->mem_type, memory_size);
> > -
> > if (args->memory_backend) {
> > memory_backend = g_strdup_printf(args->memory_backend, memory_size);
> > } else {
> > - memory_backend = g_strdup_printf("-m %s ", memory_size);
> > + mem_object = migrate_mem_type_get_opts(args->mem_type, memory_size);
> > + memory_backend = g_strdup_printf("-machine memory-backend=%s %s",
> > + MIG_MEM_ID, mem_object);
> > }
> >
> > if (args->use_dirty_ring) {
> > @@ -378,12 +391,11 @@ int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
> > "-name source,debug-threads=on "
> > "%s "
> > "-serial file:%s/src_serial "
> > - "%s %s %s %s",
> > + "%s %s %s",
> > kvm_opts ? kvm_opts : "",
> > machine, machine_opts,
> > memory_backend, tmpfs,
> > arch_opts ? arch_opts : "",
> > - shmem_opts ? shmem_opts : "",
> > args->opts_source ? args->opts_source : "",
> > ignore_stderr);
> >
> > @@ -400,13 +412,12 @@ int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
> > "%s "
> > "-serial file:%s/dest_serial "
> > "-incoming %s "
> > - "%s %s %s %s %s",
> > + "%s %s %s %s",
> > kvm_opts ? kvm_opts : "",
> > machine, machine_opts,
> > memory_backend, tmpfs, uri,
> > events,
> > arch_opts ? arch_opts : "",
> > - shmem_opts ? shmem_opts : "",
> > args->opts_target ? args->opts_target : "",
> > ignore_stderr);
> >
> > --
> > 2.50.1
> >
>
--
Peter Xu
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/4] tests/migration-test: Add MEM_TYPE_SHMEM
2025-11-17 22:39 [PATCH 0/4] tests/migration-test: Introduce mem_type Peter Xu
2025-11-17 22:39 ` [PATCH 1/4] tests/migration-test: Introduce MemType Peter Xu
2025-11-17 22:39 ` [PATCH 2/4] tests/migration-test: Merge shmem_opts into memory_backend Peter Xu
@ 2025-11-17 22:39 ` Peter Xu
2025-11-17 22:39 ` [PATCH 4/4] tests/migration-test: Use MEM_TYPE_MEMFD for memory_backend Peter Xu
2025-11-21 17:50 ` [PATCH 0/4] tests/migration-test: Introduce mem_type Fabiano Rosas
4 siblings, 0 replies; 8+ messages in thread
From: Peter Xu @ 2025-11-17 22:39 UTC (permalink / raw)
To: qemu-devel; +Cc: peterx, Juraj Marcin, Fabiano Rosas
Add memfd support for mem_type. Will be used to replace memory_backend.
Signed-off-by: Peter Xu <peterx@redhat.com>
---
tests/qtest/migration/framework.h | 13 +++++++++++++
tests/qtest/migration/framework.c | 3 +++
2 files changed, 16 insertions(+)
diff --git a/tests/qtest/migration/framework.h b/tests/qtest/migration/framework.h
index 70705725bc..9dec21c344 100644
--- a/tests/qtest/migration/framework.h
+++ b/tests/qtest/migration/framework.h
@@ -19,8 +19,21 @@
#define FILE_TEST_MARKER 'X'
typedef enum {
+ /*
+ * Use memory-backend-ram, private mappings
+ */
MEM_TYPE_ANON,
+ /*
+ * Use shmem file (under /dev/shm), shared mappings
+ */
MEM_TYPE_SHMEM,
+ /*
+ * Use anonymous memfd, shared mappings.
+ *
+ * NOTE: this is internally almost the same as MEM_TYPE_SHMEM on Linux,
+ * but only anonymously allocated.
+ */
+ MEM_TYPE_MEMFD,
MEM_TYPE_NUM,
} MemType;
diff --git a/tests/qtest/migration/framework.c b/tests/qtest/migration/framework.c
index 6df0e56c2a..4d1663356a 100644
--- a/tests/qtest/migration/framework.c
+++ b/tests/qtest/migration/framework.c
@@ -276,6 +276,9 @@ static char *migrate_mem_type_get_opts(MemType type, const char *memory_size)
backend = g_strdup_printf("-object memory-backend-file,mem-path=%s",
shmem_path);
break;
+ case MEM_TYPE_MEMFD:
+ backend = g_strdup("-object memory-backend-memfd");
+ break;
case MEM_TYPE_ANON:
backend = g_strdup("-object memory-backend-ram");
share = false;
--
2.50.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 4/4] tests/migration-test: Use MEM_TYPE_MEMFD for memory_backend
2025-11-17 22:39 [PATCH 0/4] tests/migration-test: Introduce mem_type Peter Xu
` (2 preceding siblings ...)
2025-11-17 22:39 ` [PATCH 3/4] tests/migration-test: Add MEM_TYPE_SHMEM Peter Xu
@ 2025-11-17 22:39 ` Peter Xu
2025-11-21 17:50 ` [PATCH 0/4] tests/migration-test: Introduce mem_type Fabiano Rosas
4 siblings, 0 replies; 8+ messages in thread
From: Peter Xu @ 2025-11-17 22:39 UTC (permalink / raw)
To: qemu-devel; +Cc: peterx, Juraj Marcin, Fabiano Rosas
The only two users of memory_backend as of now (cpr-exec, cpr-transfer)
uses memfd as backend, now we fully support it. We can move memory_backend
usage to mem_type and drop it.
Signed-off-by: Peter Xu <peterx@redhat.com>
---
tests/qtest/migration/framework.h | 5 -----
tests/qtest/migration/cpr-tests.c | 6 ++----
tests/qtest/migration/framework.c | 10 +++-------
3 files changed, 5 insertions(+), 16 deletions(-)
diff --git a/tests/qtest/migration/framework.h b/tests/qtest/migration/framework.h
index 9dec21c344..ed85ed502d 100644
--- a/tests/qtest/migration/framework.h
+++ b/tests/qtest/migration/framework.h
@@ -134,11 +134,6 @@ typedef struct {
bool suspend_me;
/* enable OOB QMP capability */
bool oob;
- /*
- * Format string for the main memory backend, containing one %s where the
- * size is plugged in. If omitted, "-m %s" is used.
- */
- const char *memory_backend;
/* Do not connect to target monitor and qtest sockets in qtest_init */
bool defer_target_connect;
diff --git a/tests/qtest/migration/cpr-tests.c b/tests/qtest/migration/cpr-tests.c
index 70f8e69633..2a186c6f35 100644
--- a/tests/qtest/migration/cpr-tests.c
+++ b/tests/qtest/migration/cpr-tests.c
@@ -89,8 +89,7 @@ static void test_mode_transfer_common(bool incoming_defer)
.start.opts_source = opts,
.start.opts_target = opts_target,
.start.defer_target_connect = true,
- .start.memory_backend = "-object memory-backend-memfd,id=pc.ram,size=%s"
- " -machine memory-backend=pc.ram",
+ .start.mem_type = MEM_TYPE_MEMFD,
.listen_uri = incoming_defer ? "defer" : uri,
.connect_channels = connect_channels,
.cpr_channel = cpr_channel,
@@ -235,8 +234,7 @@ static void test_mode_exec(void)
MigrateCommon args = {
.start.only_source = true,
.start.opts_source = "-machine aux-ram-share=on -nodefaults",
- .start.memory_backend = "-object memory-backend-memfd,id=pc.ram,size=%s"
- " -machine memory-backend=pc.ram",
+ .start.mem_type = MEM_TYPE_MEMFD,
.connect_uri = uri,
.listen_uri = listen_uri,
.start_hook = test_mode_exec_start,
diff --git a/tests/qtest/migration/framework.c b/tests/qtest/migration/framework.c
index 4d1663356a..81eae09c92 100644
--- a/tests/qtest/migration/framework.c
+++ b/tests/qtest/migration/framework.c
@@ -366,13 +366,9 @@ int migrate_args(char **from, char **to, const char *uri, MigrateStart *args)
ignore_stderr = "";
}
- if (args->memory_backend) {
- memory_backend = g_strdup_printf(args->memory_backend, memory_size);
- } else {
- mem_object = migrate_mem_type_get_opts(args->mem_type, memory_size);
- memory_backend = g_strdup_printf("-machine memory-backend=%s %s",
- MIG_MEM_ID, mem_object);
- }
+ mem_object = migrate_mem_type_get_opts(args->mem_type, memory_size);
+ memory_backend = g_strdup_printf("-machine memory-backend=%s %s",
+ MIG_MEM_ID, mem_object);
if (args->use_dirty_ring) {
kvm_opts = ",dirty-ring-size=4096";
--
2.50.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 0/4] tests/migration-test: Introduce mem_type
2025-11-17 22:39 [PATCH 0/4] tests/migration-test: Introduce mem_type Peter Xu
` (3 preceding siblings ...)
2025-11-17 22:39 ` [PATCH 4/4] tests/migration-test: Use MEM_TYPE_MEMFD for memory_backend Peter Xu
@ 2025-11-21 17:50 ` Fabiano Rosas
4 siblings, 0 replies; 8+ messages in thread
From: Fabiano Rosas @ 2025-11-21 17:50 UTC (permalink / raw)
To: Peter Xu, qemu-devel; +Cc: peterx, Juraj Marcin
Peter Xu <peterx@redhat.com> writes:
> This is a small refactor series to merge memory_backend and use_shmem
> parameters that migration-test uses to specify memory types. No rush for
> having it for 10.2, but since this is test code, we can also consider it as
> the current two parameters are definitely confusing..
>
> This series will also make guest-memfd support extremely easy to add too.
>
> Comments welcomed, thanks.
>
> Peter Xu (4):
> tests/migration-test: Introduce MemType
> tests/migration-test: Merge shmem_opts into memory_backend
> tests/migration-test: Add MEM_TYPE_SHMEM
> tests/migration-test: Use MEM_TYPE_MEMFD for memory_backend
>
> tests/qtest/migration/framework.h | 26 +++++--
> tests/qtest/migration/cpr-tests.c | 8 +-
> tests/qtest/migration/framework.c | 113 ++++++++++++++++++++---------
> tests/qtest/migration/misc-tests.c | 2 +-
> 4 files changed, 104 insertions(+), 45 deletions(-)
Series:
Reviewed-by: Fabiano Rosas <farosas@suse.de>
^ permalink raw reply [flat|nested] 8+ messages in thread