From: Baolu Lu <baolu.lu@linux.intel.com>
To: Zhenhua Huang <quic_zhenhuah@quicinc.com>,
jgg@ziepe.ca, robin.murphy@arm.com, joro@8bytes.org,
will@kernel.org
Cc: baolu.lu@linux.intel.com, iommu@lists.linux.dev,
linux-arm-kernel@lists.infradead.org, quic_tingweiz@quicinc.com
Subject: Re: [RFC PATCH 1/1] iommu: Fix one concurrency issue happens on non-iommu binding device
Date: Wed, 8 Nov 2023 13:23:28 +0800 [thread overview]
Message-ID: <78c28624-caa2-4207-b6dc-8810a4dfe2ab@linux.intel.com> (raw)
In-Reply-To: <1698825902-10685-1-git-send-email-quic_zhenhuah@quicinc.com>
On 11/1/23 4:05 PM, Zhenhua Huang wrote:
> Thread (1)
> During SMMU probe:
> iommu_device_register
> bus_iommu_probe
> probe_iommu_group for all devices in bus
> _probe_iommu_device
> (non-iommu binding device) first allocate dev->iommu then free
>
> Thread (2)
> client device probing:
> dma_configure
> of_iommu_configure
> get dev->iommu->fwspec and call fwspec->ops
>
> There may be a time window that dev->iommu allocated even for non iommu
> binding device in thread (1). It would be possible thread (2) meet Use-
> after-free errors at that window.
>
> Fix it by closing the time window, set dev->iommu only once
> ops->probe_device successfully.
> Previous discussion details:
> https://lore.kernel.org/linux-arm-kernel/20231017163337.GE282036@ziepe.ca/T/#mee0d7bdc375541934a571ae69f43b9660f8e7312
>
> Suggested-by: Jason Gunthorpe<jgg@ziepe.ca>
> Signed-off-by: Zhenhua Huang<quic_zhenhuah@quicinc.com>
> ---
> Hi Jason, Robin,
> Shall we first address non-iommu binding device crash with below patch? It's
> seen a lot especially when smmu probing and other driver probing at same time.
> Although it doesn't comprehensively fixes race with of_xlate VS probe, it
> indeed solves issue for non-iommu binding device.
>
> drivers/iommu/iommu.c | 42 +++++++++++++++++++++++++++++-------------
> include/linux/iommu.h | 5 +----
> 2 files changed, 30 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index f17a111..88ce802 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -386,6 +386,17 @@ static u32 dev_iommu_get_max_pasids(struct device *dev)
> return min_t(u32, max_pasids, dev->iommu->iommu_dev->max_pasids);
> }
>
> +void dev_iommu_priv_set(struct device *dev, void *priv)
> +{
> + struct dev_iommu *dev_iommu;
> +
> + dev_iommu = dev_iommu_get(dev);
> + if (WARN_ON(!dev_iommu))
> + return;
> +
> + dev->iommu->priv = priv;
> +}
The dev_iommu_priv_set() function is intended for iommu drivers to store
per-device iommu private data after successful device probing. Invoking
dev_iommu_get() within this helper is inappropriate as it may
inadvertently allocate dev->iommu, which is not the intended purpose of
dev_iommu_priv_set().
Best regards,
baolu
prev parent reply other threads:[~2023-11-08 5:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-01 8:05 [RFC PATCH 1/1] iommu: Fix one concurrency issue happens on non-iommu binding device Zhenhua Huang
2023-11-08 5:23 ` Baolu Lu [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=78c28624-caa2-4207-b6dc-8810a4dfe2ab@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=quic_tingweiz@quicinc.com \
--cc=quic_zhenhuah@quicinc.com \
--cc=robin.murphy@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