Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4227856ybz; Tue, 28 Apr 2020 07:50:11 -0700 (PDT) X-Google-Smtp-Source: APiQypK4zAeesPmISQ5FbDedR0SLJrVLsoF7QMOsXb12iRRhSrIz2okqp2zdZokV1V2k6h4MlDIk X-Received: by 2002:a17:906:2351:: with SMTP id m17mr20516593eja.179.1588085411374; Tue, 28 Apr 2020 07:50:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588085411; cv=none; d=google.com; s=arc-20160816; b=VNKWNW8clFktXkU5FjhX/SoJoo8Coeci5N+j1wOKq4zy6JJ1j02micrd8XoHHbfAc4 tjzlQDGNvnPTuZ6HR9l19TRVb6pUm0jB3st8BLZv8kxQOUARHAMag5dbId2cFs5Vzfm8 ZJ3mEhSOf+K68+Qqqb9RDqG3HkSPUUpz8upDyByqbKcX9+xn4aSThizoQ46H92HY/prE iGIaxwUjomhAPWN71KI4lCiggV47KEymjf1kgDn7an7WYUzGAkjLYwMzpmd4lWhowPck ebjidX3rIa64iH7EDbbBEhgEQWlleEodY67z0t4K9+vThiGebO6CNAm9f+xDhcxghogJ HPRQ== 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:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=zeuMnb+eYQtR27+RMVJ43X8wUAZiSMiaaDFAcFwOof8=; b=s76uaBvmHht+brqrRuonQQAB6szE3egUx6uu7UdMT14t5g4R1IIQE5XKPWsCFeAXOo UXpmFgGexc3v3ChS3qqrL4p/3dVpTSeeaYgvyQziHe+jh4mKZLeoqTyDE5nTNsI9zlYL 6wjxDUzily7UeiDcvWw2mURRqsfGUzpYO9SQUsyIYXiQHOsEL5zi2SaRl3ZhVzj8Mzsy XkLGMs48GJQEj5bKvR7CQ4DQN3SRWjv5C8p2mO1UZBNjdM1IJMBhcoJyI0d/PkQTtncb +nlYsre4cJfanLWr/i5iAt5Ty4leGLMlDkIW+2npgcDjPoBV0KiasHicK//Pe3qJeEeD K10w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Dgod49VS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q22si1037104edb.5.2020.04.28.07.49.48; Tue, 28 Apr 2020 07:50:11 -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; dkim=pass header.i=@kernel.org header.s=default header.b=Dgod49VS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727951AbgD1OsN (ORCPT + 99 others); Tue, 28 Apr 2020 10:48:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:44580 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727079AbgD1OsM (ORCPT ); Tue, 28 Apr 2020 10:48:12 -0400 Received: from tleilax.poochiereds.net (68-20-15-154.lightspeed.rlghnc.sbcglobal.net [68.20.15.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6680D206B9; Tue, 28 Apr 2020 14:48:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588085292; bh=wwPgZNGUMJkBXCHDH1r/tigwDvRty2wH177V7+Ns0W4=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Dgod49VSlqxpGshicvovMDfREGpxLC1t6lGRgtZtVHNWglRXLB5qLra42dNrYfBEU ebFx9zt28jyyst+DqdIBOZ1AhHY6tDsmF4h7qPSvJgFwLC3asQpUHq07vzjY4t0mDS hhq+cfprMCwe7JSaj+rDTDVw0b/+B1bEwr3hFANs= Message-ID: Subject: Re: [PATCH V2] fs/ceph:fix double unlock in handle_cap_export() From: Jeff Layton To: Wu Bo , sage@redhat.com, idryomov@gmail.com Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, liuzhiqiang26@huawei.com, linfeilong@huawei.com Date: Tue, 28 Apr 2020 10:48:10 -0400 In-Reply-To: <1588079622-423774-1-git-send-email-wubo40@huawei.com> References: <1588079622-423774-1-git-send-email-wubo40@huawei.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.1 (3.36.1-1.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 (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: -- Jeff Layton