-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(c9xx): don't flush dcache when invalidating #18
Conversation
The data cache invalidation function for c9xx CPUs uses `dcache.cipa` instruction. According to T-Head extension specification[1] section 3.1.5, this instruction also performs a cache clean along with the invalidation. On top of being incorrect, this leads to a serious issue on the designware ethernet driver, where stalled cache may get flushed each time we handle a new received packet[2]. As a result, received packet are randomly corrupted with old cached data. This can easily be reproduced by sending an ARP request to the device during a TFTP transfer. The last TFTP block is treated as the ARP reply we just sent, which makes U-Boot hang on the block. Always use `dcache.ipa` instruction to invalidate dcache. Replace existing usages of `dcache.ipa` with our implementation. Note that this fix is slightly intrusive as it changes the cache invalidation behavior in all drivers. However, I have not noticed any side-effect during my tests. [1] https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.3.0/xthead-2023-11-10-2.3.0.pdf [2] https://github.com/revyos/thead-u-boot/blob/918a8c89e056e3462031d6a498bb4fcc0c3526ce/drivers/net/designware.c#L475
Suggest using dcache.cipa instead of dcache.ipa Can you give me a test case? I need to validate it. |
Do you mean
Do you mean a programmatic test case? Not sure how to write that. If you just want to reproduce the issue, download any big file over tftp on the Lichee Pi 4A and wait for an ARP request to arrive (or trigger one yourself using |
Talked to the original author and he suggested using dcache.cipa instead of dcache.ipa here. |
Sorry, I'm not sure we're on the same page. Do you expect something from me or do you have something to check with the original author? To make my point clear: before this PR, For example, when handling an ARP request, U-Boot modifies the packet in-place to build its ARP reply: Lines 164 to 170 in 918a8c8
As the TH1520 isn't DMA-coherent, this garbage data in cache may be flushed after the ethernet device has written new packets at this same memory address. That's why the designware ethernet driver invalidates the buffer's dcache before handing over a new packet to the system: thead-u-boot/drivers/net/designware.c Line 475 in 918a8c8
Therefore, if we clean or flush the cache here (instead of just invalidating), what we are actually flushing is the old garbage data that U-Boot had previously written before the ethernet device wrote the new packet. This is not what we want. Generally, there is no guarantee that U-Boot won't tamper with DMA buffers, so when a buffer is marked as invalid by some driver, it should not be flushed (like |
@RevySR 👋 . Have you been able to reproduce the issue? Do you need some help or details? |
The data cache invalidation function for c9xx CPUs uses
dcache.cipa
instruction. According to T-Head extension specification[1] section 3.1.5, this instruction also performs a cache clean along with the invalidation.On top of being incorrect, this leads to a serious issue on the designware ethernet driver, where stalled cache may get flushed each time we handle a new received packet[2]. As a result, received packet are randomly corrupted with old cached data. This can easily be reproduced by sending an ARP request to the device during a TFTP transfer. The last TFTP block is treated as the ARP reply we just sent, which makes U-Boot hang on the block.
Always use
dcache.ipa
instruction to invalidate dcache. Replace existing usages ofdcache.ipa
with our implementation.Note that this fix is slightly intrusive as it changes the cache invalidation behavior in all drivers. However, I have not noticed any side-effect during my tests.
[1] https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.3.0/xthead-2023-11-10-2.3.0.pdf
[2]
thead-u-boot/drivers/net/designware.c
Line 475 in 918a8c8