diff options
author | John Levon <john.levon@nutanix.com> | 2021-09-28 17:24:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-28 17:24:54 +0100 |
commit | 2789a978b9e710ccb17bc4f7de884743abd63297 (patch) | |
tree | c3a7cee9115360da7146953bd1a8a7b55f049ff3 | |
parent | 2cc236ee84ed70a6df421e5352994ac4eb03de21 (diff) | |
download | libvfio-user-2789a978b9e710ccb17bc4f7de884743abd63297.zip libvfio-user-2789a978b9e710ccb17bc4f7de884743abd63297.tar.gz libvfio-user-2789a978b9e710ccb17bc4f7de884743abd63297.tar.bz2 |
fix issue with get_region_io_fds when fd = -1 (#606)
An unmappable region should still allow io fds, as they are orthogonal.
Co-authored-by: John Levon <john.levon@nutanix.com>
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
-rw-r--r-- | lib/libvfio-user.c | 6 | ||||
-rw-r--r-- | test/py/test_device_get_region_io_fds.py | 23 |
2 files changed, 22 insertions, 7 deletions
diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c index 8881dc7..69aeb36 100644 --- a/lib/libvfio-user.c +++ b/lib/libvfio-user.c @@ -558,7 +558,7 @@ handle_device_get_region_io_fds(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg) assert(msg != NULL); assert(msg->out_fds == NULL); - if (msg->in_size != sizeof(vfio_user_region_io_fds_request_t)) { + if (msg->in_size < sizeof(vfio_user_region_io_fds_request_t)) { return ERROR_INT(EINVAL); } @@ -576,10 +576,6 @@ handle_device_get_region_io_fds(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg) vfu_reg = &vfu_ctx->reg_info[req->index]; - if (vfu_reg->fd == -1) { - return ERROR_INT(EINVAL); - } - LIST_FOREACH(sub_reg, &vfu_reg->subregions, entry) { nr_sub_reg++; } diff --git a/test/py/test_device_get_region_io_fds.py b/test/py/test_device_get_region_io_fds.py index ab29dbb..63e3236 100644 --- a/test/py/test_device_get_region_io_fds.py +++ b/test/py/test_device_get_region_io_fds.py @@ -66,6 +66,10 @@ def test_device_get_region_io_fds_setup(): mmap_areas=mmap_areas, fd=f.fileno(), offset=0x8000) assert ret == 0 + ret = vfu_setup_region(ctx, index=VFU_PCI_DEV_BAR5_REGION_IDX, size=0x8000, + flags=(VFU_REGION_FLAG_RW), offset=0x8000) + assert ret == 0 + ret = vfu_realize_ctx(ctx) assert ret == 0 @@ -115,7 +119,7 @@ def test_device_get_region_io_fds_buffer_too_large(): msg(ctx, sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, expect = errno.EINVAL) -def test_device_get_region_io_fds_no_regions(): +def test_device_get_region_io_fds_no_fds(): payload = vfio_user_region_io_fds_request(argsz = 512, flags = 0, index = VFU_PCI_DEV_BAR1_REGION_IDX, count = 0) @@ -136,7 +140,22 @@ def test_device_get_region_io_fds_no_regions_setup(): index = VFU_PCI_DEV_BAR3_REGION_IDX, count = 0) ret = msg(ctx, sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, - expect=errno.EINVAL) + expect = 0) + +def test_device_get_region_io_fds_region_no_mmap(): + + payload = vfio_user_region_io_fds_request(argsz = 512, flags = 0, + index = VFU_PCI_DEV_BAR5_REGION_IDX, count = 0) + + ret = msg(ctx, sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, + expect = 0) + + reply, ret = vfio_user_region_io_fds_reply.pop_from_buffer(ret) + + assert reply.argsz == len(vfio_user_region_io_fds_reply()) + assert reply.count == 0 + assert reply.flags == 0 + assert reply.index == VFU_PCI_DEV_BAR5_REGION_IDX def test_device_get_region_io_fds_region_out_of_range(): |