[PATCH v2 0/4] x86/apic: Switch to x2apic driver early if x2apic is enabled

Grzegorz Jaszczyk posted 4 patches an hour ago
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(-)
[PATCH v2 0/4] x86/apic: Switch to x2apic driver early if x2apic is enabled
Posted by Grzegorz Jaszczyk an hour ago
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/20260910090512.1197517-1-jaszczyk@chromium.org/

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(-)

-- 
2.56.0.rc1.315.gc6ed9934b7-goog