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 1CDF1606A331 for ; Wed, 2 Dec 2026 12:30:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NMUOj3u8 Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D3ACA11219D; Wed, 2 Dec 2026 12:30:29 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id A7A2911219E; Wed, 2 Dec 2026 12:30:23 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 740AC437DE; Wed, 2 Dec 2026 12:30:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0CC3A1F000C1; Wed, 2 Dec 2026 12:30:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796214623; bh=YnjgPWRaA/pKKIFiTO20y8q8PK08m+xa8uO+Ozj7yrY=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=NMUOj3u8WAGlsJcPEOV30d1HD0C2M7vYVlgxo3Gmw044ySX7gnlYY2VtXwCS/lWZQ 0NFe9YzDOw7c6P0O+d2OrpcLpHCebGtKtdH2w+Rk/wlXOOHdo+kUiby1H26/yoHQM5 kszSkalsENxwL9a8GQWDLu/skObl5nYMdlTmYXza8od2xb+hHaFj9p4rY+gT/0X66J zb/Etck/tEnRMRCnD/NkrzklykvytNX4PSsybRHhvsc/1whFEItian/I6JMUt6KAoG wvOssWFWfdBJkPWfcZyqmbsho5Npk6Vo2tVAUJPAaCFdtPIsQosT8wv+QOKYpQFM0X n06LQT3Bwba1A== Date: Wed, 2 Dec 2026 14:30:18 +0200 From: Leon Romanovsky To: Alistair Popple Cc: Karol Wachowski , Sumit Semwal , Christian =?iso-8859-1?Q?K=F6nig?= , Philipp Stanner , David Airlie , Simona Vetter , Rodrigo Vivi , Matthew Brost , Thomas =?iso-8859-1?Q?Hellstr=F6m?= , Jason Gunthorpe , Kees Cook , "Gustavo A. R. Silva" , Alex Williamson , Kevin Tian , "Joerg Roedel (AMD)" , Will Deacon , Robin Murphy , dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, intel-xe@lists.freedesktop.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, kvm@vger.kernel.org, iommu@lists.linux.dev, Alexey Kardashevskiy , Mina Almasry , Baolu Lu , chaitanyak@nvidia.com, Dongwon Kim , Felix Kuehling , jhubbard@nvidia.com, Karl Mehltretter , Vivek Kasireddy , Xu Yilun , zhipingz@meta.com Subject: Re: [PATCH RFC 02/16] dma-shared-buf: Add struct dma_shared_buf Message-ID: <20261202123018.GM31440@unreal> References: <20261201-dmabuf_shared_buf_v1_xe_rc5-v1-0-b672717c7fc9@nvidia.com> <20261201-dmabuf_shared_buf_v1_xe_rc5-v1-2-b672717c7fc9@nvidia.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261201-dmabuf_shared_buf_v1_xe_rc5-v1-2-b672717c7fc9@nvidia.com> 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=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham 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 Tue, Dec 01, 2026 at 06:06:18PM +1100, Alistair Popple wrote: > Currently the sg_table is used by dma-buf exporters to describe the > range of physical addresses to map to the DMA API. This is then passed > directly back to importers. > > This is problematic for a number of reasons. It exposes exporter side > information to importers and doesn't have the capability to describe > memory that isn't backed by struct page which is what MMIO such as PCI > BAR needs. > > Add the dma-shared-buf as a library to handle this. A new type to > replace the exporter's sg_table, struct dma_shared_buf, is added > to describe a range of physical regions for mapping by the library. > dma_shared_buf_map() can then be used to map this for a particular > device. > > The mapping function handles either direct P2P mappings using the PCI > peer-to-peer core if a p2pdma provider is listed, or system memory > otherwise. This allows dma-buf exporters to use common logic to > create mappings instead of open-coding it which is hard to get right, > especially for P2P cases with complex routing and IOMMU requirements. > > This is kept in a file of its own as none of it depends on a DMA-buf and > it could be a library elsewhere. > > Signed-off-by: Alistair Popple > > --- > > This is supposed to be used as a library for dma-buf exporters/importers > so could be moved. I don't love the name so happy for suggestions or > alternatives. > --- > MAINTAINERS | 1 + > drivers/dma-buf/Makefile | 3 +- > drivers/dma-buf/dma-shared-buf.c | 138 +++++++++++++++++++++++++++++++++++++++ > include/linux/dma-shared-buf.h | 77 ++++++++++++++++++++++ > 4 files changed, 218 insertions(+), 1 deletion(-) <...> > + if (shared_buf->provider) { > + addrs->attrs |= DMA_ATTR_MMIO; The patch looks good to me. I have just one nit: Please move this assignment under PCI_P2PDMA_MAP_THRU_HOST_BRIDGE, since it does not apply to the PCI_P2PDMA_MAP_BUS_ADDR case. Thanks > + switch (pci_p2pdma_map_type(shared_buf->provider, dev)) { > + case PCI_P2PDMA_MAP_BUS_ADDR: > + for (i = 0; i < shared_buf->nr_ranges; i++) { > + const struct phys_vec *vec = > + &shared_buf->ranges[i]; > + > + addrs->ranges[i].addr = > + pci_p2pdma_bus_addr_map(shared_buf->provider, > + vec->paddr); > + addrs->ranges[i].len = vec->len; > + } > + addrs->bus_addr = true; > + return addrs; > + case PCI_P2PDMA_MAP_THRU_HOST_BRIDGE: > + break; > + default: > + ret = -EINVAL; > + goto err_free; > + } > + }