From nobody Sat Sep 26 23:03:02 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=1787933034; cv=none; d=zohomail.com; s=zohoarc; b=NnYO/VaXkyS/Za6+8pKn2Zv0oBmcMNGu/Y51oNwlfHrIEkry7e3WdMWYDKDLZFrnoV18rteCK4NDtuSt9oznZ4yfTgdhFq9OTwZCQjufOowYvpGjM8/yuMu6OWoYdYgoNfnQN8dfqdYvpxNG9bjvdx9VAwjCwPz0PsW0d03TR+k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787933034; 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=3RWZvgUuba1ly+5mbsdaLDsGlIp3+oJgpWbcXQM0UqA=; b=UhxByF26FT5LsHZ62ng5iWJUkEwmILBPXewjG2Zg/R+t3n0g+069GL33gHuHcIiiIxNiaVhw6SreJbf7Y+vSGUUAZg4vt5EMGosDPt0ve8waqEsLLFAq5b99gzrRnaSrTk7IgqEd4m4sekqt01AnCa/v3Dt3q3WwHYg0M7eVyE0= 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 1787933034200388.8779039419509; Fri, 28 Aug 2026 09:03:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyyy-0001Ju-QM; Fri, 28 Aug 2026 11:59:08 -0400 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 1wzyyv-0001J5-CW for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:05 -0400 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 1wzyyr-00089p-Gr for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:05 -0400 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 DD52321CA1; Fri, 28 Aug 2026 15:58:50 +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 A87B213674; Fri, 28 Aug 2026 15:58:49 +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 aPwnHjmwkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:58:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932735; 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=3RWZvgUuba1ly+5mbsdaLDsGlIp3+oJgpWbcXQM0UqA=; b=K4bD2UaUtzCCedKSwG5d9satH07BrgyuIi6DftGh7OoT07dDOHHtHFzYBQN/0c1P/XgpEf TWjcPnGnvEMOG4kguv5Sx/FyMAZbHAOySNkxy/jRpBbLoZH+5mdmnfat8JzbLdIbAGsDPf ZecE7d/7li+P39sUOTwcCk6lTnbhFOQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932735; 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=3RWZvgUuba1ly+5mbsdaLDsGlIp3+oJgpWbcXQM0UqA=; b=sUzBXBxtTF5JRsEoZnSHGemlQKm5aywDDgt1GswuPP8he1xsEFeQf7rELlwMoAzIOzSGGP IqQQwBzLv0t5xxDA== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=hW+JiDGV; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="a/WSIhlZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932730; 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=3RWZvgUuba1ly+5mbsdaLDsGlIp3+oJgpWbcXQM0UqA=; b=hW+JiDGVyx5kgWWh6eoNHWmJmIFoqcGodYWTDJ+21z6TK+mJJfyvAPQxQOGHXQvBehP/o6 9DpvHil0EaNqY5LmL/V8pK5vpo0JN1IUoG+wwO4MFfuF7X61UVk7fd0TiRkZTOsVNPaHGx FrmPoCXXfImAkhLj7SWgAEsG/IAReS0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932730; 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=3RWZvgUuba1ly+5mbsdaLDsGlIp3+oJgpWbcXQM0UqA=; b=a/WSIhlZ3Rp5ANyZUVhTb2vZukgHD/AHSYr6ha0iJ+4oZiNqSk/5ignkU8lGHVjxOzME9O wrnbDiLCCjr7BJCA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Aadeshveer Singh , Juraj Marcin Subject: [PULL v2 01/30] migration: Propagate error in postcopy setup functions Date: Fri, 28 Aug 2026 12:58:16 -0300 Message-ID: <20260828155845.2874508-2-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.01 X-Rspamd-Queue-Id: DD52321CA1 X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spamd-Result: default: False [-3.01 / 50.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)[]; FROM_EQ_ENVFROM(0.00)[]; FREEMAIL_CC(0.00)[redhat.com,gmail.com]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:email,suse.de:mid,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; RCPT_COUNT_THREE(0.00)[4]; DKIM_TRACE(0.00)[suse.de:+] 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) (identity @suse.de) X-ZM-MESSAGEID: 1787933037264154100 Content-Type: text/plain; charset="utf-8" From: Aadeshveer Singh Modernize error handling in postcopy_ram_incoming_setup() and postcopy_temp_pages_setup() by replacing error_reports and local error handling with standard Error propagation. Replace use of strerror() on errno with error_setg_errno() for modular handling of errors and change return values to -1 on failure as no caller checks the actual return value. Signed-off-by: Aadeshveer Singh Reviewed-by: Peter Xu Reviewed-by: Juraj Marcin Signed-off-by: Peter Xu Signed-off-by: Fabiano Rosas --- migration/postcopy-ram.c | 43 +++++++++++++++++----------------------- migration/postcopy-ram.h | 2 +- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index a3314d3180d..120828a2ead 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1462,10 +1462,9 @@ retry: return NULL; } =20 -static int postcopy_temp_pages_setup(MigrationIncomingState *mis) +static int postcopy_temp_pages_setup(MigrationIncomingState *mis, Error **= errp) { PostcopyTmpPage *tmp_page; - int err; unsigned i, channels; void *temp_page; =20 @@ -1485,11 +1484,11 @@ static int postcopy_temp_pages_setup(MigrationIncom= ingState *mis) temp_page =3D mmap(NULL, mis->largest_page_size, PROT_READ | PROT_= WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (temp_page =3D=3D MAP_FAILED) { - err =3D errno; - error_report("%s: Failed to map postcopy_tmp_pages[%d]: %s", - __func__, i, strerror(err)); + error_setg_errno(errp, errno, + "%s: Failed to map postcopy_tmp_pages[%d]", + __func__, i); /* Clean up will be done later */ - return -err; + return -1; } tmp_page->tmp_huge_page =3D temp_page; /* Initialize default states for each tmp page */ @@ -1503,11 +1502,10 @@ static int postcopy_temp_pages_setup(MigrationIncom= ingState *mis) PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (mis->postcopy_tmp_zero_page =3D=3D MAP_FAILED) { - err =3D errno; mis->postcopy_tmp_zero_page =3D NULL; - error_report("%s: Failed to map large zero page %s", - __func__, strerror(err)); - return -err; + error_setg_errno(errp, errno, "%s: Failed to map large zero page", + __func__); + return -1; } =20 memset(mis->postcopy_tmp_zero_page, '\0', mis->largest_page_size); @@ -1515,15 +1513,13 @@ static int postcopy_temp_pages_setup(MigrationIncom= ingState *mis) return 0; } =20 -int postcopy_ram_incoming_setup(MigrationIncomingState *mis) +int postcopy_ram_incoming_setup(MigrationIncomingState *mis, Error **errp) { - Error *local_err =3D NULL; - /* Open the fd for the kernel to give us userfaults */ mis->userfault_fd =3D uffd_open(O_CLOEXEC | O_NONBLOCK); if (mis->userfault_fd =3D=3D -1) { - error_report("%s: Failed to open userfault fd: %s", __func__, - strerror(errno)); + error_setg_errno(errp, errno, "%s: Failed to open userfault fd", + __func__); return -1; } =20 @@ -1531,8 +1527,7 @@ int postcopy_ram_incoming_setup(MigrationIncomingStat= e *mis) * Although the host check already tested the API, we need to * do the check again as an ABI handshake on the new fd. */ - if (!ufd_check_and_apply(mis->userfault_fd, mis, &local_err)) { - error_report_err(local_err); + if (!ufd_check_and_apply(mis->userfault_fd, mis, errp)) { return -1; } =20 @@ -1544,8 +1539,8 @@ int postcopy_ram_incoming_setup(MigrationIncomingStat= e *mis) /* Now an eventfd we use to tell the fault-thread to quit */ mis->userfault_event_fd =3D eventfd(0, EFD_CLOEXEC); if (mis->userfault_event_fd =3D=3D -1) { - error_report("%s: Opening userfault_event_fd: %s", __func__, - strerror(errno)); + error_setg_errno(errp, errno, "%s: Opening userfault_event_fd", + __func__); close(mis->userfault_fd); return -1; } @@ -1557,12 +1552,11 @@ int postcopy_ram_incoming_setup(MigrationIncomingSt= ate *mis) =20 /* Mark so that we get notified of accesses to unwritten areas */ if (foreach_not_ignored_block(ram_block_enable_notify, mis)) { - error_report("ram_block_enable_notify failed"); + error_setg(errp, "ram_block_enable_notify failed"); return -1; } =20 - if (postcopy_temp_pages_setup(mis)) { - /* Error dumped in the sub-function */ + if (postcopy_temp_pages_setup(mis, errp)) { return -1; } =20 @@ -1727,7 +1721,7 @@ int postcopy_request_shared_page(struct PostCopyFD *p= cfd, RAMBlock *rb, g_assert_not_reached(); } =20 -int postcopy_ram_incoming_setup(MigrationIncomingState *mis) +int postcopy_ram_incoming_setup(MigrationIncomingState *mis, Error **errp) { g_assert_not_reached(); } @@ -2199,9 +2193,8 @@ int postcopy_incoming_setup(MigrationIncomingState *m= is, Error **errp) * shouldn't be doing anything yet so don't actually expect requests */ if (migrate_postcopy_ram()) { - if (postcopy_ram_incoming_setup(mis)) { + if (postcopy_ram_incoming_setup(mis, errp)) { postcopy_ram_incoming_cleanup(mis); - error_setg(errp, "Failed to setup incoming postcopy RAM blocks= "); return -1; } } diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h index a080dd65a77..98d918713f5 100644 --- a/migration/postcopy-ram.h +++ b/migration/postcopy-ram.h @@ -23,7 +23,7 @@ bool postcopy_ram_supported_by_host(MigrationIncomingStat= e *mis, * Make all of RAM sensitive to accesses to areas that haven't yet been wr= itten * and wire up anything necessary to deal with it. */ -int postcopy_ram_incoming_setup(MigrationIncomingState *mis); +int postcopy_ram_incoming_setup(MigrationIncomingState *mis, Error **errp); =20 /* * Initialise postcopy-ram, setting the RAM to a state where we can go into --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932778; cv=none; d=zohomail.com; s=zohoarc; b=V06BPLBemRXS5n2xPY/VKkiKR1+KcEDoejmsf3ccetpYsWHyu4AByCvR+VEKj852mCxnPBkeSRbOGQ84xQ/gXz0UJU2YFrTqsZWTmdPmHWcS5rW8WPpEBifuVQwkTtYuLrU2NtbcOcvniIFbww1ySKQ65ozKE0pV8BmfRedm7bY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932778; 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=ewaRFj4nvWUr8moe8ioeqzVqPOi9UFniYimbaeaZ+qs=; b=Hj8H6KPZeV7Dd2RKX8y3E0K3uhmgRTRGPtxhod6B4mLK1vwMx0UOaewOAs9QhF4C+drXbHGTGwnbLkxLAdkTAS/8BwBhGdxCFyFlcLbkwqkYNeJb62SLjLaCVxlXH/qDADaEUVrHS310uYtCT/jJ2eSgvogyZXl4scc2SNvWSow= 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 1787932778010829.739581836828; Fri, 28 Aug 2026 08:59:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyyz-0001KP-GF; Fri, 28 Aug 2026 11:59:09 -0400 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 1wzyyv-0001JE-Nw for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:05 -0400 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 1wzyys-0008Af-PA for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:05 -0400 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 653301F7B9; Fri, 28 Aug 2026 15:58:52 +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 29E6913675; Fri, 28 Aug 2026 15:58:50 +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 oNzeOjqwkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:58:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932736; 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=ewaRFj4nvWUr8moe8ioeqzVqPOi9UFniYimbaeaZ+qs=; b=CxCooevI2Qi2rQnerAOa97pvSGQEjyc8K6Q5wzcWnMsJXlnwDf4bsqEN/7xyWdWO1IrYU+ I8rA16FawvXLvTQDb62ICRyAizC9TnTObK0Ljga4uL8S3njbTIGoDFyBvCXbM7eZLBCFmv LMvyMGGsHz1zG3J1FeXukw2M/Qmt6F0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932736; 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=ewaRFj4nvWUr8moe8ioeqzVqPOi9UFniYimbaeaZ+qs=; b=zKG9A1kM7FDJS477erF8C4VARC4GWM3KvMJG4U+InjA4/H5jGRqsrWHNEXun9fifg+TxqC BjGFqyVizq3S/fAw== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932732; 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=ewaRFj4nvWUr8moe8ioeqzVqPOi9UFniYimbaeaZ+qs=; b=ei0ti1DJVI2Bi0TsyHqVC2l9UB40p+AwCgSrp6lLmpTRFCAD+strJozUTEO1KKbL+y5pIG 99M75XTV85aeRPmfGVdzyKL0ZZib58MRIlUQ3R5jffzgwrFWPh+Sf2UODEQAz2BWdCYDU2 Esya6yHgnk0UEgoBxEl/EqAlW63Dflc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932732; 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=ewaRFj4nvWUr8moe8ioeqzVqPOi9UFniYimbaeaZ+qs=; b=JVUZe63NfjPvq5M614Kd8EqKIFYQv/forZhzQq3hCzduLXYHkZZS0VWYMybFj08zozPfPN BuKsUgsbqmfm5PAQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Aadeshveer Singh , Juraj Marcin Subject: [PULL v2 02/30] migration: Extract blocktime marking helper Date: Fri, 28 Aug 2026 12:58:17 -0300 Message-ID: <20260828155845.2874508-3-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.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]; RCVD_TLS_ALL(0.00)[]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; 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)[]; FREEMAIL_CC(0.00)[redhat.com,gmail.com]; RCPT_COUNT_THREE(0.00)[4]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:mid,suse.de:email]; RCVD_COUNT_TWO(0.00)[2]; FREEMAIL_ENVRCPT(0.00)[gmail.com] 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: 1787932782234154100 Content-Type: text/plain; charset="utf-8" From: Aadeshveer Singh Use new function try_mark_postcopy_blocktim_begin() to call mark_postcopy_blocktime_begin if page was not received and return if it actually marked it. This will help in having a cleaner API to call mark_postcopy_blocktime_begin as it requires the page to not be received by asserting on it's existance in RAMBlock->receivedmap. Signed-off-by: Aadeshveer Singh Reviewed-by: Peter Xu Reviewed-by: Juraj Marcin Signed-off-by: Peter Xu Signed-off-by: Fabiano Rosas --- migration/migration.c | 24 ++---------------------- migration/postcopy-ram.c | 39 +++++++++++++++++++++++++++++++++++++++ migration/postcopy-ram.h | 3 +++ 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 9df6da131ce..a30779f37c8 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -577,32 +577,12 @@ int migrate_send_rp_req_pages(MigrationIncomingState = *mis, RAMBlock *rb, ram_addr_t start, uint64_t had= dr, uint32_t tid) { - void *aligned =3D (void *)(uintptr_t)ROUND_DOWN(haddr, qemu_ram_pagesi= ze(rb)); - bool received =3D false; - - WITH_QEMU_LOCK_GUARD(&mis->page_request_mutex) { - received =3D ramblock_recv_bitmap_test_byte_offset(rb, start); - if (!received) { - if (!g_tree_lookup(mis->page_requested, aligned)) { - /* - * The page has not been received, and it's not yet in the - * page request list. Queue it. Set the value of element - * to 1, so that things like g_tree_lookup() will return - * TRUE (1) when found. - */ - g_tree_insert(mis->page_requested, aligned, (gpointer)1); - qatomic_inc(&mis->page_requested_count); - trace_postcopy_page_req_add(aligned, mis->page_requested_c= ount); - } - mark_postcopy_blocktime_begin(haddr, tid, rb); - } - } - /* + * If not able to mark page for blocktime it must already be present. * If the page is there, skip sending the message. We don't even need= the * lock because as long as the page arrived, it'll be there forever. */ - if (received) { + if (!try_mark_postcopy_blocktime_begin(mis, rb, start, haddr, tid)) { return 0; } =20 diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 120828a2ead..7dead1c68fc 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1054,6 +1054,37 @@ static void blocktime_fault_inject(PostcopyBlocktime= Context *ctx, trace_postcopy_blocktime_begin(addr, time, cpu, !!head); } =20 +/* + * Take @page_request_mutex and try marking postcopy blocktime begin. + * Return true if marking is successful and false if page alredy exists. + */ +bool try_mark_postcopy_blocktime_begin(MigrationIncomingState *mis, + RAMBlock *rb, ram_addr_t start, + uint64_t haddr, uint32_t tid) +{ + bool received =3D false; + void *aligned =3D (void *)(uintptr_t)ROUND_DOWN(haddr, qemu_ram_pagesi= ze(rb)); + + WITH_QEMU_LOCK_GUARD(&mis->page_request_mutex) { + received =3D ramblock_recv_bitmap_test_byte_offset(rb, start); + if (!received) { + if (!g_tree_lookup(mis->page_requested, aligned)) { + /* + * The page has not been received, and it's not yet in the + * page request list. Queue it. Set the value of element + * to 1, so that things like g_tree_lookup() will return + * TRUE (1) when found. + */ + g_tree_insert(mis->page_requested, aligned, (gpointer)1); + qatomic_inc(&mis->page_requested_count); + trace_postcopy_page_req_add(aligned, mis->page_requested_c= ount); + } + mark_postcopy_blocktime_begin((uint64_t)aligned, tid, rb); + } + } + return !received; +} + /* * This function is being called when pagefault occurs. It tracks down vCPU * blocking time. It's protected by @page_request_mutex. @@ -1749,6 +1780,14 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, u= int32_t ptid, RAMBlock *rb) { } + +bool try_mark_postcopy_blocktime_begin(MigrationIncomingState *mis, + RAMBlock *rb, ram_addr_t start, + uint64_t haddr, uint32_t tid) +{ + g_assert_not_reached(); + return false; +} #endif =20 /* -----------------------------------------------------------------------= -- */ diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h index 98d918713f5..ea879f0bc6f 100644 --- a/migration/postcopy-ram.h +++ b/migration/postcopy-ram.h @@ -196,6 +196,9 @@ void postcopy_preempt_new_channel(MigrationIncomingStat= e *mis, QEMUFile *file); void postcopy_preempt_setup(MigrationState *s); int postcopy_preempt_establish_channel(MigrationState *s); bool postcopy_is_paused(MigrationStatus status); +bool try_mark_postcopy_blocktime_begin(MigrationIncomingState *mis, + RAMBlock *rb, ram_addr_t start, + uint64_t haddr, uint32_t tid); void mark_postcopy_blocktime_begin(uintptr_t addr, uint32_t ptid, RAMBlock *rb); =20 --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932980; cv=none; d=zohomail.com; s=zohoarc; b=RwQrgh8uTxRHem8WYLBnhaRI5tiHxsTSFzTunwU+EfclCow1oqW0PO7wzEB7k14ufm6P7RWu7Bpgr46agVkAaPxrGJUn3WpxfkmrxdnHIeI6B2CCam3Yi2DGU22Ah+5KKvWMxCSarykxTIH/Z8uLViuA+5YJ5jXd/32MQUnH0eg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932980; 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=Rb8Z5SCDyJWp7TdpiITGRQvtQ0lXojHnbL+MAwG9tnw=; b=NrqmwZYCqEcrqYmMauBa/1yYj+++Ue/px0ylxjKC3DUIOCb7cPtqsKKeGUig+fEGsQo7CSPpLjJmFGi3UGkhSl1cWQaNTSUXAV6XfEpGpysxc8L7B6qZG0CDKOsXYkLL00fVhvnYgAREZUxvxRdYtHEwp9tTgli7RFh1rrCujLw= 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 1787932980925919.1744085819199; Fri, 28 Aug 2026 09:03:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyz0-0001Kk-Rh; Fri, 28 Aug 2026 11:59:10 -0400 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 1wzyyw-0001JY-3w for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:07 -0400 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wzyyt-0008BB-BK for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:05 -0400 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 DC2B51FD66; Fri, 28 Aug 2026 15:58:53 +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 A05FC13686; Fri, 28 Aug 2026 15:58:52 +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 QBUqHDywkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:58:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932738; 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=Rb8Z5SCDyJWp7TdpiITGRQvtQ0lXojHnbL+MAwG9tnw=; b=fPzYQ+fafM6yfMYiPJR+WziDDACJnLy0KU2dp3KnztpEWRCfYX4yNeV8HNvMozKQ27+enE cVHQZZ4ROKmFPyfjRb9Z+X+nb/qB9/xDH4Y+Wd2YuDIXS4sklJXk31Wf8PbenRN+lR/zMC UVslGR5Iii/WJYCAmbk8RtHXv9A/dw4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932738; 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=Rb8Z5SCDyJWp7TdpiITGRQvtQ0lXojHnbL+MAwG9tnw=; b=Z/pcjmZ/dA3MDOTTEQ8Wkj5wVGkVAfsS+9xDI5WIvZyF2wIkW7IEPE1Cr6yiajm7UvbOAv BYtf1/e6j2OrZ8BQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932733; 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=Rb8Z5SCDyJWp7TdpiITGRQvtQ0lXojHnbL+MAwG9tnw=; b=Rb4BiYoZvWBWsky638zse+ukJU/2b/sFkzNfPgtE+GhIbOovMKUp+xRYTOWbSRUHpEdsrd kATQsdPvy8q0cZCO2DaffcGy4pK/IFqmswon+UHnG1cGiGcn6prcWxiTzlSENwkW51b090 dDOEjj1A5OzztL7wq8fb37dVTcf2c24= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932733; 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=Rb8Z5SCDyJWp7TdpiITGRQvtQ0lXojHnbL+MAwG9tnw=; b=kk7sJuEDnflcevRrIGZvpeutaA8rn1V+I+0j8G27YNiznACoGjsHGePunlAztgzUrEs2IV 0kbWsQLAqmpI7iBw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Aadeshveer Singh , Juraj Marcin Subject: [PULL v2 03/30] migration: Rename postcopy_listen_thread_bh Date: Fri, 28 Aug 2026 12:58:18 -0300 Message-ID: <20260828155845.2874508-4-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.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]; RCVD_TLS_ALL(0.00)[]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; 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)[]; FREEMAIL_CC(0.00)[redhat.com,gmail.com]; RCPT_COUNT_THREE(0.00)[4]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:mid,suse.de:email]; RCVD_COUNT_TWO(0.00)[2]; FREEMAIL_ENVRCPT(0.00)[gmail.com] 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=195.135.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, 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: 1787932982367158500 Content-Type: text/plain; charset="utf-8" From: Aadeshveer Singh Rename postcopy_listen_thread_bh to postcopy_incoming_complete_bh for a more robust naming scheme. This will allow fast snapshot load to use this bh funciton directly to cleanup the incoming state. Signed-off-by: Aadeshveer Singh Reviewed-by: Peter Xu Reviewed-by: Juraj Marcin Signed-off-by: Peter Xu Signed-off-by: Fabiano Rosas --- migration/postcopy-ram.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 7dead1c68fc..2286d25f8c6 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -2109,7 +2109,7 @@ bool postcopy_is_paused(MigrationStatus status) status =3D=3D MIGRATION_STATUS_POSTCOPY_RECOVER_SETUP; } =20 -static void postcopy_listen_thread_bh(void *opaque) +static void postcopy_incoming_complete_bh(void *opaque) { MigrationState *s =3D migrate_get_current(); MigrationIncomingState *mis =3D migration_incoming_get_current(); @@ -2217,7 +2217,7 @@ out: rcu_unregister_thread(); postcopy_state_set(POSTCOPY_INCOMING_END); =20 - migration_bh_schedule(postcopy_listen_thread_bh, NULL); + migration_bh_schedule(postcopy_incoming_complete_bh, NULL); =20 object_unref(OBJECT(migr)); =20 --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932778; cv=none; d=zohomail.com; s=zohoarc; b=JKG6oSuQkgnbWCfbMLzQVSvu8iuVSt6mo8g6rzhpyprs8bU3aFv45FrNFjBWPtsbcuxfZnnBOs8yLv9gMSJagKFTksbawzSyQOmgz+VXjWTIUEjk6YOnD8ByxBVDUq3rYRFLdqU5onHDx3WnXPiUWiNZzZI+iYSRGRvYaRRJqFM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932778; 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=1OFQJUWDbKjObiV52ezMiOfXjlvswKMRphGWikfDBLk=; b=Oo6aglMMVUhckVZNvM87SJTZbB+dek/lg9YLLfc0/F/0Q7I2Sht9Q25AYVwzBdKPjhjQWgSTfO4NolCcPj1WncK6r+d7EzHBzBtrT2uJx7R88avIwUhVMdPhKacy3F6/RLbipl1B7bEZVhukizpGsGPn3fyZWDQHMZoYMXw+R0M= 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 1787932778082782.8393728180721; Fri, 28 Aug 2026 08:59:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyz1-0001Ko-0N; Fri, 28 Aug 2026 11:59:11 -0400 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 1wzyyz-0001KO-7S for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:09 -0400 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 1wzyyw-0008CG-3X for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:08 -0400 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 8216F221E6; Fri, 28 Aug 2026 15:58:55 +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 215B413687; Fri, 28 Aug 2026 15:58:53 +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 KFHGOD2wkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:58:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932739; 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=1OFQJUWDbKjObiV52ezMiOfXjlvswKMRphGWikfDBLk=; b=B2Ccvgd1ABNUkiTeoLSaU0icwjY5g2ts7/7U+mbGC97q1DKRnvcbrKWduFBnJdYiyDm6d+ cJgWsB2a2T9fam/EshOTFsDu7vRYAxKZYUNgEKlesDc1bDKRRgFpojrzjiNgd49+znGkqO 7xBIqBYlnp/TVDYQtXy732ScQjh+Ajw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932739; 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=1OFQJUWDbKjObiV52ezMiOfXjlvswKMRphGWikfDBLk=; b=n0wA3laYV0t1Rt+X7PPjF3HKbCg04ad1QewwkXKmpy8AGMyJlDLt/ZbmZm3vM8xr5bjt4M j4ySbglNrANqIQCg== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=kBMVoUJ2; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=qALlR4VF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932735; 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=1OFQJUWDbKjObiV52ezMiOfXjlvswKMRphGWikfDBLk=; b=kBMVoUJ28uMPoKq0sQI8RNtdgAvzJYW92+as/mwstig/MSesHCEyZyFFzAPYZ7WMV8GC8L wdPpRoHOmKInI2y62//msqVl54MLnjS/+A7lRJd/dJxCYt97cT0kpuhqPXABDDavvTXoCX wSH6LqWuercrlLCbLP2TFF4gZ/JiVRk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932735; 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=1OFQJUWDbKjObiV52ezMiOfXjlvswKMRphGWikfDBLk=; b=qALlR4VFyxC7KrpCIbM6mR358wUGTmuIQuUfRKHMGvblcOZOwcJfITDPcMS2FTM7L+Lqj/ Dt9FfOpYpFPC5dDQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Aadeshveer Singh , Juraj Marcin Subject: [PULL v2 04/30] migration: Use file_bmap for RAMBlock during incoming file load Date: Fri, 28 Aug 2026 12:58:19 -0300 Message-ID: <20260828155845.2874508-5-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Queue-Id: 8216F221E6 X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; 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)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; RCVD_TLS_ALL(0.00)[]; FREEMAIL_CC(0.00)[redhat.com,gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:email,suse.de:mid,imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; RCPT_COUNT_THREE(0.00)[4]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Spam-Score: -3.01 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) (identity @suse.de) X-ZM-MESSAGEID: 1787932782231158500 Content-Type: text/plain; charset="utf-8" From: Aadeshveer Singh Replace the temporary bitmap with the existing file_bmap attribute of the RAMBlock. This acts as a preparatory change for the upcoming fast snapshot load feature. Reusing this bitmap allows the destination to track page types during a postcopy load, enabling faster, direct placement of zero pages. Since file_bmap is currently only utilized during the migration save phase, it can be safely repurposed during the load phase without introducing conflicts. Signed-off-by: Aadeshveer Singh Reviewed-by: Peter Xu Reviewed-by: Juraj Marcin Signed-off-by: Peter Xu Signed-off-by: Fabiano Rosas --- migration/ram.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index b6eb842746a..7fa4774246a 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -252,6 +252,17 @@ int foreach_not_ignored_block(RAMBlockIterFunc func, v= oid *opaque) return ret; } =20 +static void ramblock_file_bmap_init(void) +{ + RAMBlock *rb; + + RAMBLOCK_FOREACH_NOT_IGNORED(rb) { + assert(!rb->file_bmap); + size_t size =3D rb->max_length >> qemu_target_page_bits(); + rb->file_bmap =3D bitmap_new(size); + } +} + static void ramblock_recv_map_init(void) { RAMBlock *rb; @@ -3755,6 +3766,9 @@ static int ram_load_setup(QEMUFile *f, void *opaque, = Error **errp) { xbzrle_load_setup(); ramblock_recv_map_init(); + if (migrate_mapped_ram()) { + ramblock_file_bmap_init(); + } =20 return 0; } @@ -3772,8 +3786,8 @@ static int ram_load_cleanup(void *opaque) xbzrle_load_cleanup(); =20 RAMBLOCK_FOREACH_NOT_IGNORED(rb) { - g_free(rb->receivedmap); - rb->receivedmap =3D NULL; + g_clear_pointer(&rb->receivedmap, g_free); + g_clear_pointer(&rb->file_bmap, g_free); } =20 return 0; @@ -4148,11 +4162,18 @@ err: static void parse_ramblock_mapped_ram(QEMUFile *f, RAMBlock *block, ram_addr_t length, Error **errp) { - g_autofree unsigned long *bitmap =3D NULL; MappedRamHeader header; size_t bitmap_size; long num_pages; =20 + if (length > block->max_length) { + error_setg(errp, + "mapped-ram header length %" PRIu64 " exceeds " + "RAMBlock(\"%s\") max_length %" PRIu64, + (uint64_t)length, block->idstr, (uint64_t)block->max_le= ngth); + return; + } + if (!mapped_ram_read_header(f, &header, errp)) { return; } @@ -4180,14 +4201,14 @@ static void parse_ramblock_mapped_ram(QEMUFile *f, = RAMBlock *block, num_pages =3D length / header.page_size; bitmap_size =3D BITS_TO_LONGS(num_pages) * sizeof(unsigned long); =20 - bitmap =3D g_malloc0(bitmap_size); - if (qemu_get_buffer_at(f, (uint8_t *)bitmap, bitmap_size, + if (qemu_get_buffer_at(f, (uint8_t *)block->file_bmap, bitmap_size, header.bitmap_offset) !=3D bitmap_size) { error_setg(errp, "Error reading dirty bitmap"); return; } =20 - if (!read_ramblock_mapped_ram(f, block, num_pages, bitmap, errp)) { + if (!read_ramblock_mapped_ram(f, block, num_pages, block->file_bmap, + errp)) { return; } =20 --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932864; cv=none; d=zohomail.com; s=zohoarc; b=UC8tJ5egOaxtgU2ip6uXrmHjs8P72jQP7E0mULWKwB0Jn3+pXI82rp16n4Lhot7hr7TJCN7XeyTKVZHK8xjKHehAA8dkC6z+pQxjjubhvAKIwTxAhf4Ua+NwuU9SDfdg4mN3l0vnSq7BZioUONgkIQ2jTsZWNxKwQDzA7ltGX9k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932864; 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=rrepw8xFVIYK0eTpXHlcG4uSiRXY3zAh8X76xJ5QxIo=; b=RcKStzX3nlAtpFFISj0M/CyWpUWoz7q8spwWEJ0uBo84662LIKiwv4tXiEuyV7DDYkx8ntrsIUlJOVMXVzQUZtM7/cGh8kpT3QN5VK7K51Qok9suwXdByZzjE+bywLvg4aLVmqA9e1UM1KDab09ZYHV/uFhIyUr9EsRJSWVsckU= 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 1787932864723696.8277255121578; Fri, 28 Aug 2026 09:01:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyz2-0001Lx-P0; Fri, 28 Aug 2026 11:59:12 -0400 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 1wzyz0-0001Kj-OD for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:10 -0400 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 1wzyyx-0008Dq-Fw for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:10 -0400 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 F18AB21B5E; Fri, 28 Aug 2026 15:58:57 +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 96E2C13688; Fri, 28 Aug 2026 15:58:55 +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 qErQGT+wkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:58:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932742; 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=rrepw8xFVIYK0eTpXHlcG4uSiRXY3zAh8X76xJ5QxIo=; b=T4088HU+4G0miahE3GuLt3IL8ctNeH0DcblbdzhFKHJzGTSArQGo8yqYiQpoLaXLqGtRVX uaIfevz89K/Tj+jWc0B5roRPiWsu01b4SDuDwNRbK/7aODhHVsg8Ag54dgPx+hSh+AoWXw v4NskzBKN1NBM2a/iGAWZyZaVkPC4Ag= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932742; 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=rrepw8xFVIYK0eTpXHlcG4uSiRXY3zAh8X76xJ5QxIo=; b=RV8bolo4RyToC4v69MbHzZE/01l794BQV/e+0Hy+bQcn5TmBkyg/BknCvYvAkO6xNICK7F yFtZAVAZWnLHXjAA== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932737; 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=rrepw8xFVIYK0eTpXHlcG4uSiRXY3zAh8X76xJ5QxIo=; b=tRDVqWSl26rOl/YWrH57X2HShMZW+mibcwyRisdco1a4zuUmoBb7Xao72Ea8I4CE6Hktid 7LhtnqHScFWBBYMtoElEtTXPwRFXHpm7DGih52kktsjQmpf0/+e9OAIHnYu+qgWmVTwM35 /pjFekbFGqQvN+nJszg/zmfWAuy4PF0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932737; 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=rrepw8xFVIYK0eTpXHlcG4uSiRXY3zAh8X76xJ5QxIo=; b=zZIBMB42I9MrUJCAgz9h6tEd+9eGfYxDwJVF0Zkf3YdRZK5od9R+vn7RudCqlc4Yr92cP+ mxjtO5h0HxjlhHBg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Aadeshveer Singh , Juraj Marcin Subject: [PULL v2 05/30] migration: Make qemu_get_buffer_at() thread-safe Date: Fri, 28 Aug 2026 12:58:20 -0300 Message-ID: <20260828155845.2874508-6-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.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]; RCVD_TLS_ALL(0.00)[]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; 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)[]; FREEMAIL_CC(0.00)[redhat.com,gmail.com]; RCPT_COUNT_THREE(0.00)[4]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:mid,imap1.dmz-prg2.suse.org:helo]; RCVD_COUNT_TWO(0.00)[2]; FREEMAIL_ENVRCPT(0.00)[gmail.com] 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) (identity @suse.de) X-ZM-MESSAGEID: 1787932866626154100 Content-Type: text/plain; charset="utf-8" From: Aadeshveer Singh Remove the internal QEMUFile error state modification from qemu_get_buffer_at(). This function is called by two functions, both of which already check for unexpected return values and handle their own error reporting. Removing this shared state modification makes qemu_get_buffer_at() strictly thread-safe for concurrent disk reads, serving as a preparatory change for the upcoming fast snapshot load feature. Removed local error by passing errp to improve on error handling, consequently also change caller to use error_prevent and not error_setg. Set errp in case of f->last_error as function should set errp in case it fails, and caller can simply use error_prepend without checking errp in case of error. Signed-off-by: Aadeshveer Singh Reviewed-by: Peter Xu Reviewed-by: Juraj Marcin Signed-off-by: Peter Xu Signed-off-by: Fabiano Rosas --- migration/qemu-file.c | 11 +++++------ migration/qemu-file.h | 4 ++-- migration/ram.c | 6 +++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index f30e13c66d7..7735e618549 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -550,17 +550,16 @@ void qemu_put_buffer_at(QEMUFile *f, const uint8_t *b= uf, size_t buflen, } =20 =20 -size_t qemu_get_buffer_at(QEMUFile *f, uint8_t *buf, size_t buflen, - off_t pos) +size_t qemu_get_buffer_at(QEMUFile *f, uint8_t *buf, size_t buflen, off_t = pos, + Error **errp) { - Error *err =3D NULL; - if (f->last_error) { + error_setg(errp, "Cannot read from file: stream is in error state = %d", + f->last_error); return 0; } =20 - if (qio_channel_pread_all(f->ioc, buf, buflen, pos, &err) < 0) { - qemu_file_set_error_obj(f, -EIO, err); + if (qio_channel_pread_all(f->ioc, buf, buflen, pos, errp) < 0) { return 0; } =20 diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 8f824c124d8..966766788dd 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -76,8 +76,8 @@ void qemu_set_offset(QEMUFile *f, off_t off, int whence); off_t qemu_get_offset(QEMUFile *f); void qemu_put_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen, off_t pos); -size_t qemu_get_buffer_at(QEMUFile *f, uint8_t *buf, size_t buflen, - off_t pos); +size_t qemu_get_buffer_at(QEMUFile *f, uint8_t *buf, size_t buflen, off_t = pos, + Error **errp); =20 QIOChannel *qemu_file_get_ioc(QEMUFile *file); int qemu_file_put_fd(QEMUFile *f, int fd); diff --git a/migration/ram.c b/migration/ram.c index 7fa4774246a..60ad4352150 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4133,7 +4133,7 @@ static bool read_ramblock_mapped_ram(QEMUFile *f, RAM= Block *block, block->pages_offset + offset= ); } else { read =3D qemu_get_buffer_at(f, host, size, - block->pages_offset + offset); + block->pages_offset + offset, er= rp); } =20 if (!read) { @@ -4202,8 +4202,8 @@ static void parse_ramblock_mapped_ram(QEMUFile *f, RA= MBlock *block, bitmap_size =3D BITS_TO_LONGS(num_pages) * sizeof(unsigned long); =20 if (qemu_get_buffer_at(f, (uint8_t *)block->file_bmap, bitmap_size, - header.bitmap_offset) !=3D bitmap_size) { - error_setg(errp, "Error reading dirty bitmap"); + header.bitmap_offset, errp) !=3D bitmap_size) { + error_prepend(errp, "Error reading dirty bitmap"); return; } =20 --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932918; cv=none; d=zohomail.com; s=zohoarc; b=W32DtzWwpsqI+hliDpgLL+mnpB3iYUEpCOZfxsa4hn6CF0svWBEdpKYBv83rCK/IMBJzN+QcIDBmqHO85qWvYdj+Xq/DH0O2gjaZRhCOokZWUgUVd/fq5fGig3wH19Q4wTu3jGjSYn4QaWY6/ahkdR5u4pzoxiYuOx0vQHKMB4I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932918; 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=NjkvZi9dCnM5PxlLXQzt4cvVIzMJFOAlxM7emsEzxpY=; b=D1PHCa301qcP16xYw+jTrk6JH5oz09ZGpQ1OG+AUgpqWSNbtWD0r4bOwpGF11dPO3zQo7csX+o569mjiy4k0zuG1fthn6zZ1S3d0LNUa1RtrqGg3nmF1bKKo5QT2UgJncvzcju/WAjEknAHO4MKfVN9SL3Fp7NnawsHpkv8PW2g= 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 1787932918166161.56707832966913; Fri, 28 Aug 2026 09:01:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyz4-0001MJ-DU; Fri, 28 Aug 2026 11:59:14 -0400 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 1wzyz0-0001Km-Si for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:10 -0400 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 1wzyyx-0008Du-FF for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:10 -0400 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 2109022144; Fri, 28 Aug 2026 15:58:58 +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 179F813691; Fri, 28 Aug 2026 15:58:56 +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 8KBlNkCwkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:58:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932742; 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=NjkvZi9dCnM5PxlLXQzt4cvVIzMJFOAlxM7emsEzxpY=; b=nr14Hy4n/E1U9NPrCi9UgZpxwDvVhc2ogxyPxaJ5TdTV5mTioBayY9Phvd8F8bdCdl0591 Omfw8Vz72MQdlljWmggnj0RlcKKkbXWe1QxVA/rfoYfi9Uk3zexUPBoh+V2HRH49v6sRym MGXfk/pck0j7Qc15nyBhSkYSVAZkR4c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932742; 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=NjkvZi9dCnM5PxlLXQzt4cvVIzMJFOAlxM7emsEzxpY=; b=YM1hyUiKWf9axe5fcdts8TrmybEkr2n7KicstMX80l9KhY7qFVZleXpcvsLTNH3hGoKxGa QpgWQJP69L971OBw== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=tiA0kkkR; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=yF6HGchB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932738; 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=NjkvZi9dCnM5PxlLXQzt4cvVIzMJFOAlxM7emsEzxpY=; b=tiA0kkkR/FjuZm/BlHhmfeGBdVx4W8LDxTYIKYirB77zKZabQg0xqta95KhRtTxgH5eYQ1 TSbchsKR7tclzsCy/LOJTmsb3Bt32h21fag+RI0VMx7s44gIPE9Twm6pIoWO3C/g0hOTkp DSOPba7XvGheOfaE4z3oq2ntnps1Lvk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932738; 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=NjkvZi9dCnM5PxlLXQzt4cvVIzMJFOAlxM7emsEzxpY=; b=yF6HGchBFzl/uQFmHNpXKogxuUQZwz/P8gGN5QXCH8R3X2o1f5SdExNWPHe7Q2l8yMykDL ZZQMirvoJOxI59Aw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Aadeshveer Singh Subject: [PULL v2 06/30] migration: add RAMBlock field and helper for fast snapshot load Date: Fri, 28 Aug 2026 12:58:21 -0300 Message-ID: <20260828155845.2874508-7-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.01 X-Rspamd-Queue-Id: 2109022144 X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spamd-Result: default: False [-3.01 / 50.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)[]; FROM_EQ_ENVFROM(0.00)[]; FREEMAIL_CC(0.00)[redhat.com,gmail.com]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:email,suse.de:mid,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; RCPT_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.de:+] 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) (identity @suse.de) X-ZM-MESSAGEID: 1787932919907158501 Content-Type: text/plain; charset="utf-8" From: Aadeshveer Singh Add pending_bmap field per RAMBlock which is a Bitmap to store internal state of which pages have been read by some thread to ensure coordination between fault thread and eager load thread. Modify parse_ramblock_mapped_ram(), to not load the actual RAMBlocks data in postcopy case as that will be loaded by fault thread and eager thread after the VM starts running. Change ram_load() to use new function ram_should_load_postcopy_pages() to decide how to load/read RAM. Signed-off-by: Aadeshveer Singh Signed-off-by: Peter Xu Signed-off-by: Fabiano Rosas --- include/system/ramblock.h | 6 ++++ migration/ram.c | 66 +++++++++++++++++++++++++++++++++++---- 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/include/system/ramblock.h b/include/system/ramblock.h index f0639287bf0..84624aca2c9 100644 --- a/include/system/ramblock.h +++ b/include/system/ramblock.h @@ -60,6 +60,12 @@ struct RAMBlock { =20 /* Bitmap of already received pages. Only used on destination side. */ unsigned long *receivedmap; + /* + * Bitmap for pages that are yet to be read from disk. It is required = for + * fault thread and eager thread to keep note of which pages are curre= ntly + * being read. Used by fast snapshot load. + */ + unsigned long *pending_bmap; =20 /* * bitmap to track already cleared dirty bitmap. When the bit is diff --git a/migration/ram.c b/migration/ram.c index 60ad4352150..b7c406428e2 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -263,6 +263,25 @@ static void ramblock_file_bmap_init(void) } } =20 +static void ramblock_pending_bmap_init(void) +{ + RAMBlock *rb; + + RAMBLOCK_FOREACH_NOT_IGNORED(rb) { + assert(!rb->pending_bmap); + /* + * The pending_bmap granularity must match the maximum of host and= guest + * page sizes. This ensures that every load operation checks for o= ne + * bit, allowing lockless thread coordination via a single-bit ato= mic + * test-and-clear. + */ + size_t size =3D rb->max_length / + MAX(qemu_ram_pagesize(rb), qemu_target_page_size()); + rb->pending_bmap =3D bitmap_new(size); + bitmap_set(rb->pending_bmap, 0, size); + } +} + static void ramblock_recv_map_init(void) { RAMBlock *rb; @@ -3768,6 +3787,10 @@ static int ram_load_setup(QEMUFile *f, void *opaque,= Error **errp) ramblock_recv_map_init(); if (migrate_mapped_ram()) { ramblock_file_bmap_init(); + if (migrate_postcopy_ram()) { + /* fast snapshot load */ + ramblock_pending_bmap_init(); + } } =20 return 0; @@ -3788,6 +3811,7 @@ static int ram_load_cleanup(void *opaque) RAMBLOCK_FOREACH_NOT_IGNORED(rb) { g_clear_pointer(&rb->receivedmap, g_free); g_clear_pointer(&rb->file_bmap, g_free); + g_clear_pointer(&rb->pending_bmap, g_free); } =20 return 0; @@ -4207,9 +4231,12 @@ static void parse_ramblock_mapped_ram(QEMUFile *f, R= AMBlock *block, return; } =20 - if (!read_ramblock_mapped_ram(f, block, num_pages, block->file_bmap, - errp)) { - return; + if (!migrate_postcopy_ram()) { + /* Do not load RAM during setup for fast snapshot load */ + if (!read_ramblock_mapped_ram(f, block, num_pages, block->file_bma= p, + errp)) { + return; + } } =20 /* Skip pages array */ @@ -4488,15 +4515,42 @@ static int ram_load_precopy(QEMUFile *f) return ret; } =20 +static bool ram_should_load_postcopy_pages(void) +{ + /* This is pure precopy, we don't need to load pages in postcopy way */ + if (!postcopy_is_running()) { + return false; + } + + /* + * This is postcopy, but when with mapped-ram, pages are not loaded in= the + * migration stream here, but done separately in a thread eagerly read= ing + * pages from the snapshot. Here, we only need to read the ram header= s, + * reusing the precopy code. + * TODO: when we have separate function to parse RAM headers we should + * switch to that. + */ + if (migrate_mapped_ram()) { + return false; + } + + /* + * Genuine network postcopy, we will load pages in this current stream= and + * they need to be done in postcopy way. + */ + return true; +} + static int ram_load(QEMUFile *f, void *opaque, int version_id) { int ret =3D 0; static uint64_t seq_iter; /* * If system is running in postcopy mode, page inserts to host memory = must - * be atomic + * be atomic. However, fast snapshot load uses the mapped ram precopy = like + * path to read block headers and populating bitmaps. */ - bool postcopy_running =3D postcopy_is_running(); + bool load_postcopy_pages =3D ram_should_load_postcopy_pages(); =20 seq_iter++; =20 @@ -4512,7 +4566,7 @@ static int ram_load(QEMUFile *f, void *opaque, int ve= rsion_id) */ trace_ram_load_start(); WITH_RCU_READ_LOCK_GUARD() { - if (postcopy_running) { + if (load_postcopy_pages) { /* * Note! Here RAM_CHANNEL_PRECOPY is the precopy channel of * postcopy migration, we have another RAM_CHANNEL_POSTCOPY to --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932987; cv=none; d=zohomail.com; s=zohoarc; b=XTucJ2jk85KLHuxd1++oCUwy5m58WerkruixYVgYVfXES7zSR4cexM+51pCR2yrRLapz++5shi4GCsDcIECPzFOUwHZyYGr53pqxufVE2kNtbxxRtAo1f6MK6DBxbmVOGFmb0SlFZxgZOv07G2vKiAWd96hZKe5M5+OcmJlRLW0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932987; 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=5SmeCai2W9mGUnaIlF+RloeydYydX2zCixfhNWH4ej8=; b=MhDjxsGN1r0sKd2tQybM1/eJbewTj16skrYs1M/5UbPsxlOKvZWKmDh974Rd/a1ibLLPmP5GBRTej4P0+QLhHxRQoPHGDzWikyXEcvF7rLOwNR52iEXdh/+6pAyAtIYCXFzWWvlwf2WClQ6wLSl1amkXKNeQf0doqABSsRZUbwA= 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 1787932986949533.9483959682792; Fri, 28 Aug 2026 09:03:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyz7-0001Ml-Pm; Fri, 28 Aug 2026 11:59:17 -0400 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 1wzyz5-0001MW-8d for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:15 -0400 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wzyyz-0008FU-6z for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:14 -0400 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 6CCE82229F; Fri, 28 Aug 2026 15:58:59 +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 5F8CC1352D; Fri, 28 Aug 2026 15:58:58 +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 mEpcDEKwkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:58:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932743; 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=5SmeCai2W9mGUnaIlF+RloeydYydX2zCixfhNWH4ej8=; b=pV6jcU/wBnaxJ5hudeXpFNtAKkTIRjES9tXGwRhpgRARGxp8nseRaq5Jyqi0860332CMZb ou9UAVO9PAHrvhrYBhcqMdG5IpUBwGfKTJ4yiOTVRxvvxUvcawf0la/zjY7UyP6W7+SKth SJQKq2sfowzcIl2IAuEUMsQZBTNXA7Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932743; 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=5SmeCai2W9mGUnaIlF+RloeydYydX2zCixfhNWH4ej8=; b=4c9xpu4+TEypBrwucPHv/oFZVMoXrod2FaeYiZiPzL9WVN8gTIutZBJ5UnkDbVnHhAW0o4 +5lWTGC++QguGlBA== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932739; 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=5SmeCai2W9mGUnaIlF+RloeydYydX2zCixfhNWH4ej8=; b=PezpehRgKQ+M6QKQLgb/137gnGuXnzJ5OqGcR1X/U5j+NC+C9PTUymorkpNQVPaJzFjiu5 EOqd8eFab5WscohM6yMLa7Y6mEV4EQyEnzp3sBNYMr9LrUwT3CAQ93iJYbwStGwVh816tn ELUfDBOGrl0xDkjNvkKvwSZ4cws+w6c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932739; 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=5SmeCai2W9mGUnaIlF+RloeydYydX2zCixfhNWH4ej8=; b=ZAAwK2MmEkX6bo4rO/nKZ9vxK1hc5B93ShfsvJFlhw14shckxd2yegGr2dhQGqV1um/UEI grqjqsw9HPvldPBA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Aadeshveer Singh Subject: [PULL v2 07/30] migration: add support for fault thread to load pages from disk Date: Fri, 28 Aug 2026 12:58:22 -0300 Message-ID: <20260828155845.2874508-8-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.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]; RCVD_TLS_ALL(0.00)[]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; 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)[]; FREEMAIL_CC(0.00)[redhat.com,gmail.com]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email,suse.de:mid]; RCVD_COUNT_TWO(0.00)[2]; FREEMAIL_ENVRCPT(0.00)[gmail.com] 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=195.135.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -37 X-Spam_score: -3.8 X-Spam_bar: --- X-Spam_report: (-3.8 / 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, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URG_BIZ=0.573 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: 1787932988449154100 Content-Type: text/plain; charset="utf-8" From: Aadeshveer Singh In fast snapshot load, we would like to serve faults as soon as possible hence loading pages directly instead of requesting a source Add postcopy_mapped_ram_load_page() function which serves single page fault. It uses bitmap_test_and_clear_atomic() on pending_bmap to prevent multiple threads from loading same page. It loads a page or pages depending on size of guest pages and host pages, loading exactly the larger of two. If the entire page is zero postcopy_place_page_zero() is used for efficiency and in case some part is non zero it is part by part loaded on loop using new function postcopy_mapped_ram_load_guest_page() which loads a single guest page in a buffer which is then placed using postcopy_place_page(). This covers all possible cases for various page sizes of host and guest. Because postcopy_place_page and in general postcopy does not support larger guest pages this will not work in case of guest pages sizes larger than host. Update postcopy_ram_fault_thread to call postcopy_mapped_ram_load_page instead of requesting source in case of fast snapshot load. to_src_file check is bypassed in fast snapshot load case as there is no source. Call try_mark_postcopy_blocktime_begin on every page fault to support postcopy-blocktime. Allocate another channel in postcopy_temp_pages_setup(like the preempt case), for both the fault thread and eager thread to load pages independently. Signed-off-by: Aadeshveer Singh Signed-off-by: Peter Xu Signed-off-by: Fabiano Rosas --- migration/postcopy-ram.c | 183 +++++++++++++++++++++++++++++++++++---- 1 file changed, 166 insertions(+), 17 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 2286d25f8c6..430b5f24e1a 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -946,6 +946,130 @@ int postcopy_wake_shared(struct PostCopyFD *pcfd, pagesize); } =20 +/* + * Load a single guest page from source file into the buffer. + * NOTE: This is not an atomic operation and should not be used to directl= y load + * pages on page faults in postcopy. It is meant to fill in buffer that ca= n then + * be copied into the faulting location using UFFDIO_COPY. + */ +static bool postcopy_mapped_ram_load_guest_page(MigrationIncomingState *mi= s, + RAMBlock *rb, + ram_addr_t rb_offset, void= *buf, + Error **errp) +{ + ERRP_GUARD(); + size_t page =3D rb_offset / qemu_target_page_size(); + size_t read; + + if (test_bit(page, rb->file_bmap)) { + /* + * This can happen concurrently, but it's thread-safe because + * qemu_get_buffer_at() is thread-safe, and the caller will be usi= ng + * different temporary buffers. + */ + read =3D + qemu_get_buffer_at(mis->from_src_file, buf, qemu_target_page_s= ize(), + rb->pages_offset + rb_offset, errp); + + if (read !=3D qemu_target_page_size()) { + error_prepend(errp, + "Could not read page %zu from RAM Block %s: ", p= age, + rb->idstr); + return false; + } + } else { + memset(buf, '\0', qemu_target_page_size()); + } + return true; +} + +/** + * postcopy_mapped_ram_load_page() - Load pages required to access host ad= dress. + * @mis: Migration Incoming State. + * @rb: RAMBlock from where page is loaded. + * @rb_offset: Offset of target page in RAMBlock. + * @haddr: Base of target page where to load in page. + * @channel: Used to identify between threads and use corresponding temp. + * @errp: Set error in case of failure + * + * Load page(s) from RAMBlock covering the faulting address. We might need= to + * load multiple pages in the case when host page size is greater than gue= st + * page size. As userfaultfd works on granularity of host pages, we might = need + * to load guest pages in single operation. + * + * Return: True on success. + */ +static bool postcopy_mapped_ram_load_page(MigrationIncomingState *mis, + RAMBlock *rb, ram_addr_t rb_offs= et, + uint64_t haddr, int channel, + Error **errp) +{ + void *place_source =3D mis->postcopy_tmp_pages[channel].tmp_huge_page; + char *buffer_ptr =3D (char *)place_source; + size_t guest_pages_to_load =3D + MAX(1, qemu_ram_pagesize(rb) / qemu_target_page_size()); + size_t guest_page; + size_t host_page; + + /* + * If guest page size is greater than host page size uffd needs to loa= d one + * guest page and multiple host pages, hence the offsets need to align= ed + * with guest pages (which is automatically aligned with host pages). = In the + * same case we need to check range of bits on pending_bmap(bit per ho= st + * page) to decide whether all the page have been loaded. + * + * NOTE: This is future proofing as currently target page size greater= than + * host page size is not supported. However if postcopy does support t= his in + * future, with updated place page functions this function should work + * readily. + */ + rb_offset =3D ROUND_DOWN(rb_offset, qemu_target_page_size()); + haddr =3D ROUND_DOWN(haddr, qemu_target_page_size()); + guest_page =3D rb_offset >> qemu_target_page_bits(); + host_page =3D rb_offset / qemu_ram_pagesize(rb); + + /* + * pending_bmap needs the index of host or guest page based on which is + * larger. As page index is inversely proportional to page size we use= the + * minimum of both. + */ + if (bitmap_test_and_clear_atomic(rb->pending_bmap, + MIN(host_page, guest_page), 1)) { + if (find_next_bit(rb->file_bmap, guest_page + guest_pages_to_load, + guest_page) =3D=3D guest_page + guest_pages_to_l= oad) { + /* It is efficient to use UFFDIO_ZERO if all pages are zero */ + if (postcopy_place_page_zero(mis, (void *)haddr, rb)) { + error_setg(errp, + "Failed to place zero page %zu from RAM Block %= s at " + "address %" PRIu64, + guest_page, rb->idstr, haddr); + return false; + } + } else { + size_t load_size =3D guest_pages_to_load * qemu_target_page_si= ze(); + size_t offset; + + for (offset =3D 0; offset < load_size; + offset +=3D qemu_target_page_size()) { + if (!postcopy_mapped_ram_load_guest_page( + mis, rb, rb_offset + offset, buffer_ptr + offset, + errp)) { + return false; + } + } + + if (postcopy_place_page(mis, (void *)haddr, place_source, rb))= { + error_setg(errp, + "Failed to place page %zu from RAM Block %s at " + "address %" PRIu64, + guest_page, rb->idstr, haddr); + return false; + } + } + } + return true; +} + /* * NOTE: @tid is only used when postcopy-blocktime feature is enabled, and * also optional: when zero is provided, the fault accounting will be igno= red. @@ -1308,6 +1432,7 @@ static void *postcopy_ram_fault_thread(void *opaque) int ret; size_t index; RAMBlock *rb =3D NULL; + Error *local_err =3D NULL; =20 trace_postcopy_ram_fault_thread_entry(); rcu_register_thread(); @@ -1349,11 +1474,13 @@ static void *postcopy_ram_fault_thread(void *opaque) break; } =20 - if (!mis->to_src_file) { + if (!migrate_mapped_ram() && !mis->to_src_file) { /* - * Possibly someone tells us that the return path is - * broken already using the event. We should hold until - * the channel is rebuilt. + * Possibly someone tells us that the return path is broken al= ready + * using the event. We should hold until the channel is rebuil= t. + * Fast snapshot load doesn't support pause and recover, becau= se + * it's not necessary: we can fail right away when QEMU just b= ooted + * with nothing to lose. */ postcopy_pause_fault_thread(mis); } @@ -1416,18 +1543,37 @@ static void *postcopy_ram_fault_thread(void *opaque) qemu_ram_get_idstr(rb), rb_offset, msg.arg.pagefault.feat.pti= d); + + if (migrate_mapped_ram()) { + /* Load page directly in case of fast snapshot load */ + + uintptr_t aligned =3D (uintptr_t)ROUND_DOWN( + msg.arg.pagefault.address, qemu_ram_pagesize(rb)); + + if (try_mark_postcopy_blocktime_begin( + mis, rb, rb_offset, (uintptr_t)aligned, + msg.arg.pagefault.feat.ptid)) { + if (!postcopy_mapped_ram_load_page( + mis, rb, rb_offset, aligned, RAM_CHANNEL_POSTC= OPY, + &local_err)) { + error_report_err(local_err); + break; + } + } + } else { retry: - /* - * Send the request to the source - we want to request one - * of our host page sizes (which is >=3D TPS) - */ - ret =3D postcopy_request_page(mis, rb, rb_offset, - msg.arg.pagefault.address, - msg.arg.pagefault.feat.ptid); - if (ret) { - /* May be network failure, try to wait for recovery */ - postcopy_pause_fault_thread(mis); - goto retry; + /* + * Send the request to the source - we want to request one + * of our host page sizes (which is >=3D TPS) + */ + ret =3D postcopy_request_page(mis, rb, rb_offset, + msg.arg.pagefault.address, + msg.arg.pagefault.feat.ptid); + if (ret) { + /* May be network failure, try to wait for recovery */ + postcopy_pause_fault_thread(mis); + goto retry; + } } } =20 @@ -1499,8 +1645,11 @@ static int postcopy_temp_pages_setup(MigrationIncomi= ngState *mis, Error **errp) unsigned i, channels; void *temp_page; =20 - if (migrate_postcopy_preempt()) { - /* If preemption enabled, need extra channel for urgent requests */ + if (migrate_postcopy_preempt() || migrate_mapped_ram()) { + /* + * If preemption enabled or it is fast snapshot load, need extra c= hannel + * for urgent requests/faults + */ mis->postcopy_channels =3D RAM_CHANNEL_MAX; } else { /* Both precopy/postcopy on the same channel */ --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932851; cv=none; d=zohomail.com; s=zohoarc; b=fP0OilZwukZVqkacTyqSlSVZvtI5Z4VTaxOSyu0L3evBz6wZraoqOoQM4cPvsJdU54M4RO382UYp74H1vAwAXR/rBP57v3B3MMbEbPHO5vubjOujXxUCJjA2KugGdaZGEQsBEcXmC8Y6gpzfRGriTEbXyDmz47017CRUhmOybho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932851; 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=JBaiBj8RrIFlHoMR68yaE7kUmPAVZMY+pnjc1+jCVHI=; b=OvJjBuqx8Sxy3SwrwF8TonSlcB+cfueavMnemDnQwnwdFXAmabSGLjn5VsTmHj17zQBdLqGzKS7dDSN/e+rCp5nwHkhECyTcx3y4fLenip1xfbYkUEt+hiy0+HgHaAw7SxABnXFNHKbP94DamQJhZisvxgY24lIYKAmwXyskVvI= 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 1787932851016944.7731596460741; Fri, 28 Aug 2026 09:00:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyzA-0001Ne-Ev; Fri, 28 Aug 2026 11:59:20 -0400 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 1wzyz8-0001N0-7T for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:18 -0400 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wzyz0-0008Ga-Cx for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:16 -0400 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 DEFD622197; Fri, 28 Aug 2026 15:59:00 +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 A897C13674; Fri, 28 Aug 2026 15:58:59 +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 eGoxHkOwkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:58:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932745; 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=JBaiBj8RrIFlHoMR68yaE7kUmPAVZMY+pnjc1+jCVHI=; b=fLgADZggmyzrxjqWuTHyb0F2CdKp6QoLWYeyTtX1RL9YC9BIE73Em4CY0k2CRQzuoH+mrY 6JVN9cWpoamKKQO4sWX6e4whttLX+vTzcWDcnYqvcdFNz6Sa62LR5VnSliwpWDUUEC70Wr WoP3q0Zv7zg/q4ebAXWNGsNUtF3LE9U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932745; 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=JBaiBj8RrIFlHoMR68yaE7kUmPAVZMY+pnjc1+jCVHI=; b=MPxxjW+UkoakReg90i/bvyYjqro48/isRCmWlBN6W6YqKZQnMHuAgGLKXvjJ5TvC40it7S oxJsfn3sXRdvUhDQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932740; 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=JBaiBj8RrIFlHoMR68yaE7kUmPAVZMY+pnjc1+jCVHI=; b=gcRUtD8d/iFF/zFrjf4i+Pdc1MuPswYntPUiqsXqzt6lsjJmeyz4fXu+CIrox4MxNkVCGd sriZlSmNVfwSJ9S48mELok63q4LtPBUjWUGuLGvE2GOd2+FbUS+/VEOhH5QfF5sITcBBCf jhKCwL4r+tmyKmQECLD6JzqoHlembp8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932740; 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=JBaiBj8RrIFlHoMR68yaE7kUmPAVZMY+pnjc1+jCVHI=; b=L1jMonTPrzrLC+wz4qvoevjMVPPF8w28PuAyjjuhgsikWcRuhJLJdxLxdDnVw0YSVMRg7l IasmcoUIaff8QdCQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Aadeshveer Singh , Juraj Marcin Subject: [PULL v2 08/30] migration: add eager load thread and setup for fast snapshot load Date: Fri, 28 Aug 2026 12:58:23 -0300 Message-ID: <20260828155845.2874508-9-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.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]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[redhat.com,gmail.com]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; RCVD_VIA_SMTP_AUTH(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email,imap1.dmz-prg2.suse.org:helo]; FREEMAIL_ENVRCPT(0.00)[gmail.com] 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=195.135.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, 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: 1787932853540158500 Content-Type: text/plain; charset="utf-8" From: Aadeshveer Singh In fast snapshot load a thread is needed for actively loading in pages along with the fault path so that the guest is not dependent on fault thread indefinitely. Considering the difference from usual network postcopy where major chunk of RAM is already loaded here entire RAM needs to be loaded later. Existance of background pages which are not really accessed by the guest might never be loaded and system will be locked in migration for indefinite time. As there should be no assumption about how guest accesses memory, the load times can be indefinite. Add postcopy_ram_eager_load_thread(), for the eager thread which iterates over all non ignored blocks calling ram_block_load_eager() on each. ram_block_load_eager then iterates to load in all pages using postcopy_mapped_ram_load_page(), with a different channel, which takes care of not loading in pages already loaded by fault thread. On completion the thread schedules postcopy_incoming_complete_bh() to destroy the incoming migration state. Add postcopy_ram_eager_load_setup() to create the thread. Added joining logic in postcopy_incoming_cleanup(). Add tracepoints for entry and exit to eager load thread. When both mapped-ram and postcopy-ram are set, divert from qemu_loadvm_state to run fast snapshot load Initialize postcopy RAM state and register RAM Blocks with userfaultfd via ram_postcopy_incoming_init() and postcopy_ram_incoming_setup() in process_incoming_migration_co(). Fault thread needs to be launched before VM to serve faults for some hardwares emulation that need to read RAM (like vapic devices). Populate bitmaps and offset tables while reading file in qemu_loadvm_state_main. Add function qemu_loadvm_run_fast_snapshot_load() which starts the VM using loadvm_postcopy_handle_run_bh() and launches eager load thread. Skip scheduling process_incoming_migration_bh() in process_incoming_migration_co(), for fast snapshot load as the state cleanup is managed by eager load thread on completion. Signed-off-by: Aadeshveer Singh Reviewed-by: Peter Xu Reviewed-by: Juraj Marcin Signed-off-by: Peter Xu Signed-off-by: Fabiano Rosas --- migration/migration.c | 36 +++++++++++++++++-- migration/migration.h | 5 +++ migration/postcopy-ram.c | 76 ++++++++++++++++++++++++++++++++++++++++ migration/postcopy-ram.h | 2 ++ migration/savevm.c | 16 +++++++++ migration/savevm.h | 2 ++ migration/trace-events | 2 ++ 7 files changed, 137 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index a30779f37c8..59cdc1a169f 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -710,6 +710,11 @@ static void process_incoming_migration_bh(void *opaque) migration_incoming_state_destroy(); } =20 +static bool migration_incoming_has_postcopy_thread(MigrationIncomingState = *mis) +{ + return mis->have_listen_thread || mis->have_eager_load_thread; +} + static void coroutine_fn process_incoming_migration_co(void *opaque) { @@ -739,17 +744,44 @@ process_incoming_migration_co(void *opaque) migrate_set_state(&mis->state, MIGRATION_STATUS_SETUP, MIGRATION_STATUS_ACTIVE); =20 + /* + * When loading snapshot with postcopy enabled, setup the postcopy + * infrastructure before loading the major part of device states. + * It's required because qemu_loadvm_state() may access guest memory + * while loading device states, which can cause page faults already. + */ + if (migrate_postcopy_ram() && migrate_mapped_ram()) { + migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, + MIGRATION_STATUS_POSTCOPY_DEVICE); + + if (ram_postcopy_incoming_init(mis, &local_err)) { + goto fail; + } + + postcopy_state_set(POSTCOPY_INCOMING_LISTENING); + if (postcopy_ram_incoming_setup(mis, &local_err)) { + goto fail; + } + } + mis->loadvm_co =3D qemu_coroutine_self(); ret =3D qemu_loadvm_state(mis->from_src_file, &local_err); mis->loadvm_co =3D NULL; + if (ret < 0) { + goto fail; + } + + if (migrate_postcopy_ram() && migrate_mapped_ram()) { + qemu_loadvm_run_fast_snapshot_load(mis->from_src_file, mis); + } =20 trace_vmstate_downtime_checkpoint("dst-precopy-loadvm-completed"); =20 trace_process_incoming_migration_co_end(ret); - if (mis->have_listen_thread) { + if (migration_incoming_has_postcopy_thread(mis)) { /* * Postcopy was started, cleanup should happen at the end of the - * postcopy listen thread. + * postcopy listen thread or eager load thread. */ trace_process_incoming_migration_co_postcopy_end_main(); goto out; diff --git a/migration/migration.h b/migration/migration.h index 631421c784b..e47ff4e3d11 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -42,6 +42,7 @@ #define MIGRATION_THREAD_DST_FAULT "mig/dst/fault" #define MIGRATION_THREAD_DST_LISTEN "mig/dst/listen" #define MIGRATION_THREAD_DST_PREEMPT "mig/dst/preempt" +#define MIGRATION_THREAD_DST_SNAPSHOT_LOAD "mig/dst/snapshot_load" =20 struct PostcopyBlocktimeContext; typedef struct ThreadPool ThreadPool; @@ -120,6 +121,10 @@ struct MigrationIncomingState { bool have_listen_thread; QemuThread listen_thread; =20 + /* Thread to load pages eagerly in fast snapshot load case */ + bool have_eager_load_thread; + QemuThread eager_load_thread; + /* For the kernel to send us notifications */ int userfault_fd; /* To notify the fault_thread to wake, e.g., when need to quit */ diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 430b5f24e1a..3b66c1f6d42 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -39,6 +39,8 @@ #include "qemu/mmap-alloc.h" #include "options.h" =20 +static void postcopy_incoming_complete_bh(void *opaque); + /* Arbitrary limit on size of each discard command, * keeps them around ~200 bytes */ @@ -1867,6 +1869,70 @@ int postcopy_place_page_zero(MigrationIncomingState = *mis, void *host, } } =20 +/* + * Called by postcopy_ram_eager_load_thread over all blocks to load in all= the + * pending pages of given ram block + */ +static int ram_block_load_eager(RAMBlock *rb, void *opaque) +{ + MigrationIncomingState *mis =3D migration_incoming_get_current(); + MigrationState *s =3D migrate_get_current(); + Error *errp =3D NULL; + void *host =3D qemu_ram_get_host_addr(rb); + void *target; + + for (ram_addr_t page_loc =3D 0; page_loc < rb->used_length; + page_loc +=3D qemu_ram_pagesize(rb)) { + target =3D (uint8_t *)host + page_loc; + if (!postcopy_mapped_ram_load_page(mis, rb, page_loc, (uint64_t)ta= rget, + RAM_CHANNEL_PRECOPY, &errp)) { + migrate_error_propagate(s, errp); + return -1; + } + } + return 0; +} + +/* + * Used by fast snapshot load to eagerly load in all pages of RAM and sche= dule + * cleanup after entire RAM is loaded + */ +static void *postcopy_ram_eager_load_thread(void *opaque) +{ + MigrationIncomingState *mis =3D opaque; + MigrationStatus next_state; + + trace_postcopy_ram_eager_load_thread_entry(); + rcu_register_thread(); + qemu_event_set(&mis->thread_sync_event); + + if (foreach_not_ignored_block(ram_block_load_eager, NULL)) { + next_state =3D MIGRATION_STATUS_FAILED; + } else { + next_state =3D MIGRATION_STATUS_COMPLETED; + } + migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_ACTIVE, + next_state); + + postcopy_state_set(POSTCOPY_INCOMING_END); + migration_bh_schedule(postcopy_incoming_complete_bh, mis); + + rcu_unregister_thread(); + trace_postcopy_ram_eager_load_thread_exit(); + return NULL; +} + +/* + * Create thread for eager loading in fast snapshot load case + */ +void postcopy_ram_eager_load_setup(MigrationIncomingState *mis) +{ + postcopy_thread_create( + mis, &mis->eager_load_thread, MIGRATION_THREAD_DST_SNAPSHOT_LOAD, + postcopy_ram_eager_load_thread, QEMU_THREAD_JOINABLE); + mis->have_eager_load_thread =3D true; +} + #else /* No target OS support, stubs just fail */ void fill_destination_postcopy_migration_info(MigrationInfo *info) @@ -1937,6 +2003,11 @@ bool try_mark_postcopy_blocktime_begin(MigrationInco= mingState *mis, g_assert_not_reached(); return false; } + +void postcopy_ram_eager_load_setup(MigrationIncomingState *mis) +{ + g_assert_not_reached(); +} #endif =20 /* -----------------------------------------------------------------------= -- */ @@ -2410,6 +2481,11 @@ int postcopy_incoming_cleanup(MigrationIncomingState= *mis) mis->have_listen_thread =3D false; } =20 + if (mis->have_eager_load_thread) { + qemu_thread_join(&mis->eager_load_thread); + mis->have_eager_load_thread =3D false; + } + if (migrate_postcopy_ram()) { rc =3D postcopy_ram_incoming_cleanup(mis); } diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h index ea879f0bc6f..c58a60bc8ae 100644 --- a/migration/postcopy-ram.h +++ b/migration/postcopy-ram.h @@ -205,4 +205,6 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, uint= 32_t ptid, int postcopy_incoming_setup(MigrationIncomingState *mis, Error **errp); int postcopy_incoming_cleanup(MigrationIncomingState *mis); =20 +void postcopy_ram_eager_load_setup(MigrationIncomingState *mis); + #endif diff --git a/migration/savevm.c b/migration/savevm.c index 34dd06f9f73..161a9d090fa 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -3004,6 +3004,22 @@ static bool postcopy_pause_incoming(MigrationIncomin= gState *mis) return true; } =20 +/* + * Starts the VM and launches the eager thread for fast snapshot load + */ +void qemu_loadvm_run_fast_snapshot_load(QEMUFile *f, + MigrationIncomingState *mis) +{ + postcopy_state_set(POSTCOPY_INCOMING_RUNNING); + + migration_bh_schedule(loadvm_postcopy_handle_run_bh, mis); + + migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_DEVICE, + MIGRATION_STATUS_POSTCOPY_ACTIVE); + + postcopy_ram_eager_load_setup(mis); +} + int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis, Error **errp) { diff --git a/migration/savevm.h b/migration/savevm.h index f7dcdd7d1b6..9988dd4b8a4 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -70,6 +70,8 @@ void qemu_savevm_send_postcopy_ram_discard(QEMUFile *f, c= onst char *name, int qemu_save_device_state(QEMUFile *f, Error **errp); int qemu_loadvm_state(QEMUFile *f, Error **errp); void qemu_loadvm_state_cleanup(MigrationIncomingState *mis); +void qemu_loadvm_run_fast_snapshot_load(QEMUFile *f, + MigrationIncomingState *mis); int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis, Error **errp); int qemu_load_device_state(QEMUFile *f, Error **errp); diff --git a/migration/trace-events b/migration/trace-events index af0e7845354..4ae1c226f90 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -315,6 +315,8 @@ postcopy_blocktime_tid_cpu_map(int cpu, uint32_t tid) "= cpu: %d, tid: %u" postcopy_blocktime_begin(uint64_t addr, uint64_t time, int cpu, bool exist= s) "addr: 0x%" PRIx64 ", time: %" PRIu64 ", cpu: %d, exist: %d" postcopy_blocktime_end(uint64_t addr, uint64_t time, int affected_cpu, int= affected_non_cpus) "addr: 0x%" PRIx64 ", time: %" PRIu64 ", affected_cpus:= %d, affected_non_cpus: %d" postcopy_blocktime_end_one(int cpu, uint8_t left_faults) "cpu: %d, left_fa= ults: %" PRIu8 +postcopy_ram_eager_load_thread_entry(void) "" +postcopy_ram_eager_load_thread_exit(void) "" =20 # exec.c migration_exec_outgoing(const char *cmd) "cmd=3D%s" --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932843; cv=none; d=zohomail.com; s=zohoarc; b=dsp4Ag8We/qX8Iwm+85iCLaSWdsfDfzbTcHp9JVQJKnLJCnMQZTBYdX5zhutAlZd4paWR++PgbZ1M7q6zJm7ssZqBT0QUonUMRy1O9BeFoAqkCLeBZ9ZxsitWQoh0RAex7vn+JpjaooHdCElWFIT6j2Nd7K5oJOxgugSd6JrbZo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932843; 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=cspG0Dh2mxk8vVsB+09O0NDaNl4Dzf0rDzwGrop/RnM=; b=E5Mxfy1x/RJ3oe1KDuZvaAO/NfqUxPDTe5e1w+RNAoVoL7T8U1pvOFQjF6x3p1/8J9g0GpOrqnbY38l2PoQ+yqmzsClsfH6OAEbTBh8WNK4J3CcOvoxqH9JNDx0CHFHsdEcH/qyWsOqkTE241RaSjBk/GP2/3OFr59HQvE1ZKJs= 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 1787932843132738.3846355455275; Fri, 28 Aug 2026 09:00:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyzB-0001Nn-2q; Fri, 28 Aug 2026 11:59:21 -0400 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 1wzyz8-0001N1-B0 for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:18 -0400 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 1wzyz2-0008Hq-3p for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:16 -0400 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 4F0F11F847; Fri, 28 Aug 2026 15:59:02 +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 29A6913675; Fri, 28 Aug 2026 15:59:00 +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 8CPKOkSwkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932746; 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=cspG0Dh2mxk8vVsB+09O0NDaNl4Dzf0rDzwGrop/RnM=; b=wmX5ppQCTRZG0TEbo7H5m7wbwjx25Cjwkrmc/9Kyn3Y3Ss2jr+yLSIT57ZGXCIqYkozj8R POgoH/aLHbmeNVL5q518FWjEGuzEPaxL+OEmnGstVYStgZVrMvx5Ib91PBNWt6LkQVJLT7 Be+Ekz/58/ijgbR/GEv8sNHzbYK1MgE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932746; 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=cspG0Dh2mxk8vVsB+09O0NDaNl4Dzf0rDzwGrop/RnM=; b=eNCIVivQ0rI6GPqKXukjS5UE6bZbsd9wM4gwhdNvADFtJDEa7Sw1hWkvHUlshjR+kF78Mn 3GiaraqH737kFHDg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932742; 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=cspG0Dh2mxk8vVsB+09O0NDaNl4Dzf0rDzwGrop/RnM=; b=m1h6hkarzfK4XFxRb7IGgXA2P1K7ecfBZyF4CsxGQwTIwbkvY/Q9apynMMIFcsS0F8WXH3 PkkBVYrBps474xbg9cJ7gN6Nw7UvzEMr/poVepTwjZiDo2Uq7FP8BfXGPdD/wrgP1xzZTl Tocmx1U3PBbLnnj4wgX3bHLMFrCN8HI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932742; 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=cspG0Dh2mxk8vVsB+09O0NDaNl4Dzf0rDzwGrop/RnM=; b=cNKoo+pD869k1/6+gluOakAqBikzWLQW1FSNaBvHbtvuu1VDIOMxjOxvls3RenaKaB/qhO jkdwGAyiB+/VkfDQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Aadeshveer Singh Subject: [PULL v2 09/30] migration: update capability conflict test for postcopy-ram+mapped-ram Date: Fri, 28 Aug 2026 12:58:24 -0300 Message-ID: <20260828155845.2874508-10-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.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]; RCVD_TLS_ALL(0.00)[]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; 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)[]; FREEMAIL_CC(0.00)[redhat.com,gmail.com]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email,suse.de:mid]; RCVD_COUNT_TWO(0.00)[2]; FREEMAIL_ENVRCPT(0.00)[gmail.com] 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: 1787932845189158500 Content-Type: text/plain; charset="utf-8" From: Aadeshveer Singh Remove the test test_validate_caps_pair, which asserted postcopy-ram and mapped-ram capabilities cannot be active together. The new fast snapshot load feature is exactly this pair of capabilities active together, with the following patches in this series, this combination will now supported and be functional. Remove the capability check that rejected mapped-ram and postcopy-ram being set simultaneously, as this combination now corresponds to fast snapshot load. Add a capability check against setting multifd when configured for fast snapshot load as it is not supported yet. Also add capability check against setting postcopy-preempt as it is incompatible. Add infrastructure to check postcopy_notifier_list being empty in capaility checking to block vhost-user with fast snapshot load as it is not supported. Add a check to bail in migrate_prepare to prevent unexpected usage when fast snapshot load is enabled. A smoke test exercising this feature has been added further in this series. Signed-off-by: Aadeshveer Singh Signed-off-by: Peter Xu Signed-off-by: Fabiano Rosas --- include/qemu/notify.h | 2 ++ migration/migration.c | 6 ++++ migration/options.c | 20 ++++++++++-- migration/postcopy-ram.c | 5 +++ migration/postcopy-ram.h | 1 + tests/qtest/migration/misc-tests.c | 52 ------------------------------ util/notify.c | 5 +++ 7 files changed, 37 insertions(+), 54 deletions(-) diff --git a/include/qemu/notify.h b/include/qemu/notify.h index abf18dbf595..666d13f727e 100644 --- a/include/qemu/notify.h +++ b/include/qemu/notify.h @@ -75,4 +75,6 @@ void notifier_with_return_remove(NotifierWithReturn *noti= fier); int notifier_with_return_list_notify(NotifierWithReturnList *list, void *data, Error **errp); =20 +bool notifier_with_return_list_empty(NotifierWithReturnList *list); + #endif diff --git a/migration/migration.c b/migration/migration.c index 59cdc1a169f..b413d28622a 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2048,6 +2048,12 @@ static bool migrate_prepare(MigrationState *s, bool = resume, Error **errp) error_setg(errp, "Cannot use compression with mapped-ram"); return false; } + + if (migrate_postcopy_ram()) { + error_setg(errp, "Cannot migrate with fast snapshot load " + "enabled(mapped-ram + postcopy-ram)"); + return false; + } } =20 if (migrate_mode_is_cpr()) { diff --git a/migration/options.c b/migration/options.c index dfce19405d4..d2575edb6cb 100644 --- a/migration/options.c +++ b/migration/options.c @@ -736,10 +736,26 @@ bool migrate_caps_check(bool *old_caps, bool *new_cap= s, Error **errp) "Mapped-ram migration is incompatible with xbzrle"); return false; } + } =20 - if (new_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM]) { + if (new_caps[MIGRATION_CAPABILITY_MAPPED_RAM] && + new_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM]) { + if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) { error_setg(errp, - "Mapped-ram migration is incompatible with postcopy= "); + "Multifd is not supported with fast snapshot load"); + return false; + } + + if (new_caps[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT]) { + error_setg( + errp, + "Postcopy Preempt is incompatible with fast snapshot load"= ); + return false; + } + + if (!postcopy_notifier_list_empty()) { + error_setg(errp, + "vhost-user is not supported with fast snapshot loa= d"); return false; } } diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 3b66c1f6d42..885ab58fca5 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -84,6 +84,11 @@ int postcopy_notify(enum PostcopyNotifyReason reason, Er= ror **errp) &pnd, errp); } =20 +bool postcopy_notifier_list_empty(void) +{ + return notifier_with_return_list_empty(&postcopy_notifier_list); +} + /* * NOTE: this routine is not thread safe, we can't call it concurrently. B= ut it * should be good enough for migration's purposes. diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h index c58a60bc8ae..edba7b02404 100644 --- a/migration/postcopy-ram.h +++ b/migration/postcopy-ram.h @@ -136,6 +136,7 @@ void postcopy_add_notifier(NotifierWithReturn *nn); void postcopy_remove_notifier(NotifierWithReturn *n); /* Call the notifier list set by postcopy_add_start_notifier */ int postcopy_notify(enum PostcopyNotifyReason reason, Error **errp); +bool postcopy_notifier_list_empty(void); =20 void postcopy_thread_create(MigrationIncomingState *mis, QemuThread *thread, const char *name, diff --git a/tests/qtest/migration/misc-tests.c b/tests/qtest/migration/mis= c-tests.c index ec6d438cdcb..4e0deb7f188 100644 --- a/tests/qtest/migration/misc-tests.c +++ b/tests/qtest/migration/misc-tests.c @@ -201,55 +201,6 @@ static void do_test_validate_uri_channel(MigrateCommon= *args) migrate_end(from, to, false); } =20 -static void validate_caps_pair(QTestState *from, - const char *first_capability, - const char *second_capability, - const char *expected_error) -{ - QDict *rsp; - const char *error_desc; - - migrate_set_capability(from, first_capability, true); - - rsp =3D qtest_qmp_assert_failure_ref( - from, - "{ 'execute': 'migrate-set-capabilities'," - " 'arguments': { 'capabilities': [ { " - " 'capability': %s, 'state': true } ] } }", - second_capability); - - error_desc =3D qdict_get_str(rsp, "desc"); - g_assert_cmpstr(error_desc, =3D=3D, expected_error); - qobject_unref(rsp); - - migrate_set_capability(from, first_capability, false); -} - -static void test_validate_caps_pair(char *test_path, MigrateCommon *args) -{ - g_autofree char *serial_path =3D g_strconcat(tmpfs, "/src_serial", NUL= L); - g_autofree char *cap_pair =3D g_path_get_basename(test_path); - QTestState *from, *to; - - args->start.hide_stderr =3D true; - args->start.only_source =3D true; - - if (migrate_start(&from, &to, &args->start)) { - return; - } - - if (g_str_equal(cap_pair, "mapped_ram_postcopy")) { - const char *error =3D - "Mapped-ram migration is incompatible with postcopy"; - - validate_caps_pair(from, "mapped-ram", "postcopy-ram", error); - validate_caps_pair(from, "postcopy-ram", "mapped-ram", error); - } - - qtest_quit(from); - unlink(serial_path); -} - static void test_validate_uri_channels_both_set(char *name, MigrateCommon = *args) { args->uri =3D "tcp:127.0.0.1:0", @@ -309,7 +260,4 @@ void migration_test_add_misc(MigrationTestEnv *env) test_validate_uri_channels_both_set); migration_test_add("/migration/validate_uri/channels/none_set", test_validate_uri_channels_none_set); - migration_test_add_suffix("/migration/validate_caps/", - "mapped_ram_postcopy", - test_validate_caps_pair); } diff --git a/util/notify.c b/util/notify.c index 24420a7288e..512ba6aa916 100644 --- a/util/notify.c +++ b/util/notify.c @@ -75,3 +75,8 @@ int notifier_with_return_list_notify(NotifierWithReturnLi= st *list, void *data, } return ret; } + +bool notifier_with_return_list_empty(NotifierWithReturnList *list) +{ + return QLIST_EMPTY(&list->notifiers); +} --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932778; cv=none; d=zohomail.com; s=zohoarc; b=ZT/IqNEy13Fdi3j7x7cFYZWzlHi/qndOXqUFQiuWv90x4AnciZc5jm/kI1W/iSlII5eiiy0hiNFCedUAqKtgrjWPfLtdcwAbwx3SOWJySMPpgwuN+WVy0t5nBoudpXczKbIkuSpGiQoAGyyn1vGrKhDNtwsJ+SUdSiwkUxQsh30= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932778; 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=n4S1P9FhVcrug0Pv7l10DJXkcqiruL0W7qNcFKbXuXY=; b=Bd1Z+HnmEsF95/eiZc1nmVzhmwyJtnyWTBFWe2Z8bBVZZfNkpRKAVnJ7WmCSSNwWxElI0FBYHnJ2OArHHjmIZ392fy/bt30qtEtSpdQL5PNENOhee8NI0on9FF8uh9gTsyPkyZU/7EXR6dzXb79pROYF/g8B4+sKpQO6RFbzmjs= 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 178793277808236.537132258676024; Fri, 28 Aug 2026 08:59:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyzB-0001Nj-1G; Fri, 28 Aug 2026 11:59:21 -0400 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 1wzyz9-0001NI-C1 for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:19 -0400 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wzyz3-0008It-DP for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:18 -0400 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 A8C4821AEA; Fri, 28 Aug 2026 15:59:03 +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 71B1813686; Fri, 28 Aug 2026 15:59:02 +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 2MjGEEawkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932747; 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=n4S1P9FhVcrug0Pv7l10DJXkcqiruL0W7qNcFKbXuXY=; b=Rbs88rT44naq83rdkX71A0K8+s+TDG86ZwBF4Tr0VavvUX9uy/9jilVD0Ea0QXu6XGhyct DRxucnryo2jSbNt+nUmFZmbSZbfQ3wDa89qQUF9EWfXSNVJLU1oDYCkUdBhE67N2po1jL2 nXf/XMbPBM23dsaunvApXsw7xy37ir0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932747; 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=n4S1P9FhVcrug0Pv7l10DJXkcqiruL0W7qNcFKbXuXY=; b=LcSzGn2aqKTddFrF770IfD8S9V5sCgxnljg0zoMsHndAAVxhn7r7lOhd4eYJ1QDXDBG4mf HAsTy4rziM/85qAg== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=FlvhvwXG; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="sta4Yd/S" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932743; 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=n4S1P9FhVcrug0Pv7l10DJXkcqiruL0W7qNcFKbXuXY=; b=FlvhvwXGRNKAviIZdaVEDl3d6j2ZkqxjroI9eX8RoS6hNB5RyMraaEZSSAAbCCNKVqLTez cDFn7dgEW0moSgLw47EEpriaFPCQizKvQ+1y16PGP09Hk+2TwO9GZtk8Q+YVty3qUulTiV DeitcnFldzGYLNwB+xFVNTHGQs3no80= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932743; 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=n4S1P9FhVcrug0Pv7l10DJXkcqiruL0W7qNcFKbXuXY=; b=sta4Yd/S/AtLOJnSEjedLiOtStQJJ2lJIcexBpapOfTMA12XcHXW3XzNkUwB5VHtCPhpM4 XQR1PsClhrCkxhDg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Aadeshveer Singh , Juraj Marcin Subject: [PULL v2 10/30] migration/tests: Add test for fast snapshot load Date: Fri, 28 Aug 2026 12:58:25 -0300 Message-ID: <20260828155845.2874508-11-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.01 X-Rspamd-Queue-Id: A8C4821AEA X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spamd-Result: default: False [-3.01 / 50.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)[]; FROM_EQ_ENVFROM(0.00)[]; FREEMAIL_CC(0.00)[redhat.com,gmail.com]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:email,suse.de:mid,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; RCPT_COUNT_THREE(0.00)[4]; DKIM_TRACE(0.00)[suse.de:+] 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=195.135.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, 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: 1787932782217158500 Content-Type: text/plain; charset="utf-8" From: Aadeshveer Singh Add test_postcopy_file_mapped_ram() to test for saving a snapshot in mapped ram format and loading it using postcopy/fast snapshot load. Test is similar to test_precopy_file_mapped_ram() with additional start_hook to set postcopy capabilities on the receiving end. Signed-off-by: Aadeshveer Singh Reviewed-by: Peter Xu Reviewed-by: Juraj Marcin Signed-off-by: Peter Xu Signed-off-by: Fabiano Rosas --- tests/qtest/migration/file-tests.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/qtest/migration/file-tests.c b/tests/qtest/migration/fil= e-tests.c index 5118d9dec97..c7e4b05c61c 100644 --- a/tests/qtest/migration/file-tests.c +++ b/tests/qtest/migration/file-tests.c @@ -190,6 +190,25 @@ static void test_multifd_file_mapped_ram_dio(char *nam= e, MigrateCommon *args) test_file_common(args, true); } =20 +static void *migrate_hook_start_postcopy_mapped_ram(QTestState *from, + QTestState *to) +{ + migrate_set_capability( + to, MigrationCapability_lookup.array[MIGRATION_CAPABILITY_POSTCOPY= _RAM], + true); + + return NULL; +} + +static void test_postcopy_file_mapped_ram(char *name, MigrateCommon *args) +{ + args->start.caps[MIGRATION_CAPABILITY_MAPPED_RAM] =3D true; + + args->start_hook =3D migrate_hook_start_postcopy_mapped_ram; + + test_file_common(args, false); +} + #ifndef _WIN32 static void migrate_hook_end_multifd_mapped_ram_fdset(QTestState *from, QTestState *to, @@ -330,6 +349,11 @@ void migration_test_add_file(MigrationTestEnv *env) migration_test_add("/migration/multifd/file/mapped-ram/live", test_multifd_file_mapped_ram_live); =20 + if (env->has_uffd) { + migration_test_add("/migration/postcopy/file/mapped-ram", + test_postcopy_file_mapped_ram); + } + #ifndef _WIN32 migration_test_add("/migration/multifd/file/mapped-ram/fdset", test_multifd_file_mapped_ram_fdset); --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932909; cv=none; d=zohomail.com; s=zohoarc; b=cM1uevc4NwZh8pLuc48s9pUGlqNL4X+JxFH0yO2EdakVoFRiLQz/1d3+pL4KTM6pttJHAFu7SYo9ln1TSpK2dzJGiJWCqXkiw4hkyw4Xhj91hDQELaMotQpVDp+9ekEqd1dR9rW6ETbgHp+iUEJkVDSIPoxCT9ALyz3M24BNpXo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932909; 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=OH8PIWdsNXOXaCv296Cw5fvd6R8sSm1H9li+6Zmc81A=; b=jw4i/sz4ZcQIaKQjALDlZRNEfAgocVXj8id6eoPRTBadzsgOIlpPowdpDvbTMw3lhBKGPl3lPB9XybFAQTNK6Y1Ec8CBo/ujBS8Py5B00nZlVDmYjTHE345kMqFFec88LsWL3Pkm3ZgmVndROigwu4c4iDJpCqZRzANcpkxvqKc= 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 1787932909254694.5673987930055; Fri, 28 Aug 2026 09:01:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyzN-0001PE-Es; Fri, 28 Aug 2026 11:59:35 -0400 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 1wzyzD-0001OK-MT for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:24 -0400 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wzyz4-0008KC-Eh for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:21 -0400 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 F0D37221EA; Fri, 28 Aug 2026 15:59:04 +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 E6F9813687; Fri, 28 Aug 2026 15:59:03 +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 ePJnLUewkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932749; 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=OH8PIWdsNXOXaCv296Cw5fvd6R8sSm1H9li+6Zmc81A=; b=dzXFzC28eIKFf2VSeHD/7PljeMQY5mtVvOVep7Zsvbhd+bzAaYb0GJNrjUVo/b/k0LZOOx KOLqF9AEQSq+ix3nGNAdkpMago5rsoFShZqL8ApNb8b9LE9zmI5eMPOW5mZyGtdY77UB2h P9W5VqWzOWYU09BSWJWZJSAjKtgk6Bs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932749; 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=OH8PIWdsNXOXaCv296Cw5fvd6R8sSm1H9li+6Zmc81A=; b=moigRewz0ri5t9XcX12kgBAD5EQEBkQSFMAtL17/9941tBl7HTkemKuSyycG1SNdK85xY9 C5iNtpr20vcaEjCQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932744; 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=OH8PIWdsNXOXaCv296Cw5fvd6R8sSm1H9li+6Zmc81A=; b=lhuJB4XumcibCAw76vRknbT7S9qs8nTO2i9ejLpuj3CsQjvFgpiynRRK5sPetIoSdE2NBS k5ktq4pKW+x3kzhttLE90JxH+cIe56DfLSWOoV+rvXCX6xehl06HwJ0xbvqJ7T5344nxuJ byemXeZF00QEoWI1xvJlJfI01gnhocc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932744; 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=OH8PIWdsNXOXaCv296Cw5fvd6R8sSm1H9li+6Zmc81A=; b=i4uqP7BWreGS+i0RwEps74AWs1D8Eexdrr8yvY+kPYuQT7hOmdR0GorPdHbiX7UXH/Gn/s rwQIKSEWzpNv/0BQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Aadeshveer Singh Subject: [PULL v2 11/30] docs/migration: Add documentation for fast snapshot load feature Date: Fri, 28 Aug 2026 12:58:26 -0300 Message-ID: <20260828155845.2874508-12-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.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]; RCVD_TLS_ALL(0.00)[]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; 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)[]; FREEMAIL_CC(0.00)[redhat.com,gmail.com]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email,imap1.dmz-prg2.suse.org:helo]; RCVD_COUNT_TWO(0.00)[2]; FREEMAIL_ENVRCPT(0.00)[gmail.com] 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=195.135.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, 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: 1787932913113154100 Content-Type: text/plain; charset="utf-8" From: Aadeshveer Singh Add documenatation for fast snapshot load covering an overview, the architecture, usage and limitations. Signed-off-by: Aadeshveer Singh Reviewed-by: Peter Xu Signed-off-by: Peter Xu Signed-off-by: Fabiano Rosas --- docs/devel/migration/fast-snapshot-load.rst | 82 +++++++++++++++++++++ docs/devel/migration/features.rst | 1 + 2 files changed, 83 insertions(+) create mode 100644 docs/devel/migration/fast-snapshot-load.rst diff --git a/docs/devel/migration/fast-snapshot-load.rst b/docs/devel/migra= tion/fast-snapshot-load.rst new file mode 100644 index 00000000000..fe2361d6fe1 --- /dev/null +++ b/docs/devel/migration/fast-snapshot-load.rst @@ -0,0 +1,82 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Fast Snapshot Load +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Overview +=3D=3D=3D=3D=3D=3D=3D=3D +Fast snapshot load is an extension of the postcopy migration feature +to disk loads. + +Unlike a usual snapshot load, which requires all VM data (RAM as well +as device states) to be loaded into host RAM from the snapshot file +for the guest to run, fast snapshot load uses postcopy infrastructure +to load in only the required device states and allows RAM pages to +be loaded after the guest starts execution. The idea is to start the +guest and serve its page faults on the go, reducing the perceived +resume time for large snapshots. + +Architecture +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +This feature combines postcopy migration and mapped-ram capabilities +to load RAM pages on demand. It is done by catching guest faults using +Linux ``userfaultfd`` and loading the page by calculating the offset +of its location in the snapshot file using mapped-ram capabilities. + +Fault Thread +------------ +The fault thread uses Linux ``userfaultfd`` to catch page faults caused +by guest and directly load the page from the snapshot file. It is +very similar to network postcopy fault thread, with primary difference +being it loads pages directly by reading from the snapshot file. + +Eager Thread +------------ +Eager thread iterates over all pages in RAM and loads each page not +yet loaded by fault thread. It is required as unlike network postcopy +where majority of RAM has already been loaded via precopy, here entire +RAM is waiting to be loaded. If there is no eager loading thread each +page will only be loaded when it is required by guest. In case there +are some background pages that are never/rarely accessed by guest, +the system will be locked in migration state indefinitely. + +Synchronization +--------------- +In order to make sure both of these threads do not load the same page +twice potentially overwriting and corrupting user RAM, a bitmap is +used (``RAMBlock->pending_bmap``) which tracks the pages claimed to +be loaded by threads. This prevents race condition when one thread +is loading the page and other one tries to do the same. + +Usage +=3D=3D=3D=3D=3D + +Simply enable ``mapped-ram`` and ``postcopy-ram`` capabilities on +the destination: + +.. code-block:: text + + migrate_set_capability mapped-ram on + migrate_set_capability postcopy-ram on + +Use a ``file:`` URI for migration: + +.. code-block:: text + + migrate_incoming file:/path/to/snapshot/file + +Limitations +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + + - Multifd + Fast snapshot load is currently incompatible with ``multifd`` + capability. While ``mapped-ram`` allows for parallel disk I/O, + coupling it with ``postcopy`` capability requires additional + infrastructure. + + - Host OS support + Because this feautre essentially depends on ``userfaultfd`` + to trap page faults, it is supported only on Linux hosts. + + - vhost-user + Fast snapshot load does not currently support ``vhost-user`` + backends. diff --git a/docs/devel/migration/features.rst b/docs/devel/migration/featu= res.rst index 9aef79e7fa4..23c2a93173c 100644 --- a/docs/devel/migration/features.rst +++ b/docs/devel/migration/features.rst @@ -11,6 +11,7 @@ Migration has plenty of features to support different use= cases. vfio virtio mapped-ram + fast-snapshot-load CPR qpl-compression uadk-compression --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932954; cv=none; d=zohomail.com; s=zohoarc; b=ggXRnuDINkhxYOqP12vP6WlD2gHw8lN9KNTrw4ccbXw8/33K6+5sMthXwRkLPLJ/Rosv3RXbIuT5fz7EYfTbiGN2PaEheDBQ8w3bx1UvBFXlXvsTErGq3G+Syw7AYpmzkVXEfUi7mlG2tplNpQ7sxOJVgVkoR0+P1fOYHvyJwM4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932954; 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=EG3tEJg1Q8Qn100kIO02Wh6YC7gR63FtT/AddHPZaVc=; b=hsvqC/cU+P/TdLQUBdY3vgE4rLeth2koKyfYyr30dI8j/WfI+Axm8mKUaIV1cxpgpy8cW0BrX/+MjlTIUpccFV1JbosYV1+Hn48TUPnVDnMDep8O/SjnaoU11CbUMWWZ/RlzESFqHCcDuVflUeYXGGHYwwymdH4wzYkr8EMrioE= 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 1787932954609829.318516792406; Fri, 28 Aug 2026 09:02:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyzJ-0001Or-SK; Fri, 28 Aug 2026 11:59:29 -0400 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 1wzyzG-0001Oa-Kt for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:27 -0400 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wzyz5-0008LA-Sy for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:24 -0400 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 6B32721CA1; Fri, 28 Aug 2026 15:59:06 +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 3AD3C1368F; Fri, 28 Aug 2026 15:59:05 +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 OJ5dA0mwkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932750; 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=EG3tEJg1Q8Qn100kIO02Wh6YC7gR63FtT/AddHPZaVc=; b=wMfV7oWwTc/1Zgl34kR/QDnBG2RsZ+RHH2j/PzFjbBnNtHZztOkM7T+cP2SpPHg8QuTuwJ 9s/9hjv163CNd7tJgYI+3dyBCP94mSIwgh8SehZk6iCVmQS8NE3V1RWworHx2TV//sjQSv sJ4B1HlFFD72x3SPgf8kaAbQW+dpE6Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932750; 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=EG3tEJg1Q8Qn100kIO02Wh6YC7gR63FtT/AddHPZaVc=; b=vX5syVVBpMS6mg9QGECaxV0LxY5G9UGMvmUm/mYoXx1n6PJFBgKSViLlbVUMHT25QJq2tz YpQUcDeL1UPrzzAg== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=jT4JOlHZ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=7mDys527 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932746; 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=EG3tEJg1Q8Qn100kIO02Wh6YC7gR63FtT/AddHPZaVc=; b=jT4JOlHZm0cU6gqpCkEaPyLtIVzuC93T722AYWxRxk/jBXfnfZtrQu4o4TF7lxOjY8GGZA 7YI8xf38OpYYO+Nsc5vXvPaJ7T9aVgo/jBTVKffaMrirMDWdOkzsg03o9gBn3/he0pvegC 3cwUChJ1oEnJZzktfXD6+GxLwkGvHtM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932746; 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=EG3tEJg1Q8Qn100kIO02Wh6YC7gR63FtT/AddHPZaVc=; b=7mDys527NBsZZFodYlLBMCC5tOh8e9Y3bQhz6IyGlgun+cPbAKnTPC4sr3mqpfdIiOAJx+ z02tyHMBZlHuV/AA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Jinpu Wang Subject: [PULL v2 12/30] migration/rdma: Introduce RDMA_CONTROL_NUM Date: Fri, 28 Aug 2026 12:58:27 -0300 Message-ID: <20260828155845.2874508-13-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Queue-Id: 6B32721CA1 X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; 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)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:email,suse.de:mid,ionos.com:email,imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.de:+] X-Spam-Score: -3.01 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=195.135.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, 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: 1787932956103158500 Content-Type: text/plain; charset="utf-8" From: Peter Xu Introduce this to say how many control messages we have. We did it because we're going to remove the last one (RDMA_CONTROL_UNREGISTER_FINISHED) soon. Reviewed-by: Jinpu Wang Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas Reviewed-by: Jack Wang Signed-off-by: Fabiano Rosas --- migration/rdma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/migration/rdma.c b/migration/rdma.c index 438419d1894..62a509b2362 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -144,6 +144,7 @@ enum { RDMA_CONTROL_REGISTER_FINISHED, /* current iteration finished */ RDMA_CONTROL_UNREGISTER_REQUEST, /* dynamic UN-registration */ RDMA_CONTROL_UNREGISTER_FINISHED, /* unpinning finished */ + RDMA_CONTROL_NUM, }; =20 =20 @@ -235,7 +236,7 @@ static const char *control_desc(unsigned int rdma_contr= ol) [RDMA_CONTROL_UNREGISTER_FINISHED] =3D "UNREGISTER FINISHED", }; =20 - if (rdma_control > RDMA_CONTROL_UNREGISTER_FINISHED) { + if (rdma_control >=3D RDMA_CONTROL_NUM) { return "??BAD CONTROL VALUE??"; } =20 --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932866; cv=none; d=zohomail.com; s=zohoarc; b=UTNlg1ka5wivU2x0qbGR2a1iF7EoGg8pO4ERZyDNW4VRdF/rF/PbtcRYV85fAQ0C85458KPfZl1gu5KmBcOfyOmaSZSwPZWe+KD1R//mixK4g0AJbrmVE/GnDK9C3xpgn+GuWshSDwzJI/NXbmQd4CQ2WnDXL8duPrAZSoK8t+4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932866; 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=i5oqjmmi8+oxWLJMCwx89ZO5MoyymFjRNHN3YwHmaE8=; b=SGJQXSrQHF/4HjuMAj86mjxUpx/j01iUTzDWq+lUhlnLnLwzqAKd0huhZRva63jpag0QL4tSRt9bxda41Ntn0gyVR3zZ/xy2L8ofCN7wxPJGJy9POe1zQIVni3P86gwpHVOIskeexnbbRtTUMnAzGEUDvGDBVw0NHYcGxYVU9WE= 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 1787932866312259.03849025857323; Fri, 28 Aug 2026 09:01:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyzQ-0001U2-Vd; Fri, 28 Aug 2026 11:59:37 -0400 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 1wzyzJ-0001Os-Tf for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:29 -0400 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 1wzyz7-0008MM-NQ for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:29 -0400 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-out2.suse.de (Postfix) with ESMTPS id 8B1701F842; Fri, 28 Aug 2026 15:59:07 +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 830D313688; Fri, 28 Aug 2026 15:59:06 +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 2EEDFUqwkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932751; 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=i5oqjmmi8+oxWLJMCwx89ZO5MoyymFjRNHN3YwHmaE8=; b=hwSpZWw229E1jYHrk9NqboRM6vhtLyMyf/flczWMf19Dws1kXoBOkFNCqjekVlkzjJFA0p 2sU/klQ8CSI1iNwh8ASh/fUJ3nCkJxz9B1ANAoUsuSFqe4fTBhdeZmw1S3vbUtUQCL6cYO apseQSUySLQd1FfZpp2i0Y086/KVEuk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932751; 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=i5oqjmmi8+oxWLJMCwx89ZO5MoyymFjRNHN3YwHmaE8=; b=n99UOZ0PVbMUv9zW13N/klXnFausrb5DkvOju7FCpoqpBLc07ISQIiQWgP2KoRHoswTc7C UkJuUnh8rgMIxbCw== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=c57zhPN4; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=x0GsthUZ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932747; 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=i5oqjmmi8+oxWLJMCwx89ZO5MoyymFjRNHN3YwHmaE8=; b=c57zhPN43p/DZYUVinKISshlItmcXosD8W7Ygz8oq0TSAFca93oe7rG6/UGzvBEdQz/pKL c5e73EbhiERhnDKFZsEkV/qKIs71NjUj24kfOoXqPKul6Jx0tUkLR5GmIcuWztUbOqJvcx yJhPbBF3PqJjC9ifI/zYgSgImoVZdlk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932747; 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=i5oqjmmi8+oxWLJMCwx89ZO5MoyymFjRNHN3YwHmaE8=; b=x0GsthUZWLN1gD+xdbltRxhBe8BQ+meng+FSotNu4Z2dfHhRGt0h3LXRJF/l94uKyBq3/u 2BZTOXZDHZRFpjDw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Jinpu Wang Subject: [PULL v2 13/30] migration/rdma: Remove unregister code Date: Fri, 28 Aug 2026 12:58:28 -0300 Message-ID: <20260828155845.2874508-14-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.01 X-Rspamd-Queue-Id: 8B1701F842 X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; 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)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[gitlab.com:url,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:dkim,suse.de:email,suse.de:mid,ionos.com:email]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_TLS_ALL(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)[3]; DKIM_TRACE(0.00)[suse.de:+] 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: 1787932868426154100 Content-Type: text/plain; charset="utf-8" From: Peter Xu The unregister code was there since the first commit RDMA migration was merged, but it was never functioning. Remove the dead code. Since the two control messages are the last ones, we don't even need to worry about compatibility of legacy RDMA control commands, we can directly remove the messages too. As a side effect, this patch closes a report by removing the code completely. Reported-by: Tristan (@TristanInSec) Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4003 Reviewed-by: Jinpu Wang Signed-off-by: Peter Xu Signed-off-by: Fabiano Rosas --- migration/rdma.c | 133 ----------------------------------------- migration/trace-events | 9 --- 2 files changed, 142 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index 62a509b2362..eae4afd6df0 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -142,8 +142,6 @@ enum { RDMA_CONTROL_REGISTER_REQUEST, /* dynamic page registration */ RDMA_CONTROL_REGISTER_RESULT, /* key to use after registration */ RDMA_CONTROL_REGISTER_FINISHED, /* current iteration finished */ - RDMA_CONTROL_UNREGISTER_REQUEST, /* dynamic UN-registration */ - RDMA_CONTROL_UNREGISTER_FINISHED, /* unpinning finished */ RDMA_CONTROL_NUM, }; =20 @@ -232,8 +230,6 @@ static const char *control_desc(unsigned int rdma_contr= ol) [RDMA_CONTROL_REGISTER_REQUEST] =3D "REGISTER REQUEST", [RDMA_CONTROL_REGISTER_RESULT] =3D "REGISTER RESULT", [RDMA_CONTROL_REGISTER_FINISHED] =3D "REGISTER FINISHED", - [RDMA_CONTROL_UNREGISTER_REQUEST] =3D "UNREGISTER REQUEST", - [RDMA_CONTROL_UNREGISTER_FINISHED] =3D "UNREGISTER FINISHED", }; =20 if (rdma_control >=3D RDMA_CONTROL_NUM) { @@ -370,9 +366,6 @@ typedef struct RDMAContext { int total_registrations; int total_writes; =20 - int unregister_current, unregister_next; - uint64_t unregistrations[RDMA_SIGNALED_SEND_MAX]; - GHashTable *blockmap; =20 /* the RDMAContext for return path */ @@ -1186,91 +1179,6 @@ static int qemu_rdma_reg_control(RDMAContext *rdma, = int idx) return -1; } =20 -/* - * Perform a non-optimized memory unregistration after every transfer - * for demonstration purposes, only if pin-all is not requested. - * - * Potential optimizations: - * 1. Start a new thread to run this function continuously - - for bit clearing - - and for receipt of unregister messages - * 2. Use an LRU. - * 3. Use workload hints. - */ -static int qemu_rdma_unregister_waiting(RDMAContext *rdma) -{ - Error *err =3D NULL; - - while (rdma->unregistrations[rdma->unregister_current]) { - int ret; - uint64_t wr_id =3D rdma->unregistrations[rdma->unregister_current]; - uint64_t chunk =3D - (wr_id & RDMA_WRID_CHUNK_MASK) >> RDMA_WRID_CHUNK_SHIFT; - uint64_t index =3D - (wr_id & RDMA_WRID_BLOCK_MASK) >> RDMA_WRID_BLOCK_SHIFT; - RDMALocalBlock *block =3D - &(rdma->local_ram_blocks.block[index]); - RDMARegister reg =3D { .current_index =3D index }; - RDMAControlHeader resp =3D { .type =3D RDMA_CONTROL_UNREGISTER_FIN= ISHED, - }; - RDMAControlHeader head =3D { .len =3D sizeof(RDMARegister), - .type =3D RDMA_CONTROL_UNREGISTER_REQUE= ST, - .repeat =3D 1, - }; - - trace_qemu_rdma_unregister_waiting_proc(chunk, - rdma->unregister_current); - - rdma->unregistrations[rdma->unregister_current] =3D 0; - rdma->unregister_current++; - - if (rdma->unregister_current =3D=3D RDMA_SIGNALED_SEND_MAX) { - rdma->unregister_current =3D 0; - } - - - /* - * Unregistration is speculative (because migration is single-thre= aded - * and we cannot break the protocol's inifinband message ordering). - * Thus, if the memory is currently being used for transmission, - * then abort the attempt to unregister and try again - * later the next time a completion is received for this memory. - */ - clear_bit(chunk, block->unregister_bitmap); - - if (test_bit(chunk, block->transit_bitmap)) { - trace_qemu_rdma_unregister_waiting_inflight(chunk); - continue; - } - - trace_qemu_rdma_unregister_waiting_send(chunk); - - ret =3D ibv_dereg_mr(block->pmr[chunk]); - block->pmr[chunk] =3D NULL; - block->remote_keys[chunk] =3D 0; - - if (ret !=3D 0) { - error_report("unregistration chunk failed: %s", - strerror(ret)); - return -1; - } - rdma->total_registrations--; - - reg.key.chunk =3D chunk; - register_to_network(rdma, ®); - ret =3D qemu_rdma_exchange_send(rdma, &head, (uint8_t *) ®, - &resp, NULL, NULL, &err); - if (ret < 0) { - error_report_err(err); - return -1; - } - - trace_qemu_rdma_unregister_waiting_complete(chunk); - } - - return 0; -} - static uint64_t qemu_rdma_make_wrid(uint64_t wr_id, uint64_t index, uint64_t chunk) { @@ -2757,8 +2665,6 @@ static int qemu_rdma_drain_cq(RDMAContext *rdma) } } =20 - qemu_rdma_unregister_waiting(rdma); - return 0; } =20 @@ -3336,10 +3242,6 @@ int rdma_registration_handle(QEMUFile *f) .type =3D RDMA_CONTROL_REGISTER_RESULT, .repeat =3D 0, }; - RDMAControlHeader unreg_resp =3D { .len =3D 0, - .type =3D RDMA_CONTROL_UNREGISTER_FINISHED, - .repeat =3D 0, - }; RDMAControlHeader blocks =3D { .type =3D RDMA_CONTROL_RAM_BLOCKS_RESUL= T, .repeat =3D 1 }; QIOChannelRDMA *rioc; @@ -3552,41 +3454,6 @@ int rdma_registration_handle(QEMUFile *f) ret =3D qemu_rdma_post_send_control(rdma, (uint8_t *) results, ®_resp, &err); =20 - if (ret < 0) { - error_report_err(err); - goto err; - } - break; - case RDMA_CONTROL_UNREGISTER_REQUEST: - trace_rdma_registration_handle_unregister(head.repeat); - unreg_resp.repeat =3D head.repeat; - registers =3D (RDMARegister *) rdma->wr_data[idx].control_curr; - - for (int count =3D 0; count < head.repeat; count++) { - reg =3D ®isters[count]; - network_to_register(reg); - - trace_rdma_registration_handle_unregister_loop(count, - reg->current_index, reg->key.chunk); - - block =3D &(rdma->local_ram_blocks.block[reg->current_inde= x]); - - ret =3D ibv_dereg_mr(block->pmr[reg->key.chunk]); - block->pmr[reg->key.chunk] =3D NULL; - - if (ret !=3D 0) { - error_report("rdma unregistration chunk failed: %s", - strerror(errno)); - goto err; - } - - rdma->total_registrations--; - - trace_rdma_registration_handle_unregister_success(reg->key= .chunk); - } - - ret =3D qemu_rdma_post_send_control(rdma, NULL, &unreg_resp, &= err); - if (ret < 0) { error_report_err(err); goto err; diff --git a/migration/trace-events b/migration/trace-events index 4ae1c226f90..6d70f8e8cad 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -242,12 +242,6 @@ qemu_rdma_register_and_get_keys(uint64_t len, void *st= art) "Registering %" PRIu6 qemu_rdma_register_odp_mr(const char *name) "Try to register On-Demand Pag= ing memory region: %s" qemu_rdma_advise_mr(const char *name, uint32_t len, uint64_t addr, const c= har *res) "Try to advise block %s prefetch at %" PRIu32 "@0x%" PRIx64 ": %s" qemu_rdma_resolve_host_trying(const char *host, const char *ip) "Trying %s= =3D> %s" -qemu_rdma_signal_unregister_append(uint64_t chunk, int pos) "Appending unr= egister chunk %" PRIu64 " at position %d" -qemu_rdma_signal_unregister_already(uint64_t chunk) "Unregister chunk %" P= RIu64 " already in queue" -qemu_rdma_unregister_waiting_inflight(uint64_t chunk) "Cannot unregister i= nflight chunk: %" PRIu64 -qemu_rdma_unregister_waiting_proc(uint64_t chunk, int pos) "Processing unr= egister for chunk: %" PRIu64 " at position %d" -qemu_rdma_unregister_waiting_send(uint64_t chunk) "Sending unregister for = chunk: %" PRIu64 -qemu_rdma_unregister_waiting_complete(uint64_t chunk) "Unregister for chun= k: %" PRIu64 " complete." qemu_rdma_write_flush(int sent) "sent total: %d" qemu_rdma_write_one_block(int count, int block, uint64_t chunk, uint64_t c= urrent, uint64_t len, int nb_sent, int nb_chunks) "(%d) Not clobbering: blo= ck: %d chunk %" PRIu64 " current %" PRIu64 " len %" PRIu64 " %d %d" qemu_rdma_write_one_post(uint64_t chunk, long addr, long remote, uint32_t = len) "Posting chunk: %" PRIu64 ", addr: 0x%lx remote: 0x%lx, bytes %" PRIu32 @@ -266,9 +260,6 @@ rdma_registration_handle_ram_blocks_loop(const char *na= me, uint64_t offset, uint rdma_registration_handle_register(int requests) "%d requests" rdma_registration_handle_register_loop(int req, int index, uint64_t addr, = uint64_t chunks) "Registration request (%d): index %d, current_addr %" PRIu= 64 " chunks: %" PRIu64 rdma_registration_handle_register_rkey(int rkey) "0x%x" -rdma_registration_handle_unregister(int requests) "%d requests" -rdma_registration_handle_unregister_loop(int count, int index, uint64_t ch= unk) "Unregistration request (%d): index %d, chunk %" PRIu64 -rdma_registration_handle_unregister_success(uint64_t chunk) "%" PRIu64 rdma_registration_handle_wait(void) "" rdma_registration_start(uint64_t flags) "%" PRIu64 rdma_registration_stop(uint64_t flags) "%" PRIu64 --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932869; cv=none; d=zohomail.com; s=zohoarc; b=JEGZKyI6La5fmCZKG7whCGo3TulcTN0AEmLjixn2HE1N0j/dmiTHcp1MyGLbTTiXIRRmyuDifeZSd5Z0ImbQ4Izp/8ybhwIKAmDBFi+Xw0oOisg0XJ+kLk00SSptThcAwpC8JqDqC5v1mrHXXFyr0X70Wjuj7Wqyg3b2iME4IVs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932869; 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=yvMJE5mi8zsj6pryNWUVC7tIkIWE1cvTrnxmR6wVgmc=; b=GmY5y079FEX9s+pfGGnMPtQ+A95nmFUJteVhEXQ3U4lTP+2lVTKVFFPT12hZajZgUCrf6aUzs+ifj+JuzSSZBvxMaTleer68fRHRcKX13jRQT5GYrGxk2v0fqJxXyLbCXF61dtUFUCN2u2AdcrJV/bcK+bxU+D6xCO8dAJYXcWc= 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 1787932869437252.3316844028252; Fri, 28 Aug 2026 09:01:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyzS-0001X9-4T; Fri, 28 Aug 2026 11:59:38 -0400 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 1wzyzL-0001P9-SE for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:33 -0400 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 1wzyz9-0008Nx-1w for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:31 -0400 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 DA1FE2224A; Fri, 28 Aug 2026 15:59:08 +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 CBC451352D; Fri, 28 Aug 2026 15:59:07 +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 QDW5JkuwkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932753; 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=yvMJE5mi8zsj6pryNWUVC7tIkIWE1cvTrnxmR6wVgmc=; b=Mrx8f3UyDbPiK8/M4J6wxcEfVn5vwc0YxQ2a/FNfvhOOhBPBTce1wh3Hz+ivW8WY8tJrmZ 1cPTaKuEAKfvmxiB6G2ETF9H7e4rzJus9BSqZpnrX5ye54AHk8LRZfYYSDEaeEQ9kDqIMh /eVBcUggWPX9I5AWp7DEom3hs78ifYA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932753; 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=yvMJE5mi8zsj6pryNWUVC7tIkIWE1cvTrnxmR6wVgmc=; b=ARDHsoUH98ZVXGJmbND/YAhxz3NNFRjvoO4IdUwANu1mAZVHiYay2hGGH/TUIZxh+6QjmP ncNCPD9Nd81cC0BQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932748; 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=yvMJE5mi8zsj6pryNWUVC7tIkIWE1cvTrnxmR6wVgmc=; b=NOUSdIzzmoBcLNi6zEr7qkAAdbS8ta6GRscKWvuIiPhPQO9Ieuhb5PDDmtVLz1agNTtkxS eUkQmbeKdoOltKtlMmxFHRdnMn6nrmFeq7nye7lKA7g7HGA6DuEyD1pKN0bEchHy/B1yWU 5Qqy81ylpRAkbnRvr5KPIFJnXy+vXHQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932748; 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=yvMJE5mi8zsj6pryNWUVC7tIkIWE1cvTrnxmR6wVgmc=; b=dJAAvVNFho1wV897NM1/AYkgQ3zkObHhXYy8sRIytHyKa++LxEgBdXzMgmpIpli1xhMCro xJqWqxT9T/yr8tAQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Jinpu Wang Subject: [PULL v2 14/30] migration/rdma: Stick with rdma_ prefix for all tracepoints Date: Fri, 28 Aug 2026 12:58:29 -0300 Message-ID: <20260828155845.2874508-15-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.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.997]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(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)[]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,ionos.com:email,suse.de:email,suse.de:mid]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] 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) (identity @suse.de) X-ZM-MESSAGEID: 1787932871620158500 Content-Type: text/plain; charset="utf-8" From: Peter Xu There're a bunch of RDMA tracepoints that are prefixed with "rdma_*", most of the rest with "qemu_rdma_*". Align them up. The "qemu_" prefix isn't helping. Reviewed-by: Jinpu Wang Signed-off-by: Peter Xu Signed-off-by: Fabiano Rosas --- migration/rdma.c | 76 +++++++++++++++++++++--------------------- migration/trace-events | 72 +++++++++++++++++++-------------------- 2 files changed, 74 insertions(+), 74 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index eae4afd6df0..ffae0a887f6 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -631,7 +631,7 @@ static void qemu_rdma_init_ram_blocks(RDMAContext *rdma) memset(local, 0, sizeof *local); ret =3D foreach_not_ignored_block(qemu_rdma_init_one_block, rdma); assert(!ret); - trace_qemu_rdma_init_ram_blocks(local->nb_blocks); + trace_rdma_init_ram_blocks(local->nb_blocks); rdma->dest_blocks =3D g_new0(RDMADestBlock, rdma->local_ram_blocks.nb_blocks); local->init =3D true; @@ -734,11 +734,11 @@ static void qemu_rdma_dump_id(const char *who, struct= ibv_context *verbs) struct ibv_port_attr port; =20 if (ibv_query_port(verbs, 1, &port)) { - trace_qemu_rdma_dump_id_failed(who); + trace_rdma_dump_id_failed(who); return; } =20 - trace_qemu_rdma_dump_id(who, + trace_rdma_dump_id(who, verbs->device->name, verbs->device->dev_name, verbs->device->dev_path, @@ -759,7 +759,7 @@ static void qemu_rdma_dump_gid(const char *who, struct = rdma_cm_id *id) char dgid[33]; inet_ntop(AF_INET6, &id->route.addr.addr.ibaddr.sgid, sgid, sizeof sgi= d); inet_ntop(AF_INET6, &id->route.addr.addr.ibaddr.dgid, dgid, sizeof dgi= d); - trace_qemu_rdma_dump_gid(who, sgid, dgid); + trace_rdma_dump_gid(who, sgid, dgid); } =20 /* @@ -809,7 +809,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Er= ror **errp) =20 inet_ntop(e->ai_family, &((struct sockaddr_in *) e->ai_dst_addr)->sin_addr, ip, sizeof= ip); - trace_qemu_rdma_resolve_host_trying(rdma->host, ip); + trace_rdma_resolve_host_trying(rdma->host, ip); =20 ret =3D rdma_resolve_addr(rdma->cm_id, NULL, e->ai_dst_addr, RDMA_RESOLVE_TIMEOUT_MS); @@ -998,7 +998,7 @@ static void qemu_rdma_advise_prefetch_mr(struct ibv_pd = *pd, uint64_t addr, ret =3D ibv_advise_mr(pd, advice, IBV_ADVISE_MR_FLAG_FLUSH, &sg_list, 1); /* ignore the error */ - trace_qemu_rdma_advise_mr(name, len, addr, strerror(ret)); + trace_rdma_advise_mr(name, len, addr, strerror(ret)); #endif } =20 @@ -1029,7 +1029,7 @@ static int qemu_rdma_reg_whole_ram_blocks(RDMAContext= *rdma, Error **errp) ibv_reg_mr(rdma->pd, local->block[i].local_host_addr, local->block[i].length, access); - trace_qemu_rdma_register_odp_mr(local->block[i].block_name= ); + trace_rdma_register_odp_mr(local->block[i].block_name); =20 if (local->block[i].mr) { qemu_rdma_advise_prefetch_mr(rdma->pd, @@ -1125,7 +1125,7 @@ static int qemu_rdma_register_and_get_keys(RDMAContex= t *rdma, int access =3D rkey ? IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_W= RITE : 0; =20 - trace_qemu_rdma_register_and_get_keys(len, chunk_start); + trace_rdma_register_and_get_keys(len, chunk_start); =20 block->pmr[chunk] =3D ibv_reg_mr(rdma->pd, chunk_start, len, acces= s); /* @@ -1139,7 +1139,7 @@ static int qemu_rdma_register_and_get_keys(RDMAContex= t *rdma, access |=3D IBV_ACCESS_ON_DEMAND; /* register ODP mr */ block->pmr[chunk] =3D ibv_reg_mr(rdma->pd, chunk_start, len, a= ccess); - trace_qemu_rdma_register_odp_mr(block->block_name); + trace_rdma_register_odp_mr(block->block_name); =20 if (block->pmr[chunk]) { qemu_rdma_advise_prefetch_mr(rdma->pd, (uintptr_t)chunk_st= art, @@ -1221,7 +1221,7 @@ static int qemu_rdma_poll(RDMAContext *rdma, struct i= bv_cq *cq, =20 if (rdma->control_ready_expected && (wr_id >=3D RDMA_WRID_RECV_CONTROL)) { - trace_qemu_rdma_poll_recv(wr_id - RDMA_WRID_RECV_CONTROL, wr_id, + trace_rdma_poll_recv(wr_id - RDMA_WRID_RECV_CONTROL, wr_id, rdma->nb_sent); rdma->control_ready_expected =3D 0; } @@ -1233,7 +1233,7 @@ static int qemu_rdma_poll(RDMAContext *rdma, struct i= bv_cq *cq, (wc.wr_id & RDMA_WRID_BLOCK_MASK) >> RDMA_WRID_BLOCK_SHIFT; RDMALocalBlock *block =3D &(rdma->local_ram_blocks.block[index]); =20 - trace_qemu_rdma_poll_write(wr_id, rdma->nb_sent, + trace_rdma_poll_write(wr_id, rdma->nb_sent, index, chunk, block->local_host_addr, (void *)(uintptr_t)block->remote_host_a= ddr); =20 @@ -1243,7 +1243,7 @@ static int qemu_rdma_poll(RDMAContext *rdma, struct i= bv_cq *cq, rdma->nb_sent--; } } else { - trace_qemu_rdma_poll_other(wr_id, rdma->nb_sent); + trace_rdma_poll_other(wr_id, rdma->nb_sent); } =20 *wr_id_out =3D wc.wr_id; @@ -1378,7 +1378,7 @@ static int qemu_rdma_block_for_wrid(RDMAContext *rdma, break; } if (wr_id !=3D wrid_requested) { - trace_qemu_rdma_block_for_wrid_miss(wrid_requested, wr_id); + trace_rdma_block_for_wrid_miss(wrid_requested, wr_id); } } =20 @@ -1415,7 +1415,7 @@ static int qemu_rdma_block_for_wrid(RDMAContext *rdma, break; } if (wr_id !=3D wrid_requested) { - trace_qemu_rdma_block_for_wrid_miss(wrid_requested, wr_id); + trace_rdma_block_for_wrid_miss(wrid_requested, wr_id); } } =20 @@ -1463,7 +1463,7 @@ static int qemu_rdma_post_send_control(RDMAContext *r= dma, uint8_t *buf, .num_sge =3D 1, }; =20 - trace_qemu_rdma_post_send_control(control_desc(head->type)); + trace_rdma_post_send_control(control_desc(head->type)); =20 /* * We don't actually need to do a memcpy() in here if we used @@ -1546,10 +1546,10 @@ static int qemu_rdma_exchange_get_response(RDMACont= ext *rdma, network_to_control((void *) rdma->wr_data[idx].control); memcpy(head, rdma->wr_data[idx].control, sizeof(RDMAControlHeader)); =20 - trace_qemu_rdma_exchange_get_response_start(control_desc(expecting)); + trace_rdma_exchange_get_response_start(control_desc(expecting)); =20 if (expecting =3D=3D RDMA_CONTROL_NONE) { - trace_qemu_rdma_exchange_get_response_none(control_desc(head->type= ), + trace_rdma_exchange_get_response_none(control_desc(head->type), head->type); } else if (head->type !=3D expecting || head->type =3D=3D RDMA_CONTROL= _ERROR) { error_setg(errp, "Was expecting a %s (%d) control message" @@ -1659,14 +1659,14 @@ static int qemu_rdma_exchange_send(RDMAContext *rdm= a, RDMAControlHeader *head, */ if (resp) { if (callback) { - trace_qemu_rdma_exchange_send_issue_callback(); + trace_rdma_exchange_send_issue_callback(); ret =3D callback(rdma, errp); if (ret < 0) { return -1; } } =20 - trace_qemu_rdma_exchange_send_waiting(control_desc(resp->type)); + trace_rdma_exchange_send_waiting(control_desc(resp->type)); ret =3D qemu_rdma_exchange_get_response(rdma, resp, resp->type, RDMA_WRID_DATA, errp); @@ -1679,7 +1679,7 @@ static int qemu_rdma_exchange_send(RDMAContext *rdma,= RDMAControlHeader *head, if (resp_idx) { *resp_idx =3D RDMA_WRID_DATA; } - trace_qemu_rdma_exchange_send_received(control_desc(resp->type)); + trace_rdma_exchange_send_received(control_desc(resp->type)); } =20 rdma->control_ready_expected =3D 1; @@ -1782,7 +1782,7 @@ retry: } } =20 - trace_qemu_rdma_write_one_top(chunks + 1, + trace_rdma_write_one_top(chunks + 1, (chunks + 1) * chunk_size / 1024 / 1024); =20 chunk_end =3D ram_chunk_end(block, chunk + chunks); @@ -1790,7 +1790,7 @@ retry: =20 while (test_bit(chunk, block->transit_bitmap)) { (void)count; - trace_qemu_rdma_write_one_block(count++, current_index, chunk, + trace_rdma_write_one_block(count++, current_index, chunk, sge.addr, length, rdma->nb_sent, block->nb_chunks); =20 ret =3D qemu_rdma_block_for_wrid(rdma, RDMA_WRID_RDMA_WRITE, NULL); @@ -1823,7 +1823,7 @@ retry: head.len =3D sizeof(comp); head.type =3D RDMA_CONTROL_COMPRESS; =20 - trace_qemu_rdma_write_one_zero(chunk, sge.length, + trace_rdma_write_one_zero(chunk, sge.length, current_index, current_addr= ); =20 compress_to_network(rdma, &comp); @@ -1860,7 +1860,7 @@ retry: } reg.chunks =3D chunks; =20 - trace_qemu_rdma_write_one_sendreg(chunk, sge.length, current_i= ndex, + trace_rdma_write_one_sendreg(chunk, sge.length, current_index, current_addr); =20 register_to_network(rdma, ®); @@ -1883,7 +1883,7 @@ retry: =20 network_to_result(reg_result); =20 - trace_qemu_rdma_write_one_recvregres(block->remote_keys[chunk], + trace_rdma_write_one_recvregres(block->remote_keys[chunk], reg_result->rkey, chunk); =20 block->remote_keys[chunk] =3D reg_result->rkey; @@ -1926,7 +1926,7 @@ retry: send_wr.wr.rdma.remote_addr =3D block->remote_host_addr + (current_addr - block->offset); =20 - trace_qemu_rdma_write_one_post(chunk, sge.addr, send_wr.wr.rdma.remote= _addr, + trace_rdma_write_one_post(chunk, sge.addr, send_wr.wr.rdma.remote_addr, sge.length); =20 /* @@ -1936,7 +1936,7 @@ retry: ret =3D ibv_post_send(rdma->qp, &send_wr, &bad_wr); =20 if (ret =3D=3D ENOMEM) { - trace_qemu_rdma_write_one_queue_full(); + trace_rdma_write_one_queue_full(); ret =3D qemu_rdma_block_for_wrid(rdma, RDMA_WRID_RDMA_WRITE, NULL); if (ret < 0) { error_setg(errp, "rdma migration: failed to make " @@ -1993,7 +1993,7 @@ static int qemu_rdma_write_flush(RDMAContext *rdma, E= rror **errp) =20 if (ret =3D=3D 0) { rdma->nb_sent++; - trace_qemu_rdma_write_flush(rdma->nb_sent); + trace_rdma_write_flush(rdma->nb_sent); } =20 rdma->current_length =3D 0; @@ -2109,7 +2109,7 @@ static void qemu_rdma_cleanup(RDMAContext *rdma) } =20 rdma_disconnect(rdma->cm_id); - trace_qemu_rdma_cleanup_disconnect(); + trace_rdma_cleanup_disconnect(); rdma->connected =3D false; } =20 @@ -2292,7 +2292,7 @@ static int qemu_rdma_connect(RDMAContext *rdma, bool = return_path, * on the source first requested the capability. */ if (rdma->pin_all) { - trace_qemu_rdma_connect_pin_all_requested(); + trace_rdma_connect_pin_all_requested(); cap.flags |=3D RDMA_CAPABILITY_PIN_ALL; } =20 @@ -2343,7 +2343,7 @@ static int qemu_rdma_connect(RDMAContext *rdma, bool = return_path, rdma->pin_all =3D false; } =20 - trace_qemu_rdma_connect_pin_all_outcome(rdma->pin_all); + trace_rdma_connect_pin_all_outcome(rdma->pin_all); =20 rdma_ack_cm_event(cm_event); =20 @@ -2412,7 +2412,7 @@ static int qemu_rdma_dest_init(RDMAContext *rdma, Err= or **errp) =20 inet_ntop(e->ai_family, &((struct sockaddr_in *) e->ai_dst_addr)->sin_addr, ip, sizeof= ip); - trace_qemu_rdma_dest_init_trying(rdma->host, ip); + trace_rdma_dest_init_trying(rdma->host, ip); ret =3D rdma_bind_addr(listen_id, e->ai_dst_addr); if (ret < 0) { continue; @@ -2547,7 +2547,7 @@ static size_t qemu_rdma_fill(RDMAContext *rdma, uint8= _t *buf, size_t len =3D 0; =20 if (rdma->wr_data[idx].control_len) { - trace_qemu_rdma_fill(rdma->wr_data[idx].control_len, size); + trace_rdma_fill(rdma->wr_data[idx].control_len, size); =20 len =3D MIN(size, rdma->wr_data[idx].control_len); memcpy(buf, rdma->wr_data[idx].control_curr, len); @@ -2859,7 +2859,7 @@ static int qio_channel_rdma_close(QIOChannel *ioc, RDMAContext *rdmain, *rdmaout; struct rdma_close_rcu *rcu =3D g_new(struct rdma_close_rcu, 1); =20 - trace_qemu_rdma_close(); + trace_rdma_close(); =20 rdmain =3D rioc->rdmain; if (rdmain) { @@ -3132,11 +3132,11 @@ static int qemu_rdma_accept(RDMAContext *rdma) =20 rdma_ack_cm_event(cm_event); =20 - trace_qemu_rdma_accept_pin_state(rdma->pin_all); + trace_rdma_accept_pin_state(rdma->pin_all); =20 caps_to_network(&cap); =20 - trace_qemu_rdma_accept_pin_verbsc(verbs); + trace_rdma_accept_pin_verbsc(verbs); =20 if (!rdma->verbs) { rdma->verbs =3D verbs; @@ -3727,13 +3727,13 @@ static void rdma_accept_incoming_migration(void *op= aque) RDMAContext *rdma =3D opaque; QIOChannel *ioc; =20 - trace_qemu_rdma_accept_incoming_migration(); + trace_rdma_accept_incoming_migration(); if (qemu_rdma_accept(rdma) < 0) { error_report("RDMA ERROR: Migration initialization failed"); return; } =20 - trace_qemu_rdma_accept_incoming_migration_accepted(); + trace_rdma_accept_incoming_migration_accepted(); =20 if (rdma->is_return_path) { return; diff --git a/migration/trace-events b/migration/trace-events index 6d70f8e8cad..e87d4abd911 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -214,42 +214,42 @@ migrate_global_state_post_load(const char *state) "lo= aded state: %s" migrate_global_state_pre_save(const char *state) "saved state: %s" =20 # rdma.c -qemu_rdma_accept_incoming_migration(void) "" -qemu_rdma_accept_incoming_migration_accepted(void) "" -qemu_rdma_accept_pin_state(bool pin) "%d" -qemu_rdma_accept_pin_verbsc(void *verbs) "Verbs context after listen: %p" -qemu_rdma_block_for_wrid_miss(uint64_t wcomp, uint64_t req) "A Wanted wrid= %" PRIu64 " but got %" PRIu64 -qemu_rdma_cleanup_disconnect(void) "" -qemu_rdma_close(void) "" -qemu_rdma_connect_pin_all_requested(void) "" -qemu_rdma_connect_pin_all_outcome(bool pin) "%d" -qemu_rdma_dest_init_trying(const char *host, const char *ip) "%s =3D> %s" -qemu_rdma_dump_id_failed(const char *who) "%s RDMA Device opened, but can'= t query port information" -qemu_rdma_dump_id(const char *who, const char *name, const char *dev_name,= const char *dev_path, const char *ibdev_path, int transport, const char *t= ransport_name) "%s RDMA Device opened: kernel name %s uverbs device name %s= , infiniband_verbs class device path %s, infiniband class device path %s, t= ransport: (%d) %s" -qemu_rdma_dump_gid(const char *who, const char *src, const char *dst) "%s = Source GID: %s, Dest GID: %s" -qemu_rdma_exchange_get_response_start(const char *desc) "CONTROL: %s recei= ving..." -qemu_rdma_exchange_get_response_none(const char *desc, int type) "Surprise= : got %s (%d)" -qemu_rdma_exchange_send_issue_callback(void) "" -qemu_rdma_exchange_send_waiting(const char *desc) "Waiting for response %s" -qemu_rdma_exchange_send_received(const char *desc) "Response %s received." -qemu_rdma_fill(size_t control_len, size_t size) "RDMA %zd of %zd bytes alr= eady in buffer" -qemu_rdma_init_ram_blocks(int blocks) "Allocated %d local ram block struct= ures" -qemu_rdma_poll_recv(uint64_t comp, int64_t id, int sent) "completion %" PR= Iu64 " received (%" PRId64 ") left %d" -qemu_rdma_poll_write(uint64_t comp, int left, uint64_t block, uint64_t chu= nk, void *local, void *remote) "completions %" PRIu64 " left %d, block %" P= RIu64 ", chunk: %" PRIu64 " %p %p" -qemu_rdma_poll_other(uint64_t comp, int left) "other completion %" PRIu64 = " received left %d" -qemu_rdma_post_send_control(const char *desc) "CONTROL: sending %s.." -qemu_rdma_register_and_get_keys(uint64_t len, void *start) "Registering %"= PRIu64 " bytes @ %p" -qemu_rdma_register_odp_mr(const char *name) "Try to register On-Demand Pag= ing memory region: %s" -qemu_rdma_advise_mr(const char *name, uint32_t len, uint64_t addr, const c= har *res) "Try to advise block %s prefetch at %" PRIu32 "@0x%" PRIx64 ": %s" -qemu_rdma_resolve_host_trying(const char *host, const char *ip) "Trying %s= =3D> %s" -qemu_rdma_write_flush(int sent) "sent total: %d" -qemu_rdma_write_one_block(int count, int block, uint64_t chunk, uint64_t c= urrent, uint64_t len, int nb_sent, int nb_chunks) "(%d) Not clobbering: blo= ck: %d chunk %" PRIu64 " current %" PRIu64 " len %" PRIu64 " %d %d" -qemu_rdma_write_one_post(uint64_t chunk, long addr, long remote, uint32_t = len) "Posting chunk: %" PRIu64 ", addr: 0x%lx remote: 0x%lx, bytes %" PRIu32 -qemu_rdma_write_one_queue_full(void) "" -qemu_rdma_write_one_recvregres(int mykey, int theirkey, uint64_t chunk) "R= eceived registration result: my key: 0x%x their key 0x%x, chunk %" PRIu64 -qemu_rdma_write_one_sendreg(uint64_t chunk, int len, int index, int64_t of= fset) "Sending registration request chunk %" PRIu64 " for %d bytes, index: = %d, offset: %" PRId64 -qemu_rdma_write_one_top(uint64_t chunks, uint64_t size) "Writing %" PRIu64= " chunks, (%" PRIu64 " MB)" -qemu_rdma_write_one_zero(uint64_t chunk, int len, int index, int64_t offse= t) "Entire chunk is zero, sending compress: %" PRIu64 " for %d bytes, index= : %d, offset: %" PRId64 +rdma_accept_incoming_migration(void) "" +rdma_accept_incoming_migration_accepted(void) "" +rdma_accept_pin_state(bool pin) "%d" +rdma_accept_pin_verbsc(void *verbs) "Verbs context after listen: %p" +rdma_block_for_wrid_miss(uint64_t wcomp, uint64_t req) "A Wanted wrid %" P= RIu64 " but got %" PRIu64 +rdma_cleanup_disconnect(void) "" +rdma_close(void) "" +rdma_connect_pin_all_requested(void) "" +rdma_connect_pin_all_outcome(bool pin) "%d" +rdma_dest_init_trying(const char *host, const char *ip) "%s =3D> %s" +rdma_dump_id_failed(const char *who) "%s RDMA Device opened, but can't que= ry port information" +rdma_dump_id(const char *who, const char *name, const char *dev_name, cons= t char *dev_path, const char *ibdev_path, int transport, const char *transp= ort_name) "%s RDMA Device opened: kernel name %s uverbs device name %s, inf= iniband_verbs class device path %s, infiniband class device path %s, transp= ort: (%d) %s" +rdma_dump_gid(const char *who, const char *src, const char *dst) "%s Sourc= e GID: %s, Dest GID: %s" +rdma_exchange_get_response_start(const char *desc) "CONTROL: %s receiving.= .." +rdma_exchange_get_response_none(const char *desc, int type) "Surprise: got= %s (%d)" +rdma_exchange_send_issue_callback(void) "" +rdma_exchange_send_waiting(const char *desc) "Waiting for response %s" +rdma_exchange_send_received(const char *desc) "Response %s received." +rdma_fill(size_t control_len, size_t size) "RDMA %zd of %zd bytes already = in buffer" +rdma_init_ram_blocks(int blocks) "Allocated %d local ram block structures" +rdma_poll_recv(uint64_t comp, int64_t id, int sent) "completion %" PRIu64 = " received (%" PRId64 ") left %d" +rdma_poll_write(uint64_t comp, int left, uint64_t block, uint64_t chunk, v= oid *local, void *remote) "completions %" PRIu64 " left %d, block %" PRIu64= ", chunk: %" PRIu64 " %p %p" +rdma_poll_other(uint64_t comp, int left) "other completion %" PRIu64 " rec= eived left %d" +rdma_post_send_control(const char *desc) "CONTROL: sending %s.." +rdma_register_and_get_keys(uint64_t len, void *start) "Registering %" PRIu= 64 " bytes @ %p" +rdma_register_odp_mr(const char *name) "Try to register On-Demand Paging m= emory region: %s" +rdma_advise_mr(const char *name, uint32_t len, uint64_t addr, const char *= res) "Try to advise block %s prefetch at %" PRIu32 "@0x%" PRIx64 ": %s" +rdma_resolve_host_trying(const char *host, const char *ip) "Trying %s =3D>= %s" +rdma_write_flush(int sent) "sent total: %d" +rdma_write_one_block(int count, int block, uint64_t chunk, uint64_t curren= t, uint64_t len, int nb_sent, int nb_chunks) "(%d) Not clobbering: block: %= d chunk %" PRIu64 " current %" PRIu64 " len %" PRIu64 " %d %d" +rdma_write_one_post(uint64_t chunk, long addr, long remote, uint32_t len) = "Posting chunk: %" PRIu64 ", addr: 0x%lx remote: 0x%lx, bytes %" PRIu32 +rdma_write_one_queue_full(void) "" +rdma_write_one_recvregres(int mykey, int theirkey, uint64_t chunk) "Receiv= ed registration result: my key: 0x%x their key 0x%x, chunk %" PRIu64 +rdma_write_one_sendreg(uint64_t chunk, int len, int index, int64_t offset)= "Sending registration request chunk %" PRIu64 " for %d bytes, index: %d, o= ffset: %" PRId64 +rdma_write_one_top(uint64_t chunks, uint64_t size) "Writing %" PRIu64 " ch= unks, (%" PRIu64 " MB)" +rdma_write_one_zero(uint64_t chunk, int len, int index, int64_t offset) "E= ntire chunk is zero, sending compress: %" PRIu64 " for %d bytes, index: %d,= offset: %" PRId64 rdma_add_block(const char *block_name, int block, uint64_t addr, uint64_t = offset, uint64_t len, uint64_t end, uint64_t bits, int chunks) "Added Block= : '%s':%d, addr: %" PRIu64 ", offset: %" PRIu64 " length: %" PRIu64 " end: = %" PRIu64 " bits %" PRIu64 " chunks %d" rdma_block_notification_handle(const char *name, int index) "%s at %d" rdma_delete_block(void *block, uint64_t addr, uint64_t offset, uint64_t le= n, uint64_t end, uint64_t bits, int chunks) "Deleted Block: %p, addr: %" PR= Iu64 ", offset: %" PRIu64 " length: %" PRIu64 " end: %" PRIu64 " bits %" PR= Iu64 " chunks %d" --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787933041; cv=none; d=zohomail.com; s=zohoarc; b=I6kAagwmYZ8o5h71nH9E38pD2RFkKJGIKzUeEB4ZKqCYPRUVnyup81yTRTB9JdnfOkhwcBDeBd9o+LZ5NecpQmFyXIVtUayOgNXGabDRwQULul2rvvXrdx2lJYZtOAFWXui3oyzeNTcVlKjX2vTZ2mqH+kigAE/3KcfXk4N/QsU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787933041; 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=8srkfRBJ8tr/sXtX0mTfj4YigIbqYI314IE+GV72yvo=; b=aXx4/IPB3nT8cchZxuxsUXEc+eLBFSxl3Jve0dpzegSpkSQzpriXHa2KXTp/aToaA08ZtX+lhJMmcOgmOtrMZwMxrWGkIePUnG9fxA0dPOEiUF7RbIiqiBajzb1aX9mssv/Scp/czXdvr2ONKE0GPNJ0x5xtmMkc+V9CkJGgpTQ= 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 1787933041072188.97563759609068; Fri, 28 Aug 2026 09:04:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyzR-0001U9-2i; Fri, 28 Aug 2026 11:59:37 -0400 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 1wzyzL-0001P8-SL for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:33 -0400 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 1wzyzA-0008PO-5G for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:31 -0400 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 282CF1FED2; Fri, 28 Aug 2026 15:59:10 +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 1FA9713691; Fri, 28 Aug 2026 15:59: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 qJRdOEywkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932754; 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=8srkfRBJ8tr/sXtX0mTfj4YigIbqYI314IE+GV72yvo=; b=gyHLjYwG2NUP8vpsESgdDbmpW3mienS5U2qxHBZse5mLM6zDS/q70q92F2bw9EcrX6qdWs 652JmNlK+cqPE5/zO847uLE2mpMKsm94VO0dcXHgd03t6byeWsJYqwrILMpwsP7lspCW79 2f5f/+YOthxnY9eF2bf2I8+C0H02faQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932754; 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=8srkfRBJ8tr/sXtX0mTfj4YigIbqYI314IE+GV72yvo=; b=5Szx8NsDgGQrKuqtEyEsQBnHTnKCjfqxMMHjq0vFrCRgB9MLZStSOWGqAjJhKi9aKXYTJp 9x1TKboisg08pmAQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932750; 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=8srkfRBJ8tr/sXtX0mTfj4YigIbqYI314IE+GV72yvo=; b=V56D2LX2WiAdVGAU0i2V5d/tRZ/BMDsGo7t71giHsCbnQsS/YTmtQlJKw9QVJipjCNZX/Z Oy/7FD16ckrpgrQ+/h1FvQn5yIvzvA/70DoIEyTCPAD/m22oegnkPDwEou8POjQydkvDrl hG7uQ0HKcB7ise+0noKrJO9xMIkB3BQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932750; 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=8srkfRBJ8tr/sXtX0mTfj4YigIbqYI314IE+GV72yvo=; b=Y2ZvS5kumnVkPpS6Lch4aku15DfO84dX389SY1tJeXDCTvIKddgjmkcJYDAIx4rH/wx8Td rT90LgvYWPbbGRAQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Jinpu Wang Subject: [PULL v2 15/30] migration/rdma: Drop RDMALocalBlock.is_ram_block Date: Fri, 28 Aug 2026 12:58:30 -0300 Message-ID: <20260828155845.2874508-16-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.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.993]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(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)[]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[ionos.com:email,imap1.dmz-prg2.suse.org:helo,gitlab.com:url,suse.de:email,suse.de:mid]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] 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: 1787933043097158500 Content-Type: text/plain; charset="utf-8" From: Peter Xu This is guaranteed to be true. There seems to have support for some dynamically allocated buffers but it was never really supported. Remove dead code. As a side effect, this patch closes a report by removing the buggy code completely. Reported-by: Tristan (@TristanInSec) Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4006 Reviewed-by: Jinpu Wang Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas Signed-off-by: Fabiano Rosas --- migration/rdma.c | 75 ++++++++++++++---------------------------------- 1 file changed, 21 insertions(+), 54 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index ffae0a887f6..63a8370be22 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -196,7 +196,6 @@ typedef struct RDMALocalBlock { uint32_t remote_rkey; /* rkeys for non-chunk-level registrat= ion */ int index; /* which block are we */ unsigned int src_index; /* (Only used on dest) */ - bool is_ram_block; int nb_chunks; unsigned long *transit_bitmap; unsigned long *unregister_bitmap; @@ -279,7 +278,6 @@ static void network_to_dest_block(RDMADestBlock *db) */ typedef struct RDMALocalBlocks { int nb_blocks; - bool init; /* main memory init complete */ RDMALocalBlock *block; } RDMALocalBlocks; =20 @@ -441,14 +439,12 @@ static void register_to_network(RDMAContext *rdma, RD= MARegister *reg) RDMALocalBlock *local_block; local_block =3D &rdma->local_ram_blocks.block[reg->current_index]; =20 - if (local_block->is_ram_block) { - /* - * current_addr as passed in is an address in the local ram_addr_t - * space, we need to translate this for the destination - */ - reg->key.current_addr -=3D local_block->offset; - reg->key.current_addr +=3D rdma->dest_blocks[reg->current_index].o= ffset; - } + /* + * current_addr as passed in is an address in the local ram_addr_t + * space, we need to translate this for the destination + */ + reg->key.current_addr -=3D local_block->offset; + reg->key.current_addr +=3D rdma->dest_blocks[reg->current_index].offse= t; reg->key.current_addr =3D htonll(reg->key.current_addr); reg->current_index =3D htonl(reg->current_index); reg->chunks =3D htonll(reg->chunks); @@ -585,8 +581,6 @@ static void rdma_add_block(RDMAContext *rdma, const cha= r *block_name, bitmap_clear(block->unregister_bitmap, 0, block->nb_chunks); block->remote_keys =3D g_new0(uint32_t, block->nb_chunks); =20 - block->is_ram_block =3D local->init ? false : true; - if (rdma->blockmap) { g_hash_table_insert(rdma->blockmap, (void *)(uintptr_t)block_offse= t, block); } @@ -634,7 +628,6 @@ static void qemu_rdma_init_ram_blocks(RDMAContext *rdma) trace_rdma_init_ram_blocks(local->nb_blocks); rdma->dest_blocks =3D g_new0(RDMADestBlock, rdma->local_ram_blocks.nb_blocks); - local->init =3D true; } =20 /* @@ -1767,19 +1760,10 @@ retry: chunk =3D ram_chunk_index(block->local_host_addr, (uint8_t *)(uintptr_t)sge.addr); chunk_start =3D ram_chunk_start(block, chunk); + chunks =3D length / chunk_size; =20 - if (block->is_ram_block) { - chunks =3D length / chunk_size; - - if (chunks && ((length % chunk_size) =3D=3D 0)) { - chunks--; - } - } else { - chunks =3D block->length / chunk_size; - - if (chunks && ((block->length % chunk_size) =3D=3D 0)) { - chunks--; - } + if (chunks && ((length % chunk_size) =3D=3D 0)) { + chunks--; } =20 trace_rdma_write_one_top(chunks + 1, @@ -1804,7 +1788,7 @@ retry: } } =20 - if (!rdma->pin_all || !block->is_ram_block) { + if (!rdma->pin_all) { if (!block->remote_keys[chunk]) { /* * This chunk has not yet been registered, so first check to s= ee @@ -1853,11 +1837,7 @@ retry: * Otherwise, tell other side to register. */ reg.current_index =3D current_index; - if (block->is_ram_block) { - reg.key.current_addr =3D current_addr; - } else { - reg.key.chunk =3D chunk; - } + reg.key.current_addr =3D current_addr; reg.chunks =3D chunks; =20 trace_rdma_write_one_sendreg(chunk, sge.length, current_index, @@ -3408,30 +3388,17 @@ int rdma_registration_handle(QEMUFile *f) goto err; } block =3D &(rdma->local_ram_blocks.block[reg->current_inde= x]); - if (block->is_ram_block) { - if (block->offset > reg->key.current_addr) { - error_report("rdma: bad register address for block= %s" - " offset: %" PRIx64 " current_addr: %" PRIx64, - block->block_name, block->offset, - reg->key.current_addr); - goto err; - } - host_addr =3D (block->local_host_addr + - (reg->key.current_addr - block->offset)); - chunk =3D ram_chunk_index(block->local_host_addr, - (uint8_t *) host_addr); - } else { - chunk =3D reg->key.chunk; - host_addr =3D block->local_host_addr + - (reg->key.chunk * migrate_rdma_chunk_size()); - /* Check for particularly bad chunk value */ - if (host_addr < (void *)block->local_host_addr) { - error_report("rdma: bad chunk for block %s" - " chunk: %" PRIx64, - block->block_name, reg->key.chunk); - goto err; - } + if (block->offset > reg->key.current_addr) { + error_report("rdma: bad register address for block %s" + " offset: %" PRIx64 " current_addr: %" PRIx64, + block->block_name, block->offset, + reg->key.current_addr); + goto err; } + host_addr =3D (block->local_host_addr + + (reg->key.current_addr - block->offset)); + chunk =3D ram_chunk_index(block->local_host_addr, + (uint8_t *) host_addr); chunk_start =3D ram_chunk_start(block, chunk); chunk_end =3D ram_chunk_end(block, chunk + reg->chunks); /* avoid "-Waddress-of-packed-member" warning */ --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932851; cv=none; d=zohomail.com; s=zohoarc; b=KNcT0i9O3VM6XIan4dU2BSOlX7Jv6JzVWo2ymBjUz2iQfyCXyq3fNA8k5ppwj+wAYiG+4boqPMsrlFc6JZ1O6H8+WRMyookObSvo8ySWrg/GuMn6P5/jOcnk6AjsA39aXMXVXxfIbgMfvMPY1rt4cmUGiod6yVs1JfhO1F3cmyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932851; 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=aFc6hA/abHmRVaNgSz5gbCQGFsz9FdGFyIKHi0KIXlQ=; b=ImlOqiJt8d7zHIuhtxGWRaX7R/AYh7G6Llblb+HBFhobEFqUvAtAuRsgf2xl1aVdRSSiMB9g5o8ctQCmWwqHWjfpgZXXdNb1rrnUm0fbKtchozP0C7Y1tga7AxCMadveuDrl/t2OhRtmnvGWl/eFnSsherk6hf1g7VzgxBqCPMQ= 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 1787932851103459.29212774736675; Fri, 28 Aug 2026 09:00:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyzU-0001aV-WE; Fri, 28 Aug 2026 11:59:41 -0400 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 1wzyzQ-0001Pw-78 for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:36 -0400 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wzyzB-0008QF-89 for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:32 -0400 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 7660E22291; Fri, 28 Aug 2026 15:59: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 67BC813674; Fri, 28 Aug 2026 15:59: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 aBxZDk6wkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932755; 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=aFc6hA/abHmRVaNgSz5gbCQGFsz9FdGFyIKHi0KIXlQ=; b=UyAeUl0zcJkIg/HqpLkuWOU7dGJxKdtAL8yCadRmPtR+6uOLSV24kwREe3XmNYzeuKIp4j Qy86PPtBQ/73XLKLPsKYTXxIIHEcs2TELfe1YqNLQJiABJSHHixqcbYchqnvkevWaLHoCG MSI6tzEqjephsrSFFsSNvq3RYFp93FA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932755; 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=aFc6hA/abHmRVaNgSz5gbCQGFsz9FdGFyIKHi0KIXlQ=; b=4W1IhlPm/C4kzcTbhr6uO5EpwhbUI0IRCGe0P1zptEBzkLClcrSuTgYpyeMooJUuAy1nkz 5iF+UcxQBq4EsqDw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932751; 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=aFc6hA/abHmRVaNgSz5gbCQGFsz9FdGFyIKHi0KIXlQ=; b=MUOAI/l5aE7WZl/Wvrcf7q5Qw1ku1B7Hqo9BxkWGvsvYEUQzSDEqjGIkGmTCH+b9r0c1I1 2p/vIelaABr/toTfh3ad+LF0v5zeqB7AqILj+/QEEViurYE6QZM4JunsdhHCNTaLHa6PBu 6WCagFKrYVNvx69MBse1j+nXVOP16iw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932751; 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=aFc6hA/abHmRVaNgSz5gbCQGFsz9FdGFyIKHi0KIXlQ=; b=Icp9Sh8HhggJcxNtRAES7ILXKLUJxYqHdL8AOWaFZZ/Or2Yy+4VPHx8mgDIJFQhM147fFA tDnzAUjvmhr8wQCg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Jinpu Wang Subject: [PULL v2 16/30] migration/rdma: Drop RDMALocalBlock.unregister_bitmap Date: Fri, 28 Aug 2026 12:58:31 -0300 Message-ID: <20260828155845.2874508-17-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.997]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(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)[]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:mid,imap1.dmz-prg2.suse.org:helo,ionos.com:email]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] 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=195.135.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, 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: 1787932853424158500 Content-Type: text/plain; charset="utf-8" From: Peter Xu Not used anymore. Reviewed-by: Jinpu Wang Signed-off-by: Peter Xu Reviewed-by: Jack Wang Signed-off-by: Fabiano Rosas --- migration/rdma.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index 63a8370be22..f9f39402568 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -198,7 +198,6 @@ typedef struct RDMALocalBlock { unsigned int src_index; /* (Only used on dest) */ int nb_chunks; unsigned long *transit_bitmap; - unsigned long *unregister_bitmap; } RDMALocalBlock; =20 /* @@ -577,8 +576,6 @@ static void rdma_add_block(RDMAContext *rdma, const cha= r *block_name, block->nb_chunks =3D ram_chunk_index(host_addr, host_addr + length) + = 1UL; block->transit_bitmap =3D bitmap_new(block->nb_chunks); bitmap_clear(block->transit_bitmap, 0, block->nb_chunks); - block->unregister_bitmap =3D bitmap_new(block->nb_chunks); - bitmap_clear(block->unregister_bitmap, 0, block->nb_chunks); block->remote_keys =3D g_new0(uint32_t, block->nb_chunks); =20 if (rdma->blockmap) { @@ -663,9 +660,6 @@ static void rdma_delete_block(RDMAContext *rdma, RDMALo= calBlock *block) g_free(block->transit_bitmap); block->transit_bitmap =3D NULL; =20 - g_free(block->unregister_bitmap); - block->unregister_bitmap =3D NULL; - g_free(block->remote_keys); block->remote_keys =3D NULL; =20 --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932850; cv=none; d=zohomail.com; s=zohoarc; b=Y6AYhIb7bx7VKuwnwXNZWosRz9YwLzoD1U1lh6Q5Ne/1YR/QIeYuTIKoxEaElCQ0pgtMdYlMRzTH+82GKNKJ/CQ+RTJ8a4j/czus16WQBcgIyFuTd65YSSTsxI5IY68DnCiALasG8IEkNvQXG7vHsrAR69SmApSDBQk75xoJ4Sc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932850; 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=SU6M+9tQ87hTQgwr6I/3+gapxDIcAIUfg8QtxVIi6v4=; b=d3MD325WiaRrWsgNKo5rnwn9JIE2iC9Jt8QloT3VRjTdq23reUb0UP36fd8AUzb042O63GfdzIxVuKNXcDgejKqtxYxAakaeBgR5XM9qFNfCGlmKzSCb1vWPhh1MgJrrqOjI9cV1vouScOm0CvHQlr32stCYAQUKYHqve+SboAs= 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 1787932850835551.3079436223037; Fri, 28 Aug 2026 09:00:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyzV-0001aW-0f; Fri, 28 Aug 2026 11:59:41 -0400 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 1wzyzQ-0001Pq-1Q for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:36 -0400 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wzyzD-0008R2-6t for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:33 -0400 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 B77431FE8A; Fri, 28 Aug 2026 15:59:12 +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 AFFCB13675; Fri, 28 Aug 2026 15:59: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 6F8BIE+wkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932756; 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=SU6M+9tQ87hTQgwr6I/3+gapxDIcAIUfg8QtxVIi6v4=; b=Tycc1315enBgwzbkGxALQUQVD4iSgSph2IMTrGclFIJraxtwwIBu8P+Ih/a9Z6Rar27v/z JzzNS+DAdL7/WwbTOjT1zFl1NIQowYqACi8OMDo7VqAHL2xk6ui7T4IflzEIsULJAzZv76 +yoyb5dSBUtpvPTo1U9GiU+7cc5PC2s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932756; 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=SU6M+9tQ87hTQgwr6I/3+gapxDIcAIUfg8QtxVIi6v4=; b=fr/ZHclW2XrlRFaiBcwoqkqdY1Lpe7wgg3TcG+4+OO2zaRxNDVrwLeEqxLsrUwjjL6m7VD Bbi8C4x4koY9uABQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932752; 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=SU6M+9tQ87hTQgwr6I/3+gapxDIcAIUfg8QtxVIi6v4=; b=lUPgROhIoOeAho4w8nJxEELlpyTN2I7KK6JTLMZCjBPtyVwstnzZgtigQDJlTEUxSEsHF0 /jZMcJB91k/fM1RiOkvBIokvdSRGdzXR4XziU4LowCc5S+5/UERRwIkOofHMtW2JT8HfjB VukZU5Zg+ZvvpzYuVpmSf1Db5FI6CP8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932752; 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=SU6M+9tQ87hTQgwr6I/3+gapxDIcAIUfg8QtxVIi6v4=; b=XfVV5ctgdfPpgBcqr6pbWCz0B4ur+8OOQ901MYZqRhwkRLVMjg9ZGXobUdFwt8ORbcQ2Hz IrFhFmT5Cvf4tlBQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Jinpu Wang Subject: [PULL v2 17/30] migration/rdma: Drop RDMARegister.key.chunk Date: Fri, 28 Aug 2026 12:58:32 -0300 Message-ID: <20260828155845.2874508-18-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.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]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(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)[]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[ionos.com:email,suse.de:mid,suse.de:email,imap1.dmz-prg2.suse.org:helo]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] 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=195.135.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, 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: 1787932852275154100 Content-Type: text/plain; charset="utf-8" From: Peter Xu Not used anymore. Reviewed-by: Jinpu Wang Signed-off-by: Peter Xu Reviewed-by: Jack Wang Signed-off-by: Fabiano Rosas --- migration/rdma.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index f9f39402568..683c24ba4dd 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -414,10 +414,7 @@ static void network_to_control(RDMAControlHeader *cont= rol) * the actual RDMA operation. */ typedef struct QEMU_PACKED { - union QEMU_PACKED { - uint64_t current_addr; /* offset into the ram_addr_t space */ - uint64_t chunk; /* chunk to lookup if unregistering */ - } key; + uint64_t current_addr; /* offset into the ram_addr_t space */ uint32_t current_index; /* which ramblock the chunk belongs to */ uint32_t padding; uint64_t chunks; /* how many sequential chunks to register = */ @@ -442,16 +439,16 @@ static void register_to_network(RDMAContext *rdma, RD= MARegister *reg) * current_addr as passed in is an address in the local ram_addr_t * space, we need to translate this for the destination */ - reg->key.current_addr -=3D local_block->offset; - reg->key.current_addr +=3D rdma->dest_blocks[reg->current_index].offse= t; - reg->key.current_addr =3D htonll(reg->key.current_addr); + reg->current_addr -=3D local_block->offset; + reg->current_addr +=3D rdma->dest_blocks[reg->current_index].offset; + reg->current_addr =3D htonll(reg->current_addr); reg->current_index =3D htonl(reg->current_index); reg->chunks =3D htonll(reg->chunks); } =20 static void network_to_register(RDMARegister *reg) { - reg->key.current_addr =3D ntohll(reg->key.current_addr); + reg->current_addr =3D ntohll(reg->current_addr); reg->current_index =3D ntohl(reg->current_index); reg->chunks =3D ntohll(reg->chunks); } @@ -1831,7 +1828,7 @@ retry: * Otherwise, tell other side to register. */ reg.current_index =3D current_index; - reg.key.current_addr =3D current_addr; + reg.current_addr =3D current_addr; reg.chunks =3D chunks; =20 trace_rdma_write_one_sendreg(chunk, sge.length, current_index, @@ -3373,7 +3370,7 @@ int rdma_registration_handle(QEMUFile *f) reg_result =3D &results[count]; =20 trace_rdma_registration_handle_register_loop(count, - reg->current_index, reg->key.current_addr, reg->c= hunks); + reg->current_index, reg->current_addr, reg->chunk= s); =20 if (reg->current_index >=3D rdma->local_ram_blocks.nb_bloc= ks) { error_report("rdma: 'register' bad block index %u (vs = %d)", @@ -3382,15 +3379,15 @@ int rdma_registration_handle(QEMUFile *f) goto err; } block =3D &(rdma->local_ram_blocks.block[reg->current_inde= x]); - if (block->offset > reg->key.current_addr) { + if (block->offset > reg->current_addr) { error_report("rdma: bad register address for block %s" " offset: %" PRIx64 " current_addr: %" PRIx64, block->block_name, block->offset, - reg->key.current_addr); + reg->current_addr); goto err; } host_addr =3D (block->local_host_addr + - (reg->key.current_addr - block->offset)); + (reg->current_addr - block->offset)); chunk =3D ram_chunk_index(block->local_host_addr, (uint8_t *) host_addr); chunk_start =3D ram_chunk_start(block, chunk); --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932871; cv=none; d=zohomail.com; s=zohoarc; b=Jj3fjfXNE1onHie6VTbyvU24iN6VlhRE0XSKTk3D7Qkv/+JIAdiK97wGX6UUagDQUQXh5KP6niJ3uVXIj1Ai8kHmwctS5HPV+EFQKln1msjoUJ/SsGE9W4DCOZMEdRq/VtBOmw5RWPQAsafWlWj9dyXgCckMvqEIIZkMDwnwjP4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932871; 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=F9yJ3RLbH84d6XW+2lCMAgvOPxksUFhx40vXtd8SCNM=; b=Mc9FdwgPJCieOVlQAmlwO++zrtEGn9GXglt19b8LtR/GHnqp26QvCdc3Zj3B/ChPEUGBhUj1OkzzAaPDRjp6wW9xQ0dUNn/Zjg45/ciEf8qQonOLnQtgPevsCiZwvM8fu/ehtRcjfSyKdO7WuV5GZehmkQ45RR/leb9IRtUMC0A= 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 1787932871229982.2547017857172; Fri, 28 Aug 2026 09:01:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyzS-0001Wp-2I; Fri, 28 Aug 2026 11:59:38 -0400 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 1wzyzQ-0001Pp-04 for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:36 -0400 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 1wzyzF-0008Rb-6i for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:35 -0400 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 0BE451FB86; Fri, 28 Aug 2026 15:59: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 0396513694; Fri, 28 Aug 2026 15:59:12 +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 KICAMVCwkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932758; 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=F9yJ3RLbH84d6XW+2lCMAgvOPxksUFhx40vXtd8SCNM=; b=ADHz0oVRZz5YScbUn37VnVHevXw+SeKZI7DwM3EgGsz3vcHARr0E8G6SKcBdoMmMjGK7PZ VkxybhtgEeMMzlZtkIrmJYQ2MQhxk6aWaogPZN3ypyquLubYcGMH7BjPdxRNLQTJvM5C0r x2szG+Nc9gGkGttnawuw8NIQ4AbQuo8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932758; 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=F9yJ3RLbH84d6XW+2lCMAgvOPxksUFhx40vXtd8SCNM=; b=MLJY3v4M5x4CokGhihAfmwZVxgdiifd++0sa8B/q9F/cyhaKP62n0d1DIDRjsmHLjiZso9 b/IB0jLFVJqjMPDQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932754; 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=F9yJ3RLbH84d6XW+2lCMAgvOPxksUFhx40vXtd8SCNM=; b=SgE/wGB0zWrAITVspIsYvRJ3uTCIuWroMq/nkLk85Bla+1NwGktGeqk39k5dotfwwJuTa+ 83l3wa5eaGUOeP7EdZ7TuvTzRWt/LprOrEVTc9RWPNLL1iAI8uZ92XOP6FqXlr5dU5BuR2 ArGljrACK15MJn+dkEwnlY9seMjdvdw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932754; 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=F9yJ3RLbH84d6XW+2lCMAgvOPxksUFhx40vXtd8SCNM=; b=6OQGbT9Cj5P5jjIArQAgGDqqX4CBMqXKsk++QPY4Lx57S0HeNv87Iebo36GpWC1UlaDbbr jH5a2vDWFAA8x8BA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Jinpu Wang Subject: [PULL v2 18/30] migration/rdma: Sanity check RDMA_CONTROL_REGISTER_REQUEST on buflen Date: Fri, 28 Aug 2026 12:58:33 -0300 Message-ID: <20260828155845.2874508-19-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.993]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(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)[]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[gitlab.com:url,suse.de:email,suse.de:mid,ionos.com:email,imap1.dmz-prg2.suse.org:helo]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] 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: 1787932871519158500 Content-Type: text/plain; charset="utf-8" From: Peter Xu RDMA header supports head.repeat on RDMA_CONTROL_REGISTER_REQUEST, which can include >1 memory registrations. The current code did check over head.repeat to guard against RDMA_CONTROL_MAX_COMMANDS_PER_MESSAGE, however it didn't further check the buffer size (head.len) to make sure the received data is large enough to include the repeated entries. Check it. This is almost only to harden this piece of code, in reality on source side QEMU never uses repeat>1.. However since it's a protocol, still keep it. Check the buffer size instead. In case it's not obvious to new RDMA readers: head.len should be the size RDMA has last received, as qemu_rdma_exchange_get_response() checked on it against byte_len (which was further fetched from ibv_wc.byte_len in qemu_rdma_poll()). Reported-by: Tristan (@TristanInSec) Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4028 Reviewed-by: Jinpu Wang Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas Reviewed-by: Jack Wang Signed-off-by: Fabiano Rosas --- migration/rdma.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/migration/rdma.c b/migration/rdma.c index 683c24ba4dd..f7356e759fc 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3360,6 +3360,14 @@ int rdma_registration_handle(QEMUFile *f) reg_resp.repeat =3D head.repeat; registers =3D (RDMARegister *) rdma->wr_data[idx].control_curr; =20 + /* Making sure the register buffers to read are valid */ + if (head.len !=3D head.repeat * sizeof(RDMARegister)) { + error_report("%s: Invalid RDMA_CONTROL_REGISTER_REQUEST " + "(head.repeat=3D%"PRIu32", head.len=3D%"PRIu3= 2")", + __func__, head.repeat, head.len); + goto err; + } + for (int count =3D 0; count < head.repeat; count++) { uint64_t chunk; uint8_t *chunk_start, *chunk_end; --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932839; cv=none; d=zohomail.com; s=zohoarc; b=AilCUQqcUNYOWXXBoa8SfgVhKY9jJUDflhlvCJhVkVmXp3xSYF+mqjJRvahjx7YJP4gTlijkSeaeSIIqOwhaTBHIHW82Z42QUkdAp9Vki3+YhQ+JeyfMDB0ytcmaxo96UmZt0NyfeU3WiKpHS7SnMi/mUXpOgzW6IX2mw8Ul+Dw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932839; 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=wMa2/41ubuJQG7osaYAeN+fD11e+ewIuN36eXzoto9M=; b=P/Ca6S9krZt6GT+OAqryg8Pw+TPeCXSuj1V5z8sTDeqeROl2FHlnavuY4mv6gAi5M7iiHkYXKT2HF8EkWnczDIM5fxKIVHFB/haOPbzCBgJgMqXkypqlb3PszBUrJ1p6xXHTCqHGsYt1jzkHEsgWZiUD3ePryXmLTj6BiC35uKc= 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 1787932839419896.1608191877494; Fri, 28 Aug 2026 09:00:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyzV-0001bG-Ly; Fri, 28 Aug 2026 11:59:41 -0400 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 1wzyzQ-0001U8-Jb for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:36 -0400 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 1wzyzG-0008SP-Ak for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:36 -0400 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 551CC21F92; Fri, 28 Aug 2026 15:59:15 +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 4B59313687; Fri, 28 Aug 2026 15:59: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 +CNpB1KwkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932759; 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=wMa2/41ubuJQG7osaYAeN+fD11e+ewIuN36eXzoto9M=; b=LEVshQd7HxEltMEgTHjO4/s/XsNu0zdL9Ko0NCfW4ISWmESHX4ZOHcz6CkQMdqB9ZOAFsr y3PGLUTVY83jmSDu7y9TAZ6mzeD0JTAoQ8Q1sH8oZuFPHJDvb4IGhjexuzxykI/tJz+rwZ 5WsTxP3rBZ4iFiwe90Jxb7emYiZ6E60= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932759; 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=wMa2/41ubuJQG7osaYAeN+fD11e+ewIuN36eXzoto9M=; b=A8bvhOYFsyLemT41znj8GB6GR9cwJ3anR8fRHItYDetldpiFQuzShllt8rwZER+EKeroYz OjF0Oz/HDWBABnAw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932755; 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=wMa2/41ubuJQG7osaYAeN+fD11e+ewIuN36eXzoto9M=; b=WLEgKmtqdqg/DORTvlTptMCUpSmRTDAnrVWEsD16kExjuTFOqtE0syXRtv5WDw/yCZoi1F EgplyyDGQHNnYtI1fhePBcWGLypM/PF4yn2H6liBuLx5QNDDtyg06UtAZkAMhuHLHd8jvR 7Y+JtAuigmG+FPL94lDt2jplRbXVvRE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932755; 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=wMa2/41ubuJQG7osaYAeN+fD11e+ewIuN36eXzoto9M=; b=D+6CVzVztfd9rXAQFlSb1w7GNW7GioR1QN+/DexmmrewYF0HjWGgnL3RFbJYC/AMVrSXKE uk7aA7E0aVywGeAw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Jinpu Wang Subject: [PULL v2 19/30] migration/rdma: Sanity check RDMA_CONTROL_REGISTER_REQUEST chunks Date: Fri, 28 Aug 2026 12:58:34 -0300 Message-ID: <20260828155845.2874508-20-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.993]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(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)[]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:mid,suse.de:email,ionos.com:email,gitlab.com:url]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] 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) (identity @suse.de) X-ZM-MESSAGEID: 1787932841600158500 Content-Type: text/plain; charset="utf-8" From: Peter Xu The value received on wire for head.chunks when registering new RDMA regions is not correctly checked. Logically the value can still make ram_chunk_start() (of ram_chunk_end()) to overflow, having a result pointer very small, smaller than RDMALocalBlock.local_host_addr. Add the sanity check. Reported-by: Tristan (@TristanInSec) Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4011 Reviewed-by: Jinpu Wang Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas Signed-off-by: Fabiano Rosas --- migration/rdma.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/migration/rdma.c b/migration/rdma.c index f7356e759fc..cf6688a4bc3 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3369,7 +3369,7 @@ int rdma_registration_handle(QEMUFile *f) } =20 for (int count =3D 0; count < head.repeat; count++) { - uint64_t chunk; + uint64_t chunk, chunk_sum; uint8_t *chunk_start, *chunk_end; =20 reg =3D ®isters[count]; @@ -3399,6 +3399,14 @@ int rdma_registration_handle(QEMUFile *f) chunk =3D ram_chunk_index(block->local_host_addr, (uint8_t *) host_addr); chunk_start =3D ram_chunk_start(block, chunk); + if (uadd64_overflow(chunk, reg->chunks, &chunk_sum) || + chunk_sum >=3D block->nb_chunks) { + error_report("%s: head.chunks contains illegal value" + " (chunk=3D%"PRIu64", chunks=3D%"PRIu64",= " + "nb_chunks=3D%d)", __func__, chunk, + reg->chunks, block->nb_chunks); + goto err; + } chunk_end =3D ram_chunk_end(block, chunk + reg->chunks); /* avoid "-Waddress-of-packed-member" warning */ uint32_t tmp_rkey =3D 0; --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932972; cv=none; d=zohomail.com; s=zohoarc; b=XLPC9V5vyU8kke2npLb5OxWfotkxx6HCSn9JaInDDvqHpPidm8Mv5m5gkxv3Lykkufie3Y1D8z4QnHY3SNgXMP1hxBqWSW8dN9eJTWb9tr3zYTVO+ARDe+JcSvRvsK1L1PGeER22GhfgTCUF1wBrBILXD4kODltXqJdcK3y5pCg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932972; 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=0ym9+t3Jz9G6MC9UG3qZwkpQPoOZRMWdsC8IFvFLrhg=; b=Tmyn/li7sR5OfSePGWozBAjo0zeII3+IPjfKK8kPCoU0kh7D6gKgVPdhfgcp0/E5QCvJJtO/b8QQEBD3UrT+p5aG48gfUkijdx5vu4GfkpF7ImgwZR2Dnel9m6C8jXKGIw/NAiAd2GJh23lk6sWPMkgDmvWZ/vTJVGc4ppTJv3U= 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 1787932972000636.0901374729405; Fri, 28 Aug 2026 09:02:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyzV-0001av-4s; Fri, 28 Aug 2026 11:59:41 -0400 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 1wzyzS-0001XC-1o for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:38 -0400 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wzyzG-0008Sf-IL for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:37 -0400 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-out2.suse.de (Postfix) with ESMTPS id 9C6061FE1B; Fri, 28 Aug 2026 15:59:16 +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 933131368F; Fri, 28 Aug 2026 15:59:15 +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 6Kn1GFOwkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932760; 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=0ym9+t3Jz9G6MC9UG3qZwkpQPoOZRMWdsC8IFvFLrhg=; b=ftUyj+hu2Tb2q65MZeFg+TZ3bxdN6Et7Wua50ZIlK2tw7IqVFn6ZFcxmHZwFQu0HVaFZVl tcRTtu/vJItEUfPAHTNmZLnwxWMtM4TwZzGAfuuRlY9zQ4YVRkTkrg4ZRZ8rMywoB+rcml gR5BJsYdtXwRi/Q6RTXrsKKvI5jikaI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932760; 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=0ym9+t3Jz9G6MC9UG3qZwkpQPoOZRMWdsC8IFvFLrhg=; b=8+sdWfjexDh+aFye+MY6Df4VqPF+PZkHIKpESkwDDpGJhNdrKgtsetoOMb2LsdYfALwZik 4eBH2o/m6svsYmDQ== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=JEXhacyv; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="I+/+tTNm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932756; 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=0ym9+t3Jz9G6MC9UG3qZwkpQPoOZRMWdsC8IFvFLrhg=; b=JEXhacyvJ8TGtf3ZXXp3HJTrCH4AxF3fhByA20cY1Ollrda117VlroZ2KwS4+jBCWjlWHN +HoVMpM/fBvjWVHA/lzFf8jzahgO4w5BWPFyK0a2cLOM+cFW4pln577OUVn/Yf0xZ+phZ9 GrUbuEZLnp+XFhsKxic8PFuDWoBt59Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932756; 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=0ym9+t3Jz9G6MC9UG3qZwkpQPoOZRMWdsC8IFvFLrhg=; b=I+/+tTNmNcu1fS5Ut7/YctKQKjo4b70ndgetzqS/aa/pnNx0HDngZ9YCoeEB8SA3p1viZa kGUF1Gweu75CN4Dg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Jinpu Wang Subject: [PULL v2 20/30] migration/rdma: Sanity check upper bound of register MR address Date: Fri, 28 Aug 2026 12:58:35 -0300 Message-ID: <20260828155845.2874508-21-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Queue-Id: 9C6061FE1B X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; 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)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[gitlab.com:url,ionos.com:email,suse.de:dkim,suse.de:email,suse.de:mid,imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.de:+] X-Spam-Score: -3.01 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=195.135.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, 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: 1787932976318158500 Content-Type: text/plain; charset="utf-8" From: Peter Xu Before registration of RDMA ranges, QEMU destination checks for validity of current_addr no less than the target ramblock's start address. But it didn't check for the upper bound to make sure the address is within the size of the ramblock. Add it. Reported-by: Tristan (@TristanInSec) Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4007 Reviewed-by: Jinpu Wang Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas Reviewed-by: Jack Wang Signed-off-by: Fabiano Rosas --- migration/rdma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/migration/rdma.c b/migration/rdma.c index cf6688a4bc3..d8953363fe5 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3387,7 +3387,8 @@ int rdma_registration_handle(QEMUFile *f) goto err; } block =3D &(rdma->local_ram_blocks.block[reg->current_inde= x]); - if (block->offset > reg->current_addr) { + if (block->offset > reg->current_addr || + block->offset + block->length <=3D reg->current_addr) { error_report("rdma: bad register address for block %s" " offset: %" PRIx64 " current_addr: %" PRIx64, block->block_name, block->offset, --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932809; cv=none; d=zohomail.com; s=zohoarc; b=F41X2b8NEkiaaQnxZkpBTf80Df/M+VoO4O/SEduv15DCmfDxjcG0fkCcBUMZEHw5tJjkIqQeAn27AALxsLCCcpzc6UiaTfUieXOZdFWlAwupwR2fdiEPVZWdqde/Zsv1+9/821RwZ1PLucyjoH+Wg96PUc1WC7fdKR7xZTKmA6s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932809; 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=fRRHQXAWBSoz8D3kIzWAjQPHhGiF4yCSa3k6HkPIOAA=; b=j1PMPBGRa5hnO9skyZruGpES5JZoLHxXO9Q11o4xVXNgDe0hCPMA93vhycN5cY910rUFEMLVyBtEm8kVGrmGRVLc4biM4IqRrSwzRG0ml19J+vguFvvZqk4zY3nI/zhhweTDQIgpU9YTL8vDHyymFbisuJ7yzMK5/ib5pU/EmrI= 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 1787932809492154.012906308046; Fri, 28 Aug 2026 09:00:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyzV-0001bH-NE; Fri, 28 Aug 2026 11:59:41 -0400 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 1wzyzT-0001ZU-5U for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:39 -0400 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 1wzyzH-0008TY-HA for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:38 -0400 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-out2.suse.de (Postfix) with ESMTPS id E41201F891; Fri, 28 Aug 2026 15:59: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 DB41E13688; Fri, 28 Aug 2026 15:59:16 +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 sKd9KlSwkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932762; 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=fRRHQXAWBSoz8D3kIzWAjQPHhGiF4yCSa3k6HkPIOAA=; b=B/aj0OHfji+NH42/Na8yTlqgt6L/4dyOIq2Tp/FsfxkR1hL4WnwTadHHjrU5CILLMBPuf1 2jyENZtA9nO3kqLnGqrE13E+O4VmvVwwGXzmVn0cViOVr5tgcbWFJ8AK4db3nZC8c5idaj cRNfD84rpjZlcmKilu0BOEK5FFIwTmI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932762; 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=fRRHQXAWBSoz8D3kIzWAjQPHhGiF4yCSa3k6HkPIOAA=; b=IgTc5sby619LCsYNtJiHAHTYlj06wdXNw9E9+Fb2uKMd6n4mPTAuw+M2wCTcxRO0Ju6I0f dyX2uEV2eR1J7/Dw== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=cOudFuTD; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=JdnZ08i7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932757; 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=fRRHQXAWBSoz8D3kIzWAjQPHhGiF4yCSa3k6HkPIOAA=; b=cOudFuTDOUkmmTHTtm9kjkwpyK500CA54PFpdhu9wQJGAYJOrLTHkbtWDnPM/1nlTuClDc gSfTTrN71l1dUWcY9b16cfYH7MRbfEKavW6szK13LtstYlCCAaYwdh8URsPywkRd+vSnzr BXm4Cwe3NGL3pNdgr9zsXMbvmAC+juA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932757; 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=fRRHQXAWBSoz8D3kIzWAjQPHhGiF4yCSa3k6HkPIOAA=; b=JdnZ08i7RjCkPdJ9Xi21HMqaMnAxlUKwPSk69rVr6yhLziVRd5g6tXqBje0tjdpT0ezT+L JxVA0Lvyk39L8EAA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Jinpu Wang Subject: [PULL v2 21/30] migration/rdma: Sanity check compress request ranges Date: Fri, 28 Aug 2026 12:58:36 -0300 Message-ID: <20260828155845.2874508-22-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Queue-Id: E41201F891 X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; 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)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[ionos.com:email,gitlab.com:url,suse.de:dkim,suse.de:email,suse.de:mid,imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.de:+] X-Spam-Score: -3.01 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: 1787932811412158500 Content-Type: text/plain; charset="utf-8" From: Peter Xu The offset/length ranges are not sanity checked in RDMA requests, add the checks. Reported-by: Tristan (@TristanInSec) Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4005 Reviewed-by: Jinpu Wang Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas Reviewed-by: Jack Wang Signed-off-by: Fabiano Rosas --- migration/rdma.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/migration/rdma.c b/migration/rdma.c index d8953363fe5..e976739fad3 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3198,6 +3198,28 @@ static int dest_ram_sort_func(const void *a, const v= oid *b) return (a_index < b_index) ? -1 : (a_index !=3D b_index); } =20 +static bool rdma_compress_range_check(RDMALocalBlock *block, + RDMACompress *comp) +{ + uint64_t block_end =3D block->offset + block->length; + uint64_t comp_end; + + if (uadd64_overflow(comp->offset, comp->length, &comp_end)) { + goto fail; + } + + if (comp->offset < block->offset || comp_end > block_end) { + goto fail; + } + + return true; +fail: + error_report("%s: compress request range outside range" + " (block=3D%s, offset=3D%"PRIu64", length=3D%"PRIu64")", + __func__, block->block_name, comp->offset, comp->length); + return false; +} + /* * During each iteration of the migration, we listen for instructions * by the source VM to perform dynamic page registrations before they @@ -3277,7 +3299,9 @@ int rdma_registration_handle(QEMUFile *f) goto err; } block =3D &(rdma->local_ram_blocks.block[comp->block_idx]); - + if (!rdma_compress_range_check(block, comp)) { + goto err; + } host_addr =3D block->local_host_addr + (comp->offset - block->offset); if (comp->value) { --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787933044; cv=none; d=zohomail.com; s=zohoarc; b=T62SNgt6PugXvjQs1j0VPdGI/Tywpzgd5LTREh4rXVk7Qp9M2y8MMFQPrvLhhGgtiQAoIVHWrup+UOsib4j8P1RSiehq/vtpp1QdWcu/iBczcuEPZ0AWJb+S/Yb7YZDbSPPtc74nLoJjfF47OOHR/3ZxPQLBGcMItG/D8O+hSrA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787933044; 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=JK5hagYU1EUz0RO8LHP2IW2Zhm75w1JTYi6QloT7uOI=; b=doVtFrsUd9aLyPTQJCzjSVwT8a5c4ZplGbRq7sZuEYKk0YpJYiXryVer1cnSin9Mn0/gfEkO67s3avVpAhngKVYtska6VYXvRniYOhu0dRDZoAYJaIml2iF5SsQUNQoZp2L67sqwkfnFKAYJFwsJYdZi196qoJ9i1zlFLytboVA= 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 1787933044852119.00658770199766; Fri, 28 Aug 2026 09:04:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyzW-0001bp-Df; Fri, 28 Aug 2026 11:59:42 -0400 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 1wzyzT-0001Zs-SE for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:39 -0400 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 1wzyzI-0008Um-R1 for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:39 -0400 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 107B62228E; Fri, 28 Aug 2026 15:59:19 +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 2ED761352D; Fri, 28 Aug 2026 15:59:18 +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 4Fh2AFawkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932763; 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=JK5hagYU1EUz0RO8LHP2IW2Zhm75w1JTYi6QloT7uOI=; b=FQLdvMweH6z/EOOj5171sfT6ukpVNow8XIlqKgWCWhwmxGroZoqrfCNcygvj0cmoaaowB/ ovGqJ70D+yTZW8pYk3hJY73RqgMz5Qa5HA2FSEpr6NTyb+RIi3LbfdvIhFB5xCQ0gKI6Ko 7+IeKuVBpWRror5HXJX4jut5A7bJv1s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932763; 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=JK5hagYU1EUz0RO8LHP2IW2Zhm75w1JTYi6QloT7uOI=; b=b6/wFsWUaFIAr7YBzrUrSMZNoXSgYJ+qEJsaMyZ/nJUd+RhWFTX8yPk/LsI1x1tn9k8cLG JK35uUmqmLfXsRBg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932759; 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=JK5hagYU1EUz0RO8LHP2IW2Zhm75w1JTYi6QloT7uOI=; b=i2wLUWPU+UnE94Fk4x6p4lLcoxfSdPJMWtUyJpYvmWOunn00H9V6NSa6zikLxh76jcQ2sA lar/HotoFI03txxItzL/4n53jU1IwcOwzf6oksD/WkoU76N+VI+GzM1Lg4g+vzGEVpjVrr fBYCiix5qrRIIHepaR4WnkTZ4+zkD1A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932759; 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=JK5hagYU1EUz0RO8LHP2IW2Zhm75w1JTYi6QloT7uOI=; b=AnJuWYQZB7mgktM5Y8WwrufqOcArji66RsuCN5/OrVKnOPBRd2bSdpwCOhwXnKeWHbYqcw TArTVVfSKCK5cYAw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu Subject: [PULL v2 22/30] migration: Remove unused vmstate macros Date: Fri, 28 Aug 2026 12:58:37 -0300 Message-ID: <20260828155845.2874508-23-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.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.997]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_TWO(0.00)[2]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(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)[imap1.dmz-prg2.suse.org:helo,suse.de:mid,suse.de:email]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] 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) (identity @suse.de) X-ZM-MESSAGEID: 1787933047469154100 Content-Type: text/plain; charset="utf-8" Remove the several vmstate macros that don't have any users. Acked-by: Peter Xu Signed-off-by: Fabiano Rosas --- include/migration/vmstate.h | 45 ------------------------------------- 1 file changed, 45 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 1b7f295417e..214a2131350 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -451,15 +451,6 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D vmstate_offset_sub_array(_state, _field, _type, _start= ), \ } =20 -#define VMSTATE_ARRAY_INT32_UNSAFE(_field, _state, _field_num, _info, _typ= e) {\ - .name =3D (stringify(_field)), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, int32_t), \ - .info =3D &(_info), \ - .size =3D sizeof(_type), \ - .flags =3D VMS_VARRAY_INT32, \ - .offset =3D vmstate_offset_varray(_state, _field, _type), \ -} - #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, = _type) {\ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ @@ -710,16 +701,6 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 -#define VMSTATE_STRUCT_VARRAY_INT32(_field, _state, _field_num, _version, = _vmsd, _type) { \ - .name =3D (stringify(_field)), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, int32_t), \ - .version_id =3D (_version), \ - .vmsd =3D &(_vmsd), \ - .size =3D sizeof(_type), \ - .flags =3D VMS_STRUCT|VMS_VARRAY_INT32, \ - .offset =3D vmstate_offset_varray(_state, _field, _type), \ -} - #define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version,= _vmsd, _type) { \ .name =3D (stringify(_field)), \ .num_offset =3D vmstate_offset_value(_state, _field_num, uint32_t), \ @@ -1069,8 +1050,6 @@ extern const VMStateInfo vmstate_info_g_byte_array; =20 #ifdef CONFIG_LINUX =20 -#define VMSTATE_U8(_f, _s) \ - VMSTATE_U8_V(_f, _s, 0) #define VMSTATE_U16(_f, _s) \ VMSTATE_U16_V(_f, _s, 0) #define VMSTATE_U32(_f, _s) \ @@ -1116,15 +1095,6 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_BOOL_TEST(_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_bool, bool) =20 -#define VMSTATE_INT8_TEST(_f, _s, _t) \ - VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t) - -#define VMSTATE_INT16_TEST(_f, _s, _t) \ - VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int16, int16_t) - -#define VMSTATE_INT32_TEST(_f, _s, _t) \ - VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int32, int32_t) - #define VMSTATE_INT64_TEST(_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int64, int64_t) =20 @@ -1140,12 +1110,6 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_UINT64_TEST(_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t) =20 -#define VMSTATE_FD_TEST(_f, _s, _t) = \ - VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_fd, int32_t) - -#define VMSTATE_TIMER_PTR_TEST(_f, _s, _test) \ - VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *) - #define VMSTATE_TIMER_PTR_V(_f, _s, _v) \ VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *) =20 @@ -1155,9 +1119,6 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_TIMER_PTR_ARRAY(_f, _s, _n) \ VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer) =20 -#define VMSTATE_TIMER_TEST(_f, _s, _test) \ - VMSTATE_SINGLE_TEST(_f, _s, _test, 0, vmstate_info_timer, QEMUTimer) - #define VMSTATE_TIMER_V(_f, _s, _v) \ VMSTATE_SINGLE(_f, _s, _v, vmstate_info_timer, QEMUTimer) =20 @@ -1275,12 +1236,6 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \ VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, 0) =20 -#define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size) \ - VMSTATE_VBUFFER(_f, _s, 0, NULL, _size) - -#define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size) = \ - VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, _size) - #define VMSTATE_BUFFER_TEST(_f, _s, _test) \ VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)= )) =20 --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932992; cv=none; d=zohomail.com; s=zohoarc; b=WM7G1NBpAkcUG5KPG34g2QRAnSVLCi4aHYzItc8srV6RU9fmAoo9mGMDh/Hp2gyTk589hPKmG+JIOGJLiHgmw4zklq0qOua9QIrq19C73CeaXHc89SE0Pad2Xo0PG/ALq6kvE0nuoO+gKZHfzKcFjqgr1dwu4CouDSUxTPDxT9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932992; 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=613o7Y7HZhpjY7MgVi/crv2qLfb89+OI21UrpdTG7wA=; b=j0hy9wYLn1ObJm5Bw4Tomx6UfTN7IC/pdBasYsMBb03y3oZmjL8ANFkUD0PbVRdrGAXClkv1Z0K3TtQsipXNaKvQ2yphKZtBgZHIIhwwC7AbzYlOVOmjJiUBlVVSGKnKLo6gDYyL3HFF1gdLRDzZwb6ciEfSYfXSRejztA/25Rc= 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 1787932992450693.6438565579908; Fri, 28 Aug 2026 09:03:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyzZ-0001d7-Ai; Fri, 28 Aug 2026 11:59:45 -0400 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 1wzyzY-0001cb-3s for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:44 -0400 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wzyzL-0008VU-Ie for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:43 -0400 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 8188221BDE; Fri, 28 Aug 2026 15:59:20 +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 4C9B713691; Fri, 28 Aug 2026 15:59:19 +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 2NG8B1ewkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932764; 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=613o7Y7HZhpjY7MgVi/crv2qLfb89+OI21UrpdTG7wA=; b=cMbRisKgQ86f+s/dFPHlCeizXKMTCd3/7O61WkPcd10ttgw27fufaex0t0cs+d6yup12pW Kx6DMEQ/WgIcAv/GzKBcxT1MmMZbnnA6bQBFx5UVxMWrJQ9PnjYbAp3jTl++7pimJCYqMC 9O0mEWJZCX41sDiBKVD1LgeX6WOHnqU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932764; 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=613o7Y7HZhpjY7MgVi/crv2qLfb89+OI21UrpdTG7wA=; b=KNDxqPaNirRzk0vet6CkoVmVoOJyj2H4udiZxyFS5oNUk4SDRE7lvlzMBJI+e63rQThqTM ox8jN7OvH3ieNlCQ== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=p75psaxC; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=WEugoO+5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932760; 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=613o7Y7HZhpjY7MgVi/crv2qLfb89+OI21UrpdTG7wA=; b=p75psaxCGz2lGYbx7+WsaeyVeS9x4OYUHZDQc4eSTVDl1sIljGTHD6fFmV2QT8jltpxLCW CZ8A3vomaoOPuwIgCpVWOae3Z6bgW7ctNwornq5syUKY5ZCw0z8kFjLSNFGW5NrN8iFrwh 8v7jLn0WXVeeRfWe6eBCGcgoaAGrePw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932760; 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=613o7Y7HZhpjY7MgVi/crv2qLfb89+OI21UrpdTG7wA=; b=WEugoO+58ZiMiB3ZH8KTCX/1snDFd+y/BxjVQ0XGWHk1dteYBp0BDMyFi7FQdxj2zbfmYU 4IaP8xWJf02J3eCA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Seungjung Kim Subject: [PULL v2 23/30] migration: Introduce VMStateStructMember Date: Fri, 28 Aug 2026 12:58:38 -0300 Message-ID: <20260828155845.2874508-24-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.01 X-Rspamd-Queue-Id: 8188221BDE X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spamd-Result: default: False [-3.01 / 50.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)[]; FROM_EQ_ENVFROM(0.00)[]; FREEMAIL_CC(0.00)[redhat.com,gmail.com]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[gitlab.com:url,suse.de:dkim,suse.de:email,suse.de:mid,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; RCPT_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.de:+] 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=195.135.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, 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: 1787932994588154100 Content-Type: text/plain; charset="utf-8" When migrating a buffer or array, the vmstate code needs to know the size of the buffer and the number of elements of the array. Today a vmstate writer can choose from a number of macros that take as last input the name of a struct member from where the size/num will be read. At load time, the code will access those values via an opaque pointer to the migrated data and therefore it needs to also know the size of the struct member at that offset. Currently that information is communicated by means of the VMS_VARRAY_* and VMS_VBUFFER_* flags, where each possible type is represented by a flag. So far, that's all fine, but since the vmstate code makes heavy use of macros, handling several types individually (i.e. by name: int, int32_t, etc) requires several versions of a same macro, one for each type. E.g: VMSTATE_VBUFFER_ALLOC_UINT32 ^ This creates a pattern where the vmstate writer has to match the macro name to the data type and has resulted in the code having a tendency of having one macro version for each type, for each type of vmstate. There is also some cognitive load to deal with, e.g. VMSTATE_VARRAY_INT32 doesn't hold an array of int32, it holds an array of something else and the number of elements for the array is stored in a variable of type int32. We're now dealing with the scenario where the code has been expecting int32_t at some places, but a uint64_t macro variant has been added without the code being updated. To address all these situations, introduce a new struct that will hold the offset of the struct members, but also their size, so the various extra macros can all be removed and the person writing the vmstate doesn't need to care about type-checking. Still, keep a minimum check that those fields are at least integers and fit into 64 bits. What changes: 1) type checking changes from individual types to a single check for all integers; 2) there are new ways to access the offsets; num_offset -> num_indirect.offset size_offset -> size_indirect.offset [new] num_indirect.size [new] size_indirect.size 2) reading the offsets goes from checking the VMS_VARRAY_* flags in an if/elseif block to comparing offset.size against the hardcoded sizes in bytes; 3) the VMS_VARRAY_* and VMS_VBUFFER_* flags become obsolete. Removed in the next patch; 4) memory usage increases +1 byte per vmstate; Reported-by: Seungjung Kim Fixes: CVE-2026-6426 Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3675 Acked-by: Peter Xu [fixed up vmstate_read_from_offset to work on BE host] Signed-off-by: Fabiano Rosas --- include/migration/vmstate.h | 163 +++++++++++++++++++++-------- migration/savevm.c | 4 +- migration/vmstate.c | 63 +++++++---- rust/bindings/migration-sys/lib.rs | 10 ++ rust/migration/src/vmstate.rs | 24 ++++- rust/tests/tests/vmstate_tests.rs | 26 ++--- 6 files changed, 210 insertions(+), 80 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 214a2131350..12bfa64fb92 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -31,6 +31,7 @@ =20 typedef struct VMStateInfo VMStateInfo; typedef struct VMStateField VMStateField; +typedef struct VMStateStructMember VMStateStructMember; =20 /* * VMStateInfo allows customized migration of objects that don't fit in @@ -67,15 +68,15 @@ enum VMStateFlags { * to the actual field (e.g. struct a { uint8_t *b; * }). Dereference the pointer before using it as basis for * further pointer arithmetic (see e.g. VMS_ARRAY). Does not - * affect the meaning of VMStateField.num_offset or - * VMStateField.size_offset; see VMS_VARRAY* and VMS_VBUFFER for + * affect the meaning of VMStateField.num_indirect or + * VMStateField.size_indirect; see VMS_VARRAY* and VMS_VBUFFER for * those. */ VMS_POINTER =3D 0x002, =20 /* The field is an array of fixed size. VMStateField.num contains * the number of entries in the array. The size of each entry is * given by VMStateField.size and / or opaque + - * VMStateField.size_offset; see VMS_VBUFFER and + * VMStateField.size_indirect; see VMS_VBUFFER and * VMS_MULTIPLY. Each array entry will be processed individually * (VMStateField.info.get()/put() if VMS_STRUCT is not set, * recursion into VMStateField.vmsd if VMS_STRUCT is set). May not @@ -88,8 +89,9 @@ enum VMStateFlags { * array entry. */ VMS_STRUCT =3D 0x008, =20 - /* The field is an array of variable size. The int32_t at opaque + - * VMStateField.num_offset contains the number of entries in the + /* + * The field is an array of variable size. The integer at opaque + + * VMStateField.num_indirect contains the number of entries in the * array. See the VMS_ARRAY description regarding array handling * in general. May not be combined with VMS_ARRAY or any other * VMS_VARRAY*. */ @@ -105,7 +107,7 @@ enum VMStateFlags { VMS_ARRAY_OF_POINTER =3D 0x040, =20 /* The field is an array of variable size. The uint16_t at opaque - * + VMStateField.num_offset + * + VMStateField.num_indirect * contains the number of entries in the array. See the VMS_ARRAY * description regarding array handling in general. May not be * combined with VMS_ARRAY or any other VMS_VARRAY*. */ @@ -114,26 +116,27 @@ enum VMStateFlags { /* The size of the individual entries (a single array entry if * VMS_ARRAY or any of VMS_VARRAY* are set, or the field itself if * neither is set) is variable (i.e. not known at compile-time), - * but the same for all entries. Use the int32_t at opaque + - * VMStateField.size_offset (subject to VMS_MULTIPLY) to determine + * but the same for all entries. Use the integer at opaque + + * VMStateField.size_indirect (subject to VMS_MULTIPLY) to determine * the size of each (and every) entry. */ VMS_VBUFFER =3D 0x100, =20 - /* Multiply the entry size given by the int32_t at opaque + - * VMStateField.size_offset (see VMS_VBUFFER description) with + /* + * Multiply the entry size given by the integer at opaque + + * VMStateField.size_indirect (see VMS_VBUFFER description) with * VMStateField.size to determine the number of bytes to be * allocated. Only valid in combination with VMS_VBUFFER. */ VMS_MULTIPLY =3D 0x200, =20 /* The field is an array of variable size. The uint8_t at opaque + - * VMStateField.num_offset + * VMStateField.num_indirect * contains the number of entries in the array. See the VMS_ARRAY * description regarding array handling in general. May not be * combined with VMS_ARRAY or any other VMS_VARRAY*. */ VMS_VARRAY_UINT8 =3D 0x400, =20 /* The field is an array of variable size. The uint32_t at opaque - * + VMStateField.num_offset + * + VMStateField.num_indirect * contains the number of entries in the array. See the VMS_ARRAY * description regarding array handling in general. May not be * combined with VMS_ARRAY or any other VMS_VARRAY*. */ @@ -187,29 +190,88 @@ typedef enum { MIG_PRI_MAX, } MigrationPriority; =20 + +/* + * VMStateStructMember: Metadata about a single member of the struct + * being migrated by the vmstate. This is kept separate from + * VMStateField because a single VMStateField can reference other + * members of the struct aside from the main struct member that's + * being migrated. + * + * One situation where extra fields are referenced is the common case + * of a struct containing an array or buffer, the size of which is + * stored in another member of the same struct. + * + * Example 1: + * struct IDEState { + * ... + * uint8_t *io_buffer; + * int32_t io_buffer_total_len; + * ... + * } + * VMSTATE_VARRAY_INT32(io_buffer, IDEState, io_buffer_total_len, 1, + * vmstate_info_uint8, uint8_t) + * + * In the above, io_buffer is the main field being migrated by the + * VMSTATE_VARRAY while io_buffer_total_len is the meta field that + * provides the size of the io_buffer. In this particular case, + * io_buffer_total_len is never migrated. + * + * Example 2: + * struct SpaprMachineState { + * ... + * uint32_t fdt_size; + * void *fdt_blob; + * ... + * } + * VMSTATE_UINT32(fdt_size, SpaprMachineState), + * VMSTATE_VBUFFER_ALLOC_UINT32(fdt_blob, SpaprMachineState, 0, NULL, fdt_= size), + * + * Here, fdt_blob is the field being migrated by VMSTATE_VBUFFER_ALLOC + * and fdt_size is the meta field providing the size. In this case, + * the extra field is also independently migrated by the + * VMSTATE_UINT32 above. + */ +struct VMStateStructMember { + /* offsetof the field inside the migrated struct */ + uint32_t offset; + /* size of field itself */ + uint8_t size; +}; + struct VMStateField { const char *name; size_t offset; =20 /* - * @size or @size_offset specifies the size of the element embeded in - * the field. Only one of them should be present never both. When - * @size_offset is used together with VMS_VBUFFER, it means the size is - * dynamic calculated instead of a constant. + * @size directly specifies the size of the element being + * migrated. * - * When the field is an array of any type, this stores the size of one - * element of the array. + * @size_indirect specifies the offset inside a struct where the + * size of the element is stored. * - * NOTE: even if VMS_POINTER or VMS_ARRAY_OF_POINTER may be specified, - * this parameter always reflects the real size of the objects that a - * pointer point to. + * Only one of the above should be present (except for + * VMSTATE_MULTIPLY which uses .size as a multiplier). When + * @size_indirect is used together with VMS_VBUFFER, it means + * the size is dynamic calculated instead of a constant. + * + * When the field is an array of any type, these refer to the size + * of one element of the array. + * + * NOTE: even if VMS_POINTER or VMS_ARRAY_OF_POINTER may be + * specified, these parameters always reflect the real size of the + * objects that a pointer point to. + * + * @num_indirect specifies the offset inside a struct where the + * number of elements of an array is stored. */ size_t size; - size_t size_offset; + VMStateStructMember size_indirect; + VMStateStructMember num_indirect; =20 size_t start; int num; - size_t num_offset; + const VMStateInfo *info; enum VMStateFlags flags; const VMStateDescription *vmsd; @@ -328,6 +390,17 @@ extern const VMStateInfo vmstate_info_g_byte_array; (type_check(t1, typeof_elt_of_field(t2, f)) \ + QEMU_BUILD_BUG_ON_ZERO(!QEMU_IS_ARRAY(((t2 *)0)->f))) =20 +#define type_check_int64(t) \ + (~((t)0) * sizeof(struct { \ + QEMU_BUILD_BUG_ON(sizeof(t) > sizeof(uint64_t)); \ + })) + +#define vmstate_field_offset(_state, _field) { \ + .offset =3D (offsetof(_state, _field) + \ + type_check_int64(typeof_field(_state, _field))), \ + .size =3D sizeof(typeof_field(_state, _field)), \ +} + #define vmstate_offset_value(_state, _field, _type) \ (offsetof(_state, _field) + \ type_check(_type, typeof_field(_state, _field))) @@ -454,7 +527,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, = _type) {\ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, int32_t), \ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ .flags =3D VMS_VARRAY_INT32|VMS_POINTER, \ @@ -464,7 +537,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info,= _type) {\ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint32_t),\ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ .flags =3D VMS_VARRAY_UINT32|VMS_POINTER, \ @@ -474,7 +547,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_VARRAY_INT32_ALLOC(_field, _state, _field_num, _version, _= info, _type) {\ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, int32_t), \ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ .flags =3D VMS_VARRAY_INT32 | VMS_POINTER | VMS_ALLOC, \ @@ -484,7 +557,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_VARRAY_UINT32_ALLOC(_field, _state, _field_num, _version, = _info, _type) {\ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint32_t),\ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ .flags =3D VMS_VARRAY_UINT32|VMS_POINTER|VMS_ALLOC, \ @@ -494,7 +567,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_VARRAY_UINT16_ALLOC(_field, _state, _field_num, _version, = _info, _type) {\ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint16_t),\ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ .flags =3D VMS_VARRAY_UINT16 | VMS_POINTER | VMS_ALLOC, \ @@ -504,7 +577,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version,= _info, _type) {\ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint16_t),\ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ .flags =3D VMS_VARRAY_UINT16, \ @@ -583,7 +656,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; _field, _state, _field_num, _version, _vmsd, _type) { \ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint8_t), \ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .vmsd =3D &(_vmsd), \ .size =3D sizeof(_type), \ .flags =3D VMS_POINTER | VMS_VARRAY_UINT8 | \ @@ -596,7 +669,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; _field, _state, _field_num, _version, _vmsd, _type) { \ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint32_t), \ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .vmsd =3D &(_vmsd), \ .size =3D sizeof(_type), \ .flags =3D VMS_POINTER | VMS_VARRAY_UINT32 | \ @@ -608,7 +681,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_VARRAY_OF_POINTER_UINT32(_field, _state, _field_num, _vers= ion, _info, _type) { \ .name =3D (stringify(_field)), = \ .version_id =3D (_version), = \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint32_t), = \ + .num_indirect =3D vmstate_field_offset(_state, _field_num), = \ .info =3D &(_info), = \ .flags =3D VMS_VARRAY_UINT32 | VMS_ARRAY_OF_POINTER | VMS_POINTER= , \ .offset =3D vmstate_offset_pointer(_state, _field, _type *), = \ @@ -650,7 +723,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; =20 #define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, = _vmsd, _type) { \ .name =3D (stringify(_field)), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint8_t), \ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .version_id =3D (_version), \ .vmsd =3D &(_vmsd), \ .size =3D sizeof(_type), \ @@ -674,7 +747,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _v= msd, _type) { \ .name =3D (stringify(_field)), \ .version_id =3D 0, \ - .num_offset =3D vmstate_offset_value(_state, _field_num, int32_t), \ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .size =3D sizeof(_type), \ .vmsd =3D &(_vmsd), \ .flags =3D VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \ @@ -684,7 +757,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_STRUCT_VARRAY_POINTER_UINT32(_field, _state, _field_num, _= vmsd, _type) { \ .name =3D (stringify(_field)), \ .version_id =3D 0, \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint32_t),\ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .size =3D sizeof(_type), \ .vmsd =3D &(_vmsd), \ .flags =3D VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \ @@ -694,7 +767,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _= vmsd, _type) { \ .name =3D (stringify(_field)), \ .version_id =3D 0, \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint16_t),\ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .size =3D sizeof(_type), \ .vmsd =3D &(_vmsd), \ .flags =3D VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT, \ @@ -703,7 +776,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; =20 #define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version,= _vmsd, _type) { \ .name =3D (stringify(_field)), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint32_t), \ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .version_id =3D (_version), \ .vmsd =3D &(_vmsd), \ .size =3D sizeof(_type), \ @@ -715,7 +788,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .vmsd =3D &(_vmsd), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, int32_t), \ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .size =3D sizeof(_type), \ .flags =3D VMS_STRUCT|VMS_VARRAY_INT32|VMS_ALLOC|VMS_POINTER, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ @@ -736,7 +809,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .field_exists =3D (_test), \ - .size_offset =3D vmstate_offset_value(_state, _field_size, uint32_t),\ + .size_indirect =3D vmstate_field_offset(_state, _field_size), \ .size =3D (_multiply), \ .info =3D &vmstate_info_buffer, \ .flags =3D VMS_VBUFFER|VMS_POINTER|VMS_MULTIPLY, \ @@ -747,7 +820,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .field_exists =3D (_test), \ - .size_offset =3D vmstate_offset_value(_state, _field_size, int32_t),\ + .size_indirect =3D vmstate_field_offset(_state, _field_size), \ .info =3D &vmstate_info_buffer, \ .flags =3D VMS_VBUFFER|VMS_POINTER, \ .offset =3D offsetof(_state, _field), \ @@ -757,7 +830,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .field_exists =3D (_test), \ - .size_offset =3D vmstate_offset_value(_state, _field_size, uint32_t),\ + .size_indirect =3D vmstate_field_offset(_state, _field_size), \ .info =3D &vmstate_info_buffer, \ .flags =3D VMS_VBUFFER|VMS_POINTER, \ .offset =3D offsetof(_state, _field), \ @@ -767,7 +840,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .field_exists =3D (_test), \ - .size_offset =3D vmstate_offset_value(_state, _field_size, uint64_t),\ + .size_indirect =3D vmstate_field_offset(_state, _field_size), \ .info =3D &vmstate_info_buffer, \ .flags =3D VMS_VBUFFER | VMS_POINTER, \ .offset =3D offsetof(_state, _field), \ @@ -778,7 +851,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .field_exists =3D (_test), \ - .size_offset =3D vmstate_offset_value(_state, _field_size, uint32_t),\ + .size_indirect =3D vmstate_field_offset(_state, _field_size), \ .info =3D &vmstate_info_buffer, \ .flags =3D VMS_VBUFFER|VMS_POINTER|VMS_ALLOC, \ .offset =3D offsetof(_state, _field), \ @@ -838,7 +911,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_UNUSED_VARRAY_UINT32(_state, _test, _version, _field_num, = _size) {\ .name =3D "unused", \ .field_exists =3D (_test), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint32_t),\ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .version_id =3D (_version), \ .size =3D (_size), \ .info =3D &vmstate_info_unused_buffer, \ @@ -852,7 +925,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .name =3D (stringify(_field)), \ .field_exists =3D (_test), \ .version_id =3D (_version), \ - .size_offset =3D vmstate_offset_value(_state, _field_size, int32_t),\ + .size_indirect =3D vmstate_field_offset(_state, _field_size), \ .info =3D &vmstate_info_bitmap, \ .flags =3D VMS_VBUFFER|VMS_POINTER, \ .offset =3D offsetof(_state, _field), \ diff --git a/migration/savevm.c b/migration/savevm.c index 161a9d090fa..16b049c4539 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -873,14 +873,14 @@ static void vmstate_check(const VMStateDescription *v= msd) * Size must be provided because dest QEMU needs that * info to know what to allocate */ - assert(field->size || field->size_offset); + assert(field->size !=3D 0 || field->size_indirect.size= !=3D 0); } else { /* * Otherwise size info isn't useful (because it's * always the size of host pointer), detect accidental * setup of sizes in this case. */ - assert(field->size =3D=3D 0 && field->size_offset =3D= =3D 0); + assert(field->size =3D=3D 0 && field->size_indirect.si= ze =3D=3D 0); } /* * VMS_ARRAY_OF_POINTER must be used only together with one diff --git a/migration/vmstate.c b/migration/vmstate.c index 50ebe378452..9f49abda245 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -78,32 +78,57 @@ vmsd_init_ptr_marker_field(VMStateField *fake, const VM= StateField *field) }; } =20 -static int vmstate_n_elems(void *opaque, const VMStateField *field) +static uint64_t vmstate_read_from_offset(const VMStateStructMember *member, + void *opaque) { - int n_elems =3D 1; + uint8_t *ptr =3D (uint8_t *)opaque + member->offset; + + switch (member->size) { + case 1: { + uint8_t v; + memcpy(&v, ptr, 1); + return v; + } + case 2: { + uint16_t v; + memcpy(&v, ptr, 2); + return v; + } + case 4: { + uint32_t v; + memcpy(&v, ptr, 4); + return v; + } + case 8: { + uint64_t v; + memcpy(&v, ptr, 8); + return v; + } + } + g_assert_not_reached(); +} + +static uint64_t vmstate_n_elems(void *opaque, const VMStateField *field) +{ + uint64_t n_elems =3D 1; =20 if (field->flags & VMS_ARRAY) { n_elems =3D field->num; - } else if (field->flags & VMS_VARRAY_INT32) { - n_elems =3D *(int32_t *)(opaque + field->num_offset); - } else if (field->flags & VMS_VARRAY_UINT32) { - n_elems =3D *(uint32_t *)(opaque + field->num_offset); - } else if (field->flags & VMS_VARRAY_UINT16) { - n_elems =3D *(uint16_t *)(opaque + field->num_offset); - } else if (field->flags & VMS_VARRAY_UINT8) { - n_elems =3D *(uint8_t *)(opaque + field->num_offset); + } else if (field->flags & (VMS_VARRAY_INT32 | VMS_VARRAY_UINT32 + | VMS_VARRAY_UINT16 | VMS_VARRAY_UINT8)) { + n_elems =3D vmstate_read_from_offset(&field->num_indirect, opaque); } =20 trace_vmstate_n_elems(field->name, n_elems); return n_elems; } =20 -static int vmstate_size(void *opaque, const VMStateField *field) +static uint64_t vmstate_size(void *opaque, const VMStateField *field) { - int size; + uint64_t size; =20 if (field->flags & VMS_VBUFFER) { - size =3D *(int32_t *)(opaque + field->size_offset); + size =3D vmstate_read_from_offset(&field->size_indirect, opaque); if (field->flags & VMS_MULTIPLY) { size *=3D field->size; } @@ -124,7 +149,7 @@ static void vmstate_handle_alloc(void *ptr, const VMSta= teField *field, void *opaque) { if (field->flags & VMS_POINTER && field->flags & VMS_ALLOC) { - gsize size =3D vmstate_size(opaque, field); + uint64_t size =3D vmstate_size(opaque, field); size *=3D vmstate_n_elems(opaque, field); if (size) { *(void **)ptr =3D g_malloc(size); @@ -335,8 +360,9 @@ bool vmstate_load_vmsd(QEMUFile *f, const VMStateDescri= ption *vmsd, =20 if (exists) { void *first_elem =3D opaque + field->offset; - int i, n_elems =3D vmstate_n_elems(opaque, field); - int size =3D vmstate_size(opaque, field); + int i; + uint64_t n_elems =3D vmstate_n_elems(opaque, field); + uint64_t size =3D vmstate_size(opaque, field); =20 vmstate_handle_alloc(first_elem, field, opaque); if (field->flags & VMS_POINTER) { @@ -650,8 +676,9 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMSt= ateDescription *vmsd, while (field->name) { if (vmstate_field_exists(vmsd, field, opaque, version_id)) { void *first_elem =3D opaque + field->offset; - int i, n_elems =3D vmstate_n_elems(opaque, field); - int size =3D vmstate_size(opaque, field); + int i; + uint64_t n_elems =3D vmstate_n_elems(opaque, field); + uint64_t size =3D vmstate_size(opaque, field); JSONWriter *vmdesc_loop =3D vmdesc; bool is_prev_null =3D false; /* diff --git a/rust/bindings/migration-sys/lib.rs b/rust/bindings/migration-s= ys/lib.rs index 9581481e421..baa2730ca9d 100644 --- a/rust/bindings/migration-sys/lib.rs +++ b/rust/bindings/migration-sys/lib.rs @@ -47,6 +47,7 @@ fn default() -> Self { unsafe impl Zeroable for VMStateFlags {} unsafe impl Zeroable for VMStateField {} unsafe impl Zeroable for VMStateDescription {} +unsafe impl Zeroable for VMStateStructMember {} =20 // The following higher-level helpers could be in "migration" // crate when Rust has const trait impl. @@ -115,3 +116,12 @@ pub const fn with_varray_flag(mut self, flag: VMStateF= lags) -> Self { self.with_varray_flag_unchecked(flag) } } + +impl VMStateStructMember { + pub const fn new(off: usize, size: usize) -> Self { + Self { + offset: off as u32, + size: size as u8, + } + } +} diff --git a/rust/migration/src/vmstate.rs b/rust/migration/src/vmstate.rs index 7409b592a2c..48d0065139a 100644 --- a/rust/migration/src/vmstate.rs +++ b/rust/migration/src/vmstate.rs @@ -41,7 +41,7 @@ }; =20 use crate::bindings::{self, VMStateFlags}; -pub use crate::bindings::{MigrationPriority, VMStateField}; +pub use crate::bindings::{MigrationPriority, VMStateField, VMStateStructMe= mber}; =20 /// This macro is used to call a function with a generic argument bound /// to the type of a field. The function must take a @@ -119,6 +119,23 @@ pub const fn vmstate_varray_flag(_: Phanto= mData) -> VMStateFlags T::VARRAY_FLAG } =20 +pub const OPAQUE: &[u8; 1048576] =3D &[0; 1048576]; + +pub const fn size_of_ptr_type(_: *const T) -> usize { + ::core::mem::size_of::() +} + +#[macro_export] +macro_rules! size_of_field_type { + ($struct_name:ty, $($field_name:ident).+) =3D> { + $crate::vmstate::size_of_ptr_type(unsafe { + ::core::ptr::addr_of!( + (*$crate::vmstate::OPAQUE.as_ptr().cast::<$struct_name>())= .$($field_name).+ + ) + }) + }; +} + /// Return the `VMStateField` for a field of a struct. The field must be /// visible in the current scope. /// @@ -146,7 +163,10 @@ macro_rules! vmstate_of { .as_bytes() .as_ptr().cast::<::std::os::raw::c_char>(), offset: ::std::mem::offset_of!($struct_name, $($field_name).+), - $(num_offset: ::std::mem::offset_of!($struct_name, $($num).+),= )? + $(num_indirect: $crate::vmstate::VMStateStructMember { + offset: ::std::mem::offset_of!($struct_name, $($num).+) as= u32, + size: $crate::size_of_field_type!($struct_name, $($num).+) as u8, + },)? $(field_exists: $crate::vmstate_exist_fn!($struct_name, $test_= fn),)? // The calls to `call_func_with_field!` are the magic that // computes most of the VMStateField from the type of the fiel= d. diff --git a/rust/tests/tests/vmstate_tests.rs b/rust/tests/tests/vmstate_t= ests.rs index c2c12cfab52..c002ffb2bc4 100644 --- a/rust/tests/tests/vmstate_tests.rs +++ b/rust/tests/tests/vmstate_tests.rs @@ -65,7 +65,7 @@ fn test_vmstate_uint16() { b"elem\0" ); assert_eq!(foo_fields[0].offset, 16); - assert_eq!(foo_fields[0].num_offset, 0); + assert_eq!(foo_fields[0].num_indirect.size, 0); assert_eq!(foo_fields[0].info, unsafe { &vmstate_info_int8 }); assert_eq!(foo_fields[0].version_id, 0); assert_eq!(foo_fields[0].size, 1); @@ -86,7 +86,7 @@ fn test_vmstate_unused() { b"unused\0" ); assert_eq!(foo_fields[1].offset, 0); - assert_eq!(foo_fields[1].num_offset, 0); + assert_eq!(foo_fields[1].num_indirect.size, 0); assert_eq!(foo_fields[1].info, unsafe { &vmstate_info_unused_buffer }); assert_eq!(foo_fields[1].version_id, 0); assert_eq!(foo_fields[1].size, 8); @@ -108,7 +108,7 @@ fn test_vmstate_varray_uint16_unsafe() { b"arr\0" ); assert_eq!(foo_fields[2].offset, 0); - assert_eq!(foo_fields[2].num_offset, 4); + assert_eq!(foo_fields[2].num_indirect.offset, 4); assert_eq!(foo_fields[2].info, unsafe { &vmstate_info_uint8 }); assert_eq!(foo_fields[2].version_id, 0); assert_eq!(foo_fields[2].size, 1); @@ -172,7 +172,7 @@ fn test_vmstate_bool_v() { b"val\0" ); assert_eq!(foo_fields[0].offset, 136); - assert_eq!(foo_fields[0].num_offset, 0); + assert_eq!(foo_fields[0].num_indirect.size, 0); assert_eq!(foo_fields[0].info, unsafe { &vmstate_info_bool }); assert_eq!(foo_fields[0].version_id, 2); assert_eq!(foo_fields[0].size, 1); @@ -193,7 +193,7 @@ fn test_vmstate_uint64() { b"wrap\0" ); assert_eq!(foo_fields[1].offset, 128); - assert_eq!(foo_fields[1].num_offset, 0); + assert_eq!(foo_fields[1].num_indirect.size, 0); assert_eq!(foo_fields[1].info, unsafe { &vmstate_info_uint64 }); assert_eq!(foo_fields[1].version_id, 0); assert_eq!(foo_fields[1].size, 8); @@ -215,7 +215,7 @@ fn test_vmstate_struct_varray_uint8() { b"arr_a\0" ); assert_eq!(foo_fields[2].offset, 0); - assert_eq!(foo_fields[2].num_offset, 60); + assert_eq!(foo_fields[2].num_indirect.offset, 60); assert!(foo_fields[2].info.is_null()); // VMSTATE_STRUCT_VARRAY_UINT8 = doesn't set info field. assert_eq!(foo_fields[2].version_id, 1); assert_eq!(foo_fields[2].size, 20); @@ -240,7 +240,7 @@ fn test_vmstate_macro_array() { b"arr_i64\0" ); assert_eq!(foo_fields[4].offset, 144); - assert_eq!(foo_fields[4].num_offset, 0); + assert_eq!(foo_fields[4].num_indirect.size, 0); assert_eq!(foo_fields[4].info, unsafe { &vmstate_info_int64 }); assert_eq!(foo_fields[4].version_id, 0); assert_eq!(foo_fields[4].size, 8); @@ -264,7 +264,7 @@ fn test_vmstate_struct_varray_uint8_wrapper() { unsafe { CStr::from_ptr(foo_fields[5].name) }.to_bytes_with_nul(), b"arr_a_wrap\0" ); - assert_eq!(foo_fields[5].num_offset, 228); + assert_eq!(foo_fields[5].num_indirect.offset, 228); assert!(unsafe { foo_fields[5].field_exists.unwrap()(foo_b_p, 0) }); =20 // The last VMStateField in VMSTATE_FOOB. @@ -316,7 +316,7 @@ fn test_vmstate_pointer() { b"ptr\0" ); assert_eq!(foo_fields[0].offset, 0); - assert_eq!(foo_fields[0].num_offset, 0); + assert_eq!(foo_fields[0].num_indirect.size, 0); assert_eq!(foo_fields[0].info, unsafe { &vmstate_info_int32 }); assert_eq!(foo_fields[0].version_id, 2); assert_eq!(foo_fields[0].size, 4); @@ -341,7 +341,7 @@ fn test_vmstate_struct_pointer() { b"ptr_a\0" ); assert_eq!(foo_fields[1].offset, PTR_SIZE); - assert_eq!(foo_fields[1].num_offset, 0); + assert_eq!(foo_fields[1].num_indirect.size, 0); assert_eq!(foo_fields[1].vmsd, VMSTATE_FOOA.as_ref()); assert_eq!(foo_fields[1].version_id, 0); assert_eq!(foo_fields[1].size, size_of::()); @@ -366,7 +366,7 @@ fn test_vmstate_macro_array_of_pointer() { b"arr_ptr\0" ); assert_eq!(foo_fields[2].offset, 2 * PTR_SIZE); - assert_eq!(foo_fields[2].num_offset, 0); + assert_eq!(foo_fields[2].num_indirect.size, 0); assert_eq!(foo_fields[2].info, unsafe { &vmstate_info_uint8 }); assert_eq!(foo_fields[2].version_id, 0); assert_eq!(foo_fields[2].size, PTR_SIZE); @@ -391,7 +391,7 @@ fn test_vmstate_macro_array_of_pointer_wrapped() { b"arr_ptr_wrap\0" ); assert_eq!(foo_fields[3].offset, (FOO_ARRAY_MAX + 2) * PTR_SIZE); - assert_eq!(foo_fields[3].num_offset, 0); + assert_eq!(foo_fields[3].num_indirect.size, 0); assert_eq!(foo_fields[3].info, unsafe { &vmstate_info_uint8 }); assert_eq!(foo_fields[3].version_id, 0); assert_eq!(foo_fields[3].size, PTR_SIZE); @@ -454,7 +454,7 @@ fn test_vmstate_validate() { b"foo_d_0\0" ); assert_eq!(foo_fields[0].offset, 0); - assert_eq!(foo_fields[0].num_offset, 0); + assert_eq!(foo_fields[0].num_indirect.size, 0); assert!(foo_fields[0].info.is_null()); assert_eq!(foo_fields[0].version_id, 0); assert_eq!(foo_fields[0].size, 0); --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932935; cv=none; d=zohomail.com; s=zohoarc; b=H8wOz+cn1E1I13OpWbRmnbNN9AjMjNOaEfqTCIYAr0Q/e8LNzdIVqol76d7K1bXB6a81DS5JJoWSqTy5PMA1VCP74n56qWHpCHPnDUhXJv68IpWSRWNl23wfs4ihQJ48HYQ4P/wecn08FT87rIYL4ybt2PpL2mmvTM5T/NVtcqs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932935; 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=9CGMzKgiCaGJQlCtdCNGvdm4/2JYGs55nekWuJYNlX0=; b=n52VKO2n4txUB+RtCEHH77V6py0YZWI136eBg0Dohh4f7L5lSkAUFfFuUH6wExYDMvEayVDzZoHRxCcogZT5A5p9E6pg/yQU8LBVA6gnfiOnaA+2O2dD+vzHBvDotdIHUMt8XcjRS8LjI/d1reUEjfZISUjLMiKoLk8VjZ9Jo7s= 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 1787932935009112.44417137300377; Fri, 28 Aug 2026 09:02:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyza-0001dk-Vd; Fri, 28 Aug 2026 11:59:47 -0400 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 1wzyzZ-0001dM-Tm for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:45 -0400 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 1wzyzP-0008WE-Bs for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:45 -0400 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 9DBCE22292; Fri, 28 Aug 2026 15:59:21 +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 C19F813674; Fri, 28 Aug 2026 15:59:20 +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 KIxPJFiwkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932765; 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=9CGMzKgiCaGJQlCtdCNGvdm4/2JYGs55nekWuJYNlX0=; b=HDA06hONa5q7THCXUACMpbVjaAhgIRrme/X/BzpwlmRuiYpIDLvFLstCs6QLzqJIvWaUnW 1VBsDK5lLLDnm6qJDuxnShLpDlWDh5y/XPri1fPve6rb2KOhNkryViEojchOgzSBbq1wWg P2F88qVmovX9ChgJ5TKZOKf///6fhV0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932765; 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=9CGMzKgiCaGJQlCtdCNGvdm4/2JYGs55nekWuJYNlX0=; b=BsCVUw3CXnBRU2WXf2CwAyBHvPkkQ+B2SvTcZazDzm8k3nELG6xImm+vvas5TFAZVuFhRs S9rEaU6LyOyd4GAA== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932761; 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=9CGMzKgiCaGJQlCtdCNGvdm4/2JYGs55nekWuJYNlX0=; b=p8RmdoiF9dR7c2euHblsI2KMOqg+7J1qhCXS89w9/mX6itW6oy0zfQpSWCWoDIWzJICnLN qRhO2WBbsRfDCfS0QZ3PuBy6EbTVdBkoEq4g80tgIs/1TOgpFkiVfB6+I033NeN3/X6XtD 2rU+EaA3ZqX4rSIgIhmXLGRBMnki3kA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932761; 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=9CGMzKgiCaGJQlCtdCNGvdm4/2JYGs55nekWuJYNlX0=; b=cGqst96ayBSPW/7LGB6WguZdOszd00U09nVUfTt87TleknvVohSEzhjBHlEbtGck+O3MQG jLKmXAANEmo5jcDg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu Subject: [PULL v2 24/30] migration: Remove redundant flags Date: Fri, 28 Aug 2026 12:58:39 -0300 Message-ID: <20260828155845.2874508-25-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.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.997]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_TWO(0.00)[2]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(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)[imap1.dmz-prg2.suse.org:helo,suse.de:email,suse.de:mid]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] 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) (identity @suse.de) X-ZM-MESSAGEID: 1787932936085158500 Content-Type: text/plain; charset="utf-8" Remove the VMS_VARRAY and VMS_VBUFFER flags that became redundant due to the previous commit which stores the size of the vmstate offset variables along with the offset itself. Acked-by: Peter Xu Signed-off-by: Fabiano Rosas --- include/migration/vmstate.h | 74 +++++++++++------------------- migration/savevm.c | 6 +-- migration/vmstate.c | 3 +- rust/bindings/migration-sys/lib.rs | 7 +-- rust/migration/src/vmstate.rs | 6 +-- rust/tests/tests/vmstate_tests.rs | 4 +- 6 files changed, 37 insertions(+), 63 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 12bfa64fb92..a168651a062 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -69,8 +69,9 @@ enum VMStateFlags { * }). Dereference the pointer before using it as basis for * further pointer arithmetic (see e.g. VMS_ARRAY). Does not * affect the meaning of VMStateField.num_indirect or - * VMStateField.size_indirect; see VMS_VARRAY* and VMS_VBUFFER for - * those. */ + * VMStateField.size_indirect; see VMS_VARRAY and VMS_VBUFFER for + * those. + */ VMS_POINTER =3D 0x002, =20 /* The field is an array of fixed size. VMStateField.num contains @@ -80,12 +81,13 @@ enum VMStateFlags { * VMS_MULTIPLY. Each array entry will be processed individually * (VMStateField.info.get()/put() if VMS_STRUCT is not set, * recursion into VMStateField.vmsd if VMS_STRUCT is set). May not - * be combined with VMS_VARRAY*. */ + * be combined with VMS_VARRAY. + */ VMS_ARRAY =3D 0x004, =20 /* The field is itself a struct, containing one or more * fields. Recurse into VMStateField.vmsd. Most useful in - * combination with VMS_ARRAY / VMS_VARRAY*, recursing into each + * combination with VMS_ARRAY / VMS_VARRAY, recursing into each * array entry. */ VMS_STRUCT =3D 0x008, =20 @@ -93,9 +95,9 @@ enum VMStateFlags { * The field is an array of variable size. The integer at opaque + * VMStateField.num_indirect contains the number of entries in the * array. See the VMS_ARRAY description regarding array handling - * in general. May not be combined with VMS_ARRAY or any other - * VMS_VARRAY*. */ - VMS_VARRAY_INT32 =3D 0x010, + * in general. May not be combined with VMS_ARRAY. + */ + VMS_VARRAY =3D 0x010, =20 /* Ignored */ VMS_BUFFER =3D 0x020, @@ -103,18 +105,12 @@ enum VMStateFlags { /* The field is a (fixed-size or variable-size) array of pointers * (e.g. struct a { uint8_t *b[]; }). Dereference each array entry * before using it. Note: Does not imply any one of VMS_ARRAY / - * VMS_VARRAY*; these need to be set explicitly. */ + * VMS_VARRAY; these need to be set explicitly. + */ VMS_ARRAY_OF_POINTER =3D 0x040, =20 - /* The field is an array of variable size. The uint16_t at opaque - * + VMStateField.num_indirect - * contains the number of entries in the array. See the VMS_ARRAY - * description regarding array handling in general. May not be - * combined with VMS_ARRAY or any other VMS_VARRAY*. */ - VMS_VARRAY_UINT16 =3D 0x080, - /* The size of the individual entries (a single array entry if - * VMS_ARRAY or any of VMS_VARRAY* are set, or the field itself if + * VMS_ARRAY or VMS_VARRAY are set, or the field itself if * neither is set) is variable (i.e. not known at compile-time), * but the same for all entries. Use the integer at opaque + * VMStateField.size_indirect (subject to VMS_MULTIPLY) to determine @@ -128,20 +124,6 @@ enum VMStateFlags { * allocated. Only valid in combination with VMS_VBUFFER. */ VMS_MULTIPLY =3D 0x200, =20 - /* The field is an array of variable size. The uint8_t at opaque + - * VMStateField.num_indirect - * contains the number of entries in the array. See the VMS_ARRAY - * description regarding array handling in general. May not be - * combined with VMS_ARRAY or any other VMS_VARRAY*. */ - VMS_VARRAY_UINT8 =3D 0x400, - - /* The field is an array of variable size. The uint32_t at opaque - * + VMStateField.num_indirect - * contains the number of entries in the array. See the VMS_ARRAY - * description regarding array handling in general. May not be - * combined with VMS_ARRAY or any other VMS_VARRAY*. */ - VMS_VARRAY_UINT32 =3D 0x800, - /* Fail loading the serialised VM state if this field is missing * from the input. */ VMS_MUST_EXIST =3D 0x1000, @@ -530,7 +512,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ - .flags =3D VMS_VARRAY_INT32|VMS_POINTER, \ + .flags =3D VMS_VARRAY | VMS_POINTER, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 @@ -540,7 +522,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ - .flags =3D VMS_VARRAY_UINT32|VMS_POINTER, \ + .flags =3D VMS_VARRAY | VMS_POINTER, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 @@ -550,7 +532,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ - .flags =3D VMS_VARRAY_INT32 | VMS_POINTER | VMS_ALLOC, \ + .flags =3D VMS_VARRAY | VMS_POINTER | VMS_ALLOC, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 @@ -560,7 +542,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ - .flags =3D VMS_VARRAY_UINT32|VMS_POINTER|VMS_ALLOC, \ + .flags =3D VMS_VARRAY | VMS_POINTER | VMS_ALLOC, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 @@ -570,7 +552,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ - .flags =3D VMS_VARRAY_UINT16 | VMS_POINTER | VMS_ALLOC, \ + .flags =3D VMS_VARRAY | VMS_POINTER | VMS_ALLOC, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 @@ -580,7 +562,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ - .flags =3D VMS_VARRAY_UINT16, \ + .flags =3D VMS_VARRAY, \ .offset =3D vmstate_offset_varray(_state, _field, _type), \ } =20 @@ -659,7 +641,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .vmsd =3D &(_vmsd), \ .size =3D sizeof(_type), \ - .flags =3D VMS_POINTER | VMS_VARRAY_UINT8 | \ + .flags =3D VMS_POINTER | VMS_VARRAY | \ VMS_ARRAY_OF_POINTER | VMS_STRUCT | \ VMS_ARRAY_OF_POINTER_AUTO_ALLOC, \ .offset =3D vmstate_offset_pointer(_state, _field, _type *), \ @@ -672,7 +654,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .vmsd =3D &(_vmsd), \ .size =3D sizeof(_type), \ - .flags =3D VMS_POINTER | VMS_VARRAY_UINT32 | \ + .flags =3D VMS_POINTER | VMS_VARRAY | \ VMS_ARRAY_OF_POINTER | VMS_STRUCT | \ VMS_ARRAY_OF_POINTER_AUTO_ALLOC, \ .offset =3D vmstate_offset_pointer(_state, _field, _type *), \ @@ -683,7 +665,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .version_id =3D (_version), = \ .num_indirect =3D vmstate_field_offset(_state, _field_num), = \ .info =3D &(_info), = \ - .flags =3D VMS_VARRAY_UINT32 | VMS_ARRAY_OF_POINTER | VMS_POINTER= , \ + .flags =3D VMS_VARRAY | VMS_ARRAY_OF_POINTER | VMS_POINTER, = \ .offset =3D vmstate_offset_pointer(_state, _field, _type *), = \ } =20 @@ -727,7 +709,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .version_id =3D (_version), \ .vmsd =3D &(_vmsd), \ .size =3D sizeof(_type), \ - .flags =3D VMS_STRUCT|VMS_VARRAY_UINT8, \ + .flags =3D VMS_STRUCT | VMS_VARRAY, \ .offset =3D vmstate_offset_varray(_state, _field, _type), \ } =20 @@ -750,7 +732,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .size =3D sizeof(_type), \ .vmsd =3D &(_vmsd), \ - .flags =3D VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \ + .flags =3D VMS_POINTER | VMS_VARRAY | VMS_STRUCT, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 @@ -760,7 +742,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .size =3D sizeof(_type), \ .vmsd =3D &(_vmsd), \ - .flags =3D VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \ + .flags =3D VMS_POINTER | VMS_VARRAY | VMS_STRUCT, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 @@ -770,7 +752,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .size =3D sizeof(_type), \ .vmsd =3D &(_vmsd), \ - .flags =3D VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT, \ + .flags =3D VMS_POINTER | VMS_VARRAY | VMS_STRUCT, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 @@ -780,7 +762,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .version_id =3D (_version), \ .vmsd =3D &(_vmsd), \ .size =3D sizeof(_type), \ - .flags =3D VMS_STRUCT|VMS_VARRAY_UINT32, \ + .flags =3D VMS_STRUCT | VMS_VARRAY, \ .offset =3D vmstate_offset_varray(_state, _field, _type), \ } =20 @@ -790,7 +772,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .vmsd =3D &(_vmsd), \ .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .size =3D sizeof(_type), \ - .flags =3D VMS_STRUCT|VMS_VARRAY_INT32|VMS_ALLOC|VMS_POINTER, \ + .flags =3D VMS_STRUCT | VMS_VARRAY | VMS_ALLOC | VMS_POINTER, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 @@ -915,7 +897,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .version_id =3D (_version), \ .size =3D (_size), \ .info =3D &vmstate_info_unused_buffer, \ - .flags =3D VMS_VARRAY_UINT32 | VMS_BUFFER, \ + .flags =3D VMS_VARRAY | VMS_BUFFER, \ } =20 /* _field_size should be a int32_t field in the _state struct giving the diff --git a/migration/savevm.c b/migration/savevm.c index 16b049c4539..ba705c941aa 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -884,11 +884,9 @@ static void vmstate_check(const VMStateDescription *vm= sd) } /* * VMS_ARRAY_OF_POINTER must be used only together with one - * of VMS_(V)ARRAY* flags. + * of VMS_(V)ARRAY flags. */ - assert(field->flags & (VMS_ARRAY | VMS_VARRAY_INT32 | - VMS_VARRAY_UINT16 | VMS_VARRAY_UINT= 8 | - VMS_VARRAY_UINT32)); + assert(field->flags & (VMS_ARRAY | VMS_VARRAY)); } =20 if (field->flags & VMS_ARRAY_OF_POINTER_AUTO_ALLOC) { diff --git a/migration/vmstate.c b/migration/vmstate.c index 9f49abda245..9556030f89a 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -114,8 +114,7 @@ static uint64_t vmstate_n_elems(void *opaque, const VMS= tateField *field) =20 if (field->flags & VMS_ARRAY) { n_elems =3D field->num; - } else if (field->flags & (VMS_VARRAY_INT32 | VMS_VARRAY_UINT32 - | VMS_VARRAY_UINT16 | VMS_VARRAY_UINT8)) { + } else if (field->flags & VMS_VARRAY) { n_elems =3D vmstate_read_from_offset(&field->num_indirect, opaque); } =20 diff --git a/rust/bindings/migration-sys/lib.rs b/rust/bindings/migration-s= ys/lib.rs index baa2730ca9d..c8397dc8974 100644 --- a/rust/bindings/migration-sys/lib.rs +++ b/rust/bindings/migration-sys/lib.rs @@ -57,12 +57,7 @@ pub trait VMStateFlagsExt { } =20 impl VMStateFlagsExt for VMStateFlags { - const VMS_VARRAY_FLAGS: VMStateFlags =3D VMStateFlags( - VMStateFlags::VMS_VARRAY_INT32.0 - | VMStateFlags::VMS_VARRAY_UINT8.0 - | VMStateFlags::VMS_VARRAY_UINT16.0 - | VMStateFlags::VMS_VARRAY_UINT32.0, - ); + const VMS_VARRAY_FLAGS: VMStateFlags =3D VMStateFlags(VMStateFlags::VM= S_VARRAY.0); } =20 // Add a couple builder-style methods to VMStateField, allowing diff --git a/rust/migration/src/vmstate.rs b/rust/migration/src/vmstate.rs index 48d0065139a..45c0b52738b 100644 --- a/rust/migration/src/vmstate.rs +++ b/rust/migration/src/vmstate.rs @@ -250,9 +250,9 @@ unsafe impl $crate::vmstate::VMState for $type { impl_vmstate_scalar!(vmstate_info_int16, i16); impl_vmstate_scalar!(vmstate_info_int32, i32); impl_vmstate_scalar!(vmstate_info_int64, i64); -impl_vmstate_scalar!(vmstate_info_uint8, u8, VMS_VARRAY_UINT8); -impl_vmstate_scalar!(vmstate_info_uint16, u16, VMS_VARRAY_UINT16); -impl_vmstate_scalar!(vmstate_info_uint32, u32, VMS_VARRAY_UINT32); +impl_vmstate_scalar!(vmstate_info_uint8, u8, VMS_VARRAY); +impl_vmstate_scalar!(vmstate_info_uint16, u16, VMS_VARRAY); +impl_vmstate_scalar!(vmstate_info_uint32, u32, VMS_VARRAY); impl_vmstate_scalar!(vmstate_info_uint64, u64); impl_vmstate_scalar!(vmstate_info_timer, util::timer::Timer); =20 diff --git a/rust/tests/tests/vmstate_tests.rs b/rust/tests/tests/vmstate_t= ests.rs index c002ffb2bc4..5f6dd8ae7f1 100644 --- a/rust/tests/tests/vmstate_tests.rs +++ b/rust/tests/tests/vmstate_tests.rs @@ -113,7 +113,7 @@ fn test_vmstate_varray_uint16_unsafe() { assert_eq!(foo_fields[2].version_id, 0); assert_eq!(foo_fields[2].size, 1); assert_eq!(foo_fields[2].num, 0); - assert_eq!(foo_fields[2].flags, VMStateFlags::VMS_VARRAY_UINT16); + assert_eq!(foo_fields[2].flags, VMStateFlags::VMS_VARRAY); assert!(foo_fields[2].vmsd.is_null()); assert!(foo_fields[2].field_exists.is_none()); } @@ -222,7 +222,7 @@ fn test_vmstate_struct_varray_uint8() { assert_eq!(foo_fields[2].num, 0); assert_eq!( foo_fields[2].flags.0, - VMStateFlags::VMS_STRUCT.0 | VMStateFlags::VMS_VARRAY_UINT8.0 + VMStateFlags::VMS_STRUCT.0 | VMStateFlags::VMS_VARRAY.0 ); assert_eq!(foo_fields[2].vmsd, VMSTATE_FOOA.as_ref()); assert!(foo_fields[2].field_exists.is_none()); --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932996; cv=none; d=zohomail.com; s=zohoarc; b=EU32pBY0u9K6P7kSE9hD/k1lI3bMY1jbnj8hmCWxcMPh8ZCmckfXHnKUDK1nhj1f/olF58xZ/Nwrq0ZavkhrFx2DZHJ43Qn75nJAybNK3tMgvSaIrdKnH543rY+rnQbZy1thQvwr6UX/yZZeTsoiEm0+Qvray2zHnrLPgV0shtA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932996; 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=P+k6wT9dlIGPFseuREKh7ReD8czK6BKywdzvBqkErBQ=; b=eho3OZpEV2x7zl9N+6MPzl4DNfc9E6HzcvFAZolLr4KWTVMe82Su6ZIk4CDvaqfKGve7IC9pxFKOwvIWeFj8S7BZb/p0J5RUYaBW2gSJNpp6xzOZJXKippfXk7K12wt+92NFfPMF1qp04Vr0wRyVF23wNJfXypyIZYAE/4Zf3Y4= 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 1787932996299303.3633671158336; Fri, 28 Aug 2026 09:03:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyzd-0001ew-Lc; Fri, 28 Aug 2026 11:59:49 -0400 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 1wzyzb-0001dv-FG for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:47 -0400 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 1wzyzP-000052-Bv for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:46 -0400 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 B979122293; Fri, 28 Aug 2026 15:59:22 +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 DD52413675; Fri, 28 Aug 2026 15:59:21 +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 iB4LK1mwkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932766; 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=P+k6wT9dlIGPFseuREKh7ReD8czK6BKywdzvBqkErBQ=; b=0HK5s9V7ZT6nBSgZ9Ekxj2L0Ww569jDdHIBjbCIf+PYuXcEmGLt7UmNzcxijhXuTDCtDdN FzmZWR4itM4Acq6Y5b1MyiYSGcsXguoI8ew3y4gGfJ0TT2KTZyiDa/en5ccCW2tHZ2eEfM bsbHeVZR2TMVPiA7kp8iZzPSoCRWTFc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932766; 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=P+k6wT9dlIGPFseuREKh7ReD8czK6BKywdzvBqkErBQ=; b=hYB1qGz1MFIGlZM32s3fVHWAPL1uBlsJ1d1pQ9B4gMMBxAa4z+QSzMqeUaL8QtpdqcPUe3 Zj63HXuDuPoLR8DQ== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="1qRo2LG/"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=FKDRe+Ts DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932762; 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=P+k6wT9dlIGPFseuREKh7ReD8czK6BKywdzvBqkErBQ=; b=1qRo2LG/sVBQBjHJeWvr7SyRztNT9erct1q8AeV4zIfHH1fkSvxvnxWoAYFcBszrDc+4ev eWi1Obi2Z0qh7x9yVpk7T8gXtPdkAkKaANU93AhwWfuTDNPganF73kkEyBaV3pIqaGttop R8pW4Nf57QQbdZrc/CiUivIakQr4+Do= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932762; 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=P+k6wT9dlIGPFseuREKh7ReD8czK6BKywdzvBqkErBQ=; b=FKDRe+TsR34rtFhVbrZuBnOSg4aLjjr24UQkedpCTNll4t9q5JmNHdCndzMNE8dhZC1sIx GP2HVEinlpREMcCw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu Subject: [PULL v2 25/30] migration: Remove duplicate vmstate macros Date: Fri, 28 Aug 2026 12:58:40 -0300 Message-ID: <20260828155845.2874508-26-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.01 X-Rspamd-Queue-Id: B979122293 X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; 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)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:email,suse.de:mid,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; RCVD_TLS_ALL(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_TWO(0.00)[2]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; DKIM_TRACE(0.00)[suse.de:+] 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) (identity @suse.de) X-ZM-MESSAGEID: 1787932998539154100 Content-Type: text/plain; charset="utf-8" Now that type-checking is not being done per integer size anymore, various macros have duplicated bodies. Remove them. The original names are left the same so the device code can be altered per-subsystem in the next patches. Acked-by: Peter Xu Signed-off-by: Fabiano Rosas --- include/migration/vmstate.h | 135 ++++++++++++------------------------ 1 file changed, 44 insertions(+), 91 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index a168651a062..4b6d52955ff 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -506,7 +506,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D vmstate_offset_sub_array(_state, _field, _type, _start= ), \ } =20 -#define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, = _type) {\ +#define VMSTATE_VARRAY(_field, _state, _field_num, _version, _info, _type)= {\ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .num_indirect =3D vmstate_field_offset(_state, _field_num), \ @@ -516,17 +516,11 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 -#define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info,= _type) {\ - .name =3D (stringify(_field)), \ - .version_id =3D (_version), \ - .num_indirect =3D vmstate_field_offset(_state, _field_num), \ - .info =3D &(_info), \ - .size =3D sizeof(_type), \ - .flags =3D VMS_VARRAY | VMS_POINTER, \ - .offset =3D vmstate_offset_pointer(_state, _field, _type), \ -} +#define VMSTATE_VARRAY_INT32 VMSTATE_VARRAY +#define VMSTATE_VARRAY_UINT32 VMSTATE_VARRAY =20 -#define VMSTATE_VARRAY_INT32_ALLOC(_field, _state, _field_num, _version, _= info, _type) {\ +#define VMSTATE_VARRAY_ALLOC(_field, _state, _field_num, _version, _info, \ + _type) { \ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .num_indirect =3D vmstate_field_offset(_state, _field_num), \ @@ -536,27 +530,12 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 -#define VMSTATE_VARRAY_UINT32_ALLOC(_field, _state, _field_num, _version, = _info, _type) {\ - .name =3D (stringify(_field)), \ - .version_id =3D (_version), \ - .num_indirect =3D vmstate_field_offset(_state, _field_num), \ - .info =3D &(_info), \ - .size =3D sizeof(_type), \ - .flags =3D VMS_VARRAY | VMS_POINTER | VMS_ALLOC, \ - .offset =3D vmstate_offset_pointer(_state, _field, _type), \ -} - -#define VMSTATE_VARRAY_UINT16_ALLOC(_field, _state, _field_num, _version, = _info, _type) {\ - .name =3D (stringify(_field)), \ - .version_id =3D (_version), \ - .num_indirect =3D vmstate_field_offset(_state, _field_num), \ - .info =3D &(_info), \ - .size =3D sizeof(_type), \ - .flags =3D VMS_VARRAY | VMS_POINTER | VMS_ALLOC, \ - .offset =3D vmstate_offset_pointer(_state, _field, _type), \ -} +#define VMSTATE_VARRAY_INT32_ALLOC VMSTATE_VARRAY_ALLOC +#define VMSTATE_VARRAY_UINT32_ALLOC VMSTATE_VARRAY_ALLOC +#define VMSTATE_VARRAY_UINT16_ALLOC VMSTATE_VARRAY_ALLOC =20 -#define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version,= _info, _type) {\ +#define VMSTATE_VARRAY_UNSAFE(_field, _state, _field_num, _version, _info,= \ + _type) { \ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .num_indirect =3D vmstate_field_offset(_state, _field_num), \ @@ -566,6 +545,8 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D vmstate_offset_varray(_state, _field, _type), \ } =20 +#define VMSTATE_VARRAY_UINT16_UNSAFE VMSTATE_VARRAY_UNSAFE + #define VMSTATE_VSTRUCT_TEST(_field, _state, _test, _version, _vmsd, _type= , _struct_version) { \ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ @@ -634,7 +615,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; * _info: VMStateInfo for _type (when VMS_STRUCT is not set) * start: size of (_type) pointed to (for auto memory allocation) */ -#define VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_UINT8_ALLOC(\ +#define VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_ALLOC( \ _field, _state, _field_num, _version, _vmsd, _type) { \ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ @@ -647,20 +628,13 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D vmstate_offset_pointer(_state, _field, _type *), \ } =20 -#define VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_UINT32_ALLOC(\ - _field, _state, _field_num, _version, _vmsd, _type) { \ - .name =3D (stringify(_field)), \ - .version_id =3D (_version), \ - .num_indirect =3D vmstate_field_offset(_state, _field_num), \ - .vmsd =3D &(_vmsd), \ - .size =3D sizeof(_type), \ - .flags =3D VMS_POINTER | VMS_VARRAY | \ - VMS_ARRAY_OF_POINTER | VMS_STRUCT | \ - VMS_ARRAY_OF_POINTER_AUTO_ALLOC, \ - .offset =3D vmstate_offset_pointer(_state, _field, _type *), \ -} +#define VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_UINT8_ALLOC \ + VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_ALLOC +#define VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_UINT32_ALLOC \ + VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_ALLOC =20 -#define VMSTATE_VARRAY_OF_POINTER_UINT32(_field, _state, _field_num, _vers= ion, _info, _type) { \ +#define VMSTATE_VARRAY_OF_POINTER(_field, _state, _field_num, _version, _i= nfo, \ + _type) { \ .name =3D (stringify(_field)), = \ .version_id =3D (_version), = \ .num_indirect =3D vmstate_field_offset(_state, _field_num), = \ @@ -669,6 +643,8 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D vmstate_offset_pointer(_state, _field, _type *), = \ } =20 +#define VMSTATE_VARRAY_OF_POINTER_UINT32 VMSTATE_VARRAY_OF_POINTER + #define VMSTATE_STRUCT_SUB_ARRAY(_field, _state, _start, _num, _version, _= vmsd, _type) { \ .name =3D (stringify(_field)), = \ .version_id =3D (_version), = \ @@ -703,7 +679,8 @@ extern const VMStateInfo vmstate_info_g_byte_array; _n1, _n2), \ } =20 -#define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, = _vmsd, _type) { \ +#define VMSTATE_STRUCT_VARRAY(_field, _state, _field_num, _version, _vmsd,= \ + _type) { \ .name =3D (stringify(_field)), \ .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .version_id =3D (_version), \ @@ -712,6 +689,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .flags =3D VMS_STRUCT | VMS_VARRAY, \ .offset =3D vmstate_offset_varray(_state, _field, _type), \ } +#define VMSTATE_STRUCT_VARRAY_UINT8 VMSTATE_STRUCT_VARRAY =20 /* a variable length array (i.e. _type *_field) but we know the * length @@ -726,7 +704,8 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D offsetof(_state, _field), \ } =20 -#define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _v= msd, _type) { \ +#define VMSTATE_STRUCT_VARRAY_POINTER(_field, _state, _field_num, _vmsd, \ + _type) { \ .name =3D (stringify(_field)), \ .version_id =3D 0, \ .num_indirect =3D vmstate_field_offset(_state, _field_num), \ @@ -735,28 +714,12 @@ extern const VMStateInfo vmstate_info_g_byte_array; .flags =3D VMS_POINTER | VMS_VARRAY | VMS_STRUCT, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } +#define VMSTATE_STRUCT_VARRAY_POINTER_INT32 VMSTATE_STRUCT_VARRAY_POINTER +#define VMSTATE_STRUCT_VARRAY_POINTER_UINT32 VMSTATE_STRUCT_VARRAY_POINTER +#define VMSTATE_STRUCT_VARRAY_POINTER_UINT16 VMSTATE_STRUCT_VARRAY_POINTER =20 -#define VMSTATE_STRUCT_VARRAY_POINTER_UINT32(_field, _state, _field_num, _= vmsd, _type) { \ - .name =3D (stringify(_field)), \ - .version_id =3D 0, \ - .num_indirect =3D vmstate_field_offset(_state, _field_num), \ - .size =3D sizeof(_type), \ - .vmsd =3D &(_vmsd), \ - .flags =3D VMS_POINTER | VMS_VARRAY | VMS_STRUCT, \ - .offset =3D vmstate_offset_pointer(_state, _field, _type), \ -} - -#define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _= vmsd, _type) { \ - .name =3D (stringify(_field)), \ - .version_id =3D 0, \ - .num_indirect =3D vmstate_field_offset(_state, _field_num), \ - .size =3D sizeof(_type), \ - .vmsd =3D &(_vmsd), \ - .flags =3D VMS_POINTER | VMS_VARRAY | VMS_STRUCT, \ - .offset =3D vmstate_offset_pointer(_state, _field, _type), \ -} - -#define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version,= _vmsd, _type) { \ +#define VMSTATE_STRUCT_VARRAY(_field, _state, _field_num, _version, _vmsd,= \ + _type) { \ .name =3D (stringify(_field)), \ .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .version_id =3D (_version), \ @@ -765,8 +728,11 @@ extern const VMStateInfo vmstate_info_g_byte_array; .flags =3D VMS_STRUCT | VMS_VARRAY, \ .offset =3D vmstate_offset_varray(_state, _field, _type), \ } +#define VMSTATE_STRUCT_VARRAY_INT32 VMSTATE_STRUCT_VARRAY +#define VMSTATE_STRUCT_VARRAY_UINT32 VMSTATE_STRUCT_VARRAY =20 -#define VMSTATE_STRUCT_VARRAY_ALLOC(_field, _state, _field_num, _version, = _vmsd, _type) {\ +#define VMSTATE_STRUCT_VARRAY_ALLOC(_field, _state, _field_num, _version, \ + _vmsd, _type) { \ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .vmsd =3D &(_vmsd), \ @@ -808,28 +774,11 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D offsetof(_state, _field), \ } =20 -#define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _field_siz= e) { \ - .name =3D (stringify(_field)), \ - .version_id =3D (_version), \ - .field_exists =3D (_test), \ - .size_indirect =3D vmstate_field_offset(_state, _field_size), \ - .info =3D &vmstate_info_buffer, \ - .flags =3D VMS_VBUFFER|VMS_POINTER, \ - .offset =3D offsetof(_state, _field), \ -} +#define VMSTATE_VBUFFER_UINT32 VMSTATE_VBUFFER +#define VMSTATE_VBUFFER_UINT64 VMSTATE_VBUFFER =20 -#define VMSTATE_VBUFFER_UINT64(_field, _state, _version, _test, _field_siz= e) { \ - .name =3D (stringify(_field)), \ - .version_id =3D (_version), \ - .field_exists =3D (_test), \ - .size_indirect =3D vmstate_field_offset(_state, _field_size), \ - .info =3D &vmstate_info_buffer, \ - .flags =3D VMS_VBUFFER | VMS_POINTER, \ - .offset =3D offsetof(_state, _field), \ -} - -#define VMSTATE_VBUFFER_ALLOC_UINT32(_field, _state, _version, \ - _test, _field_size) { \ +#define VMSTATE_VBUFFER_ALLOC(_field, _state, _version, \ + _test, _field_size) { \ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .field_exists =3D (_test), \ @@ -839,6 +788,8 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D offsetof(_state, _field), \ } =20 +#define VMSTATE_VBUFFER_ALLOC_UINT32 VMSTATE_VBUFFER_ALLOC + #define VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, _test, _version, _= info, _size) { \ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ @@ -890,7 +841,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; } =20 /* Discard size * field_num bytes, where field_num is a uint32 member */ -#define VMSTATE_UNUSED_VARRAY_UINT32(_state, _test, _version, _field_num, = _size) {\ +#define VMSTATE_UNUSED_VARRAY(_state, _test, _version, _field_num, _size) = {\ .name =3D "unused", \ .field_exists =3D (_test), \ .num_indirect =3D vmstate_field_offset(_state, _field_num), \ @@ -900,6 +851,8 @@ extern const VMStateInfo vmstate_info_g_byte_array; .flags =3D VMS_VARRAY | VMS_BUFFER, \ } =20 +#define VMSTATE_UNUSED_VARRAY_UINT32 VMSTATE_UNUSED_VARRAY + /* _field_size should be a int32_t field in the _state struct giving the * size of the bitmap _field in bits. */ --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932946; cv=none; d=zohomail.com; s=zohoarc; b=K03Fjg+RKeLCp1C+uklkwO+QMnafK6Y6b+BWQmBEKPlU0VIFqsIcAjHaU2S+icigd4dcBvS3Fy2s8zgYd1TxUx+k9JgLeL8j4icI6yj5E5vXD0/3u6UUaHtFS+7b70EcAFkSLaQADH3eT1DZ507Ro7AaS36xo2UrKySDN/Z8kvI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932946; 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=B/N1rpvSH2J+ABVOD57pS63ckjmMEBDdVOy+xtaMIsE=; b=aY7Go5vieJ4NvCJ8gTsC+g7FIf482VorI1V5l483f+9iLZPpNxVkvLepoeAPTP3I7ALAlJIKtbimcl9O6PKUAcZ/q1mcgNsdFOqUXzpMg3JURbBooZ5tBaVAMBIL8dC2g4A+CBO8OCtiw7V03cyVT29h9R4Kfm5UPgB+sIQnDMA= 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 1787932946254868.5935140710681; Fri, 28 Aug 2026 09:02:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyzc-0001ei-TG; Fri, 28 Aug 2026 11:59:48 -0400 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 1wzyzb-0001dw-G9 for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:47 -0400 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wzyzP-00005d-EY for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:46 -0400 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-out2.suse.de (Postfix) with ESMTPS id D9AF81FD8A; Fri, 28 Aug 2026 15:59:23 +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 0434A13694; Fri, 28 Aug 2026 15:59:22 +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 CLmoMVqwkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932768; 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=B/N1rpvSH2J+ABVOD57pS63ckjmMEBDdVOy+xtaMIsE=; b=E3xUfCMdsIzQoQTIzj5z2EiuPxUMNvTECwfJK8Xp/hw4fFl1JO5WHNPHi7ofUFqMUwZL8w kgyYmU6daBTHgUkhOMlCNXOMkxV21ls51j58XKKbmaT76Qu94n7zdI4trsvh9MRAOtnHse U85a9ZocjUe5Q7cqN02kSxc1IngcAuw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932768; 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=B/N1rpvSH2J+ABVOD57pS63ckjmMEBDdVOy+xtaMIsE=; b=3O53QKxL5RoVaQJMREUcm69r1cok3GZIeeKpS/mX89Hd0G+8pL3XB2OEosFBcWhygXisT9 aznzrR3GE3Olc8Cg== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=SMeR6yfw; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=d6V75AIr DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932763; 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=B/N1rpvSH2J+ABVOD57pS63ckjmMEBDdVOy+xtaMIsE=; b=SMeR6yfwjSTJBz6vabe853yIvQ3O4lTu5vcm4QGGX/ZsU+9fiYXEW9CRS+m0hvsF14aUxw MTbT+rrwYzzKfO4lZT7TVIDZbBsrKC0ta56eTOxxCdy/jDq8e9LQDaJuD5HEvE1Kz1S8xz +AtNoAMJww+I/1b7+2SahNMPQtORALA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932763; 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=B/N1rpvSH2J+ABVOD57pS63ckjmMEBDdVOy+xtaMIsE=; b=d6V75AIrUVycCyMQFUK0s+4QMjudoS6qvcHwKBYYWXG4Apf5go8U7DG+d2I6wV16h3jdLt zk3Gsn39I3NSqhAw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu Subject: [PULL v2 26/30] migration: Add VMS_NO_STATE flag Date: Fri, 28 Aug 2026 12:58:41 -0300 Message-ID: <20260828155845.2874508-27-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.01 X-Rspamd-Queue-Id: D9AF81FD8A X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; 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)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:dkim,suse.de:email,suse.de:mid]; RCVD_TLS_ALL(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_TWO(0.00)[2]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; DKIM_TRACE(0.00)[suse.de:+] 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=195.135.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, 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: 1787932947751154100 Content-Type: text/plain; charset="utf-8" There are a few special cases of vmstate usage: The vmstate_msix and vmstate_scsi_device have fields that contain no data, only a vmstate_info structure. The VMSTATE_VALIDATE macro serves only to invoke the .field_exists routine for validation. Regardless whether these scenarios are valid, add a separate flag to identify them so we can enforce common constraints for the normal vmstates such as having a size greater than zero. Note that n_elems is hardcoded to 1 for all vmstates, except VMS_[V]ARRAY, so VMSTATE_VALIDATE needed to set VMS_ARRAY to be able to force n_elems to 0. This patch now checks the flag at vmstate_n_elems(). Acked-by: Peter Xu Signed-off-by: Fabiano Rosas --- hw/pci/msix.c | 6 +----- hw/scsi/scsi-bus.c | 6 +----- include/migration/vmstate.h | 9 +++++++-- migration/vmstate.c | 6 +++++- rust/migration/src/vmstate.rs | 2 +- rust/tests/tests/vmstate_tests.rs | 2 +- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/hw/pci/msix.c b/hw/pci/msix.c index 1b23eaf1007..adf76b5bccc 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -711,12 +711,8 @@ const VMStateDescription vmstate_msix =3D { .fields =3D (const VMStateField[]) { { .name =3D "msix", - .version_id =3D 0, - .field_exists =3D NULL, - .size =3D 0, /* ouch */ .info =3D &vmstate_info_msix, - .flags =3D VMS_SINGLE, - .offset =3D 0, + .flags =3D VMS_SINGLE | VMS_NO_STATE, }, VMSTATE_END_OF_LIST() } diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index deb43d5560e..aa02ff631b7 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -1980,12 +1980,8 @@ const VMStateDescription vmstate_scsi_device =3D { VMSTATE_UINT32(sense_len, SCSIDevice), { .name =3D "requests", - .version_id =3D 0, - .field_exists =3D NULL, - .size =3D 0, /* ouch */ .info =3D &vmstate_info_scsi_requests, - .flags =3D VMS_SINGLE, - .offset =3D 0, + .flags =3D VMS_SINGLE | VMS_NO_STATE, }, VMSTATE_END_OF_LIST() }, diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 4b6d52955ff..e72c3fae9a6 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -109,6 +109,12 @@ enum VMStateFlags { */ VMS_ARRAY_OF_POINTER =3D 0x040, =20 + /* + * The field contains no data. Used for special cases such as + * invoking a custom VMStateInfo. + */ + VMS_NO_STATE =3D 0x080, + /* The size of the individual entries (a single array entry if * VMS_ARRAY or VMS_VARRAY are set, or the field itself if * neither is set) is variable (i.e. not known at compile-time), @@ -454,8 +460,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_VALIDATE(_name, _test) { \ .name =3D (_name), \ .field_exists =3D (_test), \ - .flags =3D VMS_ARRAY | VMS_MUST_EXIST, \ - .num =3D 0, /* 0 elements: no data, only run _test */ \ + .flags =3D VMS_MUST_EXIST | VMS_NO_STATE, \ } =20 #define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \ diff --git a/migration/vmstate.c b/migration/vmstate.c index 9556030f89a..1f9cb45923f 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -110,12 +110,16 @@ static uint64_t vmstate_read_from_offset(const VMStat= eStructMember *member, =20 static uint64_t vmstate_n_elems(void *opaque, const VMStateField *field) { - uint64_t n_elems =3D 1; + uint64_t n_elems; =20 if (field->flags & VMS_ARRAY) { n_elems =3D field->num; } else if (field->flags & VMS_VARRAY) { n_elems =3D vmstate_read_from_offset(&field->num_indirect, opaque); + } else if (field->flags & VMS_MUST_EXIST && field->flags & VMS_NO_STAT= E) { + n_elems =3D 0; + } else { + n_elems =3D 1; } =20 trace_vmstate_n_elems(field->name, n_elems); diff --git a/rust/migration/src/vmstate.rs b/rust/migration/src/vmstate.rs index 45c0b52738b..5ed061f2abb 100644 --- a/rust/migration/src/vmstate.rs +++ b/rust/migration/src/vmstate.rs @@ -381,7 +381,7 @@ macro_rules! vmstate_validate { field_exists: $crate::vmstate_exist_fn!($struct_name, $test_fn= ), flags: $crate::bindings::VMStateFlags( $crate::bindings::VMStateFlags::VMS_MUST_EXIST.0 - | $crate::bindings::VMStateFlags::VMS_ARRAY.0, + | $crate::bindings::VMStateFlags::VMS_NO_STATE.0, ), num: 0, // 0 elements: no data, only run test_fn callback ..::common::zeroable::Zeroable::ZERO diff --git a/rust/tests/tests/vmstate_tests.rs b/rust/tests/tests/vmstate_t= ests.rs index 5f6dd8ae7f1..6578d54b37d 100644 --- a/rust/tests/tests/vmstate_tests.rs +++ b/rust/tests/tests/vmstate_tests.rs @@ -461,7 +461,7 @@ fn test_vmstate_validate() { assert_eq!(foo_fields[0].num, 0); assert_eq!( foo_fields[0].flags.0, - VMStateFlags::VMS_ARRAY.0 | VMStateFlags::VMS_MUST_EXIST.0 + VMStateFlags::VMS_NO_STATE.0 | VMStateFlags::VMS_MUST_EXIST.0 ); assert!(foo_fields[0].vmsd.is_null()); assert!(unsafe { foo_fields[0].field_exists.unwrap()(foo_d_p, 0) }); --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932943; cv=none; d=zohomail.com; s=zohoarc; b=U3/oPrNtqn2efpbdAiIJcsp840iJtO5919T0WsrgKwqI8zGJEkaTWTF/GKikJi5PT18aHlDym6C/Yyh070vDQttZK2vyLNLAZh3r6aQmmN1UZUKxqGtQCol7hUCl/YgP6K3xrOoUrc/zy4nuOMmnq2gEMvEK7fLkc8ydv7UDRlk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932943; 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=8tuHdlGGPQPD+UD6SrlaKWBfSOvo8qV7InxoVIfCWkY=; b=Clmcz4CNySgkZdyiXLj6APZVsF4XX9shV/sfIz592kOnoQx1dlvOZXTgOWzmltf540cVLfLk+44G2VzcdUqUUHE4KlXqqAtJ1GD6nfdoxyTJ7O3PnbYXpI/8PULzBquaZCLqr1gK7fHO9dRABuoy0fM3XuHwZcSXXB8eMrux1Ao= 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 1787932943486865.0353957442977; Fri, 28 Aug 2026 09:02:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyzX-0001cW-Q5; Fri, 28 Aug 2026 11:59:43 -0400 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 1wzyzW-0001c1-Sc for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:42 -0400 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 1wzyzP-00006V-CR for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:42 -0400 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 13A672229A; Fri, 28 Aug 2026 15:59:25 +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 20AAF13687; Fri, 28 Aug 2026 15:59:23 +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 MJOfOFuwkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932769; 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=8tuHdlGGPQPD+UD6SrlaKWBfSOvo8qV7InxoVIfCWkY=; b=bSlBK6pG/Rm8W6xwjR3wrozx5glA7d0tAAJXa1B7fVjWlHq6qX3UYNoZsi38sbF5qiMJwk SDtR8bAqmc6ZUIJIv3R+1bCyUFOUV59Ouiumv7/wEgfbLXyeAElYuU5l1uEl14DLXa18ch ZGiy9PM3mOcu6H+Rxc9V9p+/qvDlLIM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932769; 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=8tuHdlGGPQPD+UD6SrlaKWBfSOvo8qV7InxoVIfCWkY=; b=BwEKlopgSq1gOf3j/1o1WF96ZXVQgKYxlZNSL+DKlEunK2ioaD04zgiJ5QgAhG2rzATNjl WZ+pcU55pemeMTDw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932765; 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=8tuHdlGGPQPD+UD6SrlaKWBfSOvo8qV7InxoVIfCWkY=; b=oqsPiWzataUjyicl5EnjBN23XJV19wF8D72Y2OZg0m04zeYaqNlsrPnGGBzjfE58uXpjMB Y1OCnS/Ovukue/ywU36J2zVKVcG40k4DnB8oqLv157SA4vmQ4FIHnT30C8cPHtcXnbii5W qSBNzemLNVQ4jE7kPshLZ4HaBtsIAhU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932765; 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=8tuHdlGGPQPD+UD6SrlaKWBfSOvo8qV7InxoVIfCWkY=; b=yw0/X495X9ZcpuALbElVu1tIlYxxQZp/veu52heUgItX5QoMJjA/i2r+LKbsCp0nYpZaY9 DoCQBQDdE8qR9mCw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu Subject: [PULL v2 27/30] migration: Check more vmstate flags Date: Fri, 28 Aug 2026 12:58:42 -0300 Message-ID: <20260828155845.2874508-28-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.997]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_TWO(0.00)[2]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(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,suse.de:mid,imap1.dmz-prg2.suse.org:helo]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] 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) (identity @suse.de) X-ZM-MESSAGEID: 1787932944015158500 Content-Type: text/plain; charset="utf-8" Add more checks for vmstate flags constraints. Acked-by: Peter Xu Signed-off-by: Fabiano Rosas --- migration/savevm.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/migration/savevm.c b/migration/savevm.c index ba705c941aa..5b0e89ca7c8 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -893,6 +893,25 @@ static void vmstate_check(const VMStateDescription *vm= sd) assert(field->flags & VMS_ARRAY_OF_POINTER); } =20 + /* + * The VMS*ARRAY flags and VMS_VBUFFER affect allocation, + * they must have the proper fields set and no other + * vmstate types can set those fields, otherwise it won't + * be picked-up due to the missing flag. + */ + + if (field->flags & (VMS_ARRAY | VMS_VARRAY)) { + assert(field->num > 0 || field->num_indirect.size !=3D 0); + } else { + assert(field->num =3D=3D 0 && field->num_indirect.size =3D= =3D 0); + } + + if (field->flags & VMS_VBUFFER) { + assert(field->size_indirect.size !=3D 0); + } else { + assert(field->size_indirect.size =3D=3D 0); + } + if (field->flags & (VMS_STRUCT | VMS_VSTRUCT)) { /* Recurse to sub structures */ vmstate_check(field->vmsd); --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932906; cv=none; d=zohomail.com; s=zohoarc; b=fc5DhdF901xU/Xw6ig636ftxRr1n7eALF2L8PE8sVadIZcXdxzrkZPFZGMaQ3SsfZHCzb1he11hdB5w+fGqCjHzS24XNcg57/mV6kNDFBhZtQUbSdH1zLlq357iHN4rf2CdZZXwt+l950SpEyooFwtcQdMr2OLvRQuCssJSYY1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932906; 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=B8dF9OUUnpcySr+t0ld6YPJiSh8RGUF8V5AdKubVuxg=; b=eMLBfmu4NPCFeIcHEC5V0hJoFeP86awcTOyrIKvc4OlgoVNpJbkYmrsAJy1O2jrtZn9J+JpUOwfsAkwlsDMD8m9uh7YPQaKgf4gghuwWpZ2cSvOzInWTXcX5cXQeU1GkLiJfqNBrb5/UFxDnna4QpTxeHtBKjZHqWZ9UhUocjRc= 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 178793290672454.33853923996469; Fri, 28 Aug 2026 09:01:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyze-0001fQ-JC; Fri, 28 Aug 2026 11:59:50 -0400 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 1wzyzc-0001eU-8i for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:48 -0400 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 1wzyzQ-00006l-7a for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:47 -0400 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 186411FE00; Fri, 28 Aug 2026 15:59:26 +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 3B9251368F; Fri, 28 Aug 2026 15:59:25 +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 EEOQA12wkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932770; 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=B8dF9OUUnpcySr+t0ld6YPJiSh8RGUF8V5AdKubVuxg=; b=M2PvzOpXs6aBwsRDGJ/0XJRLiQwFHoGg7eVUPTLi0Iex5rJ7H3aZyUEhrhjc8hfVzm7dyQ /R+3y75bUV0eFip+rNyCxnr3WqFXAYhr+OAMM59VL3V15Hka3ml9m/YsBtn9SsISbfPRiZ FXw4GY8LMieyA86qbeAucQEUDVm26R8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932770; 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=B8dF9OUUnpcySr+t0ld6YPJiSh8RGUF8V5AdKubVuxg=; b=4WR2X4RSKT6JVjVMynWGzXjgW/wquN2PZZxk+dEeR983LZ8LW8CucYh5UbM+TVcks2YA2s KtJJ86dIzfRgTWCA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932766; 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=B8dF9OUUnpcySr+t0ld6YPJiSh8RGUF8V5AdKubVuxg=; b=wUrD/z0EIL6mT1N695HgPmR8ucMYlbzDpFBgTG7jn2y7pV1bM0B3qWPw/0zXky19YrswgI OpwYqL6shRggUmSWSSQCmx3q8XKZmRbfpnFLkIsKoRcFCdXG0pDNJFs7+FhuXC91E9OlOg 9X1jeLiXLskw7Cr8MaPsm5Yxu4mZlPE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932766; 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=B8dF9OUUnpcySr+t0ld6YPJiSh8RGUF8V5AdKubVuxg=; b=ZoaKgWgi/IdHuJTDtnTmsJZyHRM8yostB8ALi/9Pb4ow3dk8y5XAJBMsCce9fxtojxh/hO jQ7ouZSoMY2JH4DQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu Subject: [PULL v2 28/30] migration: Harden vmstate_handle_alloc Date: Fri, 28 Aug 2026 12:58:43 -0300 Message-ID: <20260828155845.2874508-29-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.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.997]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_TWO(0.00)[2]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(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)[imap1.dmz-prg2.suse.org:helo,suse.de:mid,suse.de:email]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] 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: 1787932909009154100 Content-Type: text/plain; charset="utf-8" Harden the vmstate_handle_alloc function against overflow of the 64bit integers it consumes and failure to allocate due to an exceedingly large request. Acked-by: Peter Xu Signed-off-by: Fabiano Rosas --- migration/vmstate.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/migration/vmstate.c b/migration/vmstate.c index 1f9cb45923f..cbcd86e5b60 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -148,16 +148,28 @@ static uint64_t vmstate_size(void *opaque, const VMSt= ateField *field) return size; } =20 -static void vmstate_handle_alloc(void *ptr, const VMStateField *field, - void *opaque) +static bool vmstate_handle_alloc(void *ptr, const VMStateField *field, + uint64_t n, uint64_t size, Error **errp) { + void *p; + if (field->flags & VMS_POINTER && field->flags & VMS_ALLOC) { - uint64_t size =3D vmstate_size(opaque, field); - size *=3D vmstate_n_elems(opaque, field); - if (size) { - *(void **)ptr =3D g_malloc(size); - } + if (size && n) { + if (umul64_overflow(size, n, &size)) { + error_setg(errp, "%s: field '%s' multiply overflow", + __func__, field->name); + return false; + } + p =3D g_try_malloc(size); + if (!p) { + error_setg(errp, "%s: Could not allocate memory for field = '%s'", + __func__, field->name); + return false; + } + *(void **)ptr =3D p; + } } + return true; } =20 static bool vmstate_ptr_marker_load(QEMUFile *f, bool *load_field, @@ -367,7 +379,9 @@ bool vmstate_load_vmsd(QEMUFile *f, const VMStateDescri= ption *vmsd, uint64_t n_elems =3D vmstate_n_elems(opaque, field); uint64_t size =3D vmstate_size(opaque, field); =20 - vmstate_handle_alloc(first_elem, field, opaque); + if (!vmstate_handle_alloc(first_elem, field, n_elems, size, er= rp)) { + return false; + } if (field->flags & VMS_POINTER) { first_elem =3D *(void **)first_elem; assert(first_elem || !n_elems || !size); --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932854; cv=none; d=zohomail.com; s=zohoarc; b=E95M6kWivw0nexge7fzk8I0Q9JBl6TuZNcsY45WVji0BjS4z3fNSe0DEL7Oet4P4jrmJXpMNiPUIkPFbMqbhideAVpOHusuj/bN5d6Swc/9Vyf3n9E1pUjglIOVEyIFvemAXNrML95Sx/WaWEdzpaNuGh1XxBQ/9UwTiEYmoSGE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932854; 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=FIK1YdOSs5HZro7/pz7DahbSMBMAf6939e28pmFTaCw=; b=bwbyKL3k+zM3zoH8BCMuo34yIGn43bolNAR68WuYmt8MzXs9cXyNv2M5daW7P6BQayOMg13xlsDhPuV0Qrb6stL92iZ0RbeJ1nmb+3ihgL+mkocPJ5tJxWKoCj+PRGrXsbHLAjNX+RUbLcoXKd66JCAW0v3CPrAeSGb7hdRO7K8= 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 1787932854076373.9449133328752; Fri, 28 Aug 2026 09:00:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyze-0001fP-EY; Fri, 28 Aug 2026 11:59:50 -0400 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 1wzyzd-0001ev-Ka for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:49 -0400 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 1wzyzR-00007u-0x for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:49 -0400 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-out2.suse.de (Postfix) with ESMTPS id 331721FDDF; Fri, 28 Aug 2026 15:59:27 +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 5745D13688; Fri, 28 Aug 2026 15:59:26 +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 EERRCl6wkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932771; 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=FIK1YdOSs5HZro7/pz7DahbSMBMAf6939e28pmFTaCw=; b=tZnZf1wk0tugEGKB4mgPysx8oypqrGVe/Xpq6egJLYzCvXD0zBbCIQjry4P9jooxmC2ron 2IYyCFSeYMyUcMjO9b1V2cNGPk7sEl6UEXSTj3hFU0UZYhzvuqZM+G8AXKjiRaIua66yPl dik4ZShCM588w4OXgNeuQxAzEzlrRe8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932771; 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=FIK1YdOSs5HZro7/pz7DahbSMBMAf6939e28pmFTaCw=; b=ypQE+6p0GOqyk6chKu9Lz+EfFZbjIGNa6aVu751cUwh36kn9EQNp+oZm5mqS7j4gTGWQnb GEhzeKXJ3rlYdZBA== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=hRr+aA+h; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=wz2u54u9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932767; 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=FIK1YdOSs5HZro7/pz7DahbSMBMAf6939e28pmFTaCw=; b=hRr+aA+hUlVciUpz8SvMF0QG78j6I5+RBk67979JodfHth41EaTBYPf9lGZg0y2EUCouEA DKtUrUyONm8EZfoSlksHmbxuSaBDxorUmjoQvk/aWl/fY/wJJL+tWYLtt/lIVkhRaHn3k3 OacfbeS670C1HNrjiczBeIn/fPGEapM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932767; 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=FIK1YdOSs5HZro7/pz7DahbSMBMAf6939e28pmFTaCw=; b=wz2u54u9BoG4vVMg8X+tb0hiPutEXjwndauzuIeUQd9bF89xs8W9C5kwzo0Ib0fYEuLUBk B1HB22UqWU5NvKDg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu Subject: [PULL v2 29/30] migration: Harden vmstate_size Date: Fri, 28 Aug 2026 12:58:44 -0300 Message-ID: <20260828155845.2874508-30-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.01 X-Rspamd-Queue-Id: 331721FDDF X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spamd-Result: default: False [-3.01 / 50.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)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:dkim,suse.de:email,suse.de:mid]; RCVD_TLS_ALL(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_TWO(0.00)[2]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; DKIM_TRACE(0.00)[suse.de:+] 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: 1787932855401158500 Content-Type: text/plain; charset="utf-8" Protect vmstate_size against overflow of the on-stack 64bit integer during multiplication. The data at size_indirect.offset comes from the migration stream. Acked-by: Peter Xu Signed-off-by: Fabiano Rosas --- migration/vmstate.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/migration/vmstate.c b/migration/vmstate.c index cbcd86e5b60..24004565bfd 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -126,14 +126,20 @@ static uint64_t vmstate_n_elems(void *opaque, const V= MStateField *field) return n_elems; } =20 -static uint64_t vmstate_size(void *opaque, const VMStateField *field) +static bool vmstate_size(void *opaque, const VMStateField *field, + uint64_t *sz, Error **errp) { uint64_t size; =20 + *sz =3D 0; + if (field->flags & VMS_VBUFFER) { size =3D vmstate_read_from_offset(&field->size_indirect, opaque); - if (field->flags & VMS_MULTIPLY) { - size *=3D field->size; + if ((field->flags & VMS_MULTIPLY) && + umul64_overflow(size, field->size, &size)) { + error_setg(errp, "%s: VMState field '%s' multiply overflow", + __func__, field->name); + return false; } } else if (field->flags & VMS_ARRAY_OF_POINTER) { /* @@ -145,7 +151,8 @@ static uint64_t vmstate_size(void *opaque, const VMStat= eField *field) size =3D field->size; } =20 - return size; + *sz =3D size; + return true; } =20 static bool vmstate_handle_alloc(void *ptr, const VMStateField *field, @@ -377,7 +384,11 @@ bool vmstate_load_vmsd(QEMUFile *f, const VMStateDescr= iption *vmsd, void *first_elem =3D opaque + field->offset; int i; uint64_t n_elems =3D vmstate_n_elems(opaque, field); - uint64_t size =3D vmstate_size(opaque, field); + uint64_t size; + + if (!vmstate_size(opaque, field, &size, errp)) { + return false; + } =20 if (!vmstate_handle_alloc(first_elem, field, n_elems, size, er= rp)) { return false; @@ -695,9 +706,10 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMS= tateDescription *vmsd, void *first_elem =3D opaque + field->offset; int i; uint64_t n_elems =3D vmstate_n_elems(opaque, field); - uint64_t size =3D vmstate_size(opaque, field); + uint64_t size; JSONWriter *vmdesc_loop =3D vmdesc; bool is_prev_null =3D false; + /* * When this is enabled, it means we will always push a ptr * marker first for each element saying if it's populated. @@ -705,6 +717,10 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMS= tateDescription *vmsd, bool use_dynamic_array =3D field->flags & VMS_ARRAY_OF_POINTER_AUTO_ALLOC; =20 + if (!vmstate_size(opaque, field, &size, errp)) { + return false; + } + trace_vmstate_save_state_loop(vmsd->name, field->name, n_elems= ); if (field->flags & VMS_POINTER) { first_elem =3D *(void **)first_elem; --=20 2.53.0 From nobody Sat Sep 26 23:03:02 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=1787932975; cv=none; d=zohomail.com; s=zohoarc; b=jzBnjqF9nJFTANdHti39hEu6+zTqF4Cz81Nr38GT25eRHfS607utJC5a/QbcMWSk0KNPkNgG7F+sadnP+3cfRSBZJgGaEzjO3W9owj0ofxcD1grYSCk+Nb6o7vZLEu5ANH55eWqFRDLhz2ATCJvn2aD8EepjeMcenT/ZRAvll9c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787932975; 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=Yogt7hp0asx6p9ZHQBFyYyBwc22IVXY4dpf+tsNP4gU=; b=XYZpKRGiSF9urhx8SjCJJ6E/f120gaHlJBOmJz+N9Fpy6aANghwZzadxLgA15LOHW96sQ/LA6DAfznS1MIisVLV1QxSFthvTvo5IvK3/O8pjK9DjX7u+iteXDW2hc35ldp+YEufzbg48j9iS6Dy/2bD+1B1LmQ9NNARgNyzHuQA= 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 1787932975987860.249848363528; Fri, 28 Aug 2026 09:02:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wzyzg-0001ft-4D; Fri, 28 Aug 2026 11:59:52 -0400 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 1wzyze-0001f4-3t for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:50 -0400 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wzyzS-000092-3E for qemu-devel@nongnu.org; Fri, 28 Aug 2026 11:59:49 -0400 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-out2.suse.de (Postfix) with ESMTPS id 7C6BD1FED0; Fri, 28 Aug 2026 15:59:28 +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 728961369E; Fri, 28 Aug 2026 15:59:27 +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 cLn8EF+wkWpoBQAAD6G6ig (envelope-from ); Fri, 28 Aug 2026 15:59:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932772; 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=Yogt7hp0asx6p9ZHQBFyYyBwc22IVXY4dpf+tsNP4gU=; b=P5wY8pVAFCYeDzNNeoNq2szHu8yYJyIIyOAKCOmkWfAMZSPImBQyPEpAXfrh+yBOFKLWLb d8hhp3FzDpkQRjV0xghpzaevhtfyn8cb56luXCPBs3ShagptQR7mzxOyhMHr90TFJFhz96 NL36d9Ph1gOYD5tta4VOtfVvrn4yHvc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932772; 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=Yogt7hp0asx6p9ZHQBFyYyBwc22IVXY4dpf+tsNP4gU=; b=8gtg3LD4tK2Uqhait7n6fT02QeALXd6GGAv4mWECB5IJeFM1PsSPpsGpqOUbhTDKbg7fKC 6W70pcpUWKQe+TAw== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=eq4djWYb; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=hlD+MlIz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787932768; 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=Yogt7hp0asx6p9ZHQBFyYyBwc22IVXY4dpf+tsNP4gU=; b=eq4djWYb7CCWe31ecLJlhT5nAXnXQ6OwcobdBAIzWdOke+Xg4HR68LrSTfBniN+0dk9jOu oorsLY343rFhB7d0UGZA3fqgJ+06sA26piLQnSNVEfu4xGm3oENRVOXjT/beZ5UId4Ti1A 6xUgCZf2BKVV0CtJPmwDcraLniUwhkU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787932768; 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=Yogt7hp0asx6p9ZHQBFyYyBwc22IVXY4dpf+tsNP4gU=; b=hlD+MlIzXhWV7Wx7OUfueWkaHJJUHg/XGlaubdjRgskTSAPM/irG/MbJzaa96d+EFQpVq4 zTszEFyR8XCIQ+DA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , hongmianquan Subject: [PULL v2 30/30] migration/postcopy: fix page_requested leak for vhost-user shared pages Date: Fri, 28 Aug 2026 12:58:45 -0300 Message-ID: <20260828155845.2874508-31-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260828155845.2874508-1-farosas@suse.de> References: <20260828155845.2874508-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Queue-Id: 7C6BD1FED0 X-Spamd-Result: default: False [-3.01 / 50.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)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo,suse.de:dkim,suse.de:email,suse.de:mid,bytedance.com:email]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.de:+] X-Spam-Score: -3.01 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=195.135.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, 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: 1787932976371158500 Content-Type: text/plain; charset="utf-8" From: hongmianquan With postcopy-preempt enabled, a postcopy migration of a guest with a vhost-user device can hang at the very end on the destination, after all pages are transferred (query-migrate: status=3Dpostcopy-active, remaining= =3D0). Root cause is an add/del key mismatch on mis->page_requested: - add: a backend fault goes through postcopy_request_shared_page() -> postcopy_request_page() -> migrate_send_rp_req_pages(), which inserts the request and bumps page_requested_count keyed by client_addr. - del: qemu_ufd_copy_ioctl() removes the entry and drops the counter keyed by this QEMU process's host address for the page. client_addr is a VA in the external vhost-user backend's address space and never equals QEMU's host address, so the removal misses and the counter leaks. postcopy_ram_incoming_cleanup() then waits for it to reach zero forever, which also stalls the source (it waits for the return path). Racing threads: dst: postcopy_ram_listen_thread -> postcopy_ram_incoming_cleanup -> qemu_cond_wait_impl (waits for page_requested_count=3D= =3D0) (postcopy_preempt_thread already placed/woke the pages) src: migration_thread -> migration_completion -> await_return_path_close_on_source -> qemu_thread_join (source_return_path_thread blocked in recvmsg) The leak is only triggered when the vhost-user backend faults on a page that has not been received yet: only then does the request take the shared-fault slow path and register an entry in page_requested. If that page is subsequently delivered while the request is still outstanding, its entry is never removed. (Pages already present when the backend faults just take the wake path and never register.) So a run may leak only a few entries (9 of ~244k requests in our repro) yet still hang. Fix: key the request with the same host address the removal uses (rb->host + aligned_rbo) instead of client_addr. The backend wake still happens at placement time via postcopy_wake_shared(). Signed-off-by: hongmianquan Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas --- migration/postcopy-ram.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 885ab58fca5..5509cbdcb8d 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1123,7 +1123,20 @@ int postcopy_request_shared_page(struct PostCopyFD *= pcfd, RAMBlock *rb, return postcopy_wake_shared(pcfd, client_addr, rb); } /* TODO: support blocktime tracking */ - postcopy_request_page(mis, rb, aligned_rbo, client_addr, 0); + + /* + * The page will be placed by qemu_ufd_copy_ioctl(), which removes the + * matching entry from mis->page_requested (and drops + * page_requested_count) using this QEMU process's host address for the + * page. Register the request with the same key, rb->host + aligned_rb= o, + * not client_addr: client_addr is a VA in the external vhost-user + * backend's address space and can never equal that host address, so t= he + * removal would miss forever, leaking page_requested_count and hanging + * postcopy teardown. + */ + postcopy_request_page(mis, rb, aligned_rbo, + (uint64_t)(uintptr_t)qemu_ram_get_host_addr(rb) + + aligned_rbo, 0); return 0; } =20 --=20 2.53.0