Fixes bugs with larger kstack allocation
authorBarret Rhoden <brho@cs.berkeley.edu>
Sat, 5 Oct 2013 00:09:54 +0000 (17:09 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 16 Jan 2014 02:19:03 +0000 (18:19 -0800)
Was asking for a 0-order alloc in kthread, and the smp boot code wasn't
looking at the bottom of the stack (it was looking at the bottom of the
first page on the receiving end).

kern/arch/x86/smp_boot.c
kern/src/kthread.c

index 3e32007..8f8eb4e 100644 (file)
@@ -292,7 +292,7 @@ uintptr_t smp_main(void)
  * to call it on too deep of a stack frame. */
 void __arch_pcpu_init(uint32_t coreid)
 {
-       uintptr_t my_stack_bot;
+       uintptr_t *my_stack_bot;
        struct per_cpu_info *pcpui = &per_cpu_info[coreid];
 
        /* Flushes any potentially old mappings from smp_boot() (note the page table
@@ -311,9 +311,9 @@ void __arch_pcpu_init(uint32_t coreid)
                pcpui->tss = &ts;
                pcpui->gdt = gdt;
        } else {
-               my_stack_bot = ROUNDDOWN(read_sp(), PGSIZE);
-               pcpui->tss = (taskstate_t*)(*(uintptr_t*)my_stack_bot);
-               pcpui->gdt = (segdesc_t*)(*(uintptr_t*)my_stack_bot +
+               my_stack_bot = kstack_bottom_addr(ROUNDUP(read_sp() - 1, PGSIZE));
+               pcpui->tss = (taskstate_t*)(*my_stack_bot);
+               pcpui->gdt = (segdesc_t*)(*my_stack_bot +
                                          sizeof(taskstate_t) + sizeof(pseudodesc_t));
        }
 #ifdef CONFIG_X86_64
index 06a70ba..5494ab8 100644 (file)
@@ -18,7 +18,7 @@ uintptr_t get_kstack(void)
        if (KSTKSIZE == PGSIZE)
                stackbot = (uintptr_t)kpage_alloc_addr();
        else
-               stackbot = (uintptr_t)get_cont_pages(KSTKSHIFT >> PGSHIFT, 0);
+               stackbot = (uintptr_t)get_cont_pages(KSTKSHIFT - PGSHIFT, 0);
        assert(stackbot);
        return stackbot + KSTKSIZE;
 }
@@ -29,7 +29,7 @@ void put_kstack(uintptr_t stacktop)
        if (KSTKSIZE == PGSIZE)
                page_decref(kva2page((void*)stackbot));
        else
-               free_cont_pages((void*)stackbot, KSTKSHIFT >> PGSHIFT);
+               free_cont_pages((void*)stackbot, KSTKSHIFT - PGSHIFT);
 }
 
 uintptr_t *kstack_bottom_addr(uintptr_t stacktop)