All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs: xfs: Fix a lock-twice and sleep-in-atomic bug in xfs_iget
@ 2017-06-05  8:17 Jia-Ju Bai
  2017-06-05  8:32 ` Shan Hai
  2017-06-08  5:55   ` kernel test robot
  0 siblings, 2 replies; 6+ messages in thread
From: Jia-Ju Bai @ 2017-06-05  8:17 UTC (permalink / raw)
  To: darrick.wong; +Cc: linux-xfs, linux-kernel, Jia-Ju Bai

The driver may sleep under a read rcu lock, and function call path is:
xfs_iget (acquire the lock by rcu_read_lock)
  "goto out_error_or_again" after xfs_iget_cache_hit
    delay
      schedule_timeout_uninterruptible --> may sleep
Meanwhile, the rcu_read_lock will be called twice in this situation.

To fix it, the lock is released before "goto".

Signed-off-by: Jia-Ju Bai <baijiaju1990@163.com>
---
 fs/xfs/xfs_icache.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c
index f61c84f8..c2a4722 100644
--- a/fs/xfs/xfs_icache.c
+++ b/fs/xfs/xfs_icache.c
@@ -600,8 +600,10 @@ struct xfs_inode *
 
 	if (ip) {
 		error = xfs_iget_cache_hit(pag, ip, ino, flags, lock_flags);
-		if (error)
+		if (error) {
+			rcu_read_unlock();
 			goto out_error_or_again;
+		}
 	} else {
 		rcu_read_unlock();
 		XFS_STATS_INC(mp, xs_ig_missed);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-06-08  5:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-05  8:17 [PATCH] fs: xfs: Fix a lock-twice and sleep-in-atomic bug in xfs_iget Jia-Ju Bai
2017-06-05  8:32 ` Shan Hai
2017-06-05  8:56   ` Jia-Ju Bai
2017-06-08  5:55 ` [lkp-robot] [fs] 8ba626f5b2: BUG:scheduling_while_atomic kernel test robot
2017-06-08  5:55   ` kernel test robot
2017-06-08  5:55   ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.