Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751690AbdFEIPU (ORCPT ); Mon, 5 Jun 2017 04:15:20 -0400 Received: from m12-11.163.com ([220.181.12.11]:56009 "EHLO m12-11.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751538AbdFEIPP (ORCPT ); Mon, 5 Jun 2017 04:15:15 -0400 From: Jia-Ju Bai To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] fs: xfs: Fix a lock-twice and sleep-in-atomic bug in xfs_iget Date: Mon, 5 Jun 2017 16:17:29 +0800 Message-Id: <1496650649-2296-1-git-send-email-baijiaju1990@163.com> X-Mailer: git-send-email 1.7.9.5 X-CM-TRANSID: C8CowACnNzsEEzVZPf47JA--.33144S2 X-Coremail-Antispam: 1Uf129KBjvdXoW7Jr1xGrykXrWxJF45Wr1rWFg_yoWfCrcEqa navw1rWw43trn3Kr43JrnIyrW0g3yI9Fn7Jr47KFW3tr45Ja93GrsrXrZxGryrW3ZxC3Z3 ArykXw1Fyrya9jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUjHqc5UUUUU== X-Originating-IP: [166.111.70.19] X-CM-SenderInfo: xedlyx5dmximizq6il2tof0z/xtbBRQftelO-7afo4gAAs5 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 910 Lines: 33 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 --- 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