Skip to content

Commit 2a4bd98

Browse files
committed
Introduce NET_EPOCH_CALL() macro and use it everywhere where we free
data based on the network epoch. The macro reverses the argument order of epoch_call(9) - first function, then its argument. NFC
1 parent b132823 commit 2a4bd98

File tree

13 files changed

+29
-32
lines changed

13 files changed

+29
-32
lines changed

sys/net/bpf.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,10 @@ static struct filterops bpfread_filtops = {
274274
*
275275
* 2. An userland application uses ioctl() call to bpf_d descriptor.
276276
* All such call are serialized with global lock. BPF filters can be
277-
* changed, but pointer to old filter will be freed using epoch_call().
277+
* changed, but pointer to old filter will be freed using NET_EPOCH_CALL().
278278
* Thus it should be safe for bpf_tap/bpf_mtap* code to do access to
279279
* filter pointers, even if change will happen during bpf_tap execution.
280-
* Destroying of bpf_d descriptor also is doing using epoch_call().
280+
* Destroying of bpf_d descriptor also is doing using NET_EPOCH_CALL().
281281
*
282282
* 3. An userland application can write packets into bpf_d descriptor.
283283
* There we need to be sure, that ifnet won't disappear during bpfwrite().
@@ -288,7 +288,7 @@ static struct filterops bpfread_filtops = {
288288
*
289289
* 5. The kernel invokes bpfdetach() on interface destroying. All lists
290290
* are modified with global lock held and actual free() is done using
291-
* epoch_call().
291+
* NET_EPOCH_CALL().
292292
*/
293293

294294
static void
@@ -314,7 +314,7 @@ bpfif_rele(struct bpf_if *bp)
314314

315315
if (!refcount_release(&bp->bif_refcnt))
316316
return;
317-
epoch_call(net_epoch_preempt, &bp->epoch_ctx, bpfif_free);
317+
NET_EPOCH_CALL(bpfif_free, &bp->epoch_ctx);
318318
}
319319

320320
static void
@@ -330,7 +330,7 @@ bpfd_rele(struct bpf_d *d)
330330

331331
if (!refcount_release(&d->bd_refcnt))
332332
return;
333-
epoch_call(net_epoch_preempt, &d->epoch_ctx, bpfd_free);
333+
NET_EPOCH_CALL(bpfd_free, &d->epoch_ctx);
334334
}
335335

336336
static struct bpf_program_buffer*
@@ -2036,8 +2036,7 @@ bpf_setf(struct bpf_d *d, struct bpf_program *fp, u_long cmd)
20362036
BPFD_UNLOCK(d);
20372037

20382038
if (fcode != NULL)
2039-
epoch_call(net_epoch_preempt, &fcode->epoch_ctx,
2040-
bpf_program_buffer_free);
2039+
NET_EPOCH_CALL(bpf_program_buffer_free, &fcode->epoch_ctx);
20412040

20422041
if (track_event)
20432042
EVENTHANDLER_INVOKE(bpf_track,

sys/net/if.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ if_free(struct ifnet *ifp)
654654
IFNET_WUNLOCK();
655655

656656
if (refcount_release(&ifp->if_refcount))
657-
epoch_call(net_epoch_preempt, &ifp->if_epoch_ctx, if_destroy);
657+
NET_EPOCH_CALL(if_destroy, &ifp->if_epoch_ctx);
658658
CURVNET_RESTORE();
659659
}
660660

@@ -677,7 +677,7 @@ if_rele(struct ifnet *ifp)
677677

678678
if (!refcount_release(&ifp->if_refcount))
679679
return;
680-
epoch_call(net_epoch_preempt, &ifp->if_epoch_ctx, if_destroy);
680+
NET_EPOCH_CALL(if_destroy, &ifp->if_epoch_ctx);
681681
}
682682

683683
void
@@ -1826,7 +1826,7 @@ ifa_free(struct ifaddr *ifa)
18261826
{
18271827

18281828
if (refcount_release(&ifa->ifa_refcnt))
1829-
epoch_call(net_epoch_preempt, &ifa->ifa_epoch_ctx, ifa_destroy);
1829+
NET_EPOCH_CALL(ifa_destroy, &ifa->ifa_epoch_ctx);
18301830
}
18311831

18321832

@@ -3410,7 +3410,7 @@ if_freemulti(struct ifmultiaddr *ifma)
34103410
KASSERT(ifma->ifma_refcount == 0, ("if_freemulti_epoch: refcount %d",
34113411
ifma->ifma_refcount));
34123412

3413-
epoch_call(net_epoch_preempt, &ifma->ifma_epoch_ctx, if_destroymulti);
3413+
NET_EPOCH_CALL(if_destroymulti, &ifma->ifma_epoch_ctx);
34143414
}
34153415

34163416

sys/net/if_gre.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ gre_delete_tunnel(struct gre_softc *sc)
392392
if ((gs = sc->gre_so) != NULL && CK_LIST_EMPTY(&gs->list)) {
393393
CK_LIST_REMOVE(gs, chain);
394394
soclose(gs->so);
395-
epoch_call(net_epoch_preempt, &gs->epoch_ctx, gre_sofree);
395+
NET_EPOCH_CALL(gre_sofree, &gs->epoch_ctx);
396396
sc->gre_so = NULL;
397397
}
398398
GRE2IFP(sc)->if_drv_flags &= ~IFF_DRV_RUNNING;

sys/net/if_lagg.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ lagg_port_destroy(struct lagg_port *lp, int rundelport)
910910
* free port and release it's ifnet reference after a grace period has
911911
* elapsed.
912912
*/
913-
epoch_call(net_epoch_preempt, &lp->lp_epoch_ctx, lagg_port_destroy_cb);
913+
NET_EPOCH_CALL(lagg_port_destroy_cb, &lp->lp_epoch_ctx);
914914
/* Update lagg capabilities */
915915
lagg_capabilities(sc);
916916
lagg_linkstate(sc);

sys/net/if_vlan.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ vlan_setmulti(struct ifnet *ifp)
584584
while ((mc = CK_SLIST_FIRST(&sc->vlan_mc_listhead)) != NULL) {
585585
CK_SLIST_REMOVE_HEAD(&sc->vlan_mc_listhead, mc_entries);
586586
(void)if_delmulti(ifp_p, (struct sockaddr *)&mc->mc_addr);
587-
epoch_call(net_epoch_preempt, &mc->mc_epoch_ctx, vlan_mc_free);
587+
NET_EPOCH_CALL(vlan_mc_free, &mc->mc_epoch_ctx);
588588
}
589589

590590
/* Now program new ones. */
@@ -1543,7 +1543,7 @@ vlan_unconfig_locked(struct ifnet *ifp, int departing)
15431543
error);
15441544
}
15451545
CK_SLIST_REMOVE_HEAD(&ifv->vlan_mc_listhead, mc_entries);
1546-
epoch_call(net_epoch_preempt, &mc->mc_epoch_ctx, vlan_mc_free);
1546+
NET_EPOCH_CALL(vlan_mc_free, &mc->mc_epoch_ctx);
15471547
}
15481548

15491549
vlan_setflags(ifp, 0); /* clear special flags on parent */

sys/netinet/in.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ in_lltable_destroy_lle(struct llentry *lle)
10871087
{
10881088

10891089
LLE_WUNLOCK(lle);
1090-
epoch_call(net_epoch_preempt, &lle->lle_epoch_ctx, in_lltable_destroy_lle_unlocked);
1090+
NET_EPOCH_CALL(in_lltable_destroy_lle_unlocked, &lle->lle_epoch_ctx);
10911091
}
10921092

10931093
static struct llentry *
@@ -1348,7 +1348,7 @@ in_lltable_alloc(struct lltable *llt, u_int flags, const struct sockaddr *l3addr
13481348
linkhdrsize = LLE_MAX_LINKHDR;
13491349
if (lltable_calc_llheader(ifp, AF_INET, IF_LLADDR(ifp),
13501350
linkhdr, &linkhdrsize, &lladdr_off) != 0) {
1351-
epoch_call(net_epoch_preempt, &lle->lle_epoch_ctx, in_lltable_destroy_lle_unlocked);
1351+
NET_EPOCH_CALL(in_lltable_destroy_lle_unlocked, &lle->lle_epoch_ctx);
13521352
return (NULL);
13531353
}
13541354
lltable_set_entry_addr(ifp, lle, linkhdr, linkhdrsize,

sys/netinet/in_pcb.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,7 @@ in_pcblbgroup_free(struct inpcblbgroup *grp)
269269
{
270270

271271
CK_LIST_REMOVE(grp, il_list);
272-
epoch_call(net_epoch_preempt, &grp->il_epoch_ctx,
273-
in_pcblbgroup_free_deferred);
272+
NET_EPOCH_CALL(in_pcblbgroup_free_deferred, &grp->il_epoch_ctx);
274273
}
275274

276275
static struct inpcblbgroup *
@@ -1663,7 +1662,7 @@ in_pcbfree(struct inpcb *inp)
16631662
/* mark as destruction in progress */
16641663
inp->inp_flags2 |= INP_FREED;
16651664
INP_WUNLOCK(inp);
1666-
epoch_call(net_epoch_preempt, &inp->inp_epoch_ctx, in_pcbfree_deferred);
1665+
NET_EPOCH_CALL(in_pcbfree_deferred, &inp->inp_epoch_ctx);
16671666
}
16681667

16691668
/*
@@ -1704,7 +1703,7 @@ in_pcbdrop(struct inpcb *inp)
17041703
CK_LIST_REMOVE(inp, inp_portlist);
17051704
if (CK_LIST_FIRST(&phd->phd_pcblist) == NULL) {
17061705
CK_LIST_REMOVE(phd, phd_hash);
1707-
epoch_call(net_epoch_preempt, &phd->phd_epoch_ctx, inpcbport_free);
1706+
NET_EPOCH_CALL(inpcbport_free, &phd->phd_epoch_ctx);
17081707
}
17091708
INP_HASH_WUNLOCK(inp->inp_pcbinfo);
17101709
inp->inp_flags &= ~INP_INHASHLIST;
@@ -2674,7 +2673,7 @@ in_pcbremlists(struct inpcb *inp)
26742673
CK_LIST_REMOVE(inp, inp_portlist);
26752674
if (CK_LIST_FIRST(&phd->phd_pcblist) == NULL) {
26762675
CK_LIST_REMOVE(phd, phd_hash);
2677-
epoch_call(net_epoch_preempt, &phd->phd_epoch_ctx, inpcbport_free);
2676+
NET_EPOCH_CALL(inpcbport_free, &phd->phd_epoch_ctx);
26782677
}
26792678
INP_HASH_WUNLOCK(pcbinfo);
26802679
inp->inp_flags &= ~INP_INHASHLIST;

sys/netinet/ip_gre.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ in_gre_udp_input(struct mbuf *m, int off, struct inpcb *inp,
235235
* If socket was closed before we have entered NET_EPOCH section,
236236
* INP_FREED flag should be set. Otherwise it should be safe to
237237
* make access to ctx data, because gre_so will be freed by
238-
* gre_sofree() via epoch_call().
238+
* gre_sofree() via NET_EPOCH_CALL().
239239
*/
240240
if (__predict_false(inp->inp_flags2 & INP_FREED)) {
241241
NET_EPOCH_EXIT(et);
@@ -284,8 +284,7 @@ in_gre_setup_socket(struct gre_softc *sc)
284284
if (CK_LIST_EMPTY(&gs->list)) {
285285
CK_LIST_REMOVE(gs, chain);
286286
soclose(gs->so);
287-
epoch_call(net_epoch_preempt, &gs->epoch_ctx,
288-
gre_sofree);
287+
NET_EPOCH_CALL(gre_sofree, &gs->epoch_ctx);
289288
}
290289
gs = sc->gre_so = NULL;
291290
}

sys/netinet/tcp_ratelimit.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ rs_defer_destroy(struct tcp_rate_set *rs)
286286

287287
/* Set flag to only defer once. */
288288
rs->rs_flags |= RS_FUNERAL_SCHD;
289-
epoch_call(net_epoch_preempt, &rs->rs_epoch_ctx, rs_destroy);
289+
NET_EPOCH_CALL(rs_destroy, &rs->rs_epoch_ctx);
290290
}
291291

292292
#ifdef INET

sys/netinet6/in6.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2061,7 +2061,7 @@ in6_lltable_destroy_lle(struct llentry *lle)
20612061
{
20622062

20632063
LLE_WUNLOCK(lle);
2064-
epoch_call(net_epoch_preempt, &lle->lle_epoch_ctx, in6_lltable_destroy_lle_unlocked);
2064+
NET_EPOCH_CALL(in6_lltable_destroy_lle_unlocked, &lle->lle_epoch_ctx);
20652065
}
20662066

20672067
static struct llentry *
@@ -2282,7 +2282,7 @@ in6_lltable_alloc(struct lltable *llt, u_int flags,
22822282
linkhdrsize = LLE_MAX_LINKHDR;
22832283
if (lltable_calc_llheader(ifp, AF_INET6, IF_LLADDR(ifp),
22842284
linkhdr, &linkhdrsize, &lladdr_off) != 0) {
2285-
epoch_call(net_epoch_preempt, &lle->lle_epoch_ctx, in6_lltable_destroy_lle_unlocked);
2285+
NET_EPOCH_CALL(in6_lltable_destroy_lle_unlocked, &lle->lle_epoch_ctx);
22862286
return (NULL);
22872287
}
22882288
lltable_set_entry_addr(ifp, lle, linkhdr, linkhdrsize,

sys/netinet6/ip6_gre.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ in6_gre_udp_input(struct mbuf *m, int off, struct inpcb *inp,
228228
* If socket was closed before we have entered NET_EPOCH section,
229229
* INP_FREED flag should be set. Otherwise it should be safe to
230230
* make access to ctx data, because gre_so will be freed by
231-
* gre_sofree() via epoch_call().
231+
* gre_sofree() via NET_EPOCH_CALL().
232232
*/
233233
if (__predict_false(inp->inp_flags2 & INP_FREED)) {
234234
NET_EPOCH_EXIT(et);
@@ -280,8 +280,7 @@ in6_gre_setup_socket(struct gre_softc *sc)
280280
if (CK_LIST_EMPTY(&gs->list)) {
281281
CK_LIST_REMOVE(gs, chain);
282282
soclose(gs->so);
283-
epoch_call(net_epoch_preempt, &gs->epoch_ctx,
284-
gre_sofree);
283+
NET_EPOCH_CALL(gre_sofree, &gs->epoch_ctx);
285284
}
286285
gs = sc->gre_so = NULL;
287286
}

sys/netpfil/ipfw/nat64/nat64lsn.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ MALLOC_DEFINE(M_NAT64LSN, "NAT64LSN", "NAT64LSN");
7575
#define NAT64LSN_EPOCH_ENTER(et) NET_EPOCH_ENTER(et)
7676
#define NAT64LSN_EPOCH_EXIT(et) NET_EPOCH_EXIT(et)
7777
#define NAT64LSN_EPOCH_ASSERT() NET_EPOCH_ASSERT()
78-
#define NAT64LSN_EPOCH_CALL(c, f) epoch_call(net_epoch_preempt, (c), (f))
78+
#define NAT64LSN_EPOCH_CALL(c, f) NET_EPOCH_CALL((f), (c))
7979

8080
static uma_zone_t nat64lsn_host_zone;
8181
static uma_zone_t nat64lsn_pgchunk_zone;

sys/sys/epoch.h

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ extern epoch_t net_epoch_preempt;
101101
#define NET_EPOCH_ENTER(et) epoch_enter_preempt(net_epoch_preempt, &(et))
102102
#define NET_EPOCH_EXIT(et) epoch_exit_preempt(net_epoch_preempt, &(et))
103103
#define NET_EPOCH_WAIT() epoch_wait_preempt(net_epoch_preempt)
104+
#define NET_EPOCH_CALL(f, c) epoch_call(net_epoch_preempt, (c), (f))
104105
#define NET_EPOCH_ASSERT() MPASS(in_epoch(net_epoch_preempt))
105106

106107
#endif /* _KERNEL */

0 commit comments

Comments
 (0)