1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-18 10:35:55 +00:00
freebsd/sys
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
..
alpha Gainfully employ the new ttyioctl in the trivial cases. 2004-06-01 13:49:28 +00:00
amd64 Add some missing <sys/module.h> includes which are masked by the 2004-05-30 17:57:46 +00:00
arm Retire cpu_sched_exit(); it is not used any more. 2004-05-26 12:09:39 +00:00
boot Use the correct location of the EBDA for searching for the RSDP. 2004-05-25 05:52:48 +00:00
cam Quirk for Neuros USB audio device. 2004-05-02 19:24:23 +00:00
coda add missing #include <sys/module.h> 2004-05-30 20:27:19 +00:00
compat Explicitly #include <sys/module.h> instead of depending on <sys/kernel.h> 2004-06-01 23:24:17 +00:00
conf Axe the old midi drivers and framework. matk has developed a new 2004-06-01 06:22:59 +00:00
contrib "Get rid of the nested include of <sys/module.h> from <sys/kernel.h>" or 2004-05-31 22:48:19 +00:00
crypto
ddb Fixed DDB_NOKLDSYM on amd64's: 2004-05-18 05:30:06 +00:00
dev Explicitly #include <sys/module.h> in these files too (they use 2004-06-01 23:27:36 +00:00
fs Add MSG_NBIO flag option to soreceive() and sosend() that causes 2004-06-01 01:18:51 +00:00
geom Add SVR4-compatible VTOC-style elements to the Sun label. The 2004-06-01 20:18:25 +00:00
gnu
i4b add missing #include <sys/module.h> 2004-05-30 20:27:19 +00:00
i386 - Add a function ioapic_program_intpin() that completely programs an I/O 2004-06-01 20:28:42 +00:00
ia64 Gainfully employ the new ttyioctl in the trivial cases. 2004-06-01 13:49:28 +00:00
isa add missing #include <sys/module.h> 2004-05-30 20:27:19 +00:00
isofs/cd9660
kern Integrate accept locking from rwatson_netperf, introducing a new 2004-06-02 04:15:39 +00:00
libkern Import libkern arm specific bits. 2004-05-14 12:28:31 +00:00
modules add missing #include <sys/module.h> 2004-05-30 20:27:19 +00:00
net add missing #include <sys/module.h> 2004-05-30 20:27:19 +00:00
net80211 Add some missing <sys/module.h> includes which are masked by the 2004-05-30 17:57:46 +00:00
netatalk Remove redundant call to soisdisconnected() from ddp_abort(), as it 2004-05-05 03:34:37 +00:00
netatm
netgraph Integrate accept locking from rwatson_netperf, introducing a new 2004-06-02 04:15:39 +00:00
netinet add missing #include <sys/module.h> 2004-05-30 20:27:19 +00:00
netinet6 add missing #include <sys/module.h> 2004-05-30 20:27:19 +00:00
netipsec use correct address for SADB_EXT_ADDRESS_DST in key_do_allocsa_policy 2004-05-03 05:15:53 +00:00
netipx
netkey
netnatm
netncp add missing #include <sys/module.h> 2004-05-30 20:27:19 +00:00
netsmb add missing #include <sys/module.h> 2004-05-30 20:27:19 +00:00
nfs
nfs4client
nfsclient Make vm_page's PG_ZERO flag immutable between the time of the page's 2004-05-06 05:03:23 +00:00
nfsserver Giant wasn't dropped here if we have to return EBUSY. This is bad. 2004-05-31 20:21:06 +00:00
opencrypto add missing #include <sys/module.h> 2004-05-30 20:27:19 +00:00
pc98 There is no need to explicitly call the stop function. In all likelyhood 2004-06-01 11:57:15 +00:00
pccard
pci Add missing <sys/module.h> includes 2004-05-30 20:00:41 +00:00
posix4
powerpc Retire cpu_sched_exit(); it is not used any more. 2004-05-26 12:09:39 +00:00
rpc
security add missing #include <sys/module.h> 2004-05-30 20:27:19 +00:00
sparc64 Bring in mbuma to replace mballoc. 2004-05-31 21:46:06 +00:00
sys Integrate accept locking from rwatson_netperf, introducing a new 2004-06-02 04:15:39 +00:00
tools devlist2h.awk is too generic a name for what it does. It really 2004-05-26 00:19:39 +00:00
ufs - Fix typo 2004-05-31 16:55:12 +00:00
vm Fix a comment above uma_zsecond_create(), describing its arguments. 2004-06-01 01:36:26 +00:00
Makefile Try harder not to compile anything in sys/boot for arm. 2004-05-16 00:19:12 +00:00