From nobody Mon Feb 9 17:25:07 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1664887377; cv=none; d=zohomail.com; s=zohoarc; b=EQFYdmmdJw/1T1olOYdq752vSXqIoJvj2wrpKAx7cAQPEMF50M+IH24QdGs/KzojOq5OiYEq92EGMcjY7AiJILWW+qCEZrBpIu3BPDBDjEEKDyqmgvVGZEIc3c+l7QCPieiWUc6+dm5oqdbuABTzeGtiTl9WDAbU6NDy+pYddi4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664887377; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8Ovc7GuAoaC292+B0qn1KXIaWoLN9CJ+YBV1CJdubD4=; b=BC50rNeymVOE4OApVVE37DVyDkClbo3Tz5LtAkhCj3i9OJllij9Oc3tN8I3Mi8EnBsOCJG4FUqRTL8TByuxgJgZpV6hj43iKkZttYdOnTR8vnBFFDlraRV6wIo4Zfi3VkQ4uchLFrx//eKTdL2/ijYnz/7MUX943O1sOBubJPTs= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 166488737742038.02375234945953; Tue, 4 Oct 2022 05:42:57 -0700 (PDT) Received: from localhost ([::1]:43088 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofhGA-0002v4-EN for importer@patchew.org; Tue, 04 Oct 2022 08:42:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofhBE-0006mh-Nd for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:49 -0400 Received: from smtp-out2.suse.de ([2001:67c:2178:6::1d]:49918) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofhBA-0005rw-EQ for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:48 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 488D91F8FE; Tue, 4 Oct 2022 12:37:43 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D371C139EF; Tue, 4 Oct 2022 12:37:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mD79MBYpPGNlRQAAMHmgww (envelope-from ); Tue, 04 Oct 2022 12:37:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1664887063; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8Ovc7GuAoaC292+B0qn1KXIaWoLN9CJ+YBV1CJdubD4=; b=QCcnuC/Rmav/PpZ9rpXNFKi1UBICBBLdTMhIqGHw2J0gSJIt6j8wz9rasI2kaWdVT9+EBk uCpfBtOCV2vSm3emj9PHqDvF2HWslnmyoVF60oWLQGsPIHUwOyK6NG11yK0S6nTsfm6oeg D9QDQ6zhrIBOHw9snUO4mCWCiqphvZg= From: Nikolay Borisov To: dgilbert@redhat.com, berrange@redhat.com Cc: qemu-devel@nongnu.org, jfehlig@suse.com, Claudio.Fontana@suse.com, dfaggioli@suse.com, Nikolay Borisov Subject: [PATCH 10/11] migration: Add support for 'fixed-ram' migration restore Date: Tue, 4 Oct 2022 15:37:32 +0300 Message-Id: <20221004123733.2745519-11-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004123733.2745519-1-nborisov@suse.com> References: <20221004123733.2745519-1-nborisov@suse.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=lists.gnu.org; Received-SPF: pass client-ip=2001:67c:2178:6::1d; envelope-from=nborisov@suse.com; helo=smtp-out2.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1664887378429100001 Content-Type: text/plain; charset="utf-8" Add the necessary code to parse the format changes for 'fixed-ram' capability. One of the more notable changes in behavior is that in the 'fixed-ram' case ram pages are restored in one go rather than constantly looping through the migration stream. Also due to idiosyncrasies of the format I have added the 'ram_migrated' since it was easier to simply return directly from ->load_state rather than introducing more conditionals around the code to prevent ->load_state being called multiple times (from qemu_loadvm_section_start_full/qemu_loadvm_section_part_end i.e. from multiple QEMU_VM_SECTION_(PART|END) flags). Signed-off-by: Nikolay Borisov --- migration/migration.h | 2 + migration/ram.c | 86 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index 9aab1b16f407..7a832d072415 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -96,6 +96,8 @@ struct MigrationIncomingState { bool have_listen_thread; QemuThread listen_thread; =20 + bool ram_migrated; + /* 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/ram.c b/migration/ram.c index 951e6385e71c..cba94d01207c 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4331,6 +4331,81 @@ static int parse_ramblocks(QEMUFile *f, ram_addr_t t= otal_ram_bytes) return ret; } =20 + +static int parse_ramblocks_fixed_ram(QEMUFile *f) +{ + int ret =3D 0; + + while (!ret) { + char id[256]; + RAMBlock *block; + ram_addr_t length; + unsigned long idx; + long num_pages; + int len =3D qemu_get_byte(f); + + qemu_get_buffer(f, (uint8_t *)id, len); + id[len] =3D 0; + length =3D qemu_get_be64(f); + + block =3D qemu_ram_block_by_name(id); + if (block) { + ret =3D parse_ramblock(f, block, length); + if (ret < 0) { + return ret; + } + } else { + error_report("Unknown ramblock \"%s\", cannot accept " + "migration", id); + ret =3D -EINVAL; + continue; + } + + /* 1. read the bitmap size */ + num_pages =3D length >> TARGET_PAGE_BITS; + long bitmap_size =3D qemu_get_be32(f); + + assert(bitmap_size =3D=3D BITS_TO_LONGS(num_pages)*sizeof(unsigned= long)); + + block->pages_offset =3D qemu_get_be64(f); + + /* 2. read the actual bitmap */ + unsigned long *dirty_bitmap =3D g_malloc0(bitmap_size); + if (qemu_get_buffer(f, (uint8_t *)dirty_bitmap, bitmap_size) !=3D = bitmap_size) { + error_report("Error parsing dirty bitmap"); + return -EINVAL; + } + + /* 3. load all pages from the bitmap */ + for (idx =3D find_next_bit(dirty_bitmap, num_pages, 0); idx < num_= pages; + idx =3D find_next_bit(dirty_bitmap, num_pages, idx + 1)) { + + ram_addr_t offset =3D idx << TARGET_PAGE_BITS; + void *host =3D host_from_ram_block_offset(block, offset); + + qemu_get_buffer_at(f, host, TARGET_PAGE_SIZE, + block->pages_offset + offset); + } + + /* Skip pages array */ + qemu_set_offset(f, block->pages_offset + length, SEEK_SET); + + /* Check if this is the last ramblock */ + if (qemu_get_be64(f) =3D=3D RAM_SAVE_FLAG_EOS) { + ret =3D 1; + } else { + /* + * If not, adjust the internal file index to account for the + * previous 64 bit read + */ + qemu_file_skip(f, -8); + ret =3D 0; + } + } + + return ret; +} + /** * ram_load_precopy: load pages in precopy case * @@ -4350,7 +4425,7 @@ static int ram_load_precopy(QEMUFile *f) invalid_flags |=3D RAM_SAVE_FLAG_COMPRESS_PAGE; } =20 - while (!ret && !(flags & RAM_SAVE_FLAG_EOS)) { + while (!ret && !(flags & RAM_SAVE_FLAG_EOS) && !mis->ram_migrated) { ram_addr_t addr; void *host =3D NULL, *host_bak =3D NULL; uint8_t ch; @@ -4422,7 +4497,14 @@ static int ram_load_precopy(QEMUFile *f) =20 switch (flags & ~RAM_SAVE_FLAG_CONTINUE) { case RAM_SAVE_FLAG_MEM_SIZE: - ret =3D parse_ramblocks(f, addr); + if (migrate_fixed_ram()) { + ret =3D parse_ramblocks_fixed_ram(f); + if (ret =3D=3D 1) { + mis->ram_migrated =3D true; + } + } else { + ret =3D parse_ramblocks(f, addr); + } break; =20 case RAM_SAVE_FLAG_ZERO: --=20 2.34.1