Two fixes to vevent path
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
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.
--- drivers/iommu/iommufd/driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/iommufd/driver.c +1 -1
@@ -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
Re: [PATCH 1/2] iommufd: Initialize the flags of vevent in iommufd_viommu_report_event()
Quoted 6 lines · Yi Liu
The
vevent->header.flagsis not initialized per allocation, hence the vevent read path may treat the vevent aslost_events_headerwrongly. Usekzalloc()to alloc memory for new vevent.Fixes e8e1ef9b77a7 ("iommufd/viommu: Add iommufd_viommu_report_event helper")Signed-off-by Yi Liu <[email protected]>
Thanks!
PATCH 2/2 iommufd: Balance veventq->num_events inc/dec
In reply to Yi Liuiommufd_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.
--- drivers/iommu/iommufd/eventq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/iommufd/eventq.c +2 -1
@@ -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
Re: [PATCH 2/2] iommufd: Balance veventq->num_events inc/dec
Quoted 7 lines · Yi Liu
iommufd_veventq_fops_read()decrementsveventq->num_eventswhen a vevent is read out. However, the report path ony incrementsveventq->num_eventsfor normal events. To be balanced, make the read path decrementnum_eventsonly for normal vevents.Fixes e36ba5ab808e ("iommufd: Add IOMMUFD_OBJ_VEVENTQ and IOMMUFD_CMD_VEVENTQ_ALLOC")Signed-off-by Yi Liu <[email protected]>
Thanks!
Quoted 4 lines · Yi Liu
Yi Liu (2):
iommufd: Initialize the flags of vevent in
iommufd_viommu_report_event()
iommufd: Balanceveventq->num_eventsinc/dec
Applied, thanks
Jason