Module Name: src Committed By: cherry Date: Sun Jul 31 20:49:12 UTC 2011
Modified Files: src/sys/arch/amd64/amd64 [cherry-xenmp]: db_interface.c src/sys/arch/i386/i386 [cherry-xenmp]: db_interface.c gdt.c machdep.c src/sys/arch/i386/include [cherry-xenmp]: intrdefs.h pmap.h src/sys/arch/i386/isa [cherry-xenmp]: npx.c src/sys/arch/x86/x86 [cherry-xenmp]: pmap.c pmap_tlb.c src/sys/arch/xen/conf [cherry-xenmp]: std.xen src/sys/arch/xen/x86 [cherry-xenmp]: cpu.c x86_xpmap.c xen_ipi.c xenfunc.c Log Message: grow MP support for i386. boots to single user To generate a diff of this commit: cvs rdiff -u -r1.23.2.1 -r1.23.2.2 src/sys/arch/amd64/amd64/db_interface.c cvs rdiff -u -r1.66 -r1.66.2.1 src/sys/arch/i386/i386/db_interface.c cvs rdiff -u -r1.50 -r1.50.10.1 src/sys/arch/i386/i386/gdt.c cvs rdiff -u -r1.702.2.1 -r1.702.2.2 src/sys/arch/i386/i386/machdep.c cvs rdiff -u -r1.3 -r1.3.140.1 src/sys/arch/i386/include/intrdefs.h cvs rdiff -u -r1.109 -r1.109.2.1 src/sys/arch/i386/include/pmap.h cvs rdiff -u -r1.139.6.1 -r1.139.6.2 src/sys/arch/i386/isa/npx.c cvs rdiff -u -r1.121.2.3 -r1.121.2.4 src/sys/arch/x86/x86/pmap.c cvs rdiff -u -r1.3.2.2 -r1.3.2.3 src/sys/arch/x86/x86/pmap_tlb.c cvs rdiff -u -r1.6 -r1.6.12.1 src/sys/arch/xen/conf/std.xen cvs rdiff -u -r1.56.2.3 -r1.56.2.4 src/sys/arch/xen/x86/cpu.c cvs rdiff -u -r1.26.2.4 -r1.26.2.5 src/sys/arch/xen/x86/x86_xpmap.c cvs rdiff -u -r1.1.2.1 -r1.1.2.2 src/sys/arch/xen/x86/xen_ipi.c cvs rdiff -u -r1.11.6.1 -r1.11.6.2 src/sys/arch/xen/x86/xenfunc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/amd64/amd64/db_interface.c diff -u src/sys/arch/amd64/amd64/db_interface.c:1.23.2.1 src/sys/arch/amd64/amd64/db_interface.c:1.23.2.2 --- src/sys/arch/amd64/amd64/db_interface.c:1.23.2.1 Fri Jun 3 13:27:37 2011 +++ src/sys/arch/amd64/amd64/db_interface.c Sun Jul 31 20:49:10 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: db_interface.c,v 1.23.2.1 2011/06/03 13:27:37 cherry Exp $ */ +/* $NetBSD: db_interface.c,v 1.23.2.2 2011/07/31 20:49:10 cherry Exp $ */ /* * Mach Operating System @@ -33,7 +33,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.23.2.1 2011/06/03 13:27:37 cherry Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.23.2.2 2011/07/31 20:49:10 cherry Exp $"); #include "opt_ddb.h" #include "opt_multiprocessor.h" @@ -82,7 +82,9 @@ #ifdef MULTIPROCESSOR extern void ddb_ipi(struct trapframe); static void ddb_suspend(struct trapframe *); +#ifndef XEN int ddb_vec; +#endif /* XEN */ static bool ddb_mp_online; #endif Index: src/sys/arch/i386/i386/db_interface.c diff -u src/sys/arch/i386/i386/db_interface.c:1.66 src/sys/arch/i386/i386/db_interface.c:1.66.2.1 --- src/sys/arch/i386/i386/db_interface.c:1.66 Sun Apr 3 22:29:26 2011 +++ src/sys/arch/i386/i386/db_interface.c Sun Jul 31 20:49:10 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: db_interface.c,v 1.66 2011/04/03 22:29:26 dyoung Exp $ */ +/* $NetBSD: db_interface.c,v 1.66.2.1 2011/07/31 20:49:10 cherry Exp $ */ /* * Mach Operating System @@ -33,7 +33,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.66 2011/04/03 22:29:26 dyoung Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.66.2.1 2011/07/31 20:49:10 cherry Exp $"); #include "opt_ddb.h" #include "opt_multiprocessor.h" @@ -86,7 +86,9 @@ extern void ddb_ipi(int, struct trapframe); extern void ddb_ipi_tss(struct i386tss *); static void ddb_suspend(struct trapframe *); +#ifndef XEN int ddb_vec; +#endif /* XEN */ static bool ddb_mp_online; #endif @@ -104,8 +106,12 @@ { #ifdef MULTIPROCESSOR +#ifndef XEN ddb_vec = idt_vec_alloc(0xf0, 0xff); idt_vec_set(ddb_vec, &Xintrddbipi); +#else + /* Initialised as part of xen_ipi_init() */ +#endif /* XEN */ #endif } @@ -119,8 +125,10 @@ int cpu_me = cpu_number(); int win; +#ifndef XEN if (ddb_vec == 0) return 1; +#endif /* XEN */ __cpu_simple_lock(&db_lock); if (ddb_cpu == NOCPU) @@ -128,7 +136,11 @@ win = (ddb_cpu == cpu_me); __cpu_simple_unlock(&db_lock); if (win) { +#ifdef XEN + xen_broadcast_ipi(XEN_IPI_DDB); +#else x86_ipi(ddb_vec, LAPIC_DEST_ALLEXCL, LAPIC_DLMODE_FIXED); +#endif /* XEN */ } ddb_mp_online = x86_mp_online; x86_mp_online = false; Index: src/sys/arch/i386/i386/gdt.c diff -u src/sys/arch/i386/i386/gdt.c:1.50 src/sys/arch/i386/i386/gdt.c:1.50.10.1 --- src/sys/arch/i386/i386/gdt.c:1.50 Sat Nov 21 03:11:00 2009 +++ src/sys/arch/i386/i386/gdt.c Sun Jul 31 20:49:10 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: gdt.c,v 1.50 2009/11/21 03:11:00 rmind Exp $ */ +/* $NetBSD: gdt.c,v 1.50.10.1 2011/07/31 20:49:10 cherry Exp $ */ /*- * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.50 2009/11/21 03:11:00 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.50.10.1 2011/07/31 20:49:10 cherry Exp $"); #include "opt_multiprocessor.h" #include "opt_xen.h" @@ -207,17 +207,28 @@ KASSERT(va >= VM_MIN_KERNEL_ADDRESS); ptp = kvtopte(va); frames[f] = *ptp >> PAGE_SHIFT; - pmap_pte_clearbits(ptp, PG_RW); + { + /* + * pmap_pte_clearbits(ptp, PG_RW); + * but without spl(), since %fs is not setup + * properly yet, ie; curcpu() won't work at this + * point and spl() will break. + */ + xpq_queue_lock(); + xpq_queue_pte_update(xpmap_ptetomach(ptp), + *ptp & ~PG_RW); + xpq_flush_queue(); + xpq_queue_unlock(); + } } - /* printk("loading gdt %x, %d entries, %d pages", */ - /* frames[0] << PAGE_SHIFT, gdt_size[0], len >> PAGE_SHIFT); */ + if (HYPERVISOR_set_gdt(frames, gdt_size[0])) panic("HYPERVISOR_set_gdt failed!\n"); lgdt_finish(); #endif } -#ifdef MULTIPROCESSOR +#if defined(MULTIPROCESSOR) && !defined(XEN) void gdt_reload_cpu(struct cpu_info *ci) Index: src/sys/arch/i386/i386/machdep.c diff -u src/sys/arch/i386/i386/machdep.c:1.702.2.1 src/sys/arch/i386/i386/machdep.c:1.702.2.2 --- src/sys/arch/i386/i386/machdep.c:1.702.2.1 Thu Jun 23 14:19:14 2011 +++ src/sys/arch/i386/i386/machdep.c Sun Jul 31 20:49:10 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.702.2.1 2011/06/23 14:19:14 cherry Exp $ */ +/* $NetBSD: machdep.c,v 1.702.2.2 2011/07/31 20:49:10 cherry Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009 @@ -67,7 +67,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.702.2.1 2011/06/23 14:19:14 cherry Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.702.2.2 2011/07/31 20:49:10 cherry Exp $"); #include "opt_beep.h" #include "opt_compat_ibcs2.h" @@ -949,8 +949,12 @@ } #ifdef MULTIPROCESSOR +#ifdef XEN + xen_broadcast_ipi(XEN_IPI_HALT); +#else /* XEN */ x86_broadcast_ipi(X86_IPI_HALT); -#endif +#endif /* XEN */ +#endif /* MULTIPROCESSOR */ if (howto & RB_HALT) { #if NACPICA > 0 @@ -1123,14 +1127,18 @@ int xen_idt_idx; #endif -#ifndef XEN void cpu_init_idt(void) { +#ifndef XEN struct region_descriptor region; setregion(®ion, pentium_idt, NIDT * sizeof(idt[0]) - 1); lidt(®ion); -} +#else /* XEN */ + XENPRINTF(("HYPERVISOR_set_trap_table %p\n", xen_idt)); + if (HYPERVISOR_set_trap_table(xen_idt)) + panic("HYPERVISOR_set_trap_table %p failed\n", xen_idt); #endif /* !XEN */ +} void initgdt(union descriptor *tgdt) @@ -1166,7 +1174,30 @@ lgdt(®ion); #else /* !XEN */ frames[0] = xpmap_ptom((uint32_t)gdt - KERNBASE) >> PAGE_SHIFT; - pmap_kenter_pa((vaddr_t)gdt, (uint32_t)gdt - KERNBASE, VM_PROT_READ, 0); + { /* + * Enter the gdt page RO into the kernel map. We can't + * use pmap_kenter_pa() here, because %fs is not + * usable until the gdt is loaded, and %fs is used as + * the base pointer for curcpu() and curlwp(), both of + * which are in the callpath of pmap_kenter_pa(). + * So we mash up our own - this is MD code anyway. + * + * XXX: review this once we have finegrained locking + * for xpq. + */ + pt_entry_t *pte, npte; + pt_entry_t pg_nx = (cpu_feature[2] & CPUID_NOX ? PG_NX : 0); + + pte = kvtopte((vaddr_t)gdt); + npte = pmap_pa2pte((paddr_t)gdt - KERNBASE); + npte |= PG_RO | pg_nx | PG_V; + + xpq_queue_lock(); + xpq_queue_pte_update(xpmap_ptetomach(pte), npte); + xpq_flush_queue(); + xpq_queue_unlock(); + } + XENPRINTK(("loading gdt %lx, %d entries\n", frames[0] << PAGE_SHIFT, NGDT)); if (HYPERVISOR_set_gdt(frames, NGDT /* XXX is it right ? */)) @@ -1579,10 +1610,7 @@ xen_idt[xen_idt_idx].address = (uint32_t)&IDTVEC(svr4_fasttrap); xen_idt_idx++; lldt(GSEL(GLDT_SEL, SEL_KPL)); - - XENPRINTF(("HYPERVISOR_set_trap_table %p\n", xen_idt)); - if (HYPERVISOR_set_trap_table(xen_idt)) - panic("HYPERVISOR_set_trap_table %p failed\n", xen_idt); + cpu_init_idt(); #endif /* XEN */ init386_ksyms(); Index: src/sys/arch/i386/include/intrdefs.h diff -u src/sys/arch/i386/include/intrdefs.h:1.3 src/sys/arch/i386/include/intrdefs.h:1.3.140.1 --- src/sys/arch/i386/include/intrdefs.h:1.3 Wed Feb 26 21:29:01 2003 +++ src/sys/arch/i386/include/intrdefs.h Sun Jul 31 20:49:11 2011 @@ -1,3 +1,6 @@ -/* $NetBSD: intrdefs.h,v 1.3 2003/02/26 21:29:01 fvdl Exp $ */ +/* $NetBSD: intrdefs.h,v 1.3.140.1 2011/07/31 20:49:11 cherry Exp $ */ #include <x86/intrdefs.h> +#ifdef XEN +#include <xen/intrdefs.h> +#endif /* XEN */ Index: src/sys/arch/i386/include/pmap.h diff -u src/sys/arch/i386/include/pmap.h:1.109 src/sys/arch/i386/include/pmap.h:1.109.2.1 --- src/sys/arch/i386/include/pmap.h:1.109 Tue Feb 1 20:09:08 2011 +++ src/sys/arch/i386/include/pmap.h Sun Jul 31 20:49:11 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.h,v 1.109 2011/02/01 20:09:08 chuck Exp $ */ +/* $NetBSD: pmap.h,v 1.109.2.1 2011/07/31 20:49:11 cherry Exp $ */ /* * Copyright (c) 1997 Charles D. Cranor and Washington University. @@ -369,7 +369,9 @@ pmap_pte_set(pt_entry_t *pte, pt_entry_t npte) { int s = splvm(); + xpq_queue_lock(); xpq_queue_pte_update(xpmap_ptetomach(pte), npte); + xpq_queue_unlock(); splx(s); } @@ -377,12 +379,14 @@ pmap_pte_cas(volatile pt_entry_t *ptep, pt_entry_t o, pt_entry_t n) { int s = splvm(); + xpq_queue_lock(); pt_entry_t opte = *ptep; if (opte == o) { xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(ptep)), n); xpq_flush_queue(); } + xpq_queue_unlock(); splx(s); return opte; } @@ -391,10 +395,12 @@ pmap_pte_testset(volatile pt_entry_t *pte, pt_entry_t npte) { int s = splvm(); + xpq_queue_lock(); pt_entry_t opte = *pte; xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)), npte); xpq_flush_queue(); + xpq_queue_unlock(); splx(s); return opte; } @@ -403,8 +409,10 @@ pmap_pte_setbits(volatile pt_entry_t *pte, pt_entry_t bits) { int s = splvm(); + xpq_queue_lock(); xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)), (*pte) | bits); xpq_flush_queue(); + xpq_queue_unlock(); splx(s); } @@ -412,9 +420,11 @@ pmap_pte_clearbits(volatile pt_entry_t *pte, pt_entry_t bits) { int s = splvm(); + xpq_queue_lock(); xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)), (*pte) & ~bits); xpq_flush_queue(); + xpq_queue_unlock(); splx(s); } @@ -422,7 +432,9 @@ pmap_pte_flush(void) { int s = splvm(); + xpq_queue_lock(); xpq_flush_queue(); + xpq_queue_unlock(); splx(s); } Index: src/sys/arch/i386/isa/npx.c diff -u src/sys/arch/i386/isa/npx.c:1.139.6.1 src/sys/arch/i386/isa/npx.c:1.139.6.2 --- src/sys/arch/i386/isa/npx.c:1.139.6.1 Thu Jun 23 14:19:15 2011 +++ src/sys/arch/i386/isa/npx.c Sun Jul 31 20:49:11 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: npx.c,v 1.139.6.1 2011/06/23 14:19:15 cherry Exp $ */ +/* $NetBSD: npx.c,v 1.139.6.2 2011/07/31 20:49:11 cherry Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -96,7 +96,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: npx.c,v 1.139.6.1 2011/06/23 14:19:15 cherry Exp $"); +__KERNEL_RCSID(0, "$NetBSD: npx.c,v 1.139.6.2 2011/07/31 20:49:11 cherry Exp $"); #if 0 #define IPRINTF(x) printf x @@ -719,7 +719,11 @@ break; } splx(s); +#ifdef XEN + xen_send_ipi(oci, XEN_IPI_SYNCH_FPU); +#else /* XEN */ x86_send_ipi(oci, X86_IPI_SYNCH_FPU); +#endif while (pcb->pcb_fpcpu == oci && ticks == hardclock_ticks) { x86_pause(); Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.121.2.3 src/sys/arch/x86/x86/pmap.c:1.121.2.4 --- src/sys/arch/x86/x86/pmap.c:1.121.2.3 Sat Jul 16 10:59:46 2011 +++ src/sys/arch/x86/x86/pmap.c Sun Jul 31 20:49:11 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.121.2.3 2011/07/16 10:59:46 cherry Exp $ */ +/* $NetBSD: pmap.c,v 1.121.2.4 2011/07/31 20:49:11 cherry Exp $ */ /*- * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.121.2.3 2011/07/16 10:59:46 cherry Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.121.2.4 2011/07/31 20:49:11 cherry Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -572,7 +572,7 @@ vaddr_t, vaddr_t, vaddr_t, struct pv_entry **); -static bool pmap_get_physpage(vaddr_t, int, paddr_t *); +static bool pmap_get_physpage(vaddr_t, paddr_t *); static void pmap_alloc_level(pd_entry_t * const *, vaddr_t, int, long *); @@ -989,7 +989,7 @@ npte = pa; } else #endif /* DOM0OPS */ - npte = pmap_pa2pte(pa); + { npte = pmap_pa2pte(pa); } npte |= protection_codes[prot] | PG_k | PG_V | pmap_pg_g; npte |= pmap_pat_flags(flags); opte = pmap_pte_testset(pte, npte); /* zap! */ @@ -4108,7 +4108,7 @@ } static bool -pmap_get_physpage(vaddr_t va, int level, paddr_t *paddrp) +pmap_get_physpage(vaddr_t va, paddr_t *paddrp) { struct vm_page *ptp; struct pmap *kpm = pmap_kernel(); @@ -4182,36 +4182,36 @@ for (i = index; i <= endindex; i++) { + pt_entry_t pte; KASSERT(!pmap_valid_entry(pdep[i])); - pmap_get_physpage(va, level - 1, &pa); + pmap_get_physpage(va, &pa); + pte = pmap_pa2pte(pa) | PG_k | PG_V | PG_RW; #ifdef XEN xpq_queue_lock(); switch (level) { - case PTP_LEVELS: /* L4 */ - xpq_queue_pte_update( - xpmap_ptom(pmap_pdirpa(pmap_kernel(), i)), - pmap_pa2pte(pa) | PG_k | PG_V | PG_RW); + case PTP_LEVELS: +#ifdef __x86_64__ + /* update the per-cpu L4 */ xpq_queue_pte_update( - xpmap_ptom(ci_pdirpa(&cpu_info_primary, i)), - pmap_pa2pte(pa) | PG_k | PG_V | PG_RW); + xpmap_ptom(ci_pdirpa(&cpu_info_primary, i)), pte); +#endif /* __x86_64__ */ +#ifdef PAE + if (i > L2_SLOT_KERN) { + /* update real kernel PD too */ + xpq_queue_pte_update( + xpmap_ptetomach(&pmap_kl2pd[l2tol2(i)]), pte); + } +#endif + /* FALLTHROUGH */ - break; default: /* All other levels */ xpq_queue_pte_update( - xpmap_ptetomach(&pdep[i]), - pmap_pa2pte(pa) | PG_k | PG_V | PG_RW); - } -#ifdef PAE - if (level == PTP_LEVELS && i > L2_SLOT_KERN) { - /* update real kernel PD too */ - xpq_queue_pte_update( - xpmap_ptetomach(&pmap_kl2pd[l2tol2(i)]), - pmap_pa2pte(pa) | PG_k | PG_V | PG_RW); + xpmap_ptetomach(&pdep[i]), + pte); } -#endif xpq_queue_unlock(); #else /* XEN */ - pdep[i] = pmap_pa2pte(pa) | PG_k | PG_V | PG_RW; + pdep[i] = pte; #endif /* XEN */ KASSERT(level != PTP_LEVELS || nkptp[level - 1] + pl_i(VM_MIN_KERNEL_ADDRESS, level) == i); Index: src/sys/arch/x86/x86/pmap_tlb.c diff -u src/sys/arch/x86/x86/pmap_tlb.c:1.3.2.2 src/sys/arch/x86/x86/pmap_tlb.c:1.3.2.3 --- src/sys/arch/x86/x86/pmap_tlb.c:1.3.2.2 Thu Jun 23 14:19:49 2011 +++ src/sys/arch/x86/x86/pmap_tlb.c Sun Jul 31 20:49:11 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap_tlb.c,v 1.3.2.2 2011/06/23 14:19:49 cherry Exp $ */ +/* $NetBSD: pmap_tlb.c,v 1.3.2.3 2011/07/31 20:49:11 cherry Exp $ */ /*- * Copyright (c) 2008-2011 The NetBSD Foundation, Inc. @@ -40,7 +40,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.3.2.2 2011/06/23 14:19:49 cherry Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.3.2.3 2011/07/31 20:49:11 cherry Exp $"); #include <sys/param.h> #include <sys/kernel.h> @@ -57,7 +57,7 @@ #endif /* XEN */ #include <x86/i82489reg.h> #include <x86/i82489var.h> - +#undef MULTIPROCESSOR /* * TLB shootdown structures. */ @@ -291,7 +291,7 @@ #else static inline void pmap_send_ipi(pmap_tlb_packet_t *tp) { - int err; + int err = 0; CPU_INFO_ITERATOR cii; struct cpu_info *lci; @@ -307,7 +307,7 @@ if ((lci->ci_cpumask & pmap_tlb_mailbox.tm_pending) == 0) { continue; } - KASSERT(lci->ci_flags & CPUF_RUNNING) != 0); + KASSERT(lci->ci_flags & CPUF_RUNNING); err |= x86_ipi(LAPIC_TLB_VECTOR, lci->ci_cpuid, LAPIC_DLMODE_FIXED); Index: src/sys/arch/xen/conf/std.xen diff -u src/sys/arch/xen/conf/std.xen:1.6 src/sys/arch/xen/conf/std.xen:1.6.12.1 --- src/sys/arch/xen/conf/std.xen:1.6 Fri Dec 12 03:28:57 2008 +++ src/sys/arch/xen/conf/std.xen Sun Jul 31 20:49:11 2011 @@ -1,4 +1,4 @@ -# $NetBSD: std.xen,v 1.6 2008/12/12 03:28:57 alc Exp $ +# $NetBSD: std.xen,v 1.6.12.1 2011/07/31 20:49:11 cherry Exp $ # NetBSD: std.i386,v 1.24 2003/02/26 21:33:36 fvdl Exp # # standard, required NetBSD/i386 'options' @@ -16,5 +16,7 @@ #options CRYPTO_MD_BF_ENC # machine-dependant code for BF_encrypt #options CRYPTO_MD_BF_CBC # careful: uses bswapl, requires 486 +options MULTIPROCESSOR + # Atheros HAL options include "external/isc/atheros_hal/conf/std.ath_hal" Index: src/sys/arch/xen/x86/cpu.c diff -u src/sys/arch/xen/x86/cpu.c:1.56.2.3 src/sys/arch/xen/x86/cpu.c:1.56.2.4 --- src/sys/arch/xen/x86/cpu.c:1.56.2.3 Sat Jul 16 10:59:46 2011 +++ src/sys/arch/xen/x86/cpu.c Sun Jul 31 20:49:11 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.c,v 1.56.2.3 2011/07/16 10:59:46 cherry Exp $ */ +/* $NetBSD: cpu.c,v 1.56.2.4 2011/07/31 20:49:11 cherry Exp $ */ /* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp */ /*- @@ -66,7 +66,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.56.2.3 2011/07/16 10:59:46 cherry Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.56.2.4 2011/07/31 20:49:11 cherry Exp $"); #include "opt_ddb.h" #include "opt_multiprocessor.h" @@ -100,7 +100,12 @@ #include <machine/gdt.h> #include <machine/mtrr.h> #include <machine/pio.h> + +#ifdef i386 +#include <machine/npx.h> +#else #include <machine/fpu.h> +#endif #include <xen/xen.h> #include <xen/xen3-public/vcpu.h> @@ -175,8 +180,6 @@ struct cpu_info *cpu_info_list = &cpu_info_primary; struct cpu_info *phycpu_info_list = &phycpu_info_primary; -static void cpu_set_tss_gates(struct cpu_info *ci); - uint32_t cpus_attached = 1; uint32_t cpus_running = 0; @@ -455,7 +458,6 @@ cpu_intr_init(ci); cpu_get_tsc_freq(ci); cpu_init(ci); - cpu_set_tss_gates(ci); pmap_cpu_init_late(ci); /* XXX: cosmetic */ /* Every processor needs to init it's own ipi h/w (similar to lapic) */ @@ -502,11 +504,9 @@ /* interrupt handler stack */ cpu_intr_init(ci); - /* Setup gdt */ + /* Setup per-cpu memory for gdt */ gdt_alloc_cpu(ci); - //gdt_init_cpu(ci); - cpu_set_tss_gates(ci); pmap_cpu_init_late(ci); cpu_start_secondary(ci); @@ -674,15 +674,6 @@ * wait for it to become ready */ for (i = 100000; (!(ci->ci_flags & CPUF_PRESENT)) && i > 0; i--) { -#ifdef MPDEBUG - extern int cpu_trace[3]; - static int otrace[3]; - if (memcmp(otrace, cpu_trace, sizeof(otrace)) != 0) { - aprint_debug_dev(ci->ci_dev, "trace %02x %02x %02x\n", - cpu_trace[0], cpu_trace[1], cpu_trace[2]); - memcpy(otrace, cpu_trace, sizeof(otrace)); - } -#endif delay(10); } if ((ci->ci_flags & CPUF_PRESENT) == 0) { @@ -728,8 +719,11 @@ struct pcb *pcb; int s, i; - /* Setup TLS and kernel GS */ + /* Setup TLS and kernel GS/FS */ cpu_init_msrs(ci, true); + cpu_init_idt(); + gdt_init_cpu(ci); + cpu_probe(ci); atomic_or_32(&ci->ci_flags, CPUF_PRESENT); @@ -749,27 +743,18 @@ pcb = lwp_getpcb(curlwp); pcb->pcb_cr3 = pmap_pdirpa(pmap_kernel(), 0); /* XXX: consider using pmap_load() ? */ pcb = lwp_getpcb(ci->ci_data.cpu_idlelwp); - lcr0(pcb->pcb_cr0); - cpu_init_idt(); - gdt_init_cpu(ci); xen_ipi_init(); xen_initclocks(); /* XXX: lapic_initclocks(); */ -#ifdef i386 -#if NNPX > 0 - npxinit(ci); -#endif -#else +#ifdef __x86_64__ fpuinit(ci); - /* XXX: fixme compile fpuinit(ci); */ #endif lldt(GSEL(GLDT_SEL, SEL_KPL)); - ltr(ci->ci_tss_sel); cpu_init(ci); cpu_get_tsc_freq(ci); @@ -818,81 +803,6 @@ #endif /* MULTIPROCESSOR */ -#ifdef i386 -#if 0 -static void -tss_init(struct i386tss *tss, void *stack, void *func) -{ - memset(tss, 0, sizeof *tss); - tss->tss_esp0 = tss->tss_esp = (int)((char *)stack + USPACE - 16); - tss->tss_ss0 = GSEL(GDATA_SEL, SEL_KPL); - tss->__tss_cs = GSEL(GCODE_SEL, SEL_KPL); - tss->tss_fs = GSEL(GCPU_SEL, SEL_KPL); - tss->tss_gs = tss->__tss_es = tss->__tss_ds = - tss->__tss_ss = GSEL(GDATA_SEL, SEL_KPL); - tss->tss_cr3 = pmap_kernel()->pm_pdirpa; - tss->tss_esp = (int)((char *)stack + USPACE - 16); - tss->tss_ldt = GSEL(GLDT_SEL, SEL_KPL); - tss->__tss_eflags = PSL_MBO | PSL_NT; /* XXX not needed? */ - tss->__tss_eip = (int)func; -} -#endif - -/* XXX */ -#define IDTVEC(name) __CONCAT(X, name) -typedef void (vector)(void); -extern vector IDTVEC(tss_trap08); -#ifdef DDB -extern vector Xintrddbipi; -extern int ddb_vec; -#endif - -static void -cpu_set_tss_gates(struct cpu_info *ci) -{ -#if 0 - struct segment_descriptor sd; - - ci->ci_doubleflt_stack = (char *)uvm_km_alloc(kernel_map, USPACE, 0, - UVM_KMF_WIRED); - tss_init(&ci->ci_doubleflt_tss, ci->ci_doubleflt_stack, - IDTVEC(tss_trap08)); - setsegment(&sd, &ci->ci_doubleflt_tss, sizeof(struct i386tss) - 1, - SDT_SYS386TSS, SEL_KPL, 0, 0); - ci->ci_gdt[GTRAPTSS_SEL].sd = sd; - setgate(&idt[8], NULL, 0, SDT_SYSTASKGT, SEL_KPL, - GSEL(GTRAPTSS_SEL, SEL_KPL)); -#endif - -#if defined(DDB) && defined(MULTIPROCESSOR) - /* - * Set up separate handler for the DDB IPI, so that it doesn't - * stomp on a possibly corrupted stack. - * - * XXX overwriting the gate set in db_machine_init. - * Should rearrange the code so that it's set only once. - */ - ci->ci_ddbipi_stack = (char *)uvm_km_alloc(kernel_map, USPACE, 0, - UVM_KMF_WIRED); - tss_init(&ci->ci_ddbipi_tss, ci->ci_ddbipi_stack, - Xintrddbipi); - - setsegment(&sd, &ci->ci_ddbipi_tss, sizeof(struct i386tss) - 1, - SDT_SYS386TSS, SEL_KPL, 0, 0); - ci->ci_gdt[GIPITSS_SEL].sd = sd; - - setgate(&idt[ddb_vec], NULL, 0, SDT_SYSTASKGT, SEL_KPL, - GSEL(GIPITSS_SEL, SEL_KPL)); -#endif -} -#else -static void -cpu_set_tss_gates(struct cpu_info *ci) -{ - -} -#endif /* i386 */ - extern void hypervisor_callback(void); extern void failsafe_callback(void); #ifdef __x86_64__ @@ -902,8 +812,8 @@ /* * Setup the "trampoline". On Xen, we setup nearly all cpu context - * outside a trampoline, so we prototype and call targetrip like so: - * void targetrip(struct cpu_info *); + * outside a trampoline, so we prototype and call targetip like so: + * void targetip(struct cpu_info *); */ static void @@ -922,6 +832,7 @@ } } +#ifdef __x86_64__ extern char *ldtstore; /* XXX: Xen MP todo */ static void @@ -969,8 +880,13 @@ /* resume in kernel-mode */ initctx->flags = VGCF_in_kernel | VGCF_online; - /* Stack and entry points */ - initctx->user_regs.rbp = pcb->pcb_rbp; + /* Stack and entry points: + * We arrange for the stack frame for cpu_hatch() to + * appear as a callee frame of lwp_trampoline(). Being a + * leaf frame prevents trampling on any of the MD stack setup + * that x86/vm_machdep.c:cpu_lwp_fork() does for idle_loop() + */ + initctx->user_regs.rdi = (uint64_t) ci; /* targetrip(ci); */ initctx->user_regs.rip = (vaddr_t) targetrip; @@ -1013,6 +929,112 @@ return; } +#else /* i386 */ +extern union descriptor *ldt; +extern void Xsyscall(void); + +static void +xen_init_i386_vcpuctxt(struct cpu_info *ci, + struct vcpu_guest_context *initctx, + void targeteip(struct cpu_info *)) +{ + /* page frames to point at GDT */ + extern int gdt_size; + paddr_t frames[16]; + psize_t gdt_ents; + + struct lwp *l; + struct pcb *pcb; + + volatile struct vcpu_info *vci; + + KASSERT(ci != NULL); + KASSERT(ci != &cpu_info_primary); + KASSERT(initctx != NULL); + KASSERT(targeteip != NULL); + + memset(initctx, 0, sizeof *initctx); + + gdt_ents = roundup(gdt_size, PAGE_SIZE) >> PAGE_SHIFT; /* XXX: re-investigate roundup(gdt_size... ) for gdt_ents. */ + KASSERT(gdt_ents <= 16); + + gdt_prepframes(frames, (vaddr_t) ci->ci_gdt, gdt_ents); + + /* + * Initialise the vcpu context: + * We use this cpu's idle_loop() pcb context. + */ + + l = ci->ci_data.cpu_idlelwp; + + KASSERT(l != NULL); + pcb = lwp_getpcb(l); + KASSERT(pcb != NULL); + + /* resume with interrupts off */ + vci = ci->ci_vcpu; + vci->evtchn_upcall_mask = 1; + xen_mb(); + + /* resume in kernel-mode */ + initctx->flags = VGCF_in_kernel | VGCF_online; + + /* Stack frame setup for cpu_hatch(): + * We arrange for the stack frame for cpu_hatch() to + * appear as a callee frame of lwp_trampoline(). Being a + * leaf frame prevents trampling on any of the MD stack setup + * that x86/vm_machdep.c:cpu_lwp_fork() does for idle_loop() + */ + + initctx->user_regs.esp = pcb->pcb_esp - 4; /* Leave word for + arg1 */ + { /* targeteip(ci); */ + uint32_t *arg = (uint32_t *) initctx->user_regs.esp; + arg[1] = (uint32_t) ci; /* arg1 */ + + } + + initctx->user_regs.eip = (vaddr_t) targeteip; + initctx->user_regs.cs = GSEL(GCODE_SEL, SEL_KPL); + initctx->user_regs.eflags |= pcb->pcb_iopl; + + /* Data segments */ + initctx->user_regs.ss = GSEL(GDATA_SEL, SEL_KPL); + initctx->user_regs.es = GSEL(GDATA_SEL, SEL_KPL); + initctx->user_regs.ds = GSEL(GDATA_SEL, SEL_KPL); + initctx->user_regs.fs = GSEL(GDATA_SEL, SEL_KPL); + + /* GDT */ + memcpy(initctx->gdt_frames, frames, sizeof frames); + initctx->gdt_ents = gdt_ents; + + /* LDT */ + initctx->ldt_base = (unsigned long) ldt; + initctx->ldt_ents = NLDT; + + /* Kernel context state */ + initctx->kernel_ss = GSEL(GDATA_SEL, SEL_KPL); + initctx->kernel_sp = pcb->pcb_esp0; + initctx->ctrlreg[0] = pcb->pcb_cr0; + initctx->ctrlreg[1] = 0; /* "resuming" from kernel - no User cr3. */ + initctx->ctrlreg[2] = pcb->pcb_cr2; /* XXX: */ + /* + * Use pmap_kernel() L4 PD directly, until we setup the + * per-cpu L4 PD in pmap_cpu_init_late() + */ + initctx->ctrlreg[3] = xpmap_ptom(pcb->pcb_cr3); + initctx->ctrlreg[4] = /* CR4_PAE | */CR4_OSFXSR | CR4_OSXMMEXCPT; + + + /* Xen callbacks */ + initctx->event_callback_eip = (unsigned long) hypervisor_callback; + initctx->event_callback_cs = GSEL(GCODE_SEL, SEL_KPL); + initctx->failsafe_callback_eip = (unsigned long) failsafe_callback; + initctx->failsafe_callback_cs = GSEL(GCODE_SEL, SEL_KPL); + + return; +} +#endif /* __x86_64__ */ int mp_cpu_start(struct cpu_info *ci, vaddr_t target) @@ -1025,7 +1047,11 @@ KASSERT(ci != &cpu_info_primary); KASSERT(ci->ci_flags & CPUF_AP); +#ifdef __x86_64__ xen_init_amd64_vcpuctxt(ci, &vcpuctx, (void (*)(struct cpu_info *))target); +#else /* i386 */ + xen_init_i386_vcpuctxt(ci, &vcpuctx, (void (*)(struct cpu_info *))target); +#endif /* __x86_64__ */ /* Initialise the given vcpu to execute cpu_hatch(ci); */ if ((hyperror = HYPERVISOR_vcpu_op(VCPUOP_initialise, ci->ci_cpuid, &vcpuctx))) { Index: src/sys/arch/xen/x86/x86_xpmap.c diff -u src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.4 src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.5 --- src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.4 Sat Jul 16 10:59:46 2011 +++ src/sys/arch/xen/x86/x86_xpmap.c Sun Jul 31 20:49:11 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: x86_xpmap.c,v 1.26.2.4 2011/07/16 10:59:46 cherry Exp $ */ +/* $NetBSD: x86_xpmap.c,v 1.26.2.5 2011/07/31 20:49:11 cherry Exp $ */ /* * Copyright (c) 2006 Mathieu Ropert <m...@adviseo.fr> @@ -69,7 +69,7 @@ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.26.2.4 2011/07/16 10:59:46 cherry Exp $"); +__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.26.2.5 2011/07/31 20:49:11 cherry Exp $"); #include "opt_xen.h" #include "opt_ddb.h" @@ -946,11 +946,14 @@ #endif #else /* PAE */ /* recursive entry in higher-level per-cpu PD and pmap_kernel() */ - bt_pgd[PDIR_SLOT_PTE] = bt_cpu_pgd[PDIR_SLOT_PTE] = + bt_pgd[PDIR_SLOT_PTE] = +#ifdef __x86_64__ + bt_cpu_pgd[PDIR_SLOT_PTE] = +#endif /* __x86_64__ */ xpmap_ptom_masked(new_pgd - KERNBASE) | PG_k | PG_V; __PRINTK(("bt_cpu_pgd[PDIR_SLOT_PTE] va %#" PRIxVADDR " pa %#" PRIxPADDR " entry %#" PRIxPADDR "\n", new_pgd, (paddr_t)new_pgd - KERNBASE, - bt_cpu_pgd[PDIR_SLOT_PTE])); + bt_pgd[PDIR_SLOT_PTE])); /* Mark tables RO */ Index: src/sys/arch/xen/x86/xen_ipi.c diff -u src/sys/arch/xen/x86/xen_ipi.c:1.1.2.1 src/sys/arch/xen/x86/xen_ipi.c:1.1.2.2 --- src/sys/arch/xen/x86/xen_ipi.c:1.1.2.1 Fri Jun 3 13:27:41 2011 +++ src/sys/arch/xen/x86/xen_ipi.c Sun Jul 31 20:49:12 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: xen_ipi.c,v 1.1.2.1 2011/06/03 13:27:41 cherry Exp $ */ +/* $NetBSD: xen_ipi.c,v 1.1.2.2 2011/07/31 20:49:12 cherry Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -33,10 +33,10 @@ /* * Based on: x86/ipi.c - * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.1.2.1 2011/06/03 13:27:41 cherry Exp $"); + * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.1.2.2 2011/07/31 20:49:12 cherry Exp $"); */ -__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.1.2.1 2011/06/03 13:27:41 cherry Exp $"); +__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.1.2.2 2011/07/31 20:49:12 cherry Exp $"); #include <sys/types.h> @@ -49,15 +49,24 @@ #include <sys/systm.h> #include <machine/cpu.h> +#ifdef __x86_64__ #include <machine/fpu.h> +#else +#include <machine/npx.h> +#endif /* __x86_64__ */ #include <machine/frame.h> +#include <machine/segments.h> #include <xen/intr.h> #include <xen/intrdefs.h> #include <xen/hypervisor.h> #include <xen/xen3-public/vcpu.h> +#ifdef __x86_64__ extern void ddb_ipi(struct trapframe); +#else +extern void ddb_ipi(int, struct trapframe); +#endif /* __x86_64__ */ static void xen_ipi_halt(struct cpu_info *, struct intrframe *); static void xen_ipi_synch_fpu(struct cpu_info *, struct intrframe *); @@ -228,7 +237,11 @@ KASSERT(ci != NULL); KASSERT(intrf != NULL); +#ifdef __x86_64__ fpusave_cpu(true); +#else + npxsave_cpu(true); +#endif /* __x86_64__ */ return; } @@ -238,7 +251,37 @@ KASSERT(ci != NULL); KASSERT(intrf != NULL); +#ifdef __x86_64__ ddb_ipi(intrf->if_tf); +#else + struct trapframe tf; + tf.tf_gs = intrf->if_gs; + tf.tf_fs = intrf->if_fs; + tf.tf_es = intrf->if_es; + tf.tf_ds = intrf->if_ds; + tf.tf_edi = intrf->if_edi; + tf.tf_esi = intrf->if_esi; + tf.tf_ebp = intrf->if_ebp; + tf.tf_ebx = intrf->if_ebx; + tf.tf_ecx = intrf->if_ecx; + tf.tf_eax = intrf->if_eax; + tf.tf_trapno = intrf->__if_trapno; + tf.tf_err = intrf->__if_err; + tf.tf_eip = intrf->if_eip; + tf.tf_cs = intrf->if_cs; + tf.tf_eflags = intrf->if_eflags; + tf.tf_esp = intrf->if_esp; + tf.tf_ss = intrf->if_ss; + + /* XXX: does i386/Xen have vm86 support ? + tf.tf_vm86_es; + tf.tf_vm86_ds; + tf.tf_vm86_fs; + tf.tf_vm86_gs; + :XXX */ + + ddb_ipi(SEL_KPL, tf); +#endif } static void Index: src/sys/arch/xen/x86/xenfunc.c diff -u src/sys/arch/xen/x86/xenfunc.c:1.11.6.1 src/sys/arch/xen/x86/xenfunc.c:1.11.6.2 --- src/sys/arch/xen/x86/xenfunc.c:1.11.6.1 Fri Jun 3 13:27:42 2011 +++ src/sys/arch/xen/x86/xenfunc.c Sun Jul 31 20:49:12 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: xenfunc.c,v 1.11.6.1 2011/06/03 13:27:42 cherry Exp $ */ +/* $NetBSD: xenfunc.c,v 1.11.6.2 2011/07/31 20:49:12 cherry Exp $ */ /* * @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: xenfunc.c,v 1.11.6.1 2011/06/03 13:27:42 cherry Exp $"); +__KERNEL_RCSID(0, "$NetBSD: xenfunc.c,v 1.11.6.2 2011/07/31 20:49:12 cherry Exp $"); #include <sys/param.h> @@ -83,20 +83,19 @@ void ltr(u_short sel) { - __PRINTK(("XXX ltr not supported\n")); + panic("XXX ltr not supported\n"); } void lcr0(u_long val) { - __PRINTK(("XXX lcr0 not supported\n")); + panic("XXX lcr0 not supported\n"); } u_long rcr0(void) { /* XXX: handle X86_CR0_TS ? */ - __PRINTK(("XXX rcr0 not supported\n")); return 0; }