Skip to contentSkip to conversation

x86_64 SMP status update

PATCH Chris Wright 1 participant 1 message Jul 6, 2005

lore
Share & tools
lore
#0 lore raw

This patch gets me up to init. Using init=/bin/sh I actually got the shell prompt, although it was unstable and died shortly after an ls or two. Note, linux-2.6.11-xen0 should be populated before applying this patch. Seems to be working fine on a single CPU (i.e. maxcpus=1). This is a backport of my current patch (which is against a 2.6.12 tree).

linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/Makefile +3 -3
Index: xen-unstable/linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/Makefile
===================================================================
@@ -25,10 +25,10 @@ obj-$(CONFIG_ACPI_BOOT)		+= acpi/
 c-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
+obj-$(CONFIG_X86_IO_APIC)	+= io_apic.o mpparse.o genapic_xen.o
 c-obj-$(CONFIG_X86_IO_APIC)	+= genapic.o genapic_cluster.o genapic_flat.o
 #obj-$(CONFIG_PM)		+= suspend.o
 #obj-$(CONFIG_SOFTWARE_SUSPEND)	+= suspend_asm.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-obj-m) $(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
Index: xen-unstable/linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/smp.c
===================================================================
@@ -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(&current->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 *du
 void 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_interr
 		mb();
 		atomic_inc(&call_data->finished);
 	}
+	
+	return IRQ_HANDLED;
 }
linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/smpboot.c +199 -18

440 lines not on this page · raw message

linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/traps.c +11 -0
Index: xen-unstable/linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/traps.c
===================================================================
@@ -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
Index: xen-unstable/linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/xen_entry.S
===================================================================
@@ -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
Index: xen-unstable/linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/irq.c
===================================================================
@@ -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
Index: xen-unstable/linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/head.S
===================================================================
@@ -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
linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/setup.c +14 -0
Index: xen-unstable/linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/setup.c
===================================================================
@@ -601,6 +601,17 @@ static void __init print_memory_map(char
         }
 }
 
+void __init smp_alloc_memory(void)
+{
+	int cpu;
+
+	for (cpu = 1; cpu < NR_CPUS; cpu++) {
+		cpu_gdt_descr[cpu].address = (unsigned long)
+			alloc_bootmem_low_pages(PAGE_SIZE);
+		/* XXX free unused pages later */
+	}
+}
+
 void __init setup_arch(char **cmdline_p)
 {
 	unsigned long low_mem_size;
@@ -742,6 +753,9 @@ void __init setup_arch(char **cmdline_p)
 		}
 	}
 #endif
+#ifdef CONFIG_SMP
+	smp_alloc_memory();
+#endif
 	paging_init();
 #ifdef CONFIG_X86_LOCAL_APIC
 	/*
linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/setup64.c +1 -1
Index: xen-unstable/linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/setup64.c
===================================================================
@@ -264,13 +264,13 @@ void __init cpu_init (void)
 	 * Initialize the per-CPU GDT with the boot GDT,
 	 * and set up the GDT descriptor:
 	 */
+#if 0
 	if (cpu) {
 		memcpy(cpu_gdt_table[cpu], cpu_gdt_table[0], GDT_SIZE);
 	}	
 
 	cpu_gdt_descr[cpu].size = GDT_SIZE;
 	cpu_gdt_descr[cpu].address = (unsigned long)cpu_gdt_table[cpu];
-#if 0
 	asm volatile("lgdt %0" :: "m" (cpu_gdt_descr[cpu]));
 	asm volatile("lidt %0" :: "m" (idt_descr));
 #endif
linux-2.6.11-xen-sparse/include/asm-xen/asm-x86_64/smp.h +1 -1
Index: xen-unstable/linux-2.6.11-xen-sparse/include/asm-xen/asm-x86_64/smp.h
===================================================================
@@ -77,7 +77,7 @@ extern __inline int hard_smp_processor_i
 }
 #endif
 
-#define safe_smp_processor_id() (disable_apic ? 0 : x86_apicid_to_cpu(hard_smp_processor_id()))
+#define safe_smp_processor_id() (disable_apic ? 0 : smp_processor_id())
 
 #endif /* !ASSEMBLY */
 
linux-2.6.11-xen0/arch/x86_64/kernel/genapic.c +7 -3
Index: xen-unstable/linux-2.6.11-xen0/arch/x86_64/kernel/genapic.c
===================================================================
@@ -27,9 +27,9 @@ u8 x86_cpu_to_log_apicid[NR_CPUS] = { [0
 
 extern struct genapic apic_cluster;
 extern struct genapic apic_flat;
+extern struct genapic apic_xen;
 
-struct genapic *genapic = &apic_flat;
-
+struct genapic *genapic = &apic_xen;
 
 /*
  * Check the APIC IDs in bios_cpu_apicid and choose the APIC mode.
@@ -78,12 +78,16 @@ void __init clustered_apic_check(void)
 		genapic = &apic_cluster;
 
 print:
+	/* hardcode to xen apic functions */
+	genapic = &apic_xen;
 	printk(KERN_INFO "Setting APIC routing to %s\n", genapic->name);
 }
 
 /* Same for both flat and clustered. */
 
+extern void xen_send_IPI_shortcut(unsigned int shortcut, int vector, unsigned int dest);
+
 void send_IPI_self(int vector)
 {
-	__send_IPI_shortcut(APIC_DEST_SELF, vector, APIC_DEST_PHYSICAL);
+	xen_send_IPI_shortcut(APIC_DEST_SELF, vector, APIC_DEST_PHYSICAL);
 }
linux-2.6.11-xen0/arch/xen/x86_64/kernel/genapic_xen.c new file +149 -0

149 lines not on this page · raw message

linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/mpparse.c +4 -2
Index: xen-unstable/linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/mpparse.c
===================================================================
@@ -104,7 +104,8 @@ static int __init mpf_checksum(unsigned 
 	return sum & 0xFF;
 }
 
-#ifndef CONFIG_XEN
+//#ifndef CONFIG_XEN
+#if 1
 static void __init MP_processor_info (struct mpc_config_processor *m)
 {
 	int ver;
@@ -693,7 +694,8 @@ void __init mp_register_lapic (
 	if (id == boot_cpu_physical_apicid)
 		boot_cpu = 1;
 
-#ifndef CONFIG_XEN
+//#ifndef CONFIG_XEN
+#if 1
 	processor.mpc_type = MP_PROCESSOR;
 	processor.mpc_apicid = id;
 	processor.mpc_apicver = 0x10; /* TBD: lapic version */