From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796217906; b=o9f6X9Z86A63veJsCgnXmu+1nZc7jb1AF0KmDcUQrGhHjJ6tRl9N6FshtxhP6Ug88uX/ SG5Lqlvit3UrozHf0HxfrSnwimMVVlQhmpKTxUJ7OILvTclMdNUbdjf3uJAGl1+JUeE2h HUiuX/ic05Fypco8EBZ/jMfze0nY4VbLhZuNnaQSCHz06QEzlWuv/MX0pswO8uTj0tYAn EBKc9mAnpql5jotY3tJyCyAF5TKqTgkJbepK/wln6NcOuuuAPnnCWCz9bqrfgGg15zYx1 PcUupxPA22xcSNKkY1HYJRdpKNr1oCqe1jxrfJl7AdJGls2HO4MvlERQevkRRXWEc0g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796217906; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Received:Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=JYQVqavuCfL5wFvo47NMU+wKB2fF1B1zjOz6Zqblh2o=; b=Sm1BIsILY+OjjhuxeA5c+Rx5gmxGsxwJ7vhZXd8OpZD2HTmsGAaqDTo1/Rd9AoiV48xT yWw64UV2N0wpiAGPksgcxUutuBfjuAzkZW4TnwO3AmKuyYB9Yd+qXDek27l6ENZlO51qM fWXzZgpPZ3g0k6q5xJCHst0wUeMkauWv075uxOMzgtIuCa8A8K6AVGVMpjy6g6ob2+7/s pwkLmJdQVytUMHBy7uU/cr9ykP8qx+OM4hEWuuAqFJudAYchzDzmQudCNepqQToN6dr77 A/6piddWOOqd5Us8D7/bqOYr0juRcqLjR8w8utduuP49ijWGhVPiutFMPOI32PLk7EQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass header.d=ziepe.ca header.i=@ziepe.ca header.a=rsa-sha256 header.s=google header.b=iGACzyWB; arc=none smtp.remote-ip=209.85.160.174 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DB44606A322 for ; Wed, 2 Dec 2026 13:25:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6DB44606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.a=rsa-sha256 header.s=google header.b=iGACzyWB Received: by mail-qt1-f174.google.com with SMTP id d75a77b69052e-536c8f958d7so99088591cf.1 for ; Wed, 02 Dec 2026 05:25:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1796217905; x=1796822705; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=JYQVqavuCfL5wFvo47NMU+wKB2fF1B1zjOz6Zqblh2o=; b=iGACzyWBokasSeCeVlY57unUpJY/2op6mKoeWAEn70TiijdOLnF6DWBVaaArUAa6hv qMHQQkakYpH6l1gijlGNr2JHQ7QWL7mwys4DuRoOkObs5+dVYWGasbFOpGO6ZRo0sfM2 lrvbtPNWYYWvxQpLPJoZZZjN+tqunOqCmjMHDdMn2ElS5jLgxAXm+6JBXlspICyTY3dm YfTHsG06jgf4lDoCjTG3c8a7o8CiTUaQ8WkmxrqfZdXTCfNifiZDFR9Sr3UZ0taPOB72 YgbNr6cd5qh7aZBLTYrb+gpZCfkqZvwRBfJ4OsjucwPFeHIb88ZGww72VmB10jCUiC40 iM8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796217905; x=1796822705; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=JYQVqavuCfL5wFvo47NMU+wKB2fF1B1zjOz6Zqblh2o=; b=t2yLYsLuYCGo2LkX6fpC+eGFjDfGVVIwJjGF0Irx2TTQflAwMIR9SFHO45jKjgj1Tp maNZC/9zIE3gPfXMpXhoeIKsYvVQ7JXzPXR497u30NGYMCd/fw4JDIHhBDjwNZsG/psp qwu0MF9DF92YfUfYWw5nVcU2GEVesqCci6FxasMhiUKO8QtJ7WQF+GVlQDYOMdl2VInO XvTbPHa9E8cieKVvIy3HiFXaaNIIATuED5k/V7qq677KrhvoYmlKajdnWkpI6XC8QYkb m+kn7oNQdnyOBY9lJ942Cbfp/HyU27BesmTWRwcfKOOptVXPFqe6ZZ+pmu2ppdZSuQNU Jfiw== X-Forwarded-Encrypted: i=1; AL+hErHFtvz1IljEOa/rZxG+kSyprG/Rb14Z01TJRwQNpXKShlNg1sanT7UNFZrYpTT5FLLJfPZYQt9wMH7NoQ==@vger.kernel.org X-Gm-Message-State: APuU4Z9qDoW1HskbxRzfcmI23K0Gq1cwc2euhvaPKOKDAoUSoZimlPku PUim0b48gtpoNz3s/aD8z/oYT4Zg1YHiLAhDVnFda0Bu8YTC0jNDcQAvIIXOP/r5xgY= X-Gm-Gg: AZFdTZcXibgaEn7+6scvj6nNEHelvpM0mIxjwzmd0Em9T+nZaG9d6RHNyvGqCuqIOIP G0+2wxa4mbRgsYvQRAp372AWbRiAZNdCILgcSBzGws7E0NOBRo4s3nsQE0ceBfChCnfsMCXbOQO RDII51D0972FJWlDdFpO2tI+vmMmyHvJzoxWJTcAspDXfXNz9rJwb6e8mYMDL0LTuvfdhhOIpPd XK2PJ/ipbXn2WmPJCGXtlsaDHY7luFodnE5N1XeoBOhtes27/Z1d9j17RmOP1lIkRoZQ+Xd1/R5 IC9pLcRGk7laKEFy+A2T2RMrO2EQA47VvjmNIbwwd5epM7LqlySzDddCyev/SLkhOp1fYVoIZ2E PUGR0WEDv1BAkcrmgHsG5ZP+CSdNyaembyQqyrlSXBjbj/b4ewBm99Zys/vUNPR+flyMnaT4Aii krjXruElMyO+LrLfwAagEC/tOr/OA1p6YV3NgBvS2TZEbvIvFyK9zePNUZX0vEQ80pvn2VKXqJ+ Oz7F4aIId1Tyr1NjvuKBtPxPSD0L5xYu5yUusW5WW3a1BJPTQ9u8So64dJv6cs2MNdPj9Di9hgf FTVsNw== X-Received: by 2002:a05:622a:428d:b0:55c:54f1:a9fa with SMTP id d75a77b69052e-55d769e7ea5mr761514001cf.30.1796217905063; Wed, 02 Dec 2026 05:25:05 -0800 (PST) Received: from ziepe.ca ([142.177.118.84]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-55da87b3ba8sm237044791cf.1.2026.12.02.05.25.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 05:25:04 -0800 (PST) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1xYkKV-00000003bBw-1j1e; Wed, 02 Dec 2026 09:25:03 -0400 Date: Wed, 2 Dec 2026 09:25:03 -0400 From: Jason Gunthorpe To: Dave Airlie Cc: Christian =?utf-8?B?S8O2bmln?= , Alistair Popple , Sumit Semwal , Thomas =?utf-8?Q?Hellstr=C3=B6m?= , Simona Vetter , Matthew Brost , Vivek Kasireddy , Dongwon Kim , Kevin Tian , Xu Yilun , Karl Mehltretter , Baolu Lu , Felix Kuehling , Alex Deucher , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, linux-rdma@vger.kernel.org, iommu@lists.linux.dev, Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , linux-nvme@lists.infradead.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Mina Almasry , netdev@vger.kernel.org, Alexey Kardashevskiy , zhipingz@meta.com, treding@nvidia.com, jhubbard@nvidia.com, chaitanyak@nvidia.com, Leon Romanovsky Subject: Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type Message-ID: <20261202132503.GD351887@ziepe.ca> References: <20f5fb10-b71a-40f9-bbb2-f99b4002bf08@amd.com> <53a32383-4cf6-42ac-bbd5-476e69a3be5f@amd.com> <20261202013043.GC351887@ziepe.ca> X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Wed, Dec 02, 2026 at 11:41:46AM +1000, Dave Airlie wrote: > On Wed, 2 Dec 2026 at 11:30, Jason Gunthorpe wrote: > > > > On Wed, Dec 02, 2026 at 10:47:28AM +1000, Dave Airlie wrote: > > > > > I think this is clearly where the divide is. I'm with Christian here, > > > the exporter allocate the resource, then it owns the lifetime of the > > > resource. In order for it to have complete ownership of the lifetime > > > of the resource it needs the ability to remove the resource from other > > > users (i.e. importers). If the exporter wasn't to free some pages, it > > > should have all the information necessary to do so but traversing a > > > list of places the object has been imported and a method to forcible > > > unlink it from that side. > > > > If you change iommu mappings without telling the driver you will > > create data corruption as new mappings can fall to places the device > > is still doing DMA. > > > > The driver MUST be involved in any reclaim/move/revoke process and > > DMABUF already has APIs for that. Managing this lifetime is one of the > > main things it does. > > > > I don't like this notion we can trust one side more than the other, it > > isn't like the exporter drivers are amazing clean things either. There > > is a reasonable level of nannying.. > > This isn't just about trust, it's about lifetime and ownership. If the > exporter owns the resource, the exporter should have all necessary > information to invalidate the resource and give it back to the system. Importers own their DMA mappings and are the only things that should ever be touching them. That is the way we expect DMA APIU to be used, it is why Rust has the DMA API wrapped with the bound driver concept. It is an extremely abnormal lifetime to suggest that some driver should be operating the DMA API of someone elses device. I don't agree at all that having exporters operating the DMA API of importer devices makes any sense from a kernel lifetime perspective. > > Importers are expected to unmap. I think we have to consider any one > > that doesn't to be broken. You can't fix broken with more broken > > things like force DMA unmapping and hoping that there is an iommu, > > then hoping no corruption happens to crash the system. > > But we should allow the exporter to tell the imported to invalidate, > wait for a response and then have the exporter free it. We have that already. > What the importer does in the invalidate is up to it, but the > exporter controls the resource lifetime and any things bound to > it. Once the exporter asks for it to be invalidated it gets to assume nothing is touching it anymore. There is no reason for it to operate the DMA API of another driver, and doing so doesn't give more protections or a better life time design. > If the importer fails to invalidate the resource then that is a > clear problem. But an exporter can at least control all the mappings > for the resource and tear them down without leaking things. It really can't. Without an iommu the dma unmap does nothing. If you unmap while DMA is still running you risk random corruption from future maps. Choosing to unmap without synchronizing in the HW is an extreme dangerous action, and IMHO, accepting this buggy choice should be in side the driver that is doing it, not hidden in layers of software. > > I just saw someone in drivers/media do the most insane thing with the > > new DMA API, unbelievable. No matter what we build someone will find a > > creative way to abuse it. > > > > We need to have a 3rd party "Switzerland" if you want to keep this > > direction that limits the exposure of either side to the details. > > If I had rust for this I'd be happier, but we don't get a > switzerland, Why not? This thread had several offers of some kind of dmabuf related mapping library whatever you want to call it. That's a fine Switzerland. > but we should at least be speaking in terms of ownership and lifetime > of resources and what can reasonable be defended against. IMHO most of the problem here is the push to make unreasonable and difficult design choices because we have to defend against other drivers in the kernel. While somehow, against all reason, insisting that the exporting DRM drivers should be given the most sensitive access of everything. > Okay maybe on that one we can give in, I do think path + offset/length > lists might make sense for things like NVLINK/UALINK though were there > is more arbitrary path to the resource than just what is CPU > visible, I think UALINK type devices you want a VRAM offset relative to the end point. That gets converted into a fabric address through the fabric mapping hardware. > but maybe dma_addr_t can encapsulate that, but for some things it No. Do not abuse dma_addr_t for things that do not come from the DMA API, I think this has been said many times over the years. :( > > Even the P2P permitted placement selection shouldn't be open coded in > > drivers, this is a bit tricky to do well and none of the DRM drivers > > get there. > > Because nobody has written the code to do it? Lack of abstractions in dmabuf to help manage all of this, IMHO. > > FWIW it is a huge pita to make things work like this inside iommufd > > and if it gets messed up then iommufd will explode in a bad way. > > It is so much easier to feed through phys_addr_t since we already have > > this infrastructure. > > It's easier, but you don't respect lifetimes then. Ridiculous. iommufd can be trusted to honor the existing invalidate callback. Far more than we can trust a random DRM driver to operate the iommu API correctly. It is completely lifetime inappropriate for any other drivers to be reaching into the iommu_domain object entirely and fully controlled by iommufd. It breaks the encapsulation, complicates the code, and invites creative abuses from the GPU drivers. Do not use lifetimes as a justification for this backwards design. Jason