Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/pci Audit unload/unmap v.s. free against DMA buffer ...
details: https://anonhg.NetBSD.org/src/rev/60777fde0a7e
branches: trunk
changeset: 366363:60777fde0a7e
user: rin <rin%NetBSD.org@localhost>
date: Mon May 23 13:53:37 2022 +0000
description:
Audit unload/unmap v.s. free against DMA buffer for sys/dev/pci;
make sure that bus_dmamap_unload(9) [or bus_dmamap_destroy(9)] or
bus_dmamem_unmap(9) are preceding to freeing DMA buffer, if it is
loaded or mapped, respectively.
This is mandatory for some archs. See, e.g.:
http://www.nerv.org/netbsd/?q=id:20210511T013030Z.013443cc790088147e4beed43f53dedabeaf9312
http://www.nerv.org/netbsd/?q=id:20220511T172220Z.561179f0b6fcc5b9cd73e274f69d74e2ce9e4c93
XXX XXX XXX
Compile test only (for amd64/ALL).
Thanks riastradh@ for double check.
diffstat:
sys/dev/pci/bktr/bktr_os.c | 5 +++--
sys/dev/pci/esm.c | 12 ++++++------
sys/dev/pci/if_bwfm_pci.c | 5 +++--
sys/dev/pci/if_ena.c | 10 +++++-----
sys/dev/pci/if_iwi.c | 29 ++++++++++++++---------------
sys/dev/pci/if_ixl.c | 11 ++++++-----
sys/dev/pci/if_sk.c | 10 +++++-----
sys/dev/pci/if_ti.c | 43 ++++++++++++++++++++++++-------------------
sys/dev/pci/if_vge.c | 8 ++++----
sys/dev/pci/ubsec.c | 10 +++++-----
10 files changed, 75 insertions(+), 68 deletions(-)
diffs (truncated from 473 to 300 lines):
diff -r 13bcf6e1c8d3 -r 60777fde0a7e sys/dev/pci/bktr/bktr_os.c
--- a/sys/dev/pci/bktr/bktr_os.c Mon May 23 12:17:17 2022 +0000
+++ b/sys/dev/pci/bktr/bktr_os.c Mon May 23 13:53:37 2022 +0000
@@ -1,6 +1,6 @@
/* $SourceForge: bktr_os.c,v 1.5 2003/03/11 23:11:25 thomasklausner Exp $ */
-/* $NetBSD: bktr_os.c,v 1.68 2018/12/09 11:22:35 jdolecek Exp $ */
+/* $NetBSD: bktr_os.c,v 1.69 2022/05/23 13:53:37 rin Exp $ */
/* $FreeBSD: src/sys/dev/bktr/bktr_os.c,v 1.20 2000/10/20 08:16:53 roger Exp$ */
/*
@@ -51,7 +51,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bktr_os.c,v 1.68 2018/12/09 11:22:35 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bktr_os.c,v 1.69 2022/05/23 13:53:37 rin Exp $");
#ifdef __FreeBSD__
#include "bktr.h"
@@ -1624,6 +1624,7 @@
{
bus_dma_tag_t dmat = bktr->dmat;
+ bus_dmamap_unload(dmat, dmap);
#ifdef __NetBSD__
bus_dmamem_unmap(dmat, (void *)kva, dmap->dm_mapsize);
#else
diff -r 13bcf6e1c8d3 -r 60777fde0a7e sys/dev/pci/esm.c
--- a/sys/dev/pci/esm.c Mon May 23 12:17:17 2022 +0000
+++ b/sys/dev/pci/esm.c Mon May 23 13:53:37 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: esm.c,v 1.65 2020/04/19 08:18:19 isaki Exp $ */
+/* $NetBSD: esm.c,v 1.66 2022/05/23 13:53:37 rin Exp $ */
/*-
* Copyright (c) 2002, 2003 Matt Fredette
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: esm.c,v 1.65 2020/04/19 08:18:19 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: esm.c,v 1.66 2022/05/23 13:53:37 rin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -1418,13 +1418,13 @@
if (p->size == 0)
return;
- bus_dmamem_free(sc->dmat, p->segs, p->nsegs);
+ bus_dmamap_unload(sc->dmat, p->map);
+
+ bus_dmamap_destroy(sc->dmat, p->map);
bus_dmamem_unmap(sc->dmat, p->addr, p->size);
- bus_dmamap_destroy(sc->dmat, p->map);
-
- bus_dmamap_unload(sc->dmat, p->map);
+ bus_dmamem_free(sc->dmat, p->segs, p->nsegs);
p->size = 0;
}
diff -r 13bcf6e1c8d3 -r 60777fde0a7e sys/dev/pci/if_bwfm_pci.c
--- a/sys/dev/pci/if_bwfm_pci.c Mon May 23 12:17:17 2022 +0000
+++ b/sys/dev/pci/if_bwfm_pci.c Mon May 23 13:53:37 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_bwfm_pci.c,v 1.12 2022/04/24 07:11:31 skrll Exp $ */
+/* $NetBSD: if_bwfm_pci.c,v 1.13 2022/05/23 13:53:37 rin Exp $ */
/* $OpenBSD: if_bwfm_pci.c,v 1.18 2018/02/08 05:00:38 patrick Exp $ */
/*
* Copyright (c) 2010-2016 Broadcom Corporation
@@ -18,7 +18,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_bwfm_pci.c,v 1.12 2022/04/24 07:11:31 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bwfm_pci.c,v 1.13 2022/05/23 13:53:37 rin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -911,6 +911,7 @@
void
bwfm_pci_dmamem_free(struct bwfm_pci_softc *sc, struct bwfm_pci_dmamem *bdm)
{
+ bus_dmamap_unload(sc->sc_dmat, bdm->bdm_map);
bus_dmamem_unmap(sc->sc_dmat, bdm->bdm_kva, bdm->bdm_size);
bus_dmamem_free(sc->sc_dmat, &bdm->bdm_seg, 1);
bus_dmamap_destroy(sc->sc_dmat, bdm->bdm_map);
diff -r 13bcf6e1c8d3 -r 60777fde0a7e sys/dev/pci/if_ena.c
--- a/sys/dev/pci/if_ena.c Mon May 23 12:17:17 2022 +0000
+++ b/sys/dev/pci/if_ena.c Mon May 23 13:53:37 2022 +0000
@@ -36,7 +36,7 @@
#if 0
__FBSDID("$FreeBSD: head/sys/dev/ena/ena.c 333456 2018-05-10 09:37:54Z mw $");
#endif
-__KERNEL_RCSID(0, "$NetBSD: if_ena.c,v 1.32 2021/09/23 10:31:23 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ena.c,v 1.33 2022/05/23 13:53:37 rin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -793,12 +793,12 @@
/* Free buffer DMA maps, */
for (int i = 0; i < tx_ring->ring_size; i++) {
- m_freem(tx_ring->tx_buffer_info[i].mbuf);
- tx_ring->tx_buffer_info[i].mbuf = NULL;
bus_dmamap_unload(adapter->sc_dmat,
tx_ring->tx_buffer_info[i].map);
bus_dmamap_destroy(adapter->sc_dmat,
tx_ring->tx_buffer_info[i].map);
+ m_freem(tx_ring->tx_buffer_info[i].mbuf);
+ tx_ring->tx_buffer_info[i].mbuf = NULL;
}
/* And free allocated memory. */
@@ -994,12 +994,12 @@
/* Free buffer DMA maps, */
for (int i = 0; i < rx_ring->ring_size; i++) {
- m_freem(rx_ring->rx_buffer_info[i].mbuf);
- rx_ring->rx_buffer_info[i].mbuf = NULL;
bus_dmamap_unload(adapter->sc_dmat,
rx_ring->rx_buffer_info[i].map);
bus_dmamap_destroy(adapter->sc_dmat,
rx_ring->rx_buffer_info[i].map);
+ m_freem(rx_ring->rx_buffer_info[i].mbuf);
+ rx_ring->rx_buffer_info[i].mbuf = NULL;
}
#ifdef LRO
diff -r 13bcf6e1c8d3 -r 60777fde0a7e sys/dev/pci/if_iwi.c
--- a/sys/dev/pci/if_iwi.c Mon May 23 12:17:17 2022 +0000
+++ b/sys/dev/pci/if_iwi.c Mon May 23 13:53:37 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_iwi.c,v 1.117 2021/09/09 23:26:36 riastradh Exp $ */
+/* $NetBSD: if_iwi.c,v 1.118 2022/05/23 13:53:37 rin Exp $ */
/* $OpenBSD: if_iwi.c,v 1.111 2010/11/15 19:11:57 damien Exp $ */
/*-
@@ -19,7 +19,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_iwi.c,v 1.117 2021/09/09 23:26:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_iwi.c,v 1.118 2022/05/23 13:53:37 rin Exp $");
/*-
* Intel(R) PRO/Wireless 2200BG/2225BG/2915ABG driver
@@ -661,11 +661,6 @@
for (i = 0; i < ring->count; i++) {
data = &ring->data[i];
-
- if (data->m != NULL) {
- m_freem(data->m);
- data->m = NULL;
- }
if (data->map != NULL) {
bus_dmamap_sync(sc->sc_dmat, data->map, 0,
@@ -673,6 +668,11 @@
bus_dmamap_unload(sc->sc_dmat, data->map);
}
+ if (data->m != NULL) {
+ m_freem(data->m);
+ data->m = NULL;
+ }
+
if (data->ni != NULL) {
ieee80211_free_node(data->ni);
data->ni = NULL;
@@ -702,14 +702,14 @@
for (i = 0; i < ring->count; i++) {
data = &ring->data[i];
- if (data->m != NULL) {
- m_freem(data->m);
- }
-
if (data->map != NULL) {
bus_dmamap_unload(sc->sc_dmat, data->map);
bus_dmamap_destroy(sc->sc_dmat, data->map);
}
+
+ if (data->m != NULL) {
+ m_freem(data->m);
+ }
}
}
@@ -776,15 +776,14 @@
for (i = 0; i < ring->count; i++) {
data = &ring->data[i];
- if (data->m != NULL) {
- m_freem(data->m);
- }
-
if (data->map != NULL) {
bus_dmamap_unload(sc->sc_dmat, data->map);
bus_dmamap_destroy(sc->sc_dmat, data->map);
}
+ if (data->m != NULL) {
+ m_freem(data->m);
+ }
}
}
diff -r 13bcf6e1c8d3 -r 60777fde0a7e sys/dev/pci/if_ixl.c
--- a/sys/dev/pci/if_ixl.c Mon May 23 12:17:17 2022 +0000
+++ b/sys/dev/pci/if_ixl.c Mon May 23 13:53:37 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_ixl.c,v 1.82 2022/03/31 06:23:18 yamaguchi Exp $ */
+/* $NetBSD: if_ixl.c,v 1.83 2022/05/23 13:53:37 rin Exp $ */
/*
* Copyright (c) 2013-2015, Intel Corporation
@@ -74,7 +74,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ixl.c,v 1.82 2022/03/31 06:23:18 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ixl.c,v 1.83 2022/05/23 13:53:37 rin Exp $");
#ifdef _KERNEL_OPT
#include "opt_net_mpsafe.h"
@@ -2532,9 +2532,6 @@
unsigned int i;
softint_disestablish(txr->txr_si);
- while ((m = pcq_get(txr->txr_intrq)) != NULL)
- m_freem(m);
- pcq_destroy(txr->txr_intrq);
maps = txr->txr_maps;
for (i = 0; i < sc->sc_tx_ring_ndescs; i++) {
@@ -2543,6 +2540,10 @@
bus_dmamap_destroy(sc->sc_dmat, txm->txm_map);
}
+ while ((m = pcq_get(txr->txr_intrq)) != NULL)
+ m_freem(m);
+ pcq_destroy(txr->txr_intrq);
+
ixl_dmamem_free(sc, &txr->txr_mem);
mutex_destroy(&txr->txr_lock);
kmem_free(maps, sizeof(maps[0]) * sc->sc_tx_ring_ndescs);
diff -r 13bcf6e1c8d3 -r 60777fde0a7e sys/dev/pci/if_sk.c
--- a/sys/dev/pci/if_sk.c Mon May 23 12:17:17 2022 +0000
+++ b/sys/dev/pci/if_sk.c Mon May 23 13:53:37 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_sk.c,v 1.110 2022/05/03 20:52:32 andvar Exp $ */
+/* $NetBSD: if_sk.c,v 1.111 2022/05/23 13:53:37 rin Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -115,7 +115,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_sk.c,v 1.110 2022/05/03 20:52:32 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_sk.c,v 1.111 2022/05/23 13:53:37 rin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -2152,9 +2152,6 @@
if (sc_if->sk_cdata.sk_tx_chain[idx].sk_mbuf != NULL) {
entry = sc_if->sk_cdata.sk_tx_map[idx];
- m_freem(sc_if->sk_cdata.sk_tx_chain[idx].sk_mbuf);
- sc_if->sk_cdata.sk_tx_chain[idx].sk_mbuf = NULL;
-
bus_dmamap_sync(sc->sc_dmatag, entry->dmamap, 0,
entry->dmamap->dm_mapsize, BUS_DMASYNC_POSTWRITE);
@@ -2162,6 +2159,9 @@
SIMPLEQ_INSERT_TAIL(&sc_if->sk_txmap_head, entry,
link);
sc_if->sk_cdata.sk_tx_map[idx] = NULL;
+
+ m_freem(sc_if->sk_cdata.sk_tx_chain[idx].sk_mbuf);
+ sc_if->sk_cdata.sk_tx_chain[idx].sk_mbuf = NULL;
}
sc_if->sk_cdata.sk_tx_cnt--;
SK_INC(idx, SK_TX_RING_CNT);
diff -r 13bcf6e1c8d3 -r 60777fde0a7e sys/dev/pci/if_ti.c
--- a/sys/dev/pci/if_ti.c Mon May 23 12:17:17 2022 +0000
+++ b/sys/dev/pci/if_ti.c Mon May 23 13:53:37 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_ti.c,v 1.122 2021/11/10 16:17:34 msaitoh Exp $ */
+/* $NetBSD: if_ti.c,v 1.123 2022/05/23 13:53:37 rin Exp $ */
/*
* Copyright (c) 1997, 1998, 1999
@@ -81,7 +81,7 @@
*/
Home |
Main Index |
Thread Index |
Old Index