From 3ce77637153876cd12f5aa0c7b8a86bf5d42ee00 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Tue, 17 Jul 2018 18:03:59 +0900 Subject: [PATCH] x86 mem init: do not map identity mapping init_normal_area was mapping identity lookups (phys = virt) from 0, leading to many undetected null pointer dereferences in init_pt (but not in new process page tables leading to odd behaviour) This also makes the code use the set_pt_large_page() function, cleaning it up a bit Change-Id: I22889031de26a7e48501b0eb4d453ca62e671835 --- arch/x86_64/kernel/memory.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/arch/x86_64/kernel/memory.c b/arch/x86_64/kernel/memory.c index 14c29192..d0e38470 100644 --- a/arch/x86_64/kernel/memory.c +++ b/arch/x86_64/kernel/memory.c @@ -170,24 +170,21 @@ static unsigned long setup_l3(struct page_table *pt, static void init_normal_area(struct page_table *pt) { unsigned long map_start, map_end, phys, pt_phys; - int ident_index, virt_index; + void *virt; map_start = ihk_mc_get_memory_address(IHK_MC_GMA_MAP_START, 0); map_end = ihk_mc_get_memory_address(IHK_MC_GMA_MAP_END, 0); + virt = (void *)MAP_ST_START + map_start; - kprintf("map_start = %lx, map_end = %lx\n", map_start, map_end); - ident_index = map_start >> PTL4_SHIFT; - virt_index = (MAP_ST_START >> PTL4_SHIFT) & (PT_ENTRIES - 1); + kprintf("map_start = %lx, map_end = %lx, virt %lx\n", + map_start, map_end, virt); - memset(pt, 0, sizeof(struct page_table)); - - for (phys = (map_start & ~(PTL4_SIZE - 1)); phys < map_end; - phys += PTL4_SIZE) { - pt_phys = setup_l3(ihk_mc_alloc_pages(1, IHK_MC_AP_CRITICAL), phys, - map_start, map_end); - - pt->entry[ident_index++] = pt_phys | PFL4_PDIR_ATTR; - pt->entry[virt_index++] = pt_phys | PFL4_PDIR_ATTR; + for (phys = map_start; phys < map_end; phys += LARGE_PAGE_SIZE) { + if (set_pt_large_page(pt, virt, phys, PTATTR_WRITABLE) != 0) { + kprintf("%s: error setting mapping for 0x%lx\n", + __func__, virt); + } + virt += LARGE_PAGE_SIZE; } }