Re: [PATCH v4 7/7] mm/mm_init: Use for_each_valid_pfn() in init_unavailable_range()

From: David Woodhouse
Date: Sat Apr 26 2025 - 04:31:18 EST


On Fri, 2025-04-25 at 16:38 -0700, Andrew Morton wrote:
> On Fri, 25 Apr 2025 17:11:10 +0100 Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx> wrote:
>
> > Andrew - can we drop this from mm-new? It's breaking it.
>
> I almost did, but David seems to have a fix.
>
> --- a/include/linux/mmzone.h~mm-mm_init-use-for_each_valid_pfn-in-init_unavailable_range-fix

The symptoms only manifested when it got used in
init_unavailable_range() but that's actually a fix for the sparsemem
implementation of for_each_valid_pfn(), as David H surmised.

Please could the fix be folded into
mm-implement-for_each_valid_pfn-for-config_sparsemem.patch ?

This is what it should look like with the fix:
https://git.infradead.org/?p=users/dwmw2/linux.git;a=commitdiff;h=55bebbb093

If you want to keep the fix separate, then that's the patch that it
fixes. Do you want a commit message? I'll certainly give you a proper
SoB:

Signed-off-by: David Woodhouse <dwmw@xxxxxxxxxxxx>

Happy to resend the fixed series if it helps; it looks like you've
already basically sorted it though?

Thanks!

> +++ a/include/linux/mmzone.h
> @@ -2190,10 +2190,10 @@ static inline unsigned long next_valid_p
>   /*
>   * Either every PFN within the section (or subsection for VMEMMAP) is
>   * valid, or none of them are. So there's no point repeating the check
> - * for every PFN; only call first_valid_pfn() the first time, and when
> - * crossing a (sub)section boundary (i.e. !(pfn & ~PFN_VALID_MASK)).
> + * for every PFN; only call first_valid_pfn() again when crossing a
> + * (sub)section boundary (i.e. !(pfn & ~PAGE_{SUB,}SECTION_MASK)).
>   */
> - if (pfn & (IS_ENABLED(CONFIG_SPARSEMEM_VMEMMAP) ?
> + if (pfn & ~(IS_ENABLED(CONFIG_SPARSEMEM_VMEMMAP) ?
>      PAGE_SUBSECTION_MASK : PAGE_SECTION_MASK))
>   return pfn;
>  
> _
>

Attachment: smime.p7s
Description: S/MIME cryptographic signature