]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
x86/microcode/AMD: Handle the case of no BIOS microcode
authorBorislav Petkov (AMD) <bp@alien8.de>
Wed, 20 Aug 2025 09:58:57 +0000 (11:58 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 4 Sep 2025 13:31:52 +0000 (15:31 +0200)
commit fcf8239ad6a5de54fa7ce18e464c6b5951b982cb upstream.

Machines can be shipped without any microcode in the BIOS. Which means,
the microcode patch revision is 0.

Handle that gracefully.

Fixes: 94838d230a6c ("x86/microcode/AMD: Use the family,model,stepping encoded in the patch ID")
Reported-by: Vítek Vávra <vit.vavra.kh@gmail.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Cc: <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kernel/cpu/microcode/amd.c

index 765b4646648f7b398a7ef52707c26681f66f10e5..910accfeb7856924934ab7e45173a65f9ea287c6 100644 (file)
@@ -159,8 +159,28 @@ static int cmp_id(const void *key, const void *elem)
                return 1;
 }
 
+static u32 cpuid_to_ucode_rev(unsigned int val)
+{
+       union zen_patch_rev p = {};
+       union cpuid_1_eax c;
+
+       c.full = val;
+
+       p.stepping  = c.stepping;
+       p.model     = c.model;
+       p.ext_model = c.ext_model;
+       p.ext_fam   = c.ext_fam;
+
+       return p.ucode_rev;
+}
+
 static bool need_sha_check(u32 cur_rev)
 {
+       if (!cur_rev) {
+               cur_rev = cpuid_to_ucode_rev(bsp_cpuid_1_eax);
+               pr_info_once("No current revision, generating the lowest one: 0x%x\n", cur_rev);
+       }
+
        switch (cur_rev >> 8) {
        case 0x80012: return cur_rev <= 0x800126f; break;
        case 0x80082: return cur_rev <= 0x800820f; break;
@@ -741,8 +761,6 @@ static struct ucode_patch *cache_find_patch(struct ucode_cpu_info *uci, u16 equi
        n.equiv_cpu = equiv_cpu;
        n.patch_id  = uci->cpu_sig.rev;
 
-       WARN_ON_ONCE(!n.patch_id);
-
        list_for_each_entry(p, &microcode_cache, plist)
                if (patch_cpus_equivalent(p, &n, false))
                        return p;