From 85ccfe24bf5d3edc869f1cda942a582eb2ebe628 Mon Sep 17 00:00:00 2001 From: Kinsey Moore Date: Mon, 30 Sep 2024 15:52:57 -0500 Subject: [PATCH] bsps/aarch64/mmu: Align dynamically mapped blocks Dynamically mapped blocks must be aligned to the MMU page size just like startup-configured blocks. This was not being enforced and could cause a hang with bad input. --- bsps/aarch64/shared/mmu/vmsav8-64.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bsps/aarch64/shared/mmu/vmsav8-64.c b/bsps/aarch64/shared/mmu/vmsav8-64.c index c426dec900..29afd4d64f 100644 --- a/bsps/aarch64/shared/mmu/vmsav8-64.c +++ b/bsps/aarch64/shared/mmu/vmsav8-64.c @@ -48,12 +48,18 @@ rtems_status_code aarch64_mmu_map( { rtems_status_code sc; ISR_Level level; + uint64_t mapping_base; + uint64_t mapping_size; uint64_t max_mappable = 1LLU << aarch64_mmu_get_cpu_pa_bits(); if ( addr >= max_mappable || (addr + size) > max_mappable ) { return RTEMS_INVALID_ADDRESS; } + /* Adjust the address and size to multiples of the page table size */ + mapping_base = RTEMS_ALIGN_DOWN(addr, MMU_PAGE_SIZE); + mapping_size = RTEMS_ALIGN_UP(size + addr - mapping_base, MMU_PAGE_SIZE); + /* * Disable interrupts so they don't run while the MMU tables are being * modified. @@ -63,8 +69,8 @@ rtems_status_code aarch64_mmu_map( sc = aarch64_mmu_map_block( (uint64_t *) bsp_translation_table_base, 0x0, - addr, - size, + mapping_base, + mapping_size, -1, flags );