From nobody Mon Nov 25 07:57:49 2024 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=1717062937; cv=none; d=zohomail.com; s=zohoarc; b=mDBUeYAaalxzyTxXUOYTUBtZXhU8HXN5V1qUelfVvFphi9iD9S70+ccpLyvGW3QogjSshijcBS21oSdgt0iDRFXKxpL+16ByjDXSi12D3JfavbeIUc7IdlCJOFd+Y17Ihh4MXpdkLxpCNAKfE1slwLB8LG/Zl1yo8zgWtaipyus= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717062937; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tnIeYsOj4b7IsclyGOZghZMKCz5C3A6o8pslemkUzRU=; b=D9YEiWQgr6c4O46JoGWkiQSCJBiEZucJ6Wh+Crm4/Q7JFmQqzpPsBW/1yZcNFpeSMdEU1WnmUIuA7tKa3KwFAYeItZQ08f4X+ExlduQjbXjy5a4wbdVqBOo3GRFphXm0RtWgUUltFHs26cdVl0OhdKCDHziEnHxAoVC3TXzfEAU= 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 1717062937781580.32311609511; Thu, 30 May 2024 02:55:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCcUa-00075Q-M3; Thu, 30 May 2024 05:54:40 -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 1sCcUY-00074W-NV for qemu-devel@nongnu.org; Thu, 30 May 2024 05:54:38 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCcUW-00027V-Ly for qemu-devel@nongnu.org; Thu, 30 May 2024 05:54:38 -0400 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-6bce380eb96so485470a12.0 for ; Thu, 30 May 2024 02:54:36 -0700 (PDT) Received: from wheely.local0.net ([1.146.0.82]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c1a775d28asm1183626a91.8.2024.05.30.02.54.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 02:54:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717062875; x=1717667675; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tnIeYsOj4b7IsclyGOZghZMKCz5C3A6o8pslemkUzRU=; b=CGj0rUAWxxHjhVNwE/BSNm3WTyW9G2EDl9Uq297z1nhXeHpIDhJ/OazKJXAuemuKqO ib1NxwLyWFtkNeBXHdhuOQhFV6C6JHItteNHyVsnm5/OKBaAeiDnmqg+j/U4IBtXN31/ CVx4GngKfHgvOTjkDOeJECYGKfUR3ifWYMMPIGcR5liWddak202tmpcubND1pyed2zTn YGg9I+4iVVehAIvq/M6mmbjl9Ligp5hlBKK/7pTkuHUW0qRVB6oeB5XONGMUeON7TyRr mlRnlNEMYyUZNfql3FIaTBLrd4xZA4HVReB7mKdHEcU87l+/gVPKiGLyLV78xeNsLU9u NSIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717062875; x=1717667675; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tnIeYsOj4b7IsclyGOZghZMKCz5C3A6o8pslemkUzRU=; b=JE8Ysu/rfuNZJkaaPFmhccM2NdarFS4mKeeQwoOpX6Mr5qMHjbCY7cTuN52Tq78dzB eA4+QxvC1EnApqODVavyw3RMzTdPdgNVQoAI/PmZ068hKkfGygBYzEzpUTftF8kSuwZl ZMBu5EYn4CwRCTyzCUp5E1qpDgH1MQAoVS/mWWGJRUVygOl7Go6iehLnnTNOfvSgr9j+ pS5jQqa4/vk8/9LLZZb0F5DWIEvQtT8fK+i9FpbQD9r2Z8u1DLGUns6jPkiJezdmJwDj IugAni0U3OKUGqp6KkK1H/wobcjL/RhENV5q6tkx09gUCl+yNeoTGdAUOwgJodoYy3tJ NS+w== X-Gm-Message-State: AOJu0YwXy+ptRAHm1U3VxutAsWL1jp8icvlKDznK81i9E6/L/y3wtdf7 YGrtcx0wAdGN/NoCkhoL7jJoS0UCYinJVx3yqSVxSuEfhQ3kXTR8E6ksJZMa X-Google-Smtp-Source: AGHT+IEyzVIeXlIpDHfsSpzH3gt+zx9FIqWtWgdLPpQeAL7EcufB9lX0C0UXEDAyV1vlZqjrKeIFoA== X-Received: by 2002:a17:90a:d155:b0:2bf:cf50:593e with SMTP id 98e67ed59e1d1-2c1ab9f6c7cmr1627549a91.11.1717062874986; Thu, 30 May 2024 02:54:34 -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 v2 4/4] tests/qtest/migration-test: Add a postcopy memfile test Date: Thu, 30 May 2024 19:54:07 +1000 Message-ID: <20240530095408.31608-5-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240530095408.31608-1-npiggin@gmail.com> References: <20240530095408.31608-1-npiggin@gmail.com> 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=2607:f8b0:4864:20::530; envelope-from=npiggin@gmail.com; helo=mail-pg1-x530.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: 1717062938548100002 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 --- 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 @@ */ =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_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, 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_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 environm= ent"); + 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 =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 +808,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 +858,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_shm_memfile) { unlink(memfile_path); } =20 @@ -1275,6 +1326,15 @@ static void test_postcopy(void) test_postcopy_common(&args); } =20 +static void test_postcopy_memfile(void) +{ + MigrateCommon args =3D { + .start.use_shm_memfile =3D true, + }; + + test_postcopy_common(&args); +} + static void test_postcopy_suspend(void) { MigrateCommon args =3D { @@ -3441,6 +3501,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