diff mbox series

[1/1] arch/arm: Choose page size for AArch64

Message ID 20211203202559.253726-1-l.stelmach@samsung.com
State Changes Requested
Headers show
Series [1/1] arch/arm: Choose page size for AArch64 | expand

Commit Message

Łukasz Stelmach Dec. 3, 2021, 8:25 p.m. UTC
MMUs on AArch64 support three different page sizes: 4 kB, 16 kB,
and 64 kB. It is OS kernel's task to choose the configuration during
boot. Linux kernel can be compiled to support different page size.
To run on a system with pages larger than 4 kB userland binaries need
to be properly aligned during the linking process. However, binaries
prepared for systems with larger pages can run on systems with smaller
pages.

Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
---
 arch/Config.in.arm | 24 ++++++++++++++++++++++++
 arch/arch.mk.arm   | 12 ++++++++++++
 2 files changed, 36 insertions(+)
 create mode 100644 arch/arch.mk.arm

Comments

Yann E. MORIN Dec. 3, 2021, 9:50 p.m. UTC | #1
Łukasz, All,

On 2021-12-03 21:25 +0100, Łukasz Stelmach spake thusly:
> MMUs on AArch64 support three different page sizes: 4 kB, 16 kB,
> and 64 kB. It is OS kernel's task to choose the configuration during
> boot. Linux kernel can be compiled to support different page size.
> To run on a system with pages larger than 4 kB userland binaries need
> to be properly aligned during the linking process. However, binaries
> prepared for systems with larger pages can run on systems with smaller
> pages.
> 
> Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
> ---
>  arch/Config.in.arm | 24 ++++++++++++++++++++++++
>  arch/arch.mk.arm   | 12 ++++++++++++
>  2 files changed, 36 insertions(+)
>  create mode 100644 arch/arch.mk.arm
> 
> diff --git a/arch/Config.in.arm b/arch/Config.in.arm
> index 4c0910e4f8..bc6452878d 100644
> --- a/arch/Config.in.arm
> +++ b/arch/Config.in.arm
> @@ -930,5 +930,29 @@ config BR2_READELF_ARCH_NAME
>  	default "ARM"		if BR2_arm || BR2_armeb
>  	default "AArch64"	if BR2_aarch64 || BR2_aarch64_be
>  
> +choice
> +	prompt "Aarch64 MMU Page Size"
> +	default BR2_ARM_PAGE_SIZE_4K
> +	depends on BR2_aarch64 || BR2_aarch64_be
> +	help
> +	  Choose MMU page size
> +
> +config BR2_ARM_PAGE_SIZE_4K
> +	bool "4KB"
> +
> +config BR2_ARM_PAGE_SIZE_16K
> +	bool "16KB"
> +
> +config BR2_ARM_PAGE_SIZE_64K
> +	bool "64KB"
> +
> +endchoice

So, we alrady have a very similar choice for the ARC architecture,
except it's for 4Ki, 8Ki, or 16Ki pages.

I wonder if we could not make that choice more architecture-agnostic,
and add the entries needed for Aarch64. Then arch would tell if their
page size is configurable, and which sizes they support.

For example:

  * arch/Config.in:

    config BR2_arcle    # Ditto for arceb
        bool "arcle"
        select BR2_ARCH_HAS_MMU_PAGE_SIZE_4K if !BR2_arc750d
        select BR2_ARCH_HAS_MMU_PAGE_SIZE_8K
        select BR2_ARCH_HAS_MMU_PAGE_SIZE_16K if !BR2_arc750d

    config BR2_aarch64  # Ditto for BR2_aarch64_be
        bool "Aarch64"
        select BR2_ARCH_HAS_MMU_PAGE_SIZE_4K
        select BR2_ARCH_HAS_MMU_PAGE_SIZE_16K
        select BR2_ARCH_HAS_MMU_PAGE_SIZE_64K

    config BR2_ARCH_HAS_CONFIGURABLE_MMU_PAGE_SIZE
        bool

    config BR2_ARCH_HAS_MMU_PAGE_SIZE_4K
        bool
        select BR2_ARCH_HAS_CONFIGURABLE_MMU_PAGE_SIZE

    config BR2_ARCH_HAS_MMU_PAGE_SIZE_8K
        bool
        select BR2_ARCH_HAS_CONFIGURABLE_MMU_PAGE_SIZE

    config BR2_ARCH_HAS_MMU_PAGE_SIZE_16K
        bool
        select BR2_ARCH_HAS_CONFIGURABLE_MMU_PAGE_SIZE

    config BR2_ARCH_HAS_MMU_PAGE_SIZE_64K
        bool
        select BR2_ARCH_HAS_CONFIGURABLE_MMU_PAGE_SIZE

    choice
        bool "MMU page size"
        depends on BR2_ARCH_HAS_CONFIGURABLE_MMU_PAGE_SIZE

    config BR2_ARCH_PAGE_SIZE_4K
        bool "4Ki"
        depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_4K

    config BR2_ARCH_PAGE_SIZE_8K
        bool "8Ki"
        depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_8K

    config BR2_ARCH_PAGE_SIZE_16K
        bool "16Ki"
        depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_16K

    # No 32Ki entry because noone uses it. Yet.

    config BR2_ARCH_PAGE_SIZE_64K
        bool "64Ki"
        depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_64K

    endchoice


  * toolchain-wrapper.mk

    # Explicitly set LD's "max-page-size" instead of relying on some defaults
    ifeq ($(BR2_ARCH_PAGE_SIZE_4K),y)
    ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=4096
    else ifeq ($(BR2_ARCH_PAGE_SIZE_8K),y)
    ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=8192
    else ifeq ($(BR2_ARCH_PAGE_SIZE_16K),y)
    ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=32768
    else ifeq ($(BR2_ARCH_PAGE_SIZE_64K),y)
    ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=65536


And the corresponding code dropped from arch/Config.in.arc and
arch/arch.mk.arc, and a bit of legacy handling to keep existing
configurations functional.

Otherwise, I don't see why that could not be a generic setting.

Regards,
Yann E. MORIN.

> +config BR2_ARM_PAGE_SIZE
> +	string
> +	default "4K" if BR2_ARM_PAGE_SIZE_4K
> +	default "16K" if BR2_ARM_PAGE_SIZE_16K
> +	default "64K" if BR2_ARM_PAGE_SIZE_64K
> +
>  # vim: ft=kconfig
>  # -*- mode:kconfig; -*-
> diff --git a/arch/arch.mk.arm b/arch/arch.mk.arm
> new file mode 100644
> index 0000000000..ef65c60f6c
> --- /dev/null
> +++ b/arch/arch.mk.arm
> @@ -0,0 +1,12 @@
> +ifeq ($(filter y, $(BR2_aarch64) $(BR2_aarch64_be)), y)
> +
> +# Explicitly set LD's "max-page-size" instead of relying on some defaults
> +ifeq ($(BR2_ARM_PAGE_SIZE_4K),y)
> +ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=4096
> +else ifeq ($(BR2_ARM_PAGE_SIZE_16K),y)
> +ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=32768
> +else ifeq ($(BR2_ARM_PAGE_SIZE_64K),y)
> +ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=65536
> +endif
> +
> +endif
> -- 
> 2.30.2
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
diff mbox series

Patch

diff --git a/arch/Config.in.arm b/arch/Config.in.arm
index 4c0910e4f8..bc6452878d 100644
--- a/arch/Config.in.arm
+++ b/arch/Config.in.arm
@@ -930,5 +930,29 @@  config BR2_READELF_ARCH_NAME
 	default "ARM"		if BR2_arm || BR2_armeb
 	default "AArch64"	if BR2_aarch64 || BR2_aarch64_be
 
+choice
+	prompt "Aarch64 MMU Page Size"
+	default BR2_ARM_PAGE_SIZE_4K
+	depends on BR2_aarch64 || BR2_aarch64_be
+	help
+	  Choose MMU page size
+
+config BR2_ARM_PAGE_SIZE_4K
+	bool "4KB"
+
+config BR2_ARM_PAGE_SIZE_16K
+	bool "16KB"
+
+config BR2_ARM_PAGE_SIZE_64K
+	bool "64KB"
+
+endchoice
+
+config BR2_ARM_PAGE_SIZE
+	string
+	default "4K" if BR2_ARM_PAGE_SIZE_4K
+	default "16K" if BR2_ARM_PAGE_SIZE_16K
+	default "64K" if BR2_ARM_PAGE_SIZE_64K
+
 # vim: ft=kconfig
 # -*- mode:kconfig; -*-
diff --git a/arch/arch.mk.arm b/arch/arch.mk.arm
new file mode 100644
index 0000000000..ef65c60f6c
--- /dev/null
+++ b/arch/arch.mk.arm
@@ -0,0 +1,12 @@ 
+ifeq ($(filter y, $(BR2_aarch64) $(BR2_aarch64_be)), y)
+
+# Explicitly set LD's "max-page-size" instead of relying on some defaults
+ifeq ($(BR2_ARM_PAGE_SIZE_4K),y)
+ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=4096
+else ifeq ($(BR2_ARM_PAGE_SIZE_16K),y)
+ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=32768
+else ifeq ($(BR2_ARM_PAGE_SIZE_64K),y)
+ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=65536
+endif
+
+endif