Skip to content

drm/amdkcl: Use DMA iterator in PRIME address fallback - #231

Open
theSprog wants to merge 1 commit into
ROCm:masterfrom
theSprog:fix-kcl-prime-dma-iteration
Open

theSprog wants to merge 1 commit into
ROCm:masterfrom
theSprog:fix-kcl-prime-dma-iteration

Conversation

@theSprog

Copy link
Copy Markdown

Motivation

The KCL fallback for drm_prime_sg_to_dma_addr_array() calls drm_prime_sg_to_page_addr_arrays() to extract DMA addresses.

Older implementations of drm_prime_sg_to_page_addr_arrays() walk each DMA address range using sg->length. This assumes that the physical and DMA views of a scatterlist have identical layouts. That assumption does not hold when DMA mapping merges entries or when ONLY the DMA view is valid. In such cases the fallback can leave DMA address entries unpopulated while still returning success.

Fixes: faab963 ("drm/amdkcl: fake the drm_prime_sg_to_dma_addr_array")

Technical Details

Use for_each_sg_dma_page() to walk the mapped entries directly. This uses sgt->nents and the DMA length of each entry, matching the semantics of the upstream drm_prime_sg_to_dma_addr_array() implementation.

Note on Kernel Compatibility: for_each_sg_dma_page() was introduced by upstream commit d901b27. Feedback on its availability across all currently supported host kernel baselines taking this fallback path would be appreciated.

Test Plan

Import a DMA-BUF whose mapped scatterlist provides the DMA view required by the importer on Linux 5.4.18.

Test Result

Before this change, the DMA address array was incomplete and the import failed. After this change, the expected DMA addresses were populated and the import succeeded

Submission Checklist

The KCL fallback for drm_prime_sg_to_dma_addr_array() calls
drm_prime_sg_to_page_addr_arrays() to extract DMA addresses.

Older implementations of drm_prime_sg_to_page_addr_arrays() walk each
DMA address range using sg->length. This assumes that the physical and
DMA views of a scatterlist have identical layouts. That assumption does
not hold when DMA mapping merges entries or when ONLY the DMA view is
valid. In such cases the fallback can leave DMA address entries
unpopulated while still returning success.

Use for_each_sg_dma_page() to walk the mapped entries directly. This
uses sgt->nents and the DMA length of each entry, matching the semantics
of the upstream drm_prime_sg_to_dma_addr_array() implementation.

Tested on Linux 5.4.18 with an imported DMA-BUF whose mapped scatterlist
provides the DMA view required by the importer.

Fixes: faab963 ("drm/amdkcl: fake the drm_prime_sg_to_dma_addr_array")
Signed-off-by: Jiaming Fan <fan.jiaming@hotmail.com>
@theSprog
theSprog marked this pull request as ready for review September 27, 2026 11:07
@theSprog

Copy link
Copy Markdown
Author

@kentrussell This fixes the KCL fallback of drm_prime_sg_to_dma_addr_array() (used on kernels < 5.12). On kernels without upstream c0f83d1 (e.g. 5.4.18), DMA-BUF import fails because some DMA addresses are left unpopulated. We ship on customer-pinned kernels that we can't upgrade, so the fix has to live in KCL. KCL-only, so not applicable to amd-gfx. Could you take a look?

@theSprog

Copy link
Copy Markdown
Author

Some context: we hit this while building on the amdgpu DKMS stack on a customer's 5.4.18 kernel. DMA-BUF sharing with an out-of-tree PowerVR driver failed on import, which we traced to this fallback.

On compatibility: the fallback is only built on kernels < 5.12 without drm_prime_sg_to_dma_addr_array(). All ROCm-supported kernels have it (RHEL 8 backports it into 4.18 too), so they are unaffected. for_each_sg_dma_page() exists since v5.1.

@theSprog

theSprog commented Oct 8, 2026

Copy link
Copy Markdown
Author

@kentrussell Sorry for the noise earlier: the branch had been based on a fork master that still carried 6 unrelated commits (SVM eviction and DCN vblank changes), which made this PR look like a 16-file change with conflicts. I have rebased it onto the current master. It is now a single commit touching only include/kcl/kcl_drm_prime.h (+11/-1), and the fallback on master still has the issue.

Since this is KCL-only and not applicable to amd-gfx, could you pull it into the internal dkms branch review, like #194?

If you do see this, I'd really appreciate a reply either way, whether it's accepted or declined, so I know where it stands. Thanks.

@theSprog

Copy link
Copy Markdown
Author

@kentrussell Could you help route this to the KCL team, or point me to the appropriate contact or submission channel for KCL-only fixes? I understand this repository is a mirror. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant