mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Miaohe Lin <linmiaohe@huawei.com>
To: David Hildenbrand <david@redhat.com>
Cc: <isimatu.yasuaki@jp.fujitsu.com>, <toshi.kani@hp.com>,
	<linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] mm/memory_hotplug: fix kfree() of bootmem memory
Date: Tue, 8 Feb 2022 09:59:18 +0800	[thread overview]
Message-ID: <828c9b16-6ff0-abb7-3a16-277d2d60de81@huawei.com> (raw)
In-Reply-To: <6d4ab70e-b944-5f7d-e9a3-979ac66c70f7@redhat.com>

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.

  reply	other threads:[~2022-02-08  1:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-07 13:56 Miaohe Lin
2022-02-07 14:33 ` David Hildenbrand
2022-02-08  1:59   ` Miaohe Lin [this message]
2022-02-08  9:19     ` David Hildenbrand
2022-02-08 11:20       ` Miaohe Lin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=828c9b16-6ff0-abb7-3a16-277d2d60de81@huawei.com \
    --to=linmiaohe@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=isimatu.yasuaki@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=toshi.kani@hp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®