Woops -- we shared the stack across CPUs. To fix this, let the CPU consume the stack pointer held by 'stack'. In case of the parallel cell startup, only the primary CPU will consume the stack.
After setting the stack, the consumer will zero the variable to signalise that it's ready (cf. ap_entry). Even if we don't support SMP for 32 bit inmates, align 32 bit header code, as well as 64 bit header code. Signed-off-by: Ralf Ramsauer <[email protected]> --- inmates/lib/x86/header-32.S | 3 ++- inmates/lib/x86/header.S | 3 ++- inmates/lib/x86/include/inmate.h | 1 + inmates/lib/x86/setup.c | 2 ++ inmates/lib/x86/smp.c | 3 ++- 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/inmates/lib/x86/header-32.S b/inmates/lib/x86/header-32.S index 006cce9a..a0f2d878 100644 --- a/inmates/lib/x86/header-32.S +++ b/inmates/lib/x86/header-32.S @@ -104,7 +104,8 @@ start32: mov $c_entry,%ebx call_entry: - mov $stack_top,%esp + xor %esp, %esp + xchg stack, %esp call *%ebx stop: cli diff --git a/inmates/lib/x86/header.S b/inmates/lib/x86/header.S index cb886b8e..978decb3 100644 --- a/inmates/lib/x86/header.S +++ b/inmates/lib/x86/header.S @@ -108,7 +108,8 @@ start64: mov $c_entry,%rbx call_entry: - mov $stack_top,%rsp + xor %rsp, %rsp + xchg stack, %rsp callq *%rbx stop: cli diff --git a/inmates/lib/x86/include/inmate.h b/inmates/lib/x86/include/inmate.h index e57d7271..a3d7601b 100644 --- a/inmates/lib/x86/include/inmate.h +++ b/inmates/lib/x86/include/inmate.h @@ -221,6 +221,7 @@ static inline unsigned int cpu_id(void) #define MAX_INTERRUPT_VECTORS 32 extern unsigned long idt[]; +extern void *stack; void excp_reporting_init(void); diff --git a/inmates/lib/x86/setup.c b/inmates/lib/x86/setup.c index a1455993..807db99e 100644 --- a/inmates/lib/x86/setup.c +++ b/inmates/lib/x86/setup.c @@ -42,6 +42,8 @@ #define AUTHENTIC_AMD(n) (((const u32 *)"AuthenticAMD")[n]) +void *stack = (void*)stack_top; + struct desc_table_reg { u16 limit; unsigned long base; diff --git a/inmates/lib/x86/smp.c b/inmates/lib/x86/smp.c index 9b983611..94ce2913 100644 --- a/inmates/lib/x86/smp.c +++ b/inmates/lib/x86/smp.c @@ -54,6 +54,7 @@ void smp_start_cpu(unsigned int cpu_id, void (*entry)(void)) u64 base_val = ((u64)cpu_id << 32) | APIC_LVL_ASSERT; ap_entry = entry; + stack = alloc(PAGE_SIZE, PAGE_SIZE) + PAGE_SIZE; write_msr(X2APIC_ICR, base_val | APIC_DM_INIT); delay_us(10000); @@ -61,6 +62,6 @@ void smp_start_cpu(unsigned int cpu_id, void (*entry)(void)) delay_us(200); write_msr(X2APIC_ICR, base_val | APIC_DM_SIPI); - while (ap_entry != NULL) + while (ap_entry && stack) cpu_relax(); } -- 2.22.0 -- You received this message because you are subscribed to the Google Groups "Jailhouse" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jailhouse-dev/20190613200442.18984-2-ralf.ramsauer%40oth-regensburg.de. For more options, visit https://groups.google.com/d/optout.
