]> xenbits.xensource.com Git - people/hx242/xen.git/commitdiff
x86/mm: actually map the cpu0_stack to the per-domain region perdom-stack
authorHongyan Xia <hongyxia@amazon.com>
Wed, 24 Jun 2020 08:52:04 +0000 (09:52 +0100)
committerHongyan Xia <hongyxia@amazon.com>
Wed, 24 Jun 2020 10:57:25 +0000 (11:57 +0100)
We pass in an optional argument for load_system_tables() to specify a
separate stack for #DF. Since we are modifying the virtual address
layout of the stacks, it is better to always be certain that there is a
fallback #DF stack we can always rely on.

Signed-off-by: Hongyan Xia <hongyxia@amazon.com>
xen/arch/x86/cpu/common.c
xen/arch/x86/domain.c
xen/arch/x86/setup.c
xen/arch/x86/smpboot.c
xen/arch/x86/x86_64/traps.c
xen/include/asm-x86/system.h

index da74172776a7cfbdb3f38d740745612d1488c8d3..d52fd671522b23ecf639b121f77d066a0a146396 100644 (file)
@@ -733,7 +733,7 @@ static cpumask_t cpu_initialized;
  * - Loads GDT, IDT, TR then null LDT
  * - Sets up IST references in the IDT
  */
-void load_system_tables(void)
+void load_system_tables(void *df_stacktop)
 {
        unsigned int i, cpu = smp_processor_id();
        unsigned long stack_bottom = get_stack_bottom(),
@@ -770,7 +770,7 @@ void load_system_tables(void)
        tss->ist[IST_MCE - 1] = stack_top + (1 + IST_MCE) * PAGE_SIZE;
        tss->ist[IST_NMI - 1] = stack_top + (1 + IST_NMI) * PAGE_SIZE;
        tss->ist[IST_DB  - 1] = stack_top + (1 + IST_DB)  * PAGE_SIZE;
-       tss->ist[IST_DF  - 1] = stack_top + (1 + IST_DF)  * PAGE_SIZE;
+       tss->ist[IST_DF  - 1] = ((unsigned long)df_stacktop ?: stack_top) + (1 + IST_DF)  * PAGE_SIZE;
        tss->bitmap = IOBMP_INVALID_OFFSET;
 
        /* All other stack pointers poisioned. */
index fee6c3931a6064cb3aacfb1d874fad1e3592148e..dcab3b129c782b515d8a48891b42b81e8e28aa63 100644 (file)
@@ -528,6 +528,26 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
     return true;
 }
 
+extern char cpu0_stack[STACK_SIZE];
+
+void populate_perdom_stack(struct domain *d)
+{
+    int idx;
+
+    l3_pgentry_t *l3t = __map_domain_page(d->arch.perdomain_l3_pg);
+    l2_pgentry_t *l2t = map_l2t_from_l3e(l3t[l3_table_offset(PERDOMAIN_STACK_BOTTOM)]);
+    l1_pgentry_t *l1t = map_l1t_from_l2e(l2t[l2_table_offset(PERDOMAIN_STACK_BOTTOM)]);
+    /* Point the mappings to cpu0_stack. */
+    printk("The perdom stack bottom is %#lx\n", virt_to_maddr(cpu0_stack));
+    for ( idx = 0; idx < (1 << STACK_ORDER); idx++ )
+        l1e_write(&l1t[idx],
+                  l1e_from_pfn(virt_to_mfn(cpu0_stack) + idx, PAGE_HYPERVISOR));
+
+    unmap_domain_page(l1t);
+    unmap_domain_page(l2t);
+    unmap_domain_page(l3t);
+}
+
 int arch_domain_create(struct domain *d,
                        struct xen_domctl_createdomain *config)
 {
@@ -539,6 +559,13 @@ int arch_domain_create(struct domain *d,
 
     spin_lock_init(&d->arch.e820_lock);
 
+    /* Create the page table entries, but they are still not mapped. */
+    rc = create_perdomain_mapping(d, PERDOMAIN_STACK_BOTTOM, 1U << STACK_ORDER,
+                                  NIL(l1_pgentry_t *), NULL);
+    if ( rc )
+        return rc;
+    populate_perdom_stack(d);
+
     /* Minimal initialisation for the idle domain. */
     if ( unlikely(is_idle_domain(d)) )
     {
index 2aa1cd50b8540d8528b343c6e5e1e5a159f4577a..0a525a7f0866d0c6f9a2e9e2a4cf6e105adc2065 100644 (file)
@@ -656,13 +656,13 @@ 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();
+    load_system_tables(__va(__pa(cpu0_stack)));
 
     /* Update SYSCALL trampolines */
     percpu_traps_init();
 
     stack_base[0] = stack;
-    memguard_guard_stack(stack);
+    //memguard_guard_stack(stack);
 
     if ( IS_ENABLED(CONFIG_XEN_SHSTK) && cpu_has_xen_shstk )
     {
@@ -833,7 +833,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     percpu_init_areas();
 
     init_idt_traps();
-    load_system_tables();
+    load_system_tables(NULL);
 
     smp_prepare_boot_cpu();
     sort_exception_tables();
@@ -1924,9 +1924,11 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         wrmsrl(MSR_SPEC_CTRL, default_xen_spec_ctrl);
     }
 
+    printk("The stack bottom is %#lx\n", __pa(get_stack_bottom()));
+
     /* 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()))),
+                  [stk] "g" (PERDOMAIN_STACK_BOTTOM + (get_stack_bottom() & (STACK_SIZE-1))),
                   [fn] "i" (reinit_bsp_stack) : "memory");
     unreachable();
 }
index 5708573c417bb768656ebe222faec82483e02863..f4827658e190a92680ad80bc7f6e2f83091dc073 100644 (file)
@@ -356,7 +356,7 @@ void start_secondary(void *unused)
     get_cpu_info()->xen_cr3 = 0;
     get_cpu_info()->pv_cr3 = 0;
 
-    load_system_tables();
+    load_system_tables(NULL);
 
     /* Full exception support from here on in. */
 
index 93af0c5e879629795d4c2e8c754e4e1de3cb3be5..a7ca86911b07d1102734e26e70c3bd2df4527e8c 100644 (file)
@@ -263,6 +263,7 @@ void do_double_fault(struct cpu_user_regs *regs)
     _show_registers(regs, crs, CTXT_hypervisor, NULL);
     show_code(regs);
     show_stack_overflow(cpu, regs);
+    show_page_walk(read_cr2());
 
     panic("DOUBLE FAULT -- system shutdown\n");
 }
index 7e5891f3dfafbfec923cea31fdaa056e55c5c5ca..3d17ec62a2199fb9aeeba02dcecbf70edb6b7826 100644 (file)
@@ -301,7 +301,7 @@ static inline int local_irq_is_enabled(void)
 
 void trap_init(void);
 void init_idt_traps(void);
-void load_system_tables(void);
+void load_system_tables(void*);
 void percpu_traps_init(void);
 void subarch_percpu_traps_init(void);