Date: Sun, 23 Aug 2015 18:34:26 +0000 (UTC) From: "Alexander V. Chernikov" <melifaro@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r287078 - in projects/routing/sys: net netinet netinet6 netpfil/ipfw nfs Message-ID: <201508231834.t7NIYQhS051927@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: melifaro Date: Sun Aug 23 18:34:25 2015 New Revision: 287078 URL: https://svnweb.freebsd.org/changeset/base/287078 Log: Switch route radix to dual-lock model: use rmlock for data patch access, and config rwlock for conrol plane processing. Route table changes require bock locks held. Modified: projects/routing/sys/net/route.c projects/routing/sys/net/rt_nhops.c projects/routing/sys/net/rtsock.c projects/routing/sys/netinet/in_rmx.c projects/routing/sys/netinet6/nd6_rtr.c projects/routing/sys/netpfil/ipfw/ip_fw_table_algo.c projects/routing/sys/nfs/bootp_subr.c Modified: projects/routing/sys/net/route.c ============================================================================== --- projects/routing/sys/net/route.c Sun Aug 23 18:33:42 2015 (r287077) +++ projects/routing/sys/net/route.c Sun Aug 23 18:34:25 2015 (r287078) @@ -43,6 +43,8 @@ #include <sys/param.h> #include <sys/systm.h> +#include <sys/rwlock.h> +#include <sys/rmlock.h> #include <sys/malloc.h> #include <sys/mbuf.h> #include <sys/socket.h> @@ -288,7 +290,8 @@ rt_table_init(int offset) rh->rmhead.head.s.mask_nodes = rh->rmhead.mask_nodes; /* Init locks */ - rw_init(&rh->rib_lock, "rib head"); + rm_init(&rh->rib_lock, "rib head run"); + rw_init(&rh->rib_cfglock, "rib head cfg"); /* Finally, set base callbacks */ rh->rnh_addaddr = rn_addroute; @@ -306,7 +309,8 @@ rt_table_destroy(struct rib_head *rh) { /* Assume table is already empty */ - rw_destroy(&rh->rib_lock); + rw_destroy(&rh->rib_cfglock); + rm_destroy(&rh->rib_lock); free(rh, M_RTABLE); } @@ -372,6 +376,7 @@ rtalloc1_fib(struct sockaddr *dst, int r struct rt_addrinfo info; int err = 0, msgtype = RTM_MISS; int needlock; + RIB_LOCK_READER; KASSERT((fibnum < rt_numfibs), ("rtalloc1_fib: bad fibnum")); rh = rt_tables_get_rnh(fibnum, dst->sa_family); @@ -619,11 +624,13 @@ rtredirect_fib(struct sockaddr *dst, * add the key and gateway (in one malloc'd chunk). */ RT_UNLOCK(rt); + RIB_CFG_WLOCK(rh); RIB_WLOCK(rh); RT_LOCK(rt); rt_setgate(rt, rt_key(rt), gateway); gwrt = rtalloc1(gateway, 1, RTF_RNH_LOCKED); RIB_WUNLOCK(rh); + RIB_CFG_WUNLOCK(rh); EVENTHANDLER_INVOKE(route_redirect_event, rt, gwrt, dst); RTFREE_LOCKED(gwrt); } @@ -801,9 +808,12 @@ rt_foreach_fib(int af, rt_setwarg_t *set if (setwa_f != NULL) setwa_f(rh, fibnum, i, arg); + RIB_CFG_WLOCK(rh); + /* Do runtime locking for now */ RIB_WLOCK(rh); rh->rnh_walktree(&rh->head, (walktree_f_t *)wa_f, arg); RIB_WUNLOCK(rh); + RIB_CFG_WUNLOCK(rh); continue; } @@ -814,9 +824,12 @@ rt_foreach_fib(int af, rt_setwarg_t *set if (setwa_f != NULL) setwa_f(rh, fibnum, i, arg); + RIB_CFG_WLOCK(rh); RIB_WLOCK(rh); + /* Do runtime locking for now */ rh->rnh_walktree(&rh->head, (walktree_f_t *)wa_f, arg); RIB_WUNLOCK(rh); + RIB_CFG_WUNLOCK(rh); } } } @@ -1265,9 +1278,10 @@ rtrequest1_fib(int req, struct rt_addrin return (EAFNOSUPPORT); needlock = ((flags & RTF_RNH_LOCKED) == 0); flags &= ~RTF_RNH_LOCKED; - if (needlock) + if (needlock) { + RIB_CFG_WLOCK(rh); RIB_WLOCK(rh); - else + } else RIB_LOCK_ASSERT(rh); /* * If we are adding a host route then we don't want to put @@ -1515,8 +1529,10 @@ rtrequest1_fib(int req, struct rt_addrin error = EOPNOTSUPP; } bad: - if (needlock) + if (needlock) { RIB_WUNLOCK(rh); + RIB_CFG_WUNLOCK(rh); + } return (error); #undef senderr } @@ -1816,7 +1832,7 @@ rtinit1(struct ifaddr *ifa, int cmd, int if (rh == NULL) /* this table doesn't exist but others might */ continue; - RIB_RLOCK(rh); + RIB_CFG_RLOCK(rh); rn = rh->rnh_lookup(dst, netmask, &rh->head); #ifdef RADIX_MPATH if (rn_mpath_capable(rh)) { @@ -1842,7 +1858,7 @@ rtinit1(struct ifaddr *ifa, int cmd, int error = (rn == NULL || (rn->rn_flags & RNF_ROOT) || RNTORT(rn)->rt_ifa != ifa); - RIB_RUNLOCK(rh); + RIB_CFG_RUNLOCK(rh); if (error) { /* this is only an error if bad on ALL tables */ continue; @@ -1875,6 +1891,7 @@ rtinit1(struct ifaddr *ifa, int cmd, int * interface prefix. */ rh = rt_tables_get_rnh(fibnum, dst->sa_family); + RIB_CFG_WLOCK(rh); RIB_WLOCK(rh); /* Delete old prefix */ @@ -1890,6 +1907,7 @@ rtinit1(struct ifaddr *ifa, int cmd, int } RIB_WUNLOCK(rh); + RIB_CFG_WUNLOCK(rh); } Modified: projects/routing/sys/net/rt_nhops.c ============================================================================== --- projects/routing/sys/net/rt_nhops.c Sun Aug 23 18:33:42 2015 (r287077) +++ projects/routing/sys/net/rt_nhops.c Sun Aug 23 18:34:25 2015 (r287078) @@ -40,6 +40,9 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/syslog.h> +#include <sys/lock.h> +#include <sys/rwlock.h> +#include <sys/rmlock.h> #include <sys/malloc.h> #include <sys/mbuf.h> #include <sys/socket.h> @@ -262,8 +265,8 @@ fib4_lookup_prepend(uint32_t fibnum, str struct in_addr gw; struct ether_header *eh; int error, flags; - //uint32_t flowid; struct rtentry *rte; + RIB_LOCK_READER; KASSERT((fibnum < rt_numfibs), ("fib4_lookup_prepend: bad fibnum")); rh = rt_tables_get_rnh(fibnum, AF_INET); @@ -506,6 +509,7 @@ fib4_lookup_nh_basic(uint32_t fibnum, st struct radix_node *rn; struct sockaddr_in sin; struct rtentry *rte; + RIB_LOCK_READER; KASSERT((fibnum < rt_numfibs), ("fib4_lookup_nh_basic: bad fibnum")); rh = rt_tables_get_rnh(fibnum, AF_INET); @@ -542,6 +546,7 @@ fib4_lookup_nh_ifp(uint32_t fibnum, stru struct radix_node *rn; struct sockaddr_in sin; struct rtentry *rte; + RIB_LOCK_READER; KASSERT((fibnum < rt_numfibs), ("fib4_lookup_nh_ifp: bad fibnum")); rh = rt_tables_get_rnh(fibnum, AF_INET); @@ -587,6 +592,7 @@ fib4_lookup_nh_ext(uint32_t fibnum, stru struct radix_node *rn; struct sockaddr_in sin; struct rtentry *rte; + RIB_LOCK_READER; KASSERT((fibnum < rt_numfibs), ("fib4_lookup_nh_ext: bad fibnum")); rh = rt_tables_get_rnh(fibnum, AF_INET); @@ -641,6 +647,7 @@ rib4_lookup_nh_ext(uint32_t fibnum, stru struct radix_node *rn; struct sockaddr_in sin; struct rtentry *rte; + RIB_LOCK_READER; KASSERT((fibnum < rt_numfibs), ("rib4_lookup_nh_ext: bad fibnum")); rh = rt_tables_get_rnh(fibnum, AF_INET); @@ -766,6 +773,7 @@ fib6_lookup_prepend(uint32_t fibnum, str struct rtentry *rte; struct ifnet *lifp; struct ether_header *eh; + RIB_LOCK_READER; uint32_t flags; int error; @@ -1138,6 +1146,7 @@ fib6_lookup_nh_ifp(uint32_t fibnum, stru struct radix_node *rn; struct sockaddr_in6 sin6; struct rtentry *rte; + RIB_LOCK_READER; if (IN6_IS_SCOPE_LINKLOCAL(dst)) { /* Do not lookup link-local addresses in rtable */ @@ -1181,6 +1190,7 @@ fib6_lookup_nh_basic(uint32_t fibnum, co struct radix_node *rn; struct sockaddr_in6 sin6; struct rtentry *rte; + RIB_LOCK_READER; if (IN6_IS_SCOPE_LINKLOCAL(dst)) { /* Do not lookup link-local addresses in rtable */ @@ -1231,6 +1241,7 @@ fib6_lookup_nh_ext(uint32_t fibnum, stru struct radix_node *rn; struct sockaddr_in6 sin6; struct rtentry *rte; + RIB_LOCK_READER; if (IN6_IS_SCOPE_LINKLOCAL(dst)) { /* Do not lookup link-local addresses in rtable */ @@ -1284,6 +1295,7 @@ rib6_lookup_nh_ext(uint32_t fibnum, stru struct radix_node *rn; struct sockaddr_in6 sin6; struct rtentry *rte; + RIB_LOCK_READER; if (IN6_IS_SCOPE_LINKLOCAL(dst)) { /* Do not lookup link-local addresses in rtable */ Modified: projects/routing/sys/net/rtsock.c ============================================================================== --- projects/routing/sys/net/rtsock.c Sun Aug 23 18:33:42 2015 (r287077) +++ projects/routing/sys/net/rtsock.c Sun Aug 23 18:34:25 2015 (r287078) @@ -39,6 +39,9 @@ #include <sys/kernel.h> #include <sys/domain.h> #include <sys/lock.h> +#include <sys/lock.h> +#include <sys/rwlock.h> +#include <sys/rmlock.h> #include <sys/malloc.h> #include <sys/mbuf.h> #include <sys/priv.h> @@ -703,7 +706,7 @@ route_output(struct mbuf *m, struct sock if (rh == NULL) senderr(EAFNOSUPPORT); - RIB_RLOCK(rh); + RIB_CFG_RLOCK(rh); if (info.rti_info[RTAX_NETMASK] == NULL && rtm->rtm_type == RTM_GET) { @@ -720,7 +723,7 @@ route_output(struct mbuf *m, struct sock info.rti_info[RTAX_NETMASK], &rh->head); if (rt == NULL) { - RIB_RUNLOCK(rh); + RIB_CFG_RUNLOCK(rh); senderr(ESRCH); } #ifdef RADIX_MPATH @@ -736,7 +739,7 @@ route_output(struct mbuf *m, struct sock (rtm->rtm_type != RTM_GET || info.rti_info[RTAX_GATEWAY])) { rt = rt_mpath_matchgate(rt, info.rti_info[RTAX_GATEWAY]); if (!rt) { - RIB_RUNLOCK(rh); + RIB_CFG_RUNLOCK(rh); senderr(ESRCH); } } @@ -769,13 +772,13 @@ route_output(struct mbuf *m, struct sock */ rt = (struct rtentry *)rh->rnh_matchaddr(&laddr, &rh->head); if (rt == NULL) { - RIB_RUNLOCK(rh); + RIB_CFG_RUNLOCK(rh); senderr(ESRCH); } } RT_LOCK(rt); RT_ADDREF(rt); - RIB_RUNLOCK(rh); + RIB_CFG_RUNLOCK(rh); report: RT_LOCK_ASSERT(rt); @@ -1868,10 +1871,10 @@ sysctl_rtsock(SYSCTL_HANDLER_ARGS) for (error = 0; error == 0 && i <= lim; i++) { rh = rt_tables_get_rnh(fib, i); if (rh != NULL) { - RIB_RLOCK(rh); + RIB_CFG_RLOCK(rh); error = rh->rnh_walktree(&rh->head, sysctl_dumpentry, &w); - RIB_RUNLOCK(rh); + RIB_CFG_RUNLOCK(rh); } else if (af != 0) error = EAFNOSUPPORT; } Modified: projects/routing/sys/netinet/in_rmx.c ============================================================================== --- projects/routing/sys/netinet/in_rmx.c Sun Aug 23 18:33:42 2015 (r287077) +++ projects/routing/sys/netinet/in_rmx.c Sun Aug 23 18:34:25 2015 (r287078) @@ -33,6 +33,9 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> +#include <sys/lock.h> +#include <sys/rwlock.h> +#include <sys/rmlock.h> #include <sys/sysctl.h> #include <sys/socket.h> #include <sys/mbuf.h> Modified: projects/routing/sys/netinet6/nd6_rtr.c ============================================================================== --- projects/routing/sys/netinet6/nd6_rtr.c Sun Aug 23 18:33:42 2015 (r287077) +++ projects/routing/sys/netinet6/nd6_rtr.c Sun Aug 23 18:34:25 2015 (r287078) @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); #include <sys/lock.h> #include <sys/errno.h> #include <sys/rwlock.h> +#include <sys/rmlock.h> #include <sys/syslog.h> #include <sys/queue.h> @@ -1555,6 +1556,7 @@ nd6_prefix_onlink_rtrequest(struct nd_pr rh = rt_tables_get_rnh(rt->rt_fibnum, AF_INET6); /* XXX what if rhn == NULL? */ + RIB_CFG_WLOCK(rh); RIB_WLOCK(rh); RT_LOCK(rt); if (rt_setgate(rt, rt_key(rt), @@ -1566,6 +1568,7 @@ nd6_prefix_onlink_rtrequest(struct nd_pr dl->sdl_index = rt->rt_ifp->if_index; } RIB_WUNLOCK(rh); + RIB_CFG_WUNLOCK(rh); nd6_rtmsg(RTM_ADD, rt); RT_UNLOCK(rt); pr->ndpr_stateflags |= NDPRF_ONLINK; Modified: projects/routing/sys/netpfil/ipfw/ip_fw_table_algo.c ============================================================================== --- projects/routing/sys/netpfil/ipfw/ip_fw_table_algo.c Sun Aug 23 18:33:42 2015 (r287077) +++ projects/routing/sys/netpfil/ipfw/ip_fw_table_algo.c Sun Aug 23 18:34:25 2015 (r287078) @@ -4020,6 +4020,7 @@ ta_foreach_kfib(void *ta_state, struct t void *arg) { struct rib_head *rh; + RIB_LOCK_READER; int error; rh = rt_tables_get_rnh(ti->data, AF_INET); Modified: projects/routing/sys/nfs/bootp_subr.c ============================================================================== --- projects/routing/sys/nfs/bootp_subr.c Sun Aug 23 18:33:42 2015 (r287077) +++ projects/routing/sys/nfs/bootp_subr.c Sun Aug 23 18:34:25 2015 (r287078) @@ -375,9 +375,9 @@ bootpboot_p_rtlist(void) rnh = rt_tables_get_rnh(0, AF_INET); if (rnh == NULL) return; - RIB_RLOCK(rnh); /* could sleep XXX */ + RIB_CFG_RLOCK(rnh); /* could sleep XXX */ bootpboot_p_tree(rh->rnh_treetop); - RIB_RUNLOCK(rnh); + RIB_CFG_RUNLOCK(rnh); } void
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201508231834.t7NIYQhS051927>