Skip to contentSkip to conversation

Add support for configurable page size on ARM64

PATCH In review Thomas Petazzoni via buildroot 3 participants 5 messages Jul 26, 2022 – Aug 18, 2022

lore
Share & tools
lore
#0 lore raw

cover Add support for configurable page size on ARM64

Hello,

Here is a new iteration of the support for configurable page size on ARM64, based on earlier work from Łukasz Stelmach <[email protected]>, but fairly significantly changed.

Hopefully this iteration can makes it way upstream!

Thomas

Thomas Petazzoni (2):
package/uclibc: define BR2_UCLIBC_TARGET_ARCH for ARM64
arch: add support for configurable page size on ARM64

 arch/Config.in.arm                            | 25 +++++++
 arch/arch.mk                                  | 11 ++++
 arch/arch.mk.arc                              |  9 ---
 linux/linux.mk                                |  8 +++
 package/uclibc/Config.in                      |  1 +
 package/uclibc/uclibc.mk                      | 13 ++++
 .../tests/toolchain/test_aarch64_64k.py       | 65 +++++++++++++++++++
 7 files changed, 123 insertions(+), 9 deletions(-)
 create mode 100644 support/testing/tests/toolchain/test_aarch64_64k.py
Signature · 6 lines
2.37.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

PATCH 1/2 package/uclibc: define BR2_UCLIBC_TARGET_ARCH for ARM64

So far, BR2_UCLIBC_TARGET_ARCH had a value for all architectures... except for ARM64. Its value is passed as ARCH= when building uClibc... which is currently empty:

/usr/bin/make -j33 -C .../build/uclibc-1.0.41 ARCH="" CROSS_COMPILE=".../host/bin/aarch64-buildroot-linux-uclibc-"

And also in uclibc.mk, when we inject the architecture in uClibc's .config:

        $(call KCONFIG_ENABLE_OPT,TARGET_$(UCLIBC_TARGET_ARCH))
        $(call KCONFIG_SET_OPT,TARGET_ARCH,"$(UCLIBC_TARGET_ARCH)")

We enable TARGET_ (which doesn't exist) and set TARGET_ARCH to the empty string.

Nobody noticed so far, and it happens to work because aarch64 is the first architecture in the choice of architectures in extra/Configs/Config.in in the uClibc code. So, when the architecture is not specified, aarch64 is used.

As we are about to add some logic in uclibc.mk that will use BR2_UCLIBC_TARGET_ARCH, we noticed this missing definition.

---
 package/uclibc/Config.in | 1 +
 1 file changed, 1 insertion(+)
package/uclibc/Config.in +1 -0
index 2eea4d30f3..873d2053c8 100644
@@ -124,6 +124,7 @@ config BR2_UCLIBC_INSTALL_UTILS
 # uClibc architecture names.
 config BR2_UCLIBC_TARGET_ARCH
 	string
+	default "aarch64"	if BR2_aarch64 || BR2_aarch64_be
 	default "arc"	   if BR2_arcle || BR2_arceb
 	default "arm"	   if BR2_arm	|| BR2_armeb
 	default "m68k"	   if BR2_m68k
Signature · 6 lines
2.37.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw

Re: [Buildroot] [PATCH 1/2] package/uclibc: define BR2_UCLIBC_TARGET_ARCH for ARM64

Quoted 22 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Thomas" == Thomas Petazzoni via buildroot <[email protected]> writes:

So far, BR2_UCLIBC_TARGET_ARCH had a value for all architectures... except for ARM64. Its value is passed as ARCH= when building uClibc... which is currently empty:

/usr/bin/make -j33 -C .../build/uclibc-1.0.41 ARCH="" CROSS_COMPILE=".../host/bin/aarch64-buildroot-linux-uclibc-"

And also in uclibc.mk, when we inject the architecture in uClibc's .config:

        $(call KCONFIG_ENABLE_OPT,TARGET_$(UCLIBC_TARGET_ARCH))
        $(call KCONFIG_SET_OPT,TARGET_ARCH,"$(UCLIBC_TARGET_ARCH)")

We enable TARGET_ (which doesn't exist) and set TARGET_ARCH to the empty string.

Nobody noticed so far, and it happens to work because aarch64 is the first architecture in the choice of architectures in extra/Configs/Config.in in the uClibc code. So, when the architecture is not specified, aarch64 is used.

Quoted 4 lines

As we are about to add some logic in uclibc.mk that will use BR2_UCLIBC_TARGET_ARCH, we noticed this missing definition.

Committed to 2022.05.x and 2022.02.x, thanks.

Signature · 5 lines
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#3 lore raw

PATCH 2/2 arch: add support for configurable page size on ARM64

In reply to Thomas Petazzoni via buildroot

This commit is based on earlier work from Łukasz Stelmach <[email protected]> to add support for different page sizes on ARM64.

In his initial submission, Łukasz took an approach similar to this one, i.e make it ARM64-specific. Following the feedback on the mailing list, his second version [1] tried to generalize the logic to configure the page size between architectures. But the general consensus during the review process was that there wasn't much to generalize in the end.

So, this new iteration is back to a simpler approach:

* We have new options in Config.in.arm to configure the page size. Only 4 KB and 64 KB are supported, because our testing in Qemu and real hardware has not allowed to get a successful setup for 16 KB pages. We can always re-add support for 16 KB later if that is resolved.

* The logic to define the ARCH_TOOLCHAIN_WRAPPER_OPTS options is moved from the ARC-specific file to arch/arch.mk, and extended to cover ARM64.

* The appropriate logic in uclibc.mk and linux.mk is added to tweak the relevant configuration options.

* A test case is added in the runtime test infrastructure to test building and booting under Qemu a 64 KB configuration, with all 3 C libraries.

For the regular configuration of 4 KB pages, this commit makes one functional change: -Wl,-z,max-page-size=4096 is now passed in the compiler flags of the wrapper.

[1] https://patchwork.ozlabs.org/project/buildroot/list/?series=275452

---
 arch/Config.in.arm                            | 25 +++++++
 arch/arch.mk                                  | 11 ++++
 arch/arch.mk.arc                              |  9 ---
 linux/linux.mk                                |  8 +++
 package/uclibc/uclibc.mk                      | 13 ++++
 .../tests/toolchain/test_aarch64_64k.py       | 65 +++++++++++++++++++
 6 files changed, 122 insertions(+), 9 deletions(-)
 create mode 100644 support/testing/tests/toolchain/test_aarch64_64k.py
arch/Config.in.arm +25 -0
index eb71d70430..a0a2e2f5e9 100644
@@ -770,6 +770,31 @@ config BR2_ARM_INSTRUCTIONS_THUMB2
 
 endchoice
 
+choice
+	prompt "MMU Page Size"
+	default BR2_ARM64_PAGE_SIZE_4K
+	depends on BR2_aarch64 || BR2_aarch64_be
+	help
+	  The default is 4KB, and you should probably keep this unless
+	  you know what you are doing. In particular, the kernel
+	  configuration must match this choice. If your kernel is
+	  built by Buildroot, the kernel configuration is
+	  automatically adjusted, but not if you built your kernel
+	  outside of Buildroot.
+
+config BR2_ARM64_PAGE_SIZE_4K
+	bool "4KB"
+
+config BR2_ARM64_PAGE_SIZE_64K
+	bool "64KB"
+
+endchoice
+
+config BR2_ARM64_PAGE_SIZE
+	string
+	default "4K" if BR2_ARM64_PAGE_SIZE_4K
+	default "64K" if BR2_ARM64_PAGE_SIZE_64K
+
 config BR2_ARCH
 	default "arm"		if BR2_arm
 	default "armeb"		if BR2_armeb
arch/arch.mk +11 -0
index 289c5a1125..96f11eba42 100644
@@ -18,5 +18,16 @@ GCC_TARGET_FPU := $(call qstrip,$(BR2_GCC_TARGET_FPU))
 GCC_TARGET_FLOAT_ABI := $(call qstrip,$(BR2_GCC_TARGET_FLOAT_ABI))
 GCC_TARGET_MODE := $(call qstrip,$(BR2_GCC_TARGET_MODE))
 
+# Explicitly set LD's "max-page-size" instead of relying on some defaults
+ifeq ($(BR2_ARC_PAGE_SIZE_4K)$(BR2_ARM64_PAGE_SIZE_4K),y)
+ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=4096
+else ifeq ($(BR2_ARC_PAGE_SIZE_8K),y)
+ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=8192
+else ifeq ($(BR2_ARC_PAGE_SIZE_16K),y)
+ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=16384
+else ifeq ($(BR2_ARM64_PAGE_SIZE_64K),y)
+ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=65536
+endif
+
 # Include any architecture specific makefiles.
 -include $(sort $(wildcard arch/arch.mk.*))
arch/arch.mk.arc +0 -9
index 32b818b0e0..a6b56a869f 100644
@@ -5,13 +5,4 @@ ifeq ($(BR2_ARC_ATOMIC_EXT),y)
 ARCH_TOOLCHAIN_WRAPPER_OPTS = -matomic
 endif
 
-# Explicitly set LD's "max-page-size" instead of relying on some defaults
-ifeq ($(BR2_ARC_PAGE_SIZE_4K),y)
-ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=4096
-else ifeq ($(BR2_ARC_PAGE_SIZE_8K),y)
-ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=8192
-else ifeq ($(BR2_ARC_PAGE_SIZE_16K),y)
-ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=16384
-endif
-
 endif
linux/linux.mk +8 -0
index 322ccabbd9..3d9ac37959 100644
@@ -374,6 +374,14 @@ define LINUX_KCONFIG_FIXUP_CMDS
 		$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_4K)
 		$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_8K)
 		$(call KCONFIG_ENABLE_OPT,CONFIG_ARC_PAGE_SIZE_16K))
+	$(if $(BR2_ARM64_PAGE_SIZE_4K),
+		$(call KCONFIG_ENABLE_OPT,CONFIG_ARM64_4K_PAGES)
+		$(call KCONFIG_DISABLE_OPT,CONFIG_ARM64_16K_PAGES)
+		$(call KCONFIG_DISABLE_OPT,CONFIG_ARM64_64K_PAGES))
+	$(if $(BR2_ARM64_PAGE_SIZE_64K),
+		$(call KCONFIG_DISABLE_OPT,CONFIG_ARM64_4K_PAGES)
+		$(call KCONFIG_DISABLE_OPT,CONFIG_ARM64_16K_PAGES)
+		$(call KCONFIG_ENABLE_OPT,CONFIG_ARM64_64K_PAGES))
 	$(if $(BR2_TARGET_ROOTFS_CPIO),
 		$(call KCONFIG_ENABLE_OPT,CONFIG_BLK_DEV_INITRD))
 	# As the kernel gets compiled before root filesystems are
package/uclibc/uclibc.mk +13 -0
index 5006aa0cb6..0e17a8e65d 100644
@@ -73,6 +73,18 @@ define UCLIBC_BINFMT_CONFIG
 endef
 endif
 
+#
+# AArch64 definitions
+#
+
+ifeq ($(UCLIBC_TARGET_ARCH),aarch64)
+UCLIBC_ARM64_PAGE_SIZE = CONFIG_AARCH64_PAGE_SIZE_$(call qstrip,$(BR2_ARM64_PAGE_SIZE))
+define UCLIBC_AARCH64_PAGE_SIZE_CONFIG
+	$(SED) '/CONFIG_AARCH64_PAGE_SIZE_*/d' $(@D)/.config
+	$(call KCONFIG_ENABLE_OPT,$(UCLIBC_ARM64_PAGE_SIZE))
+endef
+endif # aarch64
+
 #
 # ARC definitions
 #
@@ -386,6 +398,7 @@ define UCLIBC_KCONFIG_FIXUP_CMDS
 	$(call KCONFIG_SET_OPT,SHARED_LIB_LOADER_PREFIX,"/lib")
 	$(UCLIBC_MMU_CONFIG)
 	$(UCLIBC_BINFMT_CONFIG)
+	$(UCLIBC_AARCH64_PAGE_SIZE_CONFIG)
 	$(UCLIBC_ARC_PAGE_SIZE_CONFIG)
 	$(UCLIBC_ARC_ATOMICS_CONFIG)
 	$(UCLIBC_ARM_ABI_CONFIG)
support/testing/tests/toolchain/test_aarch64_64k.py new file +65 -0

65 lines not on this page · raw message

Signature · 6 lines
2.37.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#4 lore raw
In reply to Thomas Petazzoni via buildroot
Quoted 6 lines · Thomas Petazzoni

Hello,

Here is a new iteration of the support for configurable page size on ARM64, based on earlier work from Łukasz Stelmach <[email protected]>, but fairly significantly changed.

Quoted 7 lines

Hopefully this iteration can makes it way upstream!

Thomas

Thomas Petazzoni (2):
package/uclibc: define BR2_UCLIBC_TARGET_ARCH for ARM64
arch: add support for configurable page size on ARM64

Both applied to master, thanks!

Regards,
Arnout

Quoted 11 lines
  arch/Config.in.arm                            | 25 +++++++
  arch/arch.mk                                  | 11 ++++
  arch/arch.mk.arc                              |  9 ---
  linux/linux.mk                                |  8 +++
  package/uclibc/Config.in                      |  1 +
  package/uclibc/uclibc.mk                      | 13 ++++
  .../tests/toolchain/test_aarch64_64k.py       | 65 +++++++++++++++++++
  7 files changed, 123 insertions(+), 9 deletions(-)

create mode 100644 support/testing/tests/toolchain/test_aarch64_64k.py

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot