diff mbox series

[3/3] lmb: Treat a region which is a subset as equal

Message ID 20230119083820.2656710-4-sjoerd@collabora.com
State Changes Requested
Delegated to: Tom Rini
Headers show
Series Fix boot regressions on at least TI am62x | expand

Commit Message

Sjoerd Simons Jan. 19, 2023, 8:38 a.m. UTC
In various cases logical memory blocks are coalesced; As a result doing
a strict check whether memory blocks are the same doesn't necessarily
work as a previous addition of a given block might have been merged into
a bigger block.

Fix this by considering a block is already registered if it's a pure
subset of one of the existing blocks.

Signed-off-by: Sjoerd Simons <sjoerd@collabora.com>

---

 lib/lmb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Tom Rini Feb. 6, 2023, 6:04 p.m. UTC | #1
On Thu, Jan 19, 2023 at 09:38:19AM +0100, Sjoerd Simons wrote:

> In various cases logical memory blocks are coalesced; As a result doing
> a strict check whether memory blocks are the same doesn't necessarily
> work as a previous addition of a given block might have been merged into
> a bigger block.
> 
> Fix this by considering a block is already registered if it's a pure
> subset of one of the existing blocks.
> 
> Signed-off-by: Sjoerd Simons <sjoerd@collabora.com>
> ---
> 
>  lib/lmb.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/lmb.c b/lib/lmb.c
> index f447c639a60..b09a043f4c2 100644
> --- a/lib/lmb.c
> +++ b/lib/lmb.c
> @@ -248,7 +248,7 @@ static long lmb_add_region_flags(struct lmb_region *rgn, phys_addr_t base,
>  		phys_size_t rgnsize = rgn->region[i].size;
>  		phys_size_t rgnflags = rgn->region[i].flags;
>  
> -		if (rgnbase == base && rgnsize == size) {
> +		if (rgnbase <= base && rgnbase + rgnsize >= base + size) {
>  			if (flags == rgnflags)
>  				/* Already have this region, so we're done */
>  				return 0;

This breaks lib_test_lmb_simple, lib_test_lmb_simple_x2 and
lib_test_lmb_alloc_addr.
Sjoerd Simons Feb. 8, 2023, 7:37 a.m. UTC | #2
On Mon, 2023-02-06 at 13:04 -0500, Tom Rini wrote:
> On Thu, Jan 19, 2023 at 09:38:19AM +0100, Sjoerd Simons wrote:
> 
> > In various cases logical memory blocks are coalesced; As a result
> > doing
> > a strict check whether memory blocks are the same doesn't
> > necessarily
> > work as a previous addition of a given block might have been merged
> > into
> > a bigger block.
> > 
> > Fix this by considering a block is already registered if it's a
> > pure
> > subset of one of the existing blocks.
> > 
> > Signed-off-by: Sjoerd Simons <sjoerd@collabora.com>
> > ---
> > 
> >  lib/lmb.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/lib/lmb.c b/lib/lmb.c
> > index f447c639a60..b09a043f4c2 100644
> > --- a/lib/lmb.c
> > +++ b/lib/lmb.c
> > @@ -248,7 +248,7 @@ static long lmb_add_region_flags(struct
> > lmb_region *rgn, phys_addr_t base,
> >                 phys_size_t rgnsize = rgn->region[i].size;
> >                 phys_size_t rgnflags = rgn->region[i].flags;
> >  
> > -               if (rgnbase == base && rgnsize == size) {
> > +               if (rgnbase <= base && rgnbase + rgnsize >= base +
> > size) {
> >                         if (flags == rgnflags)
> >                                 /* Already have this region, so
> > we're done */
> >                                 return 0;
> 
> This breaks lib_test_lmb_simple, lib_test_lmb_simple_x2 and
> lib_test_lmb_alloc_addr.

Oh sorry for missing that; I'll get those fixed. Does the direction at
least seem sensible to you ?
Tom Rini Feb. 8, 2023, 2:55 p.m. UTC | #3
On Wed, Feb 08, 2023 at 08:37:15AM +0100, Sjoerd Simons wrote:
> On Mon, 2023-02-06 at 13:04 -0500, Tom Rini wrote:
> > On Thu, Jan 19, 2023 at 09:38:19AM +0100, Sjoerd Simons wrote:
> > 
> > > In various cases logical memory blocks are coalesced; As a result
> > > doing
> > > a strict check whether memory blocks are the same doesn't
> > > necessarily
> > > work as a previous addition of a given block might have been merged
> > > into
> > > a bigger block.
> > > 
> > > Fix this by considering a block is already registered if it's a
> > > pure
> > > subset of one of the existing blocks.
> > > 
> > > Signed-off-by: Sjoerd Simons <sjoerd@collabora.com>
> > > ---
> > > 
> > >  lib/lmb.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/lib/lmb.c b/lib/lmb.c
> > > index f447c639a60..b09a043f4c2 100644
> > > --- a/lib/lmb.c
> > > +++ b/lib/lmb.c
> > > @@ -248,7 +248,7 @@ static long lmb_add_region_flags(struct
> > > lmb_region *rgn, phys_addr_t base,
> > >                 phys_size_t rgnsize = rgn->region[i].size;
> > >                 phys_size_t rgnflags = rgn->region[i].flags;
> > >  
> > > -               if (rgnbase == base && rgnsize == size) {
> > > +               if (rgnbase <= base && rgnbase + rgnsize >= base +
> > > size) {
> > >                         if (flags == rgnflags)
> > >                                 /* Already have this region, so
> > > we're done */
> > >                                 return 0;
> > 
> > This breaks lib_test_lmb_simple, lib_test_lmb_simple_x2 and
> > lib_test_lmb_alloc_addr.
> 
> Oh sorry for missing that; I'll get those fixed. Does the direction at
> least seem sensible to you ?

I think so, yes.
diff mbox series

Patch

diff --git a/lib/lmb.c b/lib/lmb.c
index f447c639a60..b09a043f4c2 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -248,7 +248,7 @@  static long lmb_add_region_flags(struct lmb_region *rgn, phys_addr_t base,
 		phys_size_t rgnsize = rgn->region[i].size;
 		phys_size_t rgnflags = rgn->region[i].flags;
 
-		if (rgnbase == base && rgnsize == size) {
+		if (rgnbase <= base && rgnbase + rgnsize >= base + size) {
 			if (flags == rgnflags)
 				/* Already have this region, so we're done */
 				return 0;