From c38634fa33c09f396a1a6a6ee4b6dcd65f864427 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Fri, 16 Jul 2021 15:27:27 -0700 Subject: [PATCH] kernel: mmu: fix assigning unaligned addr to page frame In do_page_fault(), the incoming page fault address is not aligned, and it was unconditionally assigned to the page frame virtual address field. If the backing store simply returns the virtual address without processing in k_mem_paging_backing_store_location_get(), this unaligned address will be passed to arch_mem_page_out(). On x86, it is further passed to range_map() which asserts if the physical address is not page aligned. So align the address to page size before assigning it to the page frame virtual address field. Signed-off-by: Daniel Leung --- kernel/mmu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/mmu.c b/kernel/mmu.c index 12dd369913e..1da5496e966 100644 --- a/kernel/mmu.c +++ b/kernel/mmu.c @@ -1288,7 +1288,9 @@ static bool do_page_fault(void *addr, bool pin) pf->flags |= Z_PAGE_FRAME_PINNED; } pf->flags |= Z_PAGE_FRAME_MAPPED; - pf->addr = addr; + pf->addr = UINT_TO_POINTER(POINTER_TO_UINT(addr) + & ~(CONFIG_MMU_PAGE_SIZE - 1)); + arch_mem_page_in(addr, z_page_frame_to_phys(pf)); k_mem_paging_backing_store_page_finalize(pf, page_in_location); out: