vfio-user fixes
v3 cover vfio-user fixes
Some small Coverity and related fixes for the recently merged vfio-user series.
thanks
john
John Levon (4):
hw/vfio-user: add Cédric Le Goater as a maintainer hw/vfio: fix region fd initialization hw/vfio-user: wait for proxy close correctly hw/vfio-user: fix use of uninitialized variable
MAINTAINERS | 1 + hw/vfio-user/container.c | 6 +----- hw/vfio-user/proxy.c | 10 ++++++---- hw/vfio/device.c | 6 +++++- 4 files changed, 13 insertions(+), 10 deletions(-)
Signature · 1 line
2.43.0
PATCH v3 1/4 hw/vfio-user: add Cédric Le Goater as a maintainer
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -4287,6 +4287,7 @@ F: tests/functional/test_multiprocess.py VFIO-USER: M: John Levon <[email protected]> M: Thanos Makatos <[email protected]> +M: Cédric Le Goater <[email protected]> S: Supported F: docs/interop/vfio-user.rst F: docs/system/devices/vfio-user.rst
Signature · 1 line
2.43.0
PATCH v3 2/4 hw/vfio: fix region fd initialization
In reply to John LevonWe were not initializing the region fd array to -1, so we would accidentally try to close(0) on cleanup for any region that is not referenced.
--- hw/vfio/device.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
hw/vfio/device.c +5 -1
@@ -463,6 +463,8 @@ void vfio_device_detach(VFIODevice *vbasedev)void vfio_device_prepare (VFIODevice *vbasedev,VFIOContainerBase *bcontainer,struct vfio_device_info *info) { +int i; + vbasedev->num_irqs = info->num_irqs; vbasedev->num_regions = info->num_regions; vbasedev->flags = info->flags;
@@ -477,6 +479,9 @@ void vfio_device_prepare(VFIODevice *vbasedev, VFIOContainerBase *bcontainer, vbasedev->num_regions);if (vbasedev->use_region_fds) { vbasedev->region_fds =g_new0 (int, vbasedev->num_regions); +for (i =0 ; i < vbasedev->num_regions; i++) { + vbasedev->region_fds[i] =-1 ; + } } }
@@ -489,7 +494,6 @@ void vfio_device_unprepare(VFIODevice *vbasedev)if (vbasedev->region_fds !=NULL && vbasedev->region_fds[i] !=-1 ) {close (vbasedev->region_fds[i]); } - }g_clear_pointer (&vbasedev->reginfo, g_free);
Signature · 1 line
2.43.0
PATCH v3 3/4 hw/vfio-user: wait for proxy close correctly
In reply to John LevonCoverity reported:
CID 1611806: Concurrent data access violations (BAD_CHECK_OF_WAIT_COND)
A wait is performed without a loop. If there is a spurious wakeup, the condition may not be satisfied.
Fix this by checking ->state for VFIO_PROXY_CLOSED in a loop.
Also rename the callback for clarity.
--- hw/vfio-user/proxy.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
hw/vfio-user/proxy.c +6 -4
@@ -32,7 +32,6 @@ static void vfio_user_recycle(VFIOUserProxy *proxy, VFIOUserMsg *msg);static void vfio_user_recv (void *opaque);static void vfio_user_send (void *opaque); -static void vfio_user_cb (void *opaque);static void vfio_user_request (void *opaque);
@@ -492,7 +491,7 @@ static void vfio_user_send(void *opaque) } } -static void vfio_user_cb (void *opaque) +static void vfio_user_close_cb (void *opaque) {VFIOUserProxy *proxy = opaque;
@@ -984,8 +983,11 @@ void vfio_user_disconnect(VFIOUserProxy *proxy)* handler to run after the proxy fd handlers were * deleted above. */ -aio_bh_schedule_oneshot (proxy->ctx, vfio_user_cb, proxy); -qemu_cond_wait (&proxy->close_cv, &proxy->lock); +aio_bh_schedule_oneshot (proxy->ctx, vfio_user_close_cb, proxy); + +while (proxy->state !=VFIO_PROXY_CLOSED ) { +qemu_cond_wait (&proxy->close_cv, &proxy->lock); + }/* we now hold the only ref to proxy */ qemu_mutex_unlock (&proxy->lock);
Signature · 1 line
2.43.0
PATCH v3 4/4 hw/vfio-user: fix use of uninitialized variable
In reply to John LevonCoverity reported:
CID 1611805: Uninitialized variables
in vfio_user_dma_map(). This can occur in the happy path when ->async_ops was not set; as this doesn't typically happen, it wasn't caught during testing.
Align both map and unmap implementations to initialize ret the same way to resolve this.
Resolves: Coverity CID 1611805
--- hw/vfio-user/container.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
hw/vfio-user/container.c +1 -5
@@ -64,8 +64,6 @@ static int vfio_user_dma_unmap(const VFIOContainerBase *bcontainer, 0, &local_err)) {error_report_err (local_err); ret = -EFAULT ; - } else { - ret =0 ; } } else { if (!vfio_user_send_wait(container->proxy, &msgp->hdr, NULL,
@@ -92,7 +90,7 @@ static int vfio_user_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova, bcontainer);int fd =memory_region_get_fd (mrp);Error *local_err =NULL ; -int ret; +int ret =0 ;VFIOUserFDs *fds =NULL ;VFIOUserDMAMap *msgp =g_malloc0 (sizeof (*msgp));
@@ -135,8 +133,6 @@ static int vfio_user_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova, 0, &local_err)) {error_report_err (local_err); ret = -EFAULT ; - } else { - ret =0 ; } }else {VFIOUserFDs local_fds = {1 ,0 , &fd };
Signature · 1 line
2.43.0