From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=210.118.77.12 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796029782; b=JwlniAO3TCOv/oXsstOz3BPME4tNQVgDkyEzessl5DXjMYHShuraEDy+PmoEqupX6wCV Hr6UzoqDS03WMcLiysvAGH9YEozMJnz63CNOsh+uFsAKMFYg9hkBERrvHMCD+D1/p+d4X Tvlja7OP9fp30T5eVLio7xJ/YZZG1w3F5l6ypTPCv+FLHCMaaZX0gaB2E4mng+BoQ2Bw0 dueCeppyiDozchzoV/gruWwQIYIIuf242PsJhJPqstO4eukfACdzNNm2/k7lX8QwQEFK7 gNNc5jV5t/+NmeSXNXbLmP7vs5fbDWiC3ifxBgS0KJs/KAhtmGXNPXZslofZa++j6PQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796029782; h=DMARC-Filter:Received:DKIM-Filter:DKIM-Signature:Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc: Content-Language:From:In-Reply-To:Content-Transfer-Encoding: X-CMS-MailID:X-Msg-Generator:Content-Type:X-RootMTR:X-EPHeader: X-CMS-RootMailID:References; bh=GS8PZ0u09KP6fPUGDhDdiuoUuc83vucohXlJkIlBmYY=; b=ChOcIUPlFdsPXXOdqCeOyQkFb+baxJwi7SfWINVrSOGvJc0CKBG4CWJ4p+t6gsplSh/t O/W7j03fbxHESsHW2/ZVe5U36a2Euexx2YMb8w/k7Fwmqm/hdN4LNrbJvtjfr6j5bwAbr KyGuiXJNi2Y+bMjBSL8ZHMJlMZWMu9Qta3XsyDtTjF7XdW06xvm3d9ziK2fe2XuFELZ2j wHx2kWZj5nLYNh+fjtHXhtEgrY9iZh6YEj3aLGwwQU5H1wjZk75FLzVW0HANcqkg92YYy F1T6KcvVBZ/j2bWi24Lt+mToJXdxRdf1GeD3z+kZMxe0bmH0HDGb82+mCYrbVz3ND1A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass header.d=samsung.com header.i=@samsung.com header.a=rsa-sha256 header.s=mail20170921 header.b=rM9a6VYH; arc=none smtp.remote-ip=210.118.77.12 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25068606A327 for ; Mon, 30 Nov 2026 09:09:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 25068606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.a=rsa-sha256 header.s=mail20170921 header.b=rM9a6VYH Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20261130090932euoutp021fa14fefb00bc192cc7fdf3cd7d64de9~sx4-uTHg-1484714847euoutp02i for ; Mon, 30 Nov 2026 09:09:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20261130090932euoutp021fa14fefb00bc192cc7fdf3cd7d64de9~sx4-uTHg-1484714847euoutp02i DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1796029772; bh=GS8PZ0u09KP6fPUGDhDdiuoUuc83vucohXlJkIlBmYY=; h=Date:Subject:To:Cc:From:In-Reply-To:References:From; b=rM9a6VYHDPTLMNA2nXNg/8iuFDNp8mfuENQmYu7uD7d8bbuSNklC8Sf6x8Fei2+le 8ydBi8M8BRezxyCiAg5wlRx8subu9JGxgouyRvilELW9rWPBG0AwvqtFLL0EqncT+W Bnf6Rx+3SkBuPwOrE7d+Bpc0bkajzOGrfvMiXFxE= Received: from eusmtip2.samsung.com (unknown [203.254.199.222]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20261130090932eucas1p1b7cd69615f943ff521ad086e8f0909f8~sx4-XLeT82413624136eucas1p1U; Mon, 30 Nov 2026 09:09:32 +0000 (GMT) Received: from [106.210.134.192] (unknown [106.210.134.192]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20261130090930eusmtip2deabc7060a7ebc747e6f2dcd9c02927c~sx49v2ASi0835808358eusmtip2X; Mon, 30 Nov 2026 09:09:30 +0000 (GMT) Message-ID: <874f643c-7958-4685-9b27-f185e976bc13@samsung.com> Date: Mon, 30 Nov 2026 10:09:29 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Betterbird (Windows) Subject: Re: [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size To: Bryan O'Donoghue , Vikash Garodia , Jason Gunthorpe 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 , Joerg Roedel , Will Deacon , Leon Romanovsky , Sibi Sankar , Honglei Huang , prakash.gupta@oss.qualcomm.com, Alex Williamson , Dikshita Agarwal , Abhinav Kumar , Mauro Carvalho Chehab , Hans Verkuil , stable@vger.kernel.org Content-Language: en-US From: Marek Szyprowski In-Reply-To: <21a54a2a-9df8-49c7-a7a2-e0cadd075270@kernel.org> Content-Transfer-Encoding: 8bit X-CMS-MailID: 20261130090932eucas1p1b7cd69615f943ff521ad086e8f0909f8 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20261127115859eucas1p1ae20b01eec39080daf19dbd71aba10e9 X-EPHeader: CA X-CMS-RootMailID: 20261127115859eucas1p1ae20b01eec39080daf19dbd71aba10e9 References: <20261127115849.2780625-1-m.szyprowski@samsung.com> <20261127115849.2780625-2-m.szyprowski@samsung.com> <20261127142912.GK114472@nvidia.com> <20261127172626.GQ114472@nvidia.com> <0b76ccad-877d-41b9-a7a6-02266a7bfd56@oss.qualcomm.com> <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