From nobody Wed Feb 11 06:00:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1680199547; cv=none; d=zohomail.com; s=zohoarc; b=Lc7R/7uzmTKHi3ZpY2P1biPtPGK42I3AeecxZtfZsyQ4Lty51XannMhmEXEWTfg+ayBWTyKRkstm9i7SVc+U8fmdI2w0fUi4EDO6zcIEWPcYkz0AIZ+TPJ0fiFoVyKQT35jyodatLnbsgBY3k60cCzT6wbwfI9XqBTIk2gYSugA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680199547; 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=kVyI+EulfkwfpRcLylzEL5w/yl20jYRSdQzOG7bfwY4=; b=NFz9ioEn0N03sDyrbrqz74fH2vJF8wkTaqSJSUBENV5/wLWmYGwWdZ14Ls7IZsGLy1GbrCplPIHMCUPEU93IUFMxcIPGlD5nIncdiLmETP8so0J7CZbnlztfuuj75qPzCPtmJ91u+BnduAmMEGUPDgI1PJhiHcu+ou1QJsUcD48= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1680199547459154.78629746334843; Thu, 30 Mar 2023 11:05:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1phwdR-0003IC-65; Thu, 30 Mar 2023 14:04:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1phwdI-0003HE-7u for qemu-devel@nongnu.org; Thu, 30 Mar 2023 14:04:20 -0400 Received: from smtp-out1.suse.de ([2001:67c:2178:6::1c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1phwdG-00024U-C7 for qemu-devel@nongnu.org; Thu, 30 Mar 2023 14:04:19 -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-out1.suse.de (Postfix) with ESMTPS id DA36221A2E; Thu, 30 Mar 2023 18:04:14 +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 922811348E; Thu, 30 Mar 2023 18:04:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GOImFhzPJWQ5GwAAMHmgww (envelope-from ); Thu, 30 Mar 2023 18:04:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1680199454; 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=kVyI+EulfkwfpRcLylzEL5w/yl20jYRSdQzOG7bfwY4=; b=yXuMhPQZ4Z1Eu6ODsgB4D+ffQhYaYenXy8ke8pX7QkqQI5T57kXHlH8nttwV6tJM7AU+Ho L3wkWauCpn8cfILPRk5TjLQJxNwPvHIybe/TJkT9Mawvog3Hq1qBO3iZIICN3tiAyLLFKt 0KUALOBtMYr8Fq9oJKjkUI0b2YPC1AQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1680199454; 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=kVyI+EulfkwfpRcLylzEL5w/yl20jYRSdQzOG7bfwY4=; b=2Zf7kF94laUc6FReMIdKxuYUnlJ/K2qZSKJXScwpJmy1XYqIgzp26+t6e+Hf19BwK000eR 2waTCCnyzyXfjXCQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Claudio Fontana , jfehlig@suse.com, dfaggioli@suse.com, dgilbert@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Juan Quintela , Nikolay Borisov Subject: [RFC PATCH v1 11/26] migration: Refactor precopy ram loading code Date: Thu, 30 Mar 2023 15:03:21 -0300 Message-Id: <20230330180336.2791-12-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230330180336.2791-1-farosas@suse.de> References: <20230330180336.2791-1-farosas@suse.de> 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::1c; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1680199548745100003 Content-Type: text/plain; charset="utf-8" From: Nikolay Borisov To facilitate the implementation of the 'fixed-ram' migration restore, factor out the code responsible for parsing the ramblocks headers. This also makes ram_load_precopy easier to comprehend. Signed-off-by: Nikolay Borisov Signed-off-by: Fabiano Rosas --- migration/ram.c | 142 +++++++++++++++++++++++++++--------------------- 1 file changed, 80 insertions(+), 62 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 56f0f782c8..5c085d6154 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4319,6 +4319,83 @@ void colo_flush_ram_cache(void) trace_colo_flush_ram_cache_end(); } =20 +static int parse_ramblock(QEMUFile *f, RAMBlock *block, ram_addr_t length) +{ + int ret =3D 0; + /* ADVISE is earlier, it shows the source has the postcopy capability = on */ + bool postcopy_advised =3D migration_incoming_postcopy_advised(); + + assert(block); + + if (!qemu_ram_is_migratable(block)) { + error_report("block %s should not be migrated !", block->idstr); + ret =3D -EINVAL; + } + + if (length !=3D block->used_length) { + Error *local_err =3D NULL; + + ret =3D qemu_ram_resize(block, length, &local_err); + if (local_err) { + error_report_err(local_err); + } + } + /* For postcopy we need to check hugepage sizes match */ + if (postcopy_advised && migrate_postcopy_ram() && + block->page_size !=3D qemu_host_page_size) { + uint64_t remote_page_size =3D qemu_get_be64(f); + if (remote_page_size !=3D block->page_size) { + error_report("Mismatched RAM page size %s " + "(local) %zd !=3D %" PRId64, block->idstr, + block->page_size, remote_page_size); + ret =3D -EINVAL; + } + } + if (migrate_ignore_shared()) { + hwaddr addr =3D qemu_get_be64(f); + if (ramblock_is_ignored(block) && + block->mr->addr !=3D addr) { + error_report("Mismatched GPAs for block %s " + "%" PRId64 "!=3D %" PRId64, block->idstr, + (uint64_t)addr, + (uint64_t)block->mr->addr); + ret =3D -EINVAL; + } + } + ram_control_load_hook(f, RAM_CONTROL_BLOCK_REG, block->idstr); + + return ret; +} + +static int parse_ramblocks(QEMUFile *f, ram_addr_t total_ram_bytes) +{ + int ret =3D 0; + + /* Synchronize RAM block list */ + while (!ret && total_ram_bytes) { + char id[256]; + RAMBlock *block; + ram_addr_t length; + 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); + } else { + error_report("Unknown ramblock \"%s\", cannot accept " + "migration", id); + ret =3D -EINVAL; + } + total_ram_bytes -=3D length; + } + + return ret; +} + /** * ram_load_precopy: load pages in precopy case * @@ -4333,14 +4410,13 @@ static int ram_load_precopy(QEMUFile *f) { MigrationIncomingState *mis =3D migration_incoming_get_current(); int flags =3D 0, ret =3D 0, invalid_flags =3D 0, len =3D 0, i =3D 0; - /* ADVISE is earlier, it shows the source has the postcopy capability = on */ - bool postcopy_advised =3D migration_incoming_postcopy_advised(); + if (!migrate_use_compression()) { invalid_flags |=3D RAM_SAVE_FLAG_COMPRESS_PAGE; } =20 while (!ret && !(flags & RAM_SAVE_FLAG_EOS)) { - ram_addr_t addr, total_ram_bytes; + ram_addr_t addr; void *host =3D NULL, *host_bak =3D NULL; uint8_t ch; =20 @@ -4411,65 +4487,7 @@ static int ram_load_precopy(QEMUFile *f) =20 switch (flags & ~RAM_SAVE_FLAG_CONTINUE) { case RAM_SAVE_FLAG_MEM_SIZE: - /* Synchronize RAM block list */ - total_ram_bytes =3D addr; - while (!ret && total_ram_bytes) { - RAMBlock *block; - char id[256]; - ram_addr_t length; - - 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 && !qemu_ram_is_migratable(block)) { - error_report("block %s should not be migrated !", id); - ret =3D -EINVAL; - } else if (block) { - if (length !=3D block->used_length) { - Error *local_err =3D NULL; - - ret =3D qemu_ram_resize(block, length, - &local_err); - if (local_err) { - error_report_err(local_err); - } - } - /* For postcopy we need to check hugepage sizes match = */ - if (postcopy_advised && migrate_postcopy_ram() && - block->page_size !=3D qemu_host_page_size) { - uint64_t remote_page_size =3D qemu_get_be64(f); - if (remote_page_size !=3D block->page_size) { - error_report("Mismatched RAM page size %s " - "(local) %zd !=3D %" PRId64, - id, block->page_size, - remote_page_size); - ret =3D -EINVAL; - } - } - if (migrate_ignore_shared()) { - hwaddr addr =3D qemu_get_be64(f); - if (ramblock_is_ignored(block) && - block->mr->addr !=3D addr) { - error_report("Mismatched GPAs for block %s " - "%" PRId64 "!=3D %" PRId64, - id, (uint64_t)addr, - (uint64_t)block->mr->addr); - ret =3D -EINVAL; - } - } - ram_control_load_hook(f, RAM_CONTROL_BLOCK_REG, - block->idstr); - } else { - error_report("Unknown ramblock \"%s\", cannot " - "accept migration", id); - ret =3D -EINVAL; - } - - total_ram_bytes -=3D length; - } + ret =3D parse_ramblocks(f, addr); break; =20 case RAM_SAVE_FLAG_ZERO: --=20 2.35.3