From nobody Sun Nov 29 02:11:46 2026 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=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1795729705; cv=none; d=zohomail.com; s=zohoarc; b=KjRTwt2iQHsm31uApqgw3SS34/iGVvhZWl3WZoodn2E9KuFJ6nQxI9j1lMFALA1T+vLeJbP2hn4vplqDws1WWFc3rNZVWRiHM5KYc0jyKrTBs1X6uTzhNHJOrKzcSslra3wx9/HjCoySMif+9sfNxI1oHl/M62+KcdFaPW8F6qw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795729705; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CCSNqoQZ+gKr5HKfpXcWBtv8W05h0oGi7K0t04rXA/U=; b=AFx2UXcAXQpQ3CCVYgMMiP+dISqE2NLTeDA53ycAbSw4ByBt/J5u2a8/QsMEF59CdxsecMd5JDgw5JihSIlCBWQ2Ja2W8B4z73hurVLdWZRnBVaKZYUKbeHTcj9LQu/2QQ4uv9oOcgUx2ezMcoKhtSMX0CdVNZk3ZXc7kJnQeJw= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795729705663808.1692255737729; Thu, 26 Nov 2026 13:48:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xWhJZ-0000ik-1w; Thu, 26 Nov 2026 16:47:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xWhJD-0000h8-GW for qemu-devel@nongnu.org; Thu, 26 Nov 2026 16:47:15 -0500 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xWhJB-00005u-Kh for qemu-devel@nongnu.org; Thu, 26 Nov 2026 16:47:14 -0500 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E61681FE7C; Thu, 26 Nov 2026 21:47:09 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id EC688134CA; Thu, 26 Nov 2026 21:47:08 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 3qzICtuoCGtRZgAAD6G6ig:T2 (envelope-from ); Thu, 26 Nov 2026 21:47:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1795729630; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CCSNqoQZ+gKr5HKfpXcWBtv8W05h0oGi7K0t04rXA/U=; b=HlVXky1EaG1xTmKVoUPZciOzrbkiv1sCnoitG977PgL3eEuPKqiVpWizOKINk2+Q8AddtA t+hJuMb0arNDNjSqCl/sJy+3vRjNo6hMETpC7Kz1aUgIptDv0/vBk9O/RZbAcQ47PsTz1B GcuA1qXSoSYgd1xw+RiZPyTzT+AsDgs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1795729630; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CCSNqoQZ+gKr5HKfpXcWBtv8W05h0oGi7K0t04rXA/U=; b=l58rZXkpRY1JMlvqVkzMqSW7yLVdSntYcahQ+eedMiBqcVjnUjykc1iuTd0gNPkpOsEkgQ NssmmhTygK5qmRAQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1795729629; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CCSNqoQZ+gKr5HKfpXcWBtv8W05h0oGi7K0t04rXA/U=; b=OaPligK/96pg5OxzobNl5ptxDpmBCP/B0sGmFp1msdnP82Wk63BUgw1XrGtY/mjf5gonof R0Gm07p0tvmu5axxSzCsQn46bWeDkNeRe2vzJu8LbR34fZBwO+Qub3uzOB8OTFNFF/Rrr0 PzOFXmQ4X0QJv/DTB51YgRKaV6Z+4n8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1795729629; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CCSNqoQZ+gKr5HKfpXcWBtv8W05h0oGi7K0t04rXA/U=; b=Eoi32GJPEDHu3Fq5UCSxqiQ4myn/u/MKaUKV83YTbEyWptNNKu1L2OEabDhAvyDvmAwg8G bZ8WUUrIpR1wYvDg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu Subject: [PATCH 1/5] tests/migration-stress: Fix stress.c loop Date: Thu, 26 Nov 2026 18:47:00 -0300 Message-ID: <20261126214704.3108327-2-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261126214704.3108327-1-farosas@suse.de> References: <20261126214704.3108327-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-11.80 / 50.00]; SUSE_INTERNAL_BYPASS(-9.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.995]; MIME_GOOD(-0.10)[text/plain]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; RCVD_COUNT_TWO(0.00)[2]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_DN_SOME(0.00)[]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -11.80 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a07:de40:b251:101:10:150:64:2; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: qemu development 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 @suse.de) (identity @suse.de) X-ZM-MESSAGEID: 1795729707482158500 Content-Type: text/plain; charset="utf-8" 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 =3D 0; j < pagesPerMB; j++) { dataptr =3D data; for (k =3D 0; k < RAM_PAGE_SIZE; k +=3D sizeof(long long)) { ramptr +=3D sizeof(long long); dataptr +=3D sizeof(long long); *(unsigned long long *)ramptr ^=3D *(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 --- 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/stres= s.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); } =20 +static inline void xor_1M(void *ram_start, void *data_page) +{ + unsigned long long *addr, *data; + int i, j, pages_per_mb =3D RAM_PAGE_SIZE >> 4; + int n =3D RAM_PAGE_SIZE / sizeof(unsigned long long); + + addr =3D ram_start; + + for (i =3D 0; i < pages_per_mb; i++) { + data =3D data_page; + j =3D n; + + while (j--) { + *addr ^=3D *data; + addr++; + data++; + } + } +} + static void stressone(unsigned long long ramsizeMB) { - size_t pagesPerMB =3D 1024 * 1024 / RAM_PAGE_SIZE; g_autofree char *ram =3D g_malloc(ramsizeMB * 1024 * 1024); - char *ramptr; - size_t i, j, k; + size_t i; g_autofree char *data =3D g_malloc(RAM_PAGE_SIZE); - char *dataptr; size_t nMB =3D 0; unsigned long long before, after; =20 @@ -181,17 +198,9 @@ static void stressone(unsigned long long ramsizeMB) before =3D now(); =20 while (1) { - - ramptr =3D ram; - for (i =3D 0; i < ramsizeMB; i++, nMB++) { - for (j =3D 0; j < pagesPerMB; j++) { - dataptr =3D data; - for (k =3D 0; k < RAM_PAGE_SIZE; k +=3D sizeof(long long))= { - ramptr +=3D sizeof(long long); - dataptr +=3D sizeof(long long); - *(unsigned long long *)ramptr ^=3D *(unsigned long lon= g *)dataptr; - } - } + for (i =3D 0; i < ramsizeMB; i++) { + xor_1M(ram, data); + nMB++; =20 if (nMB =3D=3D 1024) { after =3D now(); --=20 2.53.0 From nobody Sun Nov 29 02:11:46 2026 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=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1795729674; cv=none; d=zohomail.com; s=zohoarc; b=F7bZh5lzyPlahq7ed6DmECnmnlN6xuPN8Pq9sYcML0PIgcaRtSiPPtwyg2uOhDZLdVvrqBFiRqQqmGt2roOq5h/kAzh1GCECUULgy6M4A6PNyAYsh3LWpCkwn//W7ooNlcNH9zi1hlz9MyX9nIqGgVuLOmwmRoUmY7typfsjs5Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795729674; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=esexrgAySePlCg8wCqSubGvjmvFwnGtdVWX+RATGNUM=; b=OYyXDSlh21CIqaoosI0rEk1qJ2Er2VsNBy92D3BN+2ketyJv8ELOG9xu4sW8Yplhaj5F/crdZgG3K3Ns2MKsMKbjgiSjA3W2xUgoibOcxtutoLgPLMr6Yx8N1xo5OpOE1B3YqF1iba0IL3wJIyFBdaffs+3PAo7urLZVUjX4mBY= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795729674339207.48421392364162; Thu, 26 Nov 2026 13:47:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xWhJU-0000if-50; Thu, 26 Nov 2026 16:47:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xWhJD-0000h9-JU for qemu-devel@nongnu.org; Thu, 26 Nov 2026 16:47:15 -0500 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xWhJB-0000Dn-Kw for qemu-devel@nongnu.org; Thu, 26 Nov 2026 16:47:15 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3EF1B2282D; Thu, 26 Nov 2026 21:47:11 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 468F7134C3; Thu, 26 Nov 2026 21:47:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 3qzICtuoCGtRZgAAD6G6ig:T3 (envelope-from ); Thu, 26 Nov 2026 21:47:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1795729631; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=esexrgAySePlCg8wCqSubGvjmvFwnGtdVWX+RATGNUM=; b=lr5AA1PaQXlTlg5ne3r2UdI41R494POYEzIVPHMljVic4lMDpt/EtdcVZSpBQTM2pX9CN4 t5yqLmmOx2SuQsM26pPBN8uIpEXT1nypA0V5Ujc/atNgLWFRnArVCZ3PBRI/4mG5eKF2TV BPszKCloJaraLYH1LfW629+Uke8rUr4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1795729631; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=esexrgAySePlCg8wCqSubGvjmvFwnGtdVWX+RATGNUM=; b=Z8B1Q4T76TtBlr3HJk1pXDL7iiwlatGf95QE9HHCdMPty7TDVuBknd9dntiwJfZidyoROk y43yIoDrFu87GLBg== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=lr5AA1Pa; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Z8B1Q4T7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1795729631; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=esexrgAySePlCg8wCqSubGvjmvFwnGtdVWX+RATGNUM=; b=lr5AA1PaQXlTlg5ne3r2UdI41R494POYEzIVPHMljVic4lMDpt/EtdcVZSpBQTM2pX9CN4 t5yqLmmOx2SuQsM26pPBN8uIpEXT1nypA0V5Ujc/atNgLWFRnArVCZ3PBRI/4mG5eKF2TV BPszKCloJaraLYH1LfW629+Uke8rUr4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1795729631; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=esexrgAySePlCg8wCqSubGvjmvFwnGtdVWX+RATGNUM=; b=Z8B1Q4T76TtBlr3HJk1pXDL7iiwlatGf95QE9HHCdMPty7TDVuBknd9dntiwJfZidyoROk y43yIoDrFu87GLBg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu Subject: [PATCH 2/5] tests/migration-stress: Cleanups to stress.c Date: Thu, 26 Nov 2026 18:47:01 -0300 Message-ID: <20261126214704.3108327-3-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261126214704.3108327-1-farosas@suse.de> References: <20261126214704.3108327-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-12.01 / 50.00]; SUSE_INTERNAL_BYPASS(-9.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; ARC_NA(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCPT_COUNT_TWO(0.00)[2]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_TLS_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo,suse.de:email,suse.de:dkim]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -12.01 X-Rspamd-Queue-Id: 3EF1B2282D 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: qemu development 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 @suse.de) X-ZM-MESSAGEID: 1795729677431158501 Content-Type: text/plain; charset="utf-8" - 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 --- 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/stres= s.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) } } =20 -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 =3D fopen("/proc/cmdline", "r"); char *start, *end; =20 - if (fp =3D=3D NULL) { + if (!fp) { fprintf(stderr, "%s (%05d): ERROR: cannot open /proc/cmdline: %s\n= ", argv0, gettid(), strerror(errno)); return -1; } =20 - 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); =20 start =3D strstr(line, name); - if (!start) + if (!start) { return 0; + } =20 start +=3D strlen(name); =20 if (*start !=3D '=3D') { - 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++; =20 end =3D strstr(start, " "); - if (!end) + if (!end) { end =3D strstr(start, "\n"); + } =20 if (end =3D=3D 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; } =20 - if (end) + if (end) { *val =3D g_strndup(start, end - start); - else + } else { *val =3D g_strdup(start); + } return 1; } =20 - -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; } =20 - static unsigned long long now(void) { struct timeval tv; @@ -176,69 +175,68 @@ static inline void xor_1M(void *ram_start, void *data= _page) } } =20 -static void stressone(unsigned long long ramsizeMB) +static void stress_one(unsigned long long ramsize_mb) { - g_autofree char *ram =3D g_malloc(ramsizeMB * 1024 * 1024); - size_t i; - g_autofree char *data =3D g_malloc(RAM_PAGE_SIZE); - size_t nMB =3D 0; + g_autofree char *ram_start =3D g_malloc(ramsize_mb * 1024 * 1024); + g_autofree char *data_page =3D g_malloc(RAM_PAGE_SIZE); unsigned long long before, after; + int i, n_mb =3D 0; =20 - /* 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); =20 - 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; } =20 before =3D now(); =20 - while (1) { - for (i =3D 0; i < ramsizeMB; i++) { - xor_1M(ram, data); - nMB++; + for (;;) { + for (i =3D 0; i < ramsize_mb; i++) { + xor_1M(ram_start, data_page); =20 - if (nMB =3D=3D 1024) { + if (++n_mb =3D=3D 1024) { after =3D now(); fprintf(stderr, "%s (%05d): INFO: %06llums copied 1 GB in = %05llums\n", argv0, gettid(), after, after - before); before =3D now(); - nMB =3D 0; + n_mb =3D 0; } } } } =20 - -static void *stressthread(void *arg) +static void *stress_thread(void *arg) { - unsigned long long ramsizeMB =3D *(unsigned long long *)arg; + unsigned long long ramsize_mb =3D *(unsigned long long *)arg; =20 - stressone(ramsizeMB); + stress_one(ramsize_mb); =20 return NULL; } =20 -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 =3D ramsizeGB * 1024 / ncpus; - ncpus--; + unsigned long long ramsize_mb =3D ramsize_gb * 1024 / n_cpus; =20 - for (i =3D 0; i < ncpus; i++) { + n_cpus--; + + for (i =3D 0; i < n_cpus; i++) { pthread_t thr; - pthread_create(&thr, NULL, - stressthread, &ramsizeMB); + pthread_create(&thr, NULL, stress_thread, &ramsize_mb); } =20 - stressone(ramsizeMB); + stress_one(ramsize_mb); } =20 - static int mount_misc(const char *fstype, const char *dir) { if (g_mkdir_with_parents(dir, 0755) < 0 && errno !=3D EEXIST) { @@ -271,7 +269,7 @@ static int mount_all(void) =20 int main(int argc, char **argv) { - unsigned long long ramsizeGB =3D 1; + unsigned long long ramsize_gb =3D 1; char *end; int ch; int opt_ind =3D 0; @@ -283,7 +281,7 @@ int main(int argc, char **argv) { NULL, 0, NULL, 0 } }; int ret; - int ncpus =3D 0; + int n_cpus =3D 0; =20 argv0 =3D argv[0]; =20 @@ -291,7 +289,7 @@ int main(int argc, char **argv) switch (ch) { case 'r': errno =3D 0; - ramsizeGB =3D strtoll(optarg, &end, 10); + ramsize_gb =3D strtoll(optarg, &end, 10); if (errno !=3D 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) =20 case 'c': errno =3D 0; - ncpus =3D strtoll(optarg, &end, 10); + n_cpus =3D strtoll(optarg, &end, 10); if (errno !=3D 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) } =20 if (getpid() =3D=3D 1) { - if (mount_all() < 0) + if (mount_all() < 0) { exit_failure(); + } =20 - ret =3D get_command_arg_ull("ramsize", &ramsizeGB); - if (ret < 0) + ret =3D get_command_arg_ull("ramsize", &ramsize_gb); + if (ret < 0) { exit_failure(); + } } =20 - if (ncpus =3D=3D 0) - ncpus =3D sysconf(_SC_NPROCESSORS_ONLN); + if (n_cpus =3D=3D 0) { + n_cpus =3D sysconf(_SC_NPROCESSORS_ONLN); + } =20 fprintf(stdout, "%s (%05d): INFO: RAM %llu GiB across %d CPUs\n", - argv0, gettid(), ramsizeGB, ncpus); + argv0, gettid(), ramsize_gb, n_cpus); =20 - stress(ramsizeGB, ncpus); + stress(ramsize_gb, n_cpus); =20 exit_failure(); } --=20 2.53.0 From nobody Sun Nov 29 02:11:46 2026 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=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1795729704; cv=none; d=zohomail.com; s=zohoarc; b=JCw4cShIf1tiNJcH2N8aKA2irtRgoDphVcVH31z7OpYpQ36GjfLrThzachS4OF7/idWRSHnCNkTBou65MYmOQHwaituTDivx63LcLADjB5a9zOHh1atjHiQYBEcStkpvU9Q/cNg+xZYo6Nc3/l6LMe7wgo93V03MDeqBf4lBuwU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795729704; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=R+GmnFkIohooLqukNR7Ns8+/vT1O6BZG0CxIAfAsZpg=; b=n1fk2u9GFYmGGiTUq+GXFryL8yjZcIjP9D4zKdCJLqImsV/5A/xUS8FVnE4LRLTXT6BbaGN6V+Lw+3U0n5niTp5l0OqYjQLxVM6i+4/3MuCgO3IvbsEmeq481pgj4jNqjg6iY9Cp7jKYRZGaz1uTSsssoaXN5I5o7GZm7ONq9Sg= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795729704684484.15248749789316; Thu, 26 Nov 2026 13:48:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xWhJZ-0000iu-26; Thu, 26 Nov 2026 16:47:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xWhJF-0000hb-PL for qemu-devel@nongnu.org; Thu, 26 Nov 2026 16:47:18 -0500 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xWhJC-0000Ja-8L for qemu-devel@nongnu.org; Thu, 26 Nov 2026 16:47:17 -0500 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0AB272283B; Thu, 26 Nov 2026 21:47:13 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 9E75F134C3; Thu, 26 Nov 2026 21:47:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 3qzICtuoCGtRZgAAD6G6ig:T4 (envelope-from ); Thu, 26 Nov 2026 21:47:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1795729633; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R+GmnFkIohooLqukNR7Ns8+/vT1O6BZG0CxIAfAsZpg=; b=FW3o1TvdAENpKFEjlANTWXvvnKdZlwMIzRHmMb7Y9POyWXhSmaeDQ26yRLJgAyjEP4MdzI nfqP/eA+vIT+hqn0vD5FkIC71WRtbmt3JmvhU/2sbDdTzU8rtiBArC8qBcWUy7hFAd7HR1 H86D9Vb0i8rcC/tT5Wd/1Airp1HAgLk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1795729633; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R+GmnFkIohooLqukNR7Ns8+/vT1O6BZG0CxIAfAsZpg=; b=BypG1r0d+iuTp9G+m5zCe3oOEk8dN1R8eXiwjl/aGCF1eXdl3uz32ApUDavwphm0sJG4nt yi5v77YRe5nOqdBg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1795729633; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R+GmnFkIohooLqukNR7Ns8+/vT1O6BZG0CxIAfAsZpg=; b=FW3o1TvdAENpKFEjlANTWXvvnKdZlwMIzRHmMb7Y9POyWXhSmaeDQ26yRLJgAyjEP4MdzI nfqP/eA+vIT+hqn0vD5FkIC71WRtbmt3JmvhU/2sbDdTzU8rtiBArC8qBcWUy7hFAd7HR1 H86D9Vb0i8rcC/tT5Wd/1Airp1HAgLk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1795729633; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R+GmnFkIohooLqukNR7Ns8+/vT1O6BZG0CxIAfAsZpg=; b=BypG1r0d+iuTp9G+m5zCe3oOEk8dN1R8eXiwjl/aGCF1eXdl3uz32ApUDavwphm0sJG4nt yi5v77YRe5nOqdBg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Laurent Vivier , Paolo Bonzini Subject: [PATCH 3/5] tests/qtest/migration: Move guest workload code into bootfile.c Date: Thu, 26 Nov 2026 18:47:02 -0300 Message-ID: <20261126214704.3108327-4-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261126214704.3108327-1-farosas@suse.de> References: <20261126214704.3108327-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-11.80 / 50.00]; SUSE_INTERNAL_BYPASS(-9.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.996]; MIME_GOOD(-0.10)[text/plain]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_THREE(0.00)[4]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -11.80 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: qemu development 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 @suse.de) X-ZM-MESSAGEID: 1795729705546158500 Content-Type: text/plain; charset="utf-8" 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 --- 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/bootf= ile.c index e46ad09de76..d40bd0c2d3e 100644 --- a/tests/qtest/migration/bootfile.c +++ b/tests/qtest/migration/bootfile.c @@ -11,6 +11,8 @@ */ =20 #include "qemu/osdep.h" +#include "framework.h" +#include "migration-util.h" =20 /* * 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" =20 +unsigned start_address; +unsigned end_address; + static char *bootpath; =20 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] =3D suspend_me; content =3D x86_bootsect; len =3D sizeof(x86_bootsect); + start_address =3D X86_TEST_MEM_START; + end_address =3D X86_TEST_MEM_END; } else if (g_str_equal(arch, "s390x")) { content =3D s390x_elf; len =3D sizeof(s390x_elf); + start_address =3D S390_TEST_MEM_START; + end_address =3D S390_TEST_MEM_END; } else if (strcmp(arch, "ppc64") =3D=3D 0) { content =3D ppc64_kernel; len =3D sizeof(ppc64_kernel); + start_address =3D PPC_TEST_MEM_START; + end_address =3D PPC_TEST_MEM_END; } else if (strcmp(arch, "aarch64") =3D=3D 0) { content =3D aarch64_kernel; len =3D sizeof(aarch64_kernel); g_assert(sizeof(aarch64_kernel) <=3D ARM_TEST_MAX_KERNEL_SIZE); + start_address =3D ARM_TEST_MEM_START; + end_address =3D ARM_TEST_MEM_END; } else if (strcmp(arch, "loongarch64") =3D=3D 0) { content =3D loongarch64_kernel; len =3D sizeof(loongarch64_kernel); + start_address =3D LOONGARCH_TEST_MEM_START; + end_address =3D 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; } =20 -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 =3D "150M"; + boot =3D g_strdup_printf( + "-drive if=3Dnone,id=3Dd0,file=3D%s,format=3Draw " + "-device ide-hd,drive=3Dd0,secs=3D1,cyls=3D1,heads=3D1", bootp= ath); + + } else if (g_str_equal(arch, "s390x")) { + memory_size =3D "128M"; + boot =3D g_strdup_printf("-bios %s", bootpath); + + } else if (g_str_equal(arch, "ppc64")) { + memory_size =3D "256M"; + boot =3D g_strdup_printf("-bios %s", bootpath); + + } else if (g_str_equal(arch, "aarch64")) { + memory_size =3D "150M"; + boot =3D g_strdup_printf("-kernel %s", bootpath); + + } else if (g_str_equal(arch, "loongarch64")) { + memory_size =3D "256M"; + boot =3D g_strdup_printf("-bios %s", bootpath); + } else { + g_assert_not_reached(); + } + + *mem_size =3D g_strdup(memory_size); + return boot; +} + +void migrate_wait_for_dirty_mem(QTestState *from, QTestState *to) +{ + uint64_t watch_address =3D start_address + MAGIC_OFFSET_BASE; + uint64_t marker_address =3D 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) !=3D MAGIC_MARKER); + + /* If suspended, src only iterates once, and watch_byte may never chan= ge */ + 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 =3D qtest_readb(from, watch_address); + do { + usleep(1000 * 10); + } while (qtest_readb(from, watch_address) =3D=3D 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 fr= om + * 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 transit= ion + * 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 =3D false; + int bad =3D 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 =3D=3D 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, =3D=3D, dest_byte_d); + + qtest_memread(who, start_address, &first_byte, 1); + last_byte =3D first_byte; + + for (address =3D start_address + TEST_MEM_PAGE_SIZE; address < end_add= ress; + address +=3D TEST_MEM_PAGE_SIZE) + { + uint8_t b; + qtest_memread(who, address, &b, 1); + if (b !=3D last_byte) { + if (((b + 1) % 256) =3D=3D 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 =3D true; + last_byte =3D b; + } else { + bad++; + if (bad <=3D 10) { + fprintf(stderr, "Memory content inconsistency at %x" + " first_byte =3D %x last_byte =3D %x current = =3D %x" + " hit_edge =3D %x\n", + address, first_byte, last_byte, b, hit_edge); + } + } + } + } + if (bad >=3D 10) { + fprintf(stderr, "and in another %d pages", bad - 10); + } + g_assert(bad =3D=3D 0); } diff --git a/tests/qtest/migration/bootfile.h b/tests/qtest/migration/bootf= ile.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 =20 /* Common */ #define TEST_MEM_PAGE_SIZE 4096 =20 +/* + * 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 =20 #endif /* BOOTFILE_H */ diff --git a/tests/qtest/migration/framework.c b/tests/qtest/migration/fram= ework.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 =20 -unsigned start_address; -unsigned end_address; static QTestMigrationState src_state; static QTestMigrationState dst_state; static char *tmpfs; =20 -/* - * 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); } =20 -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 =3D start_address + MAGIC_OFFSET_BASE; - uint64_t marker_address =3D 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) !=3D MAGIC_MARKER); - - - /* If suspended, src only iterates once, and watch_byte may never chan= ge */ - 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 =3D qtest_readb(from, watch_address); - do { - usleep(1000 * 10); - } while (qtest_readb(from, watch_address) =3D=3D watch_byte); -} - -static void check_guests_ram(QTestState *who) -{ - /* - * Our ASM test will have been incrementing one byte from each page fr= om - * 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 transit= ion - * 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 =3D false; - int bad =3D 0; - - qtest_memread(who, start_address, &first_byte, 1); - last_byte =3D first_byte; - - for (address =3D start_address + TEST_MEM_PAGE_SIZE; address < end_add= ress; - address +=3D TEST_MEM_PAGE_SIZE) - { - uint8_t b; - qtest_memread(who, address, &b, 1); - if (b !=3D last_byte) { - if (((b + 1) % 256) =3D=3D 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 =3D true; - last_byte =3D b; - } else { - bad++; - if (bad <=3D 10) { - fprintf(stderr, "Memory content inconsistency at %x" - " first_byte =3D %x last_byte =3D %x current = =3D %x" - " hit_edge =3D %x\n", - address, first_byte, last_byte, b, hit_edge); - } - } - } - } - if (bad >=3D 10) { - fprintf(stderr, "and in another %d pages", bad - 10); - } - g_assert(bad =3D=3D 0); -} - static void cleanup(const char *filename) { g_autofree char *path =3D 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 =3D NULL; + g_autofree gchar *boot_opts =3D NULL; gchar *cmd_source =3D NULL; gchar *cmd_target =3D NULL; const gchar *ignore_stderr; g_autofree char *mem_object =3D NULL; const char *kvm_opts =3D NULL; const char *arch =3D qtest_get_arch(); - const char *memory_size; + g_autofree char *memory_size =3D NULL; const char *machine_alias, *machine_opts =3D ""; g_autofree char *machine =3D NULL; - const char *bootpath =3D bootfile_get(); g_autofree char *memory_backend =3D NULL; const char *events; =20 + boot_opts =3D bootfile_get_opts(arch, &memory_size); + if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { - memory_size =3D "150M"; =20 if (g_str_equal(arch, "i386")) { machine_alias =3D "pc"; } else { machine_alias =3D "q35"; } - arch_opts =3D g_strdup_printf( - "-drive if=3Dnone,id=3Dd0,file=3D%s,format=3Draw " - "-device ide-hd,drive=3Dd0,secs=3D1,cyls=3D1,heads=3D1", bootp= ath); - start_address =3D X86_TEST_MEM_START; - end_address =3D X86_TEST_MEM_END; } else if (g_str_equal(arch, "s390x")) { - memory_size =3D "128M"; machine_alias =3D "s390-ccw-virtio"; - arch_opts =3D g_strdup_printf("-bios %s", bootpath); - start_address =3D S390_TEST_MEM_START; - end_address =3D S390_TEST_MEM_END; } else if (strcmp(arch, "ppc64") =3D=3D 0) { - memory_size =3D "256M"; - start_address =3D PPC_TEST_MEM_START; - end_address =3D PPC_TEST_MEM_END; machine_alias =3D "pseries"; machine_opts =3D "vsmt=3D8"; arch_opts =3D g_strdup_printf( - "-nodefaults -machine " PSERIES_DEFAULT_CAPABILITIES " " - "-bios %s", bootpath); + "-nodefaults -machine " PSERIES_DEFAULT_CAPABILITIES); } else if (strcmp(arch, "aarch64") =3D=3D 0) { - memory_size =3D "150M"; machine_alias =3D "virt"; machine_opts =3D "gic-version=3D3"; - arch_opts =3D g_strdup_printf("-cpu max -kernel %s", bootpath); - start_address =3D ARM_TEST_MEM_START; - end_address =3D ARM_TEST_MEM_END; + arch_opts =3D g_strdup_printf("-cpu max"); } else if (strcmp(arch, "loongarch64") =3D=3D 0) { - memory_size =3D "256M"; machine_alias =3D "virt"; - arch_opts =3D g_strdup_printf("-bios %s", bootpath); - start_address =3D LOONGARCH_TEST_MEM_START; - end_address =3D 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=3Don " "%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) =20 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); =20 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 =3D=3D 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, =3D=3D, dest_byte_d); - - check_guests_ram(to); + migrate_check_guests_ram(to); } =20 qtest_quit(to); diff --git a/tests/qtest/migration/framework.h b/tests/qtest/migration/fram= ework.h index 10761f6e287..df25d2a5830 100644 --- a/tests/qtest/migration/framework.h +++ b/tests/qtest/migration/framework.h @@ -230,8 +230,6 @@ typedef struct { } MigrateCommon; =20 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); =20 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/mis= c-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" --=20 2.53.0 From nobody Sun Nov 29 02:11:46 2026 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=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1795729684; cv=none; d=zohomail.com; s=zohoarc; b=U6f7AyL+OCDLRgLGVRf2YsuIdgFf0ZVFfSNJQENtt5Uo4RCqWxVRtJVdn7PlEiaqpWtLBAgnhu8H5xutXn19VpFYraMdL7NctumV015nPtQUwt4sfx4uxbLkVsZHMqenevsnHq4gnYqfVRVlaoQiks6ouOxEE2O/1O5yhD58A1I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795729684; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=o5MlGXrPbTCT9eaFrpJi4zE85cvQYuh9dveEG7wpC/4=; b=AK1njI1SGTTLfC7AxWD8JKospNd2Ex/f4ETvzLTYFOi9+k4LiXaqwD1M+xpxME/wTVfVju/uVrpFZDBoTXOcjXJRZmuiN1cELJhdrJGMyNT6VPC54yIDDb7Lv9a0KH04pYS4P03sZgZ4BQUEm/0OZsQbbQE2Y5hyHoUG22639hA= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17957296844909.513964508693789; Thu, 26 Nov 2026 13:48:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xWhJK-0000iJ-Qg; Thu, 26 Nov 2026 16:47:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xWhJF-0000hc-Qo for qemu-devel@nongnu.org; Thu, 26 Nov 2026 16:47:18 -0500 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xWhJD-0000Qc-Ty for qemu-devel@nongnu.org; Thu, 26 Nov 2026 16:47:17 -0500 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id C540B2283D; Thu, 26 Nov 2026 21:47:14 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 625B2134C3; Thu, 26 Nov 2026 21:47:13 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 3qzICtuoCGtRZgAAD6G6ig:T5 (envelope-from ); Thu, 26 Nov 2026 21:47:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1795729634; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o5MlGXrPbTCT9eaFrpJi4zE85cvQYuh9dveEG7wpC/4=; b=tpyI/kKcJE1B/FV/Kd7FH7rojuOs/KXsQuPw5CA8/d7ChPO6ehX38mZA1jAE5kPyQbTl6u jIAt8gUQ6p3jcuJcfhIfZXVEVECGUtuEZkpz13XIkUrIw0EPM5dZRaUsVoa4PtvGkOFOmh XhRYJ4Jv1uKidhNLcT/Fh4Zid5i1Aeg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1795729634; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o5MlGXrPbTCT9eaFrpJi4zE85cvQYuh9dveEG7wpC/4=; b=0EY0T/SJM7efr5gf+PzkOwZPGbE7Y9UZnMi7pBYUBSbwNMxKeq9UJurdP72rLuHtSspLGi NNMfCeva0QQCvbCg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1795729634; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o5MlGXrPbTCT9eaFrpJi4zE85cvQYuh9dveEG7wpC/4=; b=tpyI/kKcJE1B/FV/Kd7FH7rojuOs/KXsQuPw5CA8/d7ChPO6ehX38mZA1jAE5kPyQbTl6u jIAt8gUQ6p3jcuJcfhIfZXVEVECGUtuEZkpz13XIkUrIw0EPM5dZRaUsVoa4PtvGkOFOmh XhRYJ4Jv1uKidhNLcT/Fh4Zid5i1Aeg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1795729634; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o5MlGXrPbTCT9eaFrpJi4zE85cvQYuh9dveEG7wpC/4=; b=0EY0T/SJM7efr5gf+PzkOwZPGbE7Y9UZnMi7pBYUBSbwNMxKeq9UJurdP72rLuHtSspLGi NNMfCeva0QQCvbCg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Laurent Vivier , Paolo Bonzini Subject: [PATCH 4/5] tests/qtest/migration: Adapt wait_for_serial routine for stress.c Date: Thu, 26 Nov 2026 18:47:03 -0300 Message-ID: <20261126214704.3108327-5-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261126214704.3108327-1-farosas@suse.de> References: <20261126214704.3108327-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-11.80 / 50.00]; SUSE_INTERNAL_BYPASS(-9.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.995]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,imap1.dmz-prg2.suse.org:helo] X-Spam-Score: -11.80 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: qemu development 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 @suse.de) X-ZM-MESSAGEID: 1795729685399158500 Content-Type: text/plain; charset="utf-8" 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 --- 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/fram= ework.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; =20 /* - * 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/r= esume) + * 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=3D'A' + * B=3D'B' + * + * For stress.c: + * A=3D"/init (): INFO: RAM # GiB across # CPUs" + * B=3D"/init (): INFO: #ms copied # GB in #ms" */ void wait_for_serial(const char *side) { g_autofree char *serialpath =3D g_strdup_printf("%s/%s", tmpfs, side); FILE *serialfile =3D fopen(serialpath, "r"); + char buf[128]; + int i =3D 0; + const char *a_b[] =3D { "AB", "ABB", "ABBB", "B", "BB", "BBB", "BBBB" = }; + const char *stress[] =3D { "/init (", ": INFO: RAM" }; + const char *skip[] =3D { "[", "]" }; + const char *bad[] =3D { "panic+", "Code:", "BUG:" }; =20 - do { - int readvalue =3D fgetc(serialfile); + for (;;) { =20 - switch (readvalue) { - case 'A': - /* Fine */ - break; + if (!fgets(buf, 128, serialfile)) { + int c =3D fgetc(serialfile); =20 - case 'B': - /* It's alive! */ - fclose(serialfile); - return; + if (c =3D=3D EOF) { + usleep(1000); + fseek(serialfile, 0, SEEK_SET); + continue; + } + } + + /* look for the main patterns */ + i =3D 0; + while (i < ARRAY_SIZE(a_b)) { + if (g_str_equal(buf, a_b[i++])) { + goto found; + } + } + + i =3D 0; + while (i < ARRAY_SIZE(stress)) { + if (strstr(buf, stress[i++])) { + goto found; + } + } =20 - 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. + */ =20 - default: - fprintf(stderr, "Unexpected %d on %s serial\n", readvalue, sid= e); - g_assert_not_reached(); + i =3D 0; + while (i < ARRAY_SIZE(bad)) { + if (strstr(buf, bad[i++])) { + goto err; + } } - } while (true); + + i =3D 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); } =20 static void cleanup(const char *filename) --=20 2.53.0 From nobody Sun Nov 29 02:11:46 2026 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=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1795729684; cv=none; d=zohomail.com; s=zohoarc; b=aS4qP0BjIU00dEIurKovgWrX1cl/kn1035HNyV9aO6xGRmrYdqbjhFL80T6S3tJSMmQHEua3yifJtDbvOQslwhUm7G6BIvd5w1wVLa/N+RKhcLupjqpBz80+vKnin9YI1drOdPptfMOrs/pjmhgZUuKRUcXLRvBBackg2TK9b0Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795729684; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=AGW9z4+wx9j3qY/dLrMFmhq4C65Q2Sh+kc3FzKpBoBs=; b=QuTJK8rJ3xIAR6IVkonYdpPIQPEdLax8NX/bO9cjtqjP9T1bgPI/bwQW4iCbDnqYOHjIco+M5Iw2tuJXu2y0CfYYwuT8On+bkiJZRSd1x0Kcgt/2+e0m9NdJKeomHk+GSGNEWEAqP14sbffhuWYdqZMjtmrCAgfCvbEtklAy8+Q= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795729684389221.81708543465345; Thu, 26 Nov 2026 13:48:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xWhJc-0000jP-Ov; Thu, 26 Nov 2026 16:47:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xWhJK-0000i9-2A for qemu-devel@nongnu.org; Thu, 26 Nov 2026 16:47:22 -0500 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xWhJH-0000ir-BO for qemu-devel@nongnu.org; Thu, 26 Nov 2026 16:47:21 -0500 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3C0641FE0D; Thu, 26 Nov 2026 21:47:17 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 3225A134C3; Thu, 26 Nov 2026 21:47:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 3qzICtuoCGtRZgAAD6G6ig:T6 (envelope-from ); Thu, 26 Nov 2026 21:47:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1795729638; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AGW9z4+wx9j3qY/dLrMFmhq4C65Q2Sh+kc3FzKpBoBs=; b=R2LDMjvkCn79fdidZIb+8EOMq6yvciXv924zzNlNyHXNxUzNDJ7vpmUUbEHf1CBV08OKNj B9w9lpRxK/Cj3ffohYI3KcJb3Xm7UbomAfHB/lmrNmryhT3KHYOKNYTu0Ra24LA/dvCE0A 6hFu2/fif9nwtT7ZpbktRC6TwTAo9LU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1795729638; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AGW9z4+wx9j3qY/dLrMFmhq4C65Q2Sh+kc3FzKpBoBs=; b=GC0mBJj+/md2mYle3ZlHoBY+BaDqD5CtWg74JiX3pt94KlwyMV50dAE7R0sf9Xk+oZMyI5 2fR3FpbY8IHV3JBg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1795729637; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AGW9z4+wx9j3qY/dLrMFmhq4C65Q2Sh+kc3FzKpBoBs=; b=GVhkgA6qSyvLWtTQOJCreFQVLD6lc0rjdkN1YmTJbgLIL9l1VUUX/q1Ls7UinN1fIRKDPn 5B5B7XxPjmMR2FbvD7DjM3oABeMBLtwt4ynlEzhj+dFB3QQxkc3FFG9qvTIwK4Ug7HvRGA pxku9q+dtwL3itKvm/9NDeTljHED8ZI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1795729637; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AGW9z4+wx9j3qY/dLrMFmhq4C65Q2Sh+kc3FzKpBoBs=; b=m/z8pywZxQUIsQwAnmgOa5NUQlNjbe3KsQdXauPKAS39v/18IDSimnRb5FWmr7OpSzLODO 9jJWSin2B9vi9BCw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Laurent Vivier , Paolo Bonzini , "Maciej S. Szmigiero" , Mark Kanda , Ben Chaney Subject: [PATCH 5/5] tests/qtest/migration: Make it possible to run stress.c Date: Thu, 26 Nov 2026 18:47:04 -0300 Message-ID: <20261126214704.3108327-6-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261126214704.3108327-1-farosas@suse.de> References: <20261126214704.3108327-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-11.80 / 50.00]; SUSE_INTERNAL_BYPASS(-9.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; RCPT_COUNT_SEVEN(0.00)[7]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,imap1.dmz-prg2.suse.org:helo]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -11.80 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a07:de40:b251:101:10:150:64:2; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: qemu development 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 @suse.de) (identity @suse.de) X-ZM-MESSAGEID: 1795729685457158500 Content-Type: text/plain; charset="utf-8" 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 --- 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/bootf= ile.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" =20 /* * The boot file modifies memory area in [start_address, end_address) @@ -29,6 +30,8 @@ unsigned start_address; unsigned end_address; =20 static char *bootpath; +static char *kernelpath; +static char *initrdpath; =20 void bootfile_delete(void) { @@ -38,14 +41,30 @@ void bootfile_delete(void) unlink(bootpath); g_free(bootpath); bootpath =3D NULL; + + g_free(kernelpath); + kernelpath =3D NULL; + + g_free(initrdpath); + initrdpath =3D NULL; } =20 -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; =20 bootfile_delete(); + + if (kernel) { + kernelpath =3D g_strdup(kernel); + initrdpath =3D g_strdup("tests/migration-stress/initrd-stress.img"= ); + + g_test_message("Using guest workload \"stress.c\""); + return NULL; + } + bootpath =3D g_strdup_printf("%s/bootsect", dir); if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { /* the assembled x86 boot sector should be exactly one sector larg= e */ @@ -85,14 +104,168 @@ char *bootfile_create(const char *arch, const char *d= ir, bool suspend_me) g_assert_cmpint(fwrite(content, len, 1, bootfile), =3D=3D, 1); fclose(bootfile); =20 + g_test_message("Using guest workload \"A-B\""); + return bootpath; } =20 -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 =3D 0, size_b =3D size_gb << 30; + uint64_t n_pages, ptrs_per_lvl; + + n_pages =3D size_b >> 12; + + ptrs_per_lvl =3D n_pages >> 21; + pgtb_size +=3D ptrs_per_lvl ?: 1; + + ptrs_per_lvl >>=3D 30; + pgtb_size +=3D ptrs_per_lvl ?: 1; + + ptrs_per_lvl >>=3D 39; + pgtb_size +=3D ptrs_per_lvl ?: 1; + + ptrs_per_lvl >>=3D 48; + pgtb_size +=3D ptrs_per_lvl ?: 1; + + pgtb_size <<=3D 12; + + size_b +=3D 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 =3D (300UL << 20); + + size_b +=3D pgtables_size(size_gb); + + /* FIXME: init keeps being killed due to OOM, add an arbitrary 1/8 */ + size_b +=3D 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 =3D getenv("QTEST_MIG_APPEND"); + const char *default_opts =3D "noapic printk.time=3D1 noreplace-smp " + "cgroup_disable=3Dmemory pci=3Dnoearly console=3DttyS0"; + g_autofree char *required_opts =3D NULL; + g_autofree char *r1 =3D NULL; + g_autofree char *r2 =3D NULL; + g_autofree char *r3 =3D NULL; + + if (user_opts) { + add_ramsize =3D !strstr(user_opts, "ramsize=3D"); + add_cpus =3D !strstr(user_opts, "cpus=3D"); + /* let them remove 'quiet' by omitting it from the env var */ + add_quiet =3D false; + } else { + add_ramsize =3D add_cpus =3D add_quiet =3D true; + } + + if (add_quiet) { + r1 =3D g_strdup("quiet "); + } + + if (add_ramsize) { + r2 =3D g_strdup_printf("ramsize=3D%ld ", ramsize); + } + + if (add_cpus) { + r3 =3D g_strdup_printf("cpus=3D%ld ", cpus); + } + + required_opts =3D 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 =3D getenv("QTEST_MIG_MEM_G"); + smp =3D getenv("QTEST_MIG_SMP"); + + if (!smp) { + smp =3D "1"; + } + + if (!size_gb_str) { + size_gb_str =3D "1"; + } + + assert(!qemu_strtol(smp, NULL, 0, &n_vcpus)); + assert(n_vcpus > 0 && n_vcpus <=3D 4096); + + assert(!qemu_strtol(size_gb_str, NULL, 0, &size_gb)); + assert(size_gb > 0 && size_gb <=3D 256000); + + /* + * stress.c dirties all of "ramsize", increase the memory size to + * avoid OOM. + */ + size_b =3D rsvd_size(size_gb); + + /* Align to the next MB to not lose the fractional bytes. */ + size_b =3D QEMU_ALIGN_UP(size_b, 1UL << 20); + + if (mem_type =3D=3D MEM_TYPE_HUGETLB) { + size_b =3D QEMU_ALIGN_UP(size_b, 1UL << 30); + } + + *size_mb_str =3D 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; =20 + 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 =3D "150M"; boot =3D g_strdup_printf( @@ -128,6 +301,10 @@ void migrate_wait_for_dirty_mem(QTestState *from, QTes= tState *to) uint64_t marker_address =3D start_address + MAGIC_OFFSET; uint8_t watch_byte; =20 + 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, QTes= tState *to) =20 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 =3D 0; unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d; =20 + if (!bootpath) { + return; + } + qtest_memread(who, start_address, &dest_byte_a, 1); =20 /* Destination still running, wait for a byte to change */ diff --git a/tests/qtest/migration/bootfile.h b/tests/qtest/migration/bootf= ile.h index 4f628160f5d..a66105bc4a1 100644 --- a/tests/qtest/migration/bootfile.h +++ b/tests/qtest/migration/bootfile.h @@ -64,9 +64,10 @@ =20 #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, Migra= teCommon *args) test_mode_transfer_common(args, true, NULL); } =20 +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 =3D g_new0(char *, max_len); + char **srcp, **dstp =3D arr; + + /* +1 to skip the last element which is "" */ + srcp =3D a; + while (*(srcp + 1)) { + *dstp++ =3D *srcp++; + } + + *dstp++ =3D *b; + + /* +1 to skip the first element which is "" */ + srcp =3D c + 1; + while (*srcp) { + *dstp++ =3D *srcp++; + } + + *dstp =3D NULL; + return (GStrv)g_strdupv(arr); +} + static void set_cpr_exec_args(QTestState *who, MigrateCommon *args) { g_autofree char *qtest_from_args =3D NULL; @@ -209,8 +237,30 @@ static void set_cpr_exec_args(QTestState *who, Migrate= Common *args) =20 exec_args =3D g_strconcat(qtest_qemu_binary(migration_get_env()->qemu_= dst), " -incoming defer ", from_str, NULL); + argv =3D 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 =3D NULL; + g_auto(GStrv) head =3D NULL; + g_auto(GStrv) tail =3D NULL; + g_auto(GStrv) local_argv; + int max_len =3D g_strv_length(argv); + + tmp =3D g_strsplit(exec_args, "'", -1); + + head =3D g_strsplit(tmp[0], " ", -1); + tail =3D g_strsplit(tmp[2], " ", -1); + + local_argv =3D 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); + } } =20 static void wait_for_migration_event(QTestState *who, const char *waitfor) diff --git a/tests/qtest/migration/framework.c b/tests/qtest/migration/fram= ework.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 =3D NULL; const char *events; =20 - boot_opts =3D bootfile_get_opts(arch, &memory_size); + boot_opts =3D bootfile_get_opts(arch, args->mem_type, &memory_size); =20 if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { =20 @@ -454,6 +454,7 @@ static void migrate_mem_type_cleanup(MemType type) =20 int migrate_start(QTestState **from, QTestState **to, MigrateStart *args) { + MigrationTestEnv *env =3D migration_get_env(); g_autofree gchar *cmd_source =3D NULL; g_autofree gchar *cmd_target =3D NULL; g_autoptr(QList) capabilities =3D migrate_start_get_qmp_capabilities(a= rgs); @@ -464,7 +465,7 @@ int migrate_start(QTestState **from, QTestState **to, M= igrateStart *args) =20 dst_state =3D (QTestMigrationState) { }; src_state =3D (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 =3D args->suspend_me; =20 if (migrate_args(&cmd_source, &cmd_target, args)) { @@ -1063,6 +1064,12 @@ MigrationTestEnv *migration_get_env(void) env->arch =3D qtest_get_arch(); env->is_x86 =3D !strcmp(env->arch, "i386") || !strcmp(env->arch, "x86_= 64"); =20 + env->kernel =3D 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 =3D 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/fram= ework.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; =20 @@ -53,6 +54,7 @@ typedef struct MigrationTestEnv { const char *arch; const char *qemu_src; const char *qemu_dst; + const char *kernel; char *tmpfs; } MigrationTestEnv; =20 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/p= lain", test_multifd_postcopy_preempt_recovery); - if (env->is_x86) { + /* + * TODO: The suspend test writes to the guest memory. That's not y= et + * 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 =3D NULL; const char *bootpath; =20 - bootpath =3D bootfile_create(qtest_get_arch(), tmpfs, false); + bootpath =3D bootfile_create(qtest_get_arch(), NULL, tmpfs, false); cmd =3D g_strdup_printf("-accel kvm,dirty-ring-size=3D4096 " "-name dirtylimit-test,debug-threads=3Don " "-m 150M -smp 1 " @@ -1077,7 +1077,11 @@ static void test_dirty_limit(char *name, MigrateComm= on *args) =20 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(Migrati= onTestEnv *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/canc= el", + test_multifd_postcopy_tcp_cancel); + } } =20 #ifdef CONFIG_RDMA --=20 2.53.0