From: "Cédric Le Goater" <clg@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
"Alex Williamson" <alex.williamson@redhat.com>,
"Avihai Horon" <avihaih@nvidia.com>,
"Cédric Le Goater" <clg@redhat.com>
Subject: [PULL 12/16] vfio/migration: Reset bytes_transferred properly
Date: Fri, 30 Jun 2023 07:22:31 +0200 [thread overview]
Message-ID: <20230630052235.1934154-13-clg@redhat.com> (raw)
In-Reply-To: <20230630052235.1934154-1-clg@redhat.com>
From: Avihai Horon <avihaih@nvidia.com>
Currently, VFIO bytes_transferred is not reset properly:
1. bytes_transferred is not reset after a VM snapshot (so a migration
following a snapshot will report incorrect value).
2. bytes_transferred is a single counter for all VFIO devices, however
upon migration failure it is reset multiple times, by each VFIO
device.
Fix it by introducing a new function vfio_reset_bytes_transferred() and
calling it during migration and snapshot start.
Remove existing bytes_transferred reset in VFIO migration state
notifier, which is not needed anymore.
Fixes: 3710586caa5d ("qapi: Add VFIO devices migration stats in Migration stats")
Signed-off-by: Avihai Horon <avihaih@nvidia.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
include/hw/vfio/vfio-common.h | 1 +
migration/migration.h | 1 +
hw/vfio/migration.c | 6 +++++-
migration/migration.c | 1 +
migration/savevm.c | 1 +
migration/target.c | 17 +++++++++++++++--
6 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 6d1b8487c374..1d19c6f251c1 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -229,6 +229,7 @@ int vfio_block_multiple_devices_migration(Error **errp);
void vfio_unblock_multiple_devices_migration(void);
int vfio_block_giommu_migration(Error **errp);
int64_t vfio_mig_bytes_transferred(void);
+void vfio_reset_bytes_transferred(void);
#ifdef CONFIG_LINUX
int vfio_get_region_info(VFIODevice *vbasedev, int index,
diff --git a/migration/migration.h b/migration/migration.h
index c859a0d35eb7..a80b22b703cd 100644
--- a/migration/migration.h
+++ b/migration/migration.h
@@ -514,6 +514,7 @@ bool migration_rate_limit(void);
void migration_cancel(const Error *error);
void populate_vfio_info(MigrationInfo *info);
+void reset_vfio_bytes_transferred(void);
void postcopy_temp_page_reset(PostcopyTmpPage *tmp_page);
#endif
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index acbf0bb7ab3c..7cf143926ce9 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -697,7 +697,6 @@ static void vfio_migration_state_notifier(Notifier *notifier, void *data)
case MIGRATION_STATUS_CANCELLING:
case MIGRATION_STATUS_CANCELLED:
case MIGRATION_STATUS_FAILED:
- bytes_transferred = 0;
/*
* If setting the device in RUNNING state fails, the device should
* be reset. To do so, use ERROR state as a recover state.
@@ -818,6 +817,11 @@ int64_t vfio_mig_bytes_transferred(void)
return bytes_transferred;
}
+void vfio_reset_bytes_transferred(void)
+{
+ bytes_transferred = 0;
+}
+
int vfio_migration_realize(VFIODevice *vbasedev, Error **errp)
{
int ret = -ENOTSUP;
diff --git a/migration/migration.c b/migration/migration.c
index 7653787f745d..096e8191d15c 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1628,6 +1628,7 @@ static bool migrate_prepare(MigrationState *s, bool blk, bool blk_inc,
*/
memset(&mig_stats, 0, sizeof(mig_stats));
memset(&compression_counters, 0, sizeof(compression_counters));
+ reset_vfio_bytes_transferred();
return true;
}
diff --git a/migration/savevm.c b/migration/savevm.c
index cdf47939244d..95c2abf47c10 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -1622,6 +1622,7 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
migrate_init(ms);
memset(&mig_stats, 0, sizeof(mig_stats));
memset(&compression_counters, 0, sizeof(compression_counters));
+ reset_vfio_bytes_transferred();
ms->to_dst_file = f;
qemu_mutex_unlock_iothread();
diff --git a/migration/target.c b/migration/target.c
index 00ca007f9784..f39c9a8d8877 100644
--- a/migration/target.c
+++ b/migration/target.c
@@ -14,12 +14,25 @@
#include "hw/vfio/vfio-common.h"
#endif
+#ifdef CONFIG_VFIO
void populate_vfio_info(MigrationInfo *info)
{
-#ifdef CONFIG_VFIO
if (vfio_mig_active()) {
info->vfio = g_malloc0(sizeof(*info->vfio));
info->vfio->transferred = vfio_mig_bytes_transferred();
}
-#endif
}
+
+void reset_vfio_bytes_transferred(void)
+{
+ vfio_reset_bytes_transferred();
+}
+#else
+void populate_vfio_info(MigrationInfo *info)
+{
+}
+
+void reset_vfio_bytes_transferred(void)
+{
+}
+#endif
--
2.41.0
next prev parent reply other threads:[~2023-06-30 5:29 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-30 5:22 [PULL 00/16] vfio queue Cédric Le Goater
2023-06-30 5:22 ` [PULL 01/16] migration: Add switchover ack capability Cédric Le Goater
2023-06-30 5:22 ` [PULL 02/16] migration: Implement switchover ack logic Cédric Le Goater
2023-06-30 5:22 ` [PULL 03/16] migration: Enable switchover ack capability Cédric Le Goater
2023-06-30 5:22 ` [PULL 04/16] tests: Add migration switchover ack capability test Cédric Le Goater
2023-06-30 5:22 ` [PULL 05/16] vfio/migration: Refactor vfio_save_block() to return saved data size Cédric Le Goater
2023-06-30 5:22 ` [PULL 06/16] vfio/migration: Store VFIO migration flags in VFIOMigration Cédric Le Goater
2023-06-30 5:22 ` [PULL 07/16] vfio/migration: Add VFIO migration pre-copy support Cédric Le Goater
2023-06-30 5:22 ` [PULL 08/16] vfio/migration: Add support for switchover ack capability Cédric Le Goater
2023-06-30 5:22 ` [PULL 09/16] vfio: Implement a common device info helper Cédric Le Goater
2023-06-30 5:22 ` [PULL 10/16] hw/vfio/pci-quirks: Support alternate offset for GPUDirect Cliques Cédric Le Goater
2023-06-30 5:22 ` [PULL 11/16] vfio/pci: Call vfio_prepare_kvm_msi_virq_batch() in MSI retry path Cédric Le Goater
2023-06-30 15:59 ` Michael Tokarev
2023-06-30 5:22 ` Cédric Le Goater [this message]
2023-06-30 5:22 ` [PULL 13/16] vfio/migration: Make VFIO migration non-experimental Cédric Le Goater
2023-06-30 5:22 ` [PULL 14/16] MAINTAINERS: Promote Cédric to VFIO co-maintainer Cédric Le Goater
2023-06-30 5:22 ` [PULL 15/16] vfio/pci: Fix a segfault in vfio_realize Cédric Le Goater
2023-06-30 5:22 ` [PULL 16/16] vfio/pci: Free leaked timer in vfio_realize error path Cédric Le Goater
2023-06-30 9:55 ` [PULL 00/16] vfio queue Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230630052235.1934154-13-clg@redhat.com \
--to=clg@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=avihaih@nvidia.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).