Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2246001rwd; Tue, 13 Jun 2023 23:24:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4gplBK0Q8Fcqh+xoU6xgOTuGj6FdfFfWQfstWwmgefik317ucnnvN7sxU8IscyBV2jShQ0 X-Received: by 2002:a17:907:16a0:b0:96f:74d0:ad0e with SMTP id hc32-20020a17090716a000b0096f74d0ad0emr16493951ejc.58.1686723855679; Tue, 13 Jun 2023 23:24:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686723855; cv=none; d=google.com; s=arc-20160816; b=0Jtt2cnXIY+3XtRXiOiWoxA/vNlcauMBL+l1adYxxi0m80WeJ6/snIOPSkZmoS631K CGCITR0qVGvk/uXyJKG40Yc3OqpLwHGOtKtCzT6BqWCwpcUD5sdpVe9XKLnHzvqcYYYO zv8NlVASiNmJXq/nRah9xFttram59+Oj9sLWjaIWIr5EzB9gbgy8wVZTuLo3sWywCop3 sw+G5l93yuBt5cnR3WrIRcjqOlR2ufmG11FU/3X67aSOASZL8fivB2g1sFQ5CSCrDcTP gj8KdW51WA5ZQsgvpeYjKpQGw+jQPAuBi1tB+tm78MzogJaTwcfzvAVJuGbUwANqFU8/ 0JfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=lIhxCQWtzeTGThHJa/gVkoJC3pkr5TnevqB9VJ3dEKo=; b=Bppx90Jcmr9tP3xQbXkPJH2lJ5K2BXRwHEhca9nmUQF0T+9l+8MoefK/EuOKs16kC6 oY/NkAXXst0+87NfYErdJCJP47rKfl7S+blubKSLUQ+SDaYVMe76xkkVxR9o8ZFhYlY1 5GYd1z1Of3j7lzUGKLehtrEeqb0iZU5VmhLnyYvNayqPQUE0O5NGg1XmNLLaaC3K0GER /8CfkzLkqifzy6CzQbLklTqRp2CItrYyDnlUakqsqo2z6x/XTW59PehfX7Esgapa1Nsp uFQkpp4YKU+Sl8WMmOZW6YnBgZic7JrtPwCu8PcNl1NoO5bTYv4JTEsASMYy2pSMPIys 6AKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m27-20020a17090607db00b0096f5fab8b2esi7528304ejc.480.2023.06.13.23.23.50; Tue, 13 Jun 2023 23:24:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233905AbjFNGTS (ORCPT + 99 others); Wed, 14 Jun 2023 02:19:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242982AbjFNGTJ (ORCPT ); Wed, 14 Jun 2023 02:19:09 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFA191BE3; Tue, 13 Jun 2023 23:19:07 -0700 (PDT) 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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.25.1