x86/microcode: refuse to load the same revision ucode
PATCH v2 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 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.
---
v1 --> v2:
- compare provided ucode with the currently cached one
--- xen/arch/x86/microcode.c | 12 ++++++++++-- xen/arch/x86/microcode_amd.c | 14 ++++++++++---- xen/arch/x86/microcode_intel.c | 12 +++++++++--- xen/include/asm-x86/microcode.h | 3 ++- 4 files changed, 31 insertions(+), 10 deletions(-)
xen/arch/x86/microcode.c +10 -2
@@ -266,10 +266,16 @@ static const struct microcode_patch *nmi_patch = ZERO_BLOCK_PTR;*/ static struct microcode_patch *parse_blob (const char *buf,size_t len) { +struct microcode_patch *ret =NULL ; +if (likely (!microcode_ops->collect_cpu_info (&this_cpu (cpu_sig))) ) -return microcode_ops->cpu_request_microcode (buf, len); + { +spin_lock (µcode_mutex); + ret = microcode_ops->cpu_request_microcode (buf, len, microcode_cache); +spin_unlock (µcode_mutex); + } -return NULL ; +return ret; }void microcode_free_patch (struct microcode_patch *microcode_patch)
@@ -641,6 +647,8 @@ int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long len)if ( !patch ) { ret = -ENOENT ; +printk (XENLOG_WARNING "microcode: couldn't find any newer revision in " +"the provided blob!\n" ); goto put; }
xen/arch/x86/microcode_amd.c +10 -4
@@ -419,10 +419,11 @@ static bool_t check_final_patch_levels(unsigned int cpu) }static struct microcode_patch *cpu_request_microcode (const void *buf, -size_t bufsize) +size_t bufsize, +const struct microcode_patch *cache) {struct microcode_amd *mc_amd; -struct microcode_header_amd *saved =NULL ; +struct microcode_header_amd *saved =NULL , *cached =NULL ;struct microcode_patch *patch =NULL ;size_t offset =0 , saved_size =0 ;int error =0 ;
@@ -507,6 +508,9 @@ static struct microcode_patch *cpu_request_microcode(const void *buf, goto out; } +if ( cache && cache->mc_amd && cache->mc_amd->mpb ) + cached = cache->mc_amd->mpb; +/* * It's possible the data file has multiple matching ucode, * lets keep searching till the latest version
@@ -516,9 +520,11 @@ static struct microcode_patch *cpu_request_microcode(const void *buf, {/* * If the new ucode covers current CPU, compare ucodes and store the -* one with higher revision. +* one with higher revision. It must also be higher than currently +* cached revision. */ if ( (microcode_fits (mc_amd) !=MIS_UCODE ) && + (!cached || (compare_header (mc_amd->mpb, cached) ==NEW_UCODE )) && (!saved || (compare_header (mc_amd->mpb, saved) ==NEW_UCODE )) ) {xfree (saved);
@@ -576,7 +582,7 @@ static struct microcode_patch *cpu_request_microcode(const void *buf,free_patch (mc_amd); out: -if ( error && !patch ) +if ( error && error != -ENODATA && !patch ) patch =ERR_PTR (error);return patch;
xen/arch/x86/microcode_intel.c +9 -3
@@ -357,13 +357,17 @@ static long get_next_ucode_from_buffer(struct microcode_intel **mc, }static struct microcode_patch *cpu_request_microcode (const void *buf, -size_t size) +size_t size, +const struct microcode_patch *cache) {long offset =0 ;int error =0 ; -struct microcode_intel *mc, *saved =NULL ; +struct microcode_intel *mc, *saved =NULL , *cached =NULL ;struct microcode_patch *patch =NULL ; +if ( cache && cache->mc_intel ) + cached = cache->mc_intel; +while ( (offset =get_next_ucode_from_buffer (&mc, buf, size, offset)) >0 ) { error =microcode_sanity_check (mc);
@@ -375,9 +379,11 @@ static struct microcode_patch *cpu_request_microcode(const void *buf,/* * If the new update covers current CPU, compare updates and store the -* one with higher revision. +* one with higher revision. It must also be higher than currently +* cached revision. */ if ( (microcode_update_match (&mc->hdr) !=MIS_UCODE ) && + (!cached || (mc->hdr.rev > cached->hdr.rev)) && (!saved || (mc->hdr.rev > saved->hdr.rev)) ) {xfree (saved);
xen/include/asm-x86/microcode.h +2 -1
@@ -21,7 +21,8 @@ struct microcode_patch {struct microcode_ops {struct microcode_patch *(*cpu_request_microcode)(const void *buf, -size_t size); +size_t size, +const struct microcode_patch *cache);int (*collect_cpu_info)(struct cpu_signature *csig);int (*apply_microcode)(const struct microcode_patch *patch);int (*start_update)(void );
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
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_cacheexists, all CPUs in the system should have at least that ucode revision.Additionally, print a user friendly message if no newer ucode can be found in the provided blob. This also requires ignoring
-ENODATAin 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.
Signed-off-by Sergey Dyasli <[email protected]>
I wonder whether it is better to put the comparison ...
Quoted 40 lines
---
v1 --> v2:
- compare provided ucode with the currently cached oneCC 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 | 12 ++++++++++-- xen/arch/x86/microcode_amd.c | 14 ++++++++++---- xen/arch/x86/microcode_intel.c | 12 +++++++++--- xen/include/asm-x86/microcode.h | 3 ++- 4 files changed, 31 insertions(+), 10 deletions(-)xen/arch/x86/microcode.c +8
-2@@ -266,10 +266,16 @@ static const struct microcode_patch *nmi_patch = ZERO_BLOCK_PTR;*/ static struct microcode_patch *parse_blob (const char *buf,size_t len) { +struct microcode_patch *ret =NULL ; +if (likely (!microcode_ops->collect_cpu_info (&this_cpu (cpu_sig))) ) -return microcode_ops->cpu_request_microcode (buf, len); + { +spin_lock (µcode_mutex); + ret = microcode_ops->cpu_request_microcode (buf, len, microcode_cache); +spin_unlock (µcode_mutex); + } -return NULL ; +return ret; }void microcode_free_patch (struct microcode_patch *microcode_patch)
xen/arch/x86/microcode.c int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long len) · line 653
Quoted 7 lines
xen/arch/x86/microcode.c +2
-0@@ -641,6 +647,8 @@ int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long len)if ( !patch ) { ret = -ENOENT ; +printk (XENLOG_WARNING "microcode: couldn't find any newer revision in " +"the provided blob!\n" ); goto put; }
... after this if(). Then you needn't modify any vendor-specific code.
Thanks
Chao
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 27 lines · Chao Gao
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_cacheexists, all CPUs in the system should have at least that ucode revision.Additionally, print a user friendly message if no newer ucode can be found in the provided blob. This also requires ignoring
-ENODATAin 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.
Signed-off-by Sergey Dyasli <[email protected]>Reviewed-by Chao Gao <[email protected]>I wonder whether it is better to put the comparison ...
Quoted 10 lines
xen/arch/x86/microcode.c int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long len) · line 653
Quoted 8 lines
xen/arch/x86/microcode.c +2
-0@@ -641,6 +647,8 @@ int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long len)if ( !patch ) { ret = -ENOENT ; +printk (XENLOG_WARNING "microcode: couldn't find any newer revision in " +"the provided blob!\n" ); goto put; }... after this
if(). Then you needn't modify any vendor-specific code.
Yeah, this would seem to allow reducing code churn by quite a bit.
Also I think the AMD side -ENODATA ignoring would better go into this
if ( error )
{
xfree(mc_amd->equiv_cpu_table);
xfree(mc_amd);
goto out;
}block in cpu_request_microcode(), thus allowing potential future unrelated -EONDATA to not also get ignored.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel