Skip to content

Commit

Permalink
mm: tlb: mtl: Fix memory page unmapping
Browse files Browse the repository at this point in the history
The sys_mm_drv_unmap_page function first replaced the tlb entry with
the default one and then read the physical address that was mapped.
However, it was already overwritten, so it always release the default
physical address instead of the truly mapped one.

Signed-off-by: Adrian Warecki <[email protected]>
  • Loading branch information
softwarecki authored and aescolar committed Feb 26, 2024
1 parent 46f3d78 commit 9cf3e08
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions drivers/mm/mm_drv_intel_adsp_mtl_tlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ int sys_mm_drv_unmap_page(void *virt)
{
k_spinlock_key_t key;
uint32_t entry_idx, bank_idx;
uint16_t entry;
uint16_t *tlb_entries = UINT_TO_POINTER(TLB_BASE);
uintptr_t pa;
int ret = 0;
Expand Down Expand Up @@ -363,16 +362,14 @@ int sys_mm_drv_unmap_page(void *virt)
sys_cache_data_flush_range(virt, CONFIG_MM_DRV_PAGE_SIZE);

entry_idx = get_tlb_entry_idx(va);
/* Restore default entry settings */
entry = pa_to_tlb_entry(va) | TLB_EXEC_BIT | TLB_WRITE_BIT;
/* Clear the enable bit */
entry &= ~TLB_ENABLE_BIT;
tlb_entries[entry_idx] = entry;

pa = tlb_entry_to_pa(tlb_entries[entry_idx]);

/* Check bounds of physical address space. */
/* Initial TLB mappings could point to non existing physical pages. */
/* Restore default entry settings with cleared the enable bit. */
tlb_entries[entry_idx] = 0;

/* Check bounds of physical address space.
* Initial TLB mappings could point to non existing physical pages.
*/
if ((pa >= L2_SRAM_BASE) && (pa < (L2_SRAM_BASE + L2_SRAM_SIZE))) {
sys_mem_blocks_free_contiguous(&L2_PHYS_SRAM_REGION,
UINT_TO_POINTER(pa), 1);
Expand Down

0 comments on commit 9cf3e08

Please sign in to comment.