All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Two fixes to vevent path
@ 2025-03-24 12:00 Yi Liu
  2025-03-24 12:00 ` [PATCH 1/2] iommufd: Initialize the flags of vevent in iommufd_viommu_report_event() Yi Liu
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Yi Liu @ 2025-03-24 12:00 UTC (permalink / raw)
  To: jgg, kevin.tian; +Cc: nicolinc, yi.l.liu, baolu.lu, iommu

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(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] iommufd: Initialize the flags of vevent in iommufd_viommu_report_event()
  2025-03-24 12:00 [PATCH 0/2] Two fixes to vevent path Yi Liu
@ 2025-03-24 12:00 ` Yi Liu
  2025-03-24 14:04   ` Nicolin Chen
  2025-03-24 12:00 ` [PATCH 2/2] iommufd: Balance veventq->num_events inc/dec Yi Liu
  2025-03-25 13:35 ` [PATCH 0/2] Two fixes to vevent path Jason Gunthorpe
  2 siblings, 1 reply; 6+ messages in thread
From: Yi Liu @ 2025-03-24 12:00 UTC (permalink / raw)
  To: jgg, kevin.tian; +Cc: nicolinc, yi.l.liu, baolu.lu, iommu

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")
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
 drivers/iommu/iommufd/driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/iommufd/driver.c b/drivers/iommu/iommufd/driver.c
index 352513974154..81e01d85b7d4 100644
--- a/drivers/iommu/iommufd/driver.c
+++ b/drivers/iommu/iommufd/driver.c
@@ -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;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] iommufd: Balance veventq->num_events inc/dec
  2025-03-24 12:00 [PATCH 0/2] Two fixes to vevent path Yi Liu
  2025-03-24 12:00 ` [PATCH 1/2] iommufd: Initialize the flags of vevent in iommufd_viommu_report_event() Yi Liu
@ 2025-03-24 12:00 ` Yi Liu
  2025-03-24 14:07   ` Nicolin Chen
  2025-03-25 13:35 ` [PATCH 0/2] Two fixes to vevent path Jason Gunthorpe
  2 siblings, 1 reply; 6+ messages in thread
From: Yi Liu @ 2025-03-24 12:00 UTC (permalink / raw)
  To: jgg, kevin.tian; +Cc: nicolinc, yi.l.liu, baolu.lu, iommu

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")
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
 drivers/iommu/iommufd/eventq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/iommufd/eventq.c b/drivers/iommu/iommufd/eventq.c
index 4c43ace8c725..f39cf0797347 100644
--- a/drivers/iommu/iommufd/eventq.c
+++ b/drivers/iommu/iommufd/eventq.c
@@ -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);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] iommufd: Initialize the flags of vevent in iommufd_viommu_report_event()
  2025-03-24 12:00 ` [PATCH 1/2] iommufd: Initialize the flags of vevent in iommufd_viommu_report_event() Yi Liu
@ 2025-03-24 14:04   ` Nicolin Chen
  0 siblings, 0 replies; 6+ messages in thread
From: Nicolin Chen @ 2025-03-24 14:04 UTC (permalink / raw)
  To: Yi Liu; +Cc: jgg, kevin.tian, baolu.lu, iommu

On Mon, Mar 24, 2025 at 05:00:33AM -0700, Yi Liu wrote:
> 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")
> Signed-off-by: Yi Liu <yi.l.liu@intel.com>

Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>
Tested-by: Nicolin Chen <nicolinc@nvidia.com>

Thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] iommufd: Balance veventq->num_events inc/dec
  2025-03-24 12:00 ` [PATCH 2/2] iommufd: Balance veventq->num_events inc/dec Yi Liu
@ 2025-03-24 14:07   ` Nicolin Chen
  0 siblings, 0 replies; 6+ messages in thread
From: Nicolin Chen @ 2025-03-24 14:07 UTC (permalink / raw)
  To: Yi Liu; +Cc: jgg, kevin.tian, baolu.lu, iommu

On Mon, Mar 24, 2025 at 05:00:34AM -0700, Yi Liu wrote:
> 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")
> Signed-off-by: Yi Liu <yi.l.liu@intel.com>
 
Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>
Tested-by: Nicolin Chen <nicolinc@nvidia.com>

Thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] Two fixes to vevent path
  2025-03-24 12:00 [PATCH 0/2] Two fixes to vevent path Yi Liu
  2025-03-24 12:00 ` [PATCH 1/2] iommufd: Initialize the flags of vevent in iommufd_viommu_report_event() Yi Liu
  2025-03-24 12:00 ` [PATCH 2/2] iommufd: Balance veventq->num_events inc/dec Yi Liu
@ 2025-03-25 13:35 ` Jason Gunthorpe
  2 siblings, 0 replies; 6+ messages in thread
From: Jason Gunthorpe @ 2025-03-25 13:35 UTC (permalink / raw)
  To: Yi Liu; +Cc: kevin.tian, nicolinc, baolu.lu, iommu

On Mon, Mar 24, 2025 at 05:00:32AM -0700, Yi Liu wrote:

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

Applied, thanks

Jason

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-03-25 13:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-24 12:00 [PATCH 0/2] Two fixes to vevent path Yi Liu
2025-03-24 12:00 ` [PATCH 1/2] iommufd: Initialize the flags of vevent in iommufd_viommu_report_event() Yi Liu
2025-03-24 14:04   ` Nicolin Chen
2025-03-24 12:00 ` [PATCH 2/2] iommufd: Balance veventq->num_events inc/dec Yi Liu
2025-03-24 14:07   ` Nicolin Chen
2025-03-25 13:35 ` [PATCH 0/2] Two fixes to vevent path Jason Gunthorpe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.