From nobody Sun Mar 22 15:40:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1773962121; cv=none; d=zohomail.com; s=zohoarc; b=BdmfjqoZiTKyKzB7kdNI9ydoqFHG3XhjG69PRHSjbGZhV/aQZIToW2IYrREtrbbxvF/JxBZmBkSkW+oOmQI34JUQqhOLdsGCEptnu8cTo4Ej0niNYQsHHCrGu9vGA92RAIHyi8kpdjeCfYh9aZ4Y8lPW2+nurrPsnBSNsPPgHhQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773962121; 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=V6xO5KlK8X7T9dIvIeNyHDMz8xdJ4Fx4esbGShwNklI=; b=ldUzx06HCB353sY70IBMM3oXW0F6RjLSBqdO4iR1Hr0bLnve/PKXk8lUByILpfKjt+sUHSFlDfpBXn9cJAZkJ9f5gQOMHxlRPa73glsl+K39MUHtzEMCP1BisKojy7gzzn2CUy0g5RDNVA5uNISOmP/+1N0/P/XrwA6nS7h8yX4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1773962121076136.58109482181158; Thu, 19 Mar 2026 16:15:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w3MYM-0001NI-6E; Thu, 19 Mar 2026 19:13:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w3MYL-0001N8-1R for qemu-devel@nongnu.org; Thu, 19 Mar 2026 19:13:21 -0400 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 1w3MYJ-0001Pw-Ar for qemu-devel@nongnu.org; Thu, 19 Mar 2026 19:13:20 -0400 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-100-Wow8rfqkMNmvIh2ID-IQqg-1; Thu, 19 Mar 2026 19:13:17 -0400 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-5091f12ed3bso2799461cf.3 for ; Thu, 19 Mar 2026 16:13:17 -0700 (PDT) Received: from x1.local ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-50b36e5bee3sm6717161cf.21.2026.03.19.16.13.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2026 16:13:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773961998; 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=V6xO5KlK8X7T9dIvIeNyHDMz8xdJ4Fx4esbGShwNklI=; b=ERHvpJO6R8gH/IGU3syxVwIV6V9dXEcQK0nUpahXXZEamHGPud2ZX5C2OgZeobClcuvHzv EC27HiZ3FmfXt13imxsPEbstgWHbl8oiUJiUM0ZQmGmEART4zKDtRnPBYfkdkCO/jnbOaD bn1uZfcVv4apvddVNuYv24uYC1GM/Xg= X-MC-Unique: Wow8rfqkMNmvIh2ID-IQqg-1 X-Mimecast-MFC-AGG-ID: Wow8rfqkMNmvIh2ID-IQqg_1773961997 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1773961996; x=1774566796; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=V6xO5KlK8X7T9dIvIeNyHDMz8xdJ4Fx4esbGShwNklI=; b=T8VWZgPP3Jg2xGqr64pvjvSgRHN8e8SO8d+bvKahPMogsFlAxyQoLp5EVrekLlxate z482gGOlMO72tCxu9EzlDYvAExu1vEu+V4KbuC7V4JqxaoYBah2WciyZ1R1ZVJACd4ra z3s4fgM4TMdPvEKqnEuj0ibotTBN4fmIKYxuALy6kCL8DQtFKrxJMdQM66gRi1QluuT3 GTEmXVdnwvZL3sCUbc2RpOui85pXxjKcrHINICPU1Y1LZJeBCTLiSVbW+/Gd6zQaCgfu fwiKxQ9rr3FKocqnhrxgnEK9Xi5RXHJrtYDNPK5Z0EAW7KoXtehFcmEZPjnC73wziT0F gZeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773961996; x=1774566796; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=V6xO5KlK8X7T9dIvIeNyHDMz8xdJ4Fx4esbGShwNklI=; b=AUkWDUukuqidwwsy9pJ+GhLmkn6V2oewQsDBHAsI27ZhCQI2gl+VWGG5nJyXT+2fo+ BJuy1vPmZqBH3uG+oiyHaLNiqm6+m1oB/jQl8mr5+bSLXI9F6gavnl7wRUNEMbrqh1+5 Ju8fqgWWxV9HqVio/JM4MeU4iA7bbysIFRYHAPk4L+kkF9yELWnS/7Igh+ipdFhu7WDK xNKQXr9ippOqRHejW5vzApDhV8tRA6iVT4HYJIMyjoiYJuCSWcfCXnFk/uoVKc3gTD8F be3ZRDJY/LPTV2XverPmfU4zhX3zeIKhlbOWJYHmGFI4vy8QunZ376emAkzMEMHQ/88U kc5w== X-Gm-Message-State: AOJu0YyHd86JmxBwDDhL0a0UJkyPr8T9PTVNNu+Ukbsk/wtLjgdKvKWk JQI3OKHfbd7GZYsRi/5D5SwZYnEJMikCFTUkAQ+xRirAkDybEMEwg69L2pE6bqEmyFCa8uOOTbJ Y0BGO7B572qIAs5clYJ9ZckX67M83ZldoZep4Y70QLFl8h8ZTGp2w8bGeCVqzBD3Z2k+fT0foJf yPt7uqrCXIYCamabYuqVnagzJRKYQgm4+7lvYHxg== X-Gm-Gg: ATEYQzwl/Od9ZLUZFnNev9UhmkZdIypqrl3nguW4/XeDZzWIp3xsI4U8pvzvtb3ZAPO g3TdsbPdUdgKsCZItjWfewYGpnQrle15H4zRZ4qWRKRjVgLkmdDq+tXspQHZolv1jLPLCpTksje eVAC0m2mJ19n/UcnR75n+ChaG0JBWw/AOiOkGNyEIHYUo0LIh45n/Ig9xxO6WT/87DBYXNS9OD4 x1SKJbQDu8+KcRUBXoJDvsMZDt1BUi893VrZnbD//kRwI+VdyWEE32P83hLmgd8V+arIzGS9Czv TjgYmI6WYAVBBxfTj8UQ4yRXZM9ujTAiGqjyGZQqZAEVSBvE+z2zUFQ+qiAl3/U3u5jJJV64bri xPxe9h4lf9yuH1g== X-Received: by 2002:a05:622a:178f:b0:509:bdb:1539 with SMTP id d75a77b69052e-50b3744891emr17086981cf.23.1773961996385; Thu, 19 Mar 2026 16:13:16 -0700 (PDT) X-Received: by 2002:a05:622a:178f:b0:509:bdb:1539 with SMTP id d75a77b69052e-50b3744891emr17086521cf.23.1773961995839; Thu, 19 Mar 2026 16:13:15 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juraj Marcin , Kirti Wankhede , "Maciej S . Szmigiero" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Joao Martins , Alex Williamson , Yishai Hadas , Fabiano Rosas , Pranav Tyagi , peterx@redhat.com, Zhiyi Guo , Markus Armbruster , Avihai Horon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH RFC 04/12] vfio/migration: Cache stop size in VFIOMigration Date: Thu, 19 Mar 2026 19:12:54 -0400 Message-ID: <20260319231302.123135-5-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260319231302.123135-1-peterx@redhat.com> References: <20260319231302.123135-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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: 1773962123376158501 Content-Type: text/plain; charset="utf-8" Add a field to cache stop size. Note that there's an initial value change in vfio_save_setup for the stop size default, but it shouldn't matter if it is followed with a math of MIN() against VFIO_MIG_DEFAULT_DATA_BUFFER_SIZE. Signed-off-by: Peter Xu --- hw/vfio/vfio-migration-internal.h | 1 + hw/vfio/migration.c | 43 +++++++++++++++++-------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/hw/vfio/vfio-migration-internal.h b/hw/vfio/vfio-migration-int= ernal.h index 814fbd9eba..08df32c055 100644 --- a/hw/vfio/vfio-migration-internal.h +++ b/hw/vfio/vfio-migration-internal.h @@ -47,6 +47,7 @@ typedef struct VFIOMigration { uint64_t mig_flags; uint64_t precopy_init_size; uint64_t precopy_dirty_size; + uint64_t stopcopy_size; bool multifd_transfer; VFIOMultifd *multifd; bool initial_data_sent; diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 851ea783f3..827d3ded63 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -41,6 +41,12 @@ */ #define VFIO_MIG_DEFAULT_DATA_BUFFER_SIZE (1 * MiB) =20 +/* + * Migration size of VFIO devices can be as little as a few KBs or as big = as + * many GBs. This value should be big enough to cover the worst case. + */ +#define VFIO_MIG_STOP_COPY_SIZE (100 * GiB) + static unsigned long bytes_transferred; =20 static const char *mig_state_to_str(enum vfio_device_mig_state state) @@ -314,8 +320,7 @@ static void vfio_migration_cleanup(VFIODevice *vbasedev) migration->data_fd =3D -1; } =20 -static int vfio_query_stop_copy_size(VFIODevice *vbasedev, - uint64_t *stop_copy_size) +static int vfio_query_stop_copy_size(VFIODevice *vbasedev) { uint64_t buf[DIV_ROUND_UP(sizeof(struct vfio_device_feature) + sizeof(struct vfio_device_feature_mig_data_s= ize), @@ -323,16 +328,22 @@ static int vfio_query_stop_copy_size(VFIODevice *vbas= edev, struct vfio_device_feature *feature =3D (struct vfio_device_feature *)= buf; struct vfio_device_feature_mig_data_size *mig_data_size =3D (struct vfio_device_feature_mig_data_size *)feature->data; + VFIOMigration *migration =3D vbasedev->migration; =20 feature->argsz =3D sizeof(buf); feature->flags =3D VFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_MIG_DATA_SIZE; =20 if (ioctl(vbasedev->fd, VFIO_DEVICE_FEATURE, feature)) { + /* + * If getting pending migration size fails, VFIO_MIG_STOP_COPY_SIZE + * is reported so downtime limit won't be violated. + */ + migration->stopcopy_size =3D VFIO_MIG_STOP_COPY_SIZE; return -errno; } =20 - *stop_copy_size =3D mig_data_size->stop_copy_length; + migration->stopcopy_size =3D mig_data_size->stop_copy_length; =20 return 0; } @@ -415,6 +426,9 @@ static void vfio_update_estimated_pending_data(VFIOMigr= ation *migration, return; } =20 + /* The total size remaining requires separate accounting */ + migration->stopcopy_size -=3D data_size; + if (migration->precopy_init_size) { uint64_t init_size =3D MIN(migration->precopy_init_size, data_size= ); =20 @@ -469,7 +483,6 @@ static int vfio_save_setup(QEMUFile *f, void *opaque, E= rror **errp) { VFIODevice *vbasedev =3D opaque; VFIOMigration *migration =3D vbasedev->migration; - uint64_t stop_copy_size =3D VFIO_MIG_DEFAULT_DATA_BUFFER_SIZE; int ret; =20 if (!vfio_multifd_setup(vbasedev, false, errp)) { @@ -478,9 +491,9 @@ static int vfio_save_setup(QEMUFile *f, void *opaque, E= rror **errp) =20 qemu_put_be64(f, VFIO_MIG_FLAG_DEV_SETUP_STATE); =20 - vfio_query_stop_copy_size(vbasedev, &stop_copy_size); + vfio_query_stop_copy_size(vbasedev); migration->data_buffer_size =3D MIN(VFIO_MIG_DEFAULT_DATA_BUFFER_SIZE, - stop_copy_size); + migration->stopcopy_size); migration->data_buffer =3D g_try_malloc0(migration->data_buffer_size); if (!migration->data_buffer) { error_setg(errp, "%s: Failed to allocate migration data buffer", @@ -576,32 +589,22 @@ static void vfio_state_pending_estimate(void *opaque,= uint64_t *must_precopy, migration->precopy_dirty_size); } =20 -/* - * Migration size of VFIO devices can be as little as a few KBs or as big = as - * many GBs. This value should be big enough to cover the worst case. - */ -#define VFIO_MIG_STOP_COPY_SIZE (100 * GiB) - static void vfio_state_pending_exact(void *opaque, uint64_t *must_precopy, uint64_t *can_postcopy) { VFIODevice *vbasedev =3D opaque; VFIOMigration *migration =3D vbasedev->migration; - uint64_t stop_copy_size =3D VFIO_MIG_STOP_COPY_SIZE; =20 - /* - * If getting pending migration size fails, VFIO_MIG_STOP_COPY_SIZE is - * reported so downtime limit won't be violated. - */ - vfio_query_stop_copy_size(vbasedev, &stop_copy_size); - *must_precopy +=3D stop_copy_size; + vfio_query_stop_copy_size(vbasedev); + *must_precopy +=3D migration->stopcopy_size; =20 if (vfio_device_state_is_precopy(vbasedev)) { vfio_query_precopy_size(migration); } =20 trace_vfio_state_pending_exact(vbasedev->name, *must_precopy, *can_pos= tcopy, - stop_copy_size, migration->precopy_init= _size, + migration->stopcopy_size, + migration->precopy_init_size, migration->precopy_dirty_size); } =20 --=20 2.50.1