From: Robin Murphy <robin.murphy@arm.com>
To: Will McVicker <willmcvicker@google.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
Lorenzo Pieralisi <lpieralisi@kernel.org>,
Joerg Roedel <jroedel@suse.de>,
Bjorn Helgaas <bhelgaas@google.com>,
"Rob Herring (Arm)" <robh@kernel.org>,
Jason Gunthorpe <jgg@ziepe.ca>
Cc: iommu@lists.linux.dev, Saravana Kannan <saravanak@google.com>,
kernel-team@android.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] platform: Fix race condition during DMA configure at IOMMU probe time
Date: Thu, 24 Apr 2025 19:22:20 +0100 [thread overview]
Message-ID: <335f3b1b-3233-4924-a124-619e249e4a50@arm.com> (raw)
In-Reply-To: <20250424180420.3928523-1-willmcvicker@google.com>
On 24/04/2025 7:04 pm, Will McVicker wrote:
> To avoid a race between the IOMMU probing thread and the device driver
> async probing thread during configuration of the platform DMA, update
> `platform_dma_configure()` to read `dev->driver` once and test if it's
> NULL before using it. This ensures that we don't de-reference an invalid
> platform driver pointer if the device driver is asynchronously bound
> while configuring the DMA.
Cheers Will! I have the corresponding changes for the other buses made
locally (fortuitously, in exactly the same style!), so I'll get a commit
message written up and those sent out tomorrow.
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
> Fixes: bcb81ac6ae3c ("iommu: Get DT/ACPI parsing into the proper probe path")
> Signed-off-by: Will McVicker <willmcvicker@google.com>
> ---
> drivers/base/platform.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index 1813cfd0c4bd..cfccf3ff36e7 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -1440,7 +1440,7 @@ static void platform_shutdown(struct device *_dev)
>
> static int platform_dma_configure(struct device *dev)
> {
> - struct platform_driver *drv = to_platform_driver(dev->driver);
> + struct device_driver *drv = READ_ONCE(dev->driver);
> struct fwnode_handle *fwnode = dev_fwnode(dev);
> enum dev_dma_attr attr;
> int ret = 0;
> @@ -1451,8 +1451,8 @@ static int platform_dma_configure(struct device *dev)
> attr = acpi_get_dma_attr(to_acpi_device_node(fwnode));
> ret = acpi_dma_configure(dev, attr);
> }
> - /* @drv may not be valid when we're called from the IOMMU layer */
> - if (ret || !dev->driver || drv->driver_managed_dma)
> + /* @dev->driver may not be valid when we're called from the IOMMU layer */
> + if (ret || !drv || to_platform_driver(drv)->driver_managed_dma)
> return ret;
>
> ret = iommu_device_use_default_domain(dev);
prev parent reply other threads:[~2025-04-24 18:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-24 18:04 Will McVicker
2025-04-24 18:22 ` Robin Murphy [this message]
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=335f3b1b-3233-4924-a124-619e249e4a50@arm.com \
--to=robin.murphy@arm.com \
--cc=bhelgaas@google.com \
--cc=dakr@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=jroedel@suse.de \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=saravanak@google.com \
--cc=willmcvicker@google.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
all inboxes | Powered by JetHome®