Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796089968; b=2dhK4GW/EpJ4afQbXkMj/7ocQuR7gtXuCrFoZznCpKR1ulLpFKjK465Oz7cVLH5/jubS VrDK6ImiElGLw+PmRuSmrBDBlrPcNZv0lEfxRgn4uG7+6TNfGuXL6seSrkDjLXVgqozEa o5OAPPV6C2NrP0i4yGTLDQRUlcemD4I86ag8MVcdFBZbXjQrFLgb65R12oFm5dNuo/UPt FNPkSz51N9SNvIRdrWoLW++YXcim8mJkXVCGSDzAKaZwooxwoDliu9F83tGGAq8zMNbnd rZEmxpeOkI2ThejBWp2FtaN9Y2Xtdbr6lCRd1NzqjBkLp2aEWHgQYQFWkiavb15RHLQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796089968; 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=ZB1Dt9zf7lhpwwV5oDC6GLZuIQ9mj6nE/MJL6RaWM9TYFUTnLncJbGRDfq+k1qN3zEWm NVrqMcChb66fRcvKjWEU3kBnwBmggwKCxb6KdV+wtGVe3FNUyccbPKSvGIO25DfXGBnlQ bpmzroFA2OWC/EoD7wSSW0zLkIZg4t+s1veaYZK46NfBxGSdfVXym/AcPaBIAA0T+DnHC yyPQP8LfKgu7PxOZZXyYUeko/nECtLdaTmRTmuCDTYHoh8XSaAGpqGbRMl+CV5rYlk5XN p2Ihpn45Ux/Y5kaCOA9+v0JeZku/ERudDaBARYn/E/74zbnYXqBuy1Vx2yG3j1ze5/A== 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.43 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 54640606A329 for ; Tue, 1 Dec 2026 01:52:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 54640606A329 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-f43.google.com with SMTP id 5b1f17b1804b1-4a35a60499eso86127175e9.0 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=XKD+Ys1LTQHlgyMz+oEKux/hOuOnNuJmwPi/mN7M9LlmxavIyJqwy8aXhJxfKUbyMa ZnFvjEmCN7tMT7XeveQtnmFVI2KCgbuu7jJNmUj9b67pO3qQv7sM8RvrpyQ/p/GKRnB+ GVl4Qo/XTlWIQj/3SOebqYwvSmv8GKDLDPBXUpHP9baOXrINvsHbmu+LmUAjMeEz+rYv AeHHhieTqlZ1/PCvqWxJRHm1S6YQrheh7mQzXkuKmghr5wAlTP+osZ+sFI5AV/4Oe/j0 EoVbf19gFOSvJWVd7WZXYj0q05rk1fYcBMv3bw8Gm/ZqkyPYhdmdgTt5WwaET91/Pix+ 6DYQ== X-Forwarded-Encrypted: i=1; AL+hErE960j0UTqpnaw775gBv46qgvxeY+hnKI69T1vkeilFfQhlO2l1uheaoX944geXCScAKijev/VzY+qE@vger.kernel.org X-Gm-Message-State: APuU4Z//2NwoWs+OffTNYfjW/I3XrBtVRftIXg3oZfVwnr8gNd6slxC9 tR4aL/GpBEzVDOWUDOV6AE797JUhwEa/SfFciHWLN3Di3+Mb+4+kmqaR X-Gm-Gg: AZFdTZcw9RNnNXO0/HSq4aSMFp2PXLF9qd/aCGTS7sp7dDW3UG43wQUrQIxfWbLmjHw NMc5KWcJUJ6VMHtzJKSeVvda6GA6/W7QSNW1n9HAiXm2GmnbmgHOrcC2xWvWDn8VmuHNBDJVcQo LCfRPZyy82d+sWS/JTCaLYkfROCSo82jo5IEgdswFHA0ETydjbtp3L4zBXEMtUhB8moRCarshn2 P3Ll37mFftImdD23ktCzuBCNKlPjyIbXmqH0kZVy9N8twOnQPP+71cwE++mdml6anNOqihFPvn6 +8FlVPy5Vs6q8Cj9kso8Bk1Ce3b7Q5t8OKAmbrgvwmOhiw5pMfo+f6pjqSrjleV7hnvHYObkCkr VBS+4N+fikGDckLHXPI27jy3gXvImbRGWM2g8e0cnEzkKt9IbD1Ya38TKrAp14+c2D/uy+Y3b2V UolCWUMbYIjafNlnzVYpDgfm4I3r1E0MG8swrDM5kTfpjpNMr5jMiPLBdz7QgOrg6bftzBI41b+ 6Z2YY/0WvUXolMSwmUKafaE+VpvqpPFjgjqyXRmbkI2X2IiUtpnKCoTJ85xDkK9S4kasWaZl7x8 hRDQAvEYahiQg/q6enNC0jZdPrjZ0IrSFNuNbw== 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-arch@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,