carp_modevent() calls carp_mod_cleanup() with carp_mtx held, and the
cleanup unregisters the generic netlink family, which takes the
generic netlink sx: a sleepable lock taken with a mutex held, which
WITNESS reports on the first kldunload. A later change makes the
unregister also wait for running handlers, which would deadlock with
carp_nl_set() taking carp_mtx in carp_alloc().
At MOD_QUIESCE, refuse the unload while vhids exist, and otherwise set
carp_unloading under carp_sx, after which carp_nl_set() fails with
ENOPROTOOPT instead of creating a vhid, so MOD_UNLOAD no longer finds
one created after MOD_QUIESCE allowed the unload. MOD_UNLOAD repeats
the check for kldunload -f, which ignores the veto, then unregisters
the family and cleans up without carp_mtx. carp_mod_cleanup() no
longer unlocks carp_mtx, which carp_mod_load() did not hold when a
protocol registration failed, nor unregisters a family that
carp_mod_load() had not registered yet.
Fixes: 40e043596409 ("carp: add netlink interface")
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")