[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 2/2] x86/microcode: Do not upload microcode if CPUs are offline



This patch is to backport the patch below from linux kernel.

    commit 30ec26da9967d0d785abc24073129a34c3211777
    Author: Ashok Raj <ashok.raj@xxxxxxxxx>
    Date:   Wed Feb 28 11:28:43 2018 +0100

        x86/microcode: Do not upload microcode if CPUs are offline

        Avoid loading microcode if any of the CPUs are offline, and issue a
        warning. Having different microcode revisions on the system at any time
        is outright dangerous.

        [ Borislav: Massage changelog. ]

        Signed-off-by: Ashok Raj <ashok.raj@xxxxxxxxx>
        Signed-off-by: Borislav Petkov <bp@xxxxxxx>
        Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
        Tested-by: Tom Lendacky <thomas.lendacky@xxxxxxx>
        Tested-by: Ashok Raj <ashok.raj@xxxxxxxxx>
        Reviewed-by: Tom Lendacky <thomas.lendacky@xxxxxxx>
        Cc: Arjan Van De Ven <arjan.van.de.ven@xxxxxxxxx>
        Link: 
http://lkml.kernel.org/r/1519352533-15992-4-git-send-email-ashok.raj@xxxxxxxxx
        Link: https://lkml.kernel.org/r/20180228102846.13447-5-bp@xxxxxxxxx

Signed-off-by: Chao Gao <chao.gao@xxxxxxxxx>
Cc: Kevin Tian <kevin.tian@xxxxxxxxx>
Cc: Jun Nakajima <jun.nakajima@xxxxxxxxx>
Cc: Ashok Raj <ashok.raj@xxxxxxxxx>
Cc: Borislav Petkov <bp@xxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
---
 xen/arch/x86/microcode.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/xen/arch/x86/microcode.c b/xen/arch/x86/microcode.c
index 94c1ca2..25d9112 100644
--- a/xen/arch/x86/microcode.c
+++ b/xen/arch/x86/microcode.c
@@ -346,16 +346,27 @@ int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) 
buf, unsigned long len)
     if ( microcode_ops == NULL )
         return -EINVAL;
 
+    /* cpu_online_map must not change. */
+    if ( !get_cpu_maps() )
+        return -EBUSY;
+
+    if ( num_present_cpus() != num_online_cpus() )
+    {
+        ret = -EINVAL;
+        printk("Not all CPUs online, aborting microcode update\n");
+        goto put;
+    }
+
     info = xmalloc_bytes(sizeof(*info) + len);
     if ( info == NULL )
-        return -ENOMEM;
+    {
+        ret = -ENOMEM;
+        goto put;
+    }
 
     ret = copy_from_guest(info->buffer, buf, len);
     if ( ret != 0 )
-    {
-        xfree(info);
-        return ret;
-    }
+        goto err;
 
     info->buffer_size = len;
     info->error = 0;
@@ -364,10 +375,7 @@ int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) 
buf, unsigned long len)
     {
         ret = microcode_ops->start_update();
         if ( ret != 0 )
-        {
-            xfree(info);
-            return ret;
-        }
+            goto err;
     }
 
     atomic_set(&info->cpu_in, 0);
@@ -393,7 +401,11 @@ int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) 
buf, unsigned long len)
     watchdog_enable();
 
     ret = info->error;
+
+ err:
     xfree(info);
+ put:
+    put_cpu_maps();
     return ret;
 }
 
-- 
1.8.3.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.