From: Lance Yang <lance.yang@linux.dev>
To: "David Hildenbrand (Arm)" <david@kernel.org>,
Chris Down <chris@chrisdown.name>,
Dave Hansen <dave.hansen@linux.intel.com>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
x86@kernel.org
Cc: "H. Peter Anvin" <hpa@zytor.com>,
Oscar Salvador <osalvador@suse.de>,
Andrew Morton <akpm@linux-foundation.org>,
Muchun Song <muchun.song@linux.dev>,
linux-mm@kvack.org, linux-cxl@vger.kernel.org,
linux-kernel@vger.kernel.org, kernel-team@meta.com
Subject: Re: [PATCH] x86/mm: Tear down the direct map when memory hot add fails
Date: Mon, 9 Nov 2026 19:52:42 +0800 [thread overview]
Message-ID: <7975c299-dcd3-4aee-8bcb-f3c0e8b8ce7a@linux.dev> (raw)
In-Reply-To: <4bfb6533-1e77-4150-9626-437678b1785d@kernel.org>
On 2026/11/9 17:34, David Hildenbrand (Arm) wrote:
> On 11/8/26 04:00, Chris Down wrote:
>> arch_add_memory() sets up the direct map before calling add_pages().
>> If add_pages() fails, the range stays mapped and any page tables
>> allocated for it are leaked. A later hot add can reuse the stale
>> mapping.
>>
>> Remove the direct mapping on failure.
>>
>> Fixes: 45e0b78b0532 ("[PATCH] hot-add-mem x86_64: use CONFIG_MEMORY_HOTPLUG_RESERVE")
>> Signed-off-by: Chris Down <chris@chrisdown.name>
>> ---
>> arch/x86/mm/init_64.c | 10 +++++++++-
>> 1 file changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
>> index 8b6d86fb5a42..846cb34b38dd 100644
>> --- a/arch/x86/mm/init_64.c
>> +++ b/arch/x86/mm/init_64.c
>> @@ -989,15 +989,23 @@ int add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages,
>> return ret;
>> }
>>
>> +static void __meminit kernel_physical_mapping_remove(unsigned long start,
>> + unsigned long end);
>> +
>> int arch_add_memory(int nid, u64 start, u64 size,
>> struct mhp_params *params)
>> {
>> unsigned long start_pfn = start >> PAGE_SHIFT;
>> unsigned long nr_pages = size >> PAGE_SHIFT;
>> + int ret;
>>
>> init_memory_mapping(start, start + size, params->pgprot);
>>
>> - return add_pages(nid, start_pfn, nr_pages, params);
>> + ret = add_pages(nid, start_pfn, nr_pages, params);
>> + if (ret)
>> + kernel_physical_mapping_remove(start, start + size);
>> +
>> + return ret;
>> }
>>
>> static void __meminit free_pagetable(struct page *page)
>>
>> base-commit: fa4ad798f6f681031775266044ba1b0cf3c670bd
>
> I thought we fixed that already, but I remembered
>
> https://lore.kernel.org/all/20260930160432.5564-1-lance.yang@linux.dev/
Ouch ... I missed the direct map cleanup in that fix ...
Reviewed-by: Lance Yang <lance.yang@linux.dev>
prev parent reply other threads:[~2026-11-09 11:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-08 3:00 Chris Down
2026-11-08 16:46 ` Harry Yoo
2026-11-09 3:44 ` Muchun Song
2026-11-09 9:13 ` Oscar Salvador (SUSE)
2026-11-09 9:34 ` David Hildenbrand (Arm)
2026-11-09 11:52 ` Lance Yang [this message]
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=7975c299-dcd3-4aee-8bcb-f3c0e8b8ce7a@linux.dev \
--to=lance.yang@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=bp@alien8.de \
--cc=chris@chrisdown.name \
--cc=dave.hansen@linux.intel.com \
--cc=david@kernel.org \
--cc=hpa@zytor.com \
--cc=kernel-team@meta.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
--cc=peterz@infradead.org \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
/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®