Skip to content

Commit ccf02aa

Browse files
htejungregkh
authored andcommitted
kernfs: invoke kernfs_unmap_bin_file() directly from kernfs_deactivate()
kernfs_unmap_bin_file() is supposed to unmap all memory mappings of the target file before kernfs_remove() finishes; however, it currently is being called from kernfs_addrm_finish() and has the same race problem as the original implementation of deactivation when there are multiple removers - only the remover which snatches the node to its addrm_cxt->removed list is guaranteed to wait for its completion before returning. It can be easily fixed by moving kernfs_unmap_bin_file() invocation from kernfs_addrm_finish() to kernfs_deactivated(). The function may be called multiple times but that shouldn't do any harm. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 35beab0 commit ccf02aa

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎fs/kernfs/dir.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,10 @@ void kernfs_put_active(struct kernfs_node *kn)
177177
* kernfs_deactivate - deactivate kernfs_node
178178
* @kn: kernfs_node to deactivate
179179
*
180-
* Deny new active references and drain existing ones. Mutiple
181-
* removers may invoke this function concurrently on @kn and all will
182-
* return after deactivation and draining are complete.
180+
* Deny new active references, drain existing ones and nuke all
181+
* existing mmaps. Mutiple removers may invoke this function
182+
* concurrently on @kn and all will return after deactivation and
183+
* draining are complete.
183184
*/
184185
static void kernfs_deactivate(struct kernfs_node *kn)
185186
__releases(&kernfs_mutex) __acquires(&kernfs_mutex)
@@ -213,6 +214,8 @@ static void kernfs_deactivate(struct kernfs_node *kn)
213214
rwsem_release(&kn->dep_map, 1, _RET_IP_);
214215
}
215216

217+
kernfs_unmap_bin_file(kn);
218+
216219
mutex_lock(&kernfs_mutex);
217220
}
218221

@@ -493,7 +496,6 @@ void kernfs_addrm_finish(struct kernfs_addrm_cxt *acxt)
493496

494497
acxt->removed = kn->u.removed_list;
495498

496-
kernfs_unmap_bin_file(kn);
497499
kernfs_put(kn);
498500
}
499501
}

0 commit comments

Comments
 (0)