From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F233C433EF for ; Tue, 8 Feb 2022 01:59:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345212AbiBHB7Y (ORCPT ); Mon, 7 Feb 2022 20:59:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235393AbiBHB7W (ORCPT ); Mon, 7 Feb 2022 20:59:22 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E030C061355 for ; Mon, 7 Feb 2022 17:59:21 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Jt5kz3VgHzccpd; Tue, 8 Feb 2022 09:58:19 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Tue, 8 Feb 2022 09:59:18 +0800 Subject: Re: [PATCH] mm/memory_hotplug: fix kfree() of bootmem memory To: David Hildenbrand CC: , , , , Andrew Morton References: <20220207135618.17231-1-linmiaohe@huawei.com> <6d4ab70e-b944-5f7d-e9a3-979ac66c70f7@redhat.com> From: Miaohe Lin Message-ID: <828c9b16-6ff0-abb7-3a16-277d2d60de81@huawei.com> Date: Tue, 8 Feb 2022 09:59:18 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <6d4ab70e-b944-5f7d-e9a3-979ac66c70f7@redhat.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi: On 2022/2/7 22:33, David Hildenbrand wrote: > On 07.02.22 14:56, Miaohe Lin wrote: >> We can't use kfree() to release the resource as it might come from bootmem. >> Use release_mem_region() instead. > > How can this happen? release_mem_region() is called either from > __add_memory() or from add_memory_driver_managed(), where we allocated > the region via register_memory_resource(). Both functions shouldn't ever > be called before the buddy is up an running. > > Do you have a backtrace of an actual instance of this issue? Or was this > identified as possibly broken by code inspection? > This is identified as possibly broken by code inspection. IIUC, alloc_resource is always used to allocate the resource. It has the below logic: if (bootmem_resource_free) { res = bootmem_resource_free; bootmem_resource_free = res->sibling; } where bootmem_resource_free is used to reusing the resource entries allocated by boot mem after the system is up: /* * For memory hotplug, there is no way to free resource entries allocated * by boot mem after the system is up. So for reusing the resource entry * we need to remember the resource. */ static struct resource *bootmem_resource_free; So I think register_memory_resource() can reuse the resource allocated by bootmem. Or am I miss anything? Thanks.