Commit 47be6184 authored by Wei Fang's avatar Wei Fang Committed by Al Viro

fs/dcache.c: avoid soft-lockup in dput()

We triggered soft-lockup under stress test which
open/access/write/close one file concurrently on more than
five different CPUs:

WARN: soft lockup - CPU#0 stuck for 11s! [who:30631]
...
[<ffffffc0003986f8>] dput+0x100/0x298
[<ffffffc00038c2dc>] terminate_walk+0x4c/0x60
[<ffffffc00038f56c>] path_lookupat+0x5cc/0x7a8
[<ffffffc00038f780>] filename_lookup+0x38/0xf0
[<ffffffc000391180>] user_path_at_empty+0x78/0xd0
[<ffffffc0003911f4>] user_path_at+0x1c/0x28
[<ffffffc00037d4fc>] SyS_faccessat+0xb4/0x230

->d_lock trylock may failed many times because of concurrently
operations, and dput() may execute a long time.

Fix this by replacing cpu_relax() with cond_resched().
dput() used to be sleepable, so make it sleepable again
should be safe.

Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarWei Fang <fangwei1@huawei.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 285b102d
...@@ -596,7 +596,6 @@ static struct dentry *dentry_kill(struct dentry *dentry) ...@@ -596,7 +596,6 @@ static struct dentry *dentry_kill(struct dentry *dentry)
failed: failed:
spin_unlock(&dentry->d_lock); spin_unlock(&dentry->d_lock);
cpu_relax();
return dentry; /* try again with same dentry */ return dentry; /* try again with same dentry */
} }
...@@ -770,6 +769,8 @@ void dput(struct dentry *dentry) ...@@ -770,6 +769,8 @@ void dput(struct dentry *dentry)
return; return;
repeat: repeat:
might_sleep();
rcu_read_lock(); rcu_read_lock();
if (likely(fast_dput(dentry))) { if (likely(fast_dput(dentry))) {
rcu_read_unlock(); rcu_read_unlock();
...@@ -803,8 +804,10 @@ void dput(struct dentry *dentry) ...@@ -803,8 +804,10 @@ void dput(struct dentry *dentry)
kill_it: kill_it:
dentry = dentry_kill(dentry); dentry = dentry_kill(dentry);
if (dentry) if (dentry) {
cond_resched();
goto repeat; goto repeat;
}
} }
EXPORT_SYMBOL(dput); EXPORT_SYMBOL(dput);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment