提交 133b4638 编写于 作者: V Vitaly Kuznetsov 提交者: Yongqiang Liu

cpu/SMT: create and export cpu_smt_possible()

mainline inclusion
from mainline-v5.4
commit e1572f1d
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/I6FB6C
CVE: CVE-2022-27672

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v6.3-rc1&id=e1572f1d08be57a5412a464cff0712a23cd0b73e

--------------------------------

KVM needs to know if SMT is theoretically possible, this means it is
supported and not forcefully disabled ('nosmt=force'). Create and
export cpu_smt_possible() answering this question.
Signed-off-by: NVitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: NGuo Mengqi <guomengqi3@huawei.com>
Reviewed-by: NWang Weiyang <wangweiyang2@huawei.com>
Reviewed-by: NWeilong Chen <chenweilong@huawei.com>
Signed-off-by: NYongqiang Liu <liuyongqiang13@huawei.com>
上级 a5f1c660
...@@ -194,12 +194,14 @@ enum cpuhp_smt_control { ...@@ -194,12 +194,14 @@ enum cpuhp_smt_control {
extern enum cpuhp_smt_control cpu_smt_control; extern enum cpuhp_smt_control cpu_smt_control;
extern void cpu_smt_disable(bool force); extern void cpu_smt_disable(bool force);
extern void cpu_smt_check_topology(void); extern void cpu_smt_check_topology(void);
extern bool cpu_smt_possible(void);
extern int cpuhp_smt_enable(void); extern int cpuhp_smt_enable(void);
extern int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval); extern int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval);
#else #else
# define cpu_smt_control (CPU_SMT_ENABLED) # define cpu_smt_control (CPU_SMT_ENABLED)
static inline void cpu_smt_disable(bool force) { } static inline void cpu_smt_disable(bool force) { }
static inline void cpu_smt_check_topology(void) { } 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_enable(void) { return 0; }
static inline int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) { return 0; } static inline int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) { return 0; }
#endif #endif
......
...@@ -368,8 +368,7 @@ enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED; ...@@ -368,8 +368,7 @@ enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED;
void __init cpu_smt_disable(bool force) void __init cpu_smt_disable(bool force)
{ {
if (cpu_smt_control == CPU_SMT_FORCE_DISABLED || if (!cpu_smt_possible())
cpu_smt_control == CPU_SMT_NOT_SUPPORTED)
return; return;
if (force) { if (force) {
...@@ -414,6 +413,14 @@ static inline bool cpu_smt_allowed(unsigned int cpu) ...@@ -414,6 +413,14 @@ static inline bool cpu_smt_allowed(unsigned int cpu)
*/ */
return !per_cpu(cpuhp_state, cpu).booted_once; 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 #else
static inline bool cpu_smt_allowed(unsigned int cpu) { return true; } static inline bool cpu_smt_allowed(unsigned int cpu) { return true; }
#endif #endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册