From: Mikko Perttunen <mperttunen@nvidia.com>
To: Marek Szyprowski <m.szyprowski@samsung.com>,
"Joerg Roedel (AMD)" <joro@8bytes.org>,
Will Deacon <will@kernel.org>,
Russell King <linux@armlinux.org.uk>,
Heiko Stuebner <heiko@sntech.de>,
Thierry Reding <thierry.reding@kernel.org>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Jonathan Hunter <jonathanh@nvidia.com>,
Krishna Reddy <vdumpa@nvidia.com>,
Krzysztof Kozlowski <krzk@kernel.org>,
Jason Gunthorpe <jgg@ziepe.ca>,
linux-tegra@vger.kernel.org
Cc: Peter Griffin <peter.griffin@linaro.org>,
Alim Akhtar <alim.akhtar@samsung.com>,
Chen-Yu Tsai <wens@kernel.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>,
Yong Wu <yong.wu@mediatek.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Rob Clark <robin.clark@oss.qualcomm.com>,
Geert Uytterhoeven <geert+renesas@glider.be>,
iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org,
Robin Murphy <robin.murphy@arm.com>
Subject: Re: [PATCH v2 06/11] ARM: dma-mapping: Handle foreign buffers in arm_iommu_get_sgtable
Date: Tue, 20 Oct 2026 12:55:19 +0900 [thread overview]
Message-ID: <lJdkrMxST1imtqkbsWFTHw@nvidia.com> (raw)
In-Reply-To: <52c9bad4-39f4-46cf-87c2-9e57e8beeb5c@arm.com>
On Tuesday, October 20, 2026 12:47 AM Robin Murphy wrote:
> On 16/10/2026 7:46 am, Mikko Perttunen wrote:
> > arm_iommu_get_sgtable can only describe buffers which came from
> > arm_iommu_alloc_attrs, and returns -ENXIO for anything else. This is
> > stricter than iommu_dma_get_sgtable(), which falls back to describing
> > the buffer as a single chunk.
> >
> > The difference shows up when a buffer is allocated for one device and
> > mapped for another, as TegraDRM does. Buffers are allocated on the
> > host1x logical device, which has no dma_configure and therefore uses
> > direct DMA ops, and are then mapped for a display controller behind the
> > SMMU.
> >
> > Add the same fallback as iommu_dma_get_sgtable().
>
> Hmm, that's not actually what it's for... :(
>
> The "fallback" is only for the case when iommu_dma_alloc() has hit the
> dma_alloc_from_pool() path, see a98d9ae937d2 ("arm64/iommu: handle
> non-remapped addresses in ->mmap and ->get_sgtable"). It was never meant
> for dipping into *other* DMA ops because the caller has erroneously
> passed the wrong device. Just like dma_mmap_attrs() and
> dma_free_attrs(), dma_get_sgtable_attrs() must match the original
> dma_alloc_attrs() call - that's a bug in TegraDRM.
Ah, indeed. That's easy to fix in TegraDRM. I think this happened
because TegraDRM has this (a bit unsavoury) use of DMA API on both the
drm device and the actual platform devices side by side.
Thanks,
Mikko
>
> Thanks,
> Robin.
>
> > Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
> > ---
> > arch/arm/mm/dma-mapping.c | 25 +++++++++++++++++++++----
> > 1 file changed, 21 insertions(+), 4 deletions(-)
> >
> > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
> > index d6315baeddb9..c2ec4f107808 100644
> > --- a/arch/arm/mm/dma-mapping.c
> > +++ b/arch/arm/mm/dma-mapping.c
> > @@ -1169,12 +1169,29 @@ static int arm_iommu_get_sgtable(struct device *dev, struct sg_table *sgt,
> > {
> > unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT;
> > struct page **pages = __iommu_get_pages(cpu_addr, attrs);
> > + struct page *page;
> > + int ret;
> >
> > - if (!pages)
> > - return -ENXIO;
> > + if (pages)
> > + return sg_alloc_table_from_pages(sgt, pages, count, 0, size,
> > + GFP_KERNEL);
> >
> > - return sg_alloc_table_from_pages(sgt, pages, count, 0, size,
> > - GFP_KERNEL);
> > + /*
> > + * The buffer was not allocated through these DMA ops. It may belong to
> > + * a device which is not behind an IOMMU at all, which can happen when a
> > + * buffer is allocated on one device and mapped for another. Describe it
> > + * as a single chunk, as iommu_dma_get_sgtable() does.
> > + */
> > + if (is_vmalloc_addr(cpu_addr))
> > + page = vmalloc_to_page(cpu_addr);
> > + else
> > + page = virt_to_page(cpu_addr);
> > +
> > + ret = sg_alloc_table(sgt, 1, GFP_KERNEL);
> > + if (!ret)
> > + sg_set_page(sgt->sgl, page, PAGE_ALIGN(size), 0);
> > +
> > + return ret;
> > }
> >
> > /*
> >
>
>
next prev parent reply other threads:[~2026-10-20 3:55 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 6:46 [PATCH v2 00/11] Make the 32-bit ARM DMA API work with normal IOMMU DMA default domains (+ Tegra PoC) Mikko Perttunen
2026-10-16 6:46 ` [PATCH v2 01/11] iommu: Add iommu_teardown_dma_ops Mikko Perttunen
2026-10-16 6:46 ` [PATCH v2 02/11] iommu: Add cookie type for ARM_DMA_USE_IOMMU Mikko Perttunen
2026-10-16 6:46 ` [PATCH v2 03/11] ARM: dma-mapping: Split mapping allocation from domain allocation Mikko Perttunen
2026-10-16 6:46 ` [PATCH v2 04/11] ARM: dma-mapping: Implement and expose DMA setup functions Mikko Perttunen
2026-10-16 7:06 ` sashiko-bot
2026-10-16 6:46 ` [PATCH v2 05/11] ARM: dma-mapping: Bypass the legacy path for core-owned DMA API domains Mikko Perttunen
2026-10-16 7:01 ` sashiko-bot
2026-10-19 16:55 ` Robin Murphy
2026-10-20 4:01 ` Mikko Perttunen
2026-10-16 6:46 ` [PATCH v2 06/11] ARM: dma-mapping: Handle foreign buffers in arm_iommu_get_sgtable Mikko Perttunen
2026-10-16 7:04 ` sashiko-bot
2026-10-19 15:47 ` Robin Murphy
2026-10-20 3:55 ` Mikko Perttunen [this message]
2026-10-16 6:46 ` [PATCH v2 07/11] iommu: Let 32-bit ARM drivers opt into a DMA API default domain Mikko Perttunen
2026-10-20 11:28 ` Robin Murphy
2026-10-16 6:46 ` [PATCH v2 08/11] iommu/tegra-smmu: Defer display client translation to driver handover Mikko Perttunen
2026-10-16 7:01 ` sashiko-bot
2026-10-16 6:46 ` [PATCH v2 09/11] gpu: host1x: Drop release of legacy 32-bit ARM DMA domain Mikko Perttunen
2026-10-16 6:46 ` [PATCH v2 10/11] drm/tegra: " Mikko Perttunen
2026-10-16 6:46 ` [PATCH v2 11/11] iommu/tegra-smmu: Use a DMA API default domain per swgroup Mikko Perttunen
2026-10-20 15:30 ` Robin Murphy
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=lJdkrMxST1imtqkbsWFTHw@nvidia.com \
--to=mperttunen@nvidia.com \
--cc=airlied@gmail.com \
--cc=alim.akhtar@samsung.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=geert+renesas@glider.be \
--cc=heiko@sntech.de \
--cc=iommu@lists.linux.dev \
--cc=jernej.skrabec@gmail.com \
--cc=jgg@ziepe.ca \
--cc=jonathanh@nvidia.com \
--cc=joro@8bytes.org \
--cc=krzk@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=m.szyprowski@samsung.com \
--cc=matthias.bgg@gmail.com \
--cc=peter.griffin@linaro.org \
--cc=robin.clark@oss.qualcomm.com \
--cc=robin.murphy@arm.com \
--cc=samuel@sholland.org \
--cc=simona@ffwll.ch \
--cc=thierry.reding@kernel.org \
--cc=vdumpa@nvidia.com \
--cc=wens@kernel.org \
--cc=will@kernel.org \
--cc=yong.wu@mediatek.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.