vfio: Improve error reporting (part 2
v6 cover vfio: Improve error reporting (part 2
Hello,
The motivation behind these changes is to improve error reporting to the upper management layer (libvirt) with a more detailed error, this to let it decide, depending on the reported error, whether to try migration again later. It would be useful in cases where migration fails due to lack of HW resources on the host. For instance, some adapters can only initiate a limited number of simultaneous dirty tracking requests and this imposes a limit on the the number of VMs that can be migrated simultaneously.
We are not quite ready for such a mechanism but what we can do first is to cleanup the error reporting in the early save_setup sequence. This is what the following changes propose, by adding an Error** argument to various handlers and propagating it to the core migration subsystem.
The first part [1] of this series modifying the core migration subsystem is now merged. This is the second part changing VFIO which was already proposed in March. See [2].
Thanks,
C.
[1] [PATCH for-9.1 v5 00/14] migration: Improve error reporting
https://lore.kernel.org/qemu-devel/[email protected]/
[2] [PATCH v4 00/25] migration: Improve error reporting
https://lore.kernel.org/qemu-devel/[email protected]/
Changes in v6:
- Commit log improvements (Avihai)
- Modified some titles (Avihai)
- vfio_migration_set_state() : Dropped the error_setg_errno() change when setting device in recover state fails (Avihai)
- vfio_migration_state_notifier() : report local error (Avihai)
- vfio_save_device_config_state() : Set errp if the migration stream is in error (Avihai)
- vfio_save_state() : Changed error prefix (Avihai)
- vfio_iommu_map_dirty_notify() : Modified goto label (Avihai)
- Fixed memory_get_xlat_addr documentation (Avihai)
- Fixed line wrapping (Avihai)
- Fixed query_dirty_bitmap documentation (Avihai)
- Dropped last patch from v5 :
vfio: Extend vfio_set_migration_error() with Error* argument
Changes in v5:
- Rebased on 20c64c8a51a4 ("migration: migration_file_set_error")
- Fixed typo in set_dirty_page_tracking documentation
- Used error_setg_errno() in vfio_devices_dma_logging_start()
- Replaced error_setg() by error_setg_errno() in vfio_migration_set_state()
- Replaced error_setg() by error_setg_errno() in vfio_devices_query_dirty_bitmap() and vfio_legacy_query_dirty_bitmap()
- ':' -> '-' in vfio_iommu_map_dirty_notify()
Cédric Le Goater (9):
vfio: Add Error** argument to .set_dirty_page_tracking() handler
vfio: Add Error** argument to vfio_devices_dma_logging_start()
migration: Extend migration_file_set_error() with Error* argument vfio/migration: Add an Error** argument to vfio_migration_set_state() vfio/migration: Add Error** argument to .vfio_save_config() handler
vfio: Reverse test on vfio_get_xlat_addr()
memory: Add Error** argument to memory_get_xlat_addr()
vfio: Add Error** argument to .get_dirty_bitmap() handler
vfio: Also trace event failures in vfio_save_complete_precopy()
include/exec/memory.h | 15 +++- include/hw/vfio/vfio-common.h | 29 ++++++- include/hw/vfio/vfio-container-base.h | 39 +++++++-- include/migration/misc.h | 2 +- hw/vfio/common.c | 112 +++++++++++++++++--------- hw/vfio/container-base.c | 11 +-- hw/vfio/container.c | 20 +++-- hw/vfio/migration.c | 105 +++++++++++++++--------- hw/vfio/pci.c | 5 +- hw/virtio/vhost-vdpa.c | 5 +- migration/migration.c | 6 +- system/memory.c | 10 +-- 12 files changed, 246 insertions(+), 113 deletions(-)
Signature · 1 line
2.45.0
PATCH v6 1/9 vfio: Add Error** argument to .set_dirty_page_tracking() handler
We will use the Error object to improve error reporting in the .log_global*() handlers of VFIO. Add documentation while at it.
---
Changes in v5:
- Fixed typo in set_dirty_page_tracking documentation
include/hw/vfio/vfio-container-base.h | 18 ++++++++++++++++-- hw/vfio/common.c | 4 ++-- hw/vfio/container-base.c | 4 ++-- hw/vfio/container.c | 6 +++--- 4 files changed, 23 insertions(+), 9 deletions(-)
include/hw/vfio/vfio-container-base.h +16 -2
@@ -82,7 +82,7 @@ int vfio_container_add_section_window(VFIOContainerBase *bcontainer,void vfio_container_del_section_window (VFIOContainerBase *bcontainer,MemoryRegionSection *section);int vfio_container_set_dirty_page_tracking (VFIOContainerBase *bcontainer, -bool start); +bool start,Error **errp);int vfio_container_query_dirty_bitmap (const VFIOContainerBase *bcontainer,VFIOBitmap *vbmap,hwaddr iova,hwaddr size);
@@ -121,9 +121,23 @@ struct VFIOIOMMUClass {int (*attach_device)(const char *name,VFIODevice *vbasedev,AddressSpace *as,Error **errp);void (*detach_device)(VFIODevice *vbasedev); +/* migration feature */ + +/** +* @set_dirty_page_tracking +* +* Start or stop dirty pages tracking on VFIO container +* +* @bcontainer: #VFIOContainerBase on which to de/activate dirty +* page tracking +* @start: indicates whether to start or stop dirty pages tracking +* @errp: pointer to Error*, to store an error if it happens. +* +* Returns zero to indicate success and negative for error +*/ int (*set_dirty_page_tracking)(const VFIOContainerBase *bcontainer, -bool start); +bool start,Error **errp);int (*query_dirty_bitmap)(const VFIOContainerBase *bcontainer,VFIOBitmap *vbmap,hwaddr iova,hwaddr size);
hw/vfio/common.c +2 -2
@@ -1076,7 +1076,7 @@ static bool vfio_listener_log_global_start(MemoryListener *listener,if (vfio_devices_all_device_dirty_tracking (bcontainer)) { ret =vfio_devices_dma_logging_start (bcontainer); }else { - ret =vfio_container_set_dirty_page_tracking (bcontainer, true); + ret =vfio_container_set_dirty_page_tracking (bcontainer, true,NULL ); }if (ret) {
@@ -1096,7 +1096,7 @@ static void vfio_listener_log_global_stop(MemoryListener *listener)if (vfio_devices_all_device_dirty_tracking (bcontainer)) {vfio_devices_dma_logging_stop (bcontainer); }else { - ret =vfio_container_set_dirty_page_tracking (bcontainer, false); + ret =vfio_container_set_dirty_page_tracking (bcontainer, false,NULL ); }if (ret) {
hw/vfio/container-base.c +2 -2
@@ -53,14 +53,14 @@ void vfio_container_del_section_window(VFIOContainerBase *bcontainer, }int vfio_container_set_dirty_page_tracking (VFIOContainerBase *bcontainer, -bool start) +bool start,Error **errp) {if (!bcontainer->dirty_pages_supported) {return 0 ; }g_assert (bcontainer->ops->set_dirty_page_tracking); -return bcontainer->ops->set_dirty_page_tracking (bcontainer, start); +return bcontainer->ops->set_dirty_page_tracking (bcontainer, start, errp); } int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
hw/vfio/container.c +3 -3
@@ -209,7 +209,7 @@ static int vfio_legacy_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova,static int vfio_legacy_set_dirty_page_tracking (const VFIOContainerBase *bcontainer, -bool start) +bool start,Error **errp) {const VFIOContainer *container =container_of (bcontainer, VFIOContainer, bcontainer);
@@ -227,8 +227,8 @@ vfio_legacy_set_dirty_page_tracking(const VFIOContainerBase *bcontainer, ret =ioctl (container->fd,VFIO_IOMMU_DIRTY_PAGES , &dirty);if (ret) { ret = -errno; -error_report ("Failed to set dirty tracking flag 0x%x errno: %d" , - dirty.flags, errno); +error_setg_errno (errp, errno,"Failed to set dirty tracking flag 0x%x" , + dirty.flags); }return ret;
Signature · 1 line
2.45.0
Re: [PATCH v6 1/9] vfio: Add Error** argument to .set_dirty_page_tracking() handler
Hi Cédric,
Quoted 22 lines · Cédric Le Goater
We will use the Error object to improve error reporting in the .log_global*() handlers of VFIO. Add documentation while at it.
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Avihai Horon <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
Changes in v5:- Fixed typo in
set_dirty_page_trackingdocumentationinclude/hw/vfio/vfio-container-base.h | 18 ++++++++++++++++-- hw/vfio/common.c | 4 ++-- hw/vfio/container-base.c | 4 ++-- hw/vfio/container.c | 6 +++--- 4 files changed, 23 insertions(+), 9 deletions(-)include/hw/vfio/vfio-container-base.h +0
-0
include/hw/vfio/vfio-container-base.h int vfio_container_add_section_window(VFIOContainerBase *bcontainer, · line 85
Quoted 5 lines
include/hw/vfio/vfio-container-base.h +1
-1@@ -82,7 +82,7 @@ int vfio_container_add_section_window(VFIOContainerBase *bcontainer,void vfio_container_del_section_window (VFIOContainerBase *bcontainer,MemoryRegionSection *section);int vfio_container_set_dirty_page_tracking (VFIOContainerBase *bcontainer, -bool start); +bool start,Error **errp);
I am a bit confused now wrt [PATCH v2 03/11] vfio: Make VFIOIOMMUClass::attach_device() and its wrapper return bool & co
Shall we return a bool or a int?
Looking at ./include/qapi/error.h I have not found any stringent requirement
* - Whenever practical, also return a value that indicates success /
* failure. This can make the error checking more concise, and can * avoid useless error object creation and destruction. Note that * we still have many functions returning void. We recommend * • bool-valued functions return true on success / false on failure, * • pointer-valued functions return non-null / null pointer, and * • integer-valued functions return non-negative / negative.
Quoted 85 lines
include/hw/vfio/vfio-container-base.h +15
-1int vfio_container_query_dirty_bitmap (const VFIOContainerBase *bcontainer,VFIOBitmap *vbmap,hwaddr iova,hwaddr size);@@ -121,9 +121,23 @@ struct VFIOIOMMUClass {int (*attach_device)(const char *name,VFIODevice *vbasedev,AddressSpace *as,Error **errp);void (*detach_device)(VFIODevice *vbasedev); +/* migration feature */ + +/** +* @set_dirty_page_tracking +* +* Start or stop dirty pages tracking on VFIO container +* +* @bcontainer: #VFIOContainerBase on which to de/activate dirty +* page tracking +* @start: indicates whether to start or stop dirty pages tracking +* @errp: pointer to Error*, to store an error if it happens. +* +* Returns zero to indicate success and negative for error +*/ int (*set_dirty_page_tracking)(const VFIOContainerBase *bcontainer, -bool start); +bool start,Error **errp);int (*query_dirty_bitmap)(const VFIOContainerBase *bcontainer,VFIOBitmap *vbmap,hwaddr iova,hwaddr size);hw/vfio/common.c +2
-2@@ -1076,7 +1076,7 @@ static bool vfio_listener_log_global_start(MemoryListener *listener,if (vfio_devices_all_device_dirty_tracking (bcontainer)) { ret =vfio_devices_dma_logging_start (bcontainer); }else { - ret =vfio_container_set_dirty_page_tracking (bcontainer, true); + ret =vfio_container_set_dirty_page_tracking (bcontainer, true,NULL ); }if (ret) {@@ -1096,7 +1096,7 @@ static void vfio_listener_log_global_stop(MemoryListener *listener)if (vfio_devices_all_device_dirty_tracking (bcontainer)) {vfio_devices_dma_logging_stop (bcontainer); }else { - ret =vfio_container_set_dirty_page_tracking (bcontainer, false); + ret =vfio_container_set_dirty_page_tracking (bcontainer, false,NULL ); }if (ret) {hw/vfio/container-base.c +2
-2@@ -53,14 +53,14 @@ void vfio_container_del_section_window(VFIOContainerBase *bcontainer, }int vfio_container_set_dirty_page_tracking (VFIOContainerBase *bcontainer, -bool start) +bool start,Error **errp) {if (!bcontainer->dirty_pages_supported) {return 0 ; }g_assert (bcontainer->ops->set_dirty_page_tracking); -return bcontainer->ops->set_dirty_page_tracking (bcontainer, start); +return bcontainer->ops->set_dirty_page_tracking (bcontainer, start, errp); } int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer,hw/vfio/container.c +1
-1@@ -209,7 +209,7 @@ static int vfio_legacy_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova,static int vfio_legacy_set_dirty_page_tracking (const VFIOContainerBase *bcontainer, -bool start) +bool start,Error **errp) {const VFIOContainer *container =container_of (bcontainer, VFIOContainer, bcontainer);
hw/vfio/container.c vfio_legacy_set_dirty_page_tracking(const VFIOContainerBase *bcontainer, · line 234
Quoted 10 lines
hw/vfio/container.c +2
-2@@ -227,8 +227,8 @@ vfio_legacy_set_dirty_page_tracking(const VFIOContainerBase *bcontainer, ret =ioctl (container->fd,VFIO_IOMMU_DIRTY_PAGES , &dirty);if (ret) { ret = -errno; -error_report ("Failed to set dirty tracking flag 0x%x errno: %d" , - dirty.flags, errno); +error_setg_errno (errp, errno,"Failed to set dirty tracking flag 0x%x" , + dirty.flags); }return ret;
Besides
Eric
Re: [PATCH v6 1/9] vfio: Add Error** argument to .set_dirty_page_tracking() handler
Quoted 33 lines · Eric Auger
Hi Cédric,
Quoted 22 lines · Cédric Le Goater
We will use the Error object to improve error reporting in the .log_global*() handlers of VFIO. Add documentation while at it.
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Avihai Horon <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
Changes in v5:- Fixed typo in
set_dirty_page_trackingdocumentationinclude/hw/vfio/vfio-container-base.h | 18 ++++++++++++++++-- hw/vfio/common.c | 4 ++-- hw/vfio/container-base.c | 4 ++-- hw/vfio/container.c | 6 +++--- 4 files changed, 23 insertions(+), 9 deletions(-)include/hw/vfio/vfio-container-base.h +0
-0include/hw/vfio/vfio-container-base.h int vfio_container_add_section_window(VFIOContainerBase *bcontainer, · line 85
Quoted 5 lines
include/hw/vfio/vfio-container-base.h +1
-1@@ -82,7 +82,7 @@ int vfio_container_add_section_window(VFIOContainerBase *bcontainer,void vfio_container_del_section_window (VFIOContainerBase *bcontainer,MemoryRegionSection *section);int vfio_container_set_dirty_page_tracking (VFIOContainerBase *bcontainer, -bool start); +bool start,Error **errp);I am a bit confused now wrt [PATCH v2 03/11] vfio: Make
VFIOIOMMUClass::attach_device()and its wrapper return bool & co
Quoted 1 line
Shall we return a bool or a int?
It would be better to follow the best practices described in qapi/error.h.
Zhenzhong excluded some files from his cleanup series to avoid conflicts with this series of mine. And indeed, I would prefer to merge this one first. It should be addressed later.
Quoted 107 lines
Looking at
./include/qapi/error.hI have not found any stringent requirement* - Whenever practical, also return a value that indicates success /
* failure. This can make the error checking more concise, and can * avoid useless error object creation and destruction. Note that * we still have many functions returning void. We recommend * • bool-valued functions return true on success / false on failure, * • pointer-valued functions return non-null / null pointer, and * • integer-valued functions return non-negative / negative.Quoted 94 lines
include/hw/vfio/vfio-container-base.h +15
-1int vfio_container_query_dirty_bitmap (const VFIOContainerBase *bcontainer,VFIOBitmap *vbmap,hwaddr iova,hwaddr size);@@ -121,9 +121,23 @@ struct VFIOIOMMUClass {int (*attach_device)(const char *name,VFIODevice *vbasedev,AddressSpace *as,Error **errp);void (*detach_device)(VFIODevice *vbasedev); +/* migration feature */ + +/** +* @set_dirty_page_tracking +* +* Start or stop dirty pages tracking on VFIO container +* +* @bcontainer: #VFIOContainerBase on which to de/activate dirty +* page tracking +* @start: indicates whether to start or stop dirty pages tracking +* @errp: pointer to Error*, to store an error if it happens. +* +* Returns zero to indicate success and negative for error +*/ int (*set_dirty_page_tracking)(const VFIOContainerBase *bcontainer, -bool start); +bool start,Error **errp);int (*query_dirty_bitmap)(const VFIOContainerBase *bcontainer,VFIOBitmap *vbmap,hwaddr iova,hwaddr size);hw/vfio/common.c +2
-2@@ -1076,7 +1076,7 @@ static bool vfio_listener_log_global_start(MemoryListener *listener,if (vfio_devices_all_device_dirty_tracking (bcontainer)) { ret =vfio_devices_dma_logging_start (bcontainer); }else { - ret =vfio_container_set_dirty_page_tracking (bcontainer, true); + ret =vfio_container_set_dirty_page_tracking (bcontainer, true,NULL ); }if (ret) {@@ -1096,7 +1096,7 @@ static void vfio_listener_log_global_stop(MemoryListener *listener)if (vfio_devices_all_device_dirty_tracking (bcontainer)) {vfio_devices_dma_logging_stop (bcontainer); }else { - ret =vfio_container_set_dirty_page_tracking (bcontainer, false); + ret =vfio_container_set_dirty_page_tracking (bcontainer, false,NULL ); }if (ret) {hw/vfio/container-base.c +2
-2@@ -53,14 +53,14 @@ void vfio_container_del_section_window(VFIOContainerBase *bcontainer, }int vfio_container_set_dirty_page_tracking (VFIOContainerBase *bcontainer, -bool start) +bool start,Error **errp) {if (!bcontainer->dirty_pages_supported) {return 0 ; }g_assert (bcontainer->ops->set_dirty_page_tracking); -return bcontainer->ops->set_dirty_page_tracking (bcontainer, start); +return bcontainer->ops->set_dirty_page_tracking (bcontainer, start, errp); } int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer,hw/vfio/container.c +3
-3@@ -209,7 +209,7 @@ static int vfio_legacy_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova,static int vfio_legacy_set_dirty_page_tracking (const VFIOContainerBase *bcontainer, -bool start) +bool start,Error **errp) {const VFIOContainer *container =container_of (bcontainer, VFIOContainer, bcontainer);@@ -227,8 +227,8 @@ vfio_legacy_set_dirty_page_tracking(const VFIOContainerBase *bcontainer, ret =ioctl (container->fd,VFIO_IOMMU_DIRTY_PAGES , &dirty);if (ret) { ret = -errno; -error_report ("Failed to set dirty tracking flag 0x%x errno: %d" , - dirty.flags, errno); +error_setg_errno (errp, errno,"Failed to set dirty tracking flag 0x%x" , + dirty.flags); }
Quoted 6 lines
hw/vfio/container.c vfio_legacy_set_dirty_page_tracking(const VFIOContainerBase *bcontainer, · line 234
Quoted 1 line
hw/vfio/container.c +0
-0return ret;Besides
Reviewed-by Eric Auger <[email protected]>Eric
Thanks,
C.
PATCH v6 2/9 vfio: Add Error** argument to vfio_devices_dma_logging_start()
In reply to Cédric Le GoaterThis allows to update the Error argument of the VFIO log_global_start() handler. Errors for container based logging will also be propagated to qemu_savevm_state_setup() when the ram save_setup() handler is executed.
The vfio_set_migration_error() call becomes redundant in vfio_listener_log_global_start(). Remove it.
---
Changes in v6:
- Commit log improvements (Avihai)
Changes in v5:
- Used error_setg_errno() in vfio_devices_dma_logging_start()
hw/vfio/common.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
hw/vfio/common.c +15 -11
@@ -1027,7 +1027,8 @@ static void vfio_device_feature_dma_logging_start_destroy(g_free (feature); } -static int vfio_devices_dma_logging_start (VFIOContainerBase *bcontainer) +static int vfio_devices_dma_logging_start (VFIOContainerBase *bcontainer, +Error **errp) {struct vfio_device_feature *feature;VFIODirtyRanges ranges;
@@ -1038,6 +1039,7 @@ static int vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer) feature =vfio_device_feature_dma_logging_start_create (bcontainer, &ranges);if (!feature) { +error_setg_errno (errp, errno,"Failed to prepare DMA logging" );return -errno; }
@@ -1049,8 +1051,8 @@ static int vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer) ret =ioctl (vbasedev->fd,VFIO_DEVICE_FEATURE , feature);if (ret) { ret = -errno; -error_report ("%s: Failed to start DMA logging, err %d (%s)" , - vbasedev->name, ret,strerror (errno)); +error_setg_errno (errp, errno,"%s: Failed to start DMA logging" , + vbasedev->name); goto out; } vbasedev->dirty_tracking = true;
@@ -1069,20 +1071,19 @@ out:static bool vfio_listener_log_global_start (MemoryListener *listener,Error **errp) { +ERRP_GUARD ();VFIOContainerBase *bcontainer =container_of (listener, VFIOContainerBase, listener);int ret;if (vfio_devices_all_device_dirty_tracking (bcontainer)) { - ret =vfio_devices_dma_logging_start (bcontainer); + ret =vfio_devices_dma_logging_start (bcontainer, errp); }else { - ret =vfio_container_set_dirty_page_tracking (bcontainer, true,NULL ); + ret =vfio_container_set_dirty_page_tracking (bcontainer, true, errp); }if (ret) { -error_report ("vfio: Could not start dirty page tracking, err: %d (%s)" , - ret,strerror (-ret)); -vfio_set_migration_error (ret); +error_prepend (errp,"vfio: Could not start dirty page tracking - " ); }return !ret; }
@@ -1091,17 +1092,20 @@ static void vfio_listener_log_global_stop(MemoryListener *listener) {VFIOContainerBase *bcontainer =container_of (listener, VFIOContainerBase, listener); +Error *local_err =NULL ;int ret =0 ;if (vfio_devices_all_device_dirty_tracking (bcontainer)) {vfio_devices_dma_logging_stop (bcontainer); }else { - ret =vfio_container_set_dirty_page_tracking (bcontainer, false,NULL ); + ret =vfio_container_set_dirty_page_tracking (bcontainer, false, + &local_err); }if (ret) { -error_report ("vfio: Could not stop dirty page tracking, err: %d (%s)" , - ret,strerror (-ret)); +error_prepend (&local_err, +"vfio: Could not stop dirty page tracking - " ); +error_report_err (local_err);vfio_set_migration_error (ret); } }
Signature · 1 line
2.45.0
Re: [PATCH v6 2/9] vfio: Add Error** argument to vfio_devices_dma_logging_start()
Hi Cédric,
Quoted 3 lines · Cédric Le Goater
This allows to update the Error argument of the VFIO
log_global_start()handler. Errors for container based logging will also be propagated toqemu_savevm_state_setup()when the ramsave_setup()handler is executed.
nit: also now collect & print errors fromvfio_container_set_dirty_page_tracking()
Quoted 92 lines
The
vfio_set_migration_error()call becomes redundant invfio_listener_log_global_start(). Remove it.Reviewed-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Avihai Horon <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
Changes in v6:
- Commit log improvements (Avihai)
Changes in v5:
- Used
error_setg_errno()invfio_devices_dma_logging_start()hw/vfio/common.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)hw/vfio/common.c +12
-9@@ -1027,7 +1027,8 @@ static void vfio_device_feature_dma_logging_start_destroy(g_free (feature); } -static int vfio_devices_dma_logging_start (VFIOContainerBase *bcontainer) +static int vfio_devices_dma_logging_start (VFIOContainerBase *bcontainer, +Error **errp) {struct vfio_device_feature *feature;VFIODirtyRanges ranges;@@ -1038,6 +1039,7 @@ static int vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer) feature =vfio_device_feature_dma_logging_start_create (bcontainer, &ranges);if (!feature) { +error_setg_errno (errp, errno,"Failed to prepare DMA logging" );return -errno; }@@ -1049,8 +1051,8 @@ static int vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer) ret =ioctl (vbasedev->fd,VFIO_DEVICE_FEATURE , feature);if (ret) { ret = -errno; -error_report ("%s: Failed to start DMA logging, err %d (%s)" , - vbasedev->name, ret,strerror (errno)); +error_setg_errno (errp, errno,"%s: Failed to start DMA logging" , + vbasedev->name); goto out; } vbasedev->dirty_tracking = true;@@ -1069,20 +1071,19 @@ out:static bool vfio_listener_log_global_start (MemoryListener *listener,Error **errp) { +ERRP_GUARD ();VFIOContainerBase *bcontainer =container_of (listener, VFIOContainerBase, listener);int ret;if (vfio_devices_all_device_dirty_tracking (bcontainer)) { - ret =vfio_devices_dma_logging_start (bcontainer); + ret =vfio_devices_dma_logging_start (bcontainer, errp); }else { - ret =vfio_container_set_dirty_page_tracking (bcontainer, true,NULL ); + ret =vfio_container_set_dirty_page_tracking (bcontainer, true, errp); }if (ret) { -error_report ("vfio: Could not start dirty page tracking, err: %d (%s)" , - ret,strerror (-ret)); -vfio_set_migration_error (ret); +error_prepend (errp,"vfio: Could not start dirty page tracking - " ); }return !ret; }@@ -1091,17 +1092,20 @@ static void vfio_listener_log_global_stop(MemoryListener *listener) {VFIOContainerBase *bcontainer =container_of (listener, VFIOContainerBase, listener); +Error *local_err =NULL ;int ret =0 ;if (vfio_devices_all_device_dirty_tracking (bcontainer)) {vfio_devices_dma_logging_stop (bcontainer); }else { - ret =vfio_container_set_dirty_page_tracking (bcontainer, false,NULL ); + ret =vfio_container_set_dirty_page_tracking (bcontainer, false, + &local_err); }
hw/vfio/common.c static void vfio_listener_log_global_stop(MemoryListener *listener) · line 1111
Quoted 10 lines
hw/vfio/common.c +3
-2if (ret) { -error_report ("vfio: Could not stop dirty page tracking, err: %d (%s)" , - ret,strerror (-ret)); +error_prepend (&local_err, +"vfio: Could not stop dirty page tracking - " ); +error_report_err (local_err);vfio_set_migration_error (ret); } }
Eric
Re: [PATCH v6 2/9] vfio: Add Error** argument to vfio_devices_dma_logging_start()
Quoted 7 lines · Eric Auger
Hi Cédric,
Quoted 3 lines · Cédric Le Goater
This allows to update the Error argument of the VFIO
log_global_start()handler. Errors for container based logging will also be propagated toqemu_savevm_state_setup()when the ramsave_setup()handler is executed.nit: also now collect & print errors from
vfio_container_set_dirty_page_tracking()
OK. To avoid resending, I amended the commit log with :
"Also, errors from vfio_container_set_dirty_page_tracking() are now collected and reported."
Thanks,
C.
Quoted 107 lines
Quoted 92 lines
The
vfio_set_migration_error()call becomes redundant invfio_listener_log_global_start(). Remove it.Reviewed-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Avihai Horon <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
Changes in v6:
- Commit log improvements (Avihai)
Changes in v5:
- Used
error_setg_errno()invfio_devices_dma_logging_start()hw/vfio/common.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)hw/vfio/common.c +12
-9@@ -1027,7 +1027,8 @@ static void vfio_device_feature_dma_logging_start_destroy(g_free (feature); } -static int vfio_devices_dma_logging_start (VFIOContainerBase *bcontainer) +static int vfio_devices_dma_logging_start (VFIOContainerBase *bcontainer, +Error **errp) {struct vfio_device_feature *feature;VFIODirtyRanges ranges;@@ -1038,6 +1039,7 @@ static int vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer) feature =vfio_device_feature_dma_logging_start_create (bcontainer, &ranges);if (!feature) { +error_setg_errno (errp, errno,"Failed to prepare DMA logging" );return -errno; }@@ -1049,8 +1051,8 @@ static int vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer) ret =ioctl (vbasedev->fd,VFIO_DEVICE_FEATURE , feature);if (ret) { ret = -errno; -error_report ("%s: Failed to start DMA logging, err %d (%s)" , - vbasedev->name, ret,strerror (errno)); +error_setg_errno (errp, errno,"%s: Failed to start DMA logging" , + vbasedev->name); goto out; } vbasedev->dirty_tracking = true;@@ -1069,20 +1071,19 @@ out:static bool vfio_listener_log_global_start (MemoryListener *listener,Error **errp) { +ERRP_GUARD ();VFIOContainerBase *bcontainer =container_of (listener, VFIOContainerBase, listener);int ret;if (vfio_devices_all_device_dirty_tracking (bcontainer)) { - ret =vfio_devices_dma_logging_start (bcontainer); + ret =vfio_devices_dma_logging_start (bcontainer, errp); }else { - ret =vfio_container_set_dirty_page_tracking (bcontainer, true,NULL ); + ret =vfio_container_set_dirty_page_tracking (bcontainer, true, errp); }if (ret) { -error_report ("vfio: Could not start dirty page tracking, err: %d (%s)" , - ret,strerror (-ret)); -vfio_set_migration_error (ret); +error_prepend (errp,"vfio: Could not start dirty page tracking - " ); }return !ret; }@@ -1091,17 +1092,20 @@ static void vfio_listener_log_global_stop(MemoryListener *listener) {VFIOContainerBase *bcontainer =container_of (listener, VFIOContainerBase, listener); +Error *local_err =NULL ;int ret =0 ;if (vfio_devices_all_device_dirty_tracking (bcontainer)) {vfio_devices_dma_logging_stop (bcontainer); }else { - ret =vfio_container_set_dirty_page_tracking (bcontainer, false,NULL ); + ret =vfio_container_set_dirty_page_tracking (bcontainer, false, + &local_err); }hw/vfio/common.c static void vfio_listener_log_global_stop(MemoryListener *listener) · line 1111
Quoted 10 lines
hw/vfio/common.c +3
-2if (ret) { -error_report ("vfio: Could not stop dirty page tracking, err: %d (%s)" , - ret,strerror (-ret)); +error_prepend (&local_err, +"vfio: Could not stop dirty page tracking - " ); +error_report_err (local_err);vfio_set_migration_error (ret); } }Reviewed-by Eric Auger <[email protected]>Eric
PATCH v6 3/9 migration: Extend migration_file_set_error() with Error* argument
In reply to Cédric Le GoaterUse it to update the current error of the migration stream if available and if not, simply print out the error. Next changes will update with an error to report.
---
Changes in v6:
- Commit log improvements (Avihai)
include/migration/misc.h | 2 +- hw/vfio/common.c | 2 +- hw/vfio/migration.c | 4 ++-- migration/migration.c | 6 ++++-- 4 files changed, 8 insertions(+), 6 deletions(-)
include/migration/misc.h +1 -1
@@ -97,7 +97,7 @@ void migration_add_notifier_mode(NotifierWithReturn *notify,void migration_remove_notifier (NotifierWithReturn *notify);bool migration_is_running (void ); -void migration_file_set_error (int err); +void migration_file_set_error (int ret,Error *err);/* True if incoming migration entered POSTCOPY_INCOMING_DISCARD */ bool migration_in_incoming_postcopy (void );
hw/vfio/common.c +1 -1
@@ -150,7 +150,7 @@ bool vfio_viommu_preset(VFIODevice *vbasedev)static void vfio_set_migration_error (int err) {if (migration_is_setup_or_active ()) { -migration_file_set_error (err); +migration_file_set_error (err,NULL ); } }
hw/vfio/migration.c +2 -2
@@ -726,7 +726,7 @@ static void vfio_vmstate_change_prepare(void *opaque, bool running,* Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ -migration_file_set_error (ret); +migration_file_set_error (ret,NULL ); } trace_vfio_vmstate_change_prepare(vbasedev->name, running,
@@ -756,7 +756,7 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state)* Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ -migration_file_set_error (ret); +migration_file_set_error (ret,NULL ); } trace_vfio_vmstate_change(vbasedev->name, running, RunState_str(state),
migration/migration.c +4 -2
@@ -2994,13 +2994,15 @@ static MigThrError postcopy_pause(MigrationState *s) } } -void migration_file_set_error (int err) +void migration_file_set_error (int ret,Error *err) {MigrationState *s = current_migration; WITH_QEMU_LOCK_GUARD(&s->qemu_file_lock) {if (s->to_dst_file) { -qemu_file_set_error (s->to_dst_file, err); +qemu_file_set_error_obj (s->to_dst_file, ret, err); + }else if (err) { +error_report_err (err); } } }
Signature · 1 line
2.45.0
Re: [PATCH v6 3/9] migration: Extend migration_file_set_error() with Error* argument
Hi Cédric,
Quoted 37 lines · Cédric Le Goater
Use it to update the current error of the migration stream if available and if not, simply print out the error. Next changes will update with an error to report.
Reviewed-by Avihai Horon <[email protected]>Acked-by Fabiano Rosas <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
Changes in v6:
- Commit log improvements (Avihai)
include/migration/misc.h | 2 +- hw/vfio/common.c | 2 +- hw/vfio/migration.c | 4 ++-- migration/migration.c | 6 ++++-- 4 files changed, 8 insertions(+), 6 deletions(-)include/migration/misc.h +1
-1@@ -97,7 +97,7 @@ void migration_add_notifier_mode(NotifierWithReturn *notify,void migration_remove_notifier (NotifierWithReturn *notify);bool migration_is_running (void ); -void migration_file_set_error (int err); +void migration_file_set_error (int ret,Error *err);/* True if incoming migration entered POSTCOPY_INCOMING_DISCARD */ bool migration_in_incoming_postcopy (void );hw/vfio/common.c +0
-0
hw/vfio/common.c bool vfio_viommu_preset(VFIODevice *vbasedev) · line 150
Quoted 1 line
hw/vfio/common.c +0
-0@@ -150,7 +150,7 @@ bool vfio_viommu_preset(VFIODevice *vbasedev)static void vfio_set_migration_error (int err)
nit: I would have renamed err into ret here to avoid any further confusion.
Quoted 41 lines
hw/vfio/common.c +1
-1{if (migration_is_setup_or_active ()) { -migration_file_set_error (err); +migration_file_set_error (err,NULL ); } }hw/vfio/migration.c +2
-2@@ -726,7 +726,7 @@ static void vfio_vmstate_change_prepare(void *opaque, bool running,* Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ -migration_file_set_error (ret); +migration_file_set_error (ret,NULL ); } trace_vfio_vmstate_change_prepare(vbasedev->name, running,@@ -756,7 +756,7 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state)* Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ -migration_file_set_error (ret); +migration_file_set_error (ret,NULL ); } trace_vfio_vmstate_change(vbasedev->name, running, RunState_str(state),migration/migration.c +1
-1@@ -2994,13 +2994,15 @@ static MigThrError postcopy_pause(MigrationState *s) } } -void migration_file_set_error (int err) +void migration_file_set_error (int ret,Error *err) {MigrationState *s = current_migration;
migration/migration.c static MigThrError postcopy_pause(MigrationState *s) · line 3008
Quoted 10 lines
migration/migration.c +3
-1WITH_QEMU_LOCK_GUARD(&s->qemu_file_lock) {if (s->to_dst_file) { -qemu_file_set_error (s->to_dst_file, err); +qemu_file_set_error_obj (s->to_dst_file, ret, err); + }else if (err) { +error_report_err (err); } } }
Eric
Re: [PATCH v6 3/9] migration: Extend migration_file_set_error() with Error* argument
Quoted 33 lines · Eric Auger
Hi Cédric,
Quoted 30 lines · Cédric Le Goater
Use it to update the current error of the migration stream if available and if not, simply print out the error. Next changes will update with an error to report.
Reviewed-by Avihai Horon <[email protected]>Acked-by Fabiano Rosas <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
Changes in v6:
- Commit log improvements (Avihai)
include/migration/misc.h | 2 +- hw/vfio/common.c | 2 +- hw/vfio/migration.c | 4 ++-- migration/migration.c | 6 ++++-- 4 files changed, 8 insertions(+), 6 deletions(-)include/migration/misc.h +1
-1@@ -97,7 +97,7 @@ void migration_add_notifier_mode(NotifierWithReturn *notify,void migration_remove_notifier (NotifierWithReturn *notify);bool migration_is_running (void ); -void migration_file_set_error (int err); +void migration_file_set_error (int ret,Error *err);
Quoted 9 lines
hw/vfio/common.c bool vfio_viommu_preset(VFIODevice *vbasedev) · line 150
Quoted 8 lines
include/migration/misc.h +0
-0/* True if incoming migration entered POSTCOPY_INCOMING_DISCARD */ bool migration_in_incoming_postcopy (void );hw/vfio/common.c +0
-0@@ -150,7 +150,7 @@ bool vfio_viommu_preset(VFIODevice *vbasedev)static void vfio_set_migration_error (int err)nit: I would have renamed err into ret here to avoid any further confusion.
That was done in v5 :
https://lore.kernel.org/qemu-devel/[email protected]/
in the last patch, that I dropped in v6 because I believe it needs more work. I will address these last changes, including the err->ret rename, in a followup series if that's ok with you.
Thanks,
C.
Quoted 55 lines
Quoted 41 lines
hw/vfio/common.c +1
-1{if (migration_is_setup_or_active ()) { -migration_file_set_error (err); +migration_file_set_error (err,NULL ); } }hw/vfio/migration.c +2
-2@@ -726,7 +726,7 @@ static void vfio_vmstate_change_prepare(void *opaque, bool running,* Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ -migration_file_set_error (ret); +migration_file_set_error (ret,NULL ); } trace_vfio_vmstate_change_prepare(vbasedev->name, running,@@ -756,7 +756,7 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state)* Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ -migration_file_set_error (ret); +migration_file_set_error (ret,NULL ); } trace_vfio_vmstate_change(vbasedev->name, running, RunState_str(state),migration/migration.c +1
-1@@ -2994,13 +2994,15 @@ static MigThrError postcopy_pause(MigrationState *s) } } -void migration_file_set_error (int err) +void migration_file_set_error (int ret,Error *err) {MigrationState *s = current_migration;migration/migration.c static MigThrError postcopy_pause(MigrationState *s) · line 3008
Quoted 10 lines
migration/migration.c +3
-1WITH_QEMU_LOCK_GUARD(&s->qemu_file_lock) {if (s->to_dst_file) { -qemu_file_set_error (s->to_dst_file, err); +qemu_file_set_error_obj (s->to_dst_file, ret, err); + }else if (err) { +error_report_err (err); } } }Reviewed-by Eric Auger <[email protected]>Eric
PATCH v6 4/9 vfio/migration: Add an Error** argument to vfio_migration_set_state()
In reply to Cédric Le GoaterAdd an Error** argument to vfio_migration_set_state() and adjust callers, including vfio_save_setup(). The error will be propagated up to qemu_savevm_state_setup() where the save_setup() handler is executed.
Modify vfio_vmstate_change_prepare() and vfio_vmstate_change() to store a reported error under the migration stream if a migration is in progress.
---
Changes in v6:
- Commit log improvements (Avihai)
- vfio_migration_set_state() : Dropped the error_setg_errno() change when setting device in recover state fails (Avihai)
- vfio_migration_state_notifier() : report local error (Avihai)
Changes in v5:
- Replaced error_setg() by error_setg_errno() in vfio_migration_set_state()
- Rebased on 20c64c8a51a4 ("migration: migration_file_set_error")
hw/vfio/migration.c | 77 ++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 29 deletions(-)
hw/vfio/migration.c +48 -29
@@ -82,7 +82,8 @@ static const char *mig_state_to_str(enum vfio_device_mig_state state)static int vfio_migration_set_state (VFIODevice *vbasedev,enum vfio_device_mig_state new_state, -enum vfio_device_mig_state recover_state) +enum vfio_device_mig_state recover_state, +Error **errp) {VFIOMigration *migration = vbasedev->migration; uint64_t buf[DIV_ROUND_UP(sizeof(struct vfio_device_feature) +
@@ -102,18 +103,19 @@ static int vfio_migration_set_state(VFIODevice *vbasedev, ret = -errno;if (recover_state ==VFIO_DEVICE_STATE_ERROR ) { -error_report ("%s: Failed setting device state to %s, err: %s. " -"Recover state is ERROR. Resetting device" , - vbasedev->name,mig_state_to_str (new_state), -strerror (errno)); +error_setg_errno (errp, errno, +"%s: Failed setting device state to %s. " +"Recover state is ERROR. Resetting device" , + vbasedev->name,mig_state_to_str (new_state)); goto reset_device; } -error_report ( -"%s: Failed setting device state to %s, err: %s. Setting device in recover state %s" , - vbasedev->name,mig_state_to_str (new_state), -strerror (errno),mig_state_to_str (recover_state)); +error_setg_errno (errp, errno, +"%s: Failed setting device state to %s. " +"Setting device in recover state %s" , + vbasedev->name,mig_state_to_str (new_state), +mig_state_to_str (recover_state)); mig_state->device_state = recover_state;if (ioctl (vbasedev->fd,VFIO_DEVICE_FEATURE , feature)) {
@@ -137,7 +139,7 @@ static int vfio_migration_set_state(VFIODevice *vbasedev,* This can happen if the device is asynchronously reset and * terminates a data transfer. */ -error_report ("%s: data_fd out of sync" , vbasedev->name); +error_setg (errp,"%s: data_fd out of sync" , vbasedev->name);close (mig_state->data_fd);return -EBADF ;
@@ -168,10 +170,11 @@ reset_device:*/ static int vfio_migration_set_state_or_reset (VFIODevice *vbasedev, -enum vfio_device_mig_state new_state) +enum vfio_device_mig_state new_state, +Error **errp) {return vfio_migration_set_state (vbasedev, new_state, -VFIO_DEVICE_STATE_ERROR ); +VFIO_DEVICE_STATE_ERROR , errp); } static int vfio_load_buffer(QEMUFile *f, VFIODevice *vbasedev,
@@ -399,10 +402,8 @@ static int vfio_save_setup(QEMUFile *f, void *opaque, Error **errp)switch (migration->device_state) {case VFIO_DEVICE_STATE_RUNNING : ret =vfio_migration_set_state (vbasedev,VFIO_DEVICE_STATE_PRE_COPY , -VFIO_DEVICE_STATE_RUNNING ); +VFIO_DEVICE_STATE_RUNNING , errp);if (ret) { -error_setg (errp,"%s: Failed to set new PRE_COPY state" , - vbasedev->name);return ret; }
@@ -435,13 +436,20 @@ static void vfio_save_cleanup(void *opaque) {VFIODevice *vbasedev = opaque;VFIOMigration *migration = vbasedev->migration; +Error *local_err =NULL ; +int ret;/* * Changing device state from STOP_COPY to STOP can take time. Do it here, * after migration has completed, so it won't increase downtime. */ if (migration->device_state ==VFIO_DEVICE_STATE_STOP_COPY ) { -vfio_migration_set_state_or_reset (vbasedev,VFIO_DEVICE_STATE_STOP ); + ret =vfio_migration_set_state_or_reset (vbasedev, +VFIO_DEVICE_STATE_STOP , + &local_err); +if (ret) { +error_report_err (local_err); + } }g_free (migration->data_buffer);
@@ -549,11 +557,13 @@ static int vfio_save_complete_precopy(QEMUFile *f, void *opaque)VFIODevice *vbasedev = opaque;ssize_t data_size;int ret; +Error *local_err =NULL ;/* We reach here with device state STOP or STOP_COPY only */ ret =vfio_migration_set_state (vbasedev,VFIO_DEVICE_STATE_STOP_COPY , -VFIO_DEVICE_STATE_STOP ); +VFIO_DEVICE_STATE_STOP , &local_err);if (ret) { +error_report_err (local_err);return ret; }
@@ -591,14 +601,9 @@ static void vfio_save_state(QEMUFile *f, void *opaque)static int vfio_load_setup (QEMUFile *f,void *opaque,Error **errp) {VFIODevice *vbasedev = opaque; -int ret; - ret =vfio_migration_set_state (vbasedev,VFIO_DEVICE_STATE_RESUMING , - vbasedev->migration->device_state); -if (ret) { -error_setg (errp,"%s: Failed to set RESUMING state" , vbasedev->name); - } -return ret; +return vfio_migration_set_state (vbasedev,VFIO_DEVICE_STATE_RESUMING , + vbasedev->migration->device_state, errp); }static int vfio_load_cleanup (void *opaque)
@@ -714,19 +719,20 @@ static void vfio_vmstate_change_prepare(void *opaque, bool running,VFIODevice *vbasedev = opaque;VFIOMigration *migration = vbasedev->migration;enum vfio_device_mig_state new_state; +Error *local_err =NULL ;int ret; new_state = migration->device_state ==VFIO_DEVICE_STATE_PRE_COPY ?VFIO_DEVICE_STATE_PRE_COPY_P2P :VFIO_DEVICE_STATE_RUNNING_P2P ; - ret =vfio_migration_set_state_or_reset (vbasedev, new_state); + ret =vfio_migration_set_state_or_reset (vbasedev, new_state, &local_err);if (ret) {/* * Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ -migration_file_set_error (ret,NULL ); +migration_file_set_error (ret, local_err); } trace_vfio_vmstate_change_prepare(vbasedev->name, running,
@@ -738,6 +744,7 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state) {VFIODevice *vbasedev = opaque;enum vfio_device_mig_state new_state; +Error *local_err =NULL ;int ret;if (running) {
@@ -750,13 +757,13 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state)VFIO_DEVICE_STATE_STOP ; } - ret =vfio_migration_set_state_or_reset (vbasedev, new_state); + ret =vfio_migration_set_state_or_reset (vbasedev, new_state, &local_err);if (ret) {/* * Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ -migration_file_set_error (ret,NULL ); +migration_file_set_error (ret, local_err); } trace_vfio_vmstate_change(vbasedev->name, running, RunState_str(state),
@@ -769,11 +776,23 @@ static int vfio_migration_state_notifier(NotifierWithReturn *notifier,VFIOMigration *migration =container_of (notifier, VFIOMigration, migration_state);VFIODevice *vbasedev = migration->vbasedev; +Error *local_err =NULL ; +int ret =0 ;trace_vfio_migration_state_notifier (vbasedev->name, e->type);if (e->type ==MIG_EVENT_PRECOPY_FAILED ) { -vfio_migration_set_state_or_reset (vbasedev,VFIO_DEVICE_STATE_RUNNING ); +/* +* MigrationNotifyFunc may return an error code and an Error +* object only for MIG_EVENT_PRECOPY_SETUP. Hence, report the +* error locally and ignore the errp argument. +*/ + ret =vfio_migration_set_state_or_reset (vbasedev, +VFIO_DEVICE_STATE_RUNNING , + &local_err); +if (ret) { +error_report_err (local_err); + } }return 0 ; }
Signature · 1 line
2.45.0
Re: [PATCH v6 4/9] vfio/migration: Add an Error** argument to vfio_migration_set_state()
Hi Cédric,
Quoted 43 lines · Cédric Le Goater
Add an Error** argument to
vfio_migration_set_state()and adjust callers, includingvfio_save_setup(). The error will be propagated up toqemu_savevm_state_setup()where thesave_setup()handler is executed.Modify
vfio_vmstate_change_prepare()andvfio_vmstate_change()to store a reported error under the migration stream if a migration is in progress.Signed-off-by Cédric Le Goater <[email protected]>---
Changes in v6:
- Commit log improvements (Avihai)
-vfio_migration_set_state(): Dropped theerror_setg_errno()change when setting device in recover state fails (Avihai)
-vfio_migration_state_notifier(): report local error (Avihai)Changes in v5:
- Replaced
error_setg()byerror_setg_errno()invfio_migration_set_state()
- Rebased on20c64c8a51a4("migration:migration_file_set_error")hw/vfio/migration.c | 77 ++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 29 deletions(-)hw/vfio/migration.c +2
-1@@ -82,7 +82,8 @@ static const char *mig_state_to_str(enum vfio_device_mig_state state)static int vfio_migration_set_state (VFIODevice *vbasedev,enum vfio_device_mig_state new_state, -enum vfio_device_mig_state recover_state) +enum vfio_device_mig_state recover_state, +Error **errp) {VFIOMigration *migration = vbasedev->migration; uint64_t buf[DIV_ROUND_UP(sizeof(struct vfio_device_feature) +@@ -102,18 +103,19 @@ static int vfio_migration_set_state(VFIODevice *vbasedev, ret = -errno;
hw/vfio/migration.c static int vfio_migration_set_state(VFIODevice *vbasedev, · line 109
Quoted 10 lines
hw/vfio/migration.c +4
-4if (recover_state ==VFIO_DEVICE_STATE_ERROR ) { -error_report ("%s: Failed setting device state to %s, err: %s. " -"Recover state is ERROR. Resetting device" , - vbasedev->name,mig_state_to_str (new_state), -strerror (errno)); +error_setg_errno (errp, errno, +"%s: Failed setting device state to %s. " +"Recover state is ERROR. Resetting device" , + vbasedev->name,mig_state_to_str (new_state));
nit: this may be simplified
with a first unconditional msg saying Failed setting device state to %s. Recover state is %s.
and not duplicating the msg.
In the reset label you can prepend "resetting the device ..."
Quoted 5 lines
hw/vfio/migration.c +0
-1goto reset_device; } - error_report(
hw/vfio/migration.c static int vfio_migration_set_state(VFIODevice *vbasedev, · line 121
Quoted 10 lines
hw/vfio/migration.c +5
-3-"%s: Failed setting device state to %s, err: %s. Setting device in recover state %s" , - vbasedev->name,mig_state_to_str (new_state), - strerror(errno), mig_state_to_str(recover_state)); +error_setg_errno (errp, errno, +"%s: Failed setting device state to %s. " +"Setting device in recover state %s" , + vbasedev->name,mig_state_to_str (new_state), + mig_state_to_str(recover_state));> mig_state->device_state = recover_state;if (ioctl (vbasedev->fd,VFIO_DEVICE_FEATURE , feature)) {
in case you fail setting the device in recover state, your simply error_report() and do not prepend any other msg in the error handle. Is it what you want? In the positive, maybe worth a comment.
Quoted 151 lines
hw/vfio/migration.c +30
-20@@ -137,7 +139,7 @@ static int vfio_migration_set_state(VFIODevice *vbasedev,* This can happen if the device is asynchronously reset and * terminates a data transfer. */ -error_report ("%s: data_fd out of sync" , vbasedev->name); +error_setg (errp,"%s: data_fd out of sync" , vbasedev->name);close (mig_state->data_fd);return -EBADF ;@@ -168,10 +170,11 @@ reset_device:*/ static int vfio_migration_set_state_or_reset (VFIODevice *vbasedev, -enum vfio_device_mig_state new_state) +enum vfio_device_mig_state new_state, +Error **errp) {return vfio_migration_set_state (vbasedev, new_state, -VFIO_DEVICE_STATE_ERROR ); +VFIO_DEVICE_STATE_ERROR , errp); } static int vfio_load_buffer(QEMUFile *f, VFIODevice *vbasedev,@@ -399,10 +402,8 @@ static int vfio_save_setup(QEMUFile *f, void *opaque, Error **errp)switch (migration->device_state) {case VFIO_DEVICE_STATE_RUNNING : ret =vfio_migration_set_state (vbasedev,VFIO_DEVICE_STATE_PRE_COPY , -VFIO_DEVICE_STATE_RUNNING ); +VFIO_DEVICE_STATE_RUNNING , errp);if (ret) { -error_setg (errp,"%s: Failed to set new PRE_COPY state" , - vbasedev->name);return ret; }@@ -435,13 +436,20 @@ static void vfio_save_cleanup(void *opaque) {VFIODevice *vbasedev = opaque;VFIOMigration *migration = vbasedev->migration; +Error *local_err =NULL ; +int ret;/* * Changing device state from STOP_COPY to STOP can take time. Do it here, * after migration has completed, so it won't increase downtime. */ if (migration->device_state ==VFIO_DEVICE_STATE_STOP_COPY ) { -vfio_migration_set_state_or_reset (vbasedev,VFIO_DEVICE_STATE_STOP ); + ret =vfio_migration_set_state_or_reset (vbasedev, +VFIO_DEVICE_STATE_STOP , + &local_err); +if (ret) { +error_report_err (local_err); + } }g_free (migration->data_buffer);@@ -549,11 +557,13 @@ static int vfio_save_complete_precopy(QEMUFile *f, void *opaque)VFIODevice *vbasedev = opaque;ssize_t data_size;int ret; +Error *local_err =NULL ;/* We reach here with device state STOP or STOP_COPY only */ ret =vfio_migration_set_state (vbasedev,VFIO_DEVICE_STATE_STOP_COPY , -VFIO_DEVICE_STATE_STOP ); +VFIO_DEVICE_STATE_STOP , &local_err);if (ret) { +error_report_err (local_err);return ret; }@@ -591,14 +601,9 @@ static void vfio_save_state(QEMUFile *f, void *opaque)static int vfio_load_setup (QEMUFile *f,void *opaque,Error **errp) {VFIODevice *vbasedev = opaque; -int ret; - ret =vfio_migration_set_state (vbasedev,VFIO_DEVICE_STATE_RESUMING , - vbasedev->migration->device_state); -if (ret) { -error_setg (errp,"%s: Failed to set RESUMING state" , vbasedev->name); - } -return ret; +return vfio_migration_set_state (vbasedev,VFIO_DEVICE_STATE_RESUMING , + vbasedev->migration->device_state, errp); }static int vfio_load_cleanup (void *opaque)@@ -714,19 +719,20 @@ static void vfio_vmstate_change_prepare(void *opaque, bool running,VFIODevice *vbasedev = opaque;VFIOMigration *migration = vbasedev->migration;enum vfio_device_mig_state new_state; +Error *local_err =NULL ;int ret; new_state = migration->device_state ==VFIO_DEVICE_STATE_PRE_COPY ?VFIO_DEVICE_STATE_PRE_COPY_P2P :VFIO_DEVICE_STATE_RUNNING_P2P ; - ret =vfio_migration_set_state_or_reset (vbasedev, new_state); + ret =vfio_migration_set_state_or_reset (vbasedev, new_state, &local_err);if (ret) {/* * Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ -migration_file_set_error (ret,NULL ); +migration_file_set_error (ret, local_err); } trace_vfio_vmstate_change_prepare(vbasedev->name, running,@@ -738,6 +744,7 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state) {VFIODevice *vbasedev = opaque;enum vfio_device_mig_state new_state; +Error *local_err =NULL ;int ret;if (running) {@@ -750,13 +757,13 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state)VFIO_DEVICE_STATE_STOP ; } - ret =vfio_migration_set_state_or_reset (vbasedev, new_state); + ret =vfio_migration_set_state_or_reset (vbasedev, new_state, &local_err);if (ret) {/* * Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ -migration_file_set_error (ret,NULL ); +migration_file_set_error (ret, local_err); } trace_vfio_vmstate_change(vbasedev->name, running, RunState_str(state),@@ -769,11 +776,23 @@ static int vfio_migration_state_notifier(NotifierWithReturn *notifier,VFIOMigration *migration =container_of (notifier, VFIOMigration, migration_state);VFIODevice *vbasedev = migration->vbasedev; +Error *local_err =NULL ; +int ret =0 ;trace_vfio_migration_state_notifier (vbasedev->name, e->type);if (e->type ==MIG_EVENT_PRECOPY_FAILED ) { -vfio_migration_set_state_or_reset (vbasedev,VFIO_DEVICE_STATE_RUNNING ); +/* +* MigrationNotifyFunc may return an error code and an Error +* object only for MIG_EVENT_PRECOPY_SETUP. Hence, report the +* error locally and ignore the errp argument.
hw/vfio/migration.c static int vfio_migration_state_notifier(NotifierWithReturn *notifier, · line 798
Quoted 10 lines
hw/vfio/migration.c +7
-0+*/ + ret =vfio_migration_set_state_or_reset (vbasedev, +VFIO_DEVICE_STATE_RUNNING , + &local_err); +if (ret) { +error_report_err (local_err); + } }return 0 ; }
Thanks
Eric
Re: [PATCH v6 4/9] vfio/migration: Add an Error** argument to vfio_migration_set_state()
Quoted 61 lines · Eric Auger
Hi Cédric,
Quoted 43 lines · Cédric Le Goater
Add an Error** argument to
vfio_migration_set_state()and adjust callers, includingvfio_save_setup(). The error will be propagated up toqemu_savevm_state_setup()where thesave_setup()handler is executed.Modify
vfio_vmstate_change_prepare()andvfio_vmstate_change()to store a reported error under the migration stream if a migration is in progress.Signed-off-by Cédric Le Goater <[email protected]>---
Changes in v6:
- Commit log improvements (Avihai)
-vfio_migration_set_state(): Dropped theerror_setg_errno()change when setting device in recover state fails (Avihai)
-vfio_migration_state_notifier(): report local error (Avihai)Changes in v5:
- Replaced
error_setg()byerror_setg_errno()invfio_migration_set_state()
- Rebased on20c64c8a51a4("migration:migration_file_set_error")hw/vfio/migration.c | 77 ++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 29 deletions(-)hw/vfio/migration.c +2
-1@@ -82,7 +82,8 @@ static const char *mig_state_to_str(enum vfio_device_mig_state state)static int vfio_migration_set_state (VFIODevice *vbasedev,enum vfio_device_mig_state new_state, -enum vfio_device_mig_state recover_state) +enum vfio_device_mig_state recover_state, +Error **errp) {VFIOMigration *migration = vbasedev->migration; uint64_t buf[DIV_ROUND_UP(sizeof(struct vfio_device_feature) +@@ -102,18 +103,19 @@ static int vfio_migration_set_state(VFIODevice *vbasedev, ret = -errno;hw/vfio/migration.c static int vfio_migration_set_state(VFIODevice *vbasedev, · line 109
Quoted 10 lines
hw/vfio/migration.c +4
-4if (recover_state ==VFIO_DEVICE_STATE_ERROR ) { -error_report ("%s: Failed setting device state to %s, err: %s. " -"Recover state is ERROR. Resetting device" , - vbasedev->name,mig_state_to_str (new_state), -strerror (errno)); +error_setg_errno (errp, errno, +"%s: Failed setting device state to %s. " +"Recover state is ERROR. Resetting device" , + vbasedev->name,mig_state_to_str (new_state));nit: this may be simplified
with a first unconditional msg saying Failed setting device state to %s. Recover state is %s.
and not duplicating the msg.
Quoted 1 line
In the reset label you can prepend "resetting the device ..."
I agree.
I'd rather do that in a followup patch after ther error_setg_* changes. Adding to the TODO list.
Quoted 15 lines
Quoted 5 lines
hw/vfio/migration.c +0
-1goto reset_device; } - error_report(hw/vfio/migration.c static int vfio_migration_set_state(VFIODevice *vbasedev, · line 121
Quoted 10 lines
hw/vfio/migration.c +5
-3-"%s: Failed setting device state to %s, err: %s. Setting device in recover state %s" , - vbasedev->name,mig_state_to_str (new_state), - strerror(errno), mig_state_to_str(recover_state)); +error_setg_errno (errp, errno, +"%s: Failed setting device state to %s. " +"Setting device in recover state %s" , + vbasedev->name,mig_state_to_str (new_state), + mig_state_to_str(recover_state));> mig_state->device_state = recover_state;if (ioctl (vbasedev->fd,VFIO_DEVICE_FEATURE , feature)) {
Quoted 3 lines
in case you fail setting the device in recover state, your simply
error_report()and do not prepend any other msg in the error handle. Is it what you want?
yes. Otherwise, we loose the previous error message, which I think is more important to report (first error). The following error_report handles an error of an error, which can go on stderr.
Quoted 1 line
In the positive, maybe worth a comment.
OK, to avoid a resend, I will amend the patch with:
mig_state->device_state = recover_state;
if (ioctl(vbasedev->fd, VFIO_DEVICE_FEATURE, feature)) {
ret = -errno;
+ /*
+ * If setting the device in recover state fails, report
+ * the error here and propagate the first error.
+ */
error_report(
"%s: Failed setting device in recover state, err: %s. Resetting device",
vbasedev->name, strerror(errno));Thanks,
C.
Quoted 165 lines
Quoted 151 lines
hw/vfio/migration.c +30
-20@@ -137,7 +139,7 @@ static int vfio_migration_set_state(VFIODevice *vbasedev,* This can happen if the device is asynchronously reset and * terminates a data transfer. */ -error_report ("%s: data_fd out of sync" , vbasedev->name); +error_setg (errp,"%s: data_fd out of sync" , vbasedev->name);close (mig_state->data_fd);return -EBADF ;@@ -168,10 +170,11 @@ reset_device:*/ static int vfio_migration_set_state_or_reset (VFIODevice *vbasedev, -enum vfio_device_mig_state new_state) +enum vfio_device_mig_state new_state, +Error **errp) {return vfio_migration_set_state (vbasedev, new_state, -VFIO_DEVICE_STATE_ERROR ); +VFIO_DEVICE_STATE_ERROR , errp); } static int vfio_load_buffer(QEMUFile *f, VFIODevice *vbasedev,@@ -399,10 +402,8 @@ static int vfio_save_setup(QEMUFile *f, void *opaque, Error **errp)switch (migration->device_state) {case VFIO_DEVICE_STATE_RUNNING : ret =vfio_migration_set_state (vbasedev,VFIO_DEVICE_STATE_PRE_COPY , -VFIO_DEVICE_STATE_RUNNING ); +VFIO_DEVICE_STATE_RUNNING , errp);if (ret) { -error_setg (errp,"%s: Failed to set new PRE_COPY state" , - vbasedev->name);return ret; }@@ -435,13 +436,20 @@ static void vfio_save_cleanup(void *opaque) {VFIODevice *vbasedev = opaque;VFIOMigration *migration = vbasedev->migration; +Error *local_err =NULL ; +int ret;/* * Changing device state from STOP_COPY to STOP can take time. Do it here, * after migration has completed, so it won't increase downtime. */ if (migration->device_state ==VFIO_DEVICE_STATE_STOP_COPY ) { -vfio_migration_set_state_or_reset (vbasedev,VFIO_DEVICE_STATE_STOP ); + ret =vfio_migration_set_state_or_reset (vbasedev, +VFIO_DEVICE_STATE_STOP , + &local_err); +if (ret) { +error_report_err (local_err); + } }g_free (migration->data_buffer);@@ -549,11 +557,13 @@ static int vfio_save_complete_precopy(QEMUFile *f, void *opaque)VFIODevice *vbasedev = opaque;ssize_t data_size;int ret; +Error *local_err =NULL ;/* We reach here with device state STOP or STOP_COPY only */ ret =vfio_migration_set_state (vbasedev,VFIO_DEVICE_STATE_STOP_COPY , -VFIO_DEVICE_STATE_STOP ); +VFIO_DEVICE_STATE_STOP , &local_err);if (ret) { +error_report_err (local_err);return ret; }@@ -591,14 +601,9 @@ static void vfio_save_state(QEMUFile *f, void *opaque)static int vfio_load_setup (QEMUFile *f,void *opaque,Error **errp) {VFIODevice *vbasedev = opaque; -int ret; - ret =vfio_migration_set_state (vbasedev,VFIO_DEVICE_STATE_RESUMING , - vbasedev->migration->device_state); -if (ret) { -error_setg (errp,"%s: Failed to set RESUMING state" , vbasedev->name); - } -return ret; +return vfio_migration_set_state (vbasedev,VFIO_DEVICE_STATE_RESUMING , + vbasedev->migration->device_state, errp); }static int vfio_load_cleanup (void *opaque)@@ -714,19 +719,20 @@ static void vfio_vmstate_change_prepare(void *opaque, bool running,VFIODevice *vbasedev = opaque;VFIOMigration *migration = vbasedev->migration;enum vfio_device_mig_state new_state; +Error *local_err =NULL ;int ret; new_state = migration->device_state ==VFIO_DEVICE_STATE_PRE_COPY ?VFIO_DEVICE_STATE_PRE_COPY_P2P :VFIO_DEVICE_STATE_RUNNING_P2P ; - ret =vfio_migration_set_state_or_reset (vbasedev, new_state); + ret =vfio_migration_set_state_or_reset (vbasedev, new_state, &local_err);if (ret) {/* * Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ -migration_file_set_error (ret,NULL ); +migration_file_set_error (ret, local_err); } trace_vfio_vmstate_change_prepare(vbasedev->name, running,@@ -738,6 +744,7 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state) {VFIODevice *vbasedev = opaque;enum vfio_device_mig_state new_state; +Error *local_err =NULL ;int ret;if (running) {@@ -750,13 +757,13 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state)VFIO_DEVICE_STATE_STOP ; } - ret =vfio_migration_set_state_or_reset (vbasedev, new_state); + ret =vfio_migration_set_state_or_reset (vbasedev, new_state, &local_err);if (ret) {/* * Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ -migration_file_set_error (ret,NULL ); +migration_file_set_error (ret, local_err); } trace_vfio_vmstate_change(vbasedev->name, running, RunState_str(state),@@ -769,11 +776,23 @@ static int vfio_migration_state_notifier(NotifierWithReturn *notifier,VFIOMigration *migration =container_of (notifier, VFIOMigration, migration_state);VFIODevice *vbasedev = migration->vbasedev; +Error *local_err =NULL ; +int ret =0 ;trace_vfio_migration_state_notifier (vbasedev->name, e->type);if (e->type ==MIG_EVENT_PRECOPY_FAILED ) { -vfio_migration_set_state_or_reset (vbasedev,VFIO_DEVICE_STATE_RUNNING ); +/* +* MigrationNotifyFunc may return an error code and an Error +* object only for MIG_EVENT_PRECOPY_SETUP. Hence, report the +* error locally and ignore the errp argument. hw/vfio/migration.c static int vfio_migration_state_notifier(NotifierWithReturn *notifier, · line 798
Quoted 10 lines
hw/vfio/migration.c +7
-0+*/ + ret =vfio_migration_set_state_or_reset (vbasedev, +VFIO_DEVICE_STATE_RUNNING , + &local_err); +if (ret) { +error_report_err (local_err); + } }return 0 ; }Thanks
Eric
Re: [PATCH v6 4/9] vfio/migration: Add an Error** argument to vfio_migration_set_state()
In reply to Cédric Le GoaterQuoted 8 lines · Cédric Le Goater
External email: Use caution opening links or attachments
Add an Error** argument to
vfio_migration_set_state()and adjust callers, includingvfio_save_setup(). The error will be propagated up toqemu_savevm_state_setup()where thesave_setup()handler is executed.
Quoted 5 lines
Modify
vfio_vmstate_change_prepare()andvfio_vmstate_change()to store a reported error under the migration stream if a migration is in progress.Signed-off-by Cédric Le Goater <[email protected]>
With/without Eric's suggestion:
Two nits below though (if you respin or want to amend inline).
Quoted 196 lines
---
Changes in v6:
- Commit log improvements (Avihai)
-vfio_migration_set_state(): Dropped theerror_setg_errno()change when setting device in recover state fails (Avihai)
-vfio_migration_state_notifier(): report local error (Avihai)Changes in v5:
- Replaced
error_setg()byerror_setg_errno()invfio_migration_set_state()
- Rebased on20c64c8a51a4("migration:migration_file_set_error")hw/vfio/migration.c | 77 ++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 29 deletions(-)hw/vfio/migration.c +35
-28@@ -82,7 +82,8 @@ static const char *mig_state_to_str(enum vfio_device_mig_state state)static int vfio_migration_set_state (VFIODevice *vbasedev,enum vfio_device_mig_state new_state, -enum vfio_device_mig_state recover_state) +enum vfio_device_mig_state recover_state, +Error **errp) {VFIOMigration *migration = vbasedev->migration; uint64_t buf[DIV_ROUND_UP(sizeof(struct vfio_device_feature) +@@ -102,18 +103,19 @@ static int vfio_migration_set_state(VFIODevice *vbasedev, ret = -errno;if (recover_state ==VFIO_DEVICE_STATE_ERROR ) { -error_report ("%s: Failed setting device state to %s, err: %s. " -"Recover state is ERROR. Resetting device" , - vbasedev->name,mig_state_to_str (new_state), -strerror (errno)); +error_setg_errno (errp, errno, +"%s: Failed setting device state to %s. " +"Recover state is ERROR. Resetting device" , + vbasedev->name,mig_state_to_str (new_state)); goto reset_device; } -error_report ( -"%s: Failed setting device state to %s, err: %s. Setting device in recover state %s" , - vbasedev->name,mig_state_to_str (new_state), -strerror (errno),mig_state_to_str (recover_state)); +error_setg_errno (errp, errno, +"%s: Failed setting device state to %s. " +"Setting device in recover state %s" , + vbasedev->name,mig_state_to_str (new_state), +mig_state_to_str (recover_state)); mig_state->device_state = recover_state;if (ioctl (vbasedev->fd,VFIO_DEVICE_FEATURE , feature)) {@@ -137,7 +139,7 @@ static int vfio_migration_set_state(VFIODevice *vbasedev,* This can happen if the device is asynchronously reset and * terminates a data transfer. */ -error_report ("%s: data_fd out of sync" , vbasedev->name); +error_setg (errp,"%s: data_fd out of sync" , vbasedev->name);close (mig_state->data_fd);return -EBADF ;@@ -168,10 +170,11 @@ reset_device:*/ static int vfio_migration_set_state_or_reset (VFIODevice *vbasedev, -enum vfio_device_mig_state new_state) +enum vfio_device_mig_state new_state, +Error **errp) {return vfio_migration_set_state (vbasedev, new_state, -VFIO_DEVICE_STATE_ERROR ); +VFIO_DEVICE_STATE_ERROR , errp); } static int vfio_load_buffer(QEMUFile *f, VFIODevice *vbasedev,@@ -399,10 +402,8 @@ static int vfio_save_setup(QEMUFile *f, void *opaque, Error **errp)switch (migration->device_state) {case VFIO_DEVICE_STATE_RUNNING : ret =vfio_migration_set_state (vbasedev,VFIO_DEVICE_STATE_PRE_COPY , -VFIO_DEVICE_STATE_RUNNING ); +VFIO_DEVICE_STATE_RUNNING , errp);if (ret) { -error_setg (errp,"%s: Failed to set new PRE_COPY state" , - vbasedev->name);return ret; }@@ -435,13 +436,20 @@ static void vfio_save_cleanup(void *opaque) {VFIODevice *vbasedev = opaque;VFIOMigration *migration = vbasedev->migration; +Error *local_err =NULL ; +int ret;/* * Changing device state from STOP_COPY to STOP can take time. Do it here, * after migration has completed, so it won't increase downtime. */ if (migration->device_state ==VFIO_DEVICE_STATE_STOP_COPY ) { -vfio_migration_set_state_or_reset (vbasedev,VFIO_DEVICE_STATE_STOP ); + ret =vfio_migration_set_state_or_reset (vbasedev, +VFIO_DEVICE_STATE_STOP , + &local_err); +if (ret) { +error_report_err (local_err); + } }g_free (migration->data_buffer);@@ -549,11 +557,13 @@ static int vfio_save_complete_precopy(QEMUFile *f, void *opaque)VFIODevice *vbasedev = opaque;ssize_t data_size;int ret; +Error *local_err =NULL ;/* We reach here with device state STOP or STOP_COPY only */ ret =vfio_migration_set_state (vbasedev,VFIO_DEVICE_STATE_STOP_COPY , -VFIO_DEVICE_STATE_STOP ); +VFIO_DEVICE_STATE_STOP , &local_err);if (ret) { +error_report_err (local_err);return ret; }@@ -591,14 +601,9 @@ static void vfio_save_state(QEMUFile *f, void *opaque)static int vfio_load_setup (QEMUFile *f,void *opaque,Error **errp) {VFIODevice *vbasedev = opaque; -int ret; - ret =vfio_migration_set_state (vbasedev,VFIO_DEVICE_STATE_RESUMING , - vbasedev->migration->device_state); -if (ret) { -error_setg (errp,"%s: Failed to set RESUMING state" , vbasedev->name); - } -return ret; +return vfio_migration_set_state (vbasedev,VFIO_DEVICE_STATE_RESUMING , + vbasedev->migration->device_state, errp); }static int vfio_load_cleanup (void *opaque)@@ -714,19 +719,20 @@ static void vfio_vmstate_change_prepare(void *opaque, bool running,VFIODevice *vbasedev = opaque;VFIOMigration *migration = vbasedev->migration;enum vfio_device_mig_state new_state; +Error *local_err =NULL ;int ret; new_state = migration->device_state ==VFIO_DEVICE_STATE_PRE_COPY ?VFIO_DEVICE_STATE_PRE_COPY_P2P :VFIO_DEVICE_STATE_RUNNING_P2P ; - ret =vfio_migration_set_state_or_reset (vbasedev, new_state); + ret =vfio_migration_set_state_or_reset (vbasedev, new_state, &local_err);if (ret) {/* * Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ -migration_file_set_error (ret,NULL ); +migration_file_set_error (ret, local_err); } trace_vfio_vmstate_change_prepare(vbasedev->name, running,@@ -738,6 +744,7 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state) {VFIODevice *vbasedev = opaque;enum vfio_device_mig_state new_state; +Error *local_err =NULL ;int ret;if (running) {@@ -750,13 +757,13 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state)VFIO_DEVICE_STATE_STOP ; } - ret =vfio_migration_set_state_or_reset (vbasedev, new_state); + ret =vfio_migration_set_state_or_reset (vbasedev, new_state, &local_err);if (ret) {/* * Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ -migration_file_set_error (ret,NULL ); +migration_file_set_error (ret, local_err); } trace_vfio_vmstate_change(vbasedev->name, running, RunState_str(state),
hw/vfio/migration.c static int vfio_migration_state_notifier(NotifierWithReturn *notifier, · line 780
Quoted 5 lines
hw/vfio/migration.c +2
-0@@ -769,11 +776,23 @@ static int vfio_migration_state_notifier(NotifierWithReturn *notifier,VFIOMigration *migration =container_of (notifier, VFIOMigration, migration_state);VFIODevice *vbasedev = migration->vbasedev; +Error *local_err =NULL ; +int ret =0 ;
Nit: No need to set ret to 0.
hw/vfio/migration.c static int vfio_migration_state_notifier(NotifierWithReturn *notifier, · line 789
Quoted 10 lines
hw/vfio/migration.c +5
-1trace_vfio_migration_state_notifier (vbasedev->name, e->type);if (e->type ==MIG_EVENT_PRECOPY_FAILED ) { -vfio_migration_set_state_or_reset (vbasedev,VFIO_DEVICE_STATE_RUNNING ); +/* +* MigrationNotifyFunc may return an error code and an Error +* object only for MIG_EVENT_PRECOPY_SETUP. Hence, report the +* error locally and ignore the errp argument. +*/
Nit: maybe rephrase to the following:
"MigrationNotifyFunc may not return an error code and an Error object for MIG_EVENT_PRECOPY_FAILED. Hence ..."
(This way, this comment will not become stale if new MIG_EVENTs that are allowed to return error are added)
Thanks.
Quoted 12 lines
hw/vfio/migration.c +6
-1+ ret =vfio_migration_set_state_or_reset (vbasedev, +VFIO_DEVICE_STATE_RUNNING , + &local_err); +if (ret) { +error_report_err (local_err); + } }return 0 ; } --2.45.0
Re: [PATCH v6 4/9] vfio/migration: Add an Error** argument to vfio_migration_set_state()
Quoted 236 lines · Avihai Horon
Quoted 8 lines · Cédric Le Goater
External email: Use caution opening links or attachments
Add an Error** argument to
vfio_migration_set_state()and adjust callers, includingvfio_save_setup(). The error will be propagated up toqemu_savevm_state_setup()where thesave_setup()handler is executed.Quoted 5 lines
Modify
vfio_vmstate_change_prepare()andvfio_vmstate_change()to store a reported error under the migration stream if a migration is in progress.Signed-off-by Cédric Le Goater <[email protected]>With/without Eric's suggestion:
Reviewed-by Avihai Horon <[email protected]>Two nits below though (if you respin or want to amend inline).
Quoted 196 lines
---
Changes in v6:
- Commit log improvements (Avihai)
-vfio_migration_set_state(): Dropped theerror_setg_errno()change when setting device in recover state fails (Avihai)
-vfio_migration_state_notifier(): report local error (Avihai)Changes in v5:
- Replaced
error_setg()byerror_setg_errno()invfio_migration_set_state()
- Rebased on20c64c8a51a4("migration:migration_file_set_error")
hw/vfio/migration.c| 77 ++++++++++++++++++++++++++++-----------------1 file changed, 48 insertions(+), 29 deletions(-)hw/vfio/migration.c +2
-1@@ -82,7 +82,8 @@ static const char *mig_state_to_str(enum vfio_device_mig_state state) static int vfio_migration_set_state(VFIODevice *vbasedev, enum vfio_device_mig_state new_state, - enum vfio_device_mig_state recover_state) + enum vfio_device_mig_state recover_state, + Error **errp) { VFIOMigration *migration = vbasedev->migration;
uint64_tbuf[DIV_ROUND_UP(sizeof(structvfio_device_feature) +hw/vfio/migration.c +10
-9@@ -102,18 +103,19 @@ static int vfio_migration_set_state(VFIODevice *vbasedev, ret = -errno; if (recover_state == VFIO_DEVICE_STATE_ERROR) { - error_report("%s: Failed setting device state to %s, err: %s. " - "Recover state is ERROR. Resetting device", - vbasedev->name, mig_state_to_str(new_state), - strerror(errno)); + error_setg_errno(errp, errno, + "%s: Failed setting device state to %s. " + "Recover state is ERROR. Resetting device", + vbasedev->name, mig_state_to_str(new_state)); goto reset_device; } - error_report( - "%s: Failed setting device state to %s, err: %s. Setting device in recover state %s", - vbasedev->name, mig_state_to_str(new_state), - strerror(errno), mig_state_to_str(recover_state)); + error_setg_errno(errp, errno, + "%s: Failed setting device state to %s. " + "Setting device in recover state %s", + vbasedev->name, mig_state_to_str(new_state), + mig_state_to_str(recover_state)); mig_state->device_state = recover_state; if (ioctl(vbasedev->fd, VFIO_DEVICE_FEATURE, feature)) {@@ -137,7 +139,7 @@ static int vfio_migration_set_state(VFIODevice *vbasedev,* This can happen if the device is asynchronously reset and * terminates a data transfer. */ - error_report("%s: data_fd out of sync", vbasedev->name); + error_setg(errp, "%s: data_fd out of sync", vbasedev->name); close(mig_state->data_fd); return -EBADF;@@ -168,10 +170,11 @@ reset_device:*/ static int
vfio_migration_set_state_or_reset(VFIODevice *vbasedev,
- enumvfio_device_mig_statenew_state) + enumvfio_device_mig_statenew_state, + Error **errp)
{
return vfio_migration_set_state(vbasedev,new_state,
-VFIO_DEVICE_STATE_ERROR); +VFIO_DEVICE_STATE_ERROR, errp); }static int vfio_load_buffer(QEMUFile *f, VFIODevice *vbasedev,
hw/vfio/migration.c +0
-0@@ -399,10 +402,8 @@ static int vfio_save_setup(QEMUFile *f, void *opaque, Error **errp) switch (migration->device_state) {case
VFIO_DEVICE_STATE_RUNNING:
ret = vfio_migration_set_state(vbasedev,VFIO_DEVICE_STATE_PRE_COPY, -VFIO_DEVICE_STATE_RUNNING); +VFIO_DEVICE_STATE_RUNNING, errp); if (ret) {
- error_setg(errp, "%s: Failed to set newPRE_COPYstate", -vbasedev->name);
return ret;
}hw/vfio/migration.c +14
-9@@ -435,13 +436,20 @@ static void vfio_save_cleanup(void *opaque) { VFIODevice *vbasedev = opaque; VFIOMigration *migration = vbasedev->migration; + Error *local_err = NULL; + int ret; /* * Changing device state from STOP_COPY to STOP can take time. Do it here, * after migration has completed, so it won't increase downtime. */ if (migration->device_state == VFIO_DEVICE_STATE_STOP_COPY) { - vfio_migration_set_state_or_reset(vbasedev, VFIO_DEVICE_STATE_STOP); + ret = vfio_migration_set_state_or_reset(vbasedev, + VFIO_DEVICE_STATE_STOP, + &local_err); + if (ret) { + error_report_err(local_err); + } } g_free(migration->data_buffer);@@ -549,11 +557,13 @@ static int vfio_save_complete_precopy(QEMUFile *f, void *opaque) VFIODevice *vbasedev = opaque; ssize_t data_size; int ret; + Error *local_err = NULL; /* We reach here with device state STOP or STOP_COPY only */ ret = vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_STOP_COPY, - VFIO_DEVICE_STATE_STOP); + VFIO_DEVICE_STATE_STOP, &local_err); if (ret) { + error_report_err(local_err); return ret; }@@ -591,14 +601,9 @@ static void vfio_save_state(QEMUFile *f, void *opaque) static int vfio_load_setup(QEMUFile *f, void *opaque, Error **errp) { VFIODevice *vbasedev = opaque; - int ret; - ret = vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_RESUMING, - vbasedev->migration->device_state); - if (ret) { - error_setg(errp, "%s: Failed to set RESUMING state", vbasedev->name); - } - return ret; + return vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_RESUMING, + vbasedev->migration->device_state, errp); } static int vfio_load_cleanup(void *opaque)@@ -714,19 +719,20 @@ static void vfio_vmstate_change_prepare(void *opaque, bool running, VFIODevice *vbasedev = opaque; VFIOMigration *migration = vbasedev->migration; enum vfio_device_mig_state new_state; + Error *local_err = NULL; int ret;
new_state=migration->device_state==VFIO_DEVICE_STATE_PRE_COPY?VFIO_DEVICE_STATE_PRE_COPY_P2P:
VFIO_DEVICE_STATE_RUNNING_P2P;- ret =
vfio_migration_set_state_or_reset(vbasedev, new_state); + ret =vfio_migration_set_state_or_reset(vbasedev, new_state, &local_err); if (ret) {
/*
* Migration should be aborted in this case, butvm_state_notify()
* currently does not support reporting failures.
*/
-migration_file_set_error(ret, NULL);
+migration_file_set_error(ret, local_err);
}trace_vfio_vmstate_change_prepare(vbasedev->name, running,
hw/vfio/migration.c +3
-2@@ -738,6 +744,7 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state) { VFIODevice *vbasedev = opaque; enum vfio_device_mig_state new_state; + Error *local_err = NULL; int ret; if (running) {@@ -750,13 +757,13 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state) VFIO_DEVICE_STATE_STOP; } - ret = vfio_migration_set_state_or_reset(vbasedev, new_state); + ret = vfio_migration_set_state_or_reset(vbasedev, new_state, &local_err); if (ret) { /* * Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ - migration_file_set_error(ret, NULL); + migration_file_set_error(ret, local_err); } trace_vfio_vmstate_change(vbasedev->name, running, RunState_str(state),hw/vfio/migration.c static int vfio_migration_state_notifier(NotifierWithReturn *notifier, · line 780
Quoted 5 lines
hw/vfio/migration.c +2
-0@@ -769,11 +776,23 @@ static int vfio_migration_state_notifier(NotifierWithReturn *notifier, VFIOMigration *migration = container_of(notifier, VFIOMigration, migration_state); VFIODevice *vbasedev = migration->vbasedev; + Error *local_err = NULL; + int ret = 0;Nit: No need to set ret to 0.
hw/vfio/migration.c static int vfio_migration_state_notifier(NotifierWithReturn *notifier, · line 789
Quoted 10 lines
hw/vfio/migration.c +5
-1trace_vfio_migration_state_notifier(vbasedev->name, e->type); if (e->type == MIG_EVENT_PRECOPY_FAILED) { - vfio_migration_set_state_or_reset(vbasedev, VFIO_DEVICE_STATE_RUNNING); + /* +* MigrationNotifyFunc may return an error code and an Error +* object only for MIG_EVENT_PRECOPY_SETUP. Hence, report the +* error locally and ignore the errp argument. +*/
Quoted 5 lines
Nit: maybe rephrase to the following:
"MigrationNotifyFunc may not return an error code and an Error object for
MIG_EVENT_PRECOPY_FAILED. Hence ..."(This way, this comment will not become stale if new
MIG_EVENTsthat are allowed to return error are added)
ok. done. There will be a (final) v7.
Thanks,
C.
Quoted 15 lines
Thanks.
Quoted 12 lines
hw/vfio/migration.c +6
-0+ ret = vfio_migration_set_state_or_reset(vbasedev, + VFIO_DEVICE_STATE_RUNNING, + &local_err); + if (ret) { + error_report_err(local_err); + } } return 0; }Signature · 1 line
2.45.0
PATCH v6 5/9 vfio/migration: Add Error** argument to .vfio_save_config() handler
In reply to Cédric Le GoaterUse vmstate_save_state_with_err() to improve error reporting in the callers and store a reported error under the migration stream. Add documentation while at it.
---
Changes in v6:
- Modified title (Avihai)
- vfio_save_device_config_state() : Set errp if the migration stream is in error (Avihai)
- vfio_save_state() : Changed error prefix (Avihai)
include/hw/vfio/vfio-common.h | 25 ++++++++++++++++++++++++- hw/vfio/migration.c | 25 ++++++++++++++++++------- hw/vfio/pci.c | 5 +++-- 3 files changed, 45 insertions(+), 10 deletions(-)
include/hw/vfio/vfio-common.h +24 -1
@@ -133,7 +133,30 @@ struct VFIODeviceOps {int (*vfio_hot_reset_multi)(VFIODevice *vdev);void (*vfio_eoi)(VFIODevice *vdev); Object *(*vfio_get_object)(VFIODevice *vdev); -void (*vfio_save_config)(VFIODevice *vdev,QEMUFile *f); + +/** +* @vfio_save_config +* +* Save device config state +* +* @vdev: #VFIODevice for which to save the config +* @f: #QEMUFile where to send the data +* @errp: pointer to Error*, to store an error if it happens. +* +* Returns zero to indicate success and negative for error +*/ +int (*vfio_save_config)(VFIODevice *vdev,QEMUFile *f,Error **errp); + +/** +* @vfio_load_config +* +* Load device config state +* +* @vdev: #VFIODevice for which to load the config +* @f: #QEMUFile where to get the data +* +* Returns zero to indicate success and negative for error +*/ int (*vfio_load_config)(VFIODevice *vdev,QEMUFile *f); };
hw/vfio/migration.c +18 -7
@@ -189,21 +189,30 @@ static int vfio_load_buffer(QEMUFile *f, VFIODevice *vbasedev,return ret; } -static int vfio_save_device_config_state (QEMUFile *f,void *opaque) +static int vfio_save_device_config_state (QEMUFile *f,void *opaque, +Error **errp) {VFIODevice *vbasedev = opaque; +int ret;qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_CONFIG_STATE );if (vbasedev->ops && vbasedev->ops->vfio_save_config) { - vbasedev->ops->vfio_save_config (vbasedev, f); + ret = vbasedev->ops->vfio_save_config (vbasedev, f, errp); +if (ret) { +return ret; + } }qemu_put_be64 (f,VFIO_MIG_FLAG_END_OF_STATE );trace_vfio_save_device_config_state (vbasedev->name); -return qemu_file_get_error (f); + ret =qemu_file_get_error (f); +if (ret <0 ) { +error_setg_errno (errp, -ret,"Failed to save state" ); + } +return ret; }static int vfio_load_device_config_state (QEMUFile *f,void *opaque)
@@ -588,13 +597,15 @@ static int vfio_save_complete_precopy(QEMUFile *f, void *opaque)static void vfio_save_state (QEMUFile *f,void *opaque) {VFIODevice *vbasedev = opaque; +Error *local_err =NULL ;int ret; - ret =vfio_save_device_config_state (f, opaque); + ret =vfio_save_device_config_state (f, opaque, &local_err);if (ret) { -error_report ("%s: Failed to save device config space" , - vbasedev->name); -qemu_file_set_error (f, ret); +error_prepend (&local_err, +"vfio: Failed to save device config space of %s - " , + vbasedev->name); +qemu_file_set_error_obj (f, ret, local_err); } }
hw/vfio/pci.c +3 -2
@@ -2586,11 +2586,12 @@ static const VMStateDescription vmstate_vfio_pci_config = { } }; -static void vfio_pci_save_config (VFIODevice *vbasedev,QEMUFile *f) +static int vfio_pci_save_config (VFIODevice *vbasedev,QEMUFile *f,Error **errp) {VFIOPCIDevice *vdev =container_of (vbasedev, VFIOPCIDevice, vbasedev); -vmstate_save_state (f, &vmstate_vfio_pci_config, vdev,NULL ); +return vmstate_save_state_with_err (f, &vmstate_vfio_pci_config, vdev,NULL , + errp); }static int vfio_pci_load_config (VFIODevice *vbasedev,QEMUFile *f)
Signature · 1 line
2.45.0
Re: [PATCH v6 5/9] vfio/migration: Add Error** argument to .vfio_save_config() handler
Quoted 122 lines · Cédric Le Goater
Use
vmstate_save_state_with_err()to improve error reporting in the callers and store a reported error under the migration stream. Add documentation while at it.Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
Changes in v6:
- Modified title (Avihai)
-vfio_save_device_config_state(): Set errp if the migration stream is in error (Avihai)
-vfio_save_state(): Changed error prefix (Avihai)include/hw/vfio/vfio-common.h | 25 ++++++++++++++++++++++++- hw/vfio/migration.c | 25 ++++++++++++++++++------- hw/vfio/pci.c | 5 +++-- 3 files changed, 45 insertions(+), 10 deletions(-)include/hw/vfio/vfio-common.h +24
-1@@ -133,7 +133,30 @@ struct VFIODeviceOps {int (*vfio_hot_reset_multi)(VFIODevice *vdev);void (*vfio_eoi)(VFIODevice *vdev); Object *(*vfio_get_object)(VFIODevice *vdev); -void (*vfio_save_config)(VFIODevice *vdev,QEMUFile *f); + +/** +* @vfio_save_config +* +* Save device config state +* +* @vdev: #VFIODevice for which to save the config +* @f: #QEMUFile where to send the data +* @errp: pointer to Error*, to store an error if it happens. +* +* Returns zero to indicate success and negative for error +*/ +int (*vfio_save_config)(VFIODevice *vdev,QEMUFile *f,Error **errp); + +/** +* @vfio_load_config +* +* Load device config state +* +* @vdev: #VFIODevice for which to load the config +* @f: #QEMUFile where to get the data +* +* Returns zero to indicate success and negative for error +*/ int (*vfio_load_config)(VFIODevice *vdev,QEMUFile *f); };hw/vfio/migration.c +18
-7@@ -189,21 +189,30 @@ static int vfio_load_buffer(QEMUFile *f, VFIODevice *vbasedev,return ret; } -static int vfio_save_device_config_state (QEMUFile *f,void *opaque) +static int vfio_save_device_config_state (QEMUFile *f,void *opaque, +Error **errp) {VFIODevice *vbasedev = opaque; +int ret;qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_CONFIG_STATE );if (vbasedev->ops && vbasedev->ops->vfio_save_config) { - vbasedev->ops->vfio_save_config (vbasedev, f); + ret = vbasedev->ops->vfio_save_config (vbasedev, f, errp); +if (ret) { +return ret; + } }qemu_put_be64 (f,VFIO_MIG_FLAG_END_OF_STATE );trace_vfio_save_device_config_state (vbasedev->name); -return qemu_file_get_error (f); + ret =qemu_file_get_error (f); +if (ret <0 ) { +error_setg_errno (errp, -ret,"Failed to save state" ); + } +return ret; }static int vfio_load_device_config_state (QEMUFile *f,void *opaque)@@ -588,13 +597,15 @@ static int vfio_save_complete_precopy(QEMUFile *f, void *opaque)static void vfio_save_state (QEMUFile *f,void *opaque) {VFIODevice *vbasedev = opaque; +Error *local_err =NULL ;int ret; - ret =vfio_save_device_config_state (f, opaque); + ret =vfio_save_device_config_state (f, opaque, &local_err);if (ret) { -error_report ("%s: Failed to save device config space" , - vbasedev->name); -qemu_file_set_error (f, ret); +error_prepend (&local_err, +"vfio: Failed to save device config space of %s - " , + vbasedev->name); + qemu_file_set_error_obj(f, ret, local_err);> } }hw/vfio/pci.c +0
-1@@ -2586,11 +2586,12 @@ static const VMStateDescription vmstate_vfio_pci_config = { } }; -static void vfio_pci_save_config (VFIODevice *vbasedev,QEMUFile *f)
hw/vfio/pci.c static const VMStateDescription vmstate_vfio_pci_config = { · line 2597
Quoted 10 lines
hw/vfio/pci.c +3
-1+static int vfio_pci_save_config (VFIODevice *vbasedev,QEMUFile *f,Error **errp) {VFIOPCIDevice *vdev =container_of (vbasedev, VFIOPCIDevice, vbasedev); -vmstate_save_state (f, &vmstate_vfio_pci_config, vdev,NULL ); +return vmstate_save_state_with_err (f, &vmstate_vfio_pci_config, vdev,NULL , + errp); }static int vfio_pci_load_config (VFIODevice *vbasedev,QEMUFile *f)
Looks good to me
Eric
Re: [PATCH v6 5/9] vfio/migration: Add Error** argument to .vfio_save_config() handler
In reply to Cédric Le GoaterQuoted 9 lines · Cédric Le Goater
External email: Use caution opening links or attachments
Use
vmstate_save_state_with_err()to improve error reporting in the callers and store a reported error under the migration stream. Add documentation while at it.Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>
Quoted 130 lines
---
Changes in v6:
- Modified title (Avihai)
-vfio_save_device_config_state(): Set errp if the migration stream is in error (Avihai)
-vfio_save_state(): Changed error prefix (Avihai)include/hw/vfio/vfio-common.h | 25 ++++++++++++++++++++++++- hw/vfio/migration.c | 25 ++++++++++++++++++------- hw/vfio/pci.c | 5 +++-- 3 files changed, 45 insertions(+), 10 deletions(-)include/hw/vfio/vfio-common.h +24
-1@@ -133,7 +133,30 @@ struct VFIODeviceOps {int (*vfio_hot_reset_multi)(VFIODevice *vdev);void (*vfio_eoi)(VFIODevice *vdev); Object *(*vfio_get_object)(VFIODevice *vdev); -void (*vfio_save_config)(VFIODevice *vdev,QEMUFile *f); + +/** +* @vfio_save_config +* +* Save device config state +* +* @vdev: #VFIODevice for which to save the config +* @f: #QEMUFile where to send the data +* @errp: pointer to Error*, to store an error if it happens. +* +* Returns zero to indicate success and negative for error +*/ +int (*vfio_save_config)(VFIODevice *vdev,QEMUFile *f,Error **errp); + +/** +* @vfio_load_config +* +* Load device config state +* +* @vdev: #VFIODevice for which to load the config +* @f: #QEMUFile where to get the data +* +* Returns zero to indicate success and negative for error +*/ int (*vfio_load_config)(VFIODevice *vdev,QEMUFile *f); };hw/vfio/migration.c +18
-7@@ -189,21 +189,30 @@ static int vfio_load_buffer(QEMUFile *f, VFIODevice *vbasedev,return ret; } -static int vfio_save_device_config_state (QEMUFile *f,void *opaque) +static int vfio_save_device_config_state (QEMUFile *f,void *opaque, +Error **errp) {VFIODevice *vbasedev = opaque; +int ret;qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_CONFIG_STATE );if (vbasedev->ops && vbasedev->ops->vfio_save_config) { - vbasedev->ops->vfio_save_config (vbasedev, f); + ret = vbasedev->ops->vfio_save_config (vbasedev, f, errp); +if (ret) { +return ret; + } }qemu_put_be64 (f,VFIO_MIG_FLAG_END_OF_STATE );trace_vfio_save_device_config_state (vbasedev->name); -return qemu_file_get_error (f); + ret =qemu_file_get_error (f); +if (ret <0 ) { +error_setg_errno (errp, -ret,"Failed to save state" ); + } +return ret; }static int vfio_load_device_config_state (QEMUFile *f,void *opaque)@@ -588,13 +597,15 @@ static int vfio_save_complete_precopy(QEMUFile *f, void *opaque)static void vfio_save_state (QEMUFile *f,void *opaque) {VFIODevice *vbasedev = opaque; +Error *local_err =NULL ;int ret; - ret =vfio_save_device_config_state (f, opaque); + ret =vfio_save_device_config_state (f, opaque, &local_err);if (ret) { -error_report ("%s: Failed to save device config space" , - vbasedev->name); -qemu_file_set_error (f, ret); +error_prepend (&local_err, +"vfio: Failed to save device config space of %s - " , + vbasedev->name); +qemu_file_set_error_obj (f, ret, local_err); } }hw/vfio/pci.c +3
-3@@ -2586,11 +2586,12 @@ static const VMStateDescription vmstate_vfio_pci_config = { } }; -static void vfio_pci_save_config (VFIODevice *vbasedev,QEMUFile *f) +static int vfio_pci_save_config (VFIODevice *vbasedev,QEMUFile *f,Error **errp) {VFIOPCIDevice *vdev =container_of (vbasedev, VFIOPCIDevice, vbasedev); -vmstate_save_state (f, &vmstate_vfio_pci_config, vdev,NULL ); +return vmstate_save_state_with_err (f, &vmstate_vfio_pci_config, vdev,NULL , + errp); }static int vfio_pci_load_config (VFIODevice *vbasedev,QEMUFile *f) --2.45.0
PATCH v6 6/9 vfio: Reverse test on vfio_get_xlat_addr()
In reply to Cédric Le GoaterIt will simplify the changes coming after.
---
Changes in v6:
- Modified title (Avihai)
- vfio_iommu_map_dirty_notify() : Modified goto label (Avihai)
hw/vfio/common.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
hw/vfio/common.c +13 -9
@@ -1224,16 +1224,20 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb) }rcu_read_lock (); -if (vfio_get_xlat_addr (iotlb,NULL , &translated_addr,NULL )) { - ret =vfio_get_dirty_bitmap (bcontainer, iova, iotlb->addr_mask +1 , - translated_addr); -if (ret) { -error_report ("vfio_iommu_map_dirty_notify(%p, 0x%" HWADDR_PRIx", " -"0x%" HWADDR_PRIx") = %d (%s)" , - bcontainer, iova, iotlb->addr_mask +1 , ret, -strerror (-ret)); - } +if (!vfio_get_xlat_addr (iotlb,NULL , &translated_addr,NULL )) { + goto out_unlock; } + + ret =vfio_get_dirty_bitmap (bcontainer, iova, iotlb->addr_mask +1 , + translated_addr); +if (ret) { +error_report ("vfio_iommu_map_dirty_notify(%p, 0x%" HWADDR_PRIx", " +"0x%" HWADDR_PRIx") = %d (%s)" , + bcontainer, iova, iotlb->addr_mask +1 , ret, +strerror (-ret)); + } + +out_unlock:rcu_read_unlock (); out:
Signature · 1 line
2.45.0
Re: [PATCH v6 6/9] vfio: Reverse test on vfio_get_xlat_addr()
Quoted 38 lines · Cédric Le Goater
It will simplify the changes coming after.
Reviewed-by Avihai Horon <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
Changes in v6:
- Modified title (Avihai)
-vfio_iommu_map_dirty_notify(): Modified goto label (Avihai)hw/vfio/common.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)hw/vfio/common.c +6
-9@@ -1224,16 +1224,20 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb) }rcu_read_lock (); -if (vfio_get_xlat_addr (iotlb,NULL , &translated_addr,NULL )) { - ret =vfio_get_dirty_bitmap (bcontainer, iova, iotlb->addr_mask +1 , - translated_addr); -if (ret) { -error_report ("vfio_iommu_map_dirty_notify(%p, 0x%" HWADDR_PRIx", " -"0x%" HWADDR_PRIx") = %d (%s)" , - bcontainer, iova, iotlb->addr_mask +1 , ret, -strerror (-ret)); - } +if (!vfio_get_xlat_addr (iotlb,NULL , &translated_addr,NULL )) { + goto out_unlock; } + + ret =vfio_get_dirty_bitmap (bcontainer, iova, iotlb->addr_mask +1 , + translated_addr); +if (ret) {
hw/vfio/common.c static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb) · line 1243
Quoted 10 lines
hw/vfio/common.c +7
-0+error_report ("vfio_iommu_map_dirty_notify(%p, 0x%" HWADDR_PRIx", " +"0x%" HWADDR_PRIx") = %d (%s)" , + bcontainer, iova, iotlb->addr_mask +1 , ret, +strerror (-ret)); + } + +out_unlock:rcu_read_unlock (); out:
Eric
PATCH v6 7/9 memory: Add Error** argument to memory_get_xlat_addr()
In reply to Cédric Le GoaterLet the callers do the reporting. This will be useful in vfio_iommu_map_dirty_notify().
---
Changes in v6:
- Fixed memory_get_xlat_addr documentation (Avihai)
include/exec/memory.h | 15 ++++++++++++++- hw/vfio/common.c | 13 +++++++++---- hw/virtio/vhost-vdpa.c | 5 ++++- system/memory.c | 10 +++++----- 4 files changed, 32 insertions(+), 11 deletions(-)
include/exec/memory.h +14 -1
@@ -774,9 +774,22 @@ void ram_discard_manager_register_listener(RamDiscardManager *rdm,void ram_discard_manager_unregister_listener (RamDiscardManager *rdm,RamDiscardListener *rdl); +/** +* memory_get_xlat_addr: Extract addresses from a TLB entry +* +* @iotlb: pointer to an #IOMMUTLBEntry +* @vaddr: virtual address +* @ram_addr: RAM address +* @read_only: indicates if writes are allowed +* @mr_has_discard_manager: indicates memory is controlled by a +* RamDiscardManager +* @errp: pointer to Error*, to store an error if it happens. +* +* Return: true on success, else false setting @errp with error. +*/ bool memory_get_xlat_addr (IOMMUTLBEntry *iotlb,void **vaddr,ram_addr_t *ram_addr,bool *read_only, -bool *mr_has_discard_manager); +bool *mr_has_discard_manager,Error **errp);typedef struct CoalescedMemoryRange CoalescedMemoryRange ;typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd ;
hw/vfio/common.c +9 -4
@@ -253,12 +253,13 @@ static bool vfio_listener_skipped_section(MemoryRegionSection *section)/* Called with rcu_read_lock held. */ static bool vfio_get_xlat_addr (IOMMUTLBEntry *iotlb,void **vaddr, -ram_addr_t *ram_addr,bool *read_only) +ram_addr_t *ram_addr,bool *read_only, +Error **errp) {bool ret, mr_has_discard_manager; ret =memory_get_xlat_addr (iotlb, vaddr, ram_addr, read_only, - &mr_has_discard_manager); + &mr_has_discard_manager, errp);if (ret && mr_has_discard_manager) {/* * Malicious VMs might trigger discarding of IOMMU-mapped memory. The
@@ -288,6 +289,7 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)hwaddr iova = iotlb->iova + giommu->iommu_offset;void *vaddr;int ret; +Error *local_err =NULL ;trace_vfio_iommu_map_notify (iotlb->perm ==IOMMU_NONE ?"UNMAP" :"MAP" , iova, iova + iotlb->addr_mask);
@@ -304,7 +306,8 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)if ((iotlb->perm &IOMMU_RW ) !=IOMMU_NONE ) {bool read_only; -if (!vfio_get_xlat_addr (iotlb, &vaddr,NULL , &read_only)) { +if (!vfio_get_xlat_addr (iotlb, &vaddr,NULL , &read_only, &local_err)) { +error_report_err (local_err); goto out; }/*
@@ -1213,6 +1216,7 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)VFIOContainerBase *bcontainer = giommu->bcontainer;hwaddr iova = iotlb->iova + giommu->iommu_offset;ram_addr_t translated_addr; +Error *local_err =NULL ;int ret = -EINVAL ;trace_vfio_iommu_map_dirty_notify (iova, iova + iotlb->addr_mask);
@@ -1224,7 +1228,8 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb) }rcu_read_lock (); -if (!vfio_get_xlat_addr (iotlb,NULL , &translated_addr,NULL )) { +if (!vfio_get_xlat_addr (iotlb,NULL , &translated_addr,NULL , &local_err)) { +error_report_err (local_err); goto out_unlock; }
hw/virtio/vhost-vdpa.c +4 -1
@@ -208,6 +208,7 @@ static void vhost_vdpa_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)void *vaddr;int ret;Int128 llend; +Error *local_err =NULL ;if (iotlb->target_as != &address_space_memory) { error_report("Wrong target AS \"%s\", only system memory is allowed",
@@ -227,7 +228,9 @@ static void vhost_vdpa_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)if ((iotlb->perm &IOMMU_RW ) !=IOMMU_NONE ) {bool read_only; -if (!memory_get_xlat_addr (iotlb, &vaddr,NULL , &read_only,NULL )) { +if (!memory_get_xlat_addr (iotlb, &vaddr,NULL , &read_only,NULL , + &local_err)) { +error_report_err (local_err);return ; } ret = vhost_vdpa_dma_map(s, VHOST_VDPA_GUEST_PA_ASID, iova,
system/memory.c +5 -5
@@ -2179,7 +2179,7 @@ void ram_discard_manager_unregister_listener(RamDiscardManager *rdm,/* Called with rcu_read_lock held. */ bool memory_get_xlat_addr (IOMMUTLBEntry *iotlb,void **vaddr,ram_addr_t *ram_addr,bool *read_only, -bool *mr_has_discard_manager) +bool *mr_has_discard_manager,Error **errp) {MemoryRegion *mr;hwaddr xlat;
@@ -2197,7 +2197,7 @@ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr, mr =address_space_translate (&address_space_memory, iotlb->translated_addr, &xlat, &len, writable,MEMTXATTRS_UNSPECIFIED );if (!memory_region_is_ram (mr)) { -error_report ("iommu map to non memory area %" HWADDR_PRIx"" , xlat); +error_setg (errp,"iommu map to non memory area %" HWADDR_PRIx"" , xlat);return false; }else if (memory_region_has_ram_discard_manager (mr)) {RamDiscardManager *rdm =memory_region_get_ram_discard_manager (mr);
@@ -2216,8 +2216,8 @@ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr,* were already restored before IOMMUs are restored. */ if (!ram_discard_manager_is_populated (rdm, &tmp)) { -error_report ("iommu map to discarded memory (e.g., unplugged via" -" virtio-mem): %" HWADDR_PRIx"" , +error_setg (errp,"iommu map to discarded memory (e.g., unplugged" +" via virtio-mem): %" HWADDR_PRIx"" , iotlb->translated_addr);return false; }
@@ -2228,7 +2228,7 @@ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr,* check that it did not truncate too much. */ if (len & iotlb->addr_mask) { -error_report ("iommu has granularity incompatible with target AS" ); +error_setg (errp,"iommu has granularity incompatible with target AS" );return false; }
Signature · 1 line
2.45.0
Re: [PATCH v6 7/9] memory: Add Error** argument to memory_get_xlat_addr()
Quoted 161 lines · Cédric Le Goater
Let the callers do the reporting. This will be useful in
vfio_iommu_map_dirty_notify().Cc Michael S. Tsirkin <[email protected]>Cc Paolo Bonzini <[email protected]>Cc David Hildenbrand <[email protected]>Reviewed-by Peter Xu <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
Changes in v6:
- Fixed
memory_get_xlat_addrdocumentation (Avihai)include/exec/memory.h | 15 ++++++++++++++- hw/vfio/common.c | 13 +++++++++---- hw/virtio/vhost-vdpa.c | 5 ++++- system/memory.c | 10 +++++----- 4 files changed, 32 insertions(+), 11 deletions(-)include/exec/memory.h +14
-1@@ -774,9 +774,22 @@ void ram_discard_manager_register_listener(RamDiscardManager *rdm,void ram_discard_manager_unregister_listener (RamDiscardManager *rdm,RamDiscardListener *rdl); +/** +* memory_get_xlat_addr: Extract addresses from a TLB entry +* +* @iotlb: pointer to an #IOMMUTLBEntry +* @vaddr: virtual address +* @ram_addr: RAM address +* @read_only: indicates if writes are allowed +* @mr_has_discard_manager: indicates memory is controlled by a +* RamDiscardManager +* @errp: pointer to Error*, to store an error if it happens. +* +* Return: true on success, else false setting @errp with error. +*/ bool memory_get_xlat_addr (IOMMUTLBEntry *iotlb,void **vaddr,ram_addr_t *ram_addr,bool *read_only, -bool *mr_has_discard_manager); +bool *mr_has_discard_manager,Error **errp);typedef struct CoalescedMemoryRange CoalescedMemoryRange ;typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd ;hw/vfio/common.c +9
-4@@ -253,12 +253,13 @@ static bool vfio_listener_skipped_section(MemoryRegionSection *section)/* Called with rcu_read_lock held. */ static bool vfio_get_xlat_addr (IOMMUTLBEntry *iotlb,void **vaddr, -ram_addr_t *ram_addr,bool *read_only) +ram_addr_t *ram_addr,bool *read_only, +Error **errp) {bool ret, mr_has_discard_manager; ret =memory_get_xlat_addr (iotlb, vaddr, ram_addr, read_only, - &mr_has_discard_manager); + &mr_has_discard_manager, errp);if (ret && mr_has_discard_manager) {/* * Malicious VMs might trigger discarding of IOMMU-mapped memory. The @@ -288,6 +289,7 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)hwaddr iova = iotlb->iova + giommu->iommu_offset;void *vaddr;int ret; +Error *local_err =NULL ;trace_vfio_iommu_map_notify (iotlb->perm ==IOMMU_NONE ?"UNMAP" :"MAP" , iova, iova + iotlb->addr_mask);@@ -304,7 +306,8 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)if ((iotlb->perm &IOMMU_RW ) !=IOMMU_NONE ) {bool read_only; -if (!vfio_get_xlat_addr (iotlb, &vaddr,NULL , &read_only)) { +if (!vfio_get_xlat_addr (iotlb, &vaddr,NULL , &read_only, &local_err)) { +error_report_err (local_err); goto out; }/* @@ -1213,6 +1216,7 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)VFIOContainerBase *bcontainer = giommu->bcontainer;hwaddr iova = iotlb->iova + giommu->iommu_offset;ram_addr_t translated_addr; +Error *local_err =NULL ;int ret = -EINVAL ;trace_vfio_iommu_map_dirty_notify (iova, iova + iotlb->addr_mask);@@ -1224,7 +1228,8 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb) }rcu_read_lock (); -if (!vfio_get_xlat_addr (iotlb,NULL , &translated_addr,NULL )) { +if (!vfio_get_xlat_addr (iotlb,NULL , &translated_addr,NULL , &local_err)) { +error_report_err (local_err); goto out_unlock; }hw/virtio/vhost-vdpa.c +4
-1@@ -208,6 +208,7 @@ static void vhost_vdpa_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)void *vaddr;int ret;Int128 llend; +Error *local_err =NULL ;if (iotlb->target_as != &address_space_memory) { error_report("Wrong target AS \"%s\", only system memory is allowed",@@ -227,7 +228,9 @@ static void vhost_vdpa_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)if ((iotlb->perm &IOMMU_RW ) !=IOMMU_NONE ) {bool read_only; -if (!memory_get_xlat_addr (iotlb, &vaddr,NULL , &read_only,NULL )) { +if (!memory_get_xlat_addr (iotlb, &vaddr,NULL , &read_only,NULL , + &local_err)) { +error_report_err (local_err);return ; } ret = vhost_vdpa_dma_map(s, VHOST_VDPA_GUEST_PA_ASID, iova,system/memory.c +4
-4@@ -2179,7 +2179,7 @@ void ram_discard_manager_unregister_listener(RamDiscardManager *rdm,/* Called with rcu_read_lock held. */ bool memory_get_xlat_addr (IOMMUTLBEntry *iotlb,void **vaddr,ram_addr_t *ram_addr,bool *read_only, -bool *mr_has_discard_manager) +bool *mr_has_discard_manager,Error **errp) {MemoryRegion *mr;hwaddr xlat;@@ -2197,7 +2197,7 @@ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr, mr =address_space_translate (&address_space_memory, iotlb->translated_addr, &xlat, &len, writable,MEMTXATTRS_UNSPECIFIED );if (!memory_region_is_ram (mr)) { -error_report ("iommu map to non memory area %" HWADDR_PRIx"" , xlat); +error_setg (errp,"iommu map to non memory area %" HWADDR_PRIx"" , xlat);return false; }else if (memory_region_has_ram_discard_manager (mr)) {RamDiscardManager *rdm =memory_region_get_ram_discard_manager (mr);@@ -2216,8 +2216,8 @@ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr,* were already restored before IOMMUs are restored. */ if (!ram_discard_manager_is_populated (rdm, &tmp)) { -error_report ("iommu map to discarded memory (e.g., unplugged via" -" virtio-mem): %" HWADDR_PRIx"" , +error_setg (errp,"iommu map to discarded memory (e.g., unplugged" +" via virtio-mem): %" HWADDR_PRIx"" , iotlb->translated_addr);return false; }
system/memory.c bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr, · line 2234
Quoted 8 lines
system/memory.c +1
-1@@ -2228,7 +2228,7 @@ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr,* check that it did not truncate too much. */ if (len & iotlb->addr_mask) { -error_report ("iommu has granularity incompatible with target AS" ); +error_setg (errp,"iommu has granularity incompatible with target AS" );return false; }
Eric
Re: [PATCH v6 7/9] memory: Add Error** argument to memory_get_xlat_addr()
In reply to Cédric Le GoaterQuoted 11 lines · Cédric Le Goater
External email: Use caution opening links or attachments
Let the callers do the reporting. This will be useful in
vfio_iommu_map_dirty_notify().Cc Michael S. Tsirkin <[email protected]>Cc Paolo Bonzini <[email protected]>Cc David Hildenbrand <[email protected]>Reviewed-by Peter Xu <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>
FWIW,
Quoted 164 lines
---
Changes in v6:
- Fixed
memory_get_xlat_addrdocumentation (Avihai)include/exec/memory.h | 15 ++++++++++++++- hw/vfio/common.c | 13 +++++++++---- hw/virtio/vhost-vdpa.c | 5 ++++- system/memory.c | 10 +++++----- 4 files changed, 32 insertions(+), 11 deletions(-)include/exec/memory.h +14
-1@@ -774,9 +774,22 @@ void ram_discard_manager_register_listener(RamDiscardManager *rdm,void ram_discard_manager_unregister_listener (RamDiscardManager *rdm,RamDiscardListener *rdl); +/** +* memory_get_xlat_addr: Extract addresses from a TLB entry +* +* @iotlb: pointer to an #IOMMUTLBEntry +* @vaddr: virtual address +* @ram_addr: RAM address +* @read_only: indicates if writes are allowed +* @mr_has_discard_manager: indicates memory is controlled by a +* RamDiscardManager +* @errp: pointer to Error*, to store an error if it happens. +* +* Return: true on success, else false setting @errp with error. +*/ bool memory_get_xlat_addr (IOMMUTLBEntry *iotlb,void **vaddr,ram_addr_t *ram_addr,bool *read_only, -bool *mr_has_discard_manager); +bool *mr_has_discard_manager,Error **errp);typedef struct CoalescedMemoryRange CoalescedMemoryRange ;typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd ;hw/vfio/common.c +9
-4@@ -253,12 +253,13 @@ static bool vfio_listener_skipped_section(MemoryRegionSection *section)/* Called with rcu_read_lock held. */ static bool vfio_get_xlat_addr (IOMMUTLBEntry *iotlb,void **vaddr, -ram_addr_t *ram_addr,bool *read_only) +ram_addr_t *ram_addr,bool *read_only, +Error **errp) {bool ret, mr_has_discard_manager; ret =memory_get_xlat_addr (iotlb, vaddr, ram_addr, read_only, - &mr_has_discard_manager); + &mr_has_discard_manager, errp);if (ret && mr_has_discard_manager) {/* * Malicious VMs might trigger discarding of IOMMU-mapped memory. The @@ -288,6 +289,7 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)hwaddr iova = iotlb->iova + giommu->iommu_offset;void *vaddr;int ret; +Error *local_err =NULL ;trace_vfio_iommu_map_notify (iotlb->perm ==IOMMU_NONE ?"UNMAP" :"MAP" , iova, iova + iotlb->addr_mask);@@ -304,7 +306,8 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)if ((iotlb->perm &IOMMU_RW ) !=IOMMU_NONE ) {bool read_only; -if (!vfio_get_xlat_addr (iotlb, &vaddr,NULL , &read_only)) { +if (!vfio_get_xlat_addr (iotlb, &vaddr,NULL , &read_only, &local_err)) { +error_report_err (local_err); goto out; }/* @@ -1213,6 +1216,7 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)VFIOContainerBase *bcontainer = giommu->bcontainer;hwaddr iova = iotlb->iova + giommu->iommu_offset;ram_addr_t translated_addr; +Error *local_err =NULL ;int ret = -EINVAL ;trace_vfio_iommu_map_dirty_notify (iova, iova + iotlb->addr_mask);@@ -1224,7 +1228,8 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb) }rcu_read_lock (); -if (!vfio_get_xlat_addr (iotlb,NULL , &translated_addr,NULL )) { +if (!vfio_get_xlat_addr (iotlb,NULL , &translated_addr,NULL , &local_err)) { +error_report_err (local_err); goto out_unlock; }hw/virtio/vhost-vdpa.c +4
-1@@ -208,6 +208,7 @@ static void vhost_vdpa_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)void *vaddr;int ret;Int128 llend; +Error *local_err =NULL ;if (iotlb->target_as != &address_space_memory) { error_report("Wrong target AS \"%s\", only system memory is allowed",@@ -227,7 +228,9 @@ static void vhost_vdpa_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)if ((iotlb->perm &IOMMU_RW ) !=IOMMU_NONE ) {bool read_only; -if (!memory_get_xlat_addr (iotlb, &vaddr,NULL , &read_only,NULL )) { +if (!memory_get_xlat_addr (iotlb, &vaddr,NULL , &read_only,NULL , + &local_err)) { +error_report_err (local_err);return ; } ret = vhost_vdpa_dma_map(s, VHOST_VDPA_GUEST_PA_ASID, iova,system/memory.c +5
-6@@ -2179,7 +2179,7 @@ void ram_discard_manager_unregister_listener(RamDiscardManager *rdm,/* Called with rcu_read_lock held. */ bool memory_get_xlat_addr (IOMMUTLBEntry *iotlb,void **vaddr,ram_addr_t *ram_addr,bool *read_only, -bool *mr_has_discard_manager) +bool *mr_has_discard_manager,Error **errp) {MemoryRegion *mr;hwaddr xlat;@@ -2197,7 +2197,7 @@ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr, mr =address_space_translate (&address_space_memory, iotlb->translated_addr, &xlat, &len, writable,MEMTXATTRS_UNSPECIFIED );if (!memory_region_is_ram (mr)) { -error_report ("iommu map to non memory area %" HWADDR_PRIx"" , xlat); +error_setg (errp,"iommu map to non memory area %" HWADDR_PRIx"" , xlat);return false; }else if (memory_region_has_ram_discard_manager (mr)) {RamDiscardManager *rdm =memory_region_get_ram_discard_manager (mr);@@ -2216,8 +2216,8 @@ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr,* were already restored before IOMMUs are restored. */ if (!ram_discard_manager_is_populated (rdm, &tmp)) { -error_report ("iommu map to discarded memory (e.g., unplugged via" -" virtio-mem): %" HWADDR_PRIx"" , +error_setg (errp,"iommu map to discarded memory (e.g., unplugged" +" via virtio-mem): %" HWADDR_PRIx"" , iotlb->translated_addr);return false; }@@ -2228,7 +2228,7 @@ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr,* check that it did not truncate too much. */ if (len & iotlb->addr_mask) { -error_report ("iommu has granularity incompatible with target AS" ); +error_setg (errp,"iommu has granularity incompatible with target AS" );return false; } --2.45.0
PATCH v6 8/9 vfio: Add Error** argument to .get_dirty_bitmap() handler
In reply to Cédric Le GoaterLet the callers do the error reporting. Add documentation while at it.
---
Changes in v6:
- Fixed the line wrapping (Avihai)
- Fixed query_dirty_bitmap documentation (Avihai)
Changes in v5:
- Replaced error_setg() by error_setg_errno() in vfio_devices_query_dirty_bitmap() and vfio_legacy_query_dirty_bitmap()
- ':' -> '-' in vfio_iommu_map_dirty_notify()
include/hw/vfio/vfio-common.h | 4 +- include/hw/vfio/vfio-container-base.h | 21 +++++++-- hw/vfio/common.c | 61 ++++++++++++++++++--------- hw/vfio/container-base.c | 7 +-- hw/vfio/container.c | 14 +++--- 5 files changed, 72 insertions(+), 35 deletions(-)
include/hw/vfio/vfio-common.h +2 -2
@@ -274,9 +274,9 @@ bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer);int vfio_devices_query_dirty_bitmap (const VFIOContainerBase *bcontainer,VFIOBitmap *vbmap,hwaddr iova, -hwaddr size); +hwaddr size,Error **errp);int vfio_get_dirty_bitmap (const VFIOContainerBase *bcontainer,uint64_t iova, -uint64_t size,ram_addr_t ram_addr); +uint64_t size,ram_addr_t ram_addr,Error **errp);/* Returns 0 on success, or a negative errno. */ int vfio_device_get_name (VFIODevice *vbasedev,Error **errp);
include/hw/vfio/vfio-container-base.h +17 -4
@@ -84,8 +84,8 @@ void vfio_container_del_section_window(VFIOContainerBase *bcontainer,int vfio_container_set_dirty_page_tracking (VFIOContainerBase *bcontainer,bool start,Error **errp);int vfio_container_query_dirty_bitmap (const VFIOContainerBase *bcontainer, -VFIOBitmap *vbmap, -hwaddr iova,hwaddr size); +VFIOBitmap *vbmap,hwaddr iova, +hwaddr size,Error **errp); void vfio_container_init(VFIOContainerBase *bcontainer, VFIOAddressSpace *space,
@@ -138,9 +138,22 @@ struct VFIOIOMMUClass {*/ int (*set_dirty_page_tracking)(const VFIOContainerBase *bcontainer,bool start,Error **errp); +/** +* @query_dirty_bitmap +* +* Get bitmap of dirty pages from container +* +* @bcontainer: #VFIOContainerBase from which to get dirty pages +* @vbmap: #VFIOBitmap internal bitmap structure +* @iova: iova base address +* @size: size of iova range +* @errp: pointer to Error*, to store an error if it happens. +* +* Returns zero to indicate success and negative for error +*/ int (*query_dirty_bitmap)(const VFIOContainerBase *bcontainer, -VFIOBitmap *vbmap, -hwaddr iova,hwaddr size); +VFIOBitmap *vbmap,hwaddr iova,hwaddr size, +Error **errp);/* PCI specific */ int (*pci_hot_reset)(VFIODevice *vbasedev,bool single);
hw/vfio/common.c +40 -21
139 lines not on this page · raw message
hw/vfio/container-base.c +4 -3
@@ -64,11 +64,12 @@ int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, }int vfio_container_query_dirty_bitmap (const VFIOContainerBase *bcontainer, -VFIOBitmap *vbmap, -hwaddr iova,hwaddr size) +VFIOBitmap *vbmap,hwaddr iova, +hwaddr size,Error **errp) {g_assert (bcontainer->ops->query_dirty_bitmap); -return bcontainer->ops->query_dirty_bitmap (bcontainer, vbmap, iova, size); +return bcontainer->ops->query_dirty_bitmap (bcontainer, vbmap, iova, size, + errp); } void vfio_container_init(VFIOContainerBase *bcontainer, VFIOAddressSpace *space,
hw/vfio/container.c +9 -5
@@ -130,6 +130,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer, };bool need_dirty_sync = false;int ret; +Error *local_err =NULL ;if (iotlb &&vfio_devices_all_running_and_mig_active (bcontainer)) { if (!vfio_devices_all_device_dirty_tracking(bcontainer) &&
@@ -165,8 +166,9 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer,if (need_dirty_sync) { ret =vfio_get_dirty_bitmap (bcontainer, iova, size, - iotlb->translated_addr); + iotlb->translated_addr, &local_err);if (ret) { +error_report_err (local_err);return ret; } }
@@ -236,7 +238,8 @@ vfio_legacy_set_dirty_page_tracking(const VFIOContainerBase *bcontainer,static int vfio_legacy_query_dirty_bitmap (const VFIOContainerBase *bcontainer,VFIOBitmap *vbmap, -hwaddr iova,hwaddr size) +hwaddr iova,hwaddr size, +Error **errp) {const VFIOContainer *container =container_of (bcontainer, VFIOContainer, bcontainer);
@@ -264,9 +267,10 @@ static int vfio_legacy_query_dirty_bitmap(const VFIOContainerBase *bcontainer, ret =ioctl (container->fd,VFIO_IOMMU_DIRTY_PAGES , dbitmap);if (ret) { ret = -errno; -error_report ("Failed to get dirty bitmap for iova: 0x%" PRIx64 -" size: 0x%" PRIx64" err: %d" , (uint64_t )range->iova, - (uint64_t )range->size, errno); +error_setg_errno (errp, errno, +"Failed to get dirty bitmap for iova: 0x%" PRIx64 +" size: 0x%" PRIx64, (uint64_t )range->iova, + (uint64_t )range->size); }g_free (dbitmap);
Signature · 1 line
2.45.0
Re: [PATCH v6 8/9] vfio: Add Error** argument to .get_dirty_bitmap() handler
Quoted 289 lines · Cédric Le Goater
Let the callers do the error reporting. Add documentation while at it.
Signed-off-by Cédric Le Goater <[email protected]>---
Changes in v6:
- Fixed the line wrapping (Avihai)
- Fixedquery_dirty_bitmapdocumentation (Avihai)Changes in v5:
- Replaced
error_setg()byerror_setg_errno()invfio_devices_query_dirty_bitmap()andvfio_legacy_query_dirty_bitmap()
- ':' -> '-' invfio_iommu_map_dirty_notify()include/hw/vfio/vfio-common.h | 4 +- include/hw/vfio/vfio-container-base.h | 21 +++++++-- hw/vfio/common.c | 61 ++++++++++++++++++--------- hw/vfio/container-base.c | 7 +-- hw/vfio/container.c | 14 +++--- 5 files changed, 72 insertions(+), 35 deletions(-)include/hw/vfio/vfio-common.h +2
-2@@ -274,9 +274,9 @@ bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer);int vfio_devices_query_dirty_bitmap (const VFIOContainerBase *bcontainer,VFIOBitmap *vbmap,hwaddr iova, -hwaddr size); +hwaddr size,Error **errp);int vfio_get_dirty_bitmap (const VFIOContainerBase *bcontainer,uint64_t iova, -uint64_t size,ram_addr_t ram_addr); +uint64_t size,ram_addr_t ram_addr,Error **errp);/* Returns 0 on success, or a negative errno. */ int vfio_device_get_name (VFIODevice *vbasedev,Error **errp);include/hw/vfio/vfio-container-base.h +17
-4@@ -84,8 +84,8 @@ void vfio_container_del_section_window(VFIOContainerBase *bcontainer,int vfio_container_set_dirty_page_tracking (VFIOContainerBase *bcontainer,bool start,Error **errp);int vfio_container_query_dirty_bitmap (const VFIOContainerBase *bcontainer, -VFIOBitmap *vbmap, -hwaddr iova,hwaddr size); +VFIOBitmap *vbmap,hwaddr iova, +hwaddr size,Error **errp); void vfio_container_init(VFIOContainerBase *bcontainer, VFIOAddressSpace *space,@@ -138,9 +138,22 @@ struct VFIOIOMMUClass {*/ int (*set_dirty_page_tracking)(const VFIOContainerBase *bcontainer,bool start,Error **errp); +/** +* @query_dirty_bitmap +* +* Get bitmap of dirty pages from container +* +* @bcontainer: #VFIOContainerBase from which to get dirty pages +* @vbmap: #VFIOBitmap internal bitmap structure +* @iova: iova base address +* @size: size of iova range +* @errp: pointer to Error*, to store an error if it happens. +* +* Returns zero to indicate success and negative for error +*/ int (*query_dirty_bitmap)(const VFIOContainerBase *bcontainer, -VFIOBitmap *vbmap, -hwaddr iova,hwaddr size); +VFIOBitmap *vbmap,hwaddr iova,hwaddr size, +Error **errp);/* PCI specific */ int (*pci_hot_reset)(VFIODevice *vbasedev,bool single);hw/vfio/common.c +40
-21@@ -1140,8 +1140,8 @@ static int vfio_device_dma_logging_report(VFIODevice *vbasedev, hwaddr iova, }int vfio_devices_query_dirty_bitmap (const VFIOContainerBase *bcontainer, -VFIOBitmap *vbmap,hwaddr iova, -hwaddr size) +VFIOBitmap *vbmap,hwaddr iova,hwaddr size, +Error **errp) {VFIODevice *vbasedev;int ret;@@ -1150,10 +1150,10 @@ int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, ret =vfio_device_dma_logging_report (vbasedev, iova, size, vbmap->bitmap);if (ret) { -error_report ("%s: Failed to get DMA logging report, iova: " -"0x%" HWADDR_PRIx", size: 0x%" HWADDR_PRIx -", err: %d (%s)" , - vbasedev->name, iova, size, ret,strerror (-ret)); +error_setg_errno (errp, -ret, +"%s: Failed to get DMA logging report, iova: " +"0x%" HWADDR_PRIx", size: 0x%" HWADDR_PRIx, + vbasedev->name, iova, size);return ret; }@@ -1163,7 +1163,7 @@ int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, }int vfio_get_dirty_bitmap (const VFIOContainerBase *bcontainer,uint64_t iova, -uint64_t size,ram_addr_t ram_addr) +uint64_t size,ram_addr_t ram_addr,Error **errp) {bool all_device_dirty_tracking =vfio_devices_all_device_dirty_tracking (bcontainer);@@ -1180,13 +1180,17 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova, ret =vfio_bitmap_alloc (&vbmap, size);if (ret) { +error_setg_errno (errp, -ret, +"Failed to allocate dirty tracking bitmap" );return ret; }if (all_device_dirty_tracking) { - ret =vfio_devices_query_dirty_bitmap (bcontainer, &vbmap, iova, size); + ret =vfio_devices_query_dirty_bitmap (bcontainer, &vbmap, iova, size, + errp); }else { - ret =vfio_container_query_dirty_bitmap (bcontainer, &vbmap, iova, size); + ret =vfio_container_query_dirty_bitmap (bcontainer, &vbmap, iova, size, + errp); }if (ret) {@@ -1234,12 +1238,13 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb) } ret =vfio_get_dirty_bitmap (bcontainer, iova, iotlb->addr_mask +1 , - translated_addr); + translated_addr, &local_err);if (ret) { -error_report ("vfio_iommu_map_dirty_notify(%p, 0x%" HWADDR_PRIx", " -"0x%" HWADDR_PRIx") = %d (%s)" , - bcontainer, iova, iotlb->addr_mask +1 , ret, -strerror (-ret)); +error_prepend (&local_err, +"vfio_iommu_map_dirty_notify(%p, 0x%" HWADDR_PRIx", " +"0x%" HWADDR_PRIx") failed - " , bcontainer, iova, + iotlb->addr_mask +1 ); +error_report_err (local_err); } out_unlock:@@ -1259,12 +1264,19 @@ static int vfio_ram_discard_get_dirty_bitmap(MemoryRegionSection *section,const ram_addr_t ram_addr =memory_region_get_ram_addr (section->mr) + section->offset_within_region;VFIORamDiscardListener *vrdl = opaque; +Error *local_err =NULL ; +int ret;/* * Sync the whole mapped region (spanning multiple individual mappings) * in one go. */ -return vfio_get_dirty_bitmap (vrdl->bcontainer, iova, size, ram_addr); + ret =vfio_get_dirty_bitmap (vrdl->bcontainer, iova, size, ram_addr, + &local_err); +if (ret) { +error_report_err (local_err); + } +return ret; } static int@@ -1296,7 +1308,7 @@ vfio_sync_ram_discard_listener_dirty_bitmap(VFIOContainerBase *bcontainer, }static int vfio_sync_dirty_bitmap (VFIOContainerBase *bcontainer, -MemoryRegionSection *section) +MemoryRegionSection *section,Error **errp) {ram_addr_t ram_addr;@@ -1327,7 +1339,14 @@ static int vfio_sync_dirty_bitmap(VFIOContainerBase *bcontainer, }return 0 ; }else if (memory_region_has_ram_discard_manager (section->mr)) { -return vfio_sync_ram_discard_listener_dirty_bitmap (bcontainer, section); +int ret; + + ret =vfio_sync_ram_discard_listener_dirty_bitmap (bcontainer, section); +if (ret) { +error_setg (errp, +"Failed to sync dirty bitmap with RAM discard listener" ); +return ret; + } } ram_addr = memory_region_get_ram_addr(section->mr) +@@ -1335,7 +1354,7 @@ static int vfio_sync_dirty_bitmap(VFIOContainerBase *bcontainer,return vfio_get_dirty_bitmap (bcontainer,REAL_HOST_PAGE_ALIGN (section->offset_within_address_space), -int128_get64 (section->size), ram_addr); +int128_get64 (section->size), ram_addr, errp); } static void vfio_listener_log_sync(MemoryListener *listener,@@ -1344,16 +1363,16 @@ static void vfio_listener_log_sync(MemoryListener *listener,VFIOContainerBase *bcontainer =container_of (listener, VFIOContainerBase, listener);int ret; +Error *local_err =NULL ;if (vfio_listener_skipped_section (section)) {return ; }if (vfio_devices_all_dirty_tracking (bcontainer)) { - ret =vfio_sync_dirty_bitmap (bcontainer, section); + ret =vfio_sync_dirty_bitmap (bcontainer, section, &local_err);if (ret) { -error_report ("vfio: Failed to sync dirty bitmap, err: %d (%s)" , ret, -strerror (-ret)); +error_report_err (local_err);vfio_set_migration_error (ret); } }hw/vfio/container-base.c +4
-3@@ -64,11 +64,12 @@ int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, }int vfio_container_query_dirty_bitmap (const VFIOContainerBase *bcontainer, -VFIOBitmap *vbmap, -hwaddr iova,hwaddr size) +VFIOBitmap *vbmap,hwaddr iova, +hwaddr size,Error **errp) {g_assert (bcontainer->ops->query_dirty_bitmap); -return bcontainer->ops->query_dirty_bitmap (bcontainer, vbmap, iova, size); +return bcontainer->ops->query_dirty_bitmap (bcontainer, vbmap, iova, size, + errp); } void vfio_container_init(VFIOContainerBase *bcontainer, VFIOAddressSpace *space,hw/vfio/container.c +5
-2@@ -130,6 +130,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer, };bool need_dirty_sync = false;int ret; +Error *local_err =NULL ;if (iotlb &&vfio_devices_all_running_and_mig_active (bcontainer)) { if (!vfio_devices_all_device_dirty_tracking(bcontainer) &&@@ -165,8 +166,9 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer,if (need_dirty_sync) { ret =vfio_get_dirty_bitmap (bcontainer, iova, size, - iotlb->translated_addr); + iotlb->translated_addr, &local_err);if (ret) { +error_report_err (local_err);return ret; } }@@ -236,7 +238,8 @@ vfio_legacy_set_dirty_page_tracking(const VFIOContainerBase *bcontainer,static int vfio_legacy_query_dirty_bitmap (const VFIOContainerBase *bcontainer,VFIOBitmap *vbmap, -hwaddr iova,hwaddr size) +hwaddr iova,hwaddr size, +Error **errp) {const VFIOContainer *container =container_of (bcontainer, VFIOContainer, bcontainer);@@ -264,9 +267,10 @@ static int vfio_legacy_query_dirty_bitmap(const VFIOContainerBase *bcontainer, ret =ioctl (container->fd,VFIO_IOMMU_DIRTY_PAGES , dbitmap);if (ret) { ret = -errno;
hw/vfio/container.c static int vfio_legacy_query_dirty_bitmap(const VFIOContainerBase *bcontainer, · line 276
Quoted 10 lines
hw/vfio/container.c +4
-3-error_report ("Failed to get dirty bitmap for iova: 0x%" PRIx64 -" size: 0x%" PRIx64" err: %d" , (uint64_t )range->iova, - (uint64_t )range->size, errno); +error_setg_errno (errp, errno, +"Failed to get dirty bitmap for iova: 0x%" PRIx64 +" size: 0x%" PRIx64, (uint64_t )range->iova, + (uint64_t )range->size); }g_free (dbitmap);
Eric
Re: [PATCH v6 8/9] vfio: Add Error** argument to .get_dirty_bitmap() handler
In reply to Cédric Le GoaterQuoted 31 lines · Cédric Le Goater
External email: Use caution opening links or attachments
Let the callers do the error reporting. Add documentation while at it.
Signed-off-by Cédric Le Goater <[email protected]>---
Changes in v6:
- Fixed the line wrapping (Avihai)
- Fixedquery_dirty_bitmapdocumentation (Avihai)Changes in v5:
- Replaced
error_setg()byerror_setg_errno()invfio_devices_query_dirty_bitmap()andvfio_legacy_query_dirty_bitmap()
- ':' -> '-' invfio_iommu_map_dirty_notify()include/hw/vfio/vfio-common.h | 4 +- include/hw/vfio/vfio-container-base.h | 21 +++++++-- hw/vfio/common.c | 61 ++++++++++++++++++--------- hw/vfio/container-base.c | 7 +-- hw/vfio/container.c | 14 +++--- 5 files changed, 72 insertions(+), 35 deletions(-)include/hw/vfio/vfio-common.h +0
-0
include/hw/vfio/vfio-common.h bool · line 277
Quoted 5 lines
include/hw/vfio/vfio-common.h +1
-1@@ -274,9 +274,9 @@ bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer);int vfio_devices_query_dirty_bitmap (const VFIOContainerBase *bcontainer,VFIOBitmap *vbmap,hwaddr iova, -hwaddr size); +hwaddr size,Error **errp);
[*] Can be wrapped like:
int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, VFIOBitmap *vbmap, hwaddr iova, hwaddr size,
Error **errp);
Quoted 157 lines
include/hw/vfio/vfio-common.h +1
-1int vfio_get_dirty_bitmap (const VFIOContainerBase *bcontainer,uint64_t iova, -uint64_t size,ram_addr_t ram_addr); +uint64_t size,ram_addr_t ram_addr,Error **errp);/* Returns 0 on success, or a negative errno. */ int vfio_device_get_name (VFIODevice *vbasedev,Error **errp);include/hw/vfio/vfio-container-base.h +17
-4@@ -84,8 +84,8 @@ void vfio_container_del_section_window(VFIOContainerBase *bcontainer,int vfio_container_set_dirty_page_tracking (VFIOContainerBase *bcontainer,bool start,Error **errp);int vfio_container_query_dirty_bitmap (const VFIOContainerBase *bcontainer, -VFIOBitmap *vbmap, -hwaddr iova,hwaddr size); +VFIOBitmap *vbmap,hwaddr iova, +hwaddr size,Error **errp); void vfio_container_init(VFIOContainerBase *bcontainer, VFIOAddressSpace *space,@@ -138,9 +138,22 @@ struct VFIOIOMMUClass {*/ int (*set_dirty_page_tracking)(const VFIOContainerBase *bcontainer,bool start,Error **errp); +/** +* @query_dirty_bitmap +* +* Get bitmap of dirty pages from container +* +* @bcontainer: #VFIOContainerBase from which to get dirty pages +* @vbmap: #VFIOBitmap internal bitmap structure +* @iova: iova base address +* @size: size of iova range +* @errp: pointer to Error*, to store an error if it happens. +* +* Returns zero to indicate success and negative for error +*/ int (*query_dirty_bitmap)(const VFIOContainerBase *bcontainer, -VFIOBitmap *vbmap, -hwaddr iova,hwaddr size); +VFIOBitmap *vbmap,hwaddr iova,hwaddr size, +Error **errp);/* PCI specific */ int (*pci_hot_reset)(VFIODevice *vbasedev,bool single);hw/vfio/common.c +28
-16@@ -1140,8 +1140,8 @@ static int vfio_device_dma_logging_report(VFIODevice *vbasedev, hwaddr iova, }int vfio_devices_query_dirty_bitmap (const VFIOContainerBase *bcontainer, -VFIOBitmap *vbmap,hwaddr iova, -hwaddr size) +VFIOBitmap *vbmap,hwaddr iova,hwaddr size, +Error **errp) {VFIODevice *vbasedev;int ret;@@ -1150,10 +1150,10 @@ int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, ret =vfio_device_dma_logging_report (vbasedev, iova, size, vbmap->bitmap);if (ret) { -error_report ("%s: Failed to get DMA logging report, iova: " -"0x%" HWADDR_PRIx", size: 0x%" HWADDR_PRIx -", err: %d (%s)" , - vbasedev->name, iova, size, ret,strerror (-ret)); +error_setg_errno (errp, -ret, +"%s: Failed to get DMA logging report, iova: " +"0x%" HWADDR_PRIx", size: 0x%" HWADDR_PRIx, + vbasedev->name, iova, size);return ret; }@@ -1163,7 +1163,7 @@ int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, }int vfio_get_dirty_bitmap (const VFIOContainerBase *bcontainer,uint64_t iova, -uint64_t size,ram_addr_t ram_addr) +uint64_t size,ram_addr_t ram_addr,Error **errp) {bool all_device_dirty_tracking =vfio_devices_all_device_dirty_tracking (bcontainer);@@ -1180,13 +1180,17 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova, ret =vfio_bitmap_alloc (&vbmap, size);if (ret) { +error_setg_errno (errp, -ret, +"Failed to allocate dirty tracking bitmap" );return ret; }if (all_device_dirty_tracking) { - ret =vfio_devices_query_dirty_bitmap (bcontainer, &vbmap, iova, size); + ret =vfio_devices_query_dirty_bitmap (bcontainer, &vbmap, iova, size, + errp); }else { - ret =vfio_container_query_dirty_bitmap (bcontainer, &vbmap, iova, size); + ret =vfio_container_query_dirty_bitmap (bcontainer, &vbmap, iova, size, + errp); }if (ret) {@@ -1234,12 +1238,13 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb) } ret =vfio_get_dirty_bitmap (bcontainer, iova, iotlb->addr_mask +1 , - translated_addr); + translated_addr, &local_err);if (ret) { -error_report ("vfio_iommu_map_dirty_notify(%p, 0x%" HWADDR_PRIx", " -"0x%" HWADDR_PRIx") = %d (%s)" , - bcontainer, iova, iotlb->addr_mask +1 , ret, -strerror (-ret)); +error_prepend (&local_err, +"vfio_iommu_map_dirty_notify(%p, 0x%" HWADDR_PRIx", " +"0x%" HWADDR_PRIx") failed - " , bcontainer, iova, + iotlb->addr_mask +1 ); +error_report_err (local_err); } out_unlock:@@ -1259,12 +1264,19 @@ static int vfio_ram_discard_get_dirty_bitmap(MemoryRegionSection *section,const ram_addr_t ram_addr =memory_region_get_ram_addr (section->mr) + section->offset_within_region;VFIORamDiscardListener *vrdl = opaque; +Error *local_err =NULL ; +int ret;/* * Sync the whole mapped region (spanning multiple individual mappings) * in one go. */ -return vfio_get_dirty_bitmap (vrdl->bcontainer, iova, size, ram_addr); + ret =vfio_get_dirty_bitmap (vrdl->bcontainer, iova, size, ram_addr, + &local_err); +if (ret) { +error_report_err (local_err); + } +return ret; } static int@@ -1296,7 +1308,7 @@ vfio_sync_ram_discard_listener_dirty_bitmap(VFIOContainerBase *bcontainer, }static int vfio_sync_dirty_bitmap (VFIOContainerBase *bcontainer, -MemoryRegionSection *section) +MemoryRegionSection *section,Error **errp) {ram_addr_t ram_addr;@@ -1327,7 +1339,14 @@ static int vfio_sync_dirty_bitmap(VFIOContainerBase *bcontainer, }return 0 ;
hw/vfio/common.c static int vfio_sync_dirty_bitmap(VFIOContainerBase *bcontainer, · line 1349
Quoted 10 lines
hw/vfio/common.c +8
-1}else if (memory_region_has_ram_discard_manager (section->mr)) { -return vfio_sync_ram_discard_listener_dirty_bitmap (bcontainer, section); +int ret; + + ret =vfio_sync_ram_discard_listener_dirty_bitmap (bcontainer, section); +if (ret) { +error_setg (errp, +"Failed to sync dirty bitmap with RAM discard listener" ); +return ret; + }
Need to move "return ret" out of the "if (ret)" branch -- we need to immediately return from the else if branch also on success.
With that,
(Nit: there are 2 more places where line wrapping can be improved, if you want. Marked them with [*])
Quoted 76 lines
hw/vfio/common.c +4
-4} ram_addr = memory_region_get_ram_addr(section->mr) +@@ -1335,7 +1354,7 @@ static int vfio_sync_dirty_bitmap(VFIOContainerBase *bcontainer,return vfio_get_dirty_bitmap (bcontainer,REAL_HOST_PAGE_ALIGN (section->offset_within_address_space), -int128_get64 (section->size), ram_addr); +int128_get64 (section->size), ram_addr, errp); } static void vfio_listener_log_sync(MemoryListener *listener,@@ -1344,16 +1363,16 @@ static void vfio_listener_log_sync(MemoryListener *listener,VFIOContainerBase *bcontainer =container_of (listener, VFIOContainerBase, listener);int ret; +Error *local_err =NULL ;if (vfio_listener_skipped_section (section)) {return ; }if (vfio_devices_all_dirty_tracking (bcontainer)) { - ret =vfio_sync_dirty_bitmap (bcontainer, section); + ret =vfio_sync_dirty_bitmap (bcontainer, section, &local_err);if (ret) { -error_report ("vfio: Failed to sync dirty bitmap, err: %d (%s)" , ret, -strerror (-ret)); +error_report_err (local_err);vfio_set_migration_error (ret); } }hw/vfio/container-base.c +4
-3@@ -64,11 +64,12 @@ int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, }int vfio_container_query_dirty_bitmap (const VFIOContainerBase *bcontainer, -VFIOBitmap *vbmap, -hwaddr iova,hwaddr size) +VFIOBitmap *vbmap,hwaddr iova, +hwaddr size,Error **errp) {g_assert (bcontainer->ops->query_dirty_bitmap); -return bcontainer->ops->query_dirty_bitmap (bcontainer, vbmap, iova, size); +return bcontainer->ops->query_dirty_bitmap (bcontainer, vbmap, iova, size, + errp); } void vfio_container_init(VFIOContainerBase *bcontainer, VFIOAddressSpace *space,hw/vfio/container.c +3
-1@@ -130,6 +130,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer, };bool need_dirty_sync = false;int ret; +Error *local_err =NULL ;if (iotlb &&vfio_devices_all_running_and_mig_active (bcontainer)) { if (!vfio_devices_all_device_dirty_tracking(bcontainer) &&@@ -165,8 +166,9 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer,if (need_dirty_sync) { ret =vfio_get_dirty_bitmap (bcontainer, iova, size, - iotlb->translated_addr); + iotlb->translated_addr, &local_err);if (ret) { +error_report_err (local_err);return ret; } }
hw/vfio/container.c vfio_legacy_set_dirty_page_tracking(const VFIOContainerBase *bcontainer, · line 242
Quoted 6 lines
hw/vfio/container.c +2
-1@@ -236,7 +238,8 @@ vfio_legacy_set_dirty_page_tracking(const VFIOContainerBase *bcontainer,static int vfio_legacy_query_dirty_bitmap (const VFIOContainerBase *bcontainer,VFIOBitmap *vbmap, -hwaddr iova,hwaddr size) +hwaddr iova,hwaddr size, +Error **errp)
[*] Can be wrapped like:
static int vfio_legacy_query_dirty_bitmap(const VFIOContainerBase *bcontainer, VFIOBitmap *vbmap, hwaddr iova,
hwaddr size, Error **errp)
Thanks.
Quoted 20 lines
hw/vfio/container.c +4
-4{const VFIOContainer *container =container_of (bcontainer, VFIOContainer, bcontainer);@@ -264,9 +267,10 @@ static int vfio_legacy_query_dirty_bitmap(const VFIOContainerBase *bcontainer, ret =ioctl (container->fd,VFIO_IOMMU_DIRTY_PAGES , dbitmap);if (ret) { ret = -errno; -error_report ("Failed to get dirty bitmap for iova: 0x%" PRIx64 -" size: 0x%" PRIx64" err: %d" , (uint64_t )range->iova, - (uint64_t )range->size, errno); +error_setg_errno (errp, errno, +"Failed to get dirty bitmap for iova: 0x%" PRIx64 +" size: 0x%" PRIx64, (uint64_t )range->iova, + (uint64_t )range->size); }g_free (dbitmap); --2.45.0
Re: [PATCH v6 8/9] vfio: Add Error** argument to .get_dirty_bitmap() handler
Quoted 41 lines · Avihai Horon
Quoted 31 lines · Cédric Le Goater
External email: Use caution opening links or attachments
Let the callers do the error reporting. Add documentation while at it.
Signed-off-by Cédric Le Goater <[email protected]>---
Changes in v6:
- Fixed the line wrapping (Avihai)
- Fixedquery_dirty_bitmapdocumentation (Avihai)Changes in v5:
- Replaced
error_setg()byerror_setg_errno()invfio_devices_query_dirty_bitmap()andvfio_legacy_query_dirty_bitmap()
- ':' -> '-' invfio_iommu_map_dirty_notify()include/hw/vfio/vfio-common.h | 4 +-
include/hw/vfio/vfio-container-base.h| 21 +++++++-- hw/vfio/common.c | 61 ++++++++++++++++++--------- hw/vfio/container-base.c | 7 +-- hw/vfio/container.c | 14 +++---5 files changed, 72 insertions(+), 35 deletions(-)include/hw/vfio/vfio-common.h +0
-0include/hw/vfio/vfio-common.h bool · line 277
Quoted 5 lines
include/hw/vfio/vfio-common.h +1
-1@@ -274,9 +274,9 @@ bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer); int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, VFIOBitmap *vbmap, hwaddr iova, - hwaddr size); + hwaddr size, Error **errp);[*] Can be wrapped like:
Quoted 3 lines
int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
VFIOBitmap *vbmap, hwaddr iova, hwaddr size,
Error **errp);
OK. So I changed all *_dirty_bitmap() prototypes.
Quoted 154 lines
Quoted 154 lines
include/hw/vfio/vfio-common.h +1
-1int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova, - uint64_t size, ram_addr_t ram_addr); + uint64_t size, ram_addr_t ram_addr, Error **errp); /* Returns 0 on success, or a negative errno. */ int vfio_device_get_name(VFIODevice *vbasedev, Error **errp);include/hw/vfio/vfio-container-base.h +17
-4@@ -84,8 +84,8 @@ void vfio_container_del_section_window(VFIOContainerBase *bcontainer, int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, bool start, Error **errp); int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer, - VFIOBitmap *vbmap, - hwaddr iova, hwaddr size); + VFIOBitmap *vbmap, hwaddr iova, + hwaddr size, Error **errp); void vfio_container_init(VFIOContainerBase *bcontainer, VFIOAddressSpace *space,@@ -138,9 +138,22 @@ struct VFIOIOMMUClass {*/ int (*set_dirty_page_tracking)(const VFIOContainerBase *bcontainer, bool start, Error **errp); + /** + * @query_dirty_bitmap + * + * Get bitmap of dirty pages from container + * + * @bcontainer: #VFIOContainerBase from which to get dirty pages + * @vbmap: #VFIOBitmap internal bitmap structure + * @iova: iova base address + * @size: size of iova range + * @errp: pointer to Error*, to store an error if it happens. + * + * Returns zero to indicate success and negative for error + */ int (*query_dirty_bitmap)(const VFIOContainerBase *bcontainer, - VFIOBitmap *vbmap, - hwaddr iova, hwaddr size); + VFIOBitmap *vbmap, hwaddr iova, hwaddr size, + Error **errp); /* PCI specific */ int (*pci_hot_reset)(VFIODevice *vbasedev, bool single);hw/vfio/common.c +7
-7@@ -1140,8 +1140,8 @@ static int vfio_device_dma_logging_report(VFIODevice *vbasedev, hwaddr iova, } int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, - VFIOBitmap *vbmap, hwaddr iova, - hwaddr size) + VFIOBitmap *vbmap, hwaddr iova, hwaddr size, + Error **errp) { VFIODevice *vbasedev; int ret;@@ -1150,10 +1150,10 @@ int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, ret = vfio_device_dma_logging_report(vbasedev, iova, size, vbmap->bitmap); if (ret) { - error_report("%s: Failed to get DMA logging report, iova: " - "0x%" HWADDR_PRIx ", size: 0x%" HWADDR_PRIx - ", err: %d (%s)", - vbasedev->name, iova, size, ret, strerror(-ret)); + error_setg_errno(errp, -ret, + "%s: Failed to get DMA logging report, iova: " + "0x%" HWADDR_PRIx ", size: 0x%" HWADDR_PRIx, + vbasedev->name, iova, size); return ret; }@@ -1163,7 +1163,7 @@ int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, } int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova, - uint64_t size, ram_addr_t ram_addr) + uint64_t size, ram_addr_t ram_addr, Error **errp) {bool
all_device_dirty_tracking=vfio_devices_all_device_dirty_tracking(bcontainer);hw/vfio/common.c +12
-7@@ -1180,13 +1180,17 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova, ret = vfio_bitmap_alloc(&vbmap, size); if (ret) { + error_setg_errno(errp, -ret, + "Failed to allocate dirty tracking bitmap"); return ret; } if (all_device_dirty_tracking) { - ret = vfio_devices_query_dirty_bitmap(bcontainer, &vbmap, iova, size); + ret = vfio_devices_query_dirty_bitmap(bcontainer, &vbmap, iova, size, + errp); } else { - ret = vfio_container_query_dirty_bitmap(bcontainer, &vbmap, iova, size); + ret = vfio_container_query_dirty_bitmap(bcontainer, &vbmap, iova, size, + errp); } if (ret) {@@ -1234,12 +1238,13 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb) } ret = vfio_get_dirty_bitmap(bcontainer, iova, iotlb->addr_mask + 1, - translated_addr); + translated_addr, &local_err); if (ret) { - error_report("vfio_iommu_map_dirty_notify(%p, 0x%"HWADDR_PRIx", " - "0x%"HWADDR_PRIx") = %d (%s)", - bcontainer, iova, iotlb->addr_mask + 1, ret, - strerror(-ret)); + error_prepend(&local_err, + "vfio_iommu_map_dirty_notify(%p, 0x%"HWADDR_PRIx", " + "0x%"HWADDR_PRIx") failed - ", bcontainer, iova, + iotlb->addr_mask + 1); + error_report_err(local_err); }
out_unlock:hw/vfio/common.c +0
-0@@ -1259,12 +1264,19 @@ static int vfio_ram_discard_get_dirty_bitmap(MemoryRegionSection *section,const
ram_addr_tram_addr=memory_region_get_ram_addr(section->mr)+section->offset_within_region; VFIORamDiscardListener *vrdl = opaque;
+ Error*local_err= NULL;
+ int ret;/*
* Sync the whole mapped region (spanning multiple individual mappings)
* in one go.
*/
- returnvfio_get_dirty_bitmap(vrdl->bcontainer, iova, size, ram_addr); + ret = vfio_get_dirty_bitmap(vrdl->bcontainer, iova, size,ram_addr, +&local_err);
+ if (ret) {
+error_report_err(local_err);
+ }
+ return ret;
}static int
hw/vfio/common.c +1
-1@@ -1296,7 +1308,7 @@ vfio_sync_ram_discard_listener_dirty_bitmap(VFIOContainerBase *bcontainer, } static int vfio_sync_dirty_bitmap(VFIOContainerBase *bcontainer, - MemoryRegionSection *section) + MemoryRegionSection *section, Error **errp) { ram_addr_t ram_addr;
Quoted 15 lines
hw/vfio/common.c static int vfio_sync_dirty_bitmap(VFIOContainerBase *bcontainer, · line 1349
Quoted 13 lines
hw/vfio/common.c +8
-1@@ -1327,7 +1339,14 @@ static int vfio_sync_dirty_bitmap(VFIOContainerBase *bcontainer, } return 0; } else if (memory_region_has_ram_discard_manager(section->mr)) { - return vfio_sync_ram_discard_listener_dirty_bitmap(bcontainer, section); + int ret; + + ret = vfio_sync_ram_discard_listener_dirty_bitmap(bcontainer, section); + if (ret) { + error_setg(errp, + "Failed to sync dirty bitmap with RAM discard listener"); + return ret; + }Need to move "return ret" out of the "if (ret)" branch -- we need to immediately return from the else if branch also on success.
drat. Good catch. This deserves a v7.
Thanks,
C.
Quoted 117 lines
With that,
Reviewed-by Avihai Horon <[email protected]>(Nit: there are 2 more places where line wrapping can be improved, if you want. Marked them with [*])
Quoted 76 lines
hw/vfio/common.c +0
-0}
ram_addr=memory_region_get_ram_addr(section->mr)+hw/vfio/common.c +4
-4@@ -1335,7 +1354,7 @@ static int vfio_sync_dirty_bitmap(VFIOContainerBase *bcontainer, return vfio_get_dirty_bitmap(bcontainer, REAL_HOST_PAGE_ALIGN(section->offset_within_address_space), - int128_get64(section->size), ram_addr); + int128_get64(section->size), ram_addr, errp); } static void vfio_listener_log_sync(MemoryListener *listener,@@ -1344,16 +1363,16 @@ static void vfio_listener_log_sync(MemoryListener *listener, VFIOContainerBase *bcontainer = container_of(listener, VFIOContainerBase, listener); int ret; + Error *local_err = NULL; if (vfio_listener_skipped_section(section)) { return; } if (vfio_devices_all_dirty_tracking(bcontainer)) { - ret = vfio_sync_dirty_bitmap(bcontainer, section); + ret = vfio_sync_dirty_bitmap(bcontainer, section, &local_err); if (ret) { - error_report("vfio: Failed to sync dirty bitmap, err: %d (%s)", ret, - strerror(-ret)); + error_report_err(local_err); vfio_set_migration_error(ret); } }hw/vfio/container-base.c +4
-3@@ -64,11 +64,12 @@ int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, } int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer, - VFIOBitmap *vbmap, - hwaddr iova, hwaddr size) + VFIOBitmap *vbmap, hwaddr iova, + hwaddr size, Error **errp) { g_assert(bcontainer->ops->query_dirty_bitmap); - return bcontainer->ops->query_dirty_bitmap(bcontainer, vbmap, iova, size); + return bcontainer->ops->query_dirty_bitmap(bcontainer, vbmap, iova, size, + errp); } void vfio_container_init(VFIOContainerBase *bcontainer, VFIOAddressSpace *space,hw/vfio/container.c +1
-0@@ -130,6 +130,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer, }; bool need_dirty_sync = false; int ret; + Error *local_err = NULL; if (iotlb && vfio_devices_all_running_and_mig_active(bcontainer)) {if (!vfio_devices_all_device_dirty_tracking(bcontainer) &&
hw/vfio/container.c +2
-1@@ -165,8 +166,9 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer, if (need_dirty_sync) { ret = vfio_get_dirty_bitmap(bcontainer, iova, size, - iotlb->translated_addr); + iotlb->translated_addr, &local_err); if (ret) { + error_report_err(local_err); return ret; } }hw/vfio/container.c vfio_legacy_set_dirty_page_tracking(const VFIOContainerBase *bcontainer, · line 242
Quoted 6 lines
hw/vfio/container.c +2
-1@@ -236,7 +238,8 @@ vfio_legacy_set_dirty_page_tracking(const VFIOContainerBase *bcontainer, static int vfio_legacy_query_dirty_bitmap(const VFIOContainerBase *bcontainer, VFIOBitmap *vbmap, - hwaddr iova, hwaddr size) + hwaddr iova, hwaddr size, + Error **errp)[*] Can be wrapped like:
static int vfio_legacy_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
VFIOBitmap *vbmap, hwaddr iova,
hwaddr size, Error **errp)Thanks.
Quoted 20 lines
hw/vfio/container.c +4
-3{ const VFIOContainer *container = container_of(bcontainer, VFIOContainer, bcontainer);@@ -264,9 +267,10 @@ static int vfio_legacy_query_dirty_bitmap(const VFIOContainerBase *bcontainer, ret = ioctl(container->fd, VFIO_IOMMU_DIRTY_PAGES, dbitmap); if (ret) { ret = -errno; - error_report("Failed to get dirty bitmap for iova: 0x%"PRIx64 - " size: 0x%"PRIx64" err: %d", (uint64_t)range->iova, - (uint64_t)range->size, errno); + error_setg_errno(errp, errno, + "Failed to get dirty bitmap for iova: 0x%"PRIx64 + " size: 0x%"PRIx64, (uint64_t)range->iova, + (uint64_t)range->size); } g_free(dbitmap);Signature · 1 line
2.45.0
PATCH v6 9/9 vfio: Also trace event failures in vfio_save_complete_precopy()
In reply to Cédric Le Goatervfio_save_complete_precopy() currently returns before doing the trace event. Change that.
--- hw/vfio/migration.c | 3 --- 1 file changed, 3 deletions(-)
hw/vfio/migration.c +0 -3
@@ -585,9 +585,6 @@ static int vfio_save_complete_precopy(QEMUFile *f, void *opaque)qemu_put_be64 (f,VFIO_MIG_FLAG_END_OF_STATE ); ret =qemu_file_get_error (f); -if (ret) { -return ret; - }trace_vfio_save_complete_precopy (vbasedev->name, ret);
Signature · 1 line
2.45.0
Re: [PATCH v6 9/9] vfio: Also trace event failures in vfio_save_complete_precopy()
Quoted 14 lines · Cédric Le Goater
vfio_save_complete_precopy()currently returns before doing the trace event. Change that.Reviewed-by Avihai Horon <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>--- hw/vfio/migration.c | 3 --- 1 file changed, 3 deletions(-)hw/vfio/migration.c +0
-0
hw/vfio/migration.c static int vfio_save_complete_precopy(QEMUFile *f, void *opaque) · line 590
Quoted 9 lines
hw/vfio/migration.c +0
-3@@ -585,9 +585,6 @@ static int vfio_save_complete_precopy(QEMUFile *f, void *opaque)qemu_put_be64 (f,VFIO_MIG_FLAG_END_OF_STATE ); ret =qemu_file_get_error (f); -if (ret) { -return ret; - }trace_vfio_save_complete_precopy (vbasedev->name, ret);
Eric