Skip to contentSkip to conversation

Fix boot regressions on at least TI am62x

PATCH Superseded Sjoerd Simons 2 participants 12 messages Jan 19, 2023 – Feb 8, 2023 Library code

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Fix boot regressions on at least TI am62x

When booting a recent u-boot master on TI am62x with the distro boot sequence it fails loading the FDT:

Booting using the fdt blob at 0x88000000
Working FDT set to 88000000
Loading Ramdisk to 8d711000, end 8ffffd95 ... OK
ERROR: reserving fdt memory region failed (addr=9e780000 size=80000 flags=4)
ERROR: reserving fdt memory region failed (addr=9e800000 size=1800000 flags=4)
ERROR: reserving fdt memory region failed (addr=9db00000 size=c00000 flags=4)
ERROR: Failed to allocate 0x8f58 bytes below 0x90000000.
device tree - allocation error
FDT creation failed!
resetting ...

It turns out that this is caused by commit 06d514d77c37 ("lmb: consider EFI memory map") due to injecting both extra and some similar memory regions via a different path into the lmb. The following series fixes the apparent fallout from that ;)

Sjoerd Simons (3):
Bump LMB_MAX_REGIONS default to 16
lmb: Set correct lmb flags for EFI memory map entries
lmb: Treat a region which is a subset as equal

 lib/Kconfig |  2 +-
 lib/lmb.c   | 15 +++++++++------
 2 files changed, 10 insertions(+), 7 deletions(-)
Signature · 1 line
2.39.0
#1 lore raw

PATCH 1/3 Bump LMB_MAX_REGIONS default to 16

Since commit 06d514d77c37 ("lmb: consider EFI memory map") the EFI regions are also pushed into the lmb if EFI_LOADER is enabled (which is by default on most system). Which can cause the number of entries to go over the maximum as it's default is only 8.

Specifically i ran into this case on an TI am62 which has an fdt with 4 reserved regions (in practice 3 lmb entries due to adjecent ranges).

As this is likely to impact more devices bump the default max regions to 16 so there is a bit more slack.

---

 lib/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/Kconfig +1 -1
index def36f275ce..7eb0e7addc7 100644
@@ -1005,7 +1005,7 @@ config LMB_USE_MAX_REGIONS
 config LMB_MAX_REGIONS
 	int "Number of memory and reserved regions in lmb lib"
 	depends on LMB && LMB_USE_MAX_REGIONS
-	default 8
+	default 16
 	help
 	  Define the number of supported regions, memory and reserved, in the
 	  library logical memory blocks.
Signature · 1 line
2.39.0
#2 lore raw

Re: [PATCH 1/3] Bump LMB_MAX_REGIONS default to 16

Quoted 5 lines · Sjoerd Simons

Since commit 06d514d77c37 ("lmb: consider EFI memory map") the EFI regions are also pushed into the lmb if EFI_LOADER is enabled (which is by default on most system). Which can cause the number of entries to go over the maximum as it's default is only 8.

Quoted 7 lines

Specifically i ran into this case on an TI am62 which has an fdt with 4 reserved regions (in practice 3 lmb entries due to adjecent ranges).

As this is likely to impact more devices bump the default max regions to 16 so there is a bit more slack.

I prefer to use:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
in this case due to it being overall a smaller size increase.

Signature · 1 line
Tom
#3 lore raw

Re: [PATCH 1/3] Bump LMB_MAX_REGIONS default to 16

Quoted 10 lines · Tom Rini
Quoted 5 lines · Sjoerd Simons

As this is likely to impact more devices bump the default max regions to 16 so there is a bit more slack.

I prefer to use:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
in this case due to it being overall a smaller size increase.

That's fine by me, achieves the same goal i was after for sure; The other 2 patches in this series are still required to fix the boot regressions i'm seeing ofcourse :)

Signature · 2 lines
Sjoerd Simons
Collabora Ltd.
#4 lore raw

Re: [PATCH 1/3] Bump LMB_MAX_REGIONS default to 16

Quoted 8 lines · Sjoerd Simons
Quoted 7 lines · Tom Rini
Quoted 5 lines · Sjoerd Simons

As this is likely to impact more devices bump the default max regions to 16 so there is a bit more slack.

Quoted 7 lines
Quoted 3 lines

I prefer to use:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
in this case due to it being overall a smaller size increase.

That's fine by me, achieves the same goal i was after for sure; The other 2 patches in this series are still required to fix the boot regressions i'm seeing ofcourse :)

Right, I'll be getting those soon.

Signature · 1 line
Tom
#5 lore raw

Re: [PATCH 1/3] Bump LMB_MAX_REGIONS default to 16

In reply to Sjoerd Simons
Quoted 5 lines · Sjoerd Simons

Since commit 06d514d77c37 ("lmb: consider EFI memory map") the EFI regions are also pushed into the lmb if EFI_LOADER is enabled (which is by default on most system). Which can cause the number of entries to go over the maximum as it's default is only 8.

Quoted 7 lines

Specifically i ran into this case on an TI am62 which has an fdt with 4 reserved regions (in practice 3 lmb entries due to adjecent ranges).

As this is likely to impact more devices bump the default max regions to 16 so there is a bit more slack.

As Philippe Schenker explained, I was mis-interpreting what my attempted solution would do, so I've reverted that and this patch here makes the most sense to use as a general fix. As such I've now applied this to u-boot/master.

Signature · 1 line
Tom
#6 lore raw

PATCH 2/3 lmb: Set correct lmb flags for EFI memory map entries

In reply to Sjoerd Simons

When adding reserved memory areas from the EFI memory map set the NOMAP flag when applicable. When this isn't done adding "no-map" flagged entries from the fdt after receiving the same from the EFI memory map fails due to non-matching flags.

---

 lib/lmb.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
lib/lmb.c +8 -5
index ec790760db6..f447c639a60 100644
@@ -175,11 +175,14 @@ static __maybe_unused int efi_lmb_reserve(struct lmb *lmb)
 		return 1;
 
 	for (i = 0, map = memmap; i < map_size / sizeof(*map); ++map, ++i) {
-		if (map->type != EFI_CONVENTIONAL_MEMORY)
-			lmb_reserve(lmb,
-				    map_to_sysmem((void *)(uintptr_t)
-						  map->physical_start),
-				    map->num_pages * EFI_PAGE_SIZE);
+		if (map->type != EFI_CONVENTIONAL_MEMORY) {
+			lmb_reserve_flags(lmb,
+					  map_to_sysmem((void *)(uintptr_t)
+							map->physical_start),
+					  map->num_pages * EFI_PAGE_SIZE,
+					  map->type == EFI_RESERVED_MEMORY_TYPE
+					      ? LMB_NOMAP : LMB_NONE);
+		}
 	}
 	efi_free_pool(memmap);
 
Signature · 1 line
2.39.0
#7 lore raw

Re: [PATCH 2/3] lmb: Set correct lmb flags for EFI memory map entries

Quoted 6 lines · Sjoerd Simons

When adding reserved memory areas from the EFI memory map set the NOMAP flag when applicable. When this isn't done adding "no-map" flagged entries from the fdt after receiving the same from the EFI memory map fails due to non-matching flags.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#8 lore raw

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

In reply to Sjoerd Simons

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.

---

 lib/lmb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/lmb.c +1 -1
index f447c639a60..b09a043f4c2 100644
@@ -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;
Signature · 1 line
2.39.0
#9 lore raw

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

Quoted 19 lines · Sjoerd Simons

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.

---

 lib/lmb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/lmb.c +0 -0
index f447c639a60..b09a043f4c2 100644

lib/lmb.c static long lmb_add_region_flags(struct lmb_region *rgn, phys_addr_t base, · line 254

Quoted 8 lines
lib/lmb.c +1 -1
@@ -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.

Signature · 1 line
Tom
#10 lore raw

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

Quoted 31 lines · Tom Rini
Quoted 29 lines · Sjoerd Simons

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.

---

 lib/lmb.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
lib/lmb.c +0 -0
index f447c639a60..b09a043f4c2 100644
@@ -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 +

Quoted 8 lines
Quoted 5 lines

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 ?

Signature · 2 lines
Sjoerd Simons
Collabora Ltd.
#11 lore raw

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

Quoted 41 lines · Sjoerd Simons
Quoted 31 lines · Tom Rini
Quoted 29 lines · Sjoerd Simons

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.

---

 lib/lmb.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
lib/lmb.c +0 -0
index f447c639a60..b09a043f4c2 100644
@@ -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 +

Quoted 8 lines
Quoted 5 lines

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.

Quoted 2 lines

Oh sorry for missing that; I'll get those fixed. Does the direction at least seem sensible to you ?

I think so, yes.

Signature · 1 line
Tom