freebsd-dev/sys/netgraph
Robert Watson 2658b3bb8e Integrate accept locking from rwatson_netperf, introducing a new
global mutex, accept_mtx, which serializes access to the following
fields across all sockets:

          so_qlen          so_incqlen         so_qstate
          so_comp          so_incomp          so_list
          so_head

While providing only coarse granularity, this approach avoids lock
order issues between sockets by avoiding ownership of the fields
by a specific socket and its per-socket mutexes.

While here, rewrite soclose(), sofree(), soaccept(), and
sonewconn() to add assertions, close additional races and  address
lock order concerns.  In particular:

- Reorganize the optimistic concurrency behavior in accept1() to
  always allocate a file descriptor with falloc() so that if we do
  find a socket, we don't have to encounter the "Oh, there wasn't
  a socket" race that can occur if falloc() sleeps in the current
  code, which broke inbound accept() ordering, not to mention
  requiring backing out socket state changes in a way that raced
  with the protocol level.  We may want to add a lockless read of
  the queue state if polling of empty queues proves to be important
  to optimize.

- In accept1(), soref() the socket while holding the accept lock
  so that the socket cannot be free'd in a race with the protocol
  layer.  Likewise in netgraph equivilents of the accept1() code.

- In sonewconn(), loop waiting for the queue to be small enough to
  insert our new socket once we've committed to inserting it, or
  races can occur that cause the incomplete socket queue to
  overfill.  In the previously implementation, it was sufficient
  to simply tested once since calling soabort() didn't release
  synchronization permitting another thread to insert a socket as
  we discard a previous one.

- In soclose()/sofree()/et al, it is the responsibility of the
  caller to remove a socket from the incomplete connection queue
  before calling soabort(), which prevents soabort() from having
  to walk into the accept socket to release the socket from its
  queue, and avoids races when releasing the accept mutex to enter
  soabort(), permitting soabort() to avoid lock ordering issues
  with the caller.

- Generally cluster accept queue related operations together
  throughout these functions in order to facilitate locking.

Annotate new locking in socketvar.h.
2004-06-02 04:15:39 +00:00
..
atm Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
bluetooth Integrate accept locking from rwatson_netperf, introducing a new 2004-06-02 04:15:39 +00:00
netgraph.h Add a new netgraph method to allow restoration of some 2004-05-29 07:21:46 +00:00
ng_async.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_async.h Use a single style of multiple inclusion protection for Netgraph headers. 2003-11-11 12:30:37 +00:00
ng_atmllc.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_atmllc.h Add a netgraph node to handle ATM LLC encapsulation. This currently handles 2004-03-08 10:54:35 +00:00
ng_base.c Add a new netgraph method to allow restoration of some 2004-05-29 07:21:46 +00:00
ng_bpf.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_bpf.h Get rid of the deprecated *LEN constants in favour of the new 2004-01-26 14:05:31 +00:00
ng_bridge.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_bridge.h Fix GCC warnings caused by initializing a zero length array. In the process, 2002-05-31 23:48:03 +00:00
ng_cisco.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_cisco.h Use a single style of multiple inclusion protection for Netgraph headers. 2003-11-11 12:30:37 +00:00
ng_device.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_device.h Use a single style of multiple inclusion protection for Netgraph headers. 2003-11-11 12:30:37 +00:00
ng_echo.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_echo.h Use a single style of multiple inclusion protection for Netgraph headers. 2003-11-11 12:30:37 +00:00
ng_eiface.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_eiface.h Use the (now standard) Ethernet address parse type. 2003-12-17 13:03:32 +00:00
ng_etf.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_etf.h Get rid of the deprecated *LEN constants in favour of the new 2004-01-26 14:05:31 +00:00
ng_ether.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_ether.h Backout previous change, it breaks build and it is not needed 2004-02-20 08:26:27 +00:00
ng_fec.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_fec.h Use a single style of multiple inclusion protection for Netgraph headers. 2003-11-11 12:30:37 +00:00
ng_frame_relay.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_frame_relay.h Use a single style of multiple inclusion protection for Netgraph headers. 2003-11-11 12:30:37 +00:00
ng_gif_demux.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_gif_demux.h Finish driving a stake through the heart of netns and the associated 2003-03-05 19:24:24 +00:00
ng_gif.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_gif.h Fixed pedantic syntax error (trailing semicolon in enum). 2001-10-04 07:51:42 +00:00
ng_hole.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_hole.h Whitespace nit. 2004-05-19 11:35:03 +00:00
ng_hub.c Don't give up if sending to one link fails, continue. 2004-04-17 23:52:57 +00:00
ng_hub.h A simple packet distribution node type that acts like an Ethernet hub. 2004-04-17 12:42:17 +00:00
ng_iface.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_iface.h Implemented the "getifindex" control message. 2004-03-07 23:00:44 +00:00
ng_ip_input.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_ip_input.h Use a single style of multiple inclusion protection for Netgraph headers. 2003-11-11 12:30:37 +00:00
ng_ksocket.c Integrate accept locking from rwatson_netperf, introducing a new 2004-06-02 04:15:39 +00:00
ng_ksocket.h Use a single style of multiple inclusion protection for Netgraph headers. 2003-11-11 12:30:37 +00:00
ng_l2tp.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_l2tp.h Use a single style of multiple inclusion protection for Netgraph headers. 2003-11-11 12:30:37 +00:00
ng_lmi.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_lmi.h Use a single style of multiple inclusion protection for Netgraph headers. 2003-11-11 12:30:37 +00:00
ng_message.h Get rid of the deprecated *LEN constants in favour of the new 2004-01-26 14:05:31 +00:00
ng_mppc.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_mppc.h Use a single style of multiple inclusion protection for Netgraph headers. 2003-11-11 12:30:37 +00:00
ng_one2many.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_one2many.h Backout previous change, it breaks build and it is not needed 2004-02-20 08:26:27 +00:00
ng_parse.c Fix a memory leak in ng_get_string_token. A dynamically-allocated 2004-04-29 01:37:11 +00:00
ng_parse.h Get rid of the deprecated *LEN constants in favour of the new 2004-01-26 14:05:31 +00:00
ng_ppp.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_ppp.h Use a single style of multiple inclusion protection for Netgraph headers. 2003-11-11 12:30:37 +00:00
ng_pppoe.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_pppoe.h Make the vaule of PTT_RELAY_SID match the RFC. This should help PPPoE 2004-03-18 12:34:14 +00:00
ng_pptpgre.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_pptpgre.h Add 'enableWindowing' configuration knob to the ng_pptpgre(4) netgraph node. 2004-04-26 14:26:54 +00:00
ng_rfc1490.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_rfc1490.h Add an "ethernet" hook to the rfc1490 netgraph module. It will send 2004-01-14 00:39:28 +00:00
ng_sample.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_sample.h Use a single style of multiple inclusion protection for Netgraph headers. 2003-11-11 12:30:37 +00:00
ng_socket.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_socket.h Use a single style of multiple inclusion protection for Netgraph headers. 2003-11-11 12:30:37 +00:00
ng_socketvar.h Use a single style of multiple inclusion protection for Netgraph headers. 2003-11-11 12:30:37 +00:00
ng_source.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_source.h Define the new command NGM_SOURCE_START_NOW to allow generation of 2004-01-26 14:54:39 +00:00
ng_split.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_split.h Use a single style of multiple inclusion protection for Netgraph headers. 2003-11-11 12:30:37 +00:00
ng_sppp.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_sppp.h sppp (4) to netgraph (4) node. As always: I'l connect it to the 2004-03-24 17:24:01 +00:00
ng_tee.c Removed a leftover from the previous change. 2004-06-01 13:15:32 +00:00
ng_tee.h Use a single style of multiple inclusion protection for Netgraph headers. 2003-11-11 12:30:37 +00:00
ng_tty.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_tty.h Use a single style of multiple inclusion protection for Netgraph headers. 2003-11-11 12:30:37 +00:00
ng_UI.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_UI.h Use a single style of multiple inclusion protection for Netgraph headers. 2003-11-11 12:30:37 +00:00
ng_vjc.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_vjc.h Use a single style of multiple inclusion protection for Netgraph headers. 2003-11-11 12:30:37 +00:00
ng_vlan.c Switch to using C99 sparse initialisers for the type methods array. 2004-05-29 00:51:19 +00:00
ng_vlan.h Netgraph node type for IEEE 802.1Q VLAN tagging. 2004-03-01 17:22:16 +00:00
NOTES