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
F132136930: D37611.id113865.diff
Tue, Oct 14, 2:18 AM
F132136923: D37611.id.diff
Tue, Oct 14, 2:18 AM
Unknown Object (File)
Mon, Oct 13, 12:48 PM
Unknown Object (File)
Wed, Oct 8, 5:37 PM
Unknown Object (File)
Sun, Oct 5, 10:13 AM
Unknown Object (File)
Thu, Oct 2, 12:31 PM
Unknown Object (File)
Wed, Oct 1, 11:27 PM
Unknown Object (File)
Mon, Sep 22, 12:50 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