git: 9383a51afd80 - stable/13 - Introduce and use the NET_EPOCH_DRAIN_CALLBACKS() macro

From: Zhenlei Huang <zlei_at_FreeBSD.org>
Date: Wed, 11 Jan 2023 10:39:59 UTC
The branch stable/13 has been updated by zlei:

URL: https://cgit.FreeBSD.org/src/commit/?id=9383a51afd805181e671254a95fc74a51fa7e0f4

commit 9383a51afd805181e671254a95fc74a51fa7e0f4
Author:     Zhenlei Huang <zlei.huang@gmail.com>
AuthorDate: 2022-07-29 13:02:39 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2023-01-11 10:35:59 +0000

    Introduce and use the NET_EPOCH_DRAIN_CALLBACKS() macro
    
    Reviewed by:    melifao, kp
    Approved by:    kp (mentor)
    Differential Revision:  https://reviews.freebsd.org/D35968
    
    (cherry picked from commit 150486f6a940947fa7a7c6db357c3f92d07a955f)
---
 sys/net/if.c                 | 4 ++--
 sys/net/if_bridge.c          | 2 +-
 sys/net/route/fib_algo.c     | 2 +-
 sys/net/route/route_tables.c | 2 +-
 sys/sys/epoch.h              | 1 +
 5 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/sys/net/if.c b/sys/net/if.c
index 38e1ebbb61b7..bcebd84306c8 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1182,7 +1182,7 @@ if_detach_internal(struct ifnet *ifp, int vmove, struct if_clone **ifcp)
 	 * which lead to leave group calls, which in turn access the
 	 * belonging ifnet structure:
 	 */
-	epoch_drain_callbacks(net_epoch_preempt);
+	NET_EPOCH_DRAIN_CALLBACKS();
 
 	/*
 	 * In any case (destroy or vmove) detach us from the groups
@@ -4083,7 +4083,7 @@ if_deregister_com_alloc(u_char type)
 	 * fixes issues about late invocation of if_destroy(), which leads
 	 * to memory leak from if_com_alloc[type] allocated if_l2com.
 	 */
-	epoch_drain_callbacks(net_epoch_preempt);
+	NET_EPOCH_DRAIN_CALLBACKS();
 
 	if_com_alloc[type] = NULL;
 	if_com_free[type] = NULL;
diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c
index 0473245a1abd..e46c7fb92793 100644
--- a/sys/net/if_bridge.c
+++ b/sys/net/if_bridge.c
@@ -600,7 +600,7 @@ vnet_bridge_uninit(const void *unused __unused)
 	BRIDGE_LIST_LOCK_DESTROY();
 
 	/* Callbacks may use the UMA zone. */
-	epoch_drain_callbacks(net_epoch_preempt);
+	NET_EPOCH_DRAIN_CALLBACKS();
 
 	uma_zdestroy(V_bridge_rtnode_zone);
 }
diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c
index 54b0464711a5..42ad3f43d9cf 100644
--- a/sys/net/route/fib_algo.c
+++ b/sys/net/route/fib_algo.c
@@ -1509,7 +1509,7 @@ set_fib_algo(uint32_t fibnum, int family, struct sysctl_oid *oidp, struct sysctl
 	fib_cleanup_algo(rh, true, false);
 
 	/* Drain cb so user can unload the module after userret if so desired */
-	epoch_drain_callbacks(net_epoch_preempt);
+	NET_EPOCH_DRAIN_CALLBACKS();
 
 	return (0);
 }
diff --git a/sys/net/route/route_tables.c b/sys/net/route/route_tables.c
index c9a9d6a915eb..54b467f9801f 100644
--- a/sys/net/route/route_tables.c
+++ b/sys/net/route/route_tables.c
@@ -299,7 +299,7 @@ rtables_destroy(const void *unused __unused)
 	 *  nexthops deletions will be scheduled for the next epoch run
 	 *  and will be completed after vnet teardown.
 	 */
-	epoch_drain_callbacks(net_epoch_preempt);
+	NET_EPOCH_DRAIN_CALLBACKS();
 
 	free(V_rt_tables, M_RTABLE);
 	vnet_rtzone_destroy();
diff --git a/sys/sys/epoch.h b/sys/sys/epoch.h
index 85c791d3df6c..63e03cafd985 100644
--- a/sys/sys/epoch.h
+++ b/sys/sys/epoch.h
@@ -104,6 +104,7 @@ extern epoch_t net_epoch_preempt;
 #define	NET_EPOCH_EXIT(et)	epoch_exit_preempt(net_epoch_preempt, &(et))
 #define	NET_EPOCH_WAIT()	epoch_wait_preempt(net_epoch_preempt)
 #define	NET_EPOCH_CALL(f, c)	epoch_call(net_epoch_preempt, (f), (c))
+#define	NET_EPOCH_DRAIN_CALLBACKS() epoch_drain_callbacks(net_epoch_preempt)
 #define	NET_EPOCH_ASSERT()	MPASS(in_epoch(net_epoch_preempt))
 #define	NET_TASK_INIT(t, p, f, c) TASK_INIT_FLAGS(t, p, f, c, TASK_NETWORK)
 #define	NET_GROUPTASK_INIT(gtask, prio, func, ctx)			\