Skip to contentSkip to conversation

x86/microcode: refuse to load the same revision ucode

PATCH Superseded Sergey Dyasli 3 participants 4 messages Nov 26, 2019 – Nov 27, 2019

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 x86/microcode: refuse to load the same revision ucode

Currently if a user tries to live-load the same or older ucode revision than CPU already has, he will get a single message in Xen log like:

(XEN) 128 cores are to update their microcode

No actual ucode loading will happen and this situation can be quite confusing. Fix this by starting ucode update only when the provided ucode revision is higher than the currently cached one (if any). This is based on the property that if microcode_cache exists, all CPUs in the system should have at least that ucode revision.

Additionally, print a user friendly message if no matching or newer ucode can be found in the provided blob. This also requires ignoring -ENODATA in AMD-side code, otherwise the message given to the user is:

(XEN) Parsing microcode blob error -61

Which actually means that a ucode blob was parsed fine, but no matching ucode was found.

---
v2 --> v3:
- move ucode comparison to generic code
- ignore -ENODATA in a different code section

v1 --> v2:
- compare provided ucode with the currently cached one

CC Jan Beulich <[email protected]>
CC Andrew Cooper <[email protected]>
CC Roger Pau Monné <[email protected]>
CC Chao Gao <[email protected]>
CC Juergen Gross <[email protected]>
---
 xen/arch/x86/microcode.c     | 19 +++++++++++++++++++
 xen/arch/x86/microcode_amd.c |  7 +++++++
 2 files changed, 26 insertions(+)
xen/arch/x86/microcode.c +19 -0
index 65d1f41e7c..44efc2d9b3 100644
@@ -640,10 +640,29 @@ int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long len)
 
     if ( !patch )
     {
+        printk(XENLOG_WARNING "microcode: couldn't find any matching ucode in "
+                              "the provided blob!\n");
         ret = -ENOENT;
         goto put;
     }
 
+    /*
+     * If microcode_cache exists, all CPUs in the system should have at least
+     * that ucode revision.
+     */
+    spin_lock(&microcode_mutex);
+    if ( microcode_cache &&
+         microcode_ops->compare_patch(patch, microcode_cache) != NEW_UCODE )
+    {
+        spin_unlock(&microcode_mutex);
+        printk(XENLOG_WARNING "microcode: couldn't find any newer revision "
+                              "in the provided blob!\n");
+        ret = -ENOENT;
+
+        goto put;
+    }
+    spin_unlock(&microcode_mutex);
+
     if ( microcode_ops->start_update )
     {
         ret = microcode_ops->start_update();
xen/arch/x86/microcode_amd.c +7 -0
index 1e52f7f49a..00750f7bbb 100644
@@ -502,6 +502,13 @@ static struct microcode_patch *cpu_request_microcode(const void *buf,
 
     if ( error )
     {
+        /*
+         * -ENODATA here means that the blob was parsed fine but no matching
+         * ucode was found. Don't return it to the caller.
+         */
+        if ( error == -ENODATA )
+            error = 0;
+
         xfree(mc_amd->equiv_cpu_table);
         xfree(mc_amd);
         goto out;
Signature · 7 lines
2.17.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v3 1/1
#1 lore raw
Quoted 15 lines · Sergey Dyasli

Currently if a user tries to live-load the same or older ucode revision than CPU already has, he will get a single message in Xen log like:

(XEN) 128 cores are to update their microcode

No actual ucode loading will happen and this situation can be quite confusing. Fix this by starting ucode update only when the provided ucode revision is higher than the currently cached one (if any). This is based on the property that if microcode_cache exists, all CPUs in the system should have at least that ucode revision.

Additionally, print a user friendly message if no matching or newer ucode can be found in the provided blob. This also requires ignoring -ENODATA in AMD-side code, otherwise the message given to the user is:

Quoted 6 lines

(XEN) Parsing microcode blob error -61

Which actually means that a ucode blob was parsed fine, but no matching ucode was found.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v3 1/1
#2 lore raw
In reply to Sergey Dyasli
Quoted 54 lines · Sergey Dyasli

Currently if a user tries to live-load the same or older ucode revision than CPU already has, he will get a single message in Xen log like:

(XEN) 128 cores are to update their microcode

No actual ucode loading will happen and this situation can be quite confusing. Fix this by starting ucode update only when the provided ucode revision is higher than the currently cached one (if any). This is based on the property that if microcode_cache exists, all CPUs in the system should have at least that ucode revision.

Additionally, print a user friendly message if no matching or newer ucode can be found in the provided blob. This also requires ignoring -ENODATA in AMD-side code, otherwise the message given to the user is:

(XEN) Parsing microcode blob error -61

Which actually means that a ucode blob was parsed fine, but no matching ucode was found.

---
v2 --> v3:
- move ucode comparison to generic code
- ignore -ENODATA in a different code section

v1 --> v2:
- compare provided ucode with the currently cached one

CC Jan Beulich <[email protected]>
CC Andrew Cooper <[email protected]>
CC Roger Pau Monné <[email protected]>
CC Chao Gao <[email protected]>
CC Juergen Gross <[email protected]>

---
xen/arch/x86/microcode.c | 19 +++++++++++++++++++
xen/arch/x86/microcode_amd.c | 7 +++++++

2 files changed, 26 insertions(+)
xen/arch/x86/microcode.c +3 -0
index 65d1f41e7c..44efc2d9b3 100644
@@ -640,10 +640,29 @@ int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long len)
 
    if ( !patch )
    {
+        printk(XENLOG_WARNING "microcode: couldn't find any matching ucode in "
+                              "the provided blob!\n");
        ret = -ENOENT;
        goto put;
    }
 
+    /*

xen/arch/x86/microcode.c int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long len) · line 659

Quoted 10 lines
xen/arch/x86/microcode.c +10 -0
+     * If microcode_cache exists, all CPUs in the system should have at least
+     * that ucode revision.
+     */
+    spin_lock(&microcode_mutex);
+    if ( microcode_cache &&
+         microcode_ops->compare_patch(patch, microcode_cache) != NEW_UCODE )
+    {
+        spin_unlock(&microcode_mutex);
+        printk(XENLOG_WARNING "microcode: couldn't find any newer revision "
+                              "in the provided blob!\n");

The patch needs to be freed.

With it fixed,

Thanks
Chao

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 54 lines · Chao Gao
Quoted 53 lines · Sergey Dyasli

Currently if a user tries to live-load the same or older ucode revision than CPU already has, he will get a single message in Xen log like:

(XEN) 128 cores are to update their microcode

No actual ucode loading will happen and this situation can be quite confusing. Fix this by starting ucode update only when the provided ucode revision is higher than the currently cached one (if any). This is based on the property that if microcode_cache exists, all CPUs in the system should have at least that ucode revision.

Additionally, print a user friendly message if no matching or newer ucode can be found in the provided blob. This also requires ignoring -ENODATA in AMD-side code, otherwise the message given to the user is:

(XEN) Parsing microcode blob error -61

Which actually means that a ucode blob was parsed fine, but no matching ucode was found.

---
v2 --> v3:
- move ucode comparison to generic code
- ignore -ENODATA in a different code section

v1 --> v2:
- compare provided ucode with the currently cached one

CC Jan Beulich <[email protected]>
CC Andrew Cooper <[email protected]>
CC Roger Pau Monné <[email protected]>
CC Chao Gao <[email protected]>
CC Juergen Gross <[email protected]>

---
xen/arch/x86/microcode.c | 19 +++++++++++++++++++
xen/arch/x86/microcode_amd.c | 7 +++++++

2 files changed, 26 insertions(+)
xen/arch/x86/microcode.c +2 -0
index 65d1f41e7c..44efc2d9b3 100644
@@ -640,10 +640,29 @@ int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long len)
 
    if ( !patch )
    {
+        printk(XENLOG_WARNING "microcode: couldn't find any matching ucode in "
+                              "the provided blob!\n");
        ret = -ENOENT;
        goto put;
    }
 
Quoted 13 lines

xen/arch/x86/microcode.c int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long len) · line 659

Quoted 11 lines
xen/arch/x86/microcode.c +11 -0
+    /*
+     * If microcode_cache exists, all CPUs in the system should have at least
+     * that ucode revision.
+     */
+    spin_lock(&microcode_mutex);
+    if ( microcode_cache &&
+         microcode_ops->compare_patch(patch, microcode_cache) != NEW_UCODE )
+    {
+        spin_unlock(&microcode_mutex);
+        printk(XENLOG_WARNING "microcode: couldn't find any newer revision "
+                              "in the provided blob!\n");

The patch needs to be freed.

Thanks for noticing this!

--
Sergey

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel