Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2030456imu; Fri, 23 Nov 2018 03:47:33 -0800 (PST) X-Google-Smtp-Source: AFSGD/U0WwAy8sTtQmeWWwkcIeqYYztrbbCI3QBpstia26UVlCijulMzn4vzTlgza/WdeALujnuu X-Received: by 2002:a63:5265:: with SMTP id s37mr13762548pgl.326.1542973653881; Fri, 23 Nov 2018 03:47:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542973653; cv=none; d=google.com; s=arc-20160816; b=d+MKXicjUt1UStXlWLQIO6TTXxb1w202gerJ8izOeKfSZw0XN6tCGrBtvatP8kH9/6 0J/TnKSaXr0CMWY3YngRLNvXNbU5yFAh40FdmkZwE/KXIQjapiKGwOzCyc8PkPcRnxcn Vxr8hl3wgEhimB2sdqS3lEG6I9uNAaIm2/Qo2VvTOIal+sVWeHK99I8/OnryPj0+kqN4 qlDX4WIqLkYb26e1lxHueCw/hUkEuh/HnHdWn8REk6zimVsguMJboY1hdpcv4p0lXDs5 JiGAAL4Gy0+R72nzSF//DKEaZEplWAzIhnFZSDSOszyfSEnaYUEq2tD622SF8u15G7U4 QhDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature; bh=CDJ9DrmAGe6lZaDRzUIe8agiwIOYYO/q1pidu1wNtsM=; b=yGvzblGY9FkEnkh2LHOCrqRy7biywtZ599w/OKoeNw1adW3pbZ+1uKwcOlfBN9GB0I HejcyIqAbqIa8iJLze+RKZnu/bMjyGCAqx0od6tcqsi1hYNF/V+KptyJKia1+XcpFVAr 92w2+0D11Z+qYAp7uhawHjBiUXvrZlqwNkjZflfGZ1fG+ZLovBhlPi/HMObOCg4hOvei U86n5pplHB1mrRB8l7utPSJ2drPGjVzi2RkfJOQcn3cv0mR3V0mIluSPwKnKTP8tj5/H Pp0ESN59VIPKNHyaPf8MBCWifCzk9LUic8mvrdO0PshReGXS6odimrDGh6Hd9PeLy+GH jVLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=Sb6kzPIS; dkim=pass header.i=@codeaurora.org header.s=default header.b=FU6QiVxI; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31-v6si56057477plc.140.2018.11.23.03.47.14; Fri, 23 Nov 2018 03:47:33 -0800 (PST) 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; dkim=pass header.i=@codeaurora.org header.s=default header.b=Sb6kzPIS; dkim=pass header.i=@codeaurora.org header.s=default header.b=FU6QiVxI; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405446AbeKVVik (ORCPT + 99 others); Thu, 22 Nov 2018 16:38:40 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:51352 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405240AbeKVVie (ORCPT ); Thu, 22 Nov 2018 16:38:34 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id BE3ED60B11; Thu, 22 Nov 2018 10:59:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1542884380; bh=bfb0kG3+6N2FbsNZt/nLpvoGzPhzmwxc3ymqV8DoBH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sb6kzPIS8PQTfnjS1PEp2BKMiNLiUATb5GLu0mEvJIFF5MCsUB+MLUpIpb/KDbBFA WkDE870z8n2RyVf/IVXvjd0qlJzsBvcgsskV7FTaUK4dHRhNGKMcsXtDfC6J46MBKy glnqUIET/xiFMr/eooY+y1MKWf2oLI6vq/n/1hv8= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.0 Received: from codeaurora.org (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: stummala@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 52AB860791; Thu, 22 Nov 2018 10:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1542884379; bh=bfb0kG3+6N2FbsNZt/nLpvoGzPhzmwxc3ymqV8DoBH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FU6QiVxI/gnZGIgiN7nT+fS32BYDEx9kJoajVnwGOT/ZiQtdw/6BLifysT/EYPFOR rQs6nW/W+rGr0cayFoC4YBOVJFqfPf5ejyBga4D1FIPPavjTzjs83Fo57vVolAMl3R V2ltRJW8wIAX9hk6n/0a7GASEKRpsBa7gXAs9SmQ= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 52AB860791 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=stummala@codeaurora.org From: Sahitya Tummala To: Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org, Sahitya Tummala Subject: [PATCH 2/2] f2fs: fix memory leak of quota files extent tree and it's nodes Date: Thu, 22 Nov 2018 16:29:20 +0530 Message-Id: <1542884360-19470-2-git-send-email-stummala@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1542884360-19470-1-git-send-email-stummala@codeaurora.org> References: <1542884360-19470-1-git-send-email-stummala@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When there is a failure in f2fs_fill_super() after the quota is enabled, then f2fs_quota_off_umount() is called in the error handling. Then sbi is freed up and f2fs_fill_super() retries again. But f2fs_quota_off_umount() doesn't guarantee that quota file's extent tree/nodes are removed/freed. It will just add to sbi->zombie_list, if those files are referenced. In the next retry, quota is enabled again with the new extent tree and nodes, causing memory leak for the previously allocated memory. Fix this by cleaning up the sbi->zombie_list before freeing sbi and before the next retry. Signed-off-by: Sahitya Tummala --- fs/f2fs/extent_cache.c | 21 +++++++++++++++++++++ fs/f2fs/f2fs.h | 1 + fs/f2fs/super.c | 5 +++++ 3 files changed, 27 insertions(+) diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c index 763ba83..c2bcd88 100644 --- a/fs/f2fs/extent_cache.c +++ b/fs/f2fs/extent_cache.c @@ -629,6 +629,27 @@ static void f2fs_update_extent_tree_range(struct inode *inode, f2fs_mark_inode_dirty_sync(inode, true); } +void f2fs_cleanup_zombie_list(struct f2fs_sb_info *sbi) +{ + struct extent_tree *et, *next; + + mutex_lock(&sbi->extent_tree_lock); + list_for_each_entry_safe(et, next, &sbi->zombie_list, list) { + if (atomic_read(&et->node_cnt)) { + write_lock(&et->lock); + __free_extent_tree(sbi, et); + write_unlock(&et->lock); + } + f2fs_bug_on(sbi, atomic_read(&et->node_cnt)); + list_del_init(&et->list); + radix_tree_delete(&sbi->extent_tree_root, et->ino); + kmem_cache_free(extent_tree_slab, et); + atomic_dec(&sbi->total_ext_tree); + atomic_dec(&sbi->total_zombie_tree); + } + mutex_unlock(&sbi->extent_tree_lock); +} + unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink) { struct extent_tree *et, *next; diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index db8a919..6807815 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3419,6 +3419,7 @@ void f2fs_update_extent_cache_range(struct dnode_of_data *dn, void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi); int __init f2fs_create_extent_cache(void); void f2fs_destroy_extent_cache(void); +void f2fs_cleanup_zombie_list(struct f2fs_sb_info *sbi); /* * sysfs.c diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index f41ac43..521fe3f 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -3023,6 +3023,11 @@ void f2fs_cleanup_extent_cache(struct f2fs_sb_info *sbi) list_for_each_entry_safe(inode, next, &sb->s_inodes, i_sb_list) f2fs_destroy_extent_tree(inode, true); + + f2fs_cleanup_zombie_list(sbi); + + f2fs_bug_on(sbi, !list_empty(&sbi->zombie_list)); + f2fs_bug_on(sbi, !list_empty(&sbi->extent_list)); } static int f2fs_fill_super(struct super_block *sb, void *data, int silent) -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.