Re: [PATCH v3 0/5] of: reserved_mem: several fixes about reserved memory

From: Marek Szyprowski

Date: Thu Oct 08 2026 - 05:46:02 EST


On 08.10.2026 08:38, Mike Rapoport wrote:
> On Tue, Oct 06, 2026 at 03:26:21PM +0200, Marek Szyprowski wrote:
>> On 03.10.2026 10:04, Mike Rapoport wrote:
>>> On Tue, Sep 22, 2026 at 05:24:32PM +0800, Wandun wrote:
>>>>>> From: Wandun Chen <chenwandun@xxxxxxxxxxx>
>>>>>>
>>>>>> This series fixes several error-handling issues in the reserved-memory
>>>>>> initialization paths.
>>>>>>
>>>>>> v2 --> v3:
>>>>>> 1. Rework the mechanism that checks in the late scan whether the early
>>>>>> reservation succeeded (patches 3-5, suggested by Marek, thanks).
>>>>>>
>>>>>> Patch 3 adds a new memblock flag MEMBLOCK_RSRV_RMEM, which is set when
>>>>>> the early reservation of a static region succeeds and checked in the
>>>>>> late scan.
>>>>> Can we keep this local to of_reserved_mem please?
>>>> Probably not. I do not see a way to keep this entirely local to
>>>> of_reserved_mem while handling the issue robustly.
>>>>
>>>> I previously implemented an approach in of_reserved_mem that records
>>>> static reserved-memory nodes whose early reservation failed in a local
>>>> array [1]. However, the early scan runs before paging_init(), so the array
>>>> cannot be dynamically expanded. If the number of failed nodes exceeds
>>>> the array size, some failures cannot be recorded and the issue remains,
>>>> and that is why Marek said "partial solution", although in practice
>>>> having that many failed nodes is unlikely.
>>> Even before paging_init() there is memblock_alloc().
>> One can call it, but such memory cannot be dereferenced/accessed for example
>> on ARM64, because it is not yet mapped in the linear map.
> Can't we use early_memremap() for it?

I didn't know that this is a valid, allowed use case for early_memremap(). If so, then
this is definitely the best approach, as it also removes the horrible two pass
initialization introduced by commit 8a6e02d0c00e ("of: reserved_mem: Restructure how
the reserved memory regions are processed").

I've backed such refactor with LLM and it looks very promising:

https://lore.kernel.org/all/20261008094125.3197971-1-m.szyprowski@xxxxxxxxxxx/


It works fine on ARM, ARM64 and RiscV64. :)

Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland