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. ]
Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Grzegorz Jaszczyk <jaszczyk@chromium.org>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Thomas Gleixner <tglx@kernel.org>
Link: https://patch.msgid.link/20260924104102.3534474-5-jaszczyk@chromium.org
5 files changed