From fe5ed6835643dfbe792ba0c9ecf8b6bb16b13da5 Mon Sep 17 00:00:00 2001 From: Jaroslaw Stelter Date: Wed, 20 Jul 2022 15:54:17 +0200 Subject: [PATCH] soc: ace_v1x: check physical memory bounds on page unmap. This patch fix issue with unmapping of virtual addresses mapped to non-existing physical memory. MTL TLB table is initialised with 1:1 mapping, however virtual space is much wider than available physical space. We should not try to free and manage of power for non-existing physical pages. Signed-off-by: Jaroslaw Stelter --- drivers/mm/mm_drv_intel_adsp_mtl_tlb.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/mm/mm_drv_intel_adsp_mtl_tlb.c b/drivers/mm/mm_drv_intel_adsp_mtl_tlb.c index 5acf601694e..908e9042782 100644 --- a/drivers/mm/mm_drv_intel_adsp_mtl_tlb.c +++ b/drivers/mm/mm_drv_intel_adsp_mtl_tlb.c @@ -401,12 +401,16 @@ int sys_mm_drv_unmap_page(void *virt) pa = tlb_entry_to_pa(tlb_entries[entry_idx]); - sys_mem_blocks_free_contiguous(&L2_PHYS_SRAM_REGION, - UINT_TO_POINTER(pa), 1); + /* 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); - bank_idx = get_hpsram_bank_idx(pa); - if (--hpsram_ref[bank_idx] == 0) { - sys_mm_drv_hpsram_pwr(bank_idx, false, false); + bank_idx = get_hpsram_bank_idx(pa); + if (--hpsram_ref[bank_idx] == 0) { + sys_mm_drv_hpsram_pwr(bank_idx, false, false); + } } k_spin_unlock(&tlb_lock, key);