From patchwork Thu Dec 7 11:28:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: piaojun X-Patchwork-Id: 10098471 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 28EB4602BF for ; Thu, 7 Dec 2017 11:30:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1AEEB29F05 for ; Thu, 7 Dec 2017 11:30:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D7722A407; Thu, 7 Dec 2017 11:30:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) (using TLSv1.2 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0001B2A3F6 for ; Thu, 7 Dec 2017 11:30:01 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.21/8.16.0.21) with SMTP id vB7BRBhk094044; Thu, 7 Dec 2017 11:29:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=to : from : message-id : date : mime-version : subject : list-id : list-unsubscribe : list-archive : list-post : list-help : list-subscribe : content-type : content-transfer-encoding : sender; s=corp-2017-10-26; bh=iJLi3Aujf+BdC9Ev8smiD9G/4qn4ZS0JHnIu0H2kRZc=; b=Wv7Gm0yTOLMCtLJAgE8Bh7IkTyvOy8u2QiMhSQLPNPg1771sNNYyemIemT40uqK6xYdA QpnLjfw6h5EWF2moGryMWwEciM+yvYevKj5+urjsA1dJKNa+1UsmiCzX/XUYP8RHW4Pq TfpkMVLM6nKHfAq3qYyOd9g+k1eIHIUyjSuaY44C7q/VURj3i4M7RDaFG2f9e7zaHC6F 9UKMtAPCE0WuLokrRynwtbMrLCVxAFDliRCGes6o0N5OBuNYQfrTb+ojNg39EzmBrRwG 5hve7fjec1oFtsdSg0FEhpKu1tx8fBOZ0xDq5Ij8XtWMWphocq8JOmKPfaQXtLrP2wER jQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2epcvqptdx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2017 11:29:41 +0000 Received: from oss.oracle.com (oss-old-reserved.oracle.com [137.254.22.2]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id vB7BTZXf002249 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 7 Dec 2017 11:29:38 GMT Received: from localhost ([127.0.0.1] helo=lb-oss.oracle.com) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1eMuMx-00021P-1G; Thu, 07 Dec 2017 03:29:35 -0800 Received: from aserv0021.oracle.com ([141.146.126.233]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1eMuMu-00021D-8v for ocfs2-devel@oss.oracle.com; Thu, 07 Dec 2017 03:29:32 -0800 Received: from userp2040.oracle.com (userp2040.oracle.com [156.151.31.90]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id vB7BTVA4016553 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Thu, 7 Dec 2017 11:29:32 GMT Received: from pps.filterd (userp2040.oracle.com [127.0.0.1]) by userp2040.oracle.com (8.16.0.21/8.16.0.21) with SMTP id vB7BR1Iu010381 for ; Thu, 7 Dec 2017 11:29:31 GMT Received: from huawei.com (szxga05-in.huawei.com [45.249.212.191]) by userp2040.oracle.com with ESMTP id 2eq4f4ggn5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 07 Dec 2017 11:29:31 +0000 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 93EE591D6BAA6; Thu, 7 Dec 2017 19:29:14 +0800 (CST) Received: from [10.177.253.249] (10.177.253.249) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.361.1; Thu, 7 Dec 2017 19:29:10 +0800 To: "ocfs2-devel@oss.oracle.com" From: piaojun Message-ID: <5A2925FB.2060908@huawei.com> Date: Thu, 7 Dec 2017 19:28:59 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 X-Originating-IP: [10.177.253.249] X-CFilter-Loop: Reflected X-CLX-Shades: MLX X-CLX-Response: 1TFkXGxMYEQpMehcbHxsRCllNF2dmchEKWUkXGnEaEBp3BhsdGHEbGhkQGnc GGBoGGhEKWV4XaG55EQpJRhdFWEtJRk91WlhFTl9JXkNFRBl1T0sRCkNOF35rQhppXm0df2dben sYc2hvRllzbmRDTXVOHAdlGVkSEQpYXBcfBBoEGxgYBxxLSEtPHhwaBRsaBBsaGgQeEgQfEBseG h8aEQpeWRd4cllbGBEKTVwXHhodEQpMWhdoaUJNXREKQ1oXHh8EGB4TBBgbGAQbExsRCkJeFxsR CkReFxgRCkRJFxwRCkJGF2cTbWAbW2VCH359EQpCXBcaEQpCRRdmXGx7cGRiehJ8QxEKQk4XbEJ IWVMaTWV4eB0RCkJMF29LGRISRFl5WxtfEQpCbBdjBUJSZkBiXlp7UhEKQkAXZlBaTW5eS3N7eH 8RCkJYF2J9b3kBTxgZcHB7EQpaWBcbEQpwaBdsfl9FQh1fbWQbYhAZGhEKcGgXbBIZc1lHTGNue k4QGRoRCnBoF3ptWG9je2BMXBwYEBkaEQpwaBdtXGFlAR18W3BQHBAZGhEKcGgXb09TexpeTW0B SUEQGRoRCnBsF2FJeUN6c0l4Z2xiEBkaEQptfhcaEQpYTRdLESA= X-PDR: PASS X-Source-IP: 45.249.212.191 X-ServerName: szxga05-in.huawei.com X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 ip4:45.249.212.32 ip4:45.249.212.35 ip4:119.145.14.93 ip4:58.251.152.93 ip4:194.213.3.17 ip4:206.16.17.72 ip4:45.249.212.255 ip4:45.249.212.187/29 ip4:45.249.212.191 ~all X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8737 signatures=668643 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=151 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=192 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712070171 X-Spam: Clean Subject: [Ocfs2-devel] [PATCH] ocfs2: fix a potential 'ABBA' deadlock caused by 'l_lock' and 'dentry_attach_lock' X-BeenThere: ocfs2-devel@oss.oracle.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ocfs2-devel-bounces@oss.oracle.com Errors-To: ocfs2-devel-bounces@oss.oracle.com X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8737 signatures=668643 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712070171 X-Virus-Scanned: ClamAV using ClamSMTP CPUA CPUB ocfs2_dentry_convert_worker get 'l_lock' get 'dentry_attach_lock' interruptted by dio_end_io: dio_end_io dio_bio_end_aio dio_complete dio->end_io ocfs2_dio_end_io ocfs2_rw_unlock ... try to get 'l_lock' but CPUA has got it. try to get 'dentry_attach_lock', but CPUB has got 'dentry_attach_lock', and would not release it. so we need use spin_lock_irqsave for 'dentry_attach_lock' to prevent interruptted by softirq. Signed-off-by: Jun Piao Reviewed-by: Alex Chen --- fs/ocfs2/dcache.c | 14 ++++++++------ fs/ocfs2/dlmglue.c | 14 +++++++------- fs/ocfs2/namei.c | 5 +++-- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/fs/ocfs2/dcache.c b/fs/ocfs2/dcache.c index 2903730..6555fbf 100644 --- a/fs/ocfs2/dcache.c +++ b/fs/ocfs2/dcache.c @@ -230,6 +230,7 @@ int ocfs2_dentry_attach_lock(struct dentry *dentry, int ret; struct dentry *alias; struct ocfs2_dentry_lock *dl = dentry->d_fsdata; + unsigned long flags; trace_ocfs2_dentry_attach_lock(dentry->d_name.len, dentry->d_name.name, (unsigned long long)parent_blkno, dl); @@ -309,10 +310,10 @@ int ocfs2_dentry_attach_lock(struct dentry *dentry, ocfs2_dentry_lock_res_init(dl, parent_blkno, inode); out_attach: - spin_lock(&dentry_attach_lock); + spin_lock_irqsave(&dentry_attach_lock, flags); dentry->d_fsdata = dl; dl->dl_count++; - spin_unlock(&dentry_attach_lock); + spin_unlock_irqrestore(&dentry_attach_lock, flags); /* * This actually gets us our PRMODE level lock. From now on, @@ -333,9 +334,9 @@ int ocfs2_dentry_attach_lock(struct dentry *dentry, if (ret < 0 && !alias) { ocfs2_lock_res_free(&dl->dl_lockres); BUG_ON(dl->dl_count != 1); - spin_lock(&dentry_attach_lock); + spin_lock_irqsave(&dentry_attach_lock, flags); dentry->d_fsdata = NULL; - spin_unlock(&dentry_attach_lock); + spin_unlock_irqrestore(&dentry_attach_lock, flags); kfree(dl); iput(inode); } @@ -379,13 +380,14 @@ void ocfs2_dentry_lock_put(struct ocfs2_super *osb, struct ocfs2_dentry_lock *dl) { int unlock = 0; + unsigned long flags; BUG_ON(dl->dl_count == 0); - spin_lock(&dentry_attach_lock); + spin_lock_irqsave(&dentry_attach_lock, flags); dl->dl_count--; unlock = !dl->dl_count; - spin_unlock(&dentry_attach_lock); + spin_unlock_irqrestore(&dentry_attach_lock, flags); if (unlock) ocfs2_drop_dentry_lock(osb, dl); diff --git a/fs/ocfs2/dlmglue.c b/fs/ocfs2/dlmglue.c index 4689940..9bff3d2 100644 --- a/fs/ocfs2/dlmglue.c +++ b/fs/ocfs2/dlmglue.c @@ -3801,7 +3801,7 @@ static int ocfs2_dentry_convert_worker(struct ocfs2_lock_res *lockres, struct ocfs2_dentry_lock *dl = ocfs2_lock_res_dl(lockres); struct ocfs2_inode_info *oi = OCFS2_I(dl->dl_inode); struct dentry *dentry; - unsigned long flags; + unsigned long flags, d_flags; int extra_ref = 0; /* @@ -3831,13 +3831,13 @@ static int ocfs2_dentry_convert_worker(struct ocfs2_lock_res *lockres, * flag. */ spin_lock_irqsave(&lockres->l_lock, flags); - spin_lock(&dentry_attach_lock); + spin_lock_irqsave(&dentry_attach_lock, d_flags); if (!(lockres->l_flags & OCFS2_LOCK_FREEING) && dl->dl_count) { dl->dl_count++; extra_ref = 1; } - spin_unlock(&dentry_attach_lock); + spin_unlock_irqrestore(&dentry_attach_lock, d_flags); spin_unlock_irqrestore(&lockres->l_lock, flags); mlog(0, "extra_ref = %d\n", extra_ref); @@ -3850,13 +3850,13 @@ static int ocfs2_dentry_convert_worker(struct ocfs2_lock_res *lockres, if (!extra_ref) return UNBLOCK_CONTINUE; - spin_lock(&dentry_attach_lock); + spin_lock_irqsave(&dentry_attach_lock, d_flags); while (1) { dentry = ocfs2_find_local_alias(dl->dl_inode, dl->dl_parent_blkno, 1); if (!dentry) break; - spin_unlock(&dentry_attach_lock); + spin_unlock_irqrestore(&dentry_attach_lock, d_flags); if (S_ISDIR(dl->dl_inode->i_mode)) shrink_dcache_parent(dentry); @@ -3874,9 +3874,9 @@ static int ocfs2_dentry_convert_worker(struct ocfs2_lock_res *lockres, d_delete(dentry); dput(dentry); - spin_lock(&dentry_attach_lock); + spin_lock_irqsave(&dentry_attach_lock, d_flags); } - spin_unlock(&dentry_attach_lock); + spin_unlock_irqrestore(&dentry_attach_lock, d_flags); /* * If we are the last holder of this dentry lock, there is no diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c index 3b0a10d..a17454e 100644 --- a/fs/ocfs2/namei.c +++ b/fs/ocfs2/namei.c @@ -223,13 +223,14 @@ static void ocfs2_cleanup_add_entry_failure(struct ocfs2_super *osb, struct dentry *dentry, struct inode *inode) { struct ocfs2_dentry_lock *dl = dentry->d_fsdata; + unsigned long flags; ocfs2_simple_drop_lockres(osb, &dl->dl_lockres); ocfs2_lock_res_free(&dl->dl_lockres); BUG_ON(dl->dl_count != 1); - spin_lock(&dentry_attach_lock); + spin_lock_irqsave(&dentry_attach_lock, flags); dentry->d_fsdata = NULL; - spin_unlock(&dentry_attach_lock); + spin_unlock_irqrestore(&dentry_attach_lock, flags); kfree(dl); iput(inode); }