From: Chen Pei <cp0613@linux.alibaba.com>
To: opensbi@lists.infradead.org
Cc: anup@brainfault.org, guoren@kernel.org,
Chen Pei <cp0613@linux.alibaba.com>
Subject: [PATCH] lib/utils/fdt: Reserve enough FDT space for fdt_cpu_fixup
Date: Fri, 12 Jun 2026 15:55:01 +0800 [thread overview]
Message-ID: <20260612075502.76324-1-cp0613@linux.alibaba.com> (raw)
The fdt_cpu_fixup() function uses a hardcoded +32 bytes reservation
when calling fdt_open_into() to make room for disabling HART DT nodes
and appending the "zicntr" isa-extension. This is insufficient on
systems where many HARTs are disabled: each disabled HART needs 4
bytes ("okay" -> "disabled"), and each zicntr append needs ~16 bytes.
With the current limit only ~8 HARTs can be disabled before
FDT_ERR_NOSPACE (-3) is returned.
Replace the hardcoded reservation with a dynamic calculation based on
SBI_HARTMASK_MAX_BITS, which defines the maximum number of HARTs
OpenSBI supports. Each HART may need up to ~20 bytes in the worst
case, so reserve SBI_HARTMASK_MAX_BITS * 20 bytes.
Also remove the now-redundant per-HART fdt_open_into() call inside
the zicntr loop since the single upfront reservation is sufficient.
Fixes: dd9439fbace2 ("lib: utils: Add a fdt_cpu_fixup() helper")
Signed-off-by: Chen Pei <cp0613@linux.alibaba.com>
---
lib/utils/fdt/fdt_fixup.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/lib/utils/fdt/fdt_fixup.c b/lib/utils/fdt/fdt_fixup.c
index b0ed20c8..bace2277 100644
--- a/lib/utils/fdt/fdt_fixup.c
+++ b/lib/utils/fdt/fdt_fixup.c
@@ -124,7 +124,13 @@ void fdt_cpu_fixup(void *fdt)
sbi_hart_has_csr(scratch, SBI_HART_CSR_CYCLE) &&
sbi_hart_has_csr(scratch, SBI_HART_CSR_INSTRET);
- err = fdt_open_into(fdt, fdt, fdt_totalsize(fdt) + 32);
+ /*
+ * Reserve enough FDT space for the worst case:
+ * - Each disabled hart: 4 bytes ("okay" -> "disabled")
+ * - Each zicntr append: ~16 bytes (property + string)
+ */
+ err = fdt_open_into(fdt, fdt, fdt_totalsize(fdt) +
+ SBI_HARTMASK_MAX_BITS * 20);
if (err < 0)
return;
@@ -163,14 +169,9 @@ void fdt_cpu_fixup(void *fdt)
* property if there hasn't been already one.
*/
if (extensions &&
- !fdt_stringlist_contains(extensions, len, "zicntr")) {
- err = fdt_open_into(fdt, fdt, fdt_totalsize(fdt) + 16);
- if (err)
- continue;
-
+ !fdt_stringlist_contains(extensions, len, "zicntr"))
fdt_appendprop_string(fdt, cpu_offset,
"riscv,isa-extensions", "zicntr");
- }
}
}
--
2.50.1
--
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
reply other threads:[~2026-06-12 7:55 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260612075502.76324-1-cp0613@linux.alibaba.com \
--to=cp0613@linux.alibaba.com \
--cc=anup@brainfault.org \
--cc=guoren@kernel.org \
--cc=opensbi@lists.infradead.org \
/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