devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of: fdt: add size 0 check after page align
@ 2024-03-02 14:03 skseofh
  2024-03-04 13:26 ` Rob Herring
  0 siblings, 1 reply; 6+ messages in thread
From: skseofh @ 2024-03-02 14:03 UTC (permalink / raw)
  To: robh+dt, frowand.list; +Cc: devicetree, linux-kernel, Daero Lee

From: Daero Lee <skseofh@gmail.com>

After page aligning, the size may become zero. So I added exception
handling code for size 0.

example : 4K page size
    [before page align]
        base = 0x1800
        size = 0x1100

    [after page align]
        size = 0x900
        base = 0x2000

        size &= PAGE_MASK(~0x7FFF) = 0

Signed-off-by: Daero Lee <skseofh@gmail.com>
---
 drivers/of/fdt.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index bf502ba8da95..01156088fbb4 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -1232,6 +1232,11 @@ void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
 		base = PAGE_ALIGN(base);
 	}
 	size &= PAGE_MASK;
+	if (!size) {
+		pr_warn("Ignoring memory block 0x%llx - 0x%llx\n",
+			base, base + size);
+		return;
+	}
 
 	if (base > MAX_MEMBLOCK_ADDR) {
 		pr_warn("Ignoring memory block 0x%llx - 0x%llx\n",
-- 
2.25.1


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

* Re: [PATCH] of: fdt: add size 0 check after page align
  2024-03-02 14:03 [PATCH] of: fdt: add size 0 check after page align skseofh
@ 2024-03-04 13:26 ` Rob Herring
  2024-03-04 14:51   ` skseofh
  2024-03-04 15:02   ` [PATCH] of: fdt: modify small size memory check skseofh
  0 siblings, 2 replies; 6+ messages in thread
From: Rob Herring @ 2024-03-04 13:26 UTC (permalink / raw)
  To: skseofh; +Cc: frowand.list, devicetree, linux-kernel

On Sat, Mar 2, 2024 at 8:03 AM <skseofh@gmail.com> wrote:
>
> From: Daero Lee <skseofh@gmail.com>
>
> After page aligning, the size may become zero. So I added exception
> handling code for size 0.

That may be true, but when would anyone only have memory regions of
less than 2 pages. In any case memblock_add will just do nothing. What
is the actual problem you are having?

Rob

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

* (no subject)
  2024-03-04 13:26 ` Rob Herring
@ 2024-03-04 14:51   ` skseofh
  2024-03-04 15:02   ` [PATCH] of: fdt: modify small size memory check skseofh
  1 sibling, 0 replies; 6+ messages in thread
From: skseofh @ 2024-03-04 14:51 UTC (permalink / raw)
  To: robh+dt; +Cc: devicetree, frowand.list, linux-kernel, skseofh

From: skseofh@gmail.com
Reply-To: 
Subject: 
In-Reply-To: CAL_JsqKNGjKq3vcUPFiPa9JNq-8=oP=uBSD=tyKaPMH3cvAkww@mail.gmail.com

>>
>> From: Daero Lee <skseofh@gmail.com>
>>
>> After page aligning, the size may become zero. So I added exception
>> handling code for size 0.
>
>That may be true, but when would anyone only have memory regions of
>less than 2 pages. In any case memblock_add will just do nothing. What
>is the actual problem you are having?

I modified the patch to clear this. Please check.

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

* [PATCH] of: fdt: modify small size memory check
  2024-03-04 13:26 ` Rob Herring
  2024-03-04 14:51   ` skseofh
@ 2024-03-04 15:02   ` skseofh
  2024-03-04 17:05     ` Rob Herring
  1 sibling, 1 reply; 6+ messages in thread
From: skseofh @ 2024-03-04 15:02 UTC (permalink / raw)
  To: robh+dt; +Cc: devicetree, frowand.list, linux-kernel, skseofh


>>
>> From: Daero Lee <skseofh@gmail.com>
>>
>> After page aligning, the size may become zero. So I added exception
>> handling code for size 0.
>
>That may be true, but when would anyone only have memory regions of
>less than 2 pages. In any case memblock_add will just do nothing. What
>is the actual problem you are having?
>
>Rob

Ignore the previous mail.
I modified the patch to clear this size check routine. Please check

-------------------------------------------------------------------------
From 2135d37c37f8c369033f79102b17ddf5bb3ff838 Mon Sep 17 00:00:00 2001
From: Daero Lee <skseofh@gmail.com>
Date: Mon, 4 Mar 2024 23:21:14 +0900
Subject: [PATCH] of: fdt: modify small size memory check

Small size memory which is less than 1 PAGE_SIZE after page align
should not be added to memblock.

In this patch, the size check was modified to make it clear.

Signed-off-by: Daero Lee <skseofh@gmail.com>
---
 drivers/of/fdt.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index bf502ba8da95..9cf844e664b0 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -1220,18 +1220,16 @@ int __init early_init_dt_scan_chosen(char *cmdline)
 void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
 {
        const u64 phys_offset = MIN_MEMBLOCK_ADDR;
+       u64 abase = PAGE_ALIGN(base), aend = PAGE_ALIGN_DOWN(base + size);

-       if (size < PAGE_SIZE - (base & ~PAGE_MASK)) {
+       if((aend - abase) < PAGE_SIZE) {
                pr_warn("Ignoring memory block 0x%llx - 0x%llx\n",
                        base, base + size);
                return;
        }

-       if (!PAGE_ALIGNED(base)) {
-               size -= PAGE_SIZE - (base & ~PAGE_MASK);
-               base = PAGE_ALIGN(base);
-       }
-       size &= PAGE_MASK;
+       base = abase;
+       size = (aend - abase) & PAGE_MASK;

        if (base > MAX_MEMBLOCK_ADDR) {
                pr_warn("Ignoring memory block 0x%llx - 0x%llx\n",
--
2.25.1


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

* Re: [PATCH] of: fdt: modify small size memory check
  2024-03-04 15:02   ` [PATCH] of: fdt: modify small size memory check skseofh
@ 2024-03-04 17:05     ` Rob Herring
  2024-03-04 22:38       ` skseofh
  0 siblings, 1 reply; 6+ messages in thread
From: Rob Herring @ 2024-03-04 17:05 UTC (permalink / raw)
  To: skseofh; +Cc: devicetree, frowand.list, linux-kernel

On Mon, Mar 4, 2024 at 9:03 AM <skseofh@gmail.com> wrote:
>
>
> >>
> >> From: Daero Lee <skseofh@gmail.com>
> >>
> >> After page aligning, the size may become zero. So I added exception
> >> handling code for size 0.
> >
> >That may be true, but when would anyone only have memory regions of
> >less than 2 pages. In any case memblock_add will just do nothing. What
> >is the actual problem you are having?
> >
> >Rob
>
> Ignore the previous mail.
> I modified the patch to clear this size check routine. Please check

You still haven't answered my questions above.

Though the patch below is a bit more readable than what we currently have...

>
> -------------------------------------------------------------------------
> From 2135d37c37f8c369033f79102b17ddf5bb3ff838 Mon Sep 17 00:00:00 2001
> From: Daero Lee <skseofh@gmail.com>
> Date: Mon, 4 Mar 2024 23:21:14 +0900
> Subject: [PATCH] of: fdt: modify small size memory check
>
> Small size memory which is less than 1 PAGE_SIZE after page align
> should not be added to memblock.
>
> In this patch, the size check was modified to make it clear.
>
> Signed-off-by: Daero Lee <skseofh@gmail.com>
> ---
>  drivers/of/fdt.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index bf502ba8da95..9cf844e664b0 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -1220,18 +1220,16 @@ int __init early_init_dt_scan_chosen(char *cmdline)
>  void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
>  {
>         const u64 phys_offset = MIN_MEMBLOCK_ADDR;
> +       u64 abase = PAGE_ALIGN(base), aend = PAGE_ALIGN_DOWN(base + size);
>
> -       if (size < PAGE_SIZE - (base & ~PAGE_MASK)) {
> +       if((aend - abase) < PAGE_SIZE) {
>                 pr_warn("Ignoring memory block 0x%llx - 0x%llx\n",
>                         base, base + size);
>                 return;
>         }
>
> -       if (!PAGE_ALIGNED(base)) {
> -               size -= PAGE_SIZE - (base & ~PAGE_MASK);
> -               base = PAGE_ALIGN(base);
> -       }
> -       size &= PAGE_MASK;
> +       base = abase;
> +       size = (aend - abase) & PAGE_MASK;
>
>         if (base > MAX_MEMBLOCK_ADDR) {
>                 pr_warn("Ignoring memory block 0x%llx - 0x%llx\n",
> --
> 2.25.1
>
>

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

* [PATCH] of: fdt: modify small size memory check
  2024-03-04 17:05     ` Rob Herring
@ 2024-03-04 22:38       ` skseofh
  0 siblings, 0 replies; 6+ messages in thread
From: skseofh @ 2024-03-04 22:38 UTC (permalink / raw)
  To: robh+dt; +Cc: devicetree, frowand.list, linux-kernel, skseofh


> >
> >
> > >>
> > >> From: Daero Lee <skseofh@gmail.com>
> > >>
> > >> After page aligning, the size may become zero. So I added exception
> > >> handling code for size 0.
> > >
> > >That may be true, but when would anyone only have memory regions of
> > >less than 2 pages. In any case memblock_add will just do nothing. What
> > >is the actual problem you are having?
> > >
> > >Rob
> >
> > Ignore the previous mail.
> > I modified the patch to clear this size check routine. Please check
>
> You still haven't answered my questions above.
> 
> Though the patch below is a bit more readable than what we currently have...

Well.. I don't see any 'real' problem with this.
But I'm not sure if it's appropriate to leave a part that will be returned 
directly in the next fuction called. Wouldn't it be better to handle the part
can be handled in this function, rather than expecting the next function to 
handle this exception?

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

end of thread, other threads:[~2024-03-04 22:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-02 14:03 [PATCH] of: fdt: add size 0 check after page align skseofh
2024-03-04 13:26 ` Rob Herring
2024-03-04 14:51   ` skseofh
2024-03-04 15:02   ` [PATCH] of: fdt: modify small size memory check skseofh
2024-03-04 17:05     ` Rob Herring
2024-03-04 22:38       ` skseofh

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