libfdt: fdt_check_full: Add can_assume(PERFECT) check
PATCH 1/1 libfdt: fdt_check_full: Add can_assume(PERFECT) check
In this function from fdt_check.c we have (reasonably and as the name implies) a number of checks on the DTB. However, there are cases where we may wish to assume that we have been given a perfect DTB already and do nothing here. Add a test for can_assume(PERFECT) as the first check in this function and if true, perform no checks.
---
Along the lines of the patches I posted back in December, in U-Boot SPL we just don't have the space for this check much of the time and so have always omitted it (going back to at least when Simon posted the initial patch to make libfdt/fdt_check.c here). This is another case where it's a noticeable size win for us. I had missed this change in particular because we had in turn missed catching up on fdt_check_full being moved out of fdt_ro.c and in to fdt_check.c.
--- libfdt/fdt_check.c | 2 ++ 1 file changed, 2 insertions(+)
libfdt/fdt_check.c +2 -0
@@ -21,6 +21,8 @@ int fdt_check_full(const void *fdt, size_t bufsize)const char *propname;bool expect_end = false; +if (can_assume (PERFECT )) +return 0 ;if (bufsize <FDT_V1_SIZE )return -FDT_ERR_TRUNCATED ;if (bufsize <fdt_header_size (fdt))
Signature · 1 line
2.43.0
Quoted 7 lines · Tom Rini
In this function from
fdt_check.cwe have (reasonably and as the name implies) a number of checks on the DTB. However, there are cases where we may wish to assume that we have been given a perfect DTB already and do nothing here. Add a test forcan_assume(PERFECT)as the first check in this function and if true, perform no checks.Signed-off-by Tom Rini <[email protected]>
Quoted 8 lines
---
Along the lines of the patches I posted back in December, in U-Boot SPL we just don't have the space for this check much of the time and so have always omitted it (going back to at least when Simon posted the initial patch to makelibfdt/fdt_check.chere). This is another case where it's a noticeable size win for us. I had missed this change in particular because we had in turn missed catching up onfdt_check_fullbeing moved out offdt_ro.cand in tofdt_check.c.
I'm not necessarily against this, but I have some misgivings.
fdt_check_full() is (deliberately) not called from anywhere else in libfdt - it's intended to allow the user to explicitly do a full validity check on the tree. Given that meaning, I'm not sure it's wise to turn it into a no-op based on the assume flags.
Your comment seems to imply that the issue here is size - simply having this function compiled - rather than being too expensive when (explicitly) called. That's a little surprising to me - it's in its own compilation unit, specifically so that the linker can omit it if it's not used. Is there something unusual about your build environment that's not letting that happen?
Quoted 21 lines
--- libfdt/fdt_check.c | 2 ++ 1 file changed, 2 insertions(+)libfdt/fdt_check.c +2
-0@@ -21,6 +21,8 @@ int fdt_check_full(const void *fdt, size_t bufsize)const char *propname;bool expect_end = false; +if (can_assume (PERFECT )) +return 0 ;if (bufsize <FDT_V1_SIZE )return -FDT_ERR_TRUNCATED ;if (bufsize <fdt_header_size (fdt))Signature · 1 line
2.43.0
Signature · 4 lines
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
Quoted 24 lines · David Gibson
Quoted 7 lines · Tom Rini
In this function from
fdt_check.cwe have (reasonably and as the name implies) a number of checks on the DTB. However, there are cases where we may wish to assume that we have been given a perfect DTB already and do nothing here. Add a test forcan_assume(PERFECT)as the first check in this function and if true, perform no checks.Signed-off-by Tom Rini <[email protected]>Quoted 8 lines
---
Along the lines of the patches I posted back in December, in U-Boot SPL we just don't have the space for this check much of the time and so have always omitted it (going back to at least when Simon posted the initial patch to makelibfdt/fdt_check.chere). This is another case where it's a noticeable size win for us. I had missed this change in particular because we had in turn missed catching up onfdt_check_fullbeing moved out offdt_ro.cand in tofdt_check.c.I'm not necessarily against this, but I have some misgivings.
fdt_check_full()is (deliberately) not called from anywhere else in libfdt - it's intended to allow the user to explicitly do a full validity check on the tree. Given that meaning, I'm not sure it's wise to turn it into a no-op based on the assume flags.
Quoted 6 lines
Your comment seems to imply that the issue here is size - simply having this function compiled - rather than being too expensive when (explicitly) called. That's a little surprising to me - it's in its own compilation unit, specifically so that the linker can omit it if it's not used. Is there something unusual about your build environment that's not letting that happen?
So, we have code like this:
/* Get the total space reserved for FDT in blob */
live_fdt = bloblist_get_blob(BLOBLISTT_CONTROL_FDT, &blob_size);
if (live_fdt != gd->fdt_blob)
return -ENOENT;
ret = fdt_check_full(live_fdt, blob_size);
if (ret)
return fdtdec_ret_to_errno(ret);And this is compiled on TPL, SPL and full U-Boot builds. On the first two, we're just too space constrained to do this check. So it's not the linker doing the right thing or not, it's avoiding having to #if the code directly (or rather, CONFIG_VAL(...)). My line of thinking was that since ASSUME_PERFECT is that everything is really perfect, this is the way to go. Yes, it's a little odd to have both "call the validation function" and "the validation function does not validate" but that's just because in the second case, we explicitly configured ourself to not validate anything.
And FWIW, that's really how we use the assume mask in U-Boot, either 0xff or 0x0. It's a case where we're either passing along the tree we bundled with ourself (and so we can assume it's fine) or it's passed along (and we verify).
Signature · 1 line
Tom
Quoted 52 lines · Tom Rini
Quoted 24 lines · David Gibson
Quoted 7 lines · Tom Rini
In this function from
fdt_check.cwe have (reasonably and as the name implies) a number of checks on the DTB. However, there are cases where we may wish to assume that we have been given a perfect DTB already and do nothing here. Add a test forcan_assume(PERFECT)as the first check in this function and if true, perform no checks.Signed-off-by Tom Rini <[email protected]>Quoted 8 lines
---
Along the lines of the patches I posted back in December, in U-Boot SPL we just don't have the space for this check much of the time and so have always omitted it (going back to at least when Simon posted the initial patch to makelibfdt/fdt_check.chere). This is another case where it's a noticeable size win for us. I had missed this change in particular because we had in turn missed catching up onfdt_check_fullbeing moved out offdt_ro.cand in tofdt_check.c.I'm not necessarily against this, but I have some misgivings.
fdt_check_full()is (deliberately) not called from anywhere else in libfdt - it's intended to allow the user to explicitly do a full validity check on the tree. Given that meaning, I'm not sure it's wise to turn it into a no-op based on the assume flags.Quoted 6 lines
Your comment seems to imply that the issue here is size - simply having this function compiled - rather than being too expensive when (explicitly) called. That's a little surprising to me - it's in its own compilation unit, specifically so that the linker can omit it if it's not used. Is there something unusual about your build environment that's not letting that happen?
So, we have code like this:
/* Get the total space reserved for FDT in blob */ live_fdt = bloblist_get_blob(BLOBLISTT_CONTROL_FDT, &blob_size); if (live_fdt != gd->fdt_blob) return -ENOENT; ret = fdt_check_full(live_fdt, blob_size); if (ret) return fdtdec_ret_to_errno(ret);And this is compiled on TPL, SPL and full U-Boot builds. On the first two, we're just too space constrained to do this check. So it's not the linker doing the right thing or not, it's avoiding having to #if the code directly (or rather,
CONFIG_VAL(...)). My line of thinking was that sinceASSUME_PERFECTis that everything is really perfect, this is the way to go. Yes, it's a little odd to have both "call the validation function" and "the validation function does not validate" but that's just because in the second case, we explicitly configured ourself to not validate anything.
Quoted 4 lines
And FWIW, that's really how we use the assume mask in U-Boot, either
0xffor0x0. It's a case where we're either passing along the tree we bundled with ourself (and so we can assume it's fine) or it's passed along (and we verify).
Hey, just checking if there's any further discussion here? I want to try and get the delta between U-Boot and upstream down to zero if we can. Thanks!
Signature · 1 line
Tom
Quoted 53 lines · Tom Rini
Quoted 52 lines · Tom Rini
Quoted 24 lines · David Gibson
Quoted 7 lines · Tom Rini
In this function from
fdt_check.cwe have (reasonably and as the name implies) a number of checks on the DTB. However, there are cases where we may wish to assume that we have been given a perfect DTB already and do nothing here. Add a test forcan_assume(PERFECT)as the first check in this function and if true, perform no checks.Signed-off-by Tom Rini <[email protected]>Quoted 8 lines
---
Along the lines of the patches I posted back in December, in U-Boot SPL we just don't have the space for this check much of the time and so have always omitted it (going back to at least when Simon posted the initial patch to makelibfdt/fdt_check.chere). This is another case where it's a noticeable size win for us. I had missed this change in particular because we had in turn missed catching up onfdt_check_fullbeing moved out offdt_ro.cand in tofdt_check.c.I'm not necessarily against this, but I have some misgivings.
fdt_check_full()is (deliberately) not called from anywhere else in libfdt - it's intended to allow the user to explicitly do a full validity check on the tree. Given that meaning, I'm not sure it's wise to turn it into a no-op based on the assume flags.Quoted 6 lines
Your comment seems to imply that the issue here is size - simply having this function compiled - rather than being too expensive when (explicitly) called. That's a little surprising to me - it's in its own compilation unit, specifically so that the linker can omit it if it's not used. Is there something unusual about your build environment that's not letting that happen?
So, we have code like this:
/* Get the total space reserved for FDT in blob */ live_fdt = bloblist_get_blob(BLOBLISTT_CONTROL_FDT, &blob_size); if (live_fdt != gd->fdt_blob) return -ENOENT; ret = fdt_check_full(live_fdt, blob_size); if (ret) return fdtdec_ret_to_errno(ret);And this is compiled on TPL, SPL and full U-Boot builds. On the first two, we're just too space constrained to do this check. So it's not the linker doing the right thing or not, it's avoiding having to #if the code directly (or rather,
CONFIG_VAL(...)). My line of thinking was that sinceASSUME_PERFECTis that everything is really perfect, this is the way to go. Yes, it's a little odd to have both "call the validation function" and "the validation function does not validate" but that's just because in the second case, we explicitly configured ourself to not validate anything.
Quoted 8 lines
Quoted 4 lines
And FWIW, that's really how we use the assume mask in U-Boot, either
0xffor0x0. It's a case where we're either passing along the tree we bundled with ourself (and so we can assume it's fine) or it's passed along (and we verify).Hey, just checking if there's any further discussion here? I want to try and get the delta between U-Boot and upstream down to zero if we can. Thanks!
Checking in again for more feedback here as I'm going to take this for U-Boot shortly otherwise, and then I guess revisit when there's a later conflict most likely.
Signature · 1 line
Tom
Quoted 53 lines · Tom Rini
Quoted 52 lines · Tom Rini
Quoted 24 lines · David Gibson
Quoted 7 lines · Tom Rini
In this function from
fdt_check.cwe have (reasonably and as the name implies) a number of checks on the DTB. However, there are cases where we may wish to assume that we have been given a perfect DTB already and do nothing here. Add a test forcan_assume(PERFECT)as the first check in this function and if true, perform no checks.Signed-off-by Tom Rini <[email protected]>Quoted 8 lines
---
Along the lines of the patches I posted back in December, in U-Boot SPL we just don't have the space for this check much of the time and so have always omitted it (going back to at least when Simon posted the initial patch to makelibfdt/fdt_check.chere). This is another case where it's a noticeable size win for us. I had missed this change in particular because we had in turn missed catching up onfdt_check_fullbeing moved out offdt_ro.cand in tofdt_check.c.I'm not necessarily against this, but I have some misgivings.
fdt_check_full()is (deliberately) not called from anywhere else in libfdt - it's intended to allow the user to explicitly do a full validity check on the tree. Given that meaning, I'm not sure it's wise to turn it into a no-op based on the assume flags.Quoted 6 lines
Your comment seems to imply that the issue here is size - simply having this function compiled - rather than being too expensive when (explicitly) called. That's a little surprising to me - it's in its own compilation unit, specifically so that the linker can omit it if it's not used. Is there something unusual about your build environment that's not letting that happen?
So, we have code like this:
/* Get the total space reserved for FDT in blob */ live_fdt = bloblist_get_blob(BLOBLISTT_CONTROL_FDT, &blob_size); if (live_fdt != gd->fdt_blob) return -ENOENT; ret = fdt_check_full(live_fdt, blob_size); if (ret) return fdtdec_ret_to_errno(ret);And this is compiled on TPL, SPL and full U-Boot builds. On the first two, we're just too space constrained to do this check. So it's not the linker doing the right thing or not, it's avoiding having to #if the code directly (or rather,
CONFIG_VAL(...)). My line of thinking was that sinceASSUME_PERFECTis that everything is really perfect, this is the way to go. Yes, it's a little odd to have both "call the validation function" and "the validation function does not validate" but that's just because in the second case, we explicitly configured ourself to not validate anything.
Quoted 7 lines
Quoted 4 lines
And FWIW, that's really how we use the assume mask in U-Boot, either
0xffor0x0. It's a case where we're either passing along the tree we bundled with ourself (and so we can assume it's fine) or it's passed along (and we verify).Hey, just checking if there's any further discussion here? I want to try and get the delta between U-Boot and upstream down to zero if we can.
No further discussion, I just have approximately zero time for dtc maintenance :(.
Signature · 4 lines
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
Quoted 59 lines · David Gibson
Quoted 58 lines · Tom Rini
Quoted 56 lines · Tom Rini
Quoted 24 lines · David Gibson
Quoted 7 lines · Tom Rini
In this function from
fdt_check.cwe have (reasonably and as the name implies) a number of checks on the DTB. However, there are cases where we may wish to assume that we have been given a perfect DTB already and do nothing here. Add a test forcan_assume(PERFECT)as the first check in this function and if true, perform no checks.Signed-off-by Tom Rini <[email protected]>Quoted 8 lines
---
Along the lines of the patches I posted back in December, in U-Boot SPL we just don't have the space for this check much of the time and so have always omitted it (going back to at least when Simon posted the initial patch to makelibfdt/fdt_check.chere). This is another case where it's a noticeable size win for us. I had missed this change in particular because we had in turn missed catching up onfdt_check_fullbeing moved out offdt_ro.cand in tofdt_check.c.I'm not necessarily against this, but I have some misgivings.
fdt_check_full()is (deliberately) not called from anywhere else in libfdt - it's intended to allow the user to explicitly do a full validity check on the tree. Given that meaning, I'm not sure it's wise to turn it into a no-op based on the assume flags.Quoted 6 lines
Your comment seems to imply that the issue here is size - simply having this function compiled - rather than being too expensive when (explicitly) called. That's a little surprising to me - it's in its own compilation unit, specifically so that the linker can omit it if it's not used. Is there something unusual about your build environment that's not letting that happen?
So, we have code like this:
/* Get the total space reserved for FDT in blob */ live_fdt = bloblist_get_blob(BLOBLISTT_CONTROL_FDT, &blob_size); if (live_fdt != gd->fdt_blob) return -ENOENT; ret = fdt_check_full(live_fdt, blob_size); if (ret) return fdtdec_ret_to_errno(ret);And this is compiled on TPL, SPL and full U-Boot builds. On the first two, we're just too space constrained to do this check. So it's not the linker doing the right thing or not, it's avoiding having to #if the code directly (or rather,
CONFIG_VAL(...)). My line of thinking was that sinceASSUME_PERFECTis that everything is really perfect, this is the way to go. Yes, it's a little odd to have both "call the validation function" and "the validation function does not validate" but that's just because in the second case, we explicitly configured ourself to not validate anything.And FWIW, that's really how we use the assume mask in U-Boot, either
0xffor0x0. It's a case where we're either passing along the tree we bundled with ourself (and so we can assume it's fine) or it's passed along (and we verify).
Quoted 5 lines
Quoted 2 lines
Hey, just checking if there's any further discussion here? I want to try and get the delta between U-Boot and upstream down to zero if we can.
No further discussion, I just have approximately zero time for dtc maintenance :(.
Ah, I understand. Thanks for merging!
Signature · 1 line
Tom
Quoted 42 lines · Tom Rini
Quoted 24 lines · David Gibson
Quoted 7 lines · Tom Rini
In this function from
fdt_check.cwe have (reasonably and as the name implies) a number of checks on the DTB. However, there are cases where we may wish to assume that we have been given a perfect DTB already and do nothing here. Add a test forcan_assume(PERFECT)as the first check in this function and if true, perform no checks.Signed-off-by Tom Rini <[email protected]>Quoted 8 lines
---
Along the lines of the patches I posted back in December, in U-Boot SPL we just don't have the space for this check much of the time and so have always omitted it (going back to at least when Simon posted the initial patch to makelibfdt/fdt_check.chere). This is another case where it's a noticeable size win for us. I had missed this change in particular because we had in turn missed catching up onfdt_check_fullbeing moved out offdt_ro.cand in tofdt_check.c.I'm not necessarily against this, but I have some misgivings.
fdt_check_full()is (deliberately) not called from anywhere else in libfdt - it's intended to allow the user to explicitly do a full validity check on the tree. Given that meaning, I'm not sure it's wise to turn it into a no-op based on the assume flags.Quoted 6 lines
Your comment seems to imply that the issue here is size - simply having this function compiled - rather than being too expensive when (explicitly) called. That's a little surprising to me - it's in its own compilation unit, specifically so that the linker can omit it if it's not used. Is there something unusual about your build environment that's not letting that happen?
So, we have code like this:
/* Get the total space reserved for FDT in blob */ live_fdt = bloblist_get_blob(BLOBLISTT_CONTROL_FDT, &blob_size); if (live_fdt != gd->fdt_blob) return -ENOENT; ret = fdt_check_full(live_fdt, blob_size); if (ret) return fdtdec_ret_to_errno(ret);
Quoted 9 lines
And this is compiled on TPL, SPL and full U-Boot builds. On the first two, we're just too space constrained to do this check. So it's not the linker doing the right thing or not, it's avoiding having to #if the code directly (or rather,
CONFIG_VAL(...)). My line of thinking was that sinceASSUME_PERFECTis that everything is really perfect, this is the way to go. Yes, it's a little odd to have both "call the validation function" and "the validation function does not validate" but that's just because in the second case, we explicitly configured ourself to not validate anything.
Ok, convincing enough. Merged.
Quoted 4 lines
And FWIW, that's really how we use the assume mask in U-Boot, either
0xffor0x0. It's a case where we're either passing along the tree we bundled with ourself (and so we can assume it's fine) or it's passed along (and we verify).
Signature · 4 lines
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
Quoted 16 lines · Tom Rini
In this function from
fdt_check.cwe have (reasonably and as the name implies) a number of checks on the DTB. However, there are cases where we may wish to assume that we have been given a perfect DTB already and do nothing here. Add a test forcan_assume(PERFECT)as the first check in this function and if true, perform no checks.Signed-off-by Tom Rini <[email protected]>---
Along the lines of the patches I posted back in December, in U-Boot SPL we just don't have the space for this check much of the time and so have always omitted it (going back to at least when Simon posted the initial patch to makelibfdt/fdt_check.chere). This is another case where it's a noticeable size win for us. I had missed this change in particular because we had in turn missed catching up onfdt_check_fullbeing moved out offdt_ro.cand in tofdt_check.c.
Quoted 3 lines
--- libfdt/fdt_check.c | 2 ++ 1 file changed, 2 insertions(+)
This does honour the flags so...
Quoted 18 lines
libfdt/fdt_check.c +2
-1@@ -21,6 +21,8 @@ int fdt_check_full(const void *fdt, size_t bufsize)const char *propname;bool expect_end = false; +if (can_assume (PERFECT )) +return 0 ;if (bufsize <FDT_V1_SIZE )return -FDT_ERR_TRUNCATED ;if (bufsize <fdt_header_size (fdt)) --2.43.0