[Xen-devel] [tip:x86/urgent] x86/smpboot: Make logical package management more robust

2016-12-13 Thread tip-bot for Thomas Gleixner
Commit-ID:  9d85eb9119f4eeeb48e87adfcd71f752655700e9
Gitweb: http://git.kernel.org/tip/9d85eb9119f4eeeb48e87adfcd71f752655700e9
Author: Thomas Gleixner 
AuthorDate: Mon, 12 Dec 2016 11:04:53 +0100
Committer:  Thomas Gleixner 
CommitDate: Tue, 13 Dec 2016 10:22:39 +0100

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: d49597fd3bc7 ("x86/cpu: Deal with broken firmware (VMWare/XEN)")
Reported-and-tested-by: Borislav Petkov 
Tested-by: Boris Ostrovsky 
Signed-off-by: Thomas Gleixner 
Cc: Juergen Gross 
Cc: Peter Zijlstra 
Cc: M. Vefa Bicakci 
Cc: xen-devel 
Cc: Charles (Chas) Williams 
Cc: Borislav Petkov 
Cc: Alok Kataria 
Cc: sta...@vger.kernel.org
Link: http://lkml.kernel.org/r/alpine.DEB.2.20.1612121102260.3429@nanos
Signed-off-by: Thomas Gleixner 

---
 arch/x86/kernel/apic/apic.c  | 15 -
 arch/x86/kernel/cpu/common.c | 24 +++--
 arch/x86/kernel/smpboot.c| 51 +---
 arch/x86/xen/smp.c   |  6 --
 4 files changed, 27 insertions(+), 69 deletions(-)

diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index bb47e5e..5b7e43e 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -2160,21 +2160,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
 */
if (version == 0x0) {
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 729f92b..1f6b50a 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.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
- * acpi/mptables information. Make sure that CPUID actually agrees with
- * that.
+ * Validate that ACPI/mptables have the same information about the
+ * effective APIC id and update the package map.
  */
-static void sanitize_package_id(struct cpuinfo_x86 *c)
+static void validate_apic_and_package_id(struct cpuinfo_x86 *c)
 {
 #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);
-   pkg = apicid >> boot_cpu_data.x86_coreid_bits;
 
-   if (apicid != c->initial_apicid) {
-   pr_err(FW_BUG "CPU%u: APIC id mismatch. Firmware: %x CPUID: 
%x\n",
+   if (apicid != c->apicid) {
+   pr_err(FW_BUG "CPU%u: APIC id mismatch. Firmware: %x APIC: 
%x\n",
   cpu, apicid, c->initial_apicid);
-   c->initial_apicid = apicid;
}
-   if (pkg != c->phys_proc_id) {
-   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);
+   BUG_ON(topology_update_package_map(c->phys_proc_id, cpu));
 #else
c->logical_proc_id = 0;
 #endif
@@ -1132,7 

[Xen-devel] [tip:irq/urgent] genirq: Revert sparse irq locking around __cpu_up() and move it to x86 for now

2015-07-15 Thread tip-bot for Thomas Gleixner
Commit-ID:  ce0d3c0a6fb1422101498ef378c0851dabbbf67f
Gitweb: http://git.kernel.org/tip/ce0d3c0a6fb1422101498ef378c0851dabbbf67f
Author: Thomas Gleixner 
AuthorDate: Tue, 14 Jul 2015 22:03:57 +0200
Committer:  Thomas Gleixner 
CommitDate: Wed, 15 Jul 2015 10:39:17 +0200

genirq: Revert sparse irq locking around __cpu_up() and move it to x86 for now

Boris reported that the sparse_irq protection around __cpu_up() in the
generic code causes a regression on Xen. Xen allocates interrupts and
some more in the xen_cpu_up() function, so it deadlocks on the
sparse_irq_lock.

There is no simple fix for this and we really should have the
protection for all architectures, but for now the only solution is to
move it to x86 where actual wreckage due to the lack of protection has
been observed.

Reported-and-tested-by: Boris Ostrovsky 
Fixes: a89941816726 'hotplug: Prevent alloc/free of irq descriptors during cpu 
up/down'
Signed-off-by: Thomas Gleixner 
Cc: Peter Zijlstra 
Cc: xiao jin 
Cc: Joerg Roedel 
Cc: Borislav Petkov 
Cc: Yanmin Zhang 
Cc: xen-devel 
---
 arch/x86/kernel/smpboot.c | 11 +++
 kernel/cpu.c  |  9 -
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index d3010aa..b1f3ed9c 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -992,8 +992,17 @@ int native_cpu_up(unsigned int cpu, struct task_struct 
*tidle)
 
common_cpu_up(cpu, tidle);
 
+   /*
+* We have to walk the irq descriptors to setup the vector
+* space for the cpu which comes online.  Prevent irq
+* alloc/free across the bringup.
+*/
+   irq_lock_sparse();
+
err = do_boot_cpu(apicid, cpu, tidle);
+
if (err) {
+   irq_unlock_sparse();
pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
return -EIO;
}
@@ -1011,6 +1020,8 @@ int native_cpu_up(unsigned int cpu, struct task_struct 
*tidle)
touch_nmi_watchdog();
}
 
+   irq_unlock_sparse();
+
return 0;
 }
 
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 6a37454..5644ec5 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -527,18 +527,9 @@ static int _cpu_up(unsigned int cpu, int tasks_frozen)
goto out_notify;
}
 
-   /*
-* Some architectures have to walk the irq descriptors to
-* setup the vector space for the cpu which comes online.
-* Prevent irq alloc/free across the bringup.
-*/
-   irq_lock_sparse();
-
/* Arch-specific enabling code. */
ret = __cpu_up(cpu, idle);
 
-   irq_unlock_sparse();
-
if (ret != 0)
goto out_notify;
BUG_ON(!cpu_online(cpu));

___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel