diff mbox series

[v2,1/1] lmb: Treat a region which is a subset as equal

Message ID 20230212150706.2967007-2-sjoerd@collabora.com
State Accepted
Commit 0d91c88230fe8bd9f8d39ca2ab69cd6282e9f949
Delegated to: Tom Rini
Headers show
Series Fix boot regressions on at least TI am62x | expand

Commit Message

Sjoerd Simons Feb. 12, 2023, 3:07 p.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>

---

Changes in v2:
- Adjust calculation to prevent integer overview (fixes lmb tests)

 lib/lmb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Tom Rini Feb. 12, 2023, 11:45 p.m. UTC | #1
On Sun, Feb 12, 2023 at 04:07:05PM +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>
> 

Applied to u-boot/master, thanks!
Ashok Reddy Soma Feb. 14, 2023, 7:57 a.m. UTC | #2
Hi Sjoerd Simons,

Thanks for you patches.

However even after your patches, I still see below error.

ERROR: reserving fdt memory region failed (addr=800000000 size=180000000 flags=4)
ERROR: reserving fdt memory region failed (addr=50000000000 size=200000000 flags=4)

My DT has extra reserved memory nodes which are reserved as below.
Any idea what may be wrong ?

Reserved memory nodes in DT:

        memory@0 {
                device_type = "memory";
                reg = <0x00 0x00 0x00 0x80000000 0x08 0x00 0x01 0x80000000>;
        };

        memory@50000000000 {
                device_type = "memory";
                reg = <0x500 0x00 0x02 0x00>;
        };

        reserved-memory {
                #address-cells = <0x02>;
                #size-cells = <0x02>;
                ranges;

                buffer@0 {
                        no-map;
                        reg = <0x08 0x00 0x01 0x80000000>;
                };

                buffer@1 {
                        no-map;
                        reg = <0x500 0x00 0x02 0x00>;
                };
        };

Boot log:

## Loading init Ramdisk from Legacy Image at 04000000 ...
   Image Name:   petalinux-image-minimal-xlnx-zyn
   Created:      2011-04-05  23:00:00 UTC
   Image Type:   AArch64 Linux RAMDisk Image (uncompressed)
   Data Size:    59194022 Bytes = 56.5 MiB
   Load Address: 00000000
   Entry Point:  00000000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 00100000
   Booting using the fdt blob at 0x100000
Working FDT set to 100000
Host not halted after 16000 microseconds.
   Loading Ramdisk to 74575000, end 77de8aa6 ... OK
ERROR: reserving fdt memory region failed (addr=800000000 size=180000000 flags=4)
ERROR: reserving fdt memory region failed (addr=50000000000 size=200000000 flags=4)
   Loading Device Tree to 0000000074564000, end 0000000074574603 ... OK
Working FDT set to 74564000

Starting kernel ...


Thanks,
Ashok


> -----Original Message-----
> From: Sjoerd Simons <sjoerd@collabora.com>
> Sent: Sunday, February 12, 2023 8:37 PM
> To: Tom Rini <trini@konsulko.com>
> Cc: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>; Heinrich
> Schuchardt <xypron.glpk@gmx.de>; Simek, Michal
> <michal.simek@amd.com>; Patrice Chotard <patrice.chotard@foss.st.com>;
> u-boot@lists.denx.de
> Subject: [PATCH v2 1/1] lmb: Treat a region which is a subset as equal
> 
> CAUTION: This message has originated from an External Source. Please use
> proper judgment and caution when opening attachments, clicking links, or
> responding to this email.
> 
> 
> 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>
> 
> ---
> 
> Changes in v2:
> - Adjust calculation to prevent integer overview (fixes lmb tests)
> 
>  lib/lmb.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/lmb.c b/lib/lmb.c
> index f447c639a60..2444b2a6212 100644
> --- a/lib/lmb.c
> +++ b/lib/lmb.c
> @@ -247,8 +247,10 @@ static long lmb_add_region_flags(struct lmb_region
> *rgn, phys_addr_t base,
>                 phys_addr_t rgnbase = rgn->region[i].base;
>                 phys_size_t rgnsize = rgn->region[i].size;
>                 phys_size_t rgnflags = rgn->region[i].flags;
> +               phys_addr_t end = base + size - 1;
> +               phys_addr_t rgnend = rgnbase + rgnsize - 1;
> 
> -               if (rgnbase == base && rgnsize == size) {
> +               if (rgnbase <= base && end <= rgnend) {
>                         if (flags == rgnflags)
>                                 /* Already have this region, so we're done */
>                                 return 0;
> --
> 2.39.1
Sjoerd Simons Feb. 14, 2023, 10:23 a.m. UTC | #3
Hey,

On Tue, 2023-02-14 at 07:57 +0000, Soma, Ashok Reddy wrote:
> Hi Sjoerd Simons,
> 
> Thanks for you patches.
> 
> However even after your patches, I still see below error.
> 
> ERROR: reserving fdt memory region failed (addr=800000000
> size=180000000 flags=4)
> ERROR: reserving fdt memory region failed (addr=50000000000
> size=200000000 flags=4)

Annoyingly it's hard to tell why the reservation has failed; It could
for example be a difference in mapping flags (making them
incompatible); looking at bdinfo could help a bit here but otherwise
it'll need slightly more debugging

> My DT has extra reserved memory nodes which are reserved as below.
> Any idea what may be wrong ?
> 
> Reserved memory nodes in DT:
> 
>         memory@0 {
>                 device_type = "memory";
>                 reg = <0x00 0x00 0x00 0x80000000 0x08 0x00 0x01
> 0x80000000>;
>         };
> 
>         memory@50000000000 {
>                 device_type = "memory";
>                 reg = <0x500 0x00 0x02 0x00>;
>         };
> 
>         reserved-memory {
>                 #address-cells = <0x02>;
>                 #size-cells = <0x02>;
>                 ranges;
> 
>                 buffer@0 {
>                         no-map;
>                         reg = <0x08 0x00 0x01 0x80000000>;
>                 };
> 
>                 buffer@1 {
>                         no-map;
>                         reg = <0x500 0x00 0x02 0x00>;
>                 };
>         };
> 
> Boot log:
> 
> ## Loading init Ramdisk from Legacy Image at 04000000 ...
>    Image Name:   petalinux-image-minimal-xlnx-zyn
>    Created:      2011-04-05  23:00:00 UTC
>    Image Type:   AArch64 Linux RAMDisk Image (uncompressed)
>    Data Size:    59194022 Bytes = 56.5 MiB
>    Load Address: 00000000
>    Entry Point:  00000000
>    Verifying Checksum ... OK
> ## Flattened Device Tree blob at 00100000
>    Booting using the fdt blob at 0x100000
> Working FDT set to 100000
> Host not halted after 16000 microseconds.
>    Loading Ramdisk to 74575000, end 77de8aa6 ... OK
> ERROR: reserving fdt memory region failed (addr=800000000
> size=180000000 flags=4)
> ERROR: reserving fdt memory region failed (addr=50000000000
> size=200000000 flags=4)
>    Loading Device Tree to 0000000074564000, end 0000000074574603 ...
> OK
> Working FDT set to 74564000
> 
> Starting kernel ...
> 
> 
> Thanks,
> Ashok
> 
> 
> > -----Original Message-----
> > From: Sjoerd Simons <sjoerd@collabora.com>
> > Sent: Sunday, February 12, 2023 8:37 PM
> > To: Tom Rini <trini@konsulko.com>
> > Cc: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>; Heinrich
> > Schuchardt <xypron.glpk@gmx.de>; Simek, Michal
> > <michal.simek@amd.com>; Patrice Chotard
> > <patrice.chotard@foss.st.com>;
> > u-boot@lists.denx.de
> > Subject: [PATCH v2 1/1] lmb: Treat a region which is a subset as
> > equal
> > 
> > CAUTION: This message has originated from an External Source.
> > Please use
> > proper judgment and caution when opening attachments, clicking
> > links, or
> > responding to this email.
> > 
> > 
> > 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>
> > 
> > ---
> > 
> > Changes in v2:
> > - Adjust calculation to prevent integer overview (fixes lmb tests)
> > 
> >  lib/lmb.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/lib/lmb.c b/lib/lmb.c
> > index f447c639a60..2444b2a6212 100644
> > --- a/lib/lmb.c
> > +++ b/lib/lmb.c
> > @@ -247,8 +247,10 @@ static long lmb_add_region_flags(struct
> > lmb_region
> > *rgn, phys_addr_t base,
> >                 phys_addr_t rgnbase = rgn->region[i].base;
> >                 phys_size_t rgnsize = rgn->region[i].size;
> >                 phys_size_t rgnflags = rgn->region[i].flags;
> > +               phys_addr_t end = base + size - 1;
> > +               phys_addr_t rgnend = rgnbase + rgnsize - 1;
> > 
> > -               if (rgnbase == base && rgnsize == size) {
> > +               if (rgnbase <= base && end <= rgnend) {
> >                         if (flags == rgnflags)
> >                                 /* Already have this region, so
> > we're done */
> >                                 return 0;
> > --
> > 2.39.1
>
diff mbox series

Patch

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