From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515653; cv=none; d=zohomail.com; s=zohoarc; b=WAfganMIiM8qEgPds7ZvhFY3c1qcLIxIpftVDIoEqz7D0EiZOFKkk3v7MG5l/7y4y/nNAX8zItNPVxv2rYZM3hS5+Eq63nMworOOUPTnaSg6MO+OIFYNL3fLwlCLm7oRA29JSlg4Bx/7zmfsJawLS8beovLCTBirmEao7zKELP8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515653; 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=J1u9p98iL9dGUhqwCh1QSReBpXp024Fs7D/IbbmF5DU=; b=CxNWswtaexDkrkSdQYeGUs+ZV3dmptzeCP2M1R/WR0MBaQhQDrHVEs7Z01Nacdr1glPj/F5TB8Qdr4t4p0Gcj+x12hJqy6+nwiYBTpdj1r7AeRYPHd9er4mTQh5MLDtsli2A6yeMN6zxyvzV9vbxM6/6DdkC+20P5YTME1e8fJU= 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 170951565362183.03256814389977; Sun, 3 Mar 2024 17:27:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx6T-0001B6-0I; Sun, 03 Mar 2024 20:26:53 -0500 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 1rgx6R-0001Aq-Ff for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:26:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx6P-0002Cq-V3 for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:26:51 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-176-bCWqCaEZP9a6jawEZylEgA-1; Sun, 03 Mar 2024 20:26:46 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9D7923C0BE4D; Mon, 4 Mar 2024 01:26:45 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 685A640C6EBA; Mon, 4 Mar 2024 01:26:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515608; h=from:from:reply-to:subject:subject: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=J1u9p98iL9dGUhqwCh1QSReBpXp024Fs7D/IbbmF5DU=; b=AlUeb2ScJpPNLu1b/rnHO3IdpYhu3M+FHCwLAwPPVk9Wm8/8cpYvFB1CCdCeoFsckYaaZ9 octT6IXmLqRPGYucPLAWyFc3S8BjlgKkST7BW3pIJjsHY0gefIeBozs2H+AOrSqNHYRdMV pn1UEE6lm3IOqXU32hM6El8AZKAmtVs= X-MC-Unique: bCWqCaEZP9a6jawEZylEgA-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas , Steve Sistare , Markus Armbruster Subject: [PULL 01/27] migration: massage cpr-reboot documentation Date: Mon, 4 Mar 2024 09:26:08 +0800 Message-ID: <20240304012634.95520-2-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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 @redhat.com) X-ZM-MESSAGEID: 1709515655133100002 Content-Type: text/plain; charset="utf-8" From: Steve Sistare Re-wrap the cpr-reboot documentation to 70 columns, use '@' for cpr-reboot references, capitalize COLO and VFIO, and tweak the wording. Suggested-by: Markus Armbruster Signed-off-by: Steve Sistare Link: https://lore.kernel.org/r/1709218462-3640-1-git-send-email-steven.sis= tare@oracle.com [peterx: s/qemu/QEMU per Markus's suggestion] Reviewed-by: Markus Armbruster Signed-off-by: Peter Xu --- qapi/migration.json | 46 +++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/qapi/migration.json b/qapi/migration.json index 0b33a71ab4..b603aa6f25 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -636,28 +636,30 @@ # # @normal: the original form of migration. (since 8.2) # -# @cpr-reboot: The migrate command stops the VM and saves state to the URI. -# After quitting qemu, the user resumes by running qemu -incoming. -# -# This mode allows the user to quit qemu, and restart an updated versi= on -# of qemu. The user may even update and reboot the OS before restarti= ng, -# as long as the URI persists across a reboot. -# -# Unlike normal mode, the use of certain local storage options does not -# block the migration, but the user must not modify guest block devices -# between the quit and restart. -# -# This mode supports vfio devices provided the user first puts the gue= st -# in the suspended runstate, such as by issuing guest-suspend-ram to t= he -# qemu guest agent. -# -# Best performance is achieved when the memory backend is shared and t= he -# @x-ignore-shared migration capability is set, but this is not requir= ed. -# Further, if the user reboots before restarting such a configuration,= the -# shared backend must be be non-volatile across reboot, such as by bac= king -# it with a dax device. -# -# cpr-reboot may not be used with postcopy, colo, or background-snapsh= ot. +# @cpr-reboot: The migrate command stops the VM and saves state to +# the URI. After quitting QEMU, the user resumes by running +# QEMU -incoming. +# +# This mode allows the user to quit QEMU, optionally update and +# reboot the OS, and restart QEMU. If the user reboots, the URI +# must persist across the reboot, such as by using a file. +# +# Unlike normal mode, the use of certain local storage options +# does not block the migration, but the user must not modify the +# contents of guest block devices between the quit and restart. +# +# This mode supports VFIO devices provided the user first puts +# the guest in the suspended runstate, such as by issuing +# guest-suspend-ram to the QEMU guest agent. +# +# Best performance is achieved when the memory backend is shared +# and the @x-ignore-shared migration capability is set, but this +# is not required. Further, if the user reboots before restarting +# such a configuration, the shared memory must persist across the +# reboot, such as by backing it with a dax device. +# +# @cpr-reboot may not be used with postcopy, background-snapshot, +# or COLO. # # (since 8.2) ## --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515713; cv=none; d=zohomail.com; s=zohoarc; b=CtF3YUNIx5OL3fhKL73fOqwar/ny6fx49jxgL2m+sO4DuG6FntmTR/5US8DcjAjeZ5jvLGW3VI9y9eRXfPxzrXbyNsC+qeU4NTdYC6SQ3WnhbJXR+/kX033rl2zGUH7hVx/SiawkHcvAlqYQjL1mq7GDGhNgSDYhK27FcGIgSOE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515713; 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=ir0qtqpandnsGtqegAJq1Iw5ZTngl6lZQdOMv82MTII=; b=ALWqWbtp+OFp69cmhqT2qFzslXxS5+9GzsfwD9UitdqyaeVzcKr0QajQj0Mxg/EBfBCJ3+bzb9sz+qakxBlavkR0dk0qH/u2k9/hOmUugBJgtUGDWGguZ1ofyA54i28RVVKLopU3MoLXFdAWDi3S+R85ndbL2ogCtXlQjuh1XGE= 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 1709515713502854.2242858657312; Sun, 3 Mar 2024 17:28:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx6X-0001Bk-J0; Sun, 03 Mar 2024 20:26:57 -0500 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 1rgx6V-0001BO-Ix for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:26:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx6U-0002D2-26 for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:26:55 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-312-F3UAZCTHMhmWDbqFiklEXw-1; Sun, 03 Mar 2024 20:26:51 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ECADF185A783; Mon, 4 Mar 2024 01:26:50 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 542BE40C6EBA; Mon, 4 Mar 2024 01:26:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515613; h=from:from:reply-to:subject:subject: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=ir0qtqpandnsGtqegAJq1Iw5ZTngl6lZQdOMv82MTII=; b=Fp3jumq8U6o9oX16Y0q51RiFAYGW1pEFt6djgN42XxvR09lbIbRPJihTot+9QWGzzIKwuP X4kEDBdhVOVoJ0pjob30U4oduIIuK4BaxCTPTHlBLhdeFaaQPFB48ZwR1YSI+flyysZdAo 32iq/Ae3pWhdyIhWr4aVe47a0c2JY9w= X-MC-Unique: F3UAZCTHMhmWDbqFiklEXw-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas , Bryan Zhang , Bryan Zhang Subject: [PULL 02/27] migration: Properly apply migration compression level parameters Date: Mon, 4 Mar 2024 09:26:09 +0800 Message-ID: <20240304012634.95520-3-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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 @redhat.com) X-ZM-MESSAGEID: 1709515715047100002 Content-Type: text/plain; charset="utf-8" From: Bryan Zhang Some glue code was missing, so that using `qmp_migrate_set_parameters` to set `multifd-zstd-level` or `multifd-zlib-level` did not work. This commit adds the glue code to fix that. Signed-off-by: Bryan Zhang Link: https://lore.kernel.org/r/20240301035901.4006936-2-bryan.zhang@byteda= nce.com Signed-off-by: Peter Xu --- migration/options.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/migration/options.c b/migration/options.c index 3e3e0b93b4..1cd3cc7c33 100644 --- a/migration/options.c +++ b/migration/options.c @@ -1312,6 +1312,12 @@ static void migrate_params_test_apply(MigrateSetPara= meters *params, if (params->has_multifd_compression) { dest->multifd_compression =3D params->multifd_compression; } + if (params->has_multifd_zlib_level) { + dest->multifd_zlib_level =3D params->multifd_zlib_level; + } + if (params->has_multifd_zstd_level) { + dest->multifd_zstd_level =3D params->multifd_zstd_level; + } if (params->has_xbzrle_cache_size) { dest->xbzrle_cache_size =3D params->xbzrle_cache_size; } @@ -1447,6 +1453,12 @@ static void migrate_params_apply(MigrateSetParameter= s *params, Error **errp) if (params->has_multifd_compression) { s->parameters.multifd_compression =3D params->multifd_compression; } + if (params->has_multifd_zlib_level) { + s->parameters.multifd_zlib_level =3D params->multifd_zlib_level; + } + if (params->has_multifd_zstd_level) { + s->parameters.multifd_zstd_level =3D params->multifd_zstd_level; + } if (params->has_xbzrle_cache_size) { s->parameters.xbzrle_cache_size =3D params->xbzrle_cache_size; xbzrle_cache_resize(params->xbzrle_cache_size, errp); --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515851; cv=none; d=zohomail.com; s=zohoarc; b=O2ipbdQWiUBZe/RyawPjshamoYoDAY7K+XV5L6PpiuRfpMZAG9zpounoLIQFG+p7NKSSZNfQyj+WNinlwNERgcTRmcMrMHWm8W4GohSDzlMlPQnW/B1NSUImwmmd0QvQDgYPlO01kac6SG8ps62NoRAmIVjH+weUEEaqoxwnk/s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515851; 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=Crwhp+L/Y2kx6IfY/lBSTl6+qMBWTiwjHq63n8HYRLQ=; b=lb6mbWxcWNV4ufGT+d9WXiLzQ5tCRGo5IxlrjFcC/NPRhiIRwSbk4MB5GT/M5fHGWj0LtYkq/AtGvSJfUCEtpjAI//msbe03XI0sFWXJFlP17hvrCUlMPhGP+e9woEPT4XEhKg42DtLHEe9RTU9zrUf8pS8j5grop5K+RHrH21M= 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 1709515851463624.4453117330712; Sun, 3 Mar 2024 17:30:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx6l-0001DX-4L; Sun, 03 Mar 2024 20:27:11 -0500 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 1rgx6j-0001Cj-7g for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx6b-0002De-Fe for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:09 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-159-j3UoXz61MV2TP-zy0DrwaA-1; Sun, 03 Mar 2024 20:26:56 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BE2208820C8; Mon, 4 Mar 2024 01:26:55 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id A3CE240C6EBA; Mon, 4 Mar 2024 01:26:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515619; h=from:from:reply-to:subject:subject: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=Crwhp+L/Y2kx6IfY/lBSTl6+qMBWTiwjHq63n8HYRLQ=; b=gsTCvfH7ukZenT4mZe9JlLf5O9ta9UInxFW9KsXoUgvTkabxkyfyaQ4Bpe+bysDGzEoWLW 8Su2HZld2wgd3cVgbwVfTx+TgjG6S7C9qH22f1LydefJE4NTtiCuc6aN0Vue/vcyf6o0Q/ KQ0OHhFZAxlxq5/xbIJkHkotFmeVMsY= X-MC-Unique: j3UoXz61MV2TP-zy0DrwaA-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas , Bryan Zhang , Bryan Zhang Subject: [PULL 03/27] tests/migration: Set compression level in migration tests Date: Mon, 4 Mar 2024 09:26:10 +0800 Message-ID: <20240304012634.95520-4-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, 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, 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 @redhat.com) X-ZM-MESSAGEID: 1709515853460100003 Content-Type: text/plain; charset="utf-8" From: Bryan Zhang Adds calls to set compression level for `zstd` and `zlib` migration tests, just to make sure that the calls work. Signed-off-by: Bryan Zhang Link: https://lore.kernel.org/r/20240301035901.4006936-3-bryan.zhang@byteda= nce.com Signed-off-by: Peter Xu --- tests/qtest/migration-test.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 83512bce85..8c35f3457b 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -2664,6 +2664,13 @@ static void * test_migrate_precopy_tcp_multifd_zlib_start(QTestState *from, QTestState *to) { + /* + * Overloading this test to also check that set_parameter does not err= or. + * This is also done in the tests for the other compression methods. + */ + migrate_set_parameter_int(from, "multifd-zlib-level", 2); + migrate_set_parameter_int(to, "multifd-zlib-level", 2); + return test_migrate_precopy_tcp_multifd_start_common(from, to, "zlib"); } =20 @@ -2672,6 +2679,9 @@ static void * test_migrate_precopy_tcp_multifd_zstd_start(QTestState *from, QTestState *to) { + migrate_set_parameter_int(from, "multifd-zstd-level", 2); + migrate_set_parameter_int(to, "multifd-zstd-level", 2); + return test_migrate_precopy_tcp_multifd_start_common(from, to, "zstd"); } #endif /* CONFIG_ZSTD */ --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515671; cv=none; d=zohomail.com; s=zohoarc; b=jXuA9Ey5NVYh7i+T2Lu612SbNMDgAh4684zA/RrpxN5J7HRO0c01JiRD641IyURBf8ZOuvikkGbVKDRadLTLAU/6oRxzhPT2nHPu4KbxFQ9Tn7/LovMdeSnHtg0ZkUwlZGAi4HuWN7BXzjowB/mYLneZWFJYW5Keka3DJF5D6nE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515671; 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=kgpnbF65mZKeFKOf2oI/kGpTOviefU6Ka4ygsHYyZJU=; b=LNLC4bkCI6SUkYeWeknXbr4Y834AT/bo+I09bcaUCw9Fyl8IuDhXAWu+geeDQrIRuDFZ5LGVRLSFL4jUtlvjk8e6bpd/aVgfrukm2917+XfyuZClUVORyOHj5Q5sPbQRjNc5WdzqoJjhZ+huGK76zShX7UGaNnR/cy9euZo3o6c= 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 1709515671071455.18597862611864; Sun, 3 Mar 2024 17:27:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx6h-0001CX-Tw; Sun, 03 Mar 2024 20:27:07 -0500 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 1rgx6g-0001C5-6g for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx6d-0002E2-Co for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:04 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-616-EqSfryIkPruSz6qsbf2qFg-1; Sun, 03 Mar 2024 20:27:00 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A4612185A783; Mon, 4 Mar 2024 01:26:59 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EB58403864F; Mon, 4 Mar 2024 01:26:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515622; h=from:from:reply-to:subject:subject: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=kgpnbF65mZKeFKOf2oI/kGpTOviefU6Ka4ygsHYyZJU=; b=fAhdEN4+1x2NpCp0w55VA5Oa4+q/JniherGuEFrAMjpolLz7CDSAq3TdbFmsMQLLcJvXQ/ xQHiBkitGdXl23qYIYlWelfdF7g9X30KJUTnIEtK+FmYP3gJvA7ep+6GdajbrX6MqACVmW t5tkyHyo9Cb1sVpqv/IEiAgnp92MNsg= X-MC-Unique: EqSfryIkPruSz6qsbf2qFg-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas Subject: [PULL 04/27] migration/multifd: Cleanup multifd_recv_sync_main Date: Mon, 4 Mar 2024 09:26:11 +0800 Message-ID: <20240304012634.95520-5-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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 @redhat.com) X-ZM-MESSAGEID: 1709515672930100003 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas Some minor cleanups and documentation for multifd_recv_sync_main. Use thread_count as done in other parts of the code. Remove p->id from the multifd_recv_state sync, since that is global and not tied to a channel. Add documentation for the sync steps. Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240229153017.2221-2-farosas@suse.de Signed-off-by: Peter Xu --- migration/multifd.c | 17 +++++++++++++---- migration/trace-events | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 6c07f19af1..c7389bf833 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -1182,18 +1182,27 @@ void multifd_recv_cleanup(void) =20 void multifd_recv_sync_main(void) { + int thread_count =3D migrate_multifd_channels(); int i; =20 if (!migrate_multifd()) { return; } - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; =20 - trace_multifd_recv_sync_main_wait(p->id); + /* + * Initiate the synchronization by waiting for all channels. + * For socket-based migration this means each channel has received + * the SYNC packet on the stream. + */ + for (i =3D 0; i < thread_count; i++) { + trace_multifd_recv_sync_main_wait(i); qemu_sem_wait(&multifd_recv_state->sem_sync); } - for (i =3D 0; i < migrate_multifd_channels(); i++) { + + /* + * Sync done. Release the channels for the next iteration. + */ + for (i =3D 0; i < thread_count; i++) { MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; =20 WITH_QEMU_LOCK_GUARD(&p->mutex) { diff --git a/migration/trace-events b/migration/trace-events index 298ad2b0dd..bf1a069632 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -132,7 +132,7 @@ multifd_recv(uint8_t id, uint64_t packet_num, uint32_t = used, uint32_t flags, uin multifd_recv_new_channel(uint8_t id) "channel %u" multifd_recv_sync_main(long packet_num) "packet num %ld" multifd_recv_sync_main_signal(uint8_t id) "channel %u" -multifd_recv_sync_main_wait(uint8_t id) "channel %u" +multifd_recv_sync_main_wait(uint8_t id) "iter %u" multifd_recv_terminate_threads(bool error) "error %d" multifd_recv_thread_end(uint8_t id, uint64_t packets, uint64_t pages) "cha= nnel %u packets %" PRIu64 " pages %" PRIu64 multifd_recv_thread_start(uint8_t id) "%u" --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515653; cv=none; d=zohomail.com; s=zohoarc; b=AARs2xYvuwIkaAYhFsqbG2DQlHA/byUhLrdtqDhPdkLAEZotAA/Tww/iGU5GM5guxXjPtIPrzt2hFCkNmHyHgAkvTZOmC6seRH98TnNYOJVq82oU0TFD6igQaOZtz7Ejfx87Ivdog42gInUUYKcy0lqn4ju688BxUsf8bI7uP24= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515653; h=Content-Type: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=XJAI1gAQLc7X13eSRo6rRfshCDrM0B/QS5LuWZzr9kU=; b=ElorPAHp5hyPVFiln4tRPOGoYF0U4ycSBxzVEyJa2Qh2btojXoS8YZJy6D/noYFUGDzL+isgkhGoLLepTMxrdhJAeP1ra1ULZikToBSWsrWk9Q9imkvu6FFpn4ezkdLGBY7kpd7dOZevY8J/JLdrLSYZ/kJ+vKWjckHZOIg6Abs= 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 1709515653622395.2684904450433; Sun, 3 Mar 2024 17:27:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx6k-0001D6-5E; Sun, 03 Mar 2024 20:27:10 -0500 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 1rgx6i-0001Cb-SE for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx6h-0002EE-7K for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:08 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-411--zhynwtGM_a9NZJT-sLgfA-1; Sun, 03 Mar 2024 20:27:04 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 44EE629ABA02; Mon, 4 Mar 2024 01:27:04 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73CFF40C6EBA; Mon, 4 Mar 2024 01:27:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515626; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XJAI1gAQLc7X13eSRo6rRfshCDrM0B/QS5LuWZzr9kU=; b=Puey8nsCIcaiqZx/et/F8Rof5yag6SNGZF2+prSMrKhyD+Bn3hc8EL8qiAS8dArEbM5Vow +iQDgkkqJ7oUaf3sopgaULdOENf1Fed1Dd19IFTaMbLbR6i2XqnK0EPYG5Z4UwChQbxi7f 31NEQtmHrhiIq9TZXt+4NWBvr+rCeMs= X-MC-Unique: -zhynwtGM_a9NZJT-sLgfA-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas , Nikolay Borisov Subject: [PULL 05/27] io: add and implement QIO_CHANNEL_FEATURE_SEEKABLE for channel file Date: Mon, 4 Mar 2024 09:26:12 +0800 Message-ID: <20240304012634.95520-6-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1709515655126100001 From: Nikolay Borisov Add a generic QIOChannel feature SEEKABLE which would be used by the qemu_file* apis. For the time being this will be only implemented for file channels. Signed-off-by: Nikolay Borisov Reviewed-by: "Daniel P. Berrang=C3=A9" Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240229153017.2221-3-farosas@suse.de Signed-off-by: Peter Xu --- include/io/channel.h | 1 + io/channel-file.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/include/io/channel.h b/include/io/channel.h index 5f9dbaab65..fcb19fd672 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -44,6 +44,7 @@ enum QIOChannelFeature { QIO_CHANNEL_FEATURE_LISTEN, QIO_CHANNEL_FEATURE_WRITE_ZERO_COPY, QIO_CHANNEL_FEATURE_READ_MSG_PEEK, + QIO_CHANNEL_FEATURE_SEEKABLE, }; =20 =20 diff --git a/io/channel-file.c b/io/channel-file.c index 4a12c61886..f91bf6db1c 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -36,6 +36,10 @@ qio_channel_file_new_fd(int fd) =20 ioc->fd =3D fd; =20 + if (lseek(fd, 0, SEEK_CUR) !=3D (off_t)-1) { + qio_channel_set_feature(QIO_CHANNEL(ioc), QIO_CHANNEL_FEATURE_SEEK= ABLE); + } + trace_qio_channel_file_new_fd(ioc, fd); =20 return ioc; @@ -60,6 +64,10 @@ qio_channel_file_new_path(const char *path, return NULL; } =20 + if (lseek(ioc->fd, 0, SEEK_CUR) !=3D (off_t)-1) { + qio_channel_set_feature(QIO_CHANNEL(ioc), QIO_CHANNEL_FEATURE_SEEK= ABLE); + } + trace_qio_channel_file_new_path(ioc, path, flags, mode, ioc->fd); =20 return ioc; --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515660; cv=none; d=zohomail.com; s=zohoarc; b=Y7NPdlXDTX+5J6jcbK1I4gdwl6HuT6VBzJ6Pnr7UkmdLpuop/Crzxz4gg9+9562zWT4BPIcr7YTV5DCuynmEJRwPxlkEWm8crOSGcyQiSabJ86dCtm5DxSXBFgHnf9CetW3eGvVzNdaT5TFZ5sl9JkCkZ3Eamx+G+zsm6MltVMU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515660; h=Content-Type: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=hJGmWnbooz2CMut3kruNHzhEFGJqsD9uISC81AxmzUI=; b=ki7vC4IPqkcataWMM77Wn6Djpd5Ivxtz5SgxPglW7x1T9PFA0fymo+OH/JSB7Dd+ZInL0ONYONlq5uMfHLHRgDN7+sgHqc9yMH0ypcyiIA5Tocf7BUGVImdOTNywnuer1K7Hr+1Zee4DHCZxYKa5Pq4W+XYmFv2z2GPkE0PNUL0= 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 1709515660184454.9234529510071; Sun, 3 Mar 2024 17:27:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx79-0001Mq-Ul; Sun, 03 Mar 2024 20:27:35 -0500 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 1rgx75-0001FB-Lw for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx6o-0002Em-9B for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:29 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-34-re0_uwB9OraZFsKMiXwm6A-1; Sun, 03 Mar 2024 20:27:09 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BF1613814E8D; Mon, 4 Mar 2024 01:27:08 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF3F740C6EBA; Mon, 4 Mar 2024 01:27:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515632; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hJGmWnbooz2CMut3kruNHzhEFGJqsD9uISC81AxmzUI=; b=A2N5hwQgKQCEZuhfRcTdP8rRxA4B6ZeI6gKfUEiLc/m8vXHY+TwjuZTmJEBMMlxcHN41hA XAtG88dt867Bp8ZlELso0pr2jzWJq4YUZ8FHOZmMu9SHcDK5fycfov/mDorltC63CljrEV XDfVvCRkEw/9gZ6rdedtP7FKxurNfz8= X-MC-Unique: re0_uwB9OraZFsKMiXwm6A-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas , Nikolay Borisov Subject: [PULL 06/27] io: Add generic pwritev/preadv interface Date: Mon, 4 Mar 2024 09:26:13 +0800 Message-ID: <20240304012634.95520-7-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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 @redhat.com) X-ZM-MESSAGEID: 1709515660840100001 From: Nikolay Borisov Introduce basic pwritev/preadv support in the generic channel layer. Specific implementation will follow for the file channel as this is required in order to support migration streams with fixed location of each ram page. Signed-off-by: Nikolay Borisov Reviewed-by: "Daniel P. Berrang=C3=A9" Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240229153017.2221-4-farosas@suse.de Signed-off-by: Peter Xu --- include/io/channel.h | 82 ++++++++++++++++++++++++++++++++++++++++++++ io/channel.c | 58 +++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) diff --git a/include/io/channel.h b/include/io/channel.h index fcb19fd672..7986c49c71 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -131,6 +131,16 @@ struct QIOChannelClass { Error **errp); =20 /* Optional callbacks */ + ssize_t (*io_pwritev)(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + off_t offset, + Error **errp); + ssize_t (*io_preadv)(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + off_t offset, + Error **errp); int (*io_shutdown)(QIOChannel *ioc, QIOChannelShutdown how, Error **errp); @@ -529,6 +539,78 @@ void qio_channel_set_follow_coroutine_ctx(QIOChannel *= ioc, bool enabled); int qio_channel_close(QIOChannel *ioc, Error **errp); =20 +/** + * qio_channel_pwritev + * @ioc: the channel object + * @iov: the array of memory regions to write data from + * @niov: the length of the @iov array + * @offset: offset in the channel where writes should begin + * @errp: pointer to a NULL-initialized error object + * + * Not all implementations will support this facility, so may report + * an error. To avoid errors, the caller may check for the feature + * flag QIO_CHANNEL_FEATURE_SEEKABLE prior to calling this method. + * + * Behaves as qio_channel_writev_full, apart from not supporting + * sending of file handles as well as beginning the write at the + * passed @offset + * + */ +ssize_t qio_channel_pwritev(QIOChannel *ioc, const struct iovec *iov, + size_t niov, off_t offset, Error **errp); + +/** + * qio_channel_pwrite + * @ioc: the channel object + * @buf: the memory region to write data into + * @buflen: the number of bytes to @buf + * @offset: offset in the channel where writes should begin + * @errp: pointer to a NULL-initialized error object + * + * Not all implementations will support this facility, so may report + * an error. To avoid errors, the caller may check for the feature + * flag QIO_CHANNEL_FEATURE_SEEKABLE prior to calling this method. + * + */ +ssize_t qio_channel_pwrite(QIOChannel *ioc, char *buf, size_t buflen, + off_t offset, Error **errp); + +/** + * qio_channel_preadv + * @ioc: the channel object + * @iov: the array of memory regions to read data into + * @niov: the length of the @iov array + * @offset: offset in the channel where writes should begin + * @errp: pointer to a NULL-initialized error object + * + * Not all implementations will support this facility, so may report + * an error. To avoid errors, the caller may check for the feature + * flag QIO_CHANNEL_FEATURE_SEEKABLE prior to calling this method. + * + * Behaves as qio_channel_readv_full, apart from not supporting + * receiving of file handles as well as beginning the read at the + * passed @offset + * + */ +ssize_t qio_channel_preadv(QIOChannel *ioc, const struct iovec *iov, + size_t niov, off_t offset, Error **errp); + +/** + * qio_channel_pread + * @ioc: the channel object + * @buf: the memory region to write data into + * @buflen: the number of bytes to @buf + * @offset: offset in the channel where writes should begin + * @errp: pointer to a NULL-initialized error object + * + * Not all implementations will support this facility, so may report + * an error. To avoid errors, the caller may check for the feature + * flag QIO_CHANNEL_FEATURE_SEEKABLE prior to calling this method. + * + */ +ssize_t qio_channel_pread(QIOChannel *ioc, char *buf, size_t buflen, + off_t offset, Error **errp); + /** * qio_channel_shutdown: * @ioc: the channel object diff --git a/io/channel.c b/io/channel.c index 86c5834510..a1f12f8e90 100644 --- a/io/channel.c +++ b/io/channel.c @@ -454,6 +454,64 @@ GSource *qio_channel_add_watch_source(QIOChannel *ioc, } =20 =20 +ssize_t qio_channel_pwritev(QIOChannel *ioc, const struct iovec *iov, + size_t niov, off_t offset, Error **errp) +{ + QIOChannelClass *klass =3D QIO_CHANNEL_GET_CLASS(ioc); + + if (!klass->io_pwritev) { + error_setg(errp, "Channel does not support pwritev"); + return -1; + } + + if (!qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_SEEKABLE)) { + error_setg_errno(errp, EINVAL, "Requested channel is not seekable"= ); + return -1; + } + + return klass->io_pwritev(ioc, iov, niov, offset, errp); +} + +ssize_t qio_channel_pwrite(QIOChannel *ioc, char *buf, size_t buflen, + off_t offset, Error **errp) +{ + struct iovec iov =3D { + .iov_base =3D buf, + .iov_len =3D buflen + }; + + return qio_channel_pwritev(ioc, &iov, 1, offset, errp); +} + +ssize_t qio_channel_preadv(QIOChannel *ioc, const struct iovec *iov, + size_t niov, off_t offset, Error **errp) +{ + QIOChannelClass *klass =3D QIO_CHANNEL_GET_CLASS(ioc); + + if (!klass->io_preadv) { + error_setg(errp, "Channel does not support preadv"); + return -1; + } + + if (!qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_SEEKABLE)) { + error_setg_errno(errp, EINVAL, "Requested channel is not seekable"= ); + return -1; + } + + return klass->io_preadv(ioc, iov, niov, offset, errp); +} + +ssize_t qio_channel_pread(QIOChannel *ioc, char *buf, size_t buflen, + off_t offset, Error **errp) +{ + struct iovec iov =3D { + .iov_base =3D buf, + .iov_len =3D buflen + }; + + return qio_channel_preadv(ioc, &iov, 1, offset, errp); +} + int qio_channel_shutdown(QIOChannel *ioc, QIOChannelShutdown how, Error **errp) --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515868; cv=none; d=zohomail.com; s=zohoarc; b=UtFz7ZwMETfPsMFwjvg/BZv9lZbWm6/gnoE9VWQTCcBk3AZPZl/rU7pyy+fObH1/QtYHSrf1vSLEtGkBZZnFsBGxo6H5S2bd1Rt15SS0yP+bXbEuIL1uxvZ041ejylRM/Zbnj7ZmhOEOo7VcOX8BX4Uj18h29aTx5eloJpednr4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515868; h=Content-Type: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=BsTsSZj0lyl+eM84vQxVcYu/bCjr0mDEg/MlpEYR7ts=; b=EnML65GXn6R63ckfePx/4MCYkbpPKl2XZXlgUdiJxpdg+DO0FJ/Ei5+Dh1cDf+t1/s+7JLLHdPHAc3NP1N2E0f10s/YKMBBNLyFP/DXsmZKyHaIgO1gJit0dbo5gs9lgCWZDZeB6oXqTrXoP9CHHPFapPftB9aOgCtm1UCBM7PA= 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 1709515868394779.1088264898418; Sun, 3 Mar 2024 17:31:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx6u-0001ET-Qy; Sun, 03 Mar 2024 20:27:20 -0500 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 1rgx6t-0001E5-4m for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx6r-0002Ev-It for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:18 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-553-Ywm8vJiXNqKD4p9LGfX6SA-1; Sun, 03 Mar 2024 20:27:13 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 606631C0512A; Mon, 4 Mar 2024 01:27:13 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F46640C6EBA; Mon, 4 Mar 2024 01:27:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515636; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BsTsSZj0lyl+eM84vQxVcYu/bCjr0mDEg/MlpEYR7ts=; b=Bb6SDdtcOp0VEz8/Jwm4y6huF/xrWeYuhJEKHahnP7y0wO0nCm3VKnqRXDNUajKT5dWQjQ JZoBc8neOSofbpCkqWRJG5jxDFwqhRXUv4ItMfqmjLx6HA0K0o6W9zlBaJoovQy93UrWKx Q3TtycreEEivZbB9iMF5nIgX1xt/gFA= X-MC-Unique: Ywm8vJiXNqKD4p9LGfX6SA-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas , Nikolay Borisov Subject: [PULL 07/27] io: implement io_pwritev/preadv for QIOChannelFile Date: Mon, 4 Mar 2024 09:26:14 +0800 Message-ID: <20240304012634.95520-8-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1709515869602100001 From: Nikolay Borisov The upcoming 'mapped-ram' feature will require qemu to write data to (and restore from) specific offsets of the migration file. Add a minimal implementation of pwritev/preadv and expose them via the io_pwritev and io_preadv interfaces. Signed-off-by: Nikolay Borisov Reviewed-by: "Daniel P. Berrang=C3=A9" Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240229153017.2221-5-farosas@suse.de Signed-off-by: Peter Xu --- io/channel-file.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/io/channel-file.c b/io/channel-file.c index f91bf6db1c..a6ad7770c6 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -146,6 +146,58 @@ static ssize_t qio_channel_file_writev(QIOChannel *ioc, return ret; } =20 +#ifdef CONFIG_PREADV +static ssize_t qio_channel_file_preadv(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + off_t offset, + Error **errp) +{ + QIOChannelFile *fioc =3D QIO_CHANNEL_FILE(ioc); + ssize_t ret; + + retry: + ret =3D preadv(fioc->fd, iov, niov, offset); + if (ret < 0) { + if (errno =3D=3D EAGAIN) { + return QIO_CHANNEL_ERR_BLOCK; + } + if (errno =3D=3D EINTR) { + goto retry; + } + + error_setg_errno(errp, errno, "Unable to read from file"); + return -1; + } + + return ret; +} + +static ssize_t qio_channel_file_pwritev(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + off_t offset, + Error **errp) +{ + QIOChannelFile *fioc =3D QIO_CHANNEL_FILE(ioc); + ssize_t ret; + + retry: + ret =3D pwritev(fioc->fd, iov, niov, offset); + if (ret <=3D 0) { + if (errno =3D=3D EAGAIN) { + return QIO_CHANNEL_ERR_BLOCK; + } + if (errno =3D=3D EINTR) { + goto retry; + } + error_setg_errno(errp, errno, "Unable to write to file"); + return -1; + } + return ret; +} +#endif /* CONFIG_PREADV */ + static int qio_channel_file_set_blocking(QIOChannel *ioc, bool enabled, Error **errp) @@ -231,6 +283,10 @@ static void qio_channel_file_class_init(ObjectClass *k= lass, ioc_klass->io_writev =3D qio_channel_file_writev; ioc_klass->io_readv =3D qio_channel_file_readv; ioc_klass->io_set_blocking =3D qio_channel_file_set_blocking; +#ifdef CONFIG_PREADV + ioc_klass->io_pwritev =3D qio_channel_file_pwritev; + ioc_klass->io_preadv =3D qio_channel_file_preadv; +#endif ioc_klass->io_seek =3D qio_channel_file_seek; ioc_klass->io_close =3D qio_channel_file_close; ioc_klass->io_create_watch =3D qio_channel_file_create_watch; --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515691; cv=none; d=zohomail.com; s=zohoarc; b=brqguooJvcSZVO6T3mu4X1RkITXFpJTQj7MgimXUpYt8ECH4h86ikO7yvjJeSF4YjZqX0m2cQFYn45/Vauk0eY+9AOQGl8wGDfpQ5B8QpTNh3Omhxo+A8JuzEF+E1KYmQNItx2xoMcjWYYf81VNta2jRtzlLFDCQTYXd5l7eZHQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515691; h=Content-Type: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=jyrMLcYDQUIO1DuGLIv/0GBLvb6vogf3wk1vgjaSm74=; b=LM1lBmr0REzy3hNjcA+eh2L6Gkiv43hWzVvveYmyMPU497I3rQJo9EzDVnGa9/CMYWGUSCVxRRIUPxFLiQOEM2gFnLfXsmQtycE3rC+e0xGTH3fNZpXydW0AcLca8CyrbDQnpGBqtkbrISYn4UdyMRcVgHGTm9DnYyWby61O+Z8= 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 1709515691035396.1175317579499; Sun, 3 Mar 2024 17:28:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx75-0001Er-HB; Sun, 03 Mar 2024 20:27:31 -0500 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 1rgx6z-0001Ee-24 for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx6w-0002Iy-1R for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:23 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-413-P6J44ohpP7iF2WPXOg73Kg-1; Sun, 03 Mar 2024 20:27:18 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AA58E811E81; Mon, 4 Mar 2024 01:27:17 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F9AE40C6EBA; Mon, 4 Mar 2024 01:27:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515641; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jyrMLcYDQUIO1DuGLIv/0GBLvb6vogf3wk1vgjaSm74=; b=QvGKgX7hF9YxsXsQbf3ybTEQ+RuDNVZ0REx6tAKZ4mzrdHBJBC5ZbupyfA12kDQjz8qMtm tLRrJMSZwow3iPmAOYLuEMByJgmr6aNSnxYYZWSKYxEekk0+PJE6ohwzVy1io4Etet6Jjo +zupNVqS6NYlAehzu9yM2MBC7cN/viQ= X-MC-Unique: P6J44ohpP7iF2WPXOg73Kg-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas Subject: [PULL 08/27] io: fsync before closing a file channel Date: Mon, 4 Mar 2024 09:26:15 +0800 Message-ID: <20240304012634.95520-9-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1709515692956100003 From: Fabiano Rosas Make sure the data is flushed to disk before closing file channels. This is to ensure data is on disk and not lost in the event of a host crash. This is currently being implemented to affect the migration code when migrating to a file, but all QIOChannelFile users should benefit from the change. Reviewed-by: "Daniel P. Berrang=C3=A9" Acked-by: "Daniel P. Berrang=C3=A9" Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240229153017.2221-6-farosas@suse.de Signed-off-by: Peter Xu --- io/channel-file.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/io/channel-file.c b/io/channel-file.c index a6ad7770c6..d4706fa592 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -242,6 +242,11 @@ static int qio_channel_file_close(QIOChannel *ioc, { QIOChannelFile *fioc =3D QIO_CHANNEL_FILE(ioc); =20 + if (qemu_fdatasync(fioc->fd) < 0) { + error_setg_errno(errp, errno, + "Unable to synchronize file data with storage dev= ice"); + return -1; + } if (qemu_close(fioc->fd) < 0) { error_setg_errno(errp, errno, "Unable to close file"); --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515736; cv=none; d=zohomail.com; s=zohoarc; b=GB8JRAUVnKKjsFQP0CGQPPMVVnrp5YRPqZBhp80g3SDsBMCziPbaqyFCeANpgQ41+vk3lXn0fKD7FYuYjx4+AqWaNPZaWAdilQm8xH1sYCswo7Ys9qD0aDEPdrmelonxkKFWGlqgfWndA7ryCzd+qL4IfP6xsPzRPalwkifI+EE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515736; h=Content-Type: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=DesdufDtGYfA1p4c4k9QF7KmvVTn3HtsAA5zhrljpmY=; b=TsmoFdKYk/um23RhAv8NFrlbCg2l9tw213tBAzw+YhcwQeQ3fG0Jfw7ao24OxlqGhD3gnph6Mx7rY1yc+x4okam9larPoEHbserTUxtOTgrG5n7owcgrO+1nMA9kWk0S3wLgypzdJlwMSRzqCSP6PMwYw1HF6rH3dzvg+fkoeKI= 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 1709515736919230.85620731855863; Sun, 3 Mar 2024 17:28:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx7J-0001W2-Tl; Sun, 03 Mar 2024 20:27:45 -0500 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 1rgx7F-0001Tt-K9 for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx6z-0002Jy-Db for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:39 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-LwlqkKlyO96hOEFGNFQbzg-1; Sun, 03 Mar 2024 20:27:21 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8FBED29ABA08; Mon, 4 Mar 2024 01:27:21 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6183B40C6EBA; Mon, 4 Mar 2024 01:27:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515643; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DesdufDtGYfA1p4c4k9QF7KmvVTn3HtsAA5zhrljpmY=; b=JTGZNqVgCrudo8Y8FRSAwtZUKGVAONL78YqqDLyjXzVmNfYvyGYczfVtii9qLl0lhQbwAL Seu2U1WGTUH49jud1WC70WsF3yUhTyn5m1JtYC0g4hbb0QCGD/4FIV3qer2ZNlGVHyigiC dnz0OsVf5xHwRsI2tB6qwE262+BZJB0= X-MC-Unique: LwlqkKlyO96hOEFGNFQbzg-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas Subject: [PULL 09/27] migration/qemu-file: add utility methods for working with seekable channels Date: Mon, 4 Mar 2024 09:26:16 +0800 Message-ID: <20240304012634.95520-10-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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 @redhat.com) X-ZM-MESSAGEID: 1709515737097100001 From: Fabiano Rosas Add utility methods that will be needed when implementing 'mapped-ram' migration capability. Signed-off-by: Fabiano Rosas Reviewed-by: "Daniel P. Berrang=C3=A9" Link: https://lore.kernel.org/r/20240229153017.2221-7-farosas@suse.de Signed-off-by: Peter Xu --- include/migration/qemu-file-types.h | 2 + migration/qemu-file.h | 6 ++ migration/qemu-file.c | 106 ++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) diff --git a/include/migration/qemu-file-types.h b/include/migration/qemu-f= ile-types.h index 9ba163f333..adec5abc07 100644 --- a/include/migration/qemu-file-types.h +++ b/include/migration/qemu-file-types.h @@ -50,6 +50,8 @@ unsigned int qemu_get_be16(QEMUFile *f); unsigned int qemu_get_be32(QEMUFile *f); uint64_t qemu_get_be64(QEMUFile *f); =20 +bool qemu_file_is_seekable(QEMUFile *f); + static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv) { qemu_put_be64(f, *pv); diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 8aec9fabf7..32fd4a34fd 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -75,6 +75,12 @@ QEMUFile *qemu_file_get_return_path(QEMUFile *f); int qemu_fflush(QEMUFile *f); void qemu_file_set_blocking(QEMUFile *f, bool block); int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size); +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, const uint8_t *buf, size_t buflen, + off_t pos); =20 QIOChannel *qemu_file_get_ioc(QEMUFile *file); =20 diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 94231ff295..b10c882629 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -33,6 +33,7 @@ #include "options.h" #include "qapi/error.h" #include "rdma.h" +#include "io/channel-file.h" =20 #define IO_BUF_SIZE 32768 #define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64) @@ -255,6 +256,10 @@ static void qemu_iovec_release_ram(QEMUFile *f) memset(f->may_free, 0, sizeof(f->may_free)); } =20 +bool qemu_file_is_seekable(QEMUFile *f) +{ + return qio_channel_has_feature(f->ioc, QIO_CHANNEL_FEATURE_SEEKABLE); +} =20 /** * Flushes QEMUFile buffer @@ -447,6 +452,107 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf,= size_t size) } } =20 +void qemu_put_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen, + off_t pos) +{ + Error *err =3D NULL; + size_t ret; + + if (f->last_error) { + return; + } + + qemu_fflush(f); + ret =3D qio_channel_pwrite(f->ioc, (char *)buf, buflen, pos, &err); + + if (err) { + qemu_file_set_error_obj(f, -EIO, err); + return; + } + + if ((ssize_t)ret =3D=3D QIO_CHANNEL_ERR_BLOCK) { + qemu_file_set_error_obj(f, -EAGAIN, NULL); + return; + } + + if (ret !=3D buflen) { + error_setg(&err, "Partial write of size %zu, expected %zu", ret, + buflen); + qemu_file_set_error_obj(f, -EIO, err); + return; + } + + stat64_add(&mig_stats.qemu_file_transferred, buflen); + + return; +} + + +size_t qemu_get_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen, + off_t pos) +{ + Error *err =3D NULL; + size_t ret; + + if (f->last_error) { + return 0; + } + + ret =3D qio_channel_pread(f->ioc, (char *)buf, buflen, pos, &err); + + if ((ssize_t)ret =3D=3D -1 || err) { + qemu_file_set_error_obj(f, -EIO, err); + return 0; + } + + if ((ssize_t)ret =3D=3D QIO_CHANNEL_ERR_BLOCK) { + qemu_file_set_error_obj(f, -EAGAIN, NULL); + return 0; + } + + if (ret !=3D buflen) { + error_setg(&err, "Partial read of size %zu, expected %zu", ret, bu= flen); + qemu_file_set_error_obj(f, -EIO, err); + return 0; + } + + return ret; +} + +void qemu_set_offset(QEMUFile *f, off_t off, int whence) +{ + Error *err =3D NULL; + off_t ret; + + if (qemu_file_is_writable(f)) { + qemu_fflush(f); + } else { + /* Drop all cached buffers if existed; will trigger a re-fill late= r */ + f->buf_index =3D 0; + f->buf_size =3D 0; + } + + ret =3D qio_channel_io_seek(f->ioc, off, whence, &err); + if (ret =3D=3D (off_t)-1) { + qemu_file_set_error_obj(f, -EIO, err); + } +} + +off_t qemu_get_offset(QEMUFile *f) +{ + Error *err =3D NULL; + off_t ret; + + qemu_fflush(f); + + ret =3D qio_channel_io_seek(f->ioc, 0, SEEK_CUR, &err); + if (ret =3D=3D (off_t)-1) { + qemu_file_set_error_obj(f, -EIO, err); + } + return ret; +} + + void qemu_put_byte(QEMUFile *f, int v) { if (f->last_error) { --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515705; cv=none; d=zohomail.com; s=zohoarc; b=Tt8d3eNbf0PprcCbKTOEJhqkGTCJpXGGi94jTPc4W4PLqHrb/qkLru4Kc0I6H63dH+asahM/8rX1EdUew/J2x1ADpT7KPtKLWTOu0qMDhywIQaZE2A7FPQSxIvN+olravlbPqdu6hoDIRt/LzIfQWwlRfxgab3SQ5VgVxedBAAk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515705; 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=FEJkd+Fnu0BaUcq09pzXPOnzQP5japOLAZGZ/W8ckog=; b=mHdLtoBhroymt0OG4E3+NjA56HcSA7BgOKX27mqdSWhqYDB2LR+Os1sLWBCGPiZyX77jCd5CwTZeChBMD/2eO60BYY4cJzEArV/xAWrqqxY3oV/1yGq5GJiM+HRJSua5nvm7QQltot6v6T2hKwNLESxk0QcJD2SnaS6qBGmFJKM= 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 1709515705260725.4898000029957; Sun, 3 Mar 2024 17:28:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx7B-0001Pu-LB; Sun, 03 Mar 2024 20:27:37 -0500 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 1rgx77-0001Kg-HO for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx75-0002L7-Bt for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:33 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-689-s7lfNDJSPjyM0yrpLAutNA-1; Sun, 03 Mar 2024 20:27:26 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 33B611064DA2; Mon, 4 Mar 2024 01:27:26 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E86440C94A7; Mon, 4 Mar 2024 01:27:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515649; h=from:from:reply-to:subject:subject: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=FEJkd+Fnu0BaUcq09pzXPOnzQP5japOLAZGZ/W8ckog=; b=RYLPwtnEyc9eP5MWCCDL0IqoJYEpnHUS3C6OWnBn6RBHl7j0Bwj6U3R0ppxduh8TxCxmy3 ShF6jZiXm/NSopJUr/uT1v3JP+C0PjNW0Hcu7AY5G+9QE7JV7uPZBUImYhJUnlLM0TS4Go kWNeUQ2yrngfKR5vsd6rRzQDMz+Hcuo= X-MC-Unique: s7lfNDJSPjyM0yrpLAutNA-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas , Markus Armbruster Subject: [PULL 10/27] migration/ram: Introduce 'mapped-ram' migration capability Date: Mon, 4 Mar 2024 09:26:17 +0800 Message-ID: <20240304012634.95520-11-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1709515707035100001 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas Add a new migration capability 'mapped-ram'. The core of the feature is to ensure that RAM pages are mapped directly to offsets in the resulting migration file instead of being streamed at arbitrary points. The reasons why we'd want such behavior are: - The resulting file will have a bounded size, since pages which are dirtied multiple times will always go to a fixed location in the file, rather than constantly being added to a sequential stream. This eliminates cases where a VM with, say, 1G of RAM can result in a migration file that's 10s of GBs, provided that the workload constantly redirties memory. - It paves the way to implement O_DIRECT-enabled save/restore of the migration stream as the pages are ensured to be written at aligned offsets. - It allows the usage of multifd so we can write RAM pages to the migration file in parallel. For now, enabling the capability has no effect. The next couple of patches implement the core functionality. Acked-by: Markus Armbruster Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240229153017.2221-8-farosas@suse.de Signed-off-by: Peter Xu --- docs/devel/migration/features.rst | 1 + docs/devel/migration/mapped-ram.rst | 138 ++++++++++++++++++++++++++++ qapi/migration.json | 6 +- migration/options.h | 1 + migration/migration.c | 7 ++ migration/options.c | 34 +++++++ migration/savevm.c | 1 + 7 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 docs/devel/migration/mapped-ram.rst diff --git a/docs/devel/migration/features.rst b/docs/devel/migration/featu= res.rst index a9acaf618e..9d1abd2587 100644 --- a/docs/devel/migration/features.rst +++ b/docs/devel/migration/features.rst @@ -10,3 +10,4 @@ Migration has plenty of features to support different use= cases. dirty-limit vfio virtio + mapped-ram diff --git a/docs/devel/migration/mapped-ram.rst b/docs/devel/migration/map= ped-ram.rst new file mode 100644 index 0000000000..fa4cefd9fc --- /dev/null +++ b/docs/devel/migration/mapped-ram.rst @@ -0,0 +1,138 @@ +Mapped-ram +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Mapped-ram is a new stream format for the RAM section designed to +supplement the existing ``file:`` migration and make it compatible +with ``multifd``. This enables parallel migration of a guest's RAM to +a file. + +The core of the feature is to ensure that RAM pages are mapped +directly to offsets in the resulting migration file. This enables the +``multifd`` threads to write exclusively to those offsets even if the +guest is constantly dirtying pages (i.e. live migration). Another +benefit is that the resulting file will have a bounded size, since +pages which are dirtied multiple times will always go to a fixed +location in the file, rather than constantly being added to a +sequential stream. Having the pages at fixed offsets also allows the +usage of O_DIRECT for save/restore of the migration stream as the +pages are ensured to be written respecting O_DIRECT alignment +restrictions (direct-io support not yet implemented). + +Usage +----- + +On both source and destination, enable the ``multifd`` and +``mapped-ram`` capabilities: + + ``migrate_set_capability multifd on`` + + ``migrate_set_capability mapped-ram on`` + +Use a ``file:`` URL for migration: + + ``migrate file:/path/to/migration/file`` + +Mapped-ram migration is best done non-live, i.e. by stopping the VM on +the source side before migrating. + +Use-cases +--------- + +The mapped-ram feature was designed for use cases where the migration +stream will be directed to a file in the filesystem and not +immediately restored on the destination VM [#]_. These could be +thought of as snapshots. We can further categorize them into live and +non-live. + +- Non-live snapshot + +If the use case requires a VM to be stopped before taking a snapshot, +that's the ideal scenario for mapped-ram migration. Not having to +track dirty pages, the migration will write the RAM pages to the disk +as fast as it can. + +Note: if a snapshot is taken of a running VM, but the VM will be +stopped after the snapshot by the admin, then consider stopping it +right before the snapshot to take benefit of the performance gains +mentioned above. + +- Live snapshot + +If the use case requires that the VM keeps running during and after +the snapshot operation, then mapped-ram migration can still be used, +but will be less performant. Other strategies such as +background-snapshot should be evaluated as well. One benefit of +mapped-ram in this scenario is portability since background-snapshot +depends on async dirty tracking (KVM_GET_DIRTY_LOG) which is not +supported outside of Linux. + +.. [#] While this same effect could be obtained with the usage of + snapshots or the ``file:`` migration alone, mapped-ram provides + a performance increase for VMs with larger RAM sizes (10s to + 100s of GiBs), specially if the VM has been stopped beforehand. + +RAM section format +------------------ + +Instead of having a sequential stream of pages that follow the +RAMBlock headers, the dirty pages for a RAMBlock follow its header +instead. This ensures that each RAM page has a fixed offset in the +resulting migration file. + +A bitmap is introduced to track which pages have been written in the +migration file. Pages are written at a fixed location for every +ramblock. Zero pages are ignored as they'd be zero in the destination +migration as well. + +:: + + Without mapped-ram: With mapped-ram: + + --------------------- -------------------------------- + | ramblock 1 header | | ramblock 1 header | + --------------------- -------------------------------- + | ramblock 2 header | | ramblock 1 mapped-ram header | + --------------------- -------------------------------- + | ... | | padding to next 1MB boundary | + --------------------- | ... | + | ramblock n header | -------------------------------- + --------------------- | ramblock 1 pages | + | RAM_SAVE_FLAG_EOS | | ... | + --------------------- -------------------------------- + | stream of pages | | ramblock 2 header | + | (iter 1) | -------------------------------- + | ... | | ramblock 2 mapped-ram header | + --------------------- -------------------------------- + | RAM_SAVE_FLAG_EOS | | padding to next 1MB boundary | + --------------------- | ... | + | stream of pages | -------------------------------- + | (iter 2) | | ramblock 2 pages | + | ... | | ... | + --------------------- -------------------------------- + | ... | | ... | + --------------------- -------------------------------- + | RAM_SAVE_FLAG_EOS | + -------------------------------- + | ... | + -------------------------------- + +where: + - ramblock header: the generic information for a ramblock, such as + idstr, used_len, etc. + + - ramblock mapped-ram header: the information added by this feature: + bitmap of pages written, bitmap size and offset of pages in the + migration file. + +Restrictions +------------ + +Since pages are written to their relative offsets and out of order +(due to the memory dirtying patterns), streaming channels such as +sockets are not supported. A seekable channel such as a file is +required. This can be verified in the QIOChannel by the presence of +the QIO_CHANNEL_FEATURE_SEEKABLE. + +The improvements brought by this feature apply only to guest physical +RAM. Other types of memory such as VRAM are migrated as part of device +states. diff --git a/qapi/migration.json b/qapi/migration.json index b603aa6f25..62acc834af 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -531,6 +531,10 @@ # and can result in more stable read performance. Requires KVM # with accelerator property "dirty-ring-size" set. (Since 8.1) # +# @mapped-ram: Migrate using fixed offsets in the migration file for +# each RAM page. Requires a migration URI that supports seeking, +# such as a file. (since 9.0) +# # Features: # # @deprecated: Member @block is deprecated. Use blockdev-mirror with @@ -555,7 +559,7 @@ { 'name': 'x-ignore-shared', 'features': [ 'unstable' ] }, 'validate-uuid', 'background-snapshot', 'zero-copy-send', 'postcopy-preempt', 'switchover-ack', - 'dirty-limit'] } + 'dirty-limit', 'mapped-ram'] } =20 ## # @MigrationCapabilityStatus: diff --git a/migration/options.h b/migration/options.h index 246c160aee..6ddd8dad9b 100644 --- a/migration/options.h +++ b/migration/options.h @@ -31,6 +31,7 @@ bool migrate_compress(void); bool migrate_dirty_bitmaps(void); bool migrate_dirty_limit(void); bool migrate_events(void); +bool migrate_mapped_ram(void); bool migrate_ignore_shared(void); bool migrate_late_block_activate(void); bool migrate_multifd(void); diff --git a/migration/migration.c b/migration/migration.c index bab68bcbef..69f68f940d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1950,6 +1950,13 @@ static bool migrate_prepare(MigrationState *s, bool = blk, bool blk_inc, return false; } =20 + if (migrate_mapped_ram()) { + if (migrate_tls()) { + error_setg(errp, "Cannot use TLS with mapped-ram"); + return false; + } + } + if (migrate_mode_is_cpr(s)) { const char *conflict =3D NULL; =20 diff --git a/migration/options.c b/migration/options.c index 1cd3cc7c33..5df89820fd 100644 --- a/migration/options.c +++ b/migration/options.c @@ -204,6 +204,7 @@ Property migration_properties[] =3D { DEFINE_PROP_MIG_CAP("x-switchover-ack", MIGRATION_CAPABILITY_SWITCHOVER_ACK), DEFINE_PROP_MIG_CAP("x-dirty-limit", MIGRATION_CAPABILITY_DIRTY_LIMIT), + DEFINE_PROP_MIG_CAP("mapped-ram", MIGRATION_CAPABILITY_MAPPED_RAM), DEFINE_PROP_END_OF_LIST(), }; =20 @@ -263,6 +264,13 @@ bool migrate_events(void) return s->capabilities[MIGRATION_CAPABILITY_EVENTS]; } =20 +bool migrate_mapped_ram(void) +{ + MigrationState *s =3D migrate_get_current(); + + return s->capabilities[MIGRATION_CAPABILITY_MAPPED_RAM]; +} + bool migrate_ignore_shared(void) { MigrationState *s =3D migrate_get_current(); @@ -645,6 +653,32 @@ bool migrate_caps_check(bool *old_caps, bool *new_caps= , Error **errp) } } =20 + if (new_caps[MIGRATION_CAPABILITY_MAPPED_RAM]) { + if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) { + error_setg(errp, + "Mapped-ram migration is incompatible with multifd"= ); + return false; + } + + if (new_caps[MIGRATION_CAPABILITY_XBZRLE]) { + error_setg(errp, + "Mapped-ram migration is incompatible with xbzrle"); + return false; + } + + if (new_caps[MIGRATION_CAPABILITY_COMPRESS]) { + error_setg(errp, + "Mapped-ram migration is incompatible with compress= ion"); + return false; + } + + if (new_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM]) { + error_setg(errp, + "Mapped-ram migration is incompatible with postcopy= "); + return false; + } + } + return true; } =20 diff --git a/migration/savevm.c b/migration/savevm.c index d612c8a902..dc1fb9c0d3 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -245,6 +245,7 @@ static bool should_validate_capability(int capability) /* Validate only new capabilities to keep compatibility. */ switch (capability) { case MIGRATION_CAPABILITY_X_IGNORE_SHARED: + case MIGRATION_CAPABILITY_MAPPED_RAM: return true; default: return false; --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515741; cv=none; d=zohomail.com; s=zohoarc; b=EezkcFzKDJfKZU9Gflhevu7w2IL0AX9Y5H7y4OvaE4EhNMAI4sts3D+U79iqYOkayMpxMzmaaHnxvG0fjnpQTBkxGxBTe4rB/QP2TXnB9vYdE+8IqHKdw41TiFHFpDQsJ7pbDvaqGi/khnQL4zpmTz4oMF3JiMURjlgNxVPuivo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515741; h=Content-Type: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=ZJ+HNeqglJdMcQsTtamaGE7iHX66VkDcR8uP6a0Bcpg=; b=KTZlI63nZt6ZnCt2WZ5O+Cxwqu0VzPhhGdq9SaUG5wAm7RU+IiXBEBfPDp8bn6Y8FW1CfFhfIhpc/k9JHsgk7JhrGYQ2x7cHG5JkBe2jW3fHw7VkAuieFUblLB4auF5i61Zz6tYguafzFQeo6KGQQ5YBEVAY/dP8tXX0IJzODW0= 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 1709515741045768.4697050210233; Sun, 3 Mar 2024 17:29:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx7H-0001U2-8Z; Sun, 03 Mar 2024 20:27:43 -0500 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 1rgx7A-0001Pt-KQ for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx79-0002LU-3v for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:36 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-340-oHHMq0p9OvWdJ9_Ez8J-eQ-1; Sun, 03 Mar 2024 20:27:30 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 785CF85A588; Mon, 4 Mar 2024 01:27:30 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id F304540C6EBA; Mon, 4 Mar 2024 01:27:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515654; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZJ+HNeqglJdMcQsTtamaGE7iHX66VkDcR8uP6a0Bcpg=; b=OaPLIR6jErvEhKcb9zgKK0otLfM9lvu24m56azKM64qsqAJJU5/RiXR3q2aKisIdcopqV9 uxNX1CulsdI0FGuutpyTO44jfQXRac5hRWLhe0n3UYIqMLdJYT+VzA+JlnSl4Tqhgx1vth g3v60bQBfc4RCFe5YvZvxlVyWQZaib4= X-MC-Unique: oHHMq0p9OvWdJ9_Ez8J-eQ-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas Subject: [PULL 11/27] migration: Add mapped-ram URI compatibility check Date: Mon, 4 Mar 2024 09:26:18 +0800 Message-ID: <20240304012634.95520-12-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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 @redhat.com) X-ZM-MESSAGEID: 1709515743130100003 From: Fabiano Rosas The mapped-ram migration format needs a channel that supports seeking to be able to write each page to an arbitrary offset in the migration stream. Reviewed-by: "Daniel P. Berrang=C3=A9" Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240229153017.2221-9-farosas@suse.de Signed-off-by: Peter Xu --- migration/migration.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index 69f68f940d..2669600d25 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -148,10 +148,39 @@ static bool transport_supports_multi_channels(Migrati= onAddress *addr) return false; } =20 +static bool migration_needs_seekable_channel(void) +{ + return migrate_mapped_ram(); +} + +static bool transport_supports_seeking(MigrationAddress *addr) +{ + if (addr->transport =3D=3D MIGRATION_ADDRESS_TYPE_FILE) { + return true; + } + + /* + * At this point, the user might not yet have passed the file + * descriptor to QEMU, so we cannot know for sure whether it + * refers to a plain file or a socket. Let it through anyway. + */ + if (addr->transport =3D=3D MIGRATION_ADDRESS_TYPE_SOCKET) { + return addr->u.socket.type =3D=3D SOCKET_ADDRESS_TYPE_FD; + } + + return false; +} + static bool migration_channels_and_transport_compatible(MigrationAddress *addr, Error **errp) { + if (migration_needs_seekable_channel() && + !transport_supports_seeking(addr)) { + error_setg(errp, "Migration requires seekable transport (e.g. file= )"); + return false; + } + if (migration_needs_multiple_sockets() && !transport_supports_multi_channels(addr)) { error_setg(errp, "Migration requires multi-channel URIs (e.g. tcp)= "); --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515759; cv=none; d=zohomail.com; s=zohoarc; b=H/HNnY5JZrBQF5Mu+1IO4x6Eo65HBfkrRezmukxtTMDtOnU43fcaBZxCmFqgSFCUrjvF5K/Wrw8U5XYd4jXwBrdnuLAjhPlWPb/vAOEkbwMuw3tsdFrgroO4oEq1NunhnJbh6daPqhzXdRwiYJvTPmIfqOPkbwl4JiJ1B7bevro= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515759; 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=wOw9cV6G1FdBgmpEqntI7YB8cm83Rvin9BHTLXvzNUg=; b=iUaAMxZK/pylsrxwo6fLbVrsl3Ixz+1G/GDw+BREPmX8ci3ZLOjEfNTGS9LhmJPfWcHzc54pcTTqpRBgo6JnO36yj89+adwJJZhT6alz/XDnfhLKVkl76nzJnzuKmJbNu9xSZM8nLP4jjqPpdlcoe9WPKQXhbxocfXfSSUpkacI= 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 1709515759777437.78430667297096; Sun, 3 Mar 2024 17:29:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx7L-0001XQ-Pp; Sun, 03 Mar 2024 20:27:48 -0500 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 1rgx7J-0001Vu-Op for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx7D-0002Mw-F8 for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:45 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-490-k8h3Ra-WMguixpHVj4FoTA-1; Sun, 03 Mar 2024 20:27:35 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A9AF487A9EC; Mon, 4 Mar 2024 01:27:34 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 319A940C6EBA; Mon, 4 Mar 2024 01:27:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515658; h=from:from:reply-to:subject:subject: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=wOw9cV6G1FdBgmpEqntI7YB8cm83Rvin9BHTLXvzNUg=; b=JR2DxA8wSjPP2v5TDtBGnmSYWf77buhtC2BYYLAvFo3weRlHwi7SY2uYzhs96N6Kd31WLP uRNWAA2K0d4NR47CIJASwa9iPfY5TBYoTbEh2uAggtOIFj99iZCI2tsEbgQeh35ONyUMg4 /Ywn74p673c1sGAJ13myORiYNceDp58= X-MC-Unique: k8h3Ra-WMguixpHVj4FoTA-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas , Nikolay Borisov Subject: [PULL 12/27] migration/ram: Add outgoing 'mapped-ram' migration Date: Mon, 4 Mar 2024 09:26:19 +0800 Message-ID: <20240304012634.95520-13-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, 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: pass (identity @redhat.com) X-ZM-MESSAGEID: 1709515761213100001 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas Implement the outgoing migration side for the 'mapped-ram' capability. A bitmap is introduced to track which pages have been written in the migration file. Pages are written at a fixed location for every ramblock. Zero pages are ignored as they'd be zero in the destination migration as well. The migration stream is altered to put the dirty pages for a ramblock after its header instead of having a sequential stream of pages that follow the ramblock headers. Without mapped-ram (current): With mapped-ram (new): --------------------- -------------------------------- | ramblock 1 header | | ramblock 1 header | --------------------- -------------------------------- | ramblock 2 header | | ramblock 1 mapped-ram header | --------------------- -------------------------------- | ... | | padding to next 1MB boundary | --------------------- | ... | | ramblock n header | -------------------------------- --------------------- | ramblock 1 pages | | RAM_SAVE_FLAG_EOS | | ... | --------------------- -------------------------------- | stream of pages | | ramblock 2 header | | (iter 1) | -------------------------------- | ... | | ramblock 2 mapped-ram header | --------------------- -------------------------------- | RAM_SAVE_FLAG_EOS | | padding to next 1MB boundary | --------------------- | ... | | stream of pages | -------------------------------- | (iter 2) | | ramblock 2 pages | | ... | | ... | --------------------- -------------------------------- | ... | | ... | --------------------- -------------------------------- | RAM_SAVE_FLAG_EOS | -------------------------------- | ... | -------------------------------- where: - ramblock header: the generic information for a ramblock, such as idstr, used_len, etc. - ramblock mapped-ram header: the new information added by this feature: bitmap of pages written, bitmap size and offset of pages in the migration file. Signed-off-by: Nikolay Borisov Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240229153017.2221-10-farosas@suse.de Signed-off-by: Peter Xu --- include/exec/ramblock.h | 13 ++++ migration/ram.c | 131 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 135 insertions(+), 9 deletions(-) diff --git a/include/exec/ramblock.h b/include/exec/ramblock.h index 3eb79723c6..848915ea5b 100644 --- a/include/exec/ramblock.h +++ b/include/exec/ramblock.h @@ -44,6 +44,19 @@ struct RAMBlock { size_t page_size; /* dirty bitmap used during migration */ unsigned long *bmap; + + /* + * Below fields are only used by mapped-ram migration + */ + /* bitmap of pages present in the migration file */ + unsigned long *file_bmap; + /* + * offset in the file pages belonging to this ramblock are saved, + * used only during migration to a file. + */ + off_t bitmap_offset; + uint64_t pages_offset; + /* bitmap of already received pages in postcopy */ unsigned long *receivedmap; =20 diff --git a/migration/ram.c b/migration/ram.c index 45a00b45ed..f807824d49 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -94,6 +94,18 @@ #define RAM_SAVE_FLAG_MULTIFD_FLUSH 0x200 /* We can't use any flag that is bigger than 0x200 */ =20 +/* + * mapped-ram migration supports O_DIRECT, so we need to make sure the + * userspace buffer, the IO operation size and the file offset are + * aligned according to the underlying device's block size. The first + * two are already aligned to page size, but we need to add padding to + * the file to align the offset. We cannot read the block size + * dynamically because the migration file can be moved between + * different systems, so use 1M to cover most block sizes and to keep + * the file offset aligned at page size as well. + */ +#define MAPPED_RAM_FILE_OFFSET_ALIGNMENT 0x100000 + XBZRLECacheStats xbzrle_counters; =20 /* used by the search for pages to send */ @@ -1126,12 +1138,18 @@ static int save_zero_page(RAMState *rs, PageSearchS= tatus *pss, return 0; } =20 + stat64_add(&mig_stats.zero_pages, 1); + + if (migrate_mapped_ram()) { + /* zero pages are not transferred with mapped-ram */ + clear_bit(offset >> TARGET_PAGE_BITS, pss->block->file_bmap); + return 1; + } + len +=3D save_page_header(pss, file, pss->block, offset | RAM_SAVE_FLA= G_ZERO); qemu_put_byte(file, 0); len +=3D 1; ram_release_page(pss->block->idstr, offset); - - stat64_add(&mig_stats.zero_pages, 1); ram_transferred_add(len); =20 /* @@ -1189,14 +1207,20 @@ static int save_normal_page(PageSearchStatus *pss, = RAMBlock *block, { QEMUFile *file =3D pss->pss_channel; =20 - ram_transferred_add(save_page_header(pss, pss->pss_channel, block, - offset | RAM_SAVE_FLAG_PAGE)); - if (async) { - qemu_put_buffer_async(file, buf, TARGET_PAGE_SIZE, - migrate_release_ram() && - migration_in_postcopy()); + if (migrate_mapped_ram()) { + qemu_put_buffer_at(file, buf, TARGET_PAGE_SIZE, + block->pages_offset + offset); + set_bit(offset >> TARGET_PAGE_BITS, block->file_bmap); } else { - qemu_put_buffer(file, buf, TARGET_PAGE_SIZE); + ram_transferred_add(save_page_header(pss, pss->pss_channel, block, + offset | RAM_SAVE_FLAG_PAGE)); + if (async) { + qemu_put_buffer_async(file, buf, TARGET_PAGE_SIZE, + migrate_release_ram() && + migration_in_postcopy()); + } else { + qemu_put_buffer(file, buf, TARGET_PAGE_SIZE); + } } ram_transferred_add(TARGET_PAGE_SIZE); stat64_add(&mig_stats.normal_pages, 1); @@ -2411,6 +2435,8 @@ static void ram_save_cleanup(void *opaque) block->clear_bmap =3D NULL; g_free(block->bmap); block->bmap =3D NULL; + g_free(block->file_bmap); + block->file_bmap =3D NULL; } =20 xbzrle_cleanup(); @@ -2778,6 +2804,9 @@ static void ram_list_init_bitmaps(void) */ block->bmap =3D bitmap_new(pages); bitmap_set(block->bmap, 0, pages); + if (migrate_mapped_ram()) { + block->file_bmap =3D bitmap_new(pages); + } block->clear_bmap_shift =3D shift; block->clear_bmap =3D bitmap_new(clear_bmap_size(pages, shift)= ); } @@ -2915,6 +2944,60 @@ void qemu_guest_free_page_hint(void *addr, size_t le= n) } } =20 +#define MAPPED_RAM_HDR_VERSION 1 +struct MappedRamHeader { + uint32_t version; + /* + * The target's page size, so we know how many pages are in the + * bitmap. + */ + uint64_t page_size; + /* + * The offset in the migration file where the pages bitmap is + * stored. + */ + uint64_t bitmap_offset; + /* + * The offset in the migration file where the actual pages (data) + * are stored. + */ + uint64_t pages_offset; +} QEMU_PACKED; +typedef struct MappedRamHeader MappedRamHeader; + +static void mapped_ram_setup_ramblock(QEMUFile *file, RAMBlock *block) +{ + g_autofree MappedRamHeader *header =3D NULL; + size_t header_size, bitmap_size; + long num_pages; + + header =3D g_new0(MappedRamHeader, 1); + header_size =3D sizeof(MappedRamHeader); + + num_pages =3D block->used_length >> TARGET_PAGE_BITS; + bitmap_size =3D BITS_TO_LONGS(num_pages) * sizeof(unsigned long); + + /* + * Save the file offsets of where the bitmap and the pages should + * go as they are written at the end of migration and during the + * iterative phase, respectively. + */ + block->bitmap_offset =3D qemu_get_offset(file) + header_size; + block->pages_offset =3D ROUND_UP(block->bitmap_offset + + bitmap_size, + MAPPED_RAM_FILE_OFFSET_ALIGNMENT); + + header->version =3D cpu_to_be32(MAPPED_RAM_HDR_VERSION); + header->page_size =3D cpu_to_be64(TARGET_PAGE_SIZE); + header->bitmap_offset =3D cpu_to_be64(block->bitmap_offset); + header->pages_offset =3D cpu_to_be64(block->pages_offset); + + qemu_put_buffer(file, (uint8_t *) header, header_size); + + /* prepare offset for next ramblock */ + qemu_set_offset(file, block->pages_offset + block->used_length, SEEK_S= ET); +} + /* * Each of ram_save_setup, ram_save_iterate and ram_save_complete has * long-running RCU critical section. When rcu-reclaims in the code @@ -2964,6 +3047,10 @@ static int ram_save_setup(QEMUFile *f, void *opaque) if (migrate_ignore_shared()) { qemu_put_be64(f, block->mr->addr); } + + if (migrate_mapped_ram()) { + mapped_ram_setup_ramblock(f, block); + } } } =20 @@ -2997,6 +3084,20 @@ static int ram_save_setup(QEMUFile *f, void *opaque) return qemu_fflush(f); } =20 +static void ram_save_file_bmap(QEMUFile *f) +{ + RAMBlock *block; + + RAMBLOCK_FOREACH_MIGRATABLE(block) { + long num_pages =3D block->used_length >> TARGET_PAGE_BITS; + long bitmap_size =3D BITS_TO_LONGS(num_pages) * sizeof(unsigned lo= ng); + + qemu_put_buffer_at(f, (uint8_t *)block->file_bmap, bitmap_size, + block->bitmap_offset); + ram_transferred_add(bitmap_size); + } +} + /** * ram_save_iterate: iterative stage for migration * @@ -3186,6 +3287,18 @@ static int ram_save_complete(QEMUFile *f, void *opaq= ue) return ret; } =20 + if (migrate_mapped_ram()) { + ram_save_file_bmap(f); + + if (qemu_file_get_error(f)) { + Error *local_err =3D NULL; + int err =3D qemu_file_get_error_obj(f, &local_err); + + error_reportf_err(local_err, "Failed to write bitmap to file: = "); + return -err; + } + } + if (migrate_multifd() && !migrate_multifd_flush_after_each_section()) { qemu_put_be64(f, RAM_SAVE_FLAG_MULTIFD_FLUSH); } --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515882; cv=none; d=zohomail.com; s=zohoarc; b=RBp/5uZ+FcHc7IVMmDZQcNhbaW4kDYS2Op+FMPuh4sq/OTFgZwZzy5ziGRKL4Mra3OE1LRwXMU8CkNRxV6iXESVokdkg8iE9yPggkBK/c5gdOk0W5/ecLhWdMDAoE/b+cKdFELmCPVuAxD/2Pu1BXoa4Jf4kK2nIqVfVznoBflQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515882; 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=FRP4T2d9MQuOlNmDtUAae05kNAQSZL4VMQhQOX0mt1U=; b=T5YKdf9CxW8fcgdJMugRTdBivkcerb+jXxFPPT8rg6F4sUy6zYJdUWVytLaZ4qncJA9IJPPuj7XVBIij0e3+l1a0XYKLl9rD5IkIpX3l2e4lAzyU9qwllMdZgTevB5prFc2eGF3bbQo1AHA3A/fepGBOIHNLqwjKdVtVKygGgQU= 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 170951588265788.92037081330693; Sun, 3 Mar 2024 17:31:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx7O-0001aa-Rv; Sun, 03 Mar 2024 20:27:50 -0500 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 1rgx7N-0001YH-1h for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx7K-0002Nr-77 for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:47 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-537-AElsu5s9O1C9bMXNHEx87w-1; Sun, 03 Mar 2024 20:27:39 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 494A73814E90; Mon, 4 Mar 2024 01:27:39 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 78D3E40C6EBA; Mon, 4 Mar 2024 01:27:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515665; h=from:from:reply-to:subject:subject: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=FRP4T2d9MQuOlNmDtUAae05kNAQSZL4VMQhQOX0mt1U=; b=T5P6iQ1PVW7TnGfGXdtEMsZJ9pDqgxTnPxpT3uTBn/BsaWDV/jAtBKfcGMKmGsPeCY6Yno QeqfynxcijQx6nwgUUYfCF5YSvqhbzWtGCq3LjsR0QU3xZm7bNh6SUvI/OSDG6oFVNPizo xCijBQUuu8EkCUP7GvvYBwcwHariM5k= X-MC-Unique: AElsu5s9O1C9bMXNHEx87w-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas , Nikolay Borisov Subject: [PULL 13/27] migration/ram: Add incoming 'mapped-ram' migration Date: Mon, 4 Mar 2024 09:26:20 +0800 Message-ID: <20240304012634.95520-14-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1709515883766100001 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas Add the necessary code to parse the format changes for the 'mapped-ram' capability. One of the more notable changes in behavior is that in the 'mapped-ram' case ram pages are restored in one go rather than constantly looping through the migration stream. Signed-off-by: Nikolay Borisov Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240229153017.2221-11-farosas@suse.de Signed-off-by: Peter Xu --- migration/ram.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 141 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index f807824d49..18620784c6 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -106,6 +106,12 @@ */ #define MAPPED_RAM_FILE_OFFSET_ALIGNMENT 0x100000 =20 +/* + * When doing mapped-ram migration, this is the amount we read from + * the pages region in the migration file at a time. + */ +#define MAPPED_RAM_LOAD_BUF_SIZE 0x100000 + XBZRLECacheStats xbzrle_counters; =20 /* used by the search for pages to send */ @@ -2998,6 +3004,35 @@ static void mapped_ram_setup_ramblock(QEMUFile *file= , RAMBlock *block) qemu_set_offset(file, block->pages_offset + block->used_length, SEEK_S= ET); } =20 +static bool mapped_ram_read_header(QEMUFile *file, MappedRamHeader *header, + Error **errp) +{ + size_t ret, header_size =3D sizeof(MappedRamHeader); + + ret =3D qemu_get_buffer(file, (uint8_t *)header, header_size); + if (ret !=3D header_size) { + error_setg(errp, "Could not read whole mapped-ram migration header= " + "(expected %zd, got %zd bytes)", header_size, ret); + return false; + } + + /* migration stream is big-endian */ + header->version =3D be32_to_cpu(header->version); + + if (header->version > MAPPED_RAM_HDR_VERSION) { + error_setg(errp, "Migration mapped-ram capability version not " + "supported (expected <=3D %d, got %d)", MAPPED_RAM_HDR_= VERSION, + header->version); + return false; + } + + header->page_size =3D be64_to_cpu(header->page_size); + header->bitmap_offset =3D be64_to_cpu(header->bitmap_offset); + header->pages_offset =3D be64_to_cpu(header->pages_offset); + + return true; +} + /* * Each of ram_save_setup, ram_save_iterate and ram_save_complete has * long-running RCU critical section. When rcu-reclaims in the code @@ -3899,22 +3934,126 @@ void colo_flush_ram_cache(void) trace_colo_flush_ram_cache_end(); } =20 +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; + ram_addr_t offset; + void *host; + size_t read, unread, size; + + for (set_bit_idx =3D find_first_bit(bitmap, num_pages); + set_bit_idx < num_pages; + set_bit_idx =3D find_next_bit(bitmap, num_pages, clear_bit_idx + = 1)) { + + clear_bit_idx =3D find_next_zero_bit(bitmap, num_pages, set_bit_id= x + 1); + + unread =3D TARGET_PAGE_SIZE * (clear_bit_idx - set_bit_idx); + offset =3D set_bit_idx << TARGET_PAGE_BITS; + + while (unread > 0) { + host =3D host_from_ram_block_offset(block, offset); + if (!host) { + error_setg(errp, "page outside of ramblock %s range", + block->idstr); + return false; + } + + size =3D MIN(unread, MAPPED_RAM_LOAD_BUF_SIZE); + + read =3D qemu_get_buffer_at(f, host, size, + block->pages_offset + offset); + if (!read) { + goto err; + } + offset +=3D read; + unread -=3D read; + } + } + + return true; + +err: + qemu_file_get_error_obj(f, errp); + error_prepend(errp, "(%s) failed to read page " RAM_ADDR_FMT + "from file offset %" PRIx64 ": ", block->idstr, offset, + block->pages_offset + offset); + return false; +} + +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; + + if (!mapped_ram_read_header(f, &header, errp)) { + return; + } + + block->pages_offset =3D header.pages_offset; + + /* + * Check the alignment of the file region that contains pages. We + * don't enforce MAPPED_RAM_FILE_OFFSET_ALIGNMENT to allow that + * value to change in the future. Do only a sanity check with page + * size alignment. + */ + if (!QEMU_IS_ALIGNED(block->pages_offset, TARGET_PAGE_SIZE)) { + error_setg(errp, + "Error reading ramblock %s pages, region has bad alignm= ent", + block->idstr); + return; + } + + num_pages =3D length / header.page_size; + bitmap_size =3D BITS_TO_LONGS(num_pages) * sizeof(unsigned long); + + bitmap =3D g_malloc0(bitmap_size); + if (qemu_get_buffer_at(f, (uint8_t *)bitmap, bitmap_size, + header.bitmap_offset) !=3D bitmap_size) { + error_setg(errp, "Error reading dirty bitmap"); + return; + } + + if (!read_ramblock_mapped_ram(f, block, num_pages, bitmap, errp)) { + return; + } + + /* Skip pages array */ + qemu_set_offset(f, block->pages_offset + length, SEEK_SET); + + return; +} + 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(); + Error *local_err =3D NULL; =20 assert(block); =20 + if (migrate_mapped_ram()) { + parse_ramblock_mapped_ram(f, block, length, &local_err); + if (local_err) { + error_report_err(local_err); + return -EINVAL; + } + return 0; + } + if (!qemu_ram_is_migratable(block)) { error_report("block %s should not be migrated !", block->idstr); return -EINVAL; } =20 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); --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515741; cv=none; d=zohomail.com; s=zohoarc; b=SOwtGqxjql3CdhJuaLY/RpKfMQqZC+jnT2R1WNYYn6n+/RR4XB9YxtCmmH/pMeOqq2qgTmHZqWEofsyBElMRLA9xHEpbn6IRnx8kgQv81/hFMgFp4dNzxehFE+Edlw4rZO3wVbLhK8Z8EK/lo1DxzmwEE6nX4lcvFklhtgwcBpk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515741; 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=09jHiMlDnRGlcKTj1Grz9Nji1UTBiEsR3mjO5FW0cWs=; b=QRmTKt11YHtAiMilTbp7iYT4jY4V4eeIyMAib2dgO6iSupc7nf3WkPloDTQsQFBaVHAe4GNQQCvoBm19dAevUwOrtDHONeiNDXZ81cYn0bQmbrg0ZNJoIOpZynfj7FlMuYQYfkkWerrytKb257XdTgau34PTh3JHsSnmVTIb27I= 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 1709515741350130.57645213780484; Sun, 3 Mar 2024 17:29:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx7S-0001cH-6b; Sun, 03 Mar 2024 20:27:54 -0500 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 1rgx7P-0001bT-19 for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx7M-0002Nz-5C for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:49 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-689-JcRsUoalMuOU6iYpBojeQQ-1; Sun, 03 Mar 2024 20:27:43 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 79B791064DA9; Mon, 4 Mar 2024 01:27:43 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 193C340C6EBA; Mon, 4 Mar 2024 01:27:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515667; h=from:from:reply-to:subject:subject: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=09jHiMlDnRGlcKTj1Grz9Nji1UTBiEsR3mjO5FW0cWs=; b=W78TUpJZ1vOEiFqZMeQO9vk7JlwQ2mC0b8J7Fe8L6E/0WbUBn47jO4KFu+bRKXiogNnkzr eozUJMNNH5N4pyWEWIzjPORE+xPEQO1mRNErnp6yFeX6TqUx3zNJBdBfodxbB4LmTGp/FG qtx1BENPb/gDpkxSwfizgcooRYjjcl8= X-MC-Unique: JcRsUoalMuOU6iYpBojeQQ-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas Subject: [PULL 14/27] tests/qtest/migration: Add tests for mapped-ram file-based migration Date: Mon, 4 Mar 2024 09:26:21 +0800 Message-ID: <20240304012634.95520-15-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1709515743134100004 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240229153017.2221-12-farosas@suse.de Signed-off-by: Peter Xu --- tests/qtest/migration-test.c | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 8c35f3457b..4c5551f7d0 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -2200,6 +2200,14 @@ static void *test_mode_reboot_start(QTestState *from= , QTestState *to) return NULL; } =20 +static void *migrate_mapped_ram_start(QTestState *from, QTestState *to) +{ + migrate_set_capability(from, "mapped-ram", true); + migrate_set_capability(to, "mapped-ram", true); + + return NULL; +} + static void test_mode_reboot(void) { g_autofree char *uri =3D g_strdup_printf("file:%s/%s", tmpfs, @@ -2214,6 +2222,32 @@ static void test_mode_reboot(void) test_file_common(&args, true); } =20 +static void test_precopy_file_mapped_ram_live(void) +{ + g_autofree char *uri =3D g_strdup_printf("file:%s/%s", tmpfs, + FILE_TEST_FILENAME); + MigrateCommon args =3D { + .connect_uri =3D uri, + .listen_uri =3D "defer", + .start_hook =3D migrate_mapped_ram_start, + }; + + test_file_common(&args, false); +} + +static void test_precopy_file_mapped_ram(void) +{ + g_autofree char *uri =3D g_strdup_printf("file:%s/%s", tmpfs, + FILE_TEST_FILENAME); + MigrateCommon args =3D { + .connect_uri =3D uri, + .listen_uri =3D "defer", + .start_hook =3D migrate_mapped_ram_start, + }; + + test_file_common(&args, true); +} + static void test_precopy_tcp_plain(void) { MigrateCommon args =3D { @@ -2462,6 +2496,13 @@ static void *migrate_precopy_fd_file_start(QTestStat= e *from, QTestState *to) return NULL; } =20 +static void *migrate_fd_file_mapped_ram_start(QTestState *from, QTestState= *to) +{ + migrate_mapped_ram_start(from, to); + + return migrate_precopy_fd_file_start(from, to); +} + static void test_migrate_precopy_fd_file(void) { MigrateCommon args =3D { @@ -2472,6 +2513,17 @@ static void test_migrate_precopy_fd_file(void) }; test_file_common(&args, true); } + +static void test_migrate_precopy_fd_file_mapped_ram(void) +{ + MigrateCommon args =3D { + .listen_uri =3D "defer", + .connect_uri =3D "fd:fd-mig", + .start_hook =3D migrate_fd_file_mapped_ram_start, + .finish_hook =3D test_migrate_fd_finish_hook + }; + test_file_common(&args, true); +} #endif /* _WIN32 */ =20 static void do_test_validate_uuid(MigrateStart *args, bool should_fail) @@ -3519,6 +3571,11 @@ int main(int argc, char **argv) migration_test_add("/migration/mode/reboot", test_mode_reboot); } =20 + migration_test_add("/migration/precopy/file/mapped-ram", + test_precopy_file_mapped_ram); + migration_test_add("/migration/precopy/file/mapped-ram/live", + test_precopy_file_mapped_ram_live); + #ifdef CONFIG_GNUTLS migration_test_add("/migration/precopy/unix/tls/psk", test_precopy_unix_tls_psk); @@ -3580,6 +3637,8 @@ int main(int argc, char **argv) test_migrate_precopy_fd_socket); migration_test_add("/migration/precopy/fd/file", test_migrate_precopy_fd_file); + migration_test_add("/migration/precopy/fd/file/mapped-ram", + test_migrate_precopy_fd_file_mapped_ram); #endif migration_test_add("/migration/validate_uuid", test_validate_uuid); migration_test_add("/migration/validate_uuid_error", --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515714; cv=none; d=zohomail.com; s=zohoarc; b=YB6xgwyftH05HnW+WxcfFI+xQJHn3nugec4PG8tI9D2MWifx0X92E/Tqi10IgZExLDUoTYUL3wlP3oH2m8bqjfI3z8RbqiN1FgXfnlLiIK3bd05kwQaSAA1CRgNf5B5QdfkGqvjZVeuoCTWobueHlmd/5ipv/J5tHT4yFkcRX+c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515714; 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=S83wTD16OpizBGfq5LLkvGAx1j3LYbEznOklSWsN13U=; b=mHi3khkicI0dkS532TSF/vBRA6jsYs6oe2pmygXLET3bwgC6bY670cIhJ3Sv/4/Ph6lnaIBpGUJUXFX7dtAVsuCDKAgLrR4PPGMWI1qxZHWwxpgHkdbw4FpBeDFAFgC+FGfCWMzshPsIFkVjX0QTwEmAzhc3pzRfcfaqrgUiNaM= 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 1709515714845700.0892172234892; Sun, 3 Mar 2024 17:28:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx7x-0002Jd-CS; Sun, 03 Mar 2024 20:28:28 -0500 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 1rgx7U-0001om-Kw for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx7P-0002ON-QB for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:54 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-644-QEp2vR6ZOLWjeGebh-sF0w-1; Sun, 03 Mar 2024 20:27:48 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C2D2C1C05AB7; Mon, 4 Mar 2024 01:27:47 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 49C0840C6EBA; Mon, 4 Mar 2024 01:27:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515671; h=from:from:reply-to:subject:subject: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=S83wTD16OpizBGfq5LLkvGAx1j3LYbEznOklSWsN13U=; b=QysZPT5903Yst/CtrMYF2ZlOlQM4tBp6vG89+9gAG1NyCgFKWcDH4XgZtjmDrz2siy6zaN 0uxzXnfe8vnYth52eS5TOPa4wcA95Cz3Xx81lzCyst1R7qN+od0D+fC6V1A5xN4a1ixxur jHEfEh/iCKRZPOsJ3WzAps8kQbwoycM= X-MC-Unique: QEp2vR6ZOLWjeGebh-sF0w-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas Subject: [PULL 15/27] migration/multifd: Rename MultiFDSend|RecvParams::data to compress_data Date: Mon, 4 Mar 2024 09:26:22 +0800 Message-ID: <20240304012634.95520-16-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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 @redhat.com) X-ZM-MESSAGEID: 1709515715015100001 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas Use a more specific name for the compression data so we can use the generic for the multifd core code. Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240229153017.2221-13-farosas@suse.de Signed-off-by: Peter Xu --- migration/multifd.h | 4 ++-- migration/multifd-zlib.c | 20 ++++++++++---------- migration/multifd-zstd.c | 20 ++++++++++---------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index b3fe27ae93..adccd3532f 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -127,7 +127,7 @@ typedef struct { /* number of iovs used */ uint32_t iovs_num; /* used for compression methods */ - void *data; + void *compress_data; } MultiFDSendParams; =20 typedef struct { @@ -183,7 +183,7 @@ typedef struct { /* num of non zero pages */ uint32_t normal_num; /* used for de-compression methods */ - void *data; + void *compress_data; } MultiFDRecvParams; =20 typedef struct { diff --git a/migration/multifd-zlib.c b/migration/multifd-zlib.c index 012e3bdea1..2a8f5fc9a6 100644 --- a/migration/multifd-zlib.c +++ b/migration/multifd-zlib.c @@ -69,7 +69,7 @@ static int zlib_send_setup(MultiFDSendParams *p, Error **= errp) err_msg =3D "out of memory for buf"; goto err_free_zbuff; } - p->data =3D z; + p->compress_data =3D z; return 0; =20 err_free_zbuff: @@ -92,15 +92,15 @@ err_free_z: */ static void zlib_send_cleanup(MultiFDSendParams *p, Error **errp) { - struct zlib_data *z =3D p->data; + struct zlib_data *z =3D p->compress_data; =20 deflateEnd(&z->zs); g_free(z->zbuff); z->zbuff =3D NULL; g_free(z->buf); z->buf =3D NULL; - g_free(p->data); - p->data =3D NULL; + g_free(p->compress_data); + p->compress_data =3D NULL; } =20 /** @@ -117,7 +117,7 @@ static void zlib_send_cleanup(MultiFDSendParams *p, Err= or **errp) static int zlib_send_prepare(MultiFDSendParams *p, Error **errp) { MultiFDPages_t *pages =3D p->pages; - struct zlib_data *z =3D p->data; + struct zlib_data *z =3D p->compress_data; z_stream *zs =3D &z->zs; uint32_t out_size =3D 0; int ret; @@ -194,7 +194,7 @@ static int zlib_recv_setup(MultiFDRecvParams *p, Error = **errp) struct zlib_data *z =3D g_new0(struct zlib_data, 1); z_stream *zs =3D &z->zs; =20 - p->data =3D z; + p->compress_data =3D z; zs->zalloc =3D Z_NULL; zs->zfree =3D Z_NULL; zs->opaque =3D Z_NULL; @@ -224,13 +224,13 @@ static int zlib_recv_setup(MultiFDRecvParams *p, Erro= r **errp) */ static void zlib_recv_cleanup(MultiFDRecvParams *p) { - struct zlib_data *z =3D p->data; + struct zlib_data *z =3D p->compress_data; =20 inflateEnd(&z->zs); g_free(z->zbuff); z->zbuff =3D NULL; - g_free(p->data); - p->data =3D NULL; + g_free(p->compress_data); + p->compress_data =3D NULL; } =20 /** @@ -246,7 +246,7 @@ static void zlib_recv_cleanup(MultiFDRecvParams *p) */ static int zlib_recv_pages(MultiFDRecvParams *p, Error **errp) { - struct zlib_data *z =3D p->data; + struct zlib_data *z =3D p->compress_data; z_stream *zs =3D &z->zs; uint32_t in_size =3D p->next_packet_size; /* we measure the change of total_out */ diff --git a/migration/multifd-zstd.c b/migration/multifd-zstd.c index dc8fe43e94..593cf290ad 100644 --- a/migration/multifd-zstd.c +++ b/migration/multifd-zstd.c @@ -52,7 +52,7 @@ static int zstd_send_setup(MultiFDSendParams *p, Error **= errp) struct zstd_data *z =3D g_new0(struct zstd_data, 1); int res; =20 - p->data =3D z; + p->compress_data =3D z; z->zcs =3D ZSTD_createCStream(); if (!z->zcs) { g_free(z); @@ -90,14 +90,14 @@ static int zstd_send_setup(MultiFDSendParams *p, Error = **errp) */ static void zstd_send_cleanup(MultiFDSendParams *p, Error **errp) { - struct zstd_data *z =3D p->data; + struct zstd_data *z =3D p->compress_data; =20 ZSTD_freeCStream(z->zcs); z->zcs =3D NULL; g_free(z->zbuff); z->zbuff =3D NULL; - g_free(p->data); - p->data =3D NULL; + g_free(p->compress_data); + p->compress_data =3D NULL; } =20 /** @@ -114,7 +114,7 @@ static void zstd_send_cleanup(MultiFDSendParams *p, Err= or **errp) static int zstd_send_prepare(MultiFDSendParams *p, Error **errp) { MultiFDPages_t *pages =3D p->pages; - struct zstd_data *z =3D p->data; + struct zstd_data *z =3D p->compress_data; int ret; uint32_t i; =20 @@ -183,7 +183,7 @@ static int zstd_recv_setup(MultiFDRecvParams *p, Error = **errp) struct zstd_data *z =3D g_new0(struct zstd_data, 1); int ret; =20 - p->data =3D z; + p->compress_data =3D z; z->zds =3D ZSTD_createDStream(); if (!z->zds) { g_free(z); @@ -221,14 +221,14 @@ static int zstd_recv_setup(MultiFDRecvParams *p, Erro= r **errp) */ static void zstd_recv_cleanup(MultiFDRecvParams *p) { - struct zstd_data *z =3D p->data; + struct zstd_data *z =3D p->compress_data; =20 ZSTD_freeDStream(z->zds); z->zds =3D NULL; g_free(z->zbuff); z->zbuff =3D NULL; - g_free(p->data); - p->data =3D NULL; + g_free(p->compress_data); + p->compress_data =3D NULL; } =20 /** @@ -248,7 +248,7 @@ static int zstd_recv_pages(MultiFDRecvParams *p, Error = **errp) uint32_t out_size =3D 0; uint32_t expected_size =3D p->normal_num * p->page_size; uint32_t flags =3D p->flags & MULTIFD_FLAG_COMPRESSION_MASK; - struct zstd_data *z =3D p->data; + struct zstd_data *z =3D p->compress_data; int ret; int i; =20 --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515741; cv=none; d=zohomail.com; s=zohoarc; b=WXoQ8Z1qwjQ6ajZc7bOWdQbKHatLUssu/QDYGY3cnpuPx9UXNBOZlT7E50kp/gRfa5rvQljfyXPUQmxwQHTvUYMpiHewaZtaZi+SzrExkBIYrW8Z1BYlwmu+MZExd6k+YMFU0jD0Ocm7wnbm7TN4ZzYSXphT76tneX4/bbbhz/A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515741; 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=VK1uP/nEMdPC5iQ/u3BYD3q+AeCBZCrpjNKly+B83s8=; b=OC9mEJXSMc/wWomBTCK24yICZYfwWWmPyc7lVYldy7bhzd4g43fRXMMajfx3VwCVLlRiBUHoRe/G9sRQo2gBlIimk0H4q9lrO1K86YTdlAau/H+aA0ougzlWL3C5LlEuaLniBJjZSdecCuZIIYxTsIMVxgpMahLx57kc/WbqmDE= 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 1709515741218970.5852235132321; Sun, 3 Mar 2024 17:29:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx7t-0002IJ-L5; Sun, 03 Mar 2024 20:28:23 -0500 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 1rgx7X-0001sC-VN for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx7U-0002Ot-3v for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:27:58 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-561-YjG5-FCxOS6Zuw9_VzD8Mw-1; Sun, 03 Mar 2024 20:27:52 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AA69E8820C3; Mon, 4 Mar 2024 01:27:51 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 845FE40C6EBA; Mon, 4 Mar 2024 01:27:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515675; h=from:from:reply-to:subject:subject: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=VK1uP/nEMdPC5iQ/u3BYD3q+AeCBZCrpjNKly+B83s8=; b=eIWqhPj9mEurcAm7nKMQXJ4LsaTE55nkiSii4FXw7bmydbFnx1LYp0HxDsPuYpDW2J2O2E +YMLzgDxhfDPDmKmsYfqAClu+es7jJO06v+cpEQoIYdmHM9i4fzwagLHBepR77IuvnFAQM Zf3h/VrYSF+R0BdlbBbISWSLVkwAkI0= X-MC-Unique: YjG5-FCxOS6Zuw9_VzD8Mw-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas Subject: [PULL 16/27] migration/multifd: Decouple recv method from pages Date: Mon, 4 Mar 2024 09:26:23 +0800 Message-ID: <20240304012634.95520-17-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1709515743146100005 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas Next patches will abstract the type of data being received by the channels, so do some cleanup now to remove references to pages and dependency on 'normal_num'. Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240229153017.2221-14-farosas@suse.de Signed-off-by: Peter Xu --- migration/multifd.h | 4 ++-- migration/multifd-zlib.c | 6 +++--- migration/multifd-zstd.c | 6 +++--- migration/multifd.c | 13 ++++++++----- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index adccd3532f..6a54377cc1 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -197,8 +197,8 @@ typedef struct { int (*recv_setup)(MultiFDRecvParams *p, Error **errp); /* Cleanup for receiving side */ void (*recv_cleanup)(MultiFDRecvParams *p); - /* Read all pages */ - int (*recv_pages)(MultiFDRecvParams *p, Error **errp); + /* Read all data */ + int (*recv)(MultiFDRecvParams *p, Error **errp); } MultiFDMethods; =20 void multifd_register_ops(int method, MultiFDMethods *ops); diff --git a/migration/multifd-zlib.c b/migration/multifd-zlib.c index 2a8f5fc9a6..6120faad65 100644 --- a/migration/multifd-zlib.c +++ b/migration/multifd-zlib.c @@ -234,7 +234,7 @@ static void zlib_recv_cleanup(MultiFDRecvParams *p) } =20 /** - * zlib_recv_pages: read the data from the channel into actual pages + * zlib_recv: read the data from the channel into actual pages * * Read the compressed buffer, and uncompress it into the actual * pages. @@ -244,7 +244,7 @@ static void zlib_recv_cleanup(MultiFDRecvParams *p) * @p: Params for the channel that we are using * @errp: pointer to an error */ -static int zlib_recv_pages(MultiFDRecvParams *p, Error **errp) +static int zlib_recv(MultiFDRecvParams *p, Error **errp) { struct zlib_data *z =3D p->compress_data; z_stream *zs =3D &z->zs; @@ -319,7 +319,7 @@ static MultiFDMethods multifd_zlib_ops =3D { .send_prepare =3D zlib_send_prepare, .recv_setup =3D zlib_recv_setup, .recv_cleanup =3D zlib_recv_cleanup, - .recv_pages =3D zlib_recv_pages + .recv =3D zlib_recv }; =20 static void multifd_zlib_register(void) diff --git a/migration/multifd-zstd.c b/migration/multifd-zstd.c index 593cf290ad..cac236833d 100644 --- a/migration/multifd-zstd.c +++ b/migration/multifd-zstd.c @@ -232,7 +232,7 @@ static void zstd_recv_cleanup(MultiFDRecvParams *p) } =20 /** - * zstd_recv_pages: read the data from the channel into actual pages + * zstd_recv: read the data from the channel into actual pages * * Read the compressed buffer, and uncompress it into the actual * pages. @@ -242,7 +242,7 @@ static void zstd_recv_cleanup(MultiFDRecvParams *p) * @p: Params for the channel that we are using * @errp: pointer to an error */ -static int zstd_recv_pages(MultiFDRecvParams *p, Error **errp) +static int zstd_recv(MultiFDRecvParams *p, Error **errp) { uint32_t in_size =3D p->next_packet_size; uint32_t out_size =3D 0; @@ -310,7 +310,7 @@ static MultiFDMethods multifd_zstd_ops =3D { .send_prepare =3D zstd_send_prepare, .recv_setup =3D zstd_recv_setup, .recv_cleanup =3D zstd_recv_cleanup, - .recv_pages =3D zstd_recv_pages + .recv =3D zstd_recv }; =20 static void multifd_zstd_register(void) diff --git a/migration/multifd.c b/migration/multifd.c index c7389bf833..3a8520097b 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -197,7 +197,7 @@ static void nocomp_recv_cleanup(MultiFDRecvParams *p) } =20 /** - * nocomp_recv_pages: read the data from the channel into actual pages + * nocomp_recv: read the data from the channel * * For no compression we just need to read things into the correct place. * @@ -206,7 +206,7 @@ static void nocomp_recv_cleanup(MultiFDRecvParams *p) * @p: Params for the channel that we are using * @errp: pointer to an error */ -static int nocomp_recv_pages(MultiFDRecvParams *p, Error **errp) +static int nocomp_recv(MultiFDRecvParams *p, Error **errp) { uint32_t flags =3D p->flags & MULTIFD_FLAG_COMPRESSION_MASK; =20 @@ -228,7 +228,7 @@ static MultiFDMethods multifd_nocomp_ops =3D { .send_prepare =3D nocomp_send_prepare, .recv_setup =3D nocomp_recv_setup, .recv_cleanup =3D nocomp_recv_cleanup, - .recv_pages =3D nocomp_recv_pages + .recv =3D nocomp_recv }; =20 static MultiFDMethods *multifd_ops[MULTIFD_COMPRESSION__MAX] =3D { @@ -1227,6 +1227,8 @@ static void *multifd_recv_thread(void *opaque) =20 while (true) { uint32_t flags; + bool has_data =3D false; + p->normal_num =3D 0; =20 if (multifd_recv_should_exit()) { break; @@ -1248,10 +1250,11 @@ static void *multifd_recv_thread(void *opaque) flags =3D p->flags; /* recv methods don't know how to handle the SYNC flag */ p->flags &=3D ~MULTIFD_FLAG_SYNC; + has_data =3D !!p->normal_num; qemu_mutex_unlock(&p->mutex); =20 - if (p->normal_num) { - ret =3D multifd_recv_state->ops->recv_pages(p, &local_err); + if (has_data) { + ret =3D multifd_recv_state->ops->recv(p, &local_err); if (ret !=3D 0) { break; } --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515810; cv=none; d=zohomail.com; s=zohoarc; b=UFpms2hYicq7V+RB9o7n6ZSW5oKpbvwCtOm5c3JoMJ+jUZD2LrygmB0qQwwXquUxdljxvsUUdO7mAnolBsvSF9hZ/C6POBz3jz0AKq6fBs1LTDNXJc1hZhoib3PqjCmKrQVxjBKtK8Y9LNP6DZU3BO5+xuQFaJlrenzy/TMMMAc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515810; 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=ptd8Yo7Ufse7uyww/jr7ItOQkXfk12UqfbcC3vvU2yI=; b=g4ApYd/hMcet9FddaE9h600a7JlfcguIfbmUDiBJxgcW94I0/oOIC/j8BAm8BMKx8xrkPH/K12kL/KFhtvSMs81xttSnnXnTNOKo8OxOPDR1xhlH2ms3kRIAnIPUyEkA52sHT2/xkhv75+//J52v5zieQFFovF/3nn4p4r+DfWI= 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 1709515810213503.2480242544914; Sun, 3 Mar 2024 17:30:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx8R-0003L4-3K; Sun, 03 Mar 2024 20:28:55 -0500 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 1rgx7e-00027b-NN for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx7a-0002PF-7S for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:04 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-616-Jv2rxVyUMFyRcRWLBlvjXQ-1; Sun, 03 Mar 2024 20:27:56 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F2E0785A589; Mon, 4 Mar 2024 01:27:55 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 78A8F40C6EBA; Mon, 4 Mar 2024 01:27:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515681; h=from:from:reply-to:subject:subject: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=ptd8Yo7Ufse7uyww/jr7ItOQkXfk12UqfbcC3vvU2yI=; b=iiF4sDFfx7yvdPxYdUjU4kDeU7BfLfFnOriP+bdiiM4LiI4vZqxD4SnOfcNoIwGCeZT5Q2 leYCIWhzh35Kd9CvJrJAl/sDKQLYjFZ5IF8lGAmpxirnJhkUjI0g9orCXJH2D/20S5SRAP CisDpEX/es+PSpjmwIEVOYVB+Zx6+pw= X-MC-Unique: Jv2rxVyUMFyRcRWLBlvjXQ-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas Subject: [PULL 17/27] migration/multifd: Allow multifd without packets Date: Mon, 4 Mar 2024 09:26:24 +0800 Message-ID: <20240304012634.95520-18-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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 @redhat.com) X-ZM-MESSAGEID: 1709515811443100001 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas For the upcoming support to the new 'mapped-ram' migration stream format, we cannot use multifd packets because each write into the ramblock section in the migration file is expected to contain only the guest pages. They are written at their respective offsets relative to the ramblock section header. There is no space for the packet information and the expected gains from the new approach come partly from being able to write the pages sequentially without extraneous data in between. The new format also simply doesn't need the packets and all necessary information can be taken from the standard migration headers with some (future) changes to multifd code. Use the presence of the mapped-ram capability to decide whether to send packets. This only moves code under multifd_use_packets(), it has no effect for now as mapped-ram cannot yet be enabled with multifd. Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240229153017.2221-15-farosas@suse.de Signed-off-by: Peter Xu --- migration/multifd.c | 175 +++++++++++++++++++++++++++++--------------- 1 file changed, 114 insertions(+), 61 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 3a8520097b..8c43424c81 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -92,6 +92,11 @@ struct { MultiFDMethods *ops; } *multifd_recv_state; =20 +static bool multifd_use_packets(void) +{ + return !migrate_mapped_ram(); +} + /* Multifd without compression */ =20 /** @@ -122,6 +127,19 @@ static void nocomp_send_cleanup(MultiFDSendParams *p, = Error **errp) return; } =20 +static void multifd_send_prepare_iovs(MultiFDSendParams *p) +{ + MultiFDPages_t *pages =3D p->pages; + + for (int i =3D 0; i < pages->num; i++) { + p->iov[p->iovs_num].iov_base =3D pages->block->host + pages->offse= t[i]; + p->iov[p->iovs_num].iov_len =3D p->page_size; + p->iovs_num++; + } + + p->next_packet_size =3D pages->num * p->page_size; +} + /** * nocomp_send_prepare: prepare date to be able to send * @@ -136,9 +154,13 @@ static void nocomp_send_cleanup(MultiFDSendParams *p, = Error **errp) static int nocomp_send_prepare(MultiFDSendParams *p, Error **errp) { bool use_zero_copy_send =3D migrate_zero_copy_send(); - MultiFDPages_t *pages =3D p->pages; int ret; =20 + if (!multifd_use_packets()) { + multifd_send_prepare_iovs(p); + return 0; + } + if (!use_zero_copy_send) { /* * Only !zerocopy needs the header in IOV; zerocopy will @@ -147,13 +169,7 @@ static int nocomp_send_prepare(MultiFDSendParams *p, E= rror **errp) multifd_send_prepare_header(p); } =20 - for (int i =3D 0; i < pages->num; i++) { - p->iov[p->iovs_num].iov_base =3D pages->block->host + pages->offse= t[i]; - p->iov[p->iovs_num].iov_len =3D p->page_size; - p->iovs_num++; - } - - p->next_packet_size =3D pages->num * p->page_size; + multifd_send_prepare_iovs(p); p->flags |=3D MULTIFD_FLAG_NOCOMP; =20 multifd_send_fill_packet(p); @@ -208,7 +224,13 @@ static void nocomp_recv_cleanup(MultiFDRecvParams *p) */ static int nocomp_recv(MultiFDRecvParams *p, Error **errp) { - uint32_t flags =3D p->flags & MULTIFD_FLAG_COMPRESSION_MASK; + uint32_t flags; + + if (!multifd_use_packets()) { + return 0; + } + + flags =3D p->flags & MULTIFD_FLAG_COMPRESSION_MASK; =20 if (flags !=3D MULTIFD_FLAG_NOCOMP) { error_setg(errp, "multifd %u: flags received %x flags expected %x", @@ -795,15 +817,18 @@ static void *multifd_send_thread(void *opaque) MigrationThread *thread =3D NULL; Error *local_err =3D NULL; int ret =3D 0; + bool use_packets =3D multifd_use_packets(); =20 thread =3D migration_threads_add(p->name, qemu_get_thread_id()); =20 trace_multifd_send_thread_start(p->id); rcu_register_thread(); =20 - if (multifd_send_initial_packet(p, &local_err) < 0) { - ret =3D -1; - goto out; + if (use_packets) { + if (multifd_send_initial_packet(p, &local_err) < 0) { + ret =3D -1; + goto out; + } } =20 while (true) { @@ -854,16 +879,20 @@ static void *multifd_send_thread(void *opaque) * it doesn't require explicit memory barriers. */ assert(qatomic_read(&p->pending_sync)); - p->flags =3D MULTIFD_FLAG_SYNC; - multifd_send_fill_packet(p); - ret =3D qio_channel_write_all(p->c, (void *)p->packet, - p->packet_len, &local_err); - if (ret !=3D 0) { - break; + + if (use_packets) { + p->flags =3D MULTIFD_FLAG_SYNC; + multifd_send_fill_packet(p); + ret =3D qio_channel_write_all(p->c, (void *)p->packet, + p->packet_len, &local_err); + if (ret !=3D 0) { + break; + } + /* p->next_packet_size will always be zero for a SYNC pack= et */ + stat64_add(&mig_stats.multifd_bytes, p->packet_len); + p->flags =3D 0; } - /* p->next_packet_size will always be zero for a SYNC packet */ - stat64_add(&mig_stats.multifd_bytes, p->packet_len); - p->flags =3D 0; + qatomic_set(&p->pending_sync, false); qemu_sem_post(&p->sem_sync); } @@ -1018,6 +1047,7 @@ bool multifd_send_setup(void) Error *local_err =3D NULL; int thread_count, ret =3D 0; uint32_t page_count =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); + bool use_packets =3D multifd_use_packets(); uint8_t i; =20 if (!migrate_multifd()) { @@ -1040,14 +1070,20 @@ bool multifd_send_setup(void) qemu_sem_init(&p->sem_sync, 0); p->id =3D i; p->pages =3D multifd_pages_init(page_count); - p->packet_len =3D sizeof(MultiFDPacket_t) - + sizeof(uint64_t) * page_count; - p->packet =3D g_malloc0(p->packet_len); - p->packet->magic =3D cpu_to_be32(MULTIFD_MAGIC); - p->packet->version =3D cpu_to_be32(MULTIFD_VERSION); + + if (use_packets) { + p->packet_len =3D sizeof(MultiFDPacket_t) + + sizeof(uint64_t) * page_count; + p->packet =3D g_malloc0(p->packet_len); + p->packet->magic =3D cpu_to_be32(MULTIFD_MAGIC); + p->packet->version =3D cpu_to_be32(MULTIFD_VERSION); + + /* We need one extra place for the packet header */ + p->iov =3D g_new0(struct iovec, page_count + 1); + } else { + p->iov =3D g_new0(struct iovec, page_count); + } p->name =3D g_strdup_printf("multifdsend_%d", i); - /* We need one extra place for the packet header */ - p->iov =3D g_new0(struct iovec, page_count + 1); p->page_size =3D qemu_target_page_size(); p->page_count =3D page_count; p->write_flags =3D 0; @@ -1110,7 +1146,9 @@ static void multifd_recv_terminate_threads(Error *err) * multifd_recv_thread may hung at MULTIFD_FLAG_SYNC handle code, * however try to wakeup it without harm in cleanup phase. */ - qemu_sem_post(&p->sem_sync); + if (multifd_use_packets()) { + qemu_sem_post(&p->sem_sync); + } =20 /* * We could arrive here for two reasons: @@ -1185,7 +1223,7 @@ void multifd_recv_sync_main(void) int thread_count =3D migrate_multifd_channels(); int i; =20 - if (!migrate_multifd()) { + if (!migrate_multifd() || !multifd_use_packets()) { return; } =20 @@ -1220,13 +1258,14 @@ static void *multifd_recv_thread(void *opaque) { MultiFDRecvParams *p =3D opaque; Error *local_err =3D NULL; + bool use_packets =3D multifd_use_packets(); int ret; =20 trace_multifd_recv_thread_start(p->id); rcu_register_thread(); =20 while (true) { - uint32_t flags; + uint32_t flags =3D 0; bool has_data =3D false; p->normal_num =3D 0; =20 @@ -1234,25 +1273,27 @@ static void *multifd_recv_thread(void *opaque) break; } =20 - ret =3D qio_channel_read_all_eof(p->c, (void *)p->packet, - p->packet_len, &local_err); - if (ret =3D=3D 0 || ret =3D=3D -1) { /* 0: EOF -1: Error */ - break; - } + if (use_packets) { + ret =3D qio_channel_read_all_eof(p->c, (void *)p->packet, + p->packet_len, &local_err); + if (ret =3D=3D 0 || ret =3D=3D -1) { /* 0: EOF -1: Error */ + break; + } =20 - qemu_mutex_lock(&p->mutex); - ret =3D multifd_recv_unfill_packet(p, &local_err); - if (ret) { + qemu_mutex_lock(&p->mutex); + ret =3D multifd_recv_unfill_packet(p, &local_err); + if (ret) { + qemu_mutex_unlock(&p->mutex); + break; + } + + flags =3D p->flags; + /* recv methods don't know how to handle the SYNC flag */ + p->flags &=3D ~MULTIFD_FLAG_SYNC; + has_data =3D !!p->normal_num; qemu_mutex_unlock(&p->mutex); - break; } =20 - flags =3D p->flags; - /* recv methods don't know how to handle the SYNC flag */ - p->flags &=3D ~MULTIFD_FLAG_SYNC; - has_data =3D !!p->normal_num; - qemu_mutex_unlock(&p->mutex); - if (has_data) { ret =3D multifd_recv_state->ops->recv(p, &local_err); if (ret !=3D 0) { @@ -1260,9 +1301,11 @@ static void *multifd_recv_thread(void *opaque) } } =20 - if (flags & MULTIFD_FLAG_SYNC) { - qemu_sem_post(&multifd_recv_state->sem_sync); - qemu_sem_wait(&p->sem_sync); + if (use_packets) { + if (flags & MULTIFD_FLAG_SYNC) { + qemu_sem_post(&multifd_recv_state->sem_sync); + qemu_sem_wait(&p->sem_sync); + } } } =20 @@ -1281,6 +1324,7 @@ int multifd_recv_setup(Error **errp) { int thread_count; uint32_t page_count =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); + bool use_packets =3D multifd_use_packets(); uint8_t i; =20 /* @@ -1305,9 +1349,12 @@ int multifd_recv_setup(Error **errp) qemu_mutex_init(&p->mutex); qemu_sem_init(&p->sem_sync, 0); p->id =3D i; - p->packet_len =3D sizeof(MultiFDPacket_t) - + sizeof(uint64_t) * page_count; - p->packet =3D g_malloc0(p->packet_len); + + if (use_packets) { + p->packet_len =3D sizeof(MultiFDPacket_t) + + sizeof(uint64_t) * page_count; + p->packet =3D g_malloc0(p->packet_len); + } p->name =3D g_strdup_printf("multifdrecv_%d", i); p->iov =3D g_new0(struct iovec, page_count); p->normal =3D g_new0(ram_addr_t, page_count); @@ -1351,18 +1398,24 @@ void multifd_recv_new_channel(QIOChannel *ioc, Erro= r **errp) { MultiFDRecvParams *p; Error *local_err =3D NULL; + bool use_packets =3D multifd_use_packets(); int id; =20 - id =3D multifd_recv_initial_packet(ioc, &local_err); - if (id < 0) { - multifd_recv_terminate_threads(local_err); - error_propagate_prepend(errp, local_err, - "failed to receive packet" - " via multifd channel %d: ", - qatomic_read(&multifd_recv_state->count)); - return; + if (use_packets) { + id =3D multifd_recv_initial_packet(ioc, &local_err); + if (id < 0) { + multifd_recv_terminate_threads(local_err); + error_propagate_prepend(errp, local_err, + "failed to receive packet" + " via multifd channel %d: ", + qatomic_read(&multifd_recv_state->coun= t)); + return; + } + trace_multifd_recv_new_channel(id); + } else { + /* next patch gives this a meaningful value */ + id =3D 0; } - trace_multifd_recv_new_channel(id); =20 p =3D &multifd_recv_state->params[id]; if (p->c !=3D NULL) { --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515883; cv=none; d=zohomail.com; s=zohoarc; b=G6W+NgVBva7XCmL40QbV70hWEEsW71OAlsnhPGEyw4tMcaMqkh3Z7d81VLF2EFIwJO2Jy6NJiPQEESGoIMJ7CDXrxzbYyw3G/m4uQvPJl9aVvH8jlPEK1rqFx5mttrrFCMAIX+vLOK3dDYxzJ+vYtEXlAEfy1Glf5Q2EfqdNDnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515883; 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=2uzSIhngj0U0fXMJpOg/NU1hFvNfpZfLtLHmfXne1e4=; b=TzSYQE/pglMml0L+fYuUbc6SURZ4wxsFCvt8PFilrS/ejLpJre8jEmmt/4hdBDZimxc0XcNs6Y6KQbF+jB0xtp6zvxYtvwMOXOy2S2/I9Pmcb9+ISoP/VVyKSu05vY16xLBeFFn2c59HArHjQ0YmIrWwdSlvMmM4g3PQrutj5Gg= 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 1709515883387549.8596602640903; Sun, 3 Mar 2024 17:31:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx8I-0002qz-FX; Sun, 03 Mar 2024 20:28:48 -0500 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 1rgx7j-0002Hf-2E for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:12 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx7b-0002PL-3r for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:06 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-563--nbgPpXpPvKowm1IKyAQPQ-1; Sun, 03 Mar 2024 20:28:00 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2EB6D87A9F5; Mon, 4 Mar 2024 01:28:00 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id C261440C6EBA; Mon, 4 Mar 2024 01:27:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515682; h=from:from:reply-to:subject:subject: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=2uzSIhngj0U0fXMJpOg/NU1hFvNfpZfLtLHmfXne1e4=; b=ZscrWQ9E2de6a7qgvjk7P58fckaHaYfaP/yUg4cyLNqZmeZbcO4WzMbPKrI1i53+YLp86M nDuFQaIUplPKLAPNhT5kBoLlmz5RTIH8TyKGrHoPmOhRjjmQJEJ/EmyJfydO+hd6MeyIKr erOFKz8PX+n6dfqC8I9oI8uyttwlQcU= X-MC-Unique: -nbgPpXpPvKowm1IKyAQPQ-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas Subject: [PULL 18/27] migration/multifd: Allow receiving pages without packets Date: Mon, 4 Mar 2024 09:26:25 +0800 Message-ID: <20240304012634.95520-19-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1709515883770100002 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas Currently multifd does not need to have knowledge of pages on the receiving side because all the information needed is within the packets that come in the stream. We're about to add support to mapped-ram migration, which cannot use packets because it expects the ramblock section in the migration file to contain only the guest pages data. Add a data structure to transfer pages between the ram migration code and the multifd receiving threads. We don't want to reuse MultiFDPages_t for two reasons: a) multifd threads don't really need to know about the data they're receiving. b) the receiving side has to be stopped to load the pages, which means we can experiment with larger granularities than page size when transferring data. Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240229153017.2221-16-farosas@suse.de Signed-off-by: Peter Xu --- migration/multifd.h | 15 ++++++ migration/file.c | 1 + migration/multifd.c | 129 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 138 insertions(+), 7 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index 6a54377cc1..1be985978e 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -13,6 +13,8 @@ #ifndef QEMU_MIGRATION_MULTIFD_H #define QEMU_MIGRATION_MULTIFD_H =20 +typedef struct MultiFDRecvData MultiFDRecvData; + bool multifd_send_setup(void); void multifd_send_shutdown(void); int multifd_recv_setup(Error **errp); @@ -23,6 +25,8 @@ void multifd_recv_new_channel(QIOChannel *ioc, Error **er= rp); void multifd_recv_sync_main(void); int multifd_send_sync_main(void); bool multifd_queue_page(RAMBlock *block, ram_addr_t offset); +bool multifd_recv(void); +MultiFDRecvData *multifd_get_recv_data(void); =20 /* Multifd Compression flags */ #define MULTIFD_FLAG_SYNC (1 << 0) @@ -63,6 +67,13 @@ typedef struct { RAMBlock *block; } MultiFDPages_t; =20 +struct MultiFDRecvData { + void *opaque; + size_t size; + /* for preadv */ + off_t file_offset; +}; + typedef struct { /* Fields are only written at creating/deletion time */ /* No lock required for them, they are read only */ @@ -152,6 +163,8 @@ typedef struct { =20 /* syncs main thread and channels */ QemuSemaphore sem_sync; + /* sem where to wait for more work */ + QemuSemaphore sem; =20 /* this mutex protects the following parameters */ QemuMutex mutex; @@ -161,6 +174,8 @@ typedef struct { uint32_t flags; /* global number of generated multifd packets */ uint64_t packet_num; + int pending_job; + MultiFDRecvData *data; =20 /* thread local variables. No locking required */ =20 diff --git a/migration/file.c b/migration/file.c index 5d4975f43e..22d052a71f 100644 --- a/migration/file.c +++ b/migration/file.c @@ -6,6 +6,7 @@ */ =20 #include "qemu/osdep.h" +#include "exec/ramblock.h" #include "qemu/cutils.h" #include "qapi/error.h" #include "channel.h" diff --git a/migration/multifd.c b/migration/multifd.c index 8c43424c81..d470af73ba 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -81,9 +81,13 @@ struct { =20 struct { MultiFDRecvParams *params; + MultiFDRecvData *data; /* number of created threads */ int count; - /* syncs main thread and channels */ + /* + * This is always posted by the recv threads, the migration thread + * uses it to wait for recv threads to finish assigned tasks. + */ QemuSemaphore sem_sync; /* global number of generated multifd packets */ uint64_t packet_num; @@ -1119,6 +1123,57 @@ bool multifd_send_setup(void) return true; } =20 +bool multifd_recv(void) +{ + int i; + static int next_recv_channel; + MultiFDRecvParams *p =3D NULL; + MultiFDRecvData *data =3D multifd_recv_state->data; + + /* + * next_channel can remain from a previous migration that was + * using more channels, so ensure it doesn't overflow if the + * limit is lower now. + */ + next_recv_channel %=3D migrate_multifd_channels(); + for (i =3D next_recv_channel;; i =3D (i + 1) % migrate_multifd_channel= s()) { + if (multifd_recv_should_exit()) { + return false; + } + + p =3D &multifd_recv_state->params[i]; + + if (qatomic_read(&p->pending_job) =3D=3D false) { + next_recv_channel =3D (i + 1) % migrate_multifd_channels(); + break; + } + } + + /* + * Order pending_job read before manipulating p->data below. Pairs + * with qatomic_store_release() at multifd_recv_thread(). + */ + smp_mb_acquire(); + + assert(!p->data->size); + multifd_recv_state->data =3D p->data; + p->data =3D data; + + /* + * Order p->data update before setting pending_job. Pairs with + * qatomic_load_acquire() at multifd_recv_thread(). + */ + qatomic_store_release(&p->pending_job, true); + qemu_sem_post(&p->sem); + + return true; +} + +MultiFDRecvData *multifd_get_recv_data(void) +{ + return multifd_recv_state->data; +} + static void multifd_recv_terminate_threads(Error *err) { int i; @@ -1143,11 +1198,26 @@ static void multifd_recv_terminate_threads(Error *e= rr) MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; =20 /* - * multifd_recv_thread may hung at MULTIFD_FLAG_SYNC handle code, - * however try to wakeup it without harm in cleanup phase. + * The migration thread and channels interact differently + * depending on the presence of packets. */ if (multifd_use_packets()) { + /* + * The channel receives as long as there are packets. When + * packets end (i.e. MULTIFD_FLAG_SYNC is reached), the + * channel waits for the migration thread to sync. If the + * sync never happens, do it here. + */ qemu_sem_post(&p->sem_sync); + } else { + /* + * The channel waits for the migration thread to give it + * work. When the migration thread runs out of work, it + * releases the channel and waits for any pending work to + * finish. If we reach here (e.g. due to error) before the + * work runs out, release the channel. + */ + qemu_sem_post(&p->sem); } =20 /* @@ -1176,6 +1246,7 @@ static void multifd_recv_cleanup_channel(MultiFDRecvP= arams *p) p->c =3D NULL; qemu_mutex_destroy(&p->mutex); qemu_sem_destroy(&p->sem_sync); + qemu_sem_destroy(&p->sem); g_free(p->name); p->name =3D NULL; p->packet_len =3D 0; @@ -1193,6 +1264,8 @@ static void multifd_recv_cleanup_state(void) qemu_sem_destroy(&multifd_recv_state->sem_sync); g_free(multifd_recv_state->params); multifd_recv_state->params =3D NULL; + g_free(multifd_recv_state->data); + multifd_recv_state->data =3D NULL; g_free(multifd_recv_state); multifd_recv_state =3D NULL; } @@ -1269,11 +1342,11 @@ static void *multifd_recv_thread(void *opaque) bool has_data =3D false; p->normal_num =3D 0; =20 - if (multifd_recv_should_exit()) { - break; - } - if (use_packets) { + if (multifd_recv_should_exit()) { + break; + } + ret =3D qio_channel_read_all_eof(p->c, (void *)p->packet, p->packet_len, &local_err); if (ret =3D=3D 0 || ret =3D=3D -1) { /* 0: EOF -1: Error */ @@ -1292,6 +1365,30 @@ static void *multifd_recv_thread(void *opaque) p->flags &=3D ~MULTIFD_FLAG_SYNC; has_data =3D !!p->normal_num; qemu_mutex_unlock(&p->mutex); + } else { + /* + * No packets, so we need to wait for the vmstate code to + * give us work. + */ + qemu_sem_wait(&p->sem); + + if (multifd_recv_should_exit()) { + break; + } + + /* pairs with qatomic_store_release() at multifd_recv() */ + if (!qatomic_load_acquire(&p->pending_job)) { + /* + * Migration thread did not send work, this is + * equivalent to pending_sync on the sending + * side. Post sem_sync to notify we reached this + * point. + */ + qemu_sem_post(&multifd_recv_state->sem_sync); + continue; + } + + has_data =3D !!p->data->size; } =20 if (has_data) { @@ -1306,6 +1403,15 @@ static void *multifd_recv_thread(void *opaque) qemu_sem_post(&multifd_recv_state->sem_sync); qemu_sem_wait(&p->sem_sync); } + } else { + p->total_normal_pages +=3D p->data->size / qemu_target_page_si= ze(); + p->data->size =3D 0; + /* + * Order data->size update before clearing + * pending_job. Pairs with smp_mb_acquire() at + * multifd_recv(). + */ + qatomic_store_release(&p->pending_job, false); } } =20 @@ -1338,6 +1444,10 @@ int multifd_recv_setup(Error **errp) thread_count =3D migrate_multifd_channels(); multifd_recv_state =3D g_malloc0(sizeof(*multifd_recv_state)); multifd_recv_state->params =3D g_new0(MultiFDRecvParams, thread_count); + + multifd_recv_state->data =3D g_new0(MultiFDRecvData, 1); + multifd_recv_state->data->size =3D 0; + qatomic_set(&multifd_recv_state->count, 0); qatomic_set(&multifd_recv_state->exiting, 0); qemu_sem_init(&multifd_recv_state->sem_sync, 0); @@ -1348,8 +1458,13 @@ int multifd_recv_setup(Error **errp) =20 qemu_mutex_init(&p->mutex); qemu_sem_init(&p->sem_sync, 0); + qemu_sem_init(&p->sem, 0); + p->pending_job =3D false; p->id =3D i; =20 + p->data =3D g_new0(MultiFDRecvData, 1); + p->data->size =3D 0; + if (use_packets) { p->packet_len =3D sizeof(MultiFDPacket_t) + sizeof(uint64_t) * page_count; --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515753; cv=none; d=zohomail.com; s=zohoarc; b=O0v8sgtfy4CIZ4U7hnWPPjJk/xzEFghXcrHYXiXCHCgS9dkORwqSxY2Oo70He6eBic2/Gr0nzVA0Bsmf55kxv9MxdiRSODxjJwMiDD3+EqjCsA66YBAsrJqY4yxuzbUSk16zGH5kN/Gzt5vrU8v5J+opO3oI9HQkdufYltHMy7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515753; 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=BOEXJHhRYNP/4RHTVDV6YHp0PaX9wEiaCsnJ5jySJbs=; b=fDl3tMt5Qd9ntTKrxoAAMAxAvW4JhAEzivuZyD6l4fVAMGWZp45y39TH/OBj/CDPk3llG6BvUZ+jkLbMUPBlOwPkiod5tI7iIH1SxRO1XMMuQme3r8efi0s3HUavo3rH9R6ob19Cm8tFW6BaRkULd+W5nzNXmrnw5d1Hz+Ky0R0= 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 1709515753221827.6493595688642; Sun, 3 Mar 2024 17:29:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx8S-0003bN-6k; Sun, 03 Mar 2024 20:28:56 -0500 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 1rgx7n-0002IX-3l for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx7h-0002Pv-12 for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:12 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-299-x8jkTkD6M8OXliMpgjiAnQ-1; Sun, 03 Mar 2024 20:28:04 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5F98B3C0DD02; Mon, 4 Mar 2024 01:28:04 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id F275540C6EBA; Mon, 4 Mar 2024 01:28:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515688; h=from:from:reply-to:subject:subject: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=BOEXJHhRYNP/4RHTVDV6YHp0PaX9wEiaCsnJ5jySJbs=; b=ITKabAVlLuoCqbhl9LVC8HSKEbddfl9lc8TA51hgEFuP8cQ4y36DHOEwP89VVez2QqGKzC 4QfjJ6V2O+ibnOdEav4dlNtaFDXEtpMr9YIqSMmYZS4ZLL96Jivhkl6nqgAvUqApXQbEu7 0twvi85OuhT8oz2i5TKCGl/z3kPYPMg= X-MC-Unique: x8jkTkD6M8OXliMpgjiAnQ-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas Subject: [PULL 19/27] migration/multifd: Add a wrapper for channels_created Date: Mon, 4 Mar 2024 09:26:26 +0800 Message-ID: <20240304012634.95520-20-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1709515755154100003 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas We'll need to access multifd_send_state->channels_created from outside multifd.c, so introduce a helper for that. Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240229153017.2221-17-farosas@suse.de Signed-off-by: Peter Xu --- migration/multifd.h | 1 + migration/multifd.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/migration/multifd.h b/migration/multifd.h index 1be985978e..1d8bbaf96b 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -17,6 +17,7 @@ typedef struct MultiFDRecvData MultiFDRecvData; =20 bool multifd_send_setup(void); void multifd_send_shutdown(void); +void multifd_send_channel_created(void); int multifd_recv_setup(Error **errp); void multifd_recv_cleanup(void); void multifd_recv_shutdown(void); diff --git a/migration/multifd.c b/migration/multifd.c index d470af73ba..3574fd3953 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -101,6 +101,11 @@ static bool multifd_use_packets(void) return !migrate_mapped_ram(); } =20 +void multifd_send_channel_created(void) +{ + qemu_sem_post(&multifd_send_state->channels_created); +} + /* Multifd without compression */ =20 /** @@ -1023,7 +1028,7 @@ out: * Here we're not interested whether creation succeeded, only that * it happened at all. */ - qemu_sem_post(&multifd_send_state->channels_created); + multifd_send_channel_created(); =20 if (ret) { return; --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515907; cv=none; d=zohomail.com; s=zohoarc; b=BOZORSJTNVbvAoBkoWweWmLABN9WDuwbPJFRqrf8MHjy2EZhtkrBA2S727PAZ+bfvjSMRTctCEr36wpH4GSfcWMLR2+ej+NKe8+ZV/gBE9jegpmgs+9rcM3FHdWwkXuQozkvsATlQvbkYMkUaapPwxYBdTVVMikhvJfgHHdU7cQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515907; 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=m+igvX/FEW4XM2C5h7L1n5XNwdEdJ5+LsMvBKmyx/Jk=; b=VwFwz1CUPcaQVt+7hHcy7rrZr2WxgoBjJqKE9TskuQaYQ7gDemIUjzkua+A/GV/q+tcKRHkHj4QL7IzqA3wih5HmY/pkFdgdmWOvplqJvVytTrjHRuV+3y9v4qyOzm1ONSQAv5hGi6FVKSbqGLtLi0a8mribrWrqtu4u4MdQeM0= 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 1709515907121186.86754722846013; Sun, 3 Mar 2024 17:31:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx8X-0004Z6-O7; Sun, 03 Mar 2024 20:29:01 -0500 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 1rgx7q-0002Jf-M6 for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx7l-0002QI-SU for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:16 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-318-aHqFX1WeNiG1A71714MvQQ-1; Sun, 03 Mar 2024 20:28:09 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A97A11064DA3; Mon, 4 Mar 2024 01:28:08 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EBDF40C6EBA; Mon, 4 Mar 2024 01:28:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515692; h=from:from:reply-to:subject:subject: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=m+igvX/FEW4XM2C5h7L1n5XNwdEdJ5+LsMvBKmyx/Jk=; b=VkJaMhy4PxR/c4jHG2fj4KUATSkU7tuyVVL4eUTwqLQS7T6WnnDTynh7QWauSnTUSY9w9s D04YcgmC6qjp0ce8c7Z7pUYhw66NTBy9fVrmYsgGhLgBgRhNNAg6Vy+D8ZQ1Iya1tZ5ka9 ANL1rJ3r2c4Cjh/fBiWAZHIE8/iE0Zk= X-MC-Unique: aHqFX1WeNiG1A71714MvQQ-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas Subject: [PULL 20/27] migration/multifd: Add outgoing QIOChannelFile support Date: Mon, 4 Mar 2024 09:26:27 +0800 Message-ID: <20240304012634.95520-21-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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 @redhat.com) X-ZM-MESSAGEID: 1709515907949100001 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas Allow multifd to open file-backed channels. This will be used when enabling the mapped-ram migration stream format which expects a seekable transport. The QIOChannel read and write methods will use the preadv/pwritev versions which don't update the file offset at each call so we can reuse the fd without re-opening for every channel. Contrary to the socket migration, the file migration doesn't need an asynchronous channel creation process, so expose multifd_channel_connect() and call it directly. Note that this is just setup code and multifd cannot yet make use of the file channels. Signed-off-by: Fabiano Rosas Reviewed-by: Peter Xu Link: https://lore.kernel.org/r/20240229153017.2221-18-farosas@suse.de Signed-off-by: Peter Xu --- migration/file.h | 4 ++++ migration/multifd.h | 1 + migration/file.c | 37 +++++++++++++++++++++++++++++++++++++ migration/multifd.c | 18 +++++++++++++++--- 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/migration/file.h b/migration/file.h index 37d6a08bfc..4577f9efdd 100644 --- a/migration/file.h +++ b/migration/file.h @@ -9,10 +9,14 @@ #define QEMU_MIGRATION_FILE_H =20 #include "qapi/qapi-types-migration.h" +#include "io/task.h" +#include "channel.h" =20 void file_start_incoming_migration(FileMigrationArgs *file_args, Error **e= rrp); =20 void file_start_outgoing_migration(MigrationState *s, FileMigrationArgs *file_args, Error **e= rrp); int file_parse_offset(char *filespec, uint64_t *offsetp, Error **errp); +void file_cleanup_outgoing_migration(void); +bool file_send_channel_create(gpointer opaque, Error **errp); #endif diff --git a/migration/multifd.h b/migration/multifd.h index 1d8bbaf96b..db8887f088 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -227,5 +227,6 @@ static inline void multifd_send_prepare_header(MultiFDS= endParams *p) p->iovs_num++; } =20 +void multifd_channel_connect(MultiFDSendParams *p, QIOChannel *ioc); =20 #endif diff --git a/migration/file.c b/migration/file.c index 22d052a71f..a350dd61f0 100644 --- a/migration/file.c +++ b/migration/file.c @@ -12,12 +12,17 @@ #include "channel.h" #include "file.h" #include "migration.h" +#include "multifd.h" #include "io/channel-file.h" #include "io/channel-util.h" #include "trace.h" =20 #define OFFSET_OPTION ",offset=3D" =20 +static struct FileOutgoingArgs { + char *fname; +} outgoing_args; + /* Remove the offset option from @filespec and return it in @offsetp. */ =20 int file_parse_offset(char *filespec, uint64_t *offsetp, Error **errp) @@ -37,6 +42,36 @@ int file_parse_offset(char *filespec, uint64_t *offsetp,= Error **errp) return 0; } =20 +void file_cleanup_outgoing_migration(void) +{ + g_free(outgoing_args.fname); + outgoing_args.fname =3D NULL; +} + +bool file_send_channel_create(gpointer opaque, Error **errp) +{ + QIOChannelFile *ioc; + int flags =3D O_WRONLY; + bool ret =3D true; + + ioc =3D qio_channel_file_new_path(outgoing_args.fname, flags, 0, errp); + if (!ioc) { + ret =3D false; + goto out; + } + + multifd_channel_connect(opaque, QIO_CHANNEL(ioc)); + +out: + /* + * File channel creation is synchronous. However posting this + * semaphore here is simpler than adding a special case. + */ + multifd_send_channel_created(); + + return ret; +} + void file_start_outgoing_migration(MigrationState *s, FileMigrationArgs *file_args, Error **e= rrp) { @@ -53,6 +88,8 @@ void file_start_outgoing_migration(MigrationState *s, return; } =20 + outgoing_args.fname =3D g_strdup(filename); + ioc =3D QIO_CHANNEL(fioc); if (offset && qio_channel_io_seek(ioc, offset, SEEK_SET, errp) < 0) { return; diff --git a/migration/multifd.c b/migration/multifd.c index 3574fd3953..caef1076ca 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -17,6 +17,7 @@ #include "exec/ramblock.h" #include "qemu/error-report.h" #include "qapi/error.h" +#include "file.h" #include "ram.h" #include "migration.h" #include "migration-stats.h" @@ -28,6 +29,7 @@ #include "threadinfo.h" #include "options.h" #include "qemu/yank.h" +#include "io/channel-file.h" #include "io/channel-socket.h" #include "yank_functions.h" =20 @@ -694,6 +696,7 @@ static bool multifd_send_cleanup_channel(MultiFDSendPar= ams *p, Error **errp) { if (p->c) { migration_ioc_unregister_yank(p->c); + qio_channel_close(p->c, &error_abort); object_unref(OBJECT(p->c)); p->c =3D NULL; } @@ -715,6 +718,7 @@ static bool multifd_send_cleanup_channel(MultiFDSendPar= ams *p, Error **errp) =20 static void multifd_send_cleanup_state(void) { + file_cleanup_outgoing_migration(); socket_cleanup_outgoing_migration(); qemu_sem_destroy(&multifd_send_state->channels_created); qemu_sem_destroy(&multifd_send_state->channels_ready); @@ -977,7 +981,7 @@ static bool multifd_tls_channel_connect(MultiFDSendPara= ms *p, return true; } =20 -static void multifd_channel_connect(MultiFDSendParams *p, QIOChannel *ioc) +void multifd_channel_connect(MultiFDSendParams *p, QIOChannel *ioc) { qio_channel_set_delay(ioc, false); =20 @@ -1045,9 +1049,14 @@ out: error_free(local_err); } =20 -static void multifd_new_send_channel_create(gpointer opaque) +static bool multifd_new_send_channel_create(gpointer opaque, Error **errp) { + if (!multifd_use_packets()) { + return file_send_channel_create(opaque, errp); + } + socket_send_channel_create(multifd_new_send_channel_async, opaque); + return true; } =20 bool multifd_send_setup(void) @@ -1096,7 +1105,10 @@ bool multifd_send_setup(void) p->page_size =3D qemu_target_page_size(); p->page_count =3D page_count; p->write_flags =3D 0; - multifd_new_send_channel_create(p); + + if (!multifd_new_send_channel_create(p, &local_err)) { + return false; + } } =20 /* --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515765; cv=none; d=zohomail.com; s=zohoarc; b=XIPiIn+SRyiOGzVNCCHYW2wfhxVqJFFOc9ENBm+qbfhubgApu0PamSOhE/RTXtIKP5SaMGqw2XwpSt0JC+GhT41m453bI2fVGtOlDkcErseyBwmcYiFjm0hdYC693xmE2AdWsQyTqUNNkM09pEpNp5WtklS/SqxMdtxgfOIYbZM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515765; 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=0ar+ofp36XyBqOk9XaHO6Ma1s1jc9ExRp4Vy0jSeUQA=; b=f7jVUmGI3hPVaHSoO8Z9MKLC40WW/v0+TsQu8ZnKyLhEkc9akoa9ptT5xClsKyyIktsjScFwdEDEL/tDbftlW40ce8S413BFtXE+AGpzfV5Jp2ELikZXsyhWXUiAhmGyVZ+n5luRNamUYCfuDR3oLE+flfaaP1hubcRBaWkvXUs= 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 1709515765840324.661122815676; Sun, 3 Mar 2024 17:29:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx8N-0002wK-Lx; Sun, 03 Mar 2024 20:28:52 -0500 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 1rgx7t-0002Mv-Tf for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx7n-0002QS-Ur for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:18 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-104-pcD6Vw-hMTCCyyHau2mTog-1; Sun, 03 Mar 2024 20:28:13 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F1246185A785; Mon, 4 Mar 2024 01:28:12 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 780E440C6EBA; Mon, 4 Mar 2024 01:28:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515695; h=from:from:reply-to:subject:subject: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=0ar+ofp36XyBqOk9XaHO6Ma1s1jc9ExRp4Vy0jSeUQA=; b=Ss5Se2gmzxUhA811zC9aFVX9vY/OS4+ZxmCrqCzZpFqz2fmRdoA2nSaeYWexVvamBjZQSt S4sokvh6p1Q4tfNOx+yMaC4qEcoJv8SBJky6dtnjNxqYLGastMD2NLlD79Xjp5LRxV36ir 7AUSkRVw98GH3X1ZbLAHZ4cuqVe6UNw= X-MC-Unique: pcD6Vw-hMTCCyyHau2mTog-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas Subject: [PULL 21/27] migration/multifd: Add incoming QIOChannelFile support Date: Mon, 4 Mar 2024 09:26:28 +0800 Message-ID: <20240304012634.95520-22-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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 @redhat.com) X-ZM-MESSAGEID: 1709515767207100001 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas On the receiving side we don't need to differentiate between main channel and threads, so whichever channel is defined first gets to be the main one. And since there are no packets, use the atomic channel count to index into the params array. Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240229153017.2221-19-farosas@suse.de Signed-off-by: Peter Xu --- migration/file.c | 35 +++++++++++++++++++++++++++-------- migration/migration.c | 3 ++- migration/multifd.c | 3 +-- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/migration/file.c b/migration/file.c index a350dd61f0..2f8b626b27 100644 --- a/migration/file.c +++ b/migration/file.c @@ -8,6 +8,7 @@ #include "qemu/osdep.h" #include "exec/ramblock.h" #include "qemu/cutils.h" +#include "qemu/error-report.h" #include "qapi/error.h" #include "channel.h" #include "file.h" @@ -15,6 +16,7 @@ #include "multifd.h" #include "io/channel-file.h" #include "io/channel-util.h" +#include "options.h" #include "trace.h" =20 #define OFFSET_OPTION ",offset=3D" @@ -112,7 +114,8 @@ void file_start_incoming_migration(FileMigrationArgs *f= ile_args, Error **errp) g_autofree char *filename =3D g_strdup(file_args->filename); QIOChannelFile *fioc =3D NULL; uint64_t offset =3D file_args->offset; - QIOChannel *ioc; + int channels =3D 1; + int i =3D 0; =20 trace_migration_file_incoming(filename); =20 @@ -121,13 +124,29 @@ void file_start_incoming_migration(FileMigrationArgs = *file_args, Error **errp) return; } =20 - ioc =3D QIO_CHANNEL(fioc); - if (offset && qio_channel_io_seek(ioc, offset, SEEK_SET, errp) < 0) { + if (offset && + qio_channel_io_seek(QIO_CHANNEL(fioc), offset, SEEK_SET, errp) < 0= ) { return; } - qio_channel_set_name(QIO_CHANNEL(ioc), "migration-file-incoming"); - qio_channel_add_watch_full(ioc, G_IO_IN, - file_accept_incoming_migration, - NULL, NULL, - g_main_context_get_thread_default()); + + if (migrate_multifd()) { + channels +=3D migrate_multifd_channels(); + } + + do { + QIOChannel *ioc =3D QIO_CHANNEL(fioc); + + qio_channel_set_name(ioc, "migration-file-incoming"); + qio_channel_add_watch_full(ioc, G_IO_IN, + file_accept_incoming_migration, + NULL, NULL, + g_main_context_get_thread_default()); + + fioc =3D qio_channel_file_new_fd(dup(fioc->fd)); + + if (!fioc || fioc->fd =3D=3D -1) { + error_setg(errp, "Error creating migration incoming channel"); + break; + } + } while (++i < channels); } diff --git a/migration/migration.c b/migration/migration.c index 2669600d25..faeb75a59b 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -910,7 +910,8 @@ void migration_ioc_process_incoming(QIOChannel *ioc, Er= ror **errp) uint32_t channel_magic =3D 0; int ret =3D 0; =20 - if (migrate_multifd() && !migrate_postcopy_ram() && + if (migrate_multifd() && !migrate_mapped_ram() && + !migrate_postcopy_ram() && qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_READ_MSG_PEEK)) { /* * With multiple channels, it is possible that we receive channels diff --git a/migration/multifd.c b/migration/multifd.c index caef1076ca..ea08f1aa9e 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -1545,8 +1545,7 @@ void multifd_recv_new_channel(QIOChannel *ioc, Error = **errp) } trace_multifd_recv_new_channel(id); } else { - /* next patch gives this a meaningful value */ - id =3D 0; + id =3D qatomic_read(&multifd_recv_state->count); } =20 p =3D &multifd_recv_state->params[id]; --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515907; cv=none; d=zohomail.com; s=zohoarc; b=fKfJQ/3ZxFxPtCEpe/i5+debVBB93IrSTZoL/ZPwrZwu59JQrAybB3Bkf2CeA9+zhZA47hSCp9fMAtr20KJ+ACmsdX0VnAswYNrZsnaFolvEaqrPBqalD1Z/DqLrrml1UZ+7aNE06aR9iFPvTJcmT75EIly4XxpQUfxal3CJU0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515907; 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=DL5BNu1/lR7kXIS2bjgMtJyUQxodIRBqqeTZL0wzwjI=; b=LcmfuPf9blQaDys2x82vK8jolQUd4K7fH0ux9pmYPFu+uBk1dtdqbX1U1aq9ZBRdkl+CgL+9AChu9TMvbPe00uX6Thm8gq95WMEWynuBWK4m+l5NZDCBKozjHlxFtyPHMRXzNOqvjEe+/o5wuZo1Ig96XSnccFpiKFF93CxD1v8= 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 17095159076331.2872944608737953; Sun, 3 Mar 2024 17:31:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx8X-0004VJ-CD; Sun, 03 Mar 2024 20:29:01 -0500 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 1rgx7y-0002Qb-1Y for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx7t-0002Qw-Lb for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:25 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-154-zQkPDTbnNgGQJqpO3k9LVQ-1; Sun, 03 Mar 2024 20:28:17 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1478388D129; Mon, 4 Mar 2024 01:28:17 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id C1D2340C6EBA; Mon, 4 Mar 2024 01:28:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515700; h=from:from:reply-to:subject:subject: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=DL5BNu1/lR7kXIS2bjgMtJyUQxodIRBqqeTZL0wzwjI=; b=c8QHFRnvTqg38GwJz2asPXen7Wk74ypT7we/LkTb7yrSdNSWXEZaKmjgX5jLrvnT17wBRh mZMbr7iXUzUNS+H25TAwsIOO6e/xUgY88/X4mr5kbWNDZHbBOJEf5Jb8xdXcDDNvIOJ+MM G+XQIA5j62s7LxoiWT6oqtqGVPEJE1A= X-MC-Unique: zQkPDTbnNgGQJqpO3k9LVQ-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas Subject: [PULL 22/27] migration/multifd: Prepare multifd sync for mapped-ram migration Date: Mon, 4 Mar 2024 09:26:29 +0800 Message-ID: <20240304012634.95520-23-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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 @redhat.com) X-ZM-MESSAGEID: 1709515907985100003 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas The mapped-ram migration can be performed live or non-live, but it is always asynchronous, i.e. the source machine and the destination machine are not migrating at the same time. We only need some pieces of the multifd sync operations. multifd_send_sync_main() Reviewed-by: Peter Xu ------------------------ Issued by the ram migration code on the migration thread, causes the multifd send channels to synchronize with the migration thread and makes the sending side emit a packet with the MULTIFD_FLUSH flag. With mapped-ram we want to maintain the sync on the sending side because that provides ordering between the rounds of dirty pages when migrating live. MULTIFD_FLUSH ------------- On the receiving side, the presence of the MULTIFD_FLUSH flag on a packet causes the receiving channels to start synchronizing with the main thread. We're not using packets with mapped-ram, so there's no MULTIFD_FLUSH flag and therefore no channel sync on the receiving side. multifd_recv_sync_main() ------------------------ Issued by the migration thread when the ram migration flag RAM_SAVE_FLAG_MULTIFD_FLUSH is received, causes the migration thread on the receiving side to start synchronizing with the recv channels. Due to compatibility, this is also issued when RAM_SAVE_FLAG_EOS is received. For mapped-ram we only need to synchronize the channels at the end of migration to avoid doing cleanup before the channels have finished their IO. Make sure the multifd syncs are only issued at the appropriate times. Note that due to pre-existing backward compatibility issues, we have the multifd_flush_after_each_section property that can cause a sync to happen at EOS. Since the EOS flag is needed on the stream, allow mapped-ram to just ignore it. Also emit an error if any other unexpected flags are found on the stream. Signed-off-by: Fabiano Rosas Reviewed-by: Peter Xu Link: https://lore.kernel.org/r/20240229153017.2221-20-farosas@suse.de Signed-off-by: Peter Xu --- migration/ram.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 18620784c6..329153d97d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1362,14 +1362,18 @@ static int find_dirty_block(RAMState *rs, PageSearc= hStatus *pss) pss->block =3D QLIST_NEXT_RCU(pss->block, next); if (!pss->block) { if (migrate_multifd() && - !migrate_multifd_flush_after_each_section()) { + (!migrate_multifd_flush_after_each_section() || + migrate_mapped_ram())) { QEMUFile *f =3D rs->pss[RAM_CHANNEL_PRECOPY].pss_channel; int ret =3D multifd_send_sync_main(); if (ret < 0) { return ret; } - qemu_put_be64(f, RAM_SAVE_FLAG_MULTIFD_FLUSH); - qemu_fflush(f); + + if (!migrate_mapped_ram()) { + qemu_put_be64(f, RAM_SAVE_FLAG_MULTIFD_FLUSH); + qemu_fflush(f); + } } /* * If memory migration starts over, we will meet a dirtied page @@ -3111,7 +3115,8 @@ static int ram_save_setup(QEMUFile *f, void *opaque) return ret; } =20 - if (migrate_multifd() && !migrate_multifd_flush_after_each_section()) { + if (migrate_multifd() && !migrate_multifd_flush_after_each_section() + && !migrate_mapped_ram()) { qemu_put_be64(f, RAM_SAVE_FLAG_MULTIFD_FLUSH); } =20 @@ -3242,7 +3247,8 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) out: if (ret >=3D 0 && migration_is_setup_or_active(migrate_get_current()->state)) { - if (migrate_multifd() && migrate_multifd_flush_after_each_section(= )) { + if (migrate_multifd() && migrate_multifd_flush_after_each_section(= ) && + !migrate_mapped_ram()) { ret =3D multifd_send_sync_main(); if (ret < 0) { return ret; @@ -3334,7 +3340,8 @@ static int ram_save_complete(QEMUFile *f, void *opaqu= e) } } =20 - if (migrate_multifd() && !migrate_multifd_flush_after_each_section()) { + if (migrate_multifd() && !migrate_multifd_flush_after_each_section() && + !migrate_mapped_ram()) { qemu_put_be64(f, RAM_SAVE_FLAG_MULTIFD_FLUSH); } qemu_put_be64(f, RAM_SAVE_FLAG_EOS); @@ -4137,6 +4144,12 @@ static int ram_load_precopy(QEMUFile *f) invalid_flags |=3D RAM_SAVE_FLAG_COMPRESS_PAGE; } =20 + if (migrate_mapped_ram()) { + invalid_flags |=3D (RAM_SAVE_FLAG_HOOK | RAM_SAVE_FLAG_MULTIFD_FLU= SH | + RAM_SAVE_FLAG_PAGE | RAM_SAVE_FLAG_XBZRLE | + RAM_SAVE_FLAG_ZERO); + } + while (!ret && !(flags & RAM_SAVE_FLAG_EOS)) { ram_addr_t addr; void *host =3D NULL, *host_bak =3D NULL; @@ -4158,6 +4171,8 @@ static int ram_load_precopy(QEMUFile *f) addr &=3D TARGET_PAGE_MASK; =20 if (flags & invalid_flags) { + error_report("Unexpected RAM flags: %d", flags & invalid_flags= ); + if (flags & invalid_flags & RAM_SAVE_FLAG_COMPRESS_PAGE) { error_report("Received an unexpected compressed page"); } @@ -4210,6 +4225,10 @@ static int ram_load_precopy(QEMUFile *f) switch (flags & ~RAM_SAVE_FLAG_CONTINUE) { case RAM_SAVE_FLAG_MEM_SIZE: ret =3D parse_ramblocks(f, addr); + + if (migrate_mapped_ram()) { + multifd_recv_sync_main(); + } break; =20 case RAM_SAVE_FLAG_ZERO: @@ -4250,7 +4269,12 @@ static int ram_load_precopy(QEMUFile *f) case RAM_SAVE_FLAG_EOS: /* normal exit */ if (migrate_multifd() && - migrate_multifd_flush_after_each_section()) { + migrate_multifd_flush_after_each_section() && + /* + * Mapped-ram migration flushes once and for all after + * parsing ramblocks. Always ignore EOS for it. + */ + !migrate_mapped_ram()) { multifd_recv_sync_main(); } break; --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515783; cv=none; d=zohomail.com; s=zohoarc; b=ZX5FcO2fKP1sD57I/Q6PLfJ8PWKb//xqdNsFyIoHGHR27n5ikQCJUUpiR+uRnWa7gsq6l75WCFf3HEgQ2f2UMrLVXn7H41yho2UGhytO1Xho+9tgt4dUpmnaZwqpWAGQqRwCGSIs+P952sOYkkg/GrvB/KrQWxXbZ3kL/13qCKY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515783; 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=u3Be6Wrk9dm4cdxf3NXplQV9depJn9+V/ytNHNx6lEU=; b=gzWKdDpU8pzOuiaQ47xArvERUkv7D6BQRIE7oau+EdrjC5pIV/PXLMussNb7yg9exhLYT8NG1+IFwHQPZmtSDNAGdZNuP0599iRZpQYkVdJn0cdupzNSRPqg+sJQ0o7QqCyTCB0O+hGWvwxmEBZqpDMq1o5DmeC1gQM9RaaoSEw= 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 170951578313685.04015425152954; Sun, 3 Mar 2024 17:29:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx8V-0004IP-Ez; Sun, 03 Mar 2024 20:28:59 -0500 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 1rgx80-0002Tk-2h for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx7x-0002Rb-VM for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:27 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-499-tCIghsUQMKWmYAvSwxC5Gg-1; Sun, 03 Mar 2024 20:28:21 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4574529ABA07; Mon, 4 Mar 2024 01:28:21 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id D93D740C6EBA; Mon, 4 Mar 2024 01:28:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515705; h=from:from:reply-to:subject:subject: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=u3Be6Wrk9dm4cdxf3NXplQV9depJn9+V/ytNHNx6lEU=; b=WW/IdNQQoNry2hyKIuczOkpnzZLWtvQBxOyxAaC83z3guAIx6TSXq/xZoDK0CVtlIJNfIC I75xHq8RhKkL/vvnjGlH5QAknRjzv+lOgsl9yM+siMb1PXRyA8xtPZNhhd5m+8chjftpro DnkSGbRRECifYeFKAzpiIryWVOJxsxA= X-MC-Unique: tCIghsUQMKWmYAvSwxC5Gg-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas Subject: [PULL 23/27] migration/multifd: Support outgoing mapped-ram stream format Date: Mon, 4 Mar 2024 09:26:30 +0800 Message-ID: <20240304012634.95520-24-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1709515785284100003 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas The new mapped-ram stream format uses a file transport and puts ram pages in the migration file at their respective offsets and can be done in parallel by using the pwritev system call which takes iovecs and an offset. Add support to enabling the new format along with multifd to make use of the threading and page handling already in place. This requires multifd to stop sending headers and leaving the stream format to the mapped-ram code. When it comes time to write the data, we need to call a version of qio_channel_write that can take an offset. Usage on HMP is: (qemu) stop (qemu) migrate_set_capability multifd on (qemu) migrate_set_capability mapped-ram on (qemu) migrate_set_parameter max-bandwidth 0 (qemu) migrate_set_parameter multifd-channels 8 (qemu) migrate file:migfile Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240229153017.2221-21-farosas@suse.de Signed-off-by: Peter Xu --- include/qemu/bitops.h | 13 +++++++++++ migration/file.h | 2 ++ migration/ram.h | 1 + migration/file.c | 54 +++++++++++++++++++++++++++++++++++++++++++ migration/migration.c | 17 ++++++++++---- migration/multifd.c | 24 +++++++++++++++++-- migration/options.c | 13 ++++++----- migration/ram.c | 17 +++++++++++--- 8 files changed, 125 insertions(+), 16 deletions(-) diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h index cb3526d1f4..2c0a2fe751 100644 --- a/include/qemu/bitops.h +++ b/include/qemu/bitops.h @@ -67,6 +67,19 @@ static inline void clear_bit(long nr, unsigned long *add= r) *p &=3D ~mask; } =20 +/** + * clear_bit_atomic - Clears a bit in memory atomically + * @nr: Bit to clear + * @addr: Address to start counting from + */ +static inline void clear_bit_atomic(long nr, unsigned long *addr) +{ + unsigned long mask =3D BIT_MASK(nr); + unsigned long *p =3D addr + BIT_WORD(nr); + + return qatomic_and(p, ~mask); +} + /** * change_bit - Toggle a bit in memory * @nr: Bit to change diff --git a/migration/file.h b/migration/file.h index 4577f9efdd..01a338cac7 100644 --- a/migration/file.h +++ b/migration/file.h @@ -19,4 +19,6 @@ void file_start_outgoing_migration(MigrationState *s, int file_parse_offset(char *filespec, uint64_t *offsetp, Error **errp); void file_cleanup_outgoing_migration(void); bool file_send_channel_create(gpointer opaque, Error **errp); +int file_write_ramblock_iov(QIOChannel *ioc, const struct iovec *iov, + int niov, RAMBlock *block, Error **errp); #endif diff --git a/migration/ram.h b/migration/ram.h index 9b937a446b..b9ac0da587 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -75,6 +75,7 @@ bool ram_dirty_bitmap_reload(MigrationState *s, RAMBlock = *rb, Error **errp); bool ramblock_page_is_discarded(RAMBlock *rb, ram_addr_t start); void postcopy_preempt_shutdown_file(MigrationState *s); void *postcopy_preempt_thread(void *opaque); +void ramblock_set_file_bmap_atomic(RAMBlock *block, ram_addr_t offset); =20 /* ram cache */ int colo_init_ram_cache(void); diff --git a/migration/file.c b/migration/file.c index 2f8b626b27..d949a941d0 100644 --- a/migration/file.c +++ b/migration/file.c @@ -150,3 +150,57 @@ void file_start_incoming_migration(FileMigrationArgs *= file_args, Error **errp) } } while (++i < channels); } + +int file_write_ramblock_iov(QIOChannel *ioc, const struct iovec *iov, + int niov, RAMBlock *block, Error **errp) +{ + ssize_t ret =3D -1; + int i, slice_idx, slice_num; + uintptr_t base, next, offset; + size_t len; + + slice_idx =3D 0; + slice_num =3D 1; + + /* + * If the iov array doesn't have contiguous elements, we need to + * split it in slices because we only have one file offset for the + * whole iov. Do this here so callers don't need to break the iov + * array themselves. + */ + for (i =3D 0; i < niov; i++, slice_num++) { + base =3D (uintptr_t) iov[i].iov_base; + + if (i !=3D niov - 1) { + len =3D iov[i].iov_len; + next =3D (uintptr_t) iov[i + 1].iov_base; + + if (base + len =3D=3D next) { + continue; + } + } + + /* + * Use the offset of the first element of the segment that + * we're sending. + */ + offset =3D (uintptr_t) iov[slice_idx].iov_base - (uintptr_t) block= ->host; + if (offset >=3D block->used_length) { + error_setg(errp, "offset " RAM_ADDR_FMT + "outside of ramblock %s range", offset, block->idst= r); + ret =3D -1; + break; + } + + ret =3D qio_channel_pwritev(ioc, &iov[slice_idx], slice_num, + block->pages_offset + offset, errp); + if (ret < 0) { + break; + } + + slice_idx +=3D slice_num; + slice_num =3D 0; + } + + return (ret < 0) ? ret : 0; +} diff --git a/migration/migration.c b/migration/migration.c index faeb75a59b..b9baab543a 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -140,12 +140,14 @@ static bool transport_supports_multi_channels(Migrati= onAddress *addr) if (addr->transport =3D=3D MIGRATION_ADDRESS_TYPE_SOCKET) { SocketAddress *saddr =3D &addr->u.socket; =20 - return saddr->type =3D=3D SOCKET_ADDRESS_TYPE_INET || - saddr->type =3D=3D SOCKET_ADDRESS_TYPE_UNIX || - saddr->type =3D=3D SOCKET_ADDRESS_TYPE_VSOCK; + return (saddr->type =3D=3D SOCKET_ADDRESS_TYPE_INET || + saddr->type =3D=3D SOCKET_ADDRESS_TYPE_UNIX || + saddr->type =3D=3D SOCKET_ADDRESS_TYPE_VSOCK); + } else if (addr->transport =3D=3D MIGRATION_ADDRESS_TYPE_FILE) { + return migrate_mapped_ram(); + } else { + return false; } - - return false; } =20 static bool migration_needs_seekable_channel(void) @@ -1985,6 +1987,11 @@ static bool migrate_prepare(MigrationState *s, bool = blk, bool blk_inc, error_setg(errp, "Cannot use TLS with mapped-ram"); return false; } + + if (migrate_multifd_compression()) { + error_setg(errp, "Cannot use compression with mapped-ram"); + return false; + } } =20 if (migrate_mode_is_cpr(s)) { diff --git a/migration/multifd.c b/migration/multifd.c index ea08f1aa9e..8118145428 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -108,6 +108,17 @@ void multifd_send_channel_created(void) qemu_sem_post(&multifd_send_state->channels_created); } =20 +static void multifd_set_file_bitmap(MultiFDSendParams *p) +{ + MultiFDPages_t *pages =3D p->pages; + + assert(pages->block); + + for (int i =3D 0; i < p->pages->num; i++) { + ramblock_set_file_bmap_atomic(pages->block, pages->offset[i]); + } +} + /* Multifd without compression */ =20 /** @@ -169,6 +180,8 @@ static int nocomp_send_prepare(MultiFDSendParams *p, Er= ror **errp) =20 if (!multifd_use_packets()) { multifd_send_prepare_iovs(p); + multifd_set_file_bitmap(p); + return 0; } =20 @@ -867,8 +880,15 @@ static void *multifd_send_thread(void *opaque) break; } =20 - ret =3D qio_channel_writev_full_all(p->c, p->iov, p->iovs_num,= NULL, - 0, p->write_flags, &local_er= r); + if (migrate_mapped_ram()) { + ret =3D file_write_ramblock_iov(p->c, p->iov, p->iovs_num, + p->pages->block, &local_err); + } else { + ret =3D qio_channel_writev_full_all(p->c, p->iov, p->iovs_= num, + NULL, 0, p->write_flags, + &local_err); + } + if (ret !=3D 0) { break; } diff --git a/migration/options.c b/migration/options.c index 5df89820fd..40eb930940 100644 --- a/migration/options.c +++ b/migration/options.c @@ -654,12 +654,6 @@ bool migrate_caps_check(bool *old_caps, bool *new_caps= , Error **errp) } =20 if (new_caps[MIGRATION_CAPABILITY_MAPPED_RAM]) { - if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) { - error_setg(errp, - "Mapped-ram migration is incompatible with multifd"= ); - return false; - } - if (new_caps[MIGRATION_CAPABILITY_XBZRLE]) { error_setg(errp, "Mapped-ram migration is incompatible with xbzrle"); @@ -1252,6 +1246,13 @@ bool migrate_params_check(MigrationParameters *param= s, Error **errp) } #endif =20 + if (migrate_mapped_ram() && + (migrate_multifd_compression() || migrate_tls())) { + error_setg(errp, + "Mapped-ram only available for non-compressed non-TLS m= ultifd migration"); + return false; + } + if (params->has_x_vcpu_dirty_limit_period && (params->x_vcpu_dirty_limit_period < 1 || params->x_vcpu_dirty_limit_period > 1000)) { diff --git a/migration/ram.c b/migration/ram.c index 329153d97d..87cb73fd76 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1148,7 +1148,7 @@ static int save_zero_page(RAMState *rs, PageSearchSta= tus *pss, =20 if (migrate_mapped_ram()) { /* zero pages are not transferred with mapped-ram */ - clear_bit(offset >> TARGET_PAGE_BITS, pss->block->file_bmap); + clear_bit_atomic(offset >> TARGET_PAGE_BITS, pss->block->file_bmap= ); return 1; } =20 @@ -2445,8 +2445,6 @@ static void ram_save_cleanup(void *opaque) block->clear_bmap =3D NULL; g_free(block->bmap); block->bmap =3D NULL; - g_free(block->file_bmap); - block->file_bmap =3D NULL; } =20 xbzrle_cleanup(); @@ -3135,9 +3133,22 @@ static void ram_save_file_bmap(QEMUFile *f) qemu_put_buffer_at(f, (uint8_t *)block->file_bmap, bitmap_size, block->bitmap_offset); ram_transferred_add(bitmap_size); + + /* + * Free the bitmap here to catch any synchronization issues + * with multifd channels. No channels should be sending pages + * after we've written the bitmap to file. + */ + g_free(block->file_bmap); + block->file_bmap =3D NULL; } } =20 +void ramblock_set_file_bmap_atomic(RAMBlock *block, ram_addr_t offset) +{ + set_bit_atomic(offset >> TARGET_PAGE_BITS, block->file_bmap); +} + /** * ram_save_iterate: iterative stage for migration * --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515747; cv=none; d=zohomail.com; s=zohoarc; b=MGw4dV5B0eiOtkcvA+igBNLS8IRef6VyWeOkzGTwYVAAJy21kXuXphCKUTZSSgFlwy5mtXBZkNJy489r6f7ymIAIWbSqwdHy/vTdctUTK6lUeaxq/WPT5fqMG0H3KREKR8j4pP/0ClBObzUX9mahxRntgfU9cDiZy+Ju9NH7914= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515747; 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=MYRu32m8uCs0jJp9EUvwDMLyBwy80EolLkVwNY9f+rI=; b=lznSsf4QtTaUP10ZEVQ4YJqVkQ0r1zwtdDvoEEXxLudlCCjJfhxilJYY6XDXSGUAxZMJNGshxVdvCCHCEZrgU/RgWS3qiXCSTRHm4+ktJAjKSzHTsAOtyIZNKX3mX+9NJWPKpy2vbTBCwrloGZcbfmnKCoeioYLDijwk7RZ7yY0= 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 1709515747962626.4008231049992; Sun, 3 Mar 2024 17:29:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx8I-0002sE-Ep; Sun, 03 Mar 2024 20:28:48 -0500 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 1rgx84-0002cG-65 for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx81-0002Rv-SD for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:31 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-368-mJug5pXLP8mhXOovYyW63g-1; Sun, 03 Mar 2024 20:28:25 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7600A8820C3; Mon, 4 Mar 2024 01:28:25 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 157FD40C6EBA; Mon, 4 Mar 2024 01:28:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515709; h=from:from:reply-to:subject:subject: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=MYRu32m8uCs0jJp9EUvwDMLyBwy80EolLkVwNY9f+rI=; b=JxtltQZt7Qj6HtohZFAPoYbA0nViVIFkO4KMIeFJkaCH0zRqP856YCt82Lm5MiTUcRD+Jq X8xESRcGNry5Xb4M98/PPfkHiq7oKtJQtGjvQEI8eL3+R9lpLZvLKZ7DxEnhFxIimPj0lU oqyocqK3FMeJKcYC9IRpi5e4liPiXXY= X-MC-Unique: mJug5pXLP8mhXOovYyW63g-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas Subject: [PULL 24/27] migration/multifd: Support incoming mapped-ram stream format Date: Mon, 4 Mar 2024 09:26:31 +0800 Message-ID: <20240304012634.95520-25-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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 @redhat.com) X-ZM-MESSAGEID: 1709515749169100001 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas For the incoming mapped-ram migration we need to read the ramblock headers, get the pages bitmap and send the host address of each non-zero page to the multifd channel thread for writing. Usage on HMP is: (qemu) migrate_set_capability multifd on (qemu) migrate_set_capability mapped-ram on (qemu) migrate_incoming file:migfile (the ram.h include needs to move because we've been previously relying on it being included from migration.c. Now file.h will start including multifd.h before migration.o is processed) Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240229153017.2221-22-farosas@suse.de Signed-off-by: Peter Xu --- migration/file.h | 2 ++ migration/multifd.h | 2 ++ migration/file.c | 18 +++++++++++++++++- migration/multifd.c | 31 ++++++++++++++++++++++++++++--- migration/ram.c | 26 ++++++++++++++++++++++++-- 5 files changed, 73 insertions(+), 6 deletions(-) diff --git a/migration/file.h b/migration/file.h index 01a338cac7..9f71e87f74 100644 --- a/migration/file.h +++ b/migration/file.h @@ -11,6 +11,7 @@ #include "qapi/qapi-types-migration.h" #include "io/task.h" #include "channel.h" +#include "multifd.h" =20 void file_start_incoming_migration(FileMigrationArgs *file_args, Error **e= rrp); =20 @@ -21,4 +22,5 @@ void file_cleanup_outgoing_migration(void); bool file_send_channel_create(gpointer opaque, Error **errp); int file_write_ramblock_iov(QIOChannel *ioc, const struct iovec *iov, int niov, RAMBlock *block, Error **errp); +int multifd_file_recv_data(MultiFDRecvParams *p, Error **errp); #endif diff --git a/migration/multifd.h b/migration/multifd.h index db8887f088..7447c2bea3 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -13,6 +13,8 @@ #ifndef QEMU_MIGRATION_MULTIFD_H #define QEMU_MIGRATION_MULTIFD_H =20 +#include "ram.h" + typedef struct MultiFDRecvData MultiFDRecvData; =20 bool multifd_send_setup(void); diff --git a/migration/file.c b/migration/file.c index d949a941d0..499d2782fe 100644 --- a/migration/file.c +++ b/migration/file.c @@ -13,7 +13,6 @@ #include "channel.h" #include "file.h" #include "migration.h" -#include "multifd.h" #include "io/channel-file.h" #include "io/channel-util.h" #include "options.h" @@ -204,3 +203,20 @@ int file_write_ramblock_iov(QIOChannel *ioc, const str= uct iovec *iov, =20 return (ret < 0) ? ret : 0; } + +int multifd_file_recv_data(MultiFDRecvParams *p, Error **errp) +{ + MultiFDRecvData *data =3D p->data; + size_t ret; + + ret =3D qio_channel_pread(p->c, (char *) data->opaque, + data->size, data->file_offset, errp); + if (ret !=3D data->size) { + error_prepend(errp, + "multifd recv (%u): read 0x%zx, expected 0x%zx", + p->id, ret, data->size); + return -1; + } + + return 0; +} diff --git a/migration/multifd.c b/migration/multifd.c index 8118145428..419feb7df1 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -18,7 +18,6 @@ #include "qemu/error-report.h" #include "qapi/error.h" #include "file.h" -#include "ram.h" #include "migration.h" #include "migration-stats.h" #include "socket.h" @@ -251,7 +250,7 @@ static int nocomp_recv(MultiFDRecvParams *p, Error **er= rp) uint32_t flags; =20 if (!multifd_use_packets()) { - return 0; + return multifd_file_recv_data(p, errp); } =20 flags =3D p->flags & MULTIFD_FLAG_COMPRESSION_MASK; @@ -1331,22 +1330,48 @@ void multifd_recv_cleanup(void) void multifd_recv_sync_main(void) { int thread_count =3D migrate_multifd_channels(); + bool file_based =3D !multifd_use_packets(); int i; =20 - if (!migrate_multifd() || !multifd_use_packets()) { + if (!migrate_multifd()) { return; } =20 + /* + * File-based channels don't use packets and therefore need to + * wait for more work. Release them to start the sync. + */ + if (file_based) { + for (i =3D 0; i < thread_count; i++) { + MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; + + trace_multifd_recv_sync_main_signal(p->id); + qemu_sem_post(&p->sem); + } + } + /* * Initiate the synchronization by waiting for all channels. + * * For socket-based migration this means each channel has received * the SYNC packet on the stream. + * + * For file-based migration this means each channel is done with + * the work (pending_job=3Dfalse). */ for (i =3D 0; i < thread_count; i++) { trace_multifd_recv_sync_main_wait(i); qemu_sem_wait(&multifd_recv_state->sem_sync); } =20 + if (file_based) { + /* + * For file-based loading is done in one iteration. We're + * done. + */ + return; + } + /* * Sync done. Release the channels for the next iteration. */ diff --git a/migration/ram.c b/migration/ram.c index 87cb73fd76..1f1b5297cf 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3952,6 +3952,22 @@ void colo_flush_ram_cache(void) trace_colo_flush_ram_cache_end(); } =20 +static size_t ram_load_multifd_pages(void *host_addr, size_t size, + uint64_t offset) +{ + MultiFDRecvData *data =3D multifd_get_recv_data(); + + data->opaque =3D host_addr; + data->file_offset =3D offset; + data->size =3D size; + + if (!multifd_recv()) { + return 0; + } + + return size; +} + static bool read_ramblock_mapped_ram(QEMUFile *f, RAMBlock *block, long num_pages, unsigned long *bitmap, Error **errp) @@ -3981,8 +3997,14 @@ static bool read_ramblock_mapped_ram(QEMUFile *f, RA= MBlock *block, =20 size =3D MIN(unread, MAPPED_RAM_LOAD_BUF_SIZE); =20 - read =3D qemu_get_buffer_at(f, host, size, - block->pages_offset + offset); + if (migrate_multifd()) { + read =3D ram_load_multifd_pages(host, size, + block->pages_offset + offset= ); + } else { + read =3D qemu_get_buffer_at(f, host, size, + block->pages_offset + offset); + } + if (!read) { goto err; } --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515911; cv=none; d=zohomail.com; s=zohoarc; b=RMPPBwpOp38WiTiozY8nr0SupQh3YoKJbfo2AO74M7fw3XCXGKy6ZT7uw4Os3EmEXb3qJ95Q7GxRWQlCXeJuqwH2BWs4AMEpiOFURNmtmJ6iYLjRxSSLDptezfPXSKIh5OO+M5QE1/XRBch3V77EIqL8OB5Co0c148WsnjHMi7o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515911; 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=epLuZtJ97aqUb1mDIYXVIAdIkCaOvXm81Z6JXpZJqf0=; b=LcL9Mqf9551f+U2Uk7ZCA2xYO38nIrsf31YG3rj1zycnm86yONxdvnsdOx7pBql8No26ZD4CkQ182iOLyxSxpwdFCC9h6d2zLVZpZkXFVAmZkTz1bN4HujlVh7vMtS+T0grgqxu9bCtzeeB18MMWmdF0pmEEvES2jAYO0TRI59o= 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 170951591169730.08078361752507; Sun, 3 Mar 2024 17:31:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx8X-0004Ym-KS; Sun, 03 Mar 2024 20:29:01 -0500 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 1rgx87-0002fx-2b for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx85-0002S8-9y for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:34 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-1-jQjm0ARKP-q1Z4nu_BInWA-1; Sun, 03 Mar 2024 20:28:29 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0FF56185A785; Mon, 4 Mar 2024 01:28:29 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F2F84024860; Mon, 4 Mar 2024 01:28:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515712; h=from:from:reply-to:subject:subject: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=epLuZtJ97aqUb1mDIYXVIAdIkCaOvXm81Z6JXpZJqf0=; b=HYeqWvtqVBXcA6zL7THIvZVg1lB1jAsoKy6uWSq/eHYeCGCQSjWS/MembqNL7T6XKchg7E 5fUbgNzJxhxcJz1YLToeu7iEVhNEv5zWsVO0a6O+c2h8tzy2dL9Wsa617ryHM+jXLD3kq+ WoXQi3nFwSK22DeNnkSnKNA+DjMwCD0= X-MC-Unique: jQjm0ARKP-q1Z4nu_BInWA-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas Subject: [PULL 25/27] migration/multifd: Add mapped-ram support to fd: URI Date: Mon, 4 Mar 2024 09:26:32 +0800 Message-ID: <20240304012634.95520-26-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1709515911917100001 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas If we receive a file descriptor that points to a regular file, there's nothing stopping us from doing multifd migration with mapped-ram to that file. Enable the fd: URI to work with multifd + mapped-ram. Note that the fds passed into multifd are duplicated because we want to avoid cross-thread effects when doing cleanup (i.e. close(fd)). The original fd doesn't need to be duplicated because monitor_get_fd() transfers ownership to the caller. Signed-off-by: Fabiano Rosas Reviewed-by: Peter Xu Link: https://lore.kernel.org/r/20240229153017.2221-23-farosas@suse.de Signed-off-by: Peter Xu --- migration/fd.h | 2 ++ migration/fd.c | 44 +++++++++++++++++++++++++++++++++++++++++++ migration/file.c | 18 ++++++++++++------ migration/migration.c | 4 ++++ migration/multifd.c | 2 ++ 5 files changed, 64 insertions(+), 6 deletions(-) diff --git a/migration/fd.h b/migration/fd.h index b901bc014e..0c0a18d9e7 100644 --- a/migration/fd.h +++ b/migration/fd.h @@ -20,4 +20,6 @@ void fd_start_incoming_migration(const char *fdname, Erro= r **errp); =20 void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp); +void fd_cleanup_outgoing_migration(void); +int fd_args_get_fd(void); #endif diff --git a/migration/fd.c b/migration/fd.c index 0eb677dcae..d4ae72d132 100644 --- a/migration/fd.c +++ b/migration/fd.c @@ -15,18 +15,41 @@ */ =20 #include "qemu/osdep.h" +#include "qapi/error.h" #include "channel.h" #include "fd.h" #include "migration.h" #include "monitor/monitor.h" +#include "io/channel-file.h" #include "io/channel-util.h" +#include "options.h" #include "trace.h" =20 =20 +static struct FdOutgoingArgs { + int fd; +} outgoing_args; + +int fd_args_get_fd(void) +{ + return outgoing_args.fd; +} + +void fd_cleanup_outgoing_migration(void) +{ + if (outgoing_args.fd > 0) { + close(outgoing_args.fd); + outgoing_args.fd =3D -1; + } +} + void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Er= ror **errp) { QIOChannel *ioc; int fd =3D monitor_get_fd(monitor_cur(), fdname, errp); + + outgoing_args.fd =3D -1; + if (fd =3D=3D -1) { return; } @@ -38,6 +61,8 @@ void fd_start_outgoing_migration(MigrationState *s, const= char *fdname, Error ** return; } =20 + outgoing_args.fd =3D fd; + qio_channel_set_name(ioc, "migration-fd-outgoing"); migration_channel_connect(s, ioc, NULL, NULL); object_unref(OBJECT(ioc)); @@ -73,4 +98,23 @@ void fd_start_incoming_migration(const char *fdname, Err= or **errp) fd_accept_incoming_migration, NULL, NULL, g_main_context_get_thread_default()); + + if (migrate_multifd()) { + int channels =3D migrate_multifd_channels(); + + while (channels--) { + ioc =3D QIO_CHANNEL(qio_channel_file_new_fd(dup(fd))); + + if (QIO_CHANNEL_FILE(ioc)->fd =3D=3D -1) { + error_setg(errp, "Failed to duplicate fd %d", fd); + return; + } + + qio_channel_set_name(ioc, "migration-fd-incoming"); + qio_channel_add_watch_full(ioc, G_IO_IN, + fd_accept_incoming_migration, + NULL, NULL, + g_main_context_get_thread_default()= ); + } + } } diff --git a/migration/file.c b/migration/file.c index 499d2782fe..164b079966 100644 --- a/migration/file.c +++ b/migration/file.c @@ -11,6 +11,7 @@ #include "qemu/error-report.h" #include "qapi/error.h" #include "channel.h" +#include "fd.h" #include "file.h" #include "migration.h" #include "io/channel-file.h" @@ -53,15 +54,20 @@ bool file_send_channel_create(gpointer opaque, Error **= errp) { QIOChannelFile *ioc; int flags =3D O_WRONLY; - bool ret =3D true; - - ioc =3D qio_channel_file_new_path(outgoing_args.fname, flags, 0, errp); - if (!ioc) { - ret =3D false; - goto out; + bool ret =3D false; + int fd =3D fd_args_get_fd(); + + if (fd && fd !=3D -1) { + ioc =3D qio_channel_file_new_fd(dup(fd)); + } else { + ioc =3D qio_channel_file_new_path(outgoing_args.fname, flags, 0, e= rrp); + if (!ioc) { + goto out; + } } =20 multifd_channel_connect(opaque, QIO_CHANNEL(ioc)); + ret =3D true; =20 out: /* diff --git a/migration/migration.c b/migration/migration.c index b9baab543a..a49fcd53ee 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -140,6 +140,10 @@ static bool transport_supports_multi_channels(Migratio= nAddress *addr) if (addr->transport =3D=3D MIGRATION_ADDRESS_TYPE_SOCKET) { SocketAddress *saddr =3D &addr->u.socket; =20 + if (saddr->type =3D=3D SOCKET_ADDRESS_TYPE_FD) { + return migrate_mapped_ram(); + } + return (saddr->type =3D=3D SOCKET_ADDRESS_TYPE_INET || saddr->type =3D=3D SOCKET_ADDRESS_TYPE_UNIX || saddr->type =3D=3D SOCKET_ADDRESS_TYPE_VSOCK); diff --git a/migration/multifd.c b/migration/multifd.c index 419feb7df1..b4e5a9dfcc 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -17,6 +17,7 @@ #include "exec/ramblock.h" #include "qemu/error-report.h" #include "qapi/error.h" +#include "fd.h" #include "file.h" #include "migration.h" #include "migration-stats.h" @@ -731,6 +732,7 @@ static bool multifd_send_cleanup_channel(MultiFDSendPar= ams *p, Error **errp) static void multifd_send_cleanup_state(void) { file_cleanup_outgoing_migration(); + fd_cleanup_outgoing_migration(); socket_cleanup_outgoing_migration(); qemu_sem_destroy(&multifd_send_state->channels_created); qemu_sem_destroy(&multifd_send_state->channels_ready); --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515744; cv=none; d=zohomail.com; s=zohoarc; b=Fjrt6D3gcgEx3biMKCbAAhUVI+G7rZ+LeRdVpSES0mqiFAgtDyCQa6G7ccUkuJgrBcZnSqTfOiJvDJ0jSqaVsiPFzZTkuOs5XxenEepvZEqhS7MpFpBIf8T7C/v7Jxm0Bz47eQpD5MHuq9nmugHsgv7W78jgPZ8iPiT+1UfhO1Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515744; 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=VGsaTKXYi4p8i16mdNER8UjgI9dBQlyWyaXYcRxh438=; b=FMZ+djyxhk9bxUDHRIhXmHiVjVC+PqCRiko14MrJuUTFE0QzmjvZ0uSGlNqP1Jb+aeptwpOY60/vY1XqPxzQiu67TWY8r4PR9mJHAIMrSrh0HVT1oZS9POmNbaqieLbfxJWQ2q2pcStN9+5uiBEOzsuNhnAgQBsRocvlTvSJf7s= 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 1709515744968561.4425120632262; Sun, 3 Mar 2024 17:29:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx8S-0003d0-LD; Sun, 03 Mar 2024 20:28:56 -0500 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 1rgx89-0002jf-Qg for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx88-0002SX-30 for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:37 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-412-miqb2J0RPwaBjBt6fb5HgQ-1; Sun, 03 Mar 2024 20:28:34 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 40FD63C0DD0A; Mon, 4 Mar 2024 01:28:33 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id D4A6B40C6EBA; Mon, 4 Mar 2024 01:28:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515715; h=from:from:reply-to:subject:subject: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=VGsaTKXYi4p8i16mdNER8UjgI9dBQlyWyaXYcRxh438=; b=Cf/kMAuUUNn9wNt1kuVAppiy9KYzZnc65UJ3IS8TYURw6j68E0uwNiJisq51VVqFhO2Drr xe1soJZag1/3rhR4OwOXxZE6oGKeQEchUhXWLO5lA1RKs5VByL2f8hYCAKmEch8APo4b0Y 8Hw6bMpDZV6cLNGUWLjETBNL+7X1eSM= X-MC-Unique: miqb2J0RPwaBjBt6fb5HgQ-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas Subject: [PULL 26/27] tests/qtest/migration: Add a multifd + mapped-ram migration test Date: Mon, 4 Mar 2024 09:26:33 +0800 Message-ID: <20240304012634.95520-27-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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 @redhat.com) X-ZM-MESSAGEID: 1709515745119100013 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240229153017.2221-24-farosas@suse.de Signed-off-by: Peter Xu --- tests/qtest/migration-test.c | 68 ++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 4c5551f7d0..4023d808f9 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -2248,6 +2248,46 @@ static void test_precopy_file_mapped_ram(void) test_file_common(&args, true); } =20 +static void *migrate_multifd_mapped_ram_start(QTestState *from, QTestState= *to) +{ + migrate_mapped_ram_start(from, to); + + migrate_set_parameter_int(from, "multifd-channels", 4); + migrate_set_parameter_int(to, "multifd-channels", 4); + + migrate_set_capability(from, "multifd", true); + migrate_set_capability(to, "multifd", true); + + return NULL; +} + +static void test_multifd_file_mapped_ram_live(void) +{ + g_autofree char *uri =3D g_strdup_printf("file:%s/%s", tmpfs, + FILE_TEST_FILENAME); + MigrateCommon args =3D { + .connect_uri =3D uri, + .listen_uri =3D "defer", + .start_hook =3D migrate_multifd_mapped_ram_start, + }; + + test_file_common(&args, false); +} + +static void test_multifd_file_mapped_ram(void) +{ + g_autofree char *uri =3D g_strdup_printf("file:%s/%s", tmpfs, + FILE_TEST_FILENAME); + MigrateCommon args =3D { + .connect_uri =3D uri, + .listen_uri =3D "defer", + .start_hook =3D migrate_multifd_mapped_ram_start, + }; + + test_file_common(&args, true); +} + + static void test_precopy_tcp_plain(void) { MigrateCommon args =3D { @@ -2524,6 +2564,25 @@ static void test_migrate_precopy_fd_file_mapped_ram(= void) }; test_file_common(&args, true); } + +static void *migrate_multifd_fd_mapped_ram_start(QTestState *from, + QTestState *to) +{ + migrate_multifd_mapped_ram_start(from, to); + return migrate_precopy_fd_file_start(from, to); +} + +static void test_multifd_fd_mapped_ram(void) +{ + MigrateCommon args =3D { + .connect_uri =3D "fd:fd-mig", + .listen_uri =3D "defer", + .start_hook =3D migrate_multifd_fd_mapped_ram_start, + .finish_hook =3D test_migrate_fd_finish_hook + }; + + test_file_common(&args, true); +} #endif /* _WIN32 */ =20 static void do_test_validate_uuid(MigrateStart *args, bool should_fail) @@ -3576,6 +3635,15 @@ int main(int argc, char **argv) migration_test_add("/migration/precopy/file/mapped-ram/live", test_precopy_file_mapped_ram_live); =20 + migration_test_add("/migration/multifd/file/mapped-ram", + test_multifd_file_mapped_ram); + migration_test_add("/migration/multifd/file/mapped-ram/live", + test_multifd_file_mapped_ram_live); +#ifndef _WIN32 + migration_test_add("/migration/multifd/fd/mapped-ram", + test_multifd_fd_mapped_ram); +#endif + #ifdef CONFIG_GNUTLS migration_test_add("/migration/precopy/unix/tls/psk", test_precopy_unix_tls_psk); --=20 2.44.0 From nobody Tue Nov 26 06:40:33 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709515883; cv=none; d=zohomail.com; s=zohoarc; b=CS8HTT7ZiH8EsL3OFkp2p1hDf/a2RYPvxPhR6vtLPx/3/uMNskcnhWlwqsxYLgCo8paaTv8d98+rNEeM4NQotNQXjD0VnlqJegXUmGNE68vbPTm5CFbEWLAPLjsR0VNSHt542qxuTzmWubgVEFzSRQ6oOz3GYnRRMjMBC0qu5r0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709515883; 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=KQjfAx5fwudle9JMFQ3un6R3jAgdZL0axGO7bP69yRk=; b=P30TM8aDBn7z7ZmTtpjRLoN6nCYXN3XncIMtlTtBnkWC/sGg6jo/YIyE6dC7dD6O4D7eMkhW7UAOyYoKX1SaOgFbXE82q+Oc/VWckNArfp1KYH9g2cmLWnIi8ZE0+wRI5nk8zs/Uvf+oyjTTeIzdFdMJQA+XhB9G/rYzeYblRMU= 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 1709515883452354.3799132778256; Sun, 3 Mar 2024 17:31:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgx8Z-0004gi-8k; Sun, 03 Mar 2024 20:29:03 -0500 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 1rgx8G-0002sG-MN for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgx8F-0002UT-58 for qemu-devel@nongnu.org; Sun, 03 Mar 2024 20:28:44 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-474-zJ38GSrmNoemaGbvBocP4w-1; Sun, 03 Mar 2024 20:28:37 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 707B93C0DD05; Mon, 4 Mar 2024 01:28:37 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10D7A40C6EBA; Mon, 4 Mar 2024 01:28:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709515721; h=from:from:reply-to:subject:subject: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=KQjfAx5fwudle9JMFQ3un6R3jAgdZL0axGO7bP69yRk=; b=ciRgfk0zOa3qfWNIp3Gqm9jtWVmYGbwRaXZNqqtMBj7d9MyQffNqA09z0j95CNhkINGoO7 Y3hQ7LOiV+yiRPyDjwe+QNdJTW0MmqX4V67sjuif6UW6SswSu6Q+HC97TIcAzJMxUiuUrE WTimxzpmRboAfNwbxwnKcOrdSmKUoYA= X-MC-Unique: zJ38GSrmNoemaGbvBocP4w-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Prasad Pandit , Fabiano Rosas Subject: [PULL 27/27] migration/multifd: Document two places for mapped-ram Date: Mon, 4 Mar 2024 09:26:34 +0800 Message-ID: <20240304012634.95520-28-peterx@redhat.com> In-Reply-To: <20240304012634.95520-1-peterx@redhat.com> References: <20240304012634.95520-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.589, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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 @redhat.com) X-ZM-MESSAGEID: 1709515885767100011 Content-Type: text/plain; charset="utf-8" From: Peter Xu Add two documentations for mapped-ram migration on two spots that may not be extremely clear. Reviewed-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240301091524.39900-1-peterx@redhat.com Cc: Prasad Pandit [peterx: fix two English errors per Prasad] Signed-off-by: Peter Xu --- migration/multifd.c | 12 ++++++++++++ migration/ram.c | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/migration/multifd.c b/migration/multifd.c index b4e5a9dfcc..d4a44da559 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -709,6 +709,18 @@ static bool multifd_send_cleanup_channel(MultiFDSendPa= rams *p, Error **errp) { if (p->c) { migration_ioc_unregister_yank(p->c); + /* + * An explicit close() on the channel here is normally not + * required, but can be helpful for "file:" iochannels, where it + * will include fdatasync() to make sure the data is flushed to the + * disk backend. + * + * The object_unref() cannot guarantee that because: (1) finalize() + * of the iochannel is only triggered on the last reference, and + * it's not guaranteed that we always hold the last refcount when + * reaching here, and, (2) even if finalize() is invoked, it only + * does a close(fd) without data flush. + */ qio_channel_close(p->c, &error_abort); object_unref(OBJECT(p->c)); p->c =3D NULL; diff --git a/migration/ram.c b/migration/ram.c index 1f1b5297cf..c79e3de521 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4258,7 +4258,13 @@ static int ram_load_precopy(QEMUFile *f) switch (flags & ~RAM_SAVE_FLAG_CONTINUE) { case RAM_SAVE_FLAG_MEM_SIZE: ret =3D parse_ramblocks(f, addr); - + /* + * For mapped-ram migration (to a file) using multifd, we sync + * once and for all here to make sure all tasks we queued to + * multifd threads are completed, so that all the ramblocks + * (including all the guest memory pages within) are fully + * loaded after this sync returns. + */ if (migrate_mapped_ram()) { multifd_recv_sync_main(); } --=20 2.44.0