Skip to contentSkip to conversation

x86/microcode: always collect_cpu_info() during boot

PATCH In review Sergey Dyasli 3 participants 5 messages Mar 25, 2019 – Apr 1, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/microcode: always collect_cpu_info() during boot

Currently cpu_sig struct is not updated during boot when either:

1. ucode_scan is set to false (e.g. no "ucode=scan" in cmdline)
2. initrd does not contain a microcode blob

These will result in cpu_sig.rev being 0 which affects APIC's check_deadline_errata() and retpoline_safe() functions.

Fix this by getting ucode revision early during boot and SMP bring up. While at it, protect early_microcode_update_cpu() for cases when microcode_ops is NULL.

---
CC: Jan Beulich <[email protected]>
CC: Andrew Cooper <[email protected]>
CC: Wei Liu <[email protected]>
CC: "Roger Pau Monné" <[email protected]>
CC: Chao Gao <[email protected]>

---
 xen/arch/x86/microcode.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
xen/arch/x86/microcode.c +12 -0
index 4163f50bb7..421d57e925 100644
@@ -383,10 +383,15 @@ static struct notifier_block microcode_percpu_nfb = {
 
 int __init early_microcode_update_cpu(bool start_update)
 {
+    unsigned int cpu = smp_processor_id();
+    struct ucode_cpu_info *uci = &per_cpu(ucode_cpu_info, cpu);
     int rc = 0;
     void *data = NULL;
     size_t len;
 
+    if ( !microcode_ops )
+        return -ENOSYS;
+
     if ( ucode_blob.size )
     {
         len = ucode_blob.size;
@@ -397,6 +402,9 @@ int __init early_microcode_update_cpu(bool start_update)
         len = ucode_mod.mod_end;
         data = bootstrap_map(&ucode_mod);
     }
+
+    microcode_ops->collect_cpu_info(cpu, &uci->cpu_sig);
+
     if ( data )
     {
         if ( start_update && microcode_ops->start_update )
@@ -413,6 +421,8 @@ int __init early_microcode_update_cpu(bool start_update)
 
 int __init early_microcode_init(void)
 {
+    unsigned int cpu = smp_processor_id();
+    struct ucode_cpu_info *uci = &per_cpu(ucode_cpu_info, cpu);
     int rc;
 
     rc = microcode_init_intel();
@@ -425,6 +435,8 @@ int __init early_microcode_init(void)
 
     if ( microcode_ops )
     {
+        microcode_ops->collect_cpu_info(cpu, &uci->cpu_sig);
+
         if ( ucode_mod.mod_end || ucode_blob.size )
             rc = early_microcode_update_cpu(true);
 
Signature · 7 lines
2.17.1


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

Currently cpu_sig struct is not updated during boot when either:

1. ucode_scan is set to false (e.g. no "ucode=scan" in cmdline)
2. initrd does not contain a microcode blob

Quoted 8 lines

These will result in cpu_sig.rev being 0 which affects APIC's check_deadline_errata() and retpoline_safe() functions.

Fix this by getting ucode revision early during boot and SMP bring up. While at it, protect early_microcode_update_cpu() for cases when microcode_ops is NULL.

Thanks
Chao

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

#2 lore raw
In reply to Sergey Dyasli
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 25.03.19 at 12:12, <[email protected]> wrote:

Currently cpu_sig struct is not updated during boot when either:

1. ucode_scan is set to false (e.g. no "ucode=scan" in cmdline)
2. initrd does not contain a microcode blob

What about "ucode=<number>"?

Quoted 4 lines

These will result in cpu_sig.rev being 0 which affects APIC's check_deadline_errata() and retpoline_safe() functions.

Fix this by getting ucode revision early during boot and SMP bring up.

Can't you then drop the call from microcode_update_cpu()?

xen/arch/x86/microcode.c int __init early_microcode_update_cpu(bool start_update) · line 425

Quoted 6 lines
xen/arch/x86/microcode.c +2 -0
@@ -413,6 +421,8 @@ int __init early_microcode_update_cpu(bool start_update)
 
 int __init early_microcode_init(void)
 {
+    unsigned int cpu = smp_processor_id();
+    struct ucode_cpu_info *uci = &per_cpu(ucode_cpu_info, cpu);

Would you mind moving these declarations ...

xen/arch/x86/microcode.c int __init early_microcode_init(void) · line 438

Quoted 5 lines
xen/arch/x86/microcode.c +1 -0
@@ -425,6 +435,8 @@ int __init early_microcode_init(void)
 
     if ( microcode_ops )
     {
+        microcode_ops->collect_cpu_info(cpu, &uci->cpu_sig);

... into this scope?

Jan

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

#3 lore raw
Quoted 7 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 25.03.19 at 12:12, <[email protected]> wrote:

Currently cpu_sig struct is not updated during boot when either:

1. ucode_scan is set to false (e.g. no "ucode=scan" in cmdline)
2. initrd does not contain a microcode blob

What about "ucode=<number>"?

Yes, it's equally affected, I'll update the commit message.

Quoted 6 lines
Quoted 4 lines

These will result in cpu_sig.rev being 0 which affects APIC's check_deadline_errata() and retpoline_safe() functions.

Fix this by getting ucode revision early during boot and SMP bring up.

Can't you then drop the call from microcode_update_cpu()?

I tried this and found that properly handling errors requires a call to __microcode_fini_cpu(). But instead of doing all this refactoring now, I'd prefer this patch to go on top of Chao's series, which greatly simplifies things in "remove struct ucode_cpu_info". Otherwise, most of my work here would be removed by the next version of Chao's series.

Chao,
To help me with this decision, when can we expect a v7 of your series?

Thanks,
Sergey

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

#4 lore raw
Quoted 25 lines · Sergey Dyasli
Quoted 7 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 25.03.19 at 12:12, <[email protected]> wrote:

Currently cpu_sig struct is not updated during boot when either:

1. ucode_scan is set to false (e.g. no "ucode=scan" in cmdline)
2. initrd does not contain a microcode blob

What about "ucode=<number>"?

Yes, it's equally affected, I'll update the commit message.

Quoted 6 lines
Quoted 4 lines

These will result in cpu_sig.rev being 0 which affects APIC's check_deadline_errata() and retpoline_safe() functions.

Fix this by getting ucode revision early during boot and SMP bring up.

Can't you then drop the call from microcode_update_cpu()?

I tried this and found that properly handling errors requires a call to __microcode_fini_cpu(). But instead of doing all this refactoring now, I'd prefer this patch to go on top of Chao's series, which greatly simplifies things in "remove struct ucode_cpu_info". Otherwise, most of my work here would be removed by the next version of Chao's series.

Quoted 3 lines

Chao,
To help me with this decision, when can we expect a v7 of your series?

Will start to work on v7 from tomorrow. And I hope that it will be finished in this week.

Thanks
Chao

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