* [PATCH 0/3] libfdt: A few more size improvements
@ 2025-12-09 21:50 Tom Rini
2025-12-09 21:50 ` [PATCH 1/3] libfdt: libfdt_internal.h correct final comment in ASSUME block Tom Rini
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Tom Rini @ 2025-12-09 21:50 UTC (permalink / raw)
To: devicetree-compiler
Hey all,
Over on the U-Boot list we're talking about re-syncing our copy of
libfdt with the Linux Kernel again (and so with upstream dtc)[1][2].
While we've worked out most of the size increase with the upgrade, there
are still a few places we can do more. This series is three patches. The
first patch fixes a comment from back when Simon was iterating on the
whole assume framework and one spot wasn't updated. The second patch
updates the FDT_RO_PROBE macro to optimize out quicker when we assume a
valid DTB and the third patch brings in one more assume check that
U-Boot has had for ages, but wasn't upstreamed. I did not see if there
was old discussion about it, but it's something U-Boot really needs.
The end result of this series, when applied on top of [2] and some other
fixes U-Boot itself needed is that our SPL size shrinks by 12 bytes on
aarch64 without LTO.
I've run a meson build and test cycle in dtc and everything continues to
pass. I've also thrown all of this through U-Boot and things are fine
there as well.
[1]: https://lore.kernel.org/u-boot/20251113122145.949112-1-marek.vasut+renesas@mailbox.org/
[2]: https://lore.kernel.org/u-boot/20251202193310.149861-1-marek.vasut+renesas@mailbox.org/
--
Tom
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 1/3] libfdt: libfdt_internal.h correct final comment in ASSUME block 2025-12-09 21:50 [PATCH 0/3] libfdt: A few more size improvements Tom Rini @ 2025-12-09 21:50 ` Tom Rini 2025-12-10 6:42 ` David Gibson 2025-12-09 21:50 ` [PATCH 2/3] libfdt: Improve size savings in FDT_RO_PROBE slightly Tom Rini 2025-12-09 21:50 ` [PATCH 3/3] libfdt: fdt_get_name: Add can_assume(VALID_DTB) check Tom Rini 2 siblings, 1 reply; 7+ messages in thread From: Tom Rini @ 2025-12-09 21:50 UTC (permalink / raw) To: devicetree-compiler The value "ASSUME_SANE" was never used in the project here, only ASSUME_PERFECT was used. Update the comment to reflect the correct name. Fixes: 464962489dcc ("Add a way to control the level of checks in the code") Signed-off-by: Tom Rini <trini@konsulko.com> --- libfdt/libfdt_internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfdt/libfdt_internal.h b/libfdt/libfdt_internal.h index b60b5456f596..9eb32394eb79 100644 --- a/libfdt/libfdt_internal.h +++ b/libfdt/libfdt_internal.h @@ -92,7 +92,7 @@ static inline uint64_t fdt64_ld_(const fdt64_t *p) * signature or hash check before using libfdt. * * For situations where security is not a concern it may be safe to enable - * ASSUME_SANE. + * ASSUME_PERFECT. */ enum { /* -- 2.43.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] libfdt: libfdt_internal.h correct final comment in ASSUME block 2025-12-09 21:50 ` [PATCH 1/3] libfdt: libfdt_internal.h correct final comment in ASSUME block Tom Rini @ 2025-12-10 6:42 ` David Gibson 0 siblings, 0 replies; 7+ messages in thread From: David Gibson @ 2025-12-10 6:42 UTC (permalink / raw) To: Tom Rini; +Cc: devicetree-compiler [-- Attachment #1: Type: text/plain, Size: 1139 bytes --] On Tue, Dec 09, 2025 at 03:50:51PM -0600, Tom Rini wrote: > The value "ASSUME_SANE" was never used in the project here, only > ASSUME_PERFECT was used. Update the comment to reflect the correct name. > > Fixes: 464962489dcc ("Add a way to control the level of checks in the code") > Signed-off-by: Tom Rini <trini@konsulko.com> Appplied, thanks. > --- > libfdt/libfdt_internal.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/libfdt/libfdt_internal.h b/libfdt/libfdt_internal.h > index b60b5456f596..9eb32394eb79 100644 > --- a/libfdt/libfdt_internal.h > +++ b/libfdt/libfdt_internal.h > @@ -92,7 +92,7 @@ static inline uint64_t fdt64_ld_(const fdt64_t *p) > * signature or hash check before using libfdt. > * > * For situations where security is not a concern it may be safe to enable > - * ASSUME_SANE. > + * ASSUME_PERFECT. > */ > enum { > /* > -- > 2.43.0 > > -- David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/3] libfdt: Improve size savings in FDT_RO_PROBE slightly 2025-12-09 21:50 [PATCH 0/3] libfdt: A few more size improvements Tom Rini 2025-12-09 21:50 ` [PATCH 1/3] libfdt: libfdt_internal.h correct final comment in ASSUME block Tom Rini @ 2025-12-09 21:50 ` Tom Rini 2025-12-10 6:46 ` David Gibson 2025-12-09 21:50 ` [PATCH 3/3] libfdt: fdt_get_name: Add can_assume(VALID_DTB) check Tom Rini 2 siblings, 1 reply; 7+ messages in thread From: Tom Rini @ 2025-12-09 21:50 UTC (permalink / raw) To: devicetree-compiler In the case where we have set FDT_ASSUME_MASK to disable ASSUME_VALID_DTB checks, we can improve the FDT_RO_PROBE macro slightly. The first thing that fdt_ro_probe_() does when we can_assume(VALID_DTB) is true is to return whatever the contents of the totalsize field of the DTB is. Since the FDT_RO_PROBE macro only cares about a negative value there, we can optimize this check such that we are to assume it's a valid DTB, we don't need to do anything here. Signed-off-by: Tom Rini <trini@konsulko.com> --- In the case of U-Boot SPL (and similar very early stages) we are extremely concerned with binary size, and also assume the device tree is valid. This patch here is not a huge savings for us, but every little bit helps when talking about something that impacts more than half our build configurations. --- libfdt/libfdt_internal.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libfdt/libfdt_internal.h b/libfdt/libfdt_internal.h index 9eb32394eb79..0e103cafa714 100644 --- a/libfdt/libfdt_internal.h +++ b/libfdt/libfdt_internal.h @@ -11,11 +11,13 @@ #define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) int32_t fdt_ro_probe_(const void *fdt); -#define FDT_RO_PROBE(fdt) \ - { \ - int32_t totalsize_; \ - if ((totalsize_ = fdt_ro_probe_(fdt)) < 0) \ - return totalsize_; \ +#define FDT_RO_PROBE(fdt) \ + { \ + if (!can_assume(VALID_DTB)) { \ + int32_t totalsize_; \ + if ((totalsize_ = fdt_ro_probe_(fdt)) < 0) \ + return totalsize_; \ + } \ } int fdt_check_node_offset_(const void *fdt, int offset); -- 2.43.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/3] libfdt: Improve size savings in FDT_RO_PROBE slightly 2025-12-09 21:50 ` [PATCH 2/3] libfdt: Improve size savings in FDT_RO_PROBE slightly Tom Rini @ 2025-12-10 6:46 ` David Gibson 0 siblings, 0 replies; 7+ messages in thread From: David Gibson @ 2025-12-10 6:46 UTC (permalink / raw) To: Tom Rini; +Cc: devicetree-compiler [-- Attachment #1: Type: text/plain, Size: 2041 bytes --] On Tue, Dec 09, 2025 at 03:50:52PM -0600, Tom Rini wrote: > In the case where we have set FDT_ASSUME_MASK to disable > ASSUME_VALID_DTB checks, we can improve the FDT_RO_PROBE macro slightly. > The first thing that fdt_ro_probe_() does when we can_assume(VALID_DTB) > is true is to return whatever the contents of the totalsize field of the > DTB is. Since the FDT_RO_PROBE macro only cares about a negative value > there, we can optimize this check such that we are to assume it's a > valid DTB, we don't need to do anything here. > > Signed-off-by: Tom Rini <trini@konsulko.com> Applied, thanks. > --- > In the case of U-Boot SPL (and similar very early stages) we are > extremely concerned with binary size, and also assume the device tree is > valid. This patch here is not a huge savings for us, but every little > bit helps when talking about something that impacts more than half our > build configurations. > --- > libfdt/libfdt_internal.h | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) > > diff --git a/libfdt/libfdt_internal.h b/libfdt/libfdt_internal.h > index 9eb32394eb79..0e103cafa714 100644 > --- a/libfdt/libfdt_internal.h > +++ b/libfdt/libfdt_internal.h > @@ -11,11 +11,13 @@ > #define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) > > int32_t fdt_ro_probe_(const void *fdt); > -#define FDT_RO_PROBE(fdt) \ > - { \ > - int32_t totalsize_; \ > - if ((totalsize_ = fdt_ro_probe_(fdt)) < 0) \ > - return totalsize_; \ > +#define FDT_RO_PROBE(fdt) \ > + { \ > + if (!can_assume(VALID_DTB)) { \ > + int32_t totalsize_; \ > + if ((totalsize_ = fdt_ro_probe_(fdt)) < 0) \ > + return totalsize_; \ > + } \ > } > > int fdt_check_node_offset_(const void *fdt, int offset); > -- > 2.43.0 > > -- David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/3] libfdt: fdt_get_name: Add can_assume(VALID_DTB) check 2025-12-09 21:50 [PATCH 0/3] libfdt: A few more size improvements Tom Rini 2025-12-09 21:50 ` [PATCH 1/3] libfdt: libfdt_internal.h correct final comment in ASSUME block Tom Rini 2025-12-09 21:50 ` [PATCH 2/3] libfdt: Improve size savings in FDT_RO_PROBE slightly Tom Rini @ 2025-12-09 21:50 ` Tom Rini 2025-12-10 6:47 ` David Gibson 2 siblings, 1 reply; 7+ messages in thread From: Tom Rini @ 2025-12-09 21:50 UTC (permalink / raw) To: devicetree-compiler In this function from fdt_ro.c we have (reasonably) some checks of the DTB before we begin work. However, we do this in a way that we cannot make use of the normal FDT_RO_PROBE macro and instead have a direct call to fdt_ro_probe_(). Add a test for !can_assume(VALID_DTB) here first so that in cases where we are assuming a valid DTB we can omit the checks. Signed-off-by: Tom Rini <trini@konsulko.com> --- This is another case which we see in U-Boot SPL, and for the last 6 years now have had the equivalent check. This change ends up being a noticeable size win for us. --- libfdt/fdt_ro.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c index b78c4e48f1cb..63494fb7ad90 100644 --- a/libfdt/fdt_ro.c +++ b/libfdt/fdt_ro.c @@ -306,8 +306,8 @@ const char *fdt_get_name(const void *fdt, int nodeoffset, int *len) const char *nameptr; int err; - if (((err = fdt_ro_probe_(fdt)) < 0) - || ((err = fdt_check_node_offset_(fdt, nodeoffset)) < 0)) + if (!can_assume(VALID_DTB) && (((err = fdt_ro_probe_(fdt)) < 0) + || ((err = fdt_check_node_offset_(fdt, nodeoffset)) < 0))) goto fail; nameptr = nh->name; -- 2.43.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] libfdt: fdt_get_name: Add can_assume(VALID_DTB) check 2025-12-09 21:50 ` [PATCH 3/3] libfdt: fdt_get_name: Add can_assume(VALID_DTB) check Tom Rini @ 2025-12-10 6:47 ` David Gibson 0 siblings, 0 replies; 7+ messages in thread From: David Gibson @ 2025-12-10 6:47 UTC (permalink / raw) To: Tom Rini; +Cc: devicetree-compiler [-- Attachment #1: Type: text/plain, Size: 1596 bytes --] On Tue, Dec 09, 2025 at 03:50:53PM -0600, Tom Rini wrote: 11;rgb:ffff/ffff/ffff> In this function from fdt_ro.c we have (reasonably) some checks of the > DTB before we begin work. However, we do this in a way that we cannot > make use of the normal FDT_RO_PROBE macro and instead have a direct call > to fdt_ro_probe_(). Add a test for !can_assume(VALID_DTB) here first so > that in cases where we are assuming a valid DTB we can omit the checks. > > Signed-off-by: Tom Rini <trini@konsulko.com> Applied, thanks. > --- > This is another case which we see in U-Boot SPL, and for the last 6 > years now have had the equivalent check. This change ends up being a > noticeable size win for us. > --- > libfdt/fdt_ro.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c > index b78c4e48f1cb..63494fb7ad90 100644 > --- a/libfdt/fdt_ro.c > +++ b/libfdt/fdt_ro.c > @@ -306,8 +306,8 @@ const char *fdt_get_name(const void *fdt, int nodeoffset, int *len) > const char *nameptr; > int err; > > - if (((err = fdt_ro_probe_(fdt)) < 0) > - || ((err = fdt_check_node_offset_(fdt, nodeoffset)) < 0)) > + if (!can_assume(VALID_DTB) && (((err = fdt_ro_probe_(fdt)) < 0) > + || ((err = fdt_check_node_offset_(fdt, nodeoffset)) < 0))) > goto fail; > > nameptr = nh->name; > -- > 2.43.0 > > -- David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-12-10 6:50 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-12-09 21:50 [PATCH 0/3] libfdt: A few more size improvements Tom Rini 2025-12-09 21:50 ` [PATCH 1/3] libfdt: libfdt_internal.h correct final comment in ASSUME block Tom Rini 2025-12-10 6:42 ` David Gibson 2025-12-09 21:50 ` [PATCH 2/3] libfdt: Improve size savings in FDT_RO_PROBE slightly Tom Rini 2025-12-10 6:46 ` David Gibson 2025-12-09 21:50 ` [PATCH 3/3] libfdt: fdt_get_name: Add can_assume(VALID_DTB) check Tom Rini 2025-12-10 6:47 ` David Gibson
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).