backends/iommufd: Introduce iommufd_backend_alloc_veventq
Add a new helper for IOMMU_VEVENTQ_ALLOC ioctl to allocate a virtual event queue (vEVENTQ) for a vIOMMU object. Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> Tested-by: Nicolin Chen <nicolinc@nvidia.com> Reviewed-by: Eric Auger <eric.auger@redhat.com> Reviewed-by: Nicolin Chen <nicolinc@nvidia.com> Tested-by: Eric Auger <eric.auger@redhat.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Signed-off-by: Shameer Kolothum <skolothumtho@nvidia.com> Message-id: 20260226084456.112142-2-skolothumtho@nvidia.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Nicolin Chen committed
Mar 6, 2026 at 09:01 UTC
0885cd5504dfdbd531a1fc0e3e421d3c9934b03a
3 files changed
+46
backends/iommufd.c
+31
@@ -504,6 +504,37 @@ bool iommufd_backend_alloc_vdev(IOMMUFDBackend *be, uint32_t dev_id,
504
return true;
505
}
506
507
+bool iommufd_backend_alloc_veventq(IOMMUFDBackend *be, uint32_t viommu_id,
508
+ uint32_t type, uint32_t depth,
509
+ uint32_t *out_veventq_id,
510
+ uint32_t *out_veventq_fd, Error **errp)
511
+{
512
+ int ret;
513
+ struct iommu_veventq_alloc alloc_veventq = {
514
+ .size = sizeof(alloc_veventq),
515
+ .flags = 0,
516
+ .type = type,
517
+ .veventq_depth = depth,
518
+ .viommu_id = viommu_id,
519
+ };
520
+
521
+ ret = ioctl(be->fd, IOMMU_VEVENTQ_ALLOC, &alloc_veventq);
522
+
523
+ trace_iommufd_viommu_alloc_eventq(be->fd, viommu_id, type,
524
+ alloc_veventq.out_veventq_id,
525
+ alloc_veventq.out_veventq_fd, ret);
526
+ if (ret) {
527
+ error_setg_errno(errp, errno, "IOMMU_VEVENTQ_ALLOC failed");
528
+ return false;
529
+ }
530
+
531
+ g_assert(out_veventq_id);
532
+ g_assert(out_veventq_fd);
533
+ *out_veventq_id = alloc_veventq.out_veventq_id;
534
+ *out_veventq_fd = alloc_veventq.out_veventq_fd;
535
+ return true;
536
+}
537
+
538
bool host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD *idev,
539
uint32_t hwpt_id, Error **errp)
540
{
backends/trace-events
+1
@@ -23,6 +23,7 @@ iommufd_backend_get_dirty_bitmap(int iommufd, uint32_t hwpt_id, uint64_t iova, u
23
iommufd_backend_invalidate_cache(int iommufd, uint32_t 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 id=%u data_type=%u entry_len=%u entry_num=%u done_num=%u data_ptr=0x%"PRIx64" (%d)"
24
iommufd_backend_alloc_viommu(int iommufd, uint32_t dev_id, uint32_t type, uint32_t hwpt_id, uint32_t viommu_id, int ret) " iommufd=%d type=%u dev_id=%u hwpt_id=%u viommu_id=%u (%d)"
25
iommufd_backend_alloc_vdev(int iommufd, uint32_t dev_id, uint32_t viommu_id, uint64_t virt_id, uint32_t vdev_id, int ret) " iommufd=%d dev_id=%u viommu_id=%u virt_id=0x%"PRIx64" vdev_id=%u (%d)"
26
+iommufd_viommu_alloc_eventq(int iommufd, uint32_t viommu_id, uint32_t type, uint32_t veventq_id, uint32_t veventq_fd, int ret) " iommufd=%d viommu_id=%u type=%u veventq_id=%u veventq_fd=%u (%d)"
27
28
# igvm-cfg.c
29
igvm_reset_enter(int type) "type=%u"
include/system/iommufd.h
+14
@@ -56,6 +56,15 @@ typedef struct IOMMUFDVdev {
56
uint32_t virt_id; /* virtual device ID */
57
} IOMMUFDVdev;
58
59
+/* Virtual event queue interface for a vIOMMU */
60
+typedef struct IOMMUFDVeventq {
61
+ IOMMUFDViommu *viommu;
62
+ uint32_t veventq_id;
63
+ uint32_t veventq_fd;
64
+ uint32_t last_event_seq; /* Sequence number of last processed event */
65
+ bool event_start; /* True after first valid event; cleared on overflow */
66
+} IOMMUFDVeventq;
67
+
68
bool iommufd_backend_connect(IOMMUFDBackend *be, Error **errp);
69
void iommufd_backend_disconnect(IOMMUFDBackend *be);
70
@@ -86,6 +95,11 @@ bool iommufd_backend_alloc_vdev(IOMMUFDBackend *be, uint32_t dev_id,
95
uint32_t viommu_id, uint64_t virt_id,
96
uint32_t *out_vdev_id, Error **errp);
97
98
+bool iommufd_backend_alloc_veventq(IOMMUFDBackend *be, uint32_t viommu_id,
99
+ uint32_t type, uint32_t depth,
100
+ uint32_t *out_veventq_id,
101
+ uint32_t *out_veventq_fd, Error **errp);
102
+
103
bool iommufd_backend_set_dirty_tracking(IOMMUFDBackend *be, uint32_t hwpt_id,
104
bool start, Error **errp);
105
bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be, uint32_t hwpt_id,