From nobody Tue Nov 18 16:02:12 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1716956080; cv=none; d=zohomail.com; s=zohoarc; b=h9OyOF7yGh/z5uL2byJRK2phBEUg8XaukSMDveR/3SxQlYfw7MsqOSu9YZrARM4v8rivGZ6TqVTQBvu72X3Lq+AUJOETZLIv0exbQ22diJ2hLaJBtmTHeVIruksEuAc6yy92Obef0BySvj79UmnWfYzXWgNx1UJxSfyoDWQqLRE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716956080; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Y78cQbaG49gfAp5lAUthC7sJF/QkcqO5aFiUYCrDG3E=; b=OgdcxqENPpruHtIHxCjQoORTf8wzBQBZU4mcY3Xu9qtPgnrLWh92YTFdsy1T/u5+YBhF2CoXafJO5YB7Y7VbXq7RkXIrMcPaYJwDx5vkQGnv0vUstpsMgabPgMSliZjhIiTQRNv+E4i6xUdlzxZUNpjYzzAuxSK1Y8Q7mPiVh/s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1716956080726608.166340928706; Tue, 28 May 2024 21:14:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCAgz-0005Yp-2e; Wed, 29 May 2024 00:13:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sCAgx-0005YZ-R1 for qemu-devel@nongnu.org; Wed, 29 May 2024 00:13:35 -0400 Received: from mail-oa1-x2a.google.com ([2001:4860:4864:20::2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCAgv-0004uE-T7 for qemu-devel@nongnu.org; Wed, 29 May 2024 00:13:35 -0400 Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-24cbb884377so766757fac.0 for ; Tue, 28 May 2024 21:13:32 -0700 (PDT) Received: from wheely.local0.net (110-175-65-7.tpgi.com.au. [110.175.65.7]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f8fcbeac22sm7202743b3a.113.2024.05.28.21.13.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 21:13:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716956011; x=1717560811; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Y78cQbaG49gfAp5lAUthC7sJF/QkcqO5aFiUYCrDG3E=; b=Pim/9etZlWAKiP/ybnjALx0Qcj3z899lzOTK/7YLvgM6TQ4Vd5O1UNVRJXkhQCGChZ VHOgYV/QB359S/PAlmgch8IF1xJwMCi84eAP+VSMVU8nOMSekJxeGtLH6Mc1q3khFzs9 XmaUKnGgD67oR9nGk8H+bHIbsgT8X/4UfPErXydZ25KS0otb6BFUUMyMw3gap3vCt/R2 lNxV3OX80JZ5f++56euHoxJ89mhqfaC9LApWusjDZFVz6U6TLX12+pjSafKGpHGmy5Vc /qxMgV/HqrpG14xDQ/Ad6Tv9yGGWQfpbpAoohbduMM8H7v8uNxG/IawtT8jj6M4n5STr CO1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716956011; x=1717560811; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Y78cQbaG49gfAp5lAUthC7sJF/QkcqO5aFiUYCrDG3E=; b=g7WngzNBXlDskECB83RoU/+EdUIP4tFDHiG4iAZGJ6UjlmhxUm7T1eIhV0Kj21FWiY BtWfvd8FliWATU2xFm/Qb4ZSBO1q+RtxSV+R/CPgtBeIhNFaKW1N+FfRe7TMr7REEO7x hmw2mWQkGguh3hhlEe09bx5+TZJ6LALKhL3Vz+cqkaTdYSv9fzv7OaEnEZPSmTwgYhPr jv/DnkPpRtP6WRuBF1ZQI33YHpB580yeTU0XKhhPRpXNPJPK4y39FgKRp84N5WsP8SCS vAZb56vdFcVG9+6KLZ2YEutB3ZGDeoCrgccb3eARWnSjNFJnR0Uzg28aSPLe2z9FlOqs yuIg== X-Gm-Message-State: AOJu0Yw3sk76CwQlHCv7neiqWSEnWLMcaz+wtJWuvRnB4TKUfRX0lqji KE8GrhsYoeIP6jnzALXzqW9Xl+Zr+XoZDTb1I7zMaL7oSqpPewFL26dZ4g== X-Google-Smtp-Source: AGHT+IH1rJE9lXS9o6fY4HKSVI0TX51RjW+KAlpBuMGgcvzUuwDAM9IF9GyQDNCKwxKl4ba0eLC3mQ== X-Received: by 2002:a05:6870:35d4:b0:23e:7764:7795 with SMTP id 586e51a60fabf-24ca12e174bmr14907257fac.28.1716956010900; Tue, 28 May 2024 21:13:30 -0700 (PDT) From: Nicholas Piggin To: qemu-devel@nongnu.org Cc: Nicholas Piggin , Peter Xu , Fabiano Rosas , Thomas Huth , Laurent Vivier , Paolo Bonzini Subject: [PATCH] tests/qtest/migrate-test: Add a postcopy memfile test Date: Wed, 29 May 2024 14:13:21 +1000 Message-ID: <20240529041322.701525-1-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2001:4860:4864:20::2a; envelope-from=npiggin@gmail.com; helo=mail-oa1-x2a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1716956082710100003 Content-Type: text/plain; charset="utf-8" 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 --- How about this? This goes on top of the reset of the patches (I'll re-send them all as a series if we can get to some agreement). This adds back the /dev/shm option with preallocation and adds a test case that requires tmpfs. Thanks, Nick tests/qtest/migration-test.c | 63 +++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 86eace354e..7fd9bbdc18 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -11,6 +11,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/cutils.h" =20 #include "libqtest.h" #include "qapi/qmp/qdict.h" @@ -553,6 +554,7 @@ typedef struct { */ bool hide_stderr; bool use_memfile; + bool use_uffd_memfile; /* only launch the target process */ bool only_target; /* Use dirty ring if true; dirty logging otherwise */ @@ -739,7 +741,48 @@ static int test_migrate_start(QTestState **from, QTest= State **to, ignore_stderr =3D ""; } =20 - if (args->use_memfile) { + if (!qtest_has_machine(machine_alias)) { + g_autofree char *msg =3D g_strdup_printf("machine %s not supported= ", + machine_alias); + g_test_skip(msg); + return -1; + } + + if (args->use_uffd_memfile) { +#if defined(__NR_userfaultfd) && defined(__linux__) + int fd; + uint64_t size; + + 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 =3D g_strdup_printf("/dev/shm/qemu-%d", getpid()); + fd =3D open(memfile_path, O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S= _IWUSR); + if (fd =3D=3D -1) { + g_test_skip("/dev/shm file could not be created"); + return -1; + } + + g_assert(qemu_strtosz(memory_size, NULL, &size) =3D=3D 0); + size +=3D 64*1024; /* QEMU may map a bit more memory for a guard p= age */ + + if (fallocate(fd, 0, 0, size) =3D=3D -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 =3D g_strdup_printf("/%s/qemu-%d", tmpfs, getpid()); memfile_opts =3D g_strdup_printf( "-object memory-backend-file,id=3Dmem0,size=3D%s" @@ -751,12 +794,6 @@ static int test_migrate_start(QTestState **from, QTest= State **to, kvm_opts =3D ",dirty-ring-size=3D4096"; } =20 - if (!qtest_has_machine(machine_alias)) { - g_autofree char *msg =3D g_strdup_printf("machine %s not supported= ", machine_alias); - g_test_skip(msg); - return -1; - } - machine =3D resolve_machine_version(machine_alias, QEMU_ENV_SRC, QEMU_ENV_DST); =20 @@ -807,7 +844,7 @@ static int test_migrate_start(QTestState **from, QTestS= tate **to, * Remove shmem file immediately to avoid memory leak in test failed c= ase. * It's valid because QEMU has already opened this file */ - if (args->use_memfile) { + if (args->use_memfile || args->use_uffd_memfile) { unlink(memfile_path); } =20 @@ -1275,6 +1312,15 @@ static void test_postcopy(void) test_postcopy_common(&args); } =20 +static void test_postcopy_memfile(void) +{ + MigrateCommon args =3D { + .start.use_uffd_memfile =3D true, + }; + + test_postcopy_common(&args); +} + static void test_postcopy_suspend(void) { MigrateCommon args =3D { @@ -3441,6 +3487,7 @@ int main(int argc, char **argv) =20 if (has_uffd) { migration_test_add("/migration/postcopy/plain", test_postcopy); + migration_test_add("/migration/postcopy/memfile", test_postcopy_me= mfile); migration_test_add("/migration/postcopy/recovery/plain", test_postcopy_recovery); migration_test_add("/migration/postcopy/preempt/plain", --=20 2.43.0