From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
"Wei Liu" <wl@xen.org>, "Roger Pau Monné" <roger.pau@citrix.com>
Subject: [Xen-devel] [PATCH 2/4] x86/ucode: Fix error paths in apply_microcode()
Date: Fri, 20 Mar 2020 21:24:50 +0000 [thread overview]
Message-ID: <20200320212453.21685-3-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <20200320212453.21685-1-andrew.cooper3@citrix.com>
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 state value. Nothing good will come of this.
Rewrite the logic to always update the stashed revision, before worring 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@citrix.com>
---
-CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wl@xen.org>
CC: Roger Pau Monné <roger.pau@citrix.com>
---
xen/arch/x86/cpu/microcode/amd.c | 14 +++++++-------
xen/arch/x86/cpu/microcode/intel.c | 22 +++++++++++-----------
2 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/xen/arch/x86/cpu/microcode/amd.c b/xen/arch/x86/cpu/microcode/amd.c
index d4b2874de6..a053e43923 100644
--- a/xen/arch/x86/cpu/microcode/amd.c
+++ b/xen/arch/x86/cpu/microcode/amd.c
@@ -229,11 +229,11 @@ static enum microcode_match_result compare_patch(
static int apply_microcode(const struct microcode_patch *patch)
{
- uint32_t rev;
int hw_err;
unsigned int cpu = smp_processor_id();
struct cpu_signature *sig = &per_cpu(cpu_sig, cpu);
const struct microcode_header_amd *hdr;
+ uint32_t rev, old_rev = sig->rev;
if ( !patch )
return -ENOENT;
@@ -249,6 +249,7 @@ static int apply_microcode(const struct microcode_patch *patch)
/* get patch id after patching */
rdmsrl(MSR_AMD_PATCHLEVEL, rev);
+ sig->rev = rev;
/*
* Some processors leave the ucode blob mapping as UC after the update.
@@ -259,15 +260,14 @@ static int apply_microcode(const struct microcode_patch *patch)
/* 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, sig->rev, hdr->patch_id);
-
- sig->rev = rev;
+ printk(XENLOG_WARNING "microcode: CPU%u updated from revision %#x to %#x\n",
+ cpu, old_rev, hdr->patch_id);
return 0;
}
diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcode/intel.c
index 5e9c2a9c7f..6ac5f98694 100644
--- a/xen/arch/x86/cpu/microcode/intel.c
+++ b/xen/arch/x86/cpu/microcode/intel.c
@@ -278,10 +278,10 @@ static enum microcode_match_result compare_patch(
static int apply_microcode(const struct microcode_patch *patch)
{
uint64_t msr_content;
- unsigned int val[2];
- unsigned int cpu_num = raw_smp_processor_id();
+ unsigned int cpu = smp_processor_id();
struct cpu_signature *sig = &this_cpu(cpu_sig);
const struct microcode_intel *mc_intel;
+ uint32_t rev, old_rev = sig->rev;
if ( !patch )
return -ENOENT;
@@ -302,20 +302,20 @@ static int apply_microcode(const struct microcode_patch *patch)
/* get the current revision from MSR 0x8B */
rdmsrl(MSR_IA32_UCODE_REV, msr_content);
- val[1] = (uint32_t)(msr_content >> 32);
+ sig->rev = rev = msr_content >> 32;
- if ( val[1] != mc_intel->hdr.rev )
+ if ( rev != mc_intel->hdr.rev )
{
- printk(KERN_ERR "microcode: CPU%d update from revision "
- "%#x to %#x failed. Resulting revision is %#x.\n", cpu_num,
- sig->rev, mc_intel->hdr.rev, val[1]);
+ printk(XENLOG_ERR
+ "microcode: CPU%u update rev %#x to %#x failed, result %#x\n",
+ cpu, old_rev, 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, sig->rev, val[1], mc_intel->hdr.year,
+
+ printk(XENLOG_WARNING
+ "microcode: CPU%u updated from revision %#x to %#x, date = %04x-%02x-%02x\n",
+ cpu, old_rev, rev, mc_intel->hdr.year,
mc_intel->hdr.month, mc_intel->hdr.day);
- sig->rev = val[1];
return 0;
}
--
2.11.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2020-03-20 21:25 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-20 21:24 [Xen-devel] [PATCH 0/4] x86/ucode: Cleanup - Part 2/n Andrew Cooper
2020-03-20 21:24 ` [Xen-devel] [PATCH 1/4] x86/ucode/amd: Fix assertion in compare_patch() Andrew Cooper
2020-03-21 16:45 ` Wei Liu
2020-03-20 21:24 ` Andrew Cooper [this message]
2020-03-21 16:49 ` [Xen-devel] [PATCH 2/4] x86/ucode: Fix error paths in apply_microcode() Wei Liu
2020-03-23 8:32 ` Jan Beulich
2020-03-20 21:24 ` [Xen-devel] [PATCH 3/4] xen: Drop raw_smp_processor_id() Andrew Cooper
2020-03-21 10:14 ` Julien Grall
2020-03-21 16:50 ` Wei Liu
2020-03-20 21:24 ` [Xen-devel] [PATCH 4/4] xen: Introduce a xmemdup_bytes() helper Andrew Cooper
2020-03-21 16:51 ` Wei Liu
2020-03-21 22:19 ` Julien Grall
2020-03-23 8:38 ` Jan Beulich
2020-03-26 15:38 ` Andrew Cooper
2020-03-26 15:47 ` Jan Beulich
2020-03-26 14:53 ` Andrew Cooper
2020-03-26 19:05 ` Julien Grall
2020-03-23 8:41 ` [Xen-devel] [PATCH 0/4] x86/ucode: Cleanup - Part 2/n Jan Beulich
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=20200320212453.21685-3-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=roger.pau@citrix.com \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.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;
as well as URLs for NNTP newsgroup(s).