- target/i386: csv: Release CSV3 shared pages after unmapping DMA - target/i386: Add new CPU model ClearwaterForest - target/i386: add sha512, sm3, sm4 feature bits - docs: Add GNR, SRF and CWF CPU models - target/i386: Export BHI_NO bit to guests - target/i386: Introduce SierraForest-v2 model - vdpa/iommufd:Implement DMA mapping through the iommufd interface - vdpa/iommufd:Introduce vdpa-iommufd module - vdpa/iommufd:support associating iommufd backend for vDPA devices - Kconfig/iommufd/VDPA: Update IOMMUFD module configuration dependencies The vDPA module can also use IOMMUFD like the VFIO module. - backends/iommufd: Get rid of qemu_open_old() - backends/iommufd: Make iommufd_backend_*() return bool - backends/iommufd: Fix missing ERRP_GUARD() for error_prepend() - backends/iommufd: Remove mutex - backends/iommufd: Remove check on number of backend users - hw/intc: Add extioi ability of 256 vcpu interrupt routing - hw/rtc: Fixed loongson rtc emulation errors - hw/loongarch/boot: Adjust the loading position of the initrd - target/loongarch: Fix the cpu unplug resource leak - target/loongarch: fix vcpu reset command word issue - vdpa:Fix dirty page bitmap synchronization not done after suspend for vdpa devices Signed-off-by: Jiabo Feng <fengjiabo1@huawei.com> (cherry picked from commit a5212066e7516ff2a316e1b2feaa75dd5ee4d17a)
141 lines
5.7 KiB
Diff
141 lines
5.7 KiB
Diff
From c9a107b1f73bddb4c9844c12444e3802e5f576b4 Mon Sep 17 00:00:00 2001
|
|
From: Zhenzhong Duan <zhenzhong.duan@intel.com>
|
|
Date: Tue, 7 May 2024 14:42:52 +0800
|
|
Subject: [PATCH] backends/iommufd: Make iommufd_backend_*() return bool
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
This is to follow the coding standand to return bool if 'Error **'
|
|
is used to pass error.
|
|
|
|
The changed functions include:
|
|
|
|
iommufd_backend_connect
|
|
iommufd_backend_alloc_ioas
|
|
|
|
By this chance, simplify the functions a bit by avoiding duplicate
|
|
recordings, e.g., log through either error interface or trace, not
|
|
both.
|
|
|
|
Suggested-by: Cédric Le Goater <clg@redhat.com>
|
|
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
|
|
Reviewed-by: Cédric Le Goater <clg@redhat.com>
|
|
Signed-off-by: Cédric Le Goater <clg@redhat.com>
|
|
---
|
|
backends/iommufd.c | 29 +++++++++++++----------------
|
|
backends/trace-events | 4 ++--
|
|
include/sysemu/iommufd.h | 6 +++---
|
|
3 files changed, 18 insertions(+), 21 deletions(-)
|
|
|
|
diff --git a/backends/iommufd.c b/backends/iommufd.c
|
|
index f061b6869a..fad580fdcb 100644
|
|
--- a/backends/iommufd.c
|
|
+++ b/backends/iommufd.c
|
|
@@ -74,24 +74,22 @@ static void iommufd_backend_class_init(ObjectClass *oc, void *data)
|
|
object_class_property_add_str(oc, "fd", NULL, iommufd_backend_set_fd);
|
|
}
|
|
|
|
-int iommufd_backend_connect(IOMMUFDBackend *be, Error **errp)
|
|
+bool iommufd_backend_connect(IOMMUFDBackend *be, Error **errp)
|
|
{
|
|
- int fd, ret = 0;
|
|
+ int fd;
|
|
|
|
if (be->owned && !be->users) {
|
|
fd = qemu_open_old("/dev/iommu", O_RDWR);
|
|
if (fd < 0) {
|
|
error_setg_errno(errp, errno, "/dev/iommu opening failed");
|
|
- ret = fd;
|
|
- goto out;
|
|
+ return false;
|
|
}
|
|
be->fd = fd;
|
|
}
|
|
be->users++;
|
|
-out:
|
|
- trace_iommufd_backend_connect(be->fd, be->owned,
|
|
- be->users, ret);
|
|
- return ret;
|
|
+
|
|
+ trace_iommufd_backend_connect(be->fd, be->owned, be->users);
|
|
+ return true;
|
|
}
|
|
|
|
void iommufd_backend_disconnect(IOMMUFDBackend *be)
|
|
@@ -108,25 +106,24 @@ out:
|
|
trace_iommufd_backend_disconnect(be->fd, be->users);
|
|
}
|
|
|
|
-int iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id,
|
|
- Error **errp)
|
|
+bool iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id,
|
|
+ Error **errp)
|
|
{
|
|
- int ret, fd = be->fd;
|
|
+ int fd = be->fd;
|
|
struct iommu_ioas_alloc alloc_data = {
|
|
.size = sizeof(alloc_data),
|
|
.flags = 0,
|
|
};
|
|
|
|
- ret = ioctl(fd, IOMMU_IOAS_ALLOC, &alloc_data);
|
|
- if (ret) {
|
|
+ if (ioctl(fd, IOMMU_IOAS_ALLOC, &alloc_data)) {
|
|
error_setg_errno(errp, errno, "Failed to allocate ioas");
|
|
- return ret;
|
|
+ return false;
|
|
}
|
|
|
|
*ioas_id = alloc_data.out_ioas_id;
|
|
- trace_iommufd_backend_alloc_ioas(fd, *ioas_id, ret);
|
|
+ trace_iommufd_backend_alloc_ioas(fd, *ioas_id);
|
|
|
|
- return ret;
|
|
+ return true;
|
|
}
|
|
|
|
void iommufd_backend_free_id(IOMMUFDBackend *be, uint32_t id)
|
|
diff --git a/backends/trace-events b/backends/trace-events
|
|
index f8592a2711..8fe77149b2 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, int ret) "fd=%d owned=%d users=%d (%d)"
|
|
+iommufd_backend_connect(int fd, bool owned, uint32_t users) "fd=%d owned=%d users=%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, int ret) " iommufd=%d ioas=%d (%d)"
|
|
+iommufd_backend_alloc_ioas(int iommufd, uint32_t ioas) " iommufd=%d ioas=%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/include/sysemu/iommufd.h b/include/sysemu/iommufd.h
|
|
index 908c94d811..0531a4ad98 100644
|
|
--- a/include/sysemu/iommufd.h
|
|
+++ b/include/sysemu/iommufd.h
|
|
@@ -43,11 +43,11 @@ typedef struct IOMMUFDViommu {
|
|
uint32_t viommu_id;
|
|
} IOMMUFDViommu;
|
|
|
|
-int iommufd_backend_connect(IOMMUFDBackend *be, Error **errp);
|
|
+bool iommufd_backend_connect(IOMMUFDBackend *be, Error **errp);
|
|
void iommufd_backend_disconnect(IOMMUFDBackend *be);
|
|
|
|
-int iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id,
|
|
- Error **errp);
|
|
+bool 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.41.0.windows.1
|
|
|