]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iommu/dma-iommu: Fix wrong scatterlist length assignment in P2PDMA path
authorLi RongQing <lirongqing@baidu.com>
Sat, 30 May 2026 11:28:52 +0000 (07:28 -0400)
committerJoerg Roedel <joerg.roedel@amd.com>
Fri, 12 Jun 2026 12:56:49 +0000 (14:56 +0200)
In iommu_dma_map_sg(), when handling PCI P2PDMA cases, the DMA length
of the current scatterlist segment `s` is incorrectly assigned from the
head entry `sg->length` instead of the current entry `s->length`.

This typo causes all P2PDMA segments in the scatterlist to inherit the
length of the first segment, leading to corrupted DMA lengths for multi-
segment scatterlists.

Fix this by using `s->length` instead of `sg->length`.

Fixes: a25e7962db ("PCI/P2PDMA: Refactor the p2pdma mapping helpers")
Signed-off-by: Li RongQing <lirongqing@baidu.com>
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
drivers/iommu/dma-iommu.c

index 54d96e847f161b7f4707232d8c21394bde31eaaf..e8d4c2dac4da80baded71ab0847868570e809f50 100644 (file)
@@ -1465,7 +1465,7 @@ int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
                         */
                        s->dma_address = pci_p2pdma_bus_addr_map(
                                p2pdma_state.mem, sg_phys(s));
-                       sg_dma_len(s) = sg->length;
+                       sg_dma_len(s) = s->length;
                        sg_dma_mark_bus_address(s);
                        continue;
                default: