Page MenuHomeFreeBSD

linuxkpi: Fix return value of dma_map_sgtable
ClosedPublic

Authored by ashafer on Dec 6 2022, 5:23 AM.
Tags
None
Referenced Files
F140109285: D37611.diff
Sat, Dec 20, 8:45 AM
Unknown Object (File)
Sun, Dec 7, 11:27 AM
Unknown Object (File)
Tue, Nov 25, 11:06 PM
Unknown Object (File)
Nov 17 2025, 10:33 AM
Unknown Object (File)
Nov 15 2025, 9:03 PM
Unknown Object (File)
Nov 8 2025, 10:28 PM
Unknown Object (File)
Nov 3 2025, 8:40 PM
Unknown Object (File)
Nov 3 2025, 8:40 PM

Details

Summary

dma_map_sgtable internally uses the dma_map_sg_attrs helper. The problem is
that dma_map_sg_attrs returns the number of entries mapped, whereas
dma_map_sgtable returns nonzero on failure. This leads to dma_map_sgtable
returning non-zero-but-positive values which tricks other areas of the stack
into thinking nents is a valid pointer.

This checks if nents is valid and returns zero if so, updating the nents field
in sgt. This fixes PRIME render offload with nvidia-drm

Test Plan

PRIME rendering offload with i915kms and nvidia-drm

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 48620
Build 45506: arc lint + arc unit

Event Timeline

Here's the github PR handling this for older versions before we moved this function into base: https://github.com/freebsd/drm-kmod/pull/218

This revision is now accepted and ready to land.Dec 6 2022, 3:25 PM
bz added a subscriber: bz.

Functionally looks fine; style may be improved (or not).

sys/compat/linuxkpi/common/include/linux/dma-mapping.h
365

Normally I'd say separate declaration:

int nents;

nents = ...
368

() around return values here and below.

369

No need for the else clause so all the {} {} can go for both.

Closing this since it was already submitted in 4085bde9fa2e