mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 04:33:26 +02:00
mm: shrinkers: fix race condition on debugfs cleanup
When something registers and unregisters many shrinkers, such as: for x in $(seq 10000); do unshare -Ui true; done Sometimes the following error is printed to the kernel log: debugfs: Directory '...' with parent 'shrinker' already present! This occurs since commitbadc28d492
("mm: shrinkers: fix deadlock in shrinker debugfs") / v6.2: Since the call to `debugfs_remove_recursive` was moved outside the `shrinker_rwsem`/`shrinker_mutex` lock, but the call to `ida_free` stayed inside, a newly registered shrinker can be re-assigned that ID and attempt to create the debugfs directory before the directory from the previous shrinker has been removed. The locking changes in commitf95bdb700b
("mm: vmscan: make global slab shrink lockless") made the race condition more likely, though it existed before then. Commitbadc28d492
("mm: shrinkers: fix deadlock in shrinker debugfs") could be reverted since the issue is addressed should no longer occur since the count and scan operations are lockless since commit20cd1892fc
("mm: shrinkers: make count and scan in shrinker debugfs lockless"). However, since this is a contended lock, prefer instead moving `ida_free` outside the lock to avoid the race. Link: https://lkml.kernel.org/r/20230503013232.299211-1-joanbrugueram@gmail.com Fixes:badc28d492
("mm: shrinkers: fix deadlock in shrinker debugfs") Signed-off-by: Joan Bruguera Micó <joanbrugueram@gmail.com> Cc: Qi Zheng <zhengqi.arch@bytedance.com> Cc: Roman Gushchin <roman.gushchin@linux.dev> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
committed by
Andrew Morton
parent
0257d9908d
commit
26e239b37e
@@ -237,7 +237,8 @@ int shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...)
|
||||
}
|
||||
EXPORT_SYMBOL(shrinker_debugfs_rename);
|
||||
|
||||
struct dentry *shrinker_debugfs_remove(struct shrinker *shrinker)
|
||||
struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker,
|
||||
int *debugfs_id)
|
||||
{
|
||||
struct dentry *entry = shrinker->debugfs_entry;
|
||||
|
||||
@@ -246,14 +247,18 @@ struct dentry *shrinker_debugfs_remove(struct shrinker *shrinker)
|
||||
kfree_const(shrinker->name);
|
||||
shrinker->name = NULL;
|
||||
|
||||
if (entry) {
|
||||
ida_free(&shrinker_debugfs_ida, shrinker->debugfs_id);
|
||||
shrinker->debugfs_entry = NULL;
|
||||
}
|
||||
*debugfs_id = entry ? shrinker->debugfs_id : -1;
|
||||
shrinker->debugfs_entry = NULL;
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
void shrinker_debugfs_remove(struct dentry *debugfs_entry, int debugfs_id)
|
||||
{
|
||||
debugfs_remove_recursive(debugfs_entry);
|
||||
ida_free(&shrinker_debugfs_ida, debugfs_id);
|
||||
}
|
||||
|
||||
static int __init shrinker_debugfs_init(void)
|
||||
{
|
||||
struct shrinker *shrinker;
|
||||
|
Reference in New Issue
Block a user