x86/apic: Switch to x2apic driver early if x2apic is enabled
v2 cover x86/apic: Switch to x2apic driver early if x2apic is enabled
During early boot, the generic x86 kernel defaults to the MMIO-based APIC driver (apic_physflat). When booting (e.g., via kexec into a crashdump kernel) with x2APIC already enabled in hardware and without ACPI MADT probing (e.g., !CONFIG_ACPI), the APIC driver pointer remains set to apic_physflat until late_time_init() runs x86_64_probe_apic().
Because check_x2apic() detects hardware x2APIC mode and sets x2apic_mode = 1, the APIC MMIO fixmap is not mapped. If a pending interrupt fires in the window between local_irq_enable() and late_time_init(), native_apic_mem_eoi() attempts to write to the unmapped APIC EOI MMIO address, resulting in an early boot page fault (#PF).
This series restructures early APIC initialization and installs apic_x2apic_phys (or apic_noop if the APIC is disabled or built without CONFIG_X86_X2APIC) as the default APIC driver in apic_early_init(), ensuring safe MSR-based or no-op APIC accesses while still allowing later APIC probing (e.g., upgrading to apic_x2apic_cluster) to proceed normally.
Changes in v2:
- Reworked v1 based on Thomas Gleixner's feedback and suggested draft, splitting it into a 4-patch series and addressing several issues from the initial draft (!CONFIG_X86_LOCAL_APIC stubs, handling early apic_is_disabled in apic_early_init(), and avoiding duplicate routing log messages and the 'apic->probed' flag by dropping the dead check in x2apic_phys_probe()):
- Rename init_apic_mappings() to apic_finalize_early_init().
- Consolidate acpi_mps_check(), check_x2apic(), and apic_setup_apic_calls() from setup_arch() into apic_early_init().
- Remove the redundant 'return apic == &apic_x2apic_phys;' check from x2apic_phys_probe() (dead code since commit cb214ede7657), which allows apic_x2apic_phys to be used as the early default driver without needing an extra 'apic->probed' flag in struct apic for x2apic_cluster to probe later.
- Replace apic_setup_apic_calls() with apic_install_default_driver() and install apic_x2apic_phys or apic_noop as the early default driver in apic_early_init().
v1: https://lore.kernel.org/all/[email protected]/
Grzegorz Jaszczyk (4):
x86/apic: Rename init_apic_mappings() to apic_finalize_early_init() x86/apic: Consolidate early APIC initialization into apic_early_init() x86/apic: Remove redundant check from x2apic_phys_probe() x86/apic: Switch to x2apic driver early if x2apic is enabled
arch/x86/include/asm/apic.h | 11 ++++------ arch/x86/kernel/apic/apic.c | 33 +++++++++++++++++++++++------- arch/x86/kernel/apic/init.c | 32 ++++++++++++++++++----------- arch/x86/kernel/apic/local.h | 4 ++++ arch/x86/kernel/apic/x2apic_phys.c | 9 ++------ arch/x86/kernel/setup.c | 12 ++--------- 6 files changed, 58 insertions(+), 43 deletions(-)
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
PATCH v2 1/4 x86/apic: Rename init_apic_mappings() to apic_finalize_early_init()
Rename init_apic_mappings() to apic_finalize_early_init() to accurately reflect its purpose (validating the TSC deadline timer and finalizing early APIC detection and fallback mapping when no SMP config was found).
--- arch/x86/include/asm/apic.h | 4 ++-- arch/x86/kernel/apic/apic.c | 5 +---- arch/x86/kernel/setup.c | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-)
arch/x86/include/asm/apic.h +2 -2
@@ -133,7 +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 ); -extern void init_apic_mappings (void ); +void apic_finalize_early_init (void );void register_lapic_address (unsigned long address);extern void setup_boot_APIC_clock (void );extern void setup_secondary_APIC_clock (void );
@@ -183,7 +183,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 init_apic_mappings (void ) { } +static inline void apic_finalize_early_init (void ) { }static inline void disable_local_APIC (void ) { }# define setup_boot_APIC_clock x86_init_noop# define setup_secondary_APIC_clock x86_init_noop
arch/x86/kernel/apic/apic.c +1 -4
@@ -2064,10 +2064,7 @@ static bool __init detect_init_APIC(void) }#endif -/** -* init_apic_mappings - initialize APIC mappings -*/ -void __init init_apic_mappings (void ) +void __init apic_finalize_early_init (void ) {if (apic_validate_deadline_timer ())pr_info ("TSC deadline timer available\n" );
arch/x86/kernel/setup.c +1 -1
@@ -1242,7 +1242,7 @@ void __init setup_arch(char **cmdline_p) x86_init.mpparse.parse_smp_cfg ();/* Last opportunity to detect and map the local APIC */ -init_apic_mappings (); +apic_finalize_early_init ();topology_init_possible_cpus ();
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
[tip: x86/apic] x86/apic: Rename init_apic_mappings() to apic_finalize_early_init()
The following commit has been merged into the x86/apic branch of tip:
The following commit has been merged into the x86/apic branch of tip:
Commit-ID: ecb8135571e435bc38c86d363f231681562c9ba6 Gitweb: https://git.kernel.org/tip/ecb8135571e435bc38c86d363f231681562c9ba6 Author: Grzegorz Jaszczyk <[email protected]> AuthorDate: Thu, 24 Sep 2026 10:40:18 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Mon, 19 Oct 2026 17:06:49 -07:00
x86/apic: Rename init_apic_mappings() to apic_finalize_early_init()
Rename init_apic_mappings() to apic_finalize_early_init() to accurately reflect its purpose (validating the TSC deadline timer and finalizing early APIC detection and fallback mapping when no SMP config was found).
No functional changes.
--- arch/x86/include/asm/apic.h | 4 ++-- arch/x86/kernel/apic/apic.c | 5 +---- arch/x86/kernel/setup.c | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-)
arch/x86/include/asm/apic.h +2 -2
@@ -133,7 +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 ); -extern void init_apic_mappings (void ); +void apic_finalize_early_init (void );void register_lapic_address (unsigned long address);extern void setup_boot_APIC_clock (void );extern void setup_secondary_APIC_clock (void );
@@ -183,7 +183,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 init_apic_mappings (void ) { } +static inline void apic_finalize_early_init (void ) { }static inline void disable_local_APIC (void ) { }# define setup_boot_APIC_clock x86_init_noop# define setup_secondary_APIC_clock x86_init_noop
arch/x86/kernel/apic/apic.c +1 -4
@@ -2064,10 +2064,7 @@ no_apic: }#endif -/** -* init_apic_mappings - initialize APIC mappings -*/ -void __init init_apic_mappings (void ) +void __init apic_finalize_early_init (void ) {if (apic_validate_deadline_timer ())pr_info ("TSC deadline timer available\n" );
arch/x86/kernel/setup.c +1 -1
@@ -1242,7 +1242,7 @@ void __init setup_arch(char **cmdline_p) x86_init.mpparse.parse_smp_cfg ();/* Last opportunity to detect and map the local APIC */ -init_apic_mappings (); +apic_finalize_early_init ();topology_init_possible_cpus ();
[tip: x86/apic] x86/apic: Rename init_apic_mappings() to apic_finalize_early_init()
In reply to Grzegorz JaszczykThe following commit has been merged into the x86/apic branch of tip:
The following commit has been merged into the x86/apic branch of tip:
Commit-ID: fc99757165a6b6662e3c5b24986f887a0269495f Gitweb: https://git.kernel.org/tip/fc99757165a6b6662e3c5b24986f887a0269495f Author: Grzegorz Jaszczyk <[email protected]> AuthorDate: Thu, 24 Sep 2026 10:40:18 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Tue, 03 Nov 2026 17:04:02 -08:00
x86/apic: Rename init_apic_mappings() to apic_finalize_early_init()
Rename init_apic_mappings() to apic_finalize_early_init() to accurately reflect its purpose (validating the TSC deadline timer and finalizing early APIC detection and fallback mapping when no SMP config was found).
No functional changes.
--- arch/x86/include/asm/apic.h | 4 ++-- arch/x86/kernel/apic/apic.c | 5 +---- arch/x86/kernel/setup.c | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-)
arch/x86/include/asm/apic.h +2 -2
@@ -133,7 +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 ); -extern void init_apic_mappings (void ); +void apic_finalize_early_init (void );void register_lapic_address (unsigned long address);extern void setup_boot_APIC_clock (void );extern void setup_secondary_APIC_clock (void );
@@ -183,7 +183,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 init_apic_mappings (void ) { } +static inline void apic_finalize_early_init (void ) { }static inline void disable_local_APIC (void ) { }# define setup_boot_APIC_clock x86_init_noop# define setup_secondary_APIC_clock x86_init_noop
arch/x86/kernel/apic/apic.c +1 -4
@@ -2064,10 +2064,7 @@ no_apic: }#endif -/** -* init_apic_mappings - initialize APIC mappings -*/ -void __init init_apic_mappings (void ) +void __init apic_finalize_early_init (void ) {if (apic_validate_deadline_timer ())pr_info ("TSC deadline timer available\n" );
arch/x86/kernel/setup.c +1 -1
@@ -1242,7 +1242,7 @@ void __init setup_arch(char **cmdline_p) x86_init.mpparse.parse_smp_cfg ();/* Last opportunity to detect and map the local APIC */ -init_apic_mappings (); +apic_finalize_early_init ();topology_init_possible_cpus ();
PATCH v2 2/4 x86/apic: Consolidate early APIC initialization into apic_early_init()
In reply to Grzegorz JaszczykEarly 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()).
--- 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(-)
arch/x86/include/asm/apic.h +2 -1
@@ -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 ;
arch/x86/kernel/apic/apic.c +14 -2
@@ -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 ())
arch/x86/kernel/setup.c +1 -9
@@ -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 */
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
[tip: x86/apic] x86/apic: Consolidate early APIC initialization into apic_early_init()
The following commit has been merged into the x86/apic branch of tip:
The following commit has been merged into the x86/apic branch of tip:
Commit-ID: 90f8b3e500657beeeb0f67bbb27c53b9707202a2 Gitweb: https://git.kernel.org/tip/90f8b3e500657beeeb0f67bbb27c53b9707202a2 Author: Grzegorz Jaszczyk <[email protected]> AuthorDate: Thu, 24 Sep 2026 10:40:19 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Mon, 19 Oct 2026 17:54:29 -07:00
x86/apic: Consolidate early APIC initialization into apic_early_init()
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.
Place apic_setup_apic_calls() at the end of apic_early_init() in preparation for replacing it with apic_install_default_driver(). 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()).
[ bp: Tone down the patch explanation text. ]
--- 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(-)
arch/x86/include/asm/apic.h +2 -1
@@ -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 ;
arch/x86/kernel/apic/apic.c +14 -2
@@ -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 @@ no_apic: }#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 ())
arch/x86/kernel/setup.c +1 -9
@@ -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 */
[tip: x86/apic] x86/apic: Consolidate early APIC initialization into apic_early_init()
In reply to Grzegorz JaszczykThe following commit has been merged into the x86/apic branch of tip:
The following commit has been merged into the x86/apic branch of tip:
Commit-ID: ae32c6e2679b05e1aab256af19599cec0abc5219 Gitweb: https://git.kernel.org/tip/ae32c6e2679b05e1aab256af19599cec0abc5219 Author: Grzegorz Jaszczyk <[email protected]> AuthorDate: Thu, 24 Sep 2026 10:40:19 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Tue, 03 Nov 2026 17:04:02 -08:00
x86/apic: Consolidate early APIC initialization into apic_early_init()
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.
Place apic_setup_apic_calls() at the end of apic_early_init() in preparation for replacing it with apic_install_default_driver(). 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()).
[ bp: Tone down the patch explanation text. ]
--- 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(-)
arch/x86/include/asm/apic.h +2 -1
@@ -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 ;
arch/x86/kernel/apic/apic.c +14 -2
@@ -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 @@ no_apic: }#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 ())
arch/x86/kernel/setup.c +1 -9
@@ -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 */
PATCH v2 3/4 x86/apic: Remove redundant check from x2apic_phys_probe()
In reply to Grzegorz JaszczykCommit 9ebd680bd029 ("x86, apic: Use probe routines to simplify apic selection") introduced x2apic_phys_probe() with a generic fallback check for 'apic == &apic_x2apic_phys' to preserve any prior selection of apic_x2apic_phys by default_acpi_madt_oem_check():
if (x2apic_mode && x2apic_phys)
return 1;
return apic == &apic_x2apic_phys;At the time, x2apic_acpi_madt_oem_check() only checked 'x2apic_phys && x2apic_enabled()', so that fallback was already redundant. Commit ea0dcf903e7d ("x86/apic: Use x2apic physical mode based on FADT setting") later added the ACPI_FADT_APIC_PHYSICAL check only to x2apic_acpi_madt_oem_check(), temporarily relying on the 'apic == &apic_x2apic_phys' fallback in x2apic_phys_probe() when x2APIC was pre-enabled by BIOS.
Subsequently, commit cb214ede7657 ("x86/apic: Work around boot failure on HP ProLiant DL980 G7 Server systems") factored out x2apic_fadt_phys() and added it directly to x2apic_phys_probe(). Because default_acpi_madt_oem_check() (via the .acpi_madt_oem_check callback) is the only path that can install apic_x2apic_phys prior to x2apic_phys_probe(), and x2apic_acpi_madt_oem_check() checks the exact same 'x2apic_phys || x2apic_fadt_phys()' condition, the fallback 'apic == &apic_x2apic_phys' check became completely unreachable again.
Remove the redundant check and the associated forward declaration of apic_x2apic_phys. In addition to cleaning up dead code, this allows apic_x2apic_phys to be installed as an early boot default driver when hardware x2APIC is pre-enabled without preventing x2apic_cluster from being probed and selected later during boot.
--- arch/x86/kernel/apic/x2apic_phys.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
arch/x86/kernel/apic/x2apic_phys.c +1 -6
@@ -6,8 +6,6 @@#include "local.h" int x2apic_phys; - -static struct apic apic_x2apic_phys;u32 x2apic_max_apicid__ro_after_init =UINT_MAX ;void __init x2apic_set_max_apicid (u32 apicid)
@@ -110,10 +108,7 @@ static int x2apic_phys_probe(void)if (!x2apic_mode)return 0 ; -if (x2apic_phys ||x2apic_fadt_phys ()) -return 1 ; - -return apic == &apic_x2apic_phys; +return x2apic_phys ||x2apic_fadt_phys (); }u32 x2apic_get_apic_id (u32 id)
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
[tip: x86/apic] x86/apic: Remove redundant check from x2apic_phys_probe()
The following commit has been merged into the x86/apic branch of tip:
The following commit has been merged into the x86/apic branch of tip:
Commit-ID: 98dff3f1bc033da4d4811d8f335fe7311dbf54df Gitweb: https://git.kernel.org/tip/98dff3f1bc033da4d4811d8f335fe7311dbf54df Author: Grzegorz Jaszczyk <[email protected]> AuthorDate: Thu, 24 Sep 2026 10:40:20 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Mon, 19 Oct 2026 18:21:25 -07:00
x86/apic: Remove redundant check from x2apic_phys_probe()
Commit
9ebd680bd029 ("x86, apic: Use probe routines to simplify apic selection")
introduced x2apic_phys_probe() with a generic fallback check for
apic == &apic_x2apic_phys
to preserve any prior selection of apic_x2apic_phys by default_acpi_madt_oem_check().
At the time, x2apic_acpi_madt_oem_check() only checked
x2apic_phys && x2apic_enabled()
so that fallback was already redundant. Commit
ea0dcf903e7d ("x86/apic: Use x2apic physical mode based on FADT setting")
later added the ACPI_FADT_APIC_PHYSICAL check only to x2apic_acpi_madt_oem_check(), temporarily relying on the fallback in x2apic_phys_probe() when x2APIC was pre-enabled by BIOS.
Subsequently,
cb214ede7657 ("x86/apic: Work around boot failure on HP ProLiant DL980 G7 Server systems")
factored out x2apic_fadt_phys() and added it directly to x2apic_phys_probe(). Because default_acpi_madt_oem_check() (via the .acpi_madt_oem_check callback) is the only path that can install apic_x2apic_phys prior to x2apic_phys_probe(), and x2apic_acpi_madt_oem_check() checks the exact same
x2apic_phys || x2apic_fadt_phys()
condition, the fallback
apic == &apic_x2apic_phys
check became completely unreachable again.
Remove the redundant check and the associated forward declaration of apic_x2apic_phys.
In addition to cleaning up dead code, this allows apic_x2apic_phys to be installed as an early boot default driver when hardware x2APIC is pre-enabled without preventing x2apic_cluster from being probed and selected later during boot.
[ bp: Massage commit message. ]
--- arch/x86/kernel/apic/x2apic_phys.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
arch/x86/kernel/apic/x2apic_phys.c +1 -6
@@ -6,8 +6,6 @@#include "local.h" int x2apic_phys; - -static struct apic apic_x2apic_phys;u32 x2apic_max_apicid__ro_after_init =UINT_MAX ;void __init x2apic_set_max_apicid (u32 apicid)
@@ -110,10 +108,7 @@ static int x2apic_phys_probe(void)if (!x2apic_mode)return 0 ; -if (x2apic_phys ||x2apic_fadt_phys ()) -return 1 ; - -return apic == &apic_x2apic_phys; +return x2apic_phys ||x2apic_fadt_phys (); }u32 x2apic_get_apic_id (u32 id)
[tip: x86/apic] x86/apic: Remove redundant check from x2apic_phys_probe()
In reply to Grzegorz JaszczykThe following commit has been merged into the x86/apic branch of tip:
The following commit has been merged into the x86/apic branch of tip:
Commit-ID: 2f4b3e8ea202808c6218e2bf67810dfcdb6cb883 Gitweb: https://git.kernel.org/tip/2f4b3e8ea202808c6218e2bf67810dfcdb6cb883 Author: Grzegorz Jaszczyk <[email protected]> AuthorDate: Thu, 24 Sep 2026 10:40:20 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Tue, 03 Nov 2026 17:04:02 -08:00
x86/apic: Remove redundant check from x2apic_phys_probe()
Commit
9ebd680bd029 ("x86, apic: Use probe routines to simplify apic selection")
introduced x2apic_phys_probe() with a generic fallback check for
apic == &apic_x2apic_phys
to preserve any prior selection of apic_x2apic_phys by default_acpi_madt_oem_check().
At the time, x2apic_acpi_madt_oem_check() only checked
x2apic_phys && x2apic_enabled()
so that fallback was already redundant. Commit
ea0dcf903e7d ("x86/apic: Use x2apic physical mode based on FADT setting")
later added the ACPI_FADT_APIC_PHYSICAL check only to x2apic_acpi_madt_oem_check(), temporarily relying on the fallback in x2apic_phys_probe() when x2APIC was pre-enabled by BIOS.
Subsequently,
cb214ede7657 ("x86/apic: Work around boot failure on HP ProLiant DL980 G7 Server systems")
factored out x2apic_fadt_phys() and added it directly to x2apic_phys_probe(). Because default_acpi_madt_oem_check() (via the .acpi_madt_oem_check callback) is the only path that can install apic_x2apic_phys prior to x2apic_phys_probe(), and x2apic_acpi_madt_oem_check() checks the exact same
x2apic_phys || x2apic_fadt_phys()
condition, the fallback
apic == &apic_x2apic_phys
check became completely unreachable again.
Remove the redundant check and the associated forward declaration of apic_x2apic_phys.
In addition to cleaning up dead code, this allows apic_x2apic_phys to be installed as an early boot default driver when hardware x2APIC is pre-enabled without preventing x2apic_cluster from being probed and selected later during boot.
[ bp: Massage commit message. ]
--- arch/x86/kernel/apic/x2apic_phys.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
arch/x86/kernel/apic/x2apic_phys.c +1 -6
@@ -6,8 +6,6 @@#include "local.h" int x2apic_phys; - -static struct apic apic_x2apic_phys;u32 x2apic_max_apicid__ro_after_init =UINT_MAX ;void __init x2apic_set_max_apicid (u32 apicid)
@@ -110,10 +108,7 @@ static int x2apic_phys_probe(void)if (!x2apic_mode)return 0 ; -if (x2apic_phys ||x2apic_fadt_phys ()) -return 1 ; - -return apic == &apic_x2apic_phys; +return x2apic_phys ||x2apic_fadt_phys (); }u32 x2apic_get_apic_id (u32 id)
PATCH v2 4/4 x86/apic: Switch to x2apic driver early if x2apic is enabled
In reply to Grzegorz JaszczykDuring early boot, the generic x86 kernel defaults to the MMIO-based APIC driver (apic_physflat). However, if the kernel is booted (e.g., via kexec) when x2APIC is already enabled in hardware, the MMIO interface to the APIC is disabled.
Normally, ACPI MADT probing would install an x2APIC driver early. However, if ACPI is disabled (e.g., CONFIG_ACPI is not set, as in crashdump kernels), x86_64_probe_apic() does not run until late_time_init() via apic_intr_mode_init().
This creates a window between local_irq_enable() and late_time_init() where interrupts are enabled, but the APIC driver pointer still points to apic_physflat. Because check_x2apic() detected hardware x2APIC mode and set x2apic_mode = 1, register_lapic_address() and apic_finalize_early_init() skip mapping the APIC fixmap. If a pending interrupt (e.g., left in IRR across kexec on secondary CPUs) fires during this window, native_apic_mem_eoi() is invoked, which attempts to write to the unmapped APIC EOI register, triggering an immediate kernel page fault (#PF).
To prevent this, replace apic_setup_apic_calls() with apic_install_default_driver(), have check_x2apic() return &apic_x2apic_phys when hardware x2APIC is enabled (or &apic_noop if x2APIC is enabled on a kernel built without CONFIG_X86_X2APIC), and install it as the default APIC driver in apic_early_init(). Similarly, if the local APIC is disabled via command line (apic_is_disabled) or acpi_mps_check(), install &apic_noop immediately as the default driver.
This ensures safe MSR-based or no-op APIC accesses during early boot while still allowing normal APIC probing (such as upgrading to apic_x2apic_cluster) to take place later during boot.
--- arch/x86/include/asm/apic.h | 4 ---- arch/x86/kernel/apic/apic.c | 22 ++++++++++++++------ arch/x86/kernel/apic/init.c | 32 +++++++++++++++++++----------- arch/x86/kernel/apic/local.h | 4 ++++ arch/x86/kernel/apic/x2apic_phys.c | 2 +- 5 files changed, 41 insertions(+), 23 deletions(-)
arch/x86/include/asm/apic.h +0 -4
@@ -367,9 +367,6 @@ extern int lapic_can_unplug_cpu(void);#ifdef CONFIG_X86_LOCAL_APIC extern struct apic_override __x86_apic_override; -void __init apic_setup_apic_calls (void ); -void __init apic_install_driver (struct apic *driver); -#define apic_update_callback (_callback, _fn) { \ __x86_apic_override._callback = _fn; \ apic->_callback = _fn; \
@@ -487,7 +484,6 @@ static inline void apic_icr_write(u32 low, u32 high) { }static inline void apic_wait_icr_idle (void ) { }static inline u32 safe_apic_wait_icr_idle (void ) {return 0 ; }static inline void apic_native_eoi (void ) {WARN_ON_ONCE (1 ); } -static inline void apic_setup_apic_calls (void ) { }static inline void apic_update_vector (unsigned int cpu,unsigned int vector,bool set) { }#define apic_update_callback (_callback, _fn) do { } while (0)
arch/x86/kernel/apic/apic.c +16 -6
@@ -1869,7 +1869,7 @@ static __init void try_to_enable_x2apic(int remap_mode)x2apic_enable (); } -static void __init check_x2apic (void ) +static __init struct apic *check_x2apic (void ) {if (x2apic_enabled ()) {pr_info ("x2apic: enabled by BIOS, switching to x2apic ops\n" );
@@ -1879,15 +1879,21 @@ static void __init check_x2apic(void) else x2apic_state =X2APIC_ON ;apic_read_boot_cpu_id (true); + +/* Force the initial driver to X2APIC */ + return &apic_x2apic_phys; }else if (!boot_cpu_has (X86_FEATURE_X2APIC )) { x2apic_state =X2APIC_DISABLED ; } + +/* Keep the default driver */ +return NULL ; }#else /* CONFIG_X86_X2APIC */ -static void __init check_x2apic (void ) +static __init struct apic *check_x2apic (void ) {if (!apic_is_x2apic_enabled ()) -return ; +return NULL ;/* * Checkme: Can we simply turn off x2APIC here instead of disabling the APIC? */
@@ -1896,6 +1902,7 @@ static void __init check_x2apic(void) apic_is_disabled = true;setup_clear_cpu_cap (X86_FEATURE_APIC ); +return &apic_noop; }static inline void try_to_enable_x2apic (int remap_mode) { }
@@ -2066,14 +2073,17 @@ static bool __init detect_init_APIC(void)void __init apic_early_init (void ) { -if (acpi_mps_check ()) { +struct apic *driver; + +if (apic_is_disabled ||acpi_mps_check ()) { apic_is_disabled = true;setup_clear_cpu_cap (X86_FEATURE_APIC ); + driver = &apic_noop; }else { -check_x2apic (); + driver =check_x2apic (); } -apic_setup_apic_calls (); +apic_install_default_driver (driver); }void __init apic_finalize_early_init (void )
arch/x86/kernel/apic/init.c +20 -12
@@ -80,19 +80,8 @@ static __init void update_static_calls(void)update_call (wakeup_secondary_cpu_64); } -void __init apic_setup_apic_calls (void ) +static void __init __apic_install_driver (struct apic *driver) { -/* Ensure that the default APIC has native_eoi populated */ - apic->native_eoi = apic->eoi; -update_static_calls (); -pr_info ("Static calls initialized\n" ); -} - -void __init apic_install_driver (struct apic *driver) -{ -if (apic == driver) -return ; - apic = driver;if (IS_ENABLED (CONFIG_X86_X2APIC ) && apic->x2apic_set_max_apicid)
@@ -105,6 +94,25 @@ void __init apic_install_driver(struct apic *driver)/* Apply any already installed callback overrides */ restore_override_callbacks ();update_static_calls (); +} + +void __init apic_install_default_driver (struct apic *driver) +{ +if (driver) { +__apic_install_driver (driver); + }else { +/* Ensure that the default APIC has the native_eoi() callback populated */ + apic->native_eoi = apic->eoi; +update_static_calls (); + } +pr_info ("Set default APIC routing to: %s\n" , apic->name); +} + +void __init apic_install_driver (struct apic *driver) +{ +if (apic == driver) +return ; +__apic_install_driver (driver);pr_info ("Switched APIC routing to: %s\n" , driver->name); }
arch/x86/kernel/apic/local.h +4 -0
@@ -13,12 +13,16 @@#include <asm/irq_vectors.h> #include <asm/apic.h> +void __init apic_install_default_driver (struct apic *driver); +void __init apic_install_driver (struct apic *driver); +/* X2APIC */ u32 x2apic_get_apic_id (u32 id);void x2apic_send_IPI_all (int vector);void x2apic_send_IPI_allbutself (int vector);void x2apic_send_IPI_self (int vector); +extern struct apic apic_x2apic_phys;extern u32 x2apic_max_apicid;/* IPI */
arch/x86/kernel/apic/x2apic_phys.c +1 -1
@@ -116,7 +116,7 @@ u32 x2apic_get_apic_id(u32 id)return id; } -static struct apic apic_x2apic_phys__ro_after_init = { +struct apic apic_x2apic_phys__ro_after_init = { .name ="physical x2apic" , .probe = x2apic_phys_probe,
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
The following commit has been merged into the x86/apic branch of tip:
The following commit has been merged into the x86/apic branch of tip:
Commit-ID: 37b841b51a2689da002350c295deac91946c0881 Gitweb: https://git.kernel.org/tip/37b841b51a2689da002350c295deac91946c0881 Author: Grzegorz Jaszczyk <[email protected]> AuthorDate: Thu, 24 Sep 2026 10:40:21 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Mon, 19 Oct 2026 18:35:37 -07:00
x86/apic: Switch to x2apic driver early if x2apic is enabled
During early boot, the generic x86 kernel defaults to the MMIO-based APIC driver (apic_physflat). However, if the kernel is booted (e.g., via kexec) when x2APIC is already enabled in hardware, the MMIO interface to the APIC is disabled.
Normally, ACPI MADT probing would install an x2APIC driver early. However, if ACPI is disabled (e.g., CONFIG_ACPI is not set, as in crashdump kernels), x86_64_probe_apic() does not run until late_time_init() via apic_intr_mode_init().
This creates a window between local_irq_enable() and late_time_init() where interrupts are enabled, but the APIC driver pointer still points to apic_physflat. Because check_x2apic() detected hardware x2APIC mode and set x2apic_mode = 1, register_lapic_address() and apic_finalize_early_init() skip mapping the APIC fixmap.
If a pending interrupt (e.g., left in IRR across kexec on secondary CPUs) fires during this window, native_apic_mem_eoi() is invoked, which attempts to write to the unmapped APIC EOI register, triggering an immediate kernel page fault (#PF).
To prevent this, make x2APIC the default driver on hardware which supports it.
Similarly, if the local APIC is disabled via command line (apic_is_disabled) or acpi_mps_check(), install &apic_noop immediately as the default driver.
This ensures safe MSR-based or no-op APIC accesses during early boot while still allowing normal APIC probing (such as upgrading to apic_x2apic_cluster) to take place later during boot.
[ bp: Massage commit message. ]
--- arch/x86/include/asm/apic.h | 4 +---- arch/x86/kernel/apic/apic.c | 22 ++++++++++++++------ arch/x86/kernel/apic/init.c | 32 ++++++++++++++++++----------- arch/x86/kernel/apic/local.h | 4 ++++- arch/x86/kernel/apic/x2apic_phys.c | 2 +- 5 files changed, 41 insertions(+), 23 deletions(-)
arch/x86/include/asm/apic.h +0 -4
@@ -367,9 +367,6 @@ extern int lapic_can_unplug_cpu(void);#ifdef CONFIG_X86_LOCAL_APIC extern struct apic_override __x86_apic_override; -void __init apic_setup_apic_calls (void ); -void __init apic_install_driver (struct apic *driver); -#define apic_update_callback (_callback, _fn) { \ __x86_apic_override._callback = _fn; \ apic->_callback = _fn; \
@@ -487,7 +484,6 @@ static inline void apic_icr_write(u32 low, u32 high) { }static inline void apic_wait_icr_idle (void ) { }static inline u32 safe_apic_wait_icr_idle (void ) {return 0 ; }static inline void apic_native_eoi (void ) {WARN_ON_ONCE (1 ); } -static inline void apic_setup_apic_calls (void ) { }static inline void apic_update_vector (unsigned int cpu,unsigned int vector,bool set) { }#define apic_update_callback (_callback, _fn) do { } while (0)
arch/x86/kernel/apic/apic.c +16 -6
@@ -1869,7 +1869,7 @@ static __init void try_to_enable_x2apic(int remap_mode)x2apic_enable (); } -static void __init check_x2apic (void ) +static __init struct apic *check_x2apic (void ) {if (x2apic_enabled ()) {pr_info ("x2apic: enabled by BIOS, switching to x2apic ops\n" );
@@ -1879,15 +1879,21 @@ static void __init check_x2apic(void) else x2apic_state =X2APIC_ON ;apic_read_boot_cpu_id (true); + +/* Force the initial driver to X2APIC */ + return &apic_x2apic_phys; }else if (!boot_cpu_has (X86_FEATURE_X2APIC )) { x2apic_state =X2APIC_DISABLED ; } + +/* Keep the default driver */ +return NULL ; }#else /* CONFIG_X86_X2APIC */ -static void __init check_x2apic (void ) +static __init struct apic *check_x2apic (void ) {if (!apic_is_x2apic_enabled ()) -return ; +return NULL ;/* * Checkme: Can we simply turn off x2APIC here instead of disabling the APIC? */
@@ -1896,6 +1902,7 @@ static void __init check_x2apic(void) apic_is_disabled = true;setup_clear_cpu_cap (X86_FEATURE_APIC ); +return &apic_noop; }static inline void try_to_enable_x2apic (int remap_mode) { }
@@ -2066,14 +2073,17 @@ no_apic:void __init apic_early_init (void ) { -if (acpi_mps_check ()) { +struct apic *driver; + +if (apic_is_disabled ||acpi_mps_check ()) { apic_is_disabled = true;setup_clear_cpu_cap (X86_FEATURE_APIC ); + driver = &apic_noop; }else { -check_x2apic (); + driver =check_x2apic (); } -apic_setup_apic_calls (); +apic_install_default_driver (driver); }void __init apic_finalize_early_init (void )
arch/x86/kernel/apic/init.c +20 -12
@@ -80,19 +80,8 @@ static __init void update_static_calls(void)update_call (wakeup_secondary_cpu_64); } -void __init apic_setup_apic_calls (void ) +static void __init __apic_install_driver (struct apic *driver) { -/* Ensure that the default APIC has native_eoi populated */ - apic->native_eoi = apic->eoi; -update_static_calls (); -pr_info ("Static calls initialized\n" ); -} - -void __init apic_install_driver (struct apic *driver) -{ -if (apic == driver) -return ; - apic = driver;if (IS_ENABLED (CONFIG_X86_X2APIC ) && apic->x2apic_set_max_apicid)
@@ -105,6 +94,25 @@ void __init apic_install_driver(struct apic *driver)/* Apply any already installed callback overrides */ restore_override_callbacks ();update_static_calls (); +} + +void __init apic_install_default_driver (struct apic *driver) +{ +if (driver) { +__apic_install_driver (driver); + }else { +/* Ensure that the default APIC has the native_eoi() callback populated */ + apic->native_eoi = apic->eoi; +update_static_calls (); + } +pr_info ("Set default APIC routing to: %s\n" , apic->name); +} + +void __init apic_install_driver (struct apic *driver) +{ +if (apic == driver) +return ; +__apic_install_driver (driver);pr_info ("Switched APIC routing to: %s\n" , driver->name); }
arch/x86/kernel/apic/local.h +4 -0
@@ -13,12 +13,16 @@#include <asm/irq_vectors.h> #include <asm/apic.h> +void __init apic_install_default_driver (struct apic *driver); +void __init apic_install_driver (struct apic *driver); +/* X2APIC */ u32 x2apic_get_apic_id (u32 id);void x2apic_send_IPI_all (int vector);void x2apic_send_IPI_allbutself (int vector);void x2apic_send_IPI_self (int vector); +extern struct apic apic_x2apic_phys;extern u32 x2apic_max_apicid;/* IPI */
arch/x86/kernel/apic/x2apic_phys.c +1 -1
@@ -116,7 +116,7 @@ u32 x2apic_get_apic_id(u32 id)return id; } -static struct apic apic_x2apic_phys__ro_after_init = { +struct apic apic_x2apic_phys__ro_after_init = { .name ="physical x2apic" , .probe = x2apic_phys_probe,
The following commit has been merged into the x86/apic branch of tip:
The following commit has been merged into the x86/apic branch of tip:
Commit-ID: 85c0baaf44b53389e997176dc0cf006416456050 Gitweb: https://git.kernel.org/tip/85c0baaf44b53389e997176dc0cf006416456050 Author: Grzegorz Jaszczyk <[email protected]> AuthorDate: Thu, 24 Sep 2026 10:40:21 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Tue, 03 Nov 2026 17:04:03 -08:00
x86/apic: Switch to x2apic driver early if x2apic is enabled
During early boot, the generic x86 kernel defaults to the MMIO-based APIC driver (apic_physflat). However, if the kernel is booted (e.g., via kexec) when x2APIC is already enabled in hardware, the MMIO interface to the APIC is disabled.
Normally, ACPI MADT probing would install an x2APIC driver early. However, if ACPI is disabled (e.g., CONFIG_ACPI is not set, as in crashdump kernels), x86_64_probe_apic() does not run until late_time_init() via apic_intr_mode_init().
This creates a window between local_irq_enable() and late_time_init() where interrupts are enabled, but the APIC driver pointer still points to apic_physflat. Because check_x2apic() detected hardware x2APIC mode and set x2apic_mode = 1, register_lapic_address() and apic_finalize_early_init() skip mapping the APIC fixmap.
If a pending interrupt (e.g., left in IRR across kexec on secondary CPUs) fires during this window, native_apic_mem_eoi() is invoked, which attempts to write to the unmapped APIC EOI register, triggering an immediate kernel page fault (#PF).
To prevent this, make x2APIC the default driver on hardware which supports it.
Similarly, if the local APIC is disabled via command line (apic_is_disabled) or acpi_mps_check(), install &apic_noop immediately as the default driver.
This ensures safe MSR-based or no-op APIC accesses during early boot while still allowing normal APIC probing (such as upgrading to apic_x2apic_cluster) to take place later during boot.
[ bp: Massage commit message. ]
--- arch/x86/include/asm/apic.h | 4 +---- arch/x86/kernel/apic/apic.c | 22 ++++++++++++++------ arch/x86/kernel/apic/init.c | 32 ++++++++++++++++++----------- arch/x86/kernel/apic/local.h | 4 ++++- arch/x86/kernel/apic/x2apic_phys.c | 2 +- 5 files changed, 41 insertions(+), 23 deletions(-)
arch/x86/include/asm/apic.h +0 -4
@@ -367,9 +367,6 @@ extern int lapic_can_unplug_cpu(void);#ifdef CONFIG_X86_LOCAL_APIC extern struct apic_override __x86_apic_override; -void __init apic_setup_apic_calls (void ); -void __init apic_install_driver (struct apic *driver); -#define apic_update_callback (_callback, _fn) { \ __x86_apic_override._callback = _fn; \ apic->_callback = _fn; \
@@ -487,7 +484,6 @@ static inline void apic_icr_write(u32 low, u32 high) { }static inline void apic_wait_icr_idle (void ) { }static inline u32 safe_apic_wait_icr_idle (void ) {return 0 ; }static inline void apic_native_eoi (void ) {WARN_ON_ONCE (1 ); } -static inline void apic_setup_apic_calls (void ) { }static inline void apic_update_vector (unsigned int cpu,unsigned int vector,bool set) { }#define apic_update_callback (_callback, _fn) do { } while (0)
arch/x86/kernel/apic/apic.c +16 -6
@@ -1869,7 +1869,7 @@ static __init void try_to_enable_x2apic(int remap_mode)x2apic_enable (); } -static void __init check_x2apic (void ) +static __init struct apic *check_x2apic (void ) {if (x2apic_enabled ()) {pr_info ("x2apic: enabled by BIOS, switching to x2apic ops\n" );
@@ -1879,15 +1879,21 @@ static void __init check_x2apic(void) else x2apic_state =X2APIC_ON ;apic_read_boot_cpu_id (true); + +/* Force the initial driver to X2APIC */ + return &apic_x2apic_phys; }else if (!boot_cpu_has (X86_FEATURE_X2APIC )) { x2apic_state =X2APIC_DISABLED ; } + +/* Keep the default driver */ +return NULL ; }#else /* CONFIG_X86_X2APIC */ -static void __init check_x2apic (void ) +static __init struct apic *check_x2apic (void ) {if (!apic_is_x2apic_enabled ()) -return ; +return NULL ;/* * Checkme: Can we simply turn off x2APIC here instead of disabling the APIC? */
@@ -1896,6 +1902,7 @@ static void __init check_x2apic(void) apic_is_disabled = true;setup_clear_cpu_cap (X86_FEATURE_APIC ); +return &apic_noop; }static inline void try_to_enable_x2apic (int remap_mode) { }
@@ -2066,14 +2073,17 @@ no_apic:void __init apic_early_init (void ) { -if (acpi_mps_check ()) { +struct apic *driver; + +if (apic_is_disabled ||acpi_mps_check ()) { apic_is_disabled = true;setup_clear_cpu_cap (X86_FEATURE_APIC ); + driver = &apic_noop; }else { -check_x2apic (); + driver =check_x2apic (); } -apic_setup_apic_calls (); +apic_install_default_driver (driver); }void __init apic_finalize_early_init (void )
arch/x86/kernel/apic/init.c +20 -12
@@ -80,19 +80,8 @@ static __init void update_static_calls(void)update_call (wakeup_secondary_cpu_64); } -void __init apic_setup_apic_calls (void ) +static void __init __apic_install_driver (struct apic *driver) { -/* Ensure that the default APIC has native_eoi populated */ - apic->native_eoi = apic->eoi; -update_static_calls (); -pr_info ("Static calls initialized\n" ); -} - -void __init apic_install_driver (struct apic *driver) -{ -if (apic == driver) -return ; - apic = driver;if (IS_ENABLED (CONFIG_X86_X2APIC ) && apic->x2apic_set_max_apicid)
@@ -105,6 +94,25 @@ void __init apic_install_driver(struct apic *driver)/* Apply any already installed callback overrides */ restore_override_callbacks ();update_static_calls (); +} + +void __init apic_install_default_driver (struct apic *driver) +{ +if (driver) { +__apic_install_driver (driver); + }else { +/* Ensure that the default APIC has the native_eoi() callback populated */ + apic->native_eoi = apic->eoi; +update_static_calls (); + } +pr_info ("Set default APIC routing to: %s\n" , apic->name); +} + +void __init apic_install_driver (struct apic *driver) +{ +if (apic == driver) +return ; +__apic_install_driver (driver);pr_info ("Switched APIC routing to: %s\n" , driver->name); }
arch/x86/kernel/apic/local.h +4 -0
@@ -13,12 +13,16 @@#include <asm/irq_vectors.h> #include <asm/apic.h> +void __init apic_install_default_driver (struct apic *driver); +void __init apic_install_driver (struct apic *driver); +/* X2APIC */ u32 x2apic_get_apic_id (u32 id);void x2apic_send_IPI_all (int vector);void x2apic_send_IPI_allbutself (int vector);void x2apic_send_IPI_self (int vector); +extern struct apic apic_x2apic_phys;extern u32 x2apic_max_apicid;/* IPI */
arch/x86/kernel/apic/x2apic_phys.c +1 -1
@@ -116,7 +116,7 @@ u32 x2apic_get_apic_id(u32 id)return id; } -static struct apic apic_x2apic_phys__ro_after_init = { +struct apic apic_x2apic_phys__ro_after_init = { .name ="physical x2apic" , .probe = x2apic_phys_probe,
Quoted 13 lines · Grzegorz Jaszczyk
During early boot, the generic x86 kernel defaults to the MMIO-based APIC driver (
apic_physflat). When booting (e.g., via kexec into a crashdump kernel) with x2APIC already enabled in hardware and without ACPI MADT probing (e.g., !CONFIG_ACPI), the APIC driver pointer remains set toapic_physflatuntillate_time_init()runsx86_64_probe_apic().Because
check_x2apic()detects hardware x2APIC mode and setsx2apic_mode= 1, the APIC MMIO fixmap is not mapped. If a pending interrupt fires in the window betweenlocal_irq_enable()andlate_time_init(),native_apic_mem_eoi()attempts to write to the unmapped APIC EOI MMIO address, resulting in an early boot page fault (#PF).
Quoted 6 lines
This series restructures early APIC initialization and installs
apic_x2apic_phys(orapic_noopif the APIC is disabled or built withoutCONFIG_X86_X2APIC) as the default APIC driver inapic_early_init(), ensuring safe MSR-based or no-op APIC accesses while still allowing later APIC probing (e.g., upgrading toapic_x2apic_cluster) to proceed normally.