freebsd-skq/sys
Kenneth D. Merry c552ebe12d Work around a race condition in devfs by changing the way closes
are handled in most CAM peripheral drivers that are not handled by
GEOM's disk class.

The usual character driver open and close semantics are that the
driver gets N open calls, but only one close, when the last caller
closes the device.

CAM peripheral drivers expect that behavior to be honored to the
letter, and the CAM peripheral driver code (specifically
cam_periph_release_locked_busses()) panics if it is done incorrectly.

Since devfs has to drop its locks while it calls a driver's close
routine, and it does not have a way to delay or prevent open calls
while it is calling the close routine, there is a race.

The sequence of events, simplified a bit, is:

- devfs acquires a lock
- devfs checks the reference count, and if it is 1, continues to close.
- devfs releases the lock

- 2nd process open call on the device happens here

- devfs calls the driver's close routine

- devfs acquires a lock
- devfs decrements the reference count
- devfs releases the lock

- 2nd process close call on the device happens here

At the second close, we get a panic in
cam_periph_release_locked_busses(), complaining that peripheral
has been released when the reference count is already 0.  This is
because we have gotten two closes in a row, which should not
happen.

The fix is to add the D_TRACKCLOSE flag to the driver's cdevsw, so
that we get a close() call for each open().  That does happen
reliably, so we can make sure that our reference counts are
correct.

Note that the sa(4) and pt(4) drivers only allow one context
through the open routine.  So these drivers aren't exposed to the
same race condition.

scsi_ch.c,
scsi_enc.c,
scsi_enc_internal.h,
scsi_pass.c,
scsi_sg.c:
		For these drivers, change the open() routine to
		increment the reference count for every open, and
		just decrement the reference count in the close.

		Call cam_periph_release_locked() in some scenarios
		to avoid additional lock and unlock calls.

scsi_pt.c:	Call cam_periph_release_locked() in some scenarios
		to avoid additional lock and unlock calls.

MFC after:	3 days
2012-05-27 06:11:09 +00:00
..
amd64 Regenerate system call tables. 2012-05-25 21:52:57 +00:00
arm MFp4 bz_ipv6_fast: 2012-05-24 22:00:48 +00:00
boot Import DTS files for the upcoming DPAA QorIQ (PowerPC) support. 2012-05-25 20:43:38 +00:00
bsm
cam Work around a race condition in devfs by changing the way closes 2012-05-27 06:11:09 +00:00
cddl Fix enforcement of file size limit with O_APPEND on ZFS. 2012-05-22 10:54:42 +00:00
compat Fix ki_cow for compat32 binaries. 2012-05-27 05:24:53 +00:00
conf Move OpenPIC FDT bus glue to a shared location, so that other PowerPC 2012-05-26 21:02:49 +00:00
contrib Merge ACPICA 20120518. 2012-05-24 23:12:30 +00:00
crypto Add support for the extended FPU states on amd64, both for native 2012-01-21 17:45:27 +00:00
ddb Update the ddb and gdb backends for the new 'trace_thread' hook. 2012-04-12 21:34:58 +00:00
dev Import EHCI attachment driver for Freescale integrated controller. 2012-05-26 21:05:11 +00:00
fs Use C99-style initialization for struct dirent in preparation for 2012-05-25 09:16:59 +00:00
gdb Update the ddb and gdb backends for the new 'trace_thread' hook. 2012-04-12 21:34:58 +00:00
geom Add a partition type for nandfs to the apm, bsd, gpt and vtoc8 schemes. 2012-05-25 20:33:34 +00:00
gnu/fs Fix build: 2012-05-23 06:49:50 +00:00
i386 Rename pmap_collect() to pmap_pv_reclaim() and rewrite it such that it no 2012-05-26 06:10:25 +00:00
ia64 MFp4 bz_ipv6_fast: 2012-05-24 22:00:48 +00:00
isa - There's no need to overwrite the default device method with the default 2011-11-22 21:28:20 +00:00
kern Fix ki_cow for compat32 binaries. 2012-05-27 05:24:53 +00:00
kgssapi
libkern Use strcmp that I replaced by accident. 2012-05-21 02:45:47 +00:00
mips MFp4 bz_ipv6_fast: 2012-05-24 22:00:48 +00:00
modules MFp4 bz_ipv6_fast: 2012-05-25 03:02:56 +00:00
net Turn LACP debugging from a compile time option to a sysctl, it is very handy to 2012-05-26 08:09:01 +00:00
net80211 Fix some corner cases in the ieee80211_send_bar() handling. 2012-05-22 19:37:12 +00:00
netatalk Fix typos 2012-02-28 15:07:05 +00:00
netgraph Revert my local not yet properly tested changes, that leaked in 2012-05-25 07:46:24 +00:00
netinet Trim the extra $FreeBSD$ from the comment below the license. We use 2012-05-26 10:28:11 +00:00
netinet6 Correctly get the payload length in host byte order. While we 2012-05-26 23:58:51 +00:00
netipsec Add multi-FIB IPv6 support to the core network stack supplementing 2012-02-03 13:08:44 +00:00
netipx Convert all users of IF_ADDR_LOCK to use new locking macros that specify 2012-01-05 19:00:36 +00:00
netnatm
netncp
netsmb
nfs Add multi-FIB IPv6 support to the core network stack supplementing 2012-02-03 13:08:44 +00:00
nfsclient PR# 165923 reported intermittent write failures for dirty 2012-05-12 12:02:51 +00:00
nfsserver Honor NFSv3 commit call (RFC 1813, Section 3.3.21) where when count is 0, 2011-12-15 02:26:53 +00:00
nlm jwd@ reported a problem via email to freebsd-fs@ on Aug 25, 2011 2012-01-31 02:11:05 +00:00
ofed Revert r234834 per luigi@ request. 2012-05-03 08:56:43 +00:00
opencrypto
pc98 MFprojects/zfsd: 2012-05-24 11:20:51 +00:00
pci intpm: add ATI IXP400 pci id 2012-04-16 10:33:46 +00:00
powerpc Import eSDHC driver for Freescale integrated controller. 2012-05-26 21:07:15 +00:00
rpc
security Check vplabel for NULL before dereferencing it. Fixes a panic 2012-05-03 15:51:34 +00:00
sparc64 Merge from x86: r232521 2012-05-25 14:52:05 +00:00
sys Stop treating td_sigmask specially for the purposes of new thread 2012-05-26 20:03:47 +00:00
teken
tools Make vnode_if.awk parse vnode operations with underscores, like VOP_FOO_BAR. 2012-02-21 19:35:59 +00:00
ufs Implement SEEK_HOLE/SEEK_DATA for UFS. 2012-05-26 05:29:53 +00:00
vm Tweak condition for disabling allocation from per-CPU buckets in 2012-05-23 18:56:29 +00:00
x86 Consitently use "__LP64__". 2012-05-24 21:44:46 +00:00
xdr
xen blkif interface comment cleanups. No functional changes 2012-02-29 17:47:01 +00:00
Makefile Add sys/ofed to the 'make cscope' target. 2012-03-20 18:05:15 +00:00