Files
Centos-kernel-stream-9/kernel
Jerry Snitselaar b3fb53d9f6 dma-direct: Fix missing sg_dma_len assignment in P2PDMA bus mappings
JIRA: https://issues.redhat.com/browse/RHEL-147906
Upstream-Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit d0d08f4bd7f667dc7a65cd7133c0a94a6f02aca3
Author: Pranjal Shrivastava <praan@google.com>
Date: Wed Nov 26 11:41:12 2025 +0000

    Prior to commit a25e7962db0d7 ("PCI/P2PDMA: Refactor the p2pdma mapping
    helpers"), P2P segments were mapped using the pci_p2pdma_map_segment()
    helper. This helper was responsible for populating sg->dma_address,
    marking the bus address, and also setting sg_dma_len(sg).

    The refactor[1] removed this helper and moved the mapping logic directly
    into the callers. While iommu_dma_map_sg() was correctly updated to set
    the length in the new flow, it was missed in dma_direct_map_sg().

    Thus, in dma_direct_map_sg(), the PCI_P2PDMA_MAP_BUS_ADDR case sets the
    dma_address and marks the segment, but immediately executes 'continue',
    which causes the loop to skip the standard assignment logic at the end:

        sg_dma_len(sg) = sg->length;

    As a result, when CONFIG_NEED_SG_DMA_LENGTH is enabled, the dma_length
    field remains uninitialized (zero) for P2P bus address mappings. This
    breaks upper-layer drivers (for e.g. RDMA/IB) that rely on sg_dma_len()
    to determine the transfer size.

    Fix this by explicitly setting the DMA length in the
    PCI_P2PDMA_MAP_BUS_ADDR case before continuing to the next scatterlist
    entry.

    Fixes: a25e7962db0d7 ("PCI/P2PDMA: Refactor the p2pdma mapping helpers")
    Reported-by: Jacob Moroni <jmoroni@google.com>
    Signed-off-by: Pranjal Shrivastava <praan@google.com>

    [1]
    https://lore.kernel.org/all/ac14a0e94355bf898de65d023ccf8a2ad22a3ece.1746424934.git.leon@kernel.org/

    Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
    Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
    Reviewed-by: Shivaji Kant <shivajikant@google.com>
    Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
    Link: https://lore.kernel.org/r/20251126114112.3694469-1-praan@google.com

(cherry picked from commit d0d08f4bd7f667dc7a65cd7133c0a94a6f02aca3)
Assisted-by: Claude:claude-opus-4-6
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2026-04-10 18:05:17 -07:00
..
2025-04-16 23:24:17 -04:00
2025-09-30 06:39:24 +00:00
2025-12-22 09:16:55 +01:00
2025-08-22 14:40:40 -04:00
2025-12-08 12:31:32 +08:00
2025-12-22 09:16:59 +01:00
2025-08-22 14:40:57 -04:00
2024-12-09 12:22:45 -05:00
2024-09-20 12:26:34 -07:00