diff options
author | Swapnil Ingle <swapnil.ingle@nutanix.com> | 2021-11-11 19:25:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-11 19:25:34 +0100 |
commit | 56842967566dcf4b89514949a6e88ba89eeaf268 (patch) | |
tree | 24cb4b4548093f56fb2ea476365e0f532344baad | |
parent | 8614299d1cce54a1a30c209c99e3a659f01bf365 (diff) | |
download | libvfio-user-56842967566dcf4b89514949a6e88ba89eeaf268.zip libvfio-user-56842967566dcf4b89514949a6e88ba89eeaf268.tar.gz libvfio-user-56842967566dcf4b89514949a6e88ba89eeaf268.tar.bz2 |
Fix reply of VFIO_USER_DEVICE_GET_REGION_INFO (#619)
* Fix reply of VFIO_USER_DEVICE_GET_REGION_INFO
Set VFIO_REGION_INFO_FLAG_CAPS flag only if caps are part of the reply.
Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
Reviewed-by: John Levon <john.levon@nutanix.com>
-rw-r--r-- | lib/libvfio-user.c | 12 | ||||
-rw-r--r-- | test/py/test_device_get_region_info.py | 8 |
2 files changed, 14 insertions, 6 deletions
diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c index a56d34c..3bbad42 100644 --- a/lib/libvfio-user.c +++ b/lib/libvfio-user.c @@ -405,6 +405,7 @@ handle_device_get_region_info(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg) struct vfio_region_info *out_info; vfu_reg_info_t *vfu_reg; size_t caps_size = 0; + int ret; assert(vfu_ctx != NULL); assert(msg != NULL); @@ -457,12 +458,15 @@ handle_device_get_region_info(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg) } if (caps_size > 0) { - out_info->flags |= VFIO_REGION_INFO_FLAG_CAPS; /* Only actually provide the caps if they fit. */ if (in_info->argsz >= out_info->argsz) { - dev_get_caps(vfu_ctx, vfu_reg, - in_info->index == VFU_PCI_DEV_MIGR_REGION_IDX, - out_info, &msg->out_fds, &msg->nr_out_fds); + out_info->flags |= VFIO_REGION_INFO_FLAG_CAPS; + ret = dev_get_caps(vfu_ctx, vfu_reg, + in_info->index == VFU_PCI_DEV_MIGR_REGION_IDX, + out_info, &msg->out_fds, &msg->nr_out_fds); + if (ret < 0) { + return ret; + } } } diff --git a/test/py/test_device_get_region_info.py b/test/py/test_device_get_region_info.py index f7e63d2..cea3e98 100644 --- a/test/py/test_device_get_region_info.py +++ b/test/py/test_device_get_region_info.py @@ -134,10 +134,14 @@ def test_device_get_region_info_small_argsz_caps(): info, _ = vfio_region_info.pop_from_buffer(result) assert info.argsz == 80 + + ''' + There are capabilites but we do not expect VFIO_REGION_INFO_FLAG_CAPS + to be set because they do not fit in reply as argsz is small + ''' assert info.flags == (VFIO_REGION_INFO_FLAG_READ | VFIO_REGION_INFO_FLAG_WRITE | - VFIO_REGION_INFO_FLAG_MMAP | - VFIO_REGION_INFO_FLAG_CAPS) + VFIO_REGION_INFO_FLAG_MMAP) assert info.index == VFU_PCI_DEV_BAR2_REGION_IDX assert info.cap_offset == 0 assert info.size == 0x8000 |