Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1460980ybm; Thu, 23 May 2019 01:10:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqye0vJ1cWZDXscTNn5JpIDNogP40SUGnZphTvrk7QQAYpQbL+yfGnrqbmk4O+++P3dgGXm3 X-Received: by 2002:a17:902:ac90:: with SMTP id h16mr32715464plr.162.1558599056268; Thu, 23 May 2019 01:10:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558599056; cv=none; d=google.com; s=arc-20160816; b=cThwgcEyzrtvFz0+2ygnl4aa30zGUZUun+uvJ+7XUvc1PPQDu80x79uSaIbdiZKR1Z tlRn1kxwIf4W3GvCz/84ANqJcXEGV7CTU+boFXai7FAtEv9e8ba1fZYZTnhPrsL25uuk gIG9Bx4GW2oaaLq6QGm/GQEU7H72eMlvd4Fzz9pW2m/XrZgwzAeu7yw8LdgtmHUypUs4 /GXcOqYZiW1p4FiSAppuDXRhNNY6o8m69+P4N3Bg8fICPE2FwhU5lIBGC4qv4QpSrQux 6Cz24SHwHV/f1Jr+orqDqd4O/sCSOAs7IO2HCM7IqeBphmOpf2ZNMm+bnxgXqquNOIfw 2HzA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=9LATe5Zv0UVlF/jNL2m695jqWqD/Xty0roUnQhn3VtA=; b=igVZFYj/nxZjgqWAXlgxLx2Cj0/x3ji5yGNNLnKhPsBKQ1AcO/NVThWOToLszrmLQl uprMUGwPa0FE+jZhB6jOYahYsATki/nVUc8zZebekZCfFH5bpi6p04Jil3zmhTc4g8Rp 6ft33pZHb86/apDCI5+fC59NrAq1KRCwqZ/yI8bloEf6k70p9s6ERrTf9k+RqQ5Aw/S0 CD4tkaahj6zfVHeFrVT2fsN/rfuxfcdi1mtV66FMeFLkryPL1/vdTdxgsvWflCmPPCwN um6nsjJGV/fm2p4ajwNj6u0E1xK6JmN0VmAj3/9/p7Pf9YGUvdT6k4q/lh70fFE/KPz1 LXFg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y1si2264415pgf.211.2019.05.23.01.10.37; Thu, 23 May 2019 01:10:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730202AbfEWIHL (ORCPT + 99 others); Thu, 23 May 2019 04:07:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36664 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726222AbfEWIHJ (ORCPT ); Thu, 23 May 2019 04:07:09 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D9DE68830E for ; Thu, 23 May 2019 08:07:09 +0000 (UTC) Received: from zhyan-laptop.redhat.com (ovpn-12-163.pek2.redhat.com [10.72.12.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id 350B05D9C6; Thu, 23 May 2019 08:07:07 +0000 (UTC) From: "Yan, Zheng" To: linux-kernel@vger.kernel.org Cc: idryomov@redhat.com, jlayton@redhat.com Subject: [PATCH 8/8] ceph: hold i_ceph_lock when removing caps for freeing inode Date: Thu, 23 May 2019 16:06:46 +0800 Message-Id: <20190523080646.19632-8-zyan@redhat.com> In-Reply-To: <20190523080646.19632-1-zyan@redhat.com> References: <20190523080646.19632-1-zyan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 23 May 2019 08:07:09 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ceph_d_revalidate(, LOOKUP_RCU) may call __ceph_caps_issued_mask() on a freeing inode. Cc: stable@vger.kernel.org Signed-off-by: "Yan, Zheng" --- fs/ceph/caps.c | 10 ++++++---- fs/ceph/inode.c | 2 +- fs/ceph/super.h | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 0176241eaea7..7754d7679122 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -1263,20 +1263,22 @@ static int send_cap_msg(struct cap_msg_args *arg) } /* - * Queue cap releases when an inode is dropped from our cache. Since - * inode is about to be destroyed, there is no need for i_ceph_lock. + * Queue cap releases when an inode is dropped from our cache. */ -void __ceph_remove_caps(struct inode *inode) +void __ceph_remove_caps(struct ceph_inode_info *ci) { - struct ceph_inode_info *ci = ceph_inode(inode); struct rb_node *p; + /* lock i_ceph_lock, because ceph_d_revalidate(..., LOOKUP_RCU) + * may call __ceph_caps_issued_mask() on a freeing inode. */ + spin_lock(&ci->i_ceph_lock); p = rb_first(&ci->i_caps); while (p) { struct ceph_cap *cap = rb_entry(p, struct ceph_cap, ci_node); p = rb_next(p); __ceph_remove_cap(cap, true); } + spin_unlock(&ci->i_ceph_lock); } /* diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index e47a25495be5..30d0cdc21035 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -534,7 +534,7 @@ void ceph_destroy_inode(struct inode *inode) ceph_fscache_unregister_inode_cookie(ci); - __ceph_remove_caps(inode); + __ceph_remove_caps(ci); if (__ceph_has_any_quota(ci)) ceph_adjust_quota_realms_count(inode, false); diff --git a/fs/ceph/super.h b/fs/ceph/super.h index 11aeb540b0cf..e74867743e07 100644 --- a/fs/ceph/super.h +++ b/fs/ceph/super.h @@ -1003,7 +1003,7 @@ extern void ceph_add_cap(struct inode *inode, unsigned cap, unsigned seq, u64 realmino, int flags, struct ceph_cap **new_cap); extern void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release); -extern void __ceph_remove_caps(struct inode* inode); +extern void __ceph_remove_caps(struct ceph_inode_info *ci); extern void ceph_put_cap(struct ceph_mds_client *mdsc, struct ceph_cap *cap); extern int ceph_is_any_caps(struct inode *inode); -- 2.17.2