From nobody Fri Nov 14 18:26:43 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@eurecom.fr; 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=fail(p=none dis=none) header.from=eurecom.fr Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760097746462851.6149679285461; Fri, 10 Oct 2025 05:02:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7Bo5-0002HZ-03; Fri, 10 Oct 2025 08:01:09 -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 1v7Bny-0002Gq-Av for qemu-devel@nongnu.org; Fri, 10 Oct 2025 08:01:02 -0400 Received: from smtp.eurecom.fr ([193.55.113.210]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7Bno-0008WI-3s for qemu-devel@nongnu.org; Fri, 10 Oct 2025 08:01:01 -0400 Received: from waha.eurecom.fr (HELO smtps.eurecom.fr) ([10.3.2.236]) by drago1i.eurecom.fr with ESMTP; 10 Oct 2025 14:00:23 +0200 Received: from marco-eurecom-desktop.s3.eurecom.fr (unknown [193.55.114.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtps.eurecom.fr (Postfix) with ESMTPSA id DF6882C52; Fri, 10 Oct 2025 14:00:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=eurecom.fr; i=@eurecom.fr; q=dns/txt; s=default; t=1760097652; x=1791633652; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+lyfvUrM3jgj34FO+j3+zKsq2tdWWpcAmDsjSrP4dxg=; b=sS4xibtTKJWcoCfAjSSBtXkFRwGp2joRmVzIUNwI5+RpMa6k4IlWlvxX 3iZQvXHiR2yrwlIZGmWF9VsSnpAIa8QPF3If9r6NGt9sbuRw5y9PqVyXW +kOilZ7bGheKuH6VT/9lk25BUuuNlyp/286fiRKtjEgsot+2IoJupzFKa Y=; X-CSE-ConnectionGUID: lf6pZSEwTxSUe1rMlTG9Hw== X-CSE-MsgGUID: ytcEx3jyRLONGOzNNFjM+Q== X-IronPort-AV: E=Sophos;i="6.19,218,1754949600"; d="scan'208";a="3223569" From: Marco Cavenati To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, jmarcin@redhat.com, berrange@redhat.com, Marco Cavenati Subject: [PATCH v2 1/2] migration: add FEATURE_SEEKABLE to QIOChannelBlock Date: Fri, 10 Oct 2025 13:59:53 +0200 Message-ID: <20251010115954.1995298-2-Marco.Cavenati@eurecom.fr> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010115954.1995298-1-Marco.Cavenati@eurecom.fr> References: <20251010115954.1995298-1-Marco.Cavenati@eurecom.fr> 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=193.55.113.210; envelope-from=Marco.Cavenati@eurecom.fr; helo=smtp.eurecom.fr 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=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: fail (Header signature does not verify) X-ZM-MESSAGEID: 1760097750997154100 Content-Type: text/plain; charset="utf-8" Enable the use of the mapped-ram migration feature with savevm/loadvm snapshots by adding the QIO_CHANNEL_FEATURE_SEEKABLE feature to QIOChannelBlock. Implement io_preadv and io_pwritev methods to provide positioned I/O capabilities that don't modify the channel's position pointer. Signed-off-by: Marco Cavenati --- migration/channel-block.c | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/migration/channel-block.c b/migration/channel-block.c index 97de5a691b..9cf383d4b5 100644 --- a/migration/channel-block.c +++ b/migration/channel-block.c @@ -30,6 +30,7 @@ qio_channel_block_new(BlockDriverState *bs) QIOChannelBlock *ioc; =20 ioc =3D QIO_CHANNEL_BLOCK(object_new(TYPE_QIO_CHANNEL_BLOCK)); + qio_channel_set_feature(QIO_CHANNEL(ioc), QIO_CHANNEL_FEATURE_SEEKABLE= ); =20 bdrv_ref(bs); ioc->bs =3D bs; @@ -96,6 +97,47 @@ qio_channel_block_writev(QIOChannel *ioc, return qiov.size; } =20 +static ssize_t +qio_channel_block_preadv(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + off_t offset, + Error **errp) +{ + QIOChannelBlock *bioc =3D QIO_CHANNEL_BLOCK(ioc); + QEMUIOVector qiov; + int ret; + + qemu_iovec_init_external(&qiov, (struct iovec *)iov, niov); + ret =3D bdrv_readv_vmstate(bioc->bs, &qiov, offset); + if (ret < 0) { + error_setg_errno(errp, -ret, "bdrv_readv_vmstate failed"); + return -1; + } + + return qiov.size; +} + +static ssize_t +qio_channel_block_pwritev(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + off_t offset, + Error **errp) +{ + QIOChannelBlock *bioc =3D QIO_CHANNEL_BLOCK(ioc); + QEMUIOVector qiov; + int ret; + + qemu_iovec_init_external(&qiov, (struct iovec *)iov, niov); + ret =3D bdrv_writev_vmstate(bioc->bs, &qiov, offset); + if (ret < 0) { + error_setg_errno(errp, -ret, "bdrv_writev_vmstate failed"); + return -1; + } + + return qiov.size; +} =20 static int qio_channel_block_set_blocking(QIOChannel *ioc, @@ -177,6 +219,8 @@ qio_channel_block_class_init(ObjectClass *klass, ioc_klass->io_writev =3D qio_channel_block_writev; ioc_klass->io_readv =3D qio_channel_block_readv; ioc_klass->io_set_blocking =3D qio_channel_block_set_blocking; + ioc_klass->io_preadv =3D qio_channel_block_preadv; + ioc_klass->io_pwritev =3D qio_channel_block_pwritev; ioc_klass->io_seek =3D qio_channel_block_seek; ioc_klass->io_close =3D qio_channel_block_close; ioc_klass->io_set_aio_fd_handler =3D qio_channel_block_set_aio_fd_hand= ler; --=20 2.48.1 From nobody Fri Nov 14 18:26:43 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@eurecom.fr; 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=fail(p=none dis=none) header.from=eurecom.fr Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760097749620691.8457179069314; Fri, 10 Oct 2025 05:02:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7BoT-0002Ui-BD; Fri, 10 Oct 2025 08:01:33 -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 1v7Bo2-0002Hr-Gc for qemu-devel@nongnu.org; Fri, 10 Oct 2025 08:01:08 -0400 Received: from smtp.eurecom.fr ([193.55.113.210]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7Bnu-0000Tm-R2 for qemu-devel@nongnu.org; Fri, 10 Oct 2025 08:01:06 -0400 Received: from waha.eurecom.fr (HELO smtps.eurecom.fr) ([10.3.2.236]) by drago1i.eurecom.fr with ESMTP; 10 Oct 2025 14:00:23 +0200 Received: from marco-eurecom-desktop.s3.eurecom.fr (unknown [193.55.114.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtps.eurecom.fr (Postfix) with ESMTPSA id E10DF2C53; Fri, 10 Oct 2025 14:00:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=eurecom.fr; i=@eurecom.fr; q=dns/txt; s=default; t=1760097659; x=1791633659; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OzB2NceYgoK+Id5vIFm5FXVb+gjrSBWMNJc5ggIFIJA=; b=daaf7fU2fE4ImAdg/3Lmld+dWOTv9Yz4vu5b6kxTjOIxBLWBcmG5wUOG IfJerEPeLIFG9C8P/GFazg3OZnJJzRa0n3Sn4Nn1bBhbWVPv/xILDezqr 58Z7D2XTEtj7+tDFDBUkVp2YJNmnFb+6RWKoppMzdYgmxFYhnQYzaubJ6 c=; X-CSE-ConnectionGUID: R3PAVViqTYyKMtDWIK+vZA== X-CSE-MsgGUID: 3bSvSXMYS4CduVs6JTZEGQ== X-IronPort-AV: E=Sophos;i="6.19,218,1754949600"; d="scan'208";a="3223570" From: Marco Cavenati To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, jmarcin@redhat.com, berrange@redhat.com, Marco Cavenati Subject: [PATCH v2 2/2] migration: mapped-ram: handle zero pages Date: Fri, 10 Oct 2025 13:59:54 +0200 Message-ID: <20251010115954.1995298-3-Marco.Cavenati@eurecom.fr> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251010115954.1995298-1-Marco.Cavenati@eurecom.fr> References: <20251010115954.1995298-1-Marco.Cavenati@eurecom.fr> 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=193.55.113.210; envelope-from=Marco.Cavenati@eurecom.fr; helo=smtp.eurecom.fr 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=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: fail (Header signature does not verify) X-ZM-MESSAGEID: 1760097753206154100 Content-Type: text/plain; charset="utf-8" Make mapped-ram compatible with loadvm snapshot restoring by explicitly zeroing memory pages in this case. Skip zeroing for -incoming and -loadvm migrations to preserve performance. Signed-off-by: Marco Cavenati --- migration/options.c | 1 - migration/ram.c | 59 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/migration/options.c b/migration/options.c index d9227809d7..e78324b80c 100644 --- a/migration/options.c +++ b/migration/options.c @@ -449,7 +449,6 @@ INITIALIZE_MIGRATE_CAPS_SET(check_caps_background_snaps= hot, static const INITIALIZE_MIGRATE_CAPS_SET(check_caps_savevm, MIGRATION_CAPABILITY_MULTIFD, - MIGRATION_CAPABILITY_MAPPED_RAM, ); =20 static bool migrate_incoming_started(void) diff --git a/migration/ram.c b/migration/ram.c index 5eef2efc78..7d15b81777 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4039,12 +4039,58 @@ static size_t ram_load_multifd_pages(void *host_add= r, size_t size, return size; } =20 +/** + * handle_zero_mapped_ram: Zero out a range of RAM pages if required during + * mapped-ram load + * + * Zeroing is only performed when restoring from a snapshot (HMP loadvm). + * During incoming migration or -loadvm cli snapshot load, the function is= a + * no-op and returns true as in those cases the pages are already guarante= ed to + * be zeroed. + * + * Returns: true on success, false on error (with @errp set). + * @from_bit_idx: Starting index relative to the map of the page (inclusiv= e) + * @to_bit_idx: Ending index relative to the map of the page (exclusive) + */ +static bool handle_zero_mapped_ram(RAMBlock *block, unsigned long from_bit= _idx, + unsigned long to_bit_idx, Error **errp) +{ + ERRP_GUARD(); + ram_addr_t offset; + size_t size; + void *host; + + /* + * Zeroing is not needed for either -loadvm (RUN_STATE_PRELAUNCH), or + * -incoming (RUN_STATE_INMIGRATE). + */ + if (!runstate_check(RUN_STATE_RESTORE_VM)) { + return true; + } + + if (from_bit_idx >=3D to_bit_idx) { + return true; + } + + size =3D TARGET_PAGE_SIZE * (to_bit_idx - from_bit_idx); + offset =3D from_bit_idx << TARGET_PAGE_BITS; + host =3D host_from_ram_block_offset(block, offset); + if (!host) { + error_setg(errp, "zero page outside of ramblock %s range", + block->idstr); + return false; + } + ram_handle_zero(host, size); + + return true; +} + static bool read_ramblock_mapped_ram(QEMUFile *f, RAMBlock *block, long num_pages, unsigned long *bitmap, Error **errp) { ERRP_GUARD(); - unsigned long set_bit_idx, clear_bit_idx; + unsigned long set_bit_idx, clear_bit_idx =3D 0; ram_addr_t offset; void *host; size_t read, unread, size; @@ -4053,6 +4099,12 @@ static bool read_ramblock_mapped_ram(QEMUFile *f, RA= MBlock *block, set_bit_idx < num_pages; set_bit_idx =3D find_next_bit(bitmap, num_pages, clear_bit_idx + = 1)) { =20 + /* Zero pages */ + if (!handle_zero_mapped_ram(block, clear_bit_idx, set_bit_idx, err= p)) { + return false; + } + + /* Non-zero pages */ clear_bit_idx =3D find_next_zero_bit(bitmap, num_pages, set_bit_id= x + 1); =20 unread =3D TARGET_PAGE_SIZE * (clear_bit_idx - set_bit_idx); @@ -4084,6 +4136,11 @@ static bool read_ramblock_mapped_ram(QEMUFile *f, RA= MBlock *block, } } =20 + /* Handle trailing 0 pages */ + if (!handle_zero_mapped_ram(block, clear_bit_idx, num_pages, errp)) { + return false; + } + return true; =20 err: --=20 2.48.1