Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3484014imu; Sun, 11 Nov 2018 16:08:39 -0800 (PST) X-Google-Smtp-Source: AJdET5e7cKXysvhF5RLCBX9CrfeYR6JuPbT6blxdr+O4JE9zLWUz97BjtUpOFQ//EDstjAVlYUFF X-Received: by 2002:a17:902:bb0a:: with SMTP id l10-v6mr661016pls.230.1541981319273; Sun, 11 Nov 2018 16:08:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541981319; cv=none; d=google.com; s=arc-20160816; b=Zh20TswDiT4ATJlqDGAyI26ne4INEwUoSqiug4ihZokl4scB1oIm0CTJoQ/S0dp82S OxJnh0/n6QXdCLd2qC+xIELX4/o2d27yXEK7zjkOgjee+NJ9D4lve3ImGzZ36UMl9PAQ jR3FZuda2Ba191i6aYSy2ekh8furPJDi7U3A6sK6RQ1C3zWlbXjWnA5uxhygixmCtcb3 LsbqPL2Zvb3OReradpGsP5wvQs68tWIznSMRoBRTmiitw881L8Ntp+vuOiSBu7uRQhbU 5jYz8e7RB3H0+SqfqXUoHgaE1RO9/fDeEKefCQfwqpaslUo2Ifac/UmS3buki0qzxdGI KtMA== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=lB1Zs7NsQ5qF9OiQJJgMwS2bGFLodXOMumGLG90Y89g=; b=gppo/c6jK4KaD2e8Ne9l1RUhSsvJuI2nyBElLKFKkyjHXMobOnGpdDaWSMRb99evUR FXmXjCF+AZ3ku88MbEQqAY1Oz1br0P8y2Pk+jsHnZVtoWCoLzLiOK4tbx/ub72p6Gyv2 8aR0g7PSEJiD5ibaW5vMMVFpJDc0Zg0g8frA86b4ht4v7ByJR+Ja4lEdIfOwtmA41hnZ xy50B6MtQj5yzcYDO7ZvhyjWGqWuKiYNWxVCnSgqkbB+JqqODOc+yd9gttMGmJjXWv2q hHqJOtIvoFJwf1P0wdi+TeWj06A/qVHHmSa5SCZxG7WCJix1uCSU9BTp+932RjQclv8m XWOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tOTLM5QD; 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 h18-v6si13084628pgv.47.2018.11.11.16.08.24; Sun, 11 Nov 2018 16:08:39 -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=@kernel.org header.s=default header.b=tOTLM5QD; 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 S1731984AbeKLJ63 (ORCPT + 99 others); Mon, 12 Nov 2018 04:58:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:60776 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731521AbeKLIRd (ORCPT ); Mon, 12 Nov 2018 03:17:33 -0500 Received: from localhost (unknown [206.108.79.134]) (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 6F2942175B; Sun, 11 Nov 2018 22:27:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975258; bh=1cz5uYiAAt/e292wJmiu1SncGABZ+rKiQgzhQrjqFII=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tOTLM5QDS1ZetZ+v12tanZiXMq3px4pX4504cevU9fyOts6oLaPW9/Nu1LQxJMR16 QNH6VcwIxf+S+l5IxfKt6TvxDykm7u+3gVUm5GJjor68vB7okk0tCTHFhis7atVtsj LnjfTGSSqZTZahPKdSyXCoqwLnQbcE5zDp3o9BaQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jack Wang , Xiao Ni , Shaohua Li , Sasha Levin Subject: [PATCH 4.19 135/361] md: fix memleak for mempool Date: Sun, 11 Nov 2018 14:18:02 -0800 Message-Id: <20181111221639.265118577@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jack Wang [ Upstream commit 6aaa58c994277647f8b05ffef3b9b225a2d08f36 ] I noticed kmemleak report memory leak when run create/stop md in a loop, backtrace: [<000000001ca975e7>] mempool_create_node+0x86/0xd0 [<0000000095576bcd>] md_run+0x1057/0x1410 [md_mod] [<000000007b45c5fc>] do_md_run+0x15/0x130 [md_mod] [<000000001ede9ec0>] md_ioctl+0x1f49/0x25d0 [md_mod] [<000000004142cacf>] blkdev_ioctl+0x680/0xd00 The root cause is we alloc mddev->flush_pool and mddev->flush_bio_pool in md_run, but from do_md_stop will not call into md_stop but __md_stop, move the mempool_destroy to __md_stop fixes the problem for me. The bug was introduced in 5a409b4f56d5, the fixes should go to 4.18+ Fixes: 5a409b4f56d5 ("MD: fix lock contention for flush bios") Signed-off-by: Jack Wang Reviewed-by: Xiao Ni Signed-off-by: Shaohua Li Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/md/md.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -5906,14 +5906,6 @@ static void __md_stop(struct mddev *mdde mddev->to_remove = &md_redundancy_group; module_put(pers->owner); clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); -} - -void md_stop(struct mddev *mddev) -{ - /* stop the array and free an attached data structures. - * This is called from dm-raid - */ - __md_stop(mddev); if (mddev->flush_bio_pool) { mempool_destroy(mddev->flush_bio_pool); mddev->flush_bio_pool = NULL; @@ -5922,6 +5914,14 @@ void md_stop(struct mddev *mddev) mempool_destroy(mddev->flush_pool); mddev->flush_pool = NULL; } +} + +void md_stop(struct mddev *mddev) +{ + /* stop the array and free an attached data structures. + * This is called from dm-raid + */ + __md_stop(mddev); bioset_exit(&mddev->bio_set); bioset_exit(&mddev->sync_set); }