From nobody Mon Oct 6 10:05:48 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 662ED2E7629; Wed, 23 Jul 2025 13:02:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753275724; cv=none; b=lClwl8iBpTTEfZ0acJF2nPcj6g8hZVdDHtAUmoP2b85uairAPz1GnMOEhQmGgLKoDKQRCDOAwIqeIJhSgEaNfUu4mibN6N5iInUNnx7yHjcg/HLVGwqvyOJ81MmKQlpQjT7FzkcvgCnuR55+z9NLayBp3TE6PQKlfKRpLIP5XgA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753275724; c=relaxed/simple; bh=uuCb+V2zNc5XSrBnwxrMawyQmHST6eRwzZ5HxKmtUAU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KJJGILTG+u3bs3pa9l7K4luxWcZ9yo7srh25CGl7/Qj71+/TNPNEsB/tTSK8CgUsJfYWK5ba0bsFDfsTw/SPppaN5Y4jUOo48ZVPRcFvhumuoELQ3uhb+N/hs2yyflVO+UI9r/Qnn4CDuo0GUzVmFaHV8NkeMvCaur0kG6Y/DO0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CMXvNedL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CMXvNedL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D21EC4CEF5; Wed, 23 Jul 2025 13:02:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753275724; bh=uuCb+V2zNc5XSrBnwxrMawyQmHST6eRwzZ5HxKmtUAU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CMXvNedLSRoRNIwJaHFwymWQJoLQyy5HeCJn+iVUJAlK00FGokYtqVBrXV4haQEzj 4iM1gvpoEs6p9cZdfKk01lySbx1k78BYRLrfwsTbzRoWU+Q+XH+Qd9DgCFFmNzMZs5 L4oDttcRXsp/Ta90c0k8VhrbYHR9/CeOaCy2K7cOOav1SR+AaaCAhZ8YMlUBM1+C3G YmlkbaQZzVl0iP3yUEOECQOLzv8Tu8kLt0j1LO5zFl7MasnoEyvYAVwA7owgkFzqoV AkQjTLVdtMNW/QuID+PRdNgGe47BkgzJUFzNMwQOk/GEInoTws1TVgMkin8/vgBYB5 3BbS2oJqswGwA== From: Leon Romanovsky To: Alex Williamson Cc: Leon Romanovsky , Christoph Hellwig , Jason Gunthorpe , Andrew Morton , Bjorn Helgaas , =?UTF-8?q?Christian=20K=C3=B6nig?= , dri-devel@lists.freedesktop.org, iommu@lists.linux.dev, Jens Axboe , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Joerg Roedel , kvm@vger.kernel.org, linaro-mm-sig@lists.linaro.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org, Logan Gunthorpe , Marek Szyprowski , Robin Murphy , Sumit Semwal , Vivek Kasireddy , Will Deacon Subject: [PATCH 03/10] PCI/P2PDMA: Simplify bus address mapping API Date: Wed, 23 Jul 2025 16:00:04 +0300 Message-ID: <30640b5e4ec975f928e685b92aaaf3e2e5e08f72.1753274085.git.leonro@nvidia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Leon Romanovsky Update the pci_p2pdma_bus_addr_map() function to take a direct pointer to the p2pdma_provider structure instead of the pci_p2pdma_map_state. This simplifies the API by removing the need for callers to extract the provider from the state structure. The change updates all callers across the kernel (block layer, IOMMU, DMA direct, and HMM) to pass the provider pointer directly, making the code more explicit and reducing unnecessary indirection. This also removes the runtime warning check since callers now have direct control over which provider they use. Signed-off-by: Leon Romanovsky --- block/blk-mq-dma.c | 2 +- drivers/iommu/dma-iommu.c | 4 ++-- include/linux/pci-p2pdma.h | 7 +++---- kernel/dma/direct.c | 4 ++-- mm/hmm.c | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/block/blk-mq-dma.c b/block/blk-mq-dma.c index 37e2142be4f7d..eeac653e3f3bd 100644 --- a/block/blk-mq-dma.c +++ b/block/blk-mq-dma.c @@ -79,7 +79,7 @@ static inline bool blk_can_dma_map_iova(struct request *r= eq, =20 static bool blk_dma_map_bus(struct blk_dma_iter *iter, struct phys_vec *ve= c) { - iter->addr =3D pci_p2pdma_bus_addr_map(&iter->p2pdma, vec->paddr); + iter->addr =3D pci_p2pdma_bus_addr_map(iter->p2pdma.mem, vec->paddr); iter->len =3D vec->len; return true; } diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index cd4bc22efa966..1853a969e1978 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -1427,8 +1427,8 @@ int iommu_dma_map_sg(struct device *dev, struct scatt= erlist *sg, int nents, * as a bus address, __finalise_sg() will copy the dma * address into the output segment. */ - s->dma_address =3D pci_p2pdma_bus_addr_map(&p2pdma_state, - sg_phys(s)); + s->dma_address =3D pci_p2pdma_bus_addr_map( + p2pdma_state.mem, sg_phys(s)); sg_dma_len(s) =3D sg->length; sg_dma_mark_bus_address(s); continue; diff --git a/include/linux/pci-p2pdma.h b/include/linux/pci-p2pdma.h index 27a2c399f47da..eef96636c67e6 100644 --- a/include/linux/pci-p2pdma.h +++ b/include/linux/pci-p2pdma.h @@ -186,16 +186,15 @@ pci_p2pdma_state(struct pci_p2pdma_map_state *state, = struct device *dev, /** * pci_p2pdma_bus_addr_map - Translate a physical address to a bus address * for a PCI_P2PDMA_MAP_BUS_ADDR transfer. - * @state: P2P state structure + * @provider: P2P provider structure * @paddr: physical address to map * * Map a physically contiguous PCI_P2PDMA_MAP_BUS_ADDR transfer. */ static inline dma_addr_t -pci_p2pdma_bus_addr_map(struct pci_p2pdma_map_state *state, phys_addr_t pa= ddr) +pci_p2pdma_bus_addr_map(struct p2pdma_provider *provider, phys_addr_t padd= r) { - WARN_ON_ONCE(state->map !=3D PCI_P2PDMA_MAP_BUS_ADDR); - return paddr + state->mem->bus_offset; + return paddr + provider->bus_offset; } =20 #endif /* _LINUX_PCI_P2P_H */ diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index fa75e30700730..de34ee5903766 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -484,8 +484,8 @@ int dma_direct_map_sg(struct device *dev, struct scatte= rlist *sgl, int nents, } break; case PCI_P2PDMA_MAP_BUS_ADDR: - sg->dma_address =3D pci_p2pdma_bus_addr_map(&p2pdma_state, - sg_phys(sg)); + sg->dma_address =3D pci_p2pdma_bus_addr_map( + p2pdma_state.mem, sg_phys(sg)); sg_dma_mark_bus_address(sg); continue; default: diff --git a/mm/hmm.c b/mm/hmm.c index 9354fae3ae06f..f9970b0e527ed 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -755,7 +755,7 @@ dma_addr_t hmm_dma_map_pfn(struct device *dev, struct h= mm_dma_map *map, break; case PCI_P2PDMA_MAP_BUS_ADDR: pfns[idx] |=3D HMM_PFN_P2PDMA_BUS | HMM_PFN_DMA_MAPPED; - return pci_p2pdma_bus_addr_map(p2pdma_state, paddr); + return pci_p2pdma_bus_addr_map(p2pdma_state->mem, paddr); default: return DMA_MAPPING_ERROR; } --=20 2.50.1