x86_64 SMP support (status update)
Below is the patch I've been working with to get x86_64 SMP support going. It's a definite work in progress. Currently, I'm able to build a second vcpu from dom0, but when it gets scheduled it crashes. Booting the same kernel with maxcpus=1 gets up to login prompt. Here's some known issues:
entry.S:
- preempt_{en,dis}able is commented out for now (due to thread_info)
- ugly shl,shr combo to clear upper 32 bits.smpboot.c:
- faults if writing to cpu_gdt_table[1], so doing bogus reuse of cpu 0 table entries directly
Here's a copy of the crash:
(XEN) (file=traps.c, line=459) Page fault: ffff83000014f67b -> ffff83000010b210 (XEN) Domain 0 (vcpu#1) crashed on cpu#1:
(XEN) CPU: 1
(XEN) EIP: e030:[<ffffffff801181d0>]
(XEN) EFLAGS: 0000000000010202
(XEN) rax: 0000000000735067 rbx: 0000000000000ff8 rcx: 0000000000000000 rdx: 0000000000000067 (XEN) rsi: 0000000020735067 rdi: ffff800000000000 rbp: 0000000000000ff8 rsp: ffff880000c36020 (XEN) r8: 0000000000000000 r9: 000000000000000b r10: ffffffff801181df r11: 0000000000000000 (XEN) r12: 0000000000000000 r13: 0000000000000000 r14: ffffffffff5fd023 r15: ffff880000c36120 (XEN) Xen stack trace from rsp=ffff880000c36020: (XEN) 0000ffff0000000f 0004000300020001 0008000700060005 ffff880000c40db0 ffff880000c36120 ffffffff803cba42 0000000000000000 0000000b0000000e (XEN) 0000000000000000 0000000000030001 0000000000000000 0000000000000000 0000000000000000 ffff880000c32800 0000000100000058 6c617475000000c3 (XEN) 0000000000636f6c 0000000100000000 eaeaeaeaeaeaeaea eaeaeaeaeaeaeaea eaeaeaeaeaeaeaea eaeaeaeaeaeaeaea eaeaeaeaeaeaeaea eaeaeaeaeaeaeaea (XEN) eaeaeaeaeaeaeaea 0000000000000000 0000000000000ff8 0000000000000000 0000000000000000 0000000000000ff8 ffff880000c362d8 ffffffff8010e4cb (XEN) ffff880000c362d8 0000000000000ff8 0000000000000000 0000000000000000 0000000000000ff8 0000000000000000 0000000000000000 ffffffff801181df (XEN) 000000000000000b 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 000000000000e030 ffffffffffffffff (XEN) ffffffff8010f33d 000000000000e030 0000000000010246 ffff880000c361c8 000000000000e02b 0000000000000ff8 ffffffff801188a0 ffffffff8043c2c0 (XEN) 0000000000000000 0000000000000000 ffff880000c40db0 ffff880000c362d8 ffffffff803cba42 0000000000000000 0000000b0000000e 0000000000000000 (XEN) 0000000000030001 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 00000007f0000022 ffff880000c36308 0000000000008124 0000000000000001 (XEN) 0000000000000ff8 0000000000000ff8 0000000000000000 0000000000000000 ffffffffff5fd023 ffff880000c36480 ffffffff8010e4cb ffff880000c36480 (XEN) ffffffffff5fd023 0000000000000000 0000000000000000 0000000000000ff8 0000000000000ff8 0000000000000000 ffffffff801181df 000000000000000b (XEN) 0000000000000000 0000000000735067 0000000000000000 0000000000000067 0000000020735067 ffff800000000000 ffffffffffffffff ffffffff801181d0 (XEN) 000000000000e030 0000000000010202 ffff880000c36380 000000000000e02b 00000006f0000021 ffff880000c36408 0000000000008124 ffff880000c40db0 (XEN) ffff880000c36480 ffffffff803cba42 0000000000000000 0000000b0000000e 0000000000000000 0000000000030001 ffff880000c36480 ffff880000c36680 (XEN) 0000000000000000 0000000000000000 ffffffff80190830 0000000000000000 0000000000000000 000073637369646c 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000ff8 0000000000000000 (XEN) 0000000000000000 0000000000000ff8 ffff880000c36638 ffffffff8010e4cb ffff880000c36638 0000000000000ff8 0000000000000000 0000000000000000 (XEN) 0000000000000ff8 0000000000000000 0000000000000000 ffffffff801181df 000000000000000b 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 000000000000e030 ffffffffffffffff ffffffff8010f33d 000000000000e030 0000000000010246 ffff880000c36528
(XEN) Xen call trace from rsp=ffff880000c36020:
(XEN) Trace empty.
(XEN) Domain 0 shutdown: rebooting machine.
And, here's the patch:
===== linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/Makefile 1.5 vs edited =====
linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/Makefile +2 -2
@@ -25,7 +25,7 @@ obj-$(CONFIG_ACPI_BOOT) += acpi/ obj-$(CONFIG_X86_MSR) += msr.o obj-$(CONFIG_MICROCODE) += microcode.o obj-$(CONFIG_X86_CPUID) += cpuid.o -#obj-$(CONFIG_SMP) += smp.o smpboot.o trampoline.o +obj-$(CONFIG_SMP) += smp.o smpboot.o trampoline.o obj-$(CONFIG_X86_LOCAL_APIC) += apic.o c-obj-$(CONFIG_X86_LOCAL_APIC) += nmi.o obj-$(CONFIG_X86_IO_APIC) += io_apic.o mpparse.o
@@ -53,7 +53,7 @@ intel_cacheinfo-y += ../../../i386/kern quirks-y += ../../../i386/kernel/quirks.o c-link := init_task.o -s-link := vsyscall.o +s-link := vsyscall.o trampoline.o $(patsubst %.o,$(obj)/%.c,$(c-obj-y) $(c-link)) $(patsubst %.o,$(obj)/%.S,$(s-obj-y) $(s-link)): ln -fsn $(srctree)/arch/x86_64/kernel/$(notdir $@) $@
linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/smp.c +33 -6
@@ -24,8 +24,13 @@#include <asm/mtrr.h> #include <asm/pgalloc.h> #include <asm/tlbflush.h> +#if 1 /* Xen */ #include <asm/mach_apic.h> +#endif #include <asm/proto.h> +#include <asm-xen/evtchn.h> + +#define xxprint (msg) HYPERVISOR_console_io(CONSOLEIO_write, strlen(msg), msg)/* * Smarter SMP flushing macros.
@@ -101,6 +106,7 @@ static inline void leave_mm (unsigned lo* 2) Leave the mm if we are in the lazy tlb mode. */ +#if 0 /* Xen */ asmlinkage void smp_invalidate_interrupt (void) {unsigned long cpu;
@@ -249,6 +255,20 @@ void flush_tlb_all(void)on_each_cpu (do_flush_tlb_all,NULL ,1 ,1 ); } +#else +asmlinkage void smp_invalidate_interrupt (void) +{return ; } +void flush_tlb_current_task (void ) +{xen_tlb_flush_mask (¤t->mm->cpu_vm_mask); } +void flush_tlb_mm (struct mm_struct * mm) +{xen_tlb_flush_mask (&mm->cpu_vm_mask); } +void flush_tlb_page (struct vm_area_struct * vma,unsigned long va) +{xen_invlpg_mask (&vma->vm_mm->cpu_vm_mask, va); } +void flush_tlb_all (void ) +{xen_tlb_flush_all (); } +#endif /* Xen */ + +void smp_kdb_stop (void ) {send_IPI_allbutself (KDB_VECTOR );
@@ -308,13 +328,13 @@ static void __smp_call_function (void (*/* Wait for response */ while (atomic_read (&data.started) != cpus) -cpu_relax (); +barrier ();if (!wait)return ;while (atomic_read (&data.finished) != cpus) -cpu_relax (); +barrier (); }/*
@@ -348,7 +368,11 @@ void smp_stop_cpu(void)*/ cpu_clear (smp_processor_id (), cpu_online_map);local_irq_disable (); +#if 1 +xxprint ("stop_this_cpu disable_local_APIC\n" ); +#else disable_local_APIC (); +#endif local_irq_enable (); }
@@ -362,8 +386,10 @@ static void smp_really_stop_cpu(void *duvoid smp_send_stop (void ) {int nolock =0 ; +#if 0 if (reboot_force)return ; +#endif /* Don't deadlock on the call lock in panic */ if (!spin_trylock (&call_lock)) {/* ignore locking because we have paniced anyways */
@@ -380,18 +406,17 @@ void smp_send_stop(void)* all the work is done automatically when * we return from the interrupt. */ -asmlinkage void smp_reschedule_interrupt(void) +asmlinkage irqreturn_t smp_reschedule_interrupt(void) { -ack_APIC_irq (); +return IRQ_HANDLED ; } -asmlinkage void smp_call_function_interrupt(void) +asmlinkage irqreturn_t smp_call_function_interrupt(void) {void (*func) (void *info) = call_data->func;void *info = call_data->info;int wait = call_data->wait; -ack_APIC_irq ();/* * Notify initiating CPU that I've grabbed the data and am * about to execute the function
@@ -408,4 +433,6 @@ asmlinkage void smp_call_function_interrmb ();atomic_inc (&call_data->finished); } + +return IRQ_HANDLED ; }
linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/smpboot.c +201 -18
442 lines not on this page · raw message
linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/traps.c +11 -0
@@ -957,6 +957,17 @@ void __init trap_init(void)cpu_init (); } +void smp_trap_init (trap_info_t *trap_ctxt) +{ +trap_info_t *t = trap_table; + +for (t = trap_table; t->address; t++) { + trap_ctxt[t->vector].flags = t->flags; + trap_ctxt[t->vector].cs = t->cs; + trap_ctxt[t->vector].address = t->address; + } +} +/* Actual parsing is done early in setup.c. */ static int __init oops_dummy (char *s)
linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/xen_entry.S +6 -3
@@ -8,11 +8,14 @@ #define sizeof_vcpu_shift 3 #ifdef CONFIG_SMP -#define preempt_disable(reg) incl threadinfo_preempt_count(reg) -#define preempt_enable(reg) decl threadinfo_preempt_count(reg) +//#define preempt_disable(reg) incl threadinfo_preempt_count(reg) +//#define preempt_enable(reg) decl threadinfo_preempt_count(reg) +#define preempt_disable(reg) +#define preempt_enable(reg) #define XEN_GET_VCPU_INFO(reg) preempt_disable(%rbp) ; \ movq %gs:pda_cpunumber,reg ; \ - shl $sizeof_vcpu_shift,reg ; \ + shl $32, reg ; \ + shr $32-sizeof_vcpu_shift,reg ; \ addq HYPERVISOR_shared_info,reg #define XEN_PUT_VCPU_INFO(reg) preempt_enable(%rbp) ; \ #define XEN_PUT_VCPU_INFO_fixup .byte 0xff,0xff,0xff
linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/irq.c +5 -1
@@ -20,7 +20,11 @@*/ atomic_t irq_err_count; - +#ifdef CONFIG_X86_IO_APIC +#ifdef APIC_MISMATCH_DEBUG +atomic_t irq_mis_count; +#endif +#endif /* * Generic, controller-independent functions:
linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/head.S +1 -1
@@ -41,7 +41,6 @@ .code64 ENTRY(_start) cld - movq init_rsp(%rip),%rsp /* Copy the necessary stuff from xen_start_info structure. */ movq $xen_start_info_union,%rdi movq $64,%rcx /* sizeof (union xen_start_info_union) / sizeof (long) */
@@ -52,6 +51,7 @@ ENTRY(_start) cld #endif /* CONFIG_SMP */ + movq init_rsp(%rip),%rsp /* zero EFLAGS after setting rsp */ pushq $0 popfq