Page MenuHomeFreeBSD

linuxkpi: Fix return value of dma_map_sgtable
ClosedPublic

Authored by ashafer_badland.io on Dec 6 2022, 5:23 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Jul 24, 1:14 AM
Unknown Object (File)
Sat, Jul 20, 11:22 PM
Unknown Object (File)
Sun, Jul 14, 11:56 AM
Unknown Object (File)
Sat, Jul 13, 7:13 PM
Unknown Object (File)
Sat, Jul 6, 10:51 AM
Unknown Object (File)
Apr 30 2024, 4:57 AM
Unknown Object (File)
Apr 27 2024, 5:37 PM
Unknown Object (File)
Apr 27 2024, 5:37 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