x86/ucode: Further fixes to identify "ucode already up to date"
PATCH 1/1 x86/ucode: Further fixes to identify "ucode already up to date"
When the revision in hardware is newer than anything Xen has to hand, 'microcode_cache' isn't set up. Then, xen-ucode initiates the update because it doesn't know whether the revisions across the system are symmetric or not. This involves the patch getting all the way into the apply_microcode() hooks before being found to be too old.
This is all a giant mess and needs an overhaul, but in the short term simply adjust the apply_microcode() to return -EEXIST.
Also, unconditionally print the preexisting microcode revision on boot. It's relevant information which is otherwise unavailable if Xen doesn't find new microcode to use.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Fouad Hilly <[email protected]>
Sorry Fouad, but this collides with your --force series once again. Hopefully it might make things fractionally easier.
Background: For 06-55-04 (Skylake server, stepping 4 specifically), there's a recent production firmware update which has a newer microcode revision than exists in the Intel public microcode repository. It's causing a mess in our automated testing, although it is finding good bugs...
--- xen/arch/x86/cpu/microcode/amd.c | 7 +++++-- xen/arch/x86/cpu/microcode/core.c | 2 ++ xen/arch/x86/cpu/microcode/intel.c | 7 +++++-- 3 files changed, 12 insertions(+), 4 deletions(-)
xen/arch/x86/cpu/microcode/amd.c +5 -2
@@ -222,12 +222,15 @@ static int cf_check apply_microcode(const struct microcode_patch *patch)uint32_t rev, old_rev = sig->rev;enum microcode_match_result result =microcode_fits (patch); +if ( result ==MIS_UCODE ) +return -EINVAL ; +/* * Allow application of the same revision to pick up SMT-specific changes * even if the revision of the other SMT thread is already up-to-date. */ -if ( result !=NEW_UCODE && result !=SAME_UCODE ) -return -EINVAL ; +if ( result ==OLD_UCODE ) +return -EEXIST ;if (check_final_patch_levels (sig) ) {
xen/arch/x86/cpu/microcode/core.c +2 -0
@@ -881,6 +881,8 @@ int __init early_microcode_init(unsigned long *module_map, ucode_ops.collect_cpu_info (); +printk (XENLOG_INFO "Boot microcode revision: 0x%08x\n" ,this_cpu (cpu_sig).rev); +/* * Some hypervisors deliberately report a microcode revision of -1 to * mean that they will not accept microcode updates.
xen/arch/x86/cpu/microcode/intel.c +5 -2
@@ -294,10 +294,13 @@ static int cf_check apply_microcode(const struct microcode_patch *patch) result =microcode_update_match (patch); -if ( result !=NEW_UCODE && - !(opt_ucode_allow_same && result ==SAME_UCODE ) ) +if ( result ==MIS_UCODE )return -EINVAL ; +if ( result ==OLD_UCODE || + (result ==SAME_UCODE && !opt_ucode_allow_same) ) +return -EEXIST ; +wbinvd ();wrmsrl (MSR_IA32_UCODE_WRITE , (unsigned long )patch->data);
Signature · 1 line
2.30.2
Quoted 6 lines · Andrew Cooper
When the revision in hardware is newer than anything Xen has to hand, '
microcode_cache' isn't set up. Then,xen-ucodeinitiates the update because it doesn't know whether the revisions across the system are symmetric or not. This involves the patch getting all the way into theapply_microcode()hooks before being found to be too old.
Quoted 6 lines
This is all a giant mess and needs an overhaul, but in the short term simply adjust the
apply_microcode()to return-EEXIST.Also, unconditionally print the preexisting microcode revision on boot. It's relevant information which is otherwise unavailable if Xen doesn't find new microcode to use.
Since you do this for the BSP only, I'm okay with that. Doing this for all CPUs would have added too much verbosity imo, and I would then have asked to log the pre-existing revision only when no update would be done by us.
Quoted 2 lines
Fixes 648db37a155a ("x86/ucode: Distinguish "ucode already up to date"")Signed-off-by Andrew Cooper <[email protected]>
with one small request related to the remark above:
xen/arch/x86/cpu/microcode/core.c int __init early_microcode_init(unsigned long *module_map, · line 884
Quoted 7 lines
xen/arch/x86/cpu/microcode/core.c +1
-0@@ -881,6 +881,8 @@ int __init early_microcode_init(unsigned long *module_map, ucode_ops.collect_cpu_info (); +printk (XENLOG_INFO "Boot microcode revision: 0x%08x\n" ,this_cpu (cpu_sig).rev);
Can this please be "BSP" or "Boot CPU" instead of just "Boot", to clarify which CPU's information this is? I'm pretty sure you too have hit systems where firmware doesn't update all cores.
Jan
Quoted 13 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
When the revision in hardware is newer than anything Xen has to hand, '
microcode_cache' isn't set up. Then,xen-ucodeinitiates the update because it doesn't know whether the revisions across the system are symmetric or not. This involves the patch getting all the way into theapply_microcode()hooks before being found to be too old.Quoted 6 lines
This is all a giant mess and needs an overhaul, but in the short term simply adjust the
apply_microcode()to return-EEXIST.Also, unconditionally print the preexisting microcode revision on boot. It's relevant information which is otherwise unavailable if Xen doesn't find new microcode to use.
Quoted 7 lines
Since you do this for the BSP only, I'm okay with that. Doing this for all CPUs would have added too much verbosity imo, and I would then have asked to log the pre-existing revision only when no update would be done by us.
Quoted 2 lines
Fixes 648db37a155a ("x86/ucode: Distinguish "ucode already up to date"")Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Jan Beulich <[email protected]>
Thanks.
Quoted 6 lines
with one small request related to the remark above:
Quoted 4 lines
xen/arch/x86/cpu/microcode/core.c +0
-0@@ -881,6 +881,8 @@ int __init early_microcode_init(unsigned long *module_map,
Quoted 6 lines
xen/arch/x86/cpu/microcode/core.c int __init early_microcode_init(unsigned long *module_map, · line 884
Quoted 3 lines
xen/arch/x86/cpu/microcode/core.c +1
-0ucode_ops.collect_cpu_info (); +printk (XENLOG_INFO "Boot microcode revision: 0x%08x\n" ,this_cpu (cpu_sig).rev);Can this please be "BSP" or "Boot CPU" instead of just "Boot", to clarify which CPU's information this is? I'm pretty sure you too have hit systems where firmware doesn't update all cores.
I'll switch to BSP.
I have further plans (4.20 at this point) to reduce logspam.
* The AP boot path should warn if it finds a revision which isn't the bsp_orig version, cached version, or thread-0 revision. Most of what is printed right now is expected and normal in the system.
* Late load should print once, not once per CPU.
~Andrew
Quoted 42 lines · Andrew Cooper
When the revision in hardware is newer than anything Xen has to hand, '
microcode_cache' isn't set up. Then,xen-ucodeinitiates the update because it doesn't know whether the revisions across the system are symmetric or not. This involves the patch getting all the way into theapply_microcode()hooks before being found to be too old.This is all a giant mess and needs an overhaul, but in the short term simply adjust the
apply_microcode()to return-EEXIST.Also, unconditionally print the preexisting microcode revision on boot. It's relevant information which is otherwise unavailable if Xen doesn't find new microcode to use.
Fixes 648db37a155a ("x86/ucode: Distinguish "ucode already up to date"")Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Fouad Hilly <[email protected]>Sorry Fouad, but this collides with your
--forceseries once again. Hopefully it might make things fractionally easier.Background: For 06-55-04 (Skylake server, stepping 4 specifically), there's a recent production firmware update which has a newer microcode revision than exists in the Intel public microcode repository. It's causing a mess in our automated testing, although it is finding good bugs...
--- xen/arch/x86/cpu/microcode/amd.c | 7 +++++-- xen/arch/x86/cpu/microcode/core.c | 2 ++ xen/arch/x86/cpu/microcode/intel.c | 7 +++++-- 3 files changed, 12 insertions(+), 4 deletions(-)xen/arch/x86/cpu/microcode/amd.c +1
-0@@ -222,12 +222,15 @@ static int cf_check apply_microcode(const struct microcode_patch *patch)uint32_t rev, old_rev = sig->rev;enum microcode_match_result result =microcode_fits (patch); +if ( result ==MIS_UCODE )
xen/arch/x86/cpu/microcode/amd.c static int cf_check apply_microcode(const struct microcode_patch *patch) · line 233
Quoted 10 lines
xen/arch/x86/cpu/microcode/amd.c +4
-2+return -EINVAL ; +/* * Allow application of the same revision to pick up SMT-specific changes * even if the revision of the other SMT thread is already up-to-date. */ -if ( result !=NEW_UCODE && result !=SAME_UCODE ) -return -EINVAL ; +if ( result ==OLD_UCODE ) +return -EEXIST ;
Won't it be simpler to just add this check ahead of the existing one, so that you can leave the code as-is, iow:
if ( result == OLD_UCODE )
return -EEXIST;
/*
* Allow application of the same revision to pick up SMT-specific changes
* even if the revision of the other SMT thread is already up-to-date.
*/
if ( result != NEW_UCODE && result != SAME_UCODE )
return -EINVAL;Thanks, Roger.
Quoted 66 lines · Roger Pau Monné
Quoted 42 lines · Andrew Cooper
When the revision in hardware is newer than anything Xen has to hand, '
microcode_cache' isn't set up. Then,xen-ucodeinitiates the update because it doesn't know whether the revisions across the system are symmetric or not. This involves the patch getting all the way into theapply_microcode()hooks before being found to be too old.This is all a giant mess and needs an overhaul, but in the short term simply adjust the
apply_microcode()to return-EEXIST.Also, unconditionally print the preexisting microcode revision on boot. It's relevant information which is otherwise unavailable if Xen doesn't find new microcode to use.
Fixes 648db37a155a ("x86/ucode: Distinguish "ucode already up to date"")Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Fouad Hilly <[email protected]>Sorry Fouad, but this collides with your
--forceseries once again. Hopefully it might make things fractionally easier.Background: For 06-55-04 (Skylake server, stepping 4 specifically), there's a recent production firmware update which has a newer microcode revision than exists in the Intel public microcode repository. It's causing a mess in our automated testing, although it is finding good bugs...
--- xen/arch/x86/cpu/microcode/amd.c | 7 +++++-- xen/arch/x86/cpu/microcode/core.c | 2 ++ xen/arch/x86/cpu/microcode/intel.c | 7 +++++-- 3 files changed, 12 insertions(+), 4 deletions(-)xen/arch/x86/cpu/microcode/amd.c +1
-0@@ -222,12 +222,15 @@ static int cf_check apply_microcode(const struct microcode_patch *patch)uint32_t rev, old_rev = sig->rev;enum microcode_match_result result =microcode_fits (patch); +if ( result ==MIS_UCODE )xen/arch/x86/cpu/microcode/amd.c static int cf_check apply_microcode(const struct microcode_patch *patch) · line 233
Quoted 10 lines
xen/arch/x86/cpu/microcode/amd.c +4
-2+return -EINVAL ; +/* * Allow application of the same revision to pick up SMT-specific changes * even if the revision of the other SMT thread is already up-to-date. */ -if ( result !=NEW_UCODE && result !=SAME_UCODE ) -return -EINVAL ; +if ( result ==OLD_UCODE ) +return -EEXIST ;Won't it be simpler to just add this check ahead of the existing one, so that you can leave the code as-is, iow:
if ( result == OLD_UCODE ) return -EEXIST; /* * Allow application of the same revision to pick up SMT-specific changes * even if the revision of the other SMT thread is already up-to-date. */ if ( result != NEW_UCODE && result != SAME_UCODE ) return -EINVAL;
Quoted 1 line
Thanks, Roger.
Not really, no. That still leaves this piece of logic which is misleading IMO.
MIS_UCODE is the only -EINVAL worthy case.
Every other *_UCODE constant needs to be 0 or -EEXIST, depending on allow-same/--force.
~Andrew
Roger Pau Monné
Acked-byQuoted 69 lines · Andrew Cooper
Quoted 66 lines · Roger Pau Monné
Quoted 42 lines · Andrew Cooper
When the revision in hardware is newer than anything Xen has to hand, '
microcode_cache' isn't set up. Then,xen-ucodeinitiates the update because it doesn't know whether the revisions across the system are symmetric or not. This involves the patch getting all the way into theapply_microcode()hooks before being found to be too old.This is all a giant mess and needs an overhaul, but in the short term simply adjust the
apply_microcode()to return-EEXIST.Also, unconditionally print the preexisting microcode revision on boot. It's relevant information which is otherwise unavailable if Xen doesn't find new microcode to use.
Fixes 648db37a155a ("x86/ucode: Distinguish "ucode already up to date"")Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Fouad Hilly <[email protected]>Sorry Fouad, but this collides with your
--forceseries once again. Hopefully it might make things fractionally easier.Background: For 06-55-04 (Skylake server, stepping 4 specifically), there's a recent production firmware update which has a newer microcode revision than exists in the Intel public microcode repository. It's causing a mess in our automated testing, although it is finding good bugs...
--- xen/arch/x86/cpu/microcode/amd.c | 7 +++++-- xen/arch/x86/cpu/microcode/core.c | 2 ++ xen/arch/x86/cpu/microcode/intel.c | 7 +++++-- 3 files changed, 12 insertions(+), 4 deletions(-)xen/arch/x86/cpu/microcode/amd.c +1
-0@@ -222,12 +222,15 @@ static int cf_check apply_microcode(const struct microcode_patch *patch)uint32_t rev, old_rev = sig->rev;enum microcode_match_result result =microcode_fits (patch); +if ( result ==MIS_UCODE )xen/arch/x86/cpu/microcode/amd.c static int cf_check apply_microcode(const struct microcode_patch *patch) · line 233
Quoted 10 lines
xen/arch/x86/cpu/microcode/amd.c +4
-2+return -EINVAL ; +/* * Allow application of the same revision to pick up SMT-specific changes * even if the revision of the other SMT thread is already up-to-date. */ -if ( result !=NEW_UCODE && result !=SAME_UCODE ) -return -EINVAL ; +if ( result ==OLD_UCODE ) +return -EEXIST ;Won't it be simpler to just add this check ahead of the existing one, so that you can leave the code as-is, iow:
if ( result == OLD_UCODE ) return -EEXIST; /* * Allow application of the same revision to pick up SMT-specific changes * even if the revision of the other SMT thread is already up-to-date. */ if ( result != NEW_UCODE && result != SAME_UCODE ) return -EINVAL;Quoted 1 line
Thanks, Roger.
Quoted 7 lines
Not really, no. That still leaves this piece of logic which is misleading IMO.
MIS_UCODEis the only-EINVALworthy case.Every other
*_UCODEconstant needs to be 0 or-EEXIST, depending on allow-same/--force.
OK, my main concern was the previous logic wouldn't allow a newly introduced state to get past the return -EINVAL, while the new logic could possibly allow it to pass through.
I don't think adding states is that common, and if you prefer it that way it's fine.
Thanks, Roger.