From 373568f63a52124c5a7eb83f99ee46b4aa869e68 Mon Sep 17 00:00:00 2001 From: Ville Juven Date: Wed, 5 Oct 2022 16:12:43 +0300 Subject: [PATCH] mpfs_mm_init.c: Ensure the L3 page table size is large enough Run-time check for L3 page table size, to ensure it is large enough to map all of the kernel memory. NOTE: The check has to be run-time, as KFLASH_SIZE/KSRAM_SIZE are really linker relocation symbols, and thus cannot be utilized compile-time. --- arch/risc-v/src/mpfs/mpfs_mm_init.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/risc-v/src/mpfs/mpfs_mm_init.c b/arch/risc-v/src/mpfs/mpfs_mm_init.c index 6a3830a4fd3..aa14554834c 100644 --- a/arch/risc-v/src/mpfs/mpfs_mm_init.c +++ b/arch/risc-v/src/mpfs/mpfs_mm_init.c @@ -58,6 +58,11 @@ #define PGT_L2_SIZE (512) /* Enough to map 1 GiB */ #define PGT_L3_SIZE (1024) /* Enough to map 4 MiB */ +/* Calculate the minimum size for the L3 table */ + +#define KMEM_SIZE (KFLASH_SIZE + KSRAM_SIZE) +#define PGT_L3_MIN_SIZE ((KMEM_SIZE + RV_MMU_PAGE_MASK) >> RV_MMU_PAGE_SHIFT) + #define SLAB_COUNT (sizeof(m_l3_pgtable) / RV_MMU_PAGE_SIZE) /**************************************************************************** @@ -214,6 +219,10 @@ void mpfs_kernel_mappings(void) ASSERT((KSRAM_START & RV_MMU_SECTION_ALIGN) == 0); ASSERT((PGPOOL_START & RV_MMU_SECTION_ALIGN) == 0); + /* Check that the L3 table is of sufficient size */ + + ASSERT(PGT_L3_SIZE >= PGT_L3_MIN_SIZE); + /* Initialize slab allocator for L3 page tables */ slab_init(PGT_L3_PBASE);