devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of/fdt: memblock_reserve /memreserve/ regions in the case of partial overlap
@ 2014-11-25 12:54 Ian Campbell
       [not found] ` <1416920095-31999-1-git-send-email-ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Ian Campbell @ 2014-11-25 12:54 UTC (permalink / raw)
  To: devicetree-u79uwXL29TY76Z2rM5mHXA; +Cc: Ian Campbell, Grant Likely, Rob Herring

memblock_is_region_reserved() returns true in the case of a partial
overlap, meaning that the current code fails to reserve the
non-overlapping portion.

I observed this causing a Midway system with a buggy fdt (the header
declares itself to be larger than it really is) failing to boot
because the over-inflated size of the fdt was causing it to seem to
run into the swapper_pg_dir region, meaning the DT wasn't reserved.
The symptoms were failing to find an disks or network and failing to
boot. I think it is work printing a warning in this case.

However given the ambiguity of whether things like the initrd are
covered by /memreserve/ and similar I think it is best to also
register the region rather than just ignoring it.

Since memblock_reserve() handles overlaps just fine lets just warn and
carry on.

Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>
Cc: Grant Likely <grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Cc: Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
---
 drivers/of/fdt.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 30e97bc..4f0f24c 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -965,7 +965,8 @@ int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base,
 					phys_addr_t size, bool nomap)
 {
 	if (memblock_is_region_reserved(base, size))
-		return -EBUSY;
+		pr_warning("DT reserved region at 0x%pa is already reserved\n",
+			   &base);
 	if (nomap)
 		return memblock_remove(base, size);
 	return memblock_reserve(base, size);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] of/fdt: memblock_reserve /memreserve/ regions in the case of partial overlap
       [not found] ` <1416920095-31999-1-git-send-email-ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>
@ 2014-11-25 14:37   ` Grant Likely
       [not found]     ` <20141125143750.1BAAAC44343-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Grant Likely @ 2014-11-25 14:37 UTC (permalink / raw)
  To: devicetree-u79uwXL29TY76Z2rM5mHXA; +Cc: Ian Campbell, Rob Herring

On Tue, 25 Nov 2014 12:54:55 +0000
, Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>
 wrote:
> memblock_is_region_reserved() returns true in the case of a partial
> overlap, meaning that the current code fails to reserve the
> non-overlapping portion.
> 
> I observed this causing a Midway system with a buggy fdt (the header
> declares itself to be larger than it really is) failing to boot
> because the over-inflated size of the fdt was causing it to seem to
> run into the swapper_pg_dir region, meaning the DT wasn't reserved.
> The symptoms were failing to find an disks or network and failing to
> boot. I think it is work printing a warning in this case.
> 
> However given the ambiguity of whether things like the initrd are
> covered by /memreserve/ and similar I think it is best to also
> register the region rather than just ignoring it.
> 
> Since memblock_reserve() handles overlaps just fine lets just warn and
> carry on.
> 
> Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>
> Cc: Grant Likely <grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> Cc: Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> ---
>  drivers/of/fdt.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index 30e97bc..4f0f24c 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -965,7 +965,8 @@ int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base,
>  					phys_addr_t size, bool nomap)
>  {
>  	if (memblock_is_region_reserved(base, size))
> -		return -EBUSY;
> +		pr_warning("DT reserved region at 0x%pa is already reserved\n",
> +			   &base);

Since memblock_remove/reserve does the right thing anyway, let's just
drop the test entirely.

g.

>  	if (nomap)
>  		return memblock_remove(base, size);
>  	return memblock_reserve(base, size);
> -- 
> 1.7.10.4
> 

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] of/fdt: memblock_reserve /memreserve/ regions in the case of partial overlap
       [not found]     ` <20141125143750.1BAAAC44343-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
@ 2014-11-25 19:31       ` Rob Herring
       [not found]         ` <CAL_JsqJV6e2oO7uJEUHzep8QAA1YztTgdaUNynKVnr_ABv+-nQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Rob Herring @ 2014-11-25 19:31 UTC (permalink / raw)
  To: Grant Likely
  Cc: Ian Campbell, devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Rob Herring

On Tue, Nov 25, 2014 at 8:37 AM, Grant Likely <grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> wrote:
> On Tue, 25 Nov 2014 12:54:55 +0000
> , Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>
>  wrote:
>> memblock_is_region_reserved() returns true in the case of a partial
>> overlap, meaning that the current code fails to reserve the
>> non-overlapping portion.
>>
>> I observed this causing a Midway system with a buggy fdt (the header
>> declares itself to be larger than it really is) failing to boot
>> because the over-inflated size of the fdt was causing it to seem to
>> run into the swapper_pg_dir region, meaning the DT wasn't reserved.
>> The symptoms were failing to find an disks or network and failing to
>> boot. I think it is work printing a warning in this case.
>>
>> However given the ambiguity of whether things like the initrd are
>> covered by /memreserve/ and similar I think it is best to also
>> register the region rather than just ignoring it.
>>
>> Since memblock_reserve() handles overlaps just fine lets just warn and
>> carry on.
>>
>> Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>
>> Cc: Grant Likely <grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
>> Cc: Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
>> Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
>> ---
>>  drivers/of/fdt.c |    3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
>> index 30e97bc..4f0f24c 100644
>> --- a/drivers/of/fdt.c
>> +++ b/drivers/of/fdt.c
>> @@ -965,7 +965,8 @@ int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base,
>>                                       phys_addr_t size, bool nomap)
>>  {
>>       if (memblock_is_region_reserved(base, size))
>> -             return -EBUSY;
>> +             pr_warning("DT reserved region at 0x%pa is already reserved\n",
>> +                        &base);
>
> Since memblock_remove/reserve does the right thing anyway, let's just
> drop the test entirely.

If the region completely overlaps, then I agree it is okay to be
quiet. But if we have partially overlapping region already with the
dtb, then we should warn here. We want to know if someone passes a dtb
that is too big.

Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] of/fdt: memblock_reserve /memreserve/ regions in the case of partial overlap
       [not found]         ` <CAL_JsqJV6e2oO7uJEUHzep8QAA1YztTgdaUNynKVnr_ABv+-nQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-11-26 13:14           ` Ian Campbell
       [not found]             ` <1417007670.11944.52.camel-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Ian Campbell @ 2014-11-26 13:14 UTC (permalink / raw)
  To: Rob Herring
  Cc: Grant Likely, devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Rob Herring

On Tue, 2014-11-25 at 13:31 -0600, Rob Herring wrote:
> On Tue, Nov 25, 2014 at 8:37 AM, Grant Likely <grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> wrote:
> > On Tue, 25 Nov 2014 12:54:55 +0000
> > , Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>
> >  wrote:
> >> memblock_is_region_reserved() returns true in the case of a partial
> >> overlap, meaning that the current code fails to reserve the
> >> non-overlapping portion.
> >>
> >> I observed this causing a Midway system with a buggy fdt (the header
> >> declares itself to be larger than it really is) failing to boot
> >> because the over-inflated size of the fdt was causing it to seem to
> >> run into the swapper_pg_dir region, meaning the DT wasn't reserved.
> >> The symptoms were failing to find an disks or network and failing to
> >> boot. I think it is work printing a warning in this case.
> >>
> >> However given the ambiguity of whether things like the initrd are
> >> covered by /memreserve/ and similar I think it is best to also
> >> register the region rather than just ignoring it.
> >>
> >> Since memblock_reserve() handles overlaps just fine lets just warn and
> >> carry on.
> >>
> >> Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>
> >> Cc: Grant Likely <grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> >> Cc: Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> >> Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> >> ---
> >>  drivers/of/fdt.c |    3 ++-
> >>  1 file changed, 2 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> >> index 30e97bc..4f0f24c 100644
> >> --- a/drivers/of/fdt.c
> >> +++ b/drivers/of/fdt.c
> >> @@ -965,7 +965,8 @@ int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base,
> >>                                       phys_addr_t size, bool nomap)
> >>  {
> >>       if (memblock_is_region_reserved(base, size))
> >> -             return -EBUSY;
> >> +             pr_warning("DT reserved region at 0x%pa is already reserved\n",
> >> +                        &base);
> >
> > Since memblock_remove/reserve does the right thing anyway, let's just
> > drop the test entirely.
> 
> If the region completely overlaps, then I agree it is okay to be
> quiet. But if we have partially overlapping region already with the
> dtb, then we should warn here. We want to know if someone passes a dtb
> that is too big.

Unfortunately memblock isn't currently capable of distinguishing partial
vs total overlap.

We could perhaps warn iff only on of the first and last byte of the new
region are already reserved, but not if they both are. i.e. 
	if (memblock_is_region_reserved(base, size) && 
           !!memblock_is_region_reserved(base, 1) != !!memblock_is_region_reserved(base+size-1, 1))

That wouldn't handle 
----RESERVED---|            |----RESERVED-----
            |----- NEW REGION----|

But maybe it's better than nothing.

Or we could pull the warning up to the caller which reserves the DTB but
not for the /memreserve/ loop.

Ian.

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] of/fdt: memblock_reserve /memreserve/ regions in the case of partial overlap
       [not found]             ` <1417007670.11944.52.camel-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>
@ 2014-11-26 13:26               ` Grant Likely
  0 siblings, 0 replies; 5+ messages in thread
From: Grant Likely @ 2014-11-26 13:26 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Rob Herring, devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Rob Herring

On Wed, Nov 26, 2014 at 1:14 PM, Ian Campbell <Ian.Campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org> wrote:
> On Tue, 2014-11-25 at 13:31 -0600, Rob Herring wrote:
>> On Tue, Nov 25, 2014 at 8:37 AM, Grant Likely <grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> wrote:
>> > On Tue, 25 Nov 2014 12:54:55 +0000
>> > , Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>
>> >  wrote:
>> >> memblock_is_region_reserved() returns true in the case of a partial
>> >> overlap, meaning that the current code fails to reserve the
>> >> non-overlapping portion.
>> >>
>> >> I observed this causing a Midway system with a buggy fdt (the header
>> >> declares itself to be larger than it really is) failing to boot
>> >> because the over-inflated size of the fdt was causing it to seem to
>> >> run into the swapper_pg_dir region, meaning the DT wasn't reserved.
>> >> The symptoms were failing to find an disks or network and failing to
>> >> boot. I think it is work printing a warning in this case.
>> >>
>> >> However given the ambiguity of whether things like the initrd are
>> >> covered by /memreserve/ and similar I think it is best to also
>> >> register the region rather than just ignoring it.
>> >>
>> >> Since memblock_reserve() handles overlaps just fine lets just warn and
>> >> carry on.
>> >>
>> >> Signed-off-by: Ian Campbell <ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>
>> >> Cc: Grant Likely <grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
>> >> Cc: Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
>> >> Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
>> >> ---
>> >>  drivers/of/fdt.c |    3 ++-
>> >>  1 file changed, 2 insertions(+), 1 deletion(-)
>> >>
>> >> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
>> >> index 30e97bc..4f0f24c 100644
>> >> --- a/drivers/of/fdt.c
>> >> +++ b/drivers/of/fdt.c
>> >> @@ -965,7 +965,8 @@ int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base,
>> >>                                       phys_addr_t size, bool nomap)
>> >>  {
>> >>       if (memblock_is_region_reserved(base, size))
>> >> -             return -EBUSY;
>> >> +             pr_warning("DT reserved region at 0x%pa is already reserved\n",
>> >> +                        &base);
>> >
>> > Since memblock_remove/reserve does the right thing anyway, let's just
>> > drop the test entirely.
>>
>> If the region completely overlaps, then I agree it is okay to be
>> quiet. But if we have partially overlapping region already with the
>> dtb, then we should warn here. We want to know if someone passes a dtb
>> that is too big.
>
> Unfortunately memblock isn't currently capable of distinguishing partial
> vs total overlap.
>
> We could perhaps warn iff only on of the first and last byte of the new
> region are already reserved, but not if they both are. i.e.
>         if (memblock_is_region_reserved(base, size) &&
>            !!memblock_is_region_reserved(base, 1) != !!memblock_is_region_reserved(base+size-1, 1))
>
> That wouldn't handle
> ----RESERVED---|            |----RESERVED-----
>             |----- NEW REGION----|
>
> But maybe it's better than nothing.
>
> Or we could pull the warning up to the caller which reserves the DTB but
> not for the /memreserve/ loop.

I've merged the patch to always reserve the region since it is safe.
I'll expect a followup patch to print a warning in the partial overlap
case.

g.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-11-26 13:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-25 12:54 [PATCH] of/fdt: memblock_reserve /memreserve/ regions in the case of partial overlap Ian Campbell
     [not found] ` <1416920095-31999-1-git-send-email-ian.campbell-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>
2014-11-25 14:37   ` Grant Likely
     [not found]     ` <20141125143750.1BAAAC44343-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2014-11-25 19:31       ` Rob Herring
     [not found]         ` <CAL_JsqJV6e2oO7uJEUHzep8QAA1YztTgdaUNynKVnr_ABv+-nQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-11-26 13:14           ` Ian Campbell
     [not found]             ` <1417007670.11944.52.camel-Sxgqhf6Nn4DQT0dZR+AlfA@public.gmane.org>
2014-11-26 13:26               ` Grant Likely

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).