Tue Apr 14 13:02:40 2020 UTC ()
add forgotten mutex_exit() in detach, which caused panic in uvm_unmap1()
due to held spin lock


(jdolecek)
diff -r1.109 -r1.110 src/sys/arch/xen/xen/xbd_xenbus.c

cvs diff -r1.109 -r1.110 src/sys/arch/xen/xen/xbd_xenbus.c (expand / switch to unified diff)

--- src/sys/arch/xen/xen/xbd_xenbus.c 2020/04/14 09:27:28 1.109
+++ src/sys/arch/xen/xen/xbd_xenbus.c 2020/04/14 13:02:40 1.110
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: xbd_xenbus.c,v 1.109 2020/04/14 09:27:28 jdolecek Exp $ */ 1/* $NetBSD: xbd_xenbus.c,v 1.110 2020/04/14 13:02:40 jdolecek Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2006 Manuel Bouyer. 4 * Copyright (c) 2006 Manuel Bouyer.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
@@ -40,27 +40,27 @@ @@ -40,27 +40,27 @@
40 * - initiate request: xbdread/write/open/ioctl/.. 40 * - initiate request: xbdread/write/open/ioctl/..
41 * - depending on operation, it is handled directly by disk(9) subsystem or 41 * - depending on operation, it is handled directly by disk(9) subsystem or
42 * goes through physio(9) first. 42 * goes through physio(9) first.
43 * - the request is ultimately processed by xbd_diskstart() that prepares the 43 * - the request is ultimately processed by xbd_diskstart() that prepares the
44 * xbd requests, post them in the ring I/O queue, then signal the backend. 44 * xbd requests, post them in the ring I/O queue, then signal the backend.
45 * 45 *
46 * When a response is available in the queue, the backend signals the frontend 46 * When a response is available in the queue, the backend signals the frontend
47 * via its event channel. This triggers xbd_handler(), which will link back 47 * via its event channel. This triggers xbd_handler(), which will link back
48 * the response to its request through the request ID, and mark the I/O as 48 * the response to its request through the request ID, and mark the I/O as
49 * completed. 49 * completed.
50 */ 50 */
51 51
52#include <sys/cdefs.h> 52#include <sys/cdefs.h>
53__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.109 2020/04/14 09:27:28 jdolecek Exp $"); 53__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.110 2020/04/14 13:02:40 jdolecek Exp $");
54 54
55#include "opt_xen.h" 55#include "opt_xen.h"
56 56
57 57
58#include <sys/param.h> 58#include <sys/param.h>
59#include <sys/buf.h> 59#include <sys/buf.h>
60#include <sys/bufq.h> 60#include <sys/bufq.h>
61#include <sys/device.h> 61#include <sys/device.h>
62#include <sys/disk.h> 62#include <sys/disk.h>
63#include <sys/disklabel.h> 63#include <sys/disklabel.h>
64#include <sys/conf.h> 64#include <sys/conf.h>
65#include <sys/fcntl.h> 65#include <sys/fcntl.h>
66#include <sys/kernel.h> 66#include <sys/kernel.h>
@@ -383,26 +383,27 @@ xbd_xenbus_detach(device_t dev, int flag @@ -383,26 +383,27 @@ xbd_xenbus_detach(device_t dev, int flag
383 383
384 /* detach disk */ 384 /* detach disk */
385 disk_detach(&sc->sc_dksc.sc_dkdev); 385 disk_detach(&sc->sc_dksc.sc_dkdev);
386 disk_destroy(&sc->sc_dksc.sc_dkdev); 386 disk_destroy(&sc->sc_dksc.sc_dkdev);
387 dk_detach(&sc->sc_dksc); 387 dk_detach(&sc->sc_dksc);
388 } 388 }
389 389
390 hypervisor_mask_event(sc->sc_evtchn); 390 hypervisor_mask_event(sc->sc_evtchn);
391 xen_intr_disestablish(sc->sc_ih); 391 xen_intr_disestablish(sc->sc_ih);
392 392
393 mutex_enter(&sc->sc_lock); 393 mutex_enter(&sc->sc_lock);
394 while (xengnt_status(sc->sc_ring_gntref)) 394 while (xengnt_status(sc->sc_ring_gntref))
395 cv_timedwait(&sc->sc_detach_cv, &sc->sc_lock, hz/2); 395 cv_timedwait(&sc->sc_detach_cv, &sc->sc_lock, hz/2);
 396 mutex_exit(&sc->sc_lock);
396 397
397 xengnt_revoke_access(sc->sc_ring_gntref); 398 xengnt_revoke_access(sc->sc_ring_gntref);
398 uvm_km_free(kernel_map, (vaddr_t)sc->sc_ring.sring, 399 uvm_km_free(kernel_map, (vaddr_t)sc->sc_ring.sring,
399 PAGE_SIZE, UVM_KMF_WIRED); 400 PAGE_SIZE, UVM_KMF_WIRED);
400 401
401 for (i = 0; i < XBD_RING_SIZE; i++) { 402 for (i = 0; i < XBD_RING_SIZE; i++) {
402 if (sc->sc_reqs[i].req_dmamap != NULL) { 403 if (sc->sc_reqs[i].req_dmamap != NULL) {
403 bus_dmamap_destroy(sc->sc_xbusd->xbusd_dmat, 404 bus_dmamap_destroy(sc->sc_xbusd->xbusd_dmat,
404 sc->sc_reqs[i].req_dmamap); 405 sc->sc_reqs[i].req_dmamap);
405 sc->sc_reqs[i].req_dmamap = NULL; 406 sc->sc_reqs[i].req_dmamap = NULL;
406 } 407 }
407 } 408 }
408 409