From patchwork Mon Sep 25 07:20:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13397342 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 31907CE7A95 for ; Mon, 25 Sep 2023 07:21:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D54E8D0009; Mon, 25 Sep 2023 03:21:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 684038D0001; Mon, 25 Sep 2023 03:21:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5732A8D0009; Mon, 25 Sep 2023 03:21:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4896E8D0001 for ; Mon, 25 Sep 2023 03:21:39 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 11588C05B0 for ; Mon, 25 Sep 2023 07:21:39 +0000 (UTC) X-FDA: 81274274718.20.B700E31 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf29.hostedemail.com (Postfix) with ESMTP id 983E4120014 for ; Mon, 25 Sep 2023 07:21:35 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of ruanjinjie@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=ruanjinjie@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695626497; 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: references; bh=5ZMq3kS6tXxeFy64MHuQV5op5xnVB9AMviqtRGSdcc8=; b=ZhqfVt0zMJcr4GxRn6k/0EWPrZeQz2hnJXJz1AKVMg/vCY4bu+eyBaC0/yuAWy3u9OMc/O CwLOZVT4efyeukceAtgLSqa4yFTNjFL2DnA2sYq2zcO5GOGlF5ciufjmPH+IiVjRmvvCzy dBrKPsXr/Do9nRy22z6vXa2hMurtBc8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695626497; a=rsa-sha256; cv=none; b=Zpl8/doF462KXoWsj2V1V1mzUscYh0BZ0438PjDCEVMIS+bYRz5xkH7l3PLS5QKnxy0E+4 4u+g0CCMsdAHIclTgNPYcX2fFu18ACb4Nq6uaVIw4hJ620Rt3TCwMKMsi8Q77ZTg/ivkLq XnANygQ9PZqWXSlm0BwwRGlWsAjVUrQ= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of ruanjinjie@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=ruanjinjie@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from kwepemi500008.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4RvDjS72lgzMlsj; Mon, 25 Sep 2023 15:17:48 +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, 25 Sep 2023 15:21:28 +0800 From: Jinjie Ruan To: , , SeongJae Park , Andrew Morton CC: Subject: [PATCH] mm/damon/vaddr-test: Fix memory leak in damon_do_test_apply_three_regions() Date: Mon, 25 Sep 2023 15:20:59 +0800 Message-ID: <20230925072100.3725620-1-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemi500008.china.huawei.com (7.221.188.139) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 983E4120014 X-Rspam-User: X-Stat-Signature: y7dwehwimah9wf1i8zzy53ayuix9cijb X-Rspamd-Server: rspam03 X-HE-Tag: 1695626495-375508 X-HE-Meta: U2FsdGVkX18EhDLnXWbesij5Twn6qr4HmUB8u/brd7cfST2ORZWXrNHxWw8nq28Zj1tiSMcRDbO3K3406PeL78PhW7w2M88DzhEWRa8rZPb8tF6AJcrgheFqbhnd60nFR+V4eq+kkpE6Jb5ApisKuERf9Vcq4A8JcXrL1IuY1nv2IB9K/5tpTqYTLBE3ud78L6eAXwQu4/BYB8dozAljzEqlH0ubvq2N7YaEPZcNRO5rFN1B0v+WWn4kx4TQ+NSywfZ+TqagVj7Gur3XjEewFitrBW2ltwKf7XPKFFJLyPj+FC+42GMYXOtqjrrouI3e48lG4X59E6Iw1DOWg4ouHIW2BG1HgpddfXxrenX3Ser9Q9cURPYzWDDa8G6x3ynU5kVSSTuOSzeIAl8oF1zmWhP5TQI0NBKRMPkV7nO/EIOgoy4EmWZmeXz4Hi93SiR966G6C8F3kq7+FPP4PBwAMlRsvpEFi4QWOtWI+b0CFVB9T4b6MpuXW2VTfzXF8Ic45h9eX6PMy/S/dgfJwnW0m2eAUfFYr3dpDT0a8clTL56wJpQAs5T85+5idlcm4k5F1987uk/7NPoe+xP1Zp1H7KyAzDqzKeyBMr60GdasaGq2yAdCNAeP7UUXgWayJA1L6mRSQJ4UMNQrEkY1e0XZGtgOB9/WzpPm7WsY9RpamTQHeWXJfXHGonurvSvCroy3KUuQgfppborWsWNVPYucWW8NPFCr77aUBy0x6gmnei0n/2EBqMg2/6/EKgfK3oLEL3zvpSrlFMQZbuiHf9P5DWZNtOWASn2oniGq9y07+nPA29AuWQuQW23FyRDs9GhkKiHxFBdTVbed9xJ3cFptyfKVxzHvYXcqpiLCvNJEHjIexu3I5PclKeNGkw7DFY7i9btOKLxTs/KA/p+5KSDBn45Gq/3t+A7o9TupEqU6g8FMQNmTmo4U4KiHcb+IY/1QU/8aoThcyQphRR25o7g XBHyb3Sp jwvoPDnIVeP8vTHxuppX7dHf6zIs91QD0hshQXTnFC2gCT0+/GBu90O8C+DimfK8FQs8pfGy91nBg8voMFf9NOX8hRoo1fKPhGe8O6PodjqJWSWuVkkwCd19vbATvdL+IU70HE+Wp1rftFT7GoRwXcCqchN32xs7TeN/nAXDgmzQUvG01I1+Li66a8ZSqlApjj42A 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_VADDR_KUNIT_TEST=y and making CONFIG_DEBUG_KMEMLEAK=y and CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN=y, the below memory leak is detected. Since commit 9f86d624292c ("mm/damon/vaddr-test: remove unnecessary variables"), the damon_destroy_ctx() is removed, but still call damon_new_target() and damon_new_region(), the damon_region which is allocated by kmem_cache_alloc() in damon_new_region() and the damon_target which is allocated by kmalloc in damon_new_target() are not freed. And the damon_region which is allocated in damon_new_region() in damon_set_regions() is also not freed. So use damon_destroy_target to free all the damon_regions and damon_target. unreferenced object 0xffff888107c9a940 (size 64): comm "kunit_try_catch", pid 1069, jiffies 4294670592 (age 732.761s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 06 00 00 00 6b 6b 6b 6b ............kkkk 60 c7 9c 07 81 88 ff ff f8 cb 9c 07 81 88 ff ff `............... backtrace: [] kmalloc_trace+0x27/0xa0 [] damon_new_target+0x3f/0x1b0 [] damon_do_test_apply_three_regions.constprop.0+0x95/0x3e0 [] damon_test_apply_three_regions1+0x21e/0x260 [] kunit_generic_run_threadfn_adapter+0x4a/0x90 [] kthread+0x2b6/0x380 [] ret_from_fork+0x2d/0x70 [] ret_from_fork_asm+0x11/0x20 unreferenced object 0xffff8881079cc740 (size 56): comm "kunit_try_catch", pid 1069, jiffies 4294670592 (age 732.761s) hex dump (first 32 bytes): 05 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 ................ 6b 6b 6b 6b 6b 6b 6b 6b 00 00 00 00 6b 6b 6b 6b kkkkkkkk....kkkk backtrace: [] damon_new_region+0x22/0x1c0 [] damon_do_test_apply_three_regions.constprop.0+0xd1/0x3e0 [] damon_test_apply_three_regions1+0x21e/0x260 [] kunit_generic_run_threadfn_adapter+0x4a/0x90 [] kthread+0x2b6/0x380 [] ret_from_fork+0x2d/0x70 [] ret_from_fork_asm+0x11/0x20 unreferenced object 0xffff888107c9ac40 (size 64): comm "kunit_try_catch", pid 1071, jiffies 4294670595 (age 732.843s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 06 00 00 00 6b 6b 6b 6b ............kkkk a0 cc 9c 07 81 88 ff ff 78 a1 76 07 81 88 ff ff ........x.v..... backtrace: [] kmalloc_trace+0x27/0xa0 [] damon_new_target+0x3f/0x1b0 [] damon_do_test_apply_three_regions.constprop.0+0x95/0x3e0 [] damon_test_apply_three_regions2+0x21e/0x260 [] kunit_generic_run_threadfn_adapter+0x4a/0x90 [] kthread+0x2b6/0x380 [] ret_from_fork+0x2d/0x70 [] ret_from_fork_asm+0x11/0x20 unreferenced object 0xffff8881079ccc80 (size 56): comm "kunit_try_catch", pid 1071, jiffies 4294670595 (age 732.843s) hex dump (first 32 bytes): 05 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 ................ 6b 6b 6b 6b 6b 6b 6b 6b 00 00 00 00 6b 6b 6b 6b kkkkkkkk....kkkk backtrace: [] damon_new_region+0x22/0x1c0 [] damon_do_test_apply_three_regions.constprop.0+0xd1/0x3e0 [] damon_test_apply_three_regions2+0x21e/0x260 [] kunit_generic_run_threadfn_adapter+0x4a/0x90 [] kthread+0x2b6/0x380 [] ret_from_fork+0x2d/0x70 [] ret_from_fork_asm+0x11/0x20 unreferenced object 0xffff888107c9af40 (size 64): comm "kunit_try_catch", pid 1073, jiffies 4294670597 (age 733.011s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 06 00 00 00 6b 6b 6b 6b ............kkkk 20 a2 76 07 81 88 ff ff b8 a6 76 07 81 88 ff ff .v.......v..... backtrace: [] kmalloc_trace+0x27/0xa0 [] damon_new_target+0x3f/0x1b0 [] damon_do_test_apply_three_regions.constprop.0+0x95/0x3e0 [] damon_test_apply_three_regions3+0x21e/0x260 [] kunit_generic_run_threadfn_adapter+0x4a/0x90 [] kthread+0x2b6/0x380 [] ret_from_fork+0x2d/0x70 [] ret_from_fork_asm+0x11/0x20 unreferenced object 0xffff88810776a200 (size 56): comm "kunit_try_catch", pid 1073, jiffies 4294670597 (age 733.011s) hex dump (first 32 bytes): 05 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 ................ 6b 6b 6b 6b 6b 6b 6b 6b 00 00 00 00 6b 6b 6b 6b kkkkkkkk....kkkk backtrace: [] damon_new_region+0x22/0x1c0 [] damon_do_test_apply_three_regions.constprop.0+0xd1/0x3e0 [] damon_test_apply_three_regions3+0x21e/0x260 [] kunit_generic_run_threadfn_adapter+0x4a/0x90 [] kthread+0x2b6/0x380 [] ret_from_fork+0x2d/0x70 [] ret_from_fork_asm+0x11/0x20 unreferenced object 0xffff88810776a740 (size 56): comm "kunit_try_catch", pid 1073, jiffies 4294670597 (age 733.025s) hex dump (first 32 bytes): 3d 00 00 00 00 00 00 00 3f 00 00 00 00 00 00 00 =.......?....... 6b 6b 6b 6b 6b 6b 6b 6b 00 00 00 00 6b 6b 6b 6b kkkkkkkk....kkkk backtrace: [] damon_new_region+0x22/0x1c0 [] damon_set_regions+0x4c2/0x8e0 [] damon_do_test_apply_three_regions.constprop.0+0xfb/0x3e0 [] damon_test_apply_three_regions3+0x21e/0x260 [] kunit_generic_run_threadfn_adapter+0x4a/0x90 [] kthread+0x2b6/0x380 [] ret_from_fork+0x2d/0x70 [] ret_from_fork_asm+0x11/0x20 unreferenced object 0xffff888108038240 (size 64): comm "kunit_try_catch", pid 1075, jiffies 4294670600 (age 733.022s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 03 00 00 00 6b 6b 6b 6b ............kkkk 48 ad 76 07 81 88 ff ff 98 ae 76 07 81 88 ff ff H.v.......v..... backtrace: [] kmalloc_trace+0x27/0xa0 [] damon_new_target+0x3f/0x1b0 [] damon_do_test_apply_three_regions.constprop.0+0x95/0x3e0 [] damon_test_apply_three_regions4+0x1cd/0x210 [] kunit_generic_run_threadfn_adapter+0x4a/0x90 [] kthread+0x2b6/0x380 [] ret_from_fork+0x2d/0x70 [] ret_from_fork_asm+0x11/0x20 unreferenced object 0xffff88810776ad28 (size 56): comm "kunit_try_catch", pid 1075, jiffies 4294670600 (age 733.022s) hex dump (first 32 bytes): 05 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 ................ 6b 6b 6b 6b 6b 6b 6b 6b 00 00 00 00 6b 6b 6b 6b kkkkkkkk....kkkk backtrace: [] damon_new_region+0x22/0x1c0 [] damon_set_regions+0x4c2/0x8e0 [] damon_do_test_apply_three_regions.constprop.0+0xfb/0x3e0 [] damon_test_apply_three_regions4+0x1cd/0x210 [] kunit_generic_run_threadfn_adapter+0x4a/0x90 [] kthread+0x2b6/0x380 [] ret_from_fork+0x2d/0x70 [] ret_from_fork_asm+0x11/0x20 Fixes: 9f86d624292c ("mm/damon/vaddr-test: remove unnecessary variables") Fixes: dae0087aeff4 ("mm/damon/vaddr: remove damon_va_apply_three_regions()") Signed-off-by: Jinjie Ruan Reviewed-by: SeongJae Park --- mm/damon/vaddr-test.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/damon/vaddr-test.h b/mm/damon/vaddr-test.h index c4b455b5ee30..dcf1ca6b31cc 100644 --- a/mm/damon/vaddr-test.h +++ b/mm/damon/vaddr-test.h @@ -148,6 +148,8 @@ static void damon_do_test_apply_three_regions(struct kunit *test, KUNIT_EXPECT_EQ(test, r->ar.start, expected[i * 2]); KUNIT_EXPECT_EQ(test, r->ar.end, expected[i * 2 + 1]); } + + damon_destroy_target(t); } /*