From: Grzegorz Jaszczyk <jaszczyk@chromium.org>
To: tglx@kernel.org
Cc: linux-kernel@vger.kernel.org, dmaluka@chromium.org,
vineethrp@chromium.org, chuanxiao.dong@intel.com,
jaszczyk@google.com, Grzegorz Jaszczyk <jaszczyk@chromium.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
Juergen Gross <jgross@suse.com>, Radu Rendec <radu@rendec.net>,
Thierry Reding <treding@nvidia.com>,
Julian Stecklina <julian.stecklina@cyberus-technology.de>,
Sean Christopherson <seanjc@google.com>,
"Naveen N Rao (AMD)" <naveen@kernel.org>,
Ard Biesheuvel <ardb@kernel.org>,
"Mike Rapoport (Microsoft)" <rppt@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Arnd Bergmann <arnd@arndb.de>,
Thomas Zimmermann <tzimmermann@suse.de>,
Thorsten Blum <blum@kernel.org>, Breno Leitao <leitao@debian.org>,
Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Subject: [PATCH v2 2/4] x86/apic: Consolidate early APIC initialization into apic_early_init()
Date: Thu, 24 Sep 2026 10:40:19 +0000 [thread overview]
Message-ID: <20260924104102.3534474-3-jaszczyk@chromium.org> (raw)
In-Reply-To: <20260924104102.3534474-1-jaszczyk@chromium.org>
Early APIC initialization is currently scattered across setup_arch():
apic_setup_apic_calls() and acpi_mps_check() run early, check_x2apic()
is invoked much later during memory range setup, and
apic_finalize_early_init() runs near the end of setup_arch().
Consolidate the initial setup into apic_early_init() in
arch/x86/kernel/apic/apic.c so that acpi_mps_check(), check_x2apic(),
and static call initialization happen together in one place. Make
check_x2apic() static as it no longer has external callers.
Place apic_setup_apic_calls() at the end of apic_early_init() in
preparation for replacing it with apic_install_default_driver() in the
subsequent patch. This ordering change is safe because neither
acpi_mps_check() nor check_x2apic() uses APIC static calls
(check_x2apic() accesses x2APIC MSRs directly via native_apic_msr_read()).
Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Grzegorz Jaszczyk <jaszczyk@chromium.org>
---
arch/x86/include/asm/apic.h | 3 ++-
arch/x86/kernel/apic/apic.c | 16 ++++++++++++++--
arch/x86/kernel/setup.c | 10 +---------
3 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
index b4c112b6d3ab3..b1610b8bc6544 100644
--- a/arch/x86/include/asm/apic.h
+++ b/arch/x86/include/asm/apic.h
@@ -133,6 +133,7 @@ extern void sync_Arb_IDs(void);
extern void init_bsp_APIC(void);
extern void apic_intr_mode_select(void);
extern void apic_intr_mode_init(void);
+void apic_early_init(void);
void apic_finalize_early_init(void);
void register_lapic_address(unsigned long address);
extern void setup_boot_APIC_clock(void);
@@ -183,6 +184,7 @@ extern void topology_reset_possible_cpus_up(void);
#else /* !CONFIG_X86_LOCAL_APIC */
static inline void lapic_shutdown(void) { }
#define local_apic_timer_c2_ok 1
+static inline void apic_early_init(void) { }
static inline void apic_finalize_early_init(void) { }
static inline void disable_local_APIC(void) { }
# define setup_boot_APIC_clock x86_init_noop
@@ -254,7 +256,6 @@ static inline u32 native_apic_msr_read(u32 reg) { BUG(); }
#define x2apic_mode (0)
#define x2apic_supported() (0)
#endif /* !CONFIG_X86_X2APIC */
-extern void __init check_x2apic(void);
struct irq_data;
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index cb78e0d6c9317..721e194ceac2d 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -1869,7 +1869,7 @@ static __init void try_to_enable_x2apic(int remap_mode)
x2apic_enable();
}
-void __init check_x2apic(void)
+static void __init check_x2apic(void)
{
if (x2apic_enabled()) {
pr_info("x2apic: enabled by BIOS, switching to x2apic ops\n");
@@ -1884,7 +1884,7 @@ void __init check_x2apic(void)
}
}
#else /* CONFIG_X86_X2APIC */
-void __init check_x2apic(void)
+static void __init check_x2apic(void)
{
if (!apic_is_x2apic_enabled())
return;
@@ -2064,6 +2064,18 @@ static bool __init detect_init_APIC(void)
}
#endif
+void __init apic_early_init(void)
+{
+ if (acpi_mps_check()) {
+ apic_is_disabled = true;
+ setup_clear_cpu_cap(X86_FEATURE_APIC);
+ } else {
+ check_x2apic();
+ }
+
+ apic_setup_apic_calls();
+}
+
void __init apic_finalize_early_init(void)
{
if (apic_validate_deadline_timer())
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 06522a205dd93..2bab41e073d52 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -993,14 +993,7 @@ void __init setup_arch(char **cmdline_p)
x86_report_nx();
- apic_setup_apic_calls();
-
- if (acpi_mps_check()) {
-#ifdef CONFIG_X86_LOCAL_APIC
- apic_is_disabled = true;
-#endif
- setup_clear_cpu_cap(X86_FEATURE_APIC);
- }
+ apic_early_init();
e820__finish_early_params();
@@ -1062,7 +1055,6 @@ void __init setup_arch(char **cmdline_p)
/* max_low_pfn get updated here */
find_low_pfn_range();
#else
- check_x2apic();
/* How many end-of-memory variables you have, grandma! */
/* need this before calling reserve_initrd */
--
2.56.0.rc1.315.gc6ed9934b7-goog
next prev parent reply other threads:[~2026-09-24 10:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 10:40 [PATCH v2 0/4] x86/apic: Switch to x2apic driver early if x2apic is enabled Grzegorz Jaszczyk
2026-09-24 10:40 ` [PATCH v2 1/4] x86/apic: Rename init_apic_mappings() to apic_finalize_early_init() Grzegorz Jaszczyk
2026-09-24 10:40 ` Grzegorz Jaszczyk [this message]
2026-09-24 10:40 ` [PATCH v2 3/4] x86/apic: Remove redundant check from x2apic_phys_probe() Grzegorz Jaszczyk
2026-09-24 10:40 ` [PATCH v2 4/4] x86/apic: Switch to x2apic driver early if x2apic is enabled Grzegorz Jaszczyk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260924104102.3534474-3-jaszczyk@chromium.org \
--to=jaszczyk@chromium.org \
--cc=akpm@linux-foundation.org \
--cc=ardb@kernel.org \
--cc=arnd@arndb.de \
--cc=blum@kernel.org \
--cc=bp@alien8.de \
--cc=chuanxiao.dong@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=dmaluka@chromium.org \
--cc=harshit.m.mogalapalli@oracle.com \
--cc=hpa@zytor.com \
--cc=jaszczyk@google.com \
--cc=jgross@suse.com \
--cc=julian.stecklina@cyberus-technology.de \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=naveen@kernel.org \
--cc=peterz@infradead.org \
--cc=radu@rendec.net \
--cc=rppt@kernel.org \
--cc=seanjc@google.com \
--cc=tglx@kernel.org \
--cc=tglx@linutronix.de \
--cc=treding@nvidia.com \
--cc=tzimmermann@suse.de \
--cc=vineethrp@chromium.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®