Fix inconsistent locking of the swap pager named objects list.
commit528a6a2f8238b93d6d9cbc3890f0af088e2bf1b7
authorkib <kib@FreeBSD.org>
Mon, 13 Jun 2016 03:42:46 +0000 (13 03:42 +0000)
committerkib <kib@FreeBSD.org>
Mon, 13 Jun 2016 03:42:46 +0000 (13 03:42 +0000)
tree4828839494817e4853b8286f51f194ab1d6d2bb0
parent501a76d1371658899cc866079b41c579cf4e0a69
Fix inconsistent locking of the swap pager named objects list.

Right now, all modifications of the list are locked by sw_alloc_mtx.
But initial lookup of the object by the handle in swap_pager_alloc()
is not protected by sw_alloc_mtx, which means that
vm_pager_object_lookup() could follow freed pointer.

Create a new named swap object with the OBJT_SWAP type, instead
of OBJT_DEFAULT.  With this change, swp_pager_meta_build() never need
to upgrade named OBJT_DEFAULT to OBJT_SWAP (in the other place, we do
not forbid for client code to create named OBJT_DEFAULT objects at
all).

That change allows to remove sw_alloc_mtx and make the list locked by
sw_alloc_sx lock.  Update swap_pager_copy() to new locking mode.

Create helper swap_pager_alloc_init() to consolidate named and
anonymous swap objects creation, while a caller ensures that the
neccesary locks are held around the helper.

Reviewed by: alc
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Approved by: re (hrs)
sys/vm/swap_pager.c