-
Notifications
You must be signed in to change notification settings - Fork 76
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
l2cache_clean/invalidate_region corrupts memory #121
Comments
Here is a way to detect the bug when it happens: The bug doesn't always happen. First of all the qspi_memcpy must use DMA, which only happens if both the data and the length is an even number of cache lines. And secondly it depends on whether the L2 cache is flushed to physical memory before we perform the DMA transfer. |
Here's an example visualizing how, why and when this bug occurs. PreconditionsImagine having filled the stack with 0xcb and all caches are updated. Physical memory
Cache
Read from spi-nor flash using DMAWhen calling Let us assume the stackpointer is located so that the saved variables ends up somewhere in In the beginning of the function our Since nothing needs to be flushed to physical memory, this is how the memory looks right now: Physical memory
Cache
Performing qspi_memcpyA bit later we will read into The memory and cache will look like this: Physical memory
Cache
If we now call Physical memory
Cache
|
There is an error in
drivers/mm/l2cache_l2cc.c
where the invalidation and cleaning of region overshoots by one cache line.The region to be cleared is from
start
up to - but excluding -end
.Furthermore, looking at e.g.
l2_cache_invalidate_region
there is an extra call tol2cc_invalidate_pal(end)
after invalidating the region. I suspect that this call should be replaced byl2cc_cache_sync()
.Fix in attached file fix-l2-cache.patch.
The text was updated successfully, but these errors were encountered: