diff options
author | Wei Fang <fangwei1@huawei.com> | 2016-07-05 23:32:20 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2016-07-24 16:37:16 -0400 |
commit | 47be61845c775643f1aa4d2a54343549f943c94c (patch) | |
tree | 7bc3d07cecb30116a51bdf11dfa0540bfacc4e43 | |
parent | 285b102d3b745f3c2c110c9c327741d87e64aacc (diff) |
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: Wei Fang <fangwei1@huawei.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | fs/dcache.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/fs/dcache.c b/fs/dcache.c index 6d60a764c848..f650a4fc5b7c 100644 --- a/fs/dcache.c +++ b/fs/dcache.c | |||
@@ -596,7 +596,6 @@ static struct dentry *dentry_kill(struct dentry *dentry) | |||
596 | 596 | ||
597 | failed: | 597 | failed: |
598 | spin_unlock(&dentry->d_lock); | 598 | spin_unlock(&dentry->d_lock); |
599 | cpu_relax(); | ||
600 | return dentry; /* try again with same dentry */ | 599 | return dentry; /* try again with same dentry */ |
601 | } | 600 | } |
602 | 601 | ||
@@ -770,6 +769,8 @@ void dput(struct dentry *dentry) | |||
770 | return; | 769 | return; |
771 | 770 | ||
772 | repeat: | 771 | repeat: |
772 | might_sleep(); | ||
773 | |||
773 | rcu_read_lock(); | 774 | rcu_read_lock(); |
774 | if (likely(fast_dput(dentry))) { | 775 | if (likely(fast_dput(dentry))) { |
775 | rcu_read_unlock(); | 776 | rcu_read_unlock(); |
@@ -803,8 +804,10 @@ repeat: | |||
803 | 804 | ||
804 | kill_it: | 805 | kill_it: |
805 | dentry = dentry_kill(dentry); | 806 | dentry = dentry_kill(dentry); |
806 | if (dentry) | 807 | if (dentry) { |
808 | cond_resched(); | ||
807 | goto repeat; | 809 | goto repeat; |
810 | } | ||
808 | } | 811 | } |
809 | EXPORT_SYMBOL(dput); | 812 | EXPORT_SYMBOL(dput); |
810 | 813 | ||