From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796214623; b=u+MbJVynasGJ8BBNliMUtF3jR1gpNJWZo6keYwm3wCquHz9mx1f6Pi25VxEwznK9GtEU 5R9LZWoy1kYg2MBCosGluU7t2rd+F85XAth7V5UlDOuUOGOo+YjdJi1cmoaa9+im3G0UF 8N8nlJANsCKphcLkUimU5kZ3uh20QksbUfT5dCS5BFCoKThMgxYzuqN5s8zAJ+WzPqJDJ T8otWjQ43PR5bp1o6Qp/6/O7ABvk8iJGK4fimqHqhFhxuRoKvdOww/JisnicPxN841/US sc8WXS60boGY3tBAJT/QrBP406pUi6Rf0AX9Xwjlx3oWKg/E9ihLqhEpzX1I8dS1Jqw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796214623; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=YnjgPWRaA/pKKIFiTO20y8q8PK08m+xa8uO+Ozj7yrY=; b=xEB2jpAwGVTb/HbpIgWsc+ZOPhgDo8Ur+4cKSZMA/2fAae0V0ECif2Qfz9yzq66svLMN cx/Z4Sfc1X+76VoP3cG7a3sIV5bhHX67lgoycUvxnojknUdMZn32lH4evBQ6mY54mwc6v YCT2wOXIa0nDV2IjZhFP3lG55KRU5ShEtKYEkEzhKfx+RA9qP+0+tPYTlKz5K41McoPO0 J7fOR3HpTH3R2hY6yRZ8LWw7QpIzMphy+cauSH4zLUXCqYa9VsxYY1zm4cjjDSe7pfkru sAvGtzPMGsHT71B4A5oydZzbtPX5r0bKlbXPBzHBEh2HIhnsUT5WzI25A5HE75NVccA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NMUOj3u8; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE2A8606A31A; Wed, 2 Dec 2026 12:30:23 +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: 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-Mailing-List: kvm@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: <20261201-dmabuf_shared_buf_v1_xe_rc5-v1-2-b672717c7fc9@nvidia.com> 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; > + } > + }