82 lines
3.6 KiB
Diff
82 lines
3.6 KiB
Diff
|
|
From cedca4d3635cde049151b5818df2cb66c2b1531f Mon Sep 17 00:00:00 2001
|
||
|
|
From: Zhenzhong Duan <zhenzhong.duan@intel.com>
|
||
|
|
Date: Fri, 3 Nov 2023 16:54:01 +0800
|
||
|
|
Subject: [PATCH] backends/iommufd: Add helpers for invalidating user-managed
|
||
|
|
HWPT
|
||
|
|
|
||
|
|
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
|
||
|
|
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
|
||
|
|
---
|
||
|
|
backends/iommufd.c | 30 ++++++++++++++++++++++++++++++
|
||
|
|
backends/trace-events | 1 +
|
||
|
|
include/sysemu/iommufd.h | 3 +++
|
||
|
|
3 files changed, 34 insertions(+)
|
||
|
|
|
||
|
|
diff --git a/backends/iommufd.c b/backends/iommufd.c
|
||
|
|
index c1260766f0..cf24370385 100644
|
||
|
|
--- a/backends/iommufd.c
|
||
|
|
+++ b/backends/iommufd.c
|
||
|
|
@@ -330,6 +330,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));
|
||
|
|
+ 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 b02433710a..ef0ff98921 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)"
|
||
|
|
diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h
|
||
|
|
index 3b28c8a81c..f6596f6338 100644
|
||
|
|
--- a/include/sysemu/iommufd.h
|
||
|
|
+++ b/include/sysemu/iommufd.h
|
||
|
|
@@ -63,6 +63,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
|
||
|
|
--
|
||
|
|
2.41.0.windows.1
|
||
|
|
|