All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] iommu/amd/iommu_v2: Fix refcount related issues
@ 2023-01-24 10:43 Vasant Hegde
  2023-01-24 10:43 ` [PATCH 1/3] iommu/amd/iommu_v2: Fix pasid_state refcount dec hit 0 warning on pasid unbind Vasant Hegde
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Vasant Hegde @ 2023-01-24 10:43 UTC (permalink / raw)
  To: iommu, joro; +Cc: suravee.suthikulpanit, jgg, Vasant Hegde, Daniel Marcovitch

This patch series fixes various issues around pasid refcount handling.

Issues addressed in this patchset are as follows:

1. refcount_dec assumes that refcount will never reach 0:
   threfore: REFCOUNT_WARN("decrement hit 0; leaking memory")
   will be invoked on pasid unbind

   *  Fixed by changing refcount_dec to refcount_dec_and_test
      to explicitly handle refcount=1 (skip waiting for wait queue)

2. ppr_handler calls the wake_up API on the pasid_state wait_queue.
   However, once refcount has been decremented, unbind_pasid may have
   already freed this object - causing unallocated memory access

   *  Fixed by adding spinlock to ensure atomicity between refcount
      check and event queue handling. Moved wait_queue APIs to
      wake_up_locked / wake_event_interruptible_locked accordingly

3. If new ppr_handler arrives after get_pasid_wait once pasid unbind
   has decremented refcount to 0 - get_pasid_state can still acquire
   a pointer to pasid_state after being freed by unbind_pasid causing
   unallocated memory access

   *  Fixed by changing ref_count_inc to ref_count_inc_not_zero
      to ensure no new ppr_handle starts after pasid has been unbound
      and NULL (invalid) pasid_state is returned on zero.

Signed-off-by: Daniel Marcovitch <dmarcovitch@nvidia.com>
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>

Base commit: v6.2-rc5

Daniel Marcovitch (3):
  iommu/amd/iommu_v2: Fix pasid_state refcount dec hit 0 warning on pasid unbind
  iommu/amd/iommu_v2: Fix pasid_state->wq race
  iommu/amd/iommu_v2: Prevent scheduling new ppr notifier during unbind_pasid

 drivers/iommu/amd/iommu_v2.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

-- 
2.31.1


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

end of thread, other threads:[~2023-01-27 12:58 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-24 10:43 [PATCH 0/3] iommu/amd/iommu_v2: Fix refcount related issues Vasant Hegde
2023-01-24 10:43 ` [PATCH 1/3] iommu/amd/iommu_v2: Fix pasid_state refcount dec hit 0 warning on pasid unbind Vasant Hegde
2023-01-24 15:23   ` Jason Gunthorpe
2023-01-27  4:44     ` Vasant Hegde
2023-01-27 12:58       ` Jason Gunthorpe
2023-01-24 10:43 ` [PATCH 2/3] iommu/amd/iommu_v2: Fix pasid_state->wq race Vasant Hegde
2023-01-24 15:30   ` Jason Gunthorpe
2023-01-24 10:43 ` [PATCH 3/3] iommu/amd/iommu_v2: Prevent scheduling new ppr notifier during unbind_pasid Vasant Hegde
2023-01-24 15:33   ` Jason Gunthorpe
2023-01-27  4:58     ` Vasant Hegde

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.