mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: Grzegorz Jaszczyk <jaszczyk@chromium.org>, tglx@kernel.org
Cc: linux-kernel@vger.kernel.org, dmaluka@chromium.org,
	vineethrp@chromium.org, chuanxiao.dong@intel.com,
	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>,
	Eric Dumazet <edumazet@google.com>,
	Melody Wang <huibo.wang@amd.com>
Subject: Re: [PATCH] x86/apic: Switch to x2apic driver early if x2apic is enabled
Date: Thu, 10 Sep 2026 08:23:30 -0700	[thread overview]
Message-ID: <5a09dd3a-7e14-4649-af53-f1da19343fab@intel.com> (raw)
In-Reply-To: <20260910090512.1197517-1-jaszczyk@chromium.org>

On 9/10/26 02:04, Grzegorz Jaszczyk wrote:
> 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.

There's also some new hardware that locks the hardware in x2apic mode. I
wonder if it has a similar problem.

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

Is this "default_acpi_madt_oem_check()" that uses apic_install_driver()?

> 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, init_apic_mappings() skipped 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).

Long-term, it seems like reducing the use of x2apic_mode would be really
nice.

> To prevent this, check if x2apic is enabled in hardware during early APIC
> call setup in apic_setup_apic_calls() and switch the default APIC driver
> from apic_physflat to apic_x2apic_phys immediately. This ensures that any
> early EOI writes use safe MSR-based accesses. The driver can still be
> upgraded later during the normal APIC probe phase.
>
> 
> diff --git a/arch/x86/kernel/apic/init.c b/arch/x86/kernel/apic/init.c
> index 821e2e536f19..c48323f725e7 100644
> --- a/arch/x86/kernel/apic/init.c
> +++ b/arch/x86/kernel/apic/init.c
> @@ -82,6 +82,8 @@ static __init void update_static_calls(void)
>  
>  void __init apic_setup_apic_calls(void)
>  {
> +	x2apic_phys_early_init();
> +
>  	/* Ensure that the default APIC has native_eoi populated */
>  	apic->native_eoi = apic->eoi;
>  	update_static_calls();

This seems a bit ad-hoc.

>  apic_driver(apic_x2apic_phys);
> +
> +void __init x2apic_phys_early_init(void)
> +{
> +	if (x2apic_enabled()) {
> +		apic = &apic_x2apic_phys;
> +		if (apic->x2apic_set_max_apicid)
> +			apic->max_apic_id = x2apic_max_apicid;
> +		pr_info("Switched default APIC to: %s\n", apic->name);
> +	}
> +}

This seems to be a subset of what apic_install_driver() and
apic_x2apic_phys->probe() do, down do the pr_info().

Even if those are overkill for this, it would be nice to use them for
consistency if they function.

It also seems like some of the more obscure apic drivers depend on
x2apic_mode. They also seem like they might be selected by the MADT
search. Could this end up overwriting those?

Maybe this is too much work for the task at hand, but this does seem to
show that there's some information missing from 'struct apic'. Say
apic_physflat had an ->initialized() that was false until its MMIO was
unmapped and apic_x2apic_phys->initialized() pointed over to:
x2apic_enabled().

apic_setup_apic_calls()
{
	// Search for an APIC driver that is initialized:
	for_each(drv) {
		if (!drv->initialized())
			continue;
		
		apic_install_driver(drv);
	}
}

Basically, I'm wondering if it's worth continuing to special-case x2apic
handling or whether it should just be a part of the apic driver
infrastructure.

  reply	other threads:[~2026-09-10 15:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10  9:04 Grzegorz Jaszczyk
2026-09-10 15:23 ` Dave Hansen [this message]
2026-09-11 15:11   ` Grzegorz Jaszczyk
2026-09-11 12:51 ` Thomas Gleixner
2026-09-11 15:17   ` Grzegorz Jaszczyk
2026-09-16 21:20     ` Thomas Gleixner

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=5a09dd3a-7e14-4649-af53-f1da19343fab@intel.com \
    --to=dave.hansen@intel.com \
    --cc=bp@alien8.de \
    --cc=chuanxiao.dong@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=dmaluka@chromium.org \
    --cc=edumazet@google.com \
    --cc=hpa@zytor.com \
    --cc=huibo.wang@amd.com \
    --cc=jaszczyk@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@kernel.org \
    --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®