Re: [PATCH] [v4] x86/cpu: Help users notice when running old Intel microcode
From: Dave Hansen
Date: Fri Feb 07 2025 - 00:04:55 EST
On 2/6/25 17:47, Alex Murray wrote:
>> Also note that the "intel-ucode-defs.h" file is simple, ugly and
>> has lots of magic numbers. That's on purpose and should allow a
>> single file to be shared across lots of stable kernel regardless of if
>> they have the new "VFM" infrastructure or not. It was generated with
>> a dumb script.
>>
> Should this script be included as part of this patch so that it is easy
> for others to update intel-ucode-defs.h if needed in the future?
I was planning on throwing it in the tree _somewhere_ at some point.
Here's a copy for now in case anyone wants to take a look. I assume
folks would rather it live in the kernel tree in scripts/ rather than
somewhere else.
The other thing I was toying with was trying to get Intel to run it as a
part of the microcode release process. That way, we could just copy the
file from the microcode repo and wouldn't have to run a script at all.
I'll post it as part of a real patch at some point.#!/usr/bin/python3
import re
import sys
import subprocess
def bits(val, bottom, top):
mask = (1 << (top + 1 - bottom)) - 1
mask = mask << bottom
return (val & mask) >> bottom
def family(sig):
if bits(sig, 8, 11) == 0xf:
return bits(sig, 8, 11) + bits(sig, 20, 27)
return bits(sig, 8, 11)
def model(sig):
return bits(sig, 4, 7) | (bits(sig, 16, 19)<<4)
def step(sig):
return bits(sig, 0, 3)
cmd = ['iucode-tool', '--list-all' ]
for arg in sys.argv[1:]:
cmd = cmd + [ arg ]
siglist = []
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
for line in process.stdout:
##print(line)
if line.find(" sig ") == -1:
continue
sig = re.search('sig (0x[0-9a-fA-F]+)', line).group(1)
rev = re.search('rev (0x[0-9a-fA-F]+)', line).group(1)
sig = int(sig, 16)
rev = int(rev, 16)
debug_rev = bits(rev, 31, 31)
if debug_rev != 0:
#print("ERROR: debug ucode file found, exiting")
sys.exit(1);
sigrev = {}
sigrev['sig'] = sig
sigrev['rev'] = rev
siglist = siglist + [ sigrev ]
sigdict = {}
for sr in siglist:
existing = sigdict.get(sr['sig'])
if existing != None:
# If the existing one is newer, just move on:
if existing['rev'] > sr['rev']:
#print("collision %s %s => %s" % (sr['sig'], sr['rev'], existing['rev']))
continue
sigdict[sr['sig']] = sr
for sig in sigdict:
rev = sigdict[sig]
print("{ .flags = X86_CPU_ID_FLAG_ENTRY_VALID, .vendor = X86_VENDOR_INTEL, .family = 0x%x, .model = 0x%02x, .steppings = 0x%04x, .driver_data = 0x%x }," % (family(sig), model(sig), 1<<step(sig), rev['rev']))