From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2557606A320 for ; Tue, 1 Dec 2026 01:53:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=rdr5WWUx; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=EmemATXp DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=efIrByk7hVkQpPW21t2WgZXcVBMWY+aGTb/Tz+E4oMM=; b=rdr5WWUxhct24c JER9cg4+ZNZTpTiYuCBQNUAora03suBuezl5C5BNf8bzCtoVRGSX82o8knqIpsC4qeU5SNlMyzFr5 HKYIMUwuA4xnDCVgtazd/0BvIljEnciozqs6n2zheDNRT9U8biiv69gQ5/7rMkAc3VdN/7OqZ2mEU PCm5keCmr9RPNHCrk7dey2I/QkmlAg6xiMrTUv4Bjnoa8N63hBPWXdzls3QRJ9YdYHqfZn6su5yAa hPFDySTZfOJ8+TLo/BloKGauVgau+IumS92kwwZEmzr+ZHnAs3QTZy5JLZd338uis9sltUn7E3QbI r7I0OybUEBhX1TNKx1ww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYD3D-00000006DIl-3nYc; Tue, 01 Dec 2026 01:52:59 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYD33-00000006DDO-059p for linux-arm-kernel@lists.infradead.org; Tue, 01 Dec 2026 01:52:50 +0000 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4a207b02a2cso80083645e9.1 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=lists.infradead.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=EmemATXpQivNKlzRSJuNeKptV2/OVYz3P9Gtz/+ynC+zcDQL6q994ClSQhLlyKhBPP mSXd32yepbPNblsQCD+0i+gXT8XLTuvmJOPBwIajdhF7kQCuDrMvIMuOivFsnuW/dh2T KuapMte1OBB0ICs3ZDUHI2cq5h1vKnP7UIeTfnh8+0IXMDDzTEJ9r/jTn7dZBKjVip6i ewQ1Vz5qtFXUxN1rHVhfj4wekdEV98m6tnDwY4MJI4U69H5m41qMIJfFTA5O2fMdD3cy dV7YqED3nahmQBjjX7qrUy5KHPLNM3J5dQ6PF6wTocQdc0Rrtk1WlyO0+Akw05WlLa3c 6X6Q== 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=CcUNekUaMUYfHg+act21Zq7N9VYV4caRgedmoxi0x7zVZvTcMGjNWiboDwQKmc8Z8x SuQtx/848/U1pgHhjoSNnUuh08al4k5JXt/iBeDd82BNUlicAVaPqbQ589di6kg+pdqb TVc7aAyb6NGN0qKKeMULnChIXy+bQXIW6x1XsD6ke5d164DeuxT/Z9P6hY3lGShwZwuW Ydds084J8n/z3/UMweyaYcpCSv/6vAHwdPudKBZ77H9Zn9a2gKld5m96SamnWGsXQpnV lZ0X+zZSigRFvHnXQou4fXW7RjUbTB4u4bIStntEsyzmNUg41EwfGYUp21yjFfhQiGH9 inDA== X-Gm-Message-State: APuU4Z/bvzpXnZFxYot2iGtRenKFg2w3Q5KBk1SgpGy2uf9RRssMtZ4C aEiztt6fYGAiWuE+dfgbzOvOhCHsUfvgrWQVEwoKPUjQ8YoTFZ13xYSfmAYkKeUG0tUYLYKu X-Gm-Gg: AZFdTZcu/z6kTgfPWPJsYndtxYnHqMFhaKAoRi9J6m0zv6lWymQm4PL+I9Wqi67MIg6 Pnc2r/tRZklxkNUDtTHdTyaqa8a2QYyts6vaLNYWqCIP3xYGgjV7XxVR1elF7sjt71FFyAKRPeF JbZ9t0DzYVA1nRR/8jm2H1M9ECFIZpsUKncePx0ObfjassU4vtyjlBZhkw/fhOUvaXd+Yhe2yPy GPEGsYafRtf/5wlREuVmjxsxbmkCVQduJjrKiPH+WNUGHCziCXJuhq1XJMRKxLWLsHLc7nhhgOk 4fdlJ2Ey+kpVVjZjOkcPWj0mDPrd0zPa3LXkW7kGRlsOyd+N+RSZSwZHVzZhHEuDC8BaI7XwhZ7 oGjju8YAG+sIEDHmiT0mCumF9TIawJ0BEeGZXZOAKBs/9QRPpHxGFHyC1jW4cC31WxP9lAhP+Ok gI6LvfxlADja7I6iyw01oRDOkDfN0ykop2trTlxWGfuIMPzP0IdLqyROOFBDGPXosBxiK/NivlF 07wLcrLOI3s6EAHpwhGuJzeipKIPkYv1GqNxiGY0t/TfiCZ83xrmopUZYM9tXJ9sgA5C1EobYqv q3wndTus7UqKP60MVrNjfT39HO3DQTlD6DjETA== 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-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261130_175249_222486_AFC318B1 X-CRM114-Status: GOOD ( 24.67 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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,