HomeFreeBSD

Prevent race condition in dnode_dest (#10101)

Description

Prevent race condition in dnode_dest (#10101)

dnode_special_close() waits for the refcount of dn_holds to go to zero
without holding the dn_mtx. dnode_rele_and_unlock() does the final
remove to dn_holds with dn_mtx being held:

refs = zfs_refcount_remove(&dn->dn_holds, tag);
mutex_exit(&dn->dn_mtx);

So, there is a race condition after the remove until dn_mtx is
dropped. During that time, dnode_destroy() can get called, which ends
up in dnode_dest() calling mutex_destroy() and a panic since the lock
is still held.

This change adds a condvar to wait for the final dnode_rele_and_unlock()
to release the dn_mtx before calling dnode_destroy().

Reviewed-by: Paul Dagnelie <pcd@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Matthew Ahrens <mahrens@delphix.com>
Signed-off-by: John Poduska <jpoduska@datto.com>
Closes #7814
Closes #10101

Details

Provenance
John Poduska <jpoduska@datto.com>Authored on Mar 12 2020, 5:25 PM
GitHub <noreply@github.com>Committed on Mar 12 2020, 5:25 PM
Parents
rG1e9231ada893: Prevent deadlock in arc_read in Linux memory reclaim callback
Branches
Unknown
Tags
Unknown

Event Timeline

GitHub <noreply@github.com> committed rGe6b28efccc48: Prevent race condition in dnode_dest (#10101) (authored by John Poduska <jpoduska@datto.com>).Mar 12 2020, 5:25 PM