From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3717AC43219 for ; Tue, 30 Apr 2019 11:56:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EB50721670 for ; Tue, 30 Apr 2019 11:56:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556625377; bh=fNU+POHS0F6DCbGOR6/viQQKgNCjWVnUZmiRFkNT+Yo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Bf8MUb5aJpZEJpvJYL9kLYERNjmsFKKH/++Zdf7WS26ar+hdr+8w+eNdDxp51Apdd lsYYqsppxLn6/JQlkWOktjac6DHo2leOUQDG6Tk3wjWLd+1wQXBTjY4xIeyiktYRCL yM2rnifKPTkOf41UJLvaW4odPqz4mAFYlQBGI26A= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727179AbfD3L4O (ORCPT ); Tue, 30 Apr 2019 07:56:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:35292 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730399AbfD3Ls5 (ORCPT ); Tue, 30 Apr 2019 07:48:57 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 261EA20449; Tue, 30 Apr 2019 11:48:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556624936; bh=fNU+POHS0F6DCbGOR6/viQQKgNCjWVnUZmiRFkNT+Yo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dMUoMc/TwwQKaBuE14O6/tqU8UD/J8PNoWMBRUKYxvz4Ejtequ4hHrfaaAsUvktf0 qv6SmhCACz+eiXyRNeKZuSKLdCz5+KMpGX5nooEFMhJZnCHChxNyUpqcdo9q1af9Rx V2LKHQumdhH1hSOfBzF0BJZ/LIWjOU3WuXK0zA+U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Yan, Zheng" , Ilya Dryomov , Luis Henriques Subject: [PATCH 5.0 29/89] ceph: fix ci->i_head_snapc leak Date: Tue, 30 Apr 2019 13:38:20 +0200 Message-Id: <20190430113611.316091671@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190430113609.741196396@linuxfoundation.org> References: <20190430113609.741196396@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yan, Zheng commit 37659182bff1eeaaeadcfc8f853c6d2b6dbc3f47 upstream. We missed two places that i_wrbuffer_ref_head, i_wr_ref, i_dirty_caps and i_flushing_caps may change. When they are all zeros, we should free i_head_snapc. Cc: stable@vger.kernel.org Link: https://tracker.ceph.com/issues/38224 Reported-and-tested-by: Luis Henriques Signed-off-by: "Yan, Zheng" Signed-off-by: Ilya Dryomov Signed-off-by: Greg Kroah-Hartman --- fs/ceph/mds_client.c | 9 +++++++++ fs/ceph/snap.c | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -1286,6 +1286,15 @@ static int remove_session_caps_cb(struct list_add(&ci->i_prealloc_cap_flush->i_list, &to_remove); ci->i_prealloc_cap_flush = NULL; } + + if (drop && + ci->i_wrbuffer_ref_head == 0 && + ci->i_wr_ref == 0 && + ci->i_dirty_caps == 0 && + ci->i_flushing_caps == 0) { + ceph_put_snap_context(ci->i_head_snapc); + ci->i_head_snapc = NULL; + } } spin_unlock(&ci->i_ceph_lock); while (!list_empty(&to_remove)) { --- a/fs/ceph/snap.c +++ b/fs/ceph/snap.c @@ -568,7 +568,12 @@ void ceph_queue_cap_snap(struct ceph_ino old_snapc = NULL; update_snapc: - if (ci->i_head_snapc) { + if (ci->i_wrbuffer_ref_head == 0 && + ci->i_wr_ref == 0 && + ci->i_dirty_caps == 0 && + ci->i_flushing_caps == 0) { + ci->i_head_snapc = NULL; + } else { ci->i_head_snapc = ceph_get_snap_context(new_snapc); dout(" new snapc is %p\n", new_snapc); }