From: Em Sharnoff <sharnoff@neon.tech>
To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-mm@kvack.org
Cc: Ingo Molnar <mingo@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Borislav Petkov <bp@alien8.de>,
"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 v4 3/4] x86/mm: Handle alloc failure in phys_*_init()
Date: Fri, 13 Jun 2025 21:11:48 +0100 [thread overview]
Message-ID: <062402c3-e640-4578-b1b1-318a0a728a93@neon.tech> (raw)
In-Reply-To: <7d0d307d-71eb-4913-8023-bccc7a8a4a3d@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 b18ab2dcc799..a585daa76d69 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -572,6 +572,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);
@@ -664,6 +666,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);
@@ -726,6 +730,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);
@@ -774,6 +780,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-06-13 20:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-13 20:09 [PATCH v4 0/4] x86/mm: Improve alloc handling of phys_*_init() Em Sharnoff
2025-06-13 20:10 ` [PATCH v4 1/4] x86/mm: Update mapped addresses in phys_{pmd,pud}_init() Em Sharnoff
2025-06-13 20:11 ` [PATCH v4 2/4] x86/mm: Allow error returns from phys_*_init() Em Sharnoff
2025-06-13 20:11 ` Em Sharnoff [this message]
2025-06-13 20:12 ` [PATCH v4 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=062402c3-e640-4578-b1b1-318a0a728a93@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@kernel.org \
--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
all inboxes | Powered by JetHome®