diff options
author | rwatson <rwatson@FreeBSD.org> | 2009-06-25 11:52:33 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2009-06-25 11:52:33 +0000 |
commit | ea70a3542dc7bf7a2e16d5d9c4639fd211a395b6 (patch) | |
tree | f7bd2b06a93cabd18d4d4396239234b49517bc87 /sys/netinet/raw_ip.c | |
parent | 078b9535f0627f5c60944246a4c3df0402604c44 (diff) | |
download | FreeBSD-src-ea70a3542dc7bf7a2e16d5d9c4639fd211a395b6.zip FreeBSD-src-ea70a3542dc7bf7a2e16d5d9c4639fd211a395b6.tar.gz |
Add a new global rwlock, in_ifaddr_lock, which will synchronize use of the
in_ifaddrhead and INADDR_HASH address lists.
Previously, these lists were used unsynchronized as they were effectively
never changed in steady state, but we've seen increasing reports of
writer-writer races on very busy VPN servers as core count has gone up
(and similar configurations where address lists change frequently and
concurrently).
For the time being, use rwlocks rather than rmlocks in order to take
advantage of their better lock debugging support. As a result, we don't
enable ip_input()'s read-locking of INADDR_HASH until an rmlock conversion
is complete and a performance analysis has been done. This means that one
class of reader-writer races still exists.
MFC after: 6 weeks
Reviewed by: bz
Diffstat (limited to 'sys/netinet/raw_ip.c')
-rw-r--r-- | sys/netinet/raw_ip.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 0157afb..00ec423 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -678,9 +678,12 @@ rip_ctlinput(int cmd, struct sockaddr *sa, void *vip) switch (cmd) { case PRC_IFDOWN: + IN_IFADDR_RLOCK(); TAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) { if (ia->ia_ifa.ifa_addr == sa && (ia->ia_flags & IFA_ROUTE)) { + ifa_ref(&ia->ia_ifa); + IN_IFADDR_RUNLOCK(); /* * in_ifscrub kills the interface route. */ @@ -692,18 +695,26 @@ rip_ctlinput(int cmd, struct sockaddr *sa, void *vip) * routing process they will come back. */ in_ifadown(&ia->ia_ifa, 0); + ifa_free(&ia->ia_ifa); break; } } + if (ia == NULL) /* If ia matched, already unlocked. */ + IN_IFADDR_RUNLOCK(); break; case PRC_IFUP: + IN_IFADDR_RLOCK(); TAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) { if (ia->ia_ifa.ifa_addr == sa) break; } - if (ia == 0 || (ia->ia_flags & IFA_ROUTE)) + if (ia == NULL || (ia->ia_flags & IFA_ROUTE)) { + IN_IFADDR_RUNLOCK(); return; + } + ifa_ref(&ia->ia_ifa); + IN_IFADDR_RUNLOCK(); flags = RTF_UP; ifp = ia->ia_ifa.ifa_ifp; @@ -714,6 +725,7 @@ rip_ctlinput(int cmd, struct sockaddr *sa, void *vip) err = rtinit(&ia->ia_ifa, RTM_ADD, flags); if (err == 0) ia->ia_flags |= IFA_ROUTE; + ifa_free(&ia->ia_ifa); break; } } |