Skip to content

Instantly share code, notes, and snippets.

@fat-tire
Last active June 25, 2017 23:58
Show Gist options
  • Save fat-tire/47b6b51d92901361470cd1131337a905 to your computer and use it in GitHub Desktop.
Save fat-tire/47b6b51d92901361470cd1131337a905 to your computer and use it in GitHub Desktop.
intelchecker.sh - A script to identify that hyperthreading bug in intel processors
#!/bin/bash
# Copyright 2017 Uwe Kleine-König
# Converted to bash for chromebooks (ie, read-only filesystem w/o perl) by fattire
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License version 2 as published by the
# Free Software Foundation.
#
# Note: You can also check your Skylake processors here: http://ark.intel.com/products/codename/37572/Skylake
# And Kaby Lake here: http://ark.intel.com/products/codename/82879/Kaby-Lake
FILE=/proc/cpuinfo
if [ ! -f $FILE ]; then
echo "failed to open $FILE\n"
exit 0
fi
function checkcpu {
if [ ! -z ${cpunum} ]; then
echo "cpu $cpunum: "
if [[ $vendor -eq "GenuineIntel" && $family -eq "6" ]]; then
echo " It's an Intel. Checking model & stepping..."
if [[ $model -eq "78" || $model -eq "94" ]] ; then
if [[ $stepping -eq "3" ]]; then
echo -n " Your CPU is affected by the issue. ";
if [[ $[microcoderev] -ge $((0xb9)) ]]; then
echo " BUT your microcode is new enough";
elif [[ $hyperthreading -ne "on" ]]; then
echo " BUT hyper threading is off, which works around the problem";
else
echo "You should install the latest intel-microcode."
echo " Yours is version $microcoderev ($[microcoderev]), but you should have at least 0xb9 ($((0xb9))).";
fi
else
echo " You may need a BIOS/UEFI update (unknown Skylake-Y/H/U/S stepping: $stepping)";
fi
elif [[ $model -eq "85" || $model -eq "142" || $model -eq "158" ]]; then
echo " You may need a BIOS/UEFI update (Kaby Lake, or Skylake-X processor)";
else
echo " But you're likely not affected";
fi
else
echo "No. Not the right kind of Intel chip. You're not affected.";
fi
fi
# clear everything for the next cpu
cpunum=
vendor=
vamily=
model=
stepping=
microcoderv=
hyperthreading=
}
clear
echo "Checking your CPUs...."
while read -r line
do
# remove the colon because it's breaking the regex for some POSIXTIVELY dumb reason
if [[ ${line//:} =~ ^processor\s*(.*) ]]; then
cpunum=`echo ${BASH_REMATCH[1]} | sed -E 's,\\t|\\r|\\n,,g'`
fi
if [[ ${line//:} =~ ^vendor_id\s*(.*) ]]; then
vendor=`echo ${BASH_REMATCH[1]} | sed -E 's,\\t|\\r|\\n,,g'`
fi
if [[ ${line//:} =~ ^cpu.*family\s*(.*) ]]; then
family=`echo ${BASH_REMATCH[1]} | sed -E 's,\\t|\\r|\\n,,g'`
fi
if [[ ${line//:} =~ ^model\s*(.*) ]]; then
x="`echo ${BASH_REMATCH[1]} | sed -E 's,\\t|\\r|\\n,,g'`"
if [[ ${BASH_REMATCH[1]} =~ [:space:0-9]+$ ]]; then
model=$x
fi
fi
if [[ ${line//:} =~ ^stepping\s*(.*) ]]; then
stepping=`echo ${BASH_REMATCH[1]} | sed -E 's,\\t|\\r|\\n,,g'`
fi
if [[ ${line//:} =~ ^microcode\s*(.*) ]]; then
microcoderev=`echo ${BASH_REMATCH[1]} | sed -E 's,\\t|\\r|\\n,,g'`
fi
if [[ ${line//:} =~ ^flags\s* ]]; then
if [[ ${line//:} == *" ht "* ]]; then
hyperthreading="on"
else
hyperthreading="off"
fi
fi
# assume blank lines between chips
if [[ ! -n ${line} ]]; then
checkcpu
fi
done < $FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment