From patchwork Mon Sep 18 05:10:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13388818 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 EFE22CD37B0 for ; Mon, 18 Sep 2023 05:11:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 76F896B0207; Mon, 18 Sep 2023 01:11:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 684676B0208; Mon, 18 Sep 2023 01:11:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 54D6D6B0209; Mon, 18 Sep 2023 01:11:59 -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 477016B0207 for ; Mon, 18 Sep 2023 01:11:59 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1C6E31A0B7E for ; Mon, 18 Sep 2023 05:11:59 +0000 (UTC) X-FDA: 81248546358.19.81B818B Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf12.hostedemail.com (Postfix) with ESMTP id 2E9D840005 for ; Mon, 18 Sep 2023 05:11:55 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf12.hostedemail.com: domain of ruanjinjie@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=ruanjinjie@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695013917; a=rsa-sha256; cv=none; b=OrDNMEPt+iUmYUfRSxud4Vzsz3Jnc+M5Dm+HJV9BLWQlIEj5+4VyDOuuqb3CJmQfmu45y/ tU2wNn2F7R1t0Qcrs/o5HP5etjLf8xt9thSL8ebd6geDBIZn0ujoF3y/nSyxN74UuH/FJG 6GDADIkR0QX36kqPcZgEP5GwYA9Ra0U= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf12.hostedemail.com: domain of ruanjinjie@huawei.com designates 45.249.212.187 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=1695013917; 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=+/CYCX9ULxLJESJb0b+bDfwDJuFBVwmRb7urQTLFm4o=; b=vyYjJRxflyuzmlMPcvTooYhRRjxM5spAO8fTe/itIajHsxRoBKvfU1yWkyEW6t20wMPJFY XbXD2FJPNL9J5DWTUzS1yR9tiq/dHHXhfuFMZNlxdn7pT0UFHSIT7sMMYed6ggG76IK/RM uMAalt960PSRCHJEhD399wNqsPX2Jb8= Received: from kwepemi500008.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Rpt8V55WCztRn7; Mon, 18 Sep 2023 13:07:38 +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 13:11:50 +0800 From: Jinjie Ruan To: , , , , , , , , CC: Subject: [PATCH RESEND 1/2] mm/damon/core-test: Fix memory leak in damon_new_region() Date: Mon, 18 Sep 2023 13:10:43 +0800 Message-ID: <20230918051044.3814018-2-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230918051044.3814018-1-ruanjinjie@huawei.com> References: <20230918051044.3814018-1-ruanjinjie@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500008.china.huawei.com (7.221.188.139) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 2E9D840005 X-Stat-Signature: p3p796tsqs5huxn9nssnh1qgxs49geib X-Rspam-User: X-HE-Tag: 1695013915-203626 X-HE-Meta: U2FsdGVkX19m0OJJYny+xvVUElJR4cx580NwBQtApHgxQUwiK0xQ4z+nasiyQkHNe7Ym3fV9cpvu1ZUka9ASFwY3DjT++uKsA7iPu6mvPz5WQ1SHSH4nq+lhz1baHz90cjAWFpQIODhh9QyYTyudJMGga7xbgTDKgx1mNRjRAeT86zgg1m1fbk21TwFEQ0GEOfjW+xKN0mHIpzYbA2SDrQ7roljQJCMfZK3svJI7pJbu87d5ml+Pkx4YV0MPhqxwFe39R/3VbB1woTcjbK9DyLsaLrouQK11s+OExAjnXf3xF8SZSAgpnMa02bE7cLxGoAng0gkbdU4MMtxsnkkvLSEGLhqDYCin1RdVC0yryPMtz2aJaXA7O8Y4xtV1dOVIvBKdGcEioWuZJevQcK72lm2FztX9ijgpjK++Tfv3NjzIQ64n7i3PpqGb4mMzg1tyIM/a59DgZ0JLy9KKnC6YNVtlUwgfSAKdGAMsWWfpi4GR/4LdNkglFFQUfVmezR3iDfWV6xiBCgY8Ifp3u4FKgoZbdx2qQX0D2WVJm4sXtyaDhsM67X3TbrKTW859Ype1EGaliYiNzE+a+D3Me2OvOikmIAvfDdhSGL5Yx0vdsn4NBe/cIrgN9n30MRvyIkCQynfqtpLZNyjJxzTB+t8rdLxqpYdobhS1l/Cb4dMRuDGii0Vd5/0N6zBdPtcW8jV/1awvutONs3kMhsABM3AbIcr8hdnhsX/J7U1aaZHUlLBVn1fq+Gv3XNBojNEzOBVsBUMiYX9AHLAhrwob9zz9DG5wiYATTOcW0raTu5BssFkpec7Yw/PlSeBlOC7GSGlpkq8mkpr24eMoDhxhhH7dXdqbqh8AQdBtaMaxuANOy3lj+kze/beUPqQffC0sMnSOa+Esf5xgD0j+Jz40NQPMDKbiCn7pu3hVXUEfIBcP8WcHhYe3UkK9jBRkOvdn35jmFgUtJIsJ5NdkhgNCmMG a6WKcAzT hP0sQt9vNb4NGpDhkzYuyFtdjcqPbwZe7byP8Xa/LjhmQfJlML5GHff4apvs6cL+MRz36teFGQwZTwAMbBko7Q9519Yxqr4T3ch2H6y1VDloG8RsAV5ctuDYr4z2hdZzLQS7Oj2PE/zTnnZst9FN0mgJeUY+w0By1xx9eWA2QwQcY3QyXR6q4CMmkAhhukIAUCpB0 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: The damon_region which is allocated by kmem_cache_alloc() in damon_new_region() in damon_test_regions() and damon_test_update_monitoring_result() are not freed and it causes below memory leak. So use damon_free_region() to free it. unreferenced object 0xffff2b49c3edc000 (size 56): comm "kunit_try_catch", pid 338, jiffies 4294895280 (age 557.084s) hex dump (first 32 bytes): 01 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 ................ 00 00 00 00 00 00 00 00 00 00 00 00 49 2b ff ff ............I+.. backtrace: [<0000000088e71769>] slab_post_alloc_hook+0xb8/0x368 [<00000000b528f67c>] kmem_cache_alloc+0x168/0x284 [<000000008603f022>] damon_new_region+0x28/0x54 [<00000000a3b8c64e>] damon_test_regions+0x38/0x270 [<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 0xffff2b49c5b20000 (size 56): comm "kunit_try_catch", pid 354, jiffies 4294895304 (age 556.988s) hex dump (first 32 bytes): 03 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 ................ 00 00 00 00 00 00 00 00 96 00 00 00 49 2b ff ff ............I+.. backtrace: [<0000000088e71769>] slab_post_alloc_hook+0xb8/0x368 [<00000000b528f67c>] kmem_cache_alloc+0x168/0x284 [<000000008603f022>] damon_new_region+0x28/0x54 [<00000000ca019f80>] damon_test_update_monitoring_result+0x18/0x34 [<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: 17ccae8bb5c9 ("mm/damon: add kunit tests") Fixes: f4c978b6594b ("mm/damon/core-test: add a test for damon_update_monitoring_results()") Signed-off-by: Jinjie Ruan --- mm/damon/core-test.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h index 6cc8b245586d..255f8c925c00 100644 --- a/mm/damon/core-test.h +++ b/mm/damon/core-test.h @@ -34,6 +34,7 @@ static void damon_test_regions(struct kunit *test) KUNIT_EXPECT_EQ(test, 0u, damon_nr_regions(t)); damon_free_target(t); + damon_free_region(r); } static unsigned int nr_damon_targets(struct damon_ctx *ctx) @@ -316,6 +317,8 @@ static void damon_test_update_monitoring_result(struct kunit *test) damon_update_monitoring_result(r, &old_attrs, &new_attrs); KUNIT_EXPECT_EQ(test, r->nr_accesses, 150); KUNIT_EXPECT_EQ(test, r->age, 20); + + damon_free_region(r); } static void damon_test_set_attrs(struct kunit *test) From patchwork Mon Sep 18 05:10:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13388819 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 EC626CD13D2 for ; Mon, 18 Sep 2023 05:12:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C4486B0208; Mon, 18 Sep 2023 01:12:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 54D216B0209; Mon, 18 Sep 2023 01:12:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C5F26B020A; Mon, 18 Sep 2023 01:12:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 26C326B0208 for ; Mon, 18 Sep 2023 01:12:00 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EDB57C0B68 for ; Mon, 18 Sep 2023 05:11:59 +0000 (UTC) X-FDA: 81248546358.17.340FB65 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf24.hostedemail.com (Postfix) with ESMTP id 6AE9B18000D for ; Mon, 18 Sep 2023 05:11:55 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of ruanjinjie@huawei.com designates 45.249.212.255 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=1695013917; 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=9ZaTUvZE/pjQ4z9Ivg9EXH3zCdyFK6qIfvk9hks0kD0=; b=TFsOq+7UGqdKCk1cv0pYq3wPcemmO7EO97qBM5ESbk1YmX3/LO82aqfv9oqHcazbhQ9LTA zFUp5lRPjbtDznJ/FRB2+GEnf3ldPaMnHMhcfuvR7XL1sReeIY1eLoyxDzNjFgKTBCHods VbAEB22f0wqWOIBONPGmAgydCzSMoZg= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of ruanjinjie@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=ruanjinjie@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695013917; a=rsa-sha256; cv=none; b=ZrCTWcocJTc9pBdkeAx8pF+WUsvflAETch2AoVi9UDMtYX6tqcE3KmeqrvylUN3cem7KWa 8ZdN3+x46MXzOmOq9cCmaFOL+76ahyiqk1P7eCU2rq5Gd4xt6756z0Yg5yQgnKGH4gziVQ sNY29LnU9tHurnHdcESOkc9uKE4kAPE= Received: from kwepemi500008.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4RptC05lLcz15NQX; Mon, 18 Sep 2023 13:09: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, 18 Sep 2023 13:11:51 +0800 From: Jinjie Ruan To: , , , , , , , , CC: Subject: [PATCH RESEND 2/2] mm/damon/core-test: Fix memory leak in damon_new_ctx() Date: Mon, 18 Sep 2023 13:10:44 +0800 Message-ID: <20230918051044.3814018-3-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230918051044.3814018-1-ruanjinjie@huawei.com> References: <20230918051044.3814018-1-ruanjinjie@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500008.china.huawei.com (7.221.188.139) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 6AE9B18000D X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: f5zq9cn4cybiedz1joono8u8r435makk X-HE-Tag: 1695013915-346059 X-HE-Meta: U2FsdGVkX19YqDqBvPFDhgK6zj12rayFyGzi8P3vnhfKM5yZfnRieVYa9vQtcib/N8K+HzJM+cl9sC9oG9NzDfWYz/VCriY21tkymnYjJxfMJIEcMdBaJqNdr7NudXgU6dOOmlYdaFC1CqFj/xSuC9X6J1umXqwI+a0Ih+YWSWyH7N9Mew22R471L6oHOlxmgRFINuOwldAOs/u38S+IIqYbL+1Li4kT2jCuZ2zxQSTdWkuo+DT4vSkAHcmWdcSmko4cf8aPWOR6OUkTCAz+2OkJFbNfWjnjqKe4/xdNLWscyBSkjMQ1UB/gZdoAkyMKjfOuygqcFRFruMDxVujpR3CcqJxKiSYpWZ0z1osxGf8fPYwyvE/NV7jbMWbHh4YsMA6p+zldFAFQKF2RHNWB19ridykfQ2GH74WeY1V0/DNjwra1CSBiI1c+DenN0/oGKDFWF41PxcymYaxVxlcIIm8/SClSzly5LY7payghalpP8nrvUvLmEJJwTjwonqkaYdwpwwCmZM8x905ykQFu2jnase0OUyMZv7zeJGZyahfndau0xorf1KPbGSB1/OR07jEOOCpWsbsFeYR8O8tGud8P3I31Bb8GNr65yi+dMw290LR+NPBwjLSppvW01fHzDeHtfbLkvcMy9N5bkIJMrL3vudvcrrPOzbGiuBd8GgKTHfbIonCNXYCsFdn46tL8DUPQ4TfcFNsBPvUzwuenPe4o8lIQVikG9LyK3s4DR5zxjYEPfQqi06v2cXQ4LALF8SOA4dUqnjZs9xwOXTQtd3+Cf5IKQwDR0fPN+MlE/+wqd5uiE4dHd0eFuDGm6gLAQ/sMGJWrzLKE8QZkfFmCJc2Pz/h+ogPUpunwA1R/wHn30XH8kTNRZRoWGDhVz9Rl0Jm9yVgcC501VNGIVXKdlpZGqpdJ4//EXoQKyzNLqviHVczEaix4BdhocW1N0uewHVlotujaSQS84WbFr8d LX8Nn8cu 36eJpRuZrFwVfA4ttnBJs8wtheaEa4oFtnXnqdKt229ewdALGCJJ9zgKmaumLP24l9tatFiiTS77rG2HzcyAzaTAm00po3128LI0BcNh2xdd+ApwCTSowmUT6tfjnfaiIS7ClnuDcbzFRl0A5unfHx9mZGb6Owxtyn+6/DJrP6TW0YUePdPJVxTq37oclUUrIGtSQ 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: 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 and it causes below memory leak. So use damon_destroy_ctx() to free it. 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 --- 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 255f8c925c00..ce86ed30fb47 100644 --- a/mm/damon/core-test.h +++ b/mm/damon/core-test.h @@ -266,6 +266,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) @@ -342,6 +344,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)