Re: [PATCH RFC] mm/memblock: Fix reserve_mem allocation overlapping KHO scratch regions
From: Mike Rapoport
Date: Sun Nov 30 2025 - 10:03:21 EST
Hi,
On Sun, Nov 30, 2025 at 05:29:39PM +0000, Swaraj Gaikwad wrote:
> Currently, `reserve_mem=` does not check for overlap with these KHO
> scratch areas. As a result, a memblock allocation may land inside a
> KHO-provided scratch region, leading to corruption or loss of the data.
> Noted by the following TODO:
> /* TODO: Allocation must be outside of scratch region */
> This RFC proposes extending `reserve_mem()` to allocate memory *only* in
> gaps outside the KHO scratch intervals. The logic is:
>
> 1. Walk through all KHO scratch ranges (kho_scratch[]).
> 2. Attempt allocation in each safe gap:
> [curr_start_addr, scratch_start)
> 3. If not found, attempt to allocate after the last scratch block.
> 4. If all attempts fail, return -ENOMEM.
>
> The allocation is done via `memblock_phys_alloc_range()`, which already
> supports constrained range allocation and preserves alignment guarantees.
>
> This is posted as an RFC because I would like feedback on:
>
> - Whether the allocation-gap scanning approach is acceptable.
> - Whether this logic belongs in reserve_mem() or should be abstracted
> into a helper for reuse.
> - I would appreciate guidance on testing this change.
So this is completely untested?
Kernel documentation asks for submitters to test their code:
https://docs.kernel.org/process/submit-checklist.html#test-your-code
Please study the code you are changing to understand how it should be
tested and don't submit untested patches.
> Signed-off-by: Swaraj Gaikwad <swarajgaikwad1925@xxxxxxxxx>
--
Sincerely yours,
Mike.