Re: [RFC PATCH 01/11] mm/cma: clamp multi-range search to 4G and honor memblock flags
From: Chris Down
Date: Fri Dec 04 2026 - 15:19:49 EST
Hi Suseendran,
Suseendran Bhaskaran writes:
>It also passes MEMBLOCK_NONE to for_each_free_mem_range() instead of
>choose_memblock_flags(). On KHO boots, hugetlb_cma_reserve() runs in
>mm_core_init_early() while kho_noprsrv_only is active and before
>kho_memory_init() reserves preserved pages in memblock.reserved, so
>ignoring choose_memblock_flags() can place multi-range CMA areas directly
>over KHO preserved memory.
This looks great, and I tested and the behaviour is much better,
thanks. As an aside, I'm about to post an RFC series which allocates
the hugetlb_cma area the same way as boot-time HugeTLB pages, so that
KHO doesn't count it when sizing bootmem. A side effect is that if
the next kernel can't fit the area in a single range outside bootmem,
it goes to the multi-range fallback instead of taking a range inside
bootmem. So that series makes this walk easier to hit after a KHO kexec,
and it can't go in without this fixed.
>Fixes: c009da4258f9 ("mm, cma: support multiple contiguous ranges, if requested")
>Fixes: d59f43b57480 ("memblock: add support for scratch memory")
The 4 GiB part of this has since been fixed by Mike's "mm/cma: fix
handling of free ranges that cross 4G for multi-range areas" [0], which
is in mm-new now, so this patch no longer applies there. That also did
the #ifdef CONFIG_PHYS_ADDR_T_64BIT change, so what's left is the
memblock flags and the wraparound check below. With the 4 GiB part gone,
c009da4258f9 is no longer what's being fixed. The flags part goes back
to d59f43b57480, since the multi-range walk already used MEMBLOCK_NONE
before free memory in memblock could hold preserved pages.
>+ orig_start = max_t(phys_addr_t, start, SZ_4G);
>+ start = ALIGN(orig_start, align);
>+ if (start < orig_start || start >= end)
I don't think the wraparound can happen. For ALIGN() to wrap, a free
range would have to start within align of the top of phys_addr_t, and
memblock memory is nowhere near there. __memblock_find_range_bottom_up()
does the same round_up() without such a check, so I'd just drop it.
Perhaps you could send the flags fix by itself as a separate patch as
you offered in the cover letter? That would selfishly make my life a
lot easier, since then I can base my series on that.
Thanks!
Chris
[0]: https://lore.kernel.org/r/20261202113910.1412130-1-rppt@xxxxxxxxxx