* [PATCH] x86/mm: Tear down the direct map when memory hot add fails
@ 2026-11-08 3:00 Chris Down
2026-11-08 16:46 ` Harry Yoo
0 siblings, 1 reply; 2+ messages in thread
From: Chris Down @ 2026-11-08 3:00 UTC (permalink / raw)
To: Dave Hansen, Andy Lutomirski, Peter Zijlstra, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, x86
Cc: H. Peter Anvin, David Hildenbrand, Oscar Salvador, Andrew Morton,
Lance Yang, Muchun Song, linux-mm, linux-cxl, linux-kernel,
kernel-team
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] x86/mm: Tear down the direct map when memory hot add fails
2026-11-08 3:00 [PATCH] x86/mm: Tear down the direct map when memory hot add fails Chris Down
@ 2026-11-08 16:46 ` Harry Yoo
0 siblings, 0 replies; 2+ messages in thread
From: Harry Yoo @ 2026-11-08 16:46 UTC (permalink / raw)
To: Chris Down
Cc: Dave Hansen, Andy Lutomirski, Peter Zijlstra, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, x86, H. Peter Anvin,
David Hildenbrand, Oscar Salvador, Andrew Morton, Lance Yang,
Muchun Song, linux-mm, linux-cxl, linux-kernel, kernel-team
On Sat, Nov 07, 2026 at 07:00:52PM -0800, 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>
> ---
Looks good to me,
Acked-by: Harry Yoo (Meta) <harry@kernel.org>
> 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
--
Cheers,
Harry / Hyeonggon
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-08 16:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-08 3:00 [PATCH] x86/mm: Tear down the direct map when memory hot add fails Chris Down
2026-11-08 16:46 ` Harry Yoo
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®