]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
x86/topology: Add topology_max_smt_threads()
authorAndi Kleen <ak@linux.intel.com>
Fri, 20 May 2016 00:09:55 +0000 (17:09 -0700)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Fri, 10 Aug 2018 22:56:34 +0000 (18:56 -0400)
For SMT specific workarounds it is useful to know if SMT is active
on any online CPU in the system. This currently requires a loop
over all online CPUs.

Add a global variable that is updated with the maximum number
of smt threads on any CPU on online/offline, and use it for
topology_max_smt_threads()

The single call is easier to use than a loop.

Not exported to user space because user space already can use
the existing sibling interfaces to find this out.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: acme@kernel.org
Cc: jolsa@kernel.org
Link: http://lkml.kernel.org/r/1463703002-19686-2-git-send-email-andi@firstfloor.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Orabug: 28220674
CVE: CVE-2018-3620

(cherry picked from commit 70b8301f6b8f7bc053377a9cbd0c4e42e29d9807)

This patch was backported as a dependency, was not part of the original L1TF
patch list.

Signed-off-by: Mihai Carabas <mihai.carabas@oracle.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Conflicts:
arch/x86/include/asm/topology.h
Contextual.
For smpboot.c we modified topology_sibling_cpumask with topology_thread_cpumask.

arch/x86/include/asm/topology.h
arch/x86/kernel/smpboot.c

index 0d02e19abe58101bf89ed3090f6eb793c20aa8f2..c727483b462f2c496dd068004312842b5fe8ae8f 100644 (file)
@@ -123,9 +123,17 @@ extern const struct cpumask *cpu_coregroup_mask(int cpu);
 #define topology_core_id(cpu)                  (cpu_data(cpu).cpu_core_id)
 
 #ifdef CONFIG_SMP
+extern int __max_smt_threads;
+
+static inline int topology_max_smt_threads(void)
+{
+       return __max_smt_threads;
+}
+
 bool topology_is_primary_thread(unsigned int cpu);
 bool topology_smt_supported(void);
 #else
+static inline int topology_max_smt_threads(void) { return 1; }
 static inline bool topology_is_primary_thread(unsigned int cpu) { return true; }
 static inline bool topology_smt_supported(void) { return false; }
 #endif
index 9cf20ce8be2dc83ebabb1022408b4948f06037a9..1af36d897a4132e81818d28857e827a085ce2fc5 100644 (file)
@@ -102,6 +102,9 @@ EXPORT_PER_CPU_SYMBOL(cpu_info);
 
 atomic_t init_deasserted;
 
+/* Maximum number of SMT threads on any online core */
+int __max_smt_threads __read_mostly;
+
 static inline void smpboot_setup_warm_reset_vector(unsigned long start_eip)
 {
        unsigned long flags;
@@ -415,7 +418,7 @@ void set_cpu_sibling_map(int cpu)
        bool has_mp = has_smt || boot_cpu_data.x86_max_cores > 1;
        struct cpuinfo_x86 *c = &cpu_data(cpu);
        struct cpuinfo_x86 *o;
-       int i;
+       int i, threads;
 
        cpumask_set_cpu(cpu, cpu_sibling_setup_mask);
 
@@ -470,6 +473,10 @@ void set_cpu_sibling_map(int cpu)
                if (match_die(c, o) && !topology_same_node(c, o))
                        primarily_use_numa_for_topology();
        }
+
+       threads = cpumask_weight(topology_thread_cpumask(cpu));
+       if (threads > __max_smt_threads)
+               __max_smt_threads = threads;
 }
 
 /* maps the cpu to the sched domain representing multi-core */
@@ -1328,6 +1335,21 @@ __init void prefill_possible_map(void)
 
 #ifdef CONFIG_HOTPLUG_CPU
 
+/* Recompute SMT state for all CPUs on offline */
+static void recompute_smt_state(void)
+{
+       int max_threads, cpu;
+
+       max_threads = 0;
+       for_each_online_cpu (cpu) {
+               int threads = cpumask_weight(topology_thread_cpumask(cpu));
+
+               if (threads > max_threads)
+                       max_threads = threads;
+       }
+       __max_smt_threads = max_threads;
+}
+
 static void remove_siblinginfo(int cpu)
 {
        int sibling;
@@ -1352,6 +1374,7 @@ static void remove_siblinginfo(int cpu)
        c->phys_proc_id = 0;
        c->cpu_core_id = 0;
        cpumask_clear_cpu(cpu, cpu_sibling_setup_mask);
+       recompute_smt_state();
 }
 
 static void __ref remove_cpu_from_maps(int cpu)