From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07EA0606A69A for ; Mon, 30 Nov 2026 11:52:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=maGw3pyk Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C100F10EF12; Mon, 30 Nov 2026 11:52:34 +0000 (UTC) Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazon11010045.outbound.protection.outlook.com [52.101.61.45]) by gabe.freedesktop.org (Postfix) with ESMTPS id D800810EF0C; Mon, 30 Nov 2026 11:52:28 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rKrWyHcyM8BK6Decnd6elUUQAvn6qsoamvISUSUft0jjWz9dVPpxLq1DuL12pXPpX8qn7+y4SAckWZZQ3JIsnh/M0PJuSngVgL8lPLQ3WmY8XIkYWNXZdvOg88NjCgpPv30yzca2hBYy0DeIVJWLI+fjDNEF4ZvUnVNeO8GE/RsXhkvqVB5+ZMqr0x6TMTccTeiDfg3hop2QCDL8jUlkNZnXBKKPMdlwuo3xM7dnop8ehXjogJnI4jCRo3J48jk9w05FK7uq2iz1X2Vd8rxNxJObtMrizsEMbituj031W3S1wh31nhxuup1FDBctkBUnCrrp8hJ6uA/57moHYkfChA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3cA2Wg3K922DnmTZtHLmlM+W0AQ7HVvIheybVaadsOw=; b=deHK7Ysm/SpToI+seHa7FGMn64RevkukZI0QNSwW7B+3JKvZbzCEJ0i/+NOk+x7/pAjW+Fv6MpFeZ1rNQSdcBqm2sy/Sa7a8D4egSK59W5SqMrbPOm9paLXqZOx2TtOUVdCpw8DzQiPJhX2j9jT0mufJzLHY26vpo+vaqLJApMkomKGgCjr5qyWGnkxuH8dMdKEp2eYgAmnt7dgbyhxFZBvqRSUJd6P0/jxtRnLRJp+Wb0EDYwjUO4rW1WPIWgKeLAyjhZS7yjS2EaNQOWxS/Yqg+y7fNnTQoyRsm1p3xpSqIHa1LjHLvsVOhgTl2ENA8xnPp76OCld2wjeT0SinQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3cA2Wg3K922DnmTZtHLmlM+W0AQ7HVvIheybVaadsOw=; b=maGw3pykodyE0sAVn/PQjeJLv7L1xlDUVK1Br9JAfPdUEujdPx92IkCFGP6VWKU85qvyUbw1VWlmVm6FrVayhFsi4aCBRXdXmgOrLJ+LU1S5eVKSzOxCkmnCW1exf9jxK/H79fGzWGg8g3PGOpDTDtZ+WtxYRyRdJ9430OUiv87QumL7acPv8bSrPVliQbCR1ve9V9F/iDp/CDwfcHpzJHIg48crV+KrdL7H8LPKCw6NSJv2DXs38kK7upLc8c0/FqFq3wG0vjzI2whZ/1fSxmUFPoaQIraU+DaUV9KByDEyEZlUzLXWw8lGA4inMes2gdc9lpah9USdO9Wi7GkJUQ== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from SA3PR12MB598757.namprd12.prod.outlook.com (2603:10b6:806:52d::14) by CH3PR12MB504971.namprd12.prod.outlook.com (2603:10b6:610:34a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.13; Mon, 30 Nov 2026 11:52:21 +0000 Received: from SA3PR12MB598757.namprd12.prod.outlook.com ([fe80::e206:100:5946:a777]) by SA3PR12MB598757.namprd12.prod.outlook.com ([fe80::e206:100:5946:a777%5]) with mapi id 15.21.0662.007; Mon, 30 Nov 2026 11:52:21 +0000 Date: Mon, 30 Nov 2026 22:52:15 +1100 From: Alistair Popple To: Christian =?utf-8?B?S8O2bmln?= Cc: Jason Gunthorpe , Dave Airlie , 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: References: <20261120-dma_mapping_type_v4-v3-3-c0183a409bdf@nvidia.com> <20261123165716.GM179082@ziepe.ca> <7ac7edd0-5c38-440a-b26a-21bcbb6f4702@amd.com> <63eb7b6e-e0a8-4443-a434-0301ed59beae@amd.com> <79d62f9a-cea8-4149-a673-7ef86942410d@amd.com> <20261127125753.GS246011@ziepe.ca> Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-ClientProxiedBy: SY4P282CA0012.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:a0::22) To SA3PR12MB598757.namprd12.prod.outlook.com (2603:10b6:806:52d::14) X-Archived-By: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA3PR12MB598757:EE_|CH3PR12MB504971:EE_ X-MS-Office365-Filtering-Correlation-Id: 979314c7-9e09-49f7-4db4-08df4ed86419 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|7416014|376014|1800799024|366016|23010399003|4143699003|11063799006|261009223027099003|22082099003|18002099003|3023799007|10067099003|56012099006|261102130727099003|261028144727099003|261026121527099003|261026140227099003|261022105027099003|261022075727099003|261102123227099003|261021121427099003|261021135927099003; X-Microsoft-Antispam-Message-Info: 3PCP/5P9s4cQS7WKNnAF9D4dNwC6aG2D2fw/A0h/oafKIIG3Xpc3MmMu8XS7D1p4/5eRwEY7rmon8pxrRZuiaE6vxeOYXy6k4dULw+YwyaiN4Baazlu6zXnV6tcsHrrFZfYlmezSs10ISu7lJWwZmM/5LLaN5PZjq//LkD3ii7mZHEKjiDYGQ2rrDwKRDrmreEgZDjHkeIUHz1ub63RMgA5rfFCB/V4aKUk8W/5dNeDt1laUhfWyJamqPL+B+qTzkH0/O54Wq8FmRe/6I//51VzncMoEJRQsBowkMypq5M6tEIEU7Xk1olUtdQc1K4m1uYZDmcrVAYaAjpS5arAYkpsntP5wL5Yj60g6XTquIG2V2gg+7xxWetK8u+FAP6/jXamYVc81elcNjTiyVBXXmOzrwUzZcL2Tj+q4MK/Ey/YzY7HY26GlgmgNTRz/L4DVmK6XxStE/8BCmpaZDUjT1bNGLsMVI9w6c3oIL88vgPspqTIFtIjnkQllMuy+SdXVOm2qFJwsKfE8+ZiAF29xokTpI3oRZDBeCKRqO3cnw7n02/0iH+1E5jwSetzpwzABOyD9iuNQcqfikRPt/56PrE5DSgaayZTjS9dYEji9jP6AgNlNCKtADmyhiadTe8011geceSXhfYb/dDQtLmdwpGuAwRagsbD8nxE7EEGFLz0= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SA3PR12MB598757.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(7416014)(376014)(1800799024)(366016)(23010399003)(4143699003)(11063799006)(261009223027099003)(22082099003)(18002099003)(3023799007)(10067099003)(56012099006)(261102130727099003)(261028144727099003)(261026121527099003)(261026140227099003)(261022105027099003)(261022075727099003)(261102123227099003)(261021121427099003)(261021135927099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?hxbCTq7ENgBWULPZHGpV2TLB55w1yEYfkw465TCXj9x31vpKhc/4xjIgqp?= =?iso-8859-1?Q?ntk011favCtyYvlki0c20OXhbiTusgdi5WqysQy/5jSI7lP3f1SFkazJSi?= =?iso-8859-1?Q?5taNClM3Vqc4VVrdA59IZkYwLbgLoAEULxfU8ec/NVHJdTfAbqoI0+NvI/?= =?iso-8859-1?Q?qLhD8JZhPUePr/DjfIMdVTb2lqfq9pk7EdKTtQeiKR0ru2mALcJpUM48hS?= =?iso-8859-1?Q?Ya98UpTQf0Osmx0sB3sE6gt/7w3TiUL5RDsCwsrx0uMKBNJsk5pgOT9y1S?= =?iso-8859-1?Q?g1N1YlO/43U2CBW2zNTm/yamUmaDbaRHb7grEekupTuM5+5Rxw3pgDIwsg?= =?iso-8859-1?Q?09CtQmx6qoRBkMb7tQc12jT71jW17cUkyDXfqJiPgXvKsbkGypOtADPfp5?= =?iso-8859-1?Q?H5I9WIXbfYKj00fq01yDEKgW5RJPNF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1cDirRZovtEaj1v8WbEwJeNtvGJmP4oIDM11tYUoZcMABqwZMv4c4pQBo?= =?iso-8859-1?Q?L9ip6FcfIUFBswzGPTztae7Yy1PD6iX7yw/Kq+fBlN3WjFr/pNo9thmbeK?= =?iso-8859-1?Q?j1vNGzf4z+Y9w1MIKEGN/L2IN71G4pbt8KNqd91t/47jOU9BEUOt2ncexb?= =?iso-8859-1?Q?saI9zpT/qEMaIX2RR7VyGkBAc+YXDyxZ1ng05dqk7j7HrHmxJhRhMOhini?= =?iso-8859-1?Q?MhIH/BNngLx5YefhjcKUEwp2iOPFPE9vxMep6AvHlHeTHqBaY9qjiaKZF5?= =?iso-8859-1?Q?3qEEa/i5cheWYwjkagxTrSVJx1/3FwdJsjasvZlkT4vSKhkExGzsQsxXxz?= =?iso-8859-1?Q?xET4pqpgC2ye54M0rUwr2quyaux2LpqD+fQ6FTiNG0htj7NEion8FXMW0W?= =?iso-8859-1?Q?eNSrbsyoQSaCMtT2xmIwjZ8Z51yNL9DOcy0r8awFp+a6fhN7iz07le83rK?= =?iso-8859-1?Q?pnQQVY/0rw=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 979314c7-9e09-49f7-4db4-08df4ed86419 X-MS-Exchange-CrossTenant-AuthSource: SA3PR12MB598757.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2026 11:52:21.1641 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: z/MDWsQAxpw4apszU2wO6fgcTfUhIwXwspz5RCBbngMBfygIGcZekUTU5eMfmlQX3EEQWa3QjSemVP1+h1jfkA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB504971 X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Intel-xe" X-Spam-Status: No, score=-3.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On 2026-11-28 at 00:44 +1100, Christian König wrote... > On 11/27/26 13:57, Jason Gunthorpe wrote: > > On Fri, Nov 27, 2026 at 09:04:15AM +0100, Christian König wrote: > > > >> If we somehow prevent the CPU physical address from being casted to > >> a struct page and/or used with vmf_insert_pfn/page/dma_map_page > >> etc.. then there is not much of a problem with passing around > >> physical addresses. > > > > I already offered that in v1 of the series using limits on > > EXPORT_SYMBOL and you NAK'd it too. > > Yes, because I think that this is not sufficient to prevent importers from doing nasty things. > > >>> If we need to shared object backings and have clearly typed and > >>> negotiated on what the backing contains then we should allow it. > >>> However I mostly agree on the mapping thing, I'd want drivers to > >>> negotiate and natively support whatever backings they can rather than > >>> having an intermediate trying to handle the conversions Not saying the > >> > >> Yes, exactly that's my concern as well. We need to avoid this middle > >> layer trap. > > > > You avoid middle layers by having reasonable subsystem helpers for > > things to use to build their stuff, especially to encapsulate common > > patterns. These helpers are part of the subsystem, or in a related > > subysstem helper library. > > > > In Linux terms middle layer almost always means something wrapping a > > function pointer callback into a driver and enforcing specific actions > > on top of that. The recommended counter is to have the driver perform > > the actions with helpers and not wrapper the ops. It particularly came > > from the block world where they stuck something like SCSI after the > > block ops but before the driver. > > > > It is hard to see that DMABUF is anywhere close to a middle layer. > > > > This is also why we don't understand your remarks about > > dma_buf_phys_vec_to_sgt(). Of course it belongs in dmabuf, it produces > > the dmabuf spec'd mangled scatterlist that only dmabuf uses. Where > > else would you put this code? > > No, that doesn't even remotely belong to DMA-buf. > > What could be done inside DMA-buf is converting dma-addr[] and SGT. Because we need that for backward compatibility. > > But creating the DMA addresses from the physical addresses is low level DMA API and is not a task the DMA-buf framework should fulfill. > > Again: DMA-buf is just the utility which allows importers and exporters to exchange information how to access a buffer. > > >>> code doing the conversions can't be a helper, bit it shouldn't ever be > >>> autoamtic or outside driver control. > > > > I think you do want it automatic, if an exporter is new and makes, > > say, a dma_addr_t[] and the importer is old and wants a sgt, why > > should we be open coding anything in every driver to deal with this? > > We shouldn't. That is not what I'm suggesting. > > > You can argue if it is automatic because the driver called a very > > general helper or automatic because the helper is wrapping a callback, > > but that should be a fairly minor quibble not a huge thread full of > > NAKs. > > > > Ultimately DMABUF has a fairly simple flow: > > 1) Allow importer/exporter to negotiate what kind of interconnect > > they want to use (PCI, ualink, etc) > > 2) Give the exporter enough information about the interconect path to > > make a placement decision > > 3) Describe the exporter's buffer so any mappings/translation/etc can > > be setup for the importer > > 4) Program the importers HW. > > > > Many of these have very common patterns, like PCI GPUs always make the > > same kind of VRAM placement decision in #2 based on P2P support. > > > > This should all be in helpers under the dmabuf umbrella and not open coded. > > Well I completely agree that this shouldn't be open coded in drivers, but it also doesn't belong into DMA-buf. > > DMA-buf is just the utility which allows you to communicate the parameters and the result of the mapping/translation back and forth between importer and exporter. > > DMA-buf is not and should not be involved in creating the actually mapping, that is the job of a low level DMA API. The problem is I can't figure out how to build that low level API. The current low level DMA API can't correctly handle PCIe P2P, or IOMMUFD, or the KVM/confidential compute use-cases (I'm less familiar with those). It can only handle creating a DMA mapping for system memory for a specific importing device. So I assume you are talking about some new API. Following Dave's lead lets call that shared_buf_map(). That would need to take some importing device context so that it could dispatch to the correct mapping code and a list of physical locations the exporter needs mapped. At a high level something like: struct dma_addr_list *shared_buf_map(import_context, location_list); Where the import_context is some importer specific struct opaque to the exporter and the location list is a list of either PCIe MMIO or system RAM physical addresses. Every exporter ->map_dma_buf() should call shared_buf_map() instead of open-coding their own mapping code, as I think we all agree we don't want that open-coded. Placement selection can be dealt with as a separate topic, so setting that aside means passing in the same location list regardless of importing device. shared_buf_map() then has to dispatch to the correct mapping generation code - either DMA API, PCIe peer-to-peer API, IOMMUFD API, KVM API or maybe some other importing device/driver specific API. I could see how that could be made to work, but it seems more complex than a dma_buf exporter op that returns a list of physical locations and a helper library that importers call to do the mapping into whatever importer specific context is needed. Instead you would have to add importer specific callbacks that the shared_buf_map code could call along with plumbing the importer context through. - Alistair > Christian. > > > > > Jason >