From: Robin Murphy <robin.murphy@arm.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: Nicolin Chen <nicolinc@nvidia.com>,
Baolu Lu <baolu.lu@linux.intel.com>,
joro@8bytes.org, will@kernel.org, bhelgaas@google.com,
iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-pci@vger.kernel.org, patches@lists.linux.dev,
pjaroszynski@nvidia.com, vsethi@nvidia.com
Subject: Re: [PATCH RFC v1 1/2] iommu: Introduce iommu_dev_reset_prepare() and iommu_dev_reset_done()
Date: Tue, 10 Jun 2025 17:31:09 +0100 [thread overview]
Message-ID: <f66bf027-5dbb-473b-b57f-ed3ed7914800@arm.com> (raw)
In-Reply-To: <20250610153646.GH543171@nvidia.com>
On 2025-06-10 4:36 pm, Jason Gunthorpe wrote:
> On Tue, Jun 10, 2025 at 03:40:40PM +0100, Robin Murphy wrote:
>> On 2025-06-10 2:04 pm, Jason Gunthorpe wrote:
>>> On Tue, Jun 10, 2025 at 12:07:00AM -0700, Nicolin Chen wrote:
>>>> On Tue, Jun 10, 2025 at 12:26:07PM +0800, Baolu Lu wrote:
>>>>> On 6/10/25 02:45, Nicolin Chen wrote:
>>>>>> + ops = dev_iommu_ops(dev);
>>>>>
>>>>> Should this be protected by group->mutext?
>>>>
>>>> Not seemingly, but should require the iommu_probe_device_lock I
>>>> think.
>>>
>>> group and ops are not permitted to change while a driver is attached..
>>>
>>> IIRC the FLR code in PCI doesn't always ensure that (due to the sysfs
>>> paths), so yeah, this looks troubled. iommu_probe_device_lock perhaps
>>> would fix it.
>>
>> No, iommu_probe_device_lock is for protecting access to dev->iommu in the
>> probe path until the device is definitively assigned to a group (or not).
>> Fundamentally it defends against multiple sources triggering a probe of the
>> same device in parallel - once the device *is* probed it is no longer
>> relevant, and the group mutex is the right thing to protect all subsequent
>> operations.
>
> Yes, adding iommu_probe_device_lock to iommu_deinit_device() would be
> gross.
>
> but something is required to protect the load of
> dev->iommu_group.. dev->iommu_group->mutex can't protect itself
> against a race UAF on deinit.
Then you do iommu_group_get/put() around it as well. And I suppose
technically you also ought to check that the device is still actually in
the group once you have acquired the mutex (although perhaps that case
ends up crashing anyway once we proceed to attempting to reset the
already-disappeared device itself...)
> READ_ONCE is good enough to protect from races with the probe path, no
> need for iommu_probe_device_lock there.
>
> In this case need to look at the PCI sysfs for races against the
> iommu_release_device()/etc that is freeing the dev->iommu_group.
>
> Maybe the sysfs is always removed before we get to release. Or maybe
> the PCI FLR sysfs code should hold the device_lock..
From a quick skim I suspect it's probably OK - at least device_del()
gets to bus_remove_device()->device_remove_groups() well enough before
the BUS_NOTIFY_REMOVED_DEVICE call that triggers iommu_release_device().
And on an unrelated thought that's just come to mind, if we ever did FLR
with PASIDs enabled, presumably that's going to wipe out the PASID
configuration, so will the caller who requested the reset actually
expect the attachments at the IOMMU end to be preserved, or would they
assume to start over from scratch? Seems like there's not necessarily
one right answer there :/
Thanks,
Robin.
next prev parent reply other threads:[~2025-06-10 16:31 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-09 18:45 [PATCH RFC v1 0/2] iommu&pci: Disable ATS during FLR resets Nicolin Chen
2025-06-09 18:45 ` [PATCH RFC v1 1/2] iommu: Introduce iommu_dev_reset_prepare() and iommu_dev_reset_done() Nicolin Chen
2025-06-10 4:26 ` Baolu Lu
2025-06-10 7:07 ` Nicolin Chen
2025-06-10 13:04 ` Jason Gunthorpe
2025-06-10 14:40 ` Robin Murphy
2025-06-10 15:36 ` Jason Gunthorpe
2025-06-10 16:31 ` Robin Murphy [this message]
2025-06-10 16:43 ` Jason Gunthorpe
2025-06-10 20:19 ` Nicolin Chen
2025-06-10 23:41 ` Jason Gunthorpe
2025-06-09 18:45 ` [PATCH RFC v1 2/2] pci: Suspend ATS before doing FLR Nicolin Chen
2025-06-10 4:27 ` Baolu Lu
2025-06-10 6:55 ` Nicolin Chen
2025-06-10 15:37 ` [PATCH RFC v1 0/2] iommu&pci: Disable ATS during FLR resets Robin Murphy
2025-06-10 16:30 ` Jason Gunthorpe
2025-06-10 20:36 ` Nicolin Chen
2025-06-10 23:43 ` Jason Gunthorpe
2025-06-13 19:27 ` Bjorn Helgaas
2025-06-13 21:10 ` Nicolin Chen
2025-06-16 13:09 ` Jason Gunthorpe
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=f66bf027-5dbb-473b-b57f-ed3ed7914800@arm.com \
--to=robin.murphy@arm.com \
--cc=baolu.lu@linux.intel.com \
--cc=bhelgaas@google.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=nicolinc@nvidia.com \
--cc=patches@lists.linux.dev \
--cc=pjaroszynski@nvidia.com \
--cc=vsethi@nvidia.com \
--cc=will@kernel.org \
/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
all inboxes | Powered by JetHome®