linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Baolu Lu <baolu.lu@linux.intel.com>
To: Jason Gunthorpe <jgg@nvidia.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	David Woodhouse <dwmw2@infradead.org>,
	Heiko Stuebner <heiko@sntech.de>,
	iommu@lists.linux.dev, Jernej Skrabec <jernej.skrabec@gmail.com>,
	Joerg Roedel <joro@8bytes.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev,
	Orson Zhai <orsonzhai@gmail.com>,
	Robin Murphy <robin.murphy@arm.com>,
	Samuel Holland <samuel@sholland.org>,
	Chen-Yu Tsai <wens@csie.org>, Will Deacon <will@kernel.org>,
	Chunyan Zhang <zhang.lyra@gmail.com>
Cc: baolu.lu@linux.intel.com, Alex Williamson <alex.williamson@redhat.com>
Subject: Re: [PATCH 09/10] iommu: Complete the locking for dev->iommu_group
Date: Thu, 20 Jul 2023 17:55:36 +0800	[thread overview]
Message-ID: <a64b95e8-435d-0659-449a-74a64a659fa7@linux.intel.com> (raw)
In-Reply-To: <9-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com>

On 2023/7/19 3:05, Jason Gunthorpe wrote:
> Revise the locking for dev->iommu_group so that it has three safe ways to
> access it:
> 
>   - It is read 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.
> 
>   - Read under the device_lock(), this primarily protects against
>     parallel probe of the same device, and parallel probe/remove
> 
>   - 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.
> 
> Narrow the scope of the global dev_iommu_group_lock to be only during the
> dev->iommu_group setup, and not for the entire probing.
> 
> Prior patches removed the various races inherent to the probe process by
> consolidating all the work under the group->mutex. In this configuration
> it is fine if two devices race to the group_device step of a new
> iommu_group, the group->mutex locking will ensure the group_device and
> domain setup part remains properly ordered.
> 
> Add the missing locking on the remove paths. For iommu_deinit_device() it
> is necessary to hold the dev_iommu_group_lock due to possible races during
> probe error unwind.
> 
> Fully lock the iommu_group_add/remove_device() path so we can use lockdep
> assertions. Other than lockdep this is redundant, VFIO no-iommu doesn't
> use group clustering.
> 
> For iommu_release_device() it is redundant, as we expect no external
> references to the struct device by this point, but it is harmless so
> add the missing lock to allow lockdep assertions to work.
> 
> This resolves the remarks of the comment in __iommu_probe_device().
> 
> Signed-off-by: Jason Gunthorpe<jgg@nvidia.com>

Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>

Best regards,
baolu

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

  reply	other threads:[~2023-07-20  9:56 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-18 19:05 [PATCH 00/10] Refine the locking for dev->iommu_group Jason Gunthorpe
2023-07-18 19:05 ` [PATCH 01/10] iommu: Remove useless group refcounting Jason Gunthorpe
2023-07-20  6:11   ` Baolu Lu
2023-07-21  7:10   ` Tian, Kevin
2023-07-21 12:01     ` Jason Gunthorpe
2023-07-18 19:05 ` [PATCH 02/10] iommu: Add a lockdep assertion for remaining dev->iommu_group reads Jason Gunthorpe
2023-07-20  6:33   ` Baolu Lu
2023-07-18 19:05 ` [PATCH 03/10] iommu: Add generic_single_device_group() Jason Gunthorpe
2023-07-20  7:39   ` Baolu Lu
2023-07-20 12:04     ` Jason Gunthorpe
2023-07-20 14:01       ` Baolu Lu
2023-07-21 17:19         ` Jason Gunthorpe
2023-07-22 14:01           ` Baolu Lu
2023-07-21  7:17   ` Tian, Kevin
2023-07-22 14:02   ` Baolu Lu
2023-07-18 19:05 ` [PATCH 04/10] iommu/sun50i: Convert to generic_single_device_group() Jason Gunthorpe
2023-07-18 19:05 ` [PATCH 05/10] iommu/sprd: " Jason Gunthorpe
2023-07-18 19:05 ` [PATCH 06/10] iommu/rockchip: " Jason Gunthorpe
2023-07-18 19:05 ` [PATCH 07/10] iommu/ipmmu-vmsa: " Jason Gunthorpe
2023-07-21  7:20   ` Tian, Kevin
2023-07-21 12:04     ` Jason Gunthorpe
2023-07-18 19:05 ` [PATCH 08/10] iommu/omap: " Jason Gunthorpe
2023-07-18 19:05 ` [PATCH 09/10] iommu: Complete the locking for dev->iommu_group Jason Gunthorpe
2023-07-20  9:55   ` Baolu Lu [this message]
2023-07-18 19:05 ` [PATCH 10/10] iommu/intel: Fix missing locking for show_device_domain_translation() Jason Gunthorpe
2023-07-20  9:56   ` Baolu Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a64b95e8-435d-0659-449a-74a64a659fa7@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=dwmw2@infradead.org \
    --cc=heiko@sntech.de \
    --cc=iommu@lists.linux.dev \
    --cc=jernej.skrabec@gmail.com \
    --cc=jgg@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=orsonzhai@gmail.com \
    --cc=robin.murphy@arm.com \
    --cc=samuel@sholland.org \
    --cc=wens@csie.org \
    --cc=will@kernel.org \
    --cc=zhang.lyra@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).