Re: [PATCH] iommu/dma-iommu: Fix wrong scatterlist length assignment in P2PDMA path
From: Logan Gunthorpe
Date: Mon Jun 01 2026 - 12:11:06 EST
On 2026-05-30 05:28, lirongqing wrote:
> From: Li RongQing <lirongqing@xxxxxxxxx>
>
> 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@xxxxxxxxx>
Hmm, I thought I had tested this stuff pretty thoroughly so I'm
surprised I missed that. But I guess seeing the users of these
specifically don't allow mixing with anonymous memory the vast majority
of tests would only have one segment.
Can you confirm that you've reproduced and tested this and it actually
fixes a bug? Not just seeing something that looks strange. I have a
vague feeling it was intentional but looking at the code it looks wrong
to me too.
Thanks,
Logan