Wed Nov 30 01:36:38 2016 UTC ()
Don't call virtio_enqueue_abort when virtio_enqueue_reserve fails.
Pointed out by uwe@


(christos)
diff -r1.12 -r1.13 src/sys/dev/pci/ld_virtio.c
diff -r1.9 -r1.10 src/sys/dev/pci/viornd.c

cvs diff -r1.12 -r1.13 src/sys/dev/pci/ld_virtio.c (expand / switch to unified diff)

--- src/sys/dev/pci/ld_virtio.c 2016/09/27 03:33:32 1.12
+++ src/sys/dev/pci/ld_virtio.c 2016/11/30 01:36:38 1.13
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ld_virtio.c,v 1.12 2016/09/27 03:33:32 pgoyette Exp $ */ 1/* $NetBSD: ld_virtio.c,v 1.13 2016/11/30 01:36:38 christos 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: ld_virtio.c,v 1.12 2016/09/27 03:33:32 pgoyette Exp $"); 29__KERNEL_RCSID(0, "$NetBSD: ld_virtio.c,v 1.13 2016/11/30 01:36:38 christos 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/buf.h> 34#include <sys/buf.h>
35#include <sys/bufq.h> 35#include <sys/bufq.h>
36#include <sys/bus.h> 36#include <sys/bus.h>
37#include <sys/device.h> 37#include <sys/device.h>
38#include <sys/disk.h> 38#include <sys/disk.h>
39#include <sys/mutex.h> 39#include <sys/mutex.h>
40#include <sys/module.h> 40#include <sys/module.h>
41 41
42#include <dev/pci/pcidevs.h> 42#include <dev/pci/pcidevs.h>
@@ -389,27 +389,26 @@ ld_virtio_start(struct ld_softc *ld, str @@ -389,27 +389,26 @@ ld_virtio_start(struct ld_softc *ld, str
389 bp->b_data, bp->b_bcount, NULL, 389 bp->b_data, bp->b_bcount, NULL,
390 ((isread?BUS_DMA_READ:BUS_DMA_WRITE) 390 ((isread?BUS_DMA_READ:BUS_DMA_WRITE)
391 |BUS_DMA_NOWAIT)); 391 |BUS_DMA_NOWAIT));
392 if (r != 0) { 392 if (r != 0) {
393 aprint_error_dev(sc->sc_dev, 393 aprint_error_dev(sc->sc_dev,
394 "payload dmamap failed, error code %d\n", r); 394 "payload dmamap failed, error code %d\n", r);
395 virtio_enqueue_abort(vsc, vq, slot); 395 virtio_enqueue_abort(vsc, vq, slot);
396 return r; 396 return r;
397 } 397 }
398 398
399 r = virtio_enqueue_reserve(vsc, vq, slot, vr->vr_payload->dm_nsegs + 399 r = virtio_enqueue_reserve(vsc, vq, slot, vr->vr_payload->dm_nsegs +
400 VIRTIO_BLK_MIN_SEGMENTS); 400 VIRTIO_BLK_MIN_SEGMENTS);
401 if (r != 0) { 401 if (r != 0) {
402 virtio_enqueue_abort(vsc, vq, slot); 
403 bus_dmamap_unload(vsc->sc_dmat, vr->vr_payload); 402 bus_dmamap_unload(vsc->sc_dmat, vr->vr_payload);
404 return r; 403 return r;
405 } 404 }
406 405
407 vr->vr_bp = bp; 406 vr->vr_bp = bp;
408 vr->vr_hdr.type = isread?VIRTIO_BLK_T_IN:VIRTIO_BLK_T_OUT; 407 vr->vr_hdr.type = isread?VIRTIO_BLK_T_IN:VIRTIO_BLK_T_OUT;
409 vr->vr_hdr.ioprio = 0; 408 vr->vr_hdr.ioprio = 0;
410 vr->vr_hdr.sector = bp->b_rawblkno * sc->sc_ld.sc_secsize / 512; 409 vr->vr_hdr.sector = bp->b_rawblkno * sc->sc_ld.sc_secsize / 512;
411 410
412 bus_dmamap_sync(vsc->sc_dmat, vr->vr_cmdsts, 411 bus_dmamap_sync(vsc->sc_dmat, vr->vr_cmdsts,
413 0, sizeof(struct virtio_blk_req_hdr), 412 0, sizeof(struct virtio_blk_req_hdr),
414 BUS_DMASYNC_PREWRITE); 413 BUS_DMASYNC_PREWRITE);
415 bus_dmamap_sync(vsc->sc_dmat, vr->vr_payload, 414 bus_dmamap_sync(vsc->sc_dmat, vr->vr_payload,

cvs diff -r1.9 -r1.10 src/sys/dev/pci/viornd.c (expand / switch to unified diff)

--- src/sys/dev/pci/viornd.c 2015/10/27 16:04:19 1.9
+++ src/sys/dev/pci/viornd.c 2016/11/30 01:36:38 1.10
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: viornd.c,v 1.9 2015/10/27 16:04:19 christos Exp $ */ 1/* $NetBSD: viornd.c,v 1.10 2016/11/30 01:36:38 christos Exp $ */
2/* $OpenBSD: viornd.c,v 1.1 2014/01/21 21:14:58 sf Exp $ */ 2/* $OpenBSD: viornd.c,v 1.1 2014/01/21 21:14:58 sf Exp $ */
3 3
4/* 4/*
5 * Copyright (c) 2014 The NetBSD Foundation, Inc. 5 * Copyright (c) 2014 The NetBSD Foundation, Inc.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to The NetBSD Foundation 8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Thor Lancelot Simon (tls@NetBSD.org). 9 * by Thor Lancelot Simon (tls@NetBSD.org).
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -97,27 +97,26 @@ viornd_get(size_t bytes, void *priv) @@ -97,27 +97,26 @@ viornd_get(size_t bytes, void *priv)
97#endif 97#endif
98 mutex_enter(&sc->sc_mutex); 98 mutex_enter(&sc->sc_mutex);
99 99
100 if (sc->sc_active) { 100 if (sc->sc_active) {
101 goto out; 101 goto out;
102 } 102 }
103 103
104 bus_dmamap_sync(vsc->sc_dmat, sc->sc_dmamap, 0, VIORND_BUFSIZE, 104 bus_dmamap_sync(vsc->sc_dmat, sc->sc_dmamap, 0, VIORND_BUFSIZE,
105 BUS_DMASYNC_PREREAD); 105 BUS_DMASYNC_PREREAD);
106 if (virtio_enqueue_prep(vsc, vq, &slot)) { 106 if (virtio_enqueue_prep(vsc, vq, &slot)) {
107 goto out; 107 goto out;
108 } 108 }
109 if (virtio_enqueue_reserve(vsc, vq, slot, 1)) { 109 if (virtio_enqueue_reserve(vsc, vq, slot, 1)) {
110 virtio_enqueue_abort(vsc, vq, slot); 
111 goto out; 110 goto out;
112 } 111 }
113 virtio_enqueue(vsc, vq, slot, sc->sc_dmamap, 0); 112 virtio_enqueue(vsc, vq, slot, sc->sc_dmamap, 0);
114 virtio_enqueue_commit(vsc, vq, slot, 1); 113 virtio_enqueue_commit(vsc, vq, slot, 1);
115 sc->sc_active = true; 114 sc->sc_active = true;
116out: 115out:
117 mutex_exit(&sc->sc_mutex); 116 mutex_exit(&sc->sc_mutex);
118} 117}
119 118
120int 119int
121viornd_match(device_t parent, cfdata_t match, void *aux) 120viornd_match(device_t parent, cfdata_t match, void *aux)
122{ 121{
123 struct virtio_softc *va = aux; 122 struct virtio_softc *va = aux;