Skip to contentSkip to conversation

Two fixes to vevent path

PATCH Applied Yi Liu 3 participants 6 messages Mar 24, 2025 – Mar 25, 2025

Subsystems (2)
lore
Share & tools
lore

Yi Liu

author
#0 lore raw

cover Two fixes to vevent path

iommufd selftest occassionally fail when reading vevent. After debugging, it is due to vevent->header.flags. It is not set properly per allocation. This can be fixed by using kzalloc(). There is another related issue. The veventq->num_events inc/dec is not balanced. This is problemtic. Make a fix for it as well.

Regards,
Yi Liu

Yi Liu (2):
iommufd: Initialize the flags of vevent in
iommufd_viommu_report_event()
iommufd: Balance veventq->num_events inc/dec

 drivers/iommu/iommufd/driver.c | 2 +-
 drivers/iommu/iommufd/eventq.c | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/2 iommufd: Initialize the flags of vevent in iommufd_viommu_report_event()

The vevent->header.flags is not initialized per allocation, hence the vevent read path may treat the vevent as lost_events_header wrongly. Use kzalloc() to alloc memory for new vevent.

Fixes e8e1ef9b77a7 ("iommufd/viommu: Add iommufd_viommu_report_event helper")
---
 drivers/iommu/iommufd/driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/iommufd/driver.c +1 -1
index 352513974154..81e01d85b7d4 100644
@@ -102,7 +102,7 @@ int iommufd_viommu_report_event(struct iommufd_viommu *viommu,
 		goto out_set_header;
 	}
 
-	vevent = kmalloc(struct_size(vevent, event_data, data_len), GFP_ATOMIC);
+	vevent = kzalloc(struct_size(vevent, event_data, data_len), GFP_ATOMIC);
 	if (!vevent) {
 		rc = -ENOMEM;
 		vevent = &veventq->lost_events_header;
Signature · 1 line
2.34.1
Reviewed-by Tested-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] iommufd: Initialize the flags of vevent in iommufd_viommu_report_event()

Quoted 6 lines · Yi Liu

The vevent->header.flags is not initialized per allocation, hence the vevent read path may treat the vevent as lost_events_header wrongly. Use kzalloc() to alloc memory for new vevent.

Fixes e8e1ef9b77a7 ("iommufd/viommu: Add iommufd_viommu_report_event helper")

Thanks!

author
#3 lore raw

PATCH 2/2 iommufd: Balance veventq->num_events inc/dec

In reply to Yi Liu

iommufd_veventq_fops_read() decrements veventq->num_events when a vevent is read out. However, the report path ony increments veventq->num_events for normal events. To be balanced, make the read path decrement num_events only for normal vevents.

Fixes e36ba5ab808e ("iommufd: Add IOMMUFD_OBJ_VEVENTQ and IOMMUFD_CMD_VEVENTQ_ALLOC")
---
 drivers/iommu/iommufd/eventq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/iommufd/eventq.c +2 -1
index 4c43ace8c725..f39cf0797347 100644
@@ -385,7 +385,8 @@ static ssize_t iommufd_veventq_fops_read(struct file *filep, char __user *buf,
 			break;
 		}
 		spin_lock(&eventq->lock);
-		veventq->num_events--;
+		if (!vevent_for_lost_events_header(cur))
+			veventq->num_events--;
 		spin_unlock(&eventq->lock);
 		done += cur->data_len;
 		kfree(cur);
Signature · 1 line
2.34.1
Reviewed-by Tested-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] iommufd: Balance veventq->num_events inc/dec

Quoted 7 lines · Yi Liu

iommufd_veventq_fops_read() decrements veventq->num_events when a vevent is read out. However, the report path ony increments veventq->num_events for normal events. To be balanced, make the read path decrement num_events only for normal vevents.

Fixes e36ba5ab808e ("iommufd: Add IOMMUFD_OBJ_VEVENTQ and IOMMUFD_CMD_VEVENTQ_ALLOC")

Thanks!

maintainer Applied
#5 lore raw
In reply to Yi Liu
Quoted 4 lines · Yi Liu

Yi Liu (2):
iommufd: Initialize the flags of vevent in
iommufd_viommu_report_event()
iommufd: Balance veventq->num_events inc/dec

Applied, thanks

Jason