Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F144607741
D44371.1775724284.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D44371.1775724284.diff
View Options
diff --git a/sys/dev/netmap/netmap_generic.c b/sys/dev/netmap/netmap_generic.c
--- a/sys/dev/netmap/netmap_generic.c
+++ b/sys/dev/netmap/netmap_generic.c
@@ -257,6 +257,7 @@
mtx_lock_spin(&kring->tx_event_lock);
if (kring->tx_event) {
SET_MBUF_DESTRUCTOR(kring->tx_event, NULL);
+ kring->tx_event->m_ext.ext_arg1 = NULL;
}
kring->tx_event = NULL;
mtx_unlock_spin(&kring->tx_event_lock);
@@ -271,16 +272,18 @@
for_each_tx_kring(r, kring, na) {
callout_drain(&kring->tx_event_callout);
- mtx_destroy(&kring->tx_event_lock);
+
if (kring->tx_pool == NULL) {
continue;
}
for (i=0; i<na->num_tx_desc; i++) {
if (kring->tx_pool[i]) {
- m_freem(kring->tx_pool[i]);
+ m_free(kring->tx_pool[i]);
+ kring->tx_pool[i] = NULL;
}
}
+ mtx_destroy(&kring->tx_event_lock);
nm_os_free(kring->tx_pool);
kring->tx_pool = NULL;
}
@@ -434,7 +437,7 @@
static void
generic_mbuf_dtor(struct mbuf *m)
{
- struct netmap_adapter *na = NA(GEN_TX_MBUF_IFP(m));
+ struct netmap_adapter *na = (struct netmap_adapter *)m->m_ext.ext_arg1;
struct netmap_kring *kring;
unsigned int r = MBUF_TXQ(m);
unsigned int r_orig = r;
@@ -458,6 +461,18 @@
kring = na->tx_rings[r];
mtx_lock_spin(&kring->tx_event_lock);
+
+ /*
+ * The netmap destructor can be called between us getting the
+ * reference and taking the lock, in that case the ring
+ * reference won't be valid. The destructor will free this mbuf
+ * so we can stop here.
+ */
+ if (m->m_ext.ext_arg1 == NULL) {
+ mtx_unlock_spin(&kring->tx_event_lock);
+ return;
+ }
+
if (kring->tx_event == m) {
kring->tx_event = NULL;
match = true;
@@ -639,6 +654,10 @@
}
SET_MBUF_DESTRUCTOR(m, generic_mbuf_dtor);
+
+ /* Take a reference to the adapter so we have it on free. */
+ m->m_ext.ext_arg1 = kring->na;
+
kring->tx_event = m;
#ifdef __FreeBSD__
/*
@@ -664,7 +683,7 @@
/* Decrement the refcount. This will free it if we lose the race
* with the driver. */
- m_freem(m);
+ m_free(m);
}
/*
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Apr 9, 8:44 AM (11 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28307870
Default Alt Text
D44371.1775724284.diff (2 KB)
Attached To
Mode
D44371: netmap: Address errors on memory free in netmap_generic
Attached
Detach File
Event Timeline
Log In to Comment