[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] x86/setup: move CPU0s stack out of the Xen text/data/bss virtual region



commit a92efb747bbf256c20278517dfc179ced84bb869
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Mon Jun 8 14:16:27 2015 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Mon Jun 8 14:16:27 2015 +0200

    x86/setup: move CPU0s stack out of the Xen text/data/bss virtual region
    
    Currently, the BSP's stack is the BSS symbol cpu0_stack.  In builds using
    memguard_stack(), a page gets shot out of the mappings.
    
    To avoid shattering the superpage which will eventually map the BSS, use the
    directmap virtual address of cpu0_stack, while still using the same 
underlying
    physical memory.  (Xen has an order 21 physical relocation requirement 
meaning
    that the order 3 alignment requirement for cpu0_stack will be honoured even
    via its diretmap mapping.)
    
    In addition, fix two issues exposed by the changes.
    
     * do_invalid_op() should use is_active_kernel_text() rather than having its
       own, different, idea of when to search through the bugframes.
     * Setting of system_state to active needs to be deferred until after code 
has
       left .init.text, for bugframes/backtraces to function in 
reinit_bsp_stack().
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/arch/x86/setup.c |   34 ++++++++++++++++++++++++++--------
 xen/arch/x86/traps.c |    3 +--
 2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index d3c1817..c32e49f 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -507,6 +507,10 @@ static void __init kexec_reserve_area(struct e820map *e820)
 
 static void noinline init_done(void)
 {
+    system_state = SYS_STATE_active;
+
+    domain_unpause_by_systemcontroller(hardware_domain);
+
     /* Free (or page-protect) the init areas. */
     memset(__init_begin, 0xcc, __init_end - __init_begin); /* int3 poison */
     free_xen_data(__init_begin, __init_end);
@@ -515,6 +519,23 @@ static void noinline init_done(void)
     startup_cpu_idle_loop();
 }
 
+/* Reinitalise all state referring to the old virtual address of the stack. */
+static void __init noreturn reinit_bsp_stack(void)
+{
+    unsigned long *stack = (void*)(get_stack_bottom() & ~(STACK_SIZE - 1));
+
+    /* Update TSS and ISTs */
+    load_system_tables();
+
+    /* Update SYSCALL trampolines */
+    percpu_traps_init();
+
+    stack_base[0] = stack;
+    memguard_guard_stack(stack);
+
+    reset_stack_and_jump(init_done);
+}
+
 static bool_t __init loader_is_grub2(const char *loader_name)
 {
     /* GRUB1="GNU GRUB 0.xx"; GRUB2="GRUB 1.xx" */
@@ -1210,9 +1231,6 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     tboot_probe();
 
-    /* Unmap the first page of CPU0's stack. */
-    memguard_guard_stack(cpu0_stack);
-
     open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period);
 
     if ( opt_watchdog ) 
@@ -1454,11 +1472,11 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     setup_io_bitmap(dom0);
 
-    system_state = SYS_STATE_active;
-
-    domain_unpause_by_systemcontroller(dom0);
-
-    reset_stack_and_jump(init_done);
+    /* Jump to the 1:1 virtual mappings of cpu0_stack. */
+    asm volatile ("mov %[stk], %%rsp; jmp %c[fn]" ::
+                  [stk] "g" (__va(__pa(get_stack_bottom()))),
+                  [fn] "i" (reinit_bsp_stack) : "memory");
+    unreachable();
 }
 
 void arch_get_xen_caps(xen_capabilities_info_t *info)
diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c
index 91701a2..080c0c1 100644
--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -1072,8 +1072,7 @@ void do_invalid_op(struct cpu_user_regs *regs)
         return;
     }
 
-    if ( (!is_kernel_text(eip) &&
-          (system_state > SYS_STATE_boot || !is_kernel_inittext(eip))) ||
+    if ( !is_active_kernel_text(regs->eip) ||
          __copy_from_user(bug_insn, eip, sizeof(bug_insn)) ||
          memcmp(bug_insn, "\xf\xb", sizeof(bug_insn)) )
         goto die;
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.