commit 4943f64f6a3f90501a05bb2c3c955de952e0cd7e Author: Ryota Ozaki Date: Wed Mar 23 15:39:09 2016 +0900 Remove BRIDGE_MPSAFE switch We need to enable it by default because bridge_input now runs in softint, but bridge_input w/o BRIDGE_MPSAFE was designed as it runs in hardware interrupt. diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c index b45fd19..9a76b71 100644 --- a/sys/net/if_bridge.c +++ b/sys/net/if_bridge.c @@ -191,13 +191,8 @@ __CTASSERT(offsetof(struct ifbifconf, ifbic_buf) == offsetof(struct ifbaconf, if if ((_sc)->sc_rtlist_psz != NULL) \ pserialize_perform((_sc)->sc_rtlist_psz); -#ifdef BRIDGE_MPSAFE #define BRIDGE_RT_RENTER(__s) do { __s = pserialize_read_enter(); } while (0) #define BRIDGE_RT_REXIT(__s) do { pserialize_read_exit(__s); } while (0) -#else /* BRIDGE_MPSAFE */ -#define BRIDGE_RT_RENTER(__s) do { __s = 0; } while (0) -#define BRIDGE_RT_REXIT(__s) do { (void)__s; } while (0) -#endif /* BRIDGE_MPSAFE */ int bridge_rtable_prune_period = BRIDGE_RTABLE_PRUNE_PERIOD; @@ -369,7 +364,7 @@ bridge_clone_create(struct if_clone *ifc, int unit) { struct bridge_softc *sc; struct ifnet *ifp; - int error, flags; + int error; sc = kmem_zalloc(sizeof(*sc), KM_SLEEP); ifp = &sc->sc_if; @@ -386,13 +381,8 @@ bridge_clone_create(struct if_clone *ifc, int unit) /* Initialize our routing table. */ bridge_rtable_init(sc); -#ifdef BRIDGE_MPSAFE - flags = WQ_MPSAFE; -#else - flags = 0; -#endif error = workqueue_create(&sc->sc_rtage_wq, "bridge_rtage", - bridge_rtage_work, sc, PRI_SOFTNET, IPL_SOFTNET, flags); + bridge_rtage_work, sc, PRI_SOFTNET, IPL_SOFTNET, WQ_MPSAFE); if (error) panic("%s: workqueue_create %d\n", __func__, error); @@ -400,13 +390,8 @@ bridge_clone_create(struct if_clone *ifc, int unit) callout_init(&sc->sc_bstpcallout, 0); LIST_INIT(&sc->sc_iflist); -#ifdef BRIDGE_MPSAFE sc->sc_iflist_psz = pserialize_create(); sc->sc_iflist_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_SOFTNET); -#else - sc->sc_iflist_psz = NULL; - sc->sc_iflist_lock = NULL; -#endif cv_init(&sc->sc_iflist_cv, "if_bridge_cv"); if_initname(ifp, ifc->ifc_name, unit); @@ -655,14 +640,13 @@ bridge_lookup_member_if(struct bridge_softc *sc, struct ifnet *member_ifp) static struct bridge_iflist * bridge_try_hold_bif(struct bridge_iflist *bif) { -#ifdef BRIDGE_MPSAFE + if (bif != NULL) { if (bif->bif_waiting) bif = NULL; else atomic_inc_32(&bif->bif_refs); } -#endif return bif; } @@ -674,7 +658,6 @@ bridge_try_hold_bif(struct bridge_iflist *bif) static void bridge_release_member(struct bridge_softc *sc, struct bridge_iflist *bif) { -#ifdef BRIDGE_MPSAFE uint32_t refs; refs = atomic_dec_uint_nv(&bif->bif_refs); @@ -683,10 +666,6 @@ bridge_release_member(struct bridge_softc *sc, struct bridge_iflist *bif) cv_broadcast(&sc->sc_iflist_cv); BRIDGE_UNLOCK(sc); } -#else - (void)sc; - (void)bif; -#endif } /* @@ -709,7 +688,6 @@ bridge_delete_member(struct bridge_softc *sc, struct bridge_iflist *bif) BRIDGE_PSZ_PERFORM(sc); -#ifdef BRIDGE_MPSAFE bif->bif_waiting = true; membar_sync(); while (bif->bif_refs > 0) { @@ -717,7 +695,6 @@ bridge_delete_member(struct bridge_softc *sc, struct bridge_iflist *bif) cv_wait(&sc->sc_iflist_cv, sc->sc_iflist_lock); } bif->bif_waiting = false; -#endif BRIDGE_UNLOCK(sc); kmem_free(bif, sizeof(*bif)); @@ -1420,9 +1397,6 @@ bridge_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *sa, struct ether_header *eh; struct ifnet *dst_if; struct bridge_softc *sc; -#ifndef BRIDGE_MPSAFE - int s; -#endif if (m->m_len < ETHER_HDR_LEN) { m = m_pullup(m, ETHER_HDR_LEN); @@ -1433,10 +1407,6 @@ bridge_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *sa, eh = mtod(m, struct ether_header *); sc = ifp->if_bridge; -#ifndef BRIDGE_MPSAFE - s = splnet(); -#endif - /* * If bridge is down, but the original output interface is up, * go ahead and send out that interface. Otherwise, the packet @@ -1460,14 +1430,14 @@ bridge_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *sa, struct bridge_iflist *bif; struct mbuf *mc; int used = 0; - int ss; + int s; - BRIDGE_PSZ_RENTER(ss); + BRIDGE_PSZ_RENTER(s); LIST_FOREACH_READER(bif, &sc->sc_iflist, bif_next) { bif = bridge_try_hold_bif(bif); if (bif == NULL) continue; - BRIDGE_PSZ_REXIT(ss); + BRIDGE_PSZ_REXIT(s); dst_if = bif->bif_ifp; if ((dst_if->if_flags & IFF_RUNNING) == 0) @@ -1503,15 +1473,12 @@ bridge_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *sa, bridge_enqueue(sc, dst_if, mc, 0); next: bridge_release_member(sc, bif); - BRIDGE_PSZ_RENTER(ss); + BRIDGE_PSZ_RENTER(s); } - BRIDGE_PSZ_REXIT(ss); + BRIDGE_PSZ_REXIT(s); if (used == 0) m_freem(m); -#ifndef BRIDGE_MPSAFE - splx(s); -#endif return (0); } @@ -1522,17 +1489,11 @@ next: if ((dst_if->if_flags & IFF_RUNNING) == 0) { m_freem(m); -#ifndef BRIDGE_MPSAFE - splx(s); -#endif return (0); } bridge_enqueue(sc, dst_if, m, 0); -#ifndef BRIDGE_MPSAFE - splx(s); -#endif return (0); } @@ -1561,24 +1522,9 @@ bridge_forward(struct bridge_softc *sc, struct mbuf *m) struct bridge_iflist *bif; struct ifnet *src_if, *dst_if; struct ether_header *eh; -#ifndef BRIDGE_MPSAFE - int s; - KERNEL_LOCK(1, NULL); - mutex_enter(softnet_lock); -#endif - - if ((sc->sc_if.if_flags & IFF_RUNNING) == 0) { -#ifndef BRIDGE_MPSAFE - mutex_exit(softnet_lock); - KERNEL_UNLOCK_ONE(NULL); -#endif + if ((sc->sc_if.if_flags & IFF_RUNNING) == 0) return; - } - -#ifndef BRIDGE_MPSAFE - s = splnet(); -#endif src_if = m->m_pkthdr.rcvif; @@ -1699,14 +1645,8 @@ bridge_forward(struct bridge_softc *sc, struct mbuf *m) bridge_enqueue(sc, dst_if, m, 1); out: -#ifndef BRIDGE_MPSAFE - splx(s); - mutex_exit(softnet_lock); - KERNEL_UNLOCK_ONE(NULL); -#else /* XXX gcc */ return; -#endif } static bool @@ -2259,13 +2199,8 @@ bridge_rtable_init(struct bridge_softc *sc) LIST_INIT(&sc->sc_rtlist); -#ifdef BRIDGE_MPSAFE sc->sc_rtlist_psz = pserialize_create(); sc->sc_rtlist_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_SOFTNET); -#else - sc->sc_rtlist_psz = NULL; - sc->sc_rtlist_lock = NULL; -#endif } /* diff --git a/sys/net/if_bridgevar.h b/sys/net/if_bridgevar.h index f9f2c80..f154097 100644 --- a/sys/net/if_bridgevar.h +++ b/sys/net/if_bridgevar.h @@ -339,23 +339,13 @@ void bstp_input(struct bridge_softc *, struct bridge_iflist *, struct mbuf *); void bridge_enqueue(struct bridge_softc *, struct ifnet *, struct mbuf *, int); -#ifdef NET_MPSAFE -#define BRIDGE_MPSAFE 1 -#endif +#define BRIDGE_LOCK(_sc) mutex_enter((_sc)->sc_iflist_lock) +#define BRIDGE_UNLOCK(_sc) mutex_exit((_sc)->sc_iflist_lock) +#define BRIDGE_LOCKED(_sc) mutex_owned((_sc)->sc_iflist_lock) -#define BRIDGE_LOCK(_sc) if ((_sc)->sc_iflist_lock) \ - mutex_enter((_sc)->sc_iflist_lock) -#define BRIDGE_UNLOCK(_sc) if ((_sc)->sc_iflist_lock) \ - mutex_exit((_sc)->sc_iflist_lock) -#define BRIDGE_LOCKED(_sc) (!(_sc)->sc_iflist_lock || \ - mutex_owned((_sc)->sc_iflist_lock)) - -#ifdef BRIDGE_MPSAFE -/* - * These macros can be used in both HW interrupt and softint contexts. - */ #define BRIDGE_PSZ_RENTER(__s) do { __s = pserialize_read_enter(); } while (0) #define BRIDGE_PSZ_REXIT(__s) do { pserialize_read_exit(__s); } while (0) +#define BRIDGE_PSZ_PERFORM(_sc) pserialize_perform((_sc)->sc_iflist_psz) /* * XXX tentative; once official API of pserialize for list operations comes, * should migrate to use it. @@ -404,23 +394,6 @@ void bridge_enqueue(struct bridge_softc *, struct ifnet *, struct mbuf *, *(elm)->field.le_prev = (elm)->field.le_next; \ } while (/*CONSTCOND*/0) -#else /* BRIDGE_MPSAFE */ - -#define BRIDGE_PSZ_RENTER(__s) do { __s = 0; } while (0) -#define BRIDGE_PSZ_REXIT(__s) do { (void)__s; } while (0) - -#define LIST_INSERT_AFTER_WRITER LIST_INSERT_AFTER -#define LIST_INSERT_BEFORE_WRITER LIST_INSERT_BEFORE -#define LIST_INSERT_HEAD_WRITER LIST_INSERT_HEAD -#define LIST_FOREACH_READER LIST_FOREACH -#define LIST_FOREACH_WRITER LIST_FOREACH -#define LIST_REMOVE_WRITER LIST_REMOVE - -#endif /* BRIDGE_MPSAFE */ - -#define BRIDGE_PSZ_PERFORM(_sc) if ((_sc)->sc_iflist_psz) \ - pserialize_perform((_sc)->sc_iflist_psz); - /* * Locking notes: * - Updates of sc_iflist are serialized by sc_iflist_lock (an adaptive mutex)