From nobody Tue Aug 25 05:12:46 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1785551863; cv=none; d=zohomail.com; s=zohoarc; b=BRzwDm58hT6xQB2zNncSG4qPQhSc3uu5yH0FDNyC6+BQkULNQA1F28TZywrdenTXXHAGIH6/4ZOgwXkh+ArwSgHq+6OcsTghGGOqJuoMKwRrnpz7idyFsPWztiuEqgORXu7DlOawhkNaOVO6T24uaF39n6PKvy1qcBtMR4ED5Jg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785551863; 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=M0lzyPwM940Xr8iUJBQTtpo6xDFVZpAe9k3Ze/FYUnI=; b=SVotg1d/7lWhQHkylEb1vTnDjK4eHB97OwhzCuikq2aFQjRevmipQE5IunCjV+4kmNJ6X8PLWajYnXK7dJksK5Sn+rwyxH+MMhVRr90WlS0Dji+rjDTCMalewmxptMWmJVvja+RokIHnGRL4JHM6LMZ219Vukrjz7O0R1RQG9Bo= 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 1785551863031712.8630916378796; Fri, 31 Jul 2026 19:37:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wpzbK-00016L-8q; Fri, 31 Jul 2026 22:37:26 -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 1wpzbJ-000167-AO for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:37:25 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wpzbH-0002VN-Ci for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:37:25 -0400 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-c9c26a5fb98so982059a12.0 for ; Fri, 31 Jul 2026 19:37:23 -0700 (PDT) Received: from setun ([223.228.61.127]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3153dd4e47dsm15678889eec.3.2026.07.31.19.37.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2026 19:37:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785551842; x=1786156642; 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=M0lzyPwM940Xr8iUJBQTtpo6xDFVZpAe9k3Ze/FYUnI=; b=GFZ8c0AYEBpNtM1gxItVu1fjAOHvnBdaP6Feo6UbQzau/+bJJPAY1yeF04s2Zhaoxi zdH/zqCIemu9oY6T3vHczW9Oyzo5fxlIkpCbhqzBvK6m8z8dUcxwEHlhjLnf9u3dlp2m e98Ascx7XBo9baQ6KZsRvvaW79HMm0HmSbhuY2kKfJDXceuEkaaNhniHjyd6xnpRfa/U uBzdke6rEx57t9Gem1Qgt44q1LbA6B4GkgmNeYGwoHGUllOtgNw+6+ztS6sTRrySmcWb 0TReYPp2q2jsyu9KDuYQ6fGC6jxyJTlAdqi0CrPUe8s6L7fjlGZgqXkX0jcNIa2RP+2c xBDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785551842; x=1786156642; 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=M0lzyPwM940Xr8iUJBQTtpo6xDFVZpAe9k3Ze/FYUnI=; b=MJ8yxNkLvgI1ZUPLtSDdt1E+hlK9cYBdR5j9F+G7eCz7+jrvllFwJYZxPWa+fLaXlC ZyJKnqeLO1q1tySdGMwmIWcmvLT4Z8iCHLMc8WNcmUXUG1caWBp7qsV0mnZiwFqha/N/ g6jKqSnbhKGU4zjlqoU/Zh7f1Bd+9aoouqfOSVRCzT8hvhJDTVUjx0dtkLnXEeXJBwo+ ie184bFDc1xHXyX6Tf8guUpzQTTl5NQuU8Pc7XwPnK9klbStTym85XBuzFazkOdbnMyL dYVF8Hwb7V1QqK5l7++1seyhynRtXphZzrLtGuK+ynMdYgREPXIYLrwXIZii3S7T9Myj PfDw== X-Gm-Message-State: AOJu0Yw1ibwy8N7fmiUwSeyv7yij84kSxIF0ow5k7izOSa3Uhj7PfdMk 0IZ7HCM3RwTC+BfWz3UPEkBZK60GC4FiZXqPYAZWBOAlQJgEPJM3NFzsSO3enseu X-Gm-Gg: AR+sD10luYZFdy2VL1L3jbu8hqbHjzZuMarcOURpaiq7d7SZ40WiSUqcsiVgzvfk27J whsfEznghpZwH1jtjDqnNCtTmzQTvcnRYsnT1b5xpL1dW1VyeGudxUIWUtGAva0QxQEKm0e9MRM 8Hsi8eOwbDHV13ClZdyAdVsA5r5+RYCCutAM+PLJbyc9y058/08QfeZ5mDh9aYEKKr1QwRcmCbb AYAHRTfcKOKJC7j5Ge3mmxSc/tuGvwh2JeagHPxw0YedW1yezydHOhRVEv4oYTBIF5kWDZ0Vqbl 9OGvgstnlTtVEKrSiHcDRN4Hqh2Z5JxqlNmsWA2JHyz4VkROgCvk7ScY8cmlB4ifL0O/oi5P6l/ 1mvrBWNQ7uoEowk+TaHhEIluC5djdbC/F05I5iSkcYbJuhfJi2JtmYeLOYol/FEBCl7SgbRwBlF 8YoNtA7mQ0xiYtkbSr23NGTtNUpsgKr3v8KkKe8tOzUBCZzPEvetwAKlROmdbQE+qN4PLjNQwD6 i/7cGN9ox7UgiWh X-Received: by 2002:a05:6a20:9186:b0:3c3:750f:3cf9 with SMTP id adf61e73a8af0-3c91a777233mr4167726637.11.1785551841802; Fri, 31 Jul 2026 19:37:21 -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 v4 01/11] migration: Propagate error in postcopy setup functions Date: Sat, 1 Aug 2026 08:06:18 +0530 Message-ID: <20260801023628.22665-2-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260801023628.22665-1-aadeshveer07@gmail.com> References: <20260801023628.22665-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::532; envelope-from=aadeshveer07@gmail.com; helo=mail-pg1-x532.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: 1785551865252158500 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:12:46 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1785551868; cv=none; d=zohomail.com; s=zohoarc; b=Yigpf8I11QUv8Sq2fhNvkOzoBN5AQ+3PWFtLB2F/b8QMSOt18Ft86bqhHuU3IZHWLxr8ODupMQ8mEvVfDJboouAxEWRyTBpwWCPCAc8KTLZmYwjdag3V5Ic+jgIj7PWtSvlxp0Af/NycwYoj0uPZo+M7FMlG4TBhGCzaYF4Q4jU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785551868; 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=KiCgApDtw4yhcRGeRuFEJPughcuv9uFM9kRTnY1jClY=; b=AHpOPrBrICjyVVEH+fFivfjDM0XTcFZ26pCu01coUKdPYpBs6yyzf/vmTLA9N7fJJ1ezx00cyJZhQV+zP99bg2X5vyLqYDuGM7/D9pWXZ77Q4AFvvlP/qIRgL8DVVewC3OgePwHZomxdw6q6rLotqBjS9r6d12/wx+mgUTsbd40= 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 1785551868825703.9666639570817; Fri, 31 Jul 2026 19:37:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wpzbS-00019a-BH; Fri, 31 Jul 2026 22:37:34 -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 1wpzbN-000171-ST for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:37:29 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wpzbM-0002Vt-5Y for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:37:29 -0400 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-38125cebfdaso2049301a91.1 for ; Fri, 31 Jul 2026 19:37:27 -0700 (PDT) Received: from setun ([223.228.61.127]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3153dd4e47dsm15678889eec.3.2026.07.31.19.37.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2026 19:37:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785551846; x=1786156646; 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=KiCgApDtw4yhcRGeRuFEJPughcuv9uFM9kRTnY1jClY=; b=Q36TqpYLGjbM6P5W5cMU+vv9MlwrSX8g5yUfhEqnBt9LJ2Dn/Y4x5hL7HSAplkZoxg CeSV/17jCKoIhVIh+L01L4/y/y0PIxILC9tvCzHxkzil2wvhLsVRCFckRPiq1g8dQKxq Ff5+VOPuFxtPhxhj3Wbv+KSyArjL3mqVxhM4Ww7TJAuPCvxepfT4g1NC7Xy7eKMZo82+ AVrWJY/SFYmBZJkG4b6ED40lBLAsJQf1bOwNO261QKIEWyCCYrMrwTTCAFCD05fS+nDU p0ywUNy7ehkusDeQuV/YoCCkVJrJwK00OHInpcFcOn2d8ChdPH4+qLB+tjVafzofZhp2 N3Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785551846; x=1786156646; 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=KiCgApDtw4yhcRGeRuFEJPughcuv9uFM9kRTnY1jClY=; b=deeiF/MMZJAQ8oT0LuXzlKCxgLUm5D3v8PJztEDPxYEoAy4hQvdwcn+qCZJThCf9uh gsFEYoIUtA7UOcFwrjPKSvWy9uJtnvmx+1mkeOYr+UW7RFMABBoZOyc2FhoO/SLmxj6x N6RU2gQHtnjkNAmQIdjnBdBbYC201DePcBapOKZ0hTGwAaorqMOUJALa13kikL3YF2D9 54PUSUI/AHJYfFzkwYHtSRWR8W0MsIdewDLYZ+sx7H6/dACh4VEDBFo8mPd5+7EWniiJ lV5+TNyLGsl1N7B6+yntXn6bEwFEb7RAJDtqN4r1iZejfzTr3wWecvWBePyQZ1aPFn6Z Nslw== X-Gm-Message-State: AOJu0YzDV9YUBx3Fhd/5ihr45ERXvC4okpxiYPdY0YvGGdNZxW/yVn+u N+dCKZCo6DlL88bNiMrxSE6moeHz+Dd2iaQR6ssLhY16VBgrLx+XU8gX5RKjbn85 X-Gm-Gg: AR+sD10gYf3p5z0HVAJAGKBE9/mW414nZUpPRX4KimYoGpIGSyciC0CWF38lolbbcZS N+/lItPW7Dt7mS+LuFxI9s1le9xOyymBY83OolvhpTliieDRaL4Zz8bF0ly9ltp4C6TtKPgP5Ik YJbd7zseAP/GMb53SQyBrAA0b52MY0cpYoiJsfkDTIkXgNZu68HUZut26ZxFvROi75T9fgFwirV I2DOQQhuxLyJiRBZzmReDF5C1M7UW3ApsmTI/SBbzk29FmEFU8hye3BqbB0KG+pVDvPpmBIWpAz EuP+hATLuFSUxCfRPCJwyFgXWVT4famuooSSTzzViXLe2j/eppquVwvMP6AN4xk9/ATQyJ9bjeo hvnFWCDLvS16ZmeH0JwQxOMYJHpFi8HtgIhqBvVkOnbPsiag4Exa4h773V6YflrQGkt7mUA05A4 S6n1QTzNWgsF0tBmSxzCssq79R23iWGg6SmZBKp9MsIbFZm4V0S6HID6/wmKBm8llsKowYRns/+ NQQseJJCbPf9DeYljWj3euGJEE= X-Received: by 2002:a17:90b:4985:b0:38e:4f41:83df with SMTP id 98e67ed59e1d1-38fbc44465emr2110308a91.15.1785551846484; Fri, 31 Jul 2026 19:37:26 -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 v4 02/11] migration: Extract blocktime marking helper Date: Sat, 1 Aug 2026 08:06:19 +0530 Message-ID: <20260801023628.22665-3-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260801023628.22665-1-aadeshveer07@gmail.com> References: <20260801023628.22665-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::102f; envelope-from=aadeshveer07@gmail.com; helo=mail-pj1-x102f.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: 1785551869092158500 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:12:46 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1785551912; cv=none; d=zohomail.com; s=zohoarc; b=aEujbVmIEfL+wIYxnondIJOVTitk3PRTEKY8+AvNGzEbr5Xn9xzdUTt0PlpFb8JDPTIr+n+v0kWmbkybEyu9Uv2LxmLuVVCsVthJHin3IrM7rL3Iee1BEVzH3EYQAh+87y/ju1cFuny16D/MR89kTzHRayHjdqfpzVfqjylbPFg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785551912; 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=izV0tyTtzE48mde8fpzOje+esPQ2rX0ju3Y/H4E2rGw=; b=nEL898hH8wTdggJZTrkHZcRVJk5DzLFm3hIbg38vp7wzkmq9s3Qf9oRfZldLkaMHeUbPKdssNdE6IcbbDVBpgPBXcnpPb7rorR/+5ucdw3qLacDam2+iCww7uZFNlp0xm3n+OZDsWQFLxyo3Pd0dqYwl7GRjwxbmdjJAsk0ghRQ= 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 1785551912756739.944388015797; Fri, 31 Jul 2026 19:38:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wpzbf-0001ID-24; Fri, 31 Jul 2026 22:37: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 1wpzbS-00019w-Of for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:37:37 -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 1wpzbR-0002WO-BA for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:37:34 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-2cc7e86e7aeso16496815ad.2 for ; Fri, 31 Jul 2026 19:37:32 -0700 (PDT) Received: from setun ([223.228.61.127]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3153dd4e47dsm15678889eec.3.2026.07.31.19.37.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2026 19:37:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785551851; x=1786156651; 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=izV0tyTtzE48mde8fpzOje+esPQ2rX0ju3Y/H4E2rGw=; b=XpM8hZraKEOItVFw4KNMOoxGOrFkVZAWw/zKdbi5ZL+e2fa60vdRik6KpdyVMlKiFp PHgwwQibP22oRIrdLTHoOFNW7EQYb7FosPb+D3knvIoY+cIUAmECRv7w6bN0/3n5mKRf cA8v20rjY2C8UGgvKc++VrgrTBrVYxJNHXEfCvVNaiacQo7P/AIUWmrS1oyt8IVhhvyL uQ2DcGYzIIV142XZLy44tWYdmWU+wl026QogGe78G1Pg23SA7H60CnXNC+lYw6cvlijQ 9pwfarPzIcQMgvuogtUIJj/aIfqzf0ABcxzqxFjjhGY7zUECdhieHggGGw3zhgWA8WsJ A8RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785551851; x=1786156651; 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=izV0tyTtzE48mde8fpzOje+esPQ2rX0ju3Y/H4E2rGw=; b=JeaDFo4TsrNF+kbzsExh5cLrStz2crM68CblzI3NUAf/Fu3klUUZVXTCjo+H1xBYN0 kHKkDsTq0uhiE0t7ApnFehSVcTzpO9oPKd8Qt5kchix1xnsiv+YQhkYQCKGOD5WNMsX7 h6V6V2r6tK1O3mKNqCQlkTbmc9a9HttMXicQEWXpgIzTUM/n0jgWlPRKA/DEQ7tHxixV vE05Ng932jp5PiOzmnsM8CJ1A3pimAI7WMwq7UKlFeyQTwnUIHbuSfu2H8pa/STcVorK c2ds2jEQajFAh+KaLK+iEgq4n+6mtr78TYKFJ2GXU52Ea5x7kiEnALWaAa5xnupYmkQk 7lHg== X-Gm-Message-State: AOJu0YzRByNOAxpHlr5nxI+29//Jr92Pk7y98LpJWN6799PRj+OVkLoC JBEMDsEq+AGzSq+X73VeGE5Jba4JEX8w0Yw+/B1Bps1i0bLcUnoQWzmcuYx/K4wt X-Gm-Gg: AR+sD10fQtBk4Q8aR8l9LjdzkaTFo7ObMs6dWCz7xpYpf6MEZzbOGJcp5G0/zK1OIoK 1jUZKju7g+xEaRlQ314pZK08xfgOp6zYfse7nZWP36O+yAgk2KfcOr7LLGrcCwhBNT3Ji+Zl03o MNnhR+j0vz9UYQ0/FvQP/pczSfyXxmGCjYOYHURMrH42Dn4BtalP24zEvAKXeE9BZjSL8nxubVD RSklbehmvMwisHZNGUhA/29vGoEzUMm3VaArgt077b5k+EYnHDPOojRWHuh5PAhZFAANRfwUYm3 qjOntxyQfVIklXOQ5qf918TV9oVS4uD/4SYBjXYrm9nQFtiHj682HDqDyhMSlTQ9JDgHt2mVkdE 4ioqEEmNlwAnSYRkZkeyOWHWNMNfI5FwOCYex06BMQSGe4iQImYD2Zz0snJOHr7mieWCzXsM9LK 7+2E1ONvUIL/Cp3/eBMKf1A8hEPmcrpmg41icSBw0YiRav9q+zGEfCUUanZg+LFlgwX7Jc1k9hn ng4fAL8B5wpORd6XQ== X-Received: by 2002:a05:6a21:111:b0:3c8:e313:8d2a with SMTP id adf61e73a8af0-3c92a9c70dfmr1833690637.43.1785551851065; Fri, 31 Jul 2026 19:37:31 -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 v4 03/11] migration: Rename postcopy_listen_thread_bh Date: Sat, 1 Aug 2026 08:06:20 +0530 Message-ID: <20260801023628.22665-4-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260801023628.22665-1-aadeshveer07@gmail.com> References: <20260801023628.22665-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: 1785551913174158500 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:12:46 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1785551909; cv=none; d=zohomail.com; s=zohoarc; b=j8OAEsmfCjtkEWWzjBRt+rw24FI0DqXdPT8aoHnQXSVFG4cpvEwOW9GHXZzGDvqZ8cGaS/dW41ZFRNDgUdQq6cro07L63KbTfGxE0UYlU//9qmyTPaiunRtWOEUiIkWMgZNJUbxq0TDNVFPLWvFnqQYXnfryQNqxjgwGPJXlJv0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785551909; 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=jIq/nRQkJTnpXSZRT4CeyLWFSbzz88Q5sMkArBGv8Ns=; b=J3UcafEy9IY1X+XyGgHHY+bV/YkrY92LKjqVeg8xEGQXP6xUKs2cX1vn9mmn2+SpUcPQhi4xROqFvBgXdGx/ElHqxNP9t04GdaPnSQajcMT1d1o8BvBjXBOBWcxM/K/Spf9Y3lFb911YvTXPc4tyEy3TvccsGvtu+fYpCDbeI3o= 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 1785551909057964.7760011186767; Fri, 31 Jul 2026 19:38:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wpzbf-0001JB-QK; Fri, 31 Jul 2026 22:37: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 1wpzbX-0001GA-2H for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:37:42 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wpzbV-0002Wq-FO for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:37:38 -0400 Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-38e347638adso2033474a91.0 for ; Fri, 31 Jul 2026 19:37:37 -0700 (PDT) Received: from setun ([223.228.61.127]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3153dd4e47dsm15678889eec.3.2026.07.31.19.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2026 19:37:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785551856; x=1786156656; 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=jIq/nRQkJTnpXSZRT4CeyLWFSbzz88Q5sMkArBGv8Ns=; b=KvEZNJant1LIhYkCCRn5h7FyLclfNDFmwQZt3FFB2/PmGsq20DEfpECNayNv1pLKkG ELSbZ9RyhJQ7nTH/Va9y/MGSOs36TbAXgSYQkMLrAFmwWZEi/Ey2NYMMhMi0UaFcULfB 4p/2KsTsXZ+ztCYHkG9GvVTkzzyo3zJ4CMlM/5guwoG3g6N/QqVuUgWEqIBiJvOhg3wz XRQszd5HY5pSYLNHWuHzpN8HGKFEyxhADjLgXTobRzw1YMfYONF91INmbSBwqs00d78g jz+UDIrmn6+56JsNGQ4FP1xJQWTTn0knzq13luPFJeIENyHk1+ZvOiYnz7/sRUpRITIG PpLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785551856; x=1786156656; 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=jIq/nRQkJTnpXSZRT4CeyLWFSbzz88Q5sMkArBGv8Ns=; b=G+iIZ/hZ8RQsIq9/kagXGTPFCv6LT82c/nk3lSr5TRzP2HETT/ZrZM1KKNV5dP4P2j ImlvO2Y3Z4WYfJh96X/EWKGwfzAGHXYJtP/09b/LeSC3GitgSeZ4ddthrQtIcc0xQAdp jciG14meARsnQUnDFJtwg9gaPRT4mFANK7DQQQkr66pOrPwgL/1hIkvS7kLzkioBqABX l5XrOWlVUxotI0X5Cm5fk4eRYRBO2OSOxj9GxPDQKZHdFMD/cDYD/RJaPgfOxisW8yWU QwFjL5wrYuPoFNpyqaG7opHmorRhWh2QJjkQIRsfg33KITfQ+663TQXMbZ1KoYYUBpbr +SHg== X-Gm-Message-State: AOJu0Yzxb4i39LiVKmhq/l0stM/X6Aa1ElUgF7ZyOYMLMithG7kkgvQP Szrf6QRcYy6YIUTw4uZtuSJGf8moW1n6nRl1kmE3is/JY/tRP1wwhId8LcdaOLPb X-Gm-Gg: AR+sD10ECzZJGYsr+wqiL2zkYIUl87yCq/UEo2CjWK+1IzLRVz/Mb80wNlXK/E9Wz9K Ca6X6QZIpPE21p+qqLhsW6h9YxsUIj8/pTrs9d5dOH24qN3q13WfmjAsBhPbYGBX1+YGQVYgiEF i3ViQxuDDvhhXPluaP6ludGrvzW9A/1ReQwi6m4fxamzxPYFsP+9Rqle5/HGBzLaUow3eBMfedu Q2iCZUxOL/s1/6L+jWm5NwZKeH7mZ3i/b5JoQysxBDMoNrqYwW/z0lf3i7hLLIQ357180qtAUsg hy8agwnGoj//mFmqgfAN4qB1hdgwJg3QwddL1AbfQEmjedRO+AGYtS0OU4Vq7JmErLpU3T+w+sp /yZwQiU4nc4cGKlQ7WCb4roWdiZ47LRYdbDLsTfiGF+Lx2aTbcNO2Yg1RcGsmiPM2k5fYUslHkN WtbrNp6tTkEOdFA5tDHM3S+vUmNSYbPPEkJCPS132j6MmTN+vft3IlbDq/byeGe5uVKL9aHFxbb on/PMiwAlz1UzUr X-Received: by 2002:a17:90b:534e:b0:38e:2aa8:60d0 with SMTP id 98e67ed59e1d1-38fbc598d19mr2111431a91.37.1785551855887; Fri, 31 Jul 2026 19:37:35 -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 v4 04/11] migration: Use file_bmap for RAMBlock during incoming file load Date: Sat, 1 Aug 2026 08:06:21 +0530 Message-ID: <20260801023628.22665-5-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260801023628.22665-1-aadeshveer07@gmail.com> References: <20260801023628.22665-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::1032; envelope-from=aadeshveer07@gmail.com; helo=mail-pj1-x1032.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: 1785551911692158500 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:12:46 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1785551879; cv=none; d=zohomail.com; s=zohoarc; b=f4y6Xdydca+8lR6eEACfvNYT9/yod9bZJG8V2ad94wWh6JykXOMwJXTJKNCwGS0/B3wGXPQqLzfQvxG6vy38NaUAYfCAPydhYyboD66hCjWTLZl92zTRH2iIk+b05y++JS+c3zydkp5XT9UbOiHRTUc4z63On7L/C8LyXnW7sP0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785551879; 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=mRIiN4bf1GyXbgbG6arVWqnbJT+ocIWOAzhCW3OZ2/A=; b=XFcZfvFij/gCKg4gcUyK76XeBMh84JNK3L3QIfIYyBHb7RPMgCa1EAACq4eHfOqRknEqVS0SYynyzCrWwCrnASdX7qqJ6PZgXs8ERSerlYMWVyMFVpzFNqcJAViOR7ICpWlzk1O+kNUcjkO1rCqfL/L7RvIXm4xDoE2AdxdWCEk= 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 1785551879394922.3845124415441; Fri, 31 Jul 2026 19:37:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wpzbh-0001UA-Sq; Fri, 31 Jul 2026 22:37:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wpzbc-0001Hy-Fj for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:37:46 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wpzba-0002XD-9i for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:37:43 -0400 Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-cbe431467e6so111651a12.1 for ; Fri, 31 Jul 2026 19:37:41 -0700 (PDT) Received: from setun ([223.228.61.127]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3153dd4e47dsm15678889eec.3.2026.07.31.19.37.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2026 19:37:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785551861; x=1786156661; 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=mRIiN4bf1GyXbgbG6arVWqnbJT+ocIWOAzhCW3OZ2/A=; b=lexT4aoHHVUduoFMwbZpH8ZrCs9cFjNIUiCYBSmOWDzHoZ2lvgbO3FFTG7AhWBFDdX ml1M4rZPQVV07zLdSQX675t8xQC1qduNjB42zlljmMQM1wn0eOPhSO4hPJJTpcRCFQsN WpIGkWZb0a/h/b2BuW6MtEPTNUkQkNDunb5wnqpeemVXKX2CAUOsrEerD/kZKjef4wvL fOyeXS559nSdjaXAN1LbZYoAtM3b36juEn4JcyeBRGTQcCOK8Qg/tOt626RwOfPKgEcL rbkyN+6wv6TMvGdRayo7feYOo7QhQNVwq2I0EtVL6hfE3IicgTH7I/fGXchi1xbr940Y ozxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785551861; x=1786156661; 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=mRIiN4bf1GyXbgbG6arVWqnbJT+ocIWOAzhCW3OZ2/A=; b=IcW9azbZ0oFV55LSJ66ziUYDaYhqhuW4pKwuZOdunEpvLf8JFfpbxGa5ViD+byU0P3 hD4iGUnI0+Ui5p+iYNKsGDLi7PP5f3coy0jevwCOF/23FQxomBfBCkE8ic54HfAf2I1n vPUG3DbHUVBb4DMyyV+Ul8K+2AOWYYWMwp7+EBu3SYKfzbfDAsdi6/VXms3VLH09lGQm qHKLP1o+0syFQvtzd1ZyEmMbjsF9yDMGWlu0eENPeFXXt9CPSvdcqp9okIoGYErFnN1X R3CP6bNR2r2pd0scx08Ismw4s3Ufpb7beq2cQjV3rzSs2pKxULuJwuOtzcI2o9ZuRMep OoVw== X-Gm-Message-State: AOJu0YwuqtL1zrIW80e4wFxuyFOo1zUJTw/SXeoKBeYcckO4+q1dN573 AsHZcTlPndlF3Q38Y+5XiR0R4215A+rnxhysW7LD0GedI1gu9x6OciGUnyPHzaM7 X-Gm-Gg: AR+sD10aVGdbaTgXdKcnUWUK0jGv461ybL+FiY2LHKiNrZg035DCTtXihvQH/fYB9H+ wqLzGkJOJ4lgm2zx8xi3Zyoykngk7Ith3/gCiD/qy36Bezn0v45CWIER1X25T3ovGk/6hiAb/9H 7WvP+LThoeq0+e19e9WI39ROyLZajTBfGf/3FDUmq31Rivrwm29nUr/lfsJd0uGVsoFopmx2b/x zF7TO8ErptmS/mqjm20uBFlzafhzxfOXpNu25KJZHk2DGi/+nFsWt9qLET2W3zjKFaxyFwLiw8W nvwHrMtR78BvP+v2ZlHA9C3rHN/L3nF8OcV3HbfOM3LWWqoJkRj1qxcqzg2MZUrRbluM8MyzjCM StmbcIOaqyQH/wAKZfTgoe9D4S/te5HFKNIhyqWK2xdABrluMB3rlA/1HUO4IH9Tj+e/rixNzSe D7oyLcbAxbkqhsKkVcojoa4dCH0evcqULtgGPcIso/GOzP7n175LLVXpRE5asbnLfiTVN7m4mUS g99xsvYMzQExb3f X-Received: by 2002:a05:6a21:4c06:b0:3bf:9e85:b423 with SMTP id adf61e73a8af0-3c91a9e1746mr4258320637.34.1785551860793; Fri, 31 Jul 2026 19:37:40 -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 v4 05/11] migration: Make qemu_get_buffer_at() thread-safe Date: Sat, 1 Aug 2026 08:06:22 +0530 Message-ID: <20260801023628.22665-6-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260801023628.22665-1-aadeshveer07@gmail.com> References: <20260801023628.22665-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::52c; envelope-from=aadeshveer07@gmail.com; helo=mail-pg1-x52c.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: 1785551881522158500 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: Juraj Marcin Reviewed-by: Peter Xu --- 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:12:46 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1785551886; cv=none; d=zohomail.com; s=zohoarc; b=RzkMjdzx4j4LoNkw32RIy+A+LnvBJMB+mvURUYxAof2hZlYzWvAWsQ8l5csniaFaxVf/Ydjt372vGMAZj9wPyzbbbh0X9FHYrJ9+udxQqaoLwGyu1mxf3e6Olco14c+nZe8eap+Lh4024mXf0iqLTZkkD3IfNy++umuWdQ4l6vo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785551886; 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=5vvoJt7uuGazpbvBnQG9ExbIA/smYa698BGAb2WHfG0=; b=Bz9wI8Y/8kE0IMYrp53eY9YBOGb8uh/oJbfsRiOkhZgTS/YU+8klbimZ5swpdbx3AnLZca2a6h4kJmA7MoVh5n4ge3tGj8m70RE6Z3GlCUxIqkBc2zNXfB7y6B2prwlQPR6jSm1fU14Xx+LpQwYbqBnItkYLAB2bYSnMUwwRbqY= 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 178555188621943.94868439930394; Fri, 31 Jul 2026 19:38:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wpzbj-0001cU-JH; Fri, 31 Jul 2026 22:37:51 -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 1wpzbh-0001Sk-8p for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:37:49 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wpzbf-0002XS-Cz for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:37:48 -0400 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-3810c5d691bso1502073a91.1 for ; Fri, 31 Jul 2026 19:37:46 -0700 (PDT) Received: from setun ([223.228.61.127]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3153dd4e47dsm15678889eec.3.2026.07.31.19.37.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2026 19:37:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785551865; x=1786156665; 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=5vvoJt7uuGazpbvBnQG9ExbIA/smYa698BGAb2WHfG0=; b=jmIvV6kpFeKoHuLidHmPFmxpXj2ifplumafOWkQ5y104oRO+6n7BzDJ+OC/xlyxLNS MJf4j+Xqape8WeZ9Hb6x6Aqnfk/10kiJuX5frVX+l8//3KOI6d9Jdzr9o0LesnlhPlh1 10w/zvlvTI6FOBqLKjxVVZLbbvTUCmf8ICxMJrcF9flilon4QPVmgTQnAEBQMgrx8hC9 qvnBClV/s+f8cB14cgTwFhh1KNVYV2y9iULr9rvHtWwlWgdd9Hhqo7jxrtKTOrD+lwRP 7TQUaFs7Qo0HXzHJs6g4M0bpo2B2rqiZWpS40yEnD6HNno6wBWcc6NkpdO+UskkMA9Lf cVPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785551866; x=1786156666; 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=5vvoJt7uuGazpbvBnQG9ExbIA/smYa698BGAb2WHfG0=; b=s1+jbYkCs7ilQjpGHfFVEzMAJt0L6/0JHR2UJdpiIys+9eOMxziFZ8shidgGNrqfQQ syx04Uq6x9M2KrTeTRKam+RdIPTTz9KzPJ3UuEsl0AwOpCcpS772FNsJZhpr4lRFsRGj MCUzJh98t+r8odBWenag2kwHQrX87rp+AKzlVzqQU/o4v4HJEdGiIAwlE2bDIGa7pt13 YTP+O+2Hr/I8m3Sy7DkxuX03epo62VqWkqWM+wwU+ibKXqKjZ+rRfUooSTj1V6k94KKA 5Vil3X8e7MibGGsPdC7Jjncyj+UuE9ChP57cCM9SNfexLOvh1mqUmEdSUwLb9+QKohCA PMVA== X-Gm-Message-State: AOJu0YxDhoPXMc3/77OmIJhp8f40D+2opxf6ZTViPHOkQvpIy9wdYqwU OayEw6xU1ukfHrYqfRxf3IR6ZkYVQGYiIiqHqEcj83Fyq6i4wfgYktmbKtt3b/iA X-Gm-Gg: AR+sD13IwEovjZfwZYU9a3JfNNTd9r/N5lF1vuiQvGeTsCWZKkWra/EoXgT/buf1P5n s2Y3lQ/oYahRggB56gkEP8hSLaLhO9r3JNUz5odDB4GJsJ9vQCNRdol3vtdyaDMAFDv9KAHJ/xw WO+JZdibfQhpIx6fNxZ6tp5+SidLOpJ/bKVQ6Ljp+bT7TR6GFTvfJONyuTP2KM7yInh51CYYPj5 5J/IqLxDBfXjgtWewOgVskasEN9cu+UjUCtlttXW+xD+uyCk9iQYO9WJhGz6nPz6hOOgL5foBVO ri71zww1TQU8YPXzv4/dq9KRdhIAErBB9uWVD5zT1OFfsWVUM6ScDGIUUu8mSwKLdMQLhCQp+Tz 8GDgrCfD0P3ZYrKpNL4XuJkP34NnWMWSvHeStrAXXmFw13PWKVNk4/nuMLB7UouOKI5fSiMUR3a Py+p+6F9z9MHarJ4vzGKocXfgBdEfDRDS30GhOC9GrBc1hkXINBo+aOupgZSw30WBkEA/KVn6gA 0mQo1AyHAdSHaag X-Received: by 2002:a17:90b:4b8f:b0:38e:2524:7272 with SMTP id 98e67ed59e1d1-38fbc56c8d6mr1714545a91.39.1785551865582; Fri, 31 Jul 2026 19:37:45 -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 v4 06/11] migration: add RAMBlock field and helper for fast snapshot load Date: Sat, 1 Aug 2026 08:06:23 +0530 Message-ID: <20260801023628.22665-7-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260801023628.22665-1-aadeshveer07@gmail.com> References: <20260801023628.22665-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::1031; envelope-from=aadeshveer07@gmail.com; helo=mail-pj1-x1031.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: 1785551887445158500 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 Reviewed-by: Juraj Marcin --- include/system/ramblock.h | 6 ++++ migration/ram.c | 59 +++++++++++++++++++++++++++++++++++---- 2 files changed, 59 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..734fd90e12 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -263,6 +263,18 @@ 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); + size_t size =3D rb->max_length / qemu_ram_pagesize(rb); + 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 +3774,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 +3798,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 +4218,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 +4495,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 +4546,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:12:46 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1785551898; cv=none; d=zohomail.com; s=zohoarc; b=RFXwK41sfFBjPgpDBieuepUpfpykv7Z5FMHU85zacDp1pDLfg36w7mBxAJp9lDe35MmxkaFXXGLNnrsL3DtbgqNDwv42buy3fAfrOcXoHQhTOCgs5Wv4g1CIl5jlyfURtm2x3Uwg6VFM150EdLHoKSGlNYcRyPgH+wRHpFANnYA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785551898; 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=V0OeYZjdGaY4S9lTtzE4pbuibV2LNEpD2FdO/1gBCT4=; b=RWB1j4xzdNkMfpeaSXdQ/gOLv/fZeUzgkwzjGAbHYDOUqts6YpwhPnpJ3L/pMKNaxdgYGxDwVKxh02P+0ZnLZE0ieBr1B5ektUAL5f6KiYZSKYayMST6a1zguribDSFBSGyeoC85Csle/VefmgEz+95ydgmdkNlaG0msQbfi/Jc= 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 1785551898590571.3713662286569; Fri, 31 Jul 2026 19:38:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wpzbq-0001zc-NM; Fri, 31 Jul 2026 22:38:00 -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 1wpzbm-0001sd-Bj for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:37:54 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wpzbk-0002Y5-5O for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:37:54 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-2cace91f112so17975885ad.0 for ; Fri, 31 Jul 2026 19:37:51 -0700 (PDT) Received: from setun ([223.228.61.127]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3153dd4e47dsm15678889eec.3.2026.07.31.19.37.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2026 19:37:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785551871; x=1786156671; 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=V0OeYZjdGaY4S9lTtzE4pbuibV2LNEpD2FdO/1gBCT4=; b=aYHzxCIQdtmBFnQJ4K2clyaMAPe6PT/Nmhln8LG7PmOrxfN2h9BPlcJlUAHg7tOc9T QMeJDAju1ycDUphfeiEG8QfC49G+qHZzqmobb1IvqolE+mtFiI5C4T08oQv/9shYfnnS kA+BFJEZRpr7RmGQBKVM8mOnEyylsEbj47n5/xhD1ga2E0oQbs6uGsbaRW0EyMpIAPOm gjOkxrZuW33keLHefmVUvnOkLwUi5K/9l6Zw6KZRV94QyZpiua5E8vwJ7Zz6jWDnqE6g wKbPmL8emvV/yGt5wbgTT94YXn3cxGr1CTobp+1rxWna0+T8yhqnWqn87PEoHs1WZ1zd f/LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785551871; x=1786156671; 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=V0OeYZjdGaY4S9lTtzE4pbuibV2LNEpD2FdO/1gBCT4=; b=DLEyZgo7qGvgDxzFrBmwbaQcgj7uefcQ1JidpDzG1AE/7WqVat7r9E3T0DDEGQXaGF 4jmXkR8CYx3cmpLVphBWDTqG4RXhxurnMBRrtsDu+cWud8t0mIKi/dbovwu1BidXbwxH YkpGHVrSCQZTqFmmUJrrr6ZEog14W4kZfp+g0bY49LWVoMkSuF/dvSWRQI/Y0zdgxTGJ KiH3hpbLkZhDnp2Dmx7FVSaLHdvWIv1vCZyFc4I93B3eHVODJYEcbqifz8kap8nnAM+y 8va3UnAX4obv6gUBwZo3sU9TV0cErFrdyS+9Pr79G4njn1UZ+15ak4prU8/c+2iqIV1/ PsZg== X-Gm-Message-State: AOJu0Yw6o4uunaMetmi5qodlwmVkuZYGDyuDO9Kb+oIhog51Y/Jk1n6P oy7Yk7mN23VmtPWqDvEofSS+JvfQgWMHhkk2451wo5zsmYwDNhmvgoIChfjPRs2N X-Gm-Gg: AR+sD13neOmFQk3SAawnLqUxtIazdHS5m6p/LY3wwD+HmXMNpRoAIw1O0SicXzJJuqd B8/xLMcD/HB7quNDlTh+a6mLFHWvJFMkl2NH8enqyaiQQmNXf6Mim1e9HenkZ7viNSSaMinJnYk gUlJzCJ3deLyoLTyw/zXmLmiz97MPjkOE4TQ3edIpT4dk6pIQkKYFPSgIp+KNwud8cCIeqWq1Ko 0Y4kCMG6Crxxg+ijhToidsi0FHAuAcnpeU6/afcpTFzjyLeNJ3YHkWRF+bNvXrm5+J3FM7fjpMi /1+3xj0UrFV22wo7kDwbJQA8yUeqC7Pw+PMO8BftUmvml4nJm4t+kRk5Lyq0GuUOQ87PCSSDCSZ 3HkGpzAhklUk+H3v88ar0/iv0QwkEe7T8RxDrcu+tHu6m4YSH/XetzeIZnVZHrEH/Fg1AS42gNT iSCToSu9nhT/H4FWCsg1UERQpCFOLdWtviBYNkRerhXgHkpcZCrBL8VCLri6KxkA5nifryU3uSv MCHQ8fPHW7txd2n X-Received: by 2002:a05:6a20:ae24:b0:3b3:1c7b:ff7 with SMTP id adf61e73a8af0-3c92a83880cmr1867325637.46.1785551870503; Fri, 31 Jul 2026 19:37:50 -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 v4 07/11] migration: add support for fault thread to load pages from disk Date: Sat, 1 Aug 2026 08:06:24 +0530 Message-ID: <20260801023628.22665-8-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260801023628.22665-1-aadeshveer07@gmail.com> References: <20260801023628.22665-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::631; envelope-from=aadeshveer07@gmail.com; helo=mail-pl1-x631.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: 1785551899337158500 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. 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 | 174 +++++++++++++++++++++++++++++++++++---- 1 file changed, 157 insertions(+), 17 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 2e2c9fae10..1da9c4309b 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -949,6 +949,121 @@ 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 host_page; + size_t 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 + */ + rb_offset =3D ROUND_DOWN(rb_offset, qemu_target_page_size()); + haddr =3D ROUND_DOWN(haddr, qemu_target_page_size()); + host_page =3D rb_offset / qemu_ram_pagesize(rb); + page =3D rb_offset >> qemu_target_page_bits(); + + if (bitmap_test_and_clear_atomic( + rb->pending_bmap, host_page, + MAX(1, qemu_target_page_size() / qemu_ram_pagesize(rb)))) { + if (find_next_bit(rb->file_bmap, page + guest_pages_to_load, page)= =3D=3D + page + guest_pages_to_load) { + /* 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, + 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, + 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 +1425,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 +1467,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 +1536,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 +1638,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:12:46 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1785551903; cv=none; d=zohomail.com; s=zohoarc; b=f6+msAQXsV3D95qKwfEp0flZsQhPdeRX0LGmMHNYzNtrDpeUpDx89KU11po+POL3AHOsTQnZ1kiGqMc/USj60A4Ouv2LkKqyKQgDAXqIN77KN4S24fUJ0GSp77Yr7C2/quf4E+C96pWuXNTkU/mvJ+IVFmF2eJGsCmpJ7N0adHQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785551903; 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=y8HAi0IGJnc6vXFo6rSOmmTTWO6ZRFain0tOHa4BFUI=; b=Amn9ydDWveiNGdlJnIiV2Paoi44kFWlpmPJMugarT0uVwldvdmu2HkWXq3Pgy1dH3AMx3rABn7cWV68Fom+1s4BzSWLHxxIHycX9IGMdIBHX7SXgvxZU1xB/JGIoE6N4QWvXmm1E73idn4i1/M6sN4AJfSGjmjGKsfWL4Gzn7Hw= 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 178555190368958.584869107675445; Fri, 31 Jul 2026 19:38:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wpzby-0002Hs-EA; Fri, 31 Jul 2026 22:38:06 -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 1wpzbr-00024o-3F for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:38:00 -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 1wpzbo-0002YW-Ro for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:37:58 -0400 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-384930ca5e2so1527332a91.3 for ; Fri, 31 Jul 2026 19:37:56 -0700 (PDT) Received: from setun ([223.228.61.127]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3153dd4e47dsm15678889eec.3.2026.07.31.19.37.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2026 19:37:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785551875; x=1786156675; 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=y8HAi0IGJnc6vXFo6rSOmmTTWO6ZRFain0tOHa4BFUI=; b=ngAikm3Y9Bc9MZsqh/aOkJ0/T7mMu6P+DYBgYto1i+r2VlpSqnpAj7l4O6eASgHToP /I4AO94yvoJ9aNctQLkXgoaD+P3eTmbUqj1N8V88Vg9zfnF/RMpBRhYiX5eUW53IgT7c PF4osdZ9TjlomTNPCnBc6hmH8kKMUo0zv2LQXZZ8KglTQhD5OAx4uP8NUycCZH/E4Lnx 6tzZu9NE1XhZfsZhHQDVa1w53ssvg8HlyUK9ww93sojDDNP4008mPSr4ilEiEk4pQaKh SMkalFjgrJLZ6REsLF0Q8FNDlYVOjpA+0tP8iYtfVow9+iRBpCYdhN4v/G4upd/cBHjz JOyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785551875; x=1786156675; 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=y8HAi0IGJnc6vXFo6rSOmmTTWO6ZRFain0tOHa4BFUI=; b=qP56hzCKHAKxEPeA1Etryem/0ApoJbZwIxMnaA8Lb5I+PW1DjX+Tzxr4HA73wNGmlR bMvgQaP9VT3qBYtWYI1w39DjZ3mvBPYYvHHRMxJoBhS9nRekL7+DG5TATu5o/WNd9Ask fNXY9esN/gF8KRXXmrJzx/IhRyTVOi/vgF8VuEteRcHdTWcnkbxcCZFXL7dWqa9wUkH5 dZUK+ZOij+dGDwDJMMhhknrp5wYnlu8GV/f5fVjHtBFcNqUCreQG3LQo2JPhEaHNdZcN ClVR5VgN95e+BiCWUp/mAauLViLt7YOIvTYJ+erMmou7HHpQwC5CHDSIV/tgVR2RZ0yl Qwtg== X-Gm-Message-State: AOJu0Ywp+OEMJDDFt4naJOy/z9C4xvAiHdmM3EO3PfDCGgv9OFke8TgN wM7YiHJUsZHf0rTNz9waXiatcF3G/J1XmO5oAKwdHUdqDN3xCyx/YyE+/K+OlARm X-Gm-Gg: AR+sD13bg4sS4BrzON95aUdlfchap3gVrICDsSaS8VSqscT6j4SktzxPMc5t85Is2/j HdOalnLcP+7B3ToV2pj7KgX/2g5JCe6hqRQldtDHpD+Bb8HM3D4DHu7tm7/Z6NTvjSIe7MGVe2O ZiOIjZmyrQRmOcyQMRbtZ/SQ+jIXOxHIT+i68laYwS8ybWFhisrGkrXLVUBgzp/vpj350ONv03t ydrZZ0V8ka+B1F5gG20cx6irJaS9B+fo56YM5Te6uZdCeoUUDdXnuY4zXLWCVfxuaTDGC7dq9DR RweZbE+JfDymwWR4rb72XBOdvLrPiECQuks6OdlQldzZAUolNcy3XnFiYQoSAAxS/nAWPrMtQ9/ ZIENuG0EpqN4iUCt3rnN9CfvJli44HLcdo0CoJ7kWy/vr2HH1h5rEuXaLrxRid1T05a6d2aRclA zCjzxKwKuWYdXCFzNbb7t5vbxOBBOpkLcOw0N5T1PI1ZVbapcrYcm9fYILK4sRVAidx0AFtT0q3 l8xZvmFFP9OTNot X-Received: by 2002:a17:90b:1c06:b0:38e:ad9d:1161 with SMTP id 98e67ed59e1d1-38fbc0c9bd9mr1870705a91.0.1785551875383; Fri, 31 Jul 2026 19:37:55 -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 v4 08/11] migration: add eager load thread and setup for fast snapshot load Date: Sat, 1 Aug 2026 08:06:25 +0530 Message-ID: <20260801023628.22665-9-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260801023628.22665-1-aadeshveer07@gmail.com> References: <20260801023628.22665-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: 1785551905407158500 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 1da9c4309b..8bfe04523a 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -2395,9 +2395,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:12:46 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1785551915; cv=none; d=zohomail.com; s=zohoarc; b=hYmH+GM2enTSJaJasfzix6ouB81RQqiz7h9yPmECRPGlC8wlQ38m7OitZBYA/DduAHHrBaDHZJiBXYZi9++3/Cm/aP7QHKoqHvtJgJuMiOGdeFRI8CpP/dHImUrwwwxGKru/cKo5EW7kK6fM0jT1liszlmamtPJz0LFV5xNqPgs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785551915; 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=XRnm5RmBx7iEg/dNO7tKTfWv8DxHd4baJ5mHfXaMt9I=; b=JiIoB46NunVzjZ6ifiLCVyGn/ezJ61lXyduMPhu/9xohAXFoj2GSzos9do+WdLs978qK2YY8gafubPXI0jlx8BWMsNA+guxhKDjlr/Bpss4J5HYpjUg9R9AoNKrWgv59SDyFhu03v4/6lNiRp216j+KmogaDU7U4RezGF/qfRlU= 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 1785551915734850.5580868255697; Fri, 31 Jul 2026 19:38:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wpzc3-0002Ps-09; Fri, 31 Jul 2026 22:38: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 1wpzbv-0002GP-JN for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:38:04 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wpzbt-0002Yq-Jr for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:38:03 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-2cc891373e0so17094425ad.2 for ; Fri, 31 Jul 2026 19:38:01 -0700 (PDT) Received: from setun ([223.228.61.127]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3153dd4e47dsm15678889eec.3.2026.07.31.19.37.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2026 19:37:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785551880; x=1786156680; 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=XRnm5RmBx7iEg/dNO7tKTfWv8DxHd4baJ5mHfXaMt9I=; b=E4F7uzko+XAMFS8YaGudJx6FcpkJCDOtHKPXxmqZnkTDUJAgOgHajIm3yr2sLj8oG9 4JbPGOpFYphcVRphkdJ3ebC4ggTOEhNb0yibDS0rFKrtkui0l5/gTK8zrTDryyqC4RWZ WJ3KnU6brzJHLQFmyEC55kU7024pH843ft4iFHrtSBhJPGFY2WDAhVXzwwE7ezYSLEPx pnuk5cmUAJEExHBtfpVtEwUyee5bd+wMQVS2veV16ljwm/5EnEy/uMxEJhyEZHMcRRuF XERQ4WwVOsFgF+KijZikEle9AHN2QEuu8E1/Kiw7MeMedZnE14O76/LsHDVIEAiSgIqt bzvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785551880; x=1786156680; 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=XRnm5RmBx7iEg/dNO7tKTfWv8DxHd4baJ5mHfXaMt9I=; b=Q5+dkVzAbvxxDAXWqHnOK2uSisv8SyVZRXJB7sW/k5doe1WftAt2db6R+63BBhlh7z cAk8Ot1bMBaNKAmS3HRGf8F4EUUEKmRj/uA/b/Tctv+VabmYX1QLWpnqCm6dQeYRTHHJ ebpZhETxywBkd9Ob3ghpKsVKkNJ/TB+lmWAk4o4TrrmRcPApGNH+OhHhma8a2xkkXRLJ Dg6vWzqx3KhIQ0LGKurB8u9wuFenquzuREJeG2t039DptCKD8q02O/9UKcQRvqJN8SNs 1sz3sywHs0dNtbiyRgOqKx8syfawMQHY09HR8hxgtEyaVyOeZqSh8vHmSxXm9PPxvumx kAfg== X-Gm-Message-State: AOJu0YzKwd1ungPe6gR2u6XiadxHcoCqz9LpuQZ9JLI1AFRyjPr9o6uE Z1ZXJU/sS1U3F6tbWGa8yQ/lR6Ccpwt0z0U12tomWccNPJMW727qDkHuk0wsUUxj X-Gm-Gg: AR+sD10oF/R2gqpPU6UZuxaZ6G83l5buHS9mtqNyFp+49NegeuE2L4FzW1snL0ElhXf cOKbdUx9wjGRrz/Gjn1N+xPUm2veaJS2qbFWg8Imtpk0xQ8fZZBs6x0W5F4gHiC8Lu92SUzGpjD 9Wp5QxxGW0mumVw8ajB9aVGtnWIH21gcjHdLIALisrTak2QzHsOlmHqXQhnHQDBC7Ak5PWPY+iN jPsZv8r5+eYe02WCEK98p6jwDDmhZOHO736nOmT1Hge7C8lp5pMunx6W6VMmmyuRHvlePXerZJa /PBH+J/odWm6OdLj7wSgOwzOM9hCQuW7cDdO7L40ngwoZLqZchVuTNXm7ORFmwkxm2k4/axFTLC gDUcxDxx1DzH+Qn2BJfo5XFUuXWG/kHTx+OjORsNoREIhlL7d2FdRgv29b79vRGjNjlZoqOgarD mt4Ir4WkqLADCuo3rEfx4YFrImH3ve48rA8pmwk6FTdfm0hbiB/P4XyyDY5zXMnY6ktmFXKN4Ty VbpMwjAarAPgAR/6Q== X-Received: by 2002:a05:6a21:1bc2:b0:3c3:abd4:ac74 with SMTP id adf61e73a8af0-3c92a8400eamr1916424637.39.1785551880301; Fri, 31 Jul 2026 19:38:00 -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 v4 09/11] migration: update capability conflict test for postcopy-ram+mapped-ram Date: Sat, 1 Aug 2026 08:06:26 +0530 Message-ID: <20260801023628.22665-10-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260801023628.22665-1-aadeshveer07@gmail.com> References: <20260801023628.22665-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::635; envelope-from=aadeshveer07@gmail.com; helo=mail-pl1-x635.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: 1785551917259158500 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. A smoke test exercising this feature has been added further in this series. Signed-off-by: Aadeshveer Singh Reviewed-by: Juraj Marcin Reviewed-by: Peter Xu --- include/qemu/notify.h | 2 ++ 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 +++ 6 files changed, 31 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/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 8bfe04523a..e01ac628f5 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:12:46 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1785551923; cv=none; d=zohomail.com; s=zohoarc; b=ELx+LDm56Kljsym1og8Wv5sq1WEzvIfjRFLSzvMFL2py3jSrRFA/1G6sc02tfXVJjuVeDjehzzNW3wIxYj3eJ51RGqWFz11PF3d9tdlJDJcMT03ypPMXvx104wUHA4ZXklH/Pr5WednQxcRlWshkYkQ5+fAaD/SplEgfYoDEiWs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785551923; 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=Buj700lO1RUwuoSNslVesdLNoDjj+hRS++McAC+2AR4=; b=f81OxgDu8/kWQGMTse7GYKMxtB0AHJ2Yx2RDfveiKhtuC+8JJ1wtLymokagI+aZeszdVPzPNCnyQQuRzEOOg06EeatKw0o0GW7nUOd1OhL9aZQbuALc3tJvjBy3ie+ZseoTmYY57JrEBnzFgJ7ZnlrV4AHka6nI8MhGElLA6niA= 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 1785551923704342.93334631845175; Fri, 31 Jul 2026 19:38:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wpzcM-0002h2-9e; Fri, 31 Jul 2026 22:38:30 -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 1wpzc1-0002Pt-Jf for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:38:10 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wpzc0-0002ZL-5k for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:38:09 -0400 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-cbb662575d3so923361a12.0 for ; Fri, 31 Jul 2026 19:38:06 -0700 (PDT) Received: from setun ([223.228.61.127]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3153dd4e47dsm15678889eec.3.2026.07.31.19.38.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2026 19:38:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785551885; x=1786156685; 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=Buj700lO1RUwuoSNslVesdLNoDjj+hRS++McAC+2AR4=; b=pE378p77xts9aKCuv1q9l8T5L/6nltdRGnE+oucUessT7y6y/QYgRXBB9nkCZjW5qD BNvNW5imA3dUKPwqbSrDMe5kQgsqzWB9+i5x1SDQuUXWF3DLvSVR/308yKVp697qlsnB 1L49kZRtzakwE6B8rfjcrXZv97z+K4HeJy7iv4vBNn87ilTMVWLe+k8Cd8xvqDiOeGoD XSkug4JjLofuNTPVlu7KVjlHtD5sKEU2LKojSWn6qXORzNgcKfQL0SkHcZucryximYKK FJmUbc5tXRuP/1blkIe1yc+F/wOSE8m+dt6QpckBAl88uKZ/14FnubKcV+2C6NfS8Q0r s1Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785551885; x=1786156685; 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=Buj700lO1RUwuoSNslVesdLNoDjj+hRS++McAC+2AR4=; b=AZhJK3n3cRxskMbBB673Halftu46/szvVi8ZJfAOqzTIKb1DszGTFTcdtVEaZsJqTJ ji0AGJ+28621S5fmZvi/3e6KYjckdPA/m4yOjkb32pjcqnaijICJHQvXe3pB//SP74Kj dUwdwTwDvo50a96+cjoqIlnf25RN/CdY3jUarN+LrPtlGw2TtEMgriAn6Eotpqaaj0Pd pV20goDVguN8JiqMCYnk9iiZPHiLeXEBhZ9hDaaNK0MM0RIYvH5N2KnM/alU8/mos14/ Txv7aCtmmPXiiB7Aou+H9k0MP2Y9mYQ9yn4tSdazuddiHB3OcFadNaD7BlhDNn0KLg1q BV8w== X-Gm-Message-State: AOJu0Yx0vlUII0ASxKx6B7AM3WVrjXUT+8ViLiY1YIUj/XVcSxeLlY7n dp3rIVhxOzXoA9TkY7HQoUXjbefqATKxbBMak7FD1MpZkT4Zf0WMhvw+Ck14gA== X-Gm-Gg: AR+sD124Jix9IDTSgtKHZR3vbeDFe6af/7vGqJfy2CXrhvShdWbqMui1uVHtW7iidv4 ebDIarppFV0rbiMl0BMtp40dDNDo1wrlr5e8coMOpdfnbo1FDefI18ue4N4bMxWfcwljov6oR7R W+AeP/xBIpi+usPNd456S/6KYdzDbSXdgvoKbpxO5IrxgMEMC3aI99xdigAYBUSe8eGZjV+P2hE 0upyxC3DJw6sF3QLxX87J5VI/6aCwngk5U6szjSqo75JJIkQJ49Yx/IvwmZyS/dEaNoO6uo4WaZ 4UfNoMuz6cJZAtfR2QOjX57h7VA1MdXNyRB84tp5OFULVCVdn/0rtoMsSwVYx7Cfk1fWPAwa2/m 26T4cYklgh8DPApy2nEhIRDfZsJKoSwsJtAw4tLOuT2jHhjdttWicAydlXUyJ7Aa/KKAMP1vj9j COB2jG0aYo4mm2sY1kSCzclls7jrQTJePEpaAM0k7NLlL6lZJXWBk4oqe4drGEjmQJXFWF0aSuQ mui/qqmGqooxIa+ X-Received: by 2002:a05:6a20:2584:b0:3bf:b885:2fae with SMTP id adf61e73a8af0-3c92aa52cfbmr1871818637.56.1785551885248; Fri, 31 Jul 2026 19:38:05 -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 v4 10/11] migration/tests: Add test for fast snapshot load Date: Sat, 1 Aug 2026 08:06:27 +0530 Message-ID: <20260801023628.22665-11-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260801023628.22665-1-aadeshveer07@gmail.com> References: <20260801023628.22665-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::530; envelope-from=aadeshveer07@gmail.com; helo=mail-pg1-x530.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: 1785551925205158500 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:12:46 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1785551920; cv=none; d=zohomail.com; s=zohoarc; b=nvpy73uUmqj4bTWfQfcEgZK6HD35g9pRbRk0ppm43wLVeiaJWwBY0+1Ro/i4OvrOCYOrrdW8S1SMFfkejVqdMkF7cgTzUKYyelb8jQQRzieCl9ldklag5XOiwXRmg0erVZRVR7PhXD7sbUaCq3xwPH/jA7FNy34QlpB4cD+cJuk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785551920; 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=PNV42ycjQBrAbERsecIeez8mURVQ70RaMpJO6wcrDxo=; b=NQ3kqXEDxFQcmKey4uItQYqYn7iv10ziG+wT7c9HpZR6TO+B8x3mQWasWkvec7PybkC+yAX+Ix64GcRO67iSoYKd5Gg9Zf1wQMYfr5fnJsPIk2vplHVabWTJ7Vhs8Xmd9FzaXStdiFMx1nLuODRpM5ZJOlptD8CTveOev8Vcbek= 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 1785551920424809.6550046538987; Fri, 31 Jul 2026 19:38:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wpzcP-0002oZ-5E; Fri, 31 Jul 2026 22:38: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 1wpzc5-0002TW-9I for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:38:20 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wpzc3-0002a3-KX for qemu-devel@nongnu.org; Fri, 31 Jul 2026 22:38:13 -0400 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-38e347638adso2033687a91.0 for ; Fri, 31 Jul 2026 19:38:11 -0700 (PDT) Received: from setun ([223.228.61.127]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3153dd4e47dsm15678889eec.3.2026.07.31.19.38.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2026 19:38:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785551890; x=1786156690; 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=PNV42ycjQBrAbERsecIeez8mURVQ70RaMpJO6wcrDxo=; b=bvjwdgxZpizVudt3oHPHledYX/2EvvawqxiP8yiLdJxuTVDlKa0bdPuYd4Sv4R0dRf 1rlUB+/a3eNUemmmBzDTQysUZ0SOpDMBMT76ZI96pWU2mgDVh0tYAEyZgLENwgJ3nBlm 3WUAcwlnAPjnXI0Ltn1J05OW0JxAILd8aAi14xz9ZCP/AjTGvDuWWHBu9Lb8QJ6AAMz/ DrQ/+tcP7v5QWPLqpPUgIKdftNwP8gIxCMqd+Tvg7O5lnOqFFLfq+n79ABEUn4iB0Jko HZ86yvyzOAxEfDHaHnBAQtGPsQI6m/PBV8GqWP5RJNtKSvgCz2iyDD70G4e0mGN5FYHF v8Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785551890; x=1786156690; 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=PNV42ycjQBrAbERsecIeez8mURVQ70RaMpJO6wcrDxo=; b=HipebkVA9y72SeC7NSshjbWnw7cLwMfTFlMrvbmmt+yz455nqb8cTYTsUsK1PzAWz/ tD7LgsKMmm3ebeDWfBffxYpp9sbWIeAuo4mCrFw6iXPrcW3CTvHhmCZ75KSxz+wduDhI RrQpawxwEnADrdM/h+06rbZirTfbXevfdv7E6+L8kapii4Pud6n7FNUXCRh1Mblp9FA7 OCb+8HGjaW7ygtugOwxtXD6J+6A4uuhp8QhPjgObaQutGfWVkdyNRLWxxhmMbPi/453x WuQgGqU6EAWJEuZ3hGiv9P54PZJ9jPWR8JJK3UE4TIRDep9NpBR5nx5jHV6PW/Lrm3U0 4mgw== X-Gm-Message-State: AOJu0YzcdKk/ZVGq2hmYpOO7IWy15sPUOP5sqyJCCzE0a9bbP0FVyFie W5AKP+EBFjb4YHLee4jqUlzjV9rWN1DAvZLvTUsNVrGuj/Tx6HXCeZ//Tnmvrw== X-Gm-Gg: AR+sD11qhNMrH0f/xdzuZgaXvAZO3Y+WWRPtgCebDjn8JlS3jTu4yHSi1fQYWwavOjl ioZAePX081lyVb5J/Grn9Q+93ETeF2G49hKb01JMSFeGyrH3onHgf7rLWEVzArSImHx8Wku9IKH jAKBuu4TmqhG3V/P0QENiEAznaHEVdDympy82xvMGJ17Mvv9h1V1cECs1PfCCkXW0TEZTbdxOxl A5QVuU8CWH41Z4NcwgtQFk5rCfVXYkmKBEWpCvalT0cK/SVF2VAMZx46/qFDAAUaygLmkGsRuUz 4V3RBPTMZb2xBYbFBhzB6jl5GRt3KVKfNr0zXkiLvQrN/1O9VNiog7NosRiAYPbJHlov9voYlgR osmvBR63YtHQZtb5bMY8tpW9hAApL2kpNGbncVob3+puPSQskYCWiuZnkWOYwRjww/p05/iZtUc B3Hn+CqQ7LC4rIUveI0YlK/z3hrC9sF0+iuF0nDeeqe0GAEYmTH6Nn5QK7tKkFfzaMZ+9i3OTap ssUpfNefszKDuSS X-Received: by 2002:a17:90b:5403:b0:38d:b36e:9813 with SMTP id 98e67ed59e1d1-38fbc434501mr1955779a91.11.1785551890293; Fri, 31 Jul 2026 19:38:10 -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 v4 11/11] docs/migration: Add documentation for fast snapshot load feature Date: Sat, 1 Aug 2026 08:06:28 +0530 Message-ID: <20260801023628.22665-12-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260801023628.22665-1-aadeshveer07@gmail.com> References: <20260801023628.22665-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::102f; envelope-from=aadeshveer07@gmail.com; helo=mail-pj1-x102f.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: 1785551921203158500 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