From: Robin Murphy <robin.murphy@arm.com>
To: Charan Teja Kalla <quic_charante@quicinc.com>,
Lorenzo Pieralisi <lpieralisi@kernel.org>,
Hanjun Guo <guohanjun@huawei.com>,
Sudeep Holla <sudeep.holla@arm.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Len Brown <lenb@kernel.org>, Russell King <linux@armlinux.org.uk>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Danilo Krummrich <dakr@kernel.org>,
Stuart Yoder <stuyoder@gmail.com>,
Laurentiu Tudor <laurentiu.tudor@nxp.com>,
Nipun Gupta <nipun.gupta@amd.com>,
Nikhil Agarwal <nikhil.agarwal@amd.com>,
Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
Rob Herring <robh@kernel.org>,
Saravana Kannan <saravanak@google.com>,
Bjorn Helgaas <bhelgaas@google.com>
Cc: linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, iommu@lists.linux.dev,
devicetree@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH 1/2] iommu: Handle race with default domain setup
Date: Mon, 17 Feb 2025 16:29:36 +0000 [thread overview]
Message-ID: <f882ec8a-c577-4487-bf46-8c406c60aa67@arm.com> (raw)
In-Reply-To: <2a090f80-e145-410d-8d02-efdaf324c8c9@quicinc.com>
On 14/02/2025 12:57 pm, Charan Teja Kalla wrote:
> Thanks a lot for posting these patches, Robin.
>
> On 2/14/2025 5:18 AM, Robin Murphy wrote:
>> drivers/iommu/iommu.c | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
>> index 870c3cdbd0f6..2486f6d6ef68 100644
>> --- a/drivers/iommu/iommu.c
>> +++ b/drivers/iommu/iommu.c
>> @@ -3097,6 +3097,11 @@ int iommu_device_use_default_domain(struct device *dev)
>> return 0;
>>
>> mutex_lock(&group->mutex);
>> + /* We may race against bus_iommu_probe() finalising groups here */
>> + if (!group->default_domain) {
>> + ret = -EPROBE_DEFER;
>> + goto unlock_out;
>> + }
>
> We just hit the issue again even after picking up this patch, though
> very hard to reproduce, on 6.6 LTS.
>
> After code inspection, it seems the issue is that - default domain is
> setup in the bus_iommu_probe() before hitting of this replay.
>
> A:async client probe in platform_dma_configure(), B:bus_iommu_probe() :-
>
> 1) A: sets up iommu_fwspec under iommu_probe_device_lock.
>
> 2) B: Sets the dev->iommu_group under iommu_probe_device_lock. Domain
> setup is deferred.
>
> 3) A: Returns with out allocating the default domain, as
> dev->iommu_group is set, whose checks are also made under the same
> 'iommu_probe_device_lock'. __This miss setting of the valid dev->dma_ops__.
>
> 4) B: Sets up the group->default_domain under group->mutex.
>
> 5) A: iommu_device_use_default_domain(): Relies on this
> group->default_domain, under the same mutex, to decide if need to go for
> replay, which is skipped. This is skipping the setting up of valid
> dma_ops and that's an issue.
>
> But I don't think that the same issue exists on 6.13 because of your
> patch, b67483b3c44e ("iommu/dma: Centralise iommu_setup_dma_ops()").
> bus_iommu_probe():
> list_for_each_entry_safe(group, next, &group_list, entry) {
> mutex_lock(&group->mutex);
> for_each_group_device(group, gdev)
> iommu_setup_dma_ops(gdev->dev);
> mutex_unlock(&group->mutex);
> }
>
> This makes the step4 above force to use the valid dma_iommu api, thus I
> see no issue when there is no probe deferral.
>
> So, I think we are good with this patch on 6.13.
>
> Now coming back to 6.6 LTS, any ideas you have here, please?
Thanks for the analysis once again! I've not looked closely at 6.6 yet,
but if we're all happy this looks like the right fix for mainline then
I'll start having a look at the backport as soon as I can (so much for
hoping it would be simple...)
Cheers,
Robin.
>
>> if (group->owner_cnt) {
>> if (group->domain != group->default_domain || group->owner ||
>> !xa_empty(&group->pasid_array)) {
>
>
> Thanks,
> Charan
next prev parent reply other threads:[~2025-02-17 16:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-13 23:48 [PATCH 0/2] iommu: Fix the longstanding probe issues Robin Murphy
2025-02-13 23:48 ` [PATCH 1/2] iommu: Handle race with default domain setup Robin Murphy
2025-02-14 12:57 ` Charan Teja Kalla
2025-02-17 16:29 ` Robin Murphy [this message]
2025-02-14 19:43 ` Jason Gunthorpe
2025-02-13 23:49 ` [PATCH 2/2] iommu: Get DT/ACPI parsing into the proper probe path Robin Murphy
2025-02-14 17:29 ` Bjorn Helgaas
2025-02-14 20:14 ` Jason Gunthorpe
2025-02-17 15:00 ` Robin Murphy
2025-02-19 18:29 ` Jason Gunthorpe
2025-02-19 22:43 ` Rob Herring
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=f882ec8a-c577-4487-bf46-8c406c60aa67@arm.com \
--to=robin.murphy@arm.com \
--cc=bhelgaas@google.com \
--cc=dakr@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=guohanjun@huawei.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=laurentiu.tudor@nxp.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=lpieralisi@kernel.org \
--cc=nikhil.agarwal@amd.com \
--cc=nipun.gupta@amd.com \
--cc=quic_charante@quicinc.com \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=saravanak@google.com \
--cc=stuyoder@gmail.com \
--cc=sudeep.holla@arm.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