From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796089969; b=QJ0AZOKNGMWhZyWpOXqGwaK+cRUu4GAdYr8VYGAceWUZeJRYbWODstFMhonRXEdVHmG9 /ZY2JOsNipyAuoa82q1O7O0ms3/q4SmJusb6baGE3QT7Z7LyWbs/h68AOaBZyK15dolkb Fk97GSrYt47hPt7C2vvW/xN834Yo4PFQJc+M/mH7lNe8Mp8SEP2EunmE5oJfNrF/IIJhZ 4kJZWChPgtg/Wj4IKgtSwxMTf1OEGIeUPk/pqG66hXvVSGfYKNdpVlOLeifpnVHR4qnQ+ vidr3pBD6fii3aK9VCexO8ULRKJP9uX+TwMw7+HQPt9vI1IU73Vt+ZHBDcNpzWEZFNA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796089969; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=efIrByk7hVkQpPW21t2WgZXcVBMWY+aGTb/Tz+E4oMM=; b=Vmpncuvh+UozvCWpKe12cIy7jpt5N+OEQY1T1yQASane3bU2nGXyf1U1IF2Xvg24ZWeS OEE2U/G/fDSZbsglNis3ln6r/7D9youNUJPP8OUsBof29N5DoVQ64nb2FiHb33j8Jq5yb TBY90rsY3/MlKu3bEQ6LX1NqUAeB4H0joRe6KKFSaiJGh6u7SSwAGGzX6ibT6z8vGyQRd UynU0sGWubxb+fsEievDLOBUA6jHLAanGJrifT1qpSAY914xMkq0f3saYVpNfPD2h8Fh2 +gs1nhX5DCx3aBKMgJgMW06C6y+7sfSh+5dwPKX1iD0H2U1DVW+YrfbhfvU8UYkQNAw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Er2QWy15; arc=none smtp.remote-ip=209.85.128.50 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 641CE606A32A for ; Tue, 1 Dec 2026 01:52:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 641CE606A32A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Er2QWy15 Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4bb6ba3b244so115010785e9.3 for ; Mon, 30 Nov 2026 17:52:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796089967; x=1796694767; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=efIrByk7hVkQpPW21t2WgZXcVBMWY+aGTb/Tz+E4oMM=; b=Er2QWy15EiuA9CBaRzEgb4z2e4vLApH8BJgOJi7R+ZmaYYn2UGn1eJSrP7tJvhtfhd Pk4irf5xhBVVqqGudmnQJKyhvFUAVLIlKk1GM6YCgahuoQxH+UyLnqjfnr61uu5T77iU 8GMiiGQZn7Lsd21LpXGLkq1BWetzAVMUAgsBE7h/xchggaaIGmj2YPZyQZ4KCwStuzg0 WdabL3roZ5VR8UjJpdUSD47Ih1HuzL/Ybk+l6h5/DAyfkBAa9vrzxGnCeI0eeH+bOqvr +iDR5e6LsmWFKEthA4MtBsKubx/+FJuWQqi6EN/pPIqE3x2e8F1Od5TCVtcFk3ylCzzL GDWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796089967; x=1796694767; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=efIrByk7hVkQpPW21t2WgZXcVBMWY+aGTb/Tz+E4oMM=; b=VbCqkc8ut/t5Kzzjn8uTUIYikMeaYP8K0NAIovsWzPduHvjd9cMDE2Qbv1YZarvP+m bdWhsUnVLi1XNxzfsF6nqPZGKCtCLdF8SpKzLYy/hse+yIwXN6RF1Wpg1zgJEvjQ1DRM 2Y4d3rh8Hav1p+BOVZMEE+o/i+EW4bgJO76d2uVuaHLKYSntt/w1SExUInV/TCxT7RE1 pf4v35RqNIx/goeszZ4bSPVLuTHgiqrVEk71FEdIcO7dQqpIxyLUjz3Em03BQn6nPrSp w+3kCqxYPXMeJLwrHFs0BouFSHPtvLW4gac2oaxOSfvjD/co/OwQrKdBgAPoC6cNY0OK tZ0w== X-Forwarded-Encrypted: i=1; AL+hErHZyRZuJfEKaUsdzeyRWqeFAz9MU1ffmy6QgmVM3pkx4a2MqCXl0EFv4IIVsfmdbg6NLQC+UnMcQBFdJ+8=@vger.kernel.org X-Gm-Message-State: APuU4Z+2gPsGHlzyUzsd+i8NCNeRU+AhoR6He3Y7H1w4aDlE2PDCZ0MM QTP3BbX7SRnXrXl0kZZTCRu49k0ubUQCj9w1uXRUKjNr3H+TXjxMlYxb X-Gm-Gg: AZFdTZdrS8XkBcTsyvULAE16us4kkUuOq0sn6j6vMm8liEE4w6ocVoVPTTAHKHFASG4 2XmdWjuUoUq/ZErwxLQLTW0Nr2yO2VvAhQIuBmDitrY6l6EFEQ/9A8ZX2dtbov8Xy3vYMpi4/Y2 0kD8eBYPXqI3AHRV3uxALIK5LtVVpk9qXnfCaPLNC3OetJ2gJPZzoLbpZKw1TQ+7pWeHSjsuv4J qT3BcoLSuPglFOe8jYnwk3XcqOJePD2X+u/xAwYJfoPR3vKHa4tv7yaTa8IjkrGgRTSYKwv1JhF RPJF/wCfq9anz3d+qVhk48NXH3ALB/+EW5OIC8nw99csQiYyKjnVDpAMAyiRtc5yAgA8wwPHotH iNIjqOe5p85uHzHQBKO3jcuaHR6NUOyOsNjNPD+cWg9+Zi01pDhNcLHOBuVa/EUQa+El6sekLBN 3aJfzAZ8ItjDkqxB8NavutROWmfAyEu44z+5XvnUjJEMd1Jm50K9UIVfllD0RTtIfqkDGEXk+9T jJey9438KjaQ7ECrAm2UfTlqwQ7h3ENVIijEczktn0F+Jntwk0MKOzMeNcfB23b4pvvMNYkBEaq JBq7XErBOM8483ilcIqTu9qPeAw0ZVOW56g/Pg== X-Received: by 2002:a05:600d:1c:b0:4a4:fc8c:cfd9 with SMTP id 5b1f17b1804b1-4bb9de0d5ffmr429905535e9.25.1796089966590; Mon, 30 Nov 2026 17:52:46 -0800 (PST) Received: from NULL.Home.net ([2001:8a0:7280:4000:12d:c3b9:cecc:8966]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb884911e3sm1199037055e9.6.2026.11.30.17.52.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 17:52:45 -0800 (PST) From: Eric Curtin To: linux-arm-kernel@lists.infradead.org Cc: Ryan Roberts , Catalin Marinas , Will Deacon , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Subject: [RFC PATCH v2 01/43] mm: Add macros ahead of supporting boot-time page size selection Date: Tue, 1 Dec 2026 01:51:33 +0000 Message-ID: <20261201015240.1017259-2-ericcurtin17@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201015240.1017259-1-ericcurtin17@gmail.com> References: <20261201015240.1017259-1-ericcurtin17@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Ryan Roberts arm64 can support several base page sizes. To let the page size be chosen on the kernel command line instead of at build time, PAGE_SHIFT, PAGE_SIZE and PAGE_MASK can no longer be compile-time constants, and code that needs a constant has to be converted. Introduce PAGE_{SHIFT,SIZE,MASK}_{MIN,MAX}, which bound the range of possible page sizes and are always compile-time constants. An arch must define all of them or none. When it defines none, they are set equal to PAGE_SHIFT, PAGE_SIZE and PAGE_MASK, so existing behaviour is unchanged. Introduce DEFINE_GLOBAL_PAGE_SIZE_VAR(), _CONST() and _ATTR() to wrap definitions of globals whose initialiser depends on PAGE_SIZE. With a fixed page size they expand to a plain definition. With a boot-time page size the variable is assigned by a function marked with the constructor attribute. Constructors are used rather than initcalls because a module is limited to one initcall but may have any number of constructors. To make this work, call do_ctors() early in start_kernel() instead of from do_basic_setup(), and run module constructors before module parameters are parsed so that the parameters can override the defaults. An arch enabling boot-time page size must select CONFIG_CONSTRUCTORS. Also add BUILD_BUG_ON_FIXED_PAGE_SIZE(), which is BUILD_BUG_ON() when PAGE_SIZE_MIN equals PAGE_SIZE_MAX and VM_BUG_ON() otherwise. The macros live in a new asm-generic/pgtable-geometry.h, included from each arch's page header next to PAGE_SHIFT, as there is no common header to hook into. Signed-off-by: Ryan Roberts Signed-off-by: Eric Curtin (cherry picked from commit 2e4f93099407da931c07e4bd7aec9ff5696207fa) --- arch/alpha/include/asm/page.h | 1 + arch/arc/include/asm/page.h | 1 + arch/arm/include/asm/page.h | 1 + arch/arm64/include/asm/page-def.h | 2 + arch/csky/include/asm/page.h | 3 + arch/hexagon/include/asm/page.h | 2 + arch/loongarch/include/asm/page.h | 2 + arch/m68k/include/asm/page.h | 1 + arch/microblaze/include/asm/page.h | 1 + arch/mips/include/asm/page.h | 1 + arch/nios2/include/asm/page.h | 2 + arch/openrisc/include/asm/page.h | 1 + arch/parisc/include/asm/page.h | 1 + arch/powerpc/include/asm/page.h | 2 + arch/riscv/include/asm/page.h | 1 + arch/s390/include/asm/page.h | 1 + arch/sh/include/asm/page.h | 1 + arch/sparc/include/asm/page.h | 3 + arch/um/include/asm/page.h | 2 + arch/x86/include/asm/page_types.h | 2 + arch/xtensa/include/asm/page.h | 1 + include/asm-generic/pgtable-geometry.h | 86 ++++++++++++++++++++++++++ init/main.c | 5 +- kernel/module/main.c | 4 +- 24 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 include/asm-generic/pgtable-geometry.h diff --git a/arch/alpha/include/asm/page.h b/arch/alpha/include/asm/page.h index 67053c52953f..f5468f52b281 100644 --- a/arch/alpha/include/asm/page.h +++ b/arch/alpha/include/asm/page.h @@ -96,5 +96,6 @@ typedef struct page *pgtable_t; #include #include +#include #endif /* _ALPHA_PAGE_H */ diff --git a/arch/arc/include/asm/page.h b/arch/arc/include/asm/page.h index facc7a03b250..844ade515d4d 100644 --- a/arch/arc/include/asm/page.h +++ b/arch/arc/include/asm/page.h @@ -6,6 +6,7 @@ #define __ASM_ARC_PAGE_H #include +#include #ifdef CONFIG_ARC_HAS_PAE40 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h index fa4c1225dde5..fab78b35823f 100644 --- a/arch/arm/include/asm/page.h +++ b/arch/arm/include/asm/page.h @@ -188,5 +188,6 @@ extern int pfn_valid(unsigned long); #include #include +#include #endif diff --git a/arch/arm64/include/asm/page-def.h b/arch/arm64/include/asm/page-def.h index d402e08442ee..e0ef167519e6 100644 --- a/arch/arm64/include/asm/page-def.h +++ b/arch/arm64/include/asm/page-def.h @@ -12,4 +12,6 @@ #include +#include + #endif /* __ASM_PAGE_DEF_H */ diff --git a/arch/csky/include/asm/page.h b/arch/csky/include/asm/page.h index 76774dbce869..cc223a7c25b2 100644 --- a/arch/csky/include/asm/page.h +++ b/arch/csky/include/asm/page.h @@ -85,4 +85,7 @@ static inline unsigned long virt_to_pfn(const void *kaddr) #include #endif /* !__ASSEMBLER__ */ + +#include + #endif /* __ASM_CSKY_PAGE_H */ diff --git a/arch/hexagon/include/asm/page.h b/arch/hexagon/include/asm/page.h index 6d82572a7f21..b2e38f1132b9 100644 --- a/arch/hexagon/include/asm/page.h +++ b/arch/hexagon/include/asm/page.h @@ -130,4 +130,6 @@ static inline unsigned long virt_to_pfn(const void *kaddr) #endif /* ifdef __ASSEMBLY__ */ #endif /* ifdef __KERNEL__ */ +#include + #endif diff --git a/arch/loongarch/include/asm/page.h b/arch/loongarch/include/asm/page.h index b9d61f7c032c..c446799933a0 100644 --- a/arch/loongarch/include/asm/page.h +++ b/arch/loongarch/include/asm/page.h @@ -107,4 +107,6 @@ extern int __virt_addr_valid(volatile void *kaddr); #endif /* !__ASSEMBLER__ */ +#include + #endif /* _ASM_PAGE_H */ diff --git a/arch/m68k/include/asm/page.h b/arch/m68k/include/asm/page.h index d30f8b2f1592..d4dc0147e47c 100644 --- a/arch/m68k/include/asm/page.h +++ b/arch/m68k/include/asm/page.h @@ -58,5 +58,6 @@ extern unsigned long _ramend; #include #include +#include #endif /* _M68K_PAGE_H */ diff --git a/arch/microblaze/include/asm/page.h b/arch/microblaze/include/asm/page.h index e1e396367ba7..4d3c1cc0073c 100644 --- a/arch/microblaze/include/asm/page.h +++ b/arch/microblaze/include/asm/page.h @@ -137,5 +137,6 @@ static inline const void *pfn_to_virt(unsigned long pfn) #include #include +#include #endif /* _ASM_MICROBLAZE_PAGE_H */ diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h index 50a382a0d8f6..9cdc0b8cb966 100644 --- a/arch/mips/include/asm/page.h +++ b/arch/mips/include/asm/page.h @@ -223,5 +223,6 @@ static inline unsigned long kaslr_offset(void) #include #include +#include #endif /* _ASM_PAGE_H */ diff --git a/arch/nios2/include/asm/page.h b/arch/nios2/include/asm/page.h index 71eb7c1b67d4..27c4c68e8aea 100644 --- a/arch/nios2/include/asm/page.h +++ b/arch/nios2/include/asm/page.h @@ -93,4 +93,6 @@ extern struct page *mem_map; #endif /* !__ASSEMBLER__ */ +#include + #endif /* _ASM_NIOS2_PAGE_H */ diff --git a/arch/openrisc/include/asm/page.h b/arch/openrisc/include/asm/page.h index d2cdbf3579bb..ce3a6d921d8d 100644 --- a/arch/openrisc/include/asm/page.h +++ b/arch/openrisc/include/asm/page.h @@ -76,5 +76,6 @@ static inline unsigned long virt_to_pfn(const void *kaddr) #include #include +#include #endif /* __ASM_OPENRISC_PAGE_H */ diff --git a/arch/parisc/include/asm/page.h b/arch/parisc/include/asm/page.h index 3630b36d07da..4dffa850d30a 100644 --- a/arch/parisc/include/asm/page.h +++ b/arch/parisc/include/asm/page.h @@ -169,6 +169,7 @@ extern int npmem_ranges; #include #include +#include #include #define PAGE0 ((struct zeropage *)absolute_pointer(__PAGE_OFFSET)) diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h index 281f25e071a3..e5c01c11f26b 100644 --- a/arch/powerpc/include/asm/page.h +++ b/arch/powerpc/include/asm/page.h @@ -293,4 +293,6 @@ static inline unsigned long kaslr_offset(void) #include #endif /* __ASSEMBLER__ */ +#include + #endif /* _ASM_POWERPC_PAGE_H */ diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h index b4bbae55e931..2e68929ac15c 100644 --- a/arch/riscv/include/asm/page.h +++ b/arch/riscv/include/asm/page.h @@ -176,5 +176,6 @@ static __always_inline void *pfn_to_kaddr(unsigned long pfn) #include #include +#include #endif /* _ASM_RISCV_PAGE_H */ diff --git a/arch/s390/include/asm/page.h b/arch/s390/include/asm/page.h index 56da819a79e6..46f340d25b74 100644 --- a/arch/s390/include/asm/page.h +++ b/arch/s390/include/asm/page.h @@ -283,6 +283,7 @@ static inline unsigned long virt_to_pfn(const void *kaddr) #include #include +#include #define AMODE31_SIZE (3 * PAGE_SIZE) diff --git a/arch/sh/include/asm/page.h b/arch/sh/include/asm/page.h index def4205491ec..13e13e900586 100644 --- a/arch/sh/include/asm/page.h +++ b/arch/sh/include/asm/page.h @@ -159,5 +159,6 @@ typedef struct page *pgtable_t; #include #include +#include #endif /* __ASM_SH_PAGE_H */ diff --git a/arch/sparc/include/asm/page.h b/arch/sparc/include/asm/page.h index 1a00cc0a1893..8f46b7a38ccd 100644 --- a/arch/sparc/include/asm/page.h +++ b/arch/sparc/include/asm/page.h @@ -7,4 +7,7 @@ #else #include #endif + +#include + #endif diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h index e348ff489b89..6eb5a5cdbcf0 100644 --- a/arch/um/include/asm/page.h +++ b/arch/um/include/asm/page.h @@ -95,4 +95,6 @@ extern unsigned long uml_physmem; #endif /* __ASSEMBLER__ */ +#include + #endif /* __UM_PAGE_H */ diff --git a/arch/x86/include/asm/page_types.h b/arch/x86/include/asm/page_types.h index 3e0801a0f782..99145b56714c 100644 --- a/arch/x86/include/asm/page_types.h +++ b/arch/x86/include/asm/page_types.h @@ -66,4 +66,6 @@ extern void initmem_init(void); #endif /* !__ASSEMBLER__ */ +#include + #endif /* _ASM_X86_PAGE_DEFS_H */ diff --git a/arch/xtensa/include/asm/page.h b/arch/xtensa/include/asm/page.h index 059493256765..6fb8bfbd0f45 100644 --- a/arch/xtensa/include/asm/page.h +++ b/arch/xtensa/include/asm/page.h @@ -174,4 +174,5 @@ static inline unsigned long ___pa(unsigned long va) #endif /* __ASSEMBLER__ */ #include +#include #endif /* _XTENSA_PAGE_H */ diff --git a/include/asm-generic/pgtable-geometry.h b/include/asm-generic/pgtable-geometry.h new file mode 100644 index 000000000000..89609cab425f --- /dev/null +++ b/include/asm-generic/pgtable-geometry.h @@ -0,0 +1,86 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef ASM_GENERIC_PGTABLE_GEOMETRY_H +#define ASM_GENERIC_PGTABLE_GEOMETRY_H + +#if defined(PAGE_SHIFT_MAX) && defined(PAGE_SIZE_MAX) && defined(PAGE_MASK_MAX) && \ + defined(PAGE_SHIFT_MIN) && defined(PAGE_SIZE_MIN) && defined(PAGE_MASK_MIN) +/* Arch supports boot-time page size selection. */ +#elif defined(PAGE_SHIFT_MAX) || defined(PAGE_SIZE_MAX) || defined(PAGE_MASK_MAX) || \ + defined(PAGE_SHIFT_MIN) || defined(PAGE_SIZE_MIN) || defined(PAGE_MASK_MIN) +#error Arch must define all or none of the boot-time page size macros +#else +/* Arch does not support boot-time page size selection. */ +#define PAGE_SHIFT_MIN PAGE_SHIFT +#define PAGE_SIZE_MIN PAGE_SIZE +#define PAGE_MASK_MIN PAGE_MASK +#define PAGE_SHIFT_MAX PAGE_SHIFT +#define PAGE_SIZE_MAX PAGE_SIZE +#define PAGE_MASK_MAX PAGE_MASK +#endif + +/* + * Define a global variable (scalar or struct), whose value is derived from + * PAGE_SIZE and friends. When PAGE_SIZE is a compile-time constant, the global + * variable is simply defined with the static value. When PAGE_SIZE is + * determined at boot-time, a constructor is registered and run before any + * initcalls or module params are parsed to initialize the variable. + * + * @type: Unqualified type. Do not include "const"; implied by macro variant. + * @name: Variable name. + * @attrib: Variable attributes (DEFINE_GLOBAL_PAGE_SIZE_VAR_ATTR only). + * @...: Initialization value. May be scalar or initializer. + * + * "static" is declared by placing "static" before the macro. + * + * Example: + * + * struct my_struct { + * int a; + * char b; + * }; + * + * static DEFINE_GLOBAL_PAGE_SIZE_VAR(struct my_struct, my_variable, { + * .a = 10, + * .b = 'e', + * }); + */ +#if PAGE_SIZE_MIN != PAGE_SIZE_MAX +#define __DEFINE_GLOBAL_PAGE_SIZE_VAR(type, name, attrib, ...) \ + type name attrib; \ + static void __init __attribute__((constructor)) __##name##_init(void) \ + { \ + name = (type)__VA_ARGS__; \ + } + +#define DEFINE_GLOBAL_PAGE_SIZE_VAR(type, name, ...) \ + __DEFINE_GLOBAL_PAGE_SIZE_VAR(type, name, , __VA_ARGS__) + +#define DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(type, name, ...) \ + __DEFINE_GLOBAL_PAGE_SIZE_VAR(type, name, __ro_after_init, __VA_ARGS__) +#else /* PAGE_SIZE_MIN == PAGE_SIZE_MAX */ +#define __DEFINE_GLOBAL_PAGE_SIZE_VAR(type, name, attrib, ...) \ + type name attrib = __VA_ARGS__; \ + +#define DEFINE_GLOBAL_PAGE_SIZE_VAR(type, name, ...) \ + __DEFINE_GLOBAL_PAGE_SIZE_VAR(type, name, , __VA_ARGS__) + +#define DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(type, name, ...) \ + __DEFINE_GLOBAL_PAGE_SIZE_VAR(const type, name, , __VA_ARGS__) +#endif + +#define DEFINE_GLOBAL_PAGE_SIZE_VAR_ATTR(type, name, attrib, ...) \ + __DEFINE_GLOBAL_PAGE_SIZE_VAR(type, name, attrib, __VA_ARGS__) + +#ifndef __ASSEMBLY__ +/* + * Compile-time check when the page size is fixed. With boot-time page size + * the condition is only known at boot, so check it at run-time instead. + */ +#if PAGE_SIZE_MIN == PAGE_SIZE_MAX +#define BUILD_BUG_ON_FIXED_PAGE_SIZE(cond) BUILD_BUG_ON(cond) +#else +#define BUILD_BUG_ON_FIXED_PAGE_SIZE(cond) VM_BUG_ON(cond) +#endif +#endif /* __ASSEMBLY__ */ + +#endif /* ASM_GENERIC_PGTABLE_GEOMETRY_H */ diff --git a/init/main.c b/init/main.c index f14780345051..3d619be281aa 100644 --- a/init/main.c +++ b/init/main.c @@ -1053,6 +1053,8 @@ static void __init print_kernel_cmdline(const char *cmdline) pr_notice("%s%s\n", KERNEL_CMDLINE_PREFIX, cmdline); } +static __init void do_ctors(void); + asmlinkage __visible __init __no_sanitize_address __noreturn __no_stack_protector void start_kernel(void) { @@ -1064,6 +1066,8 @@ void start_kernel(void) debug_objects_early_init(); init_vmlinux_build_id(); + do_ctors(); + cgroup_init_early(); local_irq_disable(); @@ -1526,7 +1530,6 @@ static void __init do_basic_setup(void) ksysfs_init(); driver_init(); init_irq_proc(); - do_ctors(); do_initcalls(); } diff --git a/kernel/module/main.c b/kernel/module/main.c index 34e0204ea37c..17145dc9c009 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -3127,7 +3127,6 @@ static noinline int do_init_module(struct module *mod) freeinit->init_data = mod->mem[MOD_INIT_DATA].base; freeinit->init_rodata = mod->mem[MOD_INIT_RODATA].base; - do_mod_ctors(mod); /* Start the module */ if (mod->init != NULL) ret = do_one_initcall(mod->init); @@ -3575,6 +3574,9 @@ static int load_module(struct load_info *info, const char __user *uargs, mod->async_probe_requested = async_probe; + /* Constructors may set defaults that module params must override. */ + do_mod_ctors(mod); + /* Module is ready to execute: parsing args may do that. */ after_dashes = parse_args(mod->name, args, mod->kp, mod->num_kp, -32768, 32767, mod,