[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen staging-4.12] x86/ucode: Fix error paths in apply_microcode()
commit 94f0bb7c3ff63b7322849cd80ed0d6c2b9998ee4 Author: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> AuthorDate: Thu Apr 9 09:31:45 2020 +0200 Commit: Jan Beulich <jbeulich@xxxxxxxx> CommitDate: Thu Apr 9 09:31:45 2020 +0200 x86/ucode: Fix error paths in apply_microcode() In the unlikley case that patch application completes, but the resutling revision isn't expected, sig->rev doesn't get updated to match reality. It will get adjusted the next time collect_cpu_info() gets called, but in the meantime Xen might operate on a stale value. Nothing good will come of this. Rewrite the logic to always update the stashed revision, before worrying about whether the attempt was a success or failure. Take the opportunity to make the printk() messages as consistent as possible. Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> Reviewed-by: Wei Liu <wl@xxxxxxx> master commit: d2a0a96cf76603b2e2b87c3ce80c3f9d098327d4 master date: 2020-03-26 18:57:45 +0000 --- xen/arch/x86/microcode_amd.c | 14 +++++++------- xen/arch/x86/microcode_intel.c | 21 +++++++++++---------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/xen/arch/x86/microcode_amd.c b/xen/arch/x86/microcode_amd.c index 7a854c012f..01bd6d6cc1 100644 --- a/xen/arch/x86/microcode_amd.c +++ b/xen/arch/x86/microcode_amd.c @@ -194,7 +194,7 @@ static int apply_microcode(unsigned int cpu) { unsigned long flags; struct ucode_cpu_info *uci = &per_cpu(ucode_cpu_info, cpu); - uint32_t rev; + uint32_t rev, old_rev = uci->cpu_sig.rev; struct microcode_amd *mc_amd = uci->mc.mc_amd; struct microcode_header_amd *hdr; int hw_err; @@ -215,6 +215,7 @@ static int apply_microcode(unsigned int cpu) /* get patch id after patching */ rdmsrl(MSR_AMD_PATCHLEVEL, rev); + uci->cpu_sig.rev = rev; spin_unlock_irqrestore(µcode_update_lock, flags); @@ -227,15 +228,14 @@ static int apply_microcode(unsigned int cpu) /* check current patch id and patch's id for match */ if ( hw_err || (rev != hdr->patch_id) ) { - printk(KERN_ERR "microcode: CPU%d update from revision " - "%#x to %#x failed\n", cpu, rev, hdr->patch_id); + printk(XENLOG_ERR + "microcode: CPU%u update rev %#x to %#x failed, result %#x\n", + cpu, old_rev, hdr->patch_id, rev); return -EIO; } - printk(KERN_WARNING "microcode: CPU%d updated from revision %#x to %#x\n", - cpu, uci->cpu_sig.rev, hdr->patch_id); - - uci->cpu_sig.rev = rev; + printk(XENLOG_WARNING "microcode: CPU%u updated from revision %#x to %#x\n", + cpu, old_rev, rev); return 0; } diff --git a/xen/arch/x86/microcode_intel.c b/xen/arch/x86/microcode_intel.c index 9657575c29..e511bd853c 100644 --- a/xen/arch/x86/microcode_intel.c +++ b/xen/arch/x86/microcode_intel.c @@ -281,9 +281,9 @@ static int apply_microcode(unsigned int cpu) { unsigned long flags; uint64_t msr_content; - unsigned int val[2]; unsigned int cpu_num = raw_smp_processor_id(); struct ucode_cpu_info *uci = &per_cpu(ucode_cpu_info, cpu_num); + uint32_t rev, old_rev = uci->cpu_sig.rev; /* We should bind the task to the CPU */ BUG_ON(cpu_num != cpu); @@ -303,23 +303,24 @@ static int apply_microcode(unsigned int cpu) /* get the current revision from MSR 0x8B */ rdmsrl(MSR_IA32_UCODE_REV, msr_content); - val[1] = (uint32_t)(msr_content >> 32); + uci->cpu_sig.rev = rev = msr_content >> 32; spin_unlock_irqrestore(µcode_update_lock, flags); - if ( val[1] != uci->mc.mc_intel->hdr.rev ) + + if ( rev != uci->mc.mc_intel->hdr.rev ) { - printk(KERN_ERR "microcode: CPU%d update from revision " - "%#x to %#x failed. Resulting revision is %#x.\n", cpu_num, - uci->cpu_sig.rev, uci->mc.mc_intel->hdr.rev, val[1]); + printk(XENLOG_ERR + "microcode: CPU%u update rev %#x to %#x failed, result %#x\n", + cpu, old_rev, uci->mc.mc_intel->hdr.rev, rev); return -EIO; } - printk(KERN_INFO "microcode: CPU%d updated from revision " - "%#x to %#x, date = %04x-%02x-%02x \n", - cpu_num, uci->cpu_sig.rev, val[1], + + printk(XENLOG_WARNING + "microcode: CPU%u updated from revision %#x to %#x, date = %04x-%02x-%02x\n", + cpu, old_rev, rev, uci->mc.mc_intel->hdr.date & 0xffff, uci->mc.mc_intel->hdr.date >> 24, (uci->mc.mc_intel->hdr.date >> 16) & 0xff); - uci->cpu_sig.rev = val[1]; return 0; } -- generated by git-patchbot for /home/xen/git/xen.git#staging-4.12
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |