Commit 9d85eb91 authored by Thomas Gleixner's avatar Thomas Gleixner

x86/smpboot: Make logical package management more robust

The logical package management has several issues:

 - The APIC ids provided by ACPI are not required to be the same as the
   initial APIC id which can be retrieved by CPUID. The APIC ids provided
   by ACPI are those which are written by the BIOS into the APIC. The
   initial id is set by hardware and can not be changed. The hardware
   provided ids contain the real hardware package information.

   Especially AMD sets the effective APIC id different from the hardware id
   as they need to reserve space for the IOAPIC ids starting at id 0.

   As a consequence those machines trigger the currently active firmware
   bug printouts in dmesg, These are obviously wrong.

 - Virtual machines have their own interesting of enumerating APICs and
   packages which are not reliably covered by the current implementation.

The sizing of the mapping array has been tweaked to be generously large to
handle systems which provide a wrong core count when HT is disabled so the
whole magic which checks for space in the physical hotplug case is not
needed anymore.

Simplify the whole machinery and do the mapping when the CPU starts and the
CPUID derived physical package information is available. This solves the
observed problems on AMD machines and works for the virtualization issues
as well.

Remove the extra call from XEN cpu bringup code as it is not longer
required.

Fixes: d49597fd ("x86/cpu: Deal with broken firmware (VMWare/XEN)")
Reported-and-tested-by: default avatarBorislav Petkov <bp@suse.de>
Tested-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Cc: Juergen Gross <jgross@suse.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: M. Vefa Bicakci <m.v.b@runbox.com>
Cc: xen-devel <xen-devel@lists.xen.org>
Cc: Charles (Chas) Williams <ciwillia@brocade.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Alok Kataria <akataria@vmware.com>
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/alpine.DEB.2.20.1612121102260.3429@nanosSigned-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent f082f02c
...@@ -2159,21 +2159,6 @@ int __generic_processor_info(int apicid, int version, bool enabled) ...@@ -2159,21 +2159,6 @@ int __generic_processor_info(int apicid, int version, bool enabled)
} }
} }
/*
* This can happen on physical hotplug. The sanity check at boot time
* is done from native_smp_prepare_cpus() after num_possible_cpus() is
* established.
*/
if (topology_update_package_map(apicid, cpu) < 0) {
int thiscpu = max + disabled_cpus;
pr_warning("APIC: Package limit reached. Processor %d/0x%x ignored.\n",
thiscpu, apicid);
disabled_cpus++;
return -ENOSPC;
}
/* /*
* Validate version * Validate version
*/ */
......
...@@ -979,29 +979,21 @@ static void x86_init_cache_qos(struct cpuinfo_x86 *c) ...@@ -979,29 +979,21 @@ static void x86_init_cache_qos(struct cpuinfo_x86 *c)
} }
/* /*
* The physical to logical package id mapping is initialized from the * Validate that ACPI/mptables have the same information about the
* acpi/mptables information. Make sure that CPUID actually agrees with * effective APIC id and update the package map.
* that.
*/ */
static void sanitize_package_id(struct cpuinfo_x86 *c) static void validate_apic_and_package_id(struct cpuinfo_x86 *c)
{ {
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
unsigned int pkg, apicid, cpu = smp_processor_id(); unsigned int apicid, cpu = smp_processor_id();
apicid = apic->cpu_present_to_apicid(cpu); apicid = apic->cpu_present_to_apicid(cpu);
pkg = apicid >> boot_cpu_data.x86_coreid_bits;
if (apicid != c->initial_apicid) { if (apicid != c->apicid) {
pr_err(FW_BUG "CPU%u: APIC id mismatch. Firmware: %x CPUID: %x\n", pr_err(FW_BUG "CPU%u: APIC id mismatch. Firmware: %x APIC: %x\n",
cpu, apicid, c->initial_apicid); cpu, apicid, c->initial_apicid);
c->initial_apicid = apicid;
} }
if (pkg != c->phys_proc_id) { BUG_ON(topology_update_package_map(c->phys_proc_id, cpu));
pr_err(FW_BUG "CPU%u: Using firmware package id %u instead of %u\n",
cpu, pkg, c->phys_proc_id);
c->phys_proc_id = pkg;
}
c->logical_proc_id = topology_phys_to_logical_pkg(pkg);
#else #else
c->logical_proc_id = 0; c->logical_proc_id = 0;
#endif #endif
...@@ -1132,7 +1124,6 @@ static void identify_cpu(struct cpuinfo_x86 *c) ...@@ -1132,7 +1124,6 @@ static void identify_cpu(struct cpuinfo_x86 *c)
#ifdef CONFIG_NUMA #ifdef CONFIG_NUMA
numa_add_cpu(smp_processor_id()); numa_add_cpu(smp_processor_id());
#endif #endif
sanitize_package_id(c);
} }
/* /*
...@@ -1187,6 +1178,7 @@ void identify_secondary_cpu(struct cpuinfo_x86 *c) ...@@ -1187,6 +1178,7 @@ void identify_secondary_cpu(struct cpuinfo_x86 *c)
enable_sep_cpu(); enable_sep_cpu();
#endif #endif
mtrr_ap_init(); mtrr_ap_init();
validate_apic_and_package_id(c);
} }
static __init int setup_noclflush(char *arg) static __init int setup_noclflush(char *arg)
......
...@@ -103,7 +103,6 @@ static unsigned int max_physical_pkg_id __read_mostly; ...@@ -103,7 +103,6 @@ static unsigned int max_physical_pkg_id __read_mostly;
unsigned int __max_logical_packages __read_mostly; unsigned int __max_logical_packages __read_mostly;
EXPORT_SYMBOL(__max_logical_packages); EXPORT_SYMBOL(__max_logical_packages);
static unsigned int logical_packages __read_mostly; static unsigned int logical_packages __read_mostly;
static bool logical_packages_frozen __read_mostly;
/* Maximum number of SMT threads on any online core */ /* Maximum number of SMT threads on any online core */
int __max_smt_threads __read_mostly; int __max_smt_threads __read_mostly;
...@@ -273,9 +272,14 @@ static void notrace start_secondary(void *unused) ...@@ -273,9 +272,14 @@ static void notrace start_secondary(void *unused)
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE); cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
} }
int topology_update_package_map(unsigned int apicid, unsigned int cpu) /**
* topology_update_package_map - Update the physical to logical package map
* @pkg: The physical package id as retrieved via CPUID
* @cpu: The cpu for which this is updated
*/
int topology_update_package_map(unsigned int pkg, unsigned int cpu)
{ {
unsigned int new, pkg = apicid >> boot_cpu_data.x86_coreid_bits; unsigned int new;
/* Called from early boot ? */ /* Called from early boot ? */
if (!physical_package_map) if (!physical_package_map)
...@@ -288,16 +292,17 @@ int topology_update_package_map(unsigned int apicid, unsigned int cpu) ...@@ -288,16 +292,17 @@ int topology_update_package_map(unsigned int apicid, unsigned int cpu)
if (test_and_set_bit(pkg, physical_package_map)) if (test_and_set_bit(pkg, physical_package_map))
goto found; goto found;
if (logical_packages_frozen) { if (logical_packages >= __max_logical_packages) {
physical_to_logical_pkg[pkg] = -1; pr_warn("Package %u of CPU %u exceeds BIOS package data %u.\n",
pr_warn("APIC(%x) Package %u exceeds logical package max\n", logical_packages, cpu, __max_logical_packages);
apicid, pkg);
return -ENOSPC; return -ENOSPC;
} }
new = logical_packages++; new = logical_packages++;
pr_info("APIC(%x) Converting physical %u to logical package %u\n", if (new != pkg) {
apicid, pkg, new); pr_info("CPU %u Converting physical %u to logical package %u\n",
cpu, pkg, new);
}
physical_to_logical_pkg[pkg] = new; physical_to_logical_pkg[pkg] = new;
found: found:
...@@ -318,9 +323,9 @@ int topology_phys_to_logical_pkg(unsigned int phys_pkg) ...@@ -318,9 +323,9 @@ int topology_phys_to_logical_pkg(unsigned int phys_pkg)
} }
EXPORT_SYMBOL(topology_phys_to_logical_pkg); EXPORT_SYMBOL(topology_phys_to_logical_pkg);
static void __init smp_init_package_map(void) static void __init smp_init_package_map(struct cpuinfo_x86 *c, unsigned int cpu)
{ {
unsigned int ncpus, cpu; unsigned int ncpus;
size_t size; size_t size;
/* /*
...@@ -365,27 +370,9 @@ static void __init smp_init_package_map(void) ...@@ -365,27 +370,9 @@ static void __init smp_init_package_map(void)
size = BITS_TO_LONGS(max_physical_pkg_id) * sizeof(unsigned long); size = BITS_TO_LONGS(max_physical_pkg_id) * sizeof(unsigned long);
physical_package_map = kzalloc(size, GFP_KERNEL); physical_package_map = kzalloc(size, GFP_KERNEL);
for_each_present_cpu(cpu) {
unsigned int apicid = apic->cpu_present_to_apicid(cpu);
if (apicid == BAD_APICID || !apic->apic_id_valid(apicid))
continue;
if (!topology_update_package_map(apicid, cpu))
continue;
pr_warn("CPU %u APICId %x disabled\n", cpu, apicid);
per_cpu(x86_bios_cpu_apicid, cpu) = BAD_APICID;
set_cpu_possible(cpu, false);
set_cpu_present(cpu, false);
}
if (logical_packages > __max_logical_packages) {
pr_warn("Detected more packages (%u), then computed by BIOS data (%u).\n",
logical_packages, __max_logical_packages);
logical_packages_frozen = true;
__max_logical_packages = logical_packages;
}
pr_info("Max logical packages: %u\n", __max_logical_packages); pr_info("Max logical packages: %u\n", __max_logical_packages);
topology_update_package_map(c->phys_proc_id, cpu);
} }
void __init smp_store_boot_cpu_info(void) void __init smp_store_boot_cpu_info(void)
...@@ -395,7 +382,7 @@ void __init smp_store_boot_cpu_info(void) ...@@ -395,7 +382,7 @@ void __init smp_store_boot_cpu_info(void)
*c = boot_cpu_data; *c = boot_cpu_data;
c->cpu_index = id; c->cpu_index = id;
smp_init_package_map(); smp_init_package_map(c, id);
} }
/* /*
......
...@@ -87,12 +87,6 @@ static void cpu_bringup(void) ...@@ -87,12 +87,6 @@ static void cpu_bringup(void)
cpu_data(cpu).x86_max_cores = 1; cpu_data(cpu).x86_max_cores = 1;
set_cpu_sibling_map(cpu); set_cpu_sibling_map(cpu);
/*
* identify_cpu() may have set logical_pkg_id to -1 due
* to incorrect phys_proc_id. Let's re-comupte it.
*/
topology_update_package_map(apic->cpu_present_to_apicid(cpu), cpu);
xen_setup_cpu_clockevents(); xen_setup_cpu_clockevents();
notify_cpu_starting(cpu); notify_cpu_starting(cpu);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment