diff mbox series

[v2,1/2] arch: Make page size configuration architecture-independent.

Message ID 20211206192732.373740-2-l.stelmach@samsung.com
State Superseded
Headers show
Series Generic MMU page size selection | expand

Commit Message

Łukasz Stelmach Dec. 6, 2021, 7:27 p.m. UTC
Rename BR2_ARC_PAGE_SIZE_* to BR2_ARCH_MMU_PAGE_SIZE_* options.

Add BR2_ARCH_HAS_CONFIGURABLE_MMU_PAGE_SIZE and
BR2_ARCH_HAS_MMU_PAGE_SIZE_* to control configuration option dependencies
and visibility.

Adapt existing ARC page size selection.

Suggested-by: Yann E. MORIN <yann.morin.1998@free.fr>
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
---
 arch/Config.in                 | 64 ++++++++++++++++++++++++++++++++++
 arch/Config.in.arc             | 38 --------------------
 arch/arch.mk.arc               |  9 -----
 linux/linux.mk                 | 27 +++++++-------
 package/uclibc/uclibc.mk       |  2 +-
 toolchain/toolchain-wrapper.mk | 13 +++++++
 6 files changed, 93 insertions(+), 60 deletions(-)

Comments

Arnout Vandecappelle Dec. 6, 2021, 8:30 p.m. UTC | #1
Hi Łukasz,

  Thank you for this patch! Since it's a bit an invasive feature, it might not 
get merged easily.

On 06/12/2021 20:27, Łukasz Stelmach wrote:
> Rename BR2_ARC_PAGE_SIZE_* to BR2_ARCH_MMU_PAGE_SIZE_* options.

  My first reaction was: this is probably going to be limited to a very small 
number of architectures, so maybe it shouldn't be a generic option (especially 
since the kernel config changes are anyway still arch specific). However, it 
turns out that mips, powerpc and sh also support several page sizes (as well as 
a few other arches that we don't support). And I can imagine that riscv may get 
this feature at some point as well. So, the generic approach is probably right 
after all.


> 
> Add BR2_ARCH_HAS_CONFIGURABLE_MMU_PAGE_SIZE and
> BR2_ARCH_HAS_MMU_PAGE_SIZE_* to control configuration option dependencies
> and visibility.
> 
> Adapt existing ARC page size selection.
> 
> Suggested-by: Yann E. MORIN <yann.morin.1998@free.fr>
> Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
> ---
>   arch/Config.in                 | 64 ++++++++++++++++++++++++++++++++++
>   arch/Config.in.arc             | 38 --------------------
>   arch/arch.mk.arc               |  9 -----
>   linux/linux.mk                 | 27 +++++++-------
>   package/uclibc/uclibc.mk       |  2 +-
>   toolchain/toolchain-wrapper.mk | 13 +++++++
>   6 files changed, 93 insertions(+), 60 deletions(-)
> 
> diff --git a/arch/Config.in b/arch/Config.in
> index 1853e26bb4..561d599561 100644
> --- a/arch/Config.in
> +++ b/arch/Config.in
> @@ -24,6 +24,9 @@ choice
>   config BR2_arcle
>   	bool "ARC (little endian)"
>   	select BR2_ARCH_HAS_MMU_MANDATORY
> +	select BR2_ARCH_HAS_MMU_PAGE_SIZE_4K
> +	select BR2_ARCH_HAS_MMU_PAGE_SIZE_8K
> +	select BR2_ARCH_HAS_MMU_PAGE_SIZE_16K
>   	help
>   	  Synopsys' DesignWare ARC Processor Cores are a family of
>   	  32-bit CPUs that can be used from deeply embedded to high
> @@ -32,6 +35,9 @@ config BR2_arcle
>   config BR2_arceb
>   	bool "ARC (big endian)"
>   	select BR2_ARCH_HAS_MMU_MANDATORY
> +	select BR2_ARCH_HAS_MMU_PAGE_SIZE_4K
> +	select BR2_ARCH_HAS_MMU_PAGE_SIZE_8K
> +	select BR2_ARCH_HAS_MMU_PAGE_SIZE_16K
>   	help
>   	  Synopsys' DesignWare ARC Processor Cores are a family of
>   	  32-bit CPUs that can be used from deeply embedded to high
> @@ -426,6 +432,64 @@ config BR2_BINFMT_FLAT_SHARED
>   
>   endchoice
>   
> +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_32K
> +	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
> +	prompt "MMU Page Size"
> +	depends on BR2_ARCH_HAS_CONFIGURABLE_MMU_PAGE_SIZE
> +	help
> +	  Choose MMU page size
> +
> +config BR2_ARCH_MMU_PAGE_SIZE_4K
> +	bool "4K"
> +	depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_4K
> +
> +config BR2_ARCH_MMU_PAGE_SIZE_8K
> +	bool "8K"
> +	depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_8K
> +
> +config BR2_ARCH_MMU_PAGE_SIZE_16K
> +	bool "16K"
> +	depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_16K
> +
> +config BR2_ARCH_MMU_PAGE_SIZE_32K
> +	bool "32K"
> +	depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_32K
> +
> +config BR2_ARCH_MMU_PAGE_SIZE_64K
> +	bool "64K"
> +	depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_64K
> +endchoice
> +
> +config BR2_ARCH_MMU_PAGE_SIZE
> +	string
> +	default "4K" if BR2_ARCH_MMU_PAGE_SIZE_4K
> +	default "8K" if BR2_ARCH_MMU_PAGE_SIZE_4K
> +	default "16K" if BR2_ARCH_MMU_PAGE_SIZE_16K
> +	default "32K" if BR2_ARCH_MMU_PAGE_SIZE_32K
> +	default "64K" if BR2_ARCH_MMU_PAGE_SIZE_64K
> +
>   if BR2_arcle || BR2_arceb
>   source "arch/Config.in.arc"
>   endif
> diff --git a/arch/Config.in.arc b/arch/Config.in.arc
> index f7a6d920b5..c82a580c5b 100644
> --- a/arch/Config.in.arc
> +++ b/arch/Config.in.arc
> @@ -84,43 +84,5 @@ config BR2_READELF_ARCH_NAME
>   	default "ARCv2"		if BR2_archs38 || BR2_archs38_64mpy || BR2_archs38_full
>   	default "ARCv2"		if BR2_archs4x_rel31 || BR2_archs4x
>   
> -choice
> -	prompt "MMU Page Size"
> -	default BR2_ARC_PAGE_SIZE_8K

  This default is lost with this change. Since MMU_PAGE_SIZE is a choice, the 
only thing you can do really is add a per-architecture default in that choice.

> -	help
> -	  MMU starting from version 3 (found in ARC 770) and now
> -	  version 4 (found in ARC HS38) allows the selection of the
> -	  page size during ASIC design creation.
> -
> -	  The following options are available for MMU v3 and v4: 4kB,
> -	  8kB and 16 kB.
> -
> -	  The default is 8 kB (that really matches the only page size
> -	  in MMU v2).  It is important to build a toolchain with page
> -	  size matching the hardware configuration. Otherwise
> -	  user-space applications will fail at runtime.

  This help text is also lost, which is unfortunate.

> -
> -config BR2_ARC_PAGE_SIZE_4K

  When a user-selectable option is removed, legacy handling is required for it. 
See the documentation at the top of Config.in.legacy. For choices, that's a bit 
complicated...


> -	bool "4KB"
> -	depends on !BR2_arc750d

  This dependency is also lost.

  Since so much is lost with this generalisation, I think a better approach is 
to keep the user-visible MMU size selection architecture-specific, and restrict 
the generic part to blind symbols. So basically:

- BR2_ARCH_MMU_PAGE_SIZE_* become blind options;
- they're plain options, not in a choice;
- the only thing that changes in Config.in.arc is that the different options 
select one of BR2_ARCH_MMU_PAGE_SIZE_*;
- most of the .mk files don't need to be changed either (see below).

> -
> -config BR2_ARC_PAGE_SIZE_8K
> -	bool "8KB"
> -	help
> -	  This is the one and only option available for MMUv2 and
> -	  default value for MMU v3 and v4.
> -
> -config BR2_ARC_PAGE_SIZE_16K
> -	bool "16KB"
> -	depends on !BR2_arc750d
> -
> -endchoice
> -
> -config BR2_ARC_PAGE_SIZE
> -	string
> -	default "4K" if BR2_ARC_PAGE_SIZE_4K
> -	default "8K" if BR2_ARC_PAGE_SIZE_8K
> -	default "16K" if BR2_ARC_PAGE_SIZE_16K
> -
>   # vim: ft=kconfig
>   # -*- mode:kconfig; -*-
> diff --git a/arch/arch.mk.arc b/arch/arch.mk.arc
> index 32b818b0e0..a6b56a869f 100644
> --- a/arch/arch.mk.arc
> +++ b/arch/arch.mk.arc
> @@ -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
> diff --git a/linux/linux.mk b/linux/linux.mk
> index 61fdc0c76c..e66e0db52f 100644
> --- a/linux/linux.mk
> +++ b/linux/linux.mk
> @@ -328,18 +328,21 @@ define LINUX_KCONFIG_FIXUP_CMDS
>   		$(call KCONFIG_ENABLE_OPT,CONFIG_AEABI))
>   	$(if $(BR2_powerpc)$(BR2_powerpc64)$(BR2_powerpc64le),
>   		$(call KCONFIG_ENABLE_OPT,CONFIG_PPC_DISABLE_WERROR))
> -	$(if $(BR2_ARC_PAGE_SIZE_4K),
> -		$(call KCONFIG_ENABLE_OPT,CONFIG_ARC_PAGE_SIZE_4K)
> -		$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_8K)
> -		$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_16K))

  With my proposal, this can be kept as well. The kernel options are anyway 
arch-specific, so it's simpler to use the arch-specific boolean than the generic 
one.

> -	$(if $(BR2_ARC_PAGE_SIZE_8K),
> -		$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_4K)
> -		$(call KCONFIG_ENABLE_OPT,CONFIG_ARC_PAGE_SIZE_8K)
> -		$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_16K))
> -	$(if $(BR2_ARC_PAGE_SIZE_16K),
> -		$(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_ARCH_MMU_PAGE_SIZE_4K),
> +		$(if $(BR2_arcle)$(BR2_arcbe),
> +			$(call KCONFIG_ENABLE_OPT,CONFIG_ARC_PAGE_SIZE_4K)
> +			$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_8K)
> +			$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_16K)))
> +	$(if $(BR2_ARCH_MMU_PAGE_SIZE_8K),
> +		$(if $(BR2_arcle)$(BR2_arcbe),
> +			$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_4K)
> +			$(call KCONFIG_ENABLE_OPT,CONFIG_ARC_PAGE_SIZE_8K)
> +			$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_16K)))
> +	$(if $(BR2_ARCH_MMU_PAGE_SIZE_16K),
> +		$(if $(BR2_arcle)$(BR2_arcbe),
> +			$(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_TARGET_ROOTFS_CPIO),
>   		$(call KCONFIG_ENABLE_OPT,CONFIG_BLK_DEV_INITRD))
>   	# As the kernel gets compiled before root filesystems are
> diff --git a/package/uclibc/uclibc.mk b/package/uclibc/uclibc.mk
> index 87e283de2a..e6699b74b8 100644
> --- a/package/uclibc/uclibc.mk
> +++ b/package/uclibc/uclibc.mk
> @@ -78,7 +78,7 @@ endif
>   #
>   
>   ifeq ($(UCLIBC_TARGET_ARCH),arc)
> -UCLIBC_ARC_PAGE_SIZE = CONFIG_ARC_PAGE_SIZE_$(call qstrip,$(BR2_ARC_PAGE_SIZE))
> +UCLIBC_ARC_PAGE_SIZE = CONFIG_ARCH_MMU_PAGE_SIZE_$(call qstrip,$(BR2_ARCH_MMU_PAGE_SIZE))

  This is also only for ARC so can stay as is. Which means that 
BR2_ARCH_MMU_PAGE_SIZE can be removed as well.

>   define UCLIBC_ARC_PAGE_SIZE_CONFIG
>   	$(SED) '/CONFIG_ARC_PAGE_SIZE_*/d' $(@D)/.config
>   	$(call KCONFIG_ENABLE_OPT,$(UCLIBC_ARC_PAGE_SIZE))
> diff --git a/toolchain/toolchain-wrapper.mk b/toolchain/toolchain-wrapper.mk
> index 8b551e3a18..a8564441b5 100644
> --- a/toolchain/toolchain-wrapper.mk
> +++ b/toolchain/toolchain-wrapper.mk
> @@ -90,3 +90,16 @@ define TOOLCHAIN_WRAPPER_INSTALL
>   	$(INSTALL) -D -m 0755 $(@D)/toolchain-wrapper \
>   		$(HOST_DIR)/bin/toolchain-wrapper
>   endef
> +
> +# Explicitly set LD's "max-page-size" instead of relying on some defaults
> +ifeq ($(BR2_ARCH_MMU_PAGE_SIZE_4K),y)
> +ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=4096
> +else ifeq ($(BR2_ARCH_MMU_PAGE_SIZE_8K),y)
> +ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=8192
> +else ifeq ($(BR2_ARCH_MMU_PAGE_SIZE_16K),y)
> +ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=16384
> +else ifeq ($(BR2_ARCH_MMU_PAGE_SIZE_32K),y)
> +ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=32768
> +else ifeq ($(BR2_ARCH_MMU_PAGE_SIZE_64K),y)
> +ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=65536
> +endif

  This is the only generic part that would remain.


  Regards,
  Arnout
Yann E. MORIN Dec. 6, 2021, 9:23 p.m. UTC | #2
Arnout, All,

On 2021-12-06 21:30 +0100, Arnout Vandecappelle spake thusly:
>  Thank you for this patch! Since it's a bit an invasive feature, it might
> not get merged easily.

Yeah, I have already been looking into it, and will do a proper review
"asap". In the meantime, the easy low-hanging fruits, see below...

> On 06/12/2021 20:27, Łukasz Stelmach wrote:
> >Rename BR2_ARC_PAGE_SIZE_* to BR2_ARCH_MMU_PAGE_SIZE_* options.
> 
>  My first reaction was: this is probably going to be limited to a very small
> number of architectures, so maybe it shouldn't be a generic option

I was the one to ask for a generic solution, since Łukasz' v1 was
basically duplicating the code from arc to arm.

> (especially since the kernel config changes are anyway still arch specific).
> However, it turns out that mips, powerpc and sh also support several page
> sizes (as well as a few other arches that we don't support). And I can
> imagine that riscv may get this feature at some point as well. So, the
> generic approach is probably right after all.

Yeah, that was also my (inner-mind) analysis which prompted the generic
solution.

> >Add BR2_ARCH_HAS_CONFIGURABLE_MMU_PAGE_SIZE and
> >BR2_ARCH_HAS_MMU_PAGE_SIZE_* to control configuration option dependencies
> >and visibility.
> >
> >Adapt existing ARC page size selection.
> >
> >Suggested-by: Yann E. MORIN <yann.morin.1998@free.fr>
> >Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
> >---
> >  arch/Config.in                 | 64 ++++++++++++++++++++++++++++++++++
> >  arch/Config.in.arc             | 38 --------------------
> >  arch/arch.mk.arc               |  9 -----
> >  linux/linux.mk                 | 27 +++++++-------
> >  package/uclibc/uclibc.mk       |  2 +-
> >  toolchain/toolchain-wrapper.mk | 13 +++++++
> >  6 files changed, 93 insertions(+), 60 deletions(-)
> >
> >diff --git a/arch/Config.in b/arch/Config.in
> >index 1853e26bb4..561d599561 100644
> >--- a/arch/Config.in
> >+++ b/arch/Config.in
> >@@ -24,6 +24,9 @@ choice
> >  config BR2_arcle
> >  	bool "ARC (little endian)"
> >  	select BR2_ARCH_HAS_MMU_MANDATORY
> >+	select BR2_ARCH_HAS_MMU_PAGE_SIZE_4K

The arc750d does not support 4K or 16K page sizes. So, as I suggested in
the review of v1, the above should be:

    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

(ditto for BR2_arceb)

> >+	select BR2_ARCH_HAS_MMU_PAGE_SIZE_8K
> >+	select BR2_ARCH_HAS_MMU_PAGE_SIZE_16K
> >  	help
> >  	  Synopsys' DesignWare ARC Processor Cores are a family of
> >  	  32-bit CPUs that can be used from deeply embedded to high
> >@@ -32,6 +35,9 @@ config BR2_arcle
> >  config BR2_arceb
> >  	bool "ARC (big endian)"
> >  	select BR2_ARCH_HAS_MMU_MANDATORY
> >+	select BR2_ARCH_HAS_MMU_PAGE_SIZE_4K
> >+	select BR2_ARCH_HAS_MMU_PAGE_SIZE_8K
> >+	select BR2_ARCH_HAS_MMU_PAGE_SIZE_16K
> >  	help
> >  	  Synopsys' DesignWare ARC Processor Cores are a family of
> >  	  32-bit CPUs that can be used from deeply embedded to high
> >@@ -426,6 +432,64 @@ config BR2_BINFMT_FLAT_SHARED
> >  endchoice
> >+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_32K
> >+	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

Limit the churn in this patach by just making the transition from arc to
generic options.

We can add more entries (32K, 64K) when we make an new architecture use
it. For example, next patch would add 64K for Aarch64 (32K would still
not be introduced because Aarch64 does not have 64K pages).

> >+choice
> >+	prompt "MMU Page Size"
> >+	depends on BR2_ARCH_HAS_CONFIGURABLE_MMU_PAGE_SIZE
> >+	help
> >+	  Choose MMU page size
> >+
> >+config BR2_ARCH_MMU_PAGE_SIZE_4K
> >+	bool "4K"
> >+	depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_4K
> >+
> >+config BR2_ARCH_MMU_PAGE_SIZE_8K
> >+	bool "8K"
> >+	depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_8K
> >+
> >+config BR2_ARCH_MMU_PAGE_SIZE_16K
> >+	bool "16K"
> >+	depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_16K
> >+
> >+config BR2_ARCH_MMU_PAGE_SIZE_32K
> >+	bool "32K"
> >+	depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_32K
> >+
> >+config BR2_ARCH_MMU_PAGE_SIZE_64K
> >+	bool "64K"
> >+	depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_64K
> >+endchoice
> >+
> >+config BR2_ARCH_MMU_PAGE_SIZE
> >+	string
> >+	default "4K" if BR2_ARCH_MMU_PAGE_SIZE_4K
> >+	default "8K" if BR2_ARCH_MMU_PAGE_SIZE_4K
> >+	default "16K" if BR2_ARCH_MMU_PAGE_SIZE_16K
> >+	default "32K" if BR2_ARCH_MMU_PAGE_SIZE_32K
> >+	default "64K" if BR2_ARCH_MMU_PAGE_SIZE_64K
> >+
> >  if BR2_arcle || BR2_arceb
> >  source "arch/Config.in.arc"
> >  endif
> >diff --git a/arch/Config.in.arc b/arch/Config.in.arc
> >index f7a6d920b5..c82a580c5b 100644
> >--- a/arch/Config.in.arc
> >+++ b/arch/Config.in.arc
> >@@ -84,43 +84,5 @@ config BR2_READELF_ARCH_NAME
> >  	default "ARCv2"		if BR2_archs38 || BR2_archs38_64mpy || BR2_archs38_full
> >  	default "ARCv2"		if BR2_archs4x_rel31 || BR2_archs4x
> >-choice
> >-	prompt "MMU Page Size"

We do not use 'prompt' but we do define the type and use that to define
the prompt:

    choice
        bool "MMU Page Size"

> >-	default BR2_ARC_PAGE_SIZE_8K
> 
>  This default is lost with this change. Since MMU_PAGE_SIZE is a choice, the
> only thing you can do really is add a per-architecture default in that
> choice.

This default thing is a bit difficult to handle nicely.

If we wnated to add proper infra for it, we'd need to introduce
BR2_ARCH_MMU_PREFERS_4K or BR2_ARCH_MMU_PREFERS_8K and so on:

    config BR2_ARCH_MMU_PREFERS_4K
        bool
        # To force selector to also depend on it:
        depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_4K

    config BR2_ARCH_MMU_PREFERS_8K
        bool
        # To force selector to also depend on it:
        depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_8K

which would be used like:

    config BR2_arcle
        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
        select BR2_ARCH_MMU_PREFERS_8K

And then that would be used in the choice:

    choice
        bool "MMU Page Size"
        default BR2_ARCH_MMU_PAGE_SIZE_4K if BR2_ARCH_MMU_PREFERS_4K
        default BR2_ARCH_MMU_PAGE_SIZE_8K if BR2_ARCH_MMU_PREFERS_8K
        # and so on...

    [...]

    endchoice

> >-	help
> >-	  MMU starting from version 3 (found in ARC 770) and now
> >-	  version 4 (found in ARC HS38) allows the selection of the
> >-	  page size during ASIC design creation.
> >-
> >-	  The following options are available for MMU v3 and v4: 4kB,
> >-	  8kB and 16 kB.
> >-
> >-	  The default is 8 kB (that really matches the only page size
> >-	  in MMU v2).  It is important to build a toolchain with page
> >-	  size matching the hardware configuration. Otherwise
> >-	  user-space applications will fail at runtime.
> 
>  This help text is also lost, which is unfortunate.
> 
> >-
> >-config BR2_ARC_PAGE_SIZE_4K
> 
>  When a user-selectable option is removed, legacy handling is required for
> it. See the documentation at the top of Config.in.legacy. For choices,
> that's a bit complicated...

Yeah, that's not totally easy, but we already have a few cases...

> >-	bool "4KB"
> >-	depends on !BR2_arc750d
> 
>  This dependency is also lost.
> 
>  Since so much is lost with this generalisation, I think a better approach
> is to keep the user-visible MMU size selection architecture-specific, and
> restrict the generic part to blind symbols. So basically:
> 
> - BR2_ARCH_MMU_PAGE_SIZE_* become blind options;
> - they're plain options, not in a choice;
> - the only thing that changes in Config.in.arc is that the different options
> select one of BR2_ARCH_MMU_PAGE_SIZE_*;
> - most of the .mk files don't need to be changed either (see below).

Hmm...

> >-config BR2_ARC_PAGE_SIZE_8K
> >-	bool "8KB"
> >-	help
> >-	  This is the one and only option available for MMUv2 and
> >-	  default value for MMU v3 and v4.
> >-
> >-config BR2_ARC_PAGE_SIZE_16K
> >-	bool "16KB"
> >-	depends on !BR2_arc750d
> >-
> >-endchoice
> >-
> >-config BR2_ARC_PAGE_SIZE
> >-	string
> >-	default "4K" if BR2_ARC_PAGE_SIZE_4K
> >-	default "8K" if BR2_ARC_PAGE_SIZE_8K
> >-	default "16K" if BR2_ARC_PAGE_SIZE_16K
> >-
> >  # vim: ft=kconfig
> >  # -*- mode:kconfig; -*-
> >diff --git a/arch/arch.mk.arc b/arch/arch.mk.arc
> >index 32b818b0e0..a6b56a869f 100644
> >--- a/arch/arch.mk.arc
> >+++ b/arch/arch.mk.arc
> >@@ -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
> >diff --git a/linux/linux.mk b/linux/linux.mk
> >index 61fdc0c76c..e66e0db52f 100644
> >--- a/linux/linux.mk
> >+++ b/linux/linux.mk
> >@@ -328,18 +328,21 @@ define LINUX_KCONFIG_FIXUP_CMDS
> >  		$(call KCONFIG_ENABLE_OPT,CONFIG_AEABI))
> >  	$(if $(BR2_powerpc)$(BR2_powerpc64)$(BR2_powerpc64le),
> >  		$(call KCONFIG_ENABLE_OPT,CONFIG_PPC_DISABLE_WERROR))
> >-	$(if $(BR2_ARC_PAGE_SIZE_4K),
> >-		$(call KCONFIG_ENABLE_OPT,CONFIG_ARC_PAGE_SIZE_4K)
> >-		$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_8K)
> >-		$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_16K))
> 
>  With my proposal, this can be kept as well. The kernel options are anyway
> arch-specific, so it's simpler to use the arch-specific boolean than the
> generic one.

Actually, I think this huge list should move to the individual
architectures.

Like we have a mean for packages to provide kernel options, we should
introduce the same for architectures.

This way, it becomes easier to maintain (I think) rather than this huge
mess...

> >-	$(if $(BR2_ARC_PAGE_SIZE_8K),
> >-		$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_4K)
> >-		$(call KCONFIG_ENABLE_OPT,CONFIG_ARC_PAGE_SIZE_8K)
> >-		$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_16K))
> >-	$(if $(BR2_ARC_PAGE_SIZE_16K),
> >-		$(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_ARCH_MMU_PAGE_SIZE_4K),
> >+		$(if $(BR2_arcle)$(BR2_arcbe),
> >+			$(call KCONFIG_ENABLE_OPT,CONFIG_ARC_PAGE_SIZE_4K)
> >+			$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_8K)
> >+			$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_16K)))
> >+	$(if $(BR2_ARCH_MMU_PAGE_SIZE_8K),
> >+		$(if $(BR2_arcle)$(BR2_arcbe),
> >+			$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_4K)
> >+			$(call KCONFIG_ENABLE_OPT,CONFIG_ARC_PAGE_SIZE_8K)
> >+			$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_16K)))
> >+	$(if $(BR2_ARCH_MMU_PAGE_SIZE_16K),
> >+		$(if $(BR2_arcle)$(BR2_arcbe),
> >+			$(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_TARGET_ROOTFS_CPIO),
> >  		$(call KCONFIG_ENABLE_OPT,CONFIG_BLK_DEV_INITRD))
> >  	# As the kernel gets compiled before root filesystems are
> >diff --git a/package/uclibc/uclibc.mk b/package/uclibc/uclibc.mk
> >index 87e283de2a..e6699b74b8 100644
> >--- a/package/uclibc/uclibc.mk
> >+++ b/package/uclibc/uclibc.mk
> >@@ -78,7 +78,7 @@ endif
> >  #
> >  ifeq ($(UCLIBC_TARGET_ARCH),arc)
> >-UCLIBC_ARC_PAGE_SIZE = CONFIG_ARC_PAGE_SIZE_$(call qstrip,$(BR2_ARC_PAGE_SIZE))
> >+UCLIBC_ARC_PAGE_SIZE = CONFIG_ARCH_MMU_PAGE_SIZE_$(call qstrip,$(BR2_ARCH_MMU_PAGE_SIZE))
> 
>  This is also only for ARC so can stay as is. Which means that
> BR2_ARCH_MMU_PAGE_SIZE can be removed as well.
> 
> >  define UCLIBC_ARC_PAGE_SIZE_CONFIG
> >  	$(SED) '/CONFIG_ARC_PAGE_SIZE_*/d' $(@D)/.config
> >  	$(call KCONFIG_ENABLE_OPT,$(UCLIBC_ARC_PAGE_SIZE))
> >diff --git a/toolchain/toolchain-wrapper.mk b/toolchain/toolchain-wrapper.mk
> >index 8b551e3a18..a8564441b5 100644
> >--- a/toolchain/toolchain-wrapper.mk
> >+++ b/toolchain/toolchain-wrapper.mk
> >@@ -90,3 +90,16 @@ define TOOLCHAIN_WRAPPER_INSTALL
> >  	$(INSTALL) -D -m 0755 $(@D)/toolchain-wrapper \
> >  		$(HOST_DIR)/bin/toolchain-wrapper
> >  endef
> >+
> >+# Explicitly set LD's "max-page-size" instead of relying on some defaults
> >+ifeq ($(BR2_ARCH_MMU_PAGE_SIZE_4K),y)
> >+ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=4096
> >+else ifeq ($(BR2_ARCH_MMU_PAGE_SIZE_8K),y)
> >+ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=8192
> >+else ifeq ($(BR2_ARCH_MMU_PAGE_SIZE_16K),y)
> >+ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=16384
> >+else ifeq ($(BR2_ARCH_MMU_PAGE_SIZE_32K),y)
> >+ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=32768
> >+else ifeq ($(BR2_ARCH_MMU_PAGE_SIZE_64K),y)
> >+ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=65536
> >+endif
> 
>  This is the only generic part that would remain.

Yeah, I think this is probably a good middle grund, in the end...

Regards,
Yann E. MORIN.
Arnout Vandecappelle Dec. 6, 2021, 9:33 p.m. UTC | #3
On 06/12/2021 22:23, Yann E. MORIN wrote:
>>> diff --git a/linux/linux.mk b/linux/linux.mk
>>> index 61fdc0c76c..e66e0db52f 100644
>>> --- a/linux/linux.mk
>>> +++ b/linux/linux.mk
>>> @@ -328,18 +328,21 @@ define LINUX_KCONFIG_FIXUP_CMDS
>>>   		$(call KCONFIG_ENABLE_OPT,CONFIG_AEABI))
>>>   	$(if $(BR2_powerpc)$(BR2_powerpc64)$(BR2_powerpc64le),
>>>   		$(call KCONFIG_ENABLE_OPT,CONFIG_PPC_DISABLE_WERROR))
>>> -	$(if $(BR2_ARC_PAGE_SIZE_4K),
>>> -		$(call KCONFIG_ENABLE_OPT,CONFIG_ARC_PAGE_SIZE_4K)
>>> -		$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_8K)
>>> -		$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_16K))
>>   With my proposal, this can be kept as well. The kernel options are anyway
>> arch-specific, so it's simpler to use the arch-specific boolean than the
>> generic one.
> Actually, I think this huge list should move to the individual
> architectures.
> 
> Like we have a mean for packages to provide kernel options, we should
> introduce the same for architectures.
> 
> This way, it becomes easier to maintain (I think) rather than this huge
> mess...

  At the moment, there are just 3 architecture-specific kernel options: AEABI, 
POWERPC_DISABLE_WERROR, and ARC_PAGE_SIZE_*. Not exactly a huge mess IMHO. And 
also IMHO, moving it to arch just increases the mess: for packages, the kernel 
option usually have to be set whenever the package is selected, so 
FOO_LINUX_CONFIG_FIXUPS can work. However, for the arch-specific fixups, they're 
always conditional on something else than the mere arch, so you still need 
conditionals in there... You could indeed add them to 
PACKAGES_LINUX_CONFIG_FIXUPS directly in the arch.mk, but in terms of lines of 
code it really doesn't look better. Also in terms of keeping things together 
it's not better: this is something related to both linux and arch, so you can't 
ever put it in the "correct" place.

  Regards,
  Arnout
Łukasz Stelmach Dec. 6, 2021, 10:26 p.m. UTC | #4
It was <2021-12-06 pon 22:23>, when Yann E. MORIN wrote:
> Arnout, All,
>
> On 2021-12-06 21:30 +0100, Arnout Vandecappelle spake thusly:
>>  Thank you for this patch! Since it's a bit an invasive feature, it might
>> not get merged easily.
>
> Yeah, I have already been looking into it, and will do a proper review
> "asap". In the meantime, the easy low-hanging fruits, see below...
>

No need for asap at all (-; These patches are a byproduct of my work
where I use BR. I am willing to make them mergeable, but I can't work on
them full-time and I will be more than grateful for your detailed
advice. I am completely new here and know next to nothing about BR
concepts of doing stuff.

Kind regards,
diff mbox series

Patch

diff --git a/arch/Config.in b/arch/Config.in
index 1853e26bb4..561d599561 100644
--- a/arch/Config.in
+++ b/arch/Config.in
@@ -24,6 +24,9 @@  choice
 config BR2_arcle
 	bool "ARC (little endian)"
 	select BR2_ARCH_HAS_MMU_MANDATORY
+	select BR2_ARCH_HAS_MMU_PAGE_SIZE_4K
+	select BR2_ARCH_HAS_MMU_PAGE_SIZE_8K
+	select BR2_ARCH_HAS_MMU_PAGE_SIZE_16K
 	help
 	  Synopsys' DesignWare ARC Processor Cores are a family of
 	  32-bit CPUs that can be used from deeply embedded to high
@@ -32,6 +35,9 @@  config BR2_arcle
 config BR2_arceb
 	bool "ARC (big endian)"
 	select BR2_ARCH_HAS_MMU_MANDATORY
+	select BR2_ARCH_HAS_MMU_PAGE_SIZE_4K
+	select BR2_ARCH_HAS_MMU_PAGE_SIZE_8K
+	select BR2_ARCH_HAS_MMU_PAGE_SIZE_16K
 	help
 	  Synopsys' DesignWare ARC Processor Cores are a family of
 	  32-bit CPUs that can be used from deeply embedded to high
@@ -426,6 +432,64 @@  config BR2_BINFMT_FLAT_SHARED
 
 endchoice
 
+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_32K
+	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
+	prompt "MMU Page Size"
+	depends on BR2_ARCH_HAS_CONFIGURABLE_MMU_PAGE_SIZE
+	help
+	  Choose MMU page size
+
+config BR2_ARCH_MMU_PAGE_SIZE_4K
+	bool "4K"
+	depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_4K
+
+config BR2_ARCH_MMU_PAGE_SIZE_8K
+	bool "8K"
+	depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_8K
+
+config BR2_ARCH_MMU_PAGE_SIZE_16K
+	bool "16K"
+	depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_16K
+
+config BR2_ARCH_MMU_PAGE_SIZE_32K
+	bool "32K"
+	depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_32K
+
+config BR2_ARCH_MMU_PAGE_SIZE_64K
+	bool "64K"
+	depends on BR2_ARCH_HAS_MMU_PAGE_SIZE_64K
+endchoice
+
+config BR2_ARCH_MMU_PAGE_SIZE
+	string
+	default "4K" if BR2_ARCH_MMU_PAGE_SIZE_4K
+	default "8K" if BR2_ARCH_MMU_PAGE_SIZE_4K
+	default "16K" if BR2_ARCH_MMU_PAGE_SIZE_16K
+	default "32K" if BR2_ARCH_MMU_PAGE_SIZE_32K
+	default "64K" if BR2_ARCH_MMU_PAGE_SIZE_64K
+
 if BR2_arcle || BR2_arceb
 source "arch/Config.in.arc"
 endif
diff --git a/arch/Config.in.arc b/arch/Config.in.arc
index f7a6d920b5..c82a580c5b 100644
--- a/arch/Config.in.arc
+++ b/arch/Config.in.arc
@@ -84,43 +84,5 @@  config BR2_READELF_ARCH_NAME
 	default "ARCv2"		if BR2_archs38 || BR2_archs38_64mpy || BR2_archs38_full
 	default "ARCv2"		if BR2_archs4x_rel31 || BR2_archs4x
 
-choice
-	prompt "MMU Page Size"
-	default BR2_ARC_PAGE_SIZE_8K
-	help
-	  MMU starting from version 3 (found in ARC 770) and now
-	  version 4 (found in ARC HS38) allows the selection of the
-	  page size during ASIC design creation.
-
-	  The following options are available for MMU v3 and v4: 4kB,
-	  8kB and 16 kB.
-
-	  The default is 8 kB (that really matches the only page size
-	  in MMU v2).  It is important to build a toolchain with page
-	  size matching the hardware configuration. Otherwise
-	  user-space applications will fail at runtime.
-
-config BR2_ARC_PAGE_SIZE_4K
-	bool "4KB"
-	depends on !BR2_arc750d
-
-config BR2_ARC_PAGE_SIZE_8K
-	bool "8KB"
-	help
-	  This is the one and only option available for MMUv2 and
-	  default value for MMU v3 and v4.
-
-config BR2_ARC_PAGE_SIZE_16K
-	bool "16KB"
-	depends on !BR2_arc750d
-
-endchoice
-
-config BR2_ARC_PAGE_SIZE
-	string
-	default "4K" if BR2_ARC_PAGE_SIZE_4K
-	default "8K" if BR2_ARC_PAGE_SIZE_8K
-	default "16K" if BR2_ARC_PAGE_SIZE_16K
-
 # vim: ft=kconfig
 # -*- mode:kconfig; -*-
diff --git a/arch/arch.mk.arc b/arch/arch.mk.arc
index 32b818b0e0..a6b56a869f 100644
--- a/arch/arch.mk.arc
+++ b/arch/arch.mk.arc
@@ -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
diff --git a/linux/linux.mk b/linux/linux.mk
index 61fdc0c76c..e66e0db52f 100644
--- a/linux/linux.mk
+++ b/linux/linux.mk
@@ -328,18 +328,21 @@  define LINUX_KCONFIG_FIXUP_CMDS
 		$(call KCONFIG_ENABLE_OPT,CONFIG_AEABI))
 	$(if $(BR2_powerpc)$(BR2_powerpc64)$(BR2_powerpc64le),
 		$(call KCONFIG_ENABLE_OPT,CONFIG_PPC_DISABLE_WERROR))
-	$(if $(BR2_ARC_PAGE_SIZE_4K),
-		$(call KCONFIG_ENABLE_OPT,CONFIG_ARC_PAGE_SIZE_4K)
-		$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_8K)
-		$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_16K))
-	$(if $(BR2_ARC_PAGE_SIZE_8K),
-		$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_4K)
-		$(call KCONFIG_ENABLE_OPT,CONFIG_ARC_PAGE_SIZE_8K)
-		$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_16K))
-	$(if $(BR2_ARC_PAGE_SIZE_16K),
-		$(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_ARCH_MMU_PAGE_SIZE_4K),
+		$(if $(BR2_arcle)$(BR2_arcbe),
+			$(call KCONFIG_ENABLE_OPT,CONFIG_ARC_PAGE_SIZE_4K)
+			$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_8K)
+			$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_16K)))
+	$(if $(BR2_ARCH_MMU_PAGE_SIZE_8K),
+		$(if $(BR2_arcle)$(BR2_arcbe),
+			$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_4K)
+			$(call KCONFIG_ENABLE_OPT,CONFIG_ARC_PAGE_SIZE_8K)
+			$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_16K)))
+	$(if $(BR2_ARCH_MMU_PAGE_SIZE_16K),
+		$(if $(BR2_arcle)$(BR2_arcbe),
+			$(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_TARGET_ROOTFS_CPIO),
 		$(call KCONFIG_ENABLE_OPT,CONFIG_BLK_DEV_INITRD))
 	# As the kernel gets compiled before root filesystems are
diff --git a/package/uclibc/uclibc.mk b/package/uclibc/uclibc.mk
index 87e283de2a..e6699b74b8 100644
--- a/package/uclibc/uclibc.mk
+++ b/package/uclibc/uclibc.mk
@@ -78,7 +78,7 @@  endif
 #
 
 ifeq ($(UCLIBC_TARGET_ARCH),arc)
-UCLIBC_ARC_PAGE_SIZE = CONFIG_ARC_PAGE_SIZE_$(call qstrip,$(BR2_ARC_PAGE_SIZE))
+UCLIBC_ARC_PAGE_SIZE = CONFIG_ARCH_MMU_PAGE_SIZE_$(call qstrip,$(BR2_ARCH_MMU_PAGE_SIZE))
 define UCLIBC_ARC_PAGE_SIZE_CONFIG
 	$(SED) '/CONFIG_ARC_PAGE_SIZE_*/d' $(@D)/.config
 	$(call KCONFIG_ENABLE_OPT,$(UCLIBC_ARC_PAGE_SIZE))
diff --git a/toolchain/toolchain-wrapper.mk b/toolchain/toolchain-wrapper.mk
index 8b551e3a18..a8564441b5 100644
--- a/toolchain/toolchain-wrapper.mk
+++ b/toolchain/toolchain-wrapper.mk
@@ -90,3 +90,16 @@  define TOOLCHAIN_WRAPPER_INSTALL
 	$(INSTALL) -D -m 0755 $(@D)/toolchain-wrapper \
 		$(HOST_DIR)/bin/toolchain-wrapper
 endef
+
+# Explicitly set LD's "max-page-size" instead of relying on some defaults
+ifeq ($(BR2_ARCH_MMU_PAGE_SIZE_4K),y)
+ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=4096
+else ifeq ($(BR2_ARCH_MMU_PAGE_SIZE_8K),y)
+ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=8192
+else ifeq ($(BR2_ARCH_MMU_PAGE_SIZE_16K),y)
+ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=16384
+else ifeq ($(BR2_ARCH_MMU_PAGE_SIZE_32K),y)
+ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=32768
+else ifeq ($(BR2_ARCH_MMU_PAGE_SIZE_64K),y)
+ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=65536
+endif