Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1396250ybz; Wed, 29 Apr 2020 21:35:13 -0700 (PDT) X-Google-Smtp-Source: APiQypICJYmvt1HTlo77rPoy0rnftDwHksWeDj8jQZ+DjnkO1GHZ/7I2U4aJbSTiBF4LYSxKZyFI X-Received: by 2002:a05:6402:2214:: with SMTP id cq20mr1086275edb.320.1588221312963; Wed, 29 Apr 2020 21:35:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588221312; cv=none; d=google.com; s=arc-20160816; b=f0LIYP57S3Lz+FiCFWwQ9xXC5llZL5Dv9pwZ89ZAYei/4CJ6KKbBFM3ObvnV0BCg8M iVXs/kZ+euoPLAMIxIMQSmciPFoZv/nNCSHiq57zxSr8I6ZuiL8fK4Q4dXe/Zzyv6u4K 3Gjvm2iMJcd/ujuerjSxMzi+ZTXqZPAwNUW9+g2k6wycm3olQCTiMudPHMrPGQaXX1P9 4eQrFYS3zprOlxcXeydncgkSLfsgWQCr6/qh+KpMGO+bWyeLPNQnLrKbt/ez2DH/1XCL WvCRMQMiPVfgOnxumXhngB0HdgecHUgNEgjupUWjJJG/rmjy2pbpk9spLAHYkdmmhdc/ QGZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=r2jtHapT5BIkvyz9lMSj1fKaI59RuT21dMJx2w6XijU=; b=aRakiie7BJqG+P2YJmj5dk7YJVzwJH/f3ZqLdOZzZ+gGFiV8Hakuk5kdsAb2XlL4Te oe3kfssxI6SFwNSHInX+D8uC/fazFWcT4FcEhp1fx6wAf9zqD/QA3Cn5gesNqJZhtwsP 0uG8eYxVKfBokqDRnH4mSA0Cts4KVK/PdEmQ7d6DOXh7z31XppokbLUouLJea4dPB+J7 s/k+0BdVqBpD75tE3lpLTSQIC0a58/fSNVbfY47ls5OoOp9I6GaFjgtJR3EvZuTmcx8g Rs3baGvNRlkgfPCZx6KDHNPLY0QpK6zNqcimsnNbH12ruPy88a+G2F2AUMb0gUgcRoph 53eQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f19si4983431edm.263.2020.04.29.21.34.47; Wed, 29 Apr 2020 21:35:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726453AbgD3EbO (ORCPT + 99 others); Thu, 30 Apr 2020 00:31:14 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:39172 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726329AbgD3EbN (ORCPT ); Thu, 30 Apr 2020 00:31:13 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 5FFAD95BDE18E57DB1F3; Thu, 30 Apr 2020 12:31:10 +0800 (CST) Received: from [127.0.0.1] (10.166.215.100) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Thu, 30 Apr 2020 12:31:01 +0800 Subject: Re: [PATCH V2] fs/ceph:fix double unlock in handle_cap_export() To: "Yan, Zheng" CC: Jeff Layton , Sage Weil , "Ilya Dryomov" , ceph-devel , "Linux Kernel Mailing List" , , References: <1588079622-423774-1-git-send-email-wubo40@huawei.com> <6c99072a-f92b-b7e8-9aef-509d1a9ee985@huawei.com> From: Wu Bo Message-ID: <3fb139b0-062a-9f17-1855-66dacf5d6825@huawei.com> Date: Thu, 30 Apr 2020 12:31:00 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.166.215.100] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/4/30 10:50, Yan, Zheng wrote: > On Wed, Apr 29, 2020 at 8:49 AM Wu Bo wrote: >> >> On 2020/4/28 22:48, Jeff Layton wrote: >>> On Tue, 2020-04-28 at 21:13 +0800, Wu Bo wrote: >>>> if the ceph_mdsc_open_export_target_session() return fails, >>>> should add a lock to avoid twice unlocking. >>>> Because the lock will be released at the retry or out_unlock tag. >>>> >>> >>> The problem looks real, but... >>> >>>> -- >>>> v1 -> v2: >>>> add spin_lock(&ci->i_ceph_lock) before goto out_unlock tag. >>>> >>>> Signed-off-by: Wu Bo >>>> --- >>>> fs/ceph/caps.c | 27 +++++++++++++++------------ >>>> 1 file changed, 15 insertions(+), 12 deletions(-) >>>> >>>> diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c >>>> index 185db76..414c0e2 100644 >>>> --- a/fs/ceph/caps.c >>>> +++ b/fs/ceph/caps.c >>>> @@ -3731,22 +3731,25 @@ static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex, >>>> >>>> /* open target session */ >>>> tsession = ceph_mdsc_open_export_target_session(mdsc, target); >>>> - if (!IS_ERR(tsession)) { >>>> - if (mds > target) { >>>> - mutex_lock(&session->s_mutex); >>>> - mutex_lock_nested(&tsession->s_mutex, >>>> - SINGLE_DEPTH_NESTING); >>>> - } else { >>>> - mutex_lock(&tsession->s_mutex); >>>> - mutex_lock_nested(&session->s_mutex, >>>> - SINGLE_DEPTH_NESTING); >>>> - } >>>> - new_cap = ceph_get_cap(mdsc, NULL); >>>> - } else { >>>> + if (IS_ERR(tsession)) { >>>> WARN_ON(1); >>>> tsession = NULL; >>>> target = -1; >>>> + mutex_lock(&session->s_mutex); >>>> + spin_lock(&ci->i_ceph_lock); >>>> + goto out_unlock; >>> >>> Why did you make this case goto out_unlock instead of retrying as it did >>> before? >>> >> >> If the problem occurs, target = -1, and goto retry lable, you need to >> call __get_cap_for_mds() or even call __ceph_remove_cap(), and then jump >> to out_unlock lable. All I think is unnecessary, goto out_unlock instead >> of retrying directly. >> > > __ceph_remove_cap() must be called even if opening target session > failed. I think adding a mutex_lock(&session->s_mutex) to the > IS_ERR(tsession) block should be enough. > Yes,I will send the V3 patch later. > >> Thanks. >> Wu Bo >> >>>> + } >>>> + >>>> + if (mds > target) { >>>> + mutex_lock(&session->s_mutex); >>>> + mutex_lock_nested(&tsession->s_mutex, >>>> + SINGLE_DEPTH_NESTING); >>>> + } else { >>>> + mutex_lock(&tsession->s_mutex); >>>> + mutex_lock_nested(&session->s_mutex, >>>> + SINGLE_DEPTH_NESTING); >>>> } >>>> + new_cap = ceph_get_cap(mdsc, NULL); >>>> goto retry; >>>> >>>> out_unlock: >>> >> >> > > . >