From: Jason Gunthorpe <jgg@nvidia.com>
To: Robin Murphy <robin.murphy@arm.com>,
Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Andy Gross <agross@kernel.org>,
Alim Akhtar <alim.akhtar@samsung.com>,
Bjorn Andersson <andersson@kernel.org>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Gerald Schaefer <gerald.schaefer@linux.ibm.com>,
Heiko Stuebner <heiko@sntech.de>,
iommu@lists.linux.dev, Jernej Skrabec <jernej.skrabec@gmail.com>,
Jonathan Hunter <jonathanh@nvidia.com>,
Joerg Roedel <joro@8bytes.org>,
Konrad Dybcio <konrad.dybcio@linaro.org>,
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
linux-arm-kernel@lists.infradead.org,
linux-arm-msm@vger.kernel.org,
linux-mediatek@lists.infradead.org,
linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org,
linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev,
linux-tegra@vger.kernel.org,
Matthias Brugger <matthias.bgg@gmail.com>,
Matthew Rosato <mjrosato@linux.ibm.com>,
Orson Zhai <orsonzhai@gmail.com>, Rob Clark <robdclark@gmail.com>,
Samuel Holland <samuel@sholland.org>,
Niklas Schnelle <schnelle@linux.ibm.com>,
Thierry Reding <thierry.reding@gmail.com>,
Krishna Reddy <vdumpa@nvidia.com>, Chen-Yu Tsai <wens@csie.org>,
Will Deacon <will@kernel.org>, Yong Wu <yong.wu@mediatek.com>,
Chunyan Zhang <zhang.lyra@gmail.com>,
Lu Baolu <baolu.lu@linux.intel.com>,
Kevin Tian <kevin.tian@intel.com>,
Nicolin Chen <nicolinc@nvidia.com>,
Steven Price <steven.price@arm.com>
Subject: Re: [PATCH 06/20] iommu/exynos: Implement an IDENTITY domain
Date: Thu, 4 May 2023 11:19:45 -0300 [thread overview]
Message-ID: <ZFO/AcHaWNZbL8p3@nvidia.com> (raw)
In-Reply-To: <aaddd64b-6935-f84a-5fda-28011c717051@arm.com>
On Wed, May 03, 2023 at 04:31:39PM +0100, Robin Murphy wrote:
> > - struct device *dev)
> > +static int exynos_iommu_identity_attach(struct iommu_domain *identity_domain,
> > + struct device *dev)
> > {
> > - struct exynos_iommu_domain *domain = to_exynos_domain(iommu_domain);
> > struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev);
> > - phys_addr_t pagetable = virt_to_phys(domain->pgtable);
> > + struct exynos_iommu_domain *domain;
> > + phys_addr_t pagetable;
> > struct sysmmu_drvdata *data, *next;
> > unsigned long flags;
> > - if (!has_sysmmu(dev) || owner->domain != iommu_domain)
> > - return;
> > + if (!owner)
> > + return -ENODEV;
>
> That can't be true - devices can't be attached without having already
> dereferenced their group, which means they've been through probe_device
> successfully.
Yes, the current code is wrong to check has_sysmmu(), I removed it
> > + if (owner->domain == identity_domain)
> > + return 0;
> > +
> > + domain = to_exynos_domain(owner->domain);
> > + pagetable = virt_to_phys(domain->pgtable);
>
> Identity domains by definition shouldn't have a pagetable? I don't think
> virt_to_phys(NULL) can be assumed to be valid or safe in general.
Read again, the first if excludes that owner->domain is identity so
it must be paging. Thus pgtable mst be valid.
More broadly the struct exynos_iommu_domain is now always a paging
domain.
> > mutex_lock(&owner->rpm_lock);
> > @@ -1009,15 +1015,25 @@ static void exynos_iommu_detach_device(struct iommu_domain *iommu_domain,
> > list_del_init(&data->domain_node);
> > spin_unlock(&data->lock);
> > }
>
> This iterates the whole domain->clients list, which may include other
> devices from other groups belonging to other IOMMU instances. I think that's
> technically an issue already given that we support cross-instance domain
> attach here, which the DRM drivers rely on. I can't quite work out off-hand
> if this is liable to make it any worse or not :/
Yeah, that looks wrong today - it should be a strict pairing with
exynos_iommu_attach_device() so it needs to check if each
client's sysmmu_drvdata is in the exynos_iommu_owner->controller list.
Marek?
At least this transformation shouldn't make it worse as we will still
call this code in all the same places as we always did. The identity
domain is also not threaded on this list.
> > - owner->domain = NULL;
> > + owner->domain = identity_domain;
> > spin_unlock_irqrestore(&domain->lock, flags);
> > mutex_unlock(&owner->rpm_lock);
> > dev_dbg(dev, "%s: Detached IOMMU with pgtable %pa\n", __func__,
>
> This no longer makes much sense.
dev_dbg(dev, "%s: Restored IOMMU to IDENTITY from pgtable %pa\n",
__func__, &pagetable);
Better?
> > @@ -1457,6 +1458,7 @@ static int exynos_iommu_of_xlate(struct device *dev,
> > INIT_LIST_HEAD(&owner->controllers);
> > mutex_init(&owner->rpm_lock);
> > + owner->domain = &exynos_identity_domain;
>
> I think strictly this would be more of a probe_device thing than an of_xlate
> thing, but it's not super-important.
The full code block is this:
owner = kzalloc(sizeof(*owner), GFP_KERNEL);
if (!owner) {
put_device(&sysmmu->dev);
return -ENOMEM;
}
INIT_LIST_HEAD(&owner->controllers);
mutex_init(&owner->rpm_lock);
owner->domain = &exynos_identity_domain;
dev_iommu_priv_set(dev, owner);
So we set the domain at the same time we allocate and initialize the
owner struct.
Why this is allocated in of_xlate is beyond me, but it is the right
place to put this initialization, we never want NULL to be stored
here.
Thanks,
Jason
next prev parent reply other threads:[~2023-05-04 14:19 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-01 18:02 [PATCH 00/20] iommu: Make default_domain's mandatory Jason Gunthorpe
2023-05-01 18:02 ` [PATCH 01/20] iommu: Add IOMMU_DOMAIN_PLATFORM Jason Gunthorpe
2023-05-01 18:02 ` [PATCH 02/20] iommu/terga-gart: Replace set_platform_dma_ops() with IOMMU_DOMAIN_PLATFORM Jason Gunthorpe
2023-05-03 9:17 ` Robin Murphy
2023-05-03 11:01 ` Jason Gunthorpe
2023-05-03 12:01 ` Robin Murphy
2023-05-03 13:45 ` Jason Gunthorpe
2023-05-03 14:43 ` Thierry Reding
2023-05-03 17:20 ` Jason Gunthorpe
2023-05-12 2:55 ` Dmitry Osipenko
2023-05-12 16:49 ` Jason Gunthorpe
2023-05-12 18:12 ` Robin Murphy
2023-05-12 20:52 ` Jason Gunthorpe
2023-05-01 18:02 ` [PATCH 03/20] iommu/s390: " Jason Gunthorpe
2023-05-02 17:57 ` Niklas Schnelle
2023-05-01 18:02 ` [PATCH 04/20] iommu/fsl_pamu: " Jason Gunthorpe
2023-05-03 10:57 ` Robin Murphy
2023-05-03 12:54 ` Jason Gunthorpe
2023-05-01 18:02 ` [PATCH 05/20] iommu: Allow an IDENTITY domain as the default_domain in ARM32 Jason Gunthorpe
2023-05-03 13:50 ` Robin Murphy
2023-05-03 14:23 ` Jason Gunthorpe
2023-05-01 18:02 ` [PATCH 06/20] iommu/exynos: Implement an IDENTITY domain Jason Gunthorpe
2023-05-03 15:31 ` Robin Murphy
2023-05-04 14:19 ` Jason Gunthorpe [this message]
2023-05-01 18:02 ` [PATCH 07/20] iommu/tegra-smmu: " Jason Gunthorpe
2023-05-01 18:02 ` [PATCH 08/20] iommu/tegra-smmu: Support DMA domains in tegra Jason Gunthorpe
2023-05-01 18:02 ` [PATCH 09/20] iommu/omap: Implement an IDENTITY domain Jason Gunthorpe
2023-05-01 18:02 ` [PATCH 10/20] iommu/msm: " Jason Gunthorpe
2023-05-01 18:02 ` [PATCH 11/20] iommu/mtk_iommu_v1: " Jason Gunthorpe
2023-05-01 18:02 ` [PATCH 12/20] iommu: Remove ops->set_platform_dma_ops() Jason Gunthorpe
2023-05-01 18:02 ` [PATCH 13/20] iommu/qcom_iommu: Add an IOMMU_IDENTITIY_DOMAIN Jason Gunthorpe
2023-05-01 18:02 ` [PATCH 14/20] iommu/ipmmu: " Jason Gunthorpe
2023-05-01 18:02 ` [PATCH 15/20] iommu/mtk_iommu: " Jason Gunthorpe
2023-05-01 18:03 ` [PATCH 16/20] iommu/sun50i: " Jason Gunthorpe
2023-05-03 15:54 ` Robin Murphy
2023-05-03 16:49 ` Jason Gunthorpe
2023-05-01 18:03 ` [PATCH 17/20] iommu: Require a default_domain for all iommu drivers Jason Gunthorpe
2023-05-01 18:03 ` [PATCH 18/20] iommu: Add ops->domain_alloc_paging() Jason Gunthorpe
2023-05-03 17:17 ` Robin Murphy
2023-05-03 19:35 ` Jason Gunthorpe
2023-05-04 12:35 ` Niklas Schnelle
2023-05-04 13:14 ` Jason Gunthorpe
2023-05-01 18:03 ` [PATCH 19/20] iommu: Convert simple drivers with DOMAIN_DMA to domain_alloc_paging() Jason Gunthorpe
2023-05-01 18:03 ` [PATCH 20/20] iommu: Convert remaining simple drivers " Jason Gunthorpe
2023-05-02 14:52 ` Niklas Schnelle
2023-05-02 15:25 ` Jason Gunthorpe
2023-05-02 18:02 ` Niklas Schnelle
2023-05-01 21:34 ` [PATCH 00/20] iommu: Make default_domain's mandatory Heiko Stübner
2023-05-01 22:40 ` Jason Gunthorpe
2023-05-01 22:10 ` Heiko Stübner
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=ZFO/AcHaWNZbL8p3@nvidia.com \
--to=jgg@nvidia.com \
--cc=agross@kernel.org \
--cc=alim.akhtar@samsung.com \
--cc=andersson@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=baolin.wang@linux.alibaba.com \
--cc=baolu.lu@linux.intel.com \
--cc=gerald.schaefer@linux.ibm.com \
--cc=heiko@sntech.de \
--cc=iommu@lists.linux.dev \
--cc=jernej.skrabec@gmail.com \
--cc=jonathanh@nvidia.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=konrad.dybcio@linaro.org \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=linux-tegra@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=matthias.bgg@gmail.com \
--cc=mjrosato@linux.ibm.com \
--cc=nicolinc@nvidia.com \
--cc=orsonzhai@gmail.com \
--cc=robdclark@gmail.com \
--cc=robin.murphy@arm.com \
--cc=samuel@sholland.org \
--cc=schnelle@linux.ibm.com \
--cc=steven.price@arm.com \
--cc=thierry.reding@gmail.com \
--cc=vdumpa@nvidia.com \
--cc=wens@csie.org \
--cc=will@kernel.org \
--cc=yong.wu@mediatek.com \
--cc=zhang.lyra@gmail.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;
as well as URLs for NNTP newsgroup(s).