From: Jason Gunthorpe <jgg@ziepe.ca>
To: Robin Murphy <robin.murphy@arm.com>
Cc: 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>,
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,
Charan Teja Kalla <quic_charante@quicinc.com>
Subject: Re: [PATCH 2/2] iommu: Get DT/ACPI parsing into the proper probe path
Date: Fri, 14 Feb 2025 16:14:35 -0400 [thread overview]
Message-ID: <20250214201435.GF3696814@ziepe.ca> (raw)
In-Reply-To: <c2f0ae276fd5a18e1653bae8bb0c51670e35b283.1739486121.git.robin.murphy@arm.com>
On Thu, Feb 13, 2025 at 11:49:00PM +0000, Robin Murphy wrote:
> much just calling the same path twice. At client driver probe time,
> dev->driver is obviously set; conversely at device_add(), or a
> subsequent bus_iommu_probe(), any device waiting for an IOMMU really
Could you put the dev->driver test into iommu_device_use_default_domain()?
It looks like many of the cases are just guarding that call.
> should *not* have a driver already, so we can use that as a condition to
> disambiguate the two cases, and avoid recursing back into the IOMMU core
> at the wrong times.
Which sounds like this:
> + mutex_unlock(&iommu_probe_device_lock);
> + dev->bus->dma_configure(dev);
> + mutex_lock(&iommu_probe_device_lock);
> + }
Shouldn't call iommu_device_use_default_domain() ?
But... I couldn't guess what the problem with calling it is?
In the not-probed case it will see dev->iommu_group is NULL and succeed.
The probed case could be prevented by checking dev->iommu_group sooner
in __iommu_probe_device()?
Anyhow, the approach seems OK
> diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
> index 9f4efa8f75a6..42b8f1833c3c 100644
> --- a/drivers/acpi/scan.c
> +++ b/drivers/acpi/scan.c
> @@ -1619,6 +1619,9 @@ static int acpi_iommu_configure_id(struct device *dev, const u32 *id_in)
> {
> int err;
>
> + if (device_iommu_mapped(dev))
> + return 0;
This is unlocked and outside a driver context, it should have a
comment explaining why races with probe can't happen?
> + /*
> + * For FDT-based systems and ACPI IORT/VIOT, the common firmware parsing
> + * is buried in the bus dma_configure path. Properly unpicking that is
> + * still a fairly big job, so for now just invoke the whole thing. Our
> + * bus_iommu_probe() walk may see devices with drivers already bound,
> + * but that must mean they're already configured - either probed by
> + * another IOMMU, or there was no IOMMU for iommu_fwspec_init() to wait
> + * for - so either way we can safely skip this and avoid worrying about
> + * those recursing back here thinking they need a replay call.
> + */
> + if (!dev->driver && dev->bus->dma_configure) {
> + mutex_unlock(&iommu_probe_device_lock);
> + dev->bus->dma_configure(dev);
> + mutex_lock(&iommu_probe_device_lock);
> + }
> +
> + /*
> + * At this point, either valid devices now have a fwspec, or we can
> + * assume that only one of Intel, AMD, s390, PAMU or legacy SMMUv2 can
> + * be present, and that any of their registered instances has suitable
> + * ops for probing, and thus cheekily co-opt the same mechanism.
> + */
> + ops = iommu_fwspec_ops(dev_iommu_fwspec_get(dev));
> + if (!ops)
> + return -ENODEV;
> +
> /* Device is probed already if in a group */
> if (dev->iommu_group)
> return 0;
This is the test I mean, if iommu_group is set then
dev->iommu->iommu_dev->ops is supposed to be valid too. It seems like
it should be done earlier..
> + /*
> + * And if we do now see any replay calls, they would indicate someone
> + * misusing the dma_configure path outside bus code.
> + */
> + if (dev_iommu_fwspec_get(dev) && dev->driver)
> + dev_WARN(dev, "late IOMMU probe at driver bind, something fishy here!\n");
WARN_ON_ONCE or dump_stack() to get the stack trace out?
> @@ -121,6 +121,9 @@ int of_iommu_configure(struct device *dev, struct device_node *master_np,
> if (!master_np)
> return -ENODEV;
>
> + if (device_iommu_mapped(dev))
> + return 0;
Same note
> @@ -151,7 +154,12 @@ int of_iommu_configure(struct device *dev, struct device_node *master_np,
> iommu_fwspec_free(dev);
> mutex_unlock(&iommu_probe_device_lock);
>
> - if (!err && dev->bus)
> + /*
> + * If we have reason to believe the IOMMU driver missed the initial
> + * iommu_probe_device() call for dev, try to fix it up. This should
> + * no longer happen unless of_dma_configure() is being misused.
> + */
> + if (!err && dev->driver)
> err = iommu_probe_device(dev);
This is being conservative? After some time of nobody complaining
it can be removed?
Jason
next prev parent reply other threads:[~2025-02-14 20:14 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
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 [this message]
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=20250214201435.GF3696814@ziepe.ca \
--to=jgg@ziepe.ca \
--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=robin.murphy@arm.com \
--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