]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
PCI/P2PDMA: Simplify bus address mapping API
authorLeon Romanovsky <leonro@nvidia.com>
Thu, 20 Nov 2025 09:28:21 +0000 (11:28 +0200)
committerAlex Williamson <alex@shazbot.org>
Thu, 20 Nov 2025 19:01:41 +0000 (12:01 -0700)
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.

Tested-by: Alex Mastro <amastro@fb.com>
Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Acked-by: Ankit Agrawal <ankita@nvidia.com>
Link: https://lore.kernel.org/r/20251120-dmabuf-vfio-v9-2-d7f71607f371@nvidia.com
Signed-off-by: Alex Williamson <alex@shazbot.org>
block/blk-mq-dma.c
drivers/iommu/dma-iommu.c
include/linux/pci-p2pdma.h
kernel/dma/direct.c
mm/hmm.c

index 449950029872a0c583accfb4a62fe26c5cda9e29..a1b623744b2f3f3c5c5a23f6300ace518b4c1749 100644 (file)
@@ -85,7 +85,7 @@ static inline bool blk_can_dma_map_iova(struct request *req,
 
 static bool blk_dma_map_bus(struct blk_dma_iter *iter, struct phys_vec *vec)
 {
-       iter->addr = pci_p2pdma_bus_addr_map(&iter->p2pdma, vec->paddr);
+       iter->addr = pci_p2pdma_bus_addr_map(iter->p2pdma.mem, vec->paddr);
        iter->len = vec->len;
        return true;
 }
index 7944a3af4545e68664b06a819509a94f7c4de39a..e52d19d2e8334d567958d50a111f83903d5dfab4 100644 (file)
@@ -1439,8 +1439,8 @@ int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
                         * as a bus address, __finalise_sg() will copy the dma
                         * address into the output segment.
                         */
-                       s->dma_address = pci_p2pdma_bus_addr_map(&p2pdma_state,
-                                               sg_phys(s));
+                       s->dma_address = pci_p2pdma_bus_addr_map(
+                               p2pdma_state.mem, sg_phys(s));
                        sg_dma_len(s) = sg->length;
                        sg_dma_mark_bus_address(s);
                        continue;
index 1400f3ad429949addfe32186c3fc1da76fd30e46..9516ef97b17ac576ff4482c3e256b541c50c36a9 100644 (file)
@@ -181,16 +181,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 paddr)
+pci_p2pdma_bus_addr_map(struct p2pdma_provider *provider, phys_addr_t paddr)
 {
-       WARN_ON_ONCE(state->map != PCI_P2PDMA_MAP_BUS_ADDR);
-       return paddr + state->mem->bus_offset;
+       return paddr + provider->bus_offset;
 }
 
 #endif /* _LINUX_PCI_P2P_H */
index 1f9ee97594269cf83d90cc07d83a114cb7600d67..d8b3dfc598b22ab699e30d0310bd4eb32703a135 100644 (file)
@@ -479,8 +479,8 @@ int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
                        }
                        break;
                case PCI_P2PDMA_MAP_BUS_ADDR:
-                       sg->dma_address = pci_p2pdma_bus_addr_map(&p2pdma_state,
-                                       sg_phys(sg));
+                       sg->dma_address = pci_p2pdma_bus_addr_map(
+                               p2pdma_state.mem, sg_phys(sg));
                        sg_dma_mark_bus_address(sg);
                        continue;
                default:
index 87562914670a1f86634de6745433e434f3d56d74..9bf0b831a0296c3bcaf876542624dc7928cf1045 100644 (file)
--- a/mm/hmm.c
+++ b/mm/hmm.c
@@ -811,7 +811,7 @@ dma_addr_t hmm_dma_map_pfn(struct device *dev, struct hmm_dma_map *map,
                break;
        case PCI_P2PDMA_MAP_BUS_ADDR:
                pfns[idx] |= 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;
        }