From: "H. Peter Anvin" <hpa@zytor.com>
To: Ingo Molnar <mingo@kernel.org>, Em Sharnoff <sharnoff@neon.tech>
Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-mm@kvack.org,
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>,
"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: Re: [PATCH] x86/mm: Handle alloc failure in phys_*_init()
Date: Wed, 04 Jun 2025 23:41:21 -0700 [thread overview]
Message-ID: <70530630-6781-485C-9F2A-531E121692D1@zytor.com> (raw)
In-Reply-To: <aEE6_S2a-1tk1dtI@gmail.com>
On June 4, 2025 11:36:45 PM PDT, Ingo Molnar <mingo@kernel.org> wrote:
>
>* Em Sharnoff <sharnoff@neon.tech> wrote:
>
>> tl;dr:
>>
>> * When setting up page table mappings for physical addresses after boot,
>> alloc_low_page() uses GFP_ATOMIC, which is allowed to fail.
>> * This isn't currently handled, and results in a null pointer
>> dereference when it occurs.
>> * This allocation failure can happen during memory hotplug.
>>
>> To handle failure, change phys_pud_init() and similar functions to
>> return zero if allocation failed (either directly or transitively), and
>> convert that to -ENOMEM in arch_add_memory().
>
>> + /*
>> + * Bail only after updating pgd/p4d to keep progress from p4d across retries.
>> + */
>> + if (!paddr_last)
>> + return 0;
>> +
>> pgd_changed = true;
>
>> - init_memory_mapping(start, start + size, params->pgprot);
>> + if (!init_memory_mapping(start, start + size, params->pgprot))
>> + return -ENOMEM;
>
>I agree that it makes total sense to fix all this (especially since you
>are actively triggering it), but have you tried also changing it away
>from GFP_ATOMIC? There's no real reason why it should be GFP_ATOMIC
>AFAICS, other than some historic inertia that nobody bothered to fix.
>
>Plus, could you please change the return flow from this zero
>special-case over to something like ERR_PTR(-ENOMEM) and IS_ERR()?
>
>*Technically* zero is a valid physical address, although we
>intentionally never use it in the kernel AFAIK and wouldn't ever put a
>page table there either. ERR_PTR()/IS_ERR() is much easier on the eyes
>than the zero special-case.
>
>Finally, could you make this a 2-patch fix series: first one to fix the
>error return path to not crash, and the second one to change it away
>from GFP_ATOMIC?
>
>Thanks,
>
> Ingo
Specifically, zero is a valid *user space* address.
next prev parent reply other threads:[~2025-06-05 6:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-04 18:59 Em Sharnoff
2025-06-05 6:36 ` Ingo Molnar
2025-06-05 6:41 ` H. Peter Anvin [this message]
2025-06-05 6:47 ` Ingo Molnar
2025-06-09 10:36 ` 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=70530630-6781-485C-9F2A-531E121692D1@zytor.com \
--to=hpa@zytor.com \
--cc=arthur@neon.tech \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=mingo@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=sharnoff@neon.tech \
--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