Commit 79c9a17c authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Dave Hansen
Browse files

x86/apic/32: Decrapify the def_bigsmp mechanism



If the system has more than 8 CPUs then XAPIC and the bigsmp APIC driver is
required. This is ensured via:

  1) Enumerating all possible CPUs up to NR_CPUS

  2) Checking at boot CPU APIC setup time whether the system has more than
     8 CPUs and has an XAPIC.

     If that's the case then it's attempted to install the bigsmp APIC
     driver and a magic variable 'def_to_bigsmp' is set to one.

  3) If that magic variable is set and CONFIG_X86_BIGSMP=n and the system
     has more than 8 CPUs smp_sanity_check() removes all CPUs >= #8 from
     the present and possible mask in the most convoluted way.

This logic is completely broken for the case where the bigsmp driver is
enabled, but not selected due to a command line option specifying the
default APIC. In that case the system boots with default APIC in logical
destination mode and fails to reduce the number of CPUs.

That aside the above which is sprinkled over 3 different places is yet
another piece of art.

It would have been too obvious to check the requirements upfront and limit
nr_cpu_ids _before_ enumerating tons of CPUs and then removing them again.

Implement exactly this. Check the bigsmp requirement when the boot APIC is
registered which happens _before_ ACPI/MPTABLE parsing and limit the number
of CPUs to 8 if it can't be used. Switch it over when the boot CPU apic is
set up if necessary.

[ dhansen: fix nr_cpu_ids off-by-one in default_setup_apic_routing() ]

Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: default avatarMichael Kelley <mikelley@microsoft.com>
Tested-by: default avatarSohil Mehta <sohil.mehta@intel.com>
Tested-by: Juergen Gross <jgross@suse.com> # Xen PV (dom0 and unpriv. guest)
parent d75baa26
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -23,8 +23,6 @@ extern int pic_mode;

#define MAX_IRQ_SOURCES		256

extern unsigned int def_to_bigsmp;

#else /* CONFIG_X86_64: */

#define MAX_MP_BUSSES		256
+3 −0
Original line number Diff line number Diff line
@@ -63,6 +63,8 @@
#include <asm/irq_regs.h>
#include <asm/cpu.h>

#include "local.h"

unsigned int num_processors;

unsigned disabled_cpus;
@@ -2420,6 +2422,7 @@ static __init void cpu_set_boot_apic(void)
{
	cpuid_to_apicid[0] = boot_cpu_physical_apicid;
	cpu_update_apic(0, boot_cpu_physical_apicid);
	x86_32_probe_bigsmp_early();
}

int generic_processor_info(int apicid)
+10 −12
Original line number Diff line number Diff line
@@ -100,12 +100,7 @@ static const struct dmi_system_id bigsmp_dmi_table[] = {

static int probe_bigsmp(void)
{
	if (def_to_bigsmp)
		dmi_bigsmp = 1;
	else
		dmi_check_system(bigsmp_dmi_table);

	return dmi_bigsmp;
	return dmi_check_system(bigsmp_dmi_table);
}

static struct apic apic_bigsmp __ro_after_init = {
@@ -149,14 +144,17 @@ static struct apic apic_bigsmp __ro_after_init = {
	.safe_wait_icr_idle		= native_safe_apic_wait_icr_idle,
};

void __init generic_bigsmp_probe(void)
bool __init apic_bigsmp_possible(bool cmdline_override)
{
	if (!probe_bigsmp())
		return;
	return apic == &apic_bigsmp || !cmdline_override;
}

void __init apic_bigsmp_force(void)
{
	if (apic != &apic_bigsmp) {
		apic = &apic_bigsmp;

	pr_info("Overriding APIC driver with %s\n", apic_bigsmp.name);
		pr_info("Overriding APIC driver with bigsmp\n");
	}
}

apic_driver(apic_bigsmp);
+11 −0
Original line number Diff line number Diff line
@@ -66,4 +66,15 @@ void default_send_IPI_self(int vector);
void default_send_IPI_mask_sequence_logical(const struct cpumask *mask, int vector);
void default_send_IPI_mask_allbutself_logical(const struct cpumask *mask, int vector);
void default_send_IPI_mask_logical(const struct cpumask *mask, int vector);
void x86_32_probe_bigsmp_early(void);
#else
static inline void x86_32_probe_bigsmp_early(void) { }
#endif

#ifdef CONFIG_X86_BIGSMP
bool apic_bigsmp_possible(bool cmdline_selected);
void apic_bigsmp_force(void);
#else
static inline bool apic_bigsmp_possible(bool cmdline_selected) { return false; };
static inline void apic_bigsmp_force(void) { }
#endif
+17 −18
Original line number Diff line number Diff line
@@ -10,6 +10,8 @@
#include <linux/errno.h>
#include <linux/smp.h>

#include <xen/xen.h>

#include <asm/io_apic.h>
#include <asm/apic.h>
#include <asm/acpi.h>
@@ -123,36 +125,33 @@ static int __init parse_apic(char *arg)
}
early_param("apic", parse_apic);

void __init default_setup_apic_routing(void)
void __init x86_32_probe_bigsmp_early(void)
{
	int version = boot_cpu_apic_version;
	if (nr_cpu_ids <= 8 || xen_pv_domain())
		return;

	if (num_possible_cpus() > 8) {
	if (IS_ENABLED(CONFIG_X86_BIGSMP)) {
		switch (boot_cpu_data.x86_vendor) {
		case X86_VENDOR_INTEL:
			if (!APIC_XAPIC(version)) {
				def_to_bigsmp = 0;
			if (!APIC_XAPIC(boot_cpu_apic_version))
				break;
			}
			/* P4 and above */
			fallthrough;
		case X86_VENDOR_HYGON:
		case X86_VENDOR_AMD:
			def_to_bigsmp = 1;
			if (apic_bigsmp_possible(cmdline_apic))
				return;
			break;
		}
	}
	pr_info("Limiting to 8 possible CPUs\n");
	set_nr_cpu_ids(8);
}

#ifdef CONFIG_X86_BIGSMP
	/*
	 * This is used to switch to bigsmp mode when
	 * - There is no apic= option specified by the user
	 * - generic_apic_probe() has chosen apic_default as the sub_arch
	 * - we find more than 8 CPUs in acpi LAPIC listing with xAPIC support
	 */

	if (!cmdline_apic && apic == &apic_default)
		generic_bigsmp_probe();
#endif
void __init default_setup_apic_routing(void)
{
	if (nr_cpu_ids > 8 && !xen_pv_domain())
		apic_bigsmp_force();

	if (apic->setup_apic_routing)
		apic->setup_apic_routing();
Loading