From patchwork Wed Jun 14 06:18:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 13279548 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 73C32EB64DA for ; Wed, 14 Jun 2023 06:19:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 65F1E6B0074; Wed, 14 Jun 2023 02:19:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 60F7C6B0075; Wed, 14 Jun 2023 02:19:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D70D8E0002; Wed, 14 Jun 2023 02:19:13 -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 3DC966B0074 for ; Wed, 14 Jun 2023 02:19:13 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EED69C07F6 for ; Wed, 14 Jun 2023 06:19:12 +0000 (UTC) X-FDA: 80900350944.13.1DC2933 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf22.hostedemail.com (Postfix) with ESMTP id 6C8D9C0013 for ; Wed, 14 Jun 2023 06:19:08 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=mawupeng1@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686723551; a=rsa-sha256; cv=none; b=i7NdHnH5cXUNi7lwsgGeofAbc8vcgHkx9yhbZT3yRAfgyud8Rl0x3IC7lkkgrOgySKq83y Rtt1gtYI5s+FIUBMrKMy3u23KPEolBj+9t653muTdCrg6MqlIbTmR5XeDVDS77gBhY0Cmq EM1ll6fmgmmkjSL7YS3T2S84abLOCc4= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=mawupeng1@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=1686723551; 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=lIhxCQWtzeTGThHJa/gVkoJC3pkr5TnevqB9VJ3dEKo=; b=RHkbVGYHFghZm+MKI6shkV30pL8sWXiumh28JS3lGXgVNFvvT8v4FPFV8b8ZYqms6reQIH i7KRy1WjOAVPJArjCPh+v/YJ9Y3xRETO1VLf4pzTfkQGqV5fOyWtc1ps4aCgENUB3SBzU6 XIAgp+ZKVV4r89xYCMvDiA81KZ0cI7w= Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Qgw9W1MSgzqTcl; Wed, 14 Jun 2023 14:14:07 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm500014.china.huawei.com (7.185.36.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Wed, 14 Jun 2023 14:19:04 +0800 From: Wupeng Ma To: , CC: , , , Subject: [PATCH stable 5.10 0/1] Fix memleak during hotremove memory Date: Wed, 14 Jun 2023 14:18:59 +0800 Message-ID: <20230614061900.3296725-1-mawupeng1@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6C8D9C0013 X-Stat-Signature: 6bzt4syxnnwwaiysdx8cd9xfjmbxn9gh X-HE-Tag: 1686723548-159222 X-HE-Meta: U2FsdGVkX19bdBk83WLeYXMYPOS0yvesdBRPJ7iOKw08+ayNw0N6/YqsDX6eTYMndqc42pogAqqTTSc2Jbm1ygjUzKDWsNLBg40dYkYT3eaJ0FEZmGWr4BJS8koNjSJi8RMHGjOr0EgQDlNAn1kQHhHcps+lRTbNtjWM1pmeu89XfTQG4JN15ciX2aoDlXhbv5H7KT/JLJ4PYGCCGGupePODxNtII68nfdDnpzhpTGwf34OjoRTsxwch9p61oIE01lBQ06RCr743xgVFGhSiLPdpE/GOF9peChYn5e5hc8Hiz2umwTBwZe8EyGIKAC+nJJliXDGfIOGOMYOROkThKUAfcp/ZFnNj0/1ISvR/F8OeyVCvd4gIpSYUQeAI9z2k8LXyVS2pPqDN3KngO4l30CLMLaEEPwkDPTLWoJp65KOCAkY5gm68DBDbAEpbMUHplufPJOXgWpAsAoFmvXJ/htI7Ffh0dpYDq/FFucctjTufBLZI2o1xIagkRAh7IlQj3beNRVQi2CyhmvKfjkvOYLKpmLJ4u0zIYAi27mTzbZNJvvmmZGE4dBxH20wmrTRBLSJCTmiTcvMmItkIEfGHcGBIhmjaM8ALenac/gRlFldmfXU8ZAkTOyjswDR/Othp9OCb7I1FjWwnIgij7qmhfPmpcnRxlHjDXcQK6vIURRwVeGSbYXUkIU/zkhW3+u6XTmYyLMoHATQGOOvWr31o8jmq1HSDbTVpWAIBO3BlanzPWnGJuWZxZwmXyoRLeUR7bV4JPB11ngROdqd9cwgb36GNVMTtJhzrAruX7zyFh/hxgpsT8YE+7gNt0EdPJn+vrYlUz7tqm0TeYuiMlqKkvlSSTGQlnfzgFWyzhXHzdyAPLyvvMI+xmuyRhHmJ5idES5COLjsMNLB5MO3/uy82uy3XLB3huOpmuUyLnjj/8naGWdU8Q7JnSfXCfYNQO63yN9APznZFpSUACl5s+9j jN0KIqvR IKtTO84IwwRtwqpQdbugcJLyqDv4BoxkMj1G3ptcD1GVM52FYW56Pp4ccOtHnk6/go/U2r+QvwJxkwiJrHNxOQ5+Z705agfu+ZhtRCQRM7TXR565qM9hUN1k8/rlIyG8FnFQZ5E+weoIbhUo= 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: From: Ma Wupeng Hi maintainers: Our test find a memleak in init_memory_block, it is clear that mem is never been released due to wrong refcount. Commit 08b3acd7a68f ("mm/memory_hotplug: Introduce offline_and_remove_memory()") failed to dec refcount after find_memory_block which fail to dec refcount to zero in remove memory causing the leak. Commit 8dc4bb58a146 ("mm/memory_hotplug: extend offline_and_remove_memory() to handle more than one memory block") introduce walk_memory_blocks to replace find_memory_block which dec refcount by calling put_device after find_memory_block_by_id. In the way, the memleak is fixed. Here is the simplified calltrace: kmem_cache_alloc_trace+0x664/0xed0 init_memory_block+0x8c/0x170 create_memory_block_devices+0xa4/0x150 add_memory_resource+0x188/0x530 __add_memory+0x78/0x104 add_memory+0x6c/0xb0 David Hildenbrand (1): mm/memory_hotplug: extend offline_and_remove_memory() to handle more than one memory block mm/memory_hotplug.c | 105 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 89 insertions(+), 16 deletions(-)