mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Brian Norris <briannorris@chromium.org>
Cc: joro@8bytes.org, will@kernel.org, iommu@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iommu: Avoid races around device probe
Date: Mon, 7 Nov 2022 16:41:33 +0000	[thread overview]
Message-ID: <1f74e7e5-f57c-e269-bc78-aeb5820031ee@arm.com> (raw)
In-Reply-To: <Y2W+DxePm8WcUn46@google.com>

On 2022-11-05 01:36, Brian Norris wrote:
> On Fri, Nov 04, 2022 at 07:51:43PM +0000, Robin Murphy wrote:
>> We currently have 3 different ways that __iommu_probe_device() may be
>> called, but no real guarantee that multiple callers can't tread on each
>> other, especially once asynchronous driver probe gets involved. It would
>> likely have taken a fair bit of luck to hit this previously, but commit
>> 57365a04c921 ("iommu: Move bus setup to IOMMU device registration") ups
>> the odds since now it's not just omap-iommu that may trigger multiple
>> bus_iommu_probe() calls in parallel if probing asynchronously.
>>
>> Add a lock to ensure we can't try to double-probe a device, and also
>> close some possible race windows to make sure we're truly robust against
>> trying to double-initialise a group via two different member devices.
>>
>> Reported-by: Brian Norris <briannorris@chromium.org>
>> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
>> ---
>>   drivers/iommu/iommu.c | 28 ++++++++++++++++++++++------
>>   1 file changed, 22 insertions(+), 6 deletions(-)
> 
> If I've tested appropriately (there's always room for operator error),
> this seems to resolve the problems I reported:
> 
> Tested-by: Brian Norris <briannorris@chromium.org>
> 
> I haven't reviewed closely enough to know how precisely this is a
> regression (your description sounds like you think the bug existed some
> time before that), but based on testing, this sounds like:
> 
> Fixes: 57365a04c921 ("iommu: Move bus setup to IOMMU device
> registration")

That commit did not introduce the race, just made it more visible. The 
underlying condition probably goes back at least 3 years to where we 
started allocating and freeing per-device data around what was then the 
ops->add_device() call.

In practice, you'd have to be absurdly lucky for an iommu_probe_device() 
call via {of,acpi}_dma_configure() to line up with bus_iommu_probe() 
touching the same device, but by inspection I think it's theoretically 
possible. Thus previously there was probably only a realistic chance of 
seeing it on certain OMAP systems, where the explicit bus_iommu_probe() 
calls could overlap if both instances probed in parallel - my commit 
just brings all the other drivers in line with that same behaviour via 
iommu_device_register(). Other systems - like Rockchip in particular - 
may have greater numbers of IOMMU instances and thus even more chance 
for parallel probes to line up just right.

Since nobody's ever reported real-world issues on OMAP (although it's 
quite likely nobody's ever tried driver_async_probe with omap-iommu 
anyway) there doesn't seem to be a compelling reason for backporting, so 
I didn't fancy spending hours digging through subsystem-wide history 
trying to figure out an appropriate fixes tag; as long as this can make 
6.1 that should be enough :)

Thanks,
Robin.

> But even if not, the report could probably use:
> 
> Link: https://lore.kernel.org/lkml/Y1CHh2oM5wyHs06J@google.com/
> 
> And most of all, thanks!
> 
> Brian

  reply	other threads:[~2022-11-07 16:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-04 19:51 Robin Murphy
2022-11-05  1:36 ` Brian Norris
2022-11-07 16:41   ` Robin Murphy [this message]
2022-11-19  9:18 ` Joerg Roedel

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=1f74e7e5-f57c-e269-bc78-aeb5820031ee@arm.com \
    --to=robin.murphy@arm.com \
    --cc=briannorris@chromium.org \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --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®