diff --git a/arch/x86_64/kernel/include/arch-memory.h b/arch/x86_64/kernel/include/arch-memory.h index e38d5e28..ab6b918b 100644 --- a/arch/x86_64/kernel/include/arch-memory.h +++ b/arch/x86_64/kernel/include/arch-memory.h @@ -42,10 +42,24 @@ #define USER_END 0x0000800000000000UL #define TASK_UNMAPPED_BASE 0x00002AAAAAA00000UL + +/* + * Canonical negative addresses (i.e., the smallest kernel virtual address) + * on x86 64 bit mode (in its most restricted 48 bit format) starts from + * 0xffff800000000000, but Linux starts mapping physical memory at 0xffff880000000000. + * The 0x80000000000 long gap (8TBs, i.e., 16 PGD level entries in the page tables) + * is used for Xen hyervisor (see arch/x86/include/asm/page.h) and that is + * what we utilize for McKernel. + * This gives us the benefit of being able to use Linux kernel virtual + * addresses identically as in Linux. + * + * NOTE: update these also in eclair.c when modified! + */ #define MAP_ST_START 0xffff800000000000UL -#define MAP_VMAP_START 0xfffff00000000000UL -#define MAP_FIXED_START 0xffffffff70000000UL -#define MAP_KERNEL_START 0xffffffff80000000UL +#define MAP_VMAP_START 0xffff850000000000UL +#define MAP_FIXED_START 0xffff860000000000UL +#define MAP_KERNEL_START 0xffff870000000000UL +#define LINUX_PAGE_OFFSET 0xffff880000000000UL #define STACK_TOP(region) ((region)->user_end) #define MAP_VMAP_SIZE 0x0000000100000000UL diff --git a/arch/x86_64/kernel/memory.c b/arch/x86_64/kernel/memory.c index c7ccee7f..da77aad6 100644 --- a/arch/x86_64/kernel/memory.c +++ b/arch/x86_64/kernel/memory.c @@ -191,6 +191,28 @@ static void init_normal_area(struct page_table *pt) } } +static void init_linux_kernel_mapping(struct page_table *pt) +{ + unsigned long map_start, map_end, phys, pt_phys; + int virt_index; + + map_start = 0; + /* Map 2 TB for now */ + map_end = 0x20000000000; + + kprintf("Linux kernel virtual: 0x%lx - 0x%lx -> 0x%lx - 0x%lx\n", + LINUX_PAGE_OFFSET, LINUX_PAGE_OFFSET + map_end, 0, map_end); + virt_index = (MAP_ST_START >> PTL4_SHIFT) & (PT_ENTRIES - 1); + + 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[virt_index++] = pt_phys | PFL4_PDIR_ATTR; + } +} + static struct page_table *__alloc_new_pt(ihk_mc_ap_flag ap_flag) { struct page_table *newpt = ihk_mc_alloc_pages(1, ap_flag); @@ -2628,6 +2650,7 @@ void init_page_table(void) /* Normal memory area */ init_normal_area(init_pt); + init_linux_kernel_mapping(init_pt); init_fixed_area(init_pt); init_low_area(init_pt); init_text_area(init_pt); diff --git a/kernel/config/smp-x86.lds b/kernel/config/smp-x86.lds index 9f4b0832..421caa08 100644 --- a/kernel/config/smp-x86.lds +++ b/kernel/config/smp-x86.lds @@ -5,7 +5,7 @@ PHDRS } SECTIONS { - . = 0xffffffff80001000; + . = 0xffff870000001000; _head = .; .text : {