* [PATCH v2] ARM: mm: fix size rounding-down of arm_add_memory() function
@ 2014-12-22 3:17 Masahiro Yamada
2014-12-22 9:09 ` Ard Biesheuvel
0 siblings, 1 reply; 3+ messages in thread
From: Masahiro Yamada @ 2014-12-22 3:17 UTC (permalink / raw)
To: linux-arm-kernel
The current rounding of "size" is wrong:
- If "start" is sufficiently near the next page boundary, "size"
is decremented by more than enough and the last page is lost.
- If "size" is sufficiently small, it is wrapped around and gets
a bogus value.
Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
Changes in v2:
- Avoid wrap around of "size"
arch/arm/kernel/setup.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index f9c8639..d13f185 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -657,10 +657,13 @@ int __init arm_add_memory(u64 start, u64 size)
/*
* Ensure that start/size are aligned to a page boundary.
- * Size is appropriately rounded down, start is rounded up.
+ * Size is rounded down, start is rounded up.
*/
- size -= start & ~PAGE_MASK;
aligned_start = PAGE_ALIGN(start);
+ if (aligned_start > start + size)
+ size = 0;
+ else
+ size -= aligned_start - start;
#ifndef CONFIG_ARCH_PHYS_ADDR_T_64BIT
if (aligned_start > ULONG_MAX) {
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v2] ARM: mm: fix size rounding-down of arm_add_memory() function
2014-12-22 3:17 [PATCH v2] ARM: mm: fix size rounding-down of arm_add_memory() function Masahiro Yamada
@ 2014-12-22 9:09 ` Ard Biesheuvel
2015-01-14 2:53 ` Masahiro Yamada
0 siblings, 1 reply; 3+ messages in thread
From: Ard Biesheuvel @ 2014-12-22 9:09 UTC (permalink / raw)
To: linux-arm-kernel
On 22 December 2014 at 04:17, Masahiro Yamada <yamada.m@jp.panasonic.com> wrote:
> The current rounding of "size" is wrong:
>
> - If "start" is sufficiently near the next page boundary, "size"
> is decremented by more than enough and the last page is lost.
>
> - If "size" is sufficiently small, it is wrapped around and gets
> a bogus value.
>
> Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
> Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>
> Changes in v2:
> - Avoid wrap around of "size"
>
> arch/arm/kernel/setup.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
> index f9c8639..d13f185 100644
> --- a/arch/arm/kernel/setup.c
> +++ b/arch/arm/kernel/setup.c
> @@ -657,10 +657,13 @@ int __init arm_add_memory(u64 start, u64 size)
>
> /*
> * Ensure that start/size are aligned to a page boundary.
> - * Size is appropriately rounded down, start is rounded up.
> + * Size is rounded down, start is rounded up.
> */
> - size -= start & ~PAGE_MASK;
> aligned_start = PAGE_ALIGN(start);
> + if (aligned_start > start + size)
> + size = 0;
> + else
> + size -= aligned_start - start;
>
> #ifndef CONFIG_ARCH_PHYS_ADDR_T_64BIT
> if (aligned_start > ULONG_MAX) {
> --
> 1.9.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2] ARM: mm: fix size rounding-down of arm_add_memory() function
2014-12-22 9:09 ` Ard Biesheuvel
@ 2015-01-14 2:53 ` Masahiro Yamada
0 siblings, 0 replies; 3+ messages in thread
From: Masahiro Yamada @ 2015-01-14 2:53 UTC (permalink / raw)
To: linux-arm-kernel
Hello Russell King,
Could you apply this patch for arm_add_memory() fix, please ?
Thanks,
Masahiro Yamada
On Mon, 22 Dec 2014 10:09:32 +0100
Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
> On 22 December 2014 at 04:17, Masahiro Yamada <yamada.m@jp.panasonic.com> wrote:
> > The current rounding of "size" is wrong:
> >
> > - If "start" is sufficiently near the next page boundary, "size"
> > is decremented by more than enough and the last page is lost.
> >
> > - If "size" is sufficiently small, it is wrapped around and gets
> > a bogus value.
> >
> > Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
> > Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
>
> Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>
>
> > ---
> >
> > Changes in v2:
> > - Avoid wrap around of "size"
> >
> > arch/arm/kernel/setup.c | 7 +++++--
> > 1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
> > index f9c8639..d13f185 100644
> > --- a/arch/arm/kernel/setup.c
> > +++ b/arch/arm/kernel/setup.c
> > @@ -657,10 +657,13 @@ int __init arm_add_memory(u64 start, u64 size)
> >
> > /*
> > * Ensure that start/size are aligned to a page boundary.
> > - * Size is appropriately rounded down, start is rounded up.
> > + * Size is rounded down, start is rounded up.
> > */
> > - size -= start & ~PAGE_MASK;
> > aligned_start = PAGE_ALIGN(start);
> > + if (aligned_start > start + size)
> > + size = 0;
> > + else
> > + size -= aligned_start - start;
> >
> > #ifndef CONFIG_ARCH_PHYS_ADDR_T_64BIT
> > if (aligned_start > ULONG_MAX) {
> > --
> > 1.9.1
> >
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-01-14 2:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-22 3:17 [PATCH v2] ARM: mm: fix size rounding-down of arm_add_memory() function Masahiro Yamada
2014-12-22 9:09 ` Ard Biesheuvel
2015-01-14 2:53 ` Masahiro Yamada
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).