diff options
author | kmacy <kmacy@FreeBSD.org> | 2008-12-29 06:31:03 +0000 |
---|---|---|
committer | kmacy <kmacy@FreeBSD.org> | 2008-12-29 06:31:03 +0000 |
commit | 9198d09682e0ff9e4b99c1a500c60ec311f33516 (patch) | |
tree | 78f4ff4cfc0d598fd6e8ccc01fa628fc8ded089f /sys/dev/xen | |
parent | e46dfc4a1843e8da9da2fceed45ebc43d45d62b1 (diff) | |
download | FreeBSD-src-9198d09682e0ff9e4b99c1a500c60ec311f33516.zip FreeBSD-src-9198d09682e0ff9e4b99c1a500c60ec311f33516.tar.gz |
merge 186535, 186537, and 186538 from releng_7_xen
Log:
- merge in latest xenbus from dfr's xenhvm
- fix race condition in xs_read_reply by converting tsleep to mtx_sleep
Log:
unmask evtchn in bind_{virq, ipi}_to_irq
Log:
- remove code for handling case of not being able to sleep
- eliminate tsleep - make sleeps atomic
Diffstat (limited to 'sys/dev/xen')
-rw-r--r-- | sys/dev/xen/blkfront/blkfront.c | 49 | ||||
-rw-r--r-- | sys/dev/xen/console/console.c | 27 | ||||
-rw-r--r-- | sys/dev/xen/console/xencons_ring.c | 11 | ||||
-rw-r--r-- | sys/dev/xen/evtchn/evtchn_dev.c | 4 | ||||
-rw-r--r-- | sys/dev/xen/netfront/netfront.c | 115 |
5 files changed, 103 insertions, 103 deletions
diff --git a/sys/dev/xen/blkfront/blkfront.c b/sys/dev/xen/blkfront/blkfront.c index dc36007..fdebc9d 100644 --- a/sys/dev/xen/blkfront/blkfront.c +++ b/sys/dev/xen/blkfront/blkfront.c @@ -40,10 +40,10 @@ __FBSDID("$FreeBSD$"); #include <machine/intr_machdep.h> #include <machine/vmparam.h> -#include <machine/xen/hypervisor.h> +#include <xen/hypervisor.h> #include <machine/xen/xen-os.h> -#include <machine/xen/xen_intr.h> -#include <machine/xen/evtchn.h> +#include <xen/xen_intr.h> +#include <xen/evtchn.h> #include <xen/interface/grant_table.h> #include <xen/interface/io/protocols.h> #include <xen/xenbus/xenbusvar.h> @@ -214,7 +214,7 @@ xlvbd_add(device_t dev, blkif_sector_t capacity, struct xb_softc *sc; int unit, error = 0; const char *name; - + blkfront_vdevice_to_unit(vdevice, &unit, &name); sc = (struct xb_softc *)malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO); @@ -227,12 +227,12 @@ xlvbd_add(device_t dev, blkif_sector_t capacity, memset(&sc->xb_disk, 0, sizeof(sc->xb_disk)); sc->xb_disk = disk_alloc(); - sc->xb_disk->d_unit = unit; + sc->xb_disk->d_unit = sc->xb_unit; sc->xb_disk->d_open = blkif_open; sc->xb_disk->d_close = blkif_close; sc->xb_disk->d_ioctl = blkif_ioctl; sc->xb_disk->d_strategy = xb_strategy; - sc->xb_disk->d_name = "xbd"; + sc->xb_disk->d_name = name; sc->xb_disk->d_drv1 = sc; sc->xb_disk->d_sectorsize = sector_size; @@ -329,8 +329,8 @@ blkfront_attach(device_t dev) /* FIXME: Use dynamic device id if this is not set. */ err = xenbus_scanf(XBT_NIL, xenbus_get_node(dev), - "virtual-device", "%i", &vdevice); - if (err != 1) { + "virtual-device", NULL, "%i", &vdevice); + if (err) { xenbus_dev_fatal(dev, err, "reading virtual-device"); printf("couldn't find virtual device"); return (err); @@ -363,9 +363,8 @@ blkfront_attach(device_t dev) info->handle = strtoul(strrchr(xenbus_get_node(dev),'/')+1, NULL, 0); err = talk_to_backend(dev, info); - if (err) { - return err; - } + if (err) + return (err); return (0); } @@ -381,7 +380,8 @@ blkfront_resume(device_t dev) blkif_free(info, 1); err = talk_to_backend(dev, info); - if (!err) + + if (info->connected == BLKIF_STATE_SUSPENDED && !err) blkif_recover(info); return err; @@ -427,7 +427,7 @@ talk_to_backend(device_t dev, struct blkfront_info *info) } err = xenbus_transaction_end(xbt, 0); if (err) { - if (err == -EAGAIN) + if (err == EAGAIN) goto again; xenbus_dev_fatal(dev, err, "completing transaction"); goto destroy_blkring; @@ -450,7 +450,7 @@ static int setup_blkring(device_t dev, struct blkfront_info *info) { blkif_sring_t *sring; - int err; + int error; info->ring_ref = GRANT_INVALID_REF; @@ -462,28 +462,27 @@ setup_blkring(device_t dev, struct blkfront_info *info) SHARED_RING_INIT(sring); FRONT_RING_INIT(&info->ring, sring, PAGE_SIZE); - err = xenbus_grant_ring(dev, (vtomach(info->ring.sring) >> PAGE_SHIFT)); - if (err < 0) { + error = xenbus_grant_ring(dev, (vtomach(info->ring.sring) >> PAGE_SHIFT), + &info->ring_ref); + if (error) { free(sring, M_DEVBUF); info->ring.sring = NULL; goto fail; } - info->ring_ref = err; - err = bind_listening_port_to_irqhandler(xenbus_get_otherend_id(dev), + error = bind_listening_port_to_irqhandler(xenbus_get_otherend_id(dev), "xbd", (driver_intr_t *)blkif_int, info, - INTR_TYPE_BIO | INTR_MPSAFE, NULL); - if (err <= 0) { - xenbus_dev_fatal(dev, err, + INTR_TYPE_BIO | INTR_MPSAFE, &info->irq); + if (error) { + xenbus_dev_fatal(dev, error, "bind_evtchn_to_irqhandler failed"); goto fail; } - info->irq = err; - return 0; + return (0); fail: blkif_free(info, 0); - return err; + return (error); } @@ -999,7 +998,7 @@ blkif_free(struct blkfront_info *info, int suspend) info->ring.sring = NULL; } if (info->irq) - unbind_from_irqhandler(info->irq, info); + unbind_from_irqhandler(info->irq); info->irq = 0; } diff --git a/sys/dev/xen/console/console.c b/sys/dev/xen/console/console.c index 5b556c2..a3d616a 100644 --- a/sys/dev/xen/console/console.c +++ b/sys/dev/xen/console/console.c @@ -15,8 +15,8 @@ __FBSDID("$FreeBSD$"); #include <sys/bus.h> #include <machine/stdarg.h> #include <machine/xen/xen-os.h> -#include <machine/xen/hypervisor.h> -#include <machine/xen/xen_intr.h> +#include <xen/hypervisor.h> +#include <xen/xen_intr.h> #include <sys/cons.h> #include <sys/priv.h> #include <sys/proc.h> @@ -75,17 +75,17 @@ static unsigned int wc, wp; /* write_cons, write_prod */ #define XCUNIT(x) (dev2unit(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) + mtx_init(&x, _name, NULL, MTX_DEF|MTX_RECURSE) #define CN_LOCK(l) \ do { \ if (panicstr == NULL) \ - mtx_lock_spin(&(l)); \ + mtx_lock(&(l)); \ } while (0) #define CN_UNLOCK(l) \ do { \ if (panicstr == NULL) \ - mtx_unlock_spin(&(l)); \ + mtx_unlock(&(l)); \ } while (0) #define CN_LOCK_ASSERT(x) mtx_assert(&x, MA_OWNED) #define CN_LOCK_DESTROY(x) mtx_destroy(&x) @@ -216,6 +216,8 @@ xc_probe(device_t dev) static int xc_attach(device_t dev) { + int error; + struct xc_softc *sc = (struct xc_softc *)device_get_softc(dev); if (xen_start_info->flags & SIF_INITDOMAIN) { xc_consdev.cn_putc = xccnputc_dom0; @@ -232,14 +234,15 @@ xc_attach(device_t dev) callout_reset(&xc_callout, XC_POLLTIME, xc_timeout, xccons); if (xen_start_info->flags & SIF_INITDOMAIN) { - PANIC_IF(bind_virq_to_irqhandler( - VIRQ_CONSOLE, - 0, - "console", - NULL, - xencons_priv_interrupt, - INTR_TYPE_TTY) < 0); + error = bind_virq_to_irqhandler( + VIRQ_CONSOLE, + 0, + "console", + NULL, + xencons_priv_interrupt, + sc, INTR_TYPE_TTY, NULL); + KASSERT(error >= 0, ("can't register console interrupt")); } diff --git a/sys/dev/xen/console/xencons_ring.c b/sys/dev/xen/console/xencons_ring.c index 3d232376..596b5de 100644 --- a/sys/dev/xen/console/xencons_ring.c +++ b/sys/dev/xen/console/xencons_ring.c @@ -15,19 +15,20 @@ __FBSDID("$FreeBSD$"); #include <sys/bus.h> #include <machine/stdarg.h> #include <machine/xen/xen-os.h> -#include <machine/xen/hypervisor.h> -#include <machine/xen/xen_intr.h> +#include <xen/hypervisor.h> +#include <xen/xen_intr.h> #include <sys/cons.h> #include <dev/xen/console/xencons_ring.h> -#include <machine/xen/evtchn.h> +#include <xen/evtchn.h> #include <xen/interface/io/console.h> #define console_evtchn console.domU.evtchn extern char *console_page; - +extern struct mtx cn_mtx; + static inline struct xencons_interface * xencons_interface(void) { @@ -82,6 +83,7 @@ xencons_handle_input(void *unused) struct xencons_interface *intf; XENCONS_RING_IDX cons, prod; + mtx_lock(&cn_mtx); intf = xencons_interface(); cons = intf->in_cons; @@ -99,6 +101,7 @@ xencons_handle_input(void *unused) notify_remote_via_evtchn(xen_start_info->console_evtchn); xencons_tx(); + mtx_unlock(&cn_mtx); } void diff --git a/sys/dev/xen/evtchn/evtchn_dev.c b/sys/dev/xen/evtchn/evtchn_dev.c index a206708..6925a22 100644 --- a/sys/dev/xen/evtchn/evtchn_dev.c +++ b/sys/dev/xen/evtchn/evtchn_dev.c @@ -26,13 +26,13 @@ __FBSDID("$FreeBSD$"); #include <machine/cpufunc.h> #include <machine/intr_machdep.h> #include <machine/xen-os.h> -#include <machine/xen_intr.h> +#include <xen/xen_intr.h> #include <machine/bus.h> #include <sys/rman.h> #include <machine/resource.h> #include <machine/synch_bitops.h> -#include <machine/hypervisor.h> +#include <xen/hypervisor.h> typedef struct evtchn_sotfc { diff --git a/sys/dev/xen/netfront/netfront.c b/sys/dev/xen/netfront/netfront.c index 607628f..7efeb20 100644 --- a/sys/dev/xen/netfront/netfront.c +++ b/sys/dev/xen/netfront/netfront.c @@ -62,9 +62,9 @@ __FBSDID("$FreeBSD$"); #include <machine/intr_machdep.h> #include <machine/xen/xen-os.h> -#include <machine/xen/hypervisor.h> -#include <machine/xen/xen_intr.h> -#include <machine/xen/evtchn.h> +#include <xen/hypervisor.h> +#include <xen/xen_intr.h> +#include <xen/evtchn.h> #include <xen/gnttab.h> #include <xen/interface/memory.h> #include <dev/xen/netfront/mbufq.h> @@ -363,24 +363,25 @@ makembuf (struct mbuf *buf) static int xen_net_read_mac(device_t dev, uint8_t mac[]) { - char *s; - int i; - char *e; - char *macstr = xenbus_read(XBT_NIL, xenbus_get_node(dev), "mac", NULL); - if (IS_ERR(macstr)) { - return PTR_ERR(macstr); - } + int error, i; + char *s, *e, *macstr; + + error = xenbus_read(XBT_NIL, xenbus_get_node(dev), "mac", NULL, + (void **) &macstr); + if (error) + return (error); + s = macstr; for (i = 0; i < ETHER_ADDR_LEN; i++) { mac[i] = strtoul(s, &e, 16); if (s == e || (e[0] != ':' && e[0] != 0)) { free(macstr, M_DEVBUF); - return ENOENT; + return (ENOENT); } s = &e[1]; } free(macstr, M_DEVBUF); - return 0; + return (0); } /** @@ -422,13 +423,11 @@ netfront_attach(device_t dev) * leave the device-layer structures intact so that this is transparent to the * rest of the kernel. */ -static int +static int netfront_resume(device_t dev) { struct netfront_info *info = device_get_softc(dev); - - DPRINTK("%s\n", xenbus_get_node(dev)); - + netif_disconnect_backend(info); return (0); } @@ -532,7 +531,7 @@ setup_device(device_t dev, struct netfront_info *info) { netif_tx_sring_t *txs; netif_rx_sring_t *rxs; - int err; + int error; struct ifnet *ifp; ifp = info->xn_ifp; @@ -545,51 +544,45 @@ setup_device(device_t dev, struct netfront_info *info) txs = (netif_tx_sring_t *)malloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT|M_ZERO); if (!txs) { - err = ENOMEM; - xenbus_dev_fatal(dev, err, "allocating tx ring page"); + error = ENOMEM; + xenbus_dev_fatal(dev, error, "allocating tx ring page"); goto fail; } SHARED_RING_INIT(txs); FRONT_RING_INIT(&info->tx, txs, PAGE_SIZE); - err = xenbus_grant_ring(dev, virt_to_mfn(txs)); - if (err < 0) + error = xenbus_grant_ring(dev, virt_to_mfn(txs), &info->tx_ring_ref); + if (error) goto fail; - info->tx_ring_ref = err; rxs = (netif_rx_sring_t *)malloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT|M_ZERO); if (!rxs) { - err = ENOMEM; - xenbus_dev_fatal(dev, err, "allocating rx ring page"); + error = ENOMEM; + xenbus_dev_fatal(dev, error, "allocating rx ring page"); goto fail; } SHARED_RING_INIT(rxs); FRONT_RING_INIT(&info->rx, rxs, PAGE_SIZE); - err = xenbus_grant_ring(dev, virt_to_mfn(rxs)); - if (err < 0) + error = xenbus_grant_ring(dev, virt_to_mfn(rxs), &info->rx_ring_ref); + if (error) goto fail; - info->rx_ring_ref = err; -#if 0 - network_connect(info); -#endif - err = bind_listening_port_to_irqhandler(xenbus_get_otherend_id(dev), - "xn", xn_intr, info, INTR_TYPE_NET | INTR_MPSAFE, NULL); + error = bind_listening_port_to_irqhandler(xenbus_get_otherend_id(dev), + "xn", xn_intr, info, INTR_TYPE_NET | INTR_MPSAFE, &info->irq); - if (err <= 0) { - xenbus_dev_fatal(dev, err, + if (error) { + xenbus_dev_fatal(dev, error, "bind_evtchn_to_irqhandler failed"); goto fail; } - info->irq = err; - + show_device(info); - return 0; + return (0); fail: netif_free(info); - return err; + return (error); } /** @@ -1225,7 +1218,7 @@ xennet_get_responses(struct netfront_info *np, 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 = (uintptr_t)m->m_ext.ext_arg1; mmu->ptr = ((vm_paddr_t)mfn << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE; mmu->val = pfn; @@ -1557,18 +1550,18 @@ xn_stop(struct netfront_info *sc) int network_connect(struct netfront_info *np) { - int i, requeue_idx, err; + int i, requeue_idx, error; grant_ref_t ref; netif_rx_request_t *req; u_int feature_rx_copy, feature_rx_flip; - err = xenbus_scanf(XBT_NIL, xenbus_get_otherend_path(np->xbdev), - "feature-rx-copy", "%u", &feature_rx_copy); - if (err != 1) + error = xenbus_scanf(XBT_NIL, xenbus_get_otherend_path(np->xbdev), + "feature-rx-copy", NULL, "%u", &feature_rx_copy); + if (error) feature_rx_copy = 0; - err = xenbus_scanf(XBT_NIL, xenbus_get_otherend_path(np->xbdev), - "feature-rx-flip", "%u", &feature_rx_flip); - if (err != 1) + error = xenbus_scanf(XBT_NIL, xenbus_get_otherend_path(np->xbdev), + "feature-rx-flip", NULL, "%u", &feature_rx_flip); + if (error) feature_rx_flip = 1; /* @@ -1581,9 +1574,9 @@ network_connect(struct netfront_info *np) XN_LOCK(np); /* Recovery procedure: */ - err = talk_to_backend(np->xbdev, np); - if (err) - return (err); + error = talk_to_backend(np->xbdev, np); + if (error) + return (error); /* Step 1: Reinitialise variables. */ netif_release_tx_bufs(np); @@ -1591,6 +1584,7 @@ network_connect(struct netfront_info *np) /* Step 2: Rebuild the RX buffer freelist and the RX ring itself. */ for (requeue_idx = 0, i = 0; i < NET_RX_RING_SIZE; i++) { struct mbuf *m; + u_long pfn; if (np->rx_mbufs[i] == NULL) continue; @@ -1598,15 +1592,16 @@ network_connect(struct netfront_info *np) m = np->rx_mbufs[requeue_idx] = xennet_get_rx_mbuf(np, i); ref = np->grant_rx_ref[requeue_idx] = xennet_get_rx_ref(np, i); req = RING_GET_REQUEST(&np->rx, requeue_idx); + pfn = vtophys(mtod(m, vm_offset_t)) >> PAGE_SHIFT; if (!np->copying_receiver) { gnttab_grant_foreign_transfer_ref(ref, xenbus_get_otherend_id(np->xbdev), - vtophys(mtod(m, vm_offset_t))); + pfn); } else { gnttab_grant_foreign_access_ref(ref, xenbus_get_otherend_id(np->xbdev), - vtophys(mtod(m, vm_offset_t)), 0); + PFNTOMFN(pfn), 0); } req->gref = ref; req->id = requeue_idx; @@ -1707,7 +1702,7 @@ create_netdev(device_t dev) ifp = np->xn_ifp = if_alloc(IFT_ETHER); ifp->if_softc = np; if_initname(ifp, "xn", device_get_unit(dev)); - ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX; + ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_ioctl = xn_ioctl; ifp->if_output = ether_output; ifp->if_start = xn_start; @@ -1777,11 +1772,14 @@ static void netif_free(struct netfront_info *info) #endif } - - static void netif_disconnect_backend(struct netfront_info *info) { - xn_stop(info); + XN_RX_LOCK(info); + XN_TX_LOCK(info); + netfront_carrier_off(info); + XN_TX_UNLOCK(info); + XN_RX_UNLOCK(info); + end_access(info->tx_ring_ref, info->tx.sring); end_access(info->rx_ring_ref, info->rx.sring); info->tx_ring_ref = GRANT_INVALID_REF; @@ -1789,12 +1787,9 @@ static void netif_disconnect_backend(struct netfront_info *info) info->tx.sring = NULL; info->rx.sring = NULL; -#if 0 if (info->irq) - unbind_from_irqhandler(info->irq, info->netdev); -#else - panic("FIX ME"); -#endif + unbind_from_irqhandler(info->irq); + info->irq = 0; } |