All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: use correct section size macro to describe the FDT virtual address
@ 2020-10-28 13:24 Ard Biesheuvel
  2020-10-28 15:20 ` Linus Walleij
  0 siblings, 1 reply; 3+ messages in thread
From: Ard Biesheuvel @ 2020-10-28 13:24 UTC (permalink / raw)
  To: linux
  Cc: nico, linus.walleij, joel, Ard Biesheuvel, linux-arm-kernel,
	m.szyprowski

Commit

  149a3ffe62b9dbc3 ("9012/1: move device tree mapping out of linear region")

created a permanent, read-only section mapping of the device tree blob
provided by the firmware, and added a set of macros to get the base and
size of the virtually mapped FDT based on the physical address. However,
while the mapping code uses the SECTION_SIZE macro correctly, the macros
use PMD_SIZE instead, which means something entirely different on ARM when
using short descriptors, and is therefore not the right quantity to use
here. So replace PMD_SIZE with SECTION_SIZE. While at it, change the names
of the macro and its parameter to clarify that it returns the virtual
address of the start of the FDT in memory, based on the physical address
in memory.

Tested-by: Joel Stanley <joel@jms.id.au>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
Already submitted as 9020/1. Related discussion can be found at

https://lore.kernel.org/linux-arm-kernel/20201007083944.27910-3-ardb@kernel.org/

 arch/arm/include/asm/memory.h | 6 +++---
 arch/arm/kernel/setup.c       | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
index bb79e52aeb90..f717d7122d9d 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -68,8 +68,8 @@
 #define XIP_VIRT_ADDR(physaddr)  (MODULES_VADDR + ((physaddr) & 0x000fffff))
 
 #define FDT_FIXED_BASE		UL(0xff800000)
-#define FDT_FIXED_SIZE		(2 * PMD_SIZE)
-#define FDT_VIRT_ADDR(physaddr)	((void *)(FDT_FIXED_BASE | (physaddr) % PMD_SIZE))
+#define FDT_FIXED_SIZE		(2 * SECTION_SIZE)
+#define FDT_VIRT_BASE(physbase)	((void *)(FDT_FIXED_BASE | (physbase) % SECTION_SIZE))
 
 #if !defined(CONFIG_SMP) && !defined(CONFIG_ARM_LPAE)
 /*
@@ -111,7 +111,7 @@ extern unsigned long vectors_base;
 #define MODULES_VADDR		PAGE_OFFSET
 
 #define XIP_VIRT_ADDR(physaddr)  (physaddr)
-#define FDT_VIRT_ADDR(physaddr)  ((void *)(physaddr))
+#define FDT_VIRT_BASE(physbase)  ((void *)(physbase))
 
 #endif /* !CONFIG_MMU */
 
diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index 694aa6b4bd03..f90479d8b50c 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -1086,7 +1086,7 @@ void __init setup_arch(char **cmdline_p)
 	void *atags_vaddr = NULL;
 
 	if (__atags_pointer)
-		atags_vaddr = FDT_VIRT_ADDR(__atags_pointer);
+		atags_vaddr = FDT_VIRT_BASE(__atags_pointer);
 
 	setup_processor();
 	if (atags_vaddr) {
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] mm: use correct section size macro to describe the FDT virtual address
  2020-10-28 13:24 [PATCH] mm: use correct section size macro to describe the FDT virtual address Ard Biesheuvel
@ 2020-10-28 15:20 ` Linus Walleij
  2020-10-28 15:22   ` Ard Biesheuvel
  0 siblings, 1 reply; 3+ messages in thread
From: Linus Walleij @ 2020-10-28 15:20 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: Marek Szyprowski, Joel Stanley, Russell King, Linux ARM,
	Nicolas Pitre

On Wed, Oct 28, 2020 at 2:25 PM Ard Biesheuvel <ardb@kernel.org> wrote:

>   149a3ffe62b9dbc3 ("9012/1: move device tree mapping out of linear region")
>
> created a permanent, read-only section mapping of the device tree blob
> provided by the firmware, and added a set of macros to get the base and
> size of the virtually mapped FDT based on the physical address. However,
> while the mapping code uses the SECTION_SIZE macro correctly, the macros
> use PMD_SIZE instead, which means something entirely different on ARM when
> using short descriptors, and is therefore not the right quantity to use
> here. So replace PMD_SIZE with SECTION_SIZE. While at it, change the names
> of the macro and its parameter to clarify that it returns the virtual
> address of the start of the FDT in memory, based on the physical address
> in memory.
>
> Tested-by: Joel Stanley <joel@jms.id.au>
> Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>

2 * SECTION_SIZE will be 2 MB on classic MMU and 4MB on
LPAE right?

Note in Documentation/arm/memory.rst:

> -ffc00000 ffefffff Fixmap mapping region.  Addresses provided
> +ffc80000 ffefffff Fixmap mapping region.  Addresses provided
>      by fix_to_virt() will be located here.
>
> +ffc00000 ffc7ffff Guard region
> +
> +ff800000 ffbfffff Permanent, fixed read-only mapping of the
> + firmware provided DT blob

So on the classic MMU the DTB mapping will use 0xff800000-0xff9fffff
and on LPAE it will use the whole 0xff800000-0xffbfffff as in the doc?

Just verifying that I understand this right...

If I have understood what I just reviewed right:
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] mm: use correct section size macro to describe the FDT virtual address
  2020-10-28 15:20 ` Linus Walleij
@ 2020-10-28 15:22   ` Ard Biesheuvel
  0 siblings, 0 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2020-10-28 15:22 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Marek Szyprowski, Joel Stanley, Russell King, Linux ARM,
	Nicolas Pitre

On Wed, 28 Oct 2020 at 16:20, Linus Walleij <linus.walleij@linaro.org> wrote:
>
> On Wed, Oct 28, 2020 at 2:25 PM Ard Biesheuvel <ardb@kernel.org> wrote:
>
> >   149a3ffe62b9dbc3 ("9012/1: move device tree mapping out of linear region")
> >
> > created a permanent, read-only section mapping of the device tree blob
> > provided by the firmware, and added a set of macros to get the base and
> > size of the virtually mapped FDT based on the physical address. However,
> > while the mapping code uses the SECTION_SIZE macro correctly, the macros
> > use PMD_SIZE instead, which means something entirely different on ARM when
> > using short descriptors, and is therefore not the right quantity to use
> > here. So replace PMD_SIZE with SECTION_SIZE. While at it, change the names
> > of the macro and its parameter to clarify that it returns the virtual
> > address of the start of the FDT in memory, based on the physical address
> > in memory.
> >
> > Tested-by: Joel Stanley <joel@jms.id.au>
> > Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
> > Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
>
> 2 * SECTION_SIZE will be 2 MB on classic MMU and 4MB on
> LPAE right?
>

Yes

> Note in Documentation/arm/memory.rst:
>
> > -ffc00000 ffefffff Fixmap mapping region.  Addresses provided
> > +ffc80000 ffefffff Fixmap mapping region.  Addresses provided
> >      by fix_to_virt() will be located here.
> >
> > +ffc00000 ffc7ffff Guard region
> > +
> > +ff800000 ffbfffff Permanent, fixed read-only mapping of the
> > + firmware provided DT blob
>
> So on the classic MMU the DTB mapping will use 0xff800000-0xff9fffff
> and on LPAE it will use the whole 0xff800000-0xffbfffff as in the doc?
>

Indeed

> Just verifying that I understand this right...
>
> If I have understood what I just reviewed right:
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
>
> Yours,
> Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@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:[~2020-10-28 15:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-28 13:24 [PATCH] mm: use correct section size macro to describe the FDT virtual address Ard Biesheuvel
2020-10-28 15:20 ` Linus Walleij
2020-10-28 15:22   ` Ard Biesheuvel

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.