Skip to content

Commit 311ddf9

Browse files
softwareckicarlescufi
authored andcommitted
ace: mm: tlb: Check tlb translation enabled before flushing cache
Before unmapping a memory page, the cache is flushed. If the given memory page is not mapped, this operation ends with a cpu exception on the ptl platform. Add check if tlb translation is active before flushing. Signed-off-by: Adrian Warecki <[email protected]>
1 parent cc54480 commit 311ddf9

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

drivers/mm/mm_drv_intel_adsp_mtl_tlb.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ static int sys_mm_drv_unmap_page_wflush(void *virt, bool flush_data)
338338
k_spinlock_key_t key;
339339
uint32_t entry_idx, bank_idx;
340340
uint16_t *tlb_entries = UINT_TO_POINTER(TLB_BASE);
341+
uint16_t entry;
341342
uintptr_t pa;
342343
int ret = 0;
343344

@@ -359,6 +360,17 @@ static int sys_mm_drv_unmap_page_wflush(void *virt, bool flush_data)
359360

360361
key = k_spin_lock(&tlb_lock);
361362

363+
entry_idx = get_tlb_entry_idx(va);
364+
entry = tlb_entries[entry_idx];
365+
366+
/* Check if the translation is enabled in the TLB entry.
367+
* Attempt to flush the cache of an inactive address will result in a cpu exception.
368+
*/
369+
if (!(entry & TLB_ENABLE_BIT)) {
370+
ret = -EFAULT;
371+
goto out_unlock;
372+
}
373+
362374
/*
363375
* Flush the cache to make sure the backing physical page
364376
* has the latest data.
@@ -371,8 +383,7 @@ static int sys_mm_drv_unmap_page_wflush(void *virt, bool flush_data)
371383
#endif
372384
}
373385

374-
entry_idx = get_tlb_entry_idx(va);
375-
pa = tlb_entry_to_pa(tlb_entries[entry_idx]);
386+
pa = tlb_entry_to_pa(entry);
376387

377388
/* Restore default entry settings with cleared the enable bit. */
378389
tlb_entries[entry_idx] = 0;
@@ -395,6 +406,7 @@ static int sys_mm_drv_unmap_page_wflush(void *virt, bool flush_data)
395406
}
396407
}
397408

409+
out_unlock:
398410
k_spin_unlock(&tlb_lock, key);
399411

400412
out:

0 commit comments

Comments
 (0)