* [PATCH] of: Fix memory block alignment in early_init_dt_add_memory_arch()
@ 2014-08-20 15:10 ` Geert Uytterhoeven
0 siblings, 0 replies; 8+ messages in thread
From: Geert Uytterhoeven @ 2014-08-20 15:10 UTC (permalink / raw)
To: Grant Likely, Rob Herring; +Cc: devicetree, linux-kernel, Geert Uytterhoeven
If a memory block is not aligned to PAGE_SIZE, its base address must be
rounded up, not down, and its size must be reduced.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
drivers/of/fdt.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index f46a24ffa3fe..95fa81b8ca19 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -928,7 +928,11 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
{
const u64 phys_offset = __pa(PAGE_OFFSET);
- base &= PAGE_MASK;
+
+ if (!PAGE_ALIGNED(base)) {
+ size -= PAGE_SIZE - (base & ~PAGE_MASK);
+ base = PAGE_ALIGN(base);
+ }
size &= PAGE_MASK;
if (base > MAX_PHYS_ADDR) {
--
1.9.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH] of: Fix memory block alignment in early_init_dt_add_memory_arch()
@ 2014-08-20 15:10 ` Geert Uytterhoeven
0 siblings, 0 replies; 8+ messages in thread
From: Geert Uytterhoeven @ 2014-08-20 15:10 UTC (permalink / raw)
To: Grant Likely, Rob Herring
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Geert Uytterhoeven
If a memory block is not aligned to PAGE_SIZE, its base address must be
rounded up, not down, and its size must be reduced.
Signed-off-by: Geert Uytterhoeven <geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
---
drivers/of/fdt.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index f46a24ffa3fe..95fa81b8ca19 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -928,7 +928,11 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
{
const u64 phys_offset = __pa(PAGE_OFFSET);
- base &= PAGE_MASK;
+
+ if (!PAGE_ALIGNED(base)) {
+ size -= PAGE_SIZE - (base & ~PAGE_MASK);
+ base = PAGE_ALIGN(base);
+ }
size &= PAGE_MASK;
if (base > MAX_PHYS_ADDR) {
--
1.9.1
--
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] 8+ messages in thread
* Re: [PATCH] of: Fix memory block alignment in early_init_dt_add_memory_arch()
@ 2014-08-27 10:30 ` Grant Likely
0 siblings, 0 replies; 8+ messages in thread
From: Grant Likely @ 2014-08-27 10:30 UTC (permalink / raw)
To: Geert Uytterhoeven, Rob Herring
Cc: devicetree, linux-kernel, Geert Uytterhoeven
On Wed, 20 Aug 2014 17:10:31 +0200, Geert Uytterhoeven <geert+renesas@glider.be> wrote:
> If a memory block is not aligned to PAGE_SIZE, its base address must be
> rounded up, not down, and its size must be reduced.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Looks reasonable. What is the situation that exposed this problem?
Should size be checked for page alignment also?
g.
> ---
> drivers/of/fdt.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index f46a24ffa3fe..95fa81b8ca19 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -928,7 +928,11 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
> void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
> {
> const u64 phys_offset = __pa(PAGE_OFFSET);
> - base &= PAGE_MASK;
> +
> + if (!PAGE_ALIGNED(base)) {
> + size -= PAGE_SIZE - (base & ~PAGE_MASK);
> + base = PAGE_ALIGN(base);
> + }
> size &= PAGE_MASK;
>
> if (base > MAX_PHYS_ADDR) {
> --
> 1.9.1
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] of: Fix memory block alignment in early_init_dt_add_memory_arch()
@ 2014-08-27 10:30 ` Grant Likely
0 siblings, 0 replies; 8+ messages in thread
From: Grant Likely @ 2014-08-27 10:30 UTC (permalink / raw)
To: Rob Herring
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Geert Uytterhoeven
On Wed, 20 Aug 2014 17:10:31 +0200, Geert Uytterhoeven <geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org> wrote:
> If a memory block is not aligned to PAGE_SIZE, its base address must be
> rounded up, not down, and its size must be reduced.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
Looks reasonable. What is the situation that exposed this problem?
Should size be checked for page alignment also?
g.
> ---
> drivers/of/fdt.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index f46a24ffa3fe..95fa81b8ca19 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -928,7 +928,11 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
> void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
> {
> const u64 phys_offset = __pa(PAGE_OFFSET);
> - base &= PAGE_MASK;
> +
> + if (!PAGE_ALIGNED(base)) {
> + size -= PAGE_SIZE - (base & ~PAGE_MASK);
> + base = PAGE_ALIGN(base);
> + }
> size &= PAGE_MASK;
>
> if (base > MAX_PHYS_ADDR) {
> --
> 1.9.1
>
--
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] 8+ messages in thread
* Re: [PATCH] of: Fix memory block alignment in early_init_dt_add_memory_arch()
@ 2014-08-27 11:08 ` Geert Uytterhoeven
0 siblings, 0 replies; 8+ messages in thread
From: Geert Uytterhoeven @ 2014-08-27 11:08 UTC (permalink / raw)
To: Grant Likely; +Cc: Geert Uytterhoeven, Rob Herring, devicetree, linux-kernel
Hi Grant,
On Wed, Aug 27, 2014 at 12:30 PM, Grant Likely <grant.likely@linaro.org> wrote:
> On Wed, 20 Aug 2014 17:10:31 +0200, Geert Uytterhoeven <geert+renesas@glider.be> wrote:
>> If a memory block is not aligned to PAGE_SIZE, its base address must be
>> rounded up, not down, and its size must be reduced.
>>
>> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
>
> Looks reasonable. What is the situation that exposed this problem?
When ARM switched from arm_add_memory() to early_init_dt_add_memory_arch()
for DT-based platforms, I just noticed this when comparing the two
implementations.
I don't know if it triggers in the wild.
> Should size be checked for page alignment also?
Size is already rounded down if it's not page aligned, cfr. the context below.
>> ---
>> drivers/of/fdt.c | 6 +++++-
>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
>> index f46a24ffa3fe..95fa81b8ca19 100644
>> --- a/drivers/of/fdt.c
>> +++ b/drivers/of/fdt.c
>> @@ -928,7 +928,11 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
>> void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
>> {
>> const u64 phys_offset = __pa(PAGE_OFFSET);
>> - base &= PAGE_MASK;
>> +
>> + if (!PAGE_ALIGNED(base)) {
>> + size -= PAGE_SIZE - (base & ~PAGE_MASK);
>> + base = PAGE_ALIGN(base);
>> + }
>> size &= PAGE_MASK;
>>
>> if (base > MAX_PHYS_ADDR) {
>> --
>> 1.9.1
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] of: Fix memory block alignment in early_init_dt_add_memory_arch()
@ 2014-08-27 11:08 ` Geert Uytterhoeven
0 siblings, 0 replies; 8+ messages in thread
From: Geert Uytterhoeven @ 2014-08-27 11:08 UTC (permalink / raw)
To: Grant Likely
Cc: Geert Uytterhoeven, Rob Herring,
devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
Hi Grant,
On Wed, Aug 27, 2014 at 12:30 PM, Grant Likely <grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> wrote:
> On Wed, 20 Aug 2014 17:10:31 +0200, Geert Uytterhoeven <geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org> wrote:
>> If a memory block is not aligned to PAGE_SIZE, its base address must be
>> rounded up, not down, and its size must be reduced.
>>
>> Signed-off-by: Geert Uytterhoeven <geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
>
> Looks reasonable. What is the situation that exposed this problem?
When ARM switched from arm_add_memory() to early_init_dt_add_memory_arch()
for DT-based platforms, I just noticed this when comparing the two
implementations.
I don't know if it triggers in the wild.
> Should size be checked for page alignment also?
Size is already rounded down if it's not page aligned, cfr. the context below.
>> ---
>> drivers/of/fdt.c | 6 +++++-
>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
>> index f46a24ffa3fe..95fa81b8ca19 100644
>> --- a/drivers/of/fdt.c
>> +++ b/drivers/of/fdt.c
>> @@ -928,7 +928,11 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
>> void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
>> {
>> const u64 phys_offset = __pa(PAGE_OFFSET);
>> - base &= PAGE_MASK;
>> +
>> + if (!PAGE_ALIGNED(base)) {
>> + size -= PAGE_SIZE - (base & ~PAGE_MASK);
>> + base = PAGE_ALIGN(base);
>> + }
>> size &= PAGE_MASK;
>>
>> if (base > MAX_PHYS_ADDR) {
>> --
>> 1.9.1
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
--
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] 8+ messages in thread
* Re: [PATCH] of: Fix memory block alignment in early_init_dt_add_memory_arch()
@ 2014-09-08 13:55 ` Grant Likely
0 siblings, 0 replies; 8+ messages in thread
From: Grant Likely @ 2014-09-08 13:55 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Geert Uytterhoeven, Rob Herring, devicetree, linux-kernel
On Wed, 27 Aug 2014 13:08:51 +0200, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> Hi Grant,
>
> On Wed, Aug 27, 2014 at 12:30 PM, Grant Likely <grant.likely@linaro.org> wrote:
> > On Wed, 20 Aug 2014 17:10:31 +0200, Geert Uytterhoeven <geert+renesas@glider.be> wrote:
> >> If a memory block is not aligned to PAGE_SIZE, its base address must be
> >> rounded up, not down, and its size must be reduced.
> >>
> >> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> >
> > Looks reasonable. What is the situation that exposed this problem?
>
> When ARM switched from arm_add_memory() to early_init_dt_add_memory_arch()
> for DT-based platforms, I just noticed this when comparing the two
> implementations.
>
> I don't know if it triggers in the wild.
>
> > Should size be checked for page alignment also?
>
> Size is already rounded down if it's not page aligned, cfr. the context below.
Indeed it is. Silly me. Applied, thanks.
g.
>
> >> ---
> >> drivers/of/fdt.c | 6 +++++-
> >> 1 file changed, 5 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> >> index f46a24ffa3fe..95fa81b8ca19 100644
> >> --- a/drivers/of/fdt.c
> >> +++ b/drivers/of/fdt.c
> >> @@ -928,7 +928,11 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
> >> void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
> >> {
> >> const u64 phys_offset = __pa(PAGE_OFFSET);
> >> - base &= PAGE_MASK;
> >> +
> >> + if (!PAGE_ALIGNED(base)) {
> >> + size -= PAGE_SIZE - (base & ~PAGE_MASK);
> >> + base = PAGE_ALIGN(base);
> >> + }
> >> size &= PAGE_MASK;
> >>
> >> if (base > MAX_PHYS_ADDR) {
> >> --
> >> 1.9.1
>
> Gr{oetje,eeting}s,
>
> Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
> -- Linus Torvalds
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] of: Fix memory block alignment in early_init_dt_add_memory_arch()
@ 2014-09-08 13:55 ` Grant Likely
0 siblings, 0 replies; 8+ messages in thread
From: Grant Likely @ 2014-09-08 13:55 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Geert Uytterhoeven, Rob Herring,
devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
On Wed, 27 Aug 2014 13:08:51 +0200, Geert Uytterhoeven <geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org> wrote:
> Hi Grant,
>
> On Wed, Aug 27, 2014 at 12:30 PM, Grant Likely <grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> wrote:
> > On Wed, 20 Aug 2014 17:10:31 +0200, Geert Uytterhoeven <geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org> wrote:
> >> If a memory block is not aligned to PAGE_SIZE, its base address must be
> >> rounded up, not down, and its size must be reduced.
> >>
> >> Signed-off-by: Geert Uytterhoeven <geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
> >
> > Looks reasonable. What is the situation that exposed this problem?
>
> When ARM switched from arm_add_memory() to early_init_dt_add_memory_arch()
> for DT-based platforms, I just noticed this when comparing the two
> implementations.
>
> I don't know if it triggers in the wild.
>
> > Should size be checked for page alignment also?
>
> Size is already rounded down if it's not page aligned, cfr. the context below.
Indeed it is. Silly me. Applied, thanks.
g.
>
> >> ---
> >> drivers/of/fdt.c | 6 +++++-
> >> 1 file changed, 5 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> >> index f46a24ffa3fe..95fa81b8ca19 100644
> >> --- a/drivers/of/fdt.c
> >> +++ b/drivers/of/fdt.c
> >> @@ -928,7 +928,11 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
> >> void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
> >> {
> >> const u64 phys_offset = __pa(PAGE_OFFSET);
> >> - base &= PAGE_MASK;
> >> +
> >> + if (!PAGE_ALIGNED(base)) {
> >> + size -= PAGE_SIZE - (base & ~PAGE_MASK);
> >> + base = PAGE_ALIGN(base);
> >> + }
> >> size &= PAGE_MASK;
> >>
> >> if (base > MAX_PHYS_ADDR) {
> >> --
> >> 1.9.1
>
> Gr{oetje,eeting}s,
>
> Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
> -- Linus Torvalds
--
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] 8+ messages in thread
end of thread, other threads:[~2014-09-08 13:55 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-20 15:10 [PATCH] of: Fix memory block alignment in early_init_dt_add_memory_arch() Geert Uytterhoeven
2014-08-20 15:10 ` Geert Uytterhoeven
2014-08-27 10:30 ` Grant Likely
2014-08-27 10:30 ` Grant Likely
2014-08-27 11:08 ` Geert Uytterhoeven
2014-08-27 11:08 ` Geert Uytterhoeven
2014-09-08 13:55 ` Grant Likely
2014-09-08 13:55 ` Grant Likely
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.