From: Nicholas Piggin <npiggin@gmail.com>
To: qemu-devel@nongnu.org
Cc: Nicholas Piggin <npiggin@gmail.com>, Peter Xu <peterx@redhat.com>,
Fabiano Rosas <farosas@suse.de>, Thomas Huth <thuth@redhat.com>,
Laurent Vivier <lvivier@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH v2 4/4] tests/qtest/migration-test: Add a postcopy memfile test
Date: Thu, 30 May 2024 19:54:07 +1000 [thread overview]
Message-ID: <20240530095408.31608-5-npiggin@gmail.com> (raw)
In-Reply-To: <20240530095408.31608-1-npiggin@gmail.com>
Postcopy requires userfaultfd support, which requires tmpfs if a memory
file is used.
This adds back support for /dev/shm memory files, but adds preallocation
to skip environments where that mount is limited in size.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
tests/qtest/migration-test.c | 77 ++++++++++++++++++++++++++++++++----
1 file changed, 69 insertions(+), 8 deletions(-)
diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 86eace354e..5078033ded 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -11,6 +11,7 @@
*/
#include "qemu/osdep.h"
+#include "qemu/cutils.h"
#include "libqtest.h"
#include "qapi/qmp/qdict.h"
@@ -553,6 +554,7 @@ typedef struct {
*/
bool hide_stderr;
bool use_memfile;
+ bool use_shm_memfile;
/* only launch the target process */
bool only_target;
/* Use dirty ring if true; dirty logging otherwise */
@@ -739,7 +741,62 @@ static int test_migrate_start(QTestState **from, QTestState **to,
ignore_stderr = "";
}
- if (args->use_memfile) {
+ if (!qtest_has_machine(machine_alias)) {
+ g_autofree char *msg = g_strdup_printf("machine %s not supported",
+ machine_alias);
+ g_test_skip(msg);
+ return -1;
+ }
+
+ if (args->use_shm_memfile) {
+#if defined(__NR_userfaultfd) && defined(__linux__)
+ int fd;
+ uint64_t size;
+
+ if (getenv("GITLAB_CI")) {
+ /*
+ * Gitlab runners are limited to 64MB shm size and despite
+ * pre-allocation there is concern that concurrent tests
+ * could result in nondeterministic failures. Until all shm
+ * usage in all CI tests is found to fail gracefully on
+ * ENOSPC, it is safer to avoid large allocations for now.
+ *
+ * https://lore.kernel.org/qemu-devel/875xuwg4mx.fsf@suse.de/
+ */
+ g_test_skip("shm tests are not supported in Gitlab CI environment");
+ return -1;
+ }
+
+ if (!g_file_test("/dev/shm", G_FILE_TEST_IS_DIR)) {
+ g_test_skip("/dev/shm does not exist or is not a directory");
+ return -1;
+ }
+
+ /*
+ * Pre-create and allocate the file here, because /dev/shm/
+ * is known to be limited in size in some places (e.g., Gitlab CI).
+ */
+ memfile_path = g_strdup_printf("/dev/shm/qemu-%d", getpid());
+ fd = open(memfile_path, O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
+ if (fd == -1) {
+ g_test_skip("/dev/shm file could not be created");
+ return -1;
+ }
+
+ g_assert(qemu_strtosz(memory_size, NULL, &size) == 0);
+ size += 64*1024; /* QEMU may map a bit more memory for a guard page */
+
+ if (fallocate(fd, 0, 0, size) == -1) {
+ unlink(memfile_path);
+ perror("could not alloc"); exit(1);
+ g_test_skip("Could not allocate machine memory in /dev/shm");
+ return -1;
+ }
+ close(fd);
+#else
+ g_test_skip("userfaultfd is not supported");
+#endif
+ } else if (args->use_memfile) {
memfile_path = g_strdup_printf("/%s/qemu-%d", tmpfs, getpid());
memfile_opts = g_strdup_printf(
"-object memory-backend-file,id=mem0,size=%s"
@@ -751,12 +808,6 @@ static int test_migrate_start(QTestState **from, QTestState **to,
kvm_opts = ",dirty-ring-size=4096";
}
- if (!qtest_has_machine(machine_alias)) {
- g_autofree char *msg = g_strdup_printf("machine %s not supported", machine_alias);
- g_test_skip(msg);
- return -1;
- }
-
machine = resolve_machine_version(machine_alias, QEMU_ENV_SRC,
QEMU_ENV_DST);
@@ -807,7 +858,7 @@ static int test_migrate_start(QTestState **from, QTestState **to,
* 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_memfile) {
+ if (args->use_memfile || args->use_shm_memfile) {
unlink(memfile_path);
}
@@ -1275,6 +1326,15 @@ static void test_postcopy(void)
test_postcopy_common(&args);
}
+static void test_postcopy_memfile(void)
+{
+ MigrateCommon args = {
+ .start.use_shm_memfile = true,
+ };
+
+ test_postcopy_common(&args);
+}
+
static void test_postcopy_suspend(void)
{
MigrateCommon args = {
@@ -3441,6 +3501,7 @@ int main(int argc, char **argv)
if (has_uffd) {
migration_test_add("/migration/postcopy/plain", test_postcopy);
+ migration_test_add("/migration/postcopy/memfile", test_postcopy_memfile);
migration_test_add("/migration/postcopy/recovery/plain",
test_postcopy_recovery);
migration_test_add("/migration/postcopy/preempt/plain",
--
2.43.0
next prev parent reply other threads:[~2024-05-30 9:55 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-30 9:54 [PATCH v2 0/4] tests/qtest/migration-test: Improve shared Nicholas Piggin
2024-05-30 9:54 ` [PATCH v2 1/4] tests/qtest/migration-test: Use regular file file for shared-memory tests Nicholas Piggin
2024-05-31 7:03 ` Prasad Pandit
2024-05-30 9:54 ` [PATCH v2 2/4] tests/qtest/migration-test: Enable test_mode_reboot Nicholas Piggin
2024-05-31 15:50 ` Fabiano Rosas
2024-05-30 9:54 ` [PATCH v2 3/4] tests/qtest/migration-test: Fix and enable test_ignore_shared Nicholas Piggin
2024-05-30 12:18 ` Dr. David Alan Gilbert
2024-12-09 17:22 ` Fabiano Rosas
2024-05-30 9:54 ` Nicholas Piggin [this message]
2024-05-31 13:34 ` [PATCH v2 4/4] tests/qtest/migration-test: Add a postcopy memfile test Peter Xu
2024-05-31 16:01 ` Fabiano Rosas
2024-06-03 6:02 ` Nicholas Piggin
2024-06-03 15:50 ` Peter Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240530095408.31608-5-npiggin@gmail.com \
--to=npiggin@gmail.com \
--cc=farosas@suse.de \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).