diff --git a/include/linux/cpu.h b/include/linux/cpu.h index 12ed4cb751deed6f9c4e0222ddca5f33dc84a4cb..4b6151c7a0b0141d170e89816494f3d566d9b948 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -194,12 +194,14 @@ enum cpuhp_smt_control { extern enum cpuhp_smt_control cpu_smt_control; extern void cpu_smt_disable(bool force); extern void cpu_smt_check_topology(void); +extern bool cpu_smt_possible(void); extern int cpuhp_smt_enable(void); extern int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval); #else # define cpu_smt_control (CPU_SMT_ENABLED) static inline void cpu_smt_disable(bool force) { } static inline void cpu_smt_check_topology(void) { } +static inline bool cpu_smt_possible(void) { return false; } static inline int cpuhp_smt_enable(void) { return 0; } static inline int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) { return 0; } #endif diff --git a/kernel/cpu.c b/kernel/cpu.c index 80c85406ec0c5759339b3ed1a70c91619b0b7c6b..b3b04e7c17d8f1ce4884a8dae48a6119fe2d8b38 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -368,8 +368,7 @@ enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED; void __init cpu_smt_disable(bool force) { - if (cpu_smt_control == CPU_SMT_FORCE_DISABLED || - cpu_smt_control == CPU_SMT_NOT_SUPPORTED) + if (!cpu_smt_possible()) return; if (force) { @@ -414,6 +413,14 @@ static inline bool cpu_smt_allowed(unsigned int cpu) */ return !per_cpu(cpuhp_state, cpu).booted_once; } + +/* Returns true if SMT is not supported of forcefully (irreversibly) disabled */ +bool cpu_smt_possible(void) +{ + return cpu_smt_control != CPU_SMT_FORCE_DISABLED && + cpu_smt_control != CPU_SMT_NOT_SUPPORTED; +} +EXPORT_SYMBOL_GPL(cpu_smt_possible); #else static inline bool cpu_smt_allowed(unsigned int cpu) { return true; } #endif