linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/10] Refine the locking for dev->iommu_group
@ 2023-07-31 17:50 Jason Gunthorpe
  2023-07-31 17:50 ` [PATCH v2 01/10] iommu: Remove useless group refcounting Jason Gunthorpe
                   ` (10 more replies)
  0 siblings, 11 replies; 34+ messages in thread
From: Jason Gunthorpe @ 2023-07-31 17:50 UTC (permalink / raw)
  To: Baolin Wang, David Woodhouse, Heiko Stuebner, iommu,
	Jernej Skrabec, Joerg Roedel, linux-arm-kernel, linux-rockchip,
	linux-sunxi, Orson Zhai, Robin Murphy, Samuel Holland,
	Chen-Yu Tsai, Will Deacon, Chunyan Zhang
  Cc: Alex Williamson, Lu Baolu

This series puts the core code usage of dev->iommu_group under a
consistent set of locking rules. Currently a lot of places in the code
access this value without any locking or READ_ONCE/etc techniques and it
is not clear how or why this is safe.

Make it so the following locking rules are used:

 - It is readable by a probe'd device driver. So long as a device driver
   is probed the dev->iommu_group will be guaranteed stable without further
   locking. The reader should provide some kind of locking that ensure's
   its remove() struct device_driver op cannot progress.

 - Read/Write under the device_lock(), this primarily protects against
   parallel probe of the same device, and parallel probe/remove. This is
   useful for places that don't naturally have a device driver probed, and
   should be rare.

 - Read/Write under the global dev_iommu_group_lock. This is used during
   probe time discovery of groups. Device drivers will scan unlocked
   portions of the device tree to locate an already existing group. These
   scans can access the dev->iommu_group under the global lock to single
   thread determining and installing the group. This ensures that groups
   are reliably formed.

Add locking assertions to enforce this.

Along the way remove a bunch of opencoded group touching in drivers trying
to implement a 'single group per driver' approach by providing a core helper
that does this common algorithm.

Overall this significantly reduces the number of places within
drivers/iommu calling iommu_group_get or touching groups at all.

This goes on top of Joerg's next tree, it needs the prior series
"Consolidate the probe_device path".

This is on github: https://github.com/jgunthorpe/linux/commits/iommu_group_locking

v2:
 - Revise comments
 - NULL singleton_group during iommu_device_unregister() for clarity
v1: https://lore.kernel.org/r/0-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com

Jason Gunthorpe (10):
  iommu: Remove useless group refcounting
  iommu: Add a lockdep assertion for remaining dev->iommu_group reads
  iommu: Add generic_single_device_group()
  iommu/sun50i: Convert to generic_single_device_group()
  iommu/sprd: Convert to generic_single_device_group()
  iommu/rockchip: Convert to generic_single_device_group()
  iommu/ipmmu-vmsa: Convert to generic_single_device_group()
  iommu/omap: Convert to generic_single_device_group()
  iommu: Complete the locking for dev->iommu_group
  iommu/intel: Fix missing locking for show_device_domain_translation()

 drivers/iommu/intel/debugfs.c  |  34 ++++----
 drivers/iommu/iommu.c          | 155 +++++++++++++++++++++------------
 drivers/iommu/ipmmu-vmsa.c     |  22 ++---
 drivers/iommu/omap-iommu.c     |  30 +------
 drivers/iommu/omap-iommu.h     |   2 +-
 drivers/iommu/rockchip-iommu.c |  22 +----
 drivers/iommu/sprd-iommu.c     |  24 +----
 drivers/iommu/sun50i-iommu.c   |  29 ++----
 include/linux/iommu.h          |   3 +
 9 files changed, 138 insertions(+), 183 deletions(-)


base-commit: a5003e75a1714857c01317d04982eef81331fe2f
-- 
2.41.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2023-08-09 14:03 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-31 17:50 [PATCH v2 00/10] Refine the locking for dev->iommu_group Jason Gunthorpe
2023-07-31 17:50 ` [PATCH v2 01/10] iommu: Remove useless group refcounting Jason Gunthorpe
2023-08-02  1:33   ` Tian, Kevin
2023-07-31 17:50 ` [PATCH v2 02/10] iommu: Add a lockdep assertion for remaining dev->iommu_group reads Jason Gunthorpe
2023-08-02  1:34   ` Tian, Kevin
2023-08-08 16:22   ` Robin Murphy
2023-08-08 16:54     ` Jason Gunthorpe
2023-07-31 17:50 ` [PATCH v2 03/10] iommu: Add generic_single_device_group() Jason Gunthorpe
2023-08-02  1:35   ` Tian, Kevin
2023-07-31 17:50 ` [PATCH v2 04/10] iommu/sun50i: Convert to generic_single_device_group() Jason Gunthorpe
2023-07-31 17:50 ` [PATCH v2 05/10] iommu/sprd: " Jason Gunthorpe
2023-07-31 17:50 ` [PATCH v2 06/10] iommu/rockchip: " Jason Gunthorpe
     [not found]   ` <CGME20230809131935eucas1p247866f51cde0952d764c92f10a41c90c@eucas1p2.samsung.com>
2023-08-09 13:19     ` Marek Szyprowski
2023-08-09 13:51       ` Jason Gunthorpe
2023-08-09 14:02         ` Marek Szyprowski
2023-07-31 17:50 ` [PATCH v2 07/10] iommu/ipmmu-vmsa: " Jason Gunthorpe
2023-07-31 17:50 ` [PATCH v2 08/10] iommu/omap: " Jason Gunthorpe
2023-07-31 17:50 ` [PATCH v2 09/10] iommu: Complete the locking for dev->iommu_group Jason Gunthorpe
2023-08-02  1:36   ` Tian, Kevin
2023-08-09 12:55   ` [PATCH v2 9/10] " Konrad Dybcio
2023-07-31 17:50 ` [PATCH v2 10/10] iommu/intel: Fix missing locking for show_device_domain_translation() Jason Gunthorpe
2023-08-02  1:37   ` Tian, Kevin
2023-08-07 12:54 ` [PATCH v2 00/10] Refine the locking for dev->iommu_group Joerg Roedel
2023-08-08 10:31   ` Chen-Yu Tsai
2023-08-08 12:24     ` Jason Gunthorpe
     [not found]     ` <CGME20230808123250eucas1p19d12a9ae0e530c123ba625189f593b36@eucas1p1.samsung.com>
2023-08-08 12:32       ` Marek Szyprowski
2023-08-08 13:00         ` Jason Gunthorpe
2023-08-08 13:08           ` Marek Szyprowski
2023-08-08 13:25             ` Jason Gunthorpe
2023-08-08 14:02               ` Marek Szyprowski
2023-08-08 14:30                 ` Jason Gunthorpe
2023-08-08 14:51                   ` Marek Szyprowski
2023-08-09  6:23                   ` Chen-Yu Tsai
     [not found]         ` <CGME20230808130032eucas1p1b0f2d07f110f9913b30019b12e1d2841@eucas1p1.samsung.com>
2023-08-08 13:00           ` Marek Szyprowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).