From nobody Tue Aug 25 05:57:27 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1786902501; cv=none; d=zohomail.com; s=zohoarc; b=Nuhi8twRPuFw0rRwwdUh/D/Wcdd2vK/SERG4r318bPqwGRiZCC9ir0aR/GqUOrgdAuldv7oDwzyMeikqFA12ZvboV3P6u4F52tfxjer9mzP2RVf/8YTWz1kCuzjr3FnyQlnHU2vDzXy2KCdNikhhP5bl1ahsv+B4KHNqNL8C5XQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786902501; 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=5hDxxdLFArNy/AE5beLWIrhBgzeK81RdKFWGUs0EIlo=; b=AkWcd3VJ+4G1tTTZl0fK+nRes3j2kLdMkyCvXfrNMY8EM3bgKQ8lnmpIi4ycOEcQeimSxh/fIOySrmsbioVk1U2cnIKfBMYC2Aaof9GClCJ0V9ik8gaAJBovCw32M7y4g941V/9EaBvLM+dj+KbYn/2m+6ghGqzbDbRJZcQHuwk= 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 1786902501244187.61528126155213; Sun, 16 Aug 2026 10:48:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wvewx-0007mq-MX; Sun, 16 Aug 2026 13:47: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 1wvews-0007jY-3C for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:06 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wvewq-00033R-0v for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:05 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-2caced6038eso29366595ad.0 for ; Sun, 16 Aug 2026 10:47:03 -0700 (PDT) Received: from setun ([223.228.54.80]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-320ead105a9sm28343674eec.31.2026.08.16.10.46.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Aug 2026 10:47:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786902423; x=1787507223; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=5hDxxdLFArNy/AE5beLWIrhBgzeK81RdKFWGUs0EIlo=; b=BcciLmolnRtVci6+K/xKWPoZGMh4MMRkueI2SiZcM3KXZdZ4EEhcrNLe0UqFNlJ661 if82vPP2VRlltVLoVGMVwm2g6pa5TX4tyvmKTExhpTvxbbrYF+wKn3cwcsGZg5AZ+/ON OAcRaYC/Kl3naFdPgngqGWkXbgeL0WZh7X4Q5wDO6Idr/QrQ3jbvW5dINXntYJHybyP5 vqs2ogw1tvnyvNrvcP3uM1/7js+04X0JGXEpQtILOMhepxFmyBPKPwmLoHKiy+236w5t PUE9z4JLyk3OmFDmGfb7zpVkO1ggPm8QVqUrPVbHhH0/aXfPIbJgnGrgVjnf3NF6z0Xg 9kpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786902423; x=1787507223; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=5hDxxdLFArNy/AE5beLWIrhBgzeK81RdKFWGUs0EIlo=; b=dhc26EScf+PGsw963dinRkErZqyVSulNRXwS+X+x3hOS0NkP17XizjGRqxH2JtKsE/ Yifb4PhdTqA1AyyQEwQa6bK5fMGD2Vih/dH1U5lD7mlihA5zHbAoGChieL54WYPZsk1s HCsFdNQP0kK57cVkJbXPFICWBwuOUjU5nutH7/bXtVwdh7/8k8Vhven5CiJq38Hwmn1j xetpm89hfSM5KSUxZAsuosNS5X2CSJmmCiUoYVuaCGUCk14X/gsdnsnBfhJY7/8kLch2 Ag8DHAeXdpvrhGimG5LcTCNfXQaFtUoltde9KtZqobnAWWETx3Z/r09UXWeCc+MPduAQ t80w== X-Gm-Message-State: AOJu0Yy2y0Ia1qhcRhPXDTcSt3p8Spes8MrLC2kD87bRorL4A7lprCvm 2FLCOvmCI65ZRqBetulqV3M/mr5XK3A/hbe6AGoUSk7LG1XBqu+i+tSeg1Pp3go3 X-Gm-Gg: AR+sD13hyOVneHkmjbq4xc/HsUUzrFbASGUZF5UE9JTT9UMJs3x+QOC9xxZfkw95bvb wwokyYzUhbXsJWRp6vaOIxOZDLin93hGmFdixFR+vEi6jDkEwfqs3bEdspgmDbDgAVZPLlCVJ6U gpTbCJMLSCiIO3Ou/2/1KKqLfEzGEr1JkTsA2FWBy90sD9UF5DTJ7ivb0WKkw8KZ7qEpze+Sx0S JGw12B2AtgwGf4rTWvD9xzkshNDeQIAW9gfdGtj6PP0/Vy3sBVm5iczFHWLVH3w4svp9N7DZv27 9vPaZ+lNRLQnIu6BL2Qg5PrlYbQCNxRjoWNYY361x6nirCpkrKO2WSf7Ia4byhNxwDUqQ58Znac v5g9e7fJx0u6MM/W1f0o6T6er3cQ2MXQaK0LH5T3NKgk26cS9xj486y7x9g2PX9+VnutagAEHqn MkzOQQ458JhrLRVpB16cx567WDieaMpy28Fp1+jIL0RobPb99wVzawh6ZZrHVmL47d/moOWUJj3 RlX07KouDrbsmg= X-Received: by 2002:a17:902:f64e:b0:2cf:70d2:da7c with SMTP id d9443c01a7336-2d37f77fdfemr287252555ad.12.1786902422575; Sun, 16 Aug 2026 10:47:02 -0700 (PDT) From: Aadeshveer Singh To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, pbonzini@redhat.com, philmd@mailo.com, lvivier@redhat.com, ayoub@saferwall.com, pierrick.bouvier@oss.qualcomm.com, Aadeshveer Singh , Juraj Marcin Subject: [PATCH v5 01/11] migration: Propagate error in postcopy setup functions Date: Sun, 16 Aug 2026 23:16:21 +0530 Message-ID: <20260816174631.1547811-2-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260816174631.1547811-1-aadeshveer07@gmail.com> References: <20260816174631.1547811-1-aadeshveer07@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=aadeshveer07@gmail.com; helo=mail-pl1-x633.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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 @gmail.com) X-ZM-MESSAGEID: 1786902502395158500 Content-Type: text/plain; charset="utf-8" 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 --- migration/postcopy-ram.c | 41 +++++++++++++++++----------------------- migration/postcopy-ram.h | 2 +- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index f5ef93f193..96a65aa976 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1464,10 +1464,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 @@ -1487,11 +1486,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 */ @@ -1505,11 +1504,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); @@ -1517,15 +1515,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 @@ -1533,8 +1529,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 @@ -1546,8 +1541,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; } @@ -1559,12 +1554,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 @@ -2201,9 +2195,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 a080dd65a7..98d918713f 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.55.0 From nobody Tue Aug 25 05:57:27 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1786902456; cv=none; d=zohomail.com; s=zohoarc; b=iT9Q//ft2cWozBf95P4T1ZfunPEjA3ka9ubhFvxTVpwA48qdGXmGt04NTOfKr8muQij9HmLc698TzPoks4K7zyHe4xSXFnvyNqEoZ89/bNAyAHSlZKcDeM11023MPReLDC9PK7nPTzSpG0w6peJJ5O6a/TKTAcQ9bLgANlR3++E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786902456; 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=BMKDxNw1pwTZZvQp5o5+ArM6rOVEta7ek/RWxDFA3V8=; b=Kv4wEUaQgmxDyJplDTD2L/pN318KZ+OYllSNYsqOrYLrVNDhhfJs8InlL/ocwSCj9ifPMS1cB6N8Bn5alzbokF+kPnvyB0k9kTMDSsRSGFNn5GDAuRd4gcpz6/VmGIGQ2T65Uie2LG6pQ19+5ViboKWzYpJ2UJb5lC2TNHUasWo= 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 17869024560411022.0982754633616; Sun, 16 Aug 2026 10:47:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wvex0-0007nf-9V; Sun, 16 Aug 2026 13:47: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 1wvewx-0007mY-2Y for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:11 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wvewv-00036B-Ch for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:10 -0400 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-38dfe910e9dso2547463a91.3 for ; Sun, 16 Aug 2026 10:47:09 -0700 (PDT) Received: from setun ([223.228.54.80]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-320ead105a9sm28343674eec.31.2026.08.16.10.47.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Aug 2026 10:47:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786902428; x=1787507228; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=BMKDxNw1pwTZZvQp5o5+ArM6rOVEta7ek/RWxDFA3V8=; b=ri23xW4C8OwPXpdNsTitFxnsVFNBcXrqFtHa7fzghDo8hkS5Whz4mb1HU78xRxcziz uFzmp3KGYER77Mx7vfBlbzyG0KVlfrlMR5vROK/Om55WixiEk24wirXlKR0pHG0KF0Gm +8LjEHopK10k30giDjPwQXTG6EdnXjLUShhfT8HVH9lxxVMLkMyteS9oRABEuBJDBTeO zQTThaCuj4ScJADNgSmP7+6z6mPHP99hO71V3+2/f4MEb8skcCoQCU+JPVo+WR+NdrUq 0PdciRj99GAFecbdkrKvfB8WXgDiir4Z4/4VAOV9is8ywbNcvNothyL6z6SnaBa5Pq9L ZEKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786902428; x=1787507228; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=BMKDxNw1pwTZZvQp5o5+ArM6rOVEta7ek/RWxDFA3V8=; b=HQIzqJP04Ei/rTebX15gGIKftSaDQLyR3EjLpuLE8nK0CuUh8LyWp1sU6NOtQ8VHFI ipg0HiaZJ76zUg0bwKMTBZk2PJrl1xT1t0UutPsp/0jZRi5s3bIeBxLUXtnt/NBYZuwY Q3rx72z+H33n8AIFtYanbs3m2P0zvOsWgFS0/L0JQaNdprZwio8kQN+fNDRCnAF0ABJv GNkyHOfcEa7Cvnty9HO03XBmr4iHQIYjhr9F7LvxaNTfVc5Lj7BxZOo+ybhuF9kRU+r8 Afd8Ls8RVFafwqLrat8hxtlTsMSaoT8kWjBZIWqE168E+W95/KzvO/tFQA2FkzfhO/u+ Lzgw== X-Gm-Message-State: AOJu0YwaVOqo2S2zYIBLwRkLPBo6yjbSWI8uXZz479o8PJeg3c4S05JV op/jASIp+bXv+9v5EyZR+eOUvfxLYiuIA6SxLlYbj56LqrfgDs0g18VLXjoAkIML X-Gm-Gg: AR+sD11w2Drmrtw/B1c5dIhCfzRkQ2E2JzGjFAoj+Fr+gCvQSw/woi1CKUf48d+hkxn WakVXBlrQRUSPjyLfkvtfET/9p2ZfIMyQdsvVwKMGqoJF8yrDuVtO+Mgc/Lmx+S57TJmoF5O3Y+ iaRTwDbSxM+a5KEZXuXvagXb6XcrLnyqvnaT4KpsUPJwpYITn6jxIFwvR0LsxgK01pyE9RX5BOU T70agfFLa+XvfGZSpfiqe/qI0fhtTOxacW3SzUG+dQvH/Oyasyio1UZy6h0QbwvcEzNpIEjAl5j 5sWoRmJKqSRthXcd1sKyA6prpbxDlShVNdP5ZjwPmqvtmL9+mVefyaEiPmiRbnHlw217Dq5fWn3 99n2GK8FkYZL+QJu4cZrBq7ZW6ucx/jHr6CW0IWMMYtY97Wacz0fu+euO1xiaIOPJ3RQLvy+OCY J/2gUlHj1Yu7Fx70s2dwsKx71M93EDz1LeqEFNdAq5uA3MV2CSphsgQ/XtE8JEMsOJfVBvVHEwL AkA4yxphtxukjhwuT88TTk4ew== X-Received: by 2002:a17:90b:53d0:b0:38e:9e9d:9209 with SMTP id 98e67ed59e1d1-3933bcec7eemr19154145a91.17.1786902427835; Sun, 16 Aug 2026 10:47:07 -0700 (PDT) From: Aadeshveer Singh To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, pbonzini@redhat.com, philmd@mailo.com, lvivier@redhat.com, ayoub@saferwall.com, pierrick.bouvier@oss.qualcomm.com, Aadeshveer Singh , Juraj Marcin Subject: [PATCH v5 02/11] migration: Extract blocktime marking helper Date: Sun, 16 Aug 2026 23:16:22 +0530 Message-ID: <20260816174631.1547811-3-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260816174631.1547811-1-aadeshveer07@gmail.com> References: <20260816174631.1547811-1-aadeshveer07@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=aadeshveer07@gmail.com; helo=mail-pj1-x1033.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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 @gmail.com) X-ZM-MESSAGEID: 1786902458838158500 Content-Type: text/plain; charset="utf-8" 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 --- migration/migration.c | 24 ++---------------------- migration/postcopy-ram.c | 31 +++++++++++++++++++++++++++++++ migration/postcopy-ram.h | 3 +++ 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 074d3f2c69..07394d8eea 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 96a65aa976..4b8f882e1e 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1057,6 +1057,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. diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h index 98d918713f..ea879f0bc6 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.55.0 From nobody Tue Aug 25 05:57:27 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1786902456; cv=none; d=zohomail.com; s=zohoarc; b=SVU2dSmBeeCVljcLCaa4NS1MuRbbP7JRrSLX3YB1+1bEopBP8lv8kclqLo5ItbVLckddNFjAnBapCgFvyCwOrBtq1nwHMEH+qWYDoH0ruqDYsAP6NE1MIO4kGXd0xOnKtRHQAWgrVwxakgU/rdc8mEezjRhZkxl+7Fuec9fsyR0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786902456; 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=A1pznOV9GW0rbqufDgwjkEClbA5koQWvItVltcogtdc=; b=Nm0OtI6MxYmT8WTttfYEEd877b/xmjaxv0kzoCpSzyuVrPHQfOjlnja7cUkXzALh2Nhs8/jWNsmp1Ri5EZ2FDGb3KSQXQIe1lZq7RA0AJuV17AbvrbKEMNvA+FloHAhwhFf5BQcdVIXJoFFLLlNLIYmr+RwqaWB0tMxvP+6EX3Y= 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 1786902456479215.30168905693813; Sun, 16 Aug 2026 10:47:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wvex2-0007ny-Ue; Sun, 16 Aug 2026 13:47:16 -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 1wvex2-0007nq-0y for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:16 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wvex0-00037M-Hh for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:15 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-2d032846c95so38601335ad.1 for ; Sun, 16 Aug 2026 10:47:14 -0700 (PDT) Received: from setun ([223.228.54.80]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-320ead105a9sm28343674eec.31.2026.08.16.10.47.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Aug 2026 10:47:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786902433; x=1787507233; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=A1pznOV9GW0rbqufDgwjkEClbA5koQWvItVltcogtdc=; b=kGzqqAZb1lteLK6YNBk770556qLh9G0fEF3itbeJn3wM+4pY8u0eryxLW7tvouQE2j RT2yznTxFkfTA+RJjG0Axicx2TBrwGlMesNSg5Ha+gs/paMWWiRt/VH8tkWHnp9itqKy lcW8sf01u+e5RYwyREb9fV1jSCyUrkwgpjd86nV+fphaXvy4kJHZs7Sp2DYAQm7jL6tW joZsDoXBmVIW/zqF38eX/xQmsV/RX9NkZsXivfED+kt73uVaorDTbw5qOCGlqnGMPnuk rVdpn6eoVOhdnzXB0jpPRky1tY5IolqoZqEyX6x4JjncEyy2fIxME4nhuvUue1KrLgiz uuGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786902433; x=1787507233; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=A1pznOV9GW0rbqufDgwjkEClbA5koQWvItVltcogtdc=; b=IRlqmfnCpoRjNxkGz9LFhftM75LTfM7DDqV+YYryQAMhnOr115ni11t2SZ/IVcD1vo IypeWFy+EyU4+qEZwJTahVFj3KvTr3bSbAOJE7Kzx6WAGA0FCpVc7r/GAJAA6NBCoa3c wAEK4TvA22Nd80Y6+yImVtZibexnK6gtOhKvUv6t/aejPZm7OjDpFrBbMWTlIkgZBiPT 7zGQ6B/h0pF/tMs81k7HkWY8cnhYctQf9dNd95cTioTaGOTBbdnT9mX9ybt8Z9VnJqAG a9cTYTqg5NSnP4nmM+z1RoZZE8QGYxRRYay0vn7wh6gGXVrWAxvF+1yZGE6NMdU9Vy3M ntUQ== X-Gm-Message-State: AOJu0Yz7TMdSrWa+6O6SkL0znYT4l5L54VSjTtjbHQs5R4MP9tAoH17e 8d1gQF62lyMuu7EH+p5+IpE+8za1LPTzb3L52o2u8ocuAtJdKFw6fgiVrrSxSytW X-Gm-Gg: AR+sD13uqbT4s7AOEoLVHC8OiV9xP9Ds5DrFMw6hjVb1Fua88y671rnHPN3fm8oz3eZ vv/17OOm/TFDX08C0RjnGcPkIi3OynBdFePwRz/GIlx2KIbsXliQrAQ/RyaIXgYV5wJSamRaigK AX2raXC1cOaOSR2zi+E/pLneT22A0AA+5WBBCTN8nckQkalThAkZERDRTKBRst7HJG7bpDqpTJQ mq2btlISOE2cx1RNRVovmySlwlS90UR6GY96gXDHo7aRnjzUcrwkIXgGOyU2SZ1kxKBDd85PN+Z trmf1ABzaMEtkSe78ikV+YXdQnJ+RkWTqGnKIMEwYuy5JnQzZv0pvYd1lBV1br5lGyhPXYnp81+ gF/4GXL3jth7xLtzgWnUt9GEeZLXxP4SemB7psF+/3ncO3ZLN4yuta0VoaFs/H/iGaLQv4kQ/oj fZ6xZFciEYfmLNHPYmtIA0fYbLTFt5y7SIv4VoLKMsCeYzqVhvIOd67aqtgudroNBAJyX8hT9wp R0Iw7BYQ8iIBcU= X-Received: by 2002:a05:6a21:7316:b0:3c4:de3:816c with SMTP id adf61e73a8af0-3cc71ed56f7mr22457209637.37.1786902433059; Sun, 16 Aug 2026 10:47:13 -0700 (PDT) From: Aadeshveer Singh To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, pbonzini@redhat.com, philmd@mailo.com, lvivier@redhat.com, ayoub@saferwall.com, pierrick.bouvier@oss.qualcomm.com, Aadeshveer Singh , Juraj Marcin Subject: [PATCH v5 03/11] migration: Rename postcopy_listen_thread_bh Date: Sun, 16 Aug 2026 23:16:23 +0530 Message-ID: <20260816174631.1547811-4-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260816174631.1547811-1-aadeshveer07@gmail.com> References: <20260816174631.1547811-1-aadeshveer07@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=aadeshveer07@gmail.com; helo=mail-pl1-x629.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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 @gmail.com) X-ZM-MESSAGEID: 1786902458739158500 Content-Type: text/plain; charset="utf-8" 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 --- 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 4b8f882e1e..2e2c9fae10 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -2103,7 +2103,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(); @@ -2211,7 +2211,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.55.0 From nobody Tue Aug 25 05:57:27 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1786902460; cv=none; d=zohomail.com; s=zohoarc; b=QCZHkmzcd4nP+S3odVU/hir7b2Z5g/meywYcdTXT9GLuttfgG8GPPFyleMpMaPvQO46lHnQbULRwKSBtpb8o3HbLWsCpfJC68uGSs4oH8soVagmrghVJqZ823zEx5TvUshjqqkNrR570aTo5XiRq21H6qle9q1lYdANqznaD4JY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786902460; 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=JVtBu3i+dc1YRdmQqvlpomuP7fHbCI5Ze5cjl4kS9Ks=; b=TzT4xAlQvKQaxI63C58l8GEYy9b/mQTyywNPW65hjzbGJKFN4Aj1Gf1FWFn9ohhVEvRT7ZKAM5u9/4iDQhrS61IaHSmPp44x0zv2pbpvlmKbDLSLEc6+i41ziHQnYhEw0YaZvRqOIvkbSB1VuHTsUNxOlVgQdHv8OUbgCdjnywA= 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 1786902460269948.430708105751; Sun, 16 Aug 2026 10:47:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wvexA-0007yu-6P; Sun, 16 Aug 2026 13:47:25 -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 1wvex7-0007wi-5J for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:21 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wvex5-00038I-Hi for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:20 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-2ce98cb8165so23846025ad.1 for ; Sun, 16 Aug 2026 10:47:19 -0700 (PDT) Received: from setun ([223.228.54.80]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-320ead105a9sm28343674eec.31.2026.08.16.10.47.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Aug 2026 10:47:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786902438; x=1787507238; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=JVtBu3i+dc1YRdmQqvlpomuP7fHbCI5Ze5cjl4kS9Ks=; b=duTjiICmNuxs6vuj8VhVwAhKFcDY7Xhxewzjha1tHvrU+8dgEHNYyYJtyryHVIwCcY poYy9aVaVi7wOm8kzAQt5JxJPC/DsIoJO5UZWG9aVaiaL0sIsWGBuFtZGOAXuFV/be5P LIoUm98i1fIUulBRPkNCaU01rNepSipp2dp6FbZfa3PZleCl+qTtewTclHGuYnlXHoyf nllOVdKxkIt5MybnKRNQM3cYLnFkI5WaKJMNwsnKZzl4r9WH6OGeZdZjyII+IBYi5XAW HA+spBd2c1UFVgb5d0QyXNoM3CbEX5syixlnWmmMuMM9KLBwQ4jD52WC06EAn9n/oz/g oRcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786902438; x=1787507238; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=JVtBu3i+dc1YRdmQqvlpomuP7fHbCI5Ze5cjl4kS9Ks=; b=nLH+15nmHP5HPw2BlSKCeBihRnuiiMjIPqqTxkddG57We0ElCmhnb2OlkCmeJZfLE9 21oMEOGQn6HB1gXwVokaL+EYTonEgs3AGORnQvl6rX6MD4KlpNbUTV/QYpjedy8/0Ocs 3iLjOXdHG//vwdZywEBRfPQBucVzWTcxfVbPl06toNX/DWQYrqr3UaJezQRckviUdFxF S7mOrxd8x3eZ9cm1AUC7EKRnTmYUb4VEq0acejao0Bxlgoi/1Na4mEy6MRhqUUdhnFMR POKEFFDa7bnSDadyoiJsDYM8w9zHVDoH2LBCRu3aSm6oIMFY0ZpEIrUh57GUKmjRdS08 tbIA== X-Gm-Message-State: AOJu0Ywk3ZFpDKIF9c1Ccbgf8l0t0rf/9VKOydcWlWwx6tKpYSHPpX/R 58DYzBrBmm3bPJ86PPuNl3rYm3HONsf99riZtYUQvqzhA0nQTZ+4eB+ucNYrC/XD X-Gm-Gg: AR+sD121wcbHRQgcuYm5VNJGZ6jjoGWccq/fQ465XDErzI+PXS3KDTKjW3ZMyJwWdWU u1TQzVib8Ye9EFHfbtxVw1bvmaP7wRJC4+VMp62vikpGGkkKHiYOuu51G3Qz0xOdrszpMFDNEGL ECEbPtvXKU5TID6ZsdzQXLy25q6DgneSdsNmCXwaetbyNSr8wZV1KWKtkw55uPlHmcduTo0HzN/ VjVIzmewvRF7GidKclNVGEQ+IRiZYYREOVkNSzrlP6j3SKdAUn8BiIhwPCnHWMBTyyBp8RNWGYE 9Qs/1qsLnE9lGMuKP/htkbHIH+NM1H1NVMYzNZ4pcz4xUWBB8cOgHcCc2AdB+TKrJK3RH/kUMg3 dxG/9es9w4b0Vm1OgRXM8PF9ApbXbzISm4t+MBqaARQHmvYcP2qzDLSJmobkSvVfrEko8m7R3cm X6OgN8V6VUAZr2Wc7bKXMyGfteRWzyexqeXatVgRhRUouPvWDZFL+ee9MsxG1ZNpWJ9HCcXv0yd zDhT63KhW/E0rnwd5INrWQR4DyHorMm5uf9Dg== X-Received: by 2002:a17:902:f551:b0:2ce:a6a4:451b with SMTP id d9443c01a7336-2d37f7647a3mr233048125ad.11.1786902437872; Sun, 16 Aug 2026 10:47:17 -0700 (PDT) From: Aadeshveer Singh To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, pbonzini@redhat.com, philmd@mailo.com, lvivier@redhat.com, ayoub@saferwall.com, pierrick.bouvier@oss.qualcomm.com, Aadeshveer Singh , Juraj Marcin Subject: [PATCH v5 04/11] migration: Use file_bmap for RAMBlock during incoming file load Date: Sun, 16 Aug 2026 23:16:24 +0530 Message-ID: <20260816174631.1547811-5-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260816174631.1547811-1-aadeshveer07@gmail.com> References: <20260816174631.1547811-1-aadeshveer07@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=aadeshveer07@gmail.com; helo=mail-pl1-x636.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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 @gmail.com) X-ZM-MESSAGEID: 1786902462079158500 Content-Type: text/plain; charset="utf-8" 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 --- migration/ram.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index fc38ffbf8a..4728f14d73 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; @@ -3749,6 +3760,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; } @@ -3766,8 +3780,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; @@ -4142,11 +4156,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; } @@ -4174,14 +4195,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.55.0 From nobody Tue Aug 25 05:57:27 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1786902526; cv=none; d=zohomail.com; s=zohoarc; b=A6W7QhNwyRvHL6nUtgPikhl9nymv2R+aHA+E8hvv0GxI2ukwC8xOHZg8fGjOMz64GS/ayD/TgVwroEmkUzvcKa1xcXgO7HY3zr1vm5QCteFQw51irl7AB0ozmRVqkgL4a1m2VW4JtbysOtczD8lmBY3aGRiK4KSBdShuLVQgFUQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786902526; 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=LEb4IeU8xhFAOEs1BVpDht8XPPtt6nino35RRBxs/u4=; b=Z750CC/A3x24ZLfv82ywaA0C3w00t0Xeho2/OAopmWmfohHPra+lyljt9k3rkpuMlTNDXU6JabNs/FkijaRM3r3Cx5gCj+zOQga+cRL/n0pZeq/rDStdMlrL0T7y1PvytypD6FN98tFq0K0paZ1U+R++hBJrrf5el8q0oyMB2ak= 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 17869025266406.912470698629136; Sun, 16 Aug 2026 10:48:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wvexE-00086N-M9; Sun, 16 Aug 2026 13:47:28 -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 1wvexC-000801-EE for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:26 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wvexA-00038y-Kc for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:26 -0400 Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-38759bcd877so3015480a91.2 for ; Sun, 16 Aug 2026 10:47:24 -0700 (PDT) Received: from setun ([223.228.54.80]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-320ead105a9sm28343674eec.31.2026.08.16.10.47.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Aug 2026 10:47:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786902443; x=1787507243; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=LEb4IeU8xhFAOEs1BVpDht8XPPtt6nino35RRBxs/u4=; b=R2HUu3Mb1BlMdIwuMD/uBm4BQ+xdCFoALR1rMo6DhaLiHaoJgSX3kWtfyuzBl/sJOL 7W/jmaFn6ppOX4fBo6Y8N2Y6VzluUCp0iX6jaYxkJC73pFMO7NfUiFfm92tq5B7koc+R sCe1pEo3oeUGIX8VjCwBqiqYJgdUqHOmY41KJpSTCgErxINagBPk2ORjb6U/hr08G75o kNDzFaqsTqfq7i+q8rKLJnRP00QJAo/Z4VehVrJD350W2w/mwn4xn4+s7AafvikmKjux QRfUBGxNp09sRw7H8k8UP8eF+LfOqMgcwo/9VaGMhHhe/3do8eWQqj9hc+0ODS0WK7wh F2NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786902443; x=1787507243; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=LEb4IeU8xhFAOEs1BVpDht8XPPtt6nino35RRBxs/u4=; b=hFiohO+00KX+uYKYzebexLHSYH3ZzD5e65gvUL3sWhdXGX8q/+xSMBNKqDHmU67+2j aY2IjXL8NM1IC/+W1CQXpNkFmUvMDzuxzZINWTNJZMm7XGorfLnB3fqmJ9lNmslYBfw2 YixtYyU5Wgy19IK9QnGxXd3ubxikIUDIT9AbeEd8xQR5dDdfbDVzRs1i7T/ohrQOZn0g gP4JIyKIlcWyRdLL7t/rOXDnBu26saMEeyOY6Fi09FMGdA+yuFXhnwCcgkszpZbKwm1M 8kWZ7xZi3PWP4UZNbVR++UvOiMo5ygveBneuyFohJQdXo15Kz99yE8PHu6mwWfvn+qXG j7Xw== X-Gm-Message-State: AOJu0YzIpgoColtW4+ZCjZ0abgB8Oc4SPg5rOeeSkXzUy5JLs861ZtZG 6N8Jf4L4CZIrUnWWoMxn5sBC1Za6gQn5QMtK9BvOwfsg0PCCtHnMKGBnr+NfWAAr X-Gm-Gg: AR+sD10IdeNGFQxrlk4Qi3eCNbt/e6CDrbMorsBWQy5bBRtIYdWCdtJZWa/DdSZYIOI QHWFp1fLXcaiuM4y4JT8/0xm5L4yUgQ/oLLvLuZMd1CtQ6nFGfJtEz62fSvTqaxHFJuJ2WjXxPX UKlfwi/L9pEHFCg7uYXSa+oCYRsCV7c+ppOXVWfLtvlrb7vHS4X2kjQ6VHXmePp6Nl6BLtboe0h fGE8XKfXF+xGSi/GUZs+HRy2G6ZtMhMCT2EYs9yGdFDMY30BNBpaG3pPybVBS/E5RET5qCdClxK KJOw17510+1OeXoGPa/vatQO8bxk3t5F/PdQFhAembnJ2GJP8PYyGXCbvPKpXDgPmVlF0ZSzK2a WeAVysWEFM7R0fskv3r02FxkbP7dNx10vP+SQrkmneyxgGK5MDRxzt4KoHH2zA+OKxYEC6kBAKt IR8uucp5fOix3PV09wkzkkkPQtaEUV9bz1kCO2P5prQKtngwzL9U+USuhUwXnEHuzfTWq3yCnkD kDa+pkbECh2TjY= X-Received: by 2002:a17:90b:384f:b0:390:b41a:b92f with SMTP id 98e67ed59e1d1-3933e648702mr19122496a91.18.1786902442753; Sun, 16 Aug 2026 10:47:22 -0700 (PDT) From: Aadeshveer Singh To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, pbonzini@redhat.com, philmd@mailo.com, lvivier@redhat.com, ayoub@saferwall.com, pierrick.bouvier@oss.qualcomm.com, Aadeshveer Singh , Juraj Marcin Subject: [PATCH v5 05/11] migration: Make qemu_get_buffer_at() thread-safe Date: Sun, 16 Aug 2026 23:16:25 +0530 Message-ID: <20260816174631.1547811-6-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260816174631.1547811-1-aadeshveer07@gmail.com> References: <20260816174631.1547811-1-aadeshveer07@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=aadeshveer07@gmail.com; helo=mail-pj1-x102c.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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 @gmail.com) X-ZM-MESSAGEID: 1786902528555158500 Content-Type: text/plain; charset="utf-8" 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 --- 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 d5a48115bd..2feaeb8982 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 8f824c124d..966766788d 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 4728f14d73..967db7c0db 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4127,7 +4127,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) { @@ -4196,8 +4196,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.55.0 From nobody Tue Aug 25 05:57:27 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1786902469; cv=none; d=zohomail.com; s=zohoarc; b=QuLGJ6KLAFG9T7j2qGU/WYaeWfeAKUg1yNsdrk3Qwr/afY8UF+ooBuPNU0QD3QwRAK7eO5pBu+CE2ATMtqlpyXPACVAJ31VoQMl/Tnd3V0dzZOv6Cer7lOURHbAtqXtn1Z2MfAfc9CBuHgMp/yOFIwvuiT6MGhUdHzUlbi8ZJ/0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786902469; 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=dubLpBFCiwdsk5+NM+KpCEOCaNgN9YyZVZ71LCMzMiw=; b=X6kkDxqOra3TxutHr3wv1pmgt7q1JVBgqsXOupqnm84LNkYSXAA8MvPFYwv1ffzBNFQdxz7gTfwEN18LKWI6EXC3xuyfddvN8xgQY/5W67O2Toirj7s+vzLLMgy1XPBB+WiVu63SUOLJy3Bb2mQatzXw8/b1ehD307+sjSP13DE= 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 1786902469985875.1514834621601; Sun, 16 Aug 2026 10:47:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wvexJ-00086r-BZ; Sun, 16 Aug 2026 13:47:33 -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 1wvexG-00086R-I2 for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:30 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wvexE-00039h-Ry for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:30 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-2cf50c6f235so32147775ad.0 for ; Sun, 16 Aug 2026 10:47:28 -0700 (PDT) Received: from setun ([223.228.54.80]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-320ead105a9sm28343674eec.31.2026.08.16.10.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Aug 2026 10:47:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786902447; x=1787507247; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=dubLpBFCiwdsk5+NM+KpCEOCaNgN9YyZVZ71LCMzMiw=; b=qcJCUdWPOZjtB3X1CqkY/X3a5mCtBlyW3AwH5+DOmFOfA8hkzrNKwwtskeHtVDS9YT 3wzsvVeFFOI/1a8JX7iyvSnS6tReMLXw+XAt+oUcyotddptH1UXrwt7+aUFG5931PX8Y AGmt/thgIs+Dc1T+2WRoMuN6H3QCv9TcKAz1906MW2H0czPZjXEC8RCkoLqbBvapIHBL PgMI1BXqcp1P9o4DHR7bDpocDGiuxk1WYdAcvUhoKfGevQ0AYFTKYfsGqYTtvoCNE719 bJJkN37/V46ssxuVayPn2tGyHJ545nz5pcrA50v/BCV14SYBupW58Q4C+bsGcGLAbHgd 6hyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786902447; x=1787507247; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=dubLpBFCiwdsk5+NM+KpCEOCaNgN9YyZVZ71LCMzMiw=; b=k81stvq9cdni50fFzSfCV4nWGq/LCRT5gXX93gdh5+lKKrJq6Shm1TwpuVqZItUCtb sywDFyOSys8PWNAPmVZaNGTowWjzMLGLXawyIicHM9KD58yiBLV31IMBIVtrOrbeyRPo njQ4RYgomwkGTY3M3WKAvV0PXcCmKYcPS1lR7OM+2hVWVHrCnNS1mCedzGGQncITaamW GB0LQ3CqZdtsDUEN2N0itaotOXUtcmmHveERmiKEkru8555SP9hku/ak4UgA9yjtlbRG BrzJBBIhIZuPgjht6XT0/Aj0uFQ9oj1lvkeM2frGfW8pTelyXoGvHBTKHx46t3BwyVs2 UO7g== X-Gm-Message-State: AOJu0YwyZ4JZ86EbNUnaDeM9f9YHzxO0Jw2LyoU+yrWC2qZ19orZkJyb IymxYK56iZ0iq4OW4RhGOFKik+TKevGrpqsAHIPxscee5IIShjOisW20miyi0w== X-Gm-Gg: AR+sD13/MYiqVd9hPvt6/hit1vHAXEwc0ify2sX91EZem+OWxLhM5MH2w3EvlUZnPff BwfvwHjRxV00VyZWevvDpO7NRUSzlOYcPhn+zDqys0f46VM0Mwowf98eiK+wyjUDek8jGpbN+vS gBS+BWoMUZF03WU5BsEeeDlNVusZg+p4HBd41OgUqczPsgB1F9iyboQBEgiwcTbHxhK0n6m0/ly cXQ7m1Bzy+FgB/nZgNazcEaFRe0EKeeJuMFQMNGjH+wemEObf1t+PDsINGBE7im0zrpnpTsoNd+ 6f/A8E53FfP/y1QrTNqQas+jn3uJOkWymgHjQqyRjNYD4qvNxtW0AtgN4bmilVT/SIYKSj4ZEYz 0laKkzYU6VbboQkv8i5sqlUGwyvWx34xfGxWMxAoZ2xxj1vfFf2axRgCk/2HOyoGfPbzOPPNui+ rXpgWeEqEh0cdOFsdAidgN4czIf8D3ZEJeWTEiMbtNMht08FUxjeIz010F/wQbPKc8d5GQ6NjlJ MgqFZOlSQBDZpk= X-Received: by 2002:a17:903:2c8:b0:2ca:e5c:7fcf with SMTP id d9443c01a7336-2d3b08014f7mr241876985ad.3.1786902447466; Sun, 16 Aug 2026 10:47:27 -0700 (PDT) From: Aadeshveer Singh To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, pbonzini@redhat.com, philmd@mailo.com, lvivier@redhat.com, ayoub@saferwall.com, pierrick.bouvier@oss.qualcomm.com, Aadeshveer Singh Subject: [PATCH v5 06/11] migration: add RAMBlock field and helper for fast snapshot load Date: Sun, 16 Aug 2026 23:16:26 +0530 Message-ID: <20260816174631.1547811-7-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260816174631.1547811-1-aadeshveer07@gmail.com> References: <20260816174631.1547811-1-aadeshveer07@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=aadeshveer07@gmail.com; helo=mail-pl1-x629.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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 @gmail.com) X-ZM-MESSAGEID: 1786902472300158500 Content-Type: text/plain; charset="utf-8" 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 --- 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 4435f8d55f..83187bf44c 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 967db7c0db..52a3af9245 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; @@ -3762,6 +3781,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; @@ -3782,6 +3805,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; @@ -4201,9 +4225,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 */ @@ -4475,15 +4502,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 @@ -4499,7 +4553,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.55.0 From nobody Tue Aug 25 05:57:27 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1786902470; cv=none; d=zohomail.com; s=zohoarc; b=LgYiJF6qtivBSHsYM+rKBlUobr4CA8uF73TTO3+UqqVe514Vqso4QsiaMLyAJUxNHI6GZT0rWeOXi61ovR3f6Ho1faKVypEHH28ZjVxI0bs+SEvQ2lz96oOA4xQDluWfAkS8RPaNG3fMcDVGdexrWxuE4RV+4AfqI0iDV7ZFuvU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786902470; 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=kVchT0V7CpUEgO1l4PpLG0SIYcB/QXOx0hXdXr5mUw0=; b=Cdn+wTSUAhrPey0HfVWtMHv6ZuNdzMAJo0ap9LLgGNaTZjEPXs8iy7eZ10DqMK0w6zMnLmGdX9nrqcr+lx9TpGPn4/hYacS/vYTh39dkyWZ8SQXPbuE87LmEP7Bulq/8g05p2YpbGi8gbWbhEOb6EhQbtmkh6Dk7+/PJFV5oYCo= 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 1786902470536547.7860068966523; Sun, 16 Aug 2026 10:47:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wvexP-0008HN-GU; Sun, 16 Aug 2026 13:47:39 -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 1wvexM-0008Da-31 for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:36 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wvexJ-0003AK-Ry for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:35 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-2ccf2360620so26131835ad.3 for ; Sun, 16 Aug 2026 10:47:33 -0700 (PDT) Received: from setun ([223.228.54.80]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-320ead105a9sm28343674eec.31.2026.08.16.10.47.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Aug 2026 10:47:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786902452; x=1787507252; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=kVchT0V7CpUEgO1l4PpLG0SIYcB/QXOx0hXdXr5mUw0=; b=k9wx6apB8GNOGk0vjU5C2hu79u2v9oZcuIQlRcZj80PLIr116JjvgT3uu+8DKxEyk4 Y1DZDmqGmMySqe5C62AW7ypU67mPoCaPUe+FKe6VASJyQb91lXKk7qmz5fBdtkeVYZS3 oJIwGm2BjLqsFiR5XFw05ddzbY/rzZHMIQtnwgdf6+CGGA+4A93BB+uwU00scTM2NKBo DuC6QAJaCKnbD87c263RbSCdIjZJhOzkhkkaRmAu6MCW7fSdgot1ggzohiih7XKbkWn6 MfbsP9af1IOJhHsPvzx0lF4xomZRlO4m4+ZR+mgpat/7M3hs3YGnv3LMw2/Rz5fz6ubC +MfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786902452; x=1787507252; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=kVchT0V7CpUEgO1l4PpLG0SIYcB/QXOx0hXdXr5mUw0=; b=QCvHYCMHc7f55VkWhe+/PxBWSIG2hl7XkM3/riE0/xIMnAnom9F7+0exiqHhCjdcZu v+GNly3MM6YnjhoQrX79OobKx7/4cvLkANE4CZhfC108iEmj2TYoM5i6UmJSmai7AxIG C2TSfut+4L8Jw+WIEfv37fNAlUGWdv+19310y0+Jj+jTyWwFn/hqt40n0RDEgKbtFZEh yxmLd+9n1IAhl70OW5MFruLUN1D+vYg3BIxqfJeT798DxnhnrtyESSmQs8NbUN8coAZs xRY+rg6RyOEl3wHAvMP9lRPxOv/wQbnZo5/xSjsGPdVBqqn56D9aq0+bxRHojO6ufp4t QWqw== X-Gm-Message-State: AOJu0YwSqQ/K+Z7a2SIHe6RkvqjyILsLjuxDsOZzKV6LueYkCy8R0E92 /CZiE7fT7BoAkCoJtLvJbFREi6Xwea1qCb/Vxlzomat3JUraUHnmDToajAsaZw== X-Gm-Gg: AR+sD12V1U2mFK8RKBGYSazxpFgPCkOLxWS8Ozy/KmYr8ZsE7kB26/n6UpARX7+vXNK /kaRJ+QFNoDiOW+WvJGDM8p4ebCEcF/9lcAvyHhC54Jo+QbqCiHcveFdEf7ap1e3e+zS/Q5yE0O bAqPsTe32d9TkDBAVyoX6pGg66itTg6Be/bcTSaesoUo42Jpfou54pN2cMad1GFLmAZXvj4Muba wGxa8Wp3Jc6VV1IQUCnN1qIJpc02vNaq+LRLSf5g+OwJmiAaKci46Jbmhkqna3nc4b2NCpGTMqL X39Ap6Z1f0Jn1mLjIvcRT+uM9ExeoL+xBRCWAtymuDIMTH4Xl9MprezvCeL2SyZO405g8ijR6/T KHzx9KYwPtxm2ovkcoqFo7B/p0/KB0sUiDFTRWH6on5ynKu6uj+CmA2FzS7Asu2pH0yIM4gM3bq +p8YKJiN6s2HLmLjDVtc1xtroUGfIhlpjsFUZ1lJgEvj9tsQFxyQZ0XttVnfuNpLwfE1md7fH5B jVNY2tDCEke4SPLvPW9XsN2dg== X-Received: by 2002:a05:6a20:cc0b:b0:3b7:807b:3cd3 with SMTP id adf61e73a8af0-3cc71cb2dcamr21842704637.23.1786902452275; Sun, 16 Aug 2026 10:47:32 -0700 (PDT) From: Aadeshveer Singh To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, pbonzini@redhat.com, philmd@mailo.com, lvivier@redhat.com, ayoub@saferwall.com, pierrick.bouvier@oss.qualcomm.com, Aadeshveer Singh Subject: [PATCH v5 07/11] migration: add support for fault thread to load pages from disk Date: Sun, 16 Aug 2026 23:16:27 +0530 Message-ID: <20260816174631.1547811-8-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260816174631.1547811-1-aadeshveer07@gmail.com> References: <20260816174631.1547811-1-aadeshveer07@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=aadeshveer07@gmail.com; helo=mail-pl1-x62e.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URG_BIZ=0.573 autolearn=no 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 @gmail.com) X-ZM-MESSAGEID: 1786902472348158500 Content-Type: text/plain; charset="utf-8" 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 --- 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 2e2c9fae10..7ff864da25 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -949,6 +949,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. @@ -1310,6 +1434,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(); @@ -1351,11 +1476,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); } @@ -1418,18 +1545,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 @@ -1501,8 +1647,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.55.0 From nobody Tue Aug 25 05:57:27 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1786902501; cv=none; d=zohomail.com; s=zohoarc; b=WIqZ7baCHdUWOOvLV+9q6XPR7/3b9YQermOALn1GT5UGtk70IxLUfSbhk5eAfDuAtZjvYaM4nzNbroLdqLhoyuN0tO/SBmXirBQXwmtFTKkoUQlA11nsTjpqfY6Ot622hK8IlKA80KvMBY3uYxUMVdlASjP6+FFJvlUP3V5nEEM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786902501; 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=kvPuN1mOPbUcNrld4JT1HPanpWXvws6ECl5ytXOEZTE=; b=a3RPkg/DhBHJTipeUcz/jDL8HR0u75Bmn+K/xK3CCzy6ZLI99xdXeXnVXr8GZQMc5qg+WlkcQ1C86OBWlNe7c1wS+L2TSSPBwZT0U2HwGswvOvDODXwIcFtzBFVGgdmmkPTKJD1VrarfeCbElqivLnnP9fJMuMLsZZPaGx6fThM= 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 1786902501344551.6761329456723; Sun, 16 Aug 2026 10:48:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wvexS-0008JL-9P; Sun, 16 Aug 2026 13:47: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 1wvexR-0008Ik-03 for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:41 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wvexO-0003B2-Nc for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:40 -0400 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-38d489b6b71so2666332a91.0 for ; Sun, 16 Aug 2026 10:47:38 -0700 (PDT) Received: from setun ([223.228.54.80]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-320ead105a9sm28343674eec.31.2026.08.16.10.47.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Aug 2026 10:47:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786902457; x=1787507257; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=kvPuN1mOPbUcNrld4JT1HPanpWXvws6ECl5ytXOEZTE=; b=QRJ/JTJHFB9c2iL91xoI7ARWiye4OX3G5pjgnA2sC8N1V41XC7NKXuM744DUF92hEQ /hM31Pv4OeszBfxC4HIJ7hn2OWxX0RcFzcG0aHuhofHdH+24BsGnNrDeuT7BBGHhte81 Wj5g3yehMQsCCF96Z14PC2/ColKqdTgtjKeysyy62o73NEq8L6tQHvK9Kcq/s2dipToc 3B2SzOnSeHsf++px6SeXpe3/PF64Gbrod5PewMHCbspoY7BKTwdhnxIzpLvWKHo+EVXw R4OiwR0LQdakmjP2vPrxy65CiIo/HfHsPFVglujpkqEb+vqo4PLF9RzynMkAQo2klcoD AYyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786902457; x=1787507257; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=kvPuN1mOPbUcNrld4JT1HPanpWXvws6ECl5ytXOEZTE=; b=BvD1FLin7n/Knbns2EiQrd7+Rq6VFCOnptUEKYzH83Ky/OWJIWie9ZriXOKPepUer1 hxiQz/tkmXVPJdyz7g6dKB7wkfw2g/WegaMxK85EUe0KTWSTBo60vTWjJGHT1BCTqy6y sQuYiBK4AfmbVEJKY9rQrIvcz/tGv2J0cW1d7D+hIMR01tN6TMZfr0OalN8Kq14Mj6Wo Gtc1qCssRgLmI2FfTnO510WDYMCjPwwZA2MbdQJ02exmNmFJuJeP4jL7OvL7NsqeP5F0 oHI1N0I5yCVQ163BhagqLsE9FOyW63zxKC4DHRnG1kxDhmbJQBoWY+VKPvAQz+L+j4jY QXdg== X-Gm-Message-State: AOJu0Yy/+bfr8y2S7E5A+tffAn9mSgYIn1bZ17tkGWawxY/T65LkaBR2 pNrd7Va+VLBOS1tU5xp/OErZyLUez/UmMTLEWagR8hhrIGYtJZJZgw/2cmWE3A== X-Gm-Gg: AR+sD11k8mLXYyYcti76Qh/fuXFQ+XTJkN0p3qk852JygkiUIwe1bkX740phNWLChZm K4YGkwQAnfKB8SjlpTTFFnBXJ281gxTdrnqtUFy9fX2UQeZQ2iFKzYbIqSKIdLPriry35RZrNZv wnnUSb8iYlUYR0wP0LuFomLBA15nkG7QZLGFGLuUb2FpvKiJsiwOKg0HRtnYsbWdKUpVCgJxNZn shxi/EgzGqI+dd17a3+ewBvhRZHek90dT1qmJRaxKIuyfwe0UenTAQjNKtqtjr3lfM+DSRbpDbx hO7UHTYHH57Cn5jjx/YohOk9Goy8NxZ8EpC3hxOG3mp5sAEuEpj3yoIT8jNjg+274l9b9NkiljR yUTL7zHhxDSx6Ag9evmJlzV82o2oCF0oAEtD4K24YjoKenXE4cBbMzP5XiO3YN7mj18y/nzKQJ/ MwJ0CVqVoWTMO+rTs8oWH+5PgV6A45D3v7uwcXlbTBTcG2SfcsiMuI/AY6H5a8ojelqMUdLqRXr xnyC1FExrKsJ3w= X-Received: by 2002:a17:90b:1f88:b0:392:c868:35af with SMTP id 98e67ed59e1d1-3933bd46d96mr22065072a91.20.1786902457363; Sun, 16 Aug 2026 10:47:37 -0700 (PDT) From: Aadeshveer Singh To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, pbonzini@redhat.com, philmd@mailo.com, lvivier@redhat.com, ayoub@saferwall.com, pierrick.bouvier@oss.qualcomm.com, Aadeshveer Singh , Juraj Marcin Subject: [PATCH v5 08/11] migration: add eager load thread and setup for fast snapshot load Date: Sun, 16 Aug 2026 23:16:28 +0530 Message-ID: <20260816174631.1547811-9-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260816174631.1547811-1-aadeshveer07@gmail.com> References: <20260816174631.1547811-1-aadeshveer07@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=aadeshveer07@gmail.com; helo=mail-pj1-x1033.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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 @gmail.com) X-ZM-MESSAGEID: 1786902502454158501 Content-Type: text/plain; charset="utf-8" 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 --- migration/migration.c | 36 +++++++++++++++++++-- migration/migration.h | 5 +++ migration/postcopy-ram.c | 69 ++++++++++++++++++++++++++++++++++++++++ migration/postcopy-ram.h | 2 ++ migration/savevm.c | 16 ++++++++++ migration/savevm.h | 2 ++ migration/trace-events | 2 ++ 7 files changed, 130 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 07394d8eea..e9c4eee6b9 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 841f49b215..540124bc27 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 7ff864da25..1f37dc1399 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -2404,9 +2404,78 @@ 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); } =20 return rc; } + +/* + * 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; +} diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h index ea879f0bc6..c58a60bc8a 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 23adaf9dd9..08f614349b 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2959,6 +2959,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 96fdf96d4e..27c6becbc3 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -67,6 +67,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 de99d976ab..38f11e1e9f 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -314,6 +314,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.55.0 From nobody Tue Aug 25 05:57:27 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1786902503; cv=none; d=zohomail.com; s=zohoarc; b=kMnBUHbS1FJlVALtnFeWBoxr3oMF4bxfRDp+E1K9JQ0T9c6uHA/Joe/+YkG/3H9VHYksGGtOw5jluTl1tYEKU/6KAL1qNckjjKsdmxSzmtgZo2vFY82pOHzxnip7ZjbM1mJHGr9TAmbIkWfyjAtaMTdXZGG655oadhfNJZovzNs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786902503; 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=1+Vxxqg8bJXz5F4kdjoTIRovNakDkVXZUTh8g/hecLM=; b=XvkwXY1kFDTBMIrelN7YcBZGJfuy8ncwcnFWldBG9sPxdyqmQN+49uT+1E+D62uLJ2SxdC+0JmoWjbjeD0Vcsk5SuochJMGQ/lUmc7rbaCDepsYIMeJ+mtuzhtPSvCvFgc3E/+Be6jtkDSL+ushbh+8U6LpKh0jyTn8U3wQK0d8= 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 178690250308386.24224064183397; Sun, 16 Aug 2026 10:48:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wvexX-0008KO-2P; Sun, 16 Aug 2026 13:47: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 1wvexW-0008Jn-5s for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:46 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wvexT-0003Bp-TU for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:45 -0400 Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-c966b9ee9cbso1612455a12.1 for ; Sun, 16 Aug 2026 10:47:43 -0700 (PDT) Received: from setun ([223.228.54.80]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-320ead105a9sm28343674eec.31.2026.08.16.10.47.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Aug 2026 10:47:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786902462; x=1787507262; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=1+Vxxqg8bJXz5F4kdjoTIRovNakDkVXZUTh8g/hecLM=; b=h5hhbDpsrM/QHyGRxfh2jCyAV/o3jPidl7K6W+QtXmMKHL/rT3wT6gqNGL/U3pNNSG yUvTY6St47iUy2GggOjCuOyQsRl3NlsnS7U+Tsj0uZvMiJEs0JiE6BlkvkvkYVkltiim 9QTxT4JHjn8PqMsNZCcKLLHal71S2vcNyJGMQHK3EzBx61tJRz2sRI0U0bzNbfm5QXD4 cW9ySKDaqC9/U0DJpBdQuT+yhfKJdXYyRvqNuwEayJ6kOhrgis8Tm9qFZspFa8TnkHJU PHOxytKzagBk0MEzFbAhrFYPQy7RwC2qcqQ2N6AowR20a8YiXmNBzb+yNEh1EjOG61wX DKcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786902462; x=1787507262; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=1+Vxxqg8bJXz5F4kdjoTIRovNakDkVXZUTh8g/hecLM=; b=LTmyA7jg5t/FXOBjUDejsPYWvBrGbiPYH7Ei2EKGFBFGPzvUsPEypJ/xU3WIJ8HnQh ztgasWW1THIusNHGfd+bKIuw3cRHut8kq52ipf+yfTX8EPVHzTrZ4c1qAAUOSnaLt7PR ZlsU8yPuzIp36ezIR6EdjMrJn+Qr4lmId8q3H/A8n9N5crdEjUVcz7cGmYUBUyE6MRq3 asirP7So98l2YHdfFgt1CGuZaCfcVDs5SL+K5OIGUN5D8lf0fKoOxGmuriYrEwWef5of ok+pvLD0gAnKJlwE7qas17g8FfEqfyk1EZuLYdjs3r4CDigM1IS/DOcRpcPcTgpu5SPu lkQA== X-Gm-Message-State: AOJu0YxR8FhtxhZkUAV17I1UA13ZCaLK1Mxfox0fknkARDMZftPgFwN0 5k6UJmCnsjUfu3M3/O+Kz4DkeRRxhcax1eeCMemNOkKVIwGArqUJxJxs9Ebbaw== X-Gm-Gg: AR+sD128+7OT4nUCzugBe9eFdvDOGnEAsZ94KBHoPZ9p9G+8ReBOzj+FyhsinJjFCUY ww38c+MIe9NGzNigCRvPVoLvWJIDhWBcOpV9xAfegvJEf4MPD6gyzaup4e9h4R7Ya0Rm3I3LsLC RnYxzK+kR9FW3oRhXWnRnl6w6iQfS/7ZIYsvZ3cb/z2WCOy3WtIbUgekpV4KWn034XQb3dB2UbT ZB90P5EZSW2ftZldJthMt8s9GnIzSuOoRQF/4Xq9/HaVTLlL3bsEs1SXlLoKZhC0BJWKbLPfAHF Em9HVqBdEzq/lYcadsUAdq5InWI32ihMhF2QkFV30wzPk2kRBWPLLyhmXnDZ907JfmyI5SxuELW rH4Gaca8B6qZy2/RyK9Ma5n2iH5I6fGnD8Sm/SucJt4KvP3+m22yqiEQJCMsn17vteSuze6iNWf GYrjY5AEpxadROIUPIlsgByVaccdqkFzP2LaIajCF54fEOzdLJS7VyFIGf3Fpjy9CeRLsDHSjaW A5MTO4oPwW5vl0= X-Received: by 2002:a05:6a21:3281:b0:3cc:56be:a559 with SMTP id adf61e73a8af0-3cc71fa8c5dmr18377457637.23.1786902462022; Sun, 16 Aug 2026 10:47:42 -0700 (PDT) From: Aadeshveer Singh To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, pbonzini@redhat.com, philmd@mailo.com, lvivier@redhat.com, ayoub@saferwall.com, pierrick.bouvier@oss.qualcomm.com, Aadeshveer Singh Subject: [PATCH v5 09/11] migration: update capability conflict test for postcopy-ram+mapped-ram Date: Sun, 16 Aug 2026 23:16:29 +0530 Message-ID: <20260816174631.1547811-10-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260816174631.1547811-1-aadeshveer07@gmail.com> References: <20260816174631.1547811-1-aadeshveer07@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=aadeshveer07@gmail.com; helo=mail-pg1-x52f.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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 @gmail.com) X-ZM-MESSAGEID: 1786902504271158500 Content-Type: text/plain; charset="utf-8" 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 --- 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 abf18dbf59..666d13f727 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 e9c4eee6b9..8f50dd1c53 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2040,6 +2040,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 5cbfd29099..4f8cc5fd6e 100644 --- a/migration/options.c +++ b/migration/options.c @@ -727,10 +727,26 @@ bool migrate_caps_check(bool *old_caps, bool *new_cap= s, Error **errp) "Mapped-ram migration is incompatible with xbzrle"); return false; } + } + + if (new_caps[MIGRATION_CAPABILITY_MAPPED_RAM] && + new_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM]) { + if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) { + error_setg(errp, + "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; + } =20 - if (new_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM]) { + if (!postcopy_notifier_list_empty()) { error_setg(errp, - "Mapped-ram migration is incompatible with postcopy= "); + "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 1f37dc1399..11500152c7 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -82,6 +82,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 c58a60bc8a..edba7b0240 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 ec6d438cdc..4e0deb7f18 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 c6e158ffb3..8d2657e411 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.55.0 From nobody Tue Aug 25 05:57:27 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1786902514; cv=none; d=zohomail.com; s=zohoarc; b=PUOLTTmk1vOXJRw9kv2B8NQUqmVgbmGddbwfrAnbVyC5FiPZRtfuidhTjGR95AEXilLNBdGA0pgdkO/Fb40vRbs8ujJqnr+2xqtgI90PmmF2RK+cGn7nutXIQelYmM6poeEmbEzkJvZOsUbQWqcV8TrIEp3NMmqEJYlDIQUSzas= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786902514; 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=6naBanft5dzX6viSmmU3Uw6eq1ZNfugHG1TUba3f5YE=; b=H13jXSuBEtIRo68u8B8Yw0Zgqu8dUlOpME7lJBw/Gq7bOqP7DJHuuPCWRm0Si+CRxck+JgLKoaLVLJho8NIx/dQ7B/euJJfIJStcushpzxN3YtXoqNesT3V9TiMr7kOKKADpY9kHelgcykd0CkxThCDszmfGLBdF0wu1Nx7wOXE= 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 1786902514965235.20507861285228; Sun, 16 Aug 2026 10:48:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wvexa-0008PO-IE; Sun, 16 Aug 2026 13:47: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 1wvexZ-0008Nq-Lb for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:49 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wvexY-0003Cd-6T for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:49 -0400 Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-cbeea240819so1369551a12.1 for ; Sun, 16 Aug 2026 10:47:47 -0700 (PDT) Received: from setun ([223.228.54.80]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-320ead105a9sm28343674eec.31.2026.08.16.10.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Aug 2026 10:47:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786902467; x=1787507267; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=6naBanft5dzX6viSmmU3Uw6eq1ZNfugHG1TUba3f5YE=; b=UCj2BuwBHuVRpl37UJAKBNKdSMLb7tw8OrLuE0fsEWSZHqlpQv6LiAlEjrJcVjZWJM He1qAu7nkE1Cp5E6p/4M9XX81oo7MkgDWwwBloKVHI8Q0UwwKiMOgmBUHrEzH6q9NYoO MPiAzHct30PUe6uYBEfq8HAv4Px/qOpEvgkTWJEj0BIWDsbZdiBff4fxkWuO1W6csYIt 7E08X2OozuEmGTAID3IofiQS/shhA90G9rbVK1bmVwpd17OppIHuPfdYsnuHQp6XxuHi c6mnB4a6j5VZEaCV9C7IbCf6v2qSup6gU44vCL6IOv0JNyOC1/U74lMz8ngKoyGP7835 L5gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786902467; x=1787507267; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=6naBanft5dzX6viSmmU3Uw6eq1ZNfugHG1TUba3f5YE=; b=NcbGb3eZDGFaYPZv3Qft3xBtEZ5Z1GcNDH/3h/y5wLxovXc5HEWRLY4Pph49gguLmE gQca02JxapWVF5UEFKztA9j0BWGbrdZIRIoRgGPKfP7b6uHMkJBCCjZ4UTtGZl0g9g+N glX82WnLHcDsI16n2P8TevPQRxj8xNkuZHd5OPyy8mRR2/xT5i/yOilZ2FVqhWkbg/OK XJt95j4x8lc/bQRvelFFjVc3ZeCHTWl5xO7riOqDf/w98ULZUPHbRpHwDAAW0jN6/VvI +NxkktUtycG+m8Xz/qOBmTuT8V6zpzeNOQMLid3GoDqQZSfkeGdDoQT8md6grwMOoGr9 OAXQ== X-Gm-Message-State: AOJu0YxNoPyid896KrSI+tYBpTnhxbqFchXGtHYVqxkUNRfvKKGk1pPj r5ds2s1qm1x98fmfrEfA9UmoEXEfX5Md5z+Ni9ryeVO156f6/caFM+R2b/QNRQ== X-Gm-Gg: AR+sD12XTUzj/08KZelAAbwVOeJax0YquhptC6obglg2POQ76l5Bcj8eY4QIarmQWLH hwJFPVahBPLtoiSyAGHa3nPdwAA1gD35w/yfgKNcpchQ+DT5csCqP0/NPUKZb5Dqi0uQh0bI7dX LvqcuNRrlIOXyn3b6Vkut31VO4trpJ1RjbWeOaQSSmnflhkwym0iW2cE8sDTWiMA+zo22jODOnv FdsN6m4Vj45q0AMsELBFSvXCkLBePwezrElAX2dv5ElBww28glclUeHvkjEJkMPtV2V/2n3hHCz X5BRL/kRijQrtcugUvK56Vj5+ab6s6qehrVc13OzsEV6wlt5bWfPL7fbvufW/qa845G2j8kGgcH /rTdSD5HK3/Ow0pc3H34vNQ5Z18eB5beyT4cZkiX/VJpdWYwRgUN8co4xq+Et33V3FAImYOk/yK 4Sga4+faKzsS8QPAF9hTtQoKcaLgMPAItLtRFyZ+48MFtO6bKPs3FwR5ORmqDROPPIdvI5QBE5G AbU9YhIR7WE+8o= X-Received: by 2002:a05:6a20:9183:b0:3b4:870e:6f44 with SMTP id adf61e73a8af0-3cc71de5b86mr21332452637.35.1786902466786; Sun, 16 Aug 2026 10:47:46 -0700 (PDT) From: Aadeshveer Singh To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, pbonzini@redhat.com, philmd@mailo.com, lvivier@redhat.com, ayoub@saferwall.com, pierrick.bouvier@oss.qualcomm.com, Aadeshveer Singh , Juraj Marcin Subject: [PATCH v5 10/11] migration/tests: Add test for fast snapshot load Date: Sun, 16 Aug 2026 23:16:30 +0530 Message-ID: <20260816174631.1547811-11-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260816174631.1547811-1-aadeshveer07@gmail.com> References: <20260816174631.1547811-1-aadeshveer07@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=aadeshveer07@gmail.com; helo=mail-pg1-x52f.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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 @gmail.com) X-ZM-MESSAGEID: 1786902516473158500 Content-Type: text/plain; charset="utf-8" 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 --- 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 5118d9dec9..c7e4b05c61 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.55.0 From nobody Tue Aug 25 05:57:27 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1786902501; cv=none; d=zohomail.com; s=zohoarc; b=IV/U3ukxS4rhzp5sgZ1xKbSuTvLyVy58JzUOn2NFhthNZCwrDebnq6yXuAMjdXe+vEZj/ndVbPZnRIzpWfzpcae5lIVzR8JOa4f7kB8/o2BWOS4RXuwRh7Dk++NQ+u7paA76ArfzHejJTP1USnLJzQRWd2FNO9C3+KHiFmw+a0A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786902501; 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=u3GrUm1TBcvSPpyf6hmkJd1nY4lbRyzlWNa4cSw3wVA=; b=HDUHPUDLhgfDDtRJExik5M7pXcqzsHUwrbDBP7def2JctmMZJVkQgLyBhgdf3M59FgypdY1v1DnqlDOg9Nd6RXdQNigINaS9qZUvreibjfEe6uhOPXNW/2p33eKJ2UtGr4PykzAs6+B9qdNWzPFJ7O37W+Z1ylHJlRD4rFV5b3w= 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 1786902501259427.4709152907808; Sun, 16 Aug 2026 10:48:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wvexg-0000JO-3q; Sun, 16 Aug 2026 13:47:56 -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 1wvexe-00009X-Ca for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:54 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wvexc-0003DC-PR for qemu-devel@nongnu.org; Sun, 16 Aug 2026 13:47:54 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-2cc7e86e7aeso28528265ad.2 for ; Sun, 16 Aug 2026 10:47:52 -0700 (PDT) Received: from setun ([223.228.54.80]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-320ead105a9sm28343674eec.31.2026.08.16.10.47.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Aug 2026 10:47:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786902471; x=1787507271; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=u3GrUm1TBcvSPpyf6hmkJd1nY4lbRyzlWNa4cSw3wVA=; b=sOgYhwToriny31lZXMUwVzK/zV5qn6Nt5cxFpGKibcJOddNueXzEaQApOXFLZyvIBw OXyiTvhQvBANLd71djDhOyNls+BER8uk33oTO4SkDU2A9UZ669fyp2qBT4plHRvKgbtk GvxGcj/kuucA7oyWF9U+7yNEQqOfBsJi+NQ3wqSWJbmD6cxBX2++qZhZqxBjWWmO3T4W /vgD0XRRj2tDrO39ODtId5vEUX3Pac07jI76RJrVc1/CJsS4xggJqr7J/rtUMeokeAnF eUysxbIad2ZYyy6jiaDC/Fo0PTmpNN0HkEI6w6vaMc/rl0+sr9GoN8/TtOpbYL88pYaL Ei1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786902471; x=1787507271; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=u3GrUm1TBcvSPpyf6hmkJd1nY4lbRyzlWNa4cSw3wVA=; b=Xn7zhPig3dPA/I6FTVEXiTwVwkPQpuWKCpTfdoJsuLyvg4rFHf83ViWZN9G9TbqSzm 823hhi8Ptar94m7LqmOXkIHigekPGPuD3J7AQKL2J3XyPMHmmX5xgapD2UGgJC/SnYMV gPArvrBAzmi4d2Hah5KWbi4BVYLQXDs/w/nmttkg1u3vqOnKlP5PGl2TLfmiAgT0iGcX v/y108o7G6AZttyx9J7Nzw48UOSVoHPO0c4KacmR8YD6/35OZDgWae1Me3IMQpSv9Uoe kQNPGYizXSEnbZDVTo3Oks8A51B844dURzDJNPTNOS/nwoY+Euu+BEmSWWThbxNtjMS4 GPOg== X-Gm-Message-State: AOJu0YxLR/aXhZz4inwsixDeuHaR3fveQRuPmlj5OozNJCoQYzg20feG dzybtM99OhoVwEjWEqUpwNMP0bp+4G54Aym82N/O8c8XTvPh43Iwmw2XKMKNng== X-Gm-Gg: AR+sD10RGSL1ZbhVAoB6YPqc2Ni4Zwv60WekksULGDjhR3WB1S8MoooZYMEQlLwYl9r nD6tHqy4vP8cgFAc4xuiJMQxpD2c+2wQaNo6C0xOw/WmRJiqfaT9625CB9C52LYaUQzDtqniY1w B4RKWbtRjjCB5yQwvyxqDO6S17vmPFcCo/FRQJGTD9pUAplko0ulyVg2Dk3ePFpaSIERs29qqgA Twh19cj8+OJeCg/Vhai1CvtLhYMXEnTxloYy+AiFrhDqACWF/mH29Hv3nu2+RP6Zr4hnzcIB0YP dixorLrnDOyq6INHJYDmBVM74MiuxGaggqQu1iwjTj6ySSDmeSoiEBvTzQluSZ75IwtdOPF0uXm EXrM3RSR2soXEGbTbql1apeVSsaWCPfNQTF5/dueIxsVhd4N9icDlZKxzJZRdpgugBuMK3VuUzZ 1EAG93j+eMQIIr54/YOTDl5Z9uCARr34vskc2/HcPcDDumXVQAqqWw1inN4pmm1bYLwFBF+GL18 4VlJ6hgT/3bwpo= X-Received: by 2002:a17:902:ce86:b0:2c8:f34c:82c0 with SMTP id d9443c01a7336-2d3b0aeeb6cmr200501005ad.2.1786902471338; Sun, 16 Aug 2026 10:47:51 -0700 (PDT) From: Aadeshveer Singh To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, pbonzini@redhat.com, philmd@mailo.com, lvivier@redhat.com, ayoub@saferwall.com, pierrick.bouvier@oss.qualcomm.com, Aadeshveer Singh Subject: [PATCH v5 11/11] docs/migration: Add documentation for fast snapshot load feature Date: Sun, 16 Aug 2026 23:16:31 +0530 Message-ID: <20260816174631.1547811-12-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260816174631.1547811-1-aadeshveer07@gmail.com> References: <20260816174631.1547811-1-aadeshveer07@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=aadeshveer07@gmail.com; helo=mail-pl1-x62e.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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 @gmail.com) X-ZM-MESSAGEID: 1786902502409158500 Content-Type: text/plain; charset="utf-8" Add documenatation for fast snapshot load covering an overview, the architecture, usage and limitations. Signed-off-by: Aadeshveer Singh Reviewed-by: Peter Xu --- 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 0000000000..fe2361d6fe --- /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 9aef79e7fa..23c2a93173 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.55.0