freebsd-nq/sys
Andriy Gapon 857bb3d01e firewire/sbp: try to improve locking, plus a few style nits
This change tries to fix the most obvious locking problems.

sbp_cam_scan_lun() is never called with the sbp lock held, so the lock
needs to be acquired internally (if it's needed at all).
Without this change a kernel with INVARIANTS panics when a firewire disk
is connected:
  panic: mutex sbp not owned at /usr/src/sys/dev/firewire/sbp.c:967
  KDB: stack backtrace:
  db_trace_self_wrapper() at 0xffffffff80420bbb = db_trace_self_wrapper+0x2b/frame 0xfffffe0504df0930
  kdb_backtrace() at 0xffffffff80670359 = kdb_backtrace+0x39/frame 0xfffffe0504df09e0
  vpanic() at 0xffffffff8063986c = vpanic+0x14c/frame 0xfffffe0504df0a20
  panic() at 0xffffffff806395b3 = panic+0x43/frame 0xfffffe0504df0a80
  __mtx_assert() at 0xffffffff8061c40d = __mtx_assert+0xed/frame 0xfffffe0504df0ac0
  sbp_cam_scan_lun() at 0xffffffff80474667 = sbp_cam_scan_lun+0x37/frame 0xfffffe0504df0af0
  xpt_done_process() at 0xffffffff802aacfa = xpt_done_process+0x2da/frame 0xfffffe0504df0b30
  xpt_done_td() at 0xffffffff802ac2e5 = xpt_done_td+0xd5/frame 0xfffffe0504df0b80
  fork_exit() at 0xffffffff805ff72f = fork_exit+0xdf/frame 0xfffffe0504df0bf0
  fork_trampoline() at 0xffffffff8082483e = fork_trampoline+0xe/frame
  0xfffffe0504df0bf0
  --- trap 0, rip = 0, rsp = 0, rbp = 0 ---

Also, I tried to reduce the scope of the sbp lock to avoid holding it
while doing bus_dma allocations.

The code badly needs some re-engineering.  SBP really should implement
a CAM transport, so that it avoids control flow inversion when re-scanning
the bus.  Also, the sbp lock seems to be too coarse.

Additionally, the commit includes some changes not related to locking.

- sbp_cam_scan_lun: restore CAM_DEV_QFREEZE before re-queueing the ccb
  because xpt_setup_ccb resets ccb_h.flags
- sbp_post_busreset: call xpt_release_simq only if it's actually frozen
- don't place private SIMQ_FREEZED flag (sic, "freezed") into sim->flags,
  use sbp->flags for that
- some style fixes and control flow enhancements

Reviewed by:	sbruno
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D9898
2017-03-07 16:07:52 +00:00
..
amd64 Regenerated Linuxulator syscall tables for r314782 2017-03-06 18:20:37 +00:00
arm o Another round fixes for mmc(4), mmcsd(4) and sdhci(4) regarding 2017-03-06 23:47:59 +00:00
arm64 Load the new sp_el0 with interrupts disabled in fork_trampoline. If an 2017-02-15 14:56:47 +00:00
boot Update our Allwinner DTS to latest DTS changes in Linux 4.10 2017-03-07 13:59:30 +00:00
bsm
cam Reject userland CCBs that have CAM_UNLOCKED set. 2017-03-03 20:51:57 +00:00
cddl Fix null pointer dereference in zfs_freebsd_setacl(). 2017-03-02 23:23:28 +00:00
compat Implement time_is_after_eq_jiffies() function in the LinuxKPI. 2017-03-07 15:37:51 +00:00
conf LinuxKPI workqueue cleanup. 2017-03-07 12:09:14 +00:00
contrib Merge ACPICA 20170303. 2017-03-03 18:56:15 +00:00
crypto Remove pc98 support completely. 2017-01-28 02:22:15 +00:00
ddb Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
dev firewire/sbp: try to improve locking, plus a few style nits 2017-03-07 16:07:52 +00:00
fs remove procfs ctl interface 2017-03-05 03:05:24 +00:00
gdb
geom The kern.geom.part.auto_resize should be tunable. 2017-02-28 20:51:20 +00:00
gnu Update our device tree files to a Linux 4.10 2017-03-07 13:56:49 +00:00
i386 Regenerated Linuxulator syscall tables for r314782 2017-03-06 18:20:37 +00:00
isa Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
kern don't stop in issignal() if P_SINGLE_EXIT is set 2017-03-07 13:41:01 +00:00
kgssapi
libkern strstr.c was inadvertently blasted with a copy of isa_nmi.c. Revert 2017-03-01 02:07:51 +00:00
mips o Another round fixes for mmc(4), mmcsd(4) and sdhci(4) regarding 2017-03-06 23:47:59 +00:00
modules qlxgbe: add GCC_MS_EXTENSIONS to CFLAGS to make old base GCC happy 2017-03-07 15:43:49 +00:00
net Introduce the concept of IPsec security policies scope. 2017-03-07 00:13:53 +00:00
net80211 net80211: fix ieee80211_htrateset setup, return EINVAL for an unsupported 2017-03-03 01:06:27 +00:00
netgraph mppc - Finish pluging NETGRAPH_MPPC_COMPRESSION. 2017-01-20 00:02:11 +00:00
netinet The patch provides the same socket option as Linux IP_ORIGDSTADDR. 2017-03-06 04:01:58 +00:00
netinet6 The patch provides the same socket option as Linux IP_ORIGDSTADDR. 2017-03-06 04:01:58 +00:00
netipsec Introduce the concept of IPsec security policies scope. 2017-03-07 00:13:53 +00:00
netnatm
netpfil pf: Fix a crash in low-memory situations 2017-03-06 23:41:23 +00:00
netsmb
nfs Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
nfsclient Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
nfsserver Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
nlm
ofed Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
opencrypto
powerpc Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
riscv Implement atomic_fcmpset_*() for RISC-V. 2017-02-05 00:32:12 +00:00
rpc Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
security Audit 'fd' and 'cmd' arguments to fcntl(2), and when generating BSM, 2016-11-22 00:41:24 +00:00
sparc64 Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
sys Export a sysctl dev.<clkdom>.<unit>.clocks for each clock domain containing 2017-03-05 07:13:29 +00:00
teken
tests
tools Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
ufs Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
vm Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
x86 mca: fix up couple of issues introduced with amd thresholding in r314636 2017-03-05 07:46:48 +00:00
xdr
xen xenstore: fix suspension when using the xenstore device 2017-03-07 09:17:48 +00:00
Makefile Remove pc98 support completely. 2017-01-28 02:22:15 +00:00