The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: Alex Murray <alex.murray@canonical.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	linux-kernel@vger.kernel.org
Cc: x86@kernel.org, tglx@linutronix.de, bp@alien8.de,
	andrew.cooper3@citrix.com
Subject: Re: [PATCH] [v4] x86/cpu: Help users notice when running old Intel microcode
Date: Thu, 6 Feb 2025 21:04:49 -0800	[thread overview]
Message-ID: <f642ec94-4917-4124-9ec5-3885d92492e3@intel.com> (raw)
In-Reply-To: <87tt96ikzf.fsf@canonical.com>

[-- Attachment #1: Type: text/plain, Size: 972 bytes --]

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.

[-- Attachment #2: ucode-versions.py --]
[-- Type: text/x-python, Size: 1755 bytes --]

#!/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']))

      reply	other threads:[~2025-02-07  5:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-06 21:47 [PATCH] [v4] x86/cpu: Help users notice when running old Intel microcode Dave Hansen
2025-02-07  1:47 ` Alex Murray
2025-02-07  5:04   ` Dave Hansen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f642ec94-4917-4124-9ec5-3885d92492e3@intel.com \
    --to=dave.hansen@intel.com \
    --cc=alex.murray@canonical.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox