freebsd-skq/sys
rwatson 9487c057e2 Correct a number of serious and closely related bugs in the UNIX domain
socket file descriptor garbage collection code, which is intended to
detect and clear cycles of orphaned file descriptors that are "in-flight"
in a socket when that socket is closed before they are received.  The
algorithm present was both run at poor times (resulting in recursion and
reentrance), and also buggy in the presence of parallelism.  In order to
fix these problems, make the following changes:

- When there are in-flight sockets and a UNIX domain socket is destroyed,
  asynchronously schedule the garbage collector, rather than running it
  synchronously in the current context.  This avoids lock order issues
  when the garbage collection code reenters the UNIX domain socket code,
  avoiding lock order reversals, deadlocks, etc.  Run the code
  asynchronously in a task queue.

- In the garbage collector, when skipping file descriptors that have
  entered a closing state (i.e., have f_count == 0), re-test the FDEFER
  flag, and decrement unp_defer.  As file descriptors can now transition
  to a closed state, while the garbage collector is running, it is no
  longer the case that unp_defer will remain an accurate count of
  deferred sockets in the mark portion of the GC algorithm.  Otherwise,
  the garbage collector will loop waiting waiting for unp_defer to reach
  zero, which it will never do as it is skipping file descriptors that
  were marked in an earlier pass, but now closed.

- Acquire the UNIX domain socket subsystem lock in unp_discard() when
  modifying the unp_rights counter, or a read/write race is risked with
  other threads also manipulating the counter.

While here:

- Remove #if 0'd code regarding acquiring the socket buffer sleep lock in
  the garbage collector, this is not required as we are able to use the
  socket buffer receive lock to protect scanning the receive buffer for
  in-flight file descriptors on the socket buffer.

- Annotate that the description of the garbage collector implementation
  is increasingly inaccurate and needs to be updated.

- Add counters of the number of deferred garbage collections and recycled
  file descriptors.  This will be removed and is here temporarily for
  debugging purposes.

With these changes in place, the unp_passfd regression test now appears
to be passed consistently on UP and SMP systems for extended runs,
whereas before it hung quickly or panicked, depending on which bug was
triggered.

Reported by:	Philip Kizer <pckizer at nostrum dot com>
MFC after:	2 weeks
2005-11-10 16:06:04 +00:00
..
alpha Reimplement the reclamation of PV entries. Specifically, perform 2005-11-09 08:19:21 +00:00
amd64 Reimplement the reclamation of PV entries. Specifically, perform 2005-11-09 08:19:21 +00:00
arm There's no need to include <machine/asmacros.h> here. 2005-11-08 13:01:29 +00:00
boot Consistently use OPT_* macros to test/set boot options. 2005-11-03 07:35:36 +00:00
bsm For consistency with more system include files, add a trailing '_' to 2005-05-29 16:11:34 +00:00
cam Make the exploring of all luns supported by an HBA more of a 2005-09-16 01:26:17 +00:00
coda Normalize a significant number of kernel malloc type names: 2005-10-31 15:41:29 +00:00
compat Implement RtlZeroMemory() and RtlCopyMemory(). This seems to allow 2005-11-10 02:22:55 +00:00
conf Add support for XBOX to the FreeBSD port. The xbox architecture is 2005-11-09 03:55:40 +00:00
contrib Move the cloned interface list management in to if_clone. For some drivers the 2005-11-08 20:08:34 +00:00
crypto Add VIA/ACE "PadLock" support as a crypto(9) driver. 2005-08-18 00:30:22 +00:00
ddb - Rename 'traceall' to 'alltrace' so that the 'tr' shortcut for 'trace' 2005-10-24 15:21:36 +00:00
dev Give a try to autoconfiguring the number of transmit and receive 2005-11-10 11:44:37 +00:00
doc
fs This is a workaround for a complicated issue involving VFS cookies and devfs. 2005-11-09 22:03:50 +00:00
gdb
geom Normalize a significant number of kernel malloc type names: 2005-10-31 15:41:29 +00:00
gnu Normalize a significant number of kernel malloc type names: 2005-10-31 15:41:29 +00:00
i4b Propagate rename of IFF_OACTIVE and IFF_RUNNING to IFF_DRV_OACTIVE and 2005-08-09 10:20:02 +00:00
i386 Fix pc98 build. 2005-11-09 12:22:26 +00:00
ia64 Reimplement the reclamation of PV entries. Specifically, perform 2005-11-09 08:19:21 +00:00
isa Add support for XBOX to the FreeBSD port. The xbox architecture is 2005-11-09 03:55:40 +00:00
isofs/cd9660 Normalize a significant number of kernel malloc type names: 2005-10-31 15:41:29 +00:00
kern Correct a number of serious and closely related bugs in the UNIX domain 2005-11-10 16:06:04 +00:00
libkern Normalize a significant number of kernel malloc type names: 2005-10-31 15:41:29 +00:00
modules Connect em(4) build on sparc64. 2005-11-09 08:46:02 +00:00
net Use sparse initializers for "struct domain" and "struct protosw", 2005-11-09 13:29:16 +00:00
net80211 Retire MT_HEADER mbuf type and change its users to use MT_DATA. 2005-11-02 13:46:32 +00:00
netatalk Use sparse initializers for "struct domain" and "struct protosw", 2005-11-09 13:29:16 +00:00
netatm Use sparse initializers for "struct domain" and "struct protosw", 2005-11-09 13:29:16 +00:00
netgraph Make IFP2NG() usable as an lvalue. 2005-11-09 13:34:43 +00:00
netinet Use sparse initializers for "struct domain" and "struct protosw", 2005-11-09 13:29:16 +00:00
netinet6 Use sparse initializers for "struct domain" and "struct protosw", 2005-11-09 13:29:16 +00:00
netipsec Use sparse initializers for "struct domain" and "struct protosw", 2005-11-09 13:29:16 +00:00
netipx Use sparse initializers for "struct domain" and "struct protosw", 2005-11-09 13:29:16 +00:00
netkey Use sparse initializers for "struct domain" and "struct protosw", 2005-11-09 13:29:16 +00:00
netnatm Use sparse initializers for "struct domain" and "struct protosw", 2005-11-09 13:29:16 +00:00
netncp Normalize a significant number of kernel malloc type names: 2005-10-31 15:41:29 +00:00
netsmb Normalize a significant number of kernel malloc type names: 2005-10-31 15:41:29 +00:00
nfs Fixes for NFS crashes on architectures that require strict alignment. 2005-07-14 20:08:27 +00:00
nfs4client Normalize a significant number of kernel malloc type names: 2005-10-31 15:41:29 +00:00
nfsclient Fix for a crash (from nfs_lookup() in an error case). 2005-11-03 19:24:54 +00:00
nfsserver Normalize a significant number of kernel malloc type names: 2005-10-31 15:41:29 +00:00
opencrypto Fix bogus check. It was possible to panic the kernel by giving 0 length. 2005-08-18 11:58:03 +00:00
pc98 MFi386: Remove obsolete options. 2005-11-09 12:26:37 +00:00
pccard Remove the kernel portion of OLDCARD. I'm working on a replacement 2005-09-25 21:29:32 +00:00
pci - Use callout_*() to manage the callout and make it MPSAFE. 2005-10-31 21:37:27 +00:00
posix4 Const-qualify ksem_timedwait's parameter abstime as it's only passed in. 2005-10-18 11:46:24 +00:00
powerpc No longer needed: replaced by mmu_if.m/pmap_dispatch.c/mmu_oea.c 2005-11-09 10:28:51 +00:00
rpc Add GIANT_REQUIRED and WITNESS sleep warnings to uprintf() and tprintf(), 2005-09-19 16:51:43 +00:00
security Normalize a significant number of kernel malloc type names: 2005-10-31 15:41:29 +00:00
sparc64 Uncomment em(4) as it's now working. 2005-11-09 08:49:46 +00:00
sys add set/read max address 48bit versions 2005-11-10 10:29:04 +00:00
tools Add convenience macros for bus_space usage that doesn't require specification 2005-09-24 20:11:07 +00:00
ufs Slightly reorganize to reduce duplicated code. 2005-11-07 18:25:23 +00:00
vm Reimplement the reclamation of PV entries. Specifically, perform 2005-11-09 08:19:21 +00:00
Makefile