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

[Xen-devel] [PATCH RFC 35/44] x86/smp: Allocate the stack in the percpu range



This involves allocating a total of 5 frames, which don't have to be an
order-3 allocation, and unconditionally has guard pages in place for a primary
stack overflow.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
 xen/arch/x86/smpboot.c       | 27 ++++++++++++++++++++++++++-
 xen/include/asm-x86/config.h |  2 ++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c
index cc80f24..1bf6dc1 100644
--- a/xen/arch/x86/smpboot.c
+++ b/xen/arch/x86/smpboot.c
@@ -762,7 +762,7 @@ static int percpu_alloc_frame(unsigned int cpu, unsigned 
long linear,
 /* Allocate data common between the BSP and APs. */
 static int cpu_smpboot_alloc_common(unsigned int cpu)
 {
-    unsigned int memflags = 0;
+    unsigned int memflags = 0, i;
     nodeid_t node = cpu_to_node(cpu);
     l4_pgentry_t *l4t = NULL;
     l3_pgentry_t *l3t = NULL;
@@ -843,6 +843,31 @@ static int cpu_smpboot_alloc_common(unsigned int cpu)
     if ( rc )
         goto out;
 
+    /* Allocate the stack. */
+    for ( i = 0; i < 8; ++i )
+    {
+        BUILD_BUG_ON((1u << STACK_ORDER) != 8);
+        BUILD_BUG_ON(!IS_ALIGNED(PERCPU_STACK_MAPPING, STACK_SIZE));
+        BUILD_BUG_ON((sizeof(struct cpu_info) -
+                      offsetof(struct cpu_info, guest_cpu_user_regs.es)) & 
0xf);
+
+        /*
+         * Pages 0-2: #DF, #NMI, #MCE IST stacks
+         * Pages 3-5: Guard pages - UNMAPPED
+         * Pages 6-7: Main stack
+         */
+        if ( i == 3 )
+        {
+            i = 5;
+            continue;
+        }
+
+        rc = percpu_alloc_frame(cpu, PERCPU_STACK_MAPPING + i * PAGE_SIZE, 
NULL,
+                                PAGE_HYPERVISOR_RW | MAP_PERCPU_AUTOFREE);
+        if ( rc )
+            goto out;
+    }
+
     rc = 0; /* Success */
 
  out:
diff --git a/xen/include/asm-x86/config.h b/xen/include/asm-x86/config.h
index cf6f1be..3974748 100644
--- a/xen/include/asm-x86/config.h
+++ b/xen/include/asm-x86/config.h
@@ -296,6 +296,8 @@ extern unsigned long xen_phys_start;
 #define PERCPU_LDT_MAPPING       (PERCPU_LINEAR_START + MB(11))
 #define PERCPU_LDT_MAPPING_END   (PERCPU_LDT_MAPPING + 0x10000)
 
+#define PERCPU_STACK_MAPPING     (PERCPU_LINEAR_START + MB(12))
+
 #define MAX_VIRT_CPUS            8192
 
 #define NATIVE_VM_ASSIST_VALID   ((1UL << VMASST_TYPE_4gb_segments)        | \
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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