From owner-svn-src-projects@FreeBSD.ORG Wed Oct 15 05:43:13 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 662B91065691; Wed, 15 Oct 2008 05:43:13 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 554608FC57; Wed, 15 Oct 2008 05:43:13 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9F5hDIA025404; Wed, 15 Oct 2008 05:43:13 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9F5hDSN025403; Wed, 15 Oct 2008 05:43:13 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810150543.m9F5hDSN025403@svn.freebsd.org> From: Kip Macy Date: Wed, 15 Oct 2008 05:43:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183905 - projects/releng_6_xen/sys/dev/xen/console X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Oct 2008 05:43:13 -0000 Author: kmacy Date: Wed Oct 15 05:43:13 2008 New Revision: 183905 URL: http://svn.freebsd.org/changeset/base/183905 Log: update console to pre-MPSAFE tty interfaces Modified: projects/releng_6_xen/sys/dev/xen/console/console.c Modified: projects/releng_6_xen/sys/dev/xen/console/console.c ============================================================================== --- projects/releng_6_xen/sys/dev/xen/console/console.c Wed Oct 15 05:00:50 2008 (r183904) +++ projects/releng_6_xen/sys/dev/xen/console/console.c Wed Oct 15 05:43:13 2008 (r183905) @@ -1,5 +1,5 @@ #include -__FBSDID("$FreeBSD$"); + #include #include @@ -18,7 +18,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include @@ -32,7 +31,9 @@ __FBSDID("$FreeBSD$"); static char driver_name[] = "xc"; devclass_t xc_devclass; /* do not make static */ -static void xcoutwakeup(struct tty *); +static void xcstart (struct tty *); +static int xcparam (struct tty *, struct termios *); +static void xcstop (struct tty *, int); static void xc_timeout(void *); static void __xencons_tx_flush(void); static boolean_t xcons_putc(int c); @@ -72,7 +73,7 @@ static unsigned int cnsl_evt_reg; static unsigned int wc, wp; /* write_cons, write_prod */ #define CDEV_MAJOR 12 -#define XCUNIT(x) (dev2unit(x)) +#define XCUNIT(x) (minor(x)) #define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN)) #define CN_LOCK_INIT(x, _name) \ mtx_init(&x, _name, NULL, MTX_SPIN|MTX_RECURSE) @@ -93,14 +94,27 @@ static unsigned int wc, wp; /* write_con static struct tty *xccons; -static tsw_open_t xcopen; -static tsw_close_t xcclose; +struct xc_softc { + int xc_unit; + struct cdev *xc_dev; +}; + -static struct ttydevsw xc_ttydevsw = { - .tsw_flags = TF_NOPREFIX, - .tsw_open = xcopen, - .tsw_close = xcclose, - .tsw_outwakeup = xcoutwakeup, +static d_open_t xcopen; +static d_close_t xcclose; +static d_ioctl_t xcioctl; + +static struct cdevsw xc_cdevsw = { + .d_version = D_VERSION, + .d_flags = D_TTY | D_NEEDGIANT, + .d_name = driver_name, + .d_open = xcopen, + .d_close = xcclose, + .d_read = ttyread, + .d_write = ttywrite, + .d_ioctl = xcioctl, + .d_poll = ttypoll, + .d_kqfilter = ttykqfilter, }; static void @@ -210,20 +224,32 @@ xc_identify(driver_t *driver, device_t p static int xc_probe(device_t dev) { + struct xc_softc *sc = (struct xc_softc *)device_get_softc(dev); + sc->xc_unit = device_get_unit(dev); return (0); } static int xc_attach(device_t dev) { + struct xc_softc *sc = (struct xc_softc *)device_get_softc(dev); + if (xen_start_info->flags & SIF_INITDOMAIN) { xc_consdev.cn_putc = xccnputc_dom0; } - xccons = tty_alloc(&xc_ttydevsw, NULL, NULL); - tty_makedev(xccons, NULL, "xc%r", 0); + sc->xc_dev = make_dev(&xc_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "xc%r", 0); + xccons = ttyalloc(); + + sc->xc_dev->si_drv1 = (void *)sc; + sc->xc_dev->si_tty = xccons; + + xccons->t_oproc = xcstart; + xccons->t_param = xcparam; + xccons->t_stop = xcstop; + xccons->t_dev = sc->xc_dev; callout_init(&xc_callout, 0); @@ -237,7 +263,6 @@ xc_attach(device_t dev) VIRQ_CONSOLE, 0, "console", - NULL, xencons_priv_interrupt, INTR_TYPE_TTY) < 0); @@ -267,15 +292,11 @@ xencons_rx(char *buf, unsigned len) { int i; struct tty *tp = xccons; - - if (xen_console_up) { - tty_lock(tp); - for (i = 0; i < len; i++) - ttydisc_rint(tp, buf[i], 0); - ttydisc_rint_done(tp); - tty_unlock(tp); - } else { - for (i = 0; i < len; i++) + + for (i = 0; i < len; i++) { + if (xen_console_up) + (*linesw[tp->t_line]->l_rint)(buf[i], tp); + else rbuf[RBUF_MASK(rp++)] = buf[i]; } } @@ -283,7 +304,7 @@ xencons_rx(char *buf, unsigned len) static void __xencons_tx_flush(void) { - int sz; + int sz, work_done = 0; CN_LOCK(cn_mtx); while (wc != wp) { @@ -300,8 +321,16 @@ __xencons_tx_flush(void) break; wc += sent; } + work_done = 1; } CN_UNLOCK(cn_mtx); + + /* + * ttwakeup calls routines using blocking locks + * + */ + if (work_done && xen_console_up && curthread->td_critnest == 0) + ttwakeup(xccons); } void @@ -323,19 +352,76 @@ xencons_priv_interrupt(void *arg) xencons_tx(); } -static int -xcopen(struct tty *tp) +int +xcopen(struct cdev *dev, int flag, int mode, struct thread *td) { + struct xc_softc *sc; + int unit = XCUNIT(dev); + struct tty *tp; + int s, error; + + sc = (struct xc_softc *)device_get_softc( + devclass_get_device(xc_devclass, unit)); + if (sc == NULL) + return (ENXIO); + + tp = dev->si_tty; + s = spltty(); + if (!ISTTYOPEN(tp)) { + tp->t_state |= TS_CARR_ON; + ttychars(tp); + tp->t_iflag = TTYDEF_IFLAG; + tp->t_oflag = TTYDEF_OFLAG; + tp->t_cflag = TTYDEF_CFLAG|CLOCAL; + tp->t_lflag = TTYDEF_LFLAG; + tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED; + xcparam(tp, &tp->t_termios); + ttsetwater(tp); + } else if (tp->t_state & TS_XCLUDE && suser(td)) { + splx(s); + return (EBUSY); + } + splx(s); xen_console_up = 1; + + error = (*linesw[tp->t_line]->l_open)(dev, tp); + return error; +} + +int +xcclose(struct cdev *dev, int flag, int mode, struct thread *td) +{ + struct tty *tp = dev->si_tty; + + if (tp == NULL) + return (0); + xen_console_up = 0; + + spltty(); + (*linesw[tp->t_line]->l_close)(tp, flag); + tty_close(tp); + spl0(); return (0); } -static void -xcclose(struct tty *tp) + +int +xcioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td) { + struct tty *tp = dev->si_tty; + int error; + + error = (*linesw[tp->t_line]->l_ioctl)(tp, cmd, data, flag, td); + if (error != ENOIOCTL) + return (error); - xen_console_up = 0; + error = ttioctl(tp, cmd, data, flag); + + if (error != ENOIOCTL) + return (error); + + return (ENOTTY); } static inline int @@ -350,15 +436,31 @@ __xencons_put_char(int ch) static void -xcoutwakeup(struct tty *tp) +xcstart(struct tty *tp) { boolean_t cons_full = FALSE; - char c; - while (ttydisc_getc(tp, &c, 1) == 1 && !cons_full) - cons_full = xcons_putc(c); + CN_LOCK(cn_mtx); + if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) { + CN_UNLOCK(cn_mtx); + + ttwwakeup(tp); + return; + } + + tp->t_state |= TS_BUSY; + CN_UNLOCK(cn_mtx); + + while (tp->t_outq.c_cc != 0 && !cons_full) + cons_full = xcons_putc(getc(&tp->t_outq)); - if (cons_full) { + /* if the console is close to full leave our state as busy */ + if (!cons_full) { + CN_LOCK(cn_mtx); + tp->t_state &= ~TS_BUSY; + CN_UNLOCK(cn_mtx); + ttwwakeup(tp); + } else { /* let the timeout kick us in a bit */ xc_start_needed = TRUE; } @@ -366,6 +468,17 @@ xcoutwakeup(struct tty *tp) } static void +xcstop(struct tty *tp, int flag) +{ + + if (tp->t_state & TS_BUSY) { + if ((tp->t_state & TS_TTSTOP) == 0) { + tp->t_state |= TS_FLUSH; + } + } +} + +static void xc_timeout(void *v) { struct tty *tp; @@ -373,19 +486,33 @@ xc_timeout(void *v) tp = (struct tty *)v; - tty_lock(tp); - while ((c = xccncheckc(NULL)) != -1) - ttydisc_rint(tp, c, 0); + while ((c = xccncheckc(NULL)) != -1) { + if (tp->t_state & TS_ISOPEN) { + (*linesw[tp->t_line]->l_rint)(c, tp); + } + } if (xc_start_needed) { xc_start_needed = FALSE; - xcoutwakeup(tp); + xcstart(tp); } - tty_unlock(tp); callout_reset(&xc_callout, XC_POLLTIME, xc_timeout, tp); } +/* + * Set line parameters. + */ +int +xcparam(struct tty *tp, struct termios *t) +{ + tp->t_ispeed = t->c_ispeed; + tp->t_ospeed = t->c_ospeed; + tp->t_cflag = t->c_cflag; + return (0); +} + + static device_method_t xc_methods[] = { DEVMETHOD(device_identify, xc_identify), DEVMETHOD(device_probe, xc_probe), @@ -396,7 +523,7 @@ static device_method_t xc_methods[] = { static driver_t xc_driver = { driver_name, xc_methods, - 0, + sizeof(struct xc_softc), }; /*** Forcibly flush console data before dying. ***/ From owner-svn-src-projects@FreeBSD.ORG Wed Oct 15 05:44:09 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3686B1065689; Wed, 15 Oct 2008 05:44:09 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 245F18FC1D; Wed, 15 Oct 2008 05:44:09 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9F5i9LX025482; Wed, 15 Oct 2008 05:44:09 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9F5i8D2025472; Wed, 15 Oct 2008 05:44:08 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810150544.m9F5i8D2025472@svn.freebsd.org> From: Kip Macy Date: Wed, 15 Oct 2008 05:44:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183906 - in projects/releng_6_xen/sys/i386: conf i386 include include/xen xen X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Oct 2008 05:44:09 -0000 Author: kmacy Date: Wed Oct 15 05:44:08 2008 New Revision: 183906 URL: http://svn.freebsd.org/changeset/base/183906 Log: Add i386 specific xen support Added: projects/releng_6_xen/sys/i386/conf/XEN projects/releng_6_xen/sys/i386/include/xen/ projects/releng_6_xen/sys/i386/include/xen/evtchn.h (contents, props changed) projects/releng_6_xen/sys/i386/include/xen/features.h (contents, props changed) projects/releng_6_xen/sys/i386/include/xen/hypercall.h (contents, props changed) projects/releng_6_xen/sys/i386/include/xen/hypervisor.h (contents, props changed) projects/releng_6_xen/sys/i386/include/xen/synch_bitops.h (contents, props changed) projects/releng_6_xen/sys/i386/include/xen/xen-os.h (contents, props changed) projects/releng_6_xen/sys/i386/include/xen/xen_intr.h (contents, props changed) projects/releng_6_xen/sys/i386/include/xen/xenbus.h (contents, props changed) projects/releng_6_xen/sys/i386/include/xen/xenfunc.h (contents, props changed) projects/releng_6_xen/sys/i386/include/xen/xenpmap.h (contents, props changed) projects/releng_6_xen/sys/i386/include/xen/xenstored.h (contents, props changed) projects/releng_6_xen/sys/i386/include/xen/xenvar.h (contents, props changed) projects/releng_6_xen/sys/i386/xen/ projects/releng_6_xen/sys/i386/xen/clock.c (contents, props changed) projects/releng_6_xen/sys/i386/xen/exception.s (contents, props changed) projects/releng_6_xen/sys/i386/xen/locore.s (contents, props changed) projects/releng_6_xen/sys/i386/xen/machdep.c (contents, props changed) projects/releng_6_xen/sys/i386/xen/pmap.c (contents, props changed) projects/releng_6_xen/sys/i386/xen/xen_bus.c (contents, props changed) projects/releng_6_xen/sys/i386/xen/xen_machdep.c (contents, props changed) Modified: projects/releng_6_xen/sys/i386/conf/DEFAULTS projects/releng_6_xen/sys/i386/i386/genassym.c projects/releng_6_xen/sys/i386/i386/machdep.c projects/releng_6_xen/sys/i386/include/asmacros.h projects/releng_6_xen/sys/i386/include/pcpu.h projects/releng_6_xen/sys/i386/include/pmap.h projects/releng_6_xen/sys/i386/include/segments.h Modified: projects/releng_6_xen/sys/i386/conf/DEFAULTS ============================================================================== --- projects/releng_6_xen/sys/i386/conf/DEFAULTS Wed Oct 15 05:43:13 2008 (r183905) +++ projects/releng_6_xen/sys/i386/conf/DEFAULTS Wed Oct 15 05:44:08 2008 (r183906) @@ -15,3 +15,5 @@ device npx # Pseudo devices. device mem # Memory and kernel memory devices device io # I/O device + +options NATIVE Added: projects/releng_6_xen/sys/i386/conf/XEN ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/releng_6_xen/sys/i386/conf/XEN Wed Oct 15 05:44:08 2008 (r183906) @@ -0,0 +1,153 @@ +# +# GENERIC -- Generic kernel configuration file for FreeBSD/i386 +# +# For more information on this file, please read the handbook section on +# Kernel Configuration Files: +# +# http://www.FreeBSD.org/doc/en_US.ISO8859-1/books/handbook/kernelconfig-config.html +# +# The handbook is also available locally in /usr/share/doc/handbook +# if you've installed the doc distribution, otherwise always see the +# FreeBSD World Wide Web server (http://www.FreeBSD.org/) for the +# latest information. +# +# An exhaustive list of options and more detailed explanations of the +# device lines is also present in the ../../conf/NOTES and NOTES files. +# If you are in doubt as to the purpose or necessity of a line, check first +# in NOTES. +# +# $FreeBSD$ + +machine i386 +cpu I686_CPU +ident XEN + +# To statically compile in device wiring instead of /boot/device.hints +#hints "GENERIC.hints" # Default places to look for devices. + +makeoptions DEBUG=-g # Build kernel with gdb(1) debug symbols +makeoptions MODULES_OVERRIDE="" + +#options SCHED_ULE # ULE scheduler +#options PREEMPTION # Enable kernel thread preemption +options SCHED_4BSD +options INET # InterNETworking +options INET6 # IPv6 communications protocols +options FFS # Berkeley Fast Filesystem +options SOFTUPDATES # Enable FFS soft updates support +options UFS_ACL # Support for access control lists +options UFS_DIRHASH # Improve performance on big directories +options MD_ROOT # MD is a potential root device +options NFSCLIENT # Network Filesystem Client +options NFSSERVER # Network Filesystem Server +options NFS_ROOT # NFS usable as /, requires NFSCLIENT +options MSDOSFS # MSDOS Filesystem +options CD9660 # ISO 9660 Filesystem +options PROCFS # Process filesystem (requires PSEUDOFS) +options PSEUDOFS # Pseudo-filesystem framework +options GEOM_LABEL # Provides labelization +options COMPAT_FREEBSD4 # Compatible with FreeBSD4 +options COMPAT_FREEBSD5 # Compatible with FreeBSD5 +options SCSI_DELAY=5000 # Delay (in ms) before probing SCSI +options KTRACE # ktrace(1) support +options SYSVSHM # SYSV-style shared memory +options SYSVMSG # SYSV-style message queues +options SYSVSEM # SYSV-style semaphores +options _KPOSIX_PRIORITY_SCHEDULING # POSIX P1003_1B real-time extensions +options KBD_INSTALL_CDEV # install a CDEV entry in /dev +options AUDIT # Security event auditing + +# Debugging for use in -current +options KDB # Enable kernel debugger support. +options DDB # Support DDB. +options GDB # Support remote GDB. +options INVARIANTS # Enable calls of extra sanity checking +options INVARIANT_SUPPORT # Extra sanity checks of internal structures, required by INVARIANTS +#options WITNESS # Enable checks to detect deadlocks and cycles +#options WITNESS_SKIPSPIN # Don't run witness on spinlocks for speed + +# To make an SMP kernel, the next two lines are needed +#options SMP # Symmetric MultiProcessor Kernel +#device apic # I/O APIC +options PAE + + +# CPU frequency control +#device cpufreq # native only + +# Bus support. +#device pci + +# SCSI peripherals +device scbus # SCSI bus (required for SCSI) +device ch # SCSI media changers +device da # Direct Access (disks) +device sa # Sequential Access (tape etc) +device cd # CD +device pass # Passthrough device (direct SCSI access) +device ses # SCSI Environmental Services (and SAF-TE) + +# atkbdc0 controls both the keyboard and the PS/2 mouse +device atkbdc # AT keyboard controller +device atkbd # AT keyboard +device psm # PS/2 mouse +device kbdmux # keyboard multiplexer +#device vga # VGA video card driver +device splash # Splash screen and screen saver support + +# syscons is the default console driver, resembling an SCO console + +#device agp # support several AGP chipsets + +# Power management support (see NOTES for more options) +#device apm +# Add suspend/resume support for the i8254. +#device pmtimer # native + +# Serial (COM) ports +device uart # Generic UART driver + +# If you've got a "dumb" serial or parallel PCI card that is +# supported by the puc(4) glue driver, uncomment the following +# line to enable it (connects to sio, uart and/or ppc drivers): +#device puc + +# PCI Ethernet NICs. +device em # Intel PRO/1000 adapter Gigabit Ethernet Card + +# PCI Ethernet NICs that use the common MII bus controller code. +# NOTE: Be sure to keep the 'device miibus' line in order to use these NICs! +device miibus # MII bus support + +# Pseudo devices. +device loop # Network loopback +device random # Entropy device +device ether # Ethernet support +device sl # Kernel SLIP +device ppp # Kernel PPP +device tun # Packet tunnel. +device pty # Pseudo-ttys (telnet etc) +device md # Memory "disks" +device gif # IPv6 and IPv4 tunneling +device faith # IPv6-to-IPv4 relaying (translation) +device firmware # firmware assist module + +# The `bpf' device enables the Berkeley Packet Filter. +# Be aware of the administrative consequences of enabling this! +# Note that 'bpf' is required for DHCP. +device bpf # Berkeley packet filter + + +options XEN +nooption NATIVE +nodevice atpic +options MCLSHIFT=12 + +nodevice isa +nooption ISAPNP + +options KTR +options KTR_COMPILE=(KTR_PMAP) +options KTR_CPUMASK=0xff +options KTR_ENTRIES=65536 +options KTR_MASK=(KTR_PMAP) Modified: projects/releng_6_xen/sys/i386/i386/genassym.c ============================================================================== --- projects/releng_6_xen/sys/i386/i386/genassym.c Wed Oct 15 05:43:13 2008 (r183905) +++ projects/releng_6_xen/sys/i386/i386/genassym.c Wed Oct 15 05:44:08 2008 (r183906) @@ -227,3 +227,9 @@ ASSYM(MTX_RECURSECNT, offsetof(struct mt ASSYM(BUS_SPACE_HANDLE_BASE, offsetof(struct bus_space_handle, bsh_base)); ASSYM(BUS_SPACE_HANDLE_IAT, offsetof(struct bus_space_handle, bsh_iat)); #endif + +#ifdef XEN +#include +ASSYM(PC_CR3, offsetof(struct pcpu, pc_cr3)); +ASSYM(HYPERVISOR_VIRT_START, __HYPERVISOR_VIRT_START); +#endif Modified: projects/releng_6_xen/sys/i386/i386/machdep.c ============================================================================== --- projects/releng_6_xen/sys/i386/i386/machdep.c Wed Oct 15 05:43:13 2008 (r183905) +++ projects/releng_6_xen/sys/i386/i386/machdep.c Wed Oct 15 05:44:08 2008 (r183906) @@ -141,6 +141,25 @@ int arch_i386_is_xbox = 0; uint32_t arch_i386_xbox_memsize = 0; #endif +#ifdef XEN +/* XEN includes */ +#include +#include +#include +#include +#include + +void Xhypervisor_callback(void); +void failsafe_callback(void); + +int gdt_set; +extern trap_info_t trap_table[]; +struct proc_ldt default_proc_ldt; +extern int init_first; +int running_xen = 1; +extern unsigned long physfree; +#endif /* XEN */ + /* Sanity check for __curthread() */ CTASSERT(offsetof(struct pcpu, pc_curthread) == 0); @@ -282,8 +301,9 @@ cpu_startup(dummy) */ bufinit(); vm_pager_bufferinit(); - +#ifndef XEN cpu_setregs(); +#endif } /* @@ -1108,6 +1128,25 @@ cpu_est_clockrate(int cpu_id, uint64_t * return (0); } +static int cpu_idle_hlt = 1; +SYSCTL_INT(_machdep, OID_AUTO, cpu_idle_hlt, CTLFLAG_RW, + &cpu_idle_hlt, 0, "Idle loop HLT enable"); +#ifdef XEN + +void +cpu_halt(void) +{ + HYPERVISOR_shutdown(SHUTDOWN_poweroff); +} + +static void +cpu_idle_default(void) +{ + idle_block(); +} + +#else + /* * Shutdown the CPU as much as possible */ @@ -1133,9 +1172,6 @@ cpu_halt(void) * XXX I'm turning it on for SMP as well by default for now. It seems to * help lock contention somewhat, and this is critical for HTT. -Peter */ -static int cpu_idle_hlt = 1; -SYSCTL_INT(_machdep, OID_AUTO, cpu_idle_hlt, CTLFLAG_RW, - &cpu_idle_hlt, 0, "Idle loop HLT enable"); static void cpu_idle_default(void) @@ -1147,6 +1183,7 @@ cpu_idle_default(void) */ __asm __volatile("sti; hlt"); } +#endif /* !XEN */ /* * Note that we have to be careful here to avoid a race between checking @@ -1317,10 +1354,16 @@ SYSCTL_ULONG(_machdep, OID_AUTO, guessed */ int _default_ldt; + +#ifdef XEN +union descriptor *gdt; +union descriptor *ldt; +#else union descriptor gdt[NGDT * MAXCPU]; /* global descriptor table */ +union descriptor ldt[NLDT]; /* local descriptor table */ +#endif static struct gate_descriptor idt0[NIDT]; struct gate_descriptor *idt = &idt0[0]; /* interrupt descriptor table */ -union descriptor ldt[NLDT]; /* local descriptor table */ struct region_descriptor r_gdt, r_idt; /* table descriptors */ int private_tss; /* flag indicating private tss */ @@ -1355,7 +1398,7 @@ struct soft_segment_descriptor gdt_segs[ { 0x0, /* segment base address */ 0xfffff, /* length - all address space */ SDT_MEMRWA, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 1, /* segment descriptor present */ 0, 0, 1, /* default 32 vs 16 bit size */ @@ -1382,7 +1425,7 @@ struct soft_segment_descriptor gdt_segs[ { 0x0, /* segment base address */ 0xfffff, /* length - all address space */ SDT_MEMERA, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 1, /* segment descriptor present */ 0, 0, 1, /* default 32 vs 16 bit size */ @@ -1391,7 +1434,7 @@ struct soft_segment_descriptor gdt_segs[ { 0x0, /* segment base address */ 0xfffff, /* length - all address space */ SDT_MEMRWA, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 1, /* segment descriptor present */ 0, 0, 1, /* default 32 vs 16 bit size */ @@ -1418,11 +1461,12 @@ struct soft_segment_descriptor gdt_segs[ { 0x400, /* segment base address */ 0xfffff, /* length */ SDT_MEMRWA, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 1, /* segment descriptor present */ 0, 0, 1, /* default 32 vs 16 bit size */ 1 /* limit granularity (byte/page units)*/ }, +#ifndef XEN /* GPROC0_SEL 9 Proc 0 Tss Descriptor */ { 0x0, /* segment base address */ @@ -1514,6 +1558,7 @@ struct soft_segment_descriptor gdt_segs[ 0, 0, 0, /* default 32 vs 16 bit size */ 0 /* limit granularity (byte/page units)*/ }, +#endif /* !XEN */ }; static struct soft_segment_descriptor ldt_segs[] = { @@ -1735,7 +1780,17 @@ getmemsize(int first) goto physmap_done; } #endif - +#ifdef XEN + has_smap = 0; + Maxmem = xen_start_info->nr_pages - init_first; + physmem = Maxmem; + basemem = 0; + physmap[0] = init_first << PAGE_SHIFT; + physmap[1] = ptoa(Maxmem) - round_page(MSGBUF_SIZE); + physmap_idx = 0; + goto physmap_done; +#endif + hasbrokenint12 = 0; TUNABLE_INT_FETCH("hw.hasbrokenint12", &hasbrokenint12); bzero(&vmf, sizeof(vmf)); @@ -1898,7 +1953,7 @@ int15e820: vmf.vmf_ah = 0x88; vm86_intcall(0x15, &vmf); extmem = vmf.vmf_ax; -#else +#elif !defined(XEN) /* * Prefer the RTC value for extended memory. */ @@ -1988,7 +2043,7 @@ physmap_done: if (getenv_quad("dcons.addr", &dcons_addr) == 0 || getenv_quad("dcons.size", &dcons_size) == 0) dcons_addr = 0; - +#ifndef XEN /* * physmap is in bytes, so when converting to page boundaries, * round up the start address and round down the end address. @@ -2106,7 +2161,10 @@ do_next: } *pte = 0; invltlb(); - +#else + phys_avail[0] = physfree; + phys_avail[1] = xen_start_info->nr_pages*PAGE_SIZE; +#endif /* * XXX * The last chunk must contain at least one page plus the message @@ -2128,6 +2186,257 @@ do_next: avail_end = phys_avail[pa_indx]; } +#ifdef XEN + +#define MTOPSIZE (1<<(14 + PAGE_SHIFT)) +void +init386(int first) +{ + int error, gsel_tss, metadata_missing, x; + unsigned long off, gdtmachpfn; + struct pcpu *pc; + struct callback_register event = { + .type = CALLBACKTYPE_event, + .address = {GSEL(GCODE_SEL, SEL_KPL), (unsigned long)Xhypervisor_callback }, + }; + struct callback_register failsafe = { + .type = CALLBACKTYPE_failsafe, + .address = {GSEL(GCODE_SEL, SEL_KPL), (unsigned long)failsafe_callback }, + }; + + thread0.td_kstack = proc0kstack; + thread0.td_pcb = (struct pcb *) + (thread0.td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1; + + /* + * This may be done better later if it gets more high level + * components in it. If so just link td->td_proc here. + */ + proc_linkup(&proc0, &ksegrp0, &thread0); + + metadata_missing = 0; + if (xen_start_info->mod_start) { + preload_metadata = (caddr_t)xen_start_info->mod_start; + preload_bootstrap_relocate(KERNBASE); + } else { + metadata_missing = 1; + } + if (envmode == 1) + kern_envp = static_env; + else if ((caddr_t)xen_start_info->cmd_line) + kern_envp = xen_setbootenv((caddr_t)xen_start_info->cmd_line); + + boothowto |= xen_boothowto(kern_envp); + + /* Init basic tunables, hz etc */ + init_param1(); + + /* + * XEN occupies a portion of the upper virtual address space + * At its base it manages an array mapping machine page frames + * to physical page frames - hence we need to be able to + * access 4GB - (64MB - 4MB + 64k) + */ + gdt_segs[GPRIV_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE); + gdt_segs[GUFS_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE); + gdt_segs[GUGS_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE); + gdt_segs[GCODE_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE); + gdt_segs[GDATA_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE); + gdt_segs[GUCODE_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE); + gdt_segs[GUDATA_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE); + gdt_segs[GBIOSLOWMEM_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE); + + pc = &__pcpu[0]; + gdt_segs[GPRIV_SEL].ssd_base = (int) pc; + gdt_segs[GPROC0_SEL].ssd_base = (int) &pc->pc_common_tss; + + PT_SET_MA(gdt, xpmap_ptom(VTOP(gdt)) | PG_V | PG_RW); + bzero(gdt, PAGE_SIZE); + for (x = 0; x < NGDT; x++) + ssdtosd(&gdt_segs[x], &gdt[x].sd); + + + printk("gdt=%p\n", gdt); + printk("PTmap=%p\n", PTmap); + printk("addr=%p\n", *vtopte((unsigned long)gdt) & ~PG_RW); + + gdtmachpfn = vtomach(gdt) >> PAGE_SHIFT; + PT_SET_MA(gdt, *vtopte((unsigned long)gdt) & ~(PG_RW|PG_M|PG_A)); + PANIC_IF(HYPERVISOR_set_gdt(&gdtmachpfn, 512) != 0); + lgdt(&r_gdt /* unused */); + gdt_set = 1; + + if ((error = HYPERVISOR_set_trap_table(trap_table)) != 0) { + panic("set_trap_table failed - error %d\n", error); + } + + error = HYPERVISOR_callback_op(CALLBACKOP_register, &event); + if (error == 0) + error = HYPERVISOR_callback_op(CALLBACKOP_register, &failsafe); +#if CONFIG_XEN_COMPAT <= 0x030002 + if (error == -ENOXENSYS) + HYPERVISOR_set_callbacks(GSEL(GCODE_SEL, SEL_KPL), + (unsigned long)Xhypervisor_callback, + GSEL(GCODE_SEL, SEL_KPL), (unsigned long)failsafe_callback); +#endif + pcpu_init(pc, 0, sizeof(struct pcpu)); + PCPU_SET(prvspace, pc); + PCPU_SET(curthread, &thread0); + PCPU_SET(curpcb, thread0.td_pcb); + PCPU_SET(pdir, (unsigned long)IdlePTD); + + /* + * Initialize mutexes. + * + * icu_lock: in order to allow an interrupt to occur in a critical + * section, to set pcpu->ipending (etc...) properly, we + * must be able to get the icu lock, so it can't be + * under witness. + */ + mutex_init(); + mtx_init(&icu_lock, "icu", NULL, MTX_SPIN | MTX_NOWITNESS); + + /* make ldt memory segments */ + PT_SET_MA(ldt, xpmap_ptom(VTOP(ldt)) | PG_V | PG_RW); + bzero(ldt, PAGE_SIZE); + ldt_segs[LUCODE_SEL].ssd_limit = atop(0 - 1); + ldt_segs[LUDATA_SEL].ssd_limit = atop(0 - 1); + for (x = 0; x < sizeof ldt_segs / sizeof ldt_segs[0]; x++) + ssdtosd(&ldt_segs[x], &ldt[x].sd); + + default_proc_ldt.ldt_base = (caddr_t)ldt; + default_proc_ldt.ldt_len = 6; + _default_ldt = (int)&default_proc_ldt; + PCPU_SET(currentldt, _default_ldt) + PT_SET_MA(ldt, *vtopte((unsigned long)ldt) & ~PG_RW); + xen_set_ldt((unsigned long) ldt, (sizeof ldt_segs / sizeof ldt_segs[0])); + +#ifdef XBOX + /* + * The following code queries the PCI ID of 0:0:0. For the XBOX, + * This should be 0x10de / 0x02a5. + * + * This is exactly what Linux does. + */ + outl(0xcf8, 0x80000000); + if (inl(0xcfc) == 0x02a510de) { + arch_i386_is_xbox = 1; + pic16l_setled(XBOX_LED_GREEN); + + /* + * We are an XBOX, but we may have either 64MB or 128MB of + * memory. The PCI host bridge should be programmed for this, + * so we just query it. + */ + outl(0xcf8, 0x80000084); + arch_i386_xbox_memsize = (inl(0xcfc) == 0x7FFFFFF) ? 128 : 64; + } +#endif /* XBOX */ +#if defined (XEN_PRIVILEGED) + /* + * Initialize the i8254 before the console so that console + * initialization can use DELAY(). + */ + i8254_init(); +#endif + /* + * Initialize the console before we print anything out. + */ + cninit(); + + if (metadata_missing) + printf("WARNING: loader(8) metadata is missing!\n"); + +#ifdef DEV_ISA + if (xen_start_info->flags & SIF_PRIVILEGED) { + elcr_probe(); +#ifdef DEV_ATPIC + atpic_startup(); +#endif + } +#endif + +#ifdef DDB + ksym_start = bootinfo.bi_symtab; + ksym_end = bootinfo.bi_esymtab; +#endif + + kdb_init(); + +#ifdef KDB + if (boothowto & RB_KDB) + kdb_enter("Boot flags requested debugger"); +#endif + + finishidentcpu(); /* Final stage of CPU initialization */ + setidt(IDT_UD, &IDTVEC(ill), SDT_SYS386TGT, SEL_KPL, + GSEL(GCODE_SEL, SEL_KPL)); + setidt(IDT_GP, &IDTVEC(prot), SDT_SYS386TGT, SEL_KPL, + GSEL(GCODE_SEL, SEL_KPL)); + initializecpu(); /* Initialize CPU registers */ + + /* make an initial tss so cpu can get interrupt stack on syscall! */ + /* Note: -16 is so we can grow the trapframe if we came from vm86 */ + PCPU_SET(common_tss.tss_esp0, thread0.td_kstack + + KSTACK_PAGES * PAGE_SIZE - sizeof(struct pcb) - 16); + PCPU_SET(common_tss.tss_ss0, GSEL(GDATA_SEL, SEL_KPL)); + gsel_tss = GSEL(GPROC0_SEL, SEL_KPL); + HYPERVISOR_stack_switch(GSEL(GDATA_SEL, SEL_KPL), + PCPU_GET(common_tss.tss_esp0)); + + + /* pointer to selector slot for %fs/%gs */ + PCPU_SET(fsgs_gdt, &gdt[GUFS_SEL].sd); + + dblfault_tss.tss_esp = dblfault_tss.tss_esp0 = dblfault_tss.tss_esp1 = + dblfault_tss.tss_esp2 = (int)&dblfault_stack[sizeof(dblfault_stack)]; + dblfault_tss.tss_ss = dblfault_tss.tss_ss0 = dblfault_tss.tss_ss1 = + dblfault_tss.tss_ss2 = GSEL(GDATA_SEL, SEL_KPL); +#ifdef PAE + dblfault_tss.tss_cr3 = (int)IdlePDPT; +#else + dblfault_tss.tss_cr3 = (int)IdlePTD; +#endif + dblfault_tss.tss_eip = (int)dblfault_handler; + dblfault_tss.tss_eflags = PSL_KERNEL; + dblfault_tss.tss_ds = dblfault_tss.tss_es = + dblfault_tss.tss_gs = GSEL(GDATA_SEL, SEL_KPL); + dblfault_tss.tss_fs = GSEL(GPRIV_SEL, SEL_KPL); + dblfault_tss.tss_cs = GSEL(GCODE_SEL, SEL_KPL); + dblfault_tss.tss_ldt = GSEL(GLDT_SEL, SEL_KPL); + + vm86_initialize(); + getmemsize(first); + init_param2(physmem); + + + /* Map the message buffer. */ + for (off = 0; off < round_page(MSGBUF_SIZE); off += PAGE_SIZE) + pmap_kenter((vm_offset_t)msgbufp + off, avail_end + off); + + /* now running on new page tables, configured,and u/iom is accessible */ + + msgbufinit(msgbufp, MSGBUF_SIZE); + + /* transfer to user mode */ + + _ucodesel = GSEL(GUCODE_SEL, SEL_UPL); + _udatasel = GSEL(GUDATA_SEL, SEL_UPL); + + /* setup proc 0's pcb */ + thread0.td_pcb->pcb_flags = 0; +#ifdef PAE + thread0.td_pcb->pcb_cr3 = (int)IdlePDPT; +#else + thread0.td_pcb->pcb_cr3 = (int)IdlePTD; +#endif + thread0.td_pcb->pcb_ext = 0; + thread0.td_frame = &proc0_tf; + thread0.td_pcb->pcb_fsd = PCPU_GET(fsgs_gdt)[0]; + thread0.td_pcb->pcb_gsd = PCPU_GET(fsgs_gdt)[1]; +} + +#else void init386(first) int first; @@ -2389,6 +2698,7 @@ init386(first) thread0.td_pcb->pcb_ext = 0; thread0.td_frame = &proc0_tf; } +#endif /* !XEN */ void cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t size) Modified: projects/releng_6_xen/sys/i386/include/asmacros.h ============================================================================== --- projects/releng_6_xen/sys/i386/include/asmacros.h Wed Oct 15 05:43:13 2008 (r183905) +++ projects/releng_6_xen/sys/i386/include/asmacros.h Wed Oct 15 05:44:08 2008 (r183906) @@ -134,6 +134,46 @@ #define MEXITCOUNT #endif /* GPROF */ +/* + * Setup the kernel segment registers. + */ +#define SET_KERNEL_SREGS \ + movl $KDSEL, %eax ; /* reload with kernel's data segment */ \ + movl %eax, %ds ; \ + movl %eax, %es ; \ + movl $KPSEL, %eax ; /* reload with per-CPU data segment */ \ + movl %eax, %fs + +#ifdef XEN +#define LOAD_CR3(reg) \ + movl reg,PCPU(CR3); \ + pushl %ecx ; \ + pushl %edx ; \ + pushl %esi ; \ + pushl reg ; \ + call xen_load_cr3 ; \ + addl $4,%esp ; \ + popl %esi ; \ + popl %edx ; \ + popl %ecx ; \ + +#define READ_CR3(reg) movl PCPU(CR3),reg; +#define LLDT(arg) \ + pushl %edx ; \ + pushl %eax ; \ + xorl %eax,%eax ; \ + movl %eax,%gs ; \ + call i386_reset_ldt ; \ + popl %eax ; \ + popl %edx +#define CLI call ni_cli +#else +#define LOAD_CR3(reg) movl reg,%cr3; +#define READ_CR3(reg) movl %cr3,reg; +#define LLDT(arg) lldt arg; +#define CLI cli +#endif /* !XEN */ + #ifdef LOCORE /* * Convenience macros for declaring interrupt entry points and trap @@ -145,4 +185,30 @@ #endif /* LOCORE */ +#ifdef __STDC__ +#define ELFNOTE(name, type, desctype, descdata...) \ +.pushsection .note.name ; \ + .align 4 ; \ + .long 2f - 1f /* namesz */ ; \ + .long 4f - 3f /* descsz */ ; \ + .long type ; \ +1:.asciz #name ; \ +2:.align 4 ; \ +3:desctype descdata ; \ +4:.align 4 ; \ +.popsection +#else /* !__STDC__, i.e. -traditional */ +#define ELFNOTE(name, type, desctype, descdata) \ +.pushsection .note.name ; \ + .align 4 ; \ + .long 2f - 1f /* namesz */ ; \ + .long 4f - 3f /* descsz */ ; \ + .long type ; \ +1:.asciz "name" ; \ +2:.align 4 ; \ +3:desctype descdata ; \ +4:.align 4 ; \ +.popsection +#endif /* __STDC__ */ + #endif /* !_MACHINE_ASMACROS_H_ */ Modified: projects/releng_6_xen/sys/i386/include/pcpu.h ============================================================================== --- projects/releng_6_xen/sys/i386/include/pcpu.h Wed Oct 15 05:43:13 2008 (r183905) +++ projects/releng_6_xen/sys/i386/include/pcpu.h Wed Oct 15 05:44:08 2008 (r183906) @@ -45,6 +45,28 @@ * to each CPU's data can be set up for things like "check curproc on all * other processors" */ + +#ifdef XEN +#define PCPU_MD_FIELDS \ + struct pcpu *pc_prvspace; /* Self-reference */ \ + struct pmap *pc_curpmap; \ + struct i386tss pc_common_tss; \ + struct segment_descriptor pc_common_tssd; \ + struct segment_descriptor *pc_tss_gdt; \ + struct segment_descriptor *pc_fsgs_gdt; \ + vm_paddr_t *pc_pdir_shadow; \ + int pc_currentldt; \ + u_int pc_acpi_id; /* ACPI CPU id */ \ + u_int pc_apic_id; \ + int pc_private_tss; /* Flag indicating private tss*/\ + u_int pc_cr3; /* track cr3 for R1/R3*/ \ + u_int pc_pdir; \ + u_int pc_lazypmap; \ + u_int pc_rendezvous; \ + u_int pc_cpuast + + +#else #define PCPU_MD_FIELDS \ struct pcpu *pc_prvspace; /* Self-reference */ \ struct pmap *pc_curpmap; \ @@ -55,7 +77,7 @@ int pc_currentldt; \ u_int pc_acpi_id; \ u_int pc_apic_id - +#endif #if defined(lint) extern struct pcpu *pcpup; Modified: projects/releng_6_xen/sys/i386/include/pmap.h ============================================================================== --- projects/releng_6_xen/sys/i386/include/pmap.h Wed Oct 15 05:43:13 2008 (r183905) +++ projects/releng_6_xen/sys/i386/include/pmap.h Wed Oct 15 05:44:08 2008 (r183906) @@ -68,7 +68,14 @@ /* Our various interpretations of the above */ #define PG_W PG_AVAIL1 /* "Wired" pseudoflag */ #define PG_MANAGED PG_AVAIL2 + +#ifdef PAE +#define PG_FRAME (0x000ffffffffff000ull) +#define PG_PS_FRAME (0x000fffffffe00000ull) +#else #define PG_FRAME (~((vm_paddr_t)PAGE_MASK)) +#define PG_PS_FRAME (0xffc00000) +#endif #define PG_PROT (PG_RW|PG_U) /* all protection bits . */ #define PG_N (PG_NC_PWT|PG_NC_PCD) /* Non-cacheable */ @@ -175,6 +182,77 @@ extern pd_entry_t *IdlePTD; /* physical * the corresponding pde that in turn maps it. */ #define vtopte(va) (PTmap + i386_btop(va)) +#define vtophys(va) pmap_kextract(((vm_offset_t) (va))) + +#ifdef XEN +#include +#include +#include +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif + +#define PG_KERNEL (PG_V | PG_A | PG_RW | PG_M) + +#define MACH_TO_VM_PAGE(ma) PHYS_TO_VM_PAGE(xpmap_mtop((ma))) +#define VM_PAGE_TO_MACH(m) xpmap_ptom(VM_PAGE_TO_PHYS((m))) + +static __inline vm_paddr_t +pmap_kextract_ma(vm_offset_t va) +{ + vm_paddr_t ma; + if ((ma = PTD[va >> PDRSHIFT]) & PG_PS) { + ma = (ma & ~(NBPDR - 1)) | (va & (NBPDR - 1)); + } else { + ma = (*vtopte(va) & PG_FRAME) | (va & PAGE_MASK); + } + return ma; +} + +static __inline vm_paddr_t +pmap_kextract(vm_offset_t va) +{ + return xpmap_mtop(pmap_kextract_ma(va)); +} +#define vtomach(va) pmap_kextract_ma(((vm_offset_t) (va))) + +vm_paddr_t pmap_extract_ma(struct pmap *pmap, vm_offset_t va); + +void pmap_kenter_ma(vm_offset_t va, vm_paddr_t pa); +void pmap_map_readonly(struct pmap *pmap, vm_offset_t va, int len); +void pmap_map_readwrite(struct pmap *pmap, vm_offset_t va, int len); + +static __inline pt_entry_t +pte_load_store(pt_entry_t *ptep, pt_entry_t v) +{ + pt_entry_t r; + + v = xpmap_ptom(v); + r = *ptep; + PT_SET_VA(ptep, v, TRUE); + return (r); +} + +static __inline pt_entry_t +pte_load_store_ma(pt_entry_t *ptep, pt_entry_t v) +{ + pt_entry_t r; + + r = *ptep; + PT_SET_VA_MA(ptep, v, TRUE); + return (r); +} + +#define pte_load_clear(ptep) pte_load_store((ptep), (pt_entry_t)0ULL) + +#define pte_store(ptep, pte) pte_load_store((ptep), (pt_entry_t)pte) +#define pte_store_ma(ptep, pte) pte_load_store_ma((ptep), (pt_entry_t)pte) +#define pde_store_ma(ptep, pte) pte_load_store_ma((ptep), (pt_entry_t)pte) + +#elif !defined(XEN) /* * Routine: pmap_kextract @@ -195,10 +273,9 @@ pmap_kextract(vm_offset_t va) } return pa; } +#endif -#define vtophys(va) pmap_kextract(((vm_offset_t) (va))) - -#ifdef PAE +#if defined(PAE) && !defined(XEN) static __inline pt_entry_t pte_load(pt_entry_t *ptep) @@ -231,7 +308,7 @@ pte_load_store(pt_entry_t *ptep, pt_entr #define pte_store(ptep, pte) pte_load_store((ptep), (pt_entry_t)pte) -#else /* PAE */ +#elif !defined (PAE) && !defined(XEN) static __inline pt_entry_t pte_load(pt_entry_t *ptep) Modified: projects/releng_6_xen/sys/i386/include/segments.h ============================================================================== --- projects/releng_6_xen/sys/i386/include/segments.h Wed Oct 15 05:43:13 2008 (r183905) +++ projects/releng_6_xen/sys/i386/include/segments.h Wed Oct 15 05:44:08 2008 (r183906) @@ -47,7 +47,11 @@ */ #define ISPL(s) ((s)&3) /* what is the priority level of a selector */ +#ifndef XEN #define SEL_KPL 0 /* kernel priority level */ +#else +#define SEL_KPL 1 /* kernel priority level */ +#endif #define SEL_UPL 3 /* user priority level */ #define ISLDT(s) ((s)&SEL_LDT) /* is it local or global */ #define SEL_LDT 4 /* local descriptor table */ @@ -222,8 +226,11 @@ struct region_descriptor { #define GBIOSARGS_SEL 17 /* BIOS interface (Arguments) */ #define GNDIS_SEL 18 /* For the NDIS layer */ +#ifndef XEN #define NGDT 19 - +#else +#define NGDT 9 +#endif /* * Entries in the Local Descriptor Table (LDT) */ @@ -240,10 +247,16 @@ struct region_descriptor { #ifdef _KERNEL extern int _default_ldt; +#ifndef XEN +extern union descriptor ldt[NLDT]; extern union descriptor gdt[]; +#else +extern union descriptor *ldt; +extern union descriptor *gdt; +#endif + extern struct soft_segment_descriptor gdt_segs[]; extern struct gate_descriptor *idt; -extern union descriptor ldt[NLDT]; extern struct region_descriptor r_gdt, r_idt; void lgdt(struct region_descriptor *rdp); Added: projects/releng_6_xen/sys/i386/include/xen/evtchn.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/releng_6_xen/sys/i386/include/xen/evtchn.h Wed Oct 15 05:44:08 2008 (r183906) @@ -0,0 +1,81 @@ +/****************************************************************************** + * evtchn.h + * + * Communication via Xen event channels. + * Also definitions for the device that demuxes notifications to userspace. + * + * Copyright (c) 2004, K A Fraser + */ + +#ifndef __ASM_EVTCHN_H__ +#define __ASM_EVTCHN_H__ +#include +#include +#include +#include + +/* + * LOW-LEVEL DEFINITIONS + */ + +/* + * Unlike notify_remote_via_evtchn(), this is safe to use across + * save/restore. Notifications on a broken connection are silently dropped. + */ +void notify_remote_via_irq(int irq); + + +/* Entry point for notifications into Linux subsystems. */ +void evtchn_do_upcall(struct intrframe *frame); + +/* Entry point for notifications into the userland character device. */ +void evtchn_device_upcall(int port); + +void mask_evtchn(int port); + +void unmask_evtchn(int port); + + + +static inline void +clear_evtchn(int port) +{ + shared_info_t *s = HYPERVISOR_shared_info; + synch_clear_bit(port, &s->evtchn_pending[0]); +} + +static inline void +notify_remote_via_evtchn(int port) +{ + struct evtchn_send send = { .port = port }; + (void)HYPERVISOR_event_channel_op(EVTCHNOP_send, &send); +} + +/* + * Use these to access the event channel underlying the IRQ handle returned + * by bind_*_to_irqhandler(). + */ +int irq_to_evtchn_port(int irq); + +void ipi_pcpu(unsigned int cpu, int vector); + +/* + * CHARACTER-DEVICE DEFINITIONS + */ + +#define PORT_NORMAL 0x0000 +#define PORT_EXCEPTION 0x8000 +#define PORTIDX_MASK 0x7fff + +/* /dev/xen/evtchn resides at device number major=10, minor=200 */ +#define EVTCHN_MINOR 200 + +/* /dev/xen/evtchn ioctls: */ +/* EVTCHN_RESET: Clear and reinit the event buffer. Clear error condition. */ *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-projects@FreeBSD.ORG Wed Oct 15 05:44:50 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DD520106569F; Wed, 15 Oct 2008 05:44:49 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id CC2718FC18; Wed, 15 Oct 2008 05:44:49 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9F5inhi025530; Wed, 15 Oct 2008 05:44:49 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9F5inSq025526; Wed, 15 Oct 2008 05:44:49 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810150544.m9F5inSq025526@svn.freebsd.org> From: Kip Macy Date: Wed, 15 Oct 2008 05:44:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183907 - in projects/releng_6_xen/sys/xen: . evtchn xenbus X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Oct 2008 05:44:50 -0000 Author: kmacy Date: Wed Oct 15 05:44:49 2008 New Revision: 183907 URL: http://svn.freebsd.org/changeset/base/183907 Log: Update interfaces to build against RELENG_6 Modified: projects/releng_6_xen/sys/xen/evtchn/evtchn.c projects/releng_6_xen/sys/xen/gnttab.c projects/releng_6_xen/sys/xen/gnttab.h projects/releng_6_xen/sys/xen/xenbus/xenbus_xs.c Modified: projects/releng_6_xen/sys/xen/evtchn/evtchn.c ============================================================================== --- projects/releng_6_xen/sys/xen/evtchn/evtchn.c Wed Oct 15 05:44:08 2008 (r183906) +++ projects/releng_6_xen/sys/xen/evtchn/evtchn.c Wed Oct 15 05:44:49 2008 (r183907) @@ -21,7 +21,9 @@ __FBSDID("$FreeBSD$"); #include #include + #include +#include #include #include #include @@ -178,7 +180,7 @@ void force_evtchn_callback(void) } void -evtchn_do_upcall(struct trapframe *frame) +evtchn_do_upcall(struct intrframe *frame) { unsigned long l1, l2; unsigned int l1i, l2i, port; @@ -434,7 +436,7 @@ bind_caller_port_to_irqhandler(unsigned irq = bind_caller_port_to_irq(caller_port); intr_register_source(&xp->xp_pins[irq].xp_intsrc); - retval = intr_add_handler(devname, irq, NULL, handler, arg, irqflags, cookiep); + retval = intr_add_handler(devname, irq, handler, arg, irqflags, cookiep); if (retval != 0) { unbind_from_irq(irq); return -retval; @@ -457,7 +459,7 @@ bind_listening_port_to_irqhandler( irq = bind_listening_port_to_irq(remote_domain); intr_register_source(&xp->xp_pins[irq].xp_intsrc); - retval = intr_add_handler(devname, irq, NULL, handler, arg, irqflags, cookiep); + retval = intr_add_handler(devname, irq, handler, arg, irqflags, cookiep); if (retval != 0) { unbind_from_irq(irq); return -retval; @@ -471,7 +473,6 @@ bind_interdomain_evtchn_to_irqhandler( unsigned int remote_domain, unsigned int remote_port, const char *devname, - driver_filter_t filter, driver_intr_t handler, unsigned long irqflags) { @@ -480,7 +481,7 @@ bind_interdomain_evtchn_to_irqhandler( irq = bind_interdomain_evtchn_to_irq(remote_domain, remote_port); intr_register_source(&xp->xp_pins[irq].xp_intsrc); - retval = intr_add_handler(devname, irq, filter, handler, NULL, irqflags, NULL); + retval = intr_add_handler(devname, irq, handler, NULL, irqflags, NULL); if (retval != 0) { unbind_from_irq(irq); return -retval; @@ -493,7 +494,6 @@ int bind_virq_to_irqhandler(unsigned int virq, unsigned int cpu, const char *devname, - driver_filter_t filter, driver_intr_t handler, unsigned long irqflags) { @@ -502,7 +502,7 @@ bind_virq_to_irqhandler(unsigned int vir irq = bind_virq_to_irq(virq, cpu); intr_register_source(&xp->xp_pins[irq].xp_intsrc); - retval = intr_add_handler(devname, irq, filter, handler, NULL, irqflags, NULL); + retval = intr_add_handler(devname, irq, handler, NULL, irqflags, NULL); if (retval != 0) { unbind_from_irq(irq); return -retval; @@ -523,7 +523,7 @@ bind_ipi_to_irqhandler(unsigned int ipi, irq = bind_ipi_to_irq(ipi, cpu); intr_register_source(&xp->xp_pins[irq].xp_intsrc); - retval = intr_add_handler(devname, irq, NULL, handler, NULL, irqflags, NULL); + retval = intr_add_handler(devname, irq, handler, NULL, irqflags, NULL); if (retval != 0) { unbind_from_irq(irq); return -retval; @@ -592,13 +592,11 @@ static void xenpic_dynirq_enable_sou static void xenpic_dynirq_disable_source(struct intsrc *isrc, int); static void xenpic_dynirq_eoi_source(struct intsrc *isrc); static void xenpic_dynirq_enable_intr(struct intsrc *isrc); -static void xenpic_dynirq_disable_intr(struct intsrc *isrc); static void xenpic_pirq_enable_source(struct intsrc *isrc); static void xenpic_pirq_disable_source(struct intsrc *isrc, int); static void xenpic_pirq_eoi_source(struct intsrc *isrc); static void xenpic_pirq_enable_intr(struct intsrc *isrc); -static void xenpic_pirq_disable_intr(struct intsrc *isrc); static int xenpic_vector(struct intsrc *isrc); @@ -613,7 +611,6 @@ struct pic xenpic_dynirq_template = { .pic_disable_source = xenpic_dynirq_disable_source, .pic_eoi_source = xenpic_dynirq_eoi_source, .pic_enable_intr = xenpic_dynirq_enable_intr, - .pic_disable_intr = xenpic_dynirq_disable_intr, .pic_vector = xenpic_vector, .pic_source_pending = xenpic_source_pending, .pic_suspend = xenpic_suspend, @@ -625,7 +622,6 @@ struct pic xenpic_pirq_template = { .pic_disable_source = xenpic_pirq_disable_source, .pic_eoi_source = xenpic_pirq_eoi_source, .pic_enable_intr = xenpic_pirq_enable_intr, - .pic_disable_intr = xenpic_pirq_disable_intr, .pic_vector = xenpic_vector, .pic_source_pending = xenpic_source_pending, .pic_suspend = xenpic_suspend, @@ -684,20 +680,6 @@ xenpic_dynirq_enable_intr(struct intsrc } static void -xenpic_dynirq_disable_intr(struct intsrc *isrc) -{ - unsigned int irq; - struct xenpic_intsrc *xp; - - xp = (struct xenpic_intsrc *)isrc; - mtx_lock_spin(&irq_mapping_update_lock); - xp->xp_masked = 1; - irq = xenpic_vector(isrc); - mask_evtchn(evtchn_from_irq(irq)); - mtx_unlock_spin(&irq_mapping_update_lock); -} - -static void xenpic_dynirq_eoi_source(struct intsrc *isrc) { unsigned int irq; @@ -830,32 +812,6 @@ xenpic_pirq_enable_intr(struct intsrc *i } static void -xenpic_pirq_disable_intr(struct intsrc *isrc) -{ - unsigned int irq; - int evtchn; - struct evtchn_close close; - - mtx_lock_spin(&irq_mapping_update_lock); - irq = xenpic_vector(isrc); - evtchn = evtchn_from_irq(irq); - - if (!VALID_EVTCHN(evtchn)) - goto done; - - mask_evtchn(evtchn); - - close.port = evtchn; - PANIC_IF(HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0); - - bind_evtchn_to_cpu(evtchn, 0); - evtchn_to_irq[evtchn] = -1; - irq_info[irq] = IRQ_UNBOUND; - done: - mtx_unlock_spin(&irq_mapping_update_lock); -} - -static void xenpic_pirq_enable_source(struct intsrc *isrc) { int evtchn; Modified: projects/releng_6_xen/sys/xen/gnttab.c ============================================================================== --- projects/releng_6_xen/sys/xen/gnttab.c Wed Oct 15 05:44:08 2008 (r183906) +++ projects/releng_6_xen/sys/xen/gnttab.c Wed Oct 15 05:44:49 2008 (r183907) @@ -25,11 +25,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include -#include - -#include -#include #include #include Modified: projects/releng_6_xen/sys/xen/gnttab.h ============================================================================== --- projects/releng_6_xen/sys/xen/gnttab.h Wed Oct 15 05:44:08 2008 (r183906) +++ projects/releng_6_xen/sys/xen/gnttab.h Wed Oct 15 05:44:49 2008 (r183907) @@ -36,12 +36,16 @@ #ifndef __ASM_GNTTAB_H__ +#include +#include +#include +#include + #include #include #include #include #include - struct gnttab_free_callback { struct gnttab_free_callback *next; void (*fn)(void *); Modified: projects/releng_6_xen/sys/xen/xenbus/xenbus_xs.c ============================================================================== --- projects/releng_6_xen/sys/xen/xenbus/xenbus_xs.c Wed Oct 15 05:44:08 2008 (r183906) +++ projects/releng_6_xen/sys/xen/xenbus/xenbus_xs.c Wed Oct 15 05:44:49 2008 (r183907) @@ -883,7 +883,7 @@ static void xenbus_thread(void *unused) DELAY(10000); xenbus_running = 1; - pause("xenbus", hz/10); + tsleep(&lbolt, 0, "xenbus", hz/10); for (;;) { err = xs_process_msg(&type); @@ -922,13 +922,13 @@ int xs_init(void) if (err) return err; - err = kproc_create(xenwatch_thread, NULL, &p, + err = kthread_create(xenwatch_thread, NULL, &p, RFHIGHPID, 0, "xenwatch"); if (err) return err; xenwatch_pid = p->p_pid; - err = kproc_create(xenbus_thread, NULL, NULL, + err = kthread_create(xenbus_thread, NULL, NULL, RFHIGHPID, 0, "xenbus"); return err; From owner-svn-src-projects@FreeBSD.ORG Wed Oct 15 05:45:27 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 253BF1065695; Wed, 15 Oct 2008 05:45:27 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 1429E8FC0C; Wed, 15 Oct 2008 05:45:27 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9F5jQYx025588; Wed, 15 Oct 2008 05:45:26 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9F5jQfF025584; Wed, 15 Oct 2008 05:45:26 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810150545.m9F5jQfF025584@svn.freebsd.org> From: Kip Macy Date: Wed, 15 Oct 2008 05:45:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183908 - projects/releng_6_xen/sys/conf X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Oct 2008 05:45:27 -0000 Author: kmacy Date: Wed Oct 15 05:45:26 2008 New Revision: 183908 URL: http://svn.freebsd.org/changeset/base/183908 Log: Add xen specific configuration Modified: projects/releng_6_xen/sys/conf/files projects/releng_6_xen/sys/conf/files.i386 projects/releng_6_xen/sys/conf/kern.pre.mk projects/releng_6_xen/sys/conf/options.i386 Modified: projects/releng_6_xen/sys/conf/files ============================================================================== --- projects/releng_6_xen/sys/conf/files Wed Oct 15 05:44:49 2008 (r183907) +++ projects/releng_6_xen/sys/conf/files Wed Oct 15 05:45:26 2008 (r183908) @@ -1475,6 +1475,7 @@ libkern/strcasecmp.c standard libkern/strcat.c standard libkern/strcmp.c standard libkern/strcpy.c standard +libkern/strcspn.c standard libkern/strdup.c standard libkern/strlcat.c standard libkern/strlcpy.c standard @@ -2043,4 +2044,20 @@ xdr/xdr_array.c optional nfslockd xdr/xdr_mbuf.c optional nfslockd xdr/xdr_mem.c optional nfslockd xdr/xdr_reference.c optional nfslockd -xdr/xdr_sizeof.c optional nfslockd \ No newline at end of file +xdr/xdr_sizeof.c optional nfslockd + + +xen/gnttab.c optional xen +xen/features.c optional xen +xen/evtchn/evtchn.c optional xen +xen/evtchn/evtchn_dev.c optional xen +xen/xenbus/xenbus_client.c optional xen +xen/xenbus/xenbus_comms.c optional xen +xen/xenbus/xenbus_dev.c optional xen +xen/xenbus/xenbus_probe.c optional xen +xen/xenbus/xenbus_probe_backend.c optional xen +xen/xenbus/xenbus_xs.c optional xen +dev/xen/console/console.c optional xen +dev/xen/console/xencons_ring.c optional xen +dev/xen/blkfront/blkfront.c optional xen +dev/xen/netfront/netfront.c optional xen \ No newline at end of file Modified: projects/releng_6_xen/sys/conf/files.i386 ============================================================================== --- projects/releng_6_xen/sys/conf/files.i386 Wed Oct 15 05:44:49 2008 (r183907) +++ projects/releng_6_xen/sys/conf/files.i386 Wed Oct 15 05:45:26 2008 (r183908) @@ -291,8 +291,8 @@ i386/cpufreq/smist.c optional cpufreq i386/i386/atomic.c standard \ compile-with "${CC} -c ${CFLAGS} ${DEFINED_PROF:S/^$/-fomit-frame-pointer/} ${.IMPSRC}" i386/i386/autoconf.c standard -i386/i386/bios.c standard -i386/i386/bioscall.s standard +i386/i386/bios.c optional native +i386/i386/bioscall.s optional native i386/i386/busdma_machdep.c standard i386/i386/db_disasm.c optional ddb i386/i386/db_interface.c optional ddb @@ -301,7 +301,8 @@ i386/i386/dump_machdep.c standard i386/i386/elan-mmcr.c optional cpu_elan i386/i386/elan-mmcr.c optional cpu_soekris i386/i386/elf_machdep.c standard -i386/i386/exception.s standard +i386/i386/exception.s optional native +i386/xen/exception.s optional xen i386/i386/gdb_machdep.c optional gdb i386/i386/geode.c optional cpu_geode i386/i386/i686_mem.c optional mem @@ -314,22 +315,26 @@ i386/i386/io_apic.c optional apic i386/i386/k6_mem.c optional mem i386/i386/legacy.c standard i386/i386/local_apic.c optional apic -i386/i386/locore.s standard no-obj +i386/i386/locore.s optional native no-obj +i386/xen/locore.s optional xen no-obj i386/i386/longrun.c optional cpu_enable_longrun i386/i386/machdep.c standard i386/i386/mem.c optional mem i386/i386/minidump_machdep.c standard i386/i386/mp_clock.c optional smp -i386/i386/mp_machdep.c optional smp +i386/i386/mp_machdep.c optional native smp +i386/xen/mp_machdep.c optional xen smp i386/i386/mp_watchdog.c optional mp_watchdog smp -i386/i386/mpboot.s optional smp +i386/i386/mpboot.s optional native smp i386/i386/mptable.c optional apic i386/i386/mptable_pci.c optional apic pci i386/i386/msi.c optional apic pci i386/i386/nexus.c standard i386/i386/perfmon.c optional perfmon i386/i386/perfmon.c optional perfmon profiling-routine -i386/i386/pmap.c standard +i386/i386/pmap.c optional native +i386/xen/pmap.c optional xen +i386/xen/xen_machdep.c optional xen i386/i386/ptrace_machdep.c standard i386/i386/support.s standard i386/i386/swtch.s standard @@ -358,9 +363,10 @@ i386/ibcs2/ibcs2_util.c optional ibcs2 i386/ibcs2/ibcs2_xenix.c optional ibcs2 i386/ibcs2/ibcs2_xenix_sysent.c optional ibcs2 i386/ibcs2/imgact_coff.c optional ibcs2 -i386/isa/atpic.c standard +i386/isa/atpic.c optional atpic #i386/isa/atpic_vector.s standard -i386/isa/clock.c standard +i386/isa/clock.c optional native +i386/xen/clock.c optional xen i386/isa/elcr.c standard i386/isa/elink.c optional ep i386/isa/elink.c optional ie Modified: projects/releng_6_xen/sys/conf/kern.pre.mk ============================================================================== --- projects/releng_6_xen/sys/conf/kern.pre.mk Wed Oct 15 05:44:49 2008 (r183907) +++ projects/releng_6_xen/sys/conf/kern.pre.mk Wed Oct 15 05:45:26 2008 (r183908) @@ -70,13 +70,17 @@ INCLUDES+= -I$S/dev/twa # .. and the same for em INCLUDES+= -I$S/dev/em +INCLUDES+= -I$S/xen/interface -I$S/xen/interface/io + + CFLAGS= ${COPTFLAGS} ${CWARNFLAGS} ${DEBUG} CFLAGS+= ${INCLUDES} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h .if ${CC} != "icc" CFLAGS+= -fno-common -finline-limit=${INLINE_LIMIT} CFLAGS+= --param inline-unit-growth=100 CFLAGS+= --param large-function-growth=1000 -WERROR?= -Werror +WERROR?= +#-Werror .endif # XXX LOCORE means "don't declare C stuff" not "for locore.s". Modified: projects/releng_6_xen/sys/conf/options.i386 ============================================================================== --- projects/releng_6_xen/sys/conf/options.i386 Wed Oct 15 05:44:49 2008 (r183907) +++ projects/releng_6_xen/sys/conf/options.i386 Wed Oct 15 05:45:26 2008 (r183908) @@ -163,3 +163,6 @@ ASR_COMPAT opt_asr.h # Debugging KDB_STOP_NMI opt_kdb.h NPX_DEBUG opt_npx.h + +NATIVE opt_global.h +XEN opt_global.h From owner-svn-src-projects@FreeBSD.ORG Wed Oct 15 05:46:48 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D5DA21065687; Wed, 15 Oct 2008 05:46:48 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id C62248FC2D; Wed, 15 Oct 2008 05:46:48 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9F5kmCg025645; Wed, 15 Oct 2008 05:46:48 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9F5km8X025644; Wed, 15 Oct 2008 05:46:48 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810150546.m9F5km8X025644@svn.freebsd.org> From: Kip Macy Date: Wed, 15 Oct 2008 05:46:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183909 - projects/releng_6_xen/sys/sys X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Oct 2008 05:46:48 -0000 Author: kmacy Date: Wed Oct 15 05:46:48 2008 New Revision: 183909 URL: http://svn.freebsd.org/changeset/base/183909 Log: add strcspn to libkern (needed by xenbus) Modified: projects/releng_6_xen/sys/sys/libkern.h Modified: projects/releng_6_xen/sys/sys/libkern.h ============================================================================== --- projects/releng_6_xen/sys/sys/libkern.h Wed Oct 15 05:45:26 2008 (r183908) +++ projects/releng_6_xen/sys/sys/libkern.h Wed Oct 15 05:46:48 2008 (r183909) @@ -98,6 +98,7 @@ void srandom(u_long); int strcasecmp(const char *, const char *); char *strcat(char * __restrict, const char * __restrict); int strcmp(const char *, const char *); +size_t strcspn(const char *s, const char *charset); char *strcpy(char * __restrict, const char * __restrict); char *strdup(const char *__restrict, struct malloc_type *); size_t strlcat(char *, const char *, size_t); @@ -151,6 +152,18 @@ memset(void *b, int c, size_t len) return (b); } +static __inline char * +strchr(const char *p, int ch) +{ + return (index(p, ch)); +} + +static __inline char * +strrchr(const char *p, int ch) +{ + return (rindex(p, ch)); +} + /* fnmatch() return values. */ #define FNM_NOMATCH 1 /* Match failed. */ From owner-svn-src-projects@FreeBSD.ORG Thu Oct 16 01:33:04 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9E3151065690; Thu, 16 Oct 2008 01:33:04 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 8AEFB8FC1E; Thu, 16 Oct 2008 01:33:04 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9G1X4C2048083; Thu, 16 Oct 2008 01:33:04 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9G1X3dZ048068; Thu, 16 Oct 2008 01:33:03 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810160133.m9G1X3dZ048068@svn.freebsd.org> From: Kip Macy Date: Thu, 16 Oct 2008 01:33:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183927 - in projects/releng_6_xen/sys: i386/i386 i386/include i386/include/xen i386/xen kern X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Oct 2008 01:33:04 -0000 Author: kmacy Date: Thu Oct 16 01:33:03 2008 New Revision: 183927 URL: http://svn.freebsd.org/changeset/base/183927 Log: - pull in xen_machdep.c from HEAD - pull in xen changes to common files - remove unused i386/xen/machdep.c Deleted: projects/releng_6_xen/sys/i386/xen/machdep.c Modified: projects/releng_6_xen/sys/i386/i386/busdma_machdep.c projects/releng_6_xen/sys/i386/i386/intr_machdep.c projects/releng_6_xen/sys/i386/i386/machdep.c projects/releng_6_xen/sys/i386/i386/swtch.s projects/releng_6_xen/sys/i386/i386/sys_machdep.c projects/releng_6_xen/sys/i386/i386/trap.c projects/releng_6_xen/sys/i386/i386/vm_machdep.c projects/releng_6_xen/sys/i386/include/cpufunc.h projects/releng_6_xen/sys/i386/include/param.h projects/releng_6_xen/sys/i386/include/vmparam.h projects/releng_6_xen/sys/i386/include/xen/xen-os.h projects/releng_6_xen/sys/i386/include/xen/xenpmap.h projects/releng_6_xen/sys/i386/xen/pmap.c projects/releng_6_xen/sys/i386/xen/xen_machdep.c projects/releng_6_xen/sys/kern/kern_fork.c projects/releng_6_xen/sys/kern/kern_synch.c projects/releng_6_xen/sys/kern/subr_trap.c Modified: projects/releng_6_xen/sys/i386/i386/busdma_machdep.c ============================================================================== --- projects/releng_6_xen/sys/i386/i386/busdma_machdep.c Wed Oct 15 21:47:01 2008 (r183926) +++ projects/releng_6_xen/sys/i386/i386/busdma_machdep.c Thu Oct 16 01:33:03 2008 (r183927) @@ -140,6 +140,11 @@ static bus_addr_t add_bounce_page(bus_dm static void free_bounce_page(bus_dma_tag_t dmat, struct bounce_page *bpage); static __inline int run_filter(bus_dma_tag_t dmat, bus_addr_t paddr); +#ifdef XEN +#undef pmap_kextract +#define pmap_kextract pmap_kextract_ma +#endif + /* * Return true if a match is made. * Modified: projects/releng_6_xen/sys/i386/i386/intr_machdep.c ============================================================================== --- projects/releng_6_xen/sys/i386/i386/intr_machdep.c Wed Oct 15 21:47:01 2008 (r183926) +++ projects/releng_6_xen/sys/i386/i386/intr_machdep.c Thu Oct 16 01:33:03 2008 (r183927) @@ -284,7 +284,12 @@ intr_execute_handlers(struct intsrc *isr /* Schedule the ithread if needed. */ if (thread) { error = intr_event_schedule_thread(ie); +#ifndef XEN KASSERT(error == 0, ("bad stray interrupt")); +#else + if (error != 0) + log(LOG_CRIT, "bad stray interrupt %d", vector); +#endif } critical_exit(); td->td_intr_nesting_level--; Modified: projects/releng_6_xen/sys/i386/i386/machdep.c ============================================================================== --- projects/releng_6_xen/sys/i386/i386/machdep.c Wed Oct 15 21:47:01 2008 (r183926) +++ projects/releng_6_xen/sys/i386/i386/machdep.c Thu Oct 16 01:33:03 2008 (r183927) @@ -152,7 +152,7 @@ uint32_t arch_i386_xbox_memsize = 0; void Xhypervisor_callback(void); void failsafe_callback(void); -int gdt_set; +int gdtset; extern trap_info_t trap_table[]; struct proc_ldt default_proc_ldt; extern int init_first; @@ -2264,7 +2264,7 @@ init386(int first) PT_SET_MA(gdt, *vtopte((unsigned long)gdt) & ~(PG_RW|PG_M|PG_A)); PANIC_IF(HYPERVISOR_set_gdt(&gdtmachpfn, 512) != 0); lgdt(&r_gdt /* unused */); - gdt_set = 1; + gdtset = 1; if ((error = HYPERVISOR_set_trap_table(trap_table)) != 0) { panic("set_trap_table failed - error %d\n", error); Modified: projects/releng_6_xen/sys/i386/i386/swtch.s ============================================================================== --- projects/releng_6_xen/sys/i386/i386/swtch.s Wed Oct 15 21:47:01 2008 (r183926) +++ projects/releng_6_xen/sys/i386/i386/swtch.s Thu Oct 16 01:33:03 2008 (r183927) @@ -71,7 +71,7 @@ ENTRY(cpu_throw) movl 8(%esp),%ecx /* New thread */ movl TD_PCB(%ecx),%edx movl PCB_CR3(%edx),%eax - movl %eax,%cr3 /* new address space */ + LOAD_CR3(%eax) /* new address space */ /* set bit in new pm_active */ movl TD_PROC(%ecx),%eax movl P_VMSPACE(%eax), %ebx @@ -114,11 +114,13 @@ ENTRY(cpu_switch) movl %gs,PCB_GS(%edx) pushfl /* PSL */ popl PCB_PSL(%edx) +#ifndef XEN /* Check to see if we need to call a switchout function. */ movl PCB_SWITCHOUT(%edx),%eax cmpl $0, %eax je 1f call *%eax +#endif 1: /* Test if debug registers should be saved. */ testl $PCB_DBREGS,PCB_FLAGS(%edx) @@ -171,7 +173,7 @@ ENTRY(cpu_switch) movl %cr3,%ebx /* The same address space? */ cmpl %ebx,%eax je sw1 - movl %eax,%cr3 /* new address space */ + LOAD_CR3(%eax) /* new address space */ /* Release bit from old pmap->pm_active */ movl PCPU(CURPMAP), %ebx @@ -191,6 +193,18 @@ ENTRY(cpu_switch) btsl %esi, PM_ACTIVE(%ebx) /* set new */ sw1: +#ifdef XEN + pushl %eax + pushl %ecx + pushl %edx + call xen_handle_thread_switch + popl %edx + popl %ecx + popl %eax + /* + * XXX set IOPL + */ +#else /* * At this point, we've switched address spaces and are ready * to load up the rest of the next context. @@ -238,7 +252,7 @@ sw1: movl 12(%esi), %ebx movl %eax, 8(%edi) movl %ebx, 12(%edi) - +#endif /* Restore context. */ movl PCB_EBX(%edx),%ebx movl PCB_ESP(%edx),%esp @@ -263,7 +277,7 @@ sw1: movl _default_ldt,%eax cmpl PCPU(CURRENTLDT),%eax je 2f - lldt _default_ldt + LLDT(_default_ldt) movl %eax,PCPU(CURRENTLDT) jmp 2f 1: @@ -366,7 +380,7 @@ ENTRY(savectx) * parent's npx state for forks by forgetting to reload. */ pushfl - cli + CLI movl PCPU(FPCURTHREAD),%eax testl %eax,%eax je 1f Modified: projects/releng_6_xen/sys/i386/i386/sys_machdep.c ============================================================================== --- projects/releng_6_xen/sys/i386/i386/sys_machdep.c Wed Oct 15 21:47:01 2008 (r183926) +++ projects/releng_6_xen/sys/i386/i386/sys_machdep.c Thu Oct 16 01:33:03 2008 (r183927) @@ -58,6 +58,25 @@ __FBSDID("$FreeBSD$"); #include /* for kernel_map */ +#ifdef XEN +#include + +void i386_reset_ldt(struct proc_ldt *pldt); + +void +i386_reset_ldt(struct proc_ldt *pldt) +{ + xen_set_ldt((vm_offset_t)pldt->ldt_base, pldt->ldt_len); +} +#define SEG_VIRT_END (HYPERVISOR_VIRT_START >> 12) & 0xffff +#define SET_DESCRIPTOR(index, sd) \ + HYPERVISOR_update_descriptor(vtomach(&PCPU_GET(fsgs_gdt)[index]), *(uint64_t *)&(sd)); +#else +#define i386_reset_ldt(x) +#define SEG_VIRT_END 0xffff +#define SET_DESCRIPTOR(index, sd) PCPU_GET(fsgs_gdt)[index] = (sd); +#endif + #define MAX_LD 8192 #define LD_PER_PAGE 512 #define NEW_MAX_LD(num) ((num + LD_PER_PAGE) & ~(LD_PER_PAGE-1)) @@ -163,7 +182,7 @@ sysarch(td, uap) */ sd.sd_lobase = base & 0xffffff; sd.sd_hibase = (base >> 24) & 0xff; - sd.sd_lolimit = 0xffff; /* 4GB limit, wraps around */ + sd.sd_lolimit = SEG_VIRT_END; /* 4GB limit, wraps */ sd.sd_hilimit = 0xf; sd.sd_type = SDT_MEMRWA; sd.sd_dpl = SEL_UPL; @@ -173,7 +192,7 @@ sysarch(td, uap) sd.sd_gran = 1; critical_enter(); td->td_pcb->pcb_fsd = sd; - PCPU_GET(fsgs_gdt)[0] = sd; + SET_DESCRIPTOR(0, sd); critical_exit(); td->td_frame->tf_fs = GSEL(GUFS_SEL, SEL_UPL); } @@ -193,7 +212,7 @@ sysarch(td, uap) */ sd.sd_lobase = base & 0xffffff; sd.sd_hibase = (base >> 24) & 0xff; - sd.sd_lolimit = 0xffff; /* 4GB limit, wraps around */ + sd.sd_lolimit = SEG_VIRT_END; /* 4GB limit, wraps */ sd.sd_hilimit = 0xf; sd.sd_type = SDT_MEMRWA; sd.sd_dpl = SEL_UPL; @@ -203,7 +222,7 @@ sysarch(td, uap) sd.sd_gran = 1; critical_enter(); td->td_pcb->pcb_gsd = sd; - PCPU_GET(fsgs_gdt)[1] = sd; + SET_DESCRIPTOR(1, sd); critical_exit(); load_gs(GSEL(GUGS_SEL, SEL_UPL)); } @@ -364,6 +383,10 @@ set_user_ldt(struct mdproc *mdp) struct proc_ldt *pldt; pldt = mdp->md_ldt; +#ifdef XEN + i386_reset_ldt(pldt); + PCPU_SET(currentldt, (int)pldt); +#else #ifdef SMP gdt[PCPU_GET(cpuid) * NGDT + GUSERLDT_SEL].sd = pldt->ldt_sd; #else @@ -371,6 +394,7 @@ set_user_ldt(struct mdproc *mdp) #endif lldt(GSEL(GUSERLDT_SEL, SEL_KPL)); PCPU_SET(currentldt, GSEL(GUSERLDT_SEL, SEL_KPL)); +#endif /* !XEN */ } #ifdef SMP @@ -385,6 +409,39 @@ set_user_ldt_rv(struct thread *td) } #endif +#ifdef XEN + +struct proc_ldt * +user_ldt_alloc(struct mdproc *mdp, int len) +{ + struct proc_ldt *pldt, *new_ldt; + + MALLOC(new_ldt, struct proc_ldt *, sizeof(struct proc_ldt), + M_SUBPROC, M_WAITOK); + + new_ldt->ldt_len = len = NEW_MAX_LD(len); + new_ldt->ldt_base = (caddr_t)kmem_alloc(kernel_map, + round_page(len * sizeof(union descriptor))); + if (new_ldt->ldt_base == NULL) { + FREE(new_ldt, M_SUBPROC); + return NULL; + } + new_ldt->ldt_refcnt = 1; + new_ldt->ldt_active = 0; + + if ((pldt = mdp->md_ldt)) { + if (len > pldt->ldt_len) + len = pldt->ldt_len; + bcopy(pldt->ldt_base, new_ldt->ldt_base, + len * sizeof(union descriptor)); + } else { + bcopy(ldt, new_ldt->ldt_base, PAGE_SIZE); + } + pmap_map_readonly(kernel_pmap, (vm_offset_t)new_ldt->ldt_base, + new_ldt->ldt_len*sizeof(union descriptor)); + return new_ldt; +} +#else /* * Must be called with either sched_lock free or held but not recursed. * If it does not return NULL, it will return with it owned. @@ -425,6 +482,7 @@ user_ldt_alloc(struct mdproc *mdp, int l } return new_ldt; } +#endif /* * Must be called either with sched_lock free or held but not recursed. @@ -443,8 +501,11 @@ user_ldt_free(struct thread *td) mtx_lock_spin(&sched_lock); mtx_assert(&sched_lock, MA_OWNED | MA_NOTRECURSED); if (td == PCPU_GET(curthread)) { +#ifndef XEN lldt(_default_ldt); +#endif PCPU_SET(currentldt, _default_ldt); + i386_reset_ldt((struct proc_ldt *)_default_ldt); } mdp->md_ldt = NULL; @@ -549,6 +610,9 @@ i386_set_ldt(td, uap, descs) } if (!(uap->start == LDT_AUTO_ALLOC && uap->num == 1)) { +#ifdef XEN + load_gs(0); /* XXX check if we really still need this */ +#endif /* complain a for a while if using old methods */ if (ldt_warnings++ < NUM_LDT_WARNINGS) { printf("Warning: pid %d used static ldt allocation.\n", @@ -671,6 +735,23 @@ again: return (error); } +#ifdef XEN +static int +i386_set_ldt_data(struct thread *td, int start, int num, + union descriptor *descs) +{ + struct mdproc *mdp = &td->td_proc->p_md; + struct proc_ldt *pldt = mdp->md_ldt; + int i, error; + + for (i = 0; i < num; i++) { + error = HYPERVISOR_update_descriptor(vtomach(&((union descriptor *)(pldt->ldt_base))[start + i]), *(uint64_t *)(descs + i)); + if (error) + panic("failed to update ldt: %d", error); + } + return (0); +} +#else static int i386_set_ldt_data(struct thread *td, int start, int num, union descriptor *descs) @@ -686,6 +767,7 @@ i386_set_ldt_data(struct thread *td, int num * sizeof(union descriptor)); return (0); } +#endif static int i386_ldt_grow(struct thread *td, int len) Modified: projects/releng_6_xen/sys/i386/i386/trap.c ============================================================================== --- projects/releng_6_xen/sys/i386/i386/trap.c Wed Oct 15 21:47:01 2008 (r183926) +++ projects/releng_6_xen/sys/i386/i386/trap.c Thu Oct 16 01:33:03 2008 (r183927) @@ -215,6 +215,7 @@ trap(frame) goto out; #endif +#ifndef XEN if ((frame.tf_eflags & PSL_I) == 0) { /* * Buggy application or kernel code has disabled @@ -245,6 +246,7 @@ trap(frame) enable_intr(); } } +#endif eva = 0; code = frame.tf_err; Modified: projects/releng_6_xen/sys/i386/i386/vm_machdep.c ============================================================================== --- projects/releng_6_xen/sys/i386/i386/vm_machdep.c Wed Oct 15 21:47:01 2008 (r183926) +++ projects/releng_6_xen/sys/i386/i386/vm_machdep.c Thu Oct 16 01:33:03 2008 (r183927) @@ -89,6 +89,9 @@ __FBSDID("$FreeBSD$"); #include #include +#ifdef XEN +#include +#endif #ifdef PC98 #include #else @@ -264,7 +267,7 @@ cpu_fork(td1, p2, td2, flags) /* Setup to release sched_lock in fork_exit(). */ td2->td_md.md_spinlock_count = 1; - td2->td_md.md_saved_flags = PSL_KERNEL | PSL_I; + td2->td_md.md_saved_flags = PSL_USER; /* * Now, cpu_switch() can schedule the new process. @@ -436,7 +439,7 @@ cpu_set_upcall(struct thread *td, struct /* Setup to release sched_lock in fork_exit(). */ td->td_md.md_spinlock_count = 1; - td->td_md.md_saved_flags = PSL_KERNEL | PSL_I; + td->td_md.md_saved_flags = PSL_USER; } /* @@ -593,6 +596,9 @@ cpu_reset_real() int b; #endif +#ifdef XEN + HYPERVISOR_shutdown(SHUTDOWN_poweroff); +#endif disable_intr(); #ifdef CPU_ELAN if (elan_mmcr != NULL) @@ -762,8 +768,11 @@ sf_buf_alloc(struct vm_page *m, int flag */ ptep = vtopte(sf->kva); opte = *ptep; +#ifdef XEN + PT_SET_MA(sf->kva, xpmap_ptom(VM_PAGE_TO_PHYS(m)) | pgeflag | PG_RW | PG_V); +#else *ptep = VM_PAGE_TO_PHYS(m) | pgeflag | PG_RW | PG_V; - +#endif /* * Avoid unnecessary TLB invalidations: If the sf_buf's old * virtual-to-physical mapping was not used, then any processor @@ -812,6 +821,14 @@ sf_buf_free(struct sf_buf *sf) if (sf->ref_count == 0) { TAILQ_INSERT_TAIL(&sf_buf_freelist, sf, free_entry); nsfbufsused--; +#ifdef XEN + /* + * Xen doesn't like having dangling R/W mappings + */ + pmap_qremove(sf->kva, 1); + sf->m = NULL; + LIST_REMOVE(sf, list_entry); +#endif if (sf_buf_alloc_want > 0) wakeup_one(&sf_buf_freelist); } Modified: projects/releng_6_xen/sys/i386/include/cpufunc.h ============================================================================== --- projects/releng_6_xen/sys/i386/include/cpufunc.h Wed Oct 15 21:47:01 2008 (r183926) +++ projects/releng_6_xen/sys/i386/include/cpufunc.h Thu Oct 16 01:33:03 2008 (r183927) @@ -42,6 +42,16 @@ #error this file needs sys/cdefs.h as a prerequisite #endif +#ifdef XEN +extern void xen_cli(void); +extern void xen_sti(void); +extern void xen_load_cr3(u_int data); +extern void xen_tlb_flush(void); +extern void xen_invlpg(u_int addr); +extern int xen_save_and_cli(void); +extern void xen_restore_flags(u_int eflags); +#endif + struct region_descriptor; #define readb(va) (*(volatile u_int8_t *) (va)) @@ -81,7 +91,11 @@ bsrl(u_int mask) static __inline void disable_intr(void) { +#ifdef XEN + xen_cli(); +#else __asm __volatile("cli" : : : "memory"); +#endif } static __inline void @@ -103,7 +117,11 @@ cpuid_count(u_int ax, u_int cx, u_int *p static __inline void enable_intr(void) { +#ifdef XEN + xen_sti(); +#else __asm __volatile("sti"); +#endif } #ifdef _KERNEL @@ -399,8 +417,11 @@ rcr2(void) static __inline void load_cr3(u_int data) { - +#ifdef XEN + xen_load_cr3(data); +#else __asm __volatile("movl %0,%%cr3" : : "r" (data) : "memory"); +#endif } static __inline u_int @@ -433,8 +454,11 @@ rcr4(void) static __inline void invltlb(void) { - +#ifdef XEN + xen_tlb_flush(); +#else load_cr3(rcr3()); +#endif } /* @@ -444,8 +468,11 @@ invltlb(void) static __inline void invlpg(u_int addr) { - +#ifdef XEN + xen_invlpg(addr); +#else __asm __volatile("invlpg %0" : : "m" (*(char *)addr) : "memory"); +#endif } static __inline u_int @@ -619,15 +646,23 @@ intr_disable(void) { register_t eflags; +#ifdef XEN + return (xen_save_and_cli()); +#endif eflags = read_eflags(); disable_intr(); + return (eflags); } static __inline void intr_restore(register_t eflags) { +#ifdef XEN + xen_restore_flags(eflags); +#else write_eflags(eflags); +#endif } #else /* !(__GNUCLIKE_ASM && __CC_SUPPORTS___INLINE) */ Modified: projects/releng_6_xen/sys/i386/include/param.h ============================================================================== --- projects/releng_6_xen/sys/i386/include/param.h Wed Oct 15 21:47:01 2008 (r183926) +++ projects/releng_6_xen/sys/i386/include/param.h Thu Oct 16 01:33:03 2008 (r183927) @@ -86,9 +86,11 @@ #ifdef PAE #define NPGPTD 4 #define PDRSHIFT 21 /* LOG2(NBPDR) */ +#define NPGPTD_SHIFT 9 #else #define NPGPTD 1 #define PDRSHIFT 22 /* LOG2(NBPDR) */ +#define NPGPTD_SHIFT 10 #endif #define NBPTD (NPGPTD< #endif +extern int gdtset; #ifdef SMP #include /* XXX for pcpu.h */ #include /* XXX for PCPU_GET */ -extern int gdt_set; static inline int smp_processor_id(void) { - if (likely(gdt_set)) + if (likely(gdtset)) return PCPU_GET(cpuid); return 0; } Modified: projects/releng_6_xen/sys/i386/include/xen/xenpmap.h ============================================================================== --- projects/releng_6_xen/sys/i386/include/xen/xenpmap.h Wed Oct 15 21:47:01 2008 (r183926) +++ projects/releng_6_xen/sys/i386/include/xen/xenpmap.h Thu Oct 16 01:33:03 2008 (r183927) @@ -33,12 +33,9 @@ #ifndef _XEN_XENPMAP_H_ #define _XEN_XENPMAP_H_ -void xen_invlpg(vm_offset_t); -void xen_load_cr3(vm_paddr_t); void _xen_queue_pt_update(vm_paddr_t, vm_paddr_t, char *, int); void xen_pt_switch(vm_paddr_t); void xen_set_ldt(vm_paddr_t, unsigned long); -void xen_tlb_flush(void); void xen_pgdpt_pin(vm_paddr_t); void xen_pgd_pin(vm_paddr_t); void xen_pgd_unpin(vm_paddr_t); Modified: projects/releng_6_xen/sys/i386/xen/pmap.c ============================================================================== --- projects/releng_6_xen/sys/i386/xen/pmap.c Wed Oct 15 21:47:01 2008 (r183926) +++ projects/releng_6_xen/sys/i386/xen/pmap.c Thu Oct 16 01:33:03 2008 (r183927) @@ -208,7 +208,7 @@ vm_offset_t virtual_end; /* VA of last a int pgeflag = 0; /* PG_G or-in */ int pseflag = 0; /* PG_PS or-in */ -static int nkpt; +int nkpt; vm_offset_t kernel_vm_end; extern u_int32_t KERNend; Modified: projects/releng_6_xen/sys/i386/xen/xen_machdep.c ============================================================================== --- projects/releng_6_xen/sys/i386/xen/xen_machdep.c Wed Oct 15 21:47:01 2008 (r183926) +++ projects/releng_6_xen/sys/i386/xen/xen_machdep.c Thu Oct 16 01:33:03 2008 (r183927) @@ -1,7 +1,7 @@ /* * * Copyright (c) 2004 Christian Limpach. - * Copyright (c) 2004-2006 Kip Macy + * Copyright (c) 2004-2006,2008 Kip Macy * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,6 +31,7 @@ */ #include +__FBSDID("$FreeBSD$"); #include #include @@ -41,11 +42,10 @@ #include #include +#include #include #include -#include - #include #include #include @@ -57,7 +57,6 @@ - #include #include #include @@ -70,6 +69,10 @@ #include #endif + +#include + + #define IDTVEC(name) __CONCAT(X,name) extern inthand_t @@ -79,6 +82,7 @@ IDTVEC(div), IDTVEC(dbg), IDTVEC(nmi), I IDTVEC(page), IDTVEC(mchk), IDTVEC(rsvd), IDTVEC(fpu), IDTVEC(align), IDTVEC(xmm), IDTVEC(lcall_syscall), IDTVEC(int0x80_syscall); + int xendebug_flags; start_info_t *xen_start_info; shared_info_t *HYPERVISOR_shared_info; @@ -86,7 +90,6 @@ xen_pfn_t *xen_machine_phys = machine_to xen_pfn_t *xen_phys_machine; int preemptable, init_first; extern unsigned int avail_space; -extern int gdt_set; void ni_cli(void); void ni_sti(void); @@ -175,6 +178,8 @@ printk(const char *fmt, ...) int retval; static char buf[PRINTK_BUFSIZE]; + return; + va_start(ap, fmt); retval = vsnprintf(buf, PRINTK_BUFSIZE - 1, fmt, ap); va_end(ap); @@ -184,28 +189,38 @@ printk(const char *fmt, ...) #define XPQUEUE_SIZE 128 + +struct mmu_log { + char *file; + int line; +}; + #ifdef SMP /* per-cpu queues and indices */ -static mmu_update_t xpq_queue[MAX_VIRT_CPUS][XPQUEUE_SIZE]; +#ifdef INVARIANTS +static struct mmu_log xpq_queue_log[MAX_VIRT_CPUS][XPQUEUE_SIZE]; +#endif + static int xpq_idx[MAX_VIRT_CPUS]; +static mmu_update_t xpq_queue[MAX_VIRT_CPUS][XPQUEUE_SIZE]; #define XPQ_QUEUE xpq_queue[vcpu] #define XPQ_IDX xpq_idx[vcpu] #define SET_VCPU() int vcpu = smp_processor_id() + +#define XPQ_QUEUE_LOG xpq_queue_log[vcpu] #else -struct mmu_log { - char *file; - int line; -}; static mmu_update_t xpq_queue[XPQUEUE_SIZE]; static struct mmu_log xpq_queue_log[XPQUEUE_SIZE]; static int xpq_idx = 0; +#define XPQ_QUEUE_LOG xpq_queue_log #define XPQ_QUEUE xpq_queue #define XPQ_IDX xpq_idx #define SET_VCPU() -#endif +#endif /* !SMP */ + #define XPQ_IDX_INC atomic_add_int(&XPQ_IDX, 1); #if 0 @@ -234,7 +249,7 @@ _xen_flush_queue(void) int error, i; /* window of vulnerability here? */ - if (__predict_true(gdt_set)) + if (__predict_true(gdtset)) critical_enter(); XPQ_IDX = 0; /* Make sure index is cleared first to avoid double updates. */ @@ -242,31 +257,39 @@ _xen_flush_queue(void) _xpq_idx, NULL, DOMID_SELF); #if 0 - if (__predict_true(gdt_set)) + if (__predict_true(gdtset)) for (i = _xpq_idx; i > 0;) { if (i >= 3) { - CTR6(KTR_PMAP, "mmu:val: %lx ptr: %lx val: %lx ptr: %lx val: %lx ptr: %lx", - (XPQ_QUEUE[i-1].val & 0xffffffff), (XPQ_QUEUE[i-1].ptr & 0xffffffff), - (XPQ_QUEUE[i-2].val & 0xffffffff), (XPQ_QUEUE[i-2].ptr & 0xffffffff), - (XPQ_QUEUE[i-3].val & 0xffffffff), (XPQ_QUEUE[i-3].ptr & 0xffffffff)); + CTR6(KTR_PMAP, "mmu:val: %lx ptr: %lx val: %lx " + "ptr: %lx val: %lx ptr: %lx", + (XPQ_QUEUE[i-1].val & 0xffffffff), + (XPQ_QUEUE[i-1].ptr & 0xffffffff), + (XPQ_QUEUE[i-2].val & 0xffffffff), + (XPQ_QUEUE[i-2].ptr & 0xffffffff), + (XPQ_QUEUE[i-3].val & 0xffffffff), + (XPQ_QUEUE[i-3].ptr & 0xffffffff)); i -= 3; } else if (i == 2) { CTR4(KTR_PMAP, "mmu: val: %lx ptr: %lx val: %lx ptr: %lx", - (XPQ_QUEUE[i-1].val & 0xffffffff), (XPQ_QUEUE[i-1].ptr & 0xffffffff), - (XPQ_QUEUE[i-2].val & 0xffffffff), (XPQ_QUEUE[i-2].ptr & 0xffffffff)); + (XPQ_QUEUE[i-1].val & 0xffffffff), + (XPQ_QUEUE[i-1].ptr & 0xffffffff), + (XPQ_QUEUE[i-2].val & 0xffffffff), + (XPQ_QUEUE[i-2].ptr & 0xffffffff)); i = 0; } else { CTR2(KTR_PMAP, "mmu: val: %lx ptr: %lx", - (XPQ_QUEUE[i-1].val & 0xffffffff), (XPQ_QUEUE[i-1].ptr & 0xffffffff)); + (XPQ_QUEUE[i-1].val & 0xffffffff), + (XPQ_QUEUE[i-1].ptr & 0xffffffff)); i = 0; } } #endif - if (__predict_true(gdt_set)) + if (__predict_true(gdtset)) critical_exit(); if (__predict_false(error < 0)) { for (i = 0; i < _xpq_idx; i++) - printf("val: %llx ptr: %llx\n", XPQ_QUEUE[i].val, XPQ_QUEUE[i].ptr); + printf("val: %llx ptr: %llx\n", + XPQ_QUEUE[i].val, XPQ_QUEUE[i].ptr); panic("Failed to execute MMU updates: %d", error); } @@ -292,7 +315,11 @@ xen_increment_idx(void) void xen_check_queue(void) { +#ifdef INVARIANTS + SET_VCPU(); + KASSERT(XPQ_IDX == 0, ("pending operations XPQ_IDX=%d", XPQ_IDX)); +#endif } void @@ -305,56 +332,86 @@ xen_invlpg(vm_offset_t va) } void -xen_load_cr3(vm_paddr_t val) +xen_load_cr3(u_int val) { struct mmuext_op op; - +#ifdef INVARIANTS + SET_VCPU(); + KASSERT(XPQ_IDX == 0, ("pending operations XPQ_IDX=%d", XPQ_IDX)); +#endif op.cmd = MMUEXT_NEW_BASEPTR; op.arg1.mfn = xpmap_ptom(val) >> PAGE_SHIFT; PANIC_IF(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0); } void -_xen_machphys_update(vm_paddr_t mfn, vm_paddr_t pfn, char *file, int line) +xen_restore_flags(u_int eflags) { - if (__predict_true(gdt_set)) - critical_enter(); + __restore_flags(eflags); +} + +int +xen_save_and_cli(void) +{ + int eflags; + + __save_and_cli(eflags); + return (eflags); +} + +void +xen_cli(void) +{ + __cli(); +} + +void +xen_sti(void) +{ + __sti(); +} + +void +_xen_machphys_update(vm_paddr_t mfn, vm_paddr_t pfn, char *file, int line) +{ SET_VCPU(); + + if (__predict_true(gdtset)) + critical_enter(); XPQ_QUEUE[XPQ_IDX].ptr = (mfn << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE; XPQ_QUEUE[XPQ_IDX].val = pfn; #ifdef INVARIANTS - xpq_queue_log[XPQ_IDX].file = file; - xpq_queue_log[XPQ_IDX].line = line; + XPQ_QUEUE_LOG[XPQ_IDX].file = file; + XPQ_QUEUE_LOG[XPQ_IDX].line = line; #endif xen_increment_idx(); - if (__predict_true(gdt_set)) + if (__predict_true(gdtset)) critical_exit(); } void _xen_queue_pt_update(vm_paddr_t ptr, vm_paddr_t val, char *file, int line) { + SET_VCPU(); - - if (__predict_true(gdt_set)) + if (__predict_true(gdtset)) mtx_assert(&vm_page_queue_mtx, MA_OWNED); - if (__predict_true(gdt_set)) + KASSERT((ptr & 7) == 0, ("misaligned update")); + + if (__predict_true(gdtset)) critical_enter(); - SET_VCPU(); + XPQ_QUEUE[XPQ_IDX].ptr = ((uint64_t)ptr) | MMU_NORMAL_PT_UPDATE; XPQ_QUEUE[XPQ_IDX].val = (uint64_t)val; - if (val) - KASSERT(val & PG_V, - ("setting invalid address ptr=0x%jx 0x%jx", ptr, val)); #ifdef INVARIANTS - xpq_queue_log[XPQ_IDX].file = file; - xpq_queue_log[XPQ_IDX].line = line; + XPQ_QUEUE_LOG[XPQ_IDX].file = file; + XPQ_QUEUE_LOG[XPQ_IDX].line = line; #endif xen_increment_idx(); - if (__predict_true(gdt_set)) + if (__predict_true(gdtset)) critical_exit(); } @@ -503,7 +560,6 @@ xen_create_contiguous_region(vm_page_t p .domid = DOMID_SELF }; set_xen_guest_handle(reservation.extent_start, &mfn); - balloon_lock(flags); @@ -633,7 +689,7 @@ extern unsigned long *SMPpt; extern struct user *proc0uarea; extern vm_offset_t proc0kstack; extern int vm86paddr, vm86phystk; -char *bootmem_start, *bootmem_current, *bootmem_end; +char *bootmem_start, *bootmem_current, *bootmem_end; pteinfo_t *pteinfo_list; void initvalues(start_info_t *startinfo); @@ -745,9 +801,13 @@ shift_phys_machine(unsigned long *phys_m memset(phys_machine, INVALID_P2M_ENTRY, PAGE_SIZE); } -#endif +#endif /* ADD_ISA_HOLE */ extern unsigned long physfree; + +int pdir, curoffset; +extern int nkpt; + void initvalues(start_info_t *startinfo) { @@ -763,11 +823,20 @@ initvalues(start_info_t *startinfo) vm_paddr_t IdlePDPTma, IdlePDPTnewma; vm_paddr_t IdlePTDnewma[4]; pd_entry_t *IdlePDPTnew, *IdlePTDnew; +#else + vm_paddr_t pdir_shadow_ma; #endif unsigned long i; + int ncpus; + nkpt = min(max((startinfo->nr_pages >> NPGPTD_SHIFT), nkpt), + NPGPTD*NPDEPG - KPTDI); +#ifdef SMP + ncpus = MAXCPU; +#else + ncpus = 1; +#endif - HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_writable_pagetables); HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments); #ifdef notyet /* @@ -783,7 +852,9 @@ initvalues(start_info_t *startinfo) ((xen_start_info->nr_pt_frames) + 3 )*PAGE_SIZE; printk("initvalues(): wooh - availmem=%x,%x\n", avail_space, cur_space); - printk("KERNBASE=%x,pt_base=%x, VTOPFN(base)=%x, nr_pt_frames=%x\n", KERNBASE,xen_start_info->pt_base, VTOPFN(xen_start_info->pt_base), xen_start_info->nr_pt_frames); + printk("KERNBASE=%x,pt_base=%x, VTOPFN(base)=%x, nr_pt_frames=%x\n", + KERNBASE,xen_start_info->pt_base, VTOPFN(xen_start_info->pt_base), + xen_start_info->nr_pt_frames); xendebug_flags = 0; /* 0xffffffff; */ /* allocate 4 pages for bootmem allocator */ @@ -797,13 +868,13 @@ initvalues(start_info_t *startinfo) /* * pre-zero unused mapped pages - mapped on 4MB boundary */ -/* - bzero((char *)cur_space, (cur_space + 0x3fffff) % 0x400000); - */ - #ifdef PAE IdlePDPT = (pd_entry_t *)startinfo->pt_base; IdlePDPTma = xpmap_ptom(VTOP(startinfo->pt_base)); + /* + * Note that only one page directory has been allocated at this point. + * Thus, if KERNBASE + */ IdlePTD = (pd_entry_t *)((uint8_t *)startinfo->pt_base + PAGE_SIZE); IdlePTDma = xpmap_ptom(VTOP(IdlePTD)); l3_pages = 1; @@ -813,9 +884,10 @@ initvalues(start_info_t *startinfo) l3_pages = 0; #endif l2_pages = 1; - l1_pages = 4; /* XXX not certain if this varies */ + l1_pages = xen_start_info->nr_pt_frames - l2_pages - l3_pages; + KPTphysoff = (l2_pages + l3_pages)*PAGE_SIZE; - + KPTphys = xpmap_ptom(VTOP(startinfo->pt_base + KPTphysoff)); XENPRINTF("IdlePTD %p\n", IdlePTD); XENPRINTF("nr_pages: %ld shared_info: 0x%lx flags: 0x%lx pt_base: 0x%lx " @@ -827,7 +899,7 @@ initvalues(start_info_t *startinfo) proc0kstack = cur_space; cur_space += (KSTACK_PAGES * PAGE_SIZE); printk("proc0kstack=%u\n", proc0kstack); - + /* vm86/bios stack */ cur_space += PAGE_SIZE; @@ -838,79 +910,100 @@ initvalues(start_info_t *startinfo) #ifdef PAE IdlePDPTnew = (pd_entry_t *)cur_space; cur_space += PAGE_SIZE; bzero(IdlePDPTnew, PAGE_SIZE); + IdlePDPTnewma = xpmap_ptom(VTOP(IdlePDPTnew)); *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-projects@FreeBSD.ORG Thu Oct 16 20:33:03 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B62661065698; Thu, 16 Oct 2008 20:33:03 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A46718FC1C; Thu, 16 Oct 2008 20:33:03 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9GKX3Ms069899; Thu, 16 Oct 2008 20:33:03 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9GKX3Oo069898; Thu, 16 Oct 2008 20:33:03 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810162033.m9GKX3Oo069898@svn.freebsd.org> From: Kip Macy Date: Thu, 16 Oct 2008 20:33:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183959 - projects/releng_6_xen/sys/libkern X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Oct 2008 20:33:03 -0000 Author: kmacy Date: Thu Oct 16 20:33:03 2008 New Revision: 183959 URL: http://svn.freebsd.org/changeset/base/183959 Log: Commit strcspn.c as it is now referenced by the build Added: projects/releng_6_xen/sys/libkern/strcspn.c (contents, props changed) Added: projects/releng_6_xen/sys/libkern/strcspn.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/releng_6_xen/sys/libkern/strcspn.c Thu Oct 16 20:33:03 2008 (r183959) @@ -0,0 +1,72 @@ +/*- + * Copyright (c) 2005 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +#define IDX(c) ((u_char)(c) / LONG_BIT) +#define BIT(c) ((u_long)1 << ((u_char)(c) % LONG_BIT)) + +size_t +strcspn(const char *s, const char *charset) +{ + /* + * NB: idx and bit are temporaries whose use causes gcc 3.4.2 to + * generate better code. Without them, gcc gets a little confused. + */ + const char *s1; + u_long bit; + u_long tbl[(UCHAR_MAX + 1) / LONG_BIT]; + int idx; + + if(*s == '\0') + return (0); + +#if LONG_BIT == 64 /* always better to unroll on 64-bit architectures */ + tbl[0] = 1; + tbl[3] = tbl[2] = tbl[1] = 0; +#else + for (tbl[0] = idx = 1; idx < sizeof(tbl) / sizeof(tbl[0]); idx++) + tbl[idx] = 0; +#endif + for (; *charset != '\0'; charset++) { + idx = IDX(*charset); + bit = BIT(*charset); + tbl[idx] |= bit; + } + + for(s1 = s; ; s1++) { + idx = IDX(*s1); + bit = BIT(*s1); + if ((tbl[idx] & bit) != 0) + break; + } + return (s1 - s); +} From owner-svn-src-projects@FreeBSD.ORG Thu Oct 16 22:45:07 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9C8BB1065687; Thu, 16 Oct 2008 22:45:07 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 899EE8FC14; Thu, 16 Oct 2008 22:45:07 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9GMj7uW072210; Thu, 16 Oct 2008 22:45:07 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9GMj7cw072203; Thu, 16 Oct 2008 22:45:07 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810162245.m9GMj7cw072203@svn.freebsd.org> From: Kip Macy Date: Thu, 16 Oct 2008 22:45:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183962 - in projects/releng_6_xen/sys/i386: conf i386 include/xen isa pci xen X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Oct 2008 22:45:07 -0000 Author: kmacy Date: Thu Oct 16 22:45:07 2008 New Revision: 183962 URL: http://svn.freebsd.org/changeset/base/183962 Log: - Fix floating point handling for xen - Enable SMP Modified: projects/releng_6_xen/sys/i386/conf/XEN projects/releng_6_xen/sys/i386/i386/machdep.c projects/releng_6_xen/sys/i386/include/xen/xen-os.h projects/releng_6_xen/sys/i386/isa/npx.c projects/releng_6_xen/sys/i386/pci/pci_cfgreg.c projects/releng_6_xen/sys/i386/pci/pci_pir.c projects/releng_6_xen/sys/i386/xen/pmap.c Modified: projects/releng_6_xen/sys/i386/conf/XEN ============================================================================== --- projects/releng_6_xen/sys/i386/conf/XEN Thu Oct 16 20:56:09 2008 (r183961) +++ projects/releng_6_xen/sys/i386/conf/XEN Thu Oct 16 22:45:07 2008 (r183962) @@ -67,8 +67,8 @@ options INVARIANT_SUPPORT # Extra sanit #options WITNESS_SKIPSPIN # Don't run witness on spinlocks for speed # To make an SMP kernel, the next two lines are needed -#options SMP # Symmetric MultiProcessor Kernel -#device apic # I/O APIC +options SMP # Symmetric MultiProcessor Kernel +device apic # I/O APIC options PAE @@ -104,6 +104,8 @@ device splash # Splash screen and scre # Add suspend/resume support for the i8254. #device pmtimer # native +device pci + # Serial (COM) ports device uart # Generic UART driver Modified: projects/releng_6_xen/sys/i386/i386/machdep.c ============================================================================== --- projects/releng_6_xen/sys/i386/i386/machdep.c Thu Oct 16 20:56:09 2008 (r183961) +++ projects/releng_6_xen/sys/i386/i386/machdep.c Thu Oct 16 22:45:07 2008 (r183962) @@ -152,7 +152,6 @@ uint32_t arch_i386_xbox_memsize = 0; void Xhypervisor_callback(void); void failsafe_callback(void); -int gdtset; extern trap_info_t trap_table[]; struct proc_ldt default_proc_ldt; extern int init_first; @@ -1195,7 +1194,7 @@ void cpu_idle(void) { -#ifdef SMP +#if defined(SMP) && !defined(XEN) if (mp_grab_cpu_hlt()) return; #endif Modified: projects/releng_6_xen/sys/i386/include/xen/xen-os.h ============================================================================== --- projects/releng_6_xen/sys/i386/include/xen/xen-os.h Thu Oct 16 20:56:09 2008 (r183961) +++ projects/releng_6_xen/sys/i386/include/xen/xen-os.h Thu Oct 16 22:45:07 2008 (r183962) @@ -37,7 +37,7 @@ extern int gdtset; static inline int smp_processor_id(void) { - if (likely(gdtset)) + if (__predict_true(gdtset)) return PCPU_GET(cpuid); return 0; } Modified: projects/releng_6_xen/sys/i386/isa/npx.c ============================================================================== --- projects/releng_6_xen/sys/i386/isa/npx.c Thu Oct 16 20:56:09 2008 (r183961) +++ projects/releng_6_xen/sys/i386/isa/npx.c Thu Oct 16 22:45:07 2008 (r183962) @@ -69,6 +69,9 @@ __FBSDID("$FreeBSD$"); #include #include +#ifdef XEN +#include +#endif #ifdef DEV_ISA #include #endif @@ -101,10 +104,15 @@ __FBSDID("$FreeBSD$"); #define fxsave(addr) __asm __volatile("fxsave %0" : "=m" (*(addr))) #define ldmxcsr(__csr) __asm __volatile("ldmxcsr %0" : : "m" (__csr)) #endif +#ifdef XEN +#define start_emulating() (HYPERVISOR_fpu_taskswitch(1)) +#define stop_emulating() (HYPERVISOR_fpu_taskswitch(0)) +#else #define start_emulating() __asm("smsw %%ax; orb %0,%%al; lmsw %%ax" \ : : "n" (CR0_TS) : "ax") #define stop_emulating() __asm("clts") +#endif #else /* !(__GNUCLIKE_ASM && !lint) */ void fldcw(caddr_t addr); Modified: projects/releng_6_xen/sys/i386/pci/pci_cfgreg.c ============================================================================== --- projects/releng_6_xen/sys/i386/pci/pci_cfgreg.c Thu Oct 16 20:56:09 2008 (r183961) +++ projects/releng_6_xen/sys/i386/pci/pci_cfgreg.c Thu Oct 16 22:45:07 2008 (r183962) @@ -82,9 +82,10 @@ static struct mtx pcicfg_mtx; static int pcireg_cfgread(int bus, int slot, int func, int reg, int bytes); static void pcireg_cfgwrite(int bus, int slot, int func, int reg, int data, int bytes); +#ifndef XEN static int pcireg_cfgopen(void); - static int pciereg_cfgopen(void); +#endif static int pciereg_cfgread(int bus, int slot, int func, int reg, int bytes); static void pciereg_cfgwrite(int bus, int slot, int func, int reg, @@ -105,6 +106,7 @@ pci_i386_map_intline(int line) return (line); } +#ifndef XEN static u_int16_t pcibios_get_version(void) { @@ -125,6 +127,7 @@ pcibios_get_version(void) } return (args.ebx & 0xffff); } +#endif /* * Initialise access to PCI configuration space @@ -132,6 +135,9 @@ pcibios_get_version(void) int pci_cfgregopen(void) { +#ifdef XEN + return (0); +#else static int opened = 0; u_int16_t vid, did; u_int16_t v; @@ -171,6 +177,7 @@ pci_cfgregopen(void) } return(1); +#endif /* !XEN */ } /* @@ -349,6 +356,7 @@ pcireg_cfgwrite(int bus, int slot, int f mtx_unlock_spin(&pcicfg_mtx); } +#ifndef XEN /* check whether the configuration mechanism has been correctly identified */ static int pci_cfgcheck(int maxdev) @@ -526,6 +534,7 @@ pciereg_cfgopen(void) devmax = 32; return (1); } +#endif /* !XEN */ #define PCIE_PADDR(bar, reg, bus, slot, func) \ ((bar) | \ Modified: projects/releng_6_xen/sys/i386/pci/pci_pir.c ============================================================================== --- projects/releng_6_xen/sys/i386/pci/pci_pir.c Thu Oct 16 20:56:09 2008 (r183961) +++ projects/releng_6_xen/sys/i386/pci/pci_pir.c Thu Oct 16 22:45:07 2008 (r183962) @@ -137,6 +137,10 @@ pci_pir_open(void) int i; uint8_t ck, *cv; +#ifdef XEN + return; +#else + /* Don't try if we've already found a table. */ if (pci_route_table != NULL) return; @@ -147,7 +151,7 @@ pci_pir_open(void) sigaddr = bios_sigsearch(0, "_PIR", 4, 16, 0); if (sigaddr == 0) return; - +#endif /* If we found something, check the checksum and length. */ /* XXX - Use pmap_mapdev()? */ pt = (struct PIR_table *)(uintptr_t)BIOS_PADDRTOVADDR(sigaddr); @@ -478,7 +482,11 @@ pci_pir_biosroute(int bus, int device, i args.eax = PCIBIOS_ROUTE_INTERRUPT; args.ebx = (bus << 8) | (device << 3) | func; args.ecx = (irq << 8) | (0xa + pin); +#ifdef XEN + return (0); +#else return (bios32(&args, PCIbios.ventry, GSEL(GCODE_SEL, SEL_KPL))); +#endif } Modified: projects/releng_6_xen/sys/i386/xen/pmap.c ============================================================================== --- projects/releng_6_xen/sys/i386/xen/pmap.c Thu Oct 16 20:56:09 2008 (r183961) +++ projects/releng_6_xen/sys/i386/xen/pmap.c Thu Oct 16 22:45:07 2008 (r183962) @@ -1424,7 +1424,6 @@ pmap_pinit(struct pmap *pmap) LIST_INSERT_HEAD(&allpmaps, pmap, pm_list); mtx_unlock_spin(&allpmaps_lock); /* Wire in kernel global address entries. */ - /* XXX copies current process, does not fill in MPPTDI */ bcopy(PTD + KPTDI, pmap->pm_pdir + KPTDI, nkpt * sizeof(pd_entry_t)); #ifdef PAE @@ -1442,11 +1441,6 @@ pmap_pinit(struct pmap *pmap) } #endif -#ifdef SMP - pmap->pm_pdir[MPPTDI] = PTD[MPPTDI]; -#endif - - #ifdef XEN for (i = 0; i < NPGPTD; i++) { pt_entry_t *pd; @@ -1742,9 +1736,6 @@ pmap_release(pmap_t pmap) bzero(pmap->pm_pdir + PTDPTDI, (nkpt + NPGPTD) * sizeof(*pmap->pm_pdir)); -#ifdef SMP - pmap->pm_pdir[MPPTDI] = 0; -#endif pmap_qremove((vm_offset_t)pmap->pm_pdir, NPGPTD); #if defined(PAE) && defined(XEN) From owner-svn-src-projects@FreeBSD.ORG Fri Oct 17 22:18:35 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7C5A61065691; Fri, 17 Oct 2008 22:18:35 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6BBCD8FC14; Fri, 17 Oct 2008 22:18:35 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9HMIZFS099207; Fri, 17 Oct 2008 22:18:35 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9HMIZEN099205; Fri, 17 Oct 2008 22:18:35 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810172218.m9HMIZEN099205@svn.freebsd.org> From: Kip Macy Date: Fri, 17 Oct 2008 22:18:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183991 - in projects/releng_6_xen/sys/i386: i386 xen X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Oct 2008 22:18:35 -0000 Author: kmacy Date: Fri Oct 17 22:18:35 2008 New Revision: 183991 URL: http://svn.freebsd.org/changeset/base/183991 Log: Fix issues in bootstrap Modified: projects/releng_6_xen/sys/i386/i386/support.s projects/releng_6_xen/sys/i386/xen/xen_machdep.c Modified: projects/releng_6_xen/sys/i386/i386/support.s ============================================================================== --- projects/releng_6_xen/sys/i386/i386/support.s Fri Oct 17 21:29:05 2008 (r183990) +++ projects/releng_6_xen/sys/i386/i386/support.s Fri Oct 17 22:18:35 2008 (r183991) @@ -1426,10 +1426,11 @@ ENTRY(bcmp) */ /* void lgdt(struct region_descriptor *rdp); */ ENTRY(lgdt) +#ifndef XEN /* reload the descriptor table */ movl 4(%esp),%eax lgdt (%eax) - +#endif /* flush the prefetch q */ jmp 1f nop Modified: projects/releng_6_xen/sys/i386/xen/xen_machdep.c ============================================================================== --- projects/releng_6_xen/sys/i386/xen/xen_machdep.c Fri Oct 17 21:29:05 2008 (r183990) +++ projects/releng_6_xen/sys/i386/xen/xen_machdep.c Fri Oct 17 22:18:35 2008 (r183991) @@ -962,7 +962,7 @@ initvalues(start_info_t *startinfo) xen_pgdpt_pin(xpmap_ptom(VTOP(IdlePDPTnew))); /* allocate remainder of nkpt pages */ - for (offset = (KERNBASE >> PDRSHIFT), i = l1_pages - 1; i < nkpt; + for (offset = (KERNBASE >> PDRSHIFT), i = l1_pages; i < nkpt; i++, cur_space += PAGE_SIZE) { pdir = (offset + i) / NPDEPG; curoffset = ((offset + i) % NPDEPG); From owner-svn-src-projects@FreeBSD.ORG Fri Oct 17 23:03:36 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3BCAB106568A; Fri, 17 Oct 2008 23:03:36 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2AD748FC14; Fri, 17 Oct 2008 23:03:36 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9HN3auM000567; Fri, 17 Oct 2008 23:03:36 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9HN3ZYl000564; Fri, 17 Oct 2008 23:03:35 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810172303.m9HN3ZYl000564@svn.freebsd.org> From: Kip Macy Date: Fri, 17 Oct 2008 23:03:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184003 - in projects/releng_6_xen/sys/i386: include xen X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Oct 2008 23:03:36 -0000 Author: kmacy Date: Fri Oct 17 23:03:35 2008 New Revision: 184003 URL: http://svn.freebsd.org/changeset/base/184003 Log: - don't rely on expensive rcr2 emulation - fix trap handling to use old-style pass by value of the trapframe Modified: projects/releng_6_xen/sys/i386/include/cpufunc.h projects/releng_6_xen/sys/i386/xen/exception.s projects/releng_6_xen/sys/i386/xen/xen_machdep.c Modified: projects/releng_6_xen/sys/i386/include/cpufunc.h ============================================================================== --- projects/releng_6_xen/sys/i386/include/cpufunc.h Fri Oct 17 22:55:47 2008 (r184002) +++ projects/releng_6_xen/sys/i386/include/cpufunc.h Fri Oct 17 23:03:35 2008 (r184003) @@ -45,6 +45,7 @@ #ifdef XEN extern void xen_cli(void); extern void xen_sti(void); +extern u_int xen_rcr2(void); extern void xen_load_cr3(u_int data); extern void xen_tlb_flush(void); extern void xen_invlpg(u_int addr); @@ -410,6 +411,9 @@ rcr2(void) { u_int data; +#ifdef XEN + return (xen_rcr2()); +#endif __asm __volatile("movl %%cr2,%0" : "=r" (data)); return (data); } Modified: projects/releng_6_xen/sys/i386/xen/exception.s ============================================================================== --- projects/releng_6_xen/sys/i386/xen/exception.s Fri Oct 17 22:55:47 2008 (r184002) +++ projects/releng_6_xen/sys/i386/xen/exception.s Fri Oct 17 23:03:35 2008 (r184003) @@ -93,8 +93,6 @@ MCOUNT_LABEL(user) MCOUNT_LABEL(btrap) -#define TRAP(a) pushl $(a) ; jmp alltraps - IDTVEC(div) pushl $0; TRAP(T_DIVIDE) IDTVEC(dbg) @@ -182,11 +180,9 @@ alltraps: pushl %ds pushl %es pushl %fs - alltraps_with_regs_pushed: SET_KERNEL_SREGS FAKE_MCOUNT(TF_EIP(%esp)) - calltrap: call trap @@ -220,9 +216,7 @@ IDTVEC(lcall_syscall) pushl %fs SET_KERNEL_SREGS FAKE_MCOUNT(TF_EIP(%esp)) - pushl %esp call syscall - add $4, %esp MEXITCOUNT jmp doreti @@ -236,16 +230,14 @@ IDTVEC(lcall_syscall) SUPERALIGN_TEXT IDTVEC(int0x80_syscall) pushl $2 /* sizeof "int 0x80" */ - pushl $0xBEEF /* for debug */ + subl $4,%esp /* skip over tf_trapno */ pushal pushl %ds pushl %es pushl %fs SET_KERNEL_SREGS FAKE_MCOUNT(TF_EIP(%esp)) - pushl %esp call syscall - add $4, %esp MEXITCOUNT jmp doreti @@ -283,7 +275,6 @@ MCOUNT_LABEL(bintr) #ifdef DEV_ATPIC #include #endif - #ifdef DEV_APIC .data .p2align 4 @@ -385,8 +376,7 @@ doreti_popl_ds: addl $8,%esp .globl doreti_iret doreti_iret: -/* #jmp hypercall_page + (__HYPERVISOR_iret * 32) */ - iret + jmp hypercall_page + (__HYPERVISOR_iret * 32) .globl ecrit ecrit: /* @@ -459,8 +449,10 @@ critical_fixup_table: .byte 0x24 #pop %ecx .byte 0x28 #pop %eax .byte 0x2c,0x2c,0x2c #add $0x8,%esp +#if 0 .byte 0x34 #iret -/* .byte 0x34,0x34,0x34,0x34,0x34 #HYPERVISOR_iret */ +#endif +.byte 0x34,0x34,0x34,0x34,0x34 #HYPERVISOR_iret /* # Hypervisor uses this for application faults while it executes.*/ Modified: projects/releng_6_xen/sys/i386/xen/xen_machdep.c ============================================================================== --- projects/releng_6_xen/sys/i386/xen/xen_machdep.c Fri Oct 17 22:55:47 2008 (r184002) +++ projects/releng_6_xen/sys/i386/xen/xen_machdep.c Fri Oct 17 23:03:35 2008 (r184003) @@ -373,6 +373,13 @@ xen_sti(void) __sti(); } +u_int +xen_rcr2(void) +{ + + return (HYPERVISOR_shared_info->vcpu_info[curcpu].arch.cr2); +} + void _xen_machphys_update(vm_paddr_t mfn, vm_paddr_t pfn, char *file, int line) { From owner-svn-src-projects@FreeBSD.ORG Fri Oct 17 23:23:50 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 887D5106568E; Fri, 17 Oct 2008 23:23:50 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 77E5E8FC0A; Fri, 17 Oct 2008 23:23:50 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9HNNoZx000951; Fri, 17 Oct 2008 23:23:50 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9HNNodf000950; Fri, 17 Oct 2008 23:23:50 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810172323.m9HNNodf000950@svn.freebsd.org> From: Kip Macy Date: Fri, 17 Oct 2008 23:23:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184004 - projects/releng_6_xen/sys/i386/xen X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Oct 2008 23:23:50 -0000 Author: kmacy Date: Fri Oct 17 23:23:50 2008 New Revision: 184004 URL: http://svn.freebsd.org/changeset/base/184004 Log: Don't set nkpt higher than the max required to map KVA Modified: projects/releng_6_xen/sys/i386/xen/xen_machdep.c Modified: projects/releng_6_xen/sys/i386/xen/xen_machdep.c ============================================================================== --- projects/releng_6_xen/sys/i386/xen/xen_machdep.c Fri Oct 17 23:03:35 2008 (r184003) +++ projects/releng_6_xen/sys/i386/xen/xen_machdep.c Fri Oct 17 23:23:50 2008 (r184004) @@ -836,8 +836,12 @@ initvalues(start_info_t *startinfo) unsigned long i; int ncpus; - nkpt = min(max((startinfo->nr_pages >> NPGPTD_SHIFT), nkpt), - NPGPTD*NPDEPG - KPTDI); + nkpt = min( + min( + max((startinfo->nr_pages >> NPGPTD_SHIFT), nkpt), + NPGPTD*NPDEPG - KPTDI), + (HYPERVISOR_VIRT_START - KERNBASE) >> PDRSHIFT); + #ifdef SMP ncpus = MAXCPU; #else @@ -973,6 +977,8 @@ initvalues(start_info_t *startinfo) i++, cur_space += PAGE_SIZE) { pdir = (offset + i) / NPDEPG; curoffset = ((offset + i) % NPDEPG); + if (((offset + i) << PDRSHIFT) == VM_MAX_KERNEL_ADDRESS) + break; /* * make sure that all the initial page table pages From owner-svn-src-projects@FreeBSD.ORG Sat Oct 18 01:12:02 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9384F106568B; Sat, 18 Oct 2008 01:12:02 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 827CB8FC19; Sat, 18 Oct 2008 01:12:02 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9I1C2jc002866; Sat, 18 Oct 2008 01:12:02 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9I1C2as002865; Sat, 18 Oct 2008 01:12:02 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810180112.m9I1C2as002865@svn.freebsd.org> From: Kip Macy Date: Sat, 18 Oct 2008 01:12:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184007 - projects/releng_6_xen/sys/i386/xen X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Oct 2008 01:12:02 -0000 Author: kmacy Date: Sat Oct 18 01:12:02 2008 New Revision: 184007 URL: http://svn.freebsd.org/changeset/base/184007 Log: - allocate data structure pages from before the nkpt allocation - calculate the pre-allocated l1 pages by looking at the initial IdlePTD Modified: projects/releng_6_xen/sys/i386/xen/xen_machdep.c Modified: projects/releng_6_xen/sys/i386/xen/xen_machdep.c ============================================================================== --- projects/releng_6_xen/sys/i386/xen/xen_machdep.c Fri Oct 17 23:28:00 2008 (r184006) +++ projects/releng_6_xen/sys/i386/xen/xen_machdep.c Sat Oct 18 01:12:02 2008 (r184007) @@ -819,7 +819,7 @@ void initvalues(start_info_t *startinfo) { int l3_pages, l2_pages, l1_pages, offset; - vm_offset_t cur_space; + vm_offset_t cur_space, cur_space_pt; struct physdev_set_iopl set_iopl; vm_paddr_t KPTphys, IdlePTDma; @@ -873,6 +873,23 @@ initvalues(start_info_t *startinfo) cur_space += (4 * PAGE_SIZE); bootmem_end = (char *)cur_space; + /* allocate page for gdt */ + gdt = (union descriptor *)cur_space; + cur_space += PAGE_SIZE*ncpus; + + /* allocate page for ldt */ + ldt = (union descriptor *)cur_space; cur_space += PAGE_SIZE; + cur_space += PAGE_SIZE; + + HYPERVISOR_shared_info = (shared_info_t *)cur_space; + cur_space += PAGE_SIZE; + + xen_store = (struct ringbuf_head *)cur_space; + cur_space += PAGE_SIZE; + + console_page = (char *)cur_space; + cur_space += PAGE_SIZE; + #ifdef ADD_ISA_HOLE shift_phys_machine(xen_phys_machine, xen_start_info->nr_pages); #endif @@ -949,6 +966,16 @@ initvalues(start_info_t *startinfo) * Unpin the current PDPT */ xen_pt_unpin(IdlePDPTma); + + for (i = 0; i < l1_pages; i++) { + int startidx = ((KERNBASE >> 18) & PAGE_MASK) >> 3; + + if (IdlePTD[startidx + i] == 0) { + l1_pages = i - 1; + break; + } + } + #endif /* PAE */ /* unmap remaining pages from initial 4MB chunk @@ -960,7 +987,9 @@ initvalues(start_info_t *startinfo) } PT_UPDATES_FLUSH(); - + + + memcpy(((uint8_t *)IdlePTDnew) + ((unsigned int)(KERNBASE >> 18)), ((uint8_t *)IdlePTD) + ((KERNBASE >> 18) & PAGE_MASK), l1_pages*sizeof(pt_entry_t)); @@ -973,6 +1002,7 @@ initvalues(start_info_t *startinfo) xen_pgdpt_pin(xpmap_ptom(VTOP(IdlePDPTnew))); /* allocate remainder of nkpt pages */ + cur_space_pt = cur_space; for (offset = (KERNBASE >> PDRSHIFT), i = l1_pages; i < nkpt; i++, cur_space += PAGE_SIZE) { pdir = (offset + i) / NPDEPG; @@ -984,9 +1014,10 @@ initvalues(start_info_t *startinfo) * make sure that all the initial page table pages * have been zeroed */ - PT_SET_MA(cur_space, xpmap_ptom(VTOP(cur_space)) | PG_V | PG_RW); - bzero((char *)cur_space, PAGE_SIZE); - PT_SET_MA(cur_space, (vm_paddr_t)0); + PT_SET_MA(cur_space_pt, + xpmap_ptom(VTOP(cur_space)) | PG_V | PG_RW); + bzero((char *)cur_space_pt, PAGE_SIZE); + PT_SET_MA(cur_space_pt, (vm_paddr_t)0); xen_pt_pin(xpmap_ptom(VTOP(cur_space))); xen_queue_pt_update((vm_paddr_t)(IdlePTDnewma[pdir] + curoffset*sizeof(vm_paddr_t)), @@ -1009,17 +1040,6 @@ initvalues(start_info_t *startinfo) IdlePDPT = IdlePDPTnew; IdlePDPTma = IdlePDPTnewma; - /* allocate page for gdt */ - gdt = (union descriptor *)cur_space; - cur_space += PAGE_SIZE*ncpus; - - /* allocate page for ldt */ - ldt = (union descriptor *)cur_space; cur_space += PAGE_SIZE; - cur_space += PAGE_SIZE; - - HYPERVISOR_shared_info = (shared_info_t *)cur_space; - cur_space += PAGE_SIZE; - /* * shared_info is an unsigned long so this will randomly break if * it is allocated above 4GB - I guess people are used to that @@ -1030,13 +1050,9 @@ initvalues(start_info_t *startinfo) printk("#4\n"); - xen_store = (struct ringbuf_head *)cur_space; - cur_space += PAGE_SIZE; xen_store_ma = (((vm_paddr_t)xen_start_info->store_mfn) << PAGE_SHIFT); PT_SET_MA(xen_store, xen_store_ma | PG_KERNEL); - console_page = (char *)cur_space; - cur_space += PAGE_SIZE; console_page_ma = (((vm_paddr_t)xen_start_info->console.domU.mfn) << PAGE_SHIFT); PT_SET_MA(console_page, console_page_ma | PG_KERNEL); From owner-svn-src-projects@FreeBSD.ORG Sat Oct 18 03:57:57 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C178D1065686; Sat, 18 Oct 2008 03:57:57 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B099B8FC15; Sat, 18 Oct 2008 03:57:57 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9I3vvNj005954; Sat, 18 Oct 2008 03:57:57 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9I3vvMd005953; Sat, 18 Oct 2008 03:57:57 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810180357.m9I3vvMd005953@svn.freebsd.org> From: Kip Macy Date: Sat, 18 Oct 2008 03:57:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184008 - projects/releng_6_xen/sys/i386/xen X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Oct 2008 03:57:57 -0000 Author: kmacy Date: Sat Oct 18 03:57:57 2008 New Revision: 184008 URL: http://svn.freebsd.org/changeset/base/184008 Log: Evidently deriving l1_pages from nr_pt_frames can be wrong in both directions. Change to always calculate. Modified: projects/releng_6_xen/sys/i386/xen/xen_machdep.c Modified: projects/releng_6_xen/sys/i386/xen/xen_machdep.c ============================================================================== --- projects/releng_6_xen/sys/i386/xen/xen_machdep.c Sat Oct 18 01:12:02 2008 (r184007) +++ projects/releng_6_xen/sys/i386/xen/xen_machdep.c Sat Oct 18 03:57:57 2008 (r184008) @@ -967,11 +967,11 @@ initvalues(start_info_t *startinfo) */ xen_pt_unpin(IdlePDPTma); - for (i = 0; i < l1_pages; i++) { + for (i = 0; i < 20; i++) { int startidx = ((KERNBASE >> 18) & PAGE_MASK) >> 3; if (IdlePTD[startidx + i] == 0) { - l1_pages = i - 1; + l1_pages = i; break; } } From owner-svn-src-projects@FreeBSD.ORG Sat Oct 18 04:26:08 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5EA6D1065686; Sat, 18 Oct 2008 04:26:08 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4D1658FC12; Sat, 18 Oct 2008 04:26:08 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9I4Q8xj006646; Sat, 18 Oct 2008 04:26:08 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9I4Q87T006644; Sat, 18 Oct 2008 04:26:08 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810180426.m9I4Q87T006644@svn.freebsd.org> From: Kip Macy Date: Sat, 18 Oct 2008 04:26:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184011 - in projects/releng_6_xen/sys: conf dev/xen/netfront X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Oct 2008 04:26:08 -0000 Author: kmacy Date: Sat Oct 18 04:26:07 2008 New Revision: 184011 URL: http://svn.freebsd.org/changeset/base/184011 Log: Add newline to sys/conf/files so that netfront.c compiles, s/ext_arg1/ext_args/ Modified: projects/releng_6_xen/sys/conf/files projects/releng_6_xen/sys/dev/xen/netfront/netfront.c Modified: projects/releng_6_xen/sys/conf/files ============================================================================== --- projects/releng_6_xen/sys/conf/files Sat Oct 18 04:13:51 2008 (r184010) +++ projects/releng_6_xen/sys/conf/files Sat Oct 18 04:26:07 2008 (r184011) @@ -2060,4 +2060,4 @@ xen/xenbus/xenbus_xs.c optional dev/xen/console/console.c optional xen dev/xen/console/xencons_ring.c optional xen dev/xen/blkfront/blkfront.c optional xen -dev/xen/netfront/netfront.c optional xen \ No newline at end of file +dev/xen/netfront/netfront.c optional xen Modified: projects/releng_6_xen/sys/dev/xen/netfront/netfront.c ============================================================================== --- projects/releng_6_xen/sys/dev/xen/netfront/netfront.c Sat Oct 18 04:13:51 2008 (r184010) +++ projects/releng_6_xen/sys/dev/xen/netfront/netfront.c Sat Oct 18 04:26:07 2008 (r184011) @@ -28,6 +28,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -347,7 +348,7 @@ makembuf (struct mbuf *buf) m->m_len = buf->m_len; m_copydata(buf, 0, buf->m_pkthdr.len, mtod(m,caddr_t) ); - m->m_ext.ext_arg1 = (caddr_t *)(uintptr_t)(vtophys(mtod(m,caddr_t)) >> PAGE_SHIFT); + m->m_ext.ext_args = (caddr_t *)(uintptr_t)(vtophys(mtod(m,caddr_t)) >> PAGE_SHIFT); return m; } @@ -749,7 +750,7 @@ refill: if ((m_new = mbufq_dequeue(&sc->xn_rx_batch)) == NULL) break; - m_new->m_ext.ext_arg1 = (vm_paddr_t *)(uintptr_t)( + m_new->m_ext.ext_args = (vm_paddr_t *)(uintptr_t)( vtophys(m_new->m_ext.ext_buf) >> PAGE_SHIFT); id = xennet_rxidx(req_prod + i); @@ -1214,7 +1215,7 @@ xennet_get_responses(struct netfront_inf MULTI_update_va_mapping(mcl, (u_long)vaddr, (((vm_paddr_t)mfn) << PAGE_SHIFT) | PG_RW | PG_V | PG_M | PG_A, 0); - pfn = (uint32_t)m->m_ext.ext_arg1; + pfn = (uint32_t)m->m_ext.ext_args; mmu->ptr = ((vm_paddr_t)mfn << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE; mmu->val = pfn; From owner-svn-src-projects@FreeBSD.ORG Sat Oct 18 04:28:22 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3109B1065693; Sat, 18 Oct 2008 04:28:22 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 071198FC16; Sat, 18 Oct 2008 04:28:22 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9I4SL5L006720; Sat, 18 Oct 2008 04:28:21 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9I4SLSf006719; Sat, 18 Oct 2008 04:28:21 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810180428.m9I4SLSf006719@svn.freebsd.org> From: Kip Macy Date: Sat, 18 Oct 2008 04:28:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184012 - projects/release_6_3_xen X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Oct 2008 04:28:22 -0000 Author: kmacy Date: Sat Oct 18 04:28:21 2008 New Revision: 184012 URL: http://svn.freebsd.org/changeset/base/184012 Log: branch to create a 6.3 with Xen support Added: projects/release_6_3_xen/ - copied from r184011, release/6.3.0/ From owner-svn-src-projects@FreeBSD.ORG Sat Oct 18 05:42:59 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 571AB1065696; Sat, 18 Oct 2008 05:42:59 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4533D8FC12; Sat, 18 Oct 2008 05:42:59 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9I5gxv9008031; Sat, 18 Oct 2008 05:42:59 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9I5gxtC008028; Sat, 18 Oct 2008 05:42:59 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810180542.m9I5gxtC008028@svn.freebsd.org> From: Kip Macy Date: Sat, 18 Oct 2008 05:42:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184013 - in projects/releng_6_xen/sys: . dev/usb netinet/libalias X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Oct 2008 05:42:59 -0000 Author: kmacy Date: Sat Oct 18 05:42:58 2008 New Revision: 184013 URL: http://svn.freebsd.org/changeset/base/184013 Log: integrate through r184012 IF_RELENG_6 Modified: projects/releng_6_xen/sys/ (props changed) projects/releng_6_xen/sys/dev/usb/umass.c projects/releng_6_xen/sys/dev/usb/usbdevs projects/releng_6_xen/sys/netinet/libalias/alias_db.c Modified: projects/releng_6_xen/sys/dev/usb/umass.c ============================================================================== --- projects/releng_6_xen/sys/dev/usb/umass.c Sat Oct 18 04:28:21 2008 (r184012) +++ projects/releng_6_xen/sys/dev/usb/umass.c Sat Oct 18 05:42:58 2008 (r184013) @@ -424,6 +424,10 @@ Static struct umass_devdescr_t umass_dev UMASS_PROTO_SCSI | UMASS_PROTO_BBB, FORCE_SHORT_INQUIRY }, + { USB_VENDOR_NIKON, USB_PRODUCT_NIKON_D300, RID_WILDCARD, + UMASS_PROTO_SCSI | UMASS_PROTO_BBB, + NO_QUIRKS + }, { USB_VENDOR_OLYMPUS, USB_PRODUCT_OLYMPUS_C1, RID_WILDCARD, UMASS_PROTO_SCSI | UMASS_PROTO_BBB, WRONG_CSWSIG Modified: projects/releng_6_xen/sys/dev/usb/usbdevs ============================================================================== --- projects/releng_6_xen/sys/dev/usb/usbdevs Sat Oct 18 04:28:21 2008 (r184012) +++ projects/releng_6_xen/sys/dev/usb/usbdevs Sat Oct 18 05:42:58 2008 (r184013) @@ -1356,6 +1356,7 @@ product NETGEAR FA120 0x1040 USB 2.0 Et /* Nikon products */ product NIKON E990 0x0102 Digital Camera E990 product NIKON LS40 0x4000 CoolScan LS40 ED +product NIKON D300 0x041a Digital Camera D300 /* NovaTech Products */ product NOVATECH NV902 0x9020 NovaTech NV-902W Modified: projects/releng_6_xen/sys/netinet/libalias/alias_db.c ============================================================================== --- projects/releng_6_xen/sys/netinet/libalias/alias_db.c Sat Oct 18 04:28:21 2008 (r184012) +++ projects/releng_6_xen/sys/netinet/libalias/alias_db.c Sat Oct 18 05:42:58 2008 (r184013) @@ -603,7 +603,7 @@ GetNewPort(struct libalias *la, struct a port_sys = ntohs(port_net); } else { /* First trial and all subsequent are random. */ - port_sys = random() & ALIAS_PORT_MASK; + port_sys = arc4random() & ALIAS_PORT_MASK; port_sys += ALIAS_PORT_BASE; port_net = htons(port_sys); } @@ -654,7 +654,7 @@ GetNewPort(struct libalias *la, struct a } #endif } - port_sys = random() & ALIAS_PORT_MASK; + port_sys = arc4random() & ALIAS_PORT_MASK; port_sys += ALIAS_PORT_BASE; port_net = htons(port_sys); } @@ -767,9 +767,9 @@ FindNewPortGroup(struct libalias *la, /* First trial and all subsequent are random. */ if (align == FIND_EVEN_ALIAS_BASE) - port_sys = random() & ALIAS_PORT_MASK_EVEN; + port_sys = arc4random() & ALIAS_PORT_MASK_EVEN; else - port_sys = random() & ALIAS_PORT_MASK; + port_sys = arc4random() & ALIAS_PORT_MASK; port_sys += ALIAS_PORT_BASE; } @@ -791,9 +791,9 @@ FindNewPortGroup(struct libalias *la, /* Find a new base to try */ if (align == FIND_EVEN_ALIAS_BASE) - port_sys = random() & ALIAS_PORT_MASK_EVEN; + port_sys = arc4random() & ALIAS_PORT_MASK_EVEN; else - port_sys = random() & ALIAS_PORT_MASK; + port_sys = arc4random() & ALIAS_PORT_MASK; port_sys += ALIAS_PORT_BASE; } From owner-svn-src-projects@FreeBSD.ORG Sat Oct 18 05:45:44 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8989E1065687; Sat, 18 Oct 2008 05:45:44 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 785848FC18; Sat, 18 Oct 2008 05:45:44 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9I5jikv008131; Sat, 18 Oct 2008 05:45:44 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9I5jioJ008130; Sat, 18 Oct 2008 05:45:44 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810180545.m9I5jioJ008130@svn.freebsd.org> From: Kip Macy Date: Sat, 18 Oct 2008 05:45:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184014 - projects/releng_6_xen/sys/conf X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Oct 2008 05:45:44 -0000 Author: kmacy Date: Sat Oct 18 05:45:44 2008 New Revision: 184014 URL: http://svn.freebsd.org/changeset/base/184014 Log: restore -Werror Modified: projects/releng_6_xen/sys/conf/kern.pre.mk Modified: projects/releng_6_xen/sys/conf/kern.pre.mk ============================================================================== --- projects/releng_6_xen/sys/conf/kern.pre.mk Sat Oct 18 05:42:58 2008 (r184013) +++ projects/releng_6_xen/sys/conf/kern.pre.mk Sat Oct 18 05:45:44 2008 (r184014) @@ -79,8 +79,7 @@ CFLAGS+= ${INCLUDES} -D_KERNEL -DHAVE_KE CFLAGS+= -fno-common -finline-limit=${INLINE_LIMIT} CFLAGS+= --param inline-unit-growth=100 CFLAGS+= --param large-function-growth=1000 -WERROR?= -#-Werror +WERROR?= -Werror .endif # XXX LOCORE means "don't declare C stuff" not "for locore.s". From owner-svn-src-projects@FreeBSD.ORG Sat Oct 18 06:19:13 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1635E1065686; Sat, 18 Oct 2008 06:19:13 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id F0F938FC1A; Sat, 18 Oct 2008 06:19:12 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9I6JCB5008729; Sat, 18 Oct 2008 06:19:12 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9I6JC1h008727; Sat, 18 Oct 2008 06:19:12 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810180619.m9I6JC1h008727@svn.freebsd.org> From: Kip Macy Date: Sat, 18 Oct 2008 06:19:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184015 - in projects/release_6_3_xen/sys/xen: . evtchn interface interface/arch-x86 interface/arch-x86/hvm interface/foreign interface/hvm interface/io xenbus X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Oct 2008 06:19:13 -0000 Author: kmacy Date: Sat Oct 18 06:19:12 2008 New Revision: 184015 URL: http://svn.freebsd.org/changeset/base/184015 Log: merge xen includes Added: projects/release_6_3_xen/sys/xen/ projects/release_6_3_xen/sys/xen/evtchn/ projects/release_6_3_xen/sys/xen/evtchn/evtchn.c projects/release_6_3_xen/sys/xen/evtchn/evtchn_dev.c projects/release_6_3_xen/sys/xen/features.c projects/release_6_3_xen/sys/xen/gnttab.c projects/release_6_3_xen/sys/xen/gnttab.h projects/release_6_3_xen/sys/xen/interface/ (props changed) projects/release_6_3_xen/sys/xen/interface/COPYING projects/release_6_3_xen/sys/xen/interface/acm.h projects/release_6_3_xen/sys/xen/interface/acm_ops.h projects/release_6_3_xen/sys/xen/interface/arch-ia64.h projects/release_6_3_xen/sys/xen/interface/arch-powerpc.h projects/release_6_3_xen/sys/xen/interface/arch-x86/ (props changed) projects/release_6_3_xen/sys/xen/interface/arch-x86/cpuid.h projects/release_6_3_xen/sys/xen/interface/arch-x86/hvm/ projects/release_6_3_xen/sys/xen/interface/arch-x86/hvm/save.h projects/release_6_3_xen/sys/xen/interface/arch-x86/xen-mca.h projects/release_6_3_xen/sys/xen/interface/arch-x86/xen-x86_32.h projects/release_6_3_xen/sys/xen/interface/arch-x86/xen-x86_64.h projects/release_6_3_xen/sys/xen/interface/arch-x86/xen.h projects/release_6_3_xen/sys/xen/interface/arch-x86_32.h projects/release_6_3_xen/sys/xen/interface/arch-x86_64.h projects/release_6_3_xen/sys/xen/interface/callback.h projects/release_6_3_xen/sys/xen/interface/dom0_ops.h projects/release_6_3_xen/sys/xen/interface/domctl.h projects/release_6_3_xen/sys/xen/interface/elfnote.h projects/release_6_3_xen/sys/xen/interface/elfstructs.h projects/release_6_3_xen/sys/xen/interface/event_channel.h projects/release_6_3_xen/sys/xen/interface/features.h projects/release_6_3_xen/sys/xen/interface/foreign/ (props changed) projects/release_6_3_xen/sys/xen/interface/foreign/Makefile projects/release_6_3_xen/sys/xen/interface/foreign/mkchecker.py projects/release_6_3_xen/sys/xen/interface/foreign/mkheader.py projects/release_6_3_xen/sys/xen/interface/foreign/reference.size projects/release_6_3_xen/sys/xen/interface/foreign/structs.py projects/release_6_3_xen/sys/xen/interface/grant_table.h projects/release_6_3_xen/sys/xen/interface/hvm/ (props changed) projects/release_6_3_xen/sys/xen/interface/hvm/e820.h projects/release_6_3_xen/sys/xen/interface/hvm/hvm_info_table.h projects/release_6_3_xen/sys/xen/interface/hvm/hvm_op.h projects/release_6_3_xen/sys/xen/interface/hvm/ioreq.h projects/release_6_3_xen/sys/xen/interface/hvm/params.h projects/release_6_3_xen/sys/xen/interface/hvm/save.h projects/release_6_3_xen/sys/xen/interface/hvm/vmx_assist.h projects/release_6_3_xen/sys/xen/interface/io/ (props changed) projects/release_6_3_xen/sys/xen/interface/io/blkif.h projects/release_6_3_xen/sys/xen/interface/io/console.h projects/release_6_3_xen/sys/xen/interface/io/fbif.h projects/release_6_3_xen/sys/xen/interface/io/kbdif.h projects/release_6_3_xen/sys/xen/interface/io/netif.h projects/release_6_3_xen/sys/xen/interface/io/pciif.h projects/release_6_3_xen/sys/xen/interface/io/protocols.h projects/release_6_3_xen/sys/xen/interface/io/ring.h projects/release_6_3_xen/sys/xen/interface/io/tpmif.h projects/release_6_3_xen/sys/xen/interface/io/xenbus.h projects/release_6_3_xen/sys/xen/interface/io/xs_wire.h projects/release_6_3_xen/sys/xen/interface/kexec.h projects/release_6_3_xen/sys/xen/interface/libelf.h projects/release_6_3_xen/sys/xen/interface/memory.h projects/release_6_3_xen/sys/xen/interface/nmi.h projects/release_6_3_xen/sys/xen/interface/physdev.h projects/release_6_3_xen/sys/xen/interface/platform.h projects/release_6_3_xen/sys/xen/interface/sched.h projects/release_6_3_xen/sys/xen/interface/sysctl.h projects/release_6_3_xen/sys/xen/interface/trace.h projects/release_6_3_xen/sys/xen/interface/vcpu.h projects/release_6_3_xen/sys/xen/interface/version.h projects/release_6_3_xen/sys/xen/interface/xen-compat.h projects/release_6_3_xen/sys/xen/interface/xen.h projects/release_6_3_xen/sys/xen/interface/xencomm.h projects/release_6_3_xen/sys/xen/interface/xenoprof.h projects/release_6_3_xen/sys/xen/xenbus/ projects/release_6_3_xen/sys/xen/xenbus/init.txt projects/release_6_3_xen/sys/xen/xenbus/xenbus_client.c projects/release_6_3_xen/sys/xen/xenbus/xenbus_comms.c projects/release_6_3_xen/sys/xen/xenbus/xenbus_comms.h projects/release_6_3_xen/sys/xen/xenbus/xenbus_dev.c projects/release_6_3_xen/sys/xen/xenbus/xenbus_probe.c projects/release_6_3_xen/sys/xen/xenbus/xenbus_probe_backend.c projects/release_6_3_xen/sys/xen/xenbus/xenbus_xs.c Added: projects/release_6_3_xen/sys/xen/evtchn/evtchn.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/release_6_3_xen/sys/xen/evtchn/evtchn.c Sat Oct 18 06:19:12 2008 (r184015) @@ -0,0 +1,1115 @@ +/****************************************************************************** + * evtchn.c + * + * Communication via Xen event channels. + * + * Copyright (c) 2002-2005, K A Fraser + * Copyright (c) 2005-2006 Kip Macy + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + + + +/* linux helper functions that got sucked in + * rename and move XXX + */ + + +static inline int find_first_bit(const unsigned long *addr, unsigned size) +{ + int d0, d1; + int res; + + /* This looks at memory. Mark it volatile to tell gcc not to move it around */ + __asm__ __volatile__( + "xorl %%eax,%%eax\n\t" + "repe; scasl\n\t" + "jz 1f\n\t" + "leal -4(%%edi),%%edi\n\t" + "bsfl (%%edi),%%eax\n" + "1:\tsubl %%ebx,%%edi\n\t" + "shll $3,%%edi\n\t" + "addl %%edi,%%eax" + :"=a" (res), "=&c" (d0), "=&D" (d1) + :"1" ((size + 31) >> 5), "2" (addr), "b" (addr) : "memory"); + return res; +} + +#define min_t(type,x,y) \ + ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; }) +#define first_cpu(src) __first_cpu(&(src), NR_CPUS) +static inline int __first_cpu(const xen_cpumask_t *srcp, int nbits) +{ + return min_t(int, nbits, find_first_bit(srcp->bits, nbits)); +} + +static inline unsigned long __ffs(unsigned long word) +{ + __asm__("bsfl %1,%0" + :"=r" (word) + :"rm" (word)); + return word; +} + +static struct mtx irq_mapping_update_lock; +static struct xenpic *xp; +struct xenpic_intsrc { + struct intsrc xp_intsrc; + uint8_t xp_vector; + boolean_t xp_masked; +}; + +struct xenpic { + struct pic *xp_dynirq_pic; + struct pic *xp_pirq_pic; + uint16_t xp_numintr; + struct xenpic_intsrc xp_pins[0]; +}; + +#define TODO printf("%s: not implemented!\n", __func__) + +/* IRQ <-> event-channel mappings. */ +static int evtchn_to_irq[NR_EVENT_CHANNELS]; + +/* Packed IRQ information: binding type, sub-type index, and event channel. */ +static uint32_t irq_info[NR_IRQS]; +/* Binding types. */ +enum { + IRQT_UNBOUND, + IRQT_PIRQ, + IRQT_VIRQ, + IRQT_IPI, + IRQT_LOCAL_PORT, + IRQT_CALLER_PORT +}; + +/* Constructor for packed IRQ information. */ +#define mk_irq_info(type, index, evtchn) \ + (((uint32_t)(type) << 24) | ((uint32_t)(index) << 16) | (uint32_t)(evtchn)) +/* Convenient shorthand for packed representation of an unbound IRQ. */ +#define IRQ_UNBOUND mk_irq_info(IRQT_UNBOUND, 0, 0) +/* Accessor macros for packed IRQ information. */ +#define evtchn_from_irq(irq) ((uint16_t)(irq_info[irq])) +#define index_from_irq(irq) ((uint8_t)(irq_info[irq] >> 16)) +#define type_from_irq(irq) ((uint8_t)(irq_info[irq] >> 24)) + +/* IRQ <-> VIRQ mapping. */ +DEFINE_PER_CPU(int, virq_to_irq[NR_VIRQS]) = {[0 ... NR_VIRQS-1] = -1}; + +/* IRQ <-> IPI mapping. */ +#ifndef NR_IPIS +#define NR_IPIS 1 +#endif +DEFINE_PER_CPU(int, ipi_to_irq[NR_IPIS]) = {[0 ... NR_IPIS-1] = -1}; + +/* Bitmap indicating which PIRQs require Xen to be notified on unmask. */ +static unsigned long pirq_needs_unmask_notify[NR_PIRQS/sizeof(unsigned long)]; + +/* Reference counts for bindings to IRQs. */ +static int irq_bindcount[NR_IRQS]; + +#define VALID_EVTCHN(_chn) ((_chn) != 0) + +#ifdef CONFIG_SMP + +static u8 cpu_evtchn[NR_EVENT_CHANNELS]; +static unsigned long cpu_evtchn_mask[NR_CPUS][NR_EVENT_CHANNELS/BITS_PER_LONG]; + +#define active_evtchns(cpu,sh,idx) \ + ((sh)->evtchn_pending[idx] & \ + cpu_evtchn_mask[cpu][idx] & \ + ~(sh)->evtchn_mask[idx]) + +static void bind_evtchn_to_cpu(unsigned int chn, unsigned int cpu) +{ + clear_bit(chn, (unsigned long *)cpu_evtchn_mask[cpu_evtchn[chn]]); + set_bit(chn, (unsigned long *)cpu_evtchn_mask[cpu]); + cpu_evtchn[chn] = cpu; +} + +static void init_evtchn_cpu_bindings(void) +{ + /* By default all event channels notify CPU#0. */ + memset(cpu_evtchn, 0, sizeof(cpu_evtchn)); + memset(cpu_evtchn_mask[0], ~0, sizeof(cpu_evtchn_mask[0])); +} + +#define cpu_from_evtchn(evtchn) (cpu_evtchn[evtchn]) + +#else + +#define active_evtchns(cpu,sh,idx) \ + ((sh)->evtchn_pending[idx] & \ + ~(sh)->evtchn_mask[idx]) +#define bind_evtchn_to_cpu(chn,cpu) ((void)0) +#define init_evtchn_cpu_bindings() ((void)0) +#define cpu_from_evtchn(evtchn) (0) + +#endif + + +/* + * Force a proper event-channel callback from Xen after clearing the + * callback mask. We do this in a very simple manner, by making a call + * down into Xen. The pending flag will be checked by Xen on return. + */ +void force_evtchn_callback(void) +{ + (void)HYPERVISOR_xen_version(0, NULL); +} + +void +evtchn_do_upcall(struct trapframe *frame) +{ + unsigned long l1, l2; + unsigned int l1i, l2i, port; + int irq, cpu; + shared_info_t *s; + vcpu_info_t *vcpu_info; + + cpu = smp_processor_id(); + s = HYPERVISOR_shared_info; + vcpu_info = &s->vcpu_info[cpu]; + + vcpu_info->evtchn_upcall_pending = 0; + + /* NB. No need for a barrier here -- XCHG is a barrier on x86. */ + l1 = xen_xchg(&vcpu_info->evtchn_pending_sel, 0); + + while (l1 != 0) { + l1i = __ffs(l1); + l1 &= ~(1 << l1i); + + while ((l2 = active_evtchns(cpu, s, l1i)) != 0) { + l2i = __ffs(l2); + + port = (l1i * BITS_PER_LONG) + l2i; + if ((irq = evtchn_to_irq[port]) != -1) { + struct intsrc *isrc = intr_lookup_source(irq); + /* + * ack + */ + mask_evtchn(port); + clear_evtchn(port); + + intr_execute_handlers(isrc, frame); + } else { + evtchn_device_upcall(port); + } + } + } +} + +void +ipi_pcpu(unsigned int cpu, int vector) +{ + int irq = per_cpu(ipi_to_irq, cpu)[vector]; + + notify_remote_via_irq(irq); +} + +static int +find_unbound_irq(void) +{ + int dynirq, irq; + + for (dynirq = 0; dynirq < NR_IRQS; dynirq++) { + irq = dynirq_to_irq(dynirq); + if (irq_bindcount[irq] == 0) + break; + } + + if (irq == NR_IRQS) + panic("No available IRQ to bind to: increase NR_IRQS!\n"); + + return (irq); +} + +static int +bind_caller_port_to_irq(unsigned int caller_port) +{ + int irq; + + mtx_lock_spin(&irq_mapping_update_lock); + + if ((irq = evtchn_to_irq[caller_port]) == -1) { + if ((irq = find_unbound_irq()) < 0) + goto out; + + evtchn_to_irq[caller_port] = irq; + irq_info[irq] = mk_irq_info(IRQT_CALLER_PORT, 0, caller_port); + } + + irq_bindcount[irq]++; + + out: + mtx_unlock_spin(&irq_mapping_update_lock); + return irq; +} + +static int +bind_local_port_to_irq(unsigned int local_port) +{ + int irq; + + mtx_lock_spin(&irq_mapping_update_lock); + + PANIC_IF(evtchn_to_irq[local_port] != -1); + + if ((irq = find_unbound_irq()) < 0) { + struct evtchn_close close = { .port = local_port }; + PANIC_IF(HYPERVISOR_event_channel_op(EVTCHNOP_close, &close)); + + goto out; + } + + evtchn_to_irq[local_port] = irq; + irq_info[irq] = mk_irq_info(IRQT_LOCAL_PORT, 0, local_port); + irq_bindcount[irq]++; + + out: + mtx_unlock_spin(&irq_mapping_update_lock); + return irq; +} + +static int +bind_listening_port_to_irq(unsigned int remote_domain) +{ + struct evtchn_alloc_unbound alloc_unbound; + int err; + + alloc_unbound.dom = DOMID_SELF; + alloc_unbound.remote_dom = remote_domain; + + err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, + &alloc_unbound); + + return err ? : bind_local_port_to_irq(alloc_unbound.port); +} + +static int +bind_interdomain_evtchn_to_irq(unsigned int remote_domain, + unsigned int remote_port) +{ + struct evtchn_bind_interdomain bind_interdomain; + int err; + + bind_interdomain.remote_dom = remote_domain; + bind_interdomain.remote_port = remote_port; + + err = HYPERVISOR_event_channel_op(EVTCHNOP_bind_interdomain, + &bind_interdomain); + + return err ? : bind_local_port_to_irq(bind_interdomain.local_port); +} + +static int +bind_virq_to_irq(unsigned int virq, unsigned int cpu) +{ + struct evtchn_bind_virq bind_virq; + int evtchn, irq; + + mtx_lock_spin(&irq_mapping_update_lock); + + if ((irq = per_cpu(virq_to_irq, cpu)[virq]) == -1) { + bind_virq.virq = virq; + bind_virq.vcpu = cpu; + PANIC_IF(HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq, + &bind_virq) != 0); + + evtchn = bind_virq.port; + + irq = find_unbound_irq(); + evtchn_to_irq[evtchn] = irq; + irq_info[irq] = mk_irq_info(IRQT_VIRQ, virq, evtchn); + + per_cpu(virq_to_irq, cpu)[virq] = irq; + + bind_evtchn_to_cpu(evtchn, cpu); + } + + irq_bindcount[irq]++; + + mtx_unlock_spin(&irq_mapping_update_lock); + + return irq; +} + +static int +bind_ipi_to_irq(unsigned int ipi, unsigned int cpu) +{ + struct evtchn_bind_ipi bind_ipi; + int evtchn, irq; + + mtx_lock_spin(&irq_mapping_update_lock); + + if ((irq = per_cpu(ipi_to_irq, cpu)[ipi]) == -1) { + if ((irq = find_unbound_irq()) < 0) + goto out; + + bind_ipi.vcpu = cpu; + PANIC_IF(HYPERVISOR_event_channel_op(EVTCHNOP_bind_ipi, &bind_ipi) != 0); + evtchn = bind_ipi.port; + + irq = find_unbound_irq(); + evtchn_to_irq[evtchn] = irq; + irq_info[irq] = mk_irq_info(IRQT_IPI, ipi, evtchn); + + per_cpu(ipi_to_irq, cpu)[ipi] = irq; + + bind_evtchn_to_cpu(evtchn, cpu); + } + + irq_bindcount[irq]++; +out: + + mtx_unlock_spin(&irq_mapping_update_lock); + + return irq; +} + + +void +unbind_from_irq(int irq) +{ + struct evtchn_close close; + int evtchn = evtchn_from_irq(irq); + + mtx_lock_spin(&irq_mapping_update_lock); + + if ((--irq_bindcount[irq] == 0) && VALID_EVTCHN(evtchn)) { + close.port = evtchn; + PANIC_IF(HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0); + + switch (type_from_irq(irq)) { + case IRQT_VIRQ: + per_cpu(virq_to_irq, cpu_from_evtchn(evtchn))[index_from_irq(irq)] = -1; + break; + case IRQT_IPI: + per_cpu(ipi_to_irq, cpu_from_evtchn(evtchn))[index_from_irq(irq)] = -1; + break; + default: + break; + } + + /* Closed ports are implicitly re-bound to VCPU0. */ + bind_evtchn_to_cpu(evtchn, 0); + + evtchn_to_irq[evtchn] = -1; + irq_info[irq] = IRQ_UNBOUND; + } + + mtx_unlock_spin(&irq_mapping_update_lock); +} + +int +bind_caller_port_to_irqhandler(unsigned int caller_port, + const char *devname, + driver_intr_t handler, + void *arg, + unsigned long irqflags, + void **cookiep) +{ + unsigned int irq; + int retval; + + irq = bind_caller_port_to_irq(caller_port); + intr_register_source(&xp->xp_pins[irq].xp_intsrc); + retval = intr_add_handler(devname, irq, NULL, handler, arg, irqflags, cookiep); + if (retval != 0) { + unbind_from_irq(irq); + return -retval; + } + + return irq; +} + +int +bind_listening_port_to_irqhandler( + unsigned int remote_domain, + const char *devname, + driver_intr_t handler, + void *arg, + unsigned long irqflags, + void **cookiep) +{ + unsigned int irq; + int retval; + + irq = bind_listening_port_to_irq(remote_domain); + intr_register_source(&xp->xp_pins[irq].xp_intsrc); + retval = intr_add_handler(devname, irq, NULL, handler, arg, irqflags, cookiep); + if (retval != 0) { + unbind_from_irq(irq); + return -retval; + } + + return irq; +} + +int +bind_interdomain_evtchn_to_irqhandler( + unsigned int remote_domain, + unsigned int remote_port, + const char *devname, + driver_filter_t filter, + driver_intr_t handler, + unsigned long irqflags) +{ + unsigned int irq; + int retval; + + irq = bind_interdomain_evtchn_to_irq(remote_domain, remote_port); + intr_register_source(&xp->xp_pins[irq].xp_intsrc); + retval = intr_add_handler(devname, irq, filter, handler, NULL, irqflags, NULL); + if (retval != 0) { + unbind_from_irq(irq); + return -retval; + } + + return irq; +} + +int +bind_virq_to_irqhandler(unsigned int virq, + unsigned int cpu, + const char *devname, + driver_filter_t filter, + driver_intr_t handler, + unsigned long irqflags) +{ + unsigned int irq; + int retval; + + irq = bind_virq_to_irq(virq, cpu); + intr_register_source(&xp->xp_pins[irq].xp_intsrc); + retval = intr_add_handler(devname, irq, filter, handler, NULL, irqflags, NULL); + if (retval != 0) { + unbind_from_irq(irq); + return -retval; + } + + return irq; +} + +int +bind_ipi_to_irqhandler(unsigned int ipi, + unsigned int cpu, + const char *devname, + driver_intr_t handler, + unsigned long irqflags) +{ + unsigned int irq; + int retval; + + irq = bind_ipi_to_irq(ipi, cpu); + intr_register_source(&xp->xp_pins[irq].xp_intsrc); + retval = intr_add_handler(devname, irq, NULL, handler, NULL, irqflags, NULL); + if (retval != 0) { + unbind_from_irq(irq); + return -retval; + } + + return irq; +} + +void +unbind_from_irqhandler(unsigned int irq, void *dev_id) +{ + if (dev_id) + intr_remove_handler(dev_id); /* XXX */ + unbind_from_irq(irq); +} + +#if 0 +/* Rebind an evtchn so that it gets delivered to a specific cpu */ +static void +rebind_irq_to_cpu(unsigned irq, unsigned tcpu) +{ + evtchn_op_t op = { .cmd = EVTCHNOP_bind_vcpu }; + int evtchn; + + mtx_lock_spin(&irq_mapping_update_lock); + + evtchn = evtchn_from_irq(irq); + if (!VALID_EVTCHN(evtchn)) { + mtx_unlock_spin(&irq_mapping_update_lock); + return; + } + + /* Send future instances of this interrupt to other vcpu. */ + bind_vcpu.port = evtchn; + bind_vcpu.vcpu = tcpu; + + /* + * If this fails, it usually just indicates that we're dealing with a + * virq or IPI channel, which don't actually need to be rebound. Ignore + * it, but don't do the xenlinux-level rebind in that case. + */ + if (HYPERVISOR_event_channel_op(&op) >= 0) + bind_evtchn_to_cpu(evtchn, tcpu); + + mtx_unlock_spin(&irq_mapping_update_lock); + +} + +static void set_affinity_irq(unsigned irq, xen_cpumask_t dest) +{ + unsigned tcpu = first_cpu(dest); + rebind_irq_to_cpu(irq, tcpu); +} +#endif + +/* + * Interface to generic handling in intr_machdep.c + */ + + +/*------------ interrupt handling --------------------------------------*/ +#define TODO printf("%s: not implemented!\n", __func__) + + +static void xenpic_dynirq_enable_source(struct intsrc *isrc); +static void xenpic_dynirq_disable_source(struct intsrc *isrc, int); +static void xenpic_dynirq_eoi_source(struct intsrc *isrc); +static void xenpic_dynirq_enable_intr(struct intsrc *isrc); +static void xenpic_dynirq_disable_intr(struct intsrc *isrc); + +static void xenpic_pirq_enable_source(struct intsrc *isrc); +static void xenpic_pirq_disable_source(struct intsrc *isrc, int); +static void xenpic_pirq_eoi_source(struct intsrc *isrc); +static void xenpic_pirq_enable_intr(struct intsrc *isrc); +static void xenpic_pirq_disable_intr(struct intsrc *isrc); + + +static int xenpic_vector(struct intsrc *isrc); +static int xenpic_source_pending(struct intsrc *isrc); +static void xenpic_suspend(struct pic* pic); +static void xenpic_resume(struct pic* pic); +static void xenpic_assign_cpu(struct intsrc *, u_int apic_id); + + +struct pic xenpic_dynirq_template = { + .pic_enable_source = xenpic_dynirq_enable_source, + .pic_disable_source = xenpic_dynirq_disable_source, + .pic_eoi_source = xenpic_dynirq_eoi_source, + .pic_enable_intr = xenpic_dynirq_enable_intr, + .pic_disable_intr = xenpic_dynirq_disable_intr, + .pic_vector = xenpic_vector, + .pic_source_pending = xenpic_source_pending, + .pic_suspend = xenpic_suspend, + .pic_resume = xenpic_resume +}; + +struct pic xenpic_pirq_template = { + .pic_enable_source = xenpic_pirq_enable_source, + .pic_disable_source = xenpic_pirq_disable_source, + .pic_eoi_source = xenpic_pirq_eoi_source, + .pic_enable_intr = xenpic_pirq_enable_intr, + .pic_disable_intr = xenpic_pirq_disable_intr, + .pic_vector = xenpic_vector, + .pic_source_pending = xenpic_source_pending, + .pic_suspend = xenpic_suspend, + .pic_resume = xenpic_resume, + .pic_assign_cpu = xenpic_assign_cpu +}; + + + +void +xenpic_dynirq_enable_source(struct intsrc *isrc) +{ + unsigned int irq; + struct xenpic_intsrc *xp; + + xp = (struct xenpic_intsrc *)isrc; + + mtx_lock_spin(&irq_mapping_update_lock); + if (xp->xp_masked) { + irq = xenpic_vector(isrc); + unmask_evtchn(evtchn_from_irq(irq)); + xp->xp_masked = FALSE; + } + mtx_unlock_spin(&irq_mapping_update_lock); +} + +static void +xenpic_dynirq_disable_source(struct intsrc *isrc, int foo) +{ + unsigned int irq; + struct xenpic_intsrc *xp; + + xp = (struct xenpic_intsrc *)isrc; + + mtx_lock_spin(&irq_mapping_update_lock); + if (!xp->xp_masked) { + irq = xenpic_vector(isrc); + mask_evtchn(evtchn_from_irq(irq)); + xp->xp_masked = TRUE; + } + mtx_unlock_spin(&irq_mapping_update_lock); +} + +static void +xenpic_dynirq_enable_intr(struct intsrc *isrc) +{ + unsigned int irq; + struct xenpic_intsrc *xp; + + xp = (struct xenpic_intsrc *)isrc; + mtx_lock_spin(&irq_mapping_update_lock); + xp->xp_masked = 0; + irq = xenpic_vector(isrc); + unmask_evtchn(evtchn_from_irq(irq)); + mtx_unlock_spin(&irq_mapping_update_lock); +} + +static void +xenpic_dynirq_disable_intr(struct intsrc *isrc) +{ + unsigned int irq; + struct xenpic_intsrc *xp; + + xp = (struct xenpic_intsrc *)isrc; + mtx_lock_spin(&irq_mapping_update_lock); + xp->xp_masked = 1; + irq = xenpic_vector(isrc); + mask_evtchn(evtchn_from_irq(irq)); + mtx_unlock_spin(&irq_mapping_update_lock); +} + +static void +xenpic_dynirq_eoi_source(struct intsrc *isrc) +{ + unsigned int irq; + struct xenpic_intsrc *xp; + + xp = (struct xenpic_intsrc *)isrc; + mtx_lock_spin(&irq_mapping_update_lock); + xp->xp_masked = 0; + irq = xenpic_vector(isrc); + unmask_evtchn(evtchn_from_irq(irq)); + mtx_unlock_spin(&irq_mapping_update_lock); +} + +static int +xenpic_vector(struct intsrc *isrc) +{ + struct xenpic_intsrc *pin; + + pin = (struct xenpic_intsrc *)isrc; + //printf("xenpic_vector(): isrc=%p,vector=%u\n", pin, pin->xp_vector); + + return (pin->xp_vector); +} + +static int +xenpic_source_pending(struct intsrc *isrc) +{ + struct xenpic_intsrc *pin = (struct xenpic_intsrc *)isrc; + + /* XXXEN: TODO */ + printf("xenpic_source_pending(): vector=%x,masked=%x\n", + pin->xp_vector, pin->xp_masked); + +/* notify_remote_via_evtchn(pin->xp_vector); // XXX RS: Is this correct? */ + return 0; +} + +static void +xenpic_suspend(struct pic* pic) +{ + TODO; +} + +static void +xenpic_resume(struct pic* pic) +{ + TODO; +} + +static void +xenpic_assign_cpu(struct intsrc *isrc, u_int apic_id) +{ + TODO; +} + +void +notify_remote_via_irq(int irq) +{ + int evtchn = evtchn_from_irq(irq); + + if (VALID_EVTCHN(evtchn)) + notify_remote_via_evtchn(evtchn); +} + +/* required for support of physical devices */ +static inline void +pirq_unmask_notify(int pirq) +{ + struct physdev_eoi eoi = { .irq = pirq }; + + if (unlikely(test_bit(pirq, &pirq_needs_unmask_notify[0]))) { + (void)HYPERVISOR_physdev_op(PHYSDEVOP_eoi, &eoi); + } +} + +static inline void +pirq_query_unmask(int pirq) +{ + struct physdev_irq_status_query irq_status_query; + + irq_status_query.irq = pirq; + (void)HYPERVISOR_physdev_op(PHYSDEVOP_IRQ_STATUS_QUERY, &irq_status_query); + clear_bit(pirq, &pirq_needs_unmask_notify[0]); + if ( irq_status_query.flags & PHYSDEVOP_IRQ_NEEDS_UNMASK_NOTIFY ) + set_bit(pirq, &pirq_needs_unmask_notify[0]); +} + +/* + * On startup, if there is no action associated with the IRQ then we are + * probing. In this case we should not share with others as it will confuse us. + */ +#define probing_irq(_irq) (intr_lookup_source(irq) == NULL) + +static void +xenpic_pirq_enable_intr(struct intsrc *isrc) +{ + struct evtchn_bind_pirq bind_pirq; + int evtchn; + unsigned int irq; + + mtx_lock_spin(&irq_mapping_update_lock); + irq = xenpic_vector(isrc); + evtchn = evtchn_from_irq(irq); + + if (VALID_EVTCHN(evtchn)) + goto out; + + bind_pirq.pirq = irq; + /* NB. We are happy to share unless we are probing. */ + bind_pirq.flags = probing_irq(irq) ? 0 : BIND_PIRQ__WILL_SHARE; + + if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_pirq, &bind_pirq) != 0) { + if (!probing_irq(irq)) /* Some failures are expected when probing. */ + printf("Failed to obtain physical IRQ %d\n", irq); + mtx_unlock_spin(&irq_mapping_update_lock); + return; + } + evtchn = bind_pirq.port; + + pirq_query_unmask(irq_to_pirq(irq)); + + bind_evtchn_to_cpu(evtchn, 0); + evtchn_to_irq[evtchn] = irq; + irq_info[irq] = mk_irq_info(IRQT_PIRQ, irq, evtchn); + + out: + unmask_evtchn(evtchn); + pirq_unmask_notify(irq_to_pirq(irq)); + mtx_unlock_spin(&irq_mapping_update_lock); +} + +static void +xenpic_pirq_disable_intr(struct intsrc *isrc) +{ + unsigned int irq; + int evtchn; + struct evtchn_close close; + + mtx_lock_spin(&irq_mapping_update_lock); + irq = xenpic_vector(isrc); + evtchn = evtchn_from_irq(irq); + + if (!VALID_EVTCHN(evtchn)) + goto done; + + mask_evtchn(evtchn); + + close.port = evtchn; + PANIC_IF(HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0); + + bind_evtchn_to_cpu(evtchn, 0); + evtchn_to_irq[evtchn] = -1; + irq_info[irq] = IRQ_UNBOUND; + done: + mtx_unlock_spin(&irq_mapping_update_lock); +} + +static void +xenpic_pirq_enable_source(struct intsrc *isrc) +{ + int evtchn; + unsigned int irq; + + mtx_lock_spin(&irq_mapping_update_lock); + irq = xenpic_vector(isrc); + evtchn = evtchn_from_irq(irq); + + if (!VALID_EVTCHN(evtchn)) + goto done; + + unmask_evtchn(evtchn); + pirq_unmask_notify(irq_to_pirq(irq)); + done: + mtx_unlock_spin(&irq_mapping_update_lock); +} + +static void +xenpic_pirq_disable_source(struct intsrc *isrc, int eoi) +{ + int evtchn; + unsigned int irq; + + mtx_lock_spin(&irq_mapping_update_lock); + irq = xenpic_vector(isrc); + evtchn = evtchn_from_irq(irq); + + if (!VALID_EVTCHN(evtchn)) + goto done; + + mask_evtchn(evtchn); + done: + mtx_unlock_spin(&irq_mapping_update_lock); +} + + +static void +xenpic_pirq_eoi_source(struct intsrc *isrc) +{ + int evtchn; + unsigned int irq; + + mtx_lock_spin(&irq_mapping_update_lock); + irq = xenpic_vector(isrc); + evtchn = evtchn_from_irq(irq); + + if (!VALID_EVTCHN(evtchn)) + goto done; + + unmask_evtchn(evtchn); + pirq_unmask_notify(irq_to_pirq(irq)); + done: + mtx_unlock_spin(&irq_mapping_update_lock); +} + +int +irq_to_evtchn_port(int irq) +{ + return evtchn_from_irq(irq); +} + +void +mask_evtchn(int port) +{ + shared_info_t *s = HYPERVISOR_shared_info; + synch_set_bit(port, &s->evtchn_mask[0]); +} + +void +unmask_evtchn(int port) +{ + shared_info_t *s = HYPERVISOR_shared_info; + unsigned int cpu = smp_processor_id(); + vcpu_info_t *vcpu_info = &s->vcpu_info[cpu]; + + /* Slow path (hypercall) if this is a non-local port. */ + if (unlikely(cpu != cpu_from_evtchn(port))) { + struct evtchn_unmask unmask = { .port = port }; + (void)HYPERVISOR_event_channel_op(EVTCHNOP_unmask, &unmask); + return; + } + + synch_clear_bit(port, &s->evtchn_mask); + + /* + * The following is basically the equivalent of 'hw_resend_irq'. Just + * like a real IO-APIC we 'lose the interrupt edge' if the channel is + * masked. + */ + if (synch_test_bit(port, &s->evtchn_pending) && + !synch_test_and_set_bit(port / BITS_PER_LONG, + &vcpu_info->evtchn_pending_sel)) { + vcpu_info->evtchn_upcall_pending = 1; + if (!vcpu_info->evtchn_upcall_mask) + force_evtchn_callback(); + } +} + +void irq_resume(void) +{ + evtchn_op_t op; + int cpu, pirq, virq, ipi, irq, evtchn; + + struct evtchn_bind_virq bind_virq; + struct evtchn_bind_ipi bind_ipi; + + init_evtchn_cpu_bindings(); + + /* New event-channel space is not 'live' yet. */ + for (evtchn = 0; evtchn < NR_EVENT_CHANNELS; evtchn++) + mask_evtchn(evtchn); + + /* Check that no PIRQs are still bound. */ + for (pirq = 0; pirq < NR_PIRQS; pirq++) + PANIC_IF(irq_info[pirq_to_irq(pirq)] != IRQ_UNBOUND); + + /* Secondary CPUs must have no VIRQ or IPI bindings. */ + for (cpu = 1; cpu < NR_CPUS; cpu++) { + for (virq = 0; virq < NR_VIRQS; virq++) + PANIC_IF(per_cpu(virq_to_irq, cpu)[virq] != -1); + for (ipi = 0; ipi < NR_IPIS; ipi++) + PANIC_IF(per_cpu(ipi_to_irq, cpu)[ipi] != -1); + } + + /* No IRQ <-> event-channel mappings. */ + for (irq = 0; irq < NR_IRQS; irq++) + irq_info[irq] &= ~0xFFFF; /* zap event-channel binding */ + for (evtchn = 0; evtchn < NR_EVENT_CHANNELS; evtchn++) + evtchn_to_irq[evtchn] = -1; + + /* Primary CPU: rebind VIRQs automatically. */ + for (virq = 0; virq < NR_VIRQS; virq++) { + if ((irq = per_cpu(virq_to_irq, 0)[virq]) == -1) + continue; + + PANIC_IF(irq_info[irq] != mk_irq_info(IRQT_VIRQ, virq, 0)); + + /* Get a new binding from Xen. */ *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-projects@FreeBSD.ORG Sat Oct 18 06:19:53 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 796A5106568E; Sat, 18 Oct 2008 06:19:53 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 65E408FC18; Sat, 18 Oct 2008 06:19:53 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9I6JrMm008786; Sat, 18 Oct 2008 06:19:53 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9I6Jqlj008773; Sat, 18 Oct 2008 06:19:52 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810180619.m9I6Jqlj008773@svn.freebsd.org> From: Kip Macy Date: Sat, 18 Oct 2008 06:19:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184016 - in projects/release_6_3_xen/sys/i386: conf i386 include isa pci X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Oct 2008 06:19:53 -0000 Author: kmacy Date: Sat Oct 18 06:19:52 2008 New Revision: 184016 URL: http://svn.freebsd.org/changeset/base/184016 Log: merge i386 xen support Modified: projects/release_6_3_xen/sys/i386/conf/DEFAULTS projects/release_6_3_xen/sys/i386/i386/busdma_machdep.c projects/release_6_3_xen/sys/i386/i386/genassym.c projects/release_6_3_xen/sys/i386/i386/intr_machdep.c projects/release_6_3_xen/sys/i386/i386/machdep.c projects/release_6_3_xen/sys/i386/i386/support.s projects/release_6_3_xen/sys/i386/i386/swtch.s projects/release_6_3_xen/sys/i386/i386/sys_machdep.c projects/release_6_3_xen/sys/i386/i386/trap.c projects/release_6_3_xen/sys/i386/i386/vm_machdep.c projects/release_6_3_xen/sys/i386/include/asmacros.h projects/release_6_3_xen/sys/i386/include/cpufunc.h projects/release_6_3_xen/sys/i386/include/param.h projects/release_6_3_xen/sys/i386/include/pcpu.h projects/release_6_3_xen/sys/i386/include/pmap.h projects/release_6_3_xen/sys/i386/include/segments.h projects/release_6_3_xen/sys/i386/include/vmparam.h projects/release_6_3_xen/sys/i386/isa/npx.c projects/release_6_3_xen/sys/i386/pci/pci_cfgreg.c projects/release_6_3_xen/sys/i386/pci/pci_pir.c Modified: projects/release_6_3_xen/sys/i386/conf/DEFAULTS ============================================================================== --- projects/release_6_3_xen/sys/i386/conf/DEFAULTS Sat Oct 18 06:19:12 2008 (r184015) +++ projects/release_6_3_xen/sys/i386/conf/DEFAULTS Sat Oct 18 06:19:52 2008 (r184016) @@ -15,3 +15,5 @@ device npx # Pseudo devices. device mem # Memory and kernel memory devices device io # I/O device + +options NATIVE Modified: projects/release_6_3_xen/sys/i386/i386/busdma_machdep.c ============================================================================== --- projects/release_6_3_xen/sys/i386/i386/busdma_machdep.c Sat Oct 18 06:19:12 2008 (r184015) +++ projects/release_6_3_xen/sys/i386/i386/busdma_machdep.c Sat Oct 18 06:19:52 2008 (r184016) @@ -140,6 +140,11 @@ static bus_addr_t add_bounce_page(bus_dm static void free_bounce_page(bus_dma_tag_t dmat, struct bounce_page *bpage); static __inline int run_filter(bus_dma_tag_t dmat, bus_addr_t paddr); +#ifdef XEN +#undef pmap_kextract +#define pmap_kextract pmap_kextract_ma +#endif + /* * Return true if a match is made. * Modified: projects/release_6_3_xen/sys/i386/i386/genassym.c ============================================================================== --- projects/release_6_3_xen/sys/i386/i386/genassym.c Sat Oct 18 06:19:12 2008 (r184015) +++ projects/release_6_3_xen/sys/i386/i386/genassym.c Sat Oct 18 06:19:52 2008 (r184016) @@ -227,3 +227,9 @@ ASSYM(MTX_RECURSECNT, offsetof(struct mt ASSYM(BUS_SPACE_HANDLE_BASE, offsetof(struct bus_space_handle, bsh_base)); ASSYM(BUS_SPACE_HANDLE_IAT, offsetof(struct bus_space_handle, bsh_iat)); #endif + +#ifdef XEN +#include +ASSYM(PC_CR3, offsetof(struct pcpu, pc_cr3)); +ASSYM(HYPERVISOR_VIRT_START, __HYPERVISOR_VIRT_START); +#endif Modified: projects/release_6_3_xen/sys/i386/i386/intr_machdep.c ============================================================================== --- projects/release_6_3_xen/sys/i386/i386/intr_machdep.c Sat Oct 18 06:19:12 2008 (r184015) +++ projects/release_6_3_xen/sys/i386/i386/intr_machdep.c Sat Oct 18 06:19:52 2008 (r184016) @@ -283,7 +283,12 @@ intr_execute_handlers(struct intsrc *isr /* Schedule the ithread if needed. */ if (thread) { error = intr_event_schedule_thread(ie); +#ifndef XEN KASSERT(error == 0, ("bad stray interrupt")); +#else + if (error != 0) + log(LOG_CRIT, "bad stray interrupt %d", vector); +#endif } critical_exit(); td->td_intr_nesting_level--; Modified: projects/release_6_3_xen/sys/i386/i386/machdep.c ============================================================================== --- projects/release_6_3_xen/sys/i386/i386/machdep.c Sat Oct 18 06:19:12 2008 (r184015) +++ projects/release_6_3_xen/sys/i386/i386/machdep.c Sat Oct 18 06:19:52 2008 (r184016) @@ -141,6 +141,24 @@ int arch_i386_is_xbox = 0; uint32_t arch_i386_xbox_memsize = 0; #endif +#ifdef XEN +/* XEN includes */ +#include +#include +#include +#include +#include + +void Xhypervisor_callback(void); +void failsafe_callback(void); + +extern trap_info_t trap_table[]; +struct proc_ldt default_proc_ldt; +extern int init_first; +int running_xen = 1; +extern unsigned long physfree; +#endif /* XEN */ + /* Sanity check for __curthread() */ CTASSERT(offsetof(struct pcpu, pc_curthread) == 0); @@ -280,8 +298,9 @@ cpu_startup(dummy) */ bufinit(); vm_pager_bufferinit(); - +#ifndef XEN cpu_setregs(); +#endif } /* @@ -1106,6 +1125,25 @@ cpu_est_clockrate(int cpu_id, uint64_t * return (0); } +static int cpu_idle_hlt = 1; +SYSCTL_INT(_machdep, OID_AUTO, cpu_idle_hlt, CTLFLAG_RW, + &cpu_idle_hlt, 0, "Idle loop HLT enable"); +#ifdef XEN + +void +cpu_halt(void) +{ + HYPERVISOR_shutdown(SHUTDOWN_poweroff); +} + +static void +cpu_idle_default(void) +{ + idle_block(); +} + +#else + /* * Shutdown the CPU as much as possible */ @@ -1131,9 +1169,6 @@ cpu_halt(void) * XXX I'm turning it on for SMP as well by default for now. It seems to * help lock contention somewhat, and this is critical for HTT. -Peter */ -static int cpu_idle_hlt = 1; -SYSCTL_INT(_machdep, OID_AUTO, cpu_idle_hlt, CTLFLAG_RW, - &cpu_idle_hlt, 0, "Idle loop HLT enable"); static void cpu_idle_default(void) @@ -1145,6 +1180,7 @@ cpu_idle_default(void) */ __asm __volatile("sti; hlt"); } +#endif /* !XEN */ /* * Note that we have to be careful here to avoid a race between checking @@ -1156,7 +1192,7 @@ void cpu_idle(void) { -#ifdef SMP +#if defined(SMP) && !defined(XEN) if (mp_grab_cpu_hlt()) return; #endif @@ -1315,10 +1351,16 @@ SYSCTL_ULONG(_machdep, OID_AUTO, guessed */ int _default_ldt; + +#ifdef XEN +union descriptor *gdt; +union descriptor *ldt; +#else union descriptor gdt[NGDT * MAXCPU]; /* global descriptor table */ +union descriptor ldt[NLDT]; /* local descriptor table */ +#endif static struct gate_descriptor idt0[NIDT]; struct gate_descriptor *idt = &idt0[0]; /* interrupt descriptor table */ -union descriptor ldt[NLDT]; /* local descriptor table */ struct region_descriptor r_gdt, r_idt; /* table descriptors */ int private_tss; /* flag indicating private tss */ @@ -1353,7 +1395,7 @@ struct soft_segment_descriptor gdt_segs[ { 0x0, /* segment base address */ 0xfffff, /* length - all address space */ SDT_MEMRWA, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 1, /* segment descriptor present */ 0, 0, 1, /* default 32 vs 16 bit size */ @@ -1380,7 +1422,7 @@ struct soft_segment_descriptor gdt_segs[ { 0x0, /* segment base address */ 0xfffff, /* length - all address space */ SDT_MEMERA, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 1, /* segment descriptor present */ 0, 0, 1, /* default 32 vs 16 bit size */ @@ -1389,7 +1431,7 @@ struct soft_segment_descriptor gdt_segs[ { 0x0, /* segment base address */ 0xfffff, /* length - all address space */ SDT_MEMRWA, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 1, /* segment descriptor present */ 0, 0, 1, /* default 32 vs 16 bit size */ @@ -1416,11 +1458,12 @@ struct soft_segment_descriptor gdt_segs[ { 0x400, /* segment base address */ 0xfffff, /* length */ SDT_MEMRWA, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 1, /* segment descriptor present */ 0, 0, 1, /* default 32 vs 16 bit size */ 1 /* limit granularity (byte/page units)*/ }, +#ifndef XEN /* GPROC0_SEL 9 Proc 0 Tss Descriptor */ { 0x0, /* segment base address */ @@ -1512,6 +1555,7 @@ struct soft_segment_descriptor gdt_segs[ 0, 0, 0, /* default 32 vs 16 bit size */ 0 /* limit granularity (byte/page units)*/ }, +#endif /* !XEN */ }; static struct soft_segment_descriptor ldt_segs[] = { @@ -1680,7 +1724,17 @@ getmemsize(int first) goto physmap_done; } #endif - +#ifdef XEN + has_smap = 0; + Maxmem = xen_start_info->nr_pages - init_first; + physmem = Maxmem; + basemem = 0; + physmap[0] = init_first << PAGE_SHIFT; + physmap[1] = ptoa(Maxmem) - round_page(MSGBUF_SIZE); + physmap_idx = 0; + goto physmap_done; +#endif + hasbrokenint12 = 0; TUNABLE_INT_FETCH("hw.hasbrokenint12", &hasbrokenint12); bzero(&vmf, sizeof(vmf)); @@ -1858,7 +1912,7 @@ int15e820: vmf.vmf_ah = 0x88; vm86_intcall(0x15, &vmf); extmem = vmf.vmf_ax; -#else +#elif !defined(XEN) /* * Prefer the RTC value for extended memory. */ @@ -1948,7 +2002,7 @@ physmap_done: if (getenv_quad("dcons.addr", &dcons_addr) == 0 || getenv_quad("dcons.size", &dcons_size) == 0) dcons_addr = 0; - +#ifndef XEN /* * physmap is in bytes, so when converting to page boundaries, * round up the start address and round down the end address. @@ -2066,7 +2120,10 @@ do_next: } *pte = 0; invltlb(); - +#else + phys_avail[0] = physfree; + phys_avail[1] = xen_start_info->nr_pages*PAGE_SIZE; +#endif /* * XXX * The last chunk must contain at least one page plus the message @@ -2088,6 +2145,257 @@ do_next: avail_end = phys_avail[pa_indx]; } +#ifdef XEN + +#define MTOPSIZE (1<<(14 + PAGE_SHIFT)) +void +init386(int first) +{ + int error, gsel_tss, metadata_missing, x; + unsigned long off, gdtmachpfn; + struct pcpu *pc; + struct callback_register event = { + .type = CALLBACKTYPE_event, + .address = {GSEL(GCODE_SEL, SEL_KPL), (unsigned long)Xhypervisor_callback }, + }; + struct callback_register failsafe = { + .type = CALLBACKTYPE_failsafe, + .address = {GSEL(GCODE_SEL, SEL_KPL), (unsigned long)failsafe_callback }, + }; + + thread0.td_kstack = proc0kstack; + thread0.td_pcb = (struct pcb *) + (thread0.td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1; + + /* + * This may be done better later if it gets more high level + * components in it. If so just link td->td_proc here. + */ + proc_linkup(&proc0, &ksegrp0, &thread0); + + metadata_missing = 0; + if (xen_start_info->mod_start) { + preload_metadata = (caddr_t)xen_start_info->mod_start; + preload_bootstrap_relocate(KERNBASE); + } else { + metadata_missing = 1; + } + if (envmode == 1) + kern_envp = static_env; + else if ((caddr_t)xen_start_info->cmd_line) + kern_envp = xen_setbootenv((caddr_t)xen_start_info->cmd_line); + + boothowto |= xen_boothowto(kern_envp); + + /* Init basic tunables, hz etc */ + init_param1(); + + /* + * XEN occupies a portion of the upper virtual address space + * At its base it manages an array mapping machine page frames + * to physical page frames - hence we need to be able to + * access 4GB - (64MB - 4MB + 64k) + */ + gdt_segs[GPRIV_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE); + gdt_segs[GUFS_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE); + gdt_segs[GUGS_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE); + gdt_segs[GCODE_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE); + gdt_segs[GDATA_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE); + gdt_segs[GUCODE_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE); + gdt_segs[GUDATA_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE); + gdt_segs[GBIOSLOWMEM_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE); + + pc = &__pcpu[0]; + gdt_segs[GPRIV_SEL].ssd_base = (int) pc; + gdt_segs[GPROC0_SEL].ssd_base = (int) &pc->pc_common_tss; + + PT_SET_MA(gdt, xpmap_ptom(VTOP(gdt)) | PG_V | PG_RW); + bzero(gdt, PAGE_SIZE); + for (x = 0; x < NGDT; x++) + ssdtosd(&gdt_segs[x], &gdt[x].sd); + + + printk("gdt=%p\n", gdt); + printk("PTmap=%p\n", PTmap); + printk("addr=%p\n", *vtopte((unsigned long)gdt) & ~PG_RW); + + gdtmachpfn = vtomach(gdt) >> PAGE_SHIFT; + PT_SET_MA(gdt, *vtopte((unsigned long)gdt) & ~(PG_RW|PG_M|PG_A)); + PANIC_IF(HYPERVISOR_set_gdt(&gdtmachpfn, 512) != 0); + lgdt(&r_gdt /* unused */); + gdtset = 1; + + if ((error = HYPERVISOR_set_trap_table(trap_table)) != 0) { + panic("set_trap_table failed - error %d\n", error); + } + + error = HYPERVISOR_callback_op(CALLBACKOP_register, &event); + if (error == 0) + error = HYPERVISOR_callback_op(CALLBACKOP_register, &failsafe); +#if CONFIG_XEN_COMPAT <= 0x030002 + if (error == -ENOXENSYS) + HYPERVISOR_set_callbacks(GSEL(GCODE_SEL, SEL_KPL), + (unsigned long)Xhypervisor_callback, + GSEL(GCODE_SEL, SEL_KPL), (unsigned long)failsafe_callback); +#endif + pcpu_init(pc, 0, sizeof(struct pcpu)); + PCPU_SET(prvspace, pc); + PCPU_SET(curthread, &thread0); + PCPU_SET(curpcb, thread0.td_pcb); + PCPU_SET(pdir, (unsigned long)IdlePTD); + + /* + * Initialize mutexes. + * + * icu_lock: in order to allow an interrupt to occur in a critical + * section, to set pcpu->ipending (etc...) properly, we + * must be able to get the icu lock, so it can't be + * under witness. + */ + mutex_init(); + mtx_init(&icu_lock, "icu", NULL, MTX_SPIN | MTX_NOWITNESS); + + /* make ldt memory segments */ + PT_SET_MA(ldt, xpmap_ptom(VTOP(ldt)) | PG_V | PG_RW); + bzero(ldt, PAGE_SIZE); + ldt_segs[LUCODE_SEL].ssd_limit = atop(0 - 1); + ldt_segs[LUDATA_SEL].ssd_limit = atop(0 - 1); + for (x = 0; x < sizeof ldt_segs / sizeof ldt_segs[0]; x++) + ssdtosd(&ldt_segs[x], &ldt[x].sd); + + default_proc_ldt.ldt_base = (caddr_t)ldt; + default_proc_ldt.ldt_len = 6; + _default_ldt = (int)&default_proc_ldt; + PCPU_SET(currentldt, _default_ldt) + PT_SET_MA(ldt, *vtopte((unsigned long)ldt) & ~PG_RW); + xen_set_ldt((unsigned long) ldt, (sizeof ldt_segs / sizeof ldt_segs[0])); + +#ifdef XBOX + /* + * The following code queries the PCI ID of 0:0:0. For the XBOX, + * This should be 0x10de / 0x02a5. + * + * This is exactly what Linux does. + */ + outl(0xcf8, 0x80000000); + if (inl(0xcfc) == 0x02a510de) { + arch_i386_is_xbox = 1; + pic16l_setled(XBOX_LED_GREEN); + + /* + * We are an XBOX, but we may have either 64MB or 128MB of + * memory. The PCI host bridge should be programmed for this, + * so we just query it. + */ + outl(0xcf8, 0x80000084); + arch_i386_xbox_memsize = (inl(0xcfc) == 0x7FFFFFF) ? 128 : 64; + } +#endif /* XBOX */ +#if defined (XEN_PRIVILEGED) + /* + * Initialize the i8254 before the console so that console + * initialization can use DELAY(). + */ + i8254_init(); +#endif + /* + * Initialize the console before we print anything out. + */ + cninit(); + + if (metadata_missing) + printf("WARNING: loader(8) metadata is missing!\n"); + +#ifdef DEV_ISA + if (xen_start_info->flags & SIF_PRIVILEGED) { + elcr_probe(); +#ifdef DEV_ATPIC + atpic_startup(); +#endif + } +#endif + +#ifdef DDB + ksym_start = bootinfo.bi_symtab; + ksym_end = bootinfo.bi_esymtab; +#endif + + kdb_init(); + +#ifdef KDB + if (boothowto & RB_KDB) + kdb_enter("Boot flags requested debugger"); +#endif + + finishidentcpu(); /* Final stage of CPU initialization */ + setidt(IDT_UD, &IDTVEC(ill), SDT_SYS386TGT, SEL_KPL, + GSEL(GCODE_SEL, SEL_KPL)); + setidt(IDT_GP, &IDTVEC(prot), SDT_SYS386TGT, SEL_KPL, + GSEL(GCODE_SEL, SEL_KPL)); + initializecpu(); /* Initialize CPU registers */ + + /* make an initial tss so cpu can get interrupt stack on syscall! */ + /* Note: -16 is so we can grow the trapframe if we came from vm86 */ + PCPU_SET(common_tss.tss_esp0, thread0.td_kstack + + KSTACK_PAGES * PAGE_SIZE - sizeof(struct pcb) - 16); + PCPU_SET(common_tss.tss_ss0, GSEL(GDATA_SEL, SEL_KPL)); + gsel_tss = GSEL(GPROC0_SEL, SEL_KPL); + HYPERVISOR_stack_switch(GSEL(GDATA_SEL, SEL_KPL), + PCPU_GET(common_tss.tss_esp0)); + + + /* pointer to selector slot for %fs/%gs */ + PCPU_SET(fsgs_gdt, &gdt[GUFS_SEL].sd); + + dblfault_tss.tss_esp = dblfault_tss.tss_esp0 = dblfault_tss.tss_esp1 = + dblfault_tss.tss_esp2 = (int)&dblfault_stack[sizeof(dblfault_stack)]; + dblfault_tss.tss_ss = dblfault_tss.tss_ss0 = dblfault_tss.tss_ss1 = + dblfault_tss.tss_ss2 = GSEL(GDATA_SEL, SEL_KPL); +#ifdef PAE + dblfault_tss.tss_cr3 = (int)IdlePDPT; +#else + dblfault_tss.tss_cr3 = (int)IdlePTD; +#endif + dblfault_tss.tss_eip = (int)dblfault_handler; + dblfault_tss.tss_eflags = PSL_KERNEL; + dblfault_tss.tss_ds = dblfault_tss.tss_es = + dblfault_tss.tss_gs = GSEL(GDATA_SEL, SEL_KPL); + dblfault_tss.tss_fs = GSEL(GPRIV_SEL, SEL_KPL); + dblfault_tss.tss_cs = GSEL(GCODE_SEL, SEL_KPL); + dblfault_tss.tss_ldt = GSEL(GLDT_SEL, SEL_KPL); + + vm86_initialize(); + getmemsize(first); + init_param2(physmem); + + + /* Map the message buffer. */ + for (off = 0; off < round_page(MSGBUF_SIZE); off += PAGE_SIZE) + pmap_kenter((vm_offset_t)msgbufp + off, avail_end + off); + + /* now running on new page tables, configured,and u/iom is accessible */ + + msgbufinit(msgbufp, MSGBUF_SIZE); + + /* transfer to user mode */ + + _ucodesel = GSEL(GUCODE_SEL, SEL_UPL); + _udatasel = GSEL(GUDATA_SEL, SEL_UPL); + + /* setup proc 0's pcb */ + thread0.td_pcb->pcb_flags = 0; +#ifdef PAE + thread0.td_pcb->pcb_cr3 = (int)IdlePDPT; +#else + thread0.td_pcb->pcb_cr3 = (int)IdlePTD; +#endif + thread0.td_pcb->pcb_ext = 0; + thread0.td_frame = &proc0_tf; + thread0.td_pcb->pcb_fsd = PCPU_GET(fsgs_gdt)[0]; + thread0.td_pcb->pcb_gsd = PCPU_GET(fsgs_gdt)[1]; +} + +#else void init386(first) int first; @@ -2353,6 +2661,7 @@ init386(first) thread0.td_pcb->pcb_ext = 0; thread0.td_frame = &proc0_tf; } +#endif /* !XEN */ void cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t size) Modified: projects/release_6_3_xen/sys/i386/i386/support.s ============================================================================== --- projects/release_6_3_xen/sys/i386/i386/support.s Sat Oct 18 06:19:12 2008 (r184015) +++ projects/release_6_3_xen/sys/i386/i386/support.s Sat Oct 18 06:19:52 2008 (r184016) @@ -1426,10 +1426,11 @@ ENTRY(bcmp) */ /* void lgdt(struct region_descriptor *rdp); */ ENTRY(lgdt) +#ifndef XEN /* reload the descriptor table */ movl 4(%esp),%eax lgdt (%eax) - +#endif /* flush the prefetch q */ jmp 1f nop Modified: projects/release_6_3_xen/sys/i386/i386/swtch.s ============================================================================== --- projects/release_6_3_xen/sys/i386/i386/swtch.s Sat Oct 18 06:19:12 2008 (r184015) +++ projects/release_6_3_xen/sys/i386/i386/swtch.s Sat Oct 18 06:19:52 2008 (r184016) @@ -71,7 +71,7 @@ ENTRY(cpu_throw) movl 8(%esp),%ecx /* New thread */ movl TD_PCB(%ecx),%edx movl PCB_CR3(%edx),%eax - movl %eax,%cr3 /* new address space */ + LOAD_CR3(%eax) /* new address space */ /* set bit in new pm_active */ movl TD_PROC(%ecx),%eax movl P_VMSPACE(%eax), %ebx @@ -114,11 +114,13 @@ ENTRY(cpu_switch) movl %gs,PCB_GS(%edx) pushfl /* PSL */ popl PCB_PSL(%edx) +#ifndef XEN /* Check to see if we need to call a switchout function. */ movl PCB_SWITCHOUT(%edx),%eax cmpl $0, %eax je 1f call *%eax +#endif 1: /* Test if debug registers should be saved. */ testl $PCB_DBREGS,PCB_FLAGS(%edx) @@ -171,7 +173,7 @@ ENTRY(cpu_switch) movl %cr3,%ebx /* The same address space? */ cmpl %ebx,%eax je sw1 - movl %eax,%cr3 /* new address space */ + LOAD_CR3(%eax) /* new address space */ /* Release bit from old pmap->pm_active */ movl PCPU(CURPMAP), %ebx @@ -191,6 +193,18 @@ ENTRY(cpu_switch) btsl %esi, PM_ACTIVE(%ebx) /* set new */ sw1: +#ifdef XEN + pushl %eax + pushl %ecx + pushl %edx + call xen_handle_thread_switch + popl %edx + popl %ecx + popl %eax + /* + * XXX set IOPL + */ +#else /* * At this point, we've switched address spaces and are ready * to load up the rest of the next context. @@ -238,7 +252,7 @@ sw1: movl 12(%esi), %ebx movl %eax, 8(%edi) movl %ebx, 12(%edi) - +#endif /* Restore context. */ movl PCB_EBX(%edx),%ebx movl PCB_ESP(%edx),%esp @@ -263,7 +277,7 @@ sw1: movl _default_ldt,%eax cmpl PCPU(CURRENTLDT),%eax je 2f - lldt _default_ldt + LLDT(_default_ldt) movl %eax,PCPU(CURRENTLDT) jmp 2f 1: @@ -366,7 +380,7 @@ ENTRY(savectx) * parent's npx state for forks by forgetting to reload. */ pushfl - cli + CLI movl PCPU(FPCURTHREAD),%eax testl %eax,%eax je 1f Modified: projects/release_6_3_xen/sys/i386/i386/sys_machdep.c ============================================================================== --- projects/release_6_3_xen/sys/i386/i386/sys_machdep.c Sat Oct 18 06:19:12 2008 (r184015) +++ projects/release_6_3_xen/sys/i386/i386/sys_machdep.c Sat Oct 18 06:19:52 2008 (r184016) @@ -58,6 +58,25 @@ __FBSDID("$FreeBSD$"); #include /* for kernel_map */ +#ifdef XEN +#include + +void i386_reset_ldt(struct proc_ldt *pldt); + +void +i386_reset_ldt(struct proc_ldt *pldt) +{ + xen_set_ldt((vm_offset_t)pldt->ldt_base, pldt->ldt_len); +} +#define SEG_VIRT_END (HYPERVISOR_VIRT_START >> 12) & 0xffff +#define SET_DESCRIPTOR(index, sd) \ + HYPERVISOR_update_descriptor(vtomach(&PCPU_GET(fsgs_gdt)[index]), *(uint64_t *)&(sd)); +#else +#define i386_reset_ldt(x) +#define SEG_VIRT_END 0xffff +#define SET_DESCRIPTOR(index, sd) PCPU_GET(fsgs_gdt)[index] = (sd); +#endif + #define MAX_LD 8192 #define LD_PER_PAGE 512 #define NEW_MAX_LD(num) ((num + LD_PER_PAGE) & ~(LD_PER_PAGE-1)) @@ -163,7 +182,7 @@ sysarch(td, uap) */ sd.sd_lobase = base & 0xffffff; sd.sd_hibase = (base >> 24) & 0xff; - sd.sd_lolimit = 0xffff; /* 4GB limit, wraps around */ + sd.sd_lolimit = SEG_VIRT_END; /* 4GB limit, wraps */ sd.sd_hilimit = 0xf; sd.sd_type = SDT_MEMRWA; sd.sd_dpl = SEL_UPL; @@ -173,7 +192,7 @@ sysarch(td, uap) sd.sd_gran = 1; critical_enter(); td->td_pcb->pcb_fsd = sd; - PCPU_GET(fsgs_gdt)[0] = sd; + SET_DESCRIPTOR(0, sd); critical_exit(); td->td_frame->tf_fs = GSEL(GUFS_SEL, SEL_UPL); } @@ -193,7 +212,7 @@ sysarch(td, uap) */ sd.sd_lobase = base & 0xffffff; sd.sd_hibase = (base >> 24) & 0xff; - sd.sd_lolimit = 0xffff; /* 4GB limit, wraps around */ + sd.sd_lolimit = SEG_VIRT_END; /* 4GB limit, wraps */ sd.sd_hilimit = 0xf; sd.sd_type = SDT_MEMRWA; sd.sd_dpl = SEL_UPL; @@ -203,7 +222,7 @@ sysarch(td, uap) sd.sd_gran = 1; critical_enter(); td->td_pcb->pcb_gsd = sd; - PCPU_GET(fsgs_gdt)[1] = sd; + SET_DESCRIPTOR(1, sd); critical_exit(); load_gs(GSEL(GUGS_SEL, SEL_UPL)); } @@ -364,6 +383,10 @@ set_user_ldt(struct mdproc *mdp) struct proc_ldt *pldt; pldt = mdp->md_ldt; +#ifdef XEN + i386_reset_ldt(pldt); + PCPU_SET(currentldt, (int)pldt); +#else #ifdef SMP gdt[PCPU_GET(cpuid) * NGDT + GUSERLDT_SEL].sd = pldt->ldt_sd; #else @@ -371,6 +394,7 @@ set_user_ldt(struct mdproc *mdp) #endif lldt(GSEL(GUSERLDT_SEL, SEL_KPL)); PCPU_SET(currentldt, GSEL(GUSERLDT_SEL, SEL_KPL)); +#endif /* !XEN */ } #ifdef SMP @@ -385,6 +409,39 @@ set_user_ldt_rv(struct thread *td) } #endif +#ifdef XEN + +struct proc_ldt * +user_ldt_alloc(struct mdproc *mdp, int len) +{ + struct proc_ldt *pldt, *new_ldt; + + MALLOC(new_ldt, struct proc_ldt *, sizeof(struct proc_ldt), + M_SUBPROC, M_WAITOK); + + new_ldt->ldt_len = len = NEW_MAX_LD(len); + new_ldt->ldt_base = (caddr_t)kmem_alloc(kernel_map, + round_page(len * sizeof(union descriptor))); + if (new_ldt->ldt_base == NULL) { + FREE(new_ldt, M_SUBPROC); + return NULL; + } + new_ldt->ldt_refcnt = 1; + new_ldt->ldt_active = 0; + + if ((pldt = mdp->md_ldt)) { + if (len > pldt->ldt_len) + len = pldt->ldt_len; + bcopy(pldt->ldt_base, new_ldt->ldt_base, + len * sizeof(union descriptor)); + } else { + bcopy(ldt, new_ldt->ldt_base, PAGE_SIZE); + } + pmap_map_readonly(kernel_pmap, (vm_offset_t)new_ldt->ldt_base, + new_ldt->ldt_len*sizeof(union descriptor)); + return new_ldt; +} +#else /* * Must be called with either sched_lock free or held but not recursed. * If it does not return NULL, it will return with it owned. @@ -425,6 +482,7 @@ user_ldt_alloc(struct mdproc *mdp, int l } return new_ldt; } +#endif /* * Must be called either with sched_lock free or held but not recursed. @@ -443,8 +501,11 @@ user_ldt_free(struct thread *td) mtx_lock_spin(&sched_lock); mtx_assert(&sched_lock, MA_OWNED | MA_NOTRECURSED); if (td == PCPU_GET(curthread)) { +#ifndef XEN lldt(_default_ldt); +#endif PCPU_SET(currentldt, _default_ldt); + i386_reset_ldt((struct proc_ldt *)_default_ldt); } mdp->md_ldt = NULL; @@ -549,6 +610,9 @@ i386_set_ldt(td, uap, descs) } if (!(uap->start == LDT_AUTO_ALLOC && uap->num == 1)) { +#ifdef XEN + load_gs(0); /* XXX check if we really still need this */ +#endif /* complain a for a while if using old methods */ if (ldt_warnings++ < NUM_LDT_WARNINGS) { printf("Warning: pid %d used static ldt allocation.\n", @@ -671,6 +735,23 @@ again: return (error); } +#ifdef XEN +static int +i386_set_ldt_data(struct thread *td, int start, int num, + union descriptor *descs) +{ + struct mdproc *mdp = &td->td_proc->p_md; + struct proc_ldt *pldt = mdp->md_ldt; + int i, error; + + for (i = 0; i < num; i++) { + error = HYPERVISOR_update_descriptor(vtomach(&((union descriptor *)(pldt->ldt_base))[start + i]), *(uint64_t *)(descs + i)); + if (error) + panic("failed to update ldt: %d", error); + } + return (0); +} +#else static int i386_set_ldt_data(struct thread *td, int start, int num, union descriptor *descs) @@ -686,6 +767,7 @@ i386_set_ldt_data(struct thread *td, int num * sizeof(union descriptor)); return (0); } +#endif static int i386_ldt_grow(struct thread *td, int len) Modified: projects/release_6_3_xen/sys/i386/i386/trap.c ============================================================================== --- projects/release_6_3_xen/sys/i386/i386/trap.c Sat Oct 18 06:19:12 2008 (r184015) +++ projects/release_6_3_xen/sys/i386/i386/trap.c Sat Oct 18 06:19:52 2008 (r184016) @@ -215,6 +215,7 @@ trap(frame) goto out; #endif +#ifndef XEN if ((frame.tf_eflags & PSL_I) == 0) { /* * Buggy application or kernel code has disabled @@ -245,6 +246,7 @@ trap(frame) enable_intr(); } } +#endif eva = 0; code = frame.tf_err; Modified: projects/release_6_3_xen/sys/i386/i386/vm_machdep.c ============================================================================== --- projects/release_6_3_xen/sys/i386/i386/vm_machdep.c Sat Oct 18 06:19:12 2008 (r184015) +++ projects/release_6_3_xen/sys/i386/i386/vm_machdep.c Sat Oct 18 06:19:52 2008 (r184016) @@ -89,6 +89,9 @@ __FBSDID("$FreeBSD$"); #include #include +#ifdef XEN +#include +#endif #ifdef PC98 #include #else @@ -264,7 +267,7 @@ cpu_fork(td1, p2, td2, flags) /* Setup to release sched_lock in fork_exit(). */ td2->td_md.md_spinlock_count = 1; - td2->td_md.md_saved_flags = PSL_KERNEL | PSL_I; + td2->td_md.md_saved_flags = PSL_USER; /* * Now, cpu_switch() can schedule the new process. @@ -436,7 +439,7 @@ cpu_set_upcall(struct thread *td, struct /* Setup to release sched_lock in fork_exit(). */ td->td_md.md_spinlock_count = 1; - td->td_md.md_saved_flags = PSL_KERNEL | PSL_I; + td->td_md.md_saved_flags = PSL_USER; } /* @@ -593,6 +596,9 @@ cpu_reset_real() int b; #endif +#ifdef XEN + HYPERVISOR_shutdown(SHUTDOWN_poweroff); +#endif disable_intr(); #ifdef CPU_ELAN if (elan_mmcr != NULL) @@ -759,8 +765,11 @@ sf_buf_alloc(struct vm_page *m, int flag */ ptep = vtopte(sf->kva); opte = *ptep; +#ifdef XEN + PT_SET_MA(sf->kva, xpmap_ptom(VM_PAGE_TO_PHYS(m)) | pgeflag | PG_RW | PG_V); +#else *ptep = VM_PAGE_TO_PHYS(m) | pgeflag | PG_RW | PG_V; - +#endif /* * Avoid unnecessary TLB invalidations: If the sf_buf's old * virtual-to-physical mapping was not used, then any processor @@ -809,6 +818,14 @@ sf_buf_free(struct sf_buf *sf) if (sf->ref_count == 0) { TAILQ_INSERT_TAIL(&sf_buf_freelist, sf, free_entry); nsfbufsused--; +#ifdef XEN + /* + * Xen doesn't like having dangling R/W mappings + */ + pmap_qremove(sf->kva, 1); + sf->m = NULL; + LIST_REMOVE(sf, list_entry); +#endif if (sf_buf_alloc_want > 0) wakeup_one(&sf_buf_freelist); } Modified: projects/release_6_3_xen/sys/i386/include/asmacros.h ============================================================================== --- projects/release_6_3_xen/sys/i386/include/asmacros.h Sat Oct 18 06:19:12 2008 (r184015) +++ projects/release_6_3_xen/sys/i386/include/asmacros.h Sat Oct 18 06:19:52 2008 (r184016) @@ -134,6 +134,46 @@ #define MEXITCOUNT #endif /* GPROF */ +/* + * Setup the kernel segment registers. + */ +#define SET_KERNEL_SREGS \ + movl $KDSEL, %eax ; /* reload with kernel's data segment */ \ + movl %eax, %ds ; \ + movl %eax, %es ; \ + movl $KPSEL, %eax ; /* reload with per-CPU data segment */ \ + movl %eax, %fs + +#ifdef XEN +#define LOAD_CR3(reg) \ + movl reg,PCPU(CR3); \ + pushl %ecx ; \ + pushl %edx ; \ + pushl %esi ; \ + pushl reg ; \ + call xen_load_cr3 ; \ + addl $4,%esp ; \ + popl %esi ; \ + popl %edx ; \ + popl %ecx ; \ + +#define READ_CR3(reg) movl PCPU(CR3),reg; +#define LLDT(arg) \ + pushl %edx ; \ + pushl %eax ; \ + xorl %eax,%eax ; \ + movl %eax,%gs ; \ + call i386_reset_ldt ; \ + popl %eax ; \ + popl %edx +#define CLI call ni_cli +#else +#define LOAD_CR3(reg) movl reg,%cr3; +#define READ_CR3(reg) movl %cr3,reg; +#define LLDT(arg) lldt arg; +#define CLI cli +#endif /* !XEN */ + #ifdef LOCORE /* * Convenience macros for declaring interrupt entry points and trap @@ -145,4 +185,30 @@ #endif /* LOCORE */ +#ifdef __STDC__ +#define ELFNOTE(name, type, desctype, descdata...) \ +.pushsection .note.name ; \ + .align 4 ; \ + .long 2f - 1f /* namesz */ ; \ + .long 4f - 3f /* descsz */ ; \ + .long type ; \ +1:.asciz #name ; \ +2:.align 4 ; \ +3:desctype descdata ; \ +4:.align 4 ; \ +.popsection +#else /* !__STDC__, i.e. -traditional */ +#define ELFNOTE(name, type, desctype, descdata) \ +.pushsection .note.name ; \ + .align 4 ; \ + .long 2f - 1f /* namesz */ ; \ + .long 4f - 3f /* descsz */ ; \ + .long type ; \ +1:.asciz "name" ; \ +2:.align 4 ; \ +3:desctype descdata ; \ +4:.align 4 ; \ +.popsection +#endif /* __STDC__ */ + #endif /* !_MACHINE_ASMACROS_H_ */ Modified: projects/release_6_3_xen/sys/i386/include/cpufunc.h ============================================================================== --- projects/release_6_3_xen/sys/i386/include/cpufunc.h Sat Oct 18 06:19:12 2008 (r184015) +++ projects/release_6_3_xen/sys/i386/include/cpufunc.h Sat Oct 18 06:19:52 2008 (r184016) @@ -42,6 +42,17 @@ #error this file needs sys/cdefs.h as a prerequisite #endif +#ifdef XEN +extern void xen_cli(void); +extern void xen_sti(void); +extern u_int xen_rcr2(void); +extern void xen_load_cr3(u_int data); +extern void xen_tlb_flush(void); +extern void xen_invlpg(u_int addr); +extern int xen_save_and_cli(void); +extern void xen_restore_flags(u_int eflags); +#endif + struct region_descriptor; #define readb(va) (*(volatile u_int8_t *) (va)) @@ -81,7 +92,11 @@ bsrl(u_int mask) static __inline void disable_intr(void) { +#ifdef XEN + xen_cli(); +#else __asm __volatile("cli" : : : "memory"); +#endif } static __inline void *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-projects@FreeBSD.ORG Sat Oct 18 06:20:17 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5E4D31065695; Sat, 18 Oct 2008 06:20:17 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4C6378FC0C; Sat, 18 Oct 2008 06:20:17 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9I6KHA3008837; Sat, 18 Oct 2008 06:20:17 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9I6KHsd008834; Sat, 18 Oct 2008 06:20:17 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810180620.m9I6KHsd008834@svn.freebsd.org> From: Kip Macy Date: Sat, 18 Oct 2008 06:20:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184017 - projects/release_6_3_xen/sys/kern X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Oct 2008 06:20:17 -0000 Author: kmacy Date: Sat Oct 18 06:20:16 2008 New Revision: 184017 URL: http://svn.freebsd.org/changeset/base/184017 Log: merge xen kern workarounds Modified: projects/release_6_3_xen/sys/kern/kern_fork.c projects/release_6_3_xen/sys/kern/kern_synch.c projects/release_6_3_xen/sys/kern/subr_trap.c Modified: projects/release_6_3_xen/sys/kern/kern_fork.c ============================================================================== --- projects/release_6_3_xen/sys/kern/kern_fork.c Sat Oct 18 06:19:52 2008 (r184016) +++ projects/release_6_3_xen/sys/kern/kern_fork.c Sat Oct 18 06:20:16 2008 (r184017) @@ -112,10 +112,15 @@ vfork(td, uap) struct thread *td; struct vfork_args *uap; { - int error; + int error, flags; struct proc *p2; - error = fork1(td, RFFDG | RFPROC | RFPPWAIT | RFMEM, 0, &p2); +#ifdef XEN + flags = RFFDG | RFPROC; +#else + flags = RFFDG | RFPROC | RFPPWAIT | RFMEM; +#endif + error = fork1(td, flags, 0, &p2); if (error == 0) { td->td_retval[0] = p2->p_pid; td->td_retval[1] = 0; Modified: projects/release_6_3_xen/sys/kern/kern_synch.c ============================================================================== --- projects/release_6_3_xen/sys/kern/kern_synch.c Sat Oct 18 06:19:52 2008 (r184016) +++ projects/release_6_3_xen/sys/kern/kern_synch.c Sat Oct 18 06:20:16 2008 (r184017) @@ -64,6 +64,12 @@ __FBSDID("$FreeBSD$"); #include +#ifdef XEN +#include +#include +#include +#endif + static void synch_setup(void *dummy); SYSINIT(synch_setup, SI_SUB_KICK_SCHEDULER, SI_ORDER_FIRST, synch_setup, NULL) @@ -417,6 +423,9 @@ mi_switch(int flags, struct thread *newt td, td->td_proc->p_comm, td->td_priority, td->td_inhibitors, td->td_wmesg, td->td_lockname); #endif +#ifdef XEN + PT_UPDATES_FLUSH(); +#endif sched_switch(td, newtd, flags); CTR3(KTR_SCHED, "mi_switch: running %p(%s) prio %d", td, td->td_proc->p_comm, td->td_priority); Modified: projects/release_6_3_xen/sys/kern/subr_trap.c ============================================================================== --- projects/release_6_3_xen/sys/kern/subr_trap.c Sat Oct 18 06:19:52 2008 (r184016) +++ projects/release_6_3_xen/sys/kern/subr_trap.c Sat Oct 18 06:20:16 2008 (r184017) @@ -67,6 +67,12 @@ __FBSDID("$FreeBSD$"); #include #include +#ifdef XEN +#include +#include +#include +#endif + /* * Define the code needed before returning to user mode, for * trap and syscall. @@ -139,6 +145,9 @@ userret(td, frame, oticks) sched_userret(td); KASSERT(td->td_locks == 0, ("userret: Returning with %d locks held.", td->td_locks)); +#ifdef XEN + PT_UPDATES_FLUSH(); +#endif } /* From owner-svn-src-projects@FreeBSD.ORG Sat Oct 18 06:30:34 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 413851065686; Sat, 18 Oct 2008 06:30:34 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 1657A8FC20; Sat, 18 Oct 2008 06:30:34 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9I6UXcG009095; Sat, 18 Oct 2008 06:30:33 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9I6UXM8009094; Sat, 18 Oct 2008 06:30:33 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810180630.m9I6UXM8009094@svn.freebsd.org> From: Kip Macy Date: Sat, 18 Oct 2008 06:30:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184019 - projects/release_6_3_xen/sys/dev/xen X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Oct 2008 06:30:34 -0000 Author: kmacy Date: Sat Oct 18 06:30:33 2008 New Revision: 184019 URL: http://svn.freebsd.org/changeset/base/184019 Log: copy device support from releng_6 branch Added: projects/release_6_3_xen/sys/dev/xen/ (props changed) - copied from r184018, projects/releng_6_xen/sys/dev/xen/ From owner-svn-src-projects@FreeBSD.ORG Sat Oct 18 06:31:32 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8A536106569E; Sat, 18 Oct 2008 06:31:32 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 77E9D8FC16; Sat, 18 Oct 2008 06:31:32 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9I6VWoA009151; Sat, 18 Oct 2008 06:31:32 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9I6VW77009147; Sat, 18 Oct 2008 06:31:32 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810180631.m9I6VW77009147@svn.freebsd.org> From: Kip Macy Date: Sat, 18 Oct 2008 06:31:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184020 - projects/release_6_3_xen/sys/conf X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Oct 2008 06:31:32 -0000 Author: kmacy Date: Sat Oct 18 06:31:32 2008 New Revision: 184020 URL: http://svn.freebsd.org/changeset/base/184020 Log: add xen support to the config Modified: projects/release_6_3_xen/sys/conf/files projects/release_6_3_xen/sys/conf/files.i386 projects/release_6_3_xen/sys/conf/kern.pre.mk projects/release_6_3_xen/sys/conf/options.i386 Modified: projects/release_6_3_xen/sys/conf/files ============================================================================== --- projects/release_6_3_xen/sys/conf/files Sat Oct 18 06:30:33 2008 (r184019) +++ projects/release_6_3_xen/sys/conf/files Sat Oct 18 06:31:32 2008 (r184020) @@ -1998,3 +1998,18 @@ vm/vm_pager.c standard vm/vm_unix.c standard vm/vm_zeroidle.c standard vm/vnode_pager.c standard + +xen/gnttab.c optional xen +xen/features.c optional xen +xen/evtchn/evtchn.c optional xen +xen/evtchn/evtchn_dev.c optional xen +xen/xenbus/xenbus_client.c optional xen +xen/xenbus/xenbus_comms.c optional xen +xen/xenbus/xenbus_dev.c optional xen +xen/xenbus/xenbus_probe.c optional xen +xen/xenbus/xenbus_probe_backend.c optional xen +xen/xenbus/xenbus_xs.c optional xen +dev/xen/console/console.c optional xen +dev/xen/console/xencons_ring.c optional xen +dev/xen/blkfront/blkfront.c optional xen +dev/xen/netfront/netfront.c optional xen Modified: projects/release_6_3_xen/sys/conf/files.i386 ============================================================================== --- projects/release_6_3_xen/sys/conf/files.i386 Sat Oct 18 06:30:33 2008 (r184019) +++ projects/release_6_3_xen/sys/conf/files.i386 Sat Oct 18 06:31:32 2008 (r184020) @@ -288,8 +288,8 @@ i386/cpufreq/smist.c optional cpufreq i386/i386/atomic.c standard \ compile-with "${CC} -c ${CFLAGS} ${DEFINED_PROF:S/^$/-fomit-frame-pointer/} ${.IMPSRC}" i386/i386/autoconf.c standard -i386/i386/bios.c standard -i386/i386/bioscall.s standard +i386/i386/bios.c optional native +i386/i386/bioscall.s optional native i386/i386/busdma_machdep.c standard i386/i386/db_disasm.c optional ddb i386/i386/db_interface.c optional ddb @@ -298,7 +298,8 @@ i386/i386/dump_machdep.c standard i386/i386/elan-mmcr.c optional cpu_elan i386/i386/elan-mmcr.c optional cpu_soekris i386/i386/elf_machdep.c standard -i386/i386/exception.s standard +i386/i386/exception.s optional native +i386/xen/exception.s optional xen i386/i386/gdb_machdep.c optional gdb i386/i386/geode.c optional cpu_geode i386/i386/i686_mem.c optional mem @@ -311,22 +312,26 @@ i386/i386/io_apic.c optional apic i386/i386/k6_mem.c optional mem i386/i386/legacy.c standard i386/i386/local_apic.c optional apic -i386/i386/locore.s standard no-obj +i386/i386/locore.s optional native no-obj +i386/xen/locore.s optional xen no-obj i386/i386/longrun.c optional cpu_enable_longrun i386/i386/machdep.c standard i386/i386/mem.c optional mem i386/i386/minidump_machdep.c standard i386/i386/mp_clock.c optional smp -i386/i386/mp_machdep.c optional smp +i386/i386/mp_machdep.c optional native smp +i386/xen/mp_machdep.c optional xen smp i386/i386/mp_watchdog.c optional mp_watchdog smp -i386/i386/mpboot.s optional smp +i386/i386/mpboot.s optional native smp i386/i386/mptable.c optional apic i386/i386/mptable_pci.c optional apic pci i386/i386/msi.c optional apic pci i386/i386/nexus.c standard i386/i386/perfmon.c optional perfmon i386/i386/perfmon.c optional perfmon profiling-routine -i386/i386/pmap.c standard +i386/i386/pmap.c optional native +i386/xen/pmap.c optional xen +i386/xen/xen_machdep.c optional xen i386/i386/ptrace_machdep.c standard i386/i386/support.s standard i386/i386/swtch.s standard @@ -355,9 +360,10 @@ i386/ibcs2/ibcs2_util.c optional ibcs2 i386/ibcs2/ibcs2_xenix.c optional ibcs2 i386/ibcs2/ibcs2_xenix_sysent.c optional ibcs2 i386/ibcs2/imgact_coff.c optional ibcs2 -i386/isa/atpic.c standard +i386/isa/atpic.c optional atpic #i386/isa/atpic_vector.s standard -i386/isa/clock.c standard +i386/isa/clock.c optional native +i386/xen/clock.c optional xen i386/isa/elcr.c standard i386/isa/elink.c optional ep i386/isa/elink.c optional ie Modified: projects/release_6_3_xen/sys/conf/kern.pre.mk ============================================================================== --- projects/release_6_3_xen/sys/conf/kern.pre.mk Sat Oct 18 06:30:33 2008 (r184019) +++ projects/release_6_3_xen/sys/conf/kern.pre.mk Sat Oct 18 06:31:32 2008 (r184020) @@ -70,6 +70,9 @@ INCLUDES+= -I$S/dev/twa # .. and the same for em INCLUDES+= -I$S/dev/em +INCLUDES+= -I$S/xen/interface -I$S/xen/interface/io + + CFLAGS= ${COPTFLAGS} ${CWARNFLAGS} ${DEBUG} CFLAGS+= ${INCLUDES} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h .if ${CC} != "icc" Modified: projects/release_6_3_xen/sys/conf/options.i386 ============================================================================== --- projects/release_6_3_xen/sys/conf/options.i386 Sat Oct 18 06:30:33 2008 (r184019) +++ projects/release_6_3_xen/sys/conf/options.i386 Sat Oct 18 06:31:32 2008 (r184020) @@ -163,3 +163,6 @@ ASR_COMPAT opt_asr.h # Debugging KDB_STOP_NMI opt_kdb.h NPX_DEBUG opt_npx.h + +NATIVE opt_global.h +XEN opt_global.h From owner-svn-src-projects@FreeBSD.ORG Sat Oct 18 06:32:47 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2A32810656A7; Sat, 18 Oct 2008 06:32:47 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 172188FC12; Sat, 18 Oct 2008 06:32:47 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9I6WkTW009206; Sat, 18 Oct 2008 06:32:46 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9I6WkcS009205; Sat, 18 Oct 2008 06:32:46 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810180632.m9I6WkcS009205@svn.freebsd.org> From: Kip Macy Date: Sat, 18 Oct 2008 06:32:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184021 - projects/releng_6_xen/sys/i386/xen X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Oct 2008 06:32:47 -0000 Author: kmacy Date: Sat Oct 18 06:32:46 2008 New Revision: 184021 URL: http://svn.freebsd.org/changeset/base/184021 Log: Add mp bootstrap Added: projects/releng_6_xen/sys/i386/xen/mp_machdep.c (contents, props changed) Added: projects/releng_6_xen/sys/i386/xen/mp_machdep.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/releng_6_xen/sys/i386/xen/mp_machdep.c Sat Oct 18 06:32:46 2008 (r184021) @@ -0,0 +1,1179 @@ +/*- + * Copyright (c) 1996, by Steve Passe + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the developer may NOT be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include "opt_apic.h" +#include "opt_cpu.h" +#include "opt_kdb.h" +#include "opt_kstack_pages.h" +#include "opt_mp_watchdog.h" +#include "opt_sched.h" + +#if !defined(lint) +#if !defined(SMP) +#error How did you get here? +#endif + +#ifndef DEV_APIC +#error The apic device is required for SMP, add "device apic" to your config file. +#endif +#if defined(CPU_DISABLE_CMPXCHG) && !defined(COMPILING_LINT) +#error SMP not supported with CPU_DISABLE_CMPXCHG +#endif +#endif /* not lint */ + +#include +#include +#include +#include /* cngetc() */ +#ifdef GPROF +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include /** COUNT_XINVLTLB_HITS */ +#include + +#include +#include +#include + +#define WARMBOOT_TARGET 0 +#define WARMBOOT_OFF (KERNBASE + 0x0467) +#define WARMBOOT_SEG (KERNBASE + 0x0469) + +#define CMOS_REG (0x70) +#define CMOS_DATA (0x71) +#define BIOS_RESET (0x0f) +#define BIOS_WARM (0x0a) + +/* + * this code MUST be enabled here and in mpboot.s. + * it follows the very early stages of AP boot by placing values in CMOS ram. + * it NORMALLY will never be needed and thus the primitive method for enabling. + * +#define CHECK_POINTS + */ + +/* lock region used by kernel profiling */ +int mcount_lock; + +/** XXX FIXME: where does this really belong, isa.h/isa.c perhaps? */ +int current_postcode; + +int mp_naps; /* # of Applications processors */ +int boot_cpu_id = -1; /* designated BSP */ +extern int nkpt; + +extern struct pcpu __pcpu[]; + +/* + * CPU topology map datastructures for HTT. + */ +static struct cpu_group mp_groups[MAXCPU]; +static struct cpu_top mp_top; + +/* AP uses this during bootstrap. Do not staticize. */ +char *bootSTK; +static int bootAP; +static union descriptor *bootAPgdt; + +/* Free these after use */ +void *bootstacks[MAXCPU]; + +/* Hotwire a 0->4MB V==P mapping */ +extern pt_entry_t *KPTphys; + +struct pcb stoppcbs[MAXCPU]; + +/* Variables needed for SMP tlb shootdown. */ +vm_offset_t smp_tlb_addr1; +vm_offset_t smp_tlb_addr2; +volatile int smp_tlb_wait; + +#ifdef COUNT_IPIS +/* Interrupt counts. */ +#ifdef IPI_PREEMPTION +static u_long *ipi_preempt_counts[MAXCPU]; +#endif +static u_long *ipi_ast_counts[MAXCPU]; +u_long *ipi_invltlb_counts[MAXCPU]; +u_long *ipi_invlrng_counts[MAXCPU]; +u_long *ipi_invlpg_counts[MAXCPU]; +u_long *ipi_invlcache_counts[MAXCPU]; +u_long *ipi_rendezvous_counts[MAXCPU]; +u_long *ipi_lazypmap_counts[MAXCPU]; +#endif + +/* + * Local data and functions. + */ + +static u_int logical_cpus; + +/* used to hold the AP's until we are ready to release them */ +static struct mtx ap_boot_mtx; + +/* Set to 1 once we're ready to let the APs out of the pen. */ +static volatile int aps_ready = 0; + +/* + * Store data from cpu_add() until later in the boot when we actually setup + * the APs. + */ +struct cpu_info { + int cpu_present:1; + int cpu_bsp:1; + int cpu_disabled:1; +} static cpu_info[MAX_APIC_ID + 1]; +static int cpu_apic_ids[MAXCPU]; + +/* Holds pending bitmap based IPIs per CPU */ +static volatile u_int cpu_ipi_pending[MAXCPU]; + +static u_int boot_address; + +static void assign_cpu_ids(void); +static void set_interrupt_apic_ids(void); +static int start_all_aps(void); +static int start_ap(int apic_id); +static void release_aps(void *dummy); + +static u_int hyperthreading_cpus; +static cpumask_t hyperthreading_cpus_mask; +extern void Xhypervisor_callback(void); +extern void failsafe_callback(void); + +void +mp_topology(void) +{ + struct cpu_group *group; + int logical_cpus; + int apic_id; + int groups; + int cpu; + + /* Build the smp_topology map. */ + /* Nothing to do if there is no HTT support. */ + if ((cpu_feature & CPUID_HTT) == 0) + return; + logical_cpus = (cpu_procinfo & CPUID_HTT_CORES) >> 16; + if (logical_cpus <= 1) + return; + group = &mp_groups[0]; + groups = 1; + for (cpu = 0, apic_id = 0; apic_id <= MAX_APIC_ID; apic_id++) { + if (!cpu_info[apic_id].cpu_present) + continue; + /* + * If the current group has members and we're not a logical + * cpu, create a new group. + */ + if (group->cg_count != 0 && (apic_id % logical_cpus) == 0) { + group++; + groups++; + } + group->cg_count++; + group->cg_mask |= 1 << cpu; + cpu++; + } + + mp_top.ct_count = groups; + mp_top.ct_group = mp_groups; + smp_topology = &mp_top; +} + + +/* + * Calculate usable address in base memory for AP trampoline code. + */ +u_int +mp_bootaddress(u_int basemem) +{ + + return (basemem); +} + +void +cpu_add(u_int apic_id, char boot_cpu) +{ + + if (apic_id > MAX_APIC_ID) { + panic("SMP: APIC ID %d too high", apic_id); + return; + } + KASSERT(cpu_info[apic_id].cpu_present == 0, ("CPU %d added twice", + apic_id)); + cpu_info[apic_id].cpu_present = 1; + if (boot_cpu) { + KASSERT(boot_cpu_id == -1, + ("CPU %d claims to be BSP, but CPU %d already is", apic_id, + boot_cpu_id)); + boot_cpu_id = apic_id; + cpu_info[apic_id].cpu_bsp = 1; + } + if (mp_ncpus < MAXCPU) + mp_ncpus++; + if (bootverbose) + printf("SMP: Added CPU %d (%s)\n", apic_id, boot_cpu ? "BSP" : + "AP"); +} + +void +cpu_mp_setmaxid(void) +{ + + mp_maxid = MAXCPU - 1; +} + +int +cpu_mp_probe(void) +{ + + /* + * Always record BSP in CPU map so that the mbuf init code works + * correctly. + */ + all_cpus = 1; + if (mp_ncpus == 0) { + /* + * No CPUs were found, so this must be a UP system. Setup + * the variables to represent a system with a single CPU + * with an id of 0. + */ + mp_ncpus = 1; + return (0); + } + + /* At least one CPU was found. */ + if (mp_ncpus == 1) { + /* + * One CPU was found, so this must be a UP system with + * an I/O APIC. + */ + return (0); + } + + /* At least two CPUs were found. */ + return (1); +} + +/* + * Initialize the IPI handlers and start up the AP's. + */ +void +cpu_mp_start(void) +{ + int i; + + /* Initialize the logical ID to APIC ID table. */ + for (i = 0; i < MAXCPU; i++) { + cpu_apic_ids[i] = -1; + cpu_ipi_pending[i] = 0; + } + +#if 0 + /* + * IPI list that has to be converted to Xen + * + */ + /* Install an inter-CPU IPI for TLB invalidation */ + setidt(IPI_INVLTLB, IDTVEC(invltlb), + SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL)); + setidt(IPI_INVLPG, IDTVEC(invlpg), + SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL)); + setidt(IPI_INVLRNG, IDTVEC(invlrng), + SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL)); + + /* Install an inter-CPU IPI for cache invalidation. */ + setidt(IPI_INVLCACHE, IDTVEC(invlcache), + SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL)); + + /* Install an inter-CPU IPI for lazy pmap release */ + setidt(IPI_LAZYPMAP, IDTVEC(lazypmap), + SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL)); + + /* Install an inter-CPU IPI for all-CPU rendezvous */ + setidt(IPI_RENDEZVOUS, IDTVEC(rendezvous), + SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL)); + + /* Install generic inter-CPU IPI handler */ + setidt(IPI_BITMAP_VECTOR, IDTVEC(ipi_intr_bitmap_handler), + SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL)); + + /* Install an inter-CPU IPI for CPU stop/restart */ + setidt(IPI_STOP, IDTVEC(cpustop), + SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL)); +#endif + + /* Set boot_cpu_id if needed. */ + if (boot_cpu_id == -1) { + boot_cpu_id = PCPU_GET(apic_id); + cpu_info[boot_cpu_id].cpu_bsp = 1; + } else + KASSERT(boot_cpu_id == PCPU_GET(apic_id), + ("BSP's APIC ID doesn't match boot_cpu_id")); + cpu_apic_ids[0] = boot_cpu_id; + + assign_cpu_ids(); + + /* Start each Application Processor */ + start_all_aps(); + + /* Setup the initial logical CPUs info. */ + logical_cpus = logical_cpus_mask = 0; + if (cpu_feature & CPUID_HTT) + logical_cpus = (cpu_procinfo & CPUID_HTT_CORES) >> 16; + + set_interrupt_apic_ids(); +} + +/* + * Print various information about the SMP system hardware and setup. + */ +void +cpu_mp_announce(void) +{ + int i, x; + + /* List CPUs */ + printf(" cpu0 (BSP): APIC ID: %2d\n", boot_cpu_id); + for (i = 1, x = 0; x <= MAX_APIC_ID; x++) { + if (!cpu_info[x].cpu_present || cpu_info[x].cpu_bsp) + continue; + if (cpu_info[x].cpu_disabled) + printf(" cpu (AP): APIC ID: %2d (disabled)\n", x); + else { + KASSERT(i < mp_ncpus, + ("mp_ncpus and actual cpus are out of whack")); + printf(" cpu%d (AP): APIC ID: %2d\n", i++, x); + } + } +} + +#define MTOPSIZE (1<<(14 + PAGE_SHIFT)) +/* + * AP CPU's call this to initialize themselves. + */ +void +init_secondary(void) +{ + vm_offset_t addr; + int gsel_tss; + + /* bootAP is set in start_ap() to our ID. */ + PCPU_SET(currentldt, _default_ldt); + + gsel_tss = GSEL(GPROC0_SEL, SEL_KPL); +#if 0 + gdt[myid * NGDT + GPROC0_SEL].sd.sd_type = SDT_SYS386TSS; +#endif + PCPU_SET(common_tss.tss_esp0, 0); /* not used until after switch */ + PCPU_SET(common_tss.tss_ss0, GSEL(GDATA_SEL, SEL_KPL)); + PCPU_SET(common_tss.tss_ioopt, (sizeof (struct i386tss)) << 16); +#if 0 + PCPU_SET(tss_gdt, &gdt[myid * NGDT + GPROC0_SEL].sd); + PCPU_SET(common_tssd, *PCPU_GET(tss_gdt)); + ltr(gsel_tss); +#endif + PCPU_SET(fsgs_gdt, &gdt[GUFS_SEL].sd); + + /* signal our startup to the BSP. */ + mp_naps++; + + /* Spin until the BSP releases the AP's. */ + while (!aps_ready) + ia32_pause(); + + /* BSP may have changed PTD while we were waiting */ + invltlb(); + for (addr = 0; addr < NKPT * NBPDR - 1; addr += PAGE_SIZE) + invlpg(addr); + + /* set up FPU state on the AP */ + npxinit(__INITIAL_NPXCW__); + +#if 0 + /* set up SSE registers */ + enable_sse(); + + /* A quick check from sanity claus */ + if (PCPU_GET(apic_id) != lapic_id()) { + printf("SMP: cpuid = %d\n", PCPU_GET(cpuid)); + printf("SMP: actual apic_id = %d\n", lapic_id()); + printf("SMP: correct apic_id = %d\n", PCPU_GET(apic_id)); + panic("cpuid mismatch! boom!!"); + } +#endif + /* Initialize curthread. */ + KASSERT(PCPU_GET(idlethread) != NULL, ("no idle thread")); + PCPU_SET(curthread, PCPU_GET(idlethread)); + + mtx_lock_spin(&ap_boot_mtx); +#if 0 + /* Init local apic for irq's */ + lapic_setup(1); + + /* Set memory range attributes for this CPU to match the BSP */ + mem_range_AP_init(); +#endif + smp_cpus++; + + CTR1(KTR_SMP, "SMP: AP CPU #%d Launched", PCPU_GET(cpuid)); + printf("SMP: AP CPU #%d Launched!\n", PCPU_GET(cpuid)); + + /* Determine if we are a logical CPU. */ + if (logical_cpus > 1 && PCPU_GET(apic_id) % logical_cpus != 0) + logical_cpus_mask |= PCPU_GET(cpumask); + + /* Determine if we are a hyperthread. */ + if (hyperthreading_cpus > 1 && + PCPU_GET(apic_id) % hyperthreading_cpus != 0) + hyperthreading_cpus_mask |= PCPU_GET(cpumask); + + /* Build our map of 'other' CPUs. */ + PCPU_SET(other_cpus, all_cpus & ~PCPU_GET(cpumask)); +#if 0 + if (bootverbose) + lapic_dump("AP"); +#endif + if (smp_cpus == mp_ncpus) { + /* enable IPI's, tlb shootdown, freezes etc */ + atomic_store_rel_int(&smp_started, 1); + smp_active = 1; /* historic */ + } + + mtx_unlock_spin(&ap_boot_mtx); + + /* wait until all the AP's are up */ + while (smp_started == 0) + ia32_pause(); + + /* ok, now grab sched_lock and enter the scheduler */ + mtx_lock_spin(&sched_lock); + + /* + * Correct spinlock nesting. The idle thread context that we are + * borrowing was created so that it would start out with a single + * spin lock (sched_lock) held in fork_trampoline(). Since we've + * explicitly acquired locks in this function, the nesting count + * is now 2 rather than 1. Since we are nested, calling + * spinlock_exit() will simply adjust the counts without allowing + * spin lock using code to interrupt us. + */ + spinlock_exit(); + KASSERT(curthread->td_md.md_spinlock_count == 1, ("invalid count")); + + binuptime(PCPU_PTR(switchtime)); + PCPU_SET(switchticks, ticks); + + cpu_throw(NULL, choosethread()); /* doesn't return */ + + panic("scheduler returned us to %s", __func__); + /* NOTREACHED */ +} + +/******************************************************************* + * local functions and data + */ + +/* + * We tell the I/O APIC code about all the CPUs we want to receive + * interrupts. If we don't want certain CPUs to receive IRQs we + * can simply not tell the I/O APIC code about them in this function. + * We also do not tell it about the BSP since it tells itself about + * the BSP internally to work with UP kernels and on UP machines. + */ +static void +set_interrupt_apic_ids(void) +{ + u_int apic_id; + + for (apic_id = 0; apic_id < MAXCPU; apic_id++) { + if (!cpu_info[apic_id].cpu_present) + continue; + if (cpu_info[apic_id].cpu_bsp) + continue; + if (cpu_info[apic_id].cpu_disabled) + continue; + + /* Don't let hyperthreads service interrupts. */ + if (hyperthreading_cpus > 1 && + apic_id % hyperthreading_cpus != 0) + continue; + + intr_add_cpu(apic_id); + } +} + +/* + * Assign logical CPU IDs to local APICs. + */ +static void +assign_cpu_ids(void) +{ + u_int i; + + /* Check for explicitly disabled CPUs. */ + for (i = 0; i <= MAX_APIC_ID; i++) { + if (!cpu_info[i].cpu_present || cpu_info[i].cpu_bsp) + continue; + + /* Don't use this CPU if it has been disabled by a tunable. */ + if (resource_disabled("lapic", i)) { + cpu_info[i].cpu_disabled = 1; + continue; + } + } + + /* + * Assign CPU IDs to local APIC IDs and disable any CPUs + * beyond MAXCPU. CPU 0 has already been assigned to the BSP, + * so we only have to assign IDs for APs. + */ + mp_ncpus = 1; + for (i = 0; i <= MAX_APIC_ID; i++) { + if (!cpu_info[i].cpu_present || cpu_info[i].cpu_bsp || + cpu_info[i].cpu_disabled) + continue; + + if (mp_ncpus < MAXCPU) { + cpu_apic_ids[mp_ncpus] = i; + mp_ncpus++; + } else + cpu_info[i].cpu_disabled = 1; + } + KASSERT(mp_maxid >= mp_ncpus - 1, + ("%s: counters out of sync: max %d, count %d", __func__, mp_maxid, + mp_ncpus)); +} + +/* + * start each AP in our list + */ +static int +start_all_aps(void) +{ + int apic_id, cpu, i; + struct pcpu *pc; + + mtx_init(&ap_boot_mtx, "ap boot", NULL, MTX_SPIN); + + /* start each AP */ + for (cpu = 1; cpu < mp_ncpus; cpu++) { + apic_id = cpu_apic_ids[cpu]; + + bootstacks[cpu] = (char *)kmem_alloc(kernel_map, KSTACK_PAGES * PAGE_SIZE); + + /* setup a vector to our boot code */ + *((volatile u_short *) WARMBOOT_OFF) = WARMBOOT_TARGET; + *((volatile u_short *) WARMBOOT_SEG) = (boot_address >> 4); + + bootSTK = (char *)bootstacks[cpu] + KSTACK_PAGES * PAGE_SIZE - 4; + bootAP = cpu; + bootAPgdt = gdt + (512*cpu); + + /* Get per-cpu data */ + pc = &__pcpu[bootAP]; + pcpu_init(pc, bootAP, sizeof(struct pcpu)); + pc->pc_apic_id = cpu_apic_ids[bootAP]; + pc->pc_prvspace = pc; + pc->pc_curthread = 0; + + gdt_segs[GPRIV_SEL].ssd_base = (int) pc; + gdt_segs[GPROC0_SEL].ssd_base = (int) &pc->pc_common_tss; + + PT_SET_MA(bootAPgdt, xpmap_ptom(VTOP(bootAPgdt)) | PG_V | PG_RW); + bzero(bootAPgdt, PAGE_SIZE); + for (i = 0; i < NGDT; i++) + ssdtosd(&gdt_segs[i], &bootAPgdt[i].sd); + PT_SET_MA(bootAPgdt, vtomach(bootAPgdt) | PG_V); +#ifdef notyet + + if (HYPERVISOR_vcpu_op(VCPUOP_get_physid, cpu, &cpu_id) == 0) { + apicid = xen_vcpu_physid_to_x86_apicid(cpu_id.phys_id); + acpiid = xen_vcpu_physid_to_x86_acpiid(cpu_id.phys_id); +#ifdef CONFIG_ACPI + if (acpiid != 0xff) + x86_acpiid_to_apicid[acpiid] = apicid; +#endif + } +#endif + + /* attempt to start the Application Processor */ + if (!start_ap(apic_id)) { + printf("AP #%d (PHY# %d) failed!\n", cpu, apic_id); + /* better panic as the AP may be running loose */ + printf("panic y/n? [y] "); + if (cngetc() != 'n') + panic("bye-bye"); + } + + all_cpus |= (1 << cpu); /* record AP in CPU map */ + } + + /* build our map of 'other' CPUs */ + PCPU_SET(other_cpus, all_cpus & ~PCPU_GET(cpumask)); + + pmap_invalidate_range(kernel_pmap, 0, NKPT * NBPDR - 1); + + /* number of APs actually started */ + return mp_naps; +} + +extern uint8_t *pcpu_boot_stack; +extern trap_info_t trap_table[]; + +static void +smp_trap_init(trap_info_t *trap_ctxt) +{ + const 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; + } +} + +void cpu_initialize_context(unsigned int cpu); + +void +cpu_initialize_context(unsigned int cpu) +{ + /* vcpu_guest_context_t is too large to allocate on the stack. + * Hence we allocate statically and protect it with a lock */ + vm_page_t m[4]; + static vcpu_guest_context_t ctxt; + vm_offset_t boot_stack; + vm_offset_t newPTD; + vm_paddr_t ma[NPGPTD]; + static int color; + int i; + + /* + * Page 0,[0-3] PTD + * Page 1, [4] boot stack + * Page [5] PDPT + + * + */ + for (i = 0; i < NPGPTD + 2; i++) { + m[i] = vm_page_alloc(NULL, color++, + VM_ALLOC_NORMAL | VM_ALLOC_NOOBJ | VM_ALLOC_WIRED | + VM_ALLOC_ZERO); + + pmap_zero_page(m[i]); + + } + boot_stack = kmem_alloc_nofault(kernel_map, 1); + newPTD = kmem_alloc_nofault(kernel_map, NPGPTD); + ma[0] = xpmap_ptom(VM_PAGE_TO_PHYS(m[0]))|PG_V; + +#ifdef PAE + pmap_kenter(boot_stack, VM_PAGE_TO_PHYS(m[NPGPTD + 1])); + for (i = 0; i < NPGPTD; i++) { + ((vm_paddr_t *)boot_stack)[i] = + ma[i] = + xpmap_ptom(VM_PAGE_TO_PHYS(m[i]))|PG_V; + } +#endif + + /* + * Copy cpu0 IdlePTD to new IdlePTD - copying only + * kernel mappings + */ + pmap_qenter(newPTD, m, 4); + + memcpy((uint8_t *)newPTD + KPTDI*sizeof(vm_paddr_t), + (uint8_t *)PTOV(IdlePTD) + KPTDI*sizeof(vm_paddr_t), + nkpt*sizeof(vm_paddr_t)); + + pmap_qremove(newPTD, 4); + kmem_free(kernel_map, newPTD, 4); + /* + * map actual idle stack to boot_stack + */ + pmap_kenter(boot_stack, VM_PAGE_TO_PHYS(m[NPGPTD])); + + + xen_pgdpt_pin(xpmap_ptom(VM_PAGE_TO_PHYS(m[NPGPTD + 1]))); + vm_page_lock_queues(); + for (i = 0; i < 4; i++) { + int pdir = (PTDPTDI + i) / NPDEPG; + int curoffset = (PTDPTDI + i) % NPDEPG; + + xen_queue_pt_update((vm_paddr_t) + ((ma[pdir] & ~PG_V) + (curoffset*sizeof(vm_paddr_t))), + ma[i]); + } + PT_UPDATES_FLUSH(); + vm_page_unlock_queues(); + + memset(&ctxt, 0, sizeof(ctxt)); + ctxt.flags = VGCF_IN_KERNEL; + ctxt.user_regs.ds = GSEL(GDATA_SEL, SEL_KPL); + ctxt.user_regs.es = GSEL(GDATA_SEL, SEL_KPL); + ctxt.user_regs.fs = GSEL(GPRIV_SEL, SEL_KPL); + ctxt.user_regs.gs = GSEL(GDATA_SEL, SEL_KPL); + ctxt.user_regs.cs = GSEL(GCODE_SEL, SEL_KPL); + ctxt.user_regs.ss = GSEL(GDATA_SEL, SEL_KPL); + ctxt.user_regs.eip = (unsigned long)init_secondary; + ctxt.user_regs.eflags = PSL_KERNEL | 0x1000; /* IOPL_RING1 */ + + memset(&ctxt.fpu_ctxt, 0, sizeof(ctxt.fpu_ctxt)); + + smp_trap_init(ctxt.trap_ctxt); + + ctxt.ldt_ents = 0; + ctxt.gdt_frames[0] = (uint32_t)((uint64_t)vtomach(bootAPgdt) >> PAGE_SHIFT); + ctxt.gdt_ents = 512; + +#ifdef __i386__ + ctxt.user_regs.esp = boot_stack + PAGE_SIZE; + + ctxt.kernel_ss = GSEL(GDATA_SEL, SEL_KPL); + ctxt.kernel_sp = boot_stack + PAGE_SIZE; + + ctxt.event_callback_cs = GSEL(GCODE_SEL, SEL_KPL); + ctxt.event_callback_eip = (unsigned long)Xhypervisor_callback; + ctxt.failsafe_callback_cs = GSEL(GCODE_SEL, SEL_KPL); + ctxt.failsafe_callback_eip = (unsigned long)failsafe_callback; + + ctxt.ctrlreg[3] = xpmap_ptom(VM_PAGE_TO_PHYS(m[NPGPTD + 1])); +#else /* __x86_64__ */ + ctxt.user_regs.esp = idle->thread.rsp0 - sizeof(struct pt_regs); + ctxt.kernel_ss = GSEL(GDATA_SEL, SEL_KPL); + ctxt.kernel_sp = idle->thread.rsp0; + + ctxt.event_callback_eip = (unsigned long)hypervisor_callback; + ctxt.failsafe_callback_eip = (unsigned long)failsafe_callback; + ctxt.syscall_callback_eip = (unsigned long)system_call; + + ctxt.ctrlreg[3] = xen_pfn_to_cr3(virt_to_mfn(init_level4_pgt)); + + ctxt.gs_base_kernel = (unsigned long)(cpu_pda(cpu)); +#endif + + printf("gdtpfn=%lx pdptpfn=%lx\n", + ctxt.gdt_frames[0], + ctxt.ctrlreg[3] >> PAGE_SHIFT); + + PANIC_IF(HYPERVISOR_vcpu_op(VCPUOP_initialise, cpu, &ctxt)); + DELAY(3000); + PANIC_IF(HYPERVISOR_vcpu_op(VCPUOP_up, cpu, NULL)); +} + +/* + * This function starts the AP (application processor) identified + * by the APIC ID 'physicalCpu'. It does quite a "song and dance" + * to accomplish this. This is necessary because of the nuances + * of the different hardware we might encounter. It isn't pretty, + * but it seems to work. + */ +static int +start_ap(int apic_id) +{ + int cpus, ms; + + /* used as a watchpoint to signal AP startup */ + cpus = mp_naps; + + cpu_initialize_context(apic_id); + + /* Wait up to 5 seconds for it to start. */ + for (ms = 0; ms < 5000; ms++) { + if (mp_naps > cpus) + return 1; /* return SUCCESS */ + DELAY(1000); + } + return 0; /* return FAILURE */ +} + +#ifdef COUNT_XINVLTLB_HITS +u_int xhits_gbl[MAXCPU]; +u_int xhits_pg[MAXCPU]; +u_int xhits_rng[MAXCPU]; +SYSCTL_NODE(_debug, OID_AUTO, xhits, CTLFLAG_RW, 0, ""); +SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, global, CTLFLAG_RW, &xhits_gbl, + sizeof(xhits_gbl), "IU", ""); +SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, page, CTLFLAG_RW, &xhits_pg, + sizeof(xhits_pg), "IU", ""); +SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, range, CTLFLAG_RW, &xhits_rng, + sizeof(xhits_rng), "IU", ""); + +u_int ipi_global; +u_int ipi_page; +u_int ipi_range; +u_int ipi_range_size; +SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_global, CTLFLAG_RW, &ipi_global, 0, ""); +SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_page, CTLFLAG_RW, &ipi_page, 0, ""); +SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_range, CTLFLAG_RW, &ipi_range, 0, ""); +SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_range_size, CTLFLAG_RW, &ipi_range_size, + 0, ""); + +u_int ipi_masked_global; +u_int ipi_masked_page; +u_int ipi_masked_range; +u_int ipi_masked_range_size; +SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_global, CTLFLAG_RW, + &ipi_masked_global, 0, ""); +SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_page, CTLFLAG_RW, + &ipi_masked_page, 0, ""); +SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_range, CTLFLAG_RW, + &ipi_masked_range, 0, ""); +SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_range_size, CTLFLAG_RW, + &ipi_masked_range_size, 0, ""); +#endif /* COUNT_XINVLTLB_HITS */ + +/* + * Flush the TLB on all other CPU's + */ +static void +smp_tlb_shootdown(u_int vector, vm_offset_t addr1, vm_offset_t addr2) +{ + u_int ncpu; + + ncpu = mp_ncpus - 1; /* does not shootdown self */ + if (ncpu < 1) + return; /* no other cpus */ + if (!(read_eflags() & PSL_I)) + panic("%s: interrupts disabled", __func__); + mtx_lock_spin(&smp_ipi_mtx); + smp_tlb_addr1 = addr1; + smp_tlb_addr2 = addr2; + atomic_store_rel_int(&smp_tlb_wait, 0); + ipi_all_but_self(vector); + while (smp_tlb_wait < ncpu) + ia32_pause(); + mtx_unlock_spin(&smp_ipi_mtx); +} + +static void +smp_targeted_tlb_shootdown(u_int mask, u_int vector, vm_offset_t addr1, vm_offset_t addr2) +{ + int ncpu, othercpus; + + othercpus = mp_ncpus - 1; + if (mask == (u_int)-1) { + ncpu = othercpus; + if (ncpu < 1) + return; + } else { + mask &= ~PCPU_GET(cpumask); + if (mask == 0) + return; + ncpu = bitcount32(mask); + if (ncpu > othercpus) { + /* XXX this should be a panic offence */ + printf("SMP: tlb shootdown to %d other cpus (only have %d)\n", + ncpu, othercpus); + ncpu = othercpus; + } + /* XXX should be a panic, implied by mask == 0 above */ + if (ncpu < 1) + return; + } + if (!(read_eflags() & PSL_I)) + panic("%s: interrupts disabled", __func__); + mtx_lock_spin(&smp_ipi_mtx); + smp_tlb_addr1 = addr1; + smp_tlb_addr2 = addr2; + atomic_store_rel_int(&smp_tlb_wait, 0); + if (mask == (u_int)-1) + ipi_all_but_self(vector); + else + ipi_selected(mask, vector); + while (smp_tlb_wait < ncpu) + ia32_pause(); + mtx_unlock_spin(&smp_ipi_mtx); +} + +void +smp_cache_flush(void) +{ + + if (smp_started) + smp_tlb_shootdown(IPI_INVLCACHE, 0, 0); +} + +void +smp_invltlb(void) +{ + + if (smp_started) { + smp_tlb_shootdown(IPI_INVLTLB, 0, 0); +#ifdef COUNT_XINVLTLB_HITS + ipi_global++; +#endif + } +} + +void +smp_invlpg(vm_offset_t addr) +{ + + if (smp_started) { + smp_tlb_shootdown(IPI_INVLPG, addr, 0); +#ifdef COUNT_XINVLTLB_HITS + ipi_page++; +#endif + } +} + +void +smp_invlpg_range(vm_offset_t addr1, vm_offset_t addr2) +{ + + if (smp_started) { + smp_tlb_shootdown(IPI_INVLRNG, addr1, addr2); +#ifdef COUNT_XINVLTLB_HITS + ipi_range++; + ipi_range_size += (addr2 - addr1) / PAGE_SIZE; +#endif + } +} + +void +smp_masked_invltlb(u_int mask) +{ + + if (smp_started) { + smp_targeted_tlb_shootdown(mask, IPI_INVLTLB, 0, 0); +#ifdef COUNT_XINVLTLB_HITS + ipi_masked_global++; +#endif + } +} + +void *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-projects@FreeBSD.ORG Sat Oct 18 06:37:19 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D6A811065699; Sat, 18 Oct 2008 06:37:19 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id AB8598FC12; Sat, 18 Oct 2008 06:37:19 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9I6bJZf009331; Sat, 18 Oct 2008 06:37:19 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9I6bJje009330; Sat, 18 Oct 2008 06:37:19 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810180637.m9I6bJje009330@svn.freebsd.org> From: Kip Macy Date: Sat, 18 Oct 2008 06:37:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184022 - projects/release_6_3_xen/sys/i386/xen X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Oct 2008 06:37:19 -0000 Author: kmacy Date: Sat Oct 18 06:37:19 2008 New Revision: 184022 URL: http://svn.freebsd.org/changeset/base/184022 Log: copy i386/xen Added: projects/release_6_3_xen/sys/i386/xen/ (props changed) - copied from r184021, projects/releng_6_xen/sys/i386/xen/ From owner-svn-src-projects@FreeBSD.ORG Sat Oct 18 06:37:43 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E2FD4106568A; Sat, 18 Oct 2008 06:37:43 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B82E58FC1A; Sat, 18 Oct 2008 06:37:43 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9I6bh9M009375; Sat, 18 Oct 2008 06:37:43 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9I6bhjl009374; Sat, 18 Oct 2008 06:37:43 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810180637.m9I6bhjl009374@svn.freebsd.org> From: Kip Macy Date: Sat, 18 Oct 2008 06:37:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184023 - projects/release_6_3_xen/sys/i386/include/xen X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Oct 2008 06:37:44 -0000 Author: kmacy Date: Sat Oct 18 06:37:43 2008 New Revision: 184023 URL: http://svn.freebsd.org/changeset/base/184023 Log: copy i386/include/xen Added: projects/release_6_3_xen/sys/i386/include/xen/ (props changed) - copied from r184022, projects/releng_6_xen/sys/i386/include/xen/ From owner-svn-src-projects@FreeBSD.ORG Sat Oct 18 06:56:08 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4323D1065692; Sat, 18 Oct 2008 06:56:08 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2EC5C8FC08; Sat, 18 Oct 2008 06:56:08 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9I6u8sA009750; Sat, 18 Oct 2008 06:56:08 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9I6u7M9009740; Sat, 18 Oct 2008 06:56:07 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810180656.m9I6u7M9009740@svn.freebsd.org> From: Kip Macy Date: Sat, 18 Oct 2008 06:56:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184024 - in projects/release_6_3_xen/sys: conf i386/i386 i386/xen libkern sys xen xen/evtchn xen/xenbus X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Oct 2008 06:56:08 -0000 Author: kmacy Date: Sat Oct 18 06:56:07 2008 New Revision: 184024 URL: http://svn.freebsd.org/changeset/base/184024 Log: - Merge fixes to sys/xen - change pcpu usage back to 6.3 - import strcspn support Added: projects/release_6_3_xen/sys/libkern/strcspn.c Modified: projects/release_6_3_xen/sys/conf/files projects/release_6_3_xen/sys/i386/i386/machdep.c projects/release_6_3_xen/sys/i386/xen/locore.s projects/release_6_3_xen/sys/i386/xen/mp_machdep.c projects/release_6_3_xen/sys/sys/libkern.h projects/release_6_3_xen/sys/xen/evtchn/evtchn.c projects/release_6_3_xen/sys/xen/gnttab.c projects/release_6_3_xen/sys/xen/gnttab.h projects/release_6_3_xen/sys/xen/xenbus/xenbus_xs.c Modified: projects/release_6_3_xen/sys/conf/files ============================================================================== --- projects/release_6_3_xen/sys/conf/files Sat Oct 18 06:37:43 2008 (r184023) +++ projects/release_6_3_xen/sys/conf/files Sat Oct 18 06:56:07 2008 (r184024) @@ -1463,6 +1463,7 @@ libkern/strcasecmp.c standard libkern/strcat.c standard libkern/strcmp.c standard libkern/strcpy.c standard +libkern/strcspn.c standard libkern/strdup.c standard libkern/strlcat.c standard libkern/strlcpy.c standard Modified: projects/release_6_3_xen/sys/i386/i386/machdep.c ============================================================================== --- projects/release_6_3_xen/sys/i386/i386/machdep.c Sat Oct 18 06:37:43 2008 (r184023) +++ projects/release_6_3_xen/sys/i386/i386/machdep.c Sat Oct 18 06:56:07 2008 (r184024) @@ -2205,7 +2205,11 @@ init386(int first) gdt_segs[GUDATA_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE); gdt_segs[GBIOSLOWMEM_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE); - pc = &__pcpu[0]; +#ifdef SMP + pc = &SMP_prvspace[0].pcpu; +#else + pc = &__pcpu; +#endif gdt_segs[GPRIV_SEL].ssd_base = (int) pc; gdt_segs[GPROC0_SEL].ssd_base = (int) &pc->pc_common_tss; Modified: projects/release_6_3_xen/sys/i386/xen/locore.s ============================================================================== --- projects/release_6_3_xen/sys/i386/xen/locore.s Sat Oct 18 06:37:43 2008 (r184023) +++ projects/release_6_3_xen/sys/i386/xen/locore.s Sat Oct 18 06:56:07 2008 (r184024) @@ -110,7 +110,16 @@ .set PTmap,(PTDPTDI << PDRSHIFT) .set PTD,PTmap + (PTDPTDI * PAGE_SIZE) .set PTDpde,PTD + (PTDPTDI * PDESIZE) - +#ifdef SMP +/* + * Define layout of per-cpu address space. + * This is "constructed" in locore.s on the BSP and in mp_machdep.c + * for each AP. DO NOT REORDER THESE WITHOUT UPDATING THE REST! + */ + .globl SMP_prvspace + .set SMP_prvspace,(MPPTDI << PDRSHIFT) +#endif /* SMP */ + /* * Compiled KERNBASE location and the kernel load address */ Modified: projects/release_6_3_xen/sys/i386/xen/mp_machdep.c ============================================================================== --- projects/release_6_3_xen/sys/i386/xen/mp_machdep.c Sat Oct 18 06:37:43 2008 (r184023) +++ projects/release_6_3_xen/sys/i386/xen/mp_machdep.c Sat Oct 18 06:56:07 2008 (r184024) @@ -81,6 +81,7 @@ __FBSDID("$FreeBSD$"); #include #include /** COUNT_XINVLTLB_HITS */ #include +#include #include #include @@ -622,7 +623,7 @@ start_all_aps(void) bootAPgdt = gdt + (512*cpu); /* Get per-cpu data */ - pc = &__pcpu[bootAP]; + pc = &SMP_prvspace[bootAP].pcpu; pcpu_init(pc, bootAP, sizeof(struct pcpu)); pc->pc_apic_id = cpu_apic_ids[bootAP]; pc->pc_prvspace = pc; Added: projects/release_6_3_xen/sys/libkern/strcspn.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/release_6_3_xen/sys/libkern/strcspn.c Sat Oct 18 06:56:07 2008 (r184024) @@ -0,0 +1,72 @@ +/*- + * Copyright (c) 2005 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +#define IDX(c) ((u_char)(c) / LONG_BIT) +#define BIT(c) ((u_long)1 << ((u_char)(c) % LONG_BIT)) + +size_t +strcspn(const char *s, const char *charset) +{ + /* + * NB: idx and bit are temporaries whose use causes gcc 3.4.2 to + * generate better code. Without them, gcc gets a little confused. + */ + const char *s1; + u_long bit; + u_long tbl[(UCHAR_MAX + 1) / LONG_BIT]; + int idx; + + if(*s == '\0') + return (0); + +#if LONG_BIT == 64 /* always better to unroll on 64-bit architectures */ + tbl[0] = 1; + tbl[3] = tbl[2] = tbl[1] = 0; +#else + for (tbl[0] = idx = 1; idx < sizeof(tbl) / sizeof(tbl[0]); idx++) + tbl[idx] = 0; +#endif + for (; *charset != '\0'; charset++) { + idx = IDX(*charset); + bit = BIT(*charset); + tbl[idx] |= bit; + } + + for(s1 = s; ; s1++) { + idx = IDX(*s1); + bit = BIT(*s1); + if ((tbl[idx] & bit) != 0) + break; + } + return (s1 - s); +} Modified: projects/release_6_3_xen/sys/sys/libkern.h ============================================================================== --- projects/release_6_3_xen/sys/sys/libkern.h Sat Oct 18 06:37:43 2008 (r184023) +++ projects/release_6_3_xen/sys/sys/libkern.h Sat Oct 18 06:56:07 2008 (r184024) @@ -98,6 +98,7 @@ void srandom(u_long); int strcasecmp(const char *, const char *); char *strcat(char * __restrict, const char * __restrict); int strcmp(const char *, const char *); +size_t strcspn(const char *s, const char *charset); char *strcpy(char * __restrict, const char * __restrict); char *strdup(const char *__restrict, struct malloc_type *); size_t strlcat(char *, const char *, size_t); @@ -151,6 +152,18 @@ memset(void *b, int c, size_t len) return (b); } +static __inline char * +strchr(const char *p, int ch) +{ + return (index(p, ch)); +} + +static __inline char * +strrchr(const char *p, int ch) +{ + return (rindex(p, ch)); +} + /* fnmatch() return values. */ #define FNM_NOMATCH 1 /* Match failed. */ Modified: projects/release_6_3_xen/sys/xen/evtchn/evtchn.c ============================================================================== --- projects/release_6_3_xen/sys/xen/evtchn/evtchn.c Sat Oct 18 06:37:43 2008 (r184023) +++ projects/release_6_3_xen/sys/xen/evtchn/evtchn.c Sat Oct 18 06:56:07 2008 (r184024) @@ -21,7 +21,9 @@ __FBSDID("$FreeBSD$"); #include #include + #include +#include #include #include #include @@ -178,7 +180,7 @@ void force_evtchn_callback(void) } void -evtchn_do_upcall(struct trapframe *frame) +evtchn_do_upcall(struct intrframe *frame) { unsigned long l1, l2; unsigned int l1i, l2i, port; @@ -434,7 +436,7 @@ bind_caller_port_to_irqhandler(unsigned irq = bind_caller_port_to_irq(caller_port); intr_register_source(&xp->xp_pins[irq].xp_intsrc); - retval = intr_add_handler(devname, irq, NULL, handler, arg, irqflags, cookiep); + retval = intr_add_handler(devname, irq, handler, arg, irqflags, cookiep); if (retval != 0) { unbind_from_irq(irq); return -retval; @@ -457,7 +459,7 @@ bind_listening_port_to_irqhandler( irq = bind_listening_port_to_irq(remote_domain); intr_register_source(&xp->xp_pins[irq].xp_intsrc); - retval = intr_add_handler(devname, irq, NULL, handler, arg, irqflags, cookiep); + retval = intr_add_handler(devname, irq, handler, arg, irqflags, cookiep); if (retval != 0) { unbind_from_irq(irq); return -retval; @@ -471,7 +473,6 @@ bind_interdomain_evtchn_to_irqhandler( unsigned int remote_domain, unsigned int remote_port, const char *devname, - driver_filter_t filter, driver_intr_t handler, unsigned long irqflags) { @@ -480,7 +481,7 @@ bind_interdomain_evtchn_to_irqhandler( irq = bind_interdomain_evtchn_to_irq(remote_domain, remote_port); intr_register_source(&xp->xp_pins[irq].xp_intsrc); - retval = intr_add_handler(devname, irq, filter, handler, NULL, irqflags, NULL); + retval = intr_add_handler(devname, irq, handler, NULL, irqflags, NULL); if (retval != 0) { unbind_from_irq(irq); return -retval; @@ -493,7 +494,6 @@ int bind_virq_to_irqhandler(unsigned int virq, unsigned int cpu, const char *devname, - driver_filter_t filter, driver_intr_t handler, unsigned long irqflags) { @@ -502,7 +502,7 @@ bind_virq_to_irqhandler(unsigned int vir irq = bind_virq_to_irq(virq, cpu); intr_register_source(&xp->xp_pins[irq].xp_intsrc); - retval = intr_add_handler(devname, irq, filter, handler, NULL, irqflags, NULL); + retval = intr_add_handler(devname, irq, handler, NULL, irqflags, NULL); if (retval != 0) { unbind_from_irq(irq); return -retval; @@ -523,7 +523,7 @@ bind_ipi_to_irqhandler(unsigned int ipi, irq = bind_ipi_to_irq(ipi, cpu); intr_register_source(&xp->xp_pins[irq].xp_intsrc); - retval = intr_add_handler(devname, irq, NULL, handler, NULL, irqflags, NULL); + retval = intr_add_handler(devname, irq, handler, NULL, irqflags, NULL); if (retval != 0) { unbind_from_irq(irq); return -retval; @@ -592,13 +592,11 @@ static void xenpic_dynirq_enable_sou static void xenpic_dynirq_disable_source(struct intsrc *isrc, int); static void xenpic_dynirq_eoi_source(struct intsrc *isrc); static void xenpic_dynirq_enable_intr(struct intsrc *isrc); -static void xenpic_dynirq_disable_intr(struct intsrc *isrc); static void xenpic_pirq_enable_source(struct intsrc *isrc); static void xenpic_pirq_disable_source(struct intsrc *isrc, int); static void xenpic_pirq_eoi_source(struct intsrc *isrc); static void xenpic_pirq_enable_intr(struct intsrc *isrc); -static void xenpic_pirq_disable_intr(struct intsrc *isrc); static int xenpic_vector(struct intsrc *isrc); @@ -613,7 +611,6 @@ struct pic xenpic_dynirq_template = { .pic_disable_source = xenpic_dynirq_disable_source, .pic_eoi_source = xenpic_dynirq_eoi_source, .pic_enable_intr = xenpic_dynirq_enable_intr, - .pic_disable_intr = xenpic_dynirq_disable_intr, .pic_vector = xenpic_vector, .pic_source_pending = xenpic_source_pending, .pic_suspend = xenpic_suspend, @@ -625,7 +622,6 @@ struct pic xenpic_pirq_template = { .pic_disable_source = xenpic_pirq_disable_source, .pic_eoi_source = xenpic_pirq_eoi_source, .pic_enable_intr = xenpic_pirq_enable_intr, - .pic_disable_intr = xenpic_pirq_disable_intr, .pic_vector = xenpic_vector, .pic_source_pending = xenpic_source_pending, .pic_suspend = xenpic_suspend, @@ -684,20 +680,6 @@ xenpic_dynirq_enable_intr(struct intsrc } static void -xenpic_dynirq_disable_intr(struct intsrc *isrc) -{ - unsigned int irq; - struct xenpic_intsrc *xp; - - xp = (struct xenpic_intsrc *)isrc; - mtx_lock_spin(&irq_mapping_update_lock); - xp->xp_masked = 1; - irq = xenpic_vector(isrc); - mask_evtchn(evtchn_from_irq(irq)); - mtx_unlock_spin(&irq_mapping_update_lock); -} - -static void xenpic_dynirq_eoi_source(struct intsrc *isrc) { unsigned int irq; @@ -830,32 +812,6 @@ xenpic_pirq_enable_intr(struct intsrc *i } static void -xenpic_pirq_disable_intr(struct intsrc *isrc) -{ - unsigned int irq; - int evtchn; - struct evtchn_close close; - - mtx_lock_spin(&irq_mapping_update_lock); - irq = xenpic_vector(isrc); - evtchn = evtchn_from_irq(irq); - - if (!VALID_EVTCHN(evtchn)) - goto done; - - mask_evtchn(evtchn); - - close.port = evtchn; - PANIC_IF(HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0); - - bind_evtchn_to_cpu(evtchn, 0); - evtchn_to_irq[evtchn] = -1; - irq_info[irq] = IRQ_UNBOUND; - done: - mtx_unlock_spin(&irq_mapping_update_lock); -} - -static void xenpic_pirq_enable_source(struct intsrc *isrc) { int evtchn; Modified: projects/release_6_3_xen/sys/xen/gnttab.c ============================================================================== --- projects/release_6_3_xen/sys/xen/gnttab.c Sat Oct 18 06:37:43 2008 (r184023) +++ projects/release_6_3_xen/sys/xen/gnttab.c Sat Oct 18 06:56:07 2008 (r184024) @@ -25,11 +25,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include -#include - -#include -#include #include #include Modified: projects/release_6_3_xen/sys/xen/gnttab.h ============================================================================== --- projects/release_6_3_xen/sys/xen/gnttab.h Sat Oct 18 06:37:43 2008 (r184023) +++ projects/release_6_3_xen/sys/xen/gnttab.h Sat Oct 18 06:56:07 2008 (r184024) @@ -36,12 +36,16 @@ #ifndef __ASM_GNTTAB_H__ +#include +#include +#include +#include + #include #include #include #include #include - struct gnttab_free_callback { struct gnttab_free_callback *next; void (*fn)(void *); Modified: projects/release_6_3_xen/sys/xen/xenbus/xenbus_xs.c ============================================================================== --- projects/release_6_3_xen/sys/xen/xenbus/xenbus_xs.c Sat Oct 18 06:37:43 2008 (r184023) +++ projects/release_6_3_xen/sys/xen/xenbus/xenbus_xs.c Sat Oct 18 06:56:07 2008 (r184024) @@ -883,7 +883,7 @@ static void xenbus_thread(void *unused) DELAY(10000); xenbus_running = 1; - pause("xenbus", hz/10); + tsleep(&lbolt, 0, "xenbus", hz/10); for (;;) { err = xs_process_msg(&type); @@ -922,13 +922,13 @@ int xs_init(void) if (err) return err; - err = kproc_create(xenwatch_thread, NULL, &p, + err = kthread_create(xenwatch_thread, NULL, &p, RFHIGHPID, 0, "xenwatch"); if (err) return err; xenwatch_pid = p->p_pid; - err = kproc_create(xenbus_thread, NULL, NULL, + err = kthread_create(xenbus_thread, NULL, NULL, RFHIGHPID, 0, "xenbus"); return err; From owner-svn-src-projects@FreeBSD.ORG Sat Oct 18 07:20:46 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8EB4B106568D; Sat, 18 Oct 2008 07:20:46 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 7A5138FC0A; Sat, 18 Oct 2008 07:20:46 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9I7KkKW010258; Sat, 18 Oct 2008 07:20:46 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9I7KkT2010249; Sat, 18 Oct 2008 07:20:46 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <200810180720.m9I7KkT2010249@svn.freebsd.org> From: Lawrence Stewart Date: Sat, 18 Oct 2008 07:20:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184025 - in projects/tcp_cc_8.x/sys: conf netinet X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Oct 2008 07:20:46 -0000 Author: lstewart Date: Sat Oct 18 07:20:45 2008 New Revision: 184025 URL: http://svn.freebsd.org/changeset/base/184025 Log: Initial import of the TCP modular congestion control framework from my private repository. See http://caia.swin.edu.au/urp/newtcp/ for more details. Patch is currently in good shape and defaults to running with the regular New Reno congestion control algorithm. Todo: - KPI man page - Integrate properly with ECN - Integrate my currently private congestion control algorithm modules - Test that vimage changes have not functionally changed anything Added: projects/tcp_cc_8.x/sys/netinet/cc.c (contents, props changed) projects/tcp_cc_8.x/sys/netinet/cc.h (contents, props changed) Modified: projects/tcp_cc_8.x/sys/conf/files projects/tcp_cc_8.x/sys/netinet/tcp_input.c projects/tcp_cc_8.x/sys/netinet/tcp_output.c projects/tcp_cc_8.x/sys/netinet/tcp_subr.c projects/tcp_cc_8.x/sys/netinet/tcp_timer.c projects/tcp_cc_8.x/sys/netinet/tcp_usrreq.c projects/tcp_cc_8.x/sys/netinet/tcp_var.h Modified: projects/tcp_cc_8.x/sys/conf/files ============================================================================== --- projects/tcp_cc_8.x/sys/conf/files Sat Oct 18 06:56:07 2008 (r184024) +++ projects/tcp_cc_8.x/sys/conf/files Sat Oct 18 07:20:45 2008 (r184025) @@ -1960,6 +1960,7 @@ netinet/ip_mroute.c optional mrouting i netinet/ip_options.c optional inet netinet/ip_output.c optional inet netinet/raw_ip.c optional inet +netinet/cc.c optional inet netinet/sctp_asconf.c optional inet sctp netinet/sctp_auth.c optional inet sctp netinet/sctp_bsd_addr.c optional inet sctp Added: projects/tcp_cc_8.x/sys/netinet/cc.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/tcp_cc_8.x/sys/netinet/cc.c Sat Oct 18 07:20:45 2008 (r184025) @@ -0,0 +1,451 @@ +/*- + * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1994, 1995 + * The Regents of the University of California. + * Copyright (c) 2008 Swinburne University of Technology, Melbourne, Australia + * All rights reserved. + * + * The majority of this software was developed at the Centre for + * Advanced Internet Architectures, Swinburne University, by Lawrence Stewart + * and James Healy, made possible in part by a grant from the Cisco University + * Research Program Fund at Community Foundation Silicon Valley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + + +/* list of available cc algorithms on the current system */ +struct cc_head cc_list = STAILQ_HEAD_INITIALIZER(cc_list); + +struct rwlock cc_list_lock; + +MALLOC_DECLARE(M_STRING); +MALLOC_DEFINE(M_STRING, "string", "a string"); + +/* create a struct to point to our newreno functions */ +struct cc_algo newreno_cc_algo = { + .name = "newreno", + .init = newreno_init, + .deinit = NULL, + .cwnd_init = newreno_cwnd_init, + .ack_received = newreno_ack_received, + .pre_fr = newreno_pre_fr, + .post_fr = newreno_post_fr, + .after_idle = newreno_after_idle, + .after_timeout = newreno_after_timeout +}; + +/* the system wide default cc algorithm */ +char cc_algorithm[TCP_CA_NAME_MAX]; + +/* + * sysctl handler that allows the default cc algorithm for the system to be + * viewed and changed + */ +static int +cc_default_algorithm(SYSCTL_HANDLER_ARGS) +{ + struct cc_algo *funcs; + + if (!req->newptr) + goto skip; + + CC_LIST_RLOCK(); + STAILQ_FOREACH(funcs, &cc_list, entries) { + if (strncmp((char *)req->newptr, funcs->name, TCP_CA_NAME_MAX) == 0) + goto reorder; + } + CC_LIST_RUNLOCK(); + + return 1; + +reorder: + /* + * Make the selected system default cc algorithm + * the first element in the list if it isn't already + */ + CC_LIST_RUNLOCK(); + CC_LIST_WLOCK(); + if (funcs != STAILQ_FIRST(&cc_list)) { + STAILQ_REMOVE(&cc_list, funcs, cc_algo, entries); + STAILQ_INSERT_HEAD(&cc_list, funcs, entries); + } + CC_LIST_WUNLOCK(); + +skip: + return sysctl_handle_string(oidp, arg1, arg2, req); +} + +/* + * sysctl handler that displays the available cc algorithms as a read + * only value + */ +static int +cc_list_available(SYSCTL_HANDLER_ARGS) +{ + struct cc_algo *algo; + int error = 0, first = 1; + struct sbuf *s = NULL; + + if ((s = sbuf_new(NULL, NULL, TCP_CA_NAME_MAX, SBUF_AUTOEXTEND)) == NULL) + return -1; + + CC_LIST_RLOCK(); + STAILQ_FOREACH(algo, &cc_list, entries) { + error = sbuf_printf(s, (first) ? "%s" : ", %s", algo->name); + if (error != 0) + break; + first = 0; + } + CC_LIST_RUNLOCK(); + + if (!error) { + sbuf_finish(s); + error = sysctl_handle_string(oidp, sbuf_data(s), 1, req); + } + + sbuf_delete(s); + return error; +} + +/* + * Initialise cc on system boot + */ +void +cc_init() +{ + /* initialise the lock that will protect read/write access to our linked list */ + CC_LIST_LOCK_INIT(); + + /* initilize list of cc algorithms */ + STAILQ_INIT(&cc_list); + + /* add newreno to the list of available algorithms */ + cc_register_algorithm(&newreno_cc_algo); + + /* set newreno to the system default */ + strncpy(cc_algorithm, newreno_cc_algo.name, sizeof(cc_algorithm)); +} + +/* + * Returns 1 on success, 0 on failure + */ +int +cc_deregister_algorithm(struct cc_algo *remove_cc) +{ + struct cc_algo *funcs, *tmpfuncs; + register struct tcpcb *tp = NULL; + register struct inpcb *inp = NULL; + int success = 0; + + /* remove the algorithm from the list available to the system */ + CC_LIST_RLOCK(); + STAILQ_FOREACH_SAFE(funcs, &cc_list, entries, tmpfuncs) { + if (funcs == remove_cc) { + if (CC_LIST_TRY_WLOCK()) { + /* if this algorithm is the system default, reset the default to newreno */ + if (strncmp(cc_algorithm, remove_cc->name, TCP_CA_NAME_MAX) == 0) + snprintf(cc_algorithm, TCP_CA_NAME_MAX, "%s", newreno_cc_algo.name); + + STAILQ_REMOVE(&cc_list, funcs, cc_algo, entries); + success = 1; + CC_LIST_W2RLOCK(); + } + break; + } + } + CC_LIST_RUNLOCK(); + + if (success) { + /* + * check all active control blocks and change any that are using this + * algorithm back to newreno. If the algorithm that was in use requires + * deinit code to be run, call it + */ + INP_INFO_RLOCK(&tcbinfo); + LIST_FOREACH(inp, &tcb, inp_list) { + /* skip tcptw structs */ + if (inp->inp_vflag & INP_TIMEWAIT) + continue; + INP_WLOCK(inp); + if ((tp = intotcpcb(inp)) != NULL) { + if (strncmp(CC_ALGO(tp)->name, remove_cc->name, TCP_CA_NAME_MAX) == 0 ) { + tmpfuncs = CC_ALGO(tp); + CC_ALGO(tp) = &newreno_cc_algo; + /* + * XXX: We should stall here until + * we're sure the tcb has stopped + * using the deregistered algo's functions... + * Not sure how to do that yet! + */ + if(CC_ALGO(tp)->init) + CC_ALGO(tp)->init(tp); + if (tmpfuncs->deinit) + tmpfuncs->deinit(tp); + } + } + INP_WUNLOCK(inp); + } + INP_INFO_RUNLOCK(&tcbinfo); + } + + return success; +} + +int +cc_register_algorithm(struct cc_algo *add_cc) +{ + CC_LIST_WLOCK(); + STAILQ_INSERT_TAIL(&cc_list, add_cc, entries); + CC_LIST_WUNLOCK(); + return 1; +} + +/* + * NEW RENO + */ + +int +newreno_init(struct tcpcb *tp) +{ + printf("initialising tcp connection with newreno congestion control\n"); + return 0; +} + +/* + * update ssthresh to approx 1/2 of cwnd + */ +void +newreno_ssthresh_update(struct tcpcb *tp) +{ + u_int win; + + /* reset ssthresh */ + win = min(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_maxseg; + + if (win < 2) + win = 2; + + tp->snd_ssthresh = win * tp->t_maxseg; +} + +/* + * initial cwnd at the start of a connection + * if there is a hostcache entry for the foreign host, base cwnd on that + * if rfc3390 is enabled, set cwnd to approx 4 MSS as recommended + * otherwise use the sysctl variables configured by the administrator + */ +void +newreno_cwnd_init(struct tcpcb *tp) +{ + struct hc_metrics_lite metrics; + struct inpcb *inp = tp->t_inpcb; + struct socket *so = inp->inp_socket; + + /* + * Set the slow-start flight size depending on whether this + * is a local network or not. + * + * Extend this so we cache the cwnd too and retrieve it here. + * Make cwnd even bigger than RFC3390 suggests but only if we + * have previous experience with the remote host. Be careful + * not make cwnd bigger than remote receive window or our own + * send socket buffer. Maybe put some additional upper bound + * on the retrieved cwnd. Should do incremental updates to + * hostcache when cwnd collapses so next connection doesn't + * overloads the path again. + * + * RFC3390 says only do this if SYN or SYN/ACK didn't got lost. + * We currently check only in syncache_socket for that. + */ + + tcp_hc_get(&inp->inp_inc, &metrics); + +#define TCP_METRICS_CWND +#ifdef TCP_METRICS_CWND + if (metrics.rmx_cwnd) + tp->snd_cwnd = max(tp->t_maxseg, + min(metrics.rmx_cwnd / 2, + min(tp->snd_wnd, so->so_snd.sb_hiwat))); + else +#endif + if (tcp_do_rfc3390) + tp->snd_cwnd = min(4 * tp->t_maxseg, max(2 * tp->t_maxseg, 4380)); +#ifdef INET6 + else if ((isipv6 && in6_localaddr(&inp->in6p_faddr)) || + (!isipv6 && in_localaddr(inp->inp_faddr))) +#else + else if (in_localaddr(inp->inp_faddr)) +#endif + tp->snd_cwnd = tp->t_maxseg * ss_fltsz_local; + else + tp->snd_cwnd = tp->t_maxseg * ss_fltsz; +} + +/* + * increase cwnd on receipt of a successful ACK + * if cwnd <= ssthresh, increases by 1 MSS per ACK + * if cwnd > ssthresh, increase by ~1 MSS per RTT + */ +void +newreno_ack_received(struct tcpcb *tp, struct tcphdr *th) +{ + u_int cw = tp->snd_cwnd; + u_int incr = tp->t_maxseg; + + if (cw > tp->snd_ssthresh) + incr = incr * incr / cw; + + tp->snd_cwnd = min(cw+incr, TCP_MAXWIN<snd_scale); +} + +/* + * update the value of ssthresh before entering FR + */ +void +newreno_pre_fr(struct tcpcb *tp, struct tcphdr *th) +{ + newreno_ssthresh_update(tp); +} + +/* + * decrease the cwnd in response to packet loss or a transmit timeout. + * th can be null, in which case cwnd will be set according to reno instead + * of new reno. + */ +void +newreno_post_fr(struct tcpcb *tp, struct tcphdr *th) +{ + /* + * Out of fast recovery. + * Window inflation should have left us + * with approximately snd_ssthresh + * outstanding data. + * But in case we would be inclined to + * send a burst, better to do it via + * the slow start mechanism. + */ + if (th && SEQ_GT(th->th_ack + tp->snd_ssthresh, tp->snd_max)) + tp->snd_cwnd = tp->snd_max - th->th_ack + tp->t_maxseg; + else + tp->snd_cwnd = tp->snd_ssthresh; +} + +/* + * if a connection has been idle for a while and more data is ready to be sent, + * reset cwnd + */ +void +newreno_after_idle(struct tcpcb *tp) +{ + /* + * We have been idle for "a while" and no acks are + * expected to clock out any data we send -- + * slow start to get ack "clock" running again. + * + * Set the slow-start flight size depending on whether + * this is a local network or not. + * + * Set the slow-start flight size depending on whether + * this is a local network or not. + */ + int ss = ss_fltsz; + +#ifdef INET6 + if (isipv6) { + if (in6_localaddr(&tp->t_inpcb->in6p_faddr)) + ss = ss_fltsz_local; + } else +#endif /* INET6 */ + + if (in_localaddr(tp->t_inpcb->inp_faddr)) + ss = ss_fltsz_local; + + tp->snd_cwnd = tp->t_maxseg * ss; +} + +/* + * reset the cwnd after a transmission timeout. + */ +void +newreno_after_timeout(struct tcpcb *tp) +{ + newreno_ssthresh_update(tp); + + /* + * Close the congestion window down to one segment + * (we'll open it by one segment for each ack we get). + * Since we probably have a window's worth of unacked + * data accumulated, this "slow start" keeps us from + * dumping all that data as back-to-back packets (which + * might overwhelm an intermediate gateway). + * + * There are two phases to the opening: Initially we + * open by one mss on each ack. This makes the window + * size increase exponentially with time. If the + * window is larger than the path can handle, this + * exponential growth results in dropped packet(s) + * almost immediately. To get more time between + * drops but still "push" the network to take advantage + * of improving conditions, we switch from exponential + * to linear window opening at some threshhold size. + * For a threshhold, we use half the current window + * size, truncated to a multiple of the mss. + * + * (the minimum cwnd that will give us exponential + * growth is 2 mss. We don't allow the threshhold + * to go below this.) + */ + tp->snd_cwnd = tp->t_maxseg; +} + +SYSCTL_NODE(_net_inet_tcp, OID_AUTO, cc, CTLFLAG_RW, NULL, + "congestion control related settings"); + +SYSCTL_PROC(_net_inet_tcp_cc, OID_AUTO, algorithm, CTLTYPE_STRING|CTLFLAG_RW, + &cc_algorithm, sizeof(cc_algorithm), cc_default_algorithm, "A", + "default congestion control algorithm"); + +SYSCTL_PROC(_net_inet_tcp_cc, OID_AUTO, available, CTLTYPE_STRING|CTLFLAG_RD, + NULL, 0, cc_list_available, "A", + "list available congestion control algorithms"); Added: projects/tcp_cc_8.x/sys/netinet/cc.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/tcp_cc_8.x/sys/netinet/cc.h Sat Oct 18 07:20:45 2008 (r184025) @@ -0,0 +1,119 @@ +/*- + * Copyright (c) 2008 Swinburne University of Technology, Melbourne, Australia + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University, by Lawrence Stewart and James Healy, + * made possible in part by a grant from the Cisco University Research Program + * Fund at Community Foundation Silicon Valley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _NETINET_CC_H_ +#define _NETINET_CC_H_ + +#include +#include + +/* + * Global CC vars + */ +extern STAILQ_HEAD(cc_head, cc_algo) cc_list; +extern char cc_algorithm[]; +extern const int tcprexmtthresh; +extern struct cc_algo newreno_cc_algo; + +/* + * Define the new net.inet.tcp.cc sysctl tree + */ +SYSCTL_DECL(_net_inet_tcp_cc); + +/* + * CC housekeeping functions + */ +void cc_init(void); +int cc_register_algorithm(struct cc_algo *add_cc); +int cc_deregister_algorithm(struct cc_algo *remove_cc); + +/* + * NewReno CC functions + */ +int newreno_init(struct tcpcb *tp); +void newreno_cwnd_init(struct tcpcb *tp); +void newreno_ack_received(struct tcpcb *tp, struct tcphdr *th); +void newreno_pre_fr(struct tcpcb *tp, struct tcphdr *th); +void newreno_post_fr(struct tcpcb *tp, struct tcphdr *th); +void newreno_after_idle(struct tcpcb *tp); +void newreno_after_timeout(struct tcpcb *tp); +void newreno_ssthresh_update(struct tcpcb *tp); + +/* + * Structure to hold function pointers to the functions responsible + * for congestion control. Based on similar structure in the SCTP stack + */ +struct cc_algo { + char name[TCP_CA_NAME_MAX]; + + /* init the congestion algorithm for the specified control block */ + int (*init) (struct tcpcb *tp); + + /* deinit the congestion algorithm for the specified control block */ + void (*deinit) (struct tcpcb *tp); + + /* initilise cwnd at the start of a connection */ + void (*cwnd_init) (struct tcpcb *tp); + + /* called on the receipt of a valid ack */ + void (*ack_received) (struct tcpcb *tp, struct tcphdr *th); + + /* called before entering FR */ + void (*pre_fr) (struct tcpcb *tp, struct tcphdr *th); + + /* after exiting FR */ + void (*post_fr) (struct tcpcb *tp, struct tcphdr *th); + + /* perform tasks when data transfer resumes after an idle period */ + void (*after_idle) (struct tcpcb *tp); + + /* perform tasks when the connection's retransmit timer expires */ + void (*after_timeout) (struct tcpcb *tp); + + STAILQ_ENTRY(cc_algo) entries; +}; + +#define CC_ALGO(tp) ((tp)->cc_algo) +#define CC_DATA(tp) ((tp)->cc_data) + +extern struct rwlock cc_list_lock; +#define CC_LIST_LOCK_INIT() rw_init(&cc_list_lock, "cc_list") +#define CC_LIST_LOCK_DESTROY() rw_destroy(&cc_list_lock) +#define CC_LIST_RLOCK() rw_rlock(&cc_list_lock) +#define CC_LIST_RUNLOCK() rw_runlock(&cc_list_lock) +#define CC_LIST_WLOCK() rw_wlock(&cc_list_lock) +#define CC_LIST_WUNLOCK() rw_wunlock(&cc_list_lock) +#define CC_LIST_TRY_WLOCK() rw_try_upgrade(&cc_list_lock) +#define CC_LIST_W2RLOCK() rw_downgrade(&cc_list_lock) + +#endif /* _NETINET_CC_H_ */ Modified: projects/tcp_cc_8.x/sys/netinet/tcp_input.c ============================================================================== --- projects/tcp_cc_8.x/sys/netinet/tcp_input.c Sat Oct 18 06:56:07 2008 (r184024) +++ projects/tcp_cc_8.x/sys/netinet/tcp_input.c Sat Oct 18 07:20:45 2008 (r184025) @@ -84,6 +84,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifdef TCPDEBUG #include #endif /* TCPDEBUG */ @@ -97,7 +98,7 @@ __FBSDID("$FreeBSD$"); #include -static const int tcprexmtthresh = 3; +const int tcprexmtthresh = 3; struct tcpstat tcpstat; SYSCTL_V_STRUCT(V_NET, vnet_inet, _net_inet_tcp, TCPCTL_STATS, stats, @@ -125,7 +126,7 @@ static int tcp_do_rfc3042 = 1; SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_tcp, OID_AUTO, rfc3042, CTLFLAG_RW, tcp_do_rfc3042, 0, "Enable RFC 3042 (Limited Transmit)"); -static int tcp_do_rfc3390 = 1; +int tcp_do_rfc3390 = 1; SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_tcp, OID_AUTO, rfc3390, CTLFLAG_RW, tcp_do_rfc3390, 0, "Enable RFC 3390 (Increasing TCP's Initial Congestion Window)"); @@ -1096,14 +1097,9 @@ tcp_do_segment(struct mbuf *m, struct tc if (SEQ_GT(th->th_ack, tp->snd_una) && SEQ_LEQ(th->th_ack, tp->snd_max) && tp->snd_cwnd >= tp->snd_wnd && - ((!V_tcp_do_newreno && - !(tp->t_flags & TF_SACK_PERMIT) && - tp->t_dupacks < tcprexmtthresh) || - ((V_tcp_do_newreno || - (tp->t_flags & TF_SACK_PERMIT)) && - !IN_FASTRECOVERY(tp) && - (to.to_flags & TOF_SACK) == 0 && - TAILQ_EMPTY(&tp->snd_holes)))) { + !IN_FASTRECOVERY(tp) && + (to.to_flags & TOF_SACK) == 0 && + TAILQ_EMPTY(&tp->snd_holes)) { KASSERT(headlocked, ("%s: headlocked", __func__)); INP_INFO_WUNLOCK(&V_tcbinfo); @@ -1870,9 +1866,7 @@ tcp_do_segment(struct mbuf *m, struct tc th->th_ack != tp->snd_una) tp->t_dupacks = 0; else if (++tp->t_dupacks > tcprexmtthresh || - ((V_tcp_do_newreno || - (tp->t_flags & TF_SACK_PERMIT)) && - IN_FASTRECOVERY(tp))) { + IN_FASTRECOVERY(tp)) { if ((tp->t_flags & TF_SACK_PERMIT) && IN_FASTRECOVERY(tp)) { int awnd; @@ -1909,14 +1903,24 @@ tcp_do_segment(struct mbuf *m, struct tc tp->t_dupacks = 0; break; } - } else if (V_tcp_do_newreno || - V_tcp_do_ecn) { + } else { if (SEQ_LEQ(th->th_ack, tp->snd_recover)) { tp->t_dupacks = 0; break; } } + + /* + * If the current tcp cc module has + * defined a hook for tasks to run + * before entering FR, call it + */ + if (CC_ALGO(tp)->pre_fr) + CC_ALGO(tp)->pre_fr(tp, th); + + ENTER_FASTRECOVERY(tp); + tp->snd_recover = tp->snd_max; tcp_congestion_exp(tp); tcp_timer_activate(tp, TT_REXMT, 0); tp->t_rtttime = 0; @@ -1981,37 +1985,16 @@ tcp_do_segment(struct mbuf *m, struct tc * If the congestion window was inflated to account * for the other side's cached packets, retract it. */ - if (V_tcp_do_newreno || (tp->t_flags & TF_SACK_PERMIT)) { - if (IN_FASTRECOVERY(tp)) { - if (SEQ_LT(th->th_ack, tp->snd_recover)) { - if (tp->t_flags & TF_SACK_PERMIT) - tcp_sack_partialack(tp, th); - else - tcp_newreno_partial_ack(tp, th); - } else { - /* - * Out of fast recovery. - * Window inflation should have left us - * with approximately snd_ssthresh - * outstanding data. - * But in case we would be inclined to - * send a burst, better to do it via - * the slow start mechanism. - */ - if (SEQ_GT(th->th_ack + - tp->snd_ssthresh, - tp->snd_max)) - tp->snd_cwnd = tp->snd_max - - th->th_ack + - tp->t_maxseg; - else - tp->snd_cwnd = tp->snd_ssthresh; - } + if (IN_FASTRECOVERY(tp)) { + if (SEQ_LT(th->th_ack, tp->snd_recover)) { + if (tp->t_flags & TF_SACK_PERMIT) + tcp_sack_partialack(tp, th); + else + tcp_newreno_partial_ack(tp, th); + } else { + if (CC_ALGO(tp)->post_fr) + CC_ALGO(tp)->post_fr(tp, th); } - } else { - if (tp->t_dupacks >= tcprexmtthresh && - tp->snd_cwnd > tp->snd_ssthresh) - tp->snd_cwnd = tp->snd_ssthresh; } tp->t_dupacks = 0; /* @@ -2117,13 +2100,9 @@ process_ACK: * If cwnd > maxseg^2, fix the cwnd increment at 1 byte * to avoid capping cwnd (as suggested in RFC2581). */ - if ((!V_tcp_do_newreno && !(tp->t_flags & TF_SACK_PERMIT)) || - !IN_FASTRECOVERY(tp)) { - u_int cw = tp->snd_cwnd; - u_int incr = tp->t_maxseg; - if (cw > tp->snd_ssthresh) - incr = max((incr * incr / cw), 1); - tp->snd_cwnd = min(cw+incr, TCP_MAXWIN<snd_scale); + if (!IN_FASTRECOVERY(tp)) { + if (CC_ALGO(tp)->ack_received) + CC_ALGO(tp)->ack_received(tp, th); } SOCKBUF_LOCK(&so->so_snd); if (acked > so->so_snd.sb_cc) { @@ -2138,14 +2117,11 @@ process_ACK: /* NB: sowwakeup_locked() does an implicit unlock. */ sowwakeup_locked(so); /* Detect una wraparound. */ - if ((V_tcp_do_newreno || (tp->t_flags & TF_SACK_PERMIT)) && - !IN_FASTRECOVERY(tp) && + if (!IN_FASTRECOVERY(tp) && SEQ_GT(tp->snd_una, tp->snd_recover) && SEQ_LEQ(th->th_ack, tp->snd_recover)) tp->snd_recover = th->th_ack - 1; - if ((V_tcp_do_newreno || (tp->t_flags & TF_SACK_PERMIT)) && - IN_FASTRECOVERY(tp) && - SEQ_GEQ(th->th_ack, tp->snd_recover)) + if (IN_FASTRECOVERY(tp) && SEQ_GEQ(th->th_ack, tp->snd_recover)) EXIT_FASTRECOVERY(tp); tp->snd_una = th->th_ack; if (tp->t_flags & TF_SACK_PERMIT) { @@ -3072,41 +3048,9 @@ tcp_mss(struct tcpcb *tp, int offer) if (metrics.rmx_bandwidth) tp->snd_bandwidth = metrics.rmx_bandwidth; - /* - * Set the slow-start flight size depending on whether this - * is a local network or not. - * - * Extend this so we cache the cwnd too and retrieve it here. - * Make cwnd even bigger than RFC3390 suggests but only if we - * have previous experience with the remote host. Be careful - * not make cwnd bigger than remote receive window or our own - * send socket buffer. Maybe put some additional upper bound - * on the retrieved cwnd. Should do incremental updates to - * hostcache when cwnd collapses so next connection doesn't - * overloads the path again. - * - * RFC3390 says only do this if SYN or SYN/ACK didn't got lost. - * We currently check only in syncache_socket for that. - */ -#define TCP_METRICS_CWND -#ifdef TCP_METRICS_CWND - if (metrics.rmx_cwnd) - tp->snd_cwnd = max(mss, - min(metrics.rmx_cwnd / 2, - min(tp->snd_wnd, so->so_snd.sb_hiwat))); - else -#endif - if (V_tcp_do_rfc3390) - tp->snd_cwnd = min(4 * mss, max(2 * mss, 4380)); -#ifdef INET6 - else if ((isipv6 && in6_localaddr(&inp->in6p_faddr)) || - (!isipv6 && in_localaddr(inp->inp_faddr))) -#else - else if (in_localaddr(inp->inp_faddr)) -#endif - tp->snd_cwnd = mss * V_ss_fltsz_local; - else - tp->snd_cwnd = mss * V_ss_fltsz; + /* set the initial cwnd value */ + if (CC_ALGO(tp)->cwnd_init) + CC_ALGO(tp)->cwnd_init(tp); } /* Modified: projects/tcp_cc_8.x/sys/netinet/tcp_output.c ============================================================================== --- projects/tcp_cc_8.x/sys/netinet/tcp_output.c Sat Oct 18 06:56:07 2008 (r184024) +++ projects/tcp_cc_8.x/sys/netinet/tcp_output.c Sat Oct 18 07:20:45 2008 (r184025) @@ -71,6 +71,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifdef TCPDEBUG #include #endif @@ -101,10 +102,6 @@ SYSCTL_V_INT(V_NET, vnet_inet, _net_inet local_slowstart_flightsize, CTLFLAG_RW, ss_fltsz_local, 1, "Slow start flight size for local networks"); -int tcp_do_newreno = 1; -SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_tcp, OID_AUTO, newreno, CTLFLAG_RW, - tcp_do_newreno, 0, "Enable NewReno Algorithms"); - int tcp_do_tso = 1; SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_tcp, OID_AUTO, tso, CTLFLAG_RW, tcp_do_tso, 0, "Enable TCP Segmentation Offload"); @@ -169,24 +166,9 @@ tcp_output(struct tcpcb *tp) */ idle = (tp->t_flags & TF_LASTIDLE) || (tp->snd_max == tp->snd_una); if (idle && (ticks - tp->t_rcvtime) >= tp->t_rxtcur) { - /* - * We have been idle for "a while" and no acks are - * expected to clock out any data we send -- - * slow start to get ack "clock" running again. - * - * Set the slow-start flight size depending on whether - * this is a local network or not. - */ - int ss = V_ss_fltsz; -#ifdef INET6 - if (isipv6) { - if (in6_localaddr(&tp->t_inpcb->in6p_faddr)) - ss = V_ss_fltsz_local; - } else -#endif /* INET6 */ - if (in_localaddr(tp->t_inpcb->inp_faddr)) - ss = V_ss_fltsz_local; - tp->snd_cwnd = tp->t_maxseg * ss; + /* reset cwnd after a period of idleness */ + if (CC_ALGO(tp)->after_idle) + CC_ALGO(tp)->after_idle(tp); } tp->t_flags &= ~TF_LASTIDLE; if (idle) { Modified: projects/tcp_cc_8.x/sys/netinet/tcp_subr.c ============================================================================== --- projects/tcp_cc_8.x/sys/netinet/tcp_subr.c Sat Oct 18 06:56:07 2008 (r184024) +++ projects/tcp_cc_8.x/sys/netinet/tcp_subr.c Sat Oct 18 07:20:45 2008 (r184025) @@ -49,6 +49,8 @@ __FBSDID("$FreeBSD$"); #ifdef INET6 #include #endif +#include +#include #include #include #include @@ -87,6 +89,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifdef INET6 #include #endif @@ -312,6 +315,8 @@ tcp_init(void) V_tcp_inflight_rttthresh = TCPTV_INFLIGHT_RTTTHRESH; tcp_finwait2_timeout = TCPTV_FINWAIT2_TIMEOUT; + cc_init(); + INP_INFO_LOCK_INIT(&V_tcbinfo, "tcp"); LIST_INIT(&V_tcb); V_tcbinfo.ipi_listhead = &V_tcb; @@ -638,6 +643,21 @@ tcp_newtcpcb(struct inpcb *inp) if (tm == NULL) return (NULL); tp = &tm->tcb; + + /* + * use the current system default cc algorithm, which is always + * the first algorithm in cc_list + */ + CC_LIST_RLOCK(); + CC_ALGO(tp) = STAILQ_FIRST(&cc_list); + CC_LIST_RUNLOCK(); + + /* if the cc module fails to init, stop building the control block */ + if (CC_ALGO(tp)->init(tp) > 0) { + uma_zfree(tcpcb_zone, tp); + return NULL; + } + tp->t_timers = &tm->tt; /* LIST_INIT(&tp->t_segq); */ /* XXX covered by M_ZERO */ tp->t_maxseg = tp->t_maxopd = @@ -800,8 +820,13 @@ tcp_discardcb(struct tcpcb *tp) } /* Disconnect offload device, if any. */ tcp_offload_detach(tp); - tcp_free_sackholes(tp); + + /* Allow the cc algorithm in use for this cb to clean up after itself */ + if (CC_ALGO(tp)->deinit) + CC_ALGO(tp)->deinit(tp); + + CC_ALGO(tp) = NULL; inp->inp_ppcb = NULL; tp->t_inpcb = NULL; uma_zfree(tcpcb_zone, tp); Modified: projects/tcp_cc_8.x/sys/netinet/tcp_timer.c ============================================================================== --- projects/tcp_cc_8.x/sys/netinet/tcp_timer.c Sat Oct 18 06:56:07 2008 (r184024) +++ projects/tcp_cc_8.x/sys/netinet/tcp_timer.c Sat Oct 18 07:20:45 2008 (r184025) @@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifdef TCPDEBUG #include #endif @@ -552,38 +553,11 @@ tcp_timer_rexmt(void * xtp) * If timing a segment in this window, stop the timer. */ tp->t_rtttime = 0; - /* - * Close the congestion window down to one segment - * (we'll open it by one segment for each ack we get). - * Since we probably have a window's worth of unacked - * data accumulated, this "slow start" keeps us from - * dumping all that data as back-to-back packets (which - * might overwhelm an intermediate gateway). - * - * There are two phases to the opening: Initially we - * open by one mss on each ack. This makes the window - * size increase exponentially with time. If the - * window is larger than the path can handle, this - * exponential growth results in dropped packet(s) - * almost immediately. To get more time between - * drops but still "push" the network to take advantage - * of improving conditions, we switch from exponential - * to linear window opening at some threshhold size. - * For a threshhold, we use half the current window - * size, truncated to a multiple of the mss. - * - * (the minimum cwnd that will give us exponential - * growth is 2 mss. We don't allow the threshhold - * to go below this.) - */ - { - u_int win = min(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_maxseg; - if (win < 2) - win = 2; - tp->snd_cwnd = tp->t_maxseg; - tp->snd_ssthresh = win * tp->t_maxseg; - tp->t_dupacks = 0; - } + + if (CC_ALGO(tp)->after_timeout) + CC_ALGO(tp)->after_timeout(tp); + + tp->t_dupacks = 0; EXIT_FASTRECOVERY(tp); (void) tcp_output(tp); Modified: projects/tcp_cc_8.x/sys/netinet/tcp_usrreq.c ============================================================================== --- projects/tcp_cc_8.x/sys/netinet/tcp_usrreq.c Sat Oct 18 06:56:07 2008 (r184024) +++ projects/tcp_cc_8.x/sys/netinet/tcp_usrreq.c Sat Oct 18 07:20:45 2008 (r184025) @@ -83,6 +83,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifdef TCPDEBUG #include #endif @@ -1281,6 +1282,8 @@ tcp_ctloutput(struct socket *so, struct struct inpcb *inp; struct tcpcb *tp; struct tcp_info ti; + char buf[TCP_CA_NAME_MAX]; + struct cc_algo *cc_algo; error = 0; inp = sotoinpcb(so); @@ -1390,6 +1393,58 @@ tcp_ctloutput(struct socket *so, struct error = EINVAL; break; + case TCP_CONGESTION: + INP_WUNLOCK(inp); + bzero(buf, sizeof(buf)); + error = sooptcopyin(sopt, &buf, sizeof(buf), 1); + if (error) + break; + INP_WLOCK_RECHECK(inp); + /* + * We return EINVAL if we can't find the requested cc + * algo. We set error here and reset to 0 if found to + * simplify the error checking, + */ + error = EINVAL; *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-projects@FreeBSD.ORG Sat Oct 18 22:47:45 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 529BE1065687; Sat, 18 Oct 2008 22:47:45 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 40C4F8FC08; Sat, 18 Oct 2008 22:47:45 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9IMljak027629; Sat, 18 Oct 2008 22:47:45 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9IMljp5027626; Sat, 18 Oct 2008 22:47:45 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810182247.m9IMljp5027626@svn.freebsd.org> From: Kip Macy Date: Sat, 18 Oct 2008 22:47:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184035 - in projects/release_6_3_xen/sys/i386: i386 xen X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Oct 2008 22:47:45 -0000 Author: kmacy Date: Sat Oct 18 22:47:44 2008 New Revision: 184035 URL: http://svn.freebsd.org/changeset/base/184035 Log: Use post 6.3 pcpu implementation, it simplifies the code and doesn't involve working around the default placement of privatespace in the hypervisor's address space Modified: projects/release_6_3_xen/sys/i386/i386/machdep.c projects/release_6_3_xen/sys/i386/xen/mp_machdep.c projects/release_6_3_xen/sys/i386/xen/xen_machdep.c Modified: projects/release_6_3_xen/sys/i386/i386/machdep.c ============================================================================== --- projects/release_6_3_xen/sys/i386/i386/machdep.c Sat Oct 18 22:22:25 2008 (r184034) +++ projects/release_6_3_xen/sys/i386/i386/machdep.c Sat Oct 18 22:47:44 2008 (r184035) @@ -126,7 +126,9 @@ __FBSDID("$FreeBSD$"); #include #endif #ifdef SMP +#ifndef XEN #include +#endif #include #endif @@ -223,9 +225,12 @@ vm_paddr_t dump_avail[PHYSMAP_SIZE + 2]; struct kva_md_info kmi; static struct trapframe proc0_tf; -#ifndef SMP +#if !defined(SMP) && !defined(XEN) static struct pcpu __pcpu; #endif +#ifdef XEN +struct pcpu __pcpu[MAXCPU]; +#endif struct mtx icu_lock; @@ -2205,11 +2210,7 @@ init386(int first) gdt_segs[GUDATA_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE); gdt_segs[GBIOSLOWMEM_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE); -#ifdef SMP - pc = &SMP_prvspace[0].pcpu; -#else - pc = &__pcpu; -#endif + pc = &__pcpu[0]; gdt_segs[GPRIV_SEL].ssd_base = (int) pc; gdt_segs[GPROC0_SEL].ssd_base = (int) &pc->pc_common_tss; Modified: projects/release_6_3_xen/sys/i386/xen/mp_machdep.c ============================================================================== --- projects/release_6_3_xen/sys/i386/xen/mp_machdep.c Sat Oct 18 22:22:25 2008 (r184034) +++ projects/release_6_3_xen/sys/i386/xen/mp_machdep.c Sat Oct 18 22:47:44 2008 (r184035) @@ -81,7 +81,6 @@ __FBSDID("$FreeBSD$"); #include #include /** COUNT_XINVLTLB_HITS */ #include -#include #include #include @@ -623,7 +622,7 @@ start_all_aps(void) bootAPgdt = gdt + (512*cpu); /* Get per-cpu data */ - pc = &SMP_prvspace[bootAP].pcpu; + pc = &__pcpu[bootAP]; pcpu_init(pc, bootAP, sizeof(struct pcpu)); pc->pc_apic_id = cpu_apic_ids[bootAP]; pc->pc_prvspace = pc; Modified: projects/release_6_3_xen/sys/i386/xen/xen_machdep.c ============================================================================== --- projects/release_6_3_xen/sys/i386/xen/xen_machdep.c Sat Oct 18 22:22:25 2008 (r184034) +++ projects/release_6_3_xen/sys/i386/xen/xen_machdep.c Sat Oct 18 22:47:44 2008 (r184035) @@ -65,10 +65,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#ifdef SMP -#include -#endif - #include @@ -834,7 +830,7 @@ initvalues(start_info_t *startinfo) vm_paddr_t pdir_shadow_ma; #endif unsigned long i; - int ncpus; + int ncpus = MAXCPU; nkpt = min( min( @@ -842,12 +838,6 @@ initvalues(start_info_t *startinfo) NPGPTD*NPDEPG - KPTDI), (HYPERVISOR_VIRT_START - KERNBASE) >> PDRSHIFT); -#ifdef SMP - ncpus = MAXCPU; -#else - ncpus = 1; -#endif - HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments); #ifdef notyet /* @@ -873,7 +863,7 @@ initvalues(start_info_t *startinfo) cur_space += (4 * PAGE_SIZE); bootmem_end = (char *)cur_space; - /* allocate page for gdt */ + /* allocate pages for gdt */ gdt = (union descriptor *)cur_space; cur_space += PAGE_SIZE*ncpus; @@ -988,8 +978,6 @@ initvalues(start_info_t *startinfo) PT_UPDATES_FLUSH(); - - memcpy(((uint8_t *)IdlePTDnew) + ((unsigned int)(KERNBASE >> 18)), ((uint8_t *)IdlePTD) + ((KERNBASE >> 18) & PAGE_MASK), l1_pages*sizeof(pt_entry_t)); From owner-svn-src-projects@FreeBSD.ORG Sat Oct 18 22:59:40 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3D3981065687; Sat, 18 Oct 2008 22:59:40 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2B9038FC1A; Sat, 18 Oct 2008 22:59:40 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9IMxeP1027866; Sat, 18 Oct 2008 22:59:40 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9IMxe7g027865; Sat, 18 Oct 2008 22:59:40 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810182259.m9IMxe7g027865@svn.freebsd.org> From: Kip Macy Date: Sat, 18 Oct 2008 22:59:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184036 - projects/release_6_3_xen/sys/i386/xen X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Oct 2008 22:59:40 -0000 Author: kmacy Date: Sat Oct 18 22:59:39 2008 New Revision: 184036 URL: http://svn.freebsd.org/changeset/base/184036 Log: remove unused SMP declarations Modified: projects/release_6_3_xen/sys/i386/xen/locore.s Modified: projects/release_6_3_xen/sys/i386/xen/locore.s ============================================================================== --- projects/release_6_3_xen/sys/i386/xen/locore.s Sat Oct 18 22:47:44 2008 (r184035) +++ projects/release_6_3_xen/sys/i386/xen/locore.s Sat Oct 18 22:59:39 2008 (r184036) @@ -110,16 +110,6 @@ .set PTmap,(PTDPTDI << PDRSHIFT) .set PTD,PTmap + (PTDPTDI * PAGE_SIZE) .set PTDpde,PTD + (PTDPTDI * PDESIZE) -#ifdef SMP -/* - * Define layout of per-cpu address space. - * This is "constructed" in locore.s on the BSP and in mp_machdep.c - * for each AP. DO NOT REORDER THESE WITHOUT UPDATING THE REST! - */ - .globl SMP_prvspace - .set SMP_prvspace,(MPPTDI << PDRSHIFT) -#endif /* SMP */ - /* * Compiled KERNBASE location and the kernel load address */ @@ -145,16 +135,6 @@ KERNend: .long 0 /* phys addr end of ke .globl physfree physfree: .long 0 /* phys addr of next free page */ -#ifdef SMP - .globl cpu0prvpage -cpu0pp: .long 0 /* phys addr cpu0 private pg */ -cpu0prvpage: .long 0 /* relocated version */ - - .globl SMPpt -SMPptpa: .long 0 /* phys addr SMP page table */ -SMPpt: .long 0 /* relocated version */ -#endif /* SMP */ - .globl IdlePTD IdlePTD: .long 0 /* phys addr of kernel PTD */