From: Em Sharnoff <sharnoff@neon.tech>
To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-mm@kvack.org
Cc: Dave Hansen <dave.hansen@linux.intel.com>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
"H. Peter Anvin" <hpa@zytor.com>,
"Edgecombe, Rick P" <rick.p.edgecombe@intel.com>,
Oleg Vasilev <oleg@neon.tech>,
Arthur Petukhovsky <arthur@neon.tech>,
Stefan Radig <stefan@neon.tech>, Misha Sakhnov <misha@neon.tech>
Subject: [PATCH v5 3/4] x86/mm: Handle alloc failure in phys_*_init()
Date: Fri, 11 Jul 2025 17:25:47 +0100 [thread overview]
Message-ID: <136b4999-1c05-4d30-9521-d621196e6ba7@neon.tech> (raw)
In-Reply-To: <4fe0984f-74dc-45fe-b2b6-bdd81ec15bac@neon.tech>
During memory hotplug, allocation failures in phys_*_init() aren't
handled, which results in a null pointer dereference if they occur.
This patch depends on the previous patch ("x86/mm: Allow error returns
from phys_*_init()").
Signed-off-by: Em Sharnoff <sharnoff@neon.tech>
---
Changelog:
- v4: Split this patch out from the error handling changes
---
arch/x86/mm/init_64.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index ca71eaec1db5..eced309a4015 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -573,6 +573,8 @@ phys_pmd_init(pmd_t *pmd_page, unsigned long paddr, unsigned long paddr_end,
}
pte = alloc_low_page();
+ if (!pte)
+ return -ENOMEM;
paddr_last = phys_pte_init(pte, paddr, paddr_end, new_prot, init);
spin_lock(&init_mm.page_table_lock);
@@ -665,6 +667,8 @@ phys_pud_init(pud_t *pud_page, unsigned long paddr, unsigned long paddr_end,
}
pmd = alloc_low_page();
+ if (!pmd)
+ return -ENOMEM;
ret = phys_pmd_init(pmd, paddr, paddr_end,
page_size_mask, prot, init);
@@ -727,6 +731,8 @@ phys_p4d_init(p4d_t *p4d_page, unsigned long paddr, unsigned long paddr_end,
}
pud = alloc_low_page();
+ if (!pud)
+ return -ENOMEM;
ret = phys_pud_init(pud, paddr, __pa(vaddr_end),
page_size_mask, prot, init);
@@ -775,6 +781,8 @@ __kernel_physical_mapping_init(unsigned long paddr_start,
}
p4d = alloc_low_page();
+ if (!p4d)
+ return -ENOMEM;
ret = phys_p4d_init(p4d, __pa(vaddr), __pa(vaddr_end),
page_size_mask, prot, init);
--
2.39.5
next prev parent reply other threads:[~2025-07-11 16:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-11 16:22 [PATCH v5 0/4] x86/mm: Improve alloc handling of phys_*_init() Em Sharnoff
2025-07-11 16:24 ` [PATCH v5 1/4] x86/mm: Update mapped addresses in phys_{pmd,pud}_init() Em Sharnoff
2025-07-11 16:25 ` [PATCH v5 2/4] x86/mm: Allow error returns from phys_*_init() Em Sharnoff
2025-07-11 16:25 ` Em Sharnoff [this message]
2025-07-11 16:26 ` [PATCH v5 4/4] x86/mm: Use GFP_KERNEL for alloc_low_pages() after boot Em Sharnoff
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=136b4999-1c05-4d30-9521-d621196e6ba7@neon.tech \
--to=sharnoff@neon.tech \
--cc=arthur@neon.tech \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=misha@neon.tech \
--cc=oleg@neon.tech \
--cc=peterz@infradead.org \
--cc=rick.p.edgecombe@intel.com \
--cc=stefan@neon.tech \
--cc=tglx@linutronix.de \
--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