vfio/migration: Fix return value of vfio_migration_realize()
PATCH 1/1 vfio/migration: Fix return value of vfio_migration_realize()
We should print "Migration disabled" when migration is blocked in vfio_migration_realize().
Fix it by reverting return value of migrate_add_blocker(), meanwhile error out directly once migrate_add_blocker() failed.
--- hw/vfio/common.c | 4 ++-- hw/vfio/migration.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)
hw/vfio/common.c +2 -2
@@ -399,7 +399,7 @@ int vfio_block_multiple_devices_migration(Error **errp) multiple_devices_migration_blocker =NULL ; } -return ret; +return !ret; }void vfio_unblock_multiple_devices_migration (void )
@@ -444,7 +444,7 @@ int vfio_block_giommu_migration(Error **errp) giommu_migration_blocker =NULL ; } -return ret; +return !ret; }void vfio_migration_finalize (void )
hw/vfio/migration.c +3 -3
@@ -646,12 +646,12 @@ int vfio_migration_realize(VFIODevice *vbasedev, Error **errp) } ret =vfio_block_multiple_devices_migration (errp); -if (ret) { +if (ret || (errp && *errp)) {return ret; } ret =vfio_block_giommu_migration (errp); -if (ret) { +if (ret || (errp && *errp)) {return ret; }
@@ -667,7 +667,7 @@ add_blocker:error_free (vbasedev->migration_blocker); vbasedev->migration_blocker =NULL ; } -return ret; +return !ret; }void vfio_migration_exit (VFIODevice *vbasedev)
Signature · 1 line
2.34.1
Quoted 6 lines · Zhenzhong Duan
We should print "Migration disabled" when migration is blocked in
vfio_migration_realize().Fix it by reverting return value of
migrate_add_blocker(), meanwhile error out directly oncemigrate_add_blocker()failed.
It wasn't immediately obvious from commit message that this is mainly about just printing an error message when blockers get added and that well migrate_add_blocker() returns 0 on success and caller of vfio_migration_realize expects the opposite when blockers are added.
Perhaps better wording would be:
migrate_add_blocker() returns 0 when successfully adding the migration blocker. However, the caller of vfio_migration_realize() considers that migration was blocked when the latter returned an error. Fix it by negating the return value obtained by migrate_add_blocker(). What matters for migration is that the blocker is added in core migration, so this cleans up usability such that user sees "Migrate disabled" when any of the vfio migration blockers are active.
Quoted 33 lines
Signed-off-by Zhenzhong Duan <[email protected]>--- hw/vfio/common.c | 4 ++-- hw/vfio/migration.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)hw/vfio/common.c +2
-2@@ -399,7 +399,7 @@ int vfio_block_multiple_devices_migration(Error **errp) multiple_devices_migration_blocker =NULL ; } -return ret; +return !ret; }void vfio_unblock_multiple_devices_migration (void )@@ -444,7 +444,7 @@ int vfio_block_giommu_migration(Error **errp) giommu_migration_blocker =NULL ; } -return ret; +return !ret; }void vfio_migration_finalize (void )hw/vfio/migration.c +0
-0
hw/vfio/migration.c int vfio_migration_realize(VFIODevice *vbasedev, Error **errp) · line 649
Quoted 5 lines
hw/vfio/migration.c +1
-1@@ -646,12 +646,12 @@ int vfio_migration_realize(VFIODevice *vbasedev, Error **errp) } ret =vfio_block_multiple_devices_migration (errp); -if (ret) { +if (ret || (errp && *errp)) {
Why do you need this extra clause?
hw/vfio/migration.c int vfio_migration_realize(VFIODevice *vbasedev, Error **errp) · line 654
Quoted 6 lines
hw/vfio/migration.c +1
-1return ret; } ret =vfio_block_giommu_migration (errp); -if (ret) { +if (ret || (errp && *errp)) {
Same here?
Quoted 12 lines
hw/vfio/migration.c +1
-1return ret; }@@ -667,7 +667,7 @@ add_blocker:error_free (vbasedev->migration_blocker); vbasedev->migration_blocker =NULL ; } -return ret; +return !ret; }void vfio_migration_exit (VFIODevice *vbasedev)
Quoted 27 lines
-----Original Message-----
From: Joao Martins <[email protected]>
Sent: Thursday, June 15, 2023 4:54 PM
To: Duan, Zhenzhong <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Peng, Chao P <[email protected]>
Subject: Re: [PATCH] vfio/migration: Fix return value ofvfio_migration_realize()Quoted 6 lines · Zhenzhong Duan
We should print "Migration disabled" when migration is blocked in
vfio_migration_realize().Fix it by reverting return value of
migrate_add_blocker(), meanwhile error out directly oncemigrate_add_blocker()failed.It wasn't immediately obvious from commit message that this is mainly about just printing an error message when blockers get added and that well
migrate_add_blocker()returns 0 on success and caller ofvfio_migration_realizeexpects the opposite when blockers are added.Perhaps better wording would be:
Quoted 7 lines
migrate_add_blocker()returns 0 when successfully adding the migration blocker. However, the caller ofvfio_migration_realize()considers that migration was blocked when the latter returned an error. Fix it by negating the return value obtained bymigrate_add_blocker(). What matters for migration is that the blocker is added in core migration, so this cleans up usability such that user sees "Migrate disabled" when any of the vfio migration blockers are active.
Great, I'll use your words.
Quoted 36 lines
hw/vfio/common.c int vfio_block_multiple_devices_migration(Error
Quoted 12 lines
Signed-off-by Zhenzhong Duan <[email protected]>--- hw/vfio/common.c | 4 ++-- hw/vfio/migration.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)hw/vfio/common.c index renamed from hw/vfio/common.c +0
-0
fa8fd949b1cf..8505385798f3100644hw/vfio/common.c +0
-0@@ -399,7 +399,7 @@ int vfio_block_multiple_devices_migration(Error**errp)
hw/vfio/migration.c int vfio_migration_realize(VFIODevice *vbasedev,
Quoted 22 lines
hw/vfio/common.c +2
-2multiple_devices_migration_blocker =NULL ; } -return ret; +return !ret; }void vfio_unblock_multiple_devices_migration (void )@@ -444,7 +444,7 @@ int vfio_block_giommu_migration(Error **errp) giommu_migration_blocker =NULL ; } -return ret; +return !ret; }void vfio_migration_finalize (void )hw/vfio/migration.c index renamed from hw/vfio/migration.c +0
-0
6b58dddb8859..0146521d129a100644hw/vfio/migration.c +0
-0@@ -646,12 +646,12 @@ int vfio_migration_realize(VFIODevice *vbasedev,Error **errp)
Quoted 7 lines
hw/vfio/migration.c int vfio_migration_realize(VFIODevice *vbasedev, Error **errp) · line 649
Quoted 5 lines
hw/vfio/migration.c +1
-1} ret =vfio_block_multiple_devices_migration (errp); -if (ret) { +if (ret || (errp && *errp)) {Why do you need this extra clause?
Now that error happens, no need to add other blockers which will fail for same reason.
Quoted 9 lines
hw/vfio/migration.c int vfio_migration_realize(VFIODevice *vbasedev, Error **errp) · line 654
Quoted 7 lines
hw/vfio/migration.c +1
-1return ret; } ret =vfio_block_giommu_migration (errp); -if (ret) { +if (ret || (errp && *errp)) {Same here?
To avoid calling into trace_vfio_migration_probe() which hints vfio migration realize succeed.
Thanks
Zhenzhong
Quoted 13 lines
Quoted 13 lines
hw/vfio/migration.c +1
-1return ret; }@@ -667,7 +667,7 @@ add_blocker:error_free (vbasedev->migration_blocker); vbasedev->migration_blocker =NULL ; } -return ret; +return !ret; }void vfio_migration_exit (VFIODevice *vbasedev)
Quoted 73 lines · Zhenzhong
Quoted 25 lines
-----Original Message-----
From: Joao Martins <[email protected]>
Sent: Thursday, June 15, 2023 4:54 PM
To: Duan, Zhenzhong <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Peng, Chao P <[email protected]>
Subject: Re: [PATCH] vfio/migration: Fix return value ofvfio_migration_realize()Quoted 6 lines · Zhenzhong Duan
We should print "Migration disabled" when migration is blocked in
vfio_migration_realize().Fix it by reverting return value of
migrate_add_blocker(), meanwhile error out directly oncemigrate_add_blocker()failed.It wasn't immediately obvious from commit message that this is mainly about just printing an error message when blockers get added and that well
migrate_add_blocker()returns 0 on success and caller ofvfio_migration_realizeexpects the opposite when blockers are added.Perhaps better wording would be:
Quoted 7 lines
migrate_add_blocker()returns 0 when successfully adding the migration blocker. However, the caller ofvfio_migration_realize()considers that migration was blocked when the latter returned an error. Fix it by negating the return value obtained bymigrate_add_blocker(). What matters for migration is that the blocker is added in core migration, so this cleans up usability such that user sees "Migrate disabled" when any of the vfio migration blockers are active.Great, I'll use your words.
Quoted 38 lines
hw/vfio/common.c int vfio_block_multiple_devices_migration(Error
Quoted 12 lines
Signed-off-by Zhenzhong Duan <[email protected]>--- hw/vfio/common.c | 4 ++-- hw/vfio/migration.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)hw/vfio/common.c index renamed from hw/vfio/common.c +0
-0
fa8fd949b1cf..8505385798f3100644hw/vfio/common.c +0
-0@@ -399,7 +399,7 @@ int vfio_block_multiple_devices_migration(Error**errp)
hw/vfio/migration.c int vfio_migration_realize(VFIODevice *vbasedev,
Quoted 22 lines
hw/vfio/common.c +2
-2multiple_devices_migration_blocker =NULL ; } -return ret; +return !ret; }void vfio_unblock_multiple_devices_migration (void )@@ -444,7 +444,7 @@ int vfio_block_giommu_migration(Error **errp) giommu_migration_blocker =NULL ; } -return ret; +return !ret; }void vfio_migration_finalize (void )hw/vfio/migration.c index renamed from hw/vfio/migration.c +0
-0
6b58dddb8859..0146521d129a100644hw/vfio/migration.c +0
-0@@ -646,12 +646,12 @@ int vfio_migration_realize(VFIODevice *vbasedev,Error **errp)
Quoted 2 lines
hw/vfio/migration.c +0
-0}
Quoted 9 lines
Quoted 5 lines
hw/vfio/migration.c int vfio_migration_realize(VFIODevice *vbasedev, Error **errp) · line 649
Quoted 3 lines
hw/vfio/migration.c +1
-1ret =vfio_block_multiple_devices_migration (errp); -if (ret) { +if (ret || (errp && *errp)) {Why do you need this extra clause?
Now that error happens, no need to add other blockers which will fail for same reason.
But you don't need the (errp && *errp) for that as that's the whole point of negating the result.
And if there's an error set it means migrate_add_blocker failed to add the blocker (e.g. snapshotting IIUC), and you would be failing here unnecessarily?
Still it feels strange to use the error pointer to check for that, it's better to return error appropriately.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hw/vfio/migration.c +0
-0return ret; }
Quoted 8 lines
Quoted 5 lines
hw/vfio/migration.c int vfio_migration_realize(VFIODevice *vbasedev, Error **errp) · line 654
Quoted 3 lines
hw/vfio/migration.c +1
-1ret =vfio_block_giommu_migration (errp); -if (ret) { +if (ret || (errp && *errp)) {Same here?
To avoid calling into
trace_vfio_migration_probe()which hints vfio migration realize succeed.
That was clear, my question was more related to second clause you are adding..
Quoted 16 lines
Thanks
ZhenzhongQuoted 13 lines
Quoted 13 lines
hw/vfio/migration.c +1
-1return ret; }@@ -667,7 +667,7 @@ add_blocker:error_free (vbasedev->migration_blocker); vbasedev->migration_blocker =NULL ; } -return ret; +return !ret; }void vfio_migration_exit (VFIODevice *vbasedev)
Quoted 96 lines
-----Original Message-----
From: Joao Martins <[email protected]>
Sent: Thursday, June 15, 2023 6:23 PM
To: Duan, Zhenzhong <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Peng, Chao P <[email protected]>
Subject: Re: [PATCH] vfio/migration: Fix return value ofvfio_migration_realize()Quoted 27 lines · Zhenzhong
Quoted 27 lines
-----Original Message-----
From: Joao Martins <[email protected]>
Sent: Thursday, June 15, 2023 4:54 PM
To: Duan, Zhenzhong <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Peng, Chao P <[email protected]>
Subject: Re: [PATCH] vfio/migration: Fix return value ofvfio_migration_realize()Quoted 6 lines · Zhenzhong Duan
We should print "Migration disabled" when migration is blocked in
vfio_migration_realize().Fix it by reverting return value of
migrate_add_blocker(), meanwhile error out directly oncemigrate_add_blocker()failed.It wasn't immediately obvious from commit message that this is mainly about just printing an error message when blockers get added and that well
migrate_add_blocker()returns 0 on success and caller ofvfio_migration_realizeexpects the opposite when blockers are added.Perhaps better wording would be:
Quoted 7 lines
Quoted 7 lines
migrate_add_blocker()returns 0 when successfully adding the migration blocker. However, the caller ofvfio_migration_realize()considers that migration was blocked when the latter returned an error. Fix it by negating the return value obtained bymigrate_add_blocker(). What matters for migration is that the blocker is added in core migration, so this cleans up usability such that user sees "Migrate disabled" when any of the vfio migration blockers areactive.
Quoted 42 lines
Great, I'll use your words.
Quoted 39 lines
hw/vfio/common.c int vfio_block_multiple_devices_migration(Error
Quoted 12 lines
Signed-off-by Zhenzhong Duan <[email protected]>--- hw/vfio/common.c | 4 ++-- hw/vfio/migration.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)hw/vfio/common.c index renamed from hw/vfio/common.c +0
-0
fa8fd949b1cf..8505385798f3100644hw/vfio/common.c +0
-0@@ -399,7 +399,7 @@ int vfio_block_multiple_devices_migration(Error**errp)
Quoted 22 lines
hw/vfio/common.c +2
-2multiple_devices_migration_blocker =NULL ; } -return ret; +return !ret; }void vfio_unblock_multiple_devices_migration (void )@@ -444,7 +444,7 @@ int vfio_block_giommu_migration(Error **errp) giommu_migration_blocker =NULL ; } -return ret; +return !ret; }void vfio_migration_finalize (void )hw/vfio/migration.c index renamed from hw/vfio/migration.c +0
-0
6b58dddb8859..0146521d129a100644hw/vfio/migration.c int vfio_migration_realize(VFIODevice · line 646
Quoted 1 line
hw/vfio/migration.c +0
-0@@ -646,12 +646,12 @@ int vfio_migration_realize(VFIODevice *vbasedev,Error **errp)
Quoted 2 lines
hw/vfio/migration.c +0
-0}Quoted 9 lines
Quoted 5 lines
hw/vfio/migration.c int vfio_migration_realize(VFIODevice *vbasedev, Error **errp) · line 649
Quoted 3 lines
hw/vfio/migration.c +1
-1ret =vfio_block_multiple_devices_migration (errp); -if (ret) { +if (ret || (errp && *errp)) {Why do you need this extra clause?
Now that error happens, no need to add other blockers which will fail for same reason.
Quoted 5 lines
But you don't need the (errp && *errp) for that as that's the whole point of negating the result.
And if there's an error set it means
migrate_add_blockerfailed to add the blocker (e.g. snapshotting IIUC), and you would be failing here unnecessarily?
If there is an error qdev_device_add() will fail, continue execution is meaningless here? There is ERRP_GUARD in this path, so it looks (*errp) is enough.
If I removed (errp && *errp) to continue, need below change to bypass trace_vfio_migration_probe Do you prefer this way?
if (!*errp) {
trace_vfio_migration_probe(vbasedev->name);
}Thanks
Zhenzhong
Quoted 37 lines
Still it feels strange to use the error pointer to check for that, it's better to return error appropriately.
Quoted 11 lines
Quoted 9 lines
hw/vfio/migration.c int vfio_migration_realize(VFIODevice *vbasedev, Error **errp) · line 654
Quoted 7 lines
hw/vfio/migration.c +1
-1return ret; } ret =vfio_block_giommu_migration (errp); -if (ret) { +if (ret || (errp && *errp)) {Same here?
To avoid calling into
trace_vfio_migration_probe()which hints vfio migrationrealize succeed.
Quoted 1 line
That was clear, my question was more related to second clause you are adding..
Quoted 16 lines
Thanks
ZhenzhongQuoted 13 lines
Quoted 13 lines
hw/vfio/migration.c +1
-1return ret; }@@ -667,7 +667,7 @@ add_blocker:error_free (vbasedev->migration_blocker); vbasedev->migration_blocker =NULL ; } -return ret; +return !ret; }void vfio_migration_exit (VFIODevice *vbasedev)
Quoted 105 lines · Zhenzhong
Quoted 96 lines
-----Original Message-----
From: Joao Martins <[email protected]>
Sent: Thursday, June 15, 2023 6:23 PM
To: Duan, Zhenzhong <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Peng, Chao P <[email protected]>
Subject: Re: [PATCH] vfio/migration: Fix return value ofvfio_migration_realize()Quoted 27 lines · Zhenzhong
Quoted 27 lines
-----Original Message-----
From: Joao Martins <[email protected]>
Sent: Thursday, June 15, 2023 4:54 PM
To: Duan, Zhenzhong <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Peng, Chao P <[email protected]>
Subject: Re: [PATCH] vfio/migration: Fix return value ofvfio_migration_realize()Quoted 6 lines · Zhenzhong Duan
We should print "Migration disabled" when migration is blocked in
vfio_migration_realize().Fix it by reverting return value of
migrate_add_blocker(), meanwhile error out directly oncemigrate_add_blocker()failed.It wasn't immediately obvious from commit message that this is mainly about just printing an error message when blockers get added and that well
migrate_add_blocker()returns 0 on success and caller ofvfio_migration_realizeexpects the opposite when blockers are added.Perhaps better wording would be:
Quoted 7 lines
Quoted 7 lines
migrate_add_blocker()returns 0 when successfully adding the migration blocker. However, the caller ofvfio_migration_realize()considers that migration was blocked when the latter returned an error. Fix it by negating the return value obtained bymigrate_add_blocker(). What matters for migration is that the blocker is added in core migration, so this cleans up usability such that user sees "Migrate disabled" when any of the vfio migration blockers areactive.
Quoted 42 lines
Great, I'll use your words.
Quoted 39 lines
hw/vfio/common.c int vfio_block_multiple_devices_migration(Error
Quoted 12 lines
Signed-off-by Zhenzhong Duan <[email protected]>--- hw/vfio/common.c | 4 ++-- hw/vfio/migration.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)hw/vfio/common.c index renamed from hw/vfio/common.c +0
-0
fa8fd949b1cf..8505385798f3100644hw/vfio/common.c +0
-0@@ -399,7 +399,7 @@ int vfio_block_multiple_devices_migration(Error**errp)
Quoted 22 lines
hw/vfio/common.c +2
-2multiple_devices_migration_blocker =NULL ; } -return ret; +return !ret; }void vfio_unblock_multiple_devices_migration (void )@@ -444,7 +444,7 @@ int vfio_block_giommu_migration(Error **errp) giommu_migration_blocker =NULL ; } -return ret; +return !ret; }void vfio_migration_finalize (void )hw/vfio/migration.c index renamed from hw/vfio/migration.c +0
-0
6b58dddb8859..0146521d129a100644hw/vfio/migration.c int vfio_migration_realize(VFIODevice · line 646
Quoted 1 line
hw/vfio/migration.c +0
-0@@ -646,12 +646,12 @@ int vfio_migration_realize(VFIODevice *vbasedev,Error **errp)
Quoted 2 lines
hw/vfio/migration.c +0
-0}Quoted 9 lines
Quoted 5 lines
hw/vfio/migration.c int vfio_migration_realize(VFIODevice *vbasedev, Error **errp) · line 649
Quoted 3 lines
hw/vfio/migration.c +1
-1ret =vfio_block_multiple_devices_migration (errp); -if (ret) { +if (ret || (errp && *errp)) {Why do you need this extra clause?
Now that error happens, no need to add other blockers which will fail for same reason.
Quoted 5 lines
But you don't need the (errp && *errp) for that as that's the whole point of negating the result.
And if there's an error set it means
migrate_add_blockerfailed to add the blocker (e.g. snapshotting IIUC), and you would be failing here unnecessarily?If there is an error
qdev_device_add()will fail, continue execution is meaningless here? There isERRP_GUARDin this path, so it looks (*errp) is enough.
Quoted 7 lines
If I removed (errp && *errp) to continue, need below change to bypass
trace_vfio_migration_probeDo you prefer this way?if (!*errp) { trace_vfio_migration_probe(vbasedev->name); }
I am mainly questioning that the error testing is correct to test here.
IIUC, the only one that can propagate any *new* error in vfio_migration_realize is the calls to migrate_add_blocker failing within the vfio_block* (migration code suggests that this happens on snapshotting). Failing to add migration blocker just means we haven't installed any blockers. And the current code presents that as a "Migration disabled" case. If we want to preserve that behaviour on migration_add_blocker() failures (which seems like that's what you are doing here) then instead of this:
return !ret;
you would do this:
ret = migration_add_blocker(...);
if (ret < 0) {
error_free(...);
blocker = NULL;
+ return ret;
}+ return 1;
Or something like that. And then if you return early as you intended?
Quoted 131 lines
-----Original Message-----
From: Joao Martins <[email protected]>
Sent: Friday, June 16, 2023 5:06 PM
To: Duan, Zhenzhong <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Peng, Chao P <[email protected]>
Subject: Re: [PATCH] vfio/migration: Fix return value ofvfio_migration_realize()Quoted 99 lines · Zhenzhong
Quoted 99 lines
-----Original Message-----
From: Joao Martins <[email protected]>
Sent: Thursday, June 15, 2023 6:23 PM
To: Duan, Zhenzhong <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Peng, Chao P <[email protected]>
Subject: Re: [PATCH] vfio/migration: Fix return value ofvfio_migration_realize()Quoted 27 lines · Zhenzhong
Quoted 27 lines
-----Original Message-----
From: Joao Martins <[email protected]>
Sent: Thursday, June 15, 2023 4:54 PM
To: Duan, Zhenzhong <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Peng, Chao P <[email protected]>
Subject: Re: [PATCH] vfio/migration: Fix return value ofvfio_migration_realize()Quoted 6 lines · Zhenzhong Duan
We should print "Migration disabled" when migration is blocked in
vfio_migration_realize().Fix it by reverting return value of
migrate_add_blocker(), meanwhile error out directly oncemigrate_add_blocker()failed.It wasn't immediately obvious from commit message that this is mainly about just printing an error message when blockers get added and that well
migrate_add_blocker()returns 0 on success and caller ofvfio_migration_realizeexpects the opposite when blockers are added.Perhaps better wording would be:
Quoted 8 lines
Quoted 8 lines
migrate_add_blocker()returns 0 when successfully adding the migration blocker. However, the caller ofvfio_migration_realize()considers that migration was blocked when the latter returned an error. Fix it by negating the return value obtained bymigrate_add_blocker(). What matters for migration is that the blocker is added in core migration, so this cleans up usability such that user sees "Migrate disabled" when any of the vfio migration blockers areactive.
Quoted 52 lines
Great, I'll use your words.
Quoted 38 lines
Quoted 12 lines
Signed-off-by Zhenzhong Duan <[email protected]>--- hw/vfio/common.c | 4 ++-- hw/vfio/migration.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)hw/vfio/common.c index renamed from hw/vfio/common.c +0
-0
fa8fd949b1cf..8505385798f3100644hw/vfio/common.c +0
-0@@ -399,7 +399,7 @@ intQuoted 1 line
vfio_block_multiple_devices_migration(Error
**errp)
Quoted 22 lines
multiple_devices_migration_blocker = NULL; }hw/vfio/common.c +2
-2-return ret; +return !ret; }void vfio_unblock_multiple_devices_migration (void )@@ -444,7 +444,7 @@ int vfio_block_giommu_migration(Error **errp) giommu_migration_blocker =NULL ; } -return ret; +return !ret; } void vfio_migration_finalize(void) diff --git
a/hw/vfio/migration.cb/hw/vfio/migration.cindex6b58dddb8859..0146521d129a100644hw/vfio/migration.c int vfio_migration_realize(VFIODevice · line 646
Quoted 1 line
hw/vfio/migration.c +0
-0@@ -646,12 +646,12 @@ int vfio_migration_realize(VFIODevice *vbasedev,Error **errp)
Quoted 7 lines
hw/vfio/migration.c int vfio_migration_realize(VFIODevice *vbasedev, Error **errp) · line 649
Quoted 5 lines
hw/vfio/migration.c +1
-1} ret =vfio_block_multiple_devices_migration (errp); -if (ret) { +if (ret || (errp && *errp)) {Why do you need this extra clause?
Now that error happens, no need to add other blockers which will fail for same reason.
Quoted 5 lines
Quoted 5 lines
But you don't need the (errp && *errp) for that as that's the whole point of negating the result.
And if there's an error set it means
migrate_add_blockerfailed to add the blocker (e.g. snapshotting IIUC), and you would be failing hereunnecessarily?
Quoted 2 lines
If there is an error
qdev_device_add()will fail, continue execution ismeaningless here?
Quoted 9 lines
There is
ERRP_GUARDin this path, so it looks (*errp) is enough.If I removed (errp && *errp) to continue, need below change to bypass
trace_vfio_migration_probeDo you prefer this way?if (!*errp) { trace_vfio_migration_probe(vbasedev->name); }I am mainly questioning that the error testing is correct to test here.
Quoted 7 lines
IIUC, the only one that can propagate any *new* error in
vfio_migration_realizeis the calls tomigrate_add_blockerfailing within the vfio_block* (migration code suggests that this happens on snapshotting). Failing to add migration blocker just means we haven't installed any blockers. And the current code presents that as a "Migration disabled" case. If we want to preserve that behaviour onmigration_add_blocker()failures (which seems like that's what you are doing here) then instead of this:
Current behavior(without my patch):
"Migration disabled" isn't printed if migrate_add_blocker succeed. "Migration disabled" is printed if migrate_add_blocker fail.
I think this behavior isn't correct, I want to revert it not preserve it, so I used !ret. Imagine we hotplug a vfio device when snapshotting, migrate_add_blocker failure will lead to hotplug fail, then the guest is still migratable as no vfio plugged. But we see "Migration disabled" which will confuse us.
Quoted 14 lines
return !ret;you would do this:
ret = migration_add_blocker(...); if (ret < 0) { error_free(...); blocker = NULL;(quoted diff) +1
-0+ return ret;}(quoted diff) +1
-0+ return 1;
Quoted 1 line
Or something like that. And then if you return early as you intended?
Yes, this change make sense, I also want to add below:
if (!pdev->failover_pair_id) {
ret = vfio_migration_realize(vbasedev, errp);
- if (ret) {
+ if (ret > 0) {
error_report("%s: Migration disabled", vbasedev->name);
}Thanks
Zhenzhong
Quoted 137 lines · Zhenzhong
Quoted 129 lines
-----Original Message-----
From: Joao Martins <[email protected]>
Sent: Friday, June 16, 2023 5:06 PM
To: Duan, Zhenzhong <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Peng, Chao P <[email protected]>
Subject: Re: [PATCH] vfio/migration: Fix return value ofvfio_migration_realize()Quoted 99 lines · Zhenzhong
Quoted 99 lines
-----Original Message-----
From: Joao Martins <[email protected]>
Sent: Thursday, June 15, 2023 6:23 PM
To: Duan, Zhenzhong <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Peng, Chao P <[email protected]>
Subject: Re: [PATCH] vfio/migration: Fix return value ofvfio_migration_realize()Quoted 27 lines · Zhenzhong
Quoted 27 lines
-----Original Message-----
From: Joao Martins <[email protected]>
Sent: Thursday, June 15, 2023 4:54 PM
To: Duan, Zhenzhong <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Peng, Chao P <[email protected]>
Subject: Re: [PATCH] vfio/migration: Fix return value ofvfio_migration_realize()Quoted 6 lines · Zhenzhong Duan
We should print "Migration disabled" when migration is blocked in
vfio_migration_realize().Fix it by reverting return value of
migrate_add_blocker(), meanwhile error out directly oncemigrate_add_blocker()failed.It wasn't immediately obvious from commit message that this is mainly about just printing an error message when blockers get added and that well
migrate_add_blocker()returns 0 on success and caller ofvfio_migration_realizeexpects the opposite when blockers are added.Perhaps better wording would be:
Quoted 8 lines
Quoted 8 lines
migrate_add_blocker()returns 0 when successfully adding the migration blocker. However, the caller ofvfio_migration_realize()considers that migration was blocked when the latter returned an error. Fix it by negating the return value obtained bymigrate_add_blocker(). What matters for migration is that the blocker is added in core migration, so this cleans up usability such that user sees "Migrate disabled" when any of the vfio migration blockers areactive.
Quoted 52 lines
Great, I'll use your words.
Quoted 38 lines
Quoted 12 lines
Signed-off-by Zhenzhong Duan <[email protected]>--- hw/vfio/common.c | 4 ++-- hw/vfio/migration.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)hw/vfio/common.c index renamed from hw/vfio/common.c +0
-0
fa8fd949b1cf..8505385798f3100644hw/vfio/common.c +0
-0@@ -399,7 +399,7 @@ intQuoted 1 line
vfio_block_multiple_devices_migration(Error
**errp)
Quoted 22 lines
multiple_devices_migration_blocker = NULL; }hw/vfio/common.c +2
-2-return ret; +return !ret; }void vfio_unblock_multiple_devices_migration (void )@@ -444,7 +444,7 @@ int vfio_block_giommu_migration(Error **errp) giommu_migration_blocker =NULL ; } -return ret; +return !ret; } void vfio_migration_finalize(void) diff --git
a/hw/vfio/migration.cb/hw/vfio/migration.cindex6b58dddb8859..0146521d129a100644hw/vfio/migration.c int vfio_migration_realize(VFIODevice · line 646
Quoted 1 line
hw/vfio/migration.c +0
-0@@ -646,12 +646,12 @@ int vfio_migration_realize(VFIODevice *vbasedev,Error **errp)
Quoted 7 lines
hw/vfio/migration.c int vfio_migration_realize(VFIODevice · line 650
Quoted 5 lines
hw/vfio/migration.c +1
-1} ret =vfio_block_multiple_devices_migration (errp); -if (ret) { +if (ret || (errp && *errp)) {Why do you need this extra clause?
Now that error happens, no need to add other blockers which will fail for same reason.
Quoted 5 lines
Quoted 5 lines
But you don't need the (errp && *errp) for that as that's the whole point of negating the result.
And if there's an error set it means
migrate_add_blockerfailed to add the blocker (e.g. snapshotting IIUC), and you would be failing hereunnecessarily?
Quoted 2 lines
If there is an error
qdev_device_add()will fail, continue execution ismeaningless here?
Quoted 9 lines
There is
ERRP_GUARDin this path, so it looks (*errp) is enough.If I removed (errp && *errp) to continue, need below change to bypass
trace_vfio_migration_probeDo you prefer this way?if (!*errp) { trace_vfio_migration_probe(vbasedev->name); }I am mainly questioning that the error testing is correct to test here.
Quoted 7 lines
IIUC, the only one that can propagate any *new* error in
vfio_migration_realizeis the calls tomigrate_add_blockerfailing within the vfio_block* (migration code suggests that this happens on snapshotting). Failing to add migration blocker just means we haven't installed any blockers. And the current code presents that as a "Migration disabled" case. If we want to preserve that behaviour onmigration_add_blocker()failures (which seems like that's what you are doing here) then instead of this:
Quoted 9 lines
Current behavior(without my patch):
"Migration disabled" isn't printed ifmigrate_add_blockersucceed. "Migration disabled" is printed ifmigrate_add_blockerfail.I think this behavior isn't correct, I want to revert it not preserve it, so I used !ret. Imagine we hotplug a vfio device when snapshotting,
migrate_add_blockerfailure will lead to hotplug fail, then the guest is still migratable as no vfio plugged. But we see "Migration disabled" which will confuse us.
/me nods
Quoted 21 lines
Quoted 14 lines
return !ret;you would do this:
ret = migration_add_blocker(...); if (ret < 0) { error_free(...); blocker = NULL;(quoted diff) +1
-0+ return ret;}(quoted diff) +1
-0+ return 1;Quoted 1 line
Or something like that. And then if you return early as you intended?
Yes, this change make sense, I also want to add below:
if (!pdev->failover_pair_id) { ret = vfio_migration_realize(vbasedev, errp);
Review
Quoted 4 lines
(quoted diff) +1
-1- if (ret) { + if (ret > 0) { error_report("%s: Migration disabled", vbasedev->name); }
Makes sense. Checking errp above before printing the tracepoint (like you suggested) is also an option taking the discussion so far, but perhaps the return type to be bool to make it clear to callers that this is not no longer an error code? Maybe let's wait for others on what style is generally preferred in error propagation.
Joao
Quoted 142 lines · Joao Martins
Quoted 141 lines · Zhenzhong
Quoted 129 lines
-----Original Message-----
From: Joao Martins <[email protected]>
Sent: Friday, June 16, 2023 5:06 PM
To: Duan, Zhenzhong <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Peng, Chao P <[email protected]>
Subject: Re: [PATCH] vfio/migration: Fix return value ofvfio_migration_realize()Quoted 99 lines · Zhenzhong
Quoted 99 lines
-----Original Message-----
From: Joao Martins <[email protected]>
Sent: Thursday, June 15, 2023 6:23 PM
To: Duan, Zhenzhong <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Peng, Chao P <[email protected]>
Subject: Re: [PATCH] vfio/migration: Fix return value ofvfio_migration_realize()Quoted 27 lines · Zhenzhong
Quoted 27 lines
-----Original Message-----
From: Joao Martins <[email protected]>
Sent: Thursday, June 15, 2023 4:54 PM
To: Duan, Zhenzhong <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Peng, Chao P <[email protected]>
Subject: Re: [PATCH] vfio/migration: Fix return value ofvfio_migration_realize()Quoted 6 lines · Zhenzhong Duan
We should print "Migration disabled" when migration is blocked in
vfio_migration_realize().Fix it by reverting return value of
migrate_add_blocker(), meanwhile error out directly oncemigrate_add_blocker()failed.It wasn't immediately obvious from commit message that this is mainly about just printing an error message when blockers get added and that well
migrate_add_blocker()returns 0 on success and caller ofvfio_migration_realizeexpects the opposite when blockers are added.Perhaps better wording would be:
Quoted 8 lines
Quoted 8 lines
migrate_add_blocker()returns 0 when successfully adding the migration blocker. However, the caller ofvfio_migration_realize()considers that migration was blocked when the latter returned an error. Fix it by negating the return value obtained bymigrate_add_blocker(). What matters for migration is that the blocker is added in core migration, so this cleans up usability such that user sees "Migrate disabled" when any of the vfio migration blockers areactive.
Quoted 52 lines
Great, I'll use your words.
Quoted 38 lines
Quoted 12 lines
Signed-off-by Zhenzhong Duan <[email protected]>--- hw/vfio/common.c | 4 ++-- hw/vfio/migration.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)hw/vfio/common.c index renamed from hw/vfio/common.c +0
-0
fa8fd949b1cf..8505385798f3100644hw/vfio/common.c +0
-0@@ -399,7 +399,7 @@ intQuoted 1 line
vfio_block_multiple_devices_migration(Error
**errp)
Quoted 22 lines
multiple_devices_migration_blocker = NULL; }hw/vfio/common.c +2
-2-return ret; +return !ret; }void vfio_unblock_multiple_devices_migration (void )@@ -444,7 +444,7 @@ int vfio_block_giommu_migration(Error **errp) giommu_migration_blocker =NULL ; } -return ret; +return !ret; } void vfio_migration_finalize(void) diff --git
a/hw/vfio/migration.cb/hw/vfio/migration.cindex6b58dddb8859..0146521d129a100644hw/vfio/migration.c int vfio_migration_realize(VFIODevice · line 646
Quoted 1 line
hw/vfio/migration.c +0
-0@@ -646,12 +646,12 @@ int vfio_migration_realize(VFIODevice *vbasedev,Error **errp)
Quoted 7 lines
hw/vfio/migration.c int vfio_migration_realize(VFIODevice · line 650
Quoted 5 lines
hw/vfio/migration.c +1
-1} ret =vfio_block_multiple_devices_migration (errp); -if (ret) { +if (ret || (errp && *errp)) {Why do you need this extra clause?
Now that error happens, no need to add other blockers which will fail for same reason.
Quoted 5 lines
Quoted 5 lines
But you don't need the (errp && *errp) for that as that's the whole point of negating the result.
And if there's an error set it means
migrate_add_blockerfailed to add the blocker (e.g. snapshotting IIUC), and you would be failing hereunnecessarily?
Quoted 2 lines
If there is an error
qdev_device_add()will fail, continue execution ismeaningless here?
Quoted 9 lines
There is
ERRP_GUARDin this path, so it looks (*errp) is enough.If I removed (errp && *errp) to continue, need below change to bypass
trace_vfio_migration_probeDo you prefer this way?if (!*errp) { trace_vfio_migration_probe(vbasedev->name); }I am mainly questioning that the error testing is correct to test here.
Quoted 7 lines
IIUC, the only one that can propagate any *new* error in
vfio_migration_realizeis the calls tomigrate_add_blockerfailing within the vfio_block* (migration code suggests that this happens on snapshotting). Failing to add migration blocker just means we haven't installed any blockers. And the current code presents that as a "Migration disabled" case. If we want to preserve that behaviour onmigration_add_blocker()failures (which seems like that's what you are doing here) then instead of this:Current behavior(without my patch):
"Migration disabled" isn't printed ifmigrate_add_blockersucceed. "Migration disabled" is printed ifmigrate_add_blockerfail.
Quoted 7 lines
Quoted 5 lines
I think this behavior isn't correct, I want to revert it not preserve it, so I used !ret. Imagine we hotplug a vfio device when snapshotting,
migrate_add_blockerfailure will lead to hotplug fail, then the guest is still migratable as no vfio plugged. But we see "Migration disabled" which will confuse us./me nods
Yes. Overall, the reason for which migration is not supported or is disabled is not very clear today (for the user). It might need some more adjustments, like this one, before we remove the experimental flag. It will also help QE to define test scenarios and track expected results.
Quoted 25 lines
Quoted 21 lines
Quoted 14 lines
return !ret;you would do this:
ret = migration_add_blocker(...); if (ret < 0) { error_free(...); blocker = NULL;(quoted diff) +1
-0+ return ret;}(quoted diff) +1
-0+ return 1;Quoted 1 line
Or something like that. And then if you return early as you intended?
Yes, this change make sense, I also want to add below:
if (!pdev->failover_pair_id) { ret = vfio_migration_realize(vbasedev, errp);Review
Quoted 4 lines
(quoted diff) +1
-1- if (ret) { + if (ret > 0) { error_report("%s: Migration disabled", vbasedev->name); }
Quoted 5 lines
Makes sense. Checking errp above before printing the tracepoint (like you suggested) is also an option taking the discussion so far, but perhaps the return type to be bool to make it clear to callers that this is not no longer an error code? Maybe let's wait for others on what style is generally preferred in error propagation.
I think the code should follow the qdev_realize() prototype, which returns a bool.
Thanks,
C.
Quoted 152 lines · Cédric Le Goater
Quoted 151 lines · Joao Martins
Quoted 149 lines · Zhenzhong
Quoted 130 lines
-----Original Message-----
From: Joao Martins <[email protected]>
Sent: Friday, June 16, 2023 5:06 PM
To: Duan, Zhenzhong <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Peng, Chao P <[email protected]>
Subject: Re: [PATCH] vfio/migration: Fix return value ofvfio_migration_realize()Quoted 99 lines · Zhenzhong
Quoted 99 lines
-----Original Message-----
From: Joao Martins <[email protected]>
Sent: Thursday, June 15, 2023 6:23 PM
To: Duan, Zhenzhong <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Peng, Chao P <[email protected]>
Subject: Re: [PATCH] vfio/migration: Fix return value ofvfio_migration_realize()Quoted 27 lines · Zhenzhong
Quoted 27 lines
-----Original Message-----
From: Joao Martins <[email protected]>
Sent: Thursday, June 15, 2023 4:54 PM
To: Duan, Zhenzhong <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Peng, Chao P <[email protected]>
Subject: Re: [PATCH] vfio/migration: Fix return value ofvfio_migration_realize()Quoted 6 lines · Zhenzhong Duan
We should print "Migration disabled" when migration is blocked in
vfio_migration_realize().Fix it by reverting return value of
migrate_add_blocker(), meanwhile error out directly oncemigrate_add_blocker()failed.It wasn't immediately obvious from commit message that this is mainly about just printing an error message when blockers get added and that well
migrate_add_blocker()returns 0 on success and caller ofvfio_migration_realizeexpects the opposite when blockers are added.Perhaps better wording would be:
Quoted 8 lines
Quoted 8 lines
migrate_add_blocker()returns 0 when successfully adding the migration blocker. However, the caller ofvfio_migration_realize()considers that migration was blocked when the latter returned an error. Fix it by negating the return value obtained bymigrate_add_blocker(). What matters for migration is that the blocker is added in core migration, so this cleans up usability such that user sees "Migrate disabled" when any of the vfio migration blockers areactive.
Quoted 52 lines
Great, I'll use your words.
Quoted 38 lines
Quoted 12 lines
Signed-off-by Zhenzhong Duan <[email protected]>---
hw/vfio/common.c | 4 ++--
hw/vfio/migration.c| 6 +++---2 files changed, 5 insertions(+), 5 deletions(-)hw/vfio/common.c index renamed from hw/vfio/common.c +0
-0
fa8fd949b1cf..8505385798f3100644hw/vfio/common.c +0
-0@@ -399,7 +399,7 @@ intQuoted 1 line
vfio_block_multiple_devices_migration(Error
**errp)
Quoted 22 lines
multiple_devices_migration_blocker= NULL; }- return ret;
+ return !ret;
}void
vfio_unblock_multiple_devices_migration(void)hw/vfio/common.c +1
-1@@ -444,7 +444,7 @@ int vfio_block_giommu_migration(Error **errp) giommu_migration_blocker = NULL; } - return ret; + return !ret; }void
vfio_migration_finalize(void)diff --gita/hw/vfio/migration.cb/hw/vfio/migration.cindex6b58dddb8859..0146521d129a100644hw/vfio/migration.c int vfio_migration_realize(VFIODevice · line 646
Quoted 1 line
hw/vfio/migration.c +0
-0@@ -646,12 +646,12 @@ int vfio_migration_realize(VFIODevice *vbasedev,Error **errp)
Quoted 7 lines
hw/vfio/migration.c int vfio_migration_realize(VFIODevice · line 650
Quoted 5 lines
hw/vfio/migration.c +1
-1} ret = vfio_block_multiple_devices_migration(errp); - if (ret) { + if (ret || (errp && *errp)) {Why do you need this extra clause?
Now that error happens, no need to add other blockers which will fail for same reason.
Quoted 5 lines
Quoted 5 lines
But you don't need the (errp && *errp) for that as that's the whole point of negating the result.
And if there's an error set it means
migrate_add_blockerfailed to add the blocker (e.g. snapshotting IIUC), and you would be failing hereunnecessarily?
Quoted 2 lines
If there is an error
qdev_device_add()will fail, continue execution ismeaningless here?
Quoted 9 lines
There is
ERRP_GUARDin this path, so it looks (*errp) is enough.If I removed (errp && *errp) to continue, need below change to bypass
trace_vfio_migration_probeDo you prefer this way?if (!*errp) {
trace_vfio_migration_probe(vbasedev->name); }I am mainly questioning that the error testing is correct to test here.
Quoted 7 lines
IIUC, the only one that can propagate any *new* error in
vfio_migration_realizeis the calls tomigrate_add_blockerfailing within the vfio_block* (migration code suggests that this happens on snapshotting). Failing to add migration blocker just means we haven't installed any blockers. And the current code presents that as a "Migration disabled" case. If we want to preserve that behaviour onmigration_add_blocker()failures (which seems like that's what you are doing here) then instead of this:Current behavior(without my patch):
"Migration disabled" isn't printed ifmigrate_add_blockersucceed. "Migration disabled" is printed ifmigrate_add_blockerfail.I think this behavior isn't correct, I want to revert it not preserve it, so I used !ret.
Imagine we hotplug a vfio device when snapshotting,migrate_add_blockerfailure will lead to hotplug fail, then the guest is still migratable as no vfio plugged.
But we see "Migration disabled" which will confuse us.
Quoted 5 lines
Quoted 1 line
/me nods
Yes. Overall, the reason for which migration is not supported or is disabled is not very clear today (for the user). It might need some more adjustments, like this one, before we remove the experimental flag.
I think the "Migration Disabled" was an UX oversight when we refactored blockers into vfio_migration_realize(). The actual migration is *not* disabled, it is just that the message or tracepoint shouldn't be printed. The reasons why it is blocked / not supported are clear in code right now.
Quoted 27 lines
It will also help QE to define test scenarios and track expected results.
Quoted 25 lines
>>
Quoted 24 lines
Quoted 11 lines
return !ret;
you would do this:
ret =
migration_add_blocker(...);
if (ret < 0) {
error_free(...);
blocker = NULL;
+ return ret;
}Quoted 3 lines
+ return 1;
Or something like that. And then if you return early as you intended?
Yes, this change make sense, I also want to add below:
if (!pdev->failover_pair_id) {
ret =vfio_migration_realize(vbasedev, errp);
- if (ret) {
+ if (ret > 0) {
error_report("%s: Migration disabled", vbasedev->name); }
Quoted 9 lines
Quoted 5 lines
Makes sense. Checking errp above before printing the tracepoint (like you suggested) is also an option taking the discussion so far, but perhaps the return type to be bool to make it clear to callers that this is not no longer an error code? Maybe let's wait for others on what style is generally preferred in error propagation.
I think the code should follow the
qdev_realize()prototype, which returns a bool.
That makes sense, it makes the decision a lot simpler.
Quoted 5 lines
Thanks,
C.