x86/xen-ucode: Introduce --force option
v4 cover x86/xen-ucode: Introduce --force option
Refactor and introduce --force option to xen-ucode, which skips microcode version check when updating x86 CPU micocode. A new hypercall introduced with flags field to facilitate the new option and allow for future flags
as needed.
This change is required to enable developers to load ucode that is the same version as the one already loaded or downgrade for testing.
Fouad Hilly (4):
x86/ucode: Introduce PF_microcode_update2 with flags parameter x86/ucode: refactor xen-ucode to utilize getopt x86/ucode: Introduce --force option to xen-ucode to force skipping
microcode version check
x86/ucode: Utilize ucode_force and remove opt_ucode_allow_same
docs/misc/xen-command-line.pandoc | 7 +--- tools/include/xenctrl.h | 3 +- tools/libs/ctrl/xc_misc.c | 12 +++--- tools/misc/xen-ucode.c | 61 ++++++++++++++++++++++------ xen/arch/x86/cpu/microcode/amd.c | 7 ---- xen/arch/x86/cpu/microcode/core.c | 20 +++++---- xen/arch/x86/cpu/microcode/intel.c | 4 -- xen/arch/x86/cpu/microcode/private.h | 2 - xen/arch/x86/include/asm/microcode.h | 3 +- xen/arch/x86/platform_hypercall.c | 13 +++++- xen/include/public/platform.h | 14 +++++++ 11 files changed, 97 insertions(+), 49 deletions(-)
Signature · 1 line
2.42.0
PATCH v4 1/4 x86/ucode: Introduce PF_microcode_update2 with flags parameter
Refactor microcode_update() by adding flags field. struct xenpf_microcode_update2 added with uint32_t flags field. Introduce XENPF_microcode_update2 hypercall with flags field.
---
[v4]
1- Commit message and description updated.
2- Changing the order of the patches.
[v3]
1- Updated Commit message description.
2- Revereted changes to a stable ABI and introduced a new struct. 3- ucode_force_flag updated from static to a local variable. 4- microcode_update() updated to reject unsupported flags yet.
[v2]
1- Update message description to highlight interface change.
2- Removed extra empty lines.
3- removed unnecessary define.
4- Corrected long lines.
5- Removed ternary operator.
6- Introduced static ucode_update_flags, which will be used later to determine local ucode_force_flag.
--- xen/arch/x86/cpu/microcode/core.c | 11 ++++++++--- xen/arch/x86/include/asm/microcode.h | 3 ++- xen/arch/x86/platform_hypercall.c | 13 ++++++++++++- xen/include/public/platform.h | 14 ++++++++++++++ 4 files changed, 36 insertions(+), 5 deletions(-)
xen/arch/x86/cpu/microcode/core.c +8 -3
@@ -40,6 +40,8 @@#include <asm/processor.h> #include <asm/setup.h> +#include <public/platform.h> +#include "private.h" /*
@@ -570,6 +572,7 @@ static int cf_check do_microcode_update(void *patch) }struct ucode_buf { +unsigned int flags;unsigned int len;char buffer[]; };
@@ -708,13 +711,14 @@ static long cf_check microcode_update_helper(void *data)return ret; } -int microcode_update (XEN_GUEST_HANDLE (const_void) buf,unsigned long len) +int microcode_update (XEN_GUEST_HANDLE (const_void) buf, +unsigned long len,unsigned int flags) {int ret;struct ucode_buf *buffer; -if ( len != (uint32_t )len ) -return -E2BIG ; +if ( flags & ~XENPF_UCODE_FORCE ) +return -EINVAL ;if ( !ucode_ops.apply_microcode )return -EINVAL ;
@@ -730,6 +734,7 @@ int microcode_update(XEN_GUEST_HANDLE(const_void) buf, unsigned long len)return -EFAULT ; } buffer->len = len; + buffer->flags = flags;/* * Always queue microcode_update_helper() on CPU0. Most of the logic
xen/arch/x86/include/asm/microcode.h +2 -1
@@ -22,7 +22,8 @@ struct cpu_signature { DECLARE_PER_CPU(struct cpu_signature, cpu_sig);void microcode_set_module (unsigned int idx); -int microcode_update (XEN_GUEST_HANDLE (const_void) buf,unsigned long len); +int microcode_update (XEN_GUEST_HANDLE (const_void) buf, +unsigned long len,unsigned int flags);int early_microcode_init (unsigned long *module_map,const struct multiboot_info *mbi); int microcode_init_cache(unsigned long *module_map,
xen/arch/x86/platform_hypercall.c +12 -1
@@ -311,7 +311,18 @@ ret_t do_platform_op(guest_from_compat_handle (data, op->u.microcode.data); - ret =microcode_update (data, op->u.microcode.length); + ret =microcode_update (data, op->u.microcode.length,0 ); +break ; + } + +case XENPF_microcode_update2: + { +XEN_GUEST_HANDLE (const_void) data; + +guest_from_compat_handle (data, op->u.microcode2.data); + + ret =microcode_update (data, op->u.microcode2.length, + op->u.microcode2.flags);break ; }
xen/include/public/platform.h +14 -0
@@ -624,6 +624,19 @@ struct xenpf_ucode_revision {typedef struct xenpf_ucode_revision xenpf_ucode_revision_t ;DEFINE_XEN_GUEST_HANDLE (xenpf_ucode_revision_t); +/* Hypercall to microcode_update with flags */ +#define XENPF_microcode_update2 66 +struct xenpf_microcode_update2 { +/* IN variables. */ +uint32_t flags;/* Flags to be passed with ucode. */ +/* Force to skip microcode version check */ +#define XENPF_UCODE_FORCE 1 +uint32_t length;/* Length of microcode data. */ +XEN_GUEST_HANDLE (const_void) data;/* Pointer to microcode data */ +}; +typedef struct xenpf_microcode_update2 xenpf_microcode_update2_t ; +DEFINE_XEN_GUEST_HANDLE (xenpf_microcode_update2_t); +/* * ` enum neg_errnoval * ` HYPERVISOR_platform_op(const struct xen_platform_op*);
@@ -656,6 +669,7 @@ struct xen_platform_op {xenpf_symdata_t symdata;xenpf_dom0_console_t dom0_console;xenpf_ucode_revision_t ucode_revision; +xenpf_microcode_update2_t microcode2;uint8_t pad[128 ]; } u; };
Signature · 1 line
2.42.0
Re: [PATCH v4 1/4] x86/ucode: Introduce PF_microcode_update2 with flags parameter
Quoted 5 lines · Fouad Hilly
Refactor
microcode_update()by adding flags field. structxenpf_microcode_update2added withuint32_tflags field. IntroduceXENPF_microcode_update2hypercall with flags field.Signed-off-by Fouad Hilly <[email protected]>
PF_ in the subject wants expanding to the full name, i.e. XENPF_microcode_update2. Can be fixed on commit.
PATCH v4 2/4 x86/ucode: refactor xen-ucode to utilize getopt
In reply to Fouad HillyUse getopt_long() to handle command line arguments.
Introduce ext_err for common exit with errors.xc_microcode_update() refactored to accept flags and utilize xenpf_microcode_update2 Introducing usage() to handle usage\help messages in a common block. show_curr_cpu is printed to stdout only.
---
[v4]
1- Merge three patches into one.
2- usage() to print messages to the correct stream. 3- Update commit message and description.
--- tools/misc/xen-ucode.c | 51 ++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 12 deletions(-)
tools/misc/xen-ucode.c +39 -12
@@ -11,12 +11,23 @@#include <sys/stat.h> #include <fcntl.h> #include <xenctrl.h> +#include <getopt.h> static xc_interface *xch;static const char intel_id[] ="GenuineIntel" ;static const char amd_id[] ="AuthenticAMD" ; +static void usage (FILE *stream,const char *name) +{ +fprintf (stream,"%s: Xen microcode updating tool\n" +"Usage: %s [microcode file] [options]\n" +"options:\n" +" -h, --help display this help and exit\n" +" -s, --show-cpu-info show CPU information and exit\n" , + name, name); +} +static void show_curr_cpu (FILE *f) {int ret;
@@ -77,6 +88,13 @@ int main(int argc, char *argv[])char *filename, *buf;size_t len;struct stat st; +int opt; + +static const struct option options[] = { + {"help" , no_argument,NULL ,'h' }, + {"show-cpu-info" , no_argument,NULL ,'s' }, + {NULL , no_argument,NULL ,0 } + }; xch =xc_interface_open (NULL ,NULL ,0 );if ( xch ==NULL )
@@ -86,22 +104,25 @@ int main(int argc, char *argv[])exit (1 ); } -if ( argc <2 ) +while ( (opt =getopt_long (argc, argv,"hs" , options,NULL )) !=-1 ) { -fprintf (stderr, -"xen-ucode: Xen microcode updating tool\n" -"Usage: %s [<microcode file> | show-cpu-info]\n" , argv[0 ]); -show_curr_cpu (stderr); -exit (2 ); +switch (opt) + { +case 'h' : +usage (stdout, argv[0 ]); +exit (EXIT_SUCCESS ); +case 's' : +show_curr_cpu (stdout); +exit (EXIT_SUCCESS ); +default : + goto ext_err; + } } -if ( !strcmp (argv[1 ],"show-cpu-info" ) ) - { -show_curr_cpu (stdout); -return 0 ; - } +if ( optind == argc ) + goto ext_err; - filename = argv[1 ]; + filename = argv[optind]; fd =open (filename,O_RDONLY );if ( fd <0 ) {
@@ -146,4 +167,10 @@ int main(int argc, char *argv[])close (fd);return 0 ; + + ext_err: +fprintf (stderr, +"%s: unable to process command line arguments\n" , argv[0 ]); +usage (stderr, argv[0 ]); +exit (EXIT_FAILURE ); }
Signature · 1 line
2.42.0
Re: [PATCH v4 2/4] x86/ucode: refactor xen-ucode to utilize getopt
Quoted 3 lines · Fouad Hilly
Use
getopt_long()to handle command line arguments.
Introduceext_errfor common exit with errors.xc_microcode_update()refactored to accept flags and utilizexenpf_microcode_update2
Importantly, not. That's deferred until the next patch.
Quoted 22 lines
Introducing
usage()to handle usage\help messages in a common block.show_curr_cpuis printed to stdout only.Signed-off-by Fouad Hilly <[email protected]>---
[v4]
1- Merge three patches into one.
2-usage()to print messages to the correct stream. 3- Update commit message and description.--- tools/misc/xen-ucode.c | 51 ++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 12 deletions(-)tools/misc/xen-ucode.c +1
-0@@ -11,12 +11,23 @@#include <sys/stat.h> #include <fcntl.h> #include <xenctrl.h> +#include <getopt.h>
tools/misc/xen-ucode.c line 24
Quoted 10 lines
tools/misc/xen-ucode.c +4
-0static xc_interface *xch;static const char intel_id[] ="GenuineIntel" ;static const char amd_id[] ="AuthenticAMD" ; +static void usage (FILE *stream,const char *name) +{ +fprintf (stream,"%s: Xen microcode updating tool\n" + "Usage: %s [microcode file] [options]\n"
Options are typically expressed first when writing this.
tools/misc/xen-ucode.c line 27
Quoted 3 lines
tools/misc/xen-ucode.c +3
-0+"options:\n" +" -h, --help display this help and exit\n" + " -s, --show-cpu-info show CPU information and exit\n",
The "and exit" is pointless to state like this.
tools/misc/xen-ucode.c line 28
Quoted 1 line
tools/misc/xen-ucode.c +1
-0+ name, name);
Alignment is out by one column here.
Also, previously, usage() was always followed by show_curr_cpu(). That's still easy to retain by reordering the two static functions.
Quoted 6 lines
tools/misc/xen-ucode.c +2
-0+} +static void show_curr_cpu (FILE *f) {int ret;
tools/misc/xen-ucode.c int main(int argc, char *argv[]) · line 97
Quoted 10 lines
tools/misc/xen-ucode.c +7
-0@@ -77,6 +88,13 @@ int main(int argc, char *argv[])char *filename, *buf;size_t len;struct stat st; +int opt; + +static const struct option options[] = { + {"help" , no_argument,NULL ,'h' }, + {"show-cpu-info" , no_argument,NULL ,'s' }, + {NULL , no_argument,NULL ,0 } + };
Typically we prefer static variables before automatic variables. This block can just be repositioned.
Quoted 10 lines
tools/misc/xen-ucode.c +1
-1xch =xc_interface_open (NULL ,NULL ,0 );if ( xch ==NULL )@@ -86,22 +104,25 @@ int main(int argc, char *argv[])exit (1 ); } -if ( argc <2 ) +while ( (opt =getopt_long (argc, argv,"hs" , options,NULL )) !=-1 ) {
tools/misc/xen-ucode.c int main(int argc, char *argv[]) · line 113
Quoted 10 lines
tools/misc/xen-ucode.c +5
-5-fprintf (stderr, -"xen-ucode: Xen microcode updating tool\n" -"Usage: %s [<microcode file> | show-cpu-info]\n" , argv[0 ]); -show_curr_cpu (stderr); -exit (2 ); +switch (opt) + { +case 'h' : +usage (stdout, argv[0 ]); +exit (EXIT_SUCCESS );
Blank line here, ...
tools/misc/xen-ucode.c int main(int argc, char *argv[]) · line 116
Quoted 3 lines
tools/misc/xen-ucode.c +3
-0+case 's' : +show_curr_cpu (stdout); +exit (EXIT_SUCCESS );
... and here.
tools/misc/xen-ucode.c int main(int argc, char *argv[]) · line 123
Quoted 12 lines
tools/misc/xen-ucode.c +5
-5+default : + goto ext_err; + } } -if ( !strcmp (argv[1 ],"show-cpu-info" ) ) - { -show_curr_cpu (stdout); -return 0 ; - } +if ( optind == argc ) + goto ext_err;
This is a change in API, because now "show-cpu-info" needs to take a -- to be interpreted.
I suspect we want:
if ( optind == argc )
goto ext_err;
/* For backwards compatibility to the pre-getopt() cmdline handling */ if ( !strcmp(argv[optind], "show-cpu-info") )
{
show_curr_cpu(stdout);
return 0;
}
to retain compatibility. (Also, this means you won't have the code rejected by XenRT when this gets added to Xen.)
All of this I can fix on commit, but there's quite a lot in the way of changes.
~Andrew
PATCH v4 3/4 x86/ucode: Introduce --force option to xen-ucode to force skipping microcode version check
In reply to Fouad HillyIntroduce --force option to xen-ucode to force skipping microcode version check, which allows the user to update x86 microcode even if both versions are the same or downgrade. xc_microcode_update() refactored to accept flags and utilize xenpf_microcode_update2.
---
[4]
1- Add --force to xen-ucode options.
2- Update xc_microcode_update() to accept and handle flags.
--- tools/include/xenctrl.h | 3 ++- tools/libs/ctrl/xc_misc.c | 12 +++++++----- tools/misc/xen-ucode.c | 14 +++++++++++--- 3 files changed, 20 insertions(+), 9 deletions(-)
tools/include/xenctrl.h +2 -1
@@ -1171,7 +1171,8 @@ typedef uint32_t xc_node_to_node_dist_t;int xc_physinfo (xc_interface *xch,xc_physinfo_t *info);int xc_cputopoinfo (xc_interface *xch,unsigned *max_cpus,xc_cputopo_t *cputopo); -int xc_microcode_update (xc_interface *xch,const void *buf,size_t len); +int xc_microcode_update (xc_interface *xch,const void *buf, +size_t len,unsigned int flags);int xc_get_cpu_version (xc_interface *xch,struct xenpf_pcpu_version *cpu_ver);int xc_get_ucode_revision (xc_interface *xch,struct xenpf_ucode_revision *ucode_rev);
tools/libs/ctrl/xc_misc.c +7 -5
@@ -203,11 +203,12 @@ int xc_physinfo(xc_interface *xch,return 0 ; } -int xc_microcode_update (xc_interface *xch,const void *buf,size_t len) +int xc_microcode_update (xc_interface *xch,const void *buf, +size_t len,unsigned int flags) {int ret;struct xen_platform_op platform_op = {}; - DECLARE_HYPERCALL_BUFFER(struct xenpf_microcode_update, uc); + DECLARE_HYPERCALL_BUFFER(struct xenpf_microcode_update2, uc); uc =xc_hypercall_buffer_alloc (xch, uc, len);if ( uc ==NULL )
@@ -215,9 +216,10 @@ int xc_microcode_update(xc_interface *xch, const void *buf, size_t len)memcpy (uc, buf, len); - platform_op.cmd = XENPF_microcode_update; - platform_op.u.microcode.length = len; -set_xen_guest_handle (platform_op.u.microcode.data, uc); + platform_op.cmd = XENPF_microcode_update2; + platform_op.u.microcode2.length = len; + platform_op.u.microcode2.flags = flags; +set_xen_guest_handle (platform_op.u.microcode2.data, uc); ret =do_platform_op (xch, &platform_op);
tools/misc/xen-ucode.c +11 -3
@@ -13,6 +13,8 @@#include <xenctrl.h> #include <getopt.h> +#include <xen/platform.h> +static xc_interface *xch;static const char intel_id[] ="GenuineIntel" ;
@@ -24,7 +26,8 @@ static void usage(FILE *stream, const char *name)"Usage: %s [microcode file] [options]\n" "options:\n" " -h, --help display this help and exit\n" -" -s, --show-cpu-info show CPU information and exit\n" , +" -s, --show-cpu-info show CPU information and exit\n" +" -f, --force force to skip microcode version check\n" , name, name); }
@@ -89,10 +92,12 @@ int main(int argc, char *argv[])size_t len;struct stat st;int opt; +uint32_t ucode_flags =0 ;static const struct option options[] = { {"help" , no_argument,NULL ,'h' }, {"show-cpu-info" , no_argument,NULL ,'s' }, + {"force" , no_argument,NULL ,'f' }, {NULL , no_argument,NULL ,0 } };
@@ -104,7 +109,7 @@ int main(int argc, char *argv[])exit (1 ); } -while ( (opt =getopt_long (argc, argv,"hs" , options,NULL )) !=-1 ) +while ( (opt =getopt_long (argc, argv,"hsf" , options,NULL )) !=-1 ) {switch (opt) {
@@ -114,6 +119,9 @@ int main(int argc, char *argv[])case 's' :show_curr_cpu (stdout);exit (EXIT_SUCCESS ); +case 'f' : + ucode_flags =XENPF_UCODE_FORCE ; +break ;default : goto ext_err; }
@@ -147,7 +155,7 @@ int main(int argc, char *argv[]) } errno =0 ; - ret =xc_microcode_update (xch, buf, len); + ret =xc_microcode_update (xch, buf, len, ucode_flags);if ( ret ==-1 && errno ==EEXIST )printf ("Microcode already up to date\n" );else if ( ret )
Signature · 1 line
2.42.0
Re: [PATCH v4 3/4] x86/ucode: Introduce --force option to xen-ucode to force skipping microcode version check
Quoted 5 lines · Fouad Hilly
Introduce --force option to xen-ucode to force skipping microcode version check, which allows the user to update x86 microcode even if both versions are the same or downgrade.
xc_microcode_update()refactored to accept flags and utilizexenpf_microcode_update2.Signed-off-by Fouad Hilly <[email protected]>
I think it would be better to stop the subject at "... to xen-ucode". The commit message itself covers what has changed.
Quoted 14 lines
tools/misc/xen-ucode.c +2
-0@@ -13,6 +13,8 @@#include <xenctrl.h> #include <getopt.h> +#include <xen/platform.h> +static xc_interface *xch;static const char intel_id[] ="GenuineIntel" ;
tools/misc/xen-ucode.c static void usage(FILE *stream, const char *name) · line 30
Quoted 6 lines
tools/misc/xen-ucode.c +2
-1@@ -24,7 +26,8 @@ static void usage(FILE *stream, const char *name)"Usage: %s [microcode file] [options]\n" "options:\n" " -h, --help display this help and exit\n" - " -s, --show-cpu-info show CPU information and exit\n", +" -s, --show-cpu-info show CPU information and exit\n" + " -f, --force force to skip microcode version check\n",
I'd phrase this as "skip certain checks; do not use unless you know exactly what you are doing"
which makes it very clear that people get to keep all pieces if they try this.
Otherwise (and subject to the style cleanup in the previous patch),
PATCH v4 4/4 x86/ucode: Utilize ucode_force and remove opt_ucode_allow_same
In reply to Fouad HillyPass ucode_force to common micorocde checks and utilize it to allow for microcode downgrade or reapply the same version of the microcode.
Update low level Intel and AMD to check for valid signature only. Any version checks is done at core.c.
While adding ucode_force, opt_ucode_allow_same was removed.
Remove opt_ucode_allow_same from documentation.
---
[4]
1- As opt_ucode_allow_same is not required anymore, it has been removed while introducing ucode_force. 2- Apply the changes for both AMD and Intel.
3- Remove the mention of opt_ucode_allow_same from documentation.
--- docs/misc/xen-command-line.pandoc | 7 +------ xen/arch/x86/cpu/microcode/amd.c | 7 ------- xen/arch/x86/cpu/microcode/core.c | 9 +++------ xen/arch/x86/cpu/microcode/intel.c | 4 ---- xen/arch/x86/cpu/microcode/private.h | 2 -- 5 files changed, 4 insertions(+), 25 deletions(-)
docs/misc/xen-command-line.pandoc +1 -6
@@ -2648,7 +2648,7 @@ performance. Alternatively, selecting `tsx=1` will re-enable TSX at the users own risk. ### ucode -> `= List of [ <integer> | scan=<bool>, nmi=<bool>, allow-same=<bool> ]` +> `= List of [ <integer> | scan=<bool>, nmi=<bool> ]` Applicability: x86 Default: `nmi`
@@ -2680,11 +2680,6 @@ precedence over `scan`. stop_machine context. In NMI handler, even NMIs are blocked, which is considered safer. The default value is `true`. -'allow-same' alters the default acceptance policy for new microcode to permit -trying to reload the same version. Many CPUs will actually reload microcode -of the same version, and this allows for easy testing of the late microcode -loading path. - ### unrestricted_guest (Intel) > `= <boolean>`
xen/arch/x86/cpu/microcode/amd.c +0 -7
@@ -225,13 +225,6 @@ static int cf_check apply_microcode(const struct microcode_patch *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 ==OLD_UCODE ) -return -EEXIST ; -if (check_final_patch_levels (sig) ) { printk(XENLOG_ERR
xen/arch/x86/cpu/microcode/core.c +3 -6
@@ -100,8 +100,6 @@ static bool __initdata ucode_scan;/* By default, ucode loading is done in NMI handler */ static bool ucode_in_nmi = true; -bool __read_mostly opt_ucode_allow_same; -/* Protected by microcode_mutex */ static struct microcode_patch *microcode_cache;
@@ -128,8 +126,6 @@ static int __init cf_check parse_ucode(const char *s)if ( (val =parse_boolean ("nmi" , s, ss)) >=0 ) ucode_in_nmi = val; -else if ( (val =parse_boolean ("allow-same" , s, ss)) >=0 ) - opt_ucode_allow_same = val;else if ( !ucode_mod_forced )/* Not forced by EFI */ {if ( (val =parse_boolean ("scan" , s, ss)) >=0 )
@@ -583,6 +579,7 @@ static long cf_check microcode_update_helper(void *data)struct ucode_buf *buffer = data;unsigned int cpu, updated;struct microcode_patch *patch; +bool ucode_force = buffer->flags ==XENPF_UCODE_FORCE ;/* cpu_online_map must not change during update */ if ( !get_cpu_maps () )
@@ -636,12 +633,12 @@ static long cf_check microcode_update_helper(void *data) microcode_cache);if ( result !=NEW_UCODE && - !(opt_ucode_allow_same && result ==SAME_UCODE ) ) + (!ucode_force || (result & ~SAME_UCODE )) ) {spin_unlock (µcode_mutex);printk (XENLOG_WARNING "microcode: couldn't find any newer%s revision in the provided blob!\n" , - opt_ucode_allow_same ?" (or the same)" :"" ); + ucode_force?" (or a valid)" :"" );microcode_free_patch (patch); ret = -EEXIST ;
xen/arch/x86/cpu/microcode/intel.c +0 -4
@@ -297,10 +297,6 @@ static int cf_check apply_microcode(const struct microcode_patch *patch)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);
xen/arch/x86/cpu/microcode/private.h +0 -2
@@ -3,8 +3,6 @@#include <asm/microcode.h> -extern bool opt_ucode_allow_same; -enum microcode_match_result {OLD_UCODE ,/* signature matched, but revision id is older */ SAME_UCODE ,/* signature matched, but revision id is the same */
Signature · 1 line
2.42.0
Re: [PATCH v4 4/4] x86/ucode: Utilize ucode_force and remove opt_ucode_allow_same
Quoted 51 lines · Fouad Hilly
Pass
ucode_forceto common micorocde checks and utilize it to allow for microcode downgrade or reapply the same version of the microcode.
Update low level Intel and AMD to check for valid signature only. Any version checks is done atcore.c.
While addingucode_force,opt_ucode_allow_samewas removed.
Removeopt_ucode_allow_samefrom documentation.Signed-off-by Fouad Hilly <[email protected]>---
[4]
1- Asopt_ucode_allow_sameis not required anymore, it has been removed while introducingucode_force. 2- Apply the changes for both AMD and Intel.
3- Remove the mention ofopt_ucode_allow_samefrom documentation.--- docs/misc/xen-command-line.pandoc | 7 +------ xen/arch/x86/cpu/microcode/amd.c | 7 ------- xen/arch/x86/cpu/microcode/core.c | 9 +++------ xen/arch/x86/cpu/microcode/intel.c | 4 ---- xen/arch/x86/cpu/microcode/private.h | 2 -- 5 files changed, 4 insertions(+), 25 deletions(-)docs/misc/xen-command-line.pandoc +1
-6@@ -2648,7 +2648,7 @@ performance. Alternatively, selecting `tsx=1` will re-enable TSX at the users own risk. ### ucode -> `= List of [ <integer> | scan=<bool>, nmi=<bool>, allow-same=<bool> ]` +> `= List of [ <integer> | scan=<bool>, nmi=<bool> ]` Applicability: x86 Default: `nmi`@@ -2680,11 +2680,6 @@ precedence over `scan`. stop_machine context. In NMI handler, even NMIs are blocked, which is considered safer. The default value is `true`. -'allow-same' alters the default acceptance policy for new microcode to permit -trying to reload the same version. Many CPUs will actually reload microcode -of the same version, and this allows for easy testing of the late microcode -loading path. - ### unrestricted_guest (Intel) > `= <boolean>`xen/arch/x86/cpu/microcode/amd.c +0
-0
xen/arch/x86/cpu/microcode/amd.c static int cf_check apply_microcode(const struct microcode_patch *patch) · line 234
Quoted 10 lines
xen/arch/x86/cpu/microcode/amd.c +0
-7@@ -225,13 +225,6 @@ static int cf_check apply_microcode(const struct microcode_patch *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 ==OLD_UCODE ) -return -EEXIST ; -
I'm afraid that because of the observation leading to 977d98e67c2e, I see no option other than to plumb the force flag down into apply_microcode().
This check cannot be deleted unconditionally, or we'll try downgrading microcode even without the force flag being passed.
Unless we can fix the cacheing layer to not treat "I didn't load ucode at boot" as "no idea of the symmetry of the system".
I'm unsure which of these two is going to be less ugly...
Quoted 34 lines
xen/arch/x86/cpu/microcode/amd.c +0
-0if (check_final_patch_levels (sig) ) { printk(XENLOG_ERRxen/arch/x86/cpu/microcode/core.c +1
-4@@ -100,8 +100,6 @@ static bool __initdata ucode_scan;/* By default, ucode loading is done in NMI handler */ static bool ucode_in_nmi = true; -bool __read_mostly opt_ucode_allow_same; -/* Protected by microcode_mutex */ static struct microcode_patch *microcode_cache;@@ -128,8 +126,6 @@ static int __init cf_check parse_ucode(const char *s)if ( (val =parse_boolean ("nmi" , s, ss)) >=0 ) ucode_in_nmi = val; -else if ( (val =parse_boolean ("allow-same" , s, ss)) >=0 ) - opt_ucode_allow_same = val;else if ( !ucode_mod_forced )/* Not forced by EFI */ {if ( (val =parse_boolean ("scan" , s, ss)) >=0 )@@ -583,6 +579,7 @@ static long cf_check microcode_update_helper(void *data)struct ucode_buf *buffer = data;unsigned int cpu, updated;struct microcode_patch *patch; +bool ucode_force = buffer->flags ==XENPF_UCODE_FORCE ;/* cpu_online_map must not change during update */ if ( !get_cpu_maps () )
xen/arch/x86/cpu/microcode/core.c static long cf_check microcode_update_helper(void *data) · line 636
Quoted 5 lines
xen/arch/x86/cpu/microcode/core.c +1
-1@@ -636,12 +633,12 @@ static long cf_check microcode_update_helper(void *data) microcode_cache);if ( result !=NEW_UCODE && - !(opt_ucode_allow_same && result ==SAME_UCODE ) ) + (!ucode_force || (result & ~SAME_UCODE )) )
What is "result & ~SAME_UCODE" trying to do?
~Andrew
Re: [PATCH v4 4/4] x86/ucode: Utilize ucode_force and remove opt_ucode_allow_same
In reply to Fouad HillyQuoted 12 lines · Fouad Hilly
docs/misc/xen-command-line.pandoc +1
-1@@ -2648,7 +2648,7 @@ performance. Alternatively, selecting `tsx=1` will re-enable TSX at the users own risk. ### ucode -> `= List of [ <integer> | scan=<bool>, nmi=<bool>, allow-same=<bool> ]` +> `= List of [ <integer> | scan=<bool>, nmi=<bool> ]` Applicability: x86 Default: `nmi`
docs/misc/xen-command-line.pandoc precedence over `scan`. · line 2684
Quoted 10 lines
docs/misc/xen-command-line.pandoc +0
-5@@ -2680,11 +2680,6 @@ precedence over `scan`. stop_machine context. In NMI handler, even NMIs are blocked, which is considered safer. The default value is `true`. -'allow-same' alters the default acceptance policy for new microcode to permit -trying to reload the same version. Many CPUs will actually reload microcode -of the same version, and this allows for easy testing of the late microcode -loading path. - ### unrestricted_guest (Intel) > `= <boolean>`
Removal of a command line (sub-)option nowadays wants accompanying by a CHANGELOG.md entry.
Jan