* [PATCH 1/5] tests/migration-stress: Fix stress.c loop
2026-11-26 21:46 [PATCH 0/5] migration-test: Support running a real kernel Fabiano Rosas
@ 2026-11-26 21:47 ` Fabiano Rosas
2026-11-26 21:47 ` [PATCH 2/5] tests/migration-stress: Cleanups to stress.c Fabiano Rosas
` (4 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Fabiano Rosas @ 2026-11-26 21:47 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Xu
The stress.c loop is touching memory out of bounds. The inner loop
variable 'k' is lagging 8 bytes behind the pointers doing the actual
XOR operation:
for (j = 0; j < pagesPerMB; j++) {
dataptr = data;
for (k = 0; k < RAM_PAGE_SIZE; k += sizeof(long long)) {
ramptr += sizeof(long long);
dataptr += sizeof(long long);
*(unsigned long long *)ramptr ^= *(unsigned long long *)dataptr;
}
}
I ran into this while tweaking the amount of memory necessary for
running the VM with the stress initrd.
Rewrite the loop without manual pointer arithmetic, use more easily
identifiable patterns and isolate it in an inlined function.
Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
tests/migration-stress/stress.c | 39 ++++++++++++++++++++-------------
1 file changed, 24 insertions(+), 15 deletions(-)
diff --git a/tests/migration-stress/stress.c b/tests/migration-stress/stress.c
index 88acf8dc257..44db4bef8f0 100644
--- a/tests/migration-stress/stress.c
+++ b/tests/migration-stress/stress.c
@@ -156,14 +156,31 @@ static unsigned long long now(void)
return (tv.tv_sec * 1000ull) + (tv.tv_usec / 1000ull);
}
+static inline void xor_1M(void *ram_start, void *data_page)
+{
+ unsigned long long *addr, *data;
+ int i, j, pages_per_mb = RAM_PAGE_SIZE >> 4;
+ int n = RAM_PAGE_SIZE / sizeof(unsigned long long);
+
+ addr = ram_start;
+
+ for (i = 0; i < pages_per_mb; i++) {
+ data = data_page;
+ j = n;
+
+ while (j--) {
+ *addr ^= *data;
+ addr++;
+ data++;
+ }
+ }
+}
+
static void stressone(unsigned long long ramsizeMB)
{
- size_t pagesPerMB = 1024 * 1024 / RAM_PAGE_SIZE;
g_autofree char *ram = g_malloc(ramsizeMB * 1024 * 1024);
- char *ramptr;
- size_t i, j, k;
+ size_t i;
g_autofree char *data = g_malloc(RAM_PAGE_SIZE);
- char *dataptr;
size_t nMB = 0;
unsigned long long before, after;
@@ -181,17 +198,9 @@ static void stressone(unsigned long long ramsizeMB)
before = now();
while (1) {
-
- ramptr = ram;
- for (i = 0; i < ramsizeMB; i++, nMB++) {
- for (j = 0; j < pagesPerMB; j++) {
- dataptr = data;
- for (k = 0; k < RAM_PAGE_SIZE; k += sizeof(long long)) {
- ramptr += sizeof(long long);
- dataptr += sizeof(long long);
- *(unsigned long long *)ramptr ^= *(unsigned long long *)dataptr;
- }
- }
+ for (i = 0; i < ramsizeMB; i++) {
+ xor_1M(ram, data);
+ nMB++;
if (nMB == 1024) {
after = now();
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 2/5] tests/migration-stress: Cleanups to stress.c
2026-11-26 21:46 [PATCH 0/5] migration-test: Support running a real kernel Fabiano Rosas
2026-11-26 21:47 ` [PATCH 1/5] tests/migration-stress: Fix stress.c loop Fabiano Rosas
@ 2026-11-26 21:47 ` Fabiano Rosas
2026-11-26 21:47 ` [PATCH 3/5] tests/qtest/migration: Move guest workload code into bootfile.c Fabiano Rosas
` (3 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Fabiano Rosas @ 2026-11-26 21:47 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Xu
- brackets in all branches
- use snake_case
- inverted christmas tree variable declaration
- fix coding style of comments
- use a 'for' in the infinite loop (easier to read)
- tweaks to comments
- increment n_mb inline
Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
tests/migration-stress/stress.c | 109 ++++++++++++++++----------------
1 file changed, 55 insertions(+), 54 deletions(-)
diff --git a/tests/migration-stress/stress.c b/tests/migration-stress/stress.c
index 44db4bef8f0..3d8cb8984b7 100644
--- a/tests/migration-stress/stress.c
+++ b/tests/migration-stress/stress.c
@@ -49,20 +49,19 @@ static __attribute__((noreturn)) void exit_failure(void)
}
}
-static int get_command_arg_str(const char *name,
- char **val)
+static int get_command_arg_str(const char *name, char **val)
{
static char line[1024];
FILE *fp = fopen("/proc/cmdline", "r");
char *start, *end;
- if (fp == NULL) {
+ if (!fp) {
fprintf(stderr, "%s (%05d): ERROR: cannot open /proc/cmdline: %s\n",
argv0, gettid(), strerror(errno));
return -1;
}
- if (!fgets(line, sizeof line, fp)) {
+ if (!fgets(line, sizeof(line), fp)) {
fprintf(stderr, "%s (%05d): ERROR: cannot read /proc/cmdline: %s\n",
argv0, gettid(), strerror(errno));
fclose(fp);
@@ -71,37 +70,38 @@ static int get_command_arg_str(const char *name,
fclose(fp);
start = strstr(line, name);
- if (!start)
+ if (!start) {
return 0;
+ }
start += strlen(name);
if (*start != '=') {
- fprintf(stderr, "%s (%05d): ERROR: no value provided for '%s' in /proc/cmdline\n",
- argv0, gettid(), name);
+ fprintf(stderr, "%s (%05d): ERROR: no value provided for '%s' "
+ "in /proc/cmdline\n", argv0, gettid(), name);
}
start++;
end = strstr(start, " ");
- if (!end)
+ if (!end) {
end = strstr(start, "\n");
+ }
if (end == start) {
- fprintf(stderr, "%s (%05d): ERROR: no value provided for '%s' in /proc/cmdline\n",
- argv0, gettid(), name);
+ fprintf(stderr, "%s (%05d): ERROR: no value provided for '%s' "
+ "in /proc/cmdline\n", argv0, gettid(), name);
return -1;
}
- if (end)
+ if (end) {
*val = g_strndup(start, end - start);
- else
+ } else {
*val = g_strdup(start);
+ }
return 1;
}
-
-static int get_command_arg_ull(const char *name,
- unsigned long long *val)
+static int get_command_arg_ull(const char *name, unsigned long long *val)
{
char *valstr;
char *end;
@@ -146,7 +146,6 @@ static int random_bytes(char *buf, size_t len)
return 0;
}
-
static unsigned long long now(void)
{
struct timeval tv;
@@ -176,69 +175,68 @@ static inline void xor_1M(void *ram_start, void *data_page)
}
}
-static void stressone(unsigned long long ramsizeMB)
+static void stress_one(unsigned long long ramsize_mb)
{
- g_autofree char *ram = g_malloc(ramsizeMB * 1024 * 1024);
- size_t i;
- g_autofree char *data = g_malloc(RAM_PAGE_SIZE);
- size_t nMB = 0;
+ g_autofree char *ram_start = g_malloc(ramsize_mb * 1024 * 1024);
+ g_autofree char *data_page = g_malloc(RAM_PAGE_SIZE);
unsigned long long before, after;
+ int i, n_mb = 0;
- /* We don't care about initial state, but we do want
+ /*
+ * init ram: We don't care about initial state, but we do want
* to fault it all into RAM, otherwise the first iter
* of the loop below will be quite slow. We can't use
* 0x0 as the byte as gcc optimizes that away into a
- * calloc instead :-) */
- memset(ram, 0xfe, ramsizeMB * 1024 * 1024);
+ * calloc instead :-)
+ */
+ memset(ram_start, 0xfe, ramsize_mb * 1024 * 1024);
- if (random_bytes(data, RAM_PAGE_SIZE) < 0) {
+ /* init data: write a page of garbage */
+ if (random_bytes(data_page, RAM_PAGE_SIZE) < 0) {
return;
}
before = now();
- while (1) {
- for (i = 0; i < ramsizeMB; i++) {
- xor_1M(ram, data);
- nMB++;
+ for (;;) {
+ for (i = 0; i < ramsize_mb; i++) {
+ xor_1M(ram_start, data_page);
- if (nMB == 1024) {
+ if (++n_mb == 1024) {
after = now();
fprintf(stderr, "%s (%05d): INFO: %06llums copied 1 GB in %05llums\n",
argv0, gettid(), after, after - before);
before = now();
- nMB = 0;
+ n_mb = 0;
}
}
}
}
-
-static void *stressthread(void *arg)
+static void *stress_thread(void *arg)
{
- unsigned long long ramsizeMB = *(unsigned long long *)arg;
+ unsigned long long ramsize_mb = *(unsigned long long *)arg;
- stressone(ramsizeMB);
+ stress_one(ramsize_mb);
return NULL;
}
-static void stress(unsigned long long ramsizeGB, int ncpus)
+static void stress(unsigned long long ramsize_gb, int n_cpus)
{
size_t i;
- unsigned long long ramsizeMB = ramsizeGB * 1024 / ncpus;
- ncpus--;
+ unsigned long long ramsize_mb = ramsize_gb * 1024 / n_cpus;
- for (i = 0; i < ncpus; i++) {
+ n_cpus--;
+
+ for (i = 0; i < n_cpus; i++) {
pthread_t thr;
- pthread_create(&thr, NULL,
- stressthread, &ramsizeMB);
+ pthread_create(&thr, NULL, stress_thread, &ramsize_mb);
}
- stressone(ramsizeMB);
+ stress_one(ramsize_mb);
}
-
static int mount_misc(const char *fstype, const char *dir)
{
if (g_mkdir_with_parents(dir, 0755) < 0 && errno != EEXIST) {
@@ -271,7 +269,7 @@ static int mount_all(void)
int main(int argc, char **argv)
{
- unsigned long long ramsizeGB = 1;
+ unsigned long long ramsize_gb = 1;
char *end;
int ch;
int opt_ind = 0;
@@ -283,7 +281,7 @@ int main(int argc, char **argv)
{ NULL, 0, NULL, 0 }
};
int ret;
- int ncpus = 0;
+ int n_cpus = 0;
argv0 = argv[0];
@@ -291,7 +289,7 @@ int main(int argc, char **argv)
switch (ch) {
case 'r':
errno = 0;
- ramsizeGB = strtoll(optarg, &end, 10);
+ ramsize_gb = strtoll(optarg, &end, 10);
if (errno != 0 || *end) {
fprintf(stderr, "%s (%05d): ERROR: Cannot parse RAM size %s\n",
argv0, gettid(), optarg);
@@ -301,7 +299,7 @@ int main(int argc, char **argv)
case 'c':
errno = 0;
- ncpus = strtoll(optarg, &end, 10);
+ n_cpus = strtoll(optarg, &end, 10);
if (errno != 0 || *end) {
fprintf(stderr, "%s (%05d): ERROR: Cannot parse CPU count %s\n",
argv0, gettid(), optarg);
@@ -317,21 +315,24 @@ int main(int argc, char **argv)
}
if (getpid() == 1) {
- if (mount_all() < 0)
+ if (mount_all() < 0) {
exit_failure();
+ }
- ret = get_command_arg_ull("ramsize", &ramsizeGB);
- if (ret < 0)
+ ret = get_command_arg_ull("ramsize", &ramsize_gb);
+ if (ret < 0) {
exit_failure();
+ }
}
- if (ncpus == 0)
- ncpus = sysconf(_SC_NPROCESSORS_ONLN);
+ if (n_cpus == 0) {
+ n_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+ }
fprintf(stdout, "%s (%05d): INFO: RAM %llu GiB across %d CPUs\n",
- argv0, gettid(), ramsizeGB, ncpus);
+ argv0, gettid(), ramsize_gb, n_cpus);
- stress(ramsizeGB, ncpus);
+ stress(ramsize_gb, n_cpus);
exit_failure();
}
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 3/5] tests/qtest/migration: Move guest workload code into bootfile.c
2026-11-26 21:46 [PATCH 0/5] migration-test: Support running a real kernel Fabiano Rosas
2026-11-26 21:47 ` [PATCH 1/5] tests/migration-stress: Fix stress.c loop Fabiano Rosas
2026-11-26 21:47 ` [PATCH 2/5] tests/migration-stress: Cleanups to stress.c Fabiano Rosas
@ 2026-11-26 21:47 ` Fabiano Rosas
2026-11-26 21:47 ` [PATCH 4/5] tests/qtest/migration: Adapt wait_for_serial routine for stress.c Fabiano Rosas
` (2 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Fabiano Rosas @ 2026-11-26 21:47 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Xu, Laurent Vivier, Paolo Bonzini
Move all the code related to the guest workload into bootfile.c in
preparation for adding a second type of workload.
Move to bootfile.c:
- start|end_address variables, used to iterate over the guest
pages. Set them at bootfile_create() since they don't need to
change.
- check_guests_ram function, used to check for memory
corruption. Merge it with the adjacent code in migrate_end. Give it
a migrate_ prefix now that it will be exported.
- migrate_prepare|wait_for_dirty_mem, the logic for monitoring guest
memory dirtying. Move along the defines for the magic marker.
- the memory size and boot drive options. Change the bootfile_get()
API to pass the options already assembled instead of passing only
the bootpath.
Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
tests/qtest/migration/bootfile.c | 166 ++++++++++++++++++++++++++-
tests/qtest/migration/bootfile.h | 20 ++++
tests/qtest/migration/framework.c | 176 ++---------------------------
tests/qtest/migration/framework.h | 2 -
tests/qtest/migration/misc-tests.c | 1 +
5 files changed, 196 insertions(+), 169 deletions(-)
diff --git a/tests/qtest/migration/bootfile.c b/tests/qtest/migration/bootfile.c
index e46ad09de76..d40bd0c2d3e 100644
--- a/tests/qtest/migration/bootfile.c
+++ b/tests/qtest/migration/bootfile.c
@@ -11,6 +11,8 @@
*/
#include "qemu/osdep.h"
+#include "framework.h"
+#include "migration-util.h"
/*
* The boot file modifies memory area in [start_address, end_address)
@@ -23,6 +25,9 @@
#include "ppc64/a-b-kernel.h"
#include "s390x/a-b-bios.h"
+unsigned start_address;
+unsigned end_address;
+
static char *bootpath;
void bootfile_delete(void)
@@ -48,19 +53,29 @@ char *bootfile_create(const char *arch, const char *dir, bool suspend_me)
x86_bootsect[SYM_suspend_me - SYM_start] = suspend_me;
content = x86_bootsect;
len = sizeof(x86_bootsect);
+ start_address = X86_TEST_MEM_START;
+ end_address = X86_TEST_MEM_END;
} else if (g_str_equal(arch, "s390x")) {
content = s390x_elf;
len = sizeof(s390x_elf);
+ start_address = S390_TEST_MEM_START;
+ end_address = S390_TEST_MEM_END;
} else if (strcmp(arch, "ppc64") == 0) {
content = ppc64_kernel;
len = sizeof(ppc64_kernel);
+ start_address = PPC_TEST_MEM_START;
+ end_address = PPC_TEST_MEM_END;
} else if (strcmp(arch, "aarch64") == 0) {
content = aarch64_kernel;
len = sizeof(aarch64_kernel);
g_assert(sizeof(aarch64_kernel) <= ARM_TEST_MAX_KERNEL_SIZE);
+ start_address = ARM_TEST_MEM_START;
+ end_address = ARM_TEST_MEM_END;
} else if (strcmp(arch, "loongarch64") == 0) {
content = loongarch64_kernel;
len = sizeof(loongarch64_kernel);
+ start_address = LOONGARCH_TEST_MEM_START;
+ end_address = LOONGARCH_TEST_MEM_END;
} else {
g_assert_not_reached();
}
@@ -73,7 +88,154 @@ char *bootfile_create(const char *arch, const char *dir, bool suspend_me)
return bootpath;
}
-char *bootfile_get(void)
+char *bootfile_get_opts(const char *arch, char **mem_size)
{
- return bootpath;
+ const char *memory_size;
+ char *boot;
+
+ if (g_str_equal(arch, "i386") || g_str_equal(arch, "x86_64")) {
+ memory_size = "150M";
+ boot = g_strdup_printf(
+ "-drive if=none,id=d0,file=%s,format=raw "
+ "-device ide-hd,drive=d0,secs=1,cyls=1,heads=1", bootpath);
+
+ } else if (g_str_equal(arch, "s390x")) {
+ memory_size = "128M";
+ boot = g_strdup_printf("-bios %s", bootpath);
+
+ } else if (g_str_equal(arch, "ppc64")) {
+ memory_size = "256M";
+ boot = g_strdup_printf("-bios %s", bootpath);
+
+ } else if (g_str_equal(arch, "aarch64")) {
+ memory_size = "150M";
+ boot = g_strdup_printf("-kernel %s", bootpath);
+
+ } else if (g_str_equal(arch, "loongarch64")) {
+ memory_size = "256M";
+ boot = g_strdup_printf("-bios %s", bootpath);
+ } else {
+ g_assert_not_reached();
+ }
+
+ *mem_size = g_strdup(memory_size);
+ return boot;
+}
+
+void migrate_wait_for_dirty_mem(QTestState *from, QTestState *to)
+{
+ uint64_t watch_address = start_address + MAGIC_OFFSET_BASE;
+ uint64_t marker_address = start_address + MAGIC_OFFSET;
+ uint8_t watch_byte;
+
+ /*
+ * Wait for the MAGIC_MARKER to get transferred, as an
+ * indicator that a migration pass has made some known
+ * amount of progress.
+ */
+ do {
+ usleep(1000 * 10);
+ } while (qtest_readq(to, marker_address) != MAGIC_MARKER);
+
+ /* If suspended, src only iterates once, and watch_byte may never change */
+ if (get_src()->suspend_me) {
+ return;
+ }
+
+ /*
+ * Now ensure that already transferred bytes are
+ * dirty again from the guest workload. Note the
+ * guest byte value will wrap around and by chance
+ * match the original watch_byte. This is harmless
+ * as we'll eventually see a different value if we
+ * keep watching
+ */
+ watch_byte = qtest_readb(from, watch_address);
+ do {
+ usleep(1000 * 10);
+ } while (qtest_readb(from, watch_address) == watch_byte);
+}
+
+void migrate_prepare_for_dirty_mem(QTestState *from)
+{
+ /*
+ * The guest workflow iterates from start_address to
+ * end_address, writing 1 byte every TEST_MEM_PAGE_SIZE
+ * bytes.
+ *
+ * IOW, if we write to mem at a point which is NOT
+ * a multiple of TEST_MEM_PAGE_SIZE, our write won't
+ * conflict with the migration workflow.
+ *
+ * We put in a marker here, that we'll use to determine
+ * when the data has been transferred to the dst.
+ */
+ qtest_writeq(from, start_address + MAGIC_OFFSET, MAGIC_MARKER);
+}
+
+void migrate_check_guests_ram(QTestState *who)
+{
+ /*
+ * Our ASM test will have been incrementing one byte from each page from
+ * start_address to < end_address in order. This gives us a constraint
+ * that any page's byte should be equal or less than the previous pages
+ * byte (mod 256); and they should all be equal except for one transition
+ * at the point where we meet the incrementer. (We're running this with
+ * the guest stopped).
+ */
+ unsigned address;
+ uint8_t first_byte;
+ uint8_t last_byte;
+ bool hit_edge = false;
+ int bad = 0;
+ unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d;
+
+ qtest_memread(who, start_address, &dest_byte_a, 1);
+
+ /* Destination still running, wait for a byte to change */
+ do {
+ qtest_memread(who, start_address, &dest_byte_b, 1);
+ usleep(1000 * 10);
+ } while (dest_byte_a == dest_byte_b);
+
+ qtest_qmp_assert_success(who, "{ 'execute' : 'stop'}");
+
+ /* With it stopped, check nothing changes */
+ qtest_memread(who, start_address, &dest_byte_c, 1);
+ usleep(1000 * 200);
+ qtest_memread(who, start_address, &dest_byte_d, 1);
+ g_assert_cmpint(dest_byte_c, ==, dest_byte_d);
+
+ qtest_memread(who, start_address, &first_byte, 1);
+ last_byte = first_byte;
+
+ for (address = start_address + TEST_MEM_PAGE_SIZE; address < end_address;
+ address += TEST_MEM_PAGE_SIZE)
+ {
+ uint8_t b;
+ qtest_memread(who, address, &b, 1);
+ if (b != last_byte) {
+ if (((b + 1) % 256) == last_byte && !hit_edge) {
+ /*
+ * This is OK, the guest stopped at the point of
+ * incrementing the previous page but didn't get
+ * to us yet.
+ */
+ hit_edge = true;
+ last_byte = b;
+ } else {
+ bad++;
+ if (bad <= 10) {
+ fprintf(stderr, "Memory content inconsistency at %x"
+ " first_byte = %x last_byte = %x current = %x"
+ " hit_edge = %x\n",
+ address, first_byte, last_byte, b, hit_edge);
+ }
+ }
+ }
+ }
+ if (bad >= 10) {
+ fprintf(stderr, "and in another %d pages", bad - 10);
+ }
+ g_assert(bad == 0);
}
diff --git a/tests/qtest/migration/bootfile.h b/tests/qtest/migration/bootfile.h
index a4060ea4f72..4f628160f5d 100644
--- a/tests/qtest/migration/bootfile.h
+++ b/tests/qtest/migration/bootfile.h
@@ -15,11 +15,27 @@
*/
#ifdef __ASSEMBLER__
#define MIGRATION_GUEST_CODE
+#else
+#include "libqtest.h"
#endif
/* Common */
#define TEST_MEM_PAGE_SIZE 4096
+/*
+ * An initial 3 MB offset is used as that corresponds
+ * to ~1 sec of data transfer with our bandwidth setting.
+ */
+#define MAGIC_OFFSET_BASE (3 * 1024 * 1024)
+/*
+ * A further 1k is added to ensure we're not a multiple
+ * of TEST_MEM_PAGE_SIZE, thus avoid clash with writes
+ * from the migration guest workload.
+ */
+#define MAGIC_OFFSET_SHUFFLE 1024
+#define MAGIC_OFFSET (MAGIC_OFFSET_BASE + MAGIC_OFFSET_SHUFFLE)
+#define MAGIC_MARKER 0xFEED12345678CAFEULL
+
/* x86 */
#define X86_TEST_MEM_START (1 * 1024 * 1024)
#define X86_TEST_MEM_END (100 * 1024 * 1024)
@@ -50,6 +66,10 @@
void bootfile_delete(void);
char *bootfile_create(const char *arch, const char *dir, bool suspend_me);
char *bootfile_get(void);
+char *bootfile_get_opts(const char *arch, char **memory_size);
+void migrate_prepare_for_dirty_mem(QTestState *from);
+void migrate_wait_for_dirty_mem(QTestState *from, QTestState *to);
+void migrate_check_guests_ram(QTestState *who);
#endif
#endif /* BOOTFILE_H */
diff --git a/tests/qtest/migration/framework.c b/tests/qtest/migration/framework.c
index b7aef6b21cb..a081c8e7bb9 100644
--- a/tests/qtest/migration/framework.c
+++ b/tests/qtest/migration/framework.c
@@ -36,27 +36,10 @@
#define QEMU_ENV_DST "QTEST_QEMU_BINARY_DST"
#define MULTIFD_TEST_CHANNELS 4
-unsigned start_address;
-unsigned end_address;
static QTestMigrationState src_state;
static QTestMigrationState dst_state;
static char *tmpfs;
-/*
- * An initial 3 MB offset is used as that corresponds
- * to ~1 sec of data transfer with our bandwidth setting.
- */
-#define MAGIC_OFFSET_BASE (3 * 1024 * 1024)
-/*
- * A further 1k is added to ensure we're not a multiple
- * of TEST_MEM_PAGE_SIZE, thus avoid clash with writes
- * from the migration guest workload.
- */
-#define MAGIC_OFFSET_SHUFFLE 1024
-#define MAGIC_OFFSET (MAGIC_OFFSET_BASE + MAGIC_OFFSET_SHUFFLE)
-#define MAGIC_MARKER 0xFEED12345678CAFEULL
-
-
/*
* Wait for some output in the serial output file,
* we get an 'A' followed by an endless string of 'B's
@@ -92,108 +75,6 @@ void wait_for_serial(const char *side)
} while (true);
}
-void migrate_prepare_for_dirty_mem(QTestState *from)
-{
- /*
- * The guest workflow iterates from start_address to
- * end_address, writing 1 byte every TEST_MEM_PAGE_SIZE
- * bytes.
- *
- * IOW, if we write to mem at a point which is NOT
- * a multiple of TEST_MEM_PAGE_SIZE, our write won't
- * conflict with the migration workflow.
- *
- * We put in a marker here, that we'll use to determine
- * when the data has been transferred to the dst.
- */
- qtest_writeq(from, start_address + MAGIC_OFFSET, MAGIC_MARKER);
-}
-
-void migrate_wait_for_dirty_mem(QTestState *from, QTestState *to)
-{
- uint64_t watch_address = start_address + MAGIC_OFFSET_BASE;
- uint64_t marker_address = start_address + MAGIC_OFFSET;
- uint8_t watch_byte;
-
- /*
- * Wait for the MAGIC_MARKER to get transferred, as an
- * indicator that a migration pass has made some known
- * amount of progress.
- */
- do {
- usleep(1000 * 10);
- } while (qtest_readq(to, marker_address) != MAGIC_MARKER);
-
-
- /* If suspended, src only iterates once, and watch_byte may never change */
- if (src_state.suspend_me) {
- return;
- }
-
- /*
- * Now ensure that already transferred bytes are
- * dirty again from the guest workload. Note the
- * guest byte value will wrap around and by chance
- * match the original watch_byte. This is harmless
- * as we'll eventually see a different value if we
- * keep watching
- */
- watch_byte = qtest_readb(from, watch_address);
- do {
- usleep(1000 * 10);
- } while (qtest_readb(from, watch_address) == watch_byte);
-}
-
-static void check_guests_ram(QTestState *who)
-{
- /*
- * Our ASM test will have been incrementing one byte from each page from
- * start_address to < end_address in order. This gives us a constraint
- * that any page's byte should be equal or less than the previous pages
- * byte (mod 256); and they should all be equal except for one transition
- * at the point where we meet the incrementer. (We're running this with
- * the guest stopped).
- */
- unsigned address;
- uint8_t first_byte;
- uint8_t last_byte;
- bool hit_edge = false;
- int bad = 0;
-
- qtest_memread(who, start_address, &first_byte, 1);
- last_byte = first_byte;
-
- for (address = start_address + TEST_MEM_PAGE_SIZE; address < end_address;
- address += TEST_MEM_PAGE_SIZE)
- {
- uint8_t b;
- qtest_memread(who, address, &b, 1);
- if (b != last_byte) {
- if (((b + 1) % 256) == last_byte && !hit_edge) {
- /*
- * This is OK, the guest stopped at the point of
- * incrementing the previous page but didn't get
- * to us yet.
- */
- hit_edge = true;
- last_byte = b;
- } else {
- bad++;
- if (bad <= 10) {
- fprintf(stderr, "Memory content inconsistency at %x"
- " first_byte = %x last_byte = %x current = %x"
- " hit_edge = %x\n",
- address, first_byte, last_byte, b, hit_edge);
- }
- }
- }
- }
- if (bad >= 10) {
- fprintf(stderr, "and in another %d pages", bad - 10);
- }
- g_assert(bad == 0);
-}
-
static void cleanup(const char *filename)
{
g_autofree char *path = g_strdup_printf("%s/%s", tmpfs, filename);
@@ -319,60 +200,41 @@ int migrate_args(char **from, char **to, MigrateStart *args)
{
/* options for source and target */
g_autofree gchar *arch_opts = NULL;
+ g_autofree gchar *boot_opts = NULL;
gchar *cmd_source = NULL;
gchar *cmd_target = NULL;
const gchar *ignore_stderr;
g_autofree char *mem_object = NULL;
const char *kvm_opts = NULL;
const char *arch = qtest_get_arch();
- const char *memory_size;
+ g_autofree char *memory_size = NULL;
const char *machine_alias, *machine_opts = "";
g_autofree char *machine = NULL;
- const char *bootpath = bootfile_get();
g_autofree char *memory_backend = NULL;
const char *events;
+ boot_opts = bootfile_get_opts(arch, &memory_size);
+
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
- memory_size = "150M";
if (g_str_equal(arch, "i386")) {
machine_alias = "pc";
} else {
machine_alias = "q35";
}
- arch_opts = g_strdup_printf(
- "-drive if=none,id=d0,file=%s,format=raw "
- "-device ide-hd,drive=d0,secs=1,cyls=1,heads=1", bootpath);
- start_address = X86_TEST_MEM_START;
- end_address = X86_TEST_MEM_END;
} else if (g_str_equal(arch, "s390x")) {
- memory_size = "128M";
machine_alias = "s390-ccw-virtio";
- arch_opts = g_strdup_printf("-bios %s", bootpath);
- start_address = S390_TEST_MEM_START;
- end_address = S390_TEST_MEM_END;
} else if (strcmp(arch, "ppc64") == 0) {
- memory_size = "256M";
- start_address = PPC_TEST_MEM_START;
- end_address = PPC_TEST_MEM_END;
machine_alias = "pseries";
machine_opts = "vsmt=8";
arch_opts = g_strdup_printf(
- "-nodefaults -machine " PSERIES_DEFAULT_CAPABILITIES " "
- "-bios %s", bootpath);
+ "-nodefaults -machine " PSERIES_DEFAULT_CAPABILITIES);
} else if (strcmp(arch, "aarch64") == 0) {
- memory_size = "150M";
machine_alias = "virt";
machine_opts = "gic-version=3";
- arch_opts = g_strdup_printf("-cpu max -kernel %s", bootpath);
- start_address = ARM_TEST_MEM_START;
- end_address = ARM_TEST_MEM_END;
+ arch_opts = g_strdup_printf("-cpu max");
} else if (strcmp(arch, "loongarch64") == 0) {
- memory_size = "256M";
machine_alias = "virt";
- arch_opts = g_strdup_printf("-bios %s", bootpath);
- start_address = LOONGARCH_TEST_MEM_START;
- end_address = LOONGARCH_TEST_MEM_END;
} else {
g_assert_not_reached();
}
@@ -416,10 +278,11 @@ int migrate_args(char **from, char **to, 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,
+ boot_opts ? boot_opts : "",
arch_opts ? arch_opts : "",
args->opts_source ? args->opts_source : "",
ignore_stderr);
@@ -437,11 +300,12 @@ int migrate_args(char **from, char **to, MigrateStart *args)
"%s "
"-serial file:%s/dest_serial "
"-incoming defer "
- "%s %s %s %s",
+ "%s %s %s %s %s",
kvm_opts ? kvm_opts : "",
machine, machine_opts,
memory_backend, tmpfs,
events,
+ boot_opts ? boot_opts : "",
arch_opts ? arch_opts : "",
args->opts_target ? args->opts_target : "",
ignore_stderr);
@@ -584,28 +448,10 @@ int migrate_start(QTestState **from, QTestState **to, MigrateStart *args)
void migrate_end(QTestState *from, QTestState *to, bool test_dest)
{
- unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d;
-
qtest_quit(from);
if (test_dest) {
- qtest_memread(to, start_address, &dest_byte_a, 1);
-
- /* Destination still running, wait for a byte to change */
- do {
- qtest_memread(to, start_address, &dest_byte_b, 1);
- usleep(1000 * 10);
- } while (dest_byte_a == dest_byte_b);
-
- qtest_qmp_assert_success(to, "{ 'execute' : 'stop'}");
-
- /* With it stopped, check nothing changes */
- qtest_memread(to, start_address, &dest_byte_c, 1);
- usleep(1000 * 200);
- qtest_memread(to, start_address, &dest_byte_d, 1);
- g_assert_cmpint(dest_byte_c, ==, dest_byte_d);
-
- check_guests_ram(to);
+ migrate_check_guests_ram(to);
}
qtest_quit(to);
diff --git a/tests/qtest/migration/framework.h b/tests/qtest/migration/framework.h
index 10761f6e287..df25d2a5830 100644
--- a/tests/qtest/migration/framework.h
+++ b/tests/qtest/migration/framework.h
@@ -230,8 +230,6 @@ typedef struct {
} MigrateCommon;
void wait_for_serial(const char *side);
-void migrate_prepare_for_dirty_mem(QTestState *from);
-void migrate_wait_for_dirty_mem(QTestState *from, QTestState *to);
int migrate_args(char **from, char **to, MigrateStart *args);
int migrate_start(QTestState **from, QTestState **to, MigrateStart *args);
diff --git a/tests/qtest/migration/misc-tests.c b/tests/qtest/migration/misc-tests.c
index 4e0deb7f188..370062db2a7 100644
--- a/tests/qtest/migration/misc-tests.c
+++ b/tests/qtest/migration/misc-tests.c
@@ -14,6 +14,7 @@
#include "qapi/error.h"
#include "qobject/qjson.h"
#include "libqtest.h"
+#include "migration/bootfile.h"
#include "migration/framework.h"
#include "migration/migration-qmp.h"
#include "migration/migration-util.h"
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 4/5] tests/qtest/migration: Adapt wait_for_serial routine for stress.c
2026-11-26 21:46 [PATCH 0/5] migration-test: Support running a real kernel Fabiano Rosas
` (2 preceding siblings ...)
2026-11-26 21:47 ` [PATCH 3/5] tests/qtest/migration: Move guest workload code into bootfile.c Fabiano Rosas
@ 2026-11-26 21:47 ` Fabiano Rosas
2026-11-26 21:47 ` [PATCH 5/5] tests/qtest/migration: Make it possible to run stress.c Fabiano Rosas
2026-11-27 13:45 ` [PATCH 0/5] migration-test: Support running a real kernel Peter Xu
5 siblings, 0 replies; 12+ messages in thread
From: Fabiano Rosas @ 2026-11-26 21:47 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Xu, Laurent Vivier, Paolo Bonzini
The wait_for_serial routine currently only supports matching against
the A-B workload, i.e. it only accepts the 'A' character and the 'B'
character.
In preparation for adding tests/migration-stress/stress.c as an
alternative guest workload for migration-test, change
wait_for_serial() to check for the strings produced by stress.c. Also
check for output from a Linux kernel such as panics and allow running
without 'quiet', for debugging.
No change intended for the default workload.
Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
tests/qtest/migration/framework.c | 90 +++++++++++++++++++++++--------
1 file changed, 69 insertions(+), 21 deletions(-)
diff --git a/tests/qtest/migration/framework.c b/tests/qtest/migration/framework.c
index a081c8e7bb9..3bfa59a0fd5 100644
--- a/tests/qtest/migration/framework.c
+++ b/tests/qtest/migration/framework.c
@@ -41,38 +41,86 @@ static QTestMigrationState dst_state;
static char *tmpfs;
/*
- * Wait for some output in the serial output file,
- * we get an 'A' followed by an endless string of 'B's
- * but on the destination we won't have the A (unless we enabled suspend/resume)
+ * Wait for some output in the serial output file, we get a so called
+ * "A" pattern followed by a endless string of the so called "B"
+ * pattern. On the destination we won't have the A (unless we enabled
+ * suspend/resume). Depending on the guest code being used, the
+ * patterns are different:
+ *
+ * For bootfile.c:
+ * A='A'
+ * B='B'
+ *
+ * For stress.c:
+ * A="/init (<tid>): INFO: RAM # GiB across # CPUs"
+ * B="/init (<tid>): INFO: #ms copied # GB in #ms"
*/
void wait_for_serial(const char *side)
{
g_autofree char *serialpath = g_strdup_printf("%s/%s", tmpfs, side);
FILE *serialfile = fopen(serialpath, "r");
+ char buf[128];
+ int i = 0;
+ const char *a_b[] = { "AB", "ABB", "ABBB", "B", "BB", "BBB", "BBBB" };
+ const char *stress[] = { "/init (", ": INFO: RAM" };
+ const char *skip[] = { "[", "]" };
+ const char *bad[] = { "panic+", "Code:", "BUG:" };
- do {
- int readvalue = fgetc(serialfile);
+ for (;;) {
- switch (readvalue) {
- case 'A':
- /* Fine */
- break;
+ if (!fgets(buf, 128, serialfile)) {
+ int c = fgetc(serialfile);
- case 'B':
- /* It's alive! */
- fclose(serialfile);
- return;
+ if (c == EOF) {
+ usleep(1000);
+ fseek(serialfile, 0, SEEK_SET);
+ continue;
+ }
+ }
+
+ /* look for the main patterns */
+ i = 0;
+ while (i < ARRAY_SIZE(a_b)) {
+ if (g_str_equal(buf, a_b[i++])) {
+ goto found;
+ }
+ }
+
+ i = 0;
+ while (i < ARRAY_SIZE(stress)) {
+ if (strstr(buf, stress[i++])) {
+ goto found;
+ }
+ }
- case EOF:
- fseek(serialfile, 0, SEEK_SET);
- usleep(1000);
- break;
+ /*
+ * Look for the stress.c patterns: dmesg lines when 'quiet' is
+ * not used in the kernel cmdline or kernel panic messages.
+ */
- default:
- fprintf(stderr, "Unexpected %d on %s serial\n", readvalue, side);
- g_assert_not_reached();
+ i = 0;
+ while (i < ARRAY_SIZE(bad)) {
+ if (strstr(buf, bad[i++])) {
+ goto err;
+ }
}
- } while (true);
+
+ i = 0;
+ while (i < ARRAY_SIZE(skip)) {
+ if (strstr(buf, skip[i++])) {
+ break;
+ }
+ }
+ usleep(1000);
+ }
+
+err:
+ fprintf(stderr, "Unexpected string on %s: %s\n", side, buf);
+ fclose(serialfile);
+ g_assert_not_reached();
+
+found:
+ fclose(serialfile);
}
static void cleanup(const char *filename)
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 5/5] tests/qtest/migration: Make it possible to run stress.c
2026-11-26 21:46 [PATCH 0/5] migration-test: Support running a real kernel Fabiano Rosas
` (3 preceding siblings ...)
2026-11-26 21:47 ` [PATCH 4/5] tests/qtest/migration: Adapt wait_for_serial routine for stress.c Fabiano Rosas
@ 2026-11-26 21:47 ` Fabiano Rosas
2026-11-27 13:45 ` [PATCH 0/5] migration-test: Support running a real kernel Peter Xu
5 siblings, 0 replies; 12+ messages in thread
From: Fabiano Rosas @ 2026-11-26 21:47 UTC (permalink / raw)
To: qemu-devel
Cc: Peter Xu, Laurent Vivier, Paolo Bonzini, Maciej S. Szmigiero,
Mark Kanda, Ben Chaney
Allow the code from tests/migration-stress/stress.c to be executed as
a guest workload for migration-test.
So far, the only workload that runs for all qtest migration-tests is a
loop over the guest memory that increments a byte on each page. It's
tailored to detect memory corruption and is specially useful for
testing ram migration.
The guestperf.py script uses another workload, stress.c, which is
similarly a loop that touches all memory pages. While still
artificial, the stress workload runs as an initrd paired with an
actual Linux kernel and could be more useful for detecting migration
issues in areas other than ram migration.
Add support for running stress.c in migration-test. Introduce the
environment variable QTEST_MIG_KERNEL to inform the kernel to be used
(guestperf takes the kernel from the running host). Change
bootfile_get_opts() to setup -kernel and -initrd.
The memory size for the guest is kept the same as guestperf.py: 1GB.
Since stress.c touches all memory that's provided to it, some extra
space needs to be allocated for the kernel use. (I tried to be precise
with this but could not reach the exact computation for the extra
space, so 300M is being added to avoid OOM.)
At bootfile_create(), either bootpath will be set, meaning the A-B
workload is to be used, or if the user set the new environment
variables, then kernel_path/initrd_path will be set. The rest of the
code tests boopath to know which workload is in use.
Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
Note: hugepages are not yet supported in the tests, this is coming in
a separate series. Depending on how it goes I can remove the HUGETLB
parts from this patch.
---
tests/qtest/migration/bootfile.c | 189 ++++++++++++++++++++++++-
tests/qtest/migration/bootfile.h | 5 +-
tests/qtest/migration/cpr-tests.c | 52 ++++++-
tests/qtest/migration/framework.c | 11 +-
tests/qtest/migration/framework.h | 2 +
tests/qtest/migration/postcopy-tests.c | 6 +-
tests/qtest/migration/precopy-tests.c | 19 ++-
7 files changed, 272 insertions(+), 12 deletions(-)
diff --git a/tests/qtest/migration/bootfile.c b/tests/qtest/migration/bootfile.c
index d40bd0c2d3e..2d14931c5fb 100644
--- a/tests/qtest/migration/bootfile.c
+++ b/tests/qtest/migration/bootfile.c
@@ -13,6 +13,7 @@
#include "qemu/osdep.h"
#include "framework.h"
#include "migration-util.h"
+#include "qemu/cutils.h"
/*
* The boot file modifies memory area in [start_address, end_address)
@@ -29,6 +30,8 @@ unsigned start_address;
unsigned end_address;
static char *bootpath;
+static char *kernelpath;
+static char *initrdpath;
void bootfile_delete(void)
{
@@ -38,14 +41,30 @@ void bootfile_delete(void)
unlink(bootpath);
g_free(bootpath);
bootpath = NULL;
+
+ g_free(kernelpath);
+ kernelpath = NULL;
+
+ g_free(initrdpath);
+ initrdpath = NULL;
}
-char *bootfile_create(const char *arch, const char *dir, bool suspend_me)
+char *bootfile_create(const char *arch, const char *kernel,
+ const char *dir, bool suspend_me)
{
unsigned char *content;
size_t len;
bootfile_delete();
+
+ if (kernel) {
+ kernelpath = g_strdup(kernel);
+ initrdpath = g_strdup("tests/migration-stress/initrd-stress.img");
+
+ g_test_message("Using guest workload \"stress.c\"");
+ return NULL;
+ }
+
bootpath = g_strdup_printf("%s/bootsect", dir);
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
/* the assembled x86 boot sector should be exactly one sector large */
@@ -85,14 +104,168 @@ char *bootfile_create(const char *arch, const char *dir, bool suspend_me)
g_assert_cmpint(fwrite(content, len, 1, bootfile), ==, 1);
fclose(bootfile);
+ g_test_message("Using guest workload \"A-B\"");
+
return bootpath;
}
-char *bootfile_get_opts(const char *arch, char **mem_size)
+/* assumes guest uses 4k */
+static uint64_t pgtables_size(long size_gb)
+{
+ uint64_t pgtb_size = 0, size_b = size_gb << 30;
+ uint64_t n_pages, ptrs_per_lvl;
+
+ n_pages = size_b >> 12;
+
+ ptrs_per_lvl = n_pages >> 21;
+ pgtb_size += ptrs_per_lvl ?: 1;
+
+ ptrs_per_lvl >>= 30;
+ pgtb_size += ptrs_per_lvl ?: 1;
+
+ ptrs_per_lvl >>= 39;
+ pgtb_size += ptrs_per_lvl ?: 1;
+
+ ptrs_per_lvl >>= 48;
+ pgtb_size += ptrs_per_lvl ?: 1;
+
+ pgtb_size <<= 12;
+
+ size_b += pgtb_size;
+ return size_b;
+}
+
+static uint64_t rsvd_size(long size_gb)
+{
+ uint64_t size_b;
+
+ /*
+ * 300M for kernel text, bss, percpu areas, etc. Rough
+ * approximation from what's reported in dmesg: "Memory:
+ * 2110788K/3145208K available (16384K kernel code, 2951K rwdata,
+ * 12716K rodata, 4088K init, 4672K bss, 177440K reserved, 0K
+ * cma-reserved)"
+ */
+ size_b = (300UL << 20);
+
+ size_b += pgtables_size(size_gb);
+
+ /* FIXME: init keeps being killed due to OOM, add an arbitrary 1/8 */
+ size_b += size_b >> 3;
+
+ return size_b;
+}
+
+/*
+ * Build the kernel command line options string to be passed to QEMU's
+ * -append option. Allow a few of the more useful kernel command line
+ * options to be replaced by the user setting the QTEST_MIG_APPEND
+ * environment variable. A few options are required and will be added
+ * automatically if not present on the user-provided string.
+ *
+ * Returns:
+ * default options + required options + user options
+ */
+static char *build_append_str(long ramsize, long cpus)
+{
+ bool add_ramsize, add_cpus, add_quiet;
+ const char *user_opts = getenv("QTEST_MIG_APPEND");
+ const char *default_opts = "noapic printk.time=1 noreplace-smp "
+ "cgroup_disable=memory pci=noearly console=ttyS0";
+ g_autofree char *required_opts = NULL;
+ g_autofree char *r1 = NULL;
+ g_autofree char *r2 = NULL;
+ g_autofree char *r3 = NULL;
+
+ if (user_opts) {
+ add_ramsize = !strstr(user_opts, "ramsize=");
+ add_cpus = !strstr(user_opts, "cpus=");
+ /* let them remove 'quiet' by omitting it from the env var */
+ add_quiet = false;
+ } else {
+ add_ramsize = add_cpus = add_quiet = true;
+ }
+
+ if (add_quiet) {
+ r1 = g_strdup("quiet ");
+ }
+
+ if (add_ramsize) {
+ r2 = g_strdup_printf("ramsize=%ld ", ramsize);
+ }
+
+ if (add_cpus) {
+ r3 = g_strdup_printf("cpus=%ld ", cpus);
+ }
+
+ required_opts = g_strconcat(r1 ?: "", r2 ?: "", r3 ?: "", NULL);
+
+ return g_strconcat(default_opts, required_opts, user_opts, NULL);
+}
+
+static char *bootfile_get_kernel_opts(const char *arch, int mem_type,
+ char **size_mb_str)
+{
+ const char *size_gb_str;
+ const char *smp;
+ long size_gb, n_vcpus;
+ uint64_t size_b;
+
+ assert(g_str_equal(arch, "x86_64"));
+ assert(kernelpath);
+ assert(initrdpath);
+
+ /*
+ * The default is 1GB / 1vcpu guest, but it can be overridden via
+ * env variables.
+ */
+ size_gb_str = getenv("QTEST_MIG_MEM_G");
+ smp = getenv("QTEST_MIG_SMP");
+
+ if (!smp) {
+ smp = "1";
+ }
+
+ if (!size_gb_str) {
+ size_gb_str = "1";
+ }
+
+ assert(!qemu_strtol(smp, NULL, 0, &n_vcpus));
+ assert(n_vcpus > 0 && n_vcpus <= 4096);
+
+ assert(!qemu_strtol(size_gb_str, NULL, 0, &size_gb));
+ assert(size_gb > 0 && size_gb <= 256000);
+
+ /*
+ * stress.c dirties all of "ramsize", increase the memory size to
+ * avoid OOM.
+ */
+ size_b = rsvd_size(size_gb);
+
+ /* Align to the next MB to not lose the fractional bytes. */
+ size_b = QEMU_ALIGN_UP(size_b, 1UL << 20);
+
+ if (mem_type == MEM_TYPE_HUGETLB) {
+ size_b = QEMU_ALIGN_UP(size_b, 1UL << 30);
+ }
+
+ *size_mb_str = g_strdup_printf("%ldM", size_b >> 20);
+
+ return g_strdup_printf(
+ "-smp %s -kernel %s -initrd %s -cpu host "
+ "-append '%s' ", smp, kernelpath, initrdpath,
+ build_append_str(size_gb, n_vcpus));
+}
+
+char *bootfile_get_opts(const char *arch, int mem_type, char **mem_size)
{
const char *memory_size;
char *boot;
+ if (!bootpath) {
+ return bootfile_get_kernel_opts(arch, mem_type, mem_size);
+ }
+
if (g_str_equal(arch, "i386") || g_str_equal(arch, "x86_64")) {
memory_size = "150M";
boot = g_strdup_printf(
@@ -128,6 +301,10 @@ void migrate_wait_for_dirty_mem(QTestState *from, QTestState *to)
uint64_t marker_address = start_address + MAGIC_OFFSET;
uint8_t watch_byte;
+ if (!bootpath) {
+ return;
+ }
+
/*
* Wait for the MAGIC_MARKER to get transferred, as an
* indicator that a migration pass has made some known
@@ -158,6 +335,10 @@ void migrate_wait_for_dirty_mem(QTestState *from, QTestState *to)
void migrate_prepare_for_dirty_mem(QTestState *from)
{
+ if (!bootpath) {
+ return;
+ }
+
/*
* The guest workflow iterates from start_address to
* end_address, writing 1 byte every TEST_MEM_PAGE_SIZE
@@ -190,6 +371,10 @@ void migrate_check_guests_ram(QTestState *who)
int bad = 0;
unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d;
+ if (!bootpath) {
+ return;
+ }
+
qtest_memread(who, start_address, &dest_byte_a, 1);
/* Destination still running, wait for a byte to change */
diff --git a/tests/qtest/migration/bootfile.h b/tests/qtest/migration/bootfile.h
index 4f628160f5d..a66105bc4a1 100644
--- a/tests/qtest/migration/bootfile.h
+++ b/tests/qtest/migration/bootfile.h
@@ -64,9 +64,10 @@
#ifndef MIGRATION_GUEST_CODE
void bootfile_delete(void);
-char *bootfile_create(const char *arch, const char *dir, bool suspend_me);
+char *bootfile_create(const char *arch, const char *kernel,
+ const char *dir, bool suspend_me);
char *bootfile_get(void);
-char *bootfile_get_opts(const char *arch, char **memory_size);
+char *bootfile_get_opts(const char *arch, int mem_type, char **memory_size);
void migrate_prepare_for_dirty_mem(QTestState *from);
void migrate_wait_for_dirty_mem(QTestState *from, QTestState *to);
void migrate_check_guests_ram(QTestState *who);
diff --git a/tests/qtest/migration/cpr-tests.c b/tests/qtest/migration/cpr-tests.c
index 3c21b79001e..d4a50e8e564 100644
--- a/tests/qtest/migration/cpr-tests.c
+++ b/tests/qtest/migration/cpr-tests.c
@@ -172,6 +172,34 @@ static void test_mode_transfer_defer(char *name, MigrateCommon *args)
test_mode_transfer_common(args, true, NULL);
}
+static GStrv strv_concat(char **a, char **b, char **c, int max_len)
+{
+ /*
+ * We don't support g_strv_builder, so do a hacky pointer
+ * arithmetic. The arr only holds the pointers, the g_strdupv
+ * at the end is a deep copy.
+ */
+ g_autofree char **arr = g_new0(char *, max_len);
+ char **srcp, **dstp = arr;
+
+ /* +1 to skip the last element which is "" */
+ srcp = a;
+ while (*(srcp + 1)) {
+ *dstp++ = *srcp++;
+ }
+
+ *dstp++ = *b;
+
+ /* +1 to skip the first element which is "" */
+ srcp = c + 1;
+ while (*srcp) {
+ *dstp++ = *srcp++;
+ }
+
+ *dstp = NULL;
+ return (GStrv)g_strdupv(arr);
+}
+
static void set_cpr_exec_args(QTestState *who, MigrateCommon *args)
{
g_autofree char *qtest_from_args = NULL;
@@ -209,8 +237,30 @@ static void set_cpr_exec_args(QTestState *who, MigrateCommon *args)
exec_args = g_strconcat(qtest_qemu_binary(migration_get_env()->qemu_dst),
" -incoming defer ", from_str, NULL);
+
argv = g_strsplit(exec_args, " ", -1);
- migrate_set_parameter_strv(who, "cpr-exec-command", argv);
+
+ /*
+ * Handle the -append qemu option. QMP does the right thing if we
+ * pass it all the kernel options as a single string, no quotes.
+ */
+ if (strstr(exec_args, " -append ")) {
+ g_auto(GStrv) tmp = NULL;
+ g_auto(GStrv) head = NULL;
+ g_auto(GStrv) tail = NULL;
+ g_auto(GStrv) local_argv;
+ int max_len = g_strv_length(argv);
+
+ tmp = g_strsplit(exec_args, "'", -1);
+
+ head = g_strsplit(tmp[0], " ", -1);
+ tail = g_strsplit(tmp[2], " ", -1);
+
+ local_argv = strv_concat(head, &tmp[1], tail, max_len);
+ migrate_set_parameter_strv(who, "cpr-exec-command", local_argv);
+ } else {
+ migrate_set_parameter_strv(who, "cpr-exec-command", argv);
+ }
}
static void wait_for_migration_event(QTestState *who, const char *waitfor)
diff --git a/tests/qtest/migration/framework.c b/tests/qtest/migration/framework.c
index 3bfa59a0fd5..2839217c94d 100644
--- a/tests/qtest/migration/framework.c
+++ b/tests/qtest/migration/framework.c
@@ -261,7 +261,7 @@ int migrate_args(char **from, char **to, MigrateStart *args)
g_autofree char *memory_backend = NULL;
const char *events;
- boot_opts = bootfile_get_opts(arch, &memory_size);
+ boot_opts = bootfile_get_opts(arch, args->mem_type, &memory_size);
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
@@ -454,6 +454,7 @@ static void migrate_mem_type_cleanup(MemType type)
int migrate_start(QTestState **from, QTestState **to, MigrateStart *args)
{
+ MigrationTestEnv *env = migration_get_env();
g_autofree gchar *cmd_source = NULL;
g_autofree gchar *cmd_target = NULL;
g_autoptr(QList) capabilities = migrate_start_get_qmp_capabilities(args);
@@ -464,7 +465,7 @@ int migrate_start(QTestState **from, QTestState **to, MigrateStart *args)
dst_state = (QTestMigrationState) { };
src_state = (QTestMigrationState) { };
- bootfile_create(qtest_get_arch(), tmpfs, args->suspend_me);
+ bootfile_create(qtest_get_arch(), env->kernel, tmpfs, args->suspend_me);
src_state.suspend_me = args->suspend_me;
if (migrate_args(&cmd_source, &cmd_target, args)) {
@@ -1063,6 +1064,12 @@ MigrationTestEnv *migration_get_env(void)
env->arch = qtest_get_arch();
env->is_x86 = !strcmp(env->arch, "i386") || !strcmp(env->arch, "x86_64");
+ env->kernel = getenv("QTEST_MIG_KERNEL");
+ if (env->kernel && !g_str_equal(env->arch, "x86_64")) {
+ g_test_message("Kernel option only supported on x86_64");
+ exit(1);
+ }
+
env->tmpfs = g_dir_make_tmp("migration-test-XXXXXX", &err);
if (!env->tmpfs) {
g_test_message("Can't create temporary directory in %s: %s",
diff --git a/tests/qtest/migration/framework.h b/tests/qtest/migration/framework.h
index df25d2a5830..06abd241d4a 100644
--- a/tests/qtest/migration/framework.h
+++ b/tests/qtest/migration/framework.h
@@ -38,6 +38,7 @@ typedef enum {
* Use guest-memfd, shared mappings.
*/
MEM_TYPE_GUEST_MEMFD,
+ MEM_TYPE_HUGETLB,
MEM_TYPE_NUM,
} MemType;
@@ -53,6 +54,7 @@ typedef struct MigrationTestEnv {
const char *arch;
const char *qemu_src;
const char *qemu_dst;
+ const char *kernel;
char *tmpfs;
} MigrationTestEnv;
diff --git a/tests/qtest/migration/postcopy-tests.c b/tests/qtest/migration/postcopy-tests.c
index 6c4fd311529..672dc8b247b 100644
--- a/tests/qtest/migration/postcopy-tests.c
+++ b/tests/qtest/migration/postcopy-tests.c
@@ -124,7 +124,11 @@ void migration_test_add_postcopy(MigrationTestEnv *env)
test_multifd_postcopy_preempt);
migration_test_add("/migration/multifd+postcopy/preempt/recovery/plain",
test_multifd_postcopy_preempt_recovery);
- if (env->is_x86) {
+ /*
+ * TODO: The suspend test writes to the guest memory. That's not yet
+ * supported with a full kernel inside the guest.
+ */
+ if (env->is_x86 && !env->kernel) {
migration_test_add("/migration/postcopy/suspend",
test_postcopy_suspend);
}
diff --git a/tests/qtest/migration/precopy-tests.c b/tests/qtest/migration/precopy-tests.c
index d57ffcac234..28b1476e9ae 100644
--- a/tests/qtest/migration/precopy-tests.c
+++ b/tests/qtest/migration/precopy-tests.c
@@ -805,7 +805,7 @@ static QTestState *dirtylimit_start_vm(void)
g_autofree gchar *cmd = NULL;
const char *bootpath;
- bootpath = bootfile_create(qtest_get_arch(), tmpfs, false);
+ bootpath = bootfile_create(qtest_get_arch(), NULL, tmpfs, false);
cmd = g_strdup_printf("-accel kvm,dirty-ring-size=4096 "
"-name dirtylimit-test,debug-threads=on "
"-m 150M -smp 1 "
@@ -1077,7 +1077,11 @@ static void test_dirty_limit(char *name, MigrateCommon *args)
static void migration_test_add_precopy_smoke(MigrationTestEnv *env)
{
- if (env->is_x86) {
+ /*
+ * TODO: The suspend test writes to the guest memory. That's not yet
+ * supported with a full kernel inside the guest.
+ */
+ if (env->is_x86 && !env->kernel) {
migration_test_add("/migration/precopy/unix/suspend/live",
test_precopy_unix_suspend_live);
migration_test_add("/migration/precopy/unix/suspend/notlive",
@@ -1093,8 +1097,15 @@ static void migration_test_add_precopy_smoke(MigrationTestEnv *env)
migration_test_add("/migration/multifd/tcp/plain/cancel",
test_multifd_precopy_tcp_cancel);
if (env->has_uffd) {
- migration_test_add("/migration/multifd+postcopy/tcp/plain/cancel",
- test_multifd_postcopy_tcp_cancel);
+ /*
+ * FIXME: Using a kernel requires disabling the dirty memory
+ * detection and shortens a race window which breaks this
+ * test. Skip it until the fix is merged.
+ */
+ if (!env->kernel) {
+ migration_test_add("/migration/multifd+postcopy/tcp/plain/cancel",
+ test_multifd_postcopy_tcp_cancel);
+ }
}
#ifdef CONFIG_RDMA
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 0/5] migration-test: Support running a real kernel
2026-11-26 21:46 [PATCH 0/5] migration-test: Support running a real kernel Fabiano Rosas
` (4 preceding siblings ...)
2026-11-26 21:47 ` [PATCH 5/5] tests/qtest/migration: Make it possible to run stress.c Fabiano Rosas
@ 2026-11-27 13:45 ` Peter Xu
2026-11-27 14:01 ` Daniel P. Berrangé
5 siblings, 1 reply; 12+ messages in thread
From: Peter Xu @ 2026-11-27 13:45 UTC (permalink / raw)
To: Fabiano Rosas; +Cc: qemu-devel
On Thu, Nov 26, 2026 at 06:46:59PM -0300, Fabiano Rosas wrote:
> There's a class of migration performance bugs that are very specific
> to the internals of QEMU and most likely require work on our side, but
> are currently invisible to our testing because migration-test runs a
> simple guest workload (not even that, really). The more important ones
> are BQL contention issues that result in vcpu starvation.
>
> My plan is to incrementally add some pieces to migration-test to
> reduce that testing gap.
>
> The first piece is adding support for running a kernel + initrd inside
> the guest which gives us an easy way to start exercising migration of
> a more loaded guest that can already cause VM exits.
>
> This series adds support for -kernel and -initrd arguments to
> migration-test and runs the same set of tests we currently have, but
> with the kernel instead of the custom loop. By default it uses the
> initrd from tests/migration-stress/ which runs a read-write loop over
> all memory and has customizable vcpu and memory size.
The whole thing sounds useful, I'll read into details after I flush more of
the older patches.. which will take some time (it also depends on if next
week I got some more urgent task "injected"..).
One high level question: this will grow qtest closer to what the functional
test is doing. Have you thought of the relationship between the two, after
we move qtest more over there? I assumed not, based on what you mentioned
in the rest part of cover letter that you planned to have it only for dev
debug purpose. But still, we'll start to ask the question to ourselves at
some point, IIUC. So I ask first. :)
--
Peter Xu
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH 0/5] migration-test: Support running a real kernel
2026-11-27 13:45 ` [PATCH 0/5] migration-test: Support running a real kernel Peter Xu
@ 2026-11-27 14:01 ` Daniel P. Berrangé
2026-11-27 15:01 ` Peter Xu
2026-11-27 15:18 ` Fabiano Rosas
0 siblings, 2 replies; 12+ messages in thread
From: Daniel P. Berrangé @ 2026-11-27 14:01 UTC (permalink / raw)
To: Peter Xu; +Cc: Fabiano Rosas, qemu-devel
On Fri, Nov 27, 2026 at 08:45:04AM -0500, Peter Xu wrote:
> On Thu, Nov 26, 2026 at 06:46:59PM -0300, Fabiano Rosas wrote:
> > There's a class of migration performance bugs that are very specific
> > to the internals of QEMU and most likely require work on our side, but
> > are currently invisible to our testing because migration-test runs a
> > simple guest workload (not even that, really). The more important ones
> > are BQL contention issues that result in vcpu starvation.
> >
> > My plan is to incrementally add some pieces to migration-test to
> > reduce that testing gap.
> >
> > The first piece is adding support for running a kernel + initrd inside
> > the guest which gives us an easy way to start exercising migration of
> > a more loaded guest that can already cause VM exits.
> >
> > This series adds support for -kernel and -initrd arguments to
> > migration-test and runs the same set of tests we currently have, but
> > with the kernel instead of the custom loop. By default it uses the
> > initrd from tests/migration-stress/ which runs a read-write loop over
> > all memory and has customizable vcpu and memory size.
>
> The whole thing sounds useful, I'll read into details after I flush more of
> the older patches.. which will take some time (it also depends on if next
> week I got some more urgent task "injected"..).
>
> One high level question: this will grow qtest closer to what the functional
> test is doing. Have you thought of the relationship between the two, after
> we move qtest more over there? I assumed not, based on what you mentioned
> in the rest part of cover letter that you planned to have it only for dev
> debug purpose. But still, we'll start to ask the question to ourselves at
> some point, IIUC. So I ask first. :)
In terms of the boundary between functional tests and qtests, I
think the guidance is in the names.
If it is a "qtest" test then it should be primarily making use
of QTest to interrogate the QEMU internalprocess state.
If it is a "functional" test, then it is interested in running
real kernels & real accelerators and validating the behaviour of
QEMU via its external mgmt interfaces.
By this definition, IMHO, the migration-test would be a functional
test, if it were created from scratch to.
It only uses libqtest.h APIs for the purpose of sending QMP
commands, not examining internal device state. Essentially it is a
historical accident that it is written as a qtest instead of a
functional test, as that was the best choice at the time.
With regards,
Daniel
--
|: https://berrange.com ~~ https://hachyderm.io/@berrange :|
|: https://libvirt.org ~~ https://entangle-photo.org :|
|: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/5] migration-test: Support running a real kernel
2026-11-27 14:01 ` Daniel P. Berrangé
@ 2026-11-27 15:01 ` Peter Xu
2026-11-27 19:15 ` Fabiano Rosas
2026-11-27 15:18 ` Fabiano Rosas
1 sibling, 1 reply; 12+ messages in thread
From: Peter Xu @ 2026-11-27 15:01 UTC (permalink / raw)
To: Daniel P. Berrangé; +Cc: Fabiano Rosas, qemu-devel
On Fri, Nov 27, 2026 at 02:01:13PM +0000, Daniel P. Berrangé wrote:
> On Fri, Nov 27, 2026 at 08:45:04AM -0500, Peter Xu wrote:
> > On Thu, Nov 26, 2026 at 06:46:59PM -0300, Fabiano Rosas wrote:
> > > There's a class of migration performance bugs that are very specific
> > > to the internals of QEMU and most likely require work on our side, but
> > > are currently invisible to our testing because migration-test runs a
> > > simple guest workload (not even that, really). The more important ones
> > > are BQL contention issues that result in vcpu starvation.
> > >
> > > My plan is to incrementally add some pieces to migration-test to
> > > reduce that testing gap.
> > >
> > > The first piece is adding support for running a kernel + initrd inside
> > > the guest which gives us an easy way to start exercising migration of
> > > a more loaded guest that can already cause VM exits.
> > >
> > > This series adds support for -kernel and -initrd arguments to
> > > migration-test and runs the same set of tests we currently have, but
> > > with the kernel instead of the custom loop. By default it uses the
> > > initrd from tests/migration-stress/ which runs a read-write loop over
> > > all memory and has customizable vcpu and memory size.
> >
> > The whole thing sounds useful, I'll read into details after I flush more of
> > the older patches.. which will take some time (it also depends on if next
> > week I got some more urgent task "injected"..).
> >
> > One high level question: this will grow qtest closer to what the functional
> > test is doing. Have you thought of the relationship between the two, after
> > we move qtest more over there? I assumed not, based on what you mentioned
> > in the rest part of cover letter that you planned to have it only for dev
> > debug purpose. But still, we'll start to ask the question to ourselves at
> > some point, IIUC. So I ask first. :)
>
> In terms of the boundary between functional tests and qtests, I
> think the guidance is in the names.
>
> If it is a "qtest" test then it should be primarily making use
> of QTest to interrogate the QEMU internalprocess state.
>
> If it is a "functional" test, then it is interested in running
> real kernels & real accelerators and validating the behaviour of
> QEMU via its external mgmt interfaces.
>
> By this definition, IMHO, the migration-test would be a functional
> test, if it were created from scratch to.
True.
>
> It only uses libqtest.h APIs for the purpose of sending QMP
> commands, not examining internal device state. Essentially it is a
> historical accident that it is written as a qtest instead of a
> functional test, as that was the best choice at the time.
Yes, I didn't try to measure functional tests, but I think qtest is good
choice even for now being very fast.
Then the question is similar, where we will have two functional tests for
migration, and we'll at some point think about what we do when they start
to overlap (perhaps, already).
--
Peter Xu
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/5] migration-test: Support running a real kernel
2026-11-27 15:01 ` Peter Xu
@ 2026-11-27 19:15 ` Fabiano Rosas
0 siblings, 0 replies; 12+ messages in thread
From: Fabiano Rosas @ 2026-11-27 19:15 UTC (permalink / raw)
To: Peter Xu, Daniel P. Berrangé; +Cc: qemu-devel
Peter Xu <peterx@redhat.com> writes:
> On Fri, Nov 27, 2026 at 02:01:13PM +0000, Daniel P. Berrangé wrote:
>> On Fri, Nov 27, 2026 at 08:45:04AM -0500, Peter Xu wrote:
>> > On Thu, Nov 26, 2026 at 06:46:59PM -0300, Fabiano Rosas wrote:
>> > > There's a class of migration performance bugs that are very specific
>> > > to the internals of QEMU and most likely require work on our side, but
>> > > are currently invisible to our testing because migration-test runs a
>> > > simple guest workload (not even that, really). The more important ones
>> > > are BQL contention issues that result in vcpu starvation.
>> > >
>> > > My plan is to incrementally add some pieces to migration-test to
>> > > reduce that testing gap.
>> > >
>> > > The first piece is adding support for running a kernel + initrd inside
>> > > the guest which gives us an easy way to start exercising migration of
>> > > a more loaded guest that can already cause VM exits.
>> > >
>> > > This series adds support for -kernel and -initrd arguments to
>> > > migration-test and runs the same set of tests we currently have, but
>> > > with the kernel instead of the custom loop. By default it uses the
>> > > initrd from tests/migration-stress/ which runs a read-write loop over
>> > > all memory and has customizable vcpu and memory size.
>> >
>> > The whole thing sounds useful, I'll read into details after I flush more of
>> > the older patches.. which will take some time (it also depends on if next
>> > week I got some more urgent task "injected"..).
>> >
>> > One high level question: this will grow qtest closer to what the functional
>> > test is doing. Have you thought of the relationship between the two, after
>> > we move qtest more over there? I assumed not, based on what you mentioned
>> > in the rest part of cover letter that you planned to have it only for dev
>> > debug purpose. But still, we'll start to ask the question to ourselves at
>> > some point, IIUC. So I ask first. :)
>>
>> In terms of the boundary between functional tests and qtests, I
>> think the guidance is in the names.
>>
>> If it is a "qtest" test then it should be primarily making use
>> of QTest to interrogate the QEMU internalprocess state.
>>
>> If it is a "functional" test, then it is interested in running
>> real kernels & real accelerators and validating the behaviour of
>> QEMU via its external mgmt interfaces.
>>
>> By this definition, IMHO, the migration-test would be a functional
>> test, if it were created from scratch to.
>
> True.
>
>>
>> It only uses libqtest.h APIs for the purpose of sending QMP
>> commands, not examining internal device state. Essentially it is a
>> historical accident that it is written as a qtest instead of a
>> functional test, as that was the best choice at the time.
>
> Yes, I didn't try to measure functional tests, but I think qtest is good
> choice even for now being very fast.
>
Come on, it's a good choice because it exists. Look at the amount of
stuff we test in migration-test.c.
> Then the question is similar, where we will have two functional tests for
> migration, and we'll at some point think about what we do when they start
> to overlap (perhaps, already).
We could have avoided putting ourselves in this situation if we had
agreed upfront on what the plan would be. We had 3 or 4 useless tests in
avocado that could have just been dropped back then and now we'd have
only one test-suite for migration functional testing. People insisted
anyway and now: ooops, duplicated effort! =)
Unfortunately, I get the short end of the stick because instead of
implementing some custom solution downstream I decided to use the
upstream code for my testing.
Do we want to centralize on the python code? Let's decide one way or
another. I promise I won't complain after the fact.
- We could freeze migration-test.c now and declare new tests go to
either qos, functional or unit only.
- Or keep migration-test.c as a suite for testing subsystem core
features only (the various capabilities, dirty tracking, etc.) and
unless a new feature comes up, tests go in functional/.
- Or something else...
I'm about to start some work on vmstate-static-checker.py now that
Pierrick provided us with the infra to build every QEMU version in a
container, so it's an opportune time.
Don't forget that once the AI gates fully open we'll probably get a
flood of new tests, it would be good to have a single message.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/5] migration-test: Support running a real kernel
2026-11-27 14:01 ` Daniel P. Berrangé
2026-11-27 15:01 ` Peter Xu
@ 2026-11-27 15:18 ` Fabiano Rosas
2026-11-27 15:33 ` Daniel P. Berrangé
1 sibling, 1 reply; 12+ messages in thread
From: Fabiano Rosas @ 2026-11-27 15:18 UTC (permalink / raw)
To: Daniel P. Berrangé, Peter Xu; +Cc: qemu-devel
Daniel P. Berrangé <berrange@redhat.com> writes:
On Fri, Nov 27, 2026 at 08:45:04AM -0500, Peter Xu wrote:
>> On Thu, Nov 26, 2026 at 06:46:59PM -0300, Fabiano Rosas wrote:
>> > There's a class of migration performance bugs that are very specific
>> > to the internals of QEMU and most likely require work on our side, but
>> > are currently invisible to our testing because migration-test runs a
>> > simple guest workload (not even that, really). The more important ones
>> > are BQL contention issues that result in vcpu starvation.
>> >
>> > My plan is to incrementally add some pieces to migration-test to
>> > reduce that testing gap.
>> >
>> > The first piece is adding support for running a kernel + initrd inside
>> > the guest which gives us an easy way to start exercising migration of
>> > a more loaded guest that can already cause VM exits.
>> >
>> > This series adds support for -kernel and -initrd arguments to
>> > migration-test and runs the same set of tests we currently have, but
>> > with the kernel instead of the custom loop. By default it uses the
>> > initrd from tests/migration-stress/ which runs a read-write loop over
>> > all memory and has customizable vcpu and memory size.
>>
> The whole thing sounds useful, I'll read into details after I flush more of
> the older patches.. which will take some time (it also depends on if next
> week I got some more urgent task "injected"..).
>
Take your time. I just need to put these out sooner rather than later
because my internal branch is growing too big and I need feedback from
the list before I get too deep.
The hugepages series will come probably sometime next week and then I'll
give you a break while I work on other stuff.
---
> One high level question: this will grow qtest closer to what the
> functional test is doing. Have you thought of the relationship
> between the two, after we move qtest more over there?
I'm not sure what "move" you mean. Are we porting tests to python? I'm
definitely open to discussion, whatever it is.
> I assumed not, based on what you mentioned
> in the rest part of cover letter that you planned to have it only for dev
> debug purpose. But still, we'll start to ask the question to ourselves at
> some point, IIUC. So I ask first. :)
I'm simply going through the path which I see is of least
resistance. These additions are simple enough. Importantly: with this
series we would be adding a different workload to the guest, but it
still runs all the existing migration-tests.
The same with the hugepages support, it's just another mem_type. For
this to work with the functional tests we'd need to either duplicate the
migration-tests there or write new tests. And we'd isolate the existing
tests entirely from these new features.
E.g.: I want to work on the migration performance around dirty log
disabling, it performs worse when hugepages are enabled, it may trigger
softlockups in the guest and it only happens when migration is aborted.
The /migration/cancel/src/after/ tests can already exercise that path,
work well and have caught bugs before. It just need hugepages and a
kernel:
args->mem_type=MEM_TYPE_HUGE
MIG_KERNEL=vmlinuz \
HUGEPAGES=/dev/hugepages/... \
migration-test -p .../cancel/src/after
>
> In terms of the boundary between functional tests and qtests, I
> think the guidance is in the names.
>
> If it is a "qtest" test then it should be primarily making use
> of QTest to interrogate the QEMU internalprocess state.
>
Hm, quite arbitrary. A "qtest" is a test that uses QTest, ok, but we can
do whatever kind of testing we want with it. If we want to stick to any
formal definition, that is. I'm not sure we need to.
> If it is a "functional" test, then it is interested in running
> real kernels & real accelerators and validating the behaviour of
> QEMU via its external mgmt interfaces.
>
> By this definition, IMHO, the migration-test would be a functional
> test, if it were created from scratch to.
>
By any other definition it already is a functional test.
I'm maybe being too literal. What I think you're trying to indicate
(maybe Peter as well), is that we should preferably group the functional
tests under tests/functional and migration-test.c is more functional
test than anything else, so it should be in there as well. Except that
since migration-test is written in a different programming language, we
would have to leave migration-test.c as is and write new migration tests
under tests/functional.
> It only uses libqtest.h APIs for the purpose of sending QMP
> commands, not examining internal device state. Essentially it is a
> historical accident that it is written as a qtest instead of a
> functional test, as that was the best choice at the time.
>
It uses qtest_read* to validate the guest memory, that was probably the
reason, no?
I also don't understand whatever happened to the whole QGraph/QOS thing,
which, by initial commits seemed it had been written explicitly to
support live migration testing.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/5] migration-test: Support running a real kernel
2026-11-27 15:18 ` Fabiano Rosas
@ 2026-11-27 15:33 ` Daniel P. Berrangé
0 siblings, 0 replies; 12+ messages in thread
From: Daniel P. Berrangé @ 2026-11-27 15:33 UTC (permalink / raw)
To: Fabiano Rosas; +Cc: Peter Xu, qemu-devel
On Fri, Nov 27, 2026 at 12:18:10PM -0300, Fabiano Rosas wrote:
> Daniel P. Berrangé <berrange@redhat.com> writes:
> On Fri, Nov 27, 2026 at 08:45:04AM -0500, Peter Xu wrote:
>
> >> On Thu, Nov 26, 2026 at 06:46:59PM -0300, Fabiano Rosas wrote:
> >> > There's a class of migration performance bugs that are very specific
> >> > to the internals of QEMU and most likely require work on our side, but
> >> > are currently invisible to our testing because migration-test runs a
> >> > simple guest workload (not even that, really). The more important ones
> >> > are BQL contention issues that result in vcpu starvation.
> >> >
> >> > My plan is to incrementally add some pieces to migration-test to
> >> > reduce that testing gap.
> >> >
> >> > The first piece is adding support for running a kernel + initrd inside
> >> > the guest which gives us an easy way to start exercising migration of
> >> > a more loaded guest that can already cause VM exits.
> >> >
> >> > This series adds support for -kernel and -initrd arguments to
> >> > migration-test and runs the same set of tests we currently have, but
> >> > with the kernel instead of the custom loop. By default it uses the
> >> > initrd from tests/migration-stress/ which runs a read-write loop over
> >> > all memory and has customizable vcpu and memory size.
> >>
> > The whole thing sounds useful, I'll read into details after I flush more of
> > the older patches.. which will take some time (it also depends on if next
> > week I got some more urgent task "injected"..).
> >
>
> Take your time. I just need to put these out sooner rather than later
> because my internal branch is growing too big and I need feedback from
> the list before I get too deep.
>
> The hugepages series will come probably sometime next week and then I'll
> give you a break while I work on other stuff.
> ---
>
> > One high level question: this will grow qtest closer to what the
> > functional test is doing. Have you thought of the relationship
> > between the two, after we move qtest more over there?
>
> I'm not sure what "move" you mean. Are we porting tests to python? I'm
> definitely open to discussion, whatever it is.
>
> > I assumed not, based on what you mentioned
> > in the rest part of cover letter that you planned to have it only for dev
> > debug purpose. But still, we'll start to ask the question to ourselves at
> > some point, IIUC. So I ask first. :)
>
> I'm simply going through the path which I see is of least
> resistance. These additions are simple enough. Importantly: with this
> series we would be adding a different workload to the guest, but it
> still runs all the existing migration-tests.
>
> The same with the hugepages support, it's just another mem_type. For
> this to work with the functional tests we'd need to either duplicate the
> migration-tests there or write new tests. And we'd isolate the existing
> tests entirely from these new features.
>
> E.g.: I want to work on the migration performance around dirty log
> disabling, it performs worse when hugepages are enabled, it may trigger
> softlockups in the guest and it only happens when migration is aborted.
>
> The /migration/cancel/src/after/ tests can already exercise that path,
> work well and have caught bugs before. It just need hugepages and a
> kernel:
>
> args->mem_type=MEM_TYPE_HUGE
>
> MIG_KERNEL=vmlinuz \
> HUGEPAGES=/dev/hugepages/... \
> migration-test -p .../cancel/src/after
>
> >
> > In terms of the boundary between functional tests and qtests, I
> > think the guidance is in the names.
> >
> > If it is a "qtest" test then it should be primarily making use
> > of QTest to interrogate the QEMU internalprocess state.
> >
>
> Hm, quite arbitrary. A "qtest" is a test that uses QTest, ok, but we can
> do whatever kind of testing we want with it. If we want to stick to any
> formal definition, that is. I'm not sure we need to.
>
> > If it is a "functional" test, then it is interested in running
> > real kernels & real accelerators and validating the behaviour of
> > QEMU via its external mgmt interfaces.
> >
> > By this definition, IMHO, the migration-test would be a functional
> > test, if it were created from scratch to.
> >
>
> By any other definition it already is a functional test.
>
> I'm maybe being too literal. What I think you're trying to indicate
> (maybe Peter as well), is that we should preferably group the functional
> tests under tests/functional and migration-test.c is more functional
> test than anything else, so it should be in there as well. Except that
> since migration-test is written in a different programming language, we
> would have to leave migration-test.c as is and write new migration tests
> under tests/functional.
Yeah, the functional tests have to be python to take advantage of
the generic testing framework there, especially the asset download
caching.
> > It only uses libqtest.h APIs for the purpose of sending QMP
> > commands, not examining internal device state. Essentially it is a
> > historical accident that it is written as a qtest instead of a
> > functional test, as that was the best choice at the time.
> >
>
> It uses qtest_read* to validate the guest memory, that was probably the
> reason, no?
Oh, indeed, I missed that call :-(
> I also don't understand whatever happened to the whole QGraph/QOS thing,
> which, by initial commits seemed it had been written explicitly to
> support live migration testing.
I don't really know the history behind that.
With regards,
Daniel
--
|: https://berrange.com ~~ https://hachyderm.io/@berrange :|
|: https://libvirt.org ~~ https://entangle-photo.org :|
|: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
^ permalink raw reply [flat|nested] 12+ messages in thread