From nobody Fri May 17 02:41:23 2024 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=1690291698; cv=none; d=zohomail.com; s=zohoarc; b=iON5Z+JHkLB1rIjto9upKmeDPTULI/e1AKOik+aPRGbniP20tq78zJ+iTG0tc0zc9Hmzcx8z1G7mSWjnqVlfXa59aqIofMWGDwZmWhymADWWU+zEKJtyc+YsH8M/MuVqWcLn3x+2PBwHba2U00CWLXIiAlcit9OBgtnO/i7nt2E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690291698; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=VmbLvJgHt3CRnBg3pX7vFO8lqsOJrLvRPE/r7vnXkMw=; b=gCB1HTayMnN9Kd42lbI8YS/xSBhMDrPQ3OWbpMZb6q3lpKIZo6YHVLWjOR2KVniuZzbKWkIM3yJN78ixofNX94Q33a/gxi4Ub+2vIdty01/zNBcV7gJz/t6KM1hNqhBYrILA9ckRwfr3wLA5nWmgH0BAPCE7px5WqMCFGl8ohcw= 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 1690291697790783.5902494920816; Tue, 25 Jul 2023 06:28:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qOI4i-00066O-GW; Tue, 25 Jul 2023 09:27:40 -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 1qOI4Z-00065k-4a for qemu-devel@nongnu.org; Tue, 25 Jul 2023 09:27:31 -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 1qOI4V-0005go-Pp for qemu-devel@nongnu.org; Tue, 25 Jul 2023 09:27:29 -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 6B0D8220FD; Tue, 25 Jul 2023 13:27:26 +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 DEFCC13487; Tue, 25 Jul 2023 13:27:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ba28KbzNv2RLYAAAMHmgww (envelope-from ); Tue, 25 Jul 2023 13:27:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1690291646; 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; bh=VmbLvJgHt3CRnBg3pX7vFO8lqsOJrLvRPE/r7vnXkMw=; b=xWfM4IWwfiaDCPRcXfBdwMH9H9Evj0mhbSw3YLKutSLcqgqdFrM1Yug7aqAJx2pLDa6RrL S6nlI5Buy7nNuBMDqTPdtRmslLb72u2x8QS64GKrH16etQltLXlX450g9So26NtS007mlr O5eqOUdRF7BwrphnR5PR3ziKzOsIWaI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1690291646; 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; bh=VmbLvJgHt3CRnBg3pX7vFO8lqsOJrLvRPE/r7vnXkMw=; b=Fq7WVM7OZTtpIpBgN3Bd95JCIRWeFIvsz6/XJzFTF5D0tBZtUh+GPpk6Puzvn96s/vgVqs 3ccCmLjsIBaDEsCw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Nikolay Borisov , Juan Quintela , Peter Xu , Leonardo Bras Subject: [PATCH] migration/ram: Refactor precopy ram loading code Date: Tue, 25 Jul 2023 10:26:51 -0300 Message-Id: <20230725132651.18635-1-farosas@suse.de> X-Mailer: git-send-email 2.35.3 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1690291699905100003 Content-Type: text/plain; charset="utf-8" From: Nikolay Borisov Extract the ramblock parsing code into a routine that operates on the sequence of headers from the stream and another the parses the individual ramblock. This makes ram_load_precopy() easier to comprehend. Signed-off-by: Nikolay Borisov Signed-off-by: Fabiano Rosas Reviewed-by: Peter Xu Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- I'm extracting the parts from the fixed-ram migration series [1] that could already go in. This patch is one of them. 1- https://lore.kernel.org/r/20230330180336.2791-1-farosas@suse.de --- migration/ram.c | 141 +++++++++++++++++++++++++++--------------------- 1 file changed, 79 insertions(+), 62 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 0ada6477e8..685e129b70 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3826,6 +3826,82 @@ 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); + return -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 (migrate_ram_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) { + RAMBlock *block; + char id[256]; + 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 * @@ -3840,14 +3916,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_compress()) { 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 @@ -3918,65 +3993,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 (migrate_ram_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