freebsd-dev/sys/netinet
Robert Watson fa046d8774 Decompose the current single inpcbinfo lock into two locks:
- The existing ipi_lock continues to protect the global inpcb list and
  inpcb counter.  This lock is now relegated to a small number of
  allocation and free operations, and occasional operations that walk
  all connections (including, awkwardly, certain UDP multicast receive
  operations -- something to revisit).

- A new ipi_hash_lock protects the two inpcbinfo hash tables for
  looking up connections and bound sockets, manipulated using new
  INP_HASH_*() macros.  This lock, combined with inpcb locks, protects
  the 4-tuple address space.

Unlike the current ipi_lock, ipi_hash_lock follows the individual inpcb
connection locks, so may be acquired while manipulating a connection on
which a lock is already held, avoiding the need to acquire the inpcbinfo
lock preemptively when a binding change might later be required.  As a
result, however, lookup operations necessarily go through a reference
acquire while holding the lookup lock, later acquiring an inpcb lock --
if required.

A new function in_pcblookup() looks up connections, and accepts flags
indicating how to return the inpcb.  Due to lock order changes, callers
no longer need acquire locks before performing a lookup: the lookup
routine will acquire the ipi_hash_lock as needed.  In the future, it will
also be able to use alternative lookup and locking strategies
transparently to callers, such as pcbgroup lookup.  New lookup flags are,
supplementing the existing INPLOOKUP_WILDCARD flag:

  INPLOOKUP_RLOCKPCB - Acquire a read lock on the returned inpcb
  INPLOOKUP_WLOCKPCB - Acquire a write lock on the returned inpcb

Callers must pass exactly one of these flags (for the time being).

Some notes:

- All protocols are updated to work within the new regime; especially,
  TCP, UDPv4, and UDPv6.  pcbinfo ipi_lock acquisitions are largely
  eliminated, and global hash lock hold times are dramatically reduced
  compared to previous locking.
- The TCP syncache still relies on the pcbinfo lock, something that we
  may want to revisit.
- Support for reverting to the FreeBSD 7.x locking strategy in TCP input
  is no longer available -- hash lookup locks are now held only very
  briefly during inpcb lookup, rather than for potentially extended
  periods.  However, the pcbinfo ipi_lock will still be acquired if a
  connection state might change such that a connection is added or
  removed.
- Raw IP sockets continue to use the pcbinfo ipi_lock for protection,
  due to maintaining their own hash tables.
- The interface in6_pcblookup_hash_locked() is maintained, which allows
  callers to acquire hash locks and perform one or more lookups atomically
  with 4-tuple allocation: this is required only for TCPv6, as there is no
  in6_pcbconnect_setup(), which there should be.
- UDPv6 locking remains significantly more conservative than UDPv4
  locking, which relates to source address selection.  This needs
  attention, as it likely significantly reduces parallelism in this code
  for multithreaded socket use (such as in BIND).
- In the UDPv4 and UDPv6 multicast cases, we need to revisit locking
  somewhat, as they relied on ipi_lock to stablise 4-tuple matches, which
  is no longer sufficient.  A second check once the inpcb lock is held
  should do the trick, keeping the general case from requiring the inpcb
  lock for every inpcb visited.
- This work reminds us that we need to revisit locking of the v4/v6 flags,
  which may be accessed lock-free both before and after this change.
- Right now, a single lock name is used for the pcbhash lock -- this is
  undesirable, and probably another argument is required to take care of
  this (or a char array name field in the pcbinfo?).

This is not an MFC candidate for 8.x due to its impact on lookup and
locking semantics.  It's possible some of these issues could be worked
around with compatibility wrappers, if necessary.

Reviewed by:    bz
Sponsored by:   Juniper Networks, Inc.
2011-05-30 09:43:55 +00:00
..
cc Staticize malloc types. 2011-04-13 11:28:46 +00:00
ipfw Decompose the current single inpcbinfo lock into two locks: 2011-05-30 09:43:55 +00:00
khelp Use the full and proper company name for Swinburne University of Technology 2011-04-12 08:13:18 +00:00
libalias LibAliasInit() should allocate memory with M_WAITOK flag. Modify it 2011-04-18 20:07:08 +00:00
accf_data.c Rework socket upcalls to close some races with setup/teardown of upcalls. 2009-06-01 21:17:03 +00:00
accf_dns.c Rework socket upcalls to close some races with setup/teardown of upcalls. 2009-06-01 21:17:03 +00:00
accf_http.c Rework socket upcalls to close some races with setup/teardown of upcalls. 2009-06-01 21:17:03 +00:00
cc.h Use the full and proper company name for Swinburne University of Technology 2011-04-12 08:13:18 +00:00
icmp6.h MFP4: @176978-176982, 176984, 176990-176994, 177441 2010-04-29 11:52:42 +00:00
icmp_var.h Many network stack subsystems use a single global data structure to hold 2009-08-02 19:43:32 +00:00
if_atm.c Bring back (most of) NATM to avoid further bitrot after r186119. 2010-12-15 22:58:45 +00:00
if_atm.h
if_ether.c - Merge changes to the base system to support OFED. These include 2011-03-21 09:40:01 +00:00
if_ether.h Add arp_update_event. This replaces route_arp_update_event, which 2009-09-08 21:17:17 +00:00
igmp_var.h
igmp.c After some off-list discussion, revert a number of changes to the 2010-11-22 19:32:54 +00:00
igmp.h These are no longer referenced in the tree, so can be safely removed. 2009-06-10 18:12:15 +00:00
in_cksum.c
in_debug.c Add initial inet DDB support for show in_ifaddr and show sin commands which 2010-10-24 22:02:36 +00:00
in_gif.c MFP4: @176978-176982, 176984, 176990-176994, 177441 2010-04-29 11:52:42 +00:00
in_gif.h
in_mcast.c Fix a few issues related to the legacy 4.4 BSD multicast APIs. 2010-04-10 12:05:31 +00:00
in_pcb.c Decompose the current single inpcbinfo lock into two locks: 2011-05-30 09:43:55 +00:00
in_pcb.h Decompose the current single inpcbinfo lock into two locks: 2011-05-30 09:43:55 +00:00
in_proto.c Add FEATURE() definitions for IPv4 and IPv6 so that we can use 2011-05-25 00:34:25 +00:00
in_rmx.c After some off-list discussion, revert a number of changes to the 2010-11-22 19:32:54 +00:00
in_systm.h
in_var.h The statically configured (permanent) ARP entries are removed when an 2011-05-20 19:12:20 +00:00
in.c Supply the LLE_STATIC flag bit to in_ifscurb() when scrubbing interface 2011-05-29 02:21:35 +00:00
in.h Make the RPC specific __rpc_inet_ntop() and __rpc_inet_pton() general 2010-09-24 15:01:45 +00:00
ip6.h Fix more continuous/contiguous typos (cf. r215955) 2010-11-27 21:51:39 +00:00
ip_carp.c Make various (pseudo) interfaces compile without INET in the kernel 2011-04-27 19:30:44 +00:00
ip_carp.h Unbreak LINT by moving all carp hooks to net/if.c / netinet/ip_carp.h, with 2010-08-11 20:18:19 +00:00
ip_divert.c Decompose the current single inpcbinfo lock into two locks: 2011-05-30 09:43:55 +00:00
ip_divert.h Various cleanup done in ipfw3-head branch including: 2010-01-04 19:01:22 +00:00
ip_dummynet.h whitespace fixes (trailing whitespace, bad indentation 2010-04-19 16:17:30 +00:00
ip_ecn.c
ip_ecn.h
ip_encap.c (S)LIST_HEAD_INITIALIZER takes a (S)LIST_HEAD as an argument. 2009-12-28 22:56:30 +00:00
ip_encap.h
ip_fastfwd.c Use correct field to track statistics counting error as bad header length. 2010-12-05 01:09:48 +00:00
ip_fw.h - Rewrite functions that copyin/out NAT configuration, so that they 2011-04-19 15:06:33 +00:00
ip_gre.c The NetBSD Foundation has granted permission to remove clause 3 and 4 from 2010-03-01 17:05:46 +00:00
ip_gre.h The NetBSD Foundation has granted permission to remove clause 3 and 4 from 2010-03-01 17:05:46 +00:00
ip_icmp.c MfP4 CH=192029: 2011-04-27 19:36:35 +00:00
ip_icmp.h MFP4: @176978-176982, 176984, 176990-176994, 177441 2010-04-29 11:52:42 +00:00
ip_id.c
ip_input.c MfP4 CH=192004: 2011-04-27 19:32:27 +00:00
ip_ipsec.c After some off-list discussion, revert a number of changes to the 2010-11-22 19:32:54 +00:00
ip_ipsec.h Remove ifdefed out part of code, which seems to have originated a decade ago 2009-11-09 19:53:34 +00:00
ip_mroute.c After some off-list discussion, revert a number of changes to the 2010-11-22 19:32:54 +00:00
ip_mroute.h Virtualize the IPv4 multicast routing code. 2010-06-02 15:44:43 +00:00
ip_options.c Use ifa_ifwithaddr_check() rather than ifa_ifwithaddr() as we are not 2010-10-14 12:32:49 +00:00
ip_options.h
ip_output.c The mbuf_frag_size always was and is file local and not queried from base 2011-04-14 09:47:09 +00:00
ip_var.h MFp4 CH=191470: 2011-04-20 08:00:29 +00:00
ip.h use u_char instead of u_int for short bitfields. 2010-02-01 14:13:44 +00:00
pim_var.h Virtualize the IPv4 multicast routing code. 2010-06-02 15:44:43 +00:00
pim.h
raw_ip.c Decompose the current single inpcbinfo lock into two locks: 2011-05-30 09:43:55 +00:00
sctp_asconf.c Remove code with any effect. 2011-05-03 20:34:02 +00:00
sctp_asconf.h 1) Typo correction in comments and one spacing change. 2011-02-05 12:12:51 +00:00
sctp_auth.c Fix a locking issue showing up on Mac OS X when subscribing to 2011-05-08 09:11:59 +00:00
sctp_auth.h Fix a locking issue showing up on Mac OS X when subscribing to 2011-05-08 09:11:59 +00:00
sctp_bsd_addr.c Improve compilation of SCTP code without INET support. 2011-04-30 11:18:16 +00:00
sctp_bsd_addr.h 1) Typo correction in comments and one spacing change. 2011-02-05 12:12:51 +00:00
sctp_cc_functions.c Implement Resource Pooling V2 and an MPTCP like congestion 2011-05-04 21:27:05 +00:00
sctp_constants.h Tunes and fixes the new DC-CC to seem to hit the 2011-03-08 11:58:25 +00:00
sctp_crc32.c 1) Typo correction in comments and one spacing change. 2011-02-05 12:12:51 +00:00
sctp_crc32.h 1) Typo correction in comments and one spacing change. 2011-02-05 12:12:51 +00:00
sctp_dtrace_declare.h Tunes and fixes the new DC-CC to seem to hit the 2011-03-08 11:58:25 +00:00
sctp_dtrace_define.h Tunes and fixes the new DC-CC to seem to hit the 2011-03-08 11:58:25 +00:00
sctp_header.h 1) Typo correction in comments and one spacing change. 2011-02-05 12:12:51 +00:00
sctp_indata.c Get rid of unused functions. 2011-05-29 18:41:06 +00:00
sctp_indata.h Get rid of unused functions. 2011-05-29 18:41:06 +00:00
sctp_input.c Fix a locking issue showing up on Mac OS X when subscribing to 2011-05-08 09:11:59 +00:00
sctp_input.h Fix a locking issue showing up on Mac OS X when subscribing to 2011-05-08 09:11:59 +00:00
sctp_lock_bsd.h 1) Typo correction in comments and one spacing change. 2011-02-05 12:12:51 +00:00
sctp_os_bsd.h Remove some leftover debug code. 2011-04-30 11:22:30 +00:00
sctp_os.h 1) Typo correction in comments and one spacing change. 2011-02-05 12:12:51 +00:00
sctp_output.c Unbreak INET-less build. 2011-05-18 19:49:39 +00:00
sctp_output.h Fix the source address selection for boundall sockets 2011-05-14 18:22:14 +00:00
sctp_pcb.c Fix a locking issue showing up on Mac OS X when subscribing to 2011-05-08 09:11:59 +00:00
sctp_pcb.h 1) Typo correction in comments and one spacing change. 2011-02-05 12:12:51 +00:00
sctp_peeloff.c Mfp4 CH=177274,177280,177284-177285,177297,177324-177325 2011-02-16 21:29:13 +00:00
sctp_peeloff.h 1) Typo correction in comments and one spacing change. 2011-02-05 12:12:51 +00:00
sctp_ss_functions.c Fix several bugs related to stream scheduling. 2011-02-13 13:53:28 +00:00
sctp_structs.h Tunes and fixes the new DC-CC to seem to hit the 2011-03-08 11:58:25 +00:00
sctp_sysctl.c Improve compilation of SCTP code without INET support. 2011-04-30 11:18:16 +00:00
sctp_sysctl.h Implement Resource Pooling V2 and an MPTCP like congestion 2011-05-04 21:27:05 +00:00
sctp_timer.c Fix a locking issue showing up on Mac OS X when subscribing to 2011-05-08 09:11:59 +00:00
sctp_timer.h 1) Typo correction in comments and one spacing change. 2011-02-05 12:12:51 +00:00
sctp_uio.h Improvements to CC modules: 2011-02-26 15:23:46 +00:00
sctp_usrreq.c Copy out the mtu when calling getsockopt() with SCTP_GET_PEER_ADDR_INFO. 2011-05-17 15:57:31 +00:00
sctp_var.h Fix a locking issue showing up on Mac OS X when subscribing to 2011-05-08 09:11:59 +00:00
sctp.h Implement Resource Pooling V2 and an MPTCP like congestion 2011-05-04 21:27:05 +00:00
sctputil.c Get rid of unused functions. 2011-05-29 18:41:06 +00:00
sctputil.h Get rid of unused functions. 2011-05-29 18:41:06 +00:00
siftr.c Decompose the current single inpcbinfo lock into two locks: 2011-05-30 09:43:55 +00:00
tcp_debug.c Remove the "The option TCPDEBUG requires option INET." requirement. 2009-06-10 10:39:41 +00:00
tcp_debug.h
tcp_fsm.h
tcp_hostcache.c sysctl(9) cleanup checkpoint: amd64 GENERIC builds cleanly. 2011-01-12 19:53:50 +00:00
tcp_hostcache.h
tcp_input.c Decompose the current single inpcbinfo lock into two locks: 2011-05-30 09:43:55 +00:00
tcp_lro.c Port of the LRO fix from mxge driver to the generic 2011-04-07 21:20:26 +00:00
tcp_lro.h Trim extra spaces before tabs. 2011-01-07 21:40:34 +00:00
tcp_offload.c Merge the remainder of kern_vimage.c and vimage.h into vnet.c and 2009-08-01 19:26:27 +00:00
tcp_offload.h Fix typos - remove duplicate "the". 2011-02-21 09:01:34 +00:00
tcp_output.c Handle a rare edge case with nearly full TCP receive buffers. If a TCP 2011-05-02 21:05:52 +00:00
tcp_reass.c Specify a CTLTYPE_FOO so that a future sysctl(8) change does not need 2011-01-18 21:14:13 +00:00
tcp_sack.c Covers values if (BYTES_THIS_ACK(tp, th) / tp->t_maxseg) value is from 2011-03-28 19:03:56 +00:00
tcp_seq.h
tcp_subr.c Decompose the current single inpcbinfo lock into two locks: 2011-05-30 09:43:55 +00:00
tcp_syncache.c Decompose the current single inpcbinfo lock into two locks: 2011-05-30 09:43:55 +00:00
tcp_syncache.h Trim extra spaces before tabs. 2011-01-07 21:40:34 +00:00
tcp_timer.c Decompose the current single inpcbinfo lock into two locks: 2011-05-30 09:43:55 +00:00
tcp_timer.h Remove the TCP inflight bandwidth limiter as announced in r211315 2010-09-16 21:06:45 +00:00
tcp_timewait.c Oops, fix order of sequence numbers in KASSERT()'s to catch negative 2011-05-14 14:41:40 +00:00
tcp_usrreq.c Decompose the current single inpcbinfo lock into two locks: 2011-05-30 09:43:55 +00:00
tcp_var.h TCP reuses t_rxtshift to determine the backoff timer used for both the 2011-04-29 15:40:12 +00:00
tcp.h Add new, per connection, statistics for TCP, including: 2010-11-17 18:55:12 +00:00
tcpip.h
toedev.h
udp_usrreq.c Decompose the current single inpcbinfo lock into two locks: 2011-05-30 09:43:55 +00:00
udp_var.h Trim extra spaces before tabs. 2011-01-07 21:40:34 +00:00
udp.h Trim extra spaces before tabs. 2011-01-07 21:40:34 +00:00