Skip to contentSkip to conversation

lib: lmb: return -EFAULT for partial bank-boundary overlap

PATCH In review Balaji Selvanathan 2 participants 2 messages Sep 12 – Sep 13 Library code

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 lib: lmb: return -EFAULT for partial bank-boundary overlap

_lmb_alloc_addr() currently returns -EINVAL when a reservation overlaps an available memory bank but extends beyond the bank boundary. It returns -EFAULT when the reservation does not overlap any available memory bank.

From LMB's perspective, neither request can be satisfied because the requested reservation is not fully contained within an available region. Callers therefore cannot make practical use of the distinction.

boot_fdt_handle_region() treats -EFAULT as a non-fatal condition and silently skips the reservation, while -EINVAL causes a boot-time error message to be printed. For bank-boundary overlap cases this message is misleading because no internal LMB error has occurred; the reservation simply does not fit within available memory.

Return -EFAULT for the partial-overlap case as well and update the corresponding unit tests

---
Changes in v2:
- Reworded the commit message to explain why the overlap is not a
serious error and why it could be ignored
- Link to v1: https://lore.kernel.org/u-boot/20260907-lmb-alloc-addr-efault-v1-1-7a5b73c2318c@oss.qualcomm.com/

---
 lib/lmb.c      | 2 --
 test/lib/lmb.c | 4 ++--
 2 files changed, 2 insertions(+), 4 deletions(-)
lib/lmb.c +0 -2
index ca00047f624..745410a8895 100644
@@ -752,8 +752,6 @@ static int _lmb_alloc_addr(phys_addr_t base, phys_size_t size, u32 flags)
 				      base + size - 1, 1))
 			/* ok, reserve the memory */
 			return lmb_reserve(base, size, flags);
-
-		return -EINVAL;
 	}
 
 	return -EFAULT;
test/lib/lmb.c +2 -2
index 168c66ae649..e6c05a492df 100644
@@ -781,9 +781,9 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram)
 		ret = lmb_alloc_addr(ram_end, 1, LMB_NONE);
 		ut_asserteq(ret, -EFAULT);
 		ret = lmb_alloc_addr(ram_end - 1, 2, LMB_NOMAP);
-		ut_asserteq(ret, -EINVAL);
+		ut_asserteq(ret, -EFAULT);
 		ret = lmb_alloc_addr(ram_end - 1, 2, LMB_NOOVERWRITE);
-		ut_asserteq(ret, -EINVAL);
+		ut_asserteq(ret, -EFAULT);
 	}
 	if (ram != 0) {
 		ret = lmb_alloc_addr(ram - 1, 1, LMB_NONE);

---
base-commit: 509312dc5386ff4c5adabf53a573abca0aac4ce5
change-id: 20260907-lmb-alloc-addr-efault-a29212da721d

Best regards,

Signature · 1 line
Balaji Selvanathan <[email protected]>
#1 lore raw
Quoted 4 lines · Balaji Selvanathan

_lmb_alloc_addr() currently returns -EINVAL when a reservation overlaps an available memory bank but extends beyond the bank boundary. It returns -EFAULT when the reservation does not overlap any available memory bank.

It returns EFAULT when the reservation is attempted over memory that is not present, is that what the second sentence means ?

Quoted 3 lines

From LMB's perspective, neither request can be satisfied because the
requested reservation is not fully contained within an available region. Callers therefore cannot make practical use of the distinction.

Have you confirmed this for every possible caller ?

Quoted 5 lines

boot_fdt_handle_region() treats -EFAULT as a non-fatal condition and silently skips the reservation, while -EINVAL causes a boot-time error message to be printed. For bank-boundary overlap cases this message is misleading because no internal LMB error has occurred; the reservation simply does not fit within available memory.

If reservation does not fit into available memory, that sounds like a fatal error.

The commit message STILL does not explain why do you think the overlap is not a serious error, and why it could be ignored. I already asked this in V1, and got pointed to this V2 which only contains more blurb in the commit message, but no actual answer to my question.