freebsd-nq/sys/ufs/ffs
John Baldwin 800c3e80de Don't defer wakeup()s for completed journal workitems.
Normally wakeups() are performed for completed softupdates work items
in workitem_free() before the underlying memory is free()'d.
complete_jseg() was clearing the "wakeup needed" flag in work items to
defer the wakeup until the end of each loop iteration.  However, this
resulted in the item being free'd before it's address was used with
wakeup().  As a result, another part of the kernel could allocate this
memory from malloc() and use it as a wait channel for a different
"event" with a different lock.  This triggered an assertion failure
when the lock passed to sleepq_add() did not match the existing lock
associated with the sleep queue.  Fix this by removing the code to
defer the wakeup in complete_jseg() allowing the wakeup to occur
slightly earlier in workitem_free() before free() is called.

The main reason I can think of for deferring a wakeup() would be to
avoid waking up a waiter while holding a lock that the waiter would
need.  However, no locks are dropped in between the wakeup() in
workitem_free() and the end of the loop in complete_jseg() as far as I
can tell.

In general I think it is not safe to do a wakeup() after free() as one
cannot control how other parts of the kernel that might reuse the
address for a different wait channel will handle spurious wakeups.

Reported by:	pho
Reviewed by:	kib
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D12494
2017-09-26 23:24:15 +00:00
..
ffs_alloc.c Fix 32bit build. 2017-09-22 16:42:41 +00:00
ffs_balloc.c All these files need sys/vmmeter.h, but now they got it implicitly 2017-04-17 17:07:00 +00:00
ffs_extern.h Create a new function ffs_getcg() to read in and verify a cylinder 2017-06-28 17:32:09 +00:00
ffs_inode.c Continuing efforts to provide hardening of FFS, this change adds a 2017-09-22 12:45:15 +00:00
ffs_rawread.c Remove spl() calls from UFS code. 2017-05-07 14:59:45 +00:00
ffs_snapshot.c Continuing efforts to provide hardening of FFS, this change adds a 2017-09-22 12:45:15 +00:00
ffs_softdep.c Don't defer wakeup()s for completed journal workitems. 2017-09-26 23:24:15 +00:00
ffs_subr.c ANSIfy ffs_subr.c 2016-10-31 20:43:43 +00:00
ffs_suspend.c Partially lift suspension when ffs_reload() finished with cgs and 2016-09-08 12:01:28 +00:00
ffs_tables.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
ffs_vfsops.c Continuing efforts to provide hardening of FFS, this change adds a 2017-09-22 12:45:15 +00:00
ffs_vnops.c Continuing efforts to provide hardening of FFS, this change adds a 2017-09-22 12:45:15 +00:00
fs.h Continuing efforts to provide hardening of FFS, this change adds a 2017-09-22 12:45:15 +00:00
softdep.h Mitigate several problems with the softdep_request_cleanup() on busy 2017-06-03 16:18:50 +00:00