Bug 293381 - linuxkpi: Possible incorrect bus_dmasync_op_t mapping for DMA_BIDIRECTIONAL
Summary: linuxkpi: Possible incorrect bus_dmasync_op_t mapping for DMA_BIDIRECTIONAL
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 15.0-CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-emulation (Nobody)
URL: https://reviews.freebsd.org/D55497
Keywords:
Depends on:
Blocks:
 
Reported: 2026-02-23 11:18 UTC by Zishun Yi
Modified: 2026-03-04 04:51 UTC (History)
1 user (show)

See Also:


Attachments
Illustrative patch (1.09 KB, patch)
2026-02-23 11:18 UTC, Zishun Yi
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zishun Yi 2026-02-23 11:18:28 UTC
Created attachment 268296 [details]
Illustrative patch

In dma_sync_single_for_cpu(), for DMA_BIDIRECTIONAL, the code currently performs BUS_DMASYNC_POSTREAD followed by BUS_DMASYNC_PREREAD. I suspect it should simply be BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE.

Reason: dma_sync_single_for_cpu() transfers the ownership of the DMA area to the CPU. Since DMA_BIDIRECTIONAL indicates the area can be used for both Device -> Main Memory and Main Memory -> Device transfers, we must assume the previous device's access was bidirectional. Because the device might have both read from and written to this area, both POST operations are necessary before the CPU accesses it.

Furthermore, since the ownership of the DMA area is being transferred to the CPU, the device will no longer access it. Therefore, I believe the PREREAD operation is unnecessary. PREREAD should instead be used when ownership is transferred back to the device.

So, for dma_sync_single_for_device(), I suspect it should use BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE to prepare the buffer for potential bidirectional access by the hardware.

PS: I noticed this logic was introduced in https://reviews.freebsd.org/D32255. this DR conclusion seemed a bit unclear, and the current mapping was ultimately adopted. Given that context, I just wanted to bring this up to see if it might be an oversight.
Please kindly correct me if my understanding is wrong.
Comment 1 Bjoern A. Zeeb freebsd_committer freebsd_triage 2026-03-04 00:34:06 UTC
You opened a review for this as well?  Can you add the URL to it into the URL: field please?
Comment 2 Zishun Yi 2026-03-04 02:10:13 UTC
(In reply to Bjoern A. Zeeb from comment #1)
Added. Thanks!