Commit dafe41ee authored by Vivek Goyal's avatar Vivek Goyal Committed by Andi Kleen

[PATCH] x86-64: Kill temp boot pmds

Early in the boot process we need the ability to set
up temporary mappings, before our normal mechanisms are
initialized.  Currently this is used to map pages that
are part of the page tables we are building and pages
during the dmi scan.

The core problem is that we are using the user portion of
the page tables to implement this.  Which means that while
this mechanism is active we cannot catch NULL pointer dereferences
and we deviate from the normal ways of handling things.

In this patch I modify early_ioremap to map pages into
the kernel portion of address space, roughly where
we will later put modules, and I make the discovery of
which addresses we can use dynamic which removes all
kinds of static limits and remove the dependencies
on implementation details between different parts of the code.

Now alloc_low_page() and unmap_low_page() use
early_iomap() and early_iounmap() to allocate/map and
unmap a page.
Signed-off-by: default avatarEric W. Biederman <ebiederm@xmission.com>
Signed-off-by: default avatarVivek Goyal <vgoyal@in.ibm.com>
Signed-off-by: default avatarAndi Kleen <ak@suse.de>
parent 9d291e78
...@@ -288,9 +288,6 @@ NEXT_PAGE(level2_ident_pgt) ...@@ -288,9 +288,6 @@ NEXT_PAGE(level2_ident_pgt)
.quad i << 21 | 0x083 .quad i << 21 | 0x083
i = i + 1 i = i + 1
.endr .endr
/* Temporary mappings for the super early allocator in arch/x86_64/mm/init.c */
.globl temp_boot_pmds
temp_boot_pmds:
.fill 492,8,0 .fill 492,8,0
NEXT_PAGE(level2_kernel_pgt) NEXT_PAGE(level2_kernel_pgt)
......
...@@ -167,23 +167,9 @@ __set_fixmap (enum fixed_addresses idx, unsigned long phys, pgprot_t prot) ...@@ -167,23 +167,9 @@ __set_fixmap (enum fixed_addresses idx, unsigned long phys, pgprot_t prot)
unsigned long __initdata table_start, table_end; unsigned long __initdata table_start, table_end;
extern pmd_t temp_boot_pmds[]; static __meminit void *alloc_low_page(unsigned long *phys)
static struct temp_map {
pmd_t *pmd;
void *address;
int allocated;
} temp_mappings[] __initdata = {
{ &temp_boot_pmds[0], (void *)(40UL * 1024 * 1024) },
{ &temp_boot_pmds[1], (void *)(42UL * 1024 * 1024) },
{}
};
static __meminit void *alloc_low_page(int *index, unsigned long *phys)
{ {
struct temp_map *ti; unsigned long pfn = table_end++;
int i;
unsigned long pfn = table_end++, paddr;
void *adr; void *adr;
if (after_bootmem) { if (after_bootmem) {
...@@ -194,57 +180,63 @@ static __meminit void *alloc_low_page(int *index, unsigned long *phys) ...@@ -194,57 +180,63 @@ static __meminit void *alloc_low_page(int *index, unsigned long *phys)
if (pfn >= end_pfn) if (pfn >= end_pfn)
panic("alloc_low_page: ran out of memory"); panic("alloc_low_page: ran out of memory");
for (i = 0; temp_mappings[i].allocated; i++) {
if (!temp_mappings[i].pmd) adr = early_ioremap(pfn * PAGE_SIZE, PAGE_SIZE);
panic("alloc_low_page: ran out of temp mappings");
}
ti = &temp_mappings[i];
paddr = (pfn << PAGE_SHIFT) & PMD_MASK;
set_pmd(ti->pmd, __pmd(paddr | _KERNPG_TABLE | _PAGE_PSE));
ti->allocated = 1;
__flush_tlb();
adr = ti->address + ((pfn << PAGE_SHIFT) & ~PMD_MASK);
memset(adr, 0, PAGE_SIZE); memset(adr, 0, PAGE_SIZE);
*index = i; *phys = pfn * PAGE_SIZE;
*phys = pfn * PAGE_SIZE; return adr;
return adr; }
}
static __meminit void unmap_low_page(int i) static __meminit void unmap_low_page(void *adr)
{ {
struct temp_map *ti;
if (after_bootmem) if (after_bootmem)
return; return;
ti = &temp_mappings[i]; early_iounmap(adr, PAGE_SIZE);
set_pmd(ti->pmd, __pmd(0));
ti->allocated = 0;
} }
/* Must run before zap_low_mappings */ /* Must run before zap_low_mappings */
__init void *early_ioremap(unsigned long addr, unsigned long size) __init void *early_ioremap(unsigned long addr, unsigned long size)
{ {
unsigned long map = round_down(addr, LARGE_PAGE_SIZE); unsigned long vaddr;
pmd_t *pmd, *last_pmd;
/* actually usually some more */ int i, pmds;
if (size >= LARGE_PAGE_SIZE) {
return NULL; pmds = ((addr & ~PMD_MASK) + size + ~PMD_MASK) / PMD_SIZE;
vaddr = __START_KERNEL_map;
pmd = level2_kernel_pgt;
last_pmd = level2_kernel_pgt + PTRS_PER_PMD - 1;
for (; pmd <= last_pmd; pmd++, vaddr += PMD_SIZE) {
for (i = 0; i < pmds; i++) {
if (pmd_present(pmd[i]))
goto next;
}
vaddr += addr & ~PMD_MASK;
addr &= PMD_MASK;
for (i = 0; i < pmds; i++, addr += PMD_SIZE)
set_pmd(pmd + i,__pmd(addr | _KERNPG_TABLE | _PAGE_PSE));
__flush_tlb();
return (void *)vaddr;
next:
;
} }
set_pmd(temp_mappings[0].pmd, __pmd(map | _KERNPG_TABLE | _PAGE_PSE)); printk("early_ioremap(0x%lx, %lu) failed\n", addr, size);
map += LARGE_PAGE_SIZE; return NULL;
set_pmd(temp_mappings[1].pmd, __pmd(map | _KERNPG_TABLE | _PAGE_PSE));
__flush_tlb();
return temp_mappings[0].address + (addr & (LARGE_PAGE_SIZE-1));
} }
/* To avoid virtual aliases later */ /* To avoid virtual aliases later */
__init void early_iounmap(void *addr, unsigned long size) __init void early_iounmap(void *addr, unsigned long size)
{ {
if ((void *)round_down((unsigned long)addr, LARGE_PAGE_SIZE) != temp_mappings[0].address) unsigned long vaddr;
printk("early_iounmap: bad address %p\n", addr); pmd_t *pmd;
set_pmd(temp_mappings[0].pmd, __pmd(0)); int i, pmds;
set_pmd(temp_mappings[1].pmd, __pmd(0));
vaddr = (unsigned long)addr;
pmds = ((vaddr & ~PMD_MASK) + size + ~PMD_MASK) / PMD_SIZE;
pmd = level2_kernel_pgt + pmd_index(vaddr);
for (i = 0; i < pmds; i++)
pmd_clear(pmd + i);
__flush_tlb(); __flush_tlb();
} }
...@@ -289,7 +281,6 @@ static void __meminit phys_pud_init(pud_t *pud_page, unsigned long addr, unsigne ...@@ -289,7 +281,6 @@ static void __meminit phys_pud_init(pud_t *pud_page, unsigned long addr, unsigne
for (; i < PTRS_PER_PUD; i++, addr = (addr & PUD_MASK) + PUD_SIZE ) { for (; i < PTRS_PER_PUD; i++, addr = (addr & PUD_MASK) + PUD_SIZE ) {
int map;
unsigned long pmd_phys; unsigned long pmd_phys;
pud_t *pud = pud_page + pud_index(addr); pud_t *pud = pud_page + pud_index(addr);
pmd_t *pmd; pmd_t *pmd;
...@@ -307,12 +298,12 @@ static void __meminit phys_pud_init(pud_t *pud_page, unsigned long addr, unsigne ...@@ -307,12 +298,12 @@ static void __meminit phys_pud_init(pud_t *pud_page, unsigned long addr, unsigne
continue; continue;
} }
pmd = alloc_low_page(&map, &pmd_phys); pmd = alloc_low_page(&pmd_phys);
spin_lock(&init_mm.page_table_lock); spin_lock(&init_mm.page_table_lock);
set_pud(pud, __pud(pmd_phys | _KERNPG_TABLE)); set_pud(pud, __pud(pmd_phys | _KERNPG_TABLE));
phys_pmd_init(pmd, addr, end); phys_pmd_init(pmd, addr, end);
spin_unlock(&init_mm.page_table_lock); spin_unlock(&init_mm.page_table_lock);
unmap_low_page(map); unmap_low_page(pmd);
} }
__flush_tlb(); __flush_tlb();
} }
...@@ -364,7 +355,6 @@ void __meminit init_memory_mapping(unsigned long start, unsigned long end) ...@@ -364,7 +355,6 @@ void __meminit init_memory_mapping(unsigned long start, unsigned long end)
end = (unsigned long)__va(end); end = (unsigned long)__va(end);
for (; start < end; start = next) { for (; start < end; start = next) {
int map;
unsigned long pud_phys; unsigned long pud_phys;
pgd_t *pgd = pgd_offset_k(start); pgd_t *pgd = pgd_offset_k(start);
pud_t *pud; pud_t *pud;
...@@ -372,7 +362,7 @@ void __meminit init_memory_mapping(unsigned long start, unsigned long end) ...@@ -372,7 +362,7 @@ void __meminit init_memory_mapping(unsigned long start, unsigned long end)
if (after_bootmem) if (after_bootmem)
pud = pud_offset(pgd, start & PGDIR_MASK); pud = pud_offset(pgd, start & PGDIR_MASK);
else else
pud = alloc_low_page(&map, &pud_phys); pud = alloc_low_page(&pud_phys);
next = start + PGDIR_SIZE; next = start + PGDIR_SIZE;
if (next > end) if (next > end)
...@@ -380,7 +370,7 @@ void __meminit init_memory_mapping(unsigned long start, unsigned long end) ...@@ -380,7 +370,7 @@ void __meminit init_memory_mapping(unsigned long start, unsigned long end)
phys_pud_init(pud, __pa(start), __pa(next)); phys_pud_init(pud, __pa(start), __pa(next));
if (!after_bootmem) if (!after_bootmem)
set_pgd(pgd_offset_k(start), mk_kernel_pgd(pud_phys)); set_pgd(pgd_offset_k(start), mk_kernel_pgd(pud_phys));
unmap_low_page(map); unmap_low_page(pud);
} }
if (!after_bootmem) if (!after_bootmem)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment