From: Marek Szyprowski <m.szyprowski@samsung.com>
To: Bryan O'Donoghue <bod@kernel.org>,
Vikash Garodia <vikash.garodia@oss.qualcomm.com>,
Jason Gunthorpe <jgg@nvidia.com>
Cc: iommu@lists.linux.dev, linux-media@vger.kernel.org,
linux-arm-msm@vger.kernel.org, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, Robin Murphy <robin.murphy@arm.com>,
Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
Leon Romanovsky <leon@kernel.org>,
Sibi Sankar <sibi.sankar@oss.qualcomm.com>,
Honglei Huang <honghuan@amd.com>,
prakash.gupta@oss.qualcomm.com,
Alex Williamson <alex@shazbot.org>,
Dikshita Agarwal <dikshita.agarwal@oss.qualcomm.com>,
Abhinav Kumar <abhinav.kumar@linux.dev>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Hans Verkuil <hverkuil+cisco@kernel.org>,
stable@vger.kernel.org
Subject: Re: [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size
Date: Mon, 30 Nov 2026 10:09:29 +0100 [thread overview]
Message-ID: <874f643c-7958-4685-9b27-f185e976bc13@samsung.com> (raw)
In-Reply-To: <21a54a2a-9df8-49c7-a7a2-e0cadd075270@kernel.org>
On 30.11.2026 02:10, Bryan O'Donoghue wrote:
> On 29/11/2026 14:19, Vikash Garodia wrote:
>>
>> On 11/27/2026 10:56 PM, Jason Gunthorpe wrote:
>>> On Fri, Nov 27, 2026 at 05:21:35PM +0000, Bryan O'Donoghue wrote:
>>>> On 27/11/2026 14:29, Jason Gunthorpe wrote:
>>>>> On Fri, Nov 27, 2026 at 12:58:45PM +0100, Marek Szyprowski wrote:
>>>>>> The IOVA reservation code compares dma_iova_state::__size directly with
>>>>>> the requested chunk size. __size is internal to the DMA IOVA API and may
>>>>>> carry flags in its upper bits, so use the dma_iova_size() accessor
>>>>>> instead.
>>>>>
>>>>> WTF is this even doing?
>>>>>
>>>>> Fix this by reserving the 0-600MB range, below the boundary the
>>>>> non-pixel stream cannot address, using dma_iova_try_alloc() so the
>>>>> IOMMU-DMA core never hands that range out to a real DMA mapping. This
>>>>> reserves only IOVA space, it does not allocate any physical memory.
>>>>>
>>>>> That isn't what this API is for, and it isn't how it even works! It is
>>>>> pure luck that the first call to it happens to take out the lower
>>>>> address space.
>>>>>
>>>>> We even had a long discussion about this driver and this need in
>>>>> another thread and this is the hack job you guys merged?
>>>>
>>>> Have to say I wasn't aware of an objection from you, I don't think I was on
>>>> that thread.
>>>
>>> Nobody ever shared this insane thing with us. Seriously, this isn't
>>> even remotely using these APIs for what they are for. Nobody thought
>>> "hey this seems like a creative use of APIs, lets ask someone" ?
>>>
>>
>> Sure, its a miss to add the maintainers of the file which defines the
>> api. Relying on b4 alone was not the right approach. Noted for any
>> future submissions.
>>
>>>> It would be possible to reserve this IOVA range in DT so given what you've
>>>> highlighted I think this and the Iris commit should be reverted and the DT
>>>> constraint implemented.
>>>
>>> That was the other thread, obviously using DT to describe a hardware
>>> issue is the correct choice. But there was some problem where they
>>> also wanted to split the SID space using DT and then the DT mechansim
>>> doesn't work because the whole thing becomes too hacky :\
>>>
>>
>> We discussed this earlier here[1] and concluded DT as the right place to
>> address this.
>> The DT approach is waiting for the series [2] to land, which should take
>> care of the reservation in a definite way.
>>
>> [1]
>> https://lore.kernel.org/all/c7b956a9-d3e8-4e18-b780-5d08f5cd2ca1@kernel.org/
>>
>> [2]
>> https://lore.kernel.org/all/20261120-add_iommu_ranges-v8-0-d90486973b73@oss.qualcomm.com/
> The other direction is to have venus and iris register their own IOMMU domain and then the address allocator they will provide places the floor at 600MB for the SID.
>
> Jason, do you think this is the right approach ?
>
> drivers/media/platform/nvidia/tegra-vde/
>
> vde->domain = iommu_paging_domain_alloc(dev);
> if (IS_ERR(vde->domain)) {
> err = PTR_ERR(vde->domain);
> vde->domain = NULL;
> goto put_group;
> }
>
> err = iova_cache_get();
> if (err)
> goto free_domain;
>
> order = __ffs(vde->domain->pgsize_bitmap);
> init_iova_domain(&vde->iova, 1UL << order, 0);
>
> err = iommu_attach_group(vde->domain, vde->group);
> if (err)
> goto put_iova;
>
> /*
> * We're using some static addresses that are not accessible by VDE
> * to trap invalid memory accesses.
> */
> shift = iova_shift(&vde->iova);
> iova = reserve_iova(&vde->iova, 0x60000000 >> shift,
> 0x70000000 >> shift);
> if (!iova) {
> err = -ENOMEM;
> goto detach_group;
> }
>
> Vikash I can prototype this up it, reverting Vishnu's patch will bring back the reset and the upstream code now relies on dodgy behaviours. If iommu-ranges lands, we can go back to using the default IOMMU domain and drop rolling our own allocations.
Well, the iris/venus driver case clearly shows that there are devices which
does some 'weird' assumptions about the IOVA values. I encountered the similar
issue long time ago when I tried to port legacy Exynos multimedia drivers to
the proposed ARM 32bit migration to generic IOMMU-DMA layer. IMHO all what
those drivers need to fully use the IOMMU-DMA glue and generic DMA-mapping
API is to let them to mark some parts of the IOVA address space as reserved.
I'm not sure if this has to be exposed in device-tree though.
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
next prev parent reply other threads:[~2026-11-30 9:09 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20261127115858eucas1p1ac63e4ce0f221453e8666ab9723a2ae0@eucas1p1.samsung.com>
2026-11-27 11:58 ` [PATCH 0/4] iommu/dma: restore flush queue use in dma_iova_destroy() Marek Szyprowski
[not found] ` <CGME20261127115859eucas1p1ae20b01eec39080daf19dbd71aba10e9@eucas1p1.samsung.com>
2026-11-27 11:58 ` [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size Marek Szyprowski
2026-11-27 12:41 ` Vikash Garodia
2026-11-27 14:29 ` Jason Gunthorpe
2026-11-27 15:24 ` Leon Romanovsky
2026-11-27 17:21 ` Bryan O'Donoghue
2026-11-27 17:26 ` Jason Gunthorpe
2026-11-28 8:55 ` Bryan O'Donoghue
2026-11-29 14:19 ` Vikash Garodia
2026-11-30 1:10 ` Bryan O'Donoghue
2026-11-30 6:15 ` Vikash Garodia
2026-11-30 9:09 ` Marek Szyprowski [this message]
2026-11-29 13:41 ` Bryan O'Donoghue
[not found] ` <CGME20261127115900eucas1p268ca3a6688c2fd99513317dfc99dbf59@eucas1p2.samsung.com>
2026-11-27 11:58 ` [PATCH 2/4] media: iris: " Marek Szyprowski
2026-11-27 12:41 ` Vikash Garodia
[not found] ` <CGME20261127115901eucas1p22ee3dbe744707c23f8ac2442f755e041@eucas1p2.samsung.com>
2026-11-27 11:58 ` [PATCH 3/4] dma-mapping: add DMA_IOVA_FLAGS mask for the dma_iova_state size flags Marek Szyprowski
2026-11-27 14:37 ` Jason Gunthorpe
[not found] ` <CGME20261127115903eucas1p27ccc4cddb7f705d6afa5c2603597b97a@eucas1p2.samsung.com>
2026-11-27 11:58 ` [PATCH 4/4] iommu/dma: restore flush queue use in dma_iova_destroy() Marek Szyprowski
2026-11-27 14:37 ` Jason Gunthorpe
2026-11-27 14:45 ` Marek Szyprowski
2026-11-27 15:17 ` Jason Gunthorpe
2026-11-27 16:29 ` Marek Szyprowski
2026-11-27 17:18 ` Marek Szyprowski
2026-11-27 15:31 ` Leon Romanovsky
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=874f643c-7958-4685-9b27-f185e976bc13@samsung.com \
--to=m.szyprowski@samsung.com \
--cc=abhinav.kumar@linux.dev \
--cc=alex@shazbot.org \
--cc=bod@kernel.org \
--cc=dikshita.agarwal@oss.qualcomm.com \
--cc=honghuan@amd.com \
--cc=hverkuil+cisco@kernel.org \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=leon@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=prakash.gupta@oss.qualcomm.com \
--cc=robin.murphy@arm.com \
--cc=sibi.sankar@oss.qualcomm.com \
--cc=stable@vger.kernel.org \
--cc=vikash.garodia@oss.qualcomm.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
all inboxes | Powered by JetHome®