From patchwork Thu Dec 21 00:55:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Chen X-Patchwork-Id: 10126855 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 4A9A260390 for ; Thu, 21 Dec 2017 00:58:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3BCC029978 for ; Thu, 21 Dec 2017 00:58:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 307D72997A; Thu, 21 Dec 2017 00:58:11 +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 userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) (using TLSv1.2 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5D81D29978 for ; Thu, 21 Dec 2017 00:58:09 +0000 (UTC) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.21/8.16.0.21) with SMTP id vBL0qNsW059393; Thu, 21 Dec 2017 00:55:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=message-id : date : from : mime-version : to : cc : 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=eZIcRo4uRuAJsNNV3oVfv5H8XopKXRsUWF+xpYzh3VY=; b=iQD0wjatgEai+dptjEGfw/PaFzxd9qVoQcfSluRsgXiiLQL4Tot9ohqy2tD+bQfTQhuQ JPTukk8WgtMXdYgDOMi10fUqiqcd/wjnggQOh16ot0wxV5IxiFLWRLnqud65/P9S4Q5H ObGUDVXHh83t6nljMlzl30ccAWWHAOWMov3zyeNPQOYlpgBIUh6IhxHEh1wh0wKEAh+U F1RhGYyudMOkWgZmlq2RkmyyrW+bh98IKZqRapNnuJlk9aW0uCEPQJN1Y1IRzzETmEBZ /E1EaQlE/ZPxQ9UM6iDZW1XCG6x2adENS0pzGiX2hVQ03SN/UZmvh+WxHWpVQ9GXxJKJ 8g== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2f02pg00hh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Dec 2017 00:55:54 +0000 Received: from oss.oracle.com (oss-old-reserved.oracle.com [137.254.22.2]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id vBL0tojf022696 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 21 Dec 2017 00:55:50 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 1eRp9K-0007NW-0w; Wed, 20 Dec 2017 16:55:50 -0800 Received: from userv0021.oracle.com ([156.151.31.71]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1eRp91-0007Kx-45 for ocfs2-devel@oss.oracle.com; Wed, 20 Dec 2017 16:55:31 -0800 Received: from userp2030.oracle.com (userp2030.oracle.com [156.151.31.89]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id vBL0tUkb022261 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL) for ; Thu, 21 Dec 2017 00:55:30 GMT Received: from pps.filterd (userp2030.oracle.com [127.0.0.1]) by userp2030.oracle.com (8.16.0.21/8.16.0.21) with SMTP id vBL0qWrC001385 for ; Thu, 21 Dec 2017 00:55:30 GMT Received: from huawei.com (szxga04-in.huawei.com [45.249.212.190]) by userp2030.oracle.com with ESMTP id 2eyx9u6333-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Thu, 21 Dec 2017 00:55:30 +0000 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 5E9D3A8C97EDE; Thu, 21 Dec 2017 08:55:14 +0800 (CST) Received: from [127.0.0.1] (10.177.26.59) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.361.1; Thu, 21 Dec 2017 08:55:10 +0800 Message-ID: <5A3B0668.2030104@huawei.com> Date: Thu, 21 Dec 2017 08:55:04 +0800 From: alex chen User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 MIME-Version: 1.0 To: Andrew Morton , Joseph Qi , Mark Fasheh , Joel Becker , Junxiao Bi X-Originating-IP: [10.177.26.59] X-CFilter-Loop: Reflected X-CLX-Shades: MLX X-CLX-Response: 1TFkXGxwbEQpMehcZGhEKWU0XZ2ZyEQpZSRcacRoQGncGGx4bcR8bEBp3Bhg aBhoRClleF2hueREKSUYXRVhLSUZPdVpYRU5fSV5DRUQZdU9LEQpDThd7aRsdY1NaWV5TYGccXh JbeUUaUFNCXlxdUH9jHUZCWREKWFwXHwQaBBsYGAccS0hLTx4cGgUbGgQbGhoEHhIEGxAbHhofG hEKXlkXeElhWU4RCk1cFxgdEhEKTFoXaGlCTXsRCkNaFx4fBBgeEwQYGxgEGxMaEQpCXhcbEQpE XhcfEQpESRcYEQpCRhdgU24eQxlzZ1hGZhEKQlwXGhEKQkUXYhJ9YhJiaxxFa30RCkJOF2xCSFl TGk1leHgdEQpCTBdpAQEYbhlbGFJHehEKQmwXaxxCQ056SBxeekARCkJAF2ZYHB0fQ2wTH1JFEQ pCWBdifW95AU8YGXBwexEKTV4XGxEKWlgXGxEKcGcXaXBET39aYWd/cl4QGRoRCnBoF2hZbx1FW 0hiSUd4EBkaEQpwaBdlWE8YR0JrfBhzbhAZGhEKcGgXa3wcZmh9UmtGE0UQGRoRCnBoF2lZb3ln Z30dYFpJEBkaEQpwaBdrfX1yGn9fbHhFcBAZGhEKcGwXZkFOZFNLWXJgeh0QGRoRCm1+FxsRClh NF0sRIA== X-PDR: PASS X-Source-IP: 45.249.212.190 X-ServerName: szxga04-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=8751 signatures=668651 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=30 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=161 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1712210007 X-Spam: Clean Cc: "ocfs2-devel@oss.oracle.com" Subject: [Ocfs2-devel] [PATCH v2] ocfs2: fix a potential deadlock in dlm_reset_mleres_owner() 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=8751 signatures=668651 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1712210007 X-Virus-Scanned: ClamAV using ClamSMTP In dlm_reset_mleres_owner(), we will lock dlm_lock_resource->spinlock after locking dlm_ctxt->master_lock, which breaks the spinlock lock ordering: dlm_domain_lock struct dlm_ctxt->spinlock struct dlm_lock_resource->spinlock struct dlm_ctxt->master_lock Fix it by unlocking dlm_ctxt->master_lock before locking dlm_lock_resource->spinlock and restarting to clean master list. Signed-off-by: Alex Chen Reviewed-by: Jun Piao --- fs/ocfs2/dlm/dlmmaster.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/ocfs2/dlm/dlmmaster.c b/fs/ocfs2/dlm/dlmmaster.c index 3e04279..d83ccdc 100644 --- a/fs/ocfs2/dlm/dlmmaster.c +++ b/fs/ocfs2/dlm/dlmmaster.c @@ -3287,16 +3287,22 @@ static struct dlm_lock_resource *dlm_reset_mleres_owner(struct dlm_ctxt *dlm, { struct dlm_lock_resource *res; + assert_spin_locked(&dlm->spinlock); + assert_spin_locked(&dlm->master_lock); + /* Find the lockres associated to the mle and set its owner to UNK */ - res = __dlm_lookup_lockres(dlm, mle->mname, mle->mnamelen, + res = __dlm_lookup_lockres_full(dlm, mle->mname, mle->mnamelen, mle->mnamehash); if (res) { spin_unlock(&dlm->master_lock); - /* move lockres onto recovery list */ spin_lock(&res->spinlock); - dlm_set_lockres_owner(dlm, res, DLM_LOCK_RES_OWNER_UNKNOWN); - dlm_move_lockres_to_recovery_list(dlm, res); + if (!(res->state & DLM_LOCK_RES_DROPPING_REF)) { + /* move lockres onto recovery list */ + dlm_set_lockres_owner(dlm, res, DLM_LOCK_RES_OWNER_UNKNOWN); + dlm_move_lockres_to_recovery_list(dlm, res); + } + spin_unlock(&res->spinlock); dlm_lockres_put(res);