detect_hyperthreading_bug (1836B)
1 #!/usr/bin/perl 2 # Copyright 2017 Uwe Kleine-König 3 # 4 # This program is free software; you can redistribute it and/or modify it under 5 # the terms of the GNU General Public License version 2 as published by the 6 # Free Software Foundation. 7 # 8 # https://lists.debian.org/debian-user/2017/06/msg01011.html 9 10 open(my $cpuinfo, "</proc/cpuinfo") or die "failed to open cpuinfo\n"; 11 12 my $cpunum, $vendor, $family, $model, $stepping, $microcoderev, $hyperthreading; 13 14 while (<$cpuinfo>) { 15 if (/^$/) { 16 print "cpu $cpunum: "; 17 if ($vendor eq "GenuineIntel" and $family == 6) { 18 if ($model == 78 or $model == 94) { 19 if ($stepping eq "3") { 20 print "Your CPU is affected, "; 21 if (hex($microcoderev) >= 0xb9) { 22 print "but your microcode is new enough\n"; 23 } elsif ($hyperthreading ne "on") { 24 print "but hyper threading is off, which works around the problem\n"; 25 } else { 26 print "you should install the latest intel-microcode\n"; 27 } 28 } else { 29 print "You may need a BIOS/UEFI update (unknown Skylake-Y/H/U/S stepping)\n"; 30 } 31 } elsif ($model == 85 or $model == 142 or $model == 158) { 32 print "You may need a BIOS/UEFI update (Kaby Lake, or Skylake-X processor)\n"; 33 } else { 34 print "You're likely not affected\n"; 35 } 36 } else { 37 print "You're not affected\n"; 38 } 39 40 $cpunum = undef; 41 $vendor = undef; 42 $family = undef; 43 $stepping = undef; 44 $microcoderev = undef; 45 $hyperthreading = undef; 46 47 next; 48 } 49 50 $cpunum = $1 if /^processor\s*:\s(.*)/; 51 $vendor = $1 if /^vendor_id\s*:\s(.*)/; 52 $family = $1 if /^cpu family\s*:\s(.*)/; 53 $model = $1 if /^model\s*:\s(.*)/; 54 $stepping = $1 if /^stepping\s*:\s(.*)/; 55 $microcoderev = $1 if /^microcode\s*:\s(.*)/; 56 57 if (/^flags\s*:/) { 58 if (/^flags\s*:.*\bht\b/) { 59 $hyperthreading = "on"; 60 } else { 61 $hyperthreading = "off"; 62 } 63 } 64 } 65