vfio-user: propagate DMA map/unmap request errors
PATCH 1/1 vfio-user: propagate DMA map/unmap request errors
From: Yuho Choi <[email protected]>
vfio_user_wait_reqs() uses the youngest nowait request as an ordering fence, but error replies for older requests are logged and recycled. An error reply or timeout for the youngest request is also only logged. The memory listener therefore commits even when QEMU and the server may disagree about DMA mappings.
Preserve the first error from each nowait batch and return it to the listener commit callback. Propagate failures during listener registration so device realization fails cleanly. After initialization, report the error and stop with hw_error(), matching the existing VFIO DMA mapping failure policy.
The memory listener commit callback cannot roll back a FlatView that has already advanced. Treat listener teardown the same way: until the proxy is disconnected, a failed unmap leaves the server's DMA access unconfirmed. Stopping QEMU avoids continued execution with inconsistent DMA state.
Add unit coverage for an older failed request followed by a successful youngest fence, a timeout, and an all-success batch.
--- MAINTAINERS | 1 + hw/vfio-user/container.c | 18 ++- hw/vfio-user/proxy.c | 89 +++++++++--- hw/vfio-user/proxy.h | 3 +- tests/unit/meson.build | 8 ++ tests/unit/test-vfio-user-proxy.c | 222 ++++++++++++++++++++++++++++++ 6 files changed, 320 insertions(+), 21 deletions(-) create mode 100644 tests/unit/test-vfio-user-proxy.c
MAINTAINERS +1 -0
@@ -4582,6 +4582,7 @@ F: docs/system/devices/vfio-user.rst F: hw/vfio-user/* F: subprojects/libvfio-user.wrap F: tests/functional/x86_64/test_vfio_user_client.py +F: tests/unit/test-vfio-user-proxy.c EBPF M: Jason Wang <[email protected]>
hw/vfio-user/container.c +17 -1
@@ -10,6 +10,7 @@#include <sys/ioctl.h> #include <linux/vfio.h> +#include "hw/core/hw-error.h" #include "hw/vfio-user/container.h" #include "hw/vfio-user/device.h" #include "hw/vfio-user/trace.h"
@@ -33,10 +34,25 @@ static void vfio_user_listener_begin(VFIOContainer *bcontainer)static void vfio_user_listener_commit (VFIOContainer *bcontainer) {VFIOUserContainer *container =VFIO_IOMMU_USER (bcontainer); +Error *local_err =NULL ;/* wait here for any async requests sent during the transaction */ container->proxy->async_ops = false; -vfio_user_wait_reqs (container->proxy); +if (vfio_user_wait_reqs (container->proxy, &local_err)) { +return ; + } + +error_prepend (&local_err,"vfio-user DMA mapping transaction failed: " ); +if (!bcontainer->initialized) { +if (!bcontainer->error) { +error_propagate (&bcontainer->error, local_err); + }else { +error_free (local_err); + } + }else { +error_report_err (local_err); +hw_error ("vfio-user: DMA mapping failed, unable to continue" ); + } } static int vfio_user_dma_unmap(const VFIOContainer *bcontainer,
hw/vfio-user/proxy.c +70 -19
160 lines not on this page · raw message
hw/vfio-user/proxy.h +2 -1
@@ -83,6 +83,7 @@ typedef struct VFIOUserProxy {VFIOUserMsgQ incoming;VFIOUserMsgQ outgoing;VFIOUserMsg *last_nowait; +Error *nowait_error;VFIOUserMsg *part_recv;size_t recv_left;VFIOUserWRMulti *wr_multi;
@@ -116,7 +117,7 @@ void vfio_user_disable_posted_writes(VFIOUserProxy *proxy);void vfio_user_request_msg (VFIOUserHdr *hdr,uint16_t cmd,uint32_t size,uint32_t flags); -void vfio_user_wait_reqs (VFIOUserProxy *proxy); +bool vfio_user_wait_reqs (VFIOUserProxy *proxy,Error **errp);bool vfio_user_send_wait (VFIOUserProxy *proxy,VFIOUserHdr *hdr,VFIOUserFDs *fds,int rsize,Error **errp); bool vfio_user_send_nowait(VFIOUserProxy *proxy, VFIOUserHdr *hdr,
tests/unit/meson.build +8 -0
@@ -148,6 +148,14 @@ if have_system genh, qemuutil, qom ], } + if host_os == 'linux' + tests += { + 'test-vfio-user-proxy': [ + 'iothread.c', io, + meson.project_source_root() / 'hw/vfio-user/proxy.c', + ], + } + endif if config_host_data.get('CONFIG_INOTIFY1') tests += {'test-util-filemonitor': []} endif
tests/unit/test-vfio-user-proxy.c new file +222 -0
222 lines not on this page · raw message
Signature · 1 line
2.43.0
hw/vfio-user/container.c static void vfio_user_listener_begin(VFIOContainer *bcontainer) · line 54
Quoted 10 lines · Yuho Choi
hw/vfio-user/container.c +10
-0+error_prepend (&local_err,"vfio-user DMA mapping transaction failed: " ); +if (!bcontainer->initialized) { +if (!bcontainer->error) { +error_propagate (&bcontainer->error, local_err); + }else { +error_free (local_err); + } + }else { +error_report_err (local_err); +hw_error ("vfio-user: DMA mapping failed, unable to continue" );
Are we sure we want qemu to abort() rather than just exit in the case the vfio-user server returns an error?
hw/vfio-user/proxy.c err: · line 457
Quoted 10 lines
hw/vfio-user/proxy.c +5
-1@@ -426,7 +450,15 @@ err:*/ vfio_user_set_error (msg->hdr,EINVAL ); msg->complete = true; -qemu_cond_signal (&msg->cv); +if (msg->type ==VFIO_MSG_NOWAIT ) { +vfio_user_record_nowait_reply_error (proxy, msg); +if (proxy->last_nowait == msg) { + proxy->last_nowait =NULL ; + }
I'm not quite getting this change, why are you resetting last_nowait here? And why as part of this change?
I think at least it's worth a comment.
thanks
john