xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad@kernel.org>
To: JBeulich@suse.com, xen-devel@lists.xensource.com,
	david.vrabel@citrix.com
Subject: [PATCH] microcode: Check whether the microcode is correct.
Date: Thu, 18 Jul 2013 23:59:23 -0400	[thread overview]
Message-ID: <1374206363-19001-2-git-send-email-konrad.wilk@oracle.com> (raw)
In-Reply-To: <1374206363-19001-1-git-send-email-konrad.wilk@oracle.com>

We do the microcode code update in two steps - the presmp:
 'microcode_presmp_init' and when CPUs are brought up:
'microcode_init'. The earlier performs the microcode update
on the BSP - but unfortunately it does not check whether the
update failed. Which means that we might try later to update
a incorrect payload on the rest of CPUs.

Furthermore now that the ucode= parameter can specify two
sources of microcode blob we have to be cognizant whether
both (or either) of the payloads are correct.

For example, the user could have constructed the cpio archive
with a empty GenuineIntel.bin file and provided the correct
GenuineIntel.bin as a seperate payload:

xen.gz ucode=2,initrd --- vmlinuz --- initramfs.cpio.gz --- GenuineIntel.bin

[the initramfs.cpio.gz has the cpio archive of the empty file
kernel/x86/microcode/GenuineIntel.bin pre-pended]

in which case we need to skip the microcode payload from the
initramfs.cpio.gz and use the GenuineIntel.bin payload.

Or if the user mishandled the GenuineIntel.bin seperate payload and
had the initramfs.cpio.gz correct. Or if both payloads had
bogus data.

This patch handles these odd situations.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
 xen/arch/x86/microcode.c |   52 ++++++++++++++++++++++++++++++----------------
 1 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/xen/arch/x86/microcode.c b/xen/arch/x86/microcode.c
index b191e9f..2ab2b46 100644
--- a/xen/arch/x86/microcode.c
+++ b/xen/arch/x86/microcode.c
@@ -433,24 +433,40 @@ static int __init microcode_presmp_init(void)
     {
         if ( ucode_mod.mod_end || ucode_blob.size )
         {
-            void *data;
-            size_t len;
-
-            if ( ucode_blob.size )
-            {
-                len = ucode_blob.size;
-                data = ucode_blob.data;
-            }
-            else
-            {
-                len = ucode_mod.mod_end;
-                data = ucode_mod_map(&ucode_mod);
-            }
-            if ( data )
-                microcode_update_cpu(data, len);
-
-            if ( !ucode_blob.size )
-                ucode_mod_map(NULL);
+            int rc;
+            do {
+                void *data = NULL;
+                size_t len;
+
+                rc = 0;
+                if ( ucode_blob.size )
+                {
+                    len = ucode_blob.size;
+                    data = ucode_blob.data;
+                }
+                else if ( ucode_mod.mod_end )
+                {
+                    len = ucode_mod.mod_end;
+                    data = ucode_mod_map(&ucode_mod);
+                }
+                if ( data )
+                    rc = microcode_update_cpu(data, len);
+
+                if ( !ucode_blob.size && ucode_mod.mod_end )
+                    ucode_mod_map(NULL);
+
+                if ( rc == -EINVAL )
+                {
+                    if ( ucode_blob.size ) /* That was tried first */
+                    {
+                        ucode_blob.size = 0;
+                        xfree(ucode_blob.data);
+                        continue;
+                    }
+                    if ( ucode_mod.mod_end )
+                        ucode_mod.mod_end = 0;
+                }
+            } while ( rc );
         }
 
         register_cpu_notifier(&microcode_percpu_nfb);
-- 
1.7.7.6

  reply	other threads:[~2013-07-19  3:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-18 16:36 Scan initramfs for microcode cpio archive. (v2) Konrad Rzeszutek Wilk
2013-07-18 16:36 ` [PATCH v2] microcode: Scan the initramfs payload for microcode blob Konrad Rzeszutek Wilk
2013-08-07 14:09   ` Jan Beulich
2013-08-08  0:50     ` Konrad Rzeszutek Wilk
2013-08-08  7:07       ` Jan Beulich
2013-07-19  3:59 ` Scan initramfs for microcode cpio archive. (v2) Konrad Rzeszutek Wilk
2013-07-19  3:59   ` Konrad Rzeszutek Wilk [this message]
2013-08-07 14:17     ` [PATCH] microcode: Check whether the microcode is correct Jan Beulich
2013-08-08  0:50       ` Konrad Rzeszutek Wilk

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=1374206363-19001-2-git-send-email-konrad.wilk@oracle.com \
    --to=konrad@kernel.org \
    --cc=JBeulich@suse.com \
    --cc=david.vrabel@citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /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).