Fri Dec 6 12:46:06 2019 UTC ()
Clear the allocated memory in hyperv_dma_alloc().


(nonaka)
diff -r1.2 -r1.3 src/sys/dev/hyperv/hyperv_common.c
diff -r1.5 -r1.6 src/sys/dev/hyperv/vmbus.c

cvs diff -r1.2 -r1.3 src/sys/dev/hyperv/hyperv_common.c (expand / switch to unified diff)

--- src/sys/dev/hyperv/hyperv_common.c 2019/05/31 04:23:19 1.2
+++ src/sys/dev/hyperv/hyperv_common.c 2019/12/06 12:46:06 1.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: hyperv_common.c,v 1.2 2019/05/31 04:23:19 nonaka Exp $ */ 1/* $NetBSD: hyperv_common.c,v 1.3 2019/12/06 12:46:06 nonaka Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2009-2012,2016-2017 Microsoft Corp. 4 * Copyright (c) 2009-2012,2016-2017 Microsoft Corp.
5 * Copyright (c) 2012 NetApp Inc. 5 * Copyright (c) 2012 NetApp Inc.
6 * Copyright (c) 2012 Citrix Inc. 6 * Copyright (c) 2012 Citrix Inc.
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice unmodified, this list of conditions, and the following 13 * notice unmodified, this list of conditions, and the following
14 * disclaimer. 14 * disclaimer.
@@ -19,27 +19,27 @@ @@ -19,27 +19,27 @@
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31#include <sys/cdefs.h> 31#include <sys/cdefs.h>
32__KERNEL_RCSID(0, "$NetBSD: hyperv_common.c,v 1.2 2019/05/31 04:23:19 nonaka Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: hyperv_common.c,v 1.3 2019/12/06 12:46:06 nonaka Exp $");
33 33
34#include "hyperv.h" 34#include "hyperv.h"
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/systm.h> 37#include <sys/systm.h>
38#include <sys/kernel.h> 38#include <sys/kernel.h>
39#include <sys/bus.h> 39#include <sys/bus.h>
40#include <sys/kmem.h> 40#include <sys/kmem.h>
41 41
42#include <dev/hyperv/hypervreg.h> 42#include <dev/hyperv/hypervreg.h>
43#include <dev/hyperv/hypervvar.h> 43#include <dev/hyperv/hypervvar.h>
44 44
45hyperv_tc64_t hyperv_tc64; 45hyperv_tc64_t hyperv_tc64;
@@ -145,26 +145,30 @@ hyperv_dma_alloc(bus_dma_tag_t dmat, str @@ -145,26 +145,30 @@ hyperv_dma_alloc(bus_dma_tag_t dmat, str
145 if (error) { 145 if (error) {
146 printf("%s: bus_dmamap_create failed: error=%d\n", 146 printf("%s: bus_dmamap_create failed: error=%d\n",
147 __func__, error); 147 __func__, error);
148 goto fail3; 148 goto fail3;
149 } 149 }
150 error = bus_dmamap_load(dmat, dma->map, dma->addr, size, NULL, 150 error = bus_dmamap_load(dmat, dma->map, dma->addr, size, NULL,
151 BUS_DMA_READ | BUS_DMA_WRITE | dmaflags); 151 BUS_DMA_READ | BUS_DMA_WRITE | dmaflags);
152 if (error) { 152 if (error) {
153 printf("%s: bus_dmamap_load failed: error=%d\n", 153 printf("%s: bus_dmamap_load failed: error=%d\n",
154 __func__, error); 154 __func__, error);
155 goto fail4; 155 goto fail4;
156 } 156 }
157 157
 158 memset(dma->addr, 0, dma->map->dm_mapsize);
 159 bus_dmamap_sync(dmat, dma->map, 0, dma->map->dm_mapsize,
 160 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
 161
158 return dma->addr; 162 return dma->addr;
159 163
160fail4: bus_dmamap_destroy(dmat, dma->map); 164fail4: bus_dmamap_destroy(dmat, dma->map);
161fail3: bus_dmamem_unmap(dmat, dma->addr, size); 165fail3: bus_dmamem_unmap(dmat, dma->addr, size);
162 dma->addr = NULL; 166 dma->addr = NULL;
163fail2: bus_dmamem_free(dmat, dma->segs, rseg); 167fail2: bus_dmamem_free(dmat, dma->segs, rseg);
164fail1: kmem_free(dma->segs, sizeof(*dma->segs) * nsegs); 168fail1: kmem_free(dma->segs, sizeof(*dma->segs) * nsegs);
165 dma->segs = NULL; 169 dma->segs = NULL;
166 dma->nsegs = 0; 170 dma->nsegs = 0;
167 return NULL; 171 return NULL;
168} 172}
169 173
170void 174void

cvs diff -r1.5 -r1.6 src/sys/dev/hyperv/vmbus.c (expand / switch to unified diff)

--- src/sys/dev/hyperv/vmbus.c 2019/11/22 12:30:32 1.5
+++ src/sys/dev/hyperv/vmbus.c 2019/12/06 12:46:06 1.6
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vmbus.c,v 1.5 2019/11/22 12:30:32 nonaka Exp $ */ 1/* $NetBSD: vmbus.c,v 1.6 2019/12/06 12:46:06 nonaka Exp $ */
2/* $OpenBSD: hyperv.c,v 1.43 2017/06/27 13:56:15 mikeb Exp $ */ 2/* $OpenBSD: hyperv.c,v 1.43 2017/06/27 13:56:15 mikeb Exp $ */
3 3
4/*- 4/*-
5 * Copyright (c) 2009-2012 Microsoft Corp. 5 * Copyright (c) 2009-2012 Microsoft Corp.
6 * Copyright (c) 2012 NetApp Inc. 6 * Copyright (c) 2012 NetApp Inc.
7 * Copyright (c) 2012 Citrix Inc. 7 * Copyright (c) 2012 Citrix Inc.
8 * Copyright (c) 2016 Mike Belopuhov <mike@esdenera.com> 8 * Copyright (c) 2016 Mike Belopuhov <mike@esdenera.com>
9 * All rights reserved. 9 * All rights reserved.
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
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33/* 33/*
34 * The OpenBSD port was done under funding by Esdenera Networks GmbH. 34 * The OpenBSD port was done under funding by Esdenera Networks GmbH.
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__KERNEL_RCSID(0, "$NetBSD: vmbus.c,v 1.5 2019/11/22 12:30:32 nonaka Exp $"); 38__KERNEL_RCSID(0, "$NetBSD: vmbus.c,v 1.6 2019/12/06 12:46:06 nonaka Exp $");
39 39
40#include <sys/param.h> 40#include <sys/param.h>
41#include <sys/systm.h> 41#include <sys/systm.h>
42#include <sys/device.h> 42#include <sys/device.h>
43#include <sys/atomic.h> 43#include <sys/atomic.h>
44#include <sys/bitops.h> 44#include <sys/bitops.h>
45#include <sys/bus.h> 45#include <sys/bus.h>
46#include <sys/cpu.h> 46#include <sys/cpu.h>
47#include <sys/intr.h> 47#include <sys/intr.h>
48#include <sys/kmem.h> 48#include <sys/kmem.h>
49#include <sys/module.h> 49#include <sys/module.h>
50#include <sys/mutex.h> 50#include <sys/mutex.h>
51#include <sys/xcall.h> 51#include <sys/xcall.h>
@@ -975,27 +975,26 @@ static struct vmbus_channel * @@ -975,27 +975,26 @@ static struct vmbus_channel *
975vmbus_channel_alloc(struct vmbus_softc *sc) 975vmbus_channel_alloc(struct vmbus_softc *sc)
976{ 976{
977 struct vmbus_channel *ch; 977 struct vmbus_channel *ch;
978 978
979 ch = kmem_zalloc(sizeof(*ch), cold ? KM_NOSLEEP : KM_SLEEP); 979 ch = kmem_zalloc(sizeof(*ch), cold ? KM_NOSLEEP : KM_SLEEP);
980 980
981 ch->ch_monprm = hyperv_dma_alloc(sc->sc_dmat, &ch->ch_monprm_dma, 981 ch->ch_monprm = hyperv_dma_alloc(sc->sc_dmat, &ch->ch_monprm_dma,
982 sizeof(*ch->ch_monprm), 8, 0, 1); 982 sizeof(*ch->ch_monprm), 8, 0, 1);
983 if (ch->ch_monprm == NULL) { 983 if (ch->ch_monprm == NULL) {
984 device_printf(sc->sc_dev, "monprm alloc failed\n"); 984 device_printf(sc->sc_dev, "monprm alloc failed\n");
985 kmem_free(ch, sizeof(*ch)); 985 kmem_free(ch, sizeof(*ch));
986 return NULL; 986 return NULL;
987 } 987 }
988 memset(ch->ch_monprm, 0, sizeof(*ch->ch_monprm)); 
989 988
990 ch->ch_refs = 1; 989 ch->ch_refs = 1;
991 ch->ch_sc = sc; 990 ch->ch_sc = sc;
992 mutex_init(&ch->ch_subchannel_lock, MUTEX_DEFAULT, IPL_NET); 991 mutex_init(&ch->ch_subchannel_lock, MUTEX_DEFAULT, IPL_NET);
993 TAILQ_INIT(&ch->ch_subchannels); 992 TAILQ_INIT(&ch->ch_subchannels);
994 993
995 ch->ch_state = VMBUS_CHANSTATE_CLOSED; 994 ch->ch_state = VMBUS_CHANSTATE_CLOSED;
996 995
997 return ch; 996 return ch;
998} 997}
999 998
1000static void 999static void
1001vmbus_channel_free(struct vmbus_channel *ch) 1000vmbus_channel_free(struct vmbus_channel *ch)
@@ -1254,27 +1253,26 @@ static int @@ -1254,27 +1253,26 @@ static int
1254vmbus_channel_ring_create(struct vmbus_channel *ch, uint32_t buflen) 1253vmbus_channel_ring_create(struct vmbus_channel *ch, uint32_t buflen)
1255{ 1254{
1256 struct vmbus_softc *sc = ch->ch_sc; 1255 struct vmbus_softc *sc = ch->ch_sc;
1257 1256
1258 buflen = roundup(buflen, PAGE_SIZE) + sizeof(struct vmbus_bufring); 1257 buflen = roundup(buflen, PAGE_SIZE) + sizeof(struct vmbus_bufring);
1259 ch->ch_ring_size = 2 * buflen; 1258 ch->ch_ring_size = 2 * buflen;
1260 ch->ch_ring = hyperv_dma_alloc(sc->sc_dmat, &ch->ch_ring_dma, 1259 ch->ch_ring = hyperv_dma_alloc(sc->sc_dmat, &ch->ch_ring_dma,
1261 ch->ch_ring_size, PAGE_SIZE, 0, 1); /* page aligned memory */ 1260 ch->ch_ring_size, PAGE_SIZE, 0, 1); /* page aligned memory */
1262 if (ch->ch_ring == NULL) { 1261 if (ch->ch_ring == NULL) {
1263 device_printf(sc->sc_dev, 1262 device_printf(sc->sc_dev,
1264 "failed to allocate channel ring\n"); 1263 "failed to allocate channel ring\n");
1265 return ENOMEM; 1264 return ENOMEM;
1266 } 1265 }
1267 memset(ch->ch_ring, 0, ch->ch_ring_size); 
1268 1266
1269 memset(&ch->ch_wrd, 0, sizeof(ch->ch_wrd)); 1267 memset(&ch->ch_wrd, 0, sizeof(ch->ch_wrd));
1270 ch->ch_wrd.rd_ring = (struct vmbus_bufring *)ch->ch_ring; 1268 ch->ch_wrd.rd_ring = (struct vmbus_bufring *)ch->ch_ring;
1271 ch->ch_wrd.rd_size = buflen; 1269 ch->ch_wrd.rd_size = buflen;
1272 ch->ch_wrd.rd_dsize = buflen - sizeof(struct vmbus_bufring); 1270 ch->ch_wrd.rd_dsize = buflen - sizeof(struct vmbus_bufring);
1273 mutex_init(&ch->ch_wrd.rd_lock, MUTEX_DEFAULT, IPL_NET); 1271 mutex_init(&ch->ch_wrd.rd_lock, MUTEX_DEFAULT, IPL_NET);
1274 1272
1275 memset(&ch->ch_rrd, 0, sizeof(ch->ch_rrd)); 1273 memset(&ch->ch_rrd, 0, sizeof(ch->ch_rrd));
1276 ch->ch_rrd.rd_ring = (struct vmbus_bufring *)((uint8_t *)ch->ch_ring + 1274 ch->ch_rrd.rd_ring = (struct vmbus_bufring *)((uint8_t *)ch->ch_ring +
1277 buflen); 1275 buflen);
1278 ch->ch_rrd.rd_size = buflen; 1276 ch->ch_rrd.rd_size = buflen;
1279 ch->ch_rrd.rd_dsize = buflen - sizeof(struct vmbus_bufring); 1277 ch->ch_rrd.rd_dsize = buflen - sizeof(struct vmbus_bufring);
1280 mutex_init(&ch->ch_rrd.rd_lock, MUTEX_DEFAULT, IPL_NET); 1278 mutex_init(&ch->ch_rrd.rd_lock, MUTEX_DEFAULT, IPL_NET);