freebsd-dev/sys
Gleb Smirnoff 93ecffe50b Improve locking strategy between keys hash and ID hash.
Before this change state creating sequence was:

1) lock wire key hash
2) link state's wire key
3) unlock wire key hash
4) lock stack key hash
5) link state's stack key
6) unlock stack key hash
7) lock ID hash
8) link into ID hash
9) unlock ID hash

What could happen here is that other thread finds the state via key
hash lookup after 6), locks ID hash and does some processing of the
state. When the thread creating state unblocks, it finds the state
it was inserting already non-virgin.

Now we perform proper interlocking between key hash locks and ID hash
lock:

1) lock wire & stack hashes
2) link state's keys
3) lock ID hash
4) unlock wire & stack hashes
5) link into ID hash
6) unlock ID hash

To achieve that, the following hacking was performed in pf_state_key_attach():

- Key hash mutex is marked with MTX_DUPOK.
- To avoid deadlock on 2 key hash mutexes, we lock them in order determined
  by their address value.
- pf_state_key_attach() had a magic to reuse a > FIN_WAIT_2 state. It unlinked
  the conflicting state synchronously. In theory this could require locking
  a third key hash, which we can't do now.
  Now we do not remove the state immediately, instead we leave this task to
  the purge thread. To avoid conflicts in a short period before state is
  purged, we push to the very end of the TAILQ.
- On success, before dropping key hash locks, pf_state_key_attach() locks
  ID hash and returns.

Tested by:	Ian FREISLICH <ianf clue.co.za>
2013-06-13 06:07:19 +00:00
..
amd64 Assert that interrupts are enabled in the trap handlers on x86 before 2013-06-03 17:40:05 +00:00
arm Increase the maximum KVM available on TI chips. Not sure why we suddenly need 2013-06-09 22:51:11 +00:00
boot - The method introduced as part of r234898 for not altering the boot path 2013-06-09 23:50:30 +00:00
bsm Implement chflagsat(2) system call, similar to fchmodat(2), but operates on 2013-03-21 22:59:01 +00:00
cam Make CAM return and GEOM DISK pass through new GEOM::lunid attribute. 2013-06-12 13:36:20 +00:00
cddl MFV r251644: 2013-06-12 07:07:06 +00:00
compat aio_mlock() added: 2013-06-08 13:30:13 +00:00
conf Migrate the LNA mixing diversity machinery from the AR9285 HAL to the driver. 2013-06-12 14:52:57 +00:00
contrib Set the FreeBSD capability bit to indicate that LNA diversity is enabled. 2013-06-13 02:20:45 +00:00
crypto When porting XTS-related code from OpenBSD I forgot to update copyright (only 2013-02-20 22:59:53 +00:00
ddb
dev Remove unused variable sc_tx_bufsz. 2013-06-13 05:46:19 +00:00
fs Relax some unnecessary unsigned type changes in ext2fs. 2013-06-13 03:23:24 +00:00
gdb
geom Make CAM return and GEOM DISK pass through new GEOM::lunid attribute. 2013-06-12 13:36:20 +00:00
gnu/fs/reiserfs Garbage collect XFS bits which are now already completely disconnected 2013-03-02 15:33:54 +00:00
i386 Assert that interrupts are enabled in the trap handlers on x86 before 2013-06-03 17:40:05 +00:00
ia64 Driver 'aacraid' added. Supports Adaptec by PMC RAID controller families Series 6, 7, 8 and upcoming products. Older Adaptec RAID controller families are supported by the 'aac' driver. 2013-05-24 09:22:43 +00:00
isa
kern Revert r251590. It unexpectedly broke the build and there were some 2013-06-10 15:22:27 +00:00
kgssapi Isilon reported that sec=krb5p NFS mounts had a problem when m_len == 0 2013-05-01 22:07:55 +00:00
libkern Attempt to mitigate poor initialization of arc4 by one-shot 2013-04-19 00:30:52 +00:00
mips Merge the 1 and 2 byte versions of the atomic functions into one. 2013-06-08 23:45:11 +00:00
modules Migrate the LNA mixing diversity machinery from the AR9285 HAL to the driver. 2013-06-12 14:52:57 +00:00
net Properly set curvnet context in lagg_port_setlladdr() task handler. 2013-06-07 10:27:50 +00:00
net80211 Don't hold the node lock over the iterator. 2013-06-07 09:03:56 +00:00
netatalk Add const qualifier to the dst parameter of the ifnet if_output method. 2013-04-26 12:50:32 +00:00
netgraph Fix several typos 2013-05-12 16:43:26 +00:00
netinet Disable IGMPv3 link timers on a transition to IGMPv2. 2013-06-07 17:12:08 +00:00
netinet6 Really fix netmask address family this time. 2013-05-19 19:42:46 +00:00
netipsec Use IP6STAT_INC/IP6STAT_DEC macros to update ip6 stats. 2013-04-09 07:11:22 +00:00
netipx
netnatm
netpfil Improve locking strategy between keys hash and ID hash. 2013-06-13 06:07:19 +00:00
netsmb If the kernel is compiled with VMIMAGE support, the first attempt of 2013-05-04 16:55:48 +00:00
nfs Move the NFS FHA (File Handle Affinity) code from sys/nfsserver to 2013-04-17 22:42:43 +00:00
nfsclient - Convert the bufobj lock to rwlock. 2013-05-31 00:43:41 +00:00
nfsserver - Convert the bufobj lock to rwlock. 2013-05-31 00:43:41 +00:00
nlm
ofed Store a reference to the vnode associated with a file descriptor in the 2013-06-11 15:37:07 +00:00
opencrypto When porting XTS-related code from OpenBSD I forgot to update copyright (only 2013-02-20 22:59:53 +00:00
pc98 MFi386: revision 251039 2013-06-01 12:21:59 +00:00
pci - Corrrect mispellings of word useful 2013-04-17 11:45:15 +00:00
powerpc Pad the PCPU MD struct, to satisfy an assert added with the projects/counters 2013-06-04 00:40:26 +00:00
rpc Fix a potential socket leak in the NFS server. If a client closes its 2013-04-08 19:03:01 +00:00
security Relax the vm object locking in mac_proc_vm_revoke_recurse(). A read lock 2013-06-04 17:23:09 +00:00
sparc64 o Relax locking assertions for vm_page_find_least() 2013-05-21 20:38:19 +00:00
sys Add PF_IEEE80211 definition. 2013-06-13 01:29:54 +00:00
teken
tools Further refine the handling of stop signals in the NFS client. The 2013-02-21 19:02:50 +00:00
ufs - Convert the bufobj lock to rwlock. 2013-05-31 00:43:41 +00:00
vm Revise the interface between vm_object_madvise() and vm_page_dontneed() so 2013-06-10 01:48:21 +00:00
x86 Add basic support for FDT to i386 & amd64. This change includes: 2013-05-21 03:05:49 +00:00
xdr Use m_get() and m_getcl() instead of compat macros. 2013-03-15 10:21:18 +00:00
xen Fix loss of the emulated keyboard on Xen PV HVM domains. 2013-05-22 19:22:44 +00:00
Makefile Remove netncp cscope entry missed in r248097 2013-03-12 14:21:52 +00:00