* [PATCH v3 0/4] vfio-user fixes
@ 2025-07-15 11:59 John Levon
2025-07-15 11:59 ` [PATCH v3 1/4] hw/vfio-user: add Cédric Le Goater as a maintainer John Levon
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: John Levon @ 2025-07-15 11:59 UTC (permalink / raw)
To: qemu-devel
Cc: Thanos Makatos, Alex Williamson, Cédric Le Goater,
John Levon
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(-)
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 1/4] hw/vfio-user: add Cédric Le Goater as a maintainer
2025-07-15 11:59 [PATCH v3 0/4] vfio-user fixes John Levon
@ 2025-07-15 11:59 ` John Levon
2025-07-15 11:59 ` [PATCH v3 2/4] hw/vfio: fix region fd initialization John Levon
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: John Levon @ 2025-07-15 11:59 UTC (permalink / raw)
To: qemu-devel
Cc: Thanos Makatos, Alex Williamson, Cédric Le Goater,
John Levon
Signed-off-by: John Levon <john.levon@nutanix.com>
---
MAINTAINERS | 1 +
1 file changed, 1 insertion(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index e88ed2c0a9..30e9b71e6e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4287,6 +4287,7 @@ F: tests/functional/test_multiprocess.py
VFIO-USER:
M: John Levon <john.levon@nutanix.com>
M: Thanos Makatos <thanos.makatos@nutanix.com>
+M: Cédric Le Goater <clg@redhat.com>
S: Supported
F: docs/interop/vfio-user.rst
F: docs/system/devices/vfio-user.rst
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 2/4] hw/vfio: fix region fd initialization
2025-07-15 11:59 [PATCH v3 0/4] vfio-user fixes John Levon
2025-07-15 11:59 ` [PATCH v3 1/4] hw/vfio-user: add Cédric Le Goater as a maintainer John Levon
@ 2025-07-15 11:59 ` John Levon
2025-07-15 11:59 ` [PATCH v3 3/4] hw/vfio-user: wait for proxy close correctly John Levon
2025-07-15 11:59 ` [PATCH v3 4/4] hw/vfio-user: fix use of uninitialized variable John Levon
3 siblings, 0 replies; 5+ messages in thread
From: John Levon @ 2025-07-15 11:59 UTC (permalink / raw)
To: qemu-devel
Cc: Thanos Makatos, Alex Williamson, Cédric Le Goater,
John Levon, Mark Cave-Ayland
We 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.
Fixes: 95cdb024 ("vfio: add region info cache")
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
---
hw/vfio/device.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/hw/vfio/device.c b/hw/vfio/device.c
index 96cf21462c..52a1996dc4 100644
--- a/hw/vfio/device.c
+++ b/hw/vfio/device.c
@@ -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);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 3/4] hw/vfio-user: wait for proxy close correctly
2025-07-15 11:59 [PATCH v3 0/4] vfio-user fixes John Levon
2025-07-15 11:59 ` [PATCH v3 1/4] hw/vfio-user: add Cédric Le Goater as a maintainer John Levon
2025-07-15 11:59 ` [PATCH v3 2/4] hw/vfio: fix region fd initialization John Levon
@ 2025-07-15 11:59 ` John Levon
2025-07-15 11:59 ` [PATCH v3 4/4] hw/vfio-user: fix use of uninitialized variable John Levon
3 siblings, 0 replies; 5+ messages in thread
From: John Levon @ 2025-07-15 11:59 UTC (permalink / raw)
To: qemu-devel
Cc: Thanos Makatos, Alex Williamson, Cédric Le Goater,
John Levon, Mark Cave-Ayland
Coverity 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.
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Mark Cave-Ayland <markcaveayland@nutanix.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
---
hw/vfio-user/proxy.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/hw/vfio-user/proxy.c b/hw/vfio-user/proxy.c
index c418954440..2275d3fe39 100644
--- a/hw/vfio-user/proxy.c
+++ b/hw/vfio-user/proxy.c
@@ -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);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 4/4] hw/vfio-user: fix use of uninitialized variable
2025-07-15 11:59 [PATCH v3 0/4] vfio-user fixes John Levon
` (2 preceding siblings ...)
2025-07-15 11:59 ` [PATCH v3 3/4] hw/vfio-user: wait for proxy close correctly John Levon
@ 2025-07-15 11:59 ` John Levon
3 siblings, 0 replies; 5+ messages in thread
From: John Levon @ 2025-07-15 11:59 UTC (permalink / raw)
To: qemu-devel
Cc: Thanos Makatos, Alex Williamson, Cédric Le Goater,
John Levon
Coverity 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
Fixes: 18e899e6 ("vfio-user: implement VFIO_USER_DMA_MAP/UNMAP")
Reported-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
---
hw/vfio-user/container.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/hw/vfio-user/container.c b/hw/vfio-user/container.c
index d318e6a339..d589dd90f5 100644
--- a/hw/vfio-user/container.c
+++ b/hw/vfio-user/container.c
@@ -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 };
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-07-15 12:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-15 11:59 [PATCH v3 0/4] vfio-user fixes John Levon
2025-07-15 11:59 ` [PATCH v3 1/4] hw/vfio-user: add Cédric Le Goater as a maintainer John Levon
2025-07-15 11:59 ` [PATCH v3 2/4] hw/vfio: fix region fd initialization John Levon
2025-07-15 11:59 ` [PATCH v3 3/4] hw/vfio-user: wait for proxy close correctly John Levon
2025-07-15 11:59 ` [PATCH v3 4/4] hw/vfio-user: fix use of uninitialized variable John Levon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).