Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

PCI/P2PDMA: Simplify bus address mapping API

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>

authored by

Leon Romanovsky and committed by
Alex Williamson
d4504262 f58ef9d1

+9 -10
+1 -1
block/blk-mq-dma.c
··· 85 85 86 86 static bool blk_dma_map_bus(struct blk_dma_iter *iter, struct phys_vec *vec) 87 87 { 88 - iter->addr = pci_p2pdma_bus_addr_map(&iter->p2pdma, vec->paddr); 88 + iter->addr = pci_p2pdma_bus_addr_map(iter->p2pdma.mem, vec->paddr); 89 89 iter->len = vec->len; 90 90 return true; 91 91 }
+2 -2
drivers/iommu/dma-iommu.c
··· 1439 1439 * as a bus address, __finalise_sg() will copy the dma 1440 1440 * address into the output segment. 1441 1441 */ 1442 - s->dma_address = pci_p2pdma_bus_addr_map(&p2pdma_state, 1443 - sg_phys(s)); 1442 + s->dma_address = pci_p2pdma_bus_addr_map( 1443 + p2pdma_state.mem, sg_phys(s)); 1444 1444 sg_dma_len(s) = sg->length; 1445 1445 sg_dma_mark_bus_address(s); 1446 1446 continue;
+3 -4
include/linux/pci-p2pdma.h
··· 181 181 /** 182 182 * pci_p2pdma_bus_addr_map - Translate a physical address to a bus address 183 183 * for a PCI_P2PDMA_MAP_BUS_ADDR transfer. 184 - * @state: P2P state structure 184 + * @provider: P2P provider structure 185 185 * @paddr: physical address to map 186 186 * 187 187 * Map a physically contiguous PCI_P2PDMA_MAP_BUS_ADDR transfer. 188 188 */ 189 189 static inline dma_addr_t 190 - pci_p2pdma_bus_addr_map(struct pci_p2pdma_map_state *state, phys_addr_t paddr) 190 + pci_p2pdma_bus_addr_map(struct p2pdma_provider *provider, phys_addr_t paddr) 191 191 { 192 - WARN_ON_ONCE(state->map != PCI_P2PDMA_MAP_BUS_ADDR); 193 - return paddr + state->mem->bus_offset; 192 + return paddr + provider->bus_offset; 194 193 } 195 194 196 195 #endif /* _LINUX_PCI_P2P_H */
+2 -2
kernel/dma/direct.c
··· 479 479 } 480 480 break; 481 481 case PCI_P2PDMA_MAP_BUS_ADDR: 482 - sg->dma_address = pci_p2pdma_bus_addr_map(&p2pdma_state, 483 - sg_phys(sg)); 482 + sg->dma_address = pci_p2pdma_bus_addr_map( 483 + p2pdma_state.mem, sg_phys(sg)); 484 484 sg_dma_mark_bus_address(sg); 485 485 continue; 486 486 default:
+1 -1
mm/hmm.c
··· 811 811 break; 812 812 case PCI_P2PDMA_MAP_BUS_ADDR: 813 813 pfns[idx] |= HMM_PFN_P2PDMA_BUS | HMM_PFN_DMA_MAPPED; 814 - return pci_p2pdma_bus_addr_map(p2pdma_state, paddr); 814 + return pci_p2pdma_bus_addr_map(p2pdma_state->mem, paddr); 815 815 default: 816 816 return DMA_MAPPING_ERROR; 817 817 }