From patchwork Mon Sep 18 12:09:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13389538 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 026C0C46CA1 for ; Mon, 18 Sep 2023 12:10:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 571966B032B; Mon, 18 Sep 2023 08:10:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 521E06B032D; Mon, 18 Sep 2023 08:10:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C3746B032F; Mon, 18 Sep 2023 08:10:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2D9716B032B for ; Mon, 18 Sep 2023 08:10:38 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 024111CAB14 for ; Mon, 18 Sep 2023 12:10:37 +0000 (UTC) X-FDA: 81249601356.05.79DDB64 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf11.hostedemail.com (Postfix) with ESMTP id D97DC40012 for ; Mon, 18 Sep 2023 12:10:34 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.hostedemail.com: domain of ruanjinjie@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=ruanjinjie@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695039036; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TL79/b7WRnBrG95p+70ViKkiyAU9oWj/HDEFTEwS2ZM=; b=4EZmu+kWQiimlfkGANUGANHsPLj6B8QI70uQEo63qVoertIOIowKa45H4irjGlDlnf7E13 JvLVU4Fng9p01RFi/RVl28pU2coKeQb2OY9LomAsM01PaehwPhYUCo7t+Bymx/pzqvL9vM agSojPbUa9q8b73HdKufBZ8yNUj4QD0= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.hostedemail.com: domain of ruanjinjie@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=ruanjinjie@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695039036; a=rsa-sha256; cv=none; b=VKr3knM1C4+FTGuUgZRBprh+87TBmgjmfdzQE4EiddlnzO3AD9uiqblGY64x4diit6PngS dx/WzAKcom/CaXzSd0ERl6N2wcdvErZUYgcEYY81Ph9gBqnpEQSx4f5rD4zi375PhR8c6k aNFKWlXulc9/OBeWjfb4p9DZFxXEwgg= Received: from kwepemi500008.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Rq3T12BGVzVkwV; Mon, 18 Sep 2023 20:07:33 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemi500008.china.huawei.com (7.221.188.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 18 Sep 2023 20:10:27 +0800 From: Jinjie Ruan To: , , , , , , , , CC: Subject: [PATCH v3 2/2] mm/damon/core-test: Fix memory leak in damon_new_ctx() Date: Mon, 18 Sep 2023 20:09:51 +0800 Message-ID: <20230918120951.2230468-3-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230918120951.2230468-1-ruanjinjie@huawei.com> References: <20230918120951.2230468-1-ruanjinjie@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemi500008.china.huawei.com (7.221.188.139) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: D97DC40012 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 16k41mbbpboje11khj11onbnhsmu3u54 X-HE-Tag: 1695039034-654067 X-HE-Meta: U2FsdGVkX18HSdq3B2fDjbMh3juOo7FgfiZ6PlaOx/78Gjg0zAVKFRckzr5jqtts1o8r1ys4vqgFY5vpuREtHVrgtQfZh4XVW5zZ575glKIeqExfjoDicjI1g3D+H5H+pPf8tyDzDHg7fd5DfBO1IKQoJSWDdcszMpwTCBE/q0aaaVMKmKLgiZ1NoExevOm7CUlYMSMd7VcNBzzrY64mHwXfYyq8a/ZxcyaKUcunJeMptZqGvwNU1yJ5ipDElvNHcxDJbcCt/MfFhhnGU4rsXmP8WVYQMGL4VvThd5ATcJR1nm94TKKjl2OWO5NEv4a1uQVFkjoq04J6XHCpRnTvKD0ZwjnmoBQ8gl+RyOC2bl8zPzkUQhmQopV8nbyeUQcJIyJ7Vz6D1Ukon5UIijpDRFVIvsUyG14u7QIE7fip4v1qi1fqYszK9BbuAxOwa9kruA9tl3/eJszeYujJYX3mm4Fu2725fDNLTXvM+ZjgdHE97hZycmWBV1XVgbyoAkGdvcA2X9K/adAso6fr0bAmMR+2YsYPHmEpzhk6p4CjdpE9MqEUuASFaLCTmuTn91ntMluKSr2AmKYAoOtc0lylclhTjyIYwbWx3L3TQFuJhjDV/3Chk4km4TPEDEg+x6rS2BI975R6GFu7ePsAXZQgFOTvp53Ndr+3g3ZoLX7H8c5azxE8r98IrKBz61IAmHPlzVBBCuLVHUWAd3B4pTxsMQNIIOse4bJJvoBJUSeAQnQ6q9thD3DH4ia1l8x+yiOVtlLm+TfUsEImxbbiY4YSFdjeONk5aMNwoK3qbs54bDLyHUiWTA4jN6X3cJk2z7NlMs0nexrGUlrcNt0jXrzMxUeCqlKKXa4vBstiWjBBn/Tp4SnSUDjkSzRbQ/eWxtLs3eXmEc2f0sg6L95sF8Mua/NjwMp6c0bFtH3HNkT+/84pK3gQeBL+KKCS9n5vEBRBVrKba8wUGfQCEHlYn7X WhBlMHJR TSL7uqMuPO7QKErjn7TGGfBv6NfTSYeadnkDcnFwaA3gDPUUrqAwuS54HSnwerEWqIqH8RnykxDQf9PTr6M25WZgO6CI0j54VC0nQd89tui4lR9R8IcJ0C6xPVJ75lQmxQMIyABjReyPTcYhTAYpRMrLP4BIi35fSt79lrk5U3hBHQMyxMzad3A3azc0gj9JYKjQlQDmZYY5JI7SzaLALJBSs2jEwviVUxgKcF7GY7ECPV3vopJNHUv3gAVQl2R0wz470pYS/LCo1ScVlTaQnrlqmUQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When CONFIG_DAMON_KUNIT_TEST=y and making CONFIG_DEBUG_KMEMLEAK=y and CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN=y, the below memory leak is detected. The damon_ctx which is allocated by kzalloc() in damon_new_ctx() in damon_test_ops_registration() and damon_test_set_attrs() are not freed. So use damon_destroy_ctx() to free it. After applying this patch, the following memory leak is never detected unreferenced object 0xffff2b49c6968800 (size 512): comm "kunit_try_catch", pid 350, jiffies 4294895294 (age 557.028s) hex dump (first 32 bytes): 88 13 00 00 00 00 00 00 a0 86 01 00 00 00 00 00 ................ 00 87 93 03 00 00 00 00 0a 00 00 00 00 00 00 00 ................ backtrace: [<0000000088e71769>] slab_post_alloc_hook+0xb8/0x368 [<0000000073acab3b>] __kmem_cache_alloc_node+0x174/0x290 [<00000000b5f89cef>] kmalloc_trace+0x40/0x164 [<00000000eb19e83f>] damon_new_ctx+0x28/0xb4 [<00000000daf6227b>] damon_test_ops_registration+0x34/0x328 [<00000000559c4801>] kunit_try_run_case+0x50/0xac [<000000003932ed49>] kunit_generic_run_threadfn_adapter+0x20/0x2c [<000000003c3e9211>] kthread+0x124/0x130 [<0000000028f85bdd>] ret_from_fork+0x10/0x20 unreferenced object 0xffff2b49c1a9cc00 (size 512): comm "kunit_try_catch", pid 356, jiffies 4294895306 (age 557.000s) hex dump (first 32 bytes): 88 13 00 00 00 00 00 00 a0 86 01 00 00 00 00 00 ................ 00 00 00 00 00 00 00 00 0a 00 00 00 00 00 00 00 ................ backtrace: [<0000000088e71769>] slab_post_alloc_hook+0xb8/0x368 [<0000000073acab3b>] __kmem_cache_alloc_node+0x174/0x290 [<00000000b5f89cef>] kmalloc_trace+0x40/0x164 [<00000000eb19e83f>] damon_new_ctx+0x28/0xb4 [<00000000058495c4>] damon_test_set_attrs+0x30/0x1a8 [<00000000559c4801>] kunit_try_run_case+0x50/0xac [<000000003932ed49>] kunit_generic_run_threadfn_adapter+0x20/0x2c [<000000003c3e9211>] kthread+0x124/0x130 [<0000000028f85bdd>] ret_from_fork+0x10/0x20 Fixes: d1836a3b2a9a ("mm/damon/core-test: initialise context before test in damon_test_set_attrs()") Fixes: 4f540f5ab4f2 ("mm/damon/core-test: add a kunit test case for ops registration") Signed-off-by: Jinjie Ruan Reviewed-by: Feng Tang Reviewed-by: SeongJae Park --- v3: - Add a new Reviewed-by. v2: - Add Reviewed-by. - Rebased on mm-unstable. - Update the commit message. --- mm/damon/core-test.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h index 28d24e698318..b2a388ee062d 100644 --- a/mm/damon/core-test.h +++ b/mm/damon/core-test.h @@ -265,6 +265,8 @@ static void damon_test_ops_registration(struct kunit *test) /* Check double-registration failure again */ KUNIT_EXPECT_EQ(test, damon_register_ops(&ops), -EINVAL); + + damon_destroy_ctx(c); } static void damon_test_set_regions(struct kunit *test) @@ -341,6 +343,8 @@ static void damon_test_set_attrs(struct kunit *test) invalid_attrs = valid_attrs; invalid_attrs.aggr_interval = 4999; KUNIT_EXPECT_EQ(test, damon_set_attrs(c, &invalid_attrs), -EINVAL); + + damon_destroy_ctx(c); } static void damos_test_new_filter(struct kunit *test)