[PATCH v2 2/2] lmb: Fix adjacent region merge in lmb_add_region_flags()

Kumar, Udit u-kumar1 at ti.com
Sun Apr 14 13:10:10 CEST 2024


Hello Patrice,

On 4/13/2024 1:54 PM, Patrice CHOTARD wrote:
>
> On 4/12/24 17:53, Patrice Chotard wrote:
>> In case a new region is adjacent to a previous region with
>> similar flag, this region is merged with its predecessor, but no
>> check are done if this new added region is overlapping another region
>> present in lmb (see reserved[3] which overlaps reserved[4]).
>>
>> [..]
>> phys_addr_t lmb_alloc(struct lmb *lmb, phys_size_t size, ulong align)
>>   {
>>   	return lmb_alloc_base(lmb, size, align, LMB_ALLOC_ANYWHERE);
>
> I think this series (v2) is not correct even if now the CI tests are OK.
> After re-reading carefully the lib_test_lmb_overlapping_reserve() test
> it appears to me there is a contradiction.
>
> It's indicating that "check that calling lmb_reserve with overlapping regions fails"
>
> but the very last test of lib_test_lmb_overlapping_reserve() has this comment :
> /* allocate 3rd region, coalesce with first and overlap with second */
> and this test allows this overlap case.
>
> It's not clear if LMB region can overlap each other or not ?


I would say partial overlap and coalescing with before one

May be Below can help

/* allocate 2nd region , This should coalesced all region into one

you will get one region as

Address --- Size

0x40010000 --- 0x30000

Next after this  /* allocate 2nd region, which should be added as first 
region */

we will have two region like

Address --- Size

(0x40000000 -- 0x8000)

(0x40010000 --- 0x30000)

Now third request comes in

/* allocate 3rd region, coalesce with first and overlap with second */

which is address of  0x40008000 and size of  0x10000, Now this region to 
be added

is coalescing with first (0x40000000 -- 0x8000) and part of this overlap 
with (0x40010000 --- 0x30000).

So, what this patch does , merge all these into one region

as (0x40000000 -- 0x40000)

> Udit, your patch edb5824be17f ("lmb: remove overlapping region with next range")
> is authorizing LMB overlapping right ?

As said before this is checking overlap and coalescing and acting 
accordingly.

> Patrice
>
>
>
>
>


More information about the U-Boot mailing list