Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
vfio/migration: Reset bytes_transferred properly
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: 3710586 ("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>
  • Loading branch information
avihai1122 authored and legoater committed Jun 30, 2023
1 parent c174088 commit 808642a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
6 changes: 5 additions & 1 deletion hw/vfio/migration.c
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions include/hw/vfio/vfio-common.h
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions migration/migration.c
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions migration/migration.h
Expand Up @@ -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
1 change: 1 addition & 0 deletions migration/savevm.c
Expand Up @@ -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();
Expand Down
17 changes: 15 additions & 2 deletions migration/target.c
Expand Up @@ -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

0 comments on commit 808642a

Please sign in to comment.