Sat Sep 7 16:01:25 2013 UTC ()
Pull up following revision(s) (requested by tsutsui in ticket #931):
	sys/dev/pci/virtio.c: revision 1.4
Make sure to check if the driver has a valid intr handler in virtio_detach().
Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.
Should be pulled up to netbsd-6 branches.


(bouyer)
diff -r1.3 -r1.3.14.1 src/sys/dev/pci/virtio.c

cvs diff -r1.3 -r1.3.14.1 src/sys/dev/pci/virtio.c (expand / switch to unified diff)

--- src/sys/dev/pci/virtio.c 2011/11/02 23:05:52 1.3
+++ src/sys/dev/pci/virtio.c 2013/09/07 16:01:25 1.3.14.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: virtio.c,v 1.3 2011/11/02 23:05:52 njoly Exp $ */ 1/* $NetBSD: virtio.c,v 1.3.14.1 2013/09/07 16:01:25 bouyer Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2010 Minoura Makoto. 4 * Copyright (c) 2010 Minoura Makoto.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -16,27 +16,27 @@ @@ -16,27 +16,27 @@
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28#include <sys/cdefs.h> 28#include <sys/cdefs.h>
29__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.3 2011/11/02 23:05:52 njoly Exp $"); 29__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.3.14.1 2013/09/07 16:01:25 bouyer Exp $");
30 30
31#include <sys/param.h> 31#include <sys/param.h>
32#include <sys/systm.h> 32#include <sys/systm.h>
33#include <sys/kernel.h> 33#include <sys/kernel.h>
34#include <sys/atomic.h> 34#include <sys/atomic.h>
35#include <sys/bus.h> 35#include <sys/bus.h>
36#include <sys/device.h> 36#include <sys/device.h>
37#include <sys/kmem.h> 37#include <sys/kmem.h>
38 38
39#include <dev/pci/pcidevs.h> 39#include <dev/pci/pcidevs.h>
40#include <dev/pci/pcireg.h> 40#include <dev/pci/pcireg.h>
41#include <dev/pci/pcivar.h> 41#include <dev/pci/pcivar.h>
42 42
@@ -189,28 +189,30 @@ virtio_attach(device_t parent, device_t  @@ -189,28 +189,30 @@ virtio_attach(device_t parent, device_t
189static int 189static int
190virtio_detach(device_t self, int flags) 190virtio_detach(device_t self, int flags)
191{ 191{
192 struct virtio_softc *sc = device_private(self); 192 struct virtio_softc *sc = device_private(self);
193 int r; 193 int r;
194 194
195 if (sc->sc_child != 0 && sc->sc_child != (void*)1) { 195 if (sc->sc_child != 0 && sc->sc_child != (void*)1) {
196 r = config_detach(sc->sc_child, flags); 196 r = config_detach(sc->sc_child, flags);
197 if (r) 197 if (r)
198 return r; 198 return r;
199 } 199 }
200 KASSERT(sc->sc_child == 0 || sc->sc_child == (void*)1); 200 KASSERT(sc->sc_child == 0 || sc->sc_child == (void*)1);
201 KASSERT(sc->sc_vqs == 0); 201 KASSERT(sc->sc_vqs == 0);
202 pci_intr_disestablish(sc->sc_pc, sc->sc_ih); 202 if (sc->sc_ih != NULL) {
203 sc->sc_ih = 0; 203 pci_intr_disestablish(sc->sc_pc, sc->sc_ih);
 204 sc->sc_ih = NULL;
 205 }
204 if (sc->sc_iosize) 206 if (sc->sc_iosize)
205 bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_iosize); 207 bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_iosize);
206 sc->sc_iosize = 0; 208 sc->sc_iosize = 0;
207 209
208 return 0; 210 return 0;
209} 211}
210 212
211/* 213/*
212 * Reset the device. 214 * Reset the device.
213 */ 215 */
214/* 216/*
215 * To reset the device to a known state, do following: 217 * To reset the device to a known state, do following:
216 * virtio_reset(sc); // this will stop the device activity 218 * virtio_reset(sc); // this will stop the device activity