[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH rfcv2 01/20] backends/iommufd: Add helpers for invalidating u
From: |
Eric Auger |
Subject: |
Re: [PATCH rfcv2 01/20] backends/iommufd: Add helpers for invalidating user-managed HWPT |
Date: |
Thu, 20 Feb 2025 17:47:04 +0100 |
User-agent: |
Mozilla Thunderbird |
Hi Zhenzhong,
On 2/19/25 9:22 AM, Zhenzhong Duan wrote:
> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
in the title, there is only a single helper here. a small commit msg may
help the reader
> ---
> include/system/iommufd.h | 3 +++
> backends/iommufd.c | 30 ++++++++++++++++++++++++++++++
> backends/trace-events | 1 +
> 3 files changed, 34 insertions(+)
>
> diff --git a/include/system/iommufd.h b/include/system/iommufd.h
> index cbab75bfbf..5d02e9d148 100644
> --- a/include/system/iommufd.h
> +++ b/include/system/iommufd.h
> @@ -61,6 +61,9 @@ bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be,
> uint32_t hwpt_id,
> uint64_t iova, ram_addr_t size,
> uint64_t page_size, uint64_t *data,
> Error **errp);
> +int iommufd_backend_invalidate_cache(IOMMUFDBackend *be, uint32_t hwpt_id,
> + uint32_t data_type, uint32_t entry_len,
> + uint32_t *entry_num, void *data_ptr);
>
> #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd"
> #endif
> diff --git a/backends/iommufd.c b/backends/iommufd.c
> index d57da44755..fc32aad5cb 100644
> --- a/backends/iommufd.c
> +++ b/backends/iommufd.c
> @@ -311,6 +311,36 @@ bool iommufd_backend_get_device_info(IOMMUFDBackend *be,
> uint32_t devid,
> return true;
> }
>
> +int iommufd_backend_invalidate_cache(IOMMUFDBackend *be, uint32_t hwpt_id,
> + uint32_t data_type, uint32_t entry_len,
> + uint32_t *entry_num, void *data_ptr)
> +{
> + int ret, fd = be->fd;
> + struct iommu_hwpt_invalidate cache = {
> + .size = sizeof(cache),
> + .hwpt_id = hwpt_id,
> + .data_type = data_type,
> + .entry_len = entry_len,
> + .entry_num = *entry_num,
> + .data_uptr = (uintptr_t)data_ptr,
> + };
> +
> + ret = ioctl(fd, IOMMU_HWPT_INVALIDATE, &cache);
> +
> + trace_iommufd_backend_invalidate_cache(fd, hwpt_id, data_type, entry_len,
> + *entry_num, cache.entry_num,
> + (uintptr_t)data_ptr, ret);
> + if (ret) {
> + *entry_num = cache.entry_num;
> + error_report("IOMMU_HWPT_INVALIDATE failed: %s", strerror(errno));
nit: you may report *entry_num also.
Wouldn't it be useful to have an Error *errp passed to the function
> + ret = -errno;
> + } else {
> + g_assert(*entry_num == cache.entry_num);
> + }
> +
> + return ret;
> +}
> +
> static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, int cap, Error **errp)
> {
> HostIOMMUDeviceCaps *caps = &hiod->caps;
> diff --git a/backends/trace-events b/backends/trace-events
> index 40811a3162..5a23db6c8a 100644
> --- a/backends/trace-events
> +++ b/backends/trace-events
> @@ -18,3 +18,4 @@ iommufd_backend_alloc_hwpt(int iommufd, uint32_t dev_id,
> uint32_t pt_id, uint32_
> 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)"
> iommufd_backend_get_dirty_bitmap(int iommufd, uint32_t hwpt_id, uint64_t
> iova, uint64_t size, uint64_t page_size, int ret) " iommufd=%d hwpt=%u
> iova=0x%"PRIx64" size=0x%"PRIx64" page_size=0x%"PRIx64" (%d)"
> +iommufd_backend_invalidate_cache(int iommufd, uint32_t hwpt_id, uint32_t
> data_type, uint32_t entry_len, uint32_t entry_num, uint32_t done_num,
> uint64_t data_ptr, int ret) " iommufd=%d hwpt_id=%u data_type=%u entry_len=%u
> entry_num=%u done_num=%u data_ptr=0x%"PRIx64" (%d)"
Eric