From: <rs@ti.com>
To: <robertcnelson@gmail.com>, <ayush@beagleboard.org>,
<Erik.Welsh@octavosystems.com>, <anshuld@ti.com>, <bb@ti.com>,
<trini@konsulko.com>, <afd@ti.com>, <xypron.glpk@gmx.de>,
<ilias.apalodimas@linaro.org>
Cc: <u-boot@lists.denx.de>
Subject: [PATCH 1/6] lmb: add LMB_FDT for fdt reserved regions
Date: Wed, 1 Apr 2026 19:14:05 -0500 [thread overview]
Message-ID: <20260402001410.3736815-2-rs@ti.com> (raw)
In-Reply-To: <20260402001410.3736815-1-rs@ti.com>
From: Randolph Sapp <rs@ti.com>
Add an LMB_FDT bit for fdt reserved regions, so we can reclaim them when
parsing a new device tree and properly warn people when a reservation
overlaps with an existing allocation.
If we don't at least warn the user of these reservation failures,
there's a chance that this region could be freed and reallocated for
something important later.
This useful warning mechanism was broken in:
5a6aa7d5913 ("boot: fdt: Handle already reserved memory in boot_fdt_reserve_region()")
Signed-off-by: Randolph Sapp <rs@ti.com>
---
boot/image-fdt.c | 5 ++++-
include/lmb.h | 7 +++++++
lib/lmb.c | 23 +++++++++++++++++++++++
3 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/boot/image-fdt.c b/boot/image-fdt.c
index a3a4fb8b558..0f5857f24d2 100644
--- a/boot/image-fdt.c
+++ b/boot/image-fdt.c
@@ -73,6 +73,7 @@ static void boot_fdt_reserve_region(u64 addr, u64 size, u32 flags)
{
long ret;
phys_addr_t rsv_addr;
+ flags |= LMB_FDT;
rsv_addr = (phys_addr_t)addr;
ret = lmb_alloc_mem(LMB_MEM_ALLOC_ADDR, 0, &rsv_addr, size, flags);
@@ -80,7 +81,7 @@ static void boot_fdt_reserve_region(u64 addr, u64 size, u32 flags)
debug(" reserving fdt memory region: addr=%llx size=%llx flags=%x\n",
(unsigned long long)addr,
(unsigned long long)size, flags);
- } else if (ret != -EEXIST && ret != -EINVAL) {
+ } else if (ret != -EINVAL) {
puts("ERROR: reserving fdt memory region failed ");
printf("(addr=%llx size=%llx flags=%x)\n",
(unsigned long long)addr,
@@ -108,6 +109,8 @@ void boot_fdt_add_mem_rsv_regions(void *fdt_blob)
if (fdt_check_header(fdt_blob) != 0)
return;
+ lmb_free_fdt_regions();
+
/* process memreserve sections */
total = fdt_num_mem_rsv(fdt_blob);
for (i = 0; i < total; i++) {
diff --git a/include/lmb.h b/include/lmb.h
index 5d5f037ccb9..1b59a63f61d 100644
--- a/include/lmb.h
+++ b/include/lmb.h
@@ -25,11 +25,13 @@
* %LMB_NOMAP: Don't add to MMU configuration
* %LMB_NOOVERWRITE: The memory region cannot be overwritten/re-reserved
* %LMB_NONOTIFY: Do not notify other modules of changes to this memory region
+ * %LMB_FDT: A FDT reserved region that can be reclaimed if the FDT changes
*/
#define LMB_NONE 0
#define LMB_NOMAP BIT(1)
#define LMB_NOOVERWRITE BIT(2)
#define LMB_NONOTIFY BIT(3)
+#define LMB_FDT BIT(4)
/**
* enum lmb_mem_type - type of memory allocation request
@@ -215,6 +217,11 @@ phys_addr_t io_lmb_alloc(struct lmb *io_lmb, phys_size_t size, ulong align);
*/
long io_lmb_free(struct lmb *io_lmb, phys_addr_t base, phys_size_t size);
+/**
+ * lmb_free_fdt_regions() - Reclaim all LMB_FDT tagged reserved regions
+ */
+void lmb_free_fdt_regions(void);
+
#endif /* __KERNEL__ */
#endif /* _LINUX_LMB_H */
diff --git a/lib/lmb.c b/lib/lmb.c
index e2d9fe86c14..542bb11dcf5 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -669,6 +669,29 @@ long lmb_free(phys_addr_t base, phys_size_t size, u32 flags)
return lmb_map_update_notify(base, size, LMB_MAP_OP_FREE, flags);
}
+void lmb_free_fdt_regions(void)
+{
+ struct alist *lmb_rgn_lst = &lmb.used_mem;
+ struct lmb_region *rgn = lmb_rgn_lst->data;
+ long ret;
+
+ for (int i = 0; i < lmb_rgn_lst->count; i++) {
+ phys_addr_t base = rgn[i].base;
+ phys_size_t size = rgn[i].size;
+ u32 flags = rgn[i].flags;
+
+ if (flags & LMB_FDT) {
+ ret = lmb_free(base, size, flags);
+ if (ret < 0) {
+ printf("Unable to free FDT memory at 0x%08lx",
+ (ulong)base);
+ continue;
+ }
+ i--;
+ }
+ }
+}
+
static int _lmb_alloc_base(phys_size_t size, ulong align,
phys_addr_t *addr, u32 flags)
{
--
2.53.0
next prev parent reply other threads:[~2026-04-02 0:15 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-02 0:14 [PATCH 0/6] various memory related fixups rs
2026-04-02 0:14 ` rs [this message]
2026-04-02 0:36 ` [PATCH 1/6] lmb: add LMB_FDT for fdt reserved regions Randolph Sapp
2026-04-02 0:14 ` [PATCH 2/6] efi_dt_fixup: use fdtdec_get_bool rs
2026-04-02 8:38 ` Ilias Apalodimas
2026-04-02 0:14 ` [PATCH 3/6] efi_selftest_memory: check for duplicates first rs
2026-04-02 0:14 ` [PATCH 4/6] efi_memory: nitpick removal loop rs
2026-04-02 9:04 ` Ilias Apalodimas
2026-04-02 17:39 ` Randolph Sapp
2026-04-02 19:02 ` Ilias Apalodimas
2026-04-02 19:21 ` Randolph Sapp
2026-04-02 0:14 ` [PATCH 5/6] efi_memory: backfill EFI_CONVENTIONAL_MEMORY rs
2026-04-02 8:53 ` Ilias Apalodimas
2026-04-02 17:32 ` Randolph Sapp
2026-04-02 19:58 ` Randolph Sapp
2026-04-03 5:28 ` Ilias Apalodimas
2026-04-04 0:08 ` Randolph Sapp
2026-04-02 0:14 ` [PATCH 6/6] memory: reserve from start_addr_sp to relocaddr rs
2026-04-02 9:21 ` Ilias Apalodimas
2026-04-02 19:15 ` Randolph Sapp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260402001410.3736815-2-rs@ti.com \
--to=rs@ti.com \
--cc=Erik.Welsh@octavosystems.com \
--cc=afd@ti.com \
--cc=anshuld@ti.com \
--cc=ayush@beagleboard.org \
--cc=bb@ti.com \
--cc=ilias.apalodimas@linaro.org \
--cc=robertcnelson@gmail.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox