aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/netmap/netmap.c
diff options
context:
space:
mode:
authorVincenzo Maffione <vmaffione@FreeBSD.org>2022-03-06 16:39:16 +0000
committerVincenzo Maffione <vmaffione@FreeBSD.org>2022-03-06 16:39:16 +0000
commit09a1893398fdcd1d000dae1cb3fd5239c0bfb360 (patch)
tree1e037f08cd9a830e4b10191901666161a97ca7d3 /sys/dev/netmap/netmap.c
parentbafaa70b6f9098d83d074968c8e6747ecec1e118 (diff)
netmap: fix refcount bug in netmap allocator
Symptom: when a single extmem memory region is provided to netmap multiple times, for multiple interfaces, the memory region is never released by netmap once all the existing file descriptors are closed. Fix the relevant condition in netmap_mem_drop(): release the memory when the last user of netmap_adapter is gone, rather then when the last user of netmap_mem_d is gone. MFC after: 2 weeks
Diffstat (limited to 'sys/dev/netmap/netmap.c')
-rw-r--r--sys/dev/netmap/netmap.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/sys/dev/netmap/netmap.c b/sys/dev/netmap/netmap.c
index ed3154a524db..17b6eeaac085 100644
--- a/sys/dev/netmap/netmap.c
+++ b/sys/dev/netmap/netmap.c
@@ -994,10 +994,12 @@ netmap_mem_restore(struct netmap_adapter *na)
static void
netmap_mem_drop(struct netmap_adapter *na)
{
- /* if the native allocator had been overridden on regif,
- * restore it now and drop the temporary one
- */
- if (netmap_mem_deref(na->nm_mem, na)) {
+ netmap_mem_deref(na->nm_mem, na);
+
+ if (na->active_fds <= 0) {
+ /* if the native allocator had been overridden on regif,
+ * restore it now and drop the temporary one
+ */
netmap_mem_restore(na);
}
}