
Revert "backends/iommufd: Make iommufd_backend_*() return bool" and fix the way of vdpa codes use related iommufd APIs. Signed-off-by: Zhou Wang <wangzhou1@hisilicon.com> Signed-off-by: Jian Cai <caijian11@h-partners.com> --- backends/iommufd.c | 29 ++++++++++++++++------------- backends/trace-events | 4 ++-- hw/virtio/vdpa-dev-iommufd.c | 6 +++--- include/sysemu/iommufd.h | 6 +++--- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/backends/iommufd.c b/backends/iommufd.c index 62df6e41f0..4446efaa32 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -74,21 +74,23 @@ static void iommufd_backend_class_init(ObjectClass *oc, void *data) object_class_property_add_str(oc, "fd", NULL, iommufd_backend_set_fd); } -bool iommufd_backend_connect(IOMMUFDBackend *be, Error **errp) +int iommufd_backend_connect(IOMMUFDBackend *be, Error **errp) { - int fd; + int fd, ret = 0; if (be->owned && !be->users) { fd = qemu_open("/dev/iommu", O_RDWR, errp); if (fd < 0) { - return false; + ret = fd; + goto out; } be->fd = fd; } be->users++; - - trace_iommufd_backend_connect(be->fd, be->owned, be->users); - return true; +out: + trace_iommufd_backend_connect(be->fd, be->owned, + be->users, ret); + return ret; } void iommufd_backend_disconnect(IOMMUFDBackend *be) @@ -105,24 +107,25 @@ out: trace_iommufd_backend_disconnect(be->fd, be->users); } -bool iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, - Error **errp) +int iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, + Error **errp) { - int fd = be->fd; + int ret, fd = be->fd; struct iommu_ioas_alloc alloc_data = { .size = sizeof(alloc_data), .flags = 0, }; - if (ioctl(fd, IOMMU_IOAS_ALLOC, &alloc_data)) { + ret = ioctl(fd, IOMMU_IOAS_ALLOC, &alloc_data); + if (ret) { error_setg_errno(errp, errno, "Failed to allocate ioas"); - return false; + return ret; } *ioas_id = alloc_data.out_ioas_id; - trace_iommufd_backend_alloc_ioas(fd, *ioas_id); + trace_iommufd_backend_alloc_ioas(fd, *ioas_id, ret); - return true; + return ret; } void iommufd_backend_free_id(IOMMUFDBackend *be, uint32_t id) diff --git a/backends/trace-events b/backends/trace-events index 8fe77149b2..f8592a2711 100644 --- a/backends/trace-events +++ b/backends/trace-events @@ -7,13 +7,13 @@ dbus_vmstate_loading(const char *id) "id: %s" dbus_vmstate_saving(const char *id) "id: %s" # iommufd.c -iommufd_backend_connect(int fd, bool owned, uint32_t users) "fd=%d owned=%d users=%d" +iommufd_backend_connect(int fd, bool owned, uint32_t users, int ret) "fd=%d owned=%d users=%d (%d)" iommufd_backend_disconnect(int fd, uint32_t users) "fd=%d users=%d" iommu_backend_set_fd(int fd) "pre-opened /dev/iommu fd=%d" iommufd_backend_map_dma(int iommufd, uint32_t ioas, uint64_t iova, uint64_t size, void *vaddr, bool readonly, int ret) " iommufd=%d ioas=%d iova=0x%"PRIx64" size=0x%"PRIx64" addr=%p readonly=%d (%d)" iommufd_backend_unmap_dma_non_exist(int iommufd, uint32_t ioas, uint64_t iova, uint64_t size, int ret) " Unmap nonexistent mapping: iommufd=%d ioas=%d iova=0x%"PRIx64" size=0x%"PRIx64" (%d)" iommufd_backend_unmap_dma(int iommufd, uint32_t ioas, uint64_t iova, uint64_t size, int ret) " iommufd=%d ioas=%d iova=0x%"PRIx64" size=0x%"PRIx64" (%d)" -iommufd_backend_alloc_ioas(int iommufd, uint32_t ioas) " iommufd=%d ioas=%d" +iommufd_backend_alloc_ioas(int iommufd, uint32_t ioas, int ret) " iommufd=%d ioas=%d (%d)" iommufd_backend_alloc_hwpt(int iommufd, uint32_t dev_id, uint32_t pt_id, uint32_t flags, uint32_t hwpt_type, uint32_t len, uint64_t data_ptr, uint32_t out_hwpt_id, int ret) " iommufd=%d dev_id=%u pt_id=%u flags=0x%x hwpt_type=%u len=%u data_ptr=0x%"PRIx64" out_hwpt=%u (%d)" iommufd_backend_free_id(int iommufd, uint32_t id, int ret) " iommufd=%d id=%d (%d)" iommufd_backend_set_dirty(int iommufd, uint32_t hwpt_id, bool start, int ret) " iommufd=%d hwpt=%u enable=%d (%d)" diff --git a/hw/virtio/vdpa-dev-iommufd.c b/hw/virtio/vdpa-dev-iommufd.c index 2b0498f9dc..f5718bae99 100644 --- a/hw/virtio/vdpa-dev-iommufd.c +++ b/hw/virtio/vdpa-dev-iommufd.c @@ -186,12 +186,12 @@ static int vhost_vdpa_container_connect_iommufd(VDPAIOMMUFDContainer *container) return -1; } - if (!iommufd_backend_connect(iommufd, &err)) { + if (iommufd_backend_connect(iommufd, &err)) { error_report_err(err); return -1; } - if (!iommufd_backend_alloc_ioas(iommufd, &ioas_id, &err)) { + if (iommufd_backend_alloc_ioas(iommufd, &ioas_id, &err)) { error_report_err(err); iommufd_backend_disconnect(iommufd); return -1; @@ -480,4 +480,4 @@ void vhost_vdpa_detach_container(VhostVdpaDevice *vdev) vhost_vdpa_container_disconnect_iommufd(container); vhost_vdpa_destroy_container(container); -} \ No newline at end of file +} diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h index 0531a4ad98..908c94d811 100644 --- a/include/sysemu/iommufd.h +++ b/include/sysemu/iommufd.h @@ -43,11 +43,11 @@ typedef struct IOMMUFDViommu { uint32_t viommu_id; } IOMMUFDViommu; -bool iommufd_backend_connect(IOMMUFDBackend *be, Error **errp); +int iommufd_backend_connect(IOMMUFDBackend *be, Error **errp); void iommufd_backend_disconnect(IOMMUFDBackend *be); -bool iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, - Error **errp); +int iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, + Error **errp); void iommufd_backend_free_id(IOMMUFDBackend *be, uint32_t id); int iommufd_backend_map_dma(IOMMUFDBackend *be, uint32_t ioas_id, hwaddr iova, ram_addr_t size, void *vaddr, bool readonly); -- 2.43.0