Commit 09136388 authored by Andi Kleen's avatar Andi Kleen Committed by Stefan Bader

x86/topology: Add topology_max_smt_threads()

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: default avatarAndi Kleen <ak@linux.intel.com>
Signed-off-by: default avatarPeter 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.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>

CVE-2018-3620
CVE-2018-3646

(cherry picked from commit 70b8301f)
Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
parent d1d1ef97
...@@ -130,6 +130,14 @@ extern const struct cpumask *cpu_coregroup_mask(int cpu); ...@@ -130,6 +130,14 @@ extern const struct cpumask *cpu_coregroup_mask(int cpu);
extern unsigned int __max_logical_packages; extern unsigned int __max_logical_packages;
#define topology_max_packages() (__max_logical_packages) #define topology_max_packages() (__max_logical_packages)
extern int __max_smt_threads;
static inline int topology_max_smt_threads(void)
{
return __max_smt_threads;
}
int topology_update_package_map(unsigned int apicid, unsigned int cpu); int topology_update_package_map(unsigned int apicid, unsigned int cpu);
int topology_phys_to_logical_pkg(unsigned int pkg); int topology_phys_to_logical_pkg(unsigned int pkg);
bool topology_is_primary_thread(unsigned int cpu); bool topology_is_primary_thread(unsigned int cpu);
...@@ -139,6 +147,7 @@ bool topology_smt_supported(void); ...@@ -139,6 +147,7 @@ bool topology_smt_supported(void);
static inline int static inline int
topology_update_package_map(unsigned int apicid, unsigned int cpu) { return 0; } topology_update_package_map(unsigned int apicid, unsigned int cpu) { return 0; }
static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return 0; } static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return 0; }
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_is_primary_thread(unsigned int cpu) { return true; }
static inline bool topology_smt_supported(void) { return false; } static inline bool topology_smt_supported(void) { return false; }
#endif #endif
......
...@@ -108,6 +108,9 @@ EXPORT_SYMBOL(__max_logical_packages); ...@@ -108,6 +108,9 @@ 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; static bool logical_packages_frozen __read_mostly;
/* 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) static inline void smpboot_setup_warm_reset_vector(unsigned long start_eip)
{ {
unsigned long flags; unsigned long flags;
...@@ -512,7 +515,7 @@ void set_cpu_sibling_map(int cpu) ...@@ -512,7 +515,7 @@ void set_cpu_sibling_map(int cpu)
bool has_mp = has_smt || boot_cpu_data.x86_max_cores > 1; bool has_mp = has_smt || boot_cpu_data.x86_max_cores > 1;
struct cpuinfo_x86 *c = &cpu_data(cpu); struct cpuinfo_x86 *c = &cpu_data(cpu);
struct cpuinfo_x86 *o; struct cpuinfo_x86 *o;
int i; int i, threads;
cpumask_set_cpu(cpu, cpu_sibling_setup_mask); cpumask_set_cpu(cpu, cpu_sibling_setup_mask);
...@@ -569,6 +572,10 @@ void set_cpu_sibling_map(int cpu) ...@@ -569,6 +572,10 @@ void set_cpu_sibling_map(int cpu)
if (match_die(c, o) && !topology_same_node(c, o)) if (match_die(c, o) && !topology_same_node(c, o))
primarily_use_numa_for_topology(); primarily_use_numa_for_topology();
} }
threads = cpumask_weight(topology_sibling_cpumask(cpu));
if (threads > __max_smt_threads)
__max_smt_threads = threads;
} }
/* maps the cpu to the sched domain representing multi-core */ /* maps the cpu to the sched domain representing multi-core */
...@@ -1469,6 +1476,21 @@ __init void prefill_possible_map(void) ...@@ -1469,6 +1476,21 @@ __init void prefill_possible_map(void)
#ifdef CONFIG_HOTPLUG_CPU #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_sibling_cpumask(cpu));
if (threads > max_threads)
max_threads = threads;
}
__max_smt_threads = max_threads;
}
static void remove_siblinginfo(int cpu) static void remove_siblinginfo(int cpu)
{ {
int sibling; int sibling;
...@@ -1494,6 +1516,7 @@ static void remove_siblinginfo(int cpu) ...@@ -1494,6 +1516,7 @@ static void remove_siblinginfo(int cpu)
c->cpu_core_id = 0; c->cpu_core_id = 0;
c->booted_cores = 0; c->booted_cores = 0;
cpumask_clear_cpu(cpu, cpu_sibling_setup_mask); cpumask_clear_cpu(cpu, cpu_sibling_setup_mask);
recompute_smt_state();
} }
static void remove_cpu_from_maps(int cpu) static void remove_cpu_from_maps(int 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