From e1a2cae2c00bb6ed091b10e44de50d2789c3f4b3 Mon Sep 17 00:00:00 2001 From: Dario Faggioli Date: Fri, 19 Apr 2019 14:30:10 +0200 Subject: [PATCH] L1TF/Linux: detect SMT via sysfs We can figure out whether SMT is enabled or not, by checking the topology of the CPUs, as it is exposed in /sys. This means the information is available also when we are running in `--sysfs-only` mode. --- spectre-meltdown-checker.sh | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/spectre-meltdown-checker.sh b/spectre-meltdown-checker.sh index dc5f10a..d158cfa 100755 --- a/spectre-meltdown-checker.sh +++ b/spectre-meltdown-checker.sh @@ -3932,16 +3932,25 @@ check_CVE_2018_3646_linux() fi smt_enabled=-1 - if [ "$opt_sysfs_only" != 1 ]; then - _info_nol " * Hyper-Threading (SMT) is enabled: " - is_cpu_smt_enabled; smt_enabled=$? - if [ "$smt_enabled" = 0 ]; then - pstatus yellow YES - elif [ "$smt_enabled" = 1 ]; then - pstatus green NO + _info_nol " * Hyper-Threading (SMT) is enabled: " + if [ "$opt_sysfs_only" = 1 ]; then + # if SMT is on, `siblings_list` has more than one element, + # separated by ','. Also, it is safe enough to assume that + # cpu0 (1) always exists, and (2) is always online. + if ! grep -q ',' /sys/devices/system/cpu/cpu0/topology/thread_siblings_list ; then + smt_enabled=1 # means disabled! else - pstatus yellow UNKNOWN + smt_enabled=0 fi + else + is_cpu_smt_enabled; smt_enabled=$? + fi + if [ "$smt_enabled" = 0 ]; then + pstatus yellow YES + elif [ "$smt_enabled" = 1 ]; then + pstatus green NO + else + pstatus yellow UNKNOWN fi if ! is_cpu_vulnerable "$cve"; then