drivers: usdhc: don't invalidate cache on non-blocking non-DMA transfer#25
Open
tchebb wants to merge 1 commit intonxp-mcuxpresso:mainfrom
Open
drivers: usdhc: don't invalidate cache on non-blocking non-DMA transfer#25tchebb wants to merge 1 commit intonxp-mcuxpresso:mainfrom
tchebb wants to merge 1 commit intonxp-mcuxpresso:mainfrom
Conversation
In USDHC_TransferNonBlocking(), DMA may be disabled if the user passes a NULL dmaConfig or if USDHC_SetAdmaTableConfig() fails. In that case, USDHC_TransferNonBlocking() correctly skips its cache clean, but USDHC_TransferHandleData() doesn't skip its cache invalidate, meaning it replaces the entire data buffer's cache line with stale data from RAM. This memory corruption causes undefined behavior and system instability. Fix the issue by remembering if we used DMA and only invalidating the cache if we did. This matches the behavior of USDHC_TransferBlocking(). Also fix USDHC_TransferScatterGatherADMANonBlocking(). Memory corruption may still occur if the DMA buffer shares a cache line with unrelated data that the CPU updates during a transfer, but there is no way for us to detect that in the SDK. The user should avoid that situation. Fixes nxp-mcuxpresso#20
Contributor
|
@tchebb Thanks a lot for the fix-up. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In
USDHC_TransferNonBlocking(), DMA may be disabled if the user passes a NULLdmaConfigor ifUSDHC_SetAdmaTableConfig()fails. In that case,USDHC_TransferNonBlocking()correctly skips its cache clean, butUSDHC_TransferHandleData()doesn't skip its cache invalidate, meaning it replaces the entire data buffer's cache line with stale data from RAM. This memory corruption causes undefined behavior and system instability.Fix the issue by remembering if we used DMA and only invalidating the cache if we did. This matches the behavior of
USDHC_TransferBlocking(). Also fixUSDHC_TransferScatterGatherADMANonBlocking().Memory corruption may still occur if the DMA buffer shares a cache line with unrelated data that the CPU updates during a transfer, but there is no way for us to detect that in the SDK. The user should avoid that situation.
Fixes #20