From nobody Sat Jul 25 19:29:21 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=1784038675; cv=none; d=zohomail.com; s=zohoarc; b=auoWKt6b7GgiXYQEeLX/Mz8HhpLjuA51F4E42iLIlDjNCUINjTxkMitaf9fb7RdHtrt9525tTFdT4rdFC3LMLOzZ0OJv6dPA7WXxkRlNhbMSR1QPaLQ6Gsrjy6p62G/IHbv38sJ8dgGkIerEVS7Kem+AHiMT5F6Icla2CABGmTQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784038675; 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=DEwZFCuCIRpLTbXq9T/Srj49IsDFq6R+mSkrteH3nSE=; b=OHO6PHKwh7ZW7AxjBpGXJmR64XDdWivo8+Ah0uW4uKFW32OwEXWcOwTVHK2b0nMU/M9D6p8/149iW4jKxtfEiFbTG93+IMZYs7KNqFV2+DXNo0P9yDvY7kVdIAi1kPaP3cPlwDu2AgnLRRjW7BwdMO5IxY9l7ei+nm0Vnb0f7bo= 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 1784038675161728.3592025128672; Tue, 14 Jul 2026 07:17:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjdwI-000659-1V; Tue, 14 Jul 2026 10:16:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wjdwC-000650-QZ for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:16:44 -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 1wjdwA-0002Tq-Vz for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:16:44 -0400 Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-381ed661712so4886663a91.2 for ; Tue, 14 Jul 2026 07:16:42 -0700 (PDT) Received: from setun ([2405:201:502b:3014:cc0c:536:1b1e:6def]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3118ee6091dsm97329733eec.14.2026.07.14.07.16.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 07:16:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784038601; x=1784643401; 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=DEwZFCuCIRpLTbXq9T/Srj49IsDFq6R+mSkrteH3nSE=; b=a3BWUq3r94cUT+lGuqrznuIJOA+WsOcUwQYMdi0J6BQS9QicV/sOUJidfGIWJo4coA n1KK4SDZlzv0lDLiSGg8Kojwpqia1lNwMIvnz5R2PYKkFXT1sGlH2XxFOjOCoJGR/J7+ czcVjyJQpTgzsbNEXOv7K6AuToDKY5CWuEGBiOOb+IxmEDpVx4i1aluDQ6VIcgx/SJqk LWpsCa3Fbp6DKlvBJyOCb0T+PfmBjzZrU/uAi41BrzaCZx8FpenbIhvuCcug1X7FI6hb 4koe+kNe9RsRl0MZtPW41DT7UVNKjvIrTWCgEzdA+WaqPQvSOt5TSQKyr2gdcx8LeHoC X0DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784038601; x=1784643401; 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=DEwZFCuCIRpLTbXq9T/Srj49IsDFq6R+mSkrteH3nSE=; b=BG3A+x5fV6eZg3reul4pbJ2psDUt/RCKUkrhq5zCw5Kgp8LUozi+mXuNr1/ixChG0u quzre16wdnz3lbRu08+UdKUBY6K6vrogIr0xU+Bccrx03R8bvAM7uijU12QP/52N6bIp qD9OVhMI9wakGwxB5CM4zHJQRD1yPpe5M0tVdNOTB8tJ17xcYM2V5NijqnfVnHGvw/2T 4zmfOsjCWmPj00pCloBuYSb/wYNXS65lTzIQDbFhNbrBb5/PjpjHCGFKuWLwOjK4oz1r ELJbRq6ZsIk4T5tNmCW6kt8lvBzHIo+mgQ1s7TXZ622ElFJhoPjiCmChQtLE9TlDejJl hWfA== X-Gm-Message-State: AOJu0YzFCzLqVNS7ESKpQEoESeDvKGQGKRfsOvzfjJlgKvmHKgEszUL5 s+66Fm495kKna5BZQ3ybnwBW8H7YhdQPfBNi1+1GfqBeTgMMC5Y81HRonpzwzNC6 X-Gm-Gg: AfdE7cl1nylRELzQCSCHt6oLQ3C0DeTAVhDZ2ZmHrWPaxtSmDQ1/pP+gSV4ArmQ/uBV eea6GTIWULoyMTiFT9JvAtVW6ZaPzvsPdkCPnjR0FIaXNn6QGTlhtDNW8eg3a3hNF1OzH00GhxA +/kV2R14SjEt26RZYTFeGpOI+AENh4aQTS6RBdfrg/lcFT2ZAKWAUWOo2PNLuRo6S30RUQWfqIz IJmgqJVNPe9tMv/rdPCFp54p8O8yJ0kfwCZh92VHyyw/iohiXWOcImN1XOp1BEA933umgeEcxZN B/V0vtskDG14FuH/0J56A8UQu+LKwqmS56kaPsq2Xv3fJN5sQ01EEZL8S0al4HfJzcy+06LhfOp I6wZpHA2nUPsUTCobxaPAiodK78Z5aiiQVYH/LHmaoxpodd3fSVdyOIuo+av/asqhEtatJ6YTC/ Q2CDRGte0Dzc+FAmX5L1uEMPtE2KzrQdV6sBUVZ6K5lA== X-Received: by 2002:a17:90b:2544:b0:38e:408:9d7d with SMTP id 98e67ed59e1d1-38e1af44e01mr2904530a91.36.1784038600941; Tue, 14 Jul 2026 07:16: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 v3 01/11] migration: Propagate error in postcopy setup functions Date: Tue, 14 Jul 2026 19:45:37 +0530 Message-ID: <20260714141547.1268000-2-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260714141547.1268000-1-aadeshveer07@gmail.com> References: <20260714141547.1268000-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: 1784038676783158500 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 --- 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 Sat Jul 25 19:29:21 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=1784038635; cv=none; d=zohomail.com; s=zohoarc; b=gOG14Td7xCxNSpHAQywpxWm27KduCFHsJlAUI4nkN+8ybamZ2ZCr3rdKJCjidAL5tXJ0hFjoUROMdAlq6WvTB0ccIAMqKyr0wDiXSQovAzGVTsGrDqVAZP7kFKujkKLy624N+yS/KZdv0bTcP9Cz0Ea+gn+TaDyU0BNcspBMkqk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784038635; 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=8ohUxk5Yj8cqgknphQ2n4dasqiuWoigzJbQ6j1A5+s0=; b=cbjaAgrEk2CMV9HRlExLcHoZ0tIkHe8onqKn+Y5uNyBU4MVRUezYf2GbVeT9YFkcrnyOK3pQBR0ZHE6PJO2BbJUvKvCNCioYDGm9N5O9j3kYmjuXqab/9sts02/bdwDn8SEqBSSe762YUDQ8gF74qj3P8rGpFwFT5zO7KL5AfUU= 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 1784038635577653.4897293790025; Tue, 14 Jul 2026 07:17:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjdwJ-00065x-L9; Tue, 14 Jul 2026 10:16:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wjdwH-00065M-BQ for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:16:49 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wjdwF-0002WT-GE for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:16:49 -0400 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-38125cebfdaso1261322a91.1 for ; Tue, 14 Jul 2026 07:16:47 -0700 (PDT) Received: from setun ([2405:201:502b:3014:cc0c:536:1b1e:6def]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3118ee6091dsm97329733eec.14.2026.07.14.07.16.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 07:16:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784038606; x=1784643406; 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=8ohUxk5Yj8cqgknphQ2n4dasqiuWoigzJbQ6j1A5+s0=; b=OIRfGR+MZ6VoXo+hoYdU52OTy0sccbJFDwb2gQUQio0eWiv0wD/OnKD6qv2ggynZDQ /dyYTLufsNviyzy1u2XwR09rG/qLlFWIEfNQECtdJhnSt8g+4SyWqMlQLj1hcBk6oa87 dxLedWNaaR+jf56852DSxFzl0cd8JsJyAOOETzkkXzpP22M1pD8owuCjGuEti4jFpkTH 4wORjQ0Skk/ayTY/Utb6RtqSEmAsnZLy/1tiyTYiS93KUP3IAM1UiZiA1DXx4KlJeO+m hqRo/Ar7XSSpe9HRR1T+CyoeKZzDWkiGG6wOTDWOddpWCbvre7t+Hr5npFmypes2Tx69 vGyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784038606; x=1784643406; 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=8ohUxk5Yj8cqgknphQ2n4dasqiuWoigzJbQ6j1A5+s0=; b=aCyapBHMXDHJf2if6ZrDxe/nALtVVeTdyKiv0/PRKd6iRc3OM3HuiycTEA0KcWgjhq 8yWtQAEn5HrGXI3xo0cvTy62Wi25E6bA5mmWdgGB+g/E6MJDM87rNtUw6aKjvm5wNZ+n vF+SZOwVqsPJnryfrui6S/FZGWuJHYh9C01Zm1h+YNuqMFD4iHD8h/T4wACkClILT60a TgUR1UIuTYgDbVRQCvgRw3c1zC+2WEy83RfoUIAt7OzLBXELAh2HZhvluc6qFEUxtgnK Wz5GeeZpGmK2CeEh3pYBnhTvOLv4DY85ARmWmjVxgOLWHBMR9/2+3HSwxDzU0h/fV+KU n3DQ== X-Gm-Message-State: AOJu0YxZ/FdGBYfX3zQAX7zfDqz2grFYmv9M1b/0jddnVwFiG5EJ9Hdl zgT9YCzvh/5eg93OyBv92PzATz4iWtSXGYiBesvomQLcW80vawCHD/6mmAKheyo6 X-Gm-Gg: AfdE7ckFQOC9GyYzngGzvoSDsDBtLXOcNcrgPnKTAuyhg0Vd9+2roDdHn5dlykb0new 7ZHOL3MZn0mKpbDVIARuWJZZbvJZYwSCBCzLH08IvDs5Mkxn6IXPr3q3iqNLTeeB49jvbB2wCgO ZPKUf74ckikOqiiEmAcEnHqLy8UtzBspfyf2xFHk2KkkxtqOgh4zgg7TWYl/zjSXcYOAYyJQOGy eqDHf02WxmKUzhPDcaAnDy5sgcY/1xkblXZJYL5zC1BX6E6nNg9juMJPSZKQyOI4xsE4d6NYPG1 OssCX2aTOhGnE/xJDRDTNAr0nTIhInux7nlNd4DrvDGgExGaY2Qy6AGhWsVYjRQOE4Kti9vQfBn Sb3Dz74GCF9rLfGRUfQivX2mC0OSzZZRAxg67kpPIamXgScWzTWpkLWS2H/TFkoiVIN0LYq8gdD 2xPYT8GGPr3ttTneY0Bt48XEF3AEMV69t2rDGDXZdXsSUbmmxCDxuL X-Received: by 2002:a17:90b:4f81:b0:387:e0db:3faa with SMTP id 98e67ed59e1d1-38dc7775133mr12097600a91.35.1784038605961; Tue, 14 Jul 2026 07:16: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 v3 02/11] migration: Extract blocktime marking helper Date: Tue, 14 Jul 2026 19:45:38 +0530 Message-ID: <20260714141547.1268000-3-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260714141547.1268000-1-aadeshveer07@gmail.com> References: <20260714141547.1268000-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::1029; envelope-from=aadeshveer07@gmail.com; helo=mail-pj1-x1029.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: 1784038636741158500 Content-Type: text/plain; charset="utf-8" Use new function try_mark_postcopy_blocktime_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 --- 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 Sat Jul 25 19:29:21 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=1784038635; cv=none; d=zohomail.com; s=zohoarc; b=a/wsAJPLzJvb60TC26Mlihst7rmgsJoKrSoTlWB7oDHWRUrWF7W/dJDnmSApeDIeiEAI4/Mu3v7SZeRdSNbAZkAvI6LzF5LrEOdnPJ4DOau4Z71nlfwajRlHTkr2toDJQhVrkVM+WH8D3gnoIOSIYB30fc0B1eScg60N8l23L/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784038635; 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=E28sxMwcOo8i2ZmSpMbygqgIQ2/6HAeSrQI+5niNHCQ=; b=MI+j4OkXMrs2JTsDE1RsDiQMMakGEtaqxkJqAQBuTTqaL2+O/5yEF6VjNZqfopop2JPQgteY9Dy8XTv35lPVuFU28m+seWld8685Du/4Qh1TBZcdN0lEfKXWV6Hx96bGYyBVDJ+pY2Q9GCgK5shW++rDbSmPiHQTFBlU9OKTk/M= 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 1784038635580847.3769756510678; Tue, 14 Jul 2026 07:17:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjdwS-00067U-Ep; Tue, 14 Jul 2026 10:17: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 1wjdwN-00066S-P0 for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:16:56 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wjdwK-0002aY-Mc for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:16:55 -0400 Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-38dfe7eb825so1027568a91.0 for ; Tue, 14 Jul 2026 07:16:52 -0700 (PDT) Received: from setun ([2405:201:502b:3014:cc0c:536:1b1e:6def]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3118ee6091dsm97329733eec.14.2026.07.14.07.16.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 07:16:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784038611; x=1784643411; 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=E28sxMwcOo8i2ZmSpMbygqgIQ2/6HAeSrQI+5niNHCQ=; b=Shly7FztIHo7k2sfwt39NvCaB+yd+xASyK8XustaNToWEbhXb+/5XZRy2v7/5/xphu 6FZ7Lp+aCVd6B9+3fshq97EC72MhXvkhId7KUsJbfCxHiXyZtCIqNkrY+O/P0zCNPxMd hQuScVQ/aviC3ME9oz9IzXp2mm6yqHtvxYPdCsTY58rcx+0hpDtKG3tfY40YVCrtUi6F vjansiykRxTFlqqjM3ecm71QgREv63VLAPQbMuCUyrK3MbxeYqGNjX0qzjTYMdtoQnDp jB2rNTiZETiOGX569yjLs8feJMmex/APNqVq3WJYIuIqEw3rGQ5bU5X/1GC75SVU6PTA MY1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784038611; x=1784643411; 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=E28sxMwcOo8i2ZmSpMbygqgIQ2/6HAeSrQI+5niNHCQ=; b=VJ4JLYdLGh2AtUljk8BSDvk7VmVEKYzvLZH9QcxyugtnrWpAcNkEaf2oTezTM6LWAR 0kLFhNGzZtU94Rqs+6/2ZF2M9aSeuCyZK0a1WgqjJnqPOYpmi/NP479Xc/winbVT2Pro fUgel0XCHYm7IbT6wVnH3rPpVhd26WJkdfISryGqVkIcwGcVD/grcz5rDXhN/HUhgHkD 5TT6IveATnYfcHjfgNTf7ySnwJF8qIZcl1/tssv5Ei9NobrwrrF4PcGpeg9VllcB5M/m q5s/2jio0dPs05CUPkvtyXklfCuHShzB6ZLKZOmmoWMSQgYU+3zPUroP4S4kifgs8ZMV P/Fw== X-Gm-Message-State: AOJu0YyMTUwWV5RHjcPzd454b/QsaRe02M1QYMGp5kQMWtTiZ0yb+nH+ dE3Z4zzLseJOTXzOtgP2TWfhgpwwRrUwoF+pAJwlS4d2+ZXQwbfBWTyZl7bJNj9h X-Gm-Gg: AfdE7ckdpAQR91iz4r/MFcSC4fsZQ8z45cOuQXI7jItDa81W4HYdlLFFOQ6k9fyO3Rg TDAq1qSRmMVeyEO8wotQA/9Z05sGRY00jCyvFmlFaKoa0zE/9Crc5mdz8PuChEXl644SypBr+d8 32yDNS5yNuNEktAKIzav+Cqct3C3koYR3Nt/c3QWDJ6vGNVrqyOESeXj7cn7VcBGrUhLwx7OEZp wJdDGZefYl3GXSfDw08avlaBGoljiQz+PpRvv554aDkXSTwc6MixmWFMA6TkuoVdd9uib9SR5+T zSf+If/ohcprTVkV6PyzIL0Vlhn7xftbUxTQ7AzSaO4Hsm6mCuVmOapSTE23sbdDEuS7EXKYb4N Dv0YnmUiqkk5BfgEv+a/bdyf3taojZe1XWGDZDB5nXoIRtvfxGklEIcCW/t/OE3k8CwywBrIyvM UC2B3yi6frL/lUEHCgdm7WXjntmqcDSn3d8jgfNfRv7w== X-Received: by 2002:a17:90b:5745:b0:381:149:cf91 with SMTP id 98e67ed59e1d1-38dc7778d65mr13201235a91.26.1784038611005; Tue, 14 Jul 2026 07:16:51 -0700 (PDT) From: Aadeshveer Singh To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, pbonzini@redhat.com, philmd@mailo.com, lvivier@redhat.com, ayoub@saferwall.com, pierrick.bouvier@oss.qualcomm.com, Aadeshveer Singh Subject: [PATCH v3 03/11] migration: Rename postcopy_listen_thread_bh Date: Tue, 14 Jul 2026 19:45:39 +0530 Message-ID: <20260714141547.1268000-4-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260714141547.1268000-1-aadeshveer07@gmail.com> References: <20260714141547.1268000-1-aadeshveer07@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=aadeshveer07@gmail.com; helo=mail-pj1-x102c.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1784038636671158500 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 --- 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 Sat Jul 25 19:29:21 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=1784038686; cv=none; d=zohomail.com; s=zohoarc; b=m2P4PxjgU+/QCcu1yp+iiQp1arrVqEg2Wga/6vEP7jPvVDs4rT2iB9ztUcDRlNRZYckHFhtwLd6geGD7R8zcDPlMfQBaotONNB8EfIVp69TltMPmJ8/451wkE9MtuFUjK5FECOudxrB2PgJ2Q3fJb7SdTi9hQXE1hI+0fK5yNu4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784038686; 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=kvprChN59fHuKDQMM7n4kbzrx/TIXJdQx0Uf4S5KvaQ=; b=MxdNx2lc496wg8olkl3sVfUQ5LPDhDAIPi5NvfgUZmPuj3S6cDCVOeUiWKZgoToYwJpjfl3bNhIXIwThMa5eDTk98eDDW7g93Yaf5f/Phsy74CI9JD7GcR1WTum198aD4cE4SqV/N8akqUH8LP6rNiZexJ5vU2UzXbVFI8LdX4c= 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 1784038686849932.0423125764457; Tue, 14 Jul 2026 07:18:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjdwV-00068C-1q; Tue, 14 Jul 2026 10:17:03 -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 1wjdwR-00067M-K2 for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:17:00 -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 1wjdwP-0002b9-Vl for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:16:59 -0400 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-381018b9375so4908146a91.0 for ; Tue, 14 Jul 2026 07:16:57 -0700 (PDT) Received: from setun ([2405:201:502b:3014:cc0c:536:1b1e:6def]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3118ee6091dsm97329733eec.14.2026.07.14.07.16.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 07:16:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784038616; x=1784643416; 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=kvprChN59fHuKDQMM7n4kbzrx/TIXJdQx0Uf4S5KvaQ=; b=kO6RA/rF3dKlzb2kTwHQj+tXBWTf+I847Z011AvU3i2PTjmWwUR9Nmxi7lJZtJ6cXy jIdvn9QWOPUBKCeOiz/D1RpftJ7eotUN3n5XRxf3b+lvAAs9CZSKgyAQlfMbblXaVd5U xsmqcav77+pS3hlmh3M/jwcaUd/M8jzYv591wzSWsiGlWlPthzD5U3nkHtr0k6UDQzT4 8y977uXlw3Sz+yhOwdpTvlpvlDajszcQp8RFp26HWXB79SBIKoS9mnzBG40k2t3m+JkS c3ct5Mc+ukyRd6xFBDdCUrZlhLavHg5DP+ZE2Xo+eXaxYFD+boUJKSgl890JE4P4FrNp pLCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784038616; x=1784643416; 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=kvprChN59fHuKDQMM7n4kbzrx/TIXJdQx0Uf4S5KvaQ=; b=WV6uJLf7krt6WmUXob9Gelv8AdK9OXU2D2Is2mjNpyrlVczgsDmnImhJhT7GxGpuZP Q28XO7sSFeA47dHKkG/dx1x7gt2gMdgGTFnvbKKoiLyTBcDuep2+VHj5GeB5YD5bPYSK mfVyhPYYXZC3QEgp7cUON2tlVK47dwqzBBRa8/wFM3kyr3XosgMHk5mkVMAmN7uvgg+l WHpTIjGwb4gek8YR2lU2i//kF5wLHbzmb7hIFHDvYIJqWC/lcB3/AgnPloP2ZMrFx9hM D1tUL0+FT6u2rTmLgK/65GKQccr0mGJHt1NRfDfoL6ElnjhhJq01iv1Ahe/DPB4wr4Ds ebbg== X-Gm-Message-State: AOJu0YzuOzG+5vX997n2FK1Rxijvw+HeaqERZc6JF0Q9z09WWqDBDKIA XKpSIBQ5WMvhNYiA0KFjjXzMTpqzAamCUkf+CBmPRTGh0z2m18F88O93TlbY9r1A X-Gm-Gg: AfdE7ckloyM/A10U+6jmIJmoQhkwqo7ITdugZp0V3yUmNBqGQV1JrvtFVcf9uU2OHog euFAiTntdaWD9cBU7vigqKMjaam5fQxq2TnHNc7vT457TyYf6xmKwI12zIxvZw2jntrDOOUWOY+ hihXmREv/2ztdaBrKkDk5vpZmjcU4XvPoW9OIrqT946AhwXcpaqo68phBlJfobQgI2ry55O6IwJ E4f9khIJgaYf6aeQJ0lhBZ5f1xVPbULW21EgONxBXj3MAiZ/5ESvxlDoVVBPhRIRBE/QMfLOegy +DVzxXHQ0wZMhlk/cvzScUvetkjscFaNLZzkNEmQ8IhO4/SLK4UfwaIvzsa3y1ij4ap9yAhVsB/ BWRpk35YK1zjPdwRPxZeOSr2RPcifXo83tfRxRDgulpWjq8r477wgi5v8xBwMDJ7S79USgPYdSu MGiF3xl33Gys4huiAmGnvvXmhQ43t3EhHtTcMQBqusxA== X-Received: by 2002:a17:90b:3903:b0:387:df8f:1409 with SMTP id 98e67ed59e1d1-38dc77d8a8fmr12051304a91.42.1784038616520; Tue, 14 Jul 2026 07:16:56 -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 v3 04/11] migration: Use file_bmap for RAMBlock during incoming file load Date: Tue, 14 Jul 2026 19:45:40 +0530 Message-ID: <20260714141547.1268000-5-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260714141547.1268000-1-aadeshveer07@gmail.com> References: <20260714141547.1268000-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: 1784038689208158500 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 --- 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 Sat Jul 25 19:29:21 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=1784038648; cv=none; d=zohomail.com; s=zohoarc; b=UY9IQaIYE1OHMs37UjHIz5ja81c8kLDgTV0WU9ExgyscwpItLMZ4Z9F934eGNfInmFVom4UI+qda/3ti93Ky0FMthB0A1OQOdJLk8zJxR4lTrZdb65bJNyVZyKb7FxVhmoK16r4Ef6gVqrXIjWIBSdiGGfy8twcYJjMLWlVJnLE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784038648; 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=eYsZovgQobkBQ5sRuVVBlvzxAKOeE/rlJyGitsyhKOw=; b=IyHXyvzOo6jmSaGyK2qTEoIE4PFiJzPDg+2e25nqmp8CJQi5ZjAPrBckRzZDU1y+WWrCGTKTnSGqP6q2QbSZzkheUriGXp7w22ZvFVddZXGxnzBaNVBy5vTd9ZoS57JpiQ3paVhCc1N1PbJhslmuTtjMQV+htOnH5rzsZFD9bGI= 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 1784038648237145.3468960706058; Tue, 14 Jul 2026 07:17:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjdwY-00068W-PZ; Tue, 14 Jul 2026 10:17:07 -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 1wjdwW-00068L-Q4 for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:17:05 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wjdwV-0002bu-6n for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:17:04 -0400 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-c85b73ffb52so2369737a12.3 for ; Tue, 14 Jul 2026 07:17:02 -0700 (PDT) Received: from setun ([2405:201:502b:3014:cc0c:536:1b1e:6def]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3118ee6091dsm97329733eec.14.2026.07.14.07.16.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 07:17:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784038621; x=1784643421; 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=eYsZovgQobkBQ5sRuVVBlvzxAKOeE/rlJyGitsyhKOw=; b=QQx0IoL8iu+6xXXMnxpd/h3UvdH3jRyiwIs7U2qKDoMWSAlYuSTdrlQkaxpEotOMic VY+5NFV3vznWniUqHUqDCMavFEnNLdTzXcMxRQkIbGBlAMnTOJyr1zlXb/JDydHYyE1d UuPzbvvYim4AjQtJJ7b4MWfXdtwws24bfhkPLJldhW8T4wb0v1lbzJAwLWwKwKxRdFgR xOc7PR4SfWOsREEAOTqDH/+RefXtkj5g/+U6tCLZAoHcGx9WqOaHk5FImJL3b7P83GDt 48pdTR9l+arwlZ1M9Ulr9yTZqeuZU+zbdJOKI/V/Qs2Q4ZZ7Xm+MsvzL9afTFt7nce0e uesw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784038621; x=1784643421; 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=eYsZovgQobkBQ5sRuVVBlvzxAKOeE/rlJyGitsyhKOw=; b=Xqc6gSYL6p9YNbb/3a7H6DJsl0msZPfDzNkrPVDq6vOnV80RuLPgSjRYIx0NXFITEQ qwCKhF/lyPuK/Y6G5t3Pw+YomC8C5jhKMHrWdEjKD7qR/DOPgjx1VMZBYUoZUMpnwKJD +wqUUwUqkAAWffkXkgm03W9cNOYNLC9O/flOFJDOpHO/FXRrrgj7c32y+cHQpEp6jeb3 6vjHIyZcFr5wqXTcBDnJpp+GurI0cAZk/NxGgzi69KGg0MF9iaVQPPjw9ZDd8oKscqZi oPK+Xk1o8s2wtgUMc8eNJ7aXwUzbMZk5a9yb9E+STSHJHoNKXWVupAAzdDySjGMIriQW 43XA== X-Gm-Message-State: AOJu0YyXWsVfVQ2d4ZwoihbCULSF9EZ+1uxtqHYSwOnoAZJq+ukNOAIM NqLLLrQ4Z5pMVtBCnGNNx/Xe/VtdBlsFavwKmBlL6Kw5Zj+FQgacrTI+fXi738U8 X-Gm-Gg: AfdE7ck7tNhJFWE/WQV7j3TIQdNp8n2uTqisBKQNFxwqhitlT/OsCq/wfaywq/R2lb2 7JPkZFxeH4pk7sCTcAX1PG0IBxreI9r+aoZZVWjF1YQvag/L9cGwfzrPfVYeFbbDBNxV7Dr2A8L tsNL/svEyJutWe8Y5bpJOVK+mc5qjbLzFOZbAVh2AN2sPU7qbEylEoDuCth2BgdVL7s7uHp2arY 8c+9+fd3krR+Z7gdbg+L3Q5q5BEYqKlECEQHSRFBLH7+Saql6i3kXFkwCvOWk+WQX2Gpivmx7aP 6nIfisEexmYd84i0taXGlBFRsZjL63yJzFxWOe+AZZsBiYswBcsZBEPJ2lKjUlhQVmEoJ8ymIz3 U2wrJaejh6HzhO3kSOytxBa+51HZao7A+PCNqxPhxaNTZsKlS1/QQaZX8GUSCRcwKO05kFCIlCM vgchLLxWz7TdFXj5xM7jpZKRVkh9qK/HsaYYzayvh95A== X-Received: by 2002:a05:6300:670e:b0:3c0:9c19:659e with SMTP id adf61e73a8af0-3c110b7ee4fmr15291939637.70.1784038621185; Tue, 14 Jul 2026 07:17:01 -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 v3 05/11] migration: Make qemu_get_buffer_at() thread-safe Date: Tue, 14 Jul 2026 19:45:41 +0530 Message-ID: <20260714141547.1268000-6-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260714141547.1268000-1-aadeshveer07@gmail.com> References: <20260714141547.1268000-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::52a; envelope-from=aadeshveer07@gmail.com; helo=mail-pg1-x52a.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: 1784038650647158500 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. Signed-off-by: Aadeshveer Singh Reviewed-by: Peter Xu --- migration/qemu-file.c | 9 +++------ migration/qemu-file.h | 4 ++-- migration/ram.c | 6 +++--- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index d5a48115bd..0c28c878a9 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -550,17 +550,14 @@ 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) { 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 Sat Jul 25 19:29:21 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=1784038683; cv=none; d=zohomail.com; s=zohoarc; b=DxgLTRVOFfNa17EmEb6NUlpFW3inEoX8HcWvsegkY09Kdfc7UCCpHd4Jribl86FslE0OqwqsW2LAytgvXxwuB4QTHg8gdXy1/5EVbuE+FCVDBbm5RD4mojE/odWcMDKqTqwXcAxUSDEA/8jh7S7V6DGWU6bheMGO/NG4PctmXsY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784038683; 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=3rc6X3QUuPZRks4ZEy0gC68K6c+Nml37luhf4A5r5bs=; b=T83T2HAvpCIkVLrxYnkscpjdEwZ1HPcGe/kysO2y5wTUI1oEsNI7ndAJ+pemL6e3W7NWRDLAl/VVSKebUrP2hj1vEb0KdSyb/fdY6bDWXNxr/31EfmsBON+o81OkfPPEgeXH92KZaxymlBhiUGSmB7ADXHpNxTLWKpPYf+/RB08= 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 1784038683460991.264756699905; Tue, 14 Jul 2026 07:18:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjdwi-0006Gp-Qt; Tue, 14 Jul 2026 10:17:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wjdwb-0006Bb-BV for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:17:10 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wjdwZ-0002cW-L6 for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:17:09 -0400 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-3856d6fbcb3so985837a91.2 for ; Tue, 14 Jul 2026 07:17:07 -0700 (PDT) Received: from setun ([2405:201:502b:3014:cc0c:536:1b1e:6def]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3118ee6091dsm97329733eec.14.2026.07.14.07.17.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 07:17:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784038626; x=1784643426; 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=3rc6X3QUuPZRks4ZEy0gC68K6c+Nml37luhf4A5r5bs=; b=MHpKRJ21Dfpiw7qe/U34qwVzakTPp9V995O/Klw9SG0rDQ1w8Z0P8VVw7OMXp/fIVI rbTGlSsxpd0mGQbaTgrkfsdNqEOBp3SVou/ToXY2sS5FwF+SsEORnJKCIW7CDCcBQrdy Osaals9o/AsbewJnY6rT9lsC9sKsUuSO8IkOtyhH/jFZ26rV3ELWB6CPauvLwfWrqP2+ Pi3Pb03cns14vECN/xk6/6l9u39iY+X/OBLWXnBGdzaHXcIsNZhLXziev9pRHprZz05s vEyvEiiVnHS/Q40jZUXOZpVBhwWxkoxHf5+wY3iznyvQyugEsH5lXv6Rq41+nviFYF5y I9Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784038626; x=1784643426; 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=3rc6X3QUuPZRks4ZEy0gC68K6c+Nml37luhf4A5r5bs=; b=VGsROgvSZViQeV076IYhRS3d5e2C9eWcQfK1hqaTn4N9SQtL1TqFLBToy2saJ+/2sQ 47YI/MKkGGZ+yRm402ywQ7Tr79DrqX6F+/zz7h1wbj/JAdYssSSHR8X3illstjZaUecA 7VxVkrSV638DDFCak48AjJOMNCqkEZjXLGTk2p3hsUw7DJ39TuxbTgKR1zv4Fbc60Nji wEmCS3B9jLlAEb/Nxd99fXfSvEad4F2CKTLxytLsArgTIWDcvvv9oQmV8M8QEMhO6wrB fe3DYMeNCpvUqlEibLcsVFJ+Lc9KEBZoZfvPwCZFMOJCPG8wEmwiEkwOUQ6GBtsWc4C/ 1h/A== X-Gm-Message-State: AOJu0YwLELFbA5jSaiaMRPEzkIDzMuI64IftuRZg6vSiuziS/bxduuo2 Aih7tGOhETeFZAieQz9e3VhNgQVDh1Dm4U/0QNg/dhO6qKo18GxUCdBiYDSqU4U5 X-Gm-Gg: AfdE7cmQ9ezTfEg0Cf0dP4rNFIqM5X6hFMLvDKU/UzJ+1tQamdpGmyfEYE6xf1MskVY TjGQhJfy5tlpzzuNqF5YlWuJJ84UyW9vFkDQ1gFgdO8/T89RR+fkq/w+zri1B34CeqQatqSfL27 Kzn8SOidntpRObIYZZ7nRrdu7Tmv/VwQJiR1mqIZ+W8xYVs9+AOZ6c4FYCC7NukGYeUrybYbVKn xgbTmukjZSN4TQbFlmaYzi8F+1j2r9hmIw0eLbyXrtM9Krk3ZCp/+o+xQidOfJsbtkQp4AMDTxf rW6ANK9XMq8kgiSYQ2iK/hfiZ1R2ka/f4bbXzd7QJpY0rJgRfGu37bgJanHLNvzSnVXQDXYGnhO kslcKevXU2u/RkfrCsEya/Hg7CSSUocr33VMx001f80As5AOseMEb7ak5VWBGg9RBGRsPviAFsM AvwLzF4AtAZDZ2eDLtU7HfbvRRL6690+k8apNsX47WNg== X-Received: by 2002:a17:90b:3d4b:b0:381:1f51:1ff0 with SMTP id 98e67ed59e1d1-38dc782ab85mr12118993a91.2.1784038625965; Tue, 14 Jul 2026 07:17: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 v3 06/11] migration: add RAMBlock field and helper for fast snapshot load Date: Tue, 14 Jul 2026 19:45:42 +0530 Message-ID: <20260714141547.1268000-7-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260714141547.1268000-1-aadeshveer07@gmail.com> References: <20260714141547.1268000-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::1035; envelope-from=aadeshveer07@gmail.com; helo=mail-pj1-x1035.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: 1784038685305158500 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: Peter Xu --- 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..330fceaa43 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_target_page_bits(); + 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 Sat Jul 25 19:29:21 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=1784038704; cv=none; d=zohomail.com; s=zohoarc; b=ReCC8uA1yAcqtACQhmTYiCVvGQ1pfMz+LbzYfq8KZTaqZwGsBySMBSXTTJGcdgvzNksSdRtDLvz4RQFOFx87fuYFG1DBEmkkPcnGIbPBKX7o7epu49nlvs9a1QUso55ibOsZ6UFCZnDIrXhmCd5282WFfsPsC9BrLV4q/5CIpyU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784038704; 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=Tnq9zGOnDlnHudTuQIdRmy2dam2H/yfvlqpu292TAdc=; b=RbMAAyIFiS3f4rOi6VgP/9cYZzvAHeRXJgt6wqd4TV653GoRie3FhNXBxp2+Q99TgqTiNWgNWrg2hknT0D3/sSLfeYUcEtSbhgXcY/QPGFYjxovIRBQIqamW3HxN+FZyYUlSRkoMqU/mil+uPNp0R2fmnJnC8KNI64LFH3FMnVI= 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 1784038704886509.92884300947856; Tue, 14 Jul 2026 07:18:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjdwn-0006Jk-4d; Tue, 14 Jul 2026 10:17:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wjdwf-0006Cc-QY for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:17:16 -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 1wjdwd-0002cz-V7 for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:17:13 -0400 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-ca97d139d5fso3157502a12.0 for ; Tue, 14 Jul 2026 07:17:11 -0700 (PDT) Received: from setun ([2405:201:502b:3014:cc0c:536:1b1e:6def]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3118ee6091dsm97329733eec.14.2026.07.14.07.17.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 07:17:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784038631; x=1784643431; 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=Tnq9zGOnDlnHudTuQIdRmy2dam2H/yfvlqpu292TAdc=; b=XiKK4PBUhoBtSWHPdFgNlbBampdIvZlQd8ofIL1+9J/VWa+vhLzLzZgbq1cMHvmJXx oDpVpj6xjJklaLptq3QUdm6E1gfZOmeGdox8A6W1McQjwe+UdPDh72ncbBBdRBVGdp/J 8gjGHzH2R1k9rsDQrBGEDnI++cazXxUjOON/ZmCMGgGsvtt1xQqGMWKWQtlsq3EHXY1e sa7+0am1osEO1x1z/MKwo156c4pBVBc1JHqeuVe2UbXLrRHWLI4EAER3LJDXOvWGBSpQ mpUqqwlgK6zMpxBUUCKEgqVx49CTDz2cl0oPWgPFCIrf0DtOXt4G9Co77NHdQOl8gvZ8 M1ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784038631; x=1784643431; 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=Tnq9zGOnDlnHudTuQIdRmy2dam2H/yfvlqpu292TAdc=; b=CJI8AqB9NAn8kegPDDURu5VsvhUTRixg1uI4SpmLzEQFNkpUTKRpS4JI0tXnT1b3Kq qIWdjYspgd4mX1dU6fZXWoGWwi1fphXCK7g+QZNTA4Rh8tEKC4fJ2yx9htPp2fce9MD8 VPjPNVh5ZPWm9g4xbhWeBHF3y5ABdnNWrAcvTQ78DGKBFlhgNHPKu4wbHAPJ9dESizS6 /nm0BSwDHxUuI1IuOyvWcC3IFgAwHGyeBY0VDvxEG5M/dZjlJU2dlY0T+RURvpYMuGwS oF8pN8RiLph+A5071ttzKNIptercOKCt7xlYT5offhJH7FWfNZ0QbOnefq05q1gsk0h/ EBMg== X-Gm-Message-State: AOJu0YyYcTD36Bnmk3ru4kb9z1sqHYACeiv+oCOPVJ1wBlD11LpHK8SJ s/WCQtJudUVxx0KVZ7SjNSjNdW+3POSeWZbX7uAvlBNf6U9AbakbOPAPCmVafLZq X-Gm-Gg: AfdE7cn8CMLqI1bVMutbWPqMQ0l6muIGaSg9WBnHPGG0VjRNnpbETIa7CpP2YrzbnC6 veUEte1jR1RUhhxiljrz/v6sSQPqk2xGEalotvv9xBeZgN2N9XP5+C7yC6CU/bR+s12xlWsyc7v ebxuus4tktSRduup2Ge4YJUzobW1SJSF3NZpN4ft062djQHfJ6O+2Jl1ue1a5ThewROLfK+6/bq YGqFhvPVyIYGE6FjiCHA5X43bJ1j+taEC+RZrt+TPQxXajWXxwdWkq7rgm+07Vu0v+xU3iDbSfp XMEvENSOibzar2uK60K+WoxXtp5FTauahA2WCHqOFfj9XxTx7fOsU4sFZ4puKx/Lnvx6cI4bLEV vDKvmOGPs50G+4AKuz8mSbK+lFeEtdQusmcd5yGfdWTJm3GEjr8BPT5GWybGRZcrp6/EHF8EBzp SDJFDBrUh5d8F8kHE7uz7olAVxEdzztdiJmvRlZ4nMmQ== X-Received: by 2002:a05:6a21:e8a:b0:3c1:744:a584 with SMTP id adf61e73a8af0-3c35738f6bamr3165458637.19.1784038630424; Tue, 14 Jul 2026 07:17: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 v3 07/11] migration: add support for fault thread to load pages from disk Date: Tue, 14 Jul 2026 19:45:43 +0530 Message-ID: <20260714141547.1268000-8-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260714141547.1268000-1-aadeshveer07@gmail.com> References: <20260714141547.1268000-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: -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: 1784038707169158500 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 by reading the snapshot file. It uses bitmap_test_and_clear_atomic on pending_bmap to coordinate between threads so each page is loaded exactly once. Non-zero pages are read using qemu_get_buffer_at into a temporary page (for loading page atomically), which is then placed using postcopy_place_page. Zero pages are placed directly using postcopy_place_page_zero. 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. Add function ramblock_file_bitmap_page_is_nonzero() which searches a range of bits corresponding to a page for a set bit. This is just a bit check for normal pages but for hugepages it checks the range to see if any part of page is non zero. Signed-off-by: Aadeshveer Singh --- migration/postcopy-ram.c | 121 +++++++++++++++++++++++++++++++++------ migration/ram.c | 11 +++- migration/ram.h | 2 + 3 files changed, 116 insertions(+), 18 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 2e2c9fae10..723070b5cd 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -949,6 +949,68 @@ int postcopy_wake_shared(struct PostCopyFD *pcfd, pagesize); } =20 +/** + * postcopy_mapped_ram_load_page() - Load a page to given host address. + * @mis: Migration Incoming State. + * @rb: RAMBlock from where page is loaded. + * @rb_offset: Offset of page in RAMBlock. + * @haddr: Base of page where to load in page. + * @channel: Used to identify between threads and use corresponding temp. + * @errp: Set error in case of failure + * + * Load a page from RAMBlock at offset at given host address. Used by post= copy + * ram fault thread and eager thread in fast snapshot load case. + * + * 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; + size_t page; + size_t read; + + page =3D rb_offset / qemu_ram_pagesize(rb); + + if (bitmap_test_and_clear_atomic(rb->pending_bmap, page, 1)) { + if (ramblock_file_bitmap_page_is_nonzero(rb, page)) { + /* + * This can happen concurrently, but it's thread-safe because + * qemu_get_buffer_at() is thread-safe, and the caller will be= using + * different temporary buffers. + */ + read =3D qemu_get_buffer_at(mis->from_src_file, place_source, + qemu_ram_pagesize(rb), + rb->pages_offset + rb_offset, errp); + + if (read !=3D qemu_ram_pagesize(rb)) { + error_prepend(errp, "Could not read page %zu from RAM Bloc= k %s", + page, rb->idstr); + 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; + } + } else { + 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; + } + } + } + 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 +1372,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 +1414,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 +1483,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 +1585,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 */ diff --git a/migration/ram.c b/migration/ram.c index 330fceaa43..4ab8e0e750 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -269,12 +269,21 @@ static void ramblock_pending_bmap_init(void) =20 RAMBLOCK_FOREACH_NOT_IGNORED(rb) { assert(!rb->pending_bmap); - size_t size =3D rb->max_length >> qemu_target_page_bits(); + 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); } } =20 +bool ramblock_file_bitmap_page_is_nonzero(RAMBlock *rb, uint64_t page_idx) +{ + int page_bits =3D qemu_ram_pagesize(rb) / qemu_target_page_size(); + uint64_t bmap_page_start =3D page_idx * page_bits; + uint64_t bmap_page_end =3D bmap_page_start + page_bits; + return find_next_bit(rb->file_bmap, bmap_page_end, bmap_page_start) != =3D + bmap_page_end; +} + static void ramblock_recv_map_init(void) { RAMBlock *rb; diff --git a/migration/ram.h b/migration/ram.h index 41697a7599..7e2eac58d3 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -95,6 +95,8 @@ void ram_handle_zero(void *host, uint64_t size); void ram_transferred_add(uint64_t bytes); void ram_release_page(const char *rbname, uint64_t offset); =20 +bool ramblock_file_bitmap_page_is_nonzero(RAMBlock *rb, uint64_t page_idx); + int ramblock_recv_bitmap_test(RAMBlock *rb, void *host_addr); bool ramblock_recv_bitmap_test_byte_offset(RAMBlock *rb, uint64_t byte_off= set); void ramblock_recv_bitmap_set(RAMBlock *rb, void *host_addr); --=20 2.55.0 From nobody Sat Jul 25 19:29:21 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=1784038683; cv=none; d=zohomail.com; s=zohoarc; b=Be0GsFrt+UZrpr69Jv19jpZBZa+Q6sCYQwJCSdjYDiOgNuadjIXGSC01CB/37q1v8ryJ4CyyDjfh4ayt5Nxm6JIp98TPVReLSFBki9jcDH3+8o3CJn0J4yOS91bZon+yIQpI493zhdcD4zaf2aF3w6tsIFioCeGvcjnovLkGaak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784038683; 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=7hXOeLEBDDuTdVXIHXQYAUgjtSxRd3WpCR6xjiEdoF0=; b=N4/oEQ1NKLxLq7Y9ElVq9gpZPJlwXNvAQyMi0h+W4Sx+S6iGSXB2tVhDtSFGq4+gyyhLhwBkYU1m+K+A37+sQKrtasSw529NhOrvOkoCZ/nh2mR4D/9Vvfp98ihOaQmdrCXYenZlW4QEKRsUjNKVkq65vinc6w/cgPML8d3eeX0= 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 1784038683503831.6932943844016; Tue, 14 Jul 2026 07:18:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjdwo-0006KE-VE; Tue, 14 Jul 2026 10:17:22 -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 1wjdwm-0006Ir-HZ for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:17:20 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wjdwi-0002dQ-KD for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:17:18 -0400 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-c96c92c0980so627520a12.3 for ; Tue, 14 Jul 2026 07:17:16 -0700 (PDT) Received: from setun ([2405:201:502b:3014:cc0c:536:1b1e:6def]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3118ee6091dsm97329733eec.14.2026.07.14.07.17.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 07:17:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784038635; x=1784643435; 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=7hXOeLEBDDuTdVXIHXQYAUgjtSxRd3WpCR6xjiEdoF0=; b=CdaQHvZr9AIhpPwDvDlBnbvVrJG35PoygDmsWPJuc01rDCk89axNBhigFHp0gpEAuc 1ybiSgUIToLxzUNgenMo/RjurrvXGzvbfzkArvwZpVxVS6eH5XcglrZR4gIO44+5mByx sytXfw1y9MgU5PdfRGx2OvBaJXenpcCazwQWPmFwsqdJJ04TY1E4WVeNNSORWRl6reAP oyKubwx+oUyD2bpKqUwRHX/2VQqtG90Jvgc9wx903EubzzuTEblD0kVL24jL9DMAkRDQ DsFy9fr2TsINZPTG7Xg7bGgDn5oVucbO28rYfvi1hMzH2AqtqYYyi+J1clSPlRFlJAge /7Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784038635; x=1784643435; 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=7hXOeLEBDDuTdVXIHXQYAUgjtSxRd3WpCR6xjiEdoF0=; b=laXlHLhD/qP5d2QTvsDaVafdtYcbSy5pqlxLuppJz6AA3FuntbpzUawrhZxf9qlQ21 plJvJiEz1kWvy8ug3eAgNtuQ8ShuEtnVil9ahN7zpK6rSnyW549SsW0pMNFaPjmEUrWa 3vZwCeDZKIZfjnTxUBiq1Mg5ad+vuO1eqDyHapaMGA8PpD1KlTySct4WNoeA/1NvEyLR iuK7rtbF0EbD0KcTU6GLGm0ION0/yI0dr9jvgEWXl2cZQ+HoSNpzyEL1zJH20t7xr4wN IjwTaDwEKkuq+5WLRY/zzq0meH+ENMItnTcxUbmKtfZgok5dfFH95rqne8vgSj/XpeIV D/7w== X-Gm-Message-State: AOJu0YwuNV/BN2Lr60gR6Ua+sU9R4LlgD//7QVmkB9PSZdudnNktpscj YWogbz2PylfjHpQJL/fZNOTLMea5iDyrm0gDkZdJoCZpUehOUDW+aTyLcPlyiLTv X-Gm-Gg: AfdE7cm3Z93yrwIzf5RykPqmq6sdE5ZRTIihxcRoMEgBsl4ahDiURmRVfUQkEB1KKx3 1XHWHuT7oUI9FTHGnzMweymovquLO2UhqrdOaQs8AsvJ1dAYjC2yGM2x4kMaMOCOZXCztIHykUE snhZzNa9EPdr9jTjwl73y+bpd3I9v9pYdZg5YsFvkJ0tUMa///egz4jAnAUlOJUM341Ot5oMVDF UCDncXT6dArDJPD4bLyycHMy8ogWUi26BAWc4labBBs0HIMOqkBu0IOchtZMqcCPVbtDiORj6Ch LM3mGNf2MOB9EIqjXkAlY8ZgZCDiOBJAdG/Lq3TAYFTwIU3kYjuQcHYhAm1b15ZKUIQ19v0mdaw 1BwseDW5xd/k3Bst3Js074/Qryie5ypiAjRgk7GuwjOvRL8s9n4oU6sZI5xUNJWrLmN/6/1lfr/ Iyit22cle7Z2Qgh5tiNtkmWK2R3hUuWFG90I9K6SFJ+A== X-Received: by 2002:a05:6a21:3981:b0:3bf:6c08:2b34 with SMTP id adf61e73a8af0-3c110bb713dmr13525075637.60.1784038635060; Tue, 14 Jul 2026 07:17:15 -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 v3 08/11] migration: add eager load thread and setup for fast snapshot load Date: Tue, 14 Jul 2026 19:45:44 +0530 Message-ID: <20260714141547.1268000-9-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260714141547.1268000-1-aadeshveer07@gmail.com> References: <20260714141547.1268000-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::531; envelope-from=aadeshveer07@gmail.com; helo=mail-pg1-x531.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: 1784038685373158500 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 --- 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 723070b5cd..37eb98b5b1 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -2342,9 +2342,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; + + 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)) { + migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_ACTIVE, + MIGRATION_STATUS_FAILED); + goto out; + } + migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_ACTIVE, + MIGRATION_STATUS_COMPLETED); + +out: + 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 Sat Jul 25 19:29:21 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=1784038671; cv=none; d=zohomail.com; s=zohoarc; b=fjiRwI01KCb8GirC3Nlc4tIwlGfWMUkk3iZby/rjwr9sOViopbukErh/nlMefkiOKU+idBSRWvY9WQmILMmC7Owa6uBuU4u6686KxA02cl7Qs9QtVbat9l8i1HvzwbZ7QfD/xnqZ9Du9dyIW0RmFtzrTJ1bHR47vsL8dFT36TWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784038671; 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=HGHpwp6tqTCl74NPIsgt9M/weDmjWAglJt/Lx4OhHJk=; b=VeNnZiq4DdhC5vDXQ5rBrebsib392+v9Es1BsS1OLE6vkjtkqbjPnmfJaxMy8AnBc6Tc1vPxvz+ZHIXJqRPcqVk1gnibgDw5RXXZ7ExBzAI/cOmqoYfMDA4RbSq8cfh2Pfnm+m1BDxHQAAguHAdBMbqCi1sUmIZykCXN7BgYdsc= 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 1784038671850391.1220330023559; Tue, 14 Jul 2026 07:17:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjdwq-0006OK-Ue; Tue, 14 Jul 2026 10:17:24 -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 1wjdwp-0006KU-DY for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:17:23 -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 1wjdwn-0002e2-7M for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:17:23 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-2ccf2360620so8196605ad.3 for ; Tue, 14 Jul 2026 07:17:20 -0700 (PDT) Received: from setun ([2405:201:502b:3014:cc0c:536:1b1e:6def]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3118ee6091dsm97329733eec.14.2026.07.14.07.17.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 07:17:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784038640; x=1784643440; 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=HGHpwp6tqTCl74NPIsgt9M/weDmjWAglJt/Lx4OhHJk=; b=AnG9IFywakp7d2PVKePaaZnpS/BoBUt44nzUlPxzXnOg3QRYFxQtalaFqk88yjmGxI pPS0EyqrxLsqj1lOCZOYoODFSnFW0U9HGmf1Imi4ZWM6LdHOKSh7dBFPNq0s/+fA4gRM UJiAaBdBVM6aRbp9RZZF4cptmHpTFE9UP0NJHXDtn/M8BdLK63PA7rBXeAr/vp0gZFJ9 /7C+GTpS1KVD4M4hYfMm31mG5KYlrOyxTU6IaofI4HkY/YDh+8gLfHPg3j9XBMEeqTCS Rqc1hi78u6c4Z6//Jgqdc1arVCG/gSBkWxeC4bKAukxMnzSNO59+r7R0gJUBfUpdSvS5 Qo3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784038640; x=1784643440; 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=HGHpwp6tqTCl74NPIsgt9M/weDmjWAglJt/Lx4OhHJk=; b=OiIWWhbd+sh5PBy7xopWjbwxvFNpI+CFViSYIV/NkJAgqspDTZu5F4WK9r1v086hmk VJ8umvF9dDDIVKRx7NY2X1MMRfFoIOtMKNwUb404gh6jAymJq6nzJPEA2uVjEw15JOSa 1TmlnSZC1eMPgWqNzol4m9hB2dCANOoiOk3LH8fFSiFmaOuI3O3KvLEAcFy5vQxvCRGP CE1ecgjE6s/vT6orPquReL2EZpIES4zF+UTl6oyikXfXBwk1GCSBUH718RCwhGnvakC1 +sL4fvK0tLUWgcq47z/HG/Oh4hZ2k0w9VhLffVlZ29RrlTIExdvzrQmyamwXhebOtbgV n9yQ== X-Gm-Message-State: AOJu0Yx9Tyd9qID3jpVDZokiKA7aQ8I84SuIPzd2TXZK9A5CiB/jvavJ meRGDkRjFOSftia+uyhLGfGhtiEE9KBdYUO1xlP2lRq9ffUzJvBq2/pF1bAaG39M X-Gm-Gg: AfdE7cnfDm9LUQHmOkrRx6PVdVwox951WGgi2FOwbk6dFJgnZjhH1ojmXiEsm/rdjF/ taFs4Y1527L++6AOYFv02sq+7JFDAyvrsCpzoU6blmZ/wz1mGRwAZ5kUbTojpweILhvRViXicdT D/xjJO4IVr9w8A73ubIuzCpGYrXuE26d7KF6prjeXF6BmnqPlRWT+afZ4BTLYVwb851W+LC85tM jBjetSbEZL6Jib4XLiG0etTnv3mEtRpsNFzOL01KN3UxPMCyTVZYpE8IEOED12IVk4g3CtrdI6W +If9XchU5wHBna0shiZ8gEs+AIPvbG37jDV8eDBVq760k9MOB2EuXyxL8KDBT3dAGj4C3KWtMQH NIAQv7Djfdtv6RJTtxkJHf9qugLp8nRI0iBKUoVu22T7IJKpnYeNKep/7ccMHul2z1IIC6jKO1R DoGnVxGteYrsPzd3oqQUVZJqUjGsag9Ex35jH8x24BJw== X-Received: by 2002:a17:90b:58f0:b0:387:e0db:bc23 with SMTP id 98e67ed59e1d1-38dc77b82bemr13324655a91.35.1784038639701; Tue, 14 Jul 2026 07:17:19 -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 v3 09/11] migration/tests: remove capability conflict test postcopy-ram+mapped-ram Date: Tue, 14 Jul 2026 19:45:45 +0530 Message-ID: <20260714141547.1268000-10-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260714141547.1268000-1-aadeshveer07@gmail.com> References: <20260714141547.1268000-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: 1784038672840158500 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. A smoke test exercising this feature has been added further in this series. Signed-off-by: Aadeshveer Singh Reviewed-by: Peter Xu --- migration/options.c | 14 ++++++-- tests/qtest/migration/misc-tests.c | 52 ------------------------------ 2 files changed, 12 insertions(+), 54 deletions(-) diff --git a/migration/options.c b/migration/options.c index 5cbfd29099..d61a10f1c4 100644 --- a/migration/options.c +++ b/migration/options.c @@ -727,10 +727,20 @@ bool migrate_caps_check(bool *old_caps, bool *new_cap= s, Error **errp) "Mapped-ram migration is incompatible with xbzrle"); return false; } + } =20 - if (new_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM]) { + if (new_caps[MIGRATION_CAPABILITY_MAPPED_RAM] && + new_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM]) { + if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) { error_setg(errp, - "Mapped-ram migration is incompatible with postcopy= "); + "Multifd is not supported with fast snapshot load"); + return false; + } + + if (new_caps[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT]) { + error_setg( + errp, + "Postcopy Preempt is incompatible with fast snapshot load"= ); return false; } } 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); } --=20 2.55.0 From nobody Sat Jul 25 19:29:21 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=1784038668; cv=none; d=zohomail.com; s=zohoarc; b=nGMvD/W8o+5jPU+OlCfmw5aVfUZDtryLWv9pWIQxuyv7fysSA3HFq89/m+rPcsgsGg2P4nbBjRrs/XdNmHqzMLggn2Ghk9cngJcsq4a79EP5ej2+obG1bP5vPIsq484zzS31TJQsKGHiIj+Fo6gHU6+ggYRbjfrA2vyVEddubwc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784038668; 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=mVg3v8CNWYJMVnr2dIbwlnL/I8cway67EWY5NeiWAvo=; b=eiV9P9yIaMEwXyxETfpj6ESZEHfjup6bJCnb+6+tU4FJgZzYfzBsHCIs6IiTu3gOogWRyZDKsuEJaw2rZdiXxjSe7nerK6NN7XPlcslzZvMzZJBnB9ebLuaDMqmsx2eF3e7Iej3CtHuSi+h7gq62EDdjgCvDXZTeB5AUH1SRTU4= 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 1784038668285400.56988600000693; Tue, 14 Jul 2026 07:17:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjdwx-0006f1-V1; Tue, 14 Jul 2026 10:17:31 -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 1wjdwu-0006XX-9N for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:17:28 -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 1wjdws-0002fA-OM for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:17:28 -0400 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-38511175ad3so3517081a91.2 for ; Tue, 14 Jul 2026 07:17:26 -0700 (PDT) Received: from setun ([2405:201:502b:3014:cc0c:536:1b1e:6def]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3118ee6091dsm97329733eec.14.2026.07.14.07.17.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 07:17:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784038645; x=1784643445; 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=mVg3v8CNWYJMVnr2dIbwlnL/I8cway67EWY5NeiWAvo=; b=Trq+jcGFvPJySROpB/D9HvlBINMugKCHXFHuW6WQGA69tLT3vztc7xt0cYFkwOs46D /q8CtqZwtzVhyRTxn/G45XfIg+rnhlzvjPTwlm3BSgOY/stRXA8/wt2Jgti40oC/he5u WeKStIZEyywbLRzBOcsqWGzTv7qEsZuTjPSVd93HdZ8aDFVVH8Ra7rMCb55PhYWOin/S AL9j4VG5hlYUFlOiCJ969MsdazAxoou+C6eabZ/0HDlb+HAmn/cxNTDJsuif7Hnw+bA4 kTdTt9w95PFDErFXf5ZeBWy1T1uTrQXvXPfKkiuD5wZW2oP/GaFCAZdGHNOUm1yChIRU ojew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784038645; x=1784643445; 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=mVg3v8CNWYJMVnr2dIbwlnL/I8cway67EWY5NeiWAvo=; b=BfPj3214yzLB9fgrWJVqYQAEqCRCSNeMNAJtdQ8G9biMFlsppC9TqLkpwuatDpsvTg yAUHYTzsel04tTwtSm5+tPGQf5vV0fJD2iCM/BstHacCYcewslFmt0DC5caQmYlDi6Au 7cUrbkTKjq8Nh9oh5Bu50x2p8lleQUx761wcHbO7cgHFvH+/3LOMWjl2OX17ce8qmoco /D4uB3JV+adMI95aP7JZLze8q6Z0uQte/bTNBSnfMXacCRxXOWKtIsteWX2NWrxam84s EmMgIeE3nybLCSIutZAcvo8bdZYZ7wxES24O7roSlcTbEGu8kS0L64QzXS3swjrVn8LE GCHA== X-Gm-Message-State: AOJu0Ywvr0m3xkXJ1UNk+RL4ufW8dkVaHM408pf6sCh4dajna1YCH01M oI76ruAHDSk9175D65+TItpkfu8A7bSKARo1J0o1dx71F5ro2dt0eNWX76CNZ/6+ X-Gm-Gg: AfdE7ckxQ2Jy4WW6L5diT8ObrYTtJGRwrmlOgV1deu+6a22EkGUoewselN5k/bGGv7h 04oc3aZ50bNVvHUVJFOK0Leeg1dJT8L0ZUCXSgyy3//AFGOBWYoHJROx1RuO2lf5R/jJSY7hCOb iEIbJ4JFdQSAW/uuxrRxuFg83eQ5VDa8YI6UX83/9bqtKlzKPbGMPxXokb0J/Nzk7oRg2FbojkJ DWpyKApoHDWmX5rSpNFLSaPqGd+0M9ZlwOigOarBqNlIc2Qum/YybYEb8fznr02B3LDIAvEN78H U635rJQqeHH5IGjKVi7MZYzX+R7qRDmpHYRT4SnU7WYrkJEM5sYAtUk8wolSAKilyTgzV5LhDPz bP4ZgMVkomX1YbFAo2t+OqXPV7XP7hFewbQdjsiF/m8IIF11gbxLN/kSFCgb4FhNScOECSq426f azjVT1R7+Zrw7CegKOuTCNExeAoIkOAa1f3umA4MBofxYPmvACeufC X-Received: by 2002:a17:90b:1d52:b0:381:a766:efcb with SMTP id 98e67ed59e1d1-38e1ae5f663mr3032527a91.4.1784038645017; Tue, 14 Jul 2026 07:17:25 -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 v3 10/11] migration/tests: Add test for fast snapshot load Date: Tue, 14 Jul 2026 19:45:46 +0530 Message-ID: <20260714141547.1268000-11-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260714141547.1268000-1-aadeshveer07@gmail.com> References: <20260714141547.1268000-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: 1784038670655158501 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 --- 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 Sat Jul 25 19:29:21 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=1784038701; cv=none; d=zohomail.com; s=zohoarc; b=KFzmQ1/zG2ZXy3yryyHq4+huhlCJ0BtzPVfY4vw374KZ94Ud9afbspNGfsvdKXFS8BFI/tEw9xmxINVII5eV1a4yGrt+Exr1TBPGKO6N/FCu94OF8De2XxKMOUy/6WFP0VUo4eU3sACmepFMIMPL+zSxW6Vjqlro0Hutma5Su8M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784038701; 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=PqcGrgmKaIPs+t/tbnDgVo9n56qGlWCzwPaKeCT0WGA=; b=cGp9EMXA5c7lvSP5xE0bXlBOE+Zh043EkEXE02LR6pQ9Vrk8OtKiFbQDGNwAq6YpzwlHwSLJoNB+6VQL+nFmIUUETOpSoCLJSohuEqQxyyFg76meQ/D5XVk9THnuHhcUmQsxtCnw5M6c5rvumRudS0V6119MQj9rvPNsagx4slY= 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 1784038701266988.5500929983137; Tue, 14 Jul 2026 07:18:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjdxD-0007AU-2b; Tue, 14 Jul 2026 10:17: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 1wjdwy-0006gQ-Lu for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:17:33 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wjdww-0002fq-RU for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:17:32 -0400 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-38dc4553f62so3023016a91.0 for ; Tue, 14 Jul 2026 07:17:30 -0700 (PDT) Received: from setun ([2405:201:502b:3014:cc0c:536:1b1e:6def]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3118ee6091dsm97329733eec.14.2026.07.14.07.17.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 07:17:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784038649; x=1784643449; 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=PqcGrgmKaIPs+t/tbnDgVo9n56qGlWCzwPaKeCT0WGA=; b=lobb+ABQjyXq8+S1hXA6tu5Z7NHMxUHwQKeEgqAhpW0+ecbHiItHF5vs7ZUaXcbBLF xD+1SyCaG8/9TO+dXbPAVQUB3GQNfqzWkAyK4oS5rc27XUIQrctt11Iv7scUxlcuOBWT YgzAZdiZBj6nstJIflP2CaplGjEDZbZtj/S0buY/L8kD14gnI4vPYSyT7xgpva9TRt9k RCah1bj9d7c6nwTVPG61vxVQDKuCab3eiHHNDj8aY8TcpfTzq8Ak2/JrNwcEkCvAk6GT HM78at/13ZWa/AjzuY6NUxcf8U6IKneVgRpyQpwRZGn/szbnwS91WkpFc329rstjVJhN IGog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784038649; x=1784643449; 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=PqcGrgmKaIPs+t/tbnDgVo9n56qGlWCzwPaKeCT0WGA=; b=DjY12wvhhjruhk6160kJAMx9jLLcUPlLeBKpc3UjAarmIaPYaHiYm2yfK5AlvM6DCb UDQR7566dtz2YzKe3xkiaN4d7WMj98zQxm7dFc64vg2E/CHyCEgNkzOh1bQrntrAKe61 uFGXtjPyxSqXf0Vym/5434jbQAmkwNtm1P0YpOC52hWxGZ71DPMzSMj18mj6518xYYBz Nb3ShoTmOxazBQZTvaAAC3VabDgl5wLPWOHLo0YIcX2kLRy9NVggeX9Fb58RflTL8qfn /Y5E6fW+dp/GR59Cv+sfWEc4Sgyf1wuVHy7SfyKngPspifyMMvngZn4ng0vLoCCgA/+I dwhg== X-Gm-Message-State: AOJu0Yzc4Dpcb7C9rKsdAJV5ExpJdZOEn4h2t9xm6v7S1h990AxBwfp2 UFp0LhAxTgQDqx2th+3S45YkYgDbQ1LAvqR/TPdPBqH4uc77j/Y6bYOi+dh8S/xs X-Gm-Gg: AfdE7cleRc2Lfusq4imlJrI2wR/nxxXr7Eyha54mVT+svKGt4BYpqBBshKk9DakAN+v qnR7Hok7Q6JhM0uvXBZEEix0znj7eJY2RjDRH5xuQZfjGyrCLXIaahB0u4UP2T9+p2w4ARMzJid UaAHSfPEkB8j07vJnewJfCiY+3HjyJORvwgskVZA8QPe6URrcH3XhCq3wJAo7wozH6pY38ua36w AF+1rUgGAJQARh2RP3mfvloX3nLhL4sm4pE802fsek6YECzVqFS8OBThVvE3r19TaGmd3rIdA2S tNTVfhh9N5z/ZENQx57AeIFuThwJ5yMmhc2epLTqGuuKpwbv1bJepLWoTT3Ss73kVCG9TSZph+1 4dWMFyeU5QDtMpcR4OLbvqRup97lgFDRqEUISFZhowgNrIJjL5INgI7UjtIodG7nYhuIc01hFB8 ywD6iC48eomNTSx3Np6NQ4eMCxVGeE0ZHFbK8pcpRsNQ== X-Received: by 2002:a17:90b:2e47:b0:35f:b6a1:8d27 with SMTP id 98e67ed59e1d1-38e1af04765mr2489114a91.18.1784038649337; Tue, 14 Jul 2026 07:17:29 -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 v3 11/11] docs/migration: Add documentation for fast snapshot load feature Date: Tue, 14 Jul 2026 19:45:47 +0530 Message-ID: <20260714141547.1268000-12-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260714141547.1268000-1-aadeshveer07@gmail.com> References: <20260714141547.1268000-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::102e; envelope-from=aadeshveer07@gmail.com; helo=mail-pj1-x102e.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: 1784038703093158500 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 --- docs/devel/migration/fast-snapshot-load.rst | 81 +++++++++++++++++++++ docs/devel/migration/features.rst | 1 + 2 files changed, 82 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..0c0dc676fb --- /dev/null +++ b/docs/devel/migration/fast-snapshot-load.rst @@ -0,0 +1,81 @@ +=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 load RAM pages on +demand. 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