Skip to content

Commit

Permalink
regions_mm: Invalidate cache when freeing memory
Browse files Browse the repository at this point in the history
Platforms based on xtensa have a non-coherent cache between cores. Before
releasing a memory block, it is necessary to invalidate the cache. This
memory block can be allocated by another core and performing cache
writeback by the previous owner will destroy current content of the main
memory.

Invalidate cache when freeing allocated memory block.

Signed-off-by: Adrian Warecki <[email protected]>
  • Loading branch information
softwarecki authored and kv2019i committed Oct 8, 2024
1 parent af55b45 commit 4570e53
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions zephyr/lib/regions_mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,16 @@ int vmh_free(struct vmh_heap *heap, void *ptr)
if (retval)
return retval;

/* Platforms based on xtensa have a non-coherent cache between cores. Before releasing
* a memory block, it is necessary to invalidate the cache. This memory block can be
* allocated by another core and performing cache writeback by the previous owner will
* destroy current content of the main memory. The cache is invalidated by the
* sys_mm_drv_unmap_region function, when a memory page is unmapped. There is no need to
* invalidate it when releasing buffers of at least a page in size.
*/
if (size_to_free < CONFIG_MM_DRV_PAGE_SIZE)
sys_cache_data_invd_range(ptr, size_to_free);

return vmh_unmap_region(heap->physical_blocks_allocators[mem_block_iter], ptr,
size_to_free);
}
Expand Down

0 comments on commit 4570e53

Please sign in to comment.