Skip to content

Commit 8da38eb

Browse files
filipposironiKAGA-KOKO
authored andcommitted
x86/microcode: Update the new microcode revision unconditionally
Handle the case where microcode gets loaded on the BSP's hyperthread sibling first and the boot_cpu_data's microcode revision doesn't get updated because of early exit due to the siblings sharing a microcode engine. For that, simply write the updated revision on all CPUs unconditionally. Signed-off-by: Filippo Sironi <sironi@amazon.de> Signed-off-by: Borislav Petkov <bp@suse.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: prarit@redhat.com Cc: stable@vger.kernel.org Link: http://lkml.kernel.org/r/1533050970-14385-1-git-send-email-sironi@amazon.de
1 parent 370a132 commit 8da38eb

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

arch/x86/kernel/cpu/microcode/amd.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ static enum ucode_state apply_microcode_amd(int cpu)
504504
struct microcode_amd *mc_amd;
505505
struct ucode_cpu_info *uci;
506506
struct ucode_patch *p;
507+
enum ucode_state ret;
507508
u32 rev, dummy;
508509

509510
BUG_ON(raw_smp_processor_id() != cpu);
@@ -521,27 +522,30 @@ static enum ucode_state apply_microcode_amd(int cpu)
521522

522523
/* need to apply patch? */
523524
if (rev >= mc_amd->hdr.patch_id) {
524-
c->microcode = rev;
525-
uci->cpu_sig.rev = rev;
526-
return UCODE_OK;
525+
ret = UCODE_OK;
526+
goto out;
527527
}
528528

529529
if (__apply_microcode_amd(mc_amd)) {
530530
pr_err("CPU%d: update failed for patch_level=0x%08x\n",
531531
cpu, mc_amd->hdr.patch_id);
532532
return UCODE_ERROR;
533533
}
534-
pr_info("CPU%d: new patch_level=0x%08x\n", cpu,
535-
mc_amd->hdr.patch_id);
536534

537-
uci->cpu_sig.rev = mc_amd->hdr.patch_id;
538-
c->microcode = mc_amd->hdr.patch_id;
535+
rev = mc_amd->hdr.patch_id;
536+
ret = UCODE_UPDATED;
537+
538+
pr_info("CPU%d: new patch_level=0x%08x\n", cpu, rev);
539+
540+
out:
541+
uci->cpu_sig.rev = rev;
542+
c->microcode = rev;
539543

540544
/* Update boot_cpu_data's revision too, if we're on the BSP: */
541545
if (c->cpu_index == boot_cpu_data.cpu_index)
542-
boot_cpu_data.microcode = mc_amd->hdr.patch_id;
546+
boot_cpu_data.microcode = rev;
543547

544-
return UCODE_UPDATED;
548+
return ret;
545549
}
546550

547551
static int install_equiv_cpu_table(const u8 *buf)

arch/x86/kernel/cpu/microcode/intel.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ static enum ucode_state apply_microcode_intel(int cpu)
795795
struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
796796
struct cpuinfo_x86 *c = &cpu_data(cpu);
797797
struct microcode_intel *mc;
798+
enum ucode_state ret;
798799
static int prev_rev;
799800
u32 rev;
800801

@@ -817,9 +818,8 @@ static enum ucode_state apply_microcode_intel(int cpu)
817818
*/
818819
rev = intel_get_microcode_revision();
819820
if (rev >= mc->hdr.rev) {
820-
uci->cpu_sig.rev = rev;
821-
c->microcode = rev;
822-
return UCODE_OK;
821+
ret = UCODE_OK;
822+
goto out;
823823
}
824824

825825
/*
@@ -848,14 +848,17 @@ static enum ucode_state apply_microcode_intel(int cpu)
848848
prev_rev = rev;
849849
}
850850

851+
ret = UCODE_UPDATED;
852+
853+
out:
851854
uci->cpu_sig.rev = rev;
852-
c->microcode = rev;
855+
c->microcode = rev;
853856

854857
/* Update boot_cpu_data's revision too, if we're on the BSP: */
855858
if (c->cpu_index == boot_cpu_data.cpu_index)
856859
boot_cpu_data.microcode = rev;
857860

858-
return UCODE_UPDATED;
861+
return ret;
859862
}
860863

861864
static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,

0 commit comments

Comments
 (0)