Skip to contentSkip to conversation

x86, amd_ucode: Skip microcode updates for final levels

PATCH In review Aravind Gopalakrishnan 4 participants 11 messages Aug 3, 2015 – Aug 11, 2015

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 x86, amd_ucode: Skip microcode updates for final levels

Some of older[Fam10h] systems require that certain number of applied microcode patch levels should not be overwritten by the microcode loader. Otherwise, system hangs are known to occur.

The 'final_levels' of patch ids have been obtained empirically. Refer bug https://bugzilla.suse.com/show_bug.cgi?id=913996
for details of the issue.

The short version is that people have predominantly noticed system hang issues when trying to update microcode levels beyond the patch IDs below.
[0x01000098, 0x0100009f, 0x010000af]

Quoted 1 line

From internal discussions, we gathered that OS/hypervisor

cannot reliably perform microcode updates beyond these levels due to hardware issues. Therefore, we need to abort microcode update process if we hit any of these levels.

In this patch, we check for those microcode versions and abort if the current core has one of those final patch levels applied by the BIOS

A linux version of the patch has already made it into tip-
http://marc.info/?l=linux-kernel&m=143703405627170

---
Changes from V2 (per Boris)
- introduce family check as it's theoritically possible to have same patch level for different family too.
- Indicate that the check is only on Fam10h too while at it

Changes from V1 (per Andrew)
- use commit text from linux patch
- include details about how 'final_levels' are obtaines in comments (I have also copied it into commit message. But shall remove if you feel it's redundant)
- use ARRAY_SIZE() and kill NULL terminator
- use XENLOG_INFO in place of pr_debug()
- correct unsigned int usage

 xen/arch/x86/microcode_amd.c | 45 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
xen/arch/x86/microcode_amd.c +45 -0
index f79b397..b5f7148 100644
@@ -347,6 +347,43 @@ static int container_fast_forward(const void *data, size_t size_left, size_t *of
     return 0;
 }
 
+/*
+ * The 'final_levels' of patch ids have been obtained empirically.
+ * Refer bug https://bugzilla.suse.com/show_bug.cgi?id=913996
+ * for details of the issue. The short version is that people
+ * using certain Fam10h systems noticed system hang issues when
+ * trying to update microcode levels beyond the patch IDs below.
+ * From internal discussions, we gathered that OS/hypervisor
+ * cannot reliably perform microcode updates beyond these levels
+ * due to hardware issues. Therefore, we need to abort microcode
+ * update process if we hit any of these levels.
+ */
+static unsigned int final_levels[] = {
+    0x01000098,
+    0x0100009f,
+    0x010000af
+};
+
+static bool_t check_final_patch_levels(int cpu)
+{
+    /*
+     * Check the current patch levels on the cpu. If they are equal to
+     * any of the 'final_levels', then we should not update the microcode
+     * patch on the cpu as system will hang otherwise.
+     */
+    struct ucode_cpu_info *uci = &per_cpu(ucode_cpu_info, cpu);
+    unsigned int i;
+
+    if ( boot_cpu_data.x86 != 0x10 )
+        return 0;
+
+    for ( i = 0; i < ARRAY_SIZE(final_levels); i++ )
+        if ( uci->cpu_sig.rev == final_levels[i] )
+            return 1;
+
+    return 0;
+}
+
 static int cpu_request_microcode(int cpu, const void *buf, size_t bufsize)
 {
     struct microcode_amd *mc_amd, *mc_old;
@@ -369,6 +406,14 @@ static int cpu_request_microcode(int cpu, const void *buf, size_t bufsize)
         goto out;
     }
 
+    if ( check_final_patch_levels(cpu) )
+    {
+        printk(XENLOG_INFO
+               "microcode: Cannot update microcode patch on the cpu as we hit a final level\n");
+        error = -EPERM;
+        goto out;
+    }
+
     mc_amd = xmalloc(struct microcode_amd);
     if ( !mc_amd )
     {
Signature · 1 line
1.9.1
Reviewed-by on v3 1/1
#1 lore raw
Quoted 22 lines · Aravind Gopalakrishnan

Some of older[Fam10h] systems require that certain number of applied microcode patch levels should not be overwritten by the microcode loader. Otherwise, system hangs are known to occur.

The 'final_levels' of patch ids have been obtained empirically. Refer bug https://bugzilla.suse.com/show_bug.cgi?id=913996
for details of the issue.

The short version is that people have predominantly noticed system hang issues when trying to update microcode levels beyond the patch IDs below.
[0x01000098, 0x0100009f, 0x010000af]

From internal discussions, we gathered that OS/hypervisor
cannot reliably perform microcode updates beyond these levels due to hardware issues. Therefore, we need to abort microcode update process if we hit any of these levels.

In this patch, we check for those microcode versions and abort if the current core has one of those final patch levels applied by the BIOS

Quoted 5 lines

A linux version of the patch has already made it into tip-
http://marc.info/?l=linux-kernel&m=143703405627170

Quoted 81 lines

---
Changes from V2 (per Boris)
- introduce family check as it's theoritically possible to have same patch level for different family too.
- Indicate that the check is only on Fam10h too while at it

Changes from V1 (per Andrew)
- use commit text from linux patch
- include details about how 'final_levels' are obtaines in comments (I have also copied it into commit message. But shall remove if you feel it's redundant)
- use ARRAY_SIZE() and kill NULL terminator
- use XENLOG_INFO in place of pr_debug()
- correct unsigned int usage

  xen/arch/x86/microcode_amd.c | 45 ++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 45 insertions(+)
xen/arch/x86/microcode_amd.c +45 -0
index f79b397..b5f7148 100644
@@ -347,6 +347,43 @@ static int container_fast_forward(const void *data, size_t size_left, size_t *of
      return 0;
  }
 
+/*
+ * The 'final_levels' of patch ids have been obtained empirically.
+ * Refer bug https://bugzilla.suse.com/show_bug.cgi?id=913996
+ * for details of the issue. The short version is that people
+ * using certain Fam10h systems noticed system hang issues when
+ * trying to update microcode levels beyond the patch IDs below.
+ * From internal discussions, we gathered that OS/hypervisor
+ * cannot reliably perform microcode updates beyond these levels
+ * due to hardware issues. Therefore, we need to abort microcode
+ * update process if we hit any of these levels.
+ */
+static unsigned int final_levels[] = {
+    0x01000098,
+    0x0100009f,
+    0x010000af
+};
+
+static bool_t check_final_patch_levels(int cpu)
+{
+    /*
+     * Check the current patch levels on the cpu. If they are equal to
+     * any of the 'final_levels', then we should not update the microcode
+     * patch on the cpu as system will hang otherwise.
+     */
+    struct ucode_cpu_info *uci = &per_cpu(ucode_cpu_info, cpu);
+    unsigned int i;
+
+    if ( boot_cpu_data.x86 != 0x10 )
+        return 0;
+
+    for ( i = 0; i < ARRAY_SIZE(final_levels); i++ )
+        if ( uci->cpu_sig.rev == final_levels[i] )
+            return 1;
+
+    return 0;
+}
+
  static int cpu_request_microcode(int cpu, const void *buf, size_t bufsize)
  {
      struct microcode_amd *mc_amd, *mc_old;
@@ -369,6 +406,14 @@ static int cpu_request_microcode(int cpu, const void *buf, size_t bufsize)
          goto out;
      }
 
+    if ( check_final_patch_levels(cpu) )
+    {
+        printk(XENLOG_INFO
+               "microcode: Cannot update microcode patch on the cpu as we hit a final level\n");
+        error = -EPERM;
+        goto out;
+    }
+
      mc_amd = xmalloc(struct microcode_amd);
      if ( !mc_amd )
      {
#2 lore raw
Quoted 23 lines · Boris Ostrovsky
Quoted 22 lines · Aravind Gopalakrishnan

Some of older[Fam10h] systems require that certain number of applied microcode patch levels should not be overwritten by the microcode loader. Otherwise, system hangs are known to occur.

The 'final_levels' of patch ids have been obtained empirically. Refer bug https://bugzilla.suse.com/show_bug.cgi?id=913996
for details of the issue.

The short version is that people have predominantly noticed system hang issues when trying to update microcode levels beyond the patch IDs below.
[0x01000098, 0x0100009f, 0x010000af]

From internal discussions, we gathered that OS/hypervisor
cannot reliably perform microcode updates beyond these levels due to hardware issues. Therefore, we need to abort microcode update process if we hit any of these levels.

In this patch, we check for those microcode versions and abort if the current core has one of those final patch levels applied by the BIOS

Quoted 7 lines
Quoted 5 lines

A linux version of the patch has already made it into tip-
http://marc.info/?l=linux-kernel&m=143703405627170

For the avoidance of any confusion, I am happy for my R-b to stand, given this addition to the patch.

~Andrew

#3 lore raw
In reply to Aravind Gopalakrishnan
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 03.08.15 at 21:34, <[email protected]> wrote:
xen/arch/x86/microcode_amd.c +2 -0
@@ -347,6 +347,43 @@ static int container_fast_forward(const void *data, size_t size_left, size_t *of
     return 0;
 }
 
+/*
+ * The 'final_levels' of patch ids have been obtained empirically.

xen/arch/x86/microcode_amd.c static int container_fast_forward(const void *data, size_t size_left, size_t *of · line 361

Quoted 10 lines
xen/arch/x86/microcode_amd.c +10 -0
+ * Refer bug https://bugzilla.suse.com/show_bug.cgi?id=913996 
+ * for details of the issue. The short version is that people
+ * using certain Fam10h systems noticed system hang issues when
+ * trying to update microcode levels beyond the patch IDs below.
+ * From internal discussions, we gathered that OS/hypervisor
+ * cannot reliably perform microcode updates beyond these levels
+ * due to hardware issues. Therefore, we need to abort microcode
+ * update process if we hit any of these levels.
+ */
+static unsigned int final_levels[] = {

const

xen/arch/x86/microcode_amd.c static int container_fast_forward(const void *data, size_t size_left, size_t *of · line 367

Quoted 6 lines
xen/arch/x86/microcode_amd.c +6 -0
+    0x01000098,
+    0x0100009f,
+    0x010000af
+};
+
+static bool_t check_final_patch_levels(int cpu)

unsigned int

Jan

#4 lore raw
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 03.08.15 at 21:34, <[email protected]> wrote:
xen/arch/x86/microcode_amd.c +0 -0
@@ -347,6 +347,43 @@ static int container_fast_forward(const void *data, size_t size_left, size_t *of
      return 0;
  }
 
Quoted 13 lines

xen/arch/x86/microcode_amd.c static int container_fast_forward(const void *data, size_t size_left, size_t *of · line 361

Quoted 12 lines
xen/arch/x86/microcode_amd.c +12 -0
+/*
+ * The 'final_levels' of patch ids have been obtained empirically.
+ * Refer bug https://bugzilla.suse.com/show_bug.cgi?id=913996
+ * for details of the issue. The short version is that people
+ * using certain Fam10h systems noticed system hang issues when
+ * trying to update microcode levels beyond the patch IDs below.
+ * From internal discussions, we gathered that OS/hypervisor
+ * cannot reliably perform microcode updates beyond these levels
+ * due to hardware issues. Therefore, we need to abort microcode
+ * update process if we hit any of these levels.
+ */
+static unsigned int final_levels[] = {

const

Okay, will fix this.

Quoted 8 lines

xen/arch/x86/microcode_amd.c static int container_fast_forward(const void *data, size_t size_left, size_t *of · line 367

Quoted 6 lines
xen/arch/x86/microcode_amd.c +6 -0
+    0x01000098,
+    0x0100009f,
+    0x010000af
+};
+
+static bool_t check_final_patch_levels(int cpu)

unsigned int

I can change this too, but- Any specific reason for this?
The other sanity checker or verification functions like verify_patch_size() or microcode_fits() return a bool_t too..

Thanks,
-Aravind.

#5 lore raw
Quoted 33 lines · Aravind Gopalakrishnan
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 03.08.15 at 21:34, <[email protected]> wrote:
xen/arch/x86/microcode_amd.c +4 -0
@@ -347,6 +347,43 @@ static int container_fast_forward(const void
 *data, size_t size_left, size_t *of
      return 0;
  }
  +/*
+ * The 'final_levels' of patch ids have been obtained empirically.
+ * Refer bug https://bugzilla.suse.com/show_bug.cgi?id=913996
+ * for details of the issue. The short version is that people
+ * using certain Fam10h systems noticed system hang issues when
Quoted 8 lines

xen/arch/x86/microcode_amd.c static int container_fast_forward(const void *data, size_t size_left, size_t *of · line 361

Quoted 7 lines
xen/arch/x86/microcode_amd.c +7 -0
+ * trying to update microcode levels beyond the patch IDs below.
+ * From internal discussions, we gathered that OS/hypervisor
+ * cannot reliably perform microcode updates beyond these levels
+ * due to hardware issues. Therefore, we need to abort microcode
+ * update process if we hit any of these levels.
+ */
+static unsigned int final_levels[] = {

const

Okay, will fix this.

Quoted 8 lines

xen/arch/x86/microcode_amd.c static int container_fast_forward(const void *data, size_t size_left, size_t *of · line 367

Quoted 6 lines
xen/arch/x86/microcode_amd.c +6 -0
+    0x01000098,
+    0x0100009f,
+    0x010000af
+};
+
+static bool_t check_final_patch_levels(int cpu)

unsigned int

Quoted 3 lines

I can change this too, but- Any specific reason for this? The other sanity checker or verification functions like verify_patch_size() or microcode_fits() return a bool_t too..

"int cpu" is the issue (I am guessing), not the return type.

~Andrew

#6 lore raw
Quoted 9 lines · Andrew Cooper
Quoted 9 lines
Quoted 9 lines

xen/arch/x86/microcode_amd.c static int container_fast_forward(const void *data, size_t size_left, size_t *of · line 367

Quoted 7 lines
xen/arch/x86/microcode_amd.c +6 -0
+    0x01000098,
+    0x0100009f,
+    0x010000af
+};
+
+static bool_t check_final_patch_levels(int cpu)

unsigned int

Quoted 5 lines
Quoted 3 lines

I can change this too, but- Any specific reason for this? The other sanity checker or verification functions like verify_patch_size() or microcode_fits() return a bool_t too..

"int cpu" is the issue (I am guessing), not the return type.

Thought about that too.. but all the microcode_ops functions accept an 'int cpu'. I'm just using the same type in check_final_patch_levels().

Anyway, will wait for Jan's feedback..

Thanks,
-Aravind.

#7 lore raw
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 11.08.15 at 17:28, <[email protected]> wrote:
Quoted 12 lines · Andrew Cooper
Quoted 12 lines
Quoted 9 lines

xen/arch/x86/microcode_amd.c static int container_fast_forward(const void *data, size_t size_left, size_t *of · line 367

Quoted 7 lines
xen/arch/x86/microcode_amd.c +6 -0
+    0x01000098,
+    0x0100009f,
+    0x010000af
+};
+
+static bool_t check_final_patch_levels(int cpu)

unsigned int

I can change this too, but- Any specific reason for this? The other sanity checker or verification functions like verify_patch_size() or microcode_fits() return a bool_t too..

Quoted 6 lines
Quoted 2 lines

"int cpu" is the issue (I am guessing), not the return type.

Thought about that too.. but all the microcode_ops functions accept an 'int cpu'.
I'm just using the same type in check_final_patch_levels().

And ideally all other bad examples would be fixed in a cleanup patch too - CPU numbers can't be negative. In any event we should aim at not proliferating such sub-optimal code.

Jan

#8 lore raw
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

+static bool_t check_final_patch_levels(int cpu)

unsigned int

I can change this too, but- Any specific reason for this? The other sanity checker or verification functions like verify_patch_size() or microcode_fits() return a bool_t too..

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

"int cpu" is the issue (I am guessing), not the return type.

Thought about that too.. but all the microcode_ops functions accept an 'int cpu'.
I'm just using the same type in check_final_patch_levels().

And ideally all other bad examples would be fixed in a cleanup patch too - CPU numbers can't be negative. In any event we should aim at not proliferating such sub-optimal code.

Okay, I can clean that up while at it.

Would it be OK if I did a pre-patch to cleanup the 'int cpu' usage in the microcode* files and then apply this patch on top of it?

Thanks,
-Aravind.

#9 lore raw
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 11.08.15 at 17:43, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

+static bool_t check_final_patch_levels(int cpu)

unsigned int

I can change this too, but- Any specific reason for this? The other sanity checker or verification functions like verify_patch_size() or microcode_fits() return a bool_t too..

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

"int cpu" is the issue (I am guessing), not the return type.

Thought about that too.. but all the microcode_ops functions accept an 'int cpu'.
I'm just using the same type in check_final_patch_levels().

And ideally all other bad examples would be fixed in a cleanup patch too - CPU numbers can't be negative. In any event we should aim at not proliferating such sub-optimal code.

Quoted 4 lines

Okay, I can clean that up while at it.

Would it be OK if I did a pre-patch to cleanup the 'int cpu' usage in the microcode* files and then apply this patch on top of it?

Sure.

Jan

#10 lore raw
In reply to Andrew Cooper
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 11.08.15 at 17:17, <[email protected]> wrote:
Quoted 3 lines · Aravind Gopalakrishnan
Quoted 2 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 03.08.15 at 21:34, <[email protected]> wrote:

+static bool_t check_final_patch_levels(int cpu)

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

unsigned int

I can change this too, but- Any specific reason for this? The other sanity checker or verification functions like verify_patch_size() or microcode_fits() return a bool_t too..

"int cpu" is the issue (I am guessing), not the return type.

Indeed.

jan