Skip to content

Commit ec818ca

Browse files
rleonmszyprow
authored andcommitted
mm/hmm: properly take MMIO path
In case peer-to-peer transaction traverses through host bridge, the IOMMU needs to have IOMMU_MMIO flag, together with skip of CPU sync. The latter was handled by provided DMA_ATTR_SKIP_CPU_SYNC flag, but IOMMU flag was missed, due to assumption that such memory can be treated as regular one. Reuse newly introduced DMA attribute to properly take MMIO path. Reviewed-by: Jason Gunthorpe <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Marek Szyprowski <[email protected]> Link: https://lore.kernel.org/r/998251caf3f9d1a3f6f8205f1f494c707fb4d8fa.1757423202.git.leonro@nvidia.com
1 parent e1d69da commit ec818ca

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

mm/hmm.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ dma_addr_t hmm_dma_map_pfn(struct device *dev, struct hmm_dma_map *map,
746746
case PCI_P2PDMA_MAP_NONE:
747747
break;
748748
case PCI_P2PDMA_MAP_THRU_HOST_BRIDGE:
749-
attrs |= DMA_ATTR_SKIP_CPU_SYNC;
749+
attrs |= DMA_ATTR_MMIO;
750750
pfns[idx] |= HMM_PFN_P2PDMA;
751751
break;
752752
case PCI_P2PDMA_MAP_BUS_ADDR:
@@ -776,7 +776,7 @@ dma_addr_t hmm_dma_map_pfn(struct device *dev, struct hmm_dma_map *map,
776776
goto error;
777777

778778
dma_addr = dma_map_phys(dev, paddr, map->dma_entry_size,
779-
DMA_BIDIRECTIONAL, 0);
779+
DMA_BIDIRECTIONAL, attrs);
780780
if (dma_mapping_error(dev, dma_addr))
781781
goto error;
782782

@@ -811,16 +811,17 @@ bool hmm_dma_unmap_pfn(struct device *dev, struct hmm_dma_map *map, size_t idx)
811811
if ((pfns[idx] & valid_dma) != valid_dma)
812812
return false;
813813

814+
if (pfns[idx] & HMM_PFN_P2PDMA)
815+
attrs |= DMA_ATTR_MMIO;
816+
814817
if (pfns[idx] & HMM_PFN_P2PDMA_BUS)
815818
; /* no need to unmap bus address P2P mappings */
816-
else if (dma_use_iova(state)) {
817-
if (pfns[idx] & HMM_PFN_P2PDMA)
818-
attrs |= DMA_ATTR_SKIP_CPU_SYNC;
819+
else if (dma_use_iova(state))
819820
dma_iova_unlink(dev, state, idx * map->dma_entry_size,
820821
map->dma_entry_size, DMA_BIDIRECTIONAL, attrs);
821-
} else if (dma_need_unmap(dev))
822+
else if (dma_need_unmap(dev))
822823
dma_unmap_phys(dev, dma_addrs[idx], map->dma_entry_size,
823-
DMA_BIDIRECTIONAL, 0);
824+
DMA_BIDIRECTIONAL, attrs);
824825

825826
pfns[idx] &=
826827
~(HMM_PFN_DMA_MAPPED | HMM_PFN_P2PDMA | HMM_PFN_P2PDMA_BUS);

0 commit comments

Comments
 (0)