From patchwork Thu Feb 2 13:58:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13126052 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 882E3C636D4 for ; Thu, 2 Feb 2023 13:35:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231768AbjBBNfE (ORCPT ); Thu, 2 Feb 2023 08:35:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230017AbjBBNfD (ORCPT ); Thu, 2 Feb 2023 08:35:03 -0500 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF1771A962; Thu, 2 Feb 2023 05:35:01 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4P70C04Cbpz4f3mJQ; Thu, 2 Feb 2023 21:34:52 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP3 (Coremail) with SMTP id _Ch0CgBH9CH9u9tjvuV3Cg--.42880S4; Thu, 02 Feb 2023 21:34:54 +0800 (CST) From: Yu Kuai To: gregkh@linuxfoundation.org, stable@vger.kernel.org, jack@suse.cz, paolo.valente@linaro.org, axboe@kernel.dk Cc: linux-block@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [PATCH 4.19] cfq: fix memory leak for cfqq Date: Thu, 2 Feb 2023 21:58:50 +0800 Message-Id: <20230202135850.2415165-1-yukuai1@huaweicloud.com> X-Mailer: git-send-email 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r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvj fUouWlDUUUU X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Yu Kuai If cfqq is merged with another cfqq(assume that no cfqq is merged to this cfqq) and then user thread is moved to another cgroup, then check_blkcg_changed() will set cic->cfqq[1] to NULL. However, this cfqq is still merged and no one will referece this cfqq, which will cause following kmemleak: comm "cgexec", pid 2541110, jiffies 4317578508 (age 5728.064s) hex dump (first 32 bytes): 03 00 00 00 90 03 00 00 80 8d 0f be 20 80 ff ff ............ ... a0 16 c6 a1 21 80 ff ff 00 00 00 00 00 00 00 00 ....!........... backtrace: [<0000000071d2775e>] kmem_cache_alloc_node+0x13c/0x660 [<00000000e827e6fd>] cfq_get_queue+0x318/0x6f0 [<00000000945249ee>] cfq_set_request+0x724/0xe38 [<00000000af64d5a9>] elv_set_request+0x84/0xd0 [<0000000047344f0d>] __get_request+0x970/0xf90 [<00000000d016bd51>] get_request+0x278/0x970 [<0000000052512d36>] blk_queue_bio+0x278/0xcc0 [<0000000085282101>] generic_make_request+0x3c0/0x778 [<0000000089f69c24>] submit_bio+0xdc/0x408 [<00000000748509ae>] ext4_mpage_readpages+0xc84/0x13b8 [ext4] [<0000000078bfc705>] ext4_readpages+0x80/0xc0 [ext4] [<00000000317f2ed7>] read_pages+0xd0/0x610 [<00000000e7ab01d2>] __do_page_cache_readahead+0x36c/0x430 [<0000000071df2285>] ondemand_readahead+0x24c/0x6b0 [<00000000124a824a>] page_cache_sync_readahead+0x188/0x448 [<00000000bca561ae>] generic_file_buffered_read+0x648/0x2b58 unreferenced object 0xffffa028411d4720 (size 240): Fix the problem by put cooperator in check_blkcg_changed(), so that old cfqq can be freed. Signed-off-by: Yu Kuai --- block/cfq-iosched.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c index 2eb87444b157..88bae553ece3 100644 --- a/block/cfq-iosched.c +++ b/block/cfq-iosched.c @@ -3778,6 +3778,7 @@ static void check_blkcg_changed(struct cfq_io_cq *cic, struct bio *bio) if (cfqq) { cfq_log_cfqq(cfqd, cfqq, "changed cgroup"); cic_set_cfqq(cic, NULL, true); + cfq_put_cooperator(cfqq); cfq_put_queue(cfqq); }