x86/xen-ucode: Introduce --force option
v6 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 XENPF_microcode_update2 with flags parameter x86/ucode: refactor xen-ucode to utilize getopt x86/ucode: Introduce --force option to xen-ucode 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 | 63 +++++++++++++++--- xen/arch/x86/cpu/microcode/amd.c | 8 ++- xen/arch/x86/cpu/microcode/core.c | 99 +++++++++++++++++----------- xen/arch/x86/cpu/microcode/intel.c | 9 ++- xen/arch/x86/cpu/microcode/private.h | 5 +- xen/arch/x86/include/asm/microcode.h | 3 +- xen/arch/x86/platform_hypercall.c | 13 +++- xen/include/public/platform.h | 14 ++++ 11 files changed, 167 insertions(+), 69 deletions(-)
Signature · 1 line
2.42.0
PATCH v6 1/4 x86/ucode: Introduce XENPF_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.
---
[v6]
No change
[v5]
1- Update commit message to include the full name of XENPF_microcode_update2
[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
PATCH v6 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. Introducing usage() to handle usage\help messages in a common block. show_curr_cpu is printed to stdout only.
---
[v6]
1- Update usage() printed message format: [microcode file] [options] -> [microcode file | options] 2- Add missing blanks in switch ( opt )
[v5]
1- Update message description.
2- re-arrange static and automatic variables.
3- Fix indentations.
4- reverted the deletion of show-cpu-info for backwards compatibility.
[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 | 52 +++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 8 deletions(-)
tools/misc/xen-ucode.c +44 -8
@@ -11,6 +11,7 @@#include <sys/stat.h> #include <fcntl.h> #include <xenctrl.h> +#include <getopt.h> static xc_interface *xch;
@@ -71,12 +72,29 @@ static void show_curr_cpu(FILE *f) } } +static void usage (FILE *stream,const char *name) +{ +fprintf (stream, +"%s: Xen microcode updating tool\n" +"options:\n" +" -h, --help display this help\n" +" -s, --show-cpu-info show CPU information\n" +"Usage: %s [microcode file | options]\n" , name, name); +show_curr_cpu (stream); +} +int main (int argc,char *argv[]) { +static const struct option options[] = { + {"help" , no_argument,NULL ,'h' }, + {"show-cpu-info" , no_argument,NULL ,'s' }, + {NULL , no_argument,NULL ,0 } + };int fd, ret;char *filename, *buf;size_t len;struct stat st; +int opt; xch =xc_interface_open (NULL ,NULL ,0 );if ( xch ==NULL )
@@ -86,22 +104,34 @@ 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" ) ) +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 ; } - filename = argv[1 ]; + filename = argv[optind]; fd =open (filename,O_RDONLY );if ( fd <0 ) {
@@ -146,4 +176,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 v6 2/4] x86/ucode: refactor xen-ucode to utilize getopt
tools/misc/xen-ucode.c static void show_curr_cpu(FILE *f) · line 82
Quoted 12 lines · Fouad Hilly
tools/misc/xen-ucode.c +8
-0@@ -71,12 +72,29 @@ static void show_curr_cpu(FILE *f) } } +static void usage (FILE *stream,const char *name) +{ +fprintf (stream, +"%s: Xen microcode updating tool\n" +"options:\n" +" -h, --help display this help\n" +" -s, --show-cpu-info show CPU information\n" +"Usage: %s [microcode file | options]\n" , name, name);
You did see Anthony's comments on this before sending the new version, didn't you? I agree with him (and I'm somewhat embarrassed that I didn't notice this myself earlier on).
tools/misc/xen-ucode.c int main(int argc, char *argv[]) · line 185
Quoted 11 lines
tools/misc/xen-ucode.c +6
-0@@ -146,4 +176,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 ); }
And there was a comment on this, too.
Jan
Re: [PATCH v6 2/4] x86/ucode: refactor xen-ucode to utilize getopt
In reply to Fouad Hillytools/misc/xen-ucode.c static void show_curr_cpu(FILE *f) · line 82
Quoted 12 lines · Fouad Hilly
tools/misc/xen-ucode.c +8
-0@@ -71,12 +72,29 @@ static void show_curr_cpu(FILE *f) } } +static void usage (FILE *stream,const char *name) +{ +fprintf (stream, +"%s: Xen microcode updating tool\n" +"options:\n" +" -h, --help display this help\n" +" -s, --show-cpu-info show CPU information\n" +"Usage: %s [microcode file | options]\n" , name, name);
Oh, and: While I gave this precise layout as an outline, it wasn't really meant to be used literally. Note how "microcode" and "file" now suggest there need to be two separate command line elements. Perhaps using "microcode-file" instead may already make this less ambiguous.
Jan
Re: [PATCH v6 2/4] x86/ucode: refactor xen-ucode to utilize getopt
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Fouad Hilly
(quoted diff) +0
-0@@ -71,12 +72,29 @@ static void show_curr_cpu(FILE *f) } }
Quoted 14 lines
tools/misc/xen-ucode.c static void show_curr_cpu(FILE *f) · line 82
Quoted 8 lines
tools/misc/xen-ucode.c +8
-0+static void usage (FILE *stream,const char *name) +{ +fprintf (stream, +"%s: Xen microcode updating tool\n" +"options:\n" +" -h, --help display this help\n" +" -s, --show-cpu-info show CPU information\n" +"Usage: %s [microcode file | options]\n" , name, name);Oh, and: While I gave this precise layout as an outline, it wasn't really meant to be used literally. Note how "microcode" and "file" now suggest there need to be two separate command line elements. Perhaps using "microcode-file" instead may already make this less ambiguous.
Yes indeed, I will fix in v7:
static void usage(FILE *stream, const char *name)
{
fprintf(stream,
"%s: Xen microcode updating tool\n"
"Usage: %s [options | microcode-file]\n"
"options:\n"
" -h, --help display this help\n"
" -s, --show-cpu-info show CPU information\n"
" -f, --force <microcode-file> skip certain checks; do not
\n"
" use unless you know exactly
\n"
" what you are doing\n",
name, name);
show_curr_cpu(stream);
}Quoted 3 lines
Jan
Thanks,
Fouad
PATCH v6 3/4 x86/ucode: Introduce --force option to xen-ucode
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.
---
[v6]
1- Fix usage() output for -f option to be explicitly wrapped for 80 character width [v5]
1- Update commit message.
2- Re-phrase --force option description.
[v4]
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 | 15 ++++++++++++--- 3 files changed, 21 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 +12 -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" ;
@@ -79,7 +81,9 @@ static void usage(FILE *stream, const char *name)"options:\n" " -h, --help display this help\n" " -s, --show-cpu-info show CPU information\n" - "Usage: %s [microcode file | options]\n", name, name); +" -f, --force skip certain checks; do not use unless\n" +"you know exactly what you are doing\n" + "Usage: %s [microcode file [-f,--force] | options]\n", name, name);show_curr_cpu (stream); }
@@ -88,6 +92,7 @@ int main(int argc, char *argv[])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 } };int fd, ret;
@@ -95,6 +100,7 @@ int main(int argc, char *argv[])size_t len;struct stat st;int opt; +uint32_t ucode_flags =0 ; xch =xc_interface_open (NULL ,NULL ,0 );if ( xch ==NULL )
@@ -104,7 +110,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 ) {
@@ -116,6 +122,9 @@ int main(int argc, char *argv[])show_curr_cpu (stdout);exit (EXIT_SUCCESS ); +case 'f' : + ucode_flags =XENPF_UCODE_FORCE ; +break ;default : goto ext_err; }
@@ -156,7 +165,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 v6 3/4] x86/ucode: Introduce --force option to xen-ucode
Quoted 82 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]>Reviewed-by Andrew Cooper <[email protected]>---
[v6]
1- Fixusage()output for -f option to be explicitly wrapped for 80 character width [v5]
1- Update commit message.
2- Re-phrase --force option description.
[v4]
1- Add --force to xen-ucode options.
2- Updatexc_microcode_update()to accept and handle flags.--- tools/include/xenctrl.h | 3 ++- tools/libs/ctrl/xc_misc.c | 12 +++++++----- tools/misc/xen-ucode.c | 15 ++++++++++++--- 3 files changed, 21 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 +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 85
Quoted 6 lines
tools/misc/xen-ucode.c +2
-1@@ -79,7 +81,9 @@ static void usage(FILE *stream, const char *name)"options:\n" " -h, --help display this help\n" " -s, --show-cpu-info show CPU information\n" - "Usage: %s [microcode file | options]\n", name, name); +" -f, --force skip certain checks; do not use unless\n" +"you know exactly what you are doing\n"
Did you look at the produced output? Imo you want to have
" -f, --force skip certain checks; do not use unless\n"
" you know exactly what you are doing\n"
tools/misc/xen-ucode.c static void usage(FILE *stream, const char *name) · line 86
Quoted 1 line
tools/misc/xen-ucode.c +1
-0+ "Usage: %s [microcode file [-f,--force] | options]\n", name, name);
At least
"Usage: %s [microcode file [-f|--force] | options]\n", name, name);
But: "options" now includes -f / --force, yet that on its own makes no sense. I think this needs further textual clarification to properly indicate what is valid to use and what is not.
Jan
Re: [PATCH v6 3/4] x86/ucode: Introduce --force option to xen-ucode
Quoted 108 lines · Jan Beulich
Quoted 1 line · Fouad Hilly
Introduce --force option to xen-ucode to force skipping microcode
version check, which
Quoted 1 line
allows the user to update x86 microcode even if both versions are the
same or downgrade.
Quoted 1 line
xc_microcode_update()refactored to accept flags and utilize
xenpf_microcode_update2.Quoted 6 lines
Signed-off-by Fouad Hilly <[email protected]>Reviewed-by Andrew Cooper <[email protected]>---
[v6]
1- Fixusage()output for -f option to be explicitly wrapped for 80character width
Quoted 17 lines
[v5]
1- Update commit message.
2- Re-phrase --force option description.
[v4]
1- Add --force to xen-ucode options.
2- Updatexc_microcode_update()to accept and handle flags.--- tools/include/xenctrl.h | 3 ++- tools/libs/ctrl/xc_misc.c | 12 +++++++----- tools/misc/xen-ucode.c | 15 ++++++++++++--- 3 files changed, 21 insertions(+), 9 deletions(-)tools/include/xenctrl.h +0
-0tools/include/xenctrl.h typedef uint32_t xc_node_to_node_dist_t; · line 1176
Quoted 7 lines
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);tools/libs/ctrl/xc_misc.c int xc_microcode_update(xc_interface *xch, const
Quoted 22 lines
tools/include/xenctrl.h +0
-0int xc_get_ucode_revision (xc_interface *xch,struct xenpf_ucode_revision *ucode_rev);tools/libs/ctrl/xc_misc.c +3
-2@@ -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, constvoid *buf,
size_tlen)Quoted 27 lines
tools/libs/ctrl/xc_misc.c +4
-3memcpy (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 +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 84
Quoted 5 lines
tools/misc/xen-ucode.c +1
-1@@ -79,7 +81,9 @@ static void usage(FILE *stream, const char *name)"options:\n" " -h, --help display this help\n" " -s, --show-cpu-info show CPU information\n" - "Usage: %s [microcode file | options]\n", name, name); + " -f, --force skip certain checks; do not useunless\n"
tools/misc/xen-ucode.c static void usage(FILE *stream, const char *name) · line 85
Quoted 1 line
tools/misc/xen-ucode.c +1
-0+"you know exactly what you are doing\n" Did you look at the produced output? Imo you want to have
" -f, --force skip certain checks; do not use
unless\n"
" you know exactly what you are doing\n"tools/misc/xen-ucode.c static void usage(FILE *stream, const char *name) · line 86
Quoted 1 line
tools/misc/xen-ucode.c +1
-0+ "Usage: %s [microcode file [-f,--force] | options]\n",name, name);
At least
Quoted 9 lines
"Usage: %s [microcode file [-f|--force] | options]\n", name,name);
But: "options" now includes -f / --force, yet that on its own makes no sense.
I think this needs further textual clarification to properly indicate what is
valid to use and what is not.
Will be fixed in v7:
static void usage(FILE *stream, const char *name)
{
fprintf(stream,
"%s: Xen microcode updating tool\n"
"Usage: %s [options | microcode-file]\n"
"options:\n"
" -h, --help display this help\n"
" -s, --show-cpu-info show CPU information\n"
" -f, --force <microcode-file> skip certain checks; do not
\n"
" use unless you know exactly
\n"
" what you are doing\n",
name, name);
show_curr_cpu(stream);
}Quoted 3 lines
Jan
Thanks,
Fouad
Re: [PATCH v6 3/4] x86/ucode: Introduce --force option to xen-ucode
Quoted 37 lines · Fouad Hilly
Quoted 16 lines · Jan Beulich
tools/misc/xen-ucode.c static void usage(FILE *stream, const char *name) · line 85
Quoted 7 lines · Fouad Hilly
tools/misc/xen-ucode.c +2
-1@@ -79,7 +81,9 @@ static void usage(FILE *stream, const char *name)"options:\n" " -h, --help display this help\n" " -s, --show-cpu-info show CPU information\n" - "Usage: %s [microcode file | options]\n", name, name); +" -f, --force skip certain checks; do not use unless\n" +"you know exactly what you are doing\n" Did you look at the produced output? Imo you want to have
" -f, --force skip certain checks; do not use unless\n"
" you know exactly what you are doing\n"tools/misc/xen-ucode.c static void usage(FILE *stream, const char *name) · line 86
Quoted 1 line
tools/misc/xen-ucode.c +1
-0+ "Usage: %s [microcode file [-f,--force] | options]\n", name, name);Quoted 8 lines
At least
"Usage: %s [microcode file [-f|--force] | options]\n", name, name);But: "options" now includes -f / --force, yet that on its own makes no sense. I think this needs further textual clarification to properly indicate what is valid to use and what is not.
Will be fixed in v7:
static voidusage(FILE *stream, const char *name){ fprintf(stream, "%s: Xen microcode updating tool\n" "Usage: %s [options | microcode-file]\n" "options:\n" " -h, --help display this help\n" " -s, --show-cpu-info show CPU information\n" " -f, --force <microcode-file> skip certain checks; do not
Quoted 1 line
\n"
If I recall correctly, "--force" doesn't take any argument, so this usage is misleading. One could be tempted to execute ./xen-ucode -fmicrocode or event ./xen-ucode --force -microcode and expect it to work with files "microcode" or "-microcode" but instead I think getopt() is just going to return an error.
Instead of writing "--force <microcode-file>", could you change the help text, with something like "skip certain checks when applying microcode"?
Quoted 5 lines
" use unless you know exactly
\n"" what you are doing\n", name, name); show_curr_cpu(stream);
Cheers,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH v6 3/4] x86/ucode: Introduce --force option to xen-ucode
Quoted 48 lines · Anthony PERARD
Quoted 9 lines · Fouad Hilly
Quoted 7 lines · Jan Beulich
tools/misc/xen-ucode.c static void usage(FILE *stream, const char *name) · line 84
Quoted 6 lines · Fouad Hilly
tools/misc/xen-ucode.c +1
-1@@ -79,7 +81,9 @@ static void usage(FILE *stream, const char *name)"options:\n" " -h, --help display this help\n" " -s, --show-cpu-info show CPU information\n" - "Usage: %s [microcode file | options]\n", name, name); + " -f, --force skip certain checks; do notuse unless\n"
Quoted 5 lines
Quoted 5 lines
tools/misc/xen-ucode.c static void usage(FILE *stream, const char *name) · line 85
Quoted 1 line
tools/misc/xen-ucode.c +1
-0+"you know exactly what you are doing\n" Did you look at the produced output? Imo you want to have
" -f, --force skip certain checks; do not use
unless\n"
Quoted 1 line
Quoted 1 line
" you know exactly what you are
doing\n"
Quoted 2 lines
Quoted 2 lines
Review static void usage(FILE *stream, const char *name) · line 86
Quoted 2 lines
(quoted diff) +1
-0+ "Usage: %s [microcode file [-f,--force] | options]\n",name, name);
Quoted 4 lines
Quoted 4 lines
At least
"Usage: %s [microcode file [-f|--force] | options]\n",name, name);
Quoted 2 lines
Quoted 2 lines
But: "options" now includes -f / --force, yet that on its own makes no
sense.
Quoted 1 line
Quoted 1 line
I think this needs further textual clarification to properly indicate
what is
Quoted 5 lines
Quoted 2 lines
valid to use and what is not.
Will be fixed in v7:
static voidusage(FILE *stream, const char *name)Quoted 8 lines
{ fprintf(stream, "%s: Xen microcode updating tool\n" "Usage: %s [options | microcode-file]\n" "options:\n" " -h, --help display this help\n" " -s, --show-cpu-info show CPU information\n" " -f, --force <microcode-file> skip certain checks; donot
Quoted 1 line
\n"
Quoted 9 lines
If I recall correctly, "--force" doesn't take any argument, so this usage is misleading. One could be tempted to execute
./xen-ucode -fmicrocodeor event./xen-ucode --force -microcodeand expect it to work with files "microcode" or "-microcode" but instead I thinkgetopt()is just going to return an error.Instead of writing "--force <microcode-file>", could you change the help text, with something like "skip certain checks when applying microcode"?
Sure, can be done in v7:
static void usage(FILE *stream, const char *name) {
fprintf(stream,
"%s: Xen microcode updating tool\n" "Usage: %s [options | microcode-file]\n" "options:\n"
" -h, --help display this help\n"
" -s, --show-cpu-info show CPU information\n",
" -f, --force skip certain checks when applying\n"
" microcode; do not use unless you
know\n"
" exactly what you are doing\n",
name, name);
show_curr_cpu(stream);
}Quoted 10 lines
Quoted 2 lines
" use unless you know
exactly
Quoted 4 lines
\n"
" what you are doing\n", name, name); show_curr_cpu(stream);Cheers,
Quoted 7 lines
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Thanks,
Fouad
PATCH v6 4/4 x86/ucode: Utilize ucode_force and remove opt_ucode_allow_same
In reply to Fouad HillyPass xen-ucode flags to do low level checks on micorocde version and utilize it to allow for microcode downgrade or reapply the same version of the microcode.ucode_force is required to be passed to a low level Intel and AMD for version checks to be done.
While adding ucode_force, opt_ucode_allow_same was removed. Remove opt_ucode_allow_same from documentation.
---
[v6]
1- Removed struct microcode_nmi_patch_with_flags.
2- removed const from control_thread_fn() and primary_thread_fn().
3- Fixed "flags" checks.
[v5]
1- Update commit message.
2- Introduce structs microcode_patch_with_flags and microcode_nmi_patch_with_flags. 3- pass flags to Intel and AMD low level through apply_microcode().
[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 | 8 ++- xen/arch/x86/cpu/microcode/core.c | 88 +++++++++++++++++----------- xen/arch/x86/cpu/microcode/intel.c | 9 ++- xen/arch/x86/cpu/microcode/private.h | 5 +- 5 files changed, 68 insertions(+), 49 deletions(-)
docs/misc/xen-command-line.pandoc +1 -6
@@ -2650,7 +2650,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`
@@ -2682,11 +2682,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 +6 -2
@@ -22,6 +22,8 @@#include "private.h" +#include "public/platform.h" + #define pr_debug(x...) ((void)0)struct equiv_cpu_entry {
@@ -214,13 +216,15 @@ static enum microcode_match_result cf_check compare_patch(return compare_header (new, old); } -static int cf_check apply_microcode(const struct microcode_patch *patch) +static int cf_check apply_microcode(const struct microcode_patch *patch, +unsigned int flags) {int hw_err;unsigned int cpu =smp_processor_id ();struct cpu_signature *sig = &per_cpu (cpu_sig, cpu);uint32_t rev, old_rev = sig->rev;enum microcode_match_result result =microcode_fits (patch); +bool ucode_force = flags &XENPF_UCODE_FORCE ;if ( result ==MIS_UCODE )return -EINVAL ;
@@ -229,7 +233,7 @@ static int cf_check apply_microcode(const struct microcode_patch *patch)* 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 ) +if ( !ucode_force && (result ==SAME_UCODE || result ==OLD_UCODE ) )return -EEXIST ;if (check_final_patch_levels (sig) )
xen/arch/x86/cpu/microcode/core.c +53 -35
251 lines not on this page · raw message
xen/arch/x86/cpu/microcode/intel.c +6 -3
@@ -29,6 +29,8 @@#include "private.h" +#include "public/platform.h" + #define pr_debug(x...) ((void)0)struct microcode_patch {
@@ -284,21 +286,22 @@ static enum microcode_match_result cf_check compare_patch(return compare_revisions (old->rev, new->rev); } -static int cf_check apply_microcode(const struct microcode_patch *patch) +static int cf_check apply_microcode(const struct microcode_patch *patch, +unsigned int flags) {uint64_t msr_content;unsigned int cpu =smp_processor_id ();struct cpu_signature *sig = &this_cpu (cpu_sig);uint32_t rev, old_rev = sig->rev;enum microcode_match_result result; +bool ucode_force = flags &XENPF_UCODE_FORCE ; result =microcode_update_match (patch);if ( result ==MIS_UCODE )return -EINVAL ; -if ( result ==OLD_UCODE || - (result ==SAME_UCODE && !opt_ucode_allow_same) ) +if ( !ucode_force && (result ==SAME_UCODE || result ==OLD_UCODE ) )return -EEXIST ;wbinvd ();
xen/arch/x86/cpu/microcode/private.h +2 -3
@@ -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 */
@@ -50,7 +48,8 @@ struct microcode_ops {* Attempt to load the provided patch into the CPU. Returns an error if * anything didn't go as expected. */ -int (*apply_microcode)(const struct microcode_patch *patch); +int (*apply_microcode)(const struct microcode_patch *patch, +unsigned int flags);/* * Given two patches, are they both applicable to the current CPU, and is
Signature · 1 line
2.42.0
Re: [PATCH v6 4/4] x86/ucode: Utilize ucode_force and remove opt_ucode_allow_same
Quoted 12 lines · Fouad Hilly
docs/misc/xen-command-line.pandoc +1
-1@@ -2650,7 +2650,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 2688
Quoted 7 lines
docs/misc/xen-command-line.pandoc +0
-4@@ -2682,11 +2682,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.
The removal of a command line (sub)option should come with a CHANGELOG.md entry.
xen/arch/x86/cpu/microcode/core.c struct ucode_mod_blob { · line 95
Quoted 9 lines
xen/arch/x86/cpu/microcode/core.c +3
-0@@ -90,6 +90,11 @@ struct ucode_mod_blob {size_t size; }; +struct patch_with_flags { +unsigned int flags; +struct microcode_patch *patch;
Pointer-to-const? If the const was omitted here just because of microcode_free_patch(), then I think the issue should be taken care of there.
xen/arch/x86/cpu/microcode/core.c static DEFINE_PER_CPU(int, loading_err); · line 241
Quoted 6 lines
xen/arch/x86/cpu/microcode/core.c +1
-1@@ -237,7 +238,11 @@ static DEFINE_PER_CPU(int, loading_err);*/ static cpumask_t cpu_callin_map;static atomic_t cpu_out, cpu_updated; -static const struct microcode_patch *nmi_patch =ZERO_BLOCK_PTR ; +static struct patch_with_flags nmi_patch_with_flags =
Could the variable name perhaps continue to be "nmi_patch"? Or be simply "nmi_arg" or some such?
xen/arch/x86/cpu/microcode/core.c static DEFINE_PER_CPU(int, loading_err); · line 243
Quoted 2 lines
xen/arch/x86/cpu/microcode/core.c +2
-0+{ + .flags = 0,
Nit: This isn't really needed.
xen/arch/x86/cpu/microcode/core.c static int secondary_nmi_work(void) · line 391
Quoted 8 lines
xen/arch/x86/cpu/microcode/core.c +2
-1@@ -379,7 +386,8 @@ static int secondary_nmi_work(void)return wait_for_state (LOADING_EXIT ) ?0 : -EBUSY ; } -static int primary_thread_work (const struct microcode_patch *patch) +static int primary_thread_work (struct microcode_patch *patch, +unsigned int flags) {
Why is this change needed?
xen/arch/x86/cpu/microcode/core.c static int secondary_thread_fn(void) · line 459
Quoted 7 lines
xen/arch/x86/cpu/microcode/core.c +2
-1@@ -446,7 +455,8 @@ static int secondary_thread_fn(void)return this_cpu (loading_err); } -static int primary_thread_fn (const struct microcode_patch *patch) +static int primary_thread_fn (struct microcode_patch *patch, +unsigned int flags)
Same here.
Jan
Re: [PATCH v6 4/4] x86/ucode: Utilize ucode_force and remove opt_ucode_allow_same
Quoted 19 lines · Jan Beulich
docs/misc/xen-command-line.pandoc performance. · line 2650
Quoted 4 lines · Fouad Hilly
docs/misc/xen-command-line.pandoc +0
-0@@ -2650,7 +2650,7 @@ performance. Alternatively, selecting `tsx=1` will re-enable TSX at the users ownrisk.
docs/misc/xen-command-line.pandoc precedence over `scan`. · line 2685
Quoted 12 lines
docs/misc/xen-command-line.pandoc +1
-2### ucode -> `= List of [ <integer> | scan=<bool>, nmi=<bool>, allow-same=<bool> ]` +> `= List of [ <integer> | scan=<bool>, nmi=<bool> ]` Applicability: x86 Default: `nmi`@@ -2682,11 +2682,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 topermit
Quoted 9 lines
docs/misc/xen-command-line.pandoc precedence over `scan`. · line 2686
Quoted 1 line
docs/misc/xen-command-line.pandoc +0
-1-trying to reload the same version. Many CPUs will actually reloadmicrocode
docs/misc/xen-command-line.pandoc precedence over `scan`. · line 2687
Quoted 1 line
docs/misc/xen-command-line.pandoc +0
-1-of the same version, and this allows for easy testing of the latemicrocode
docs/misc/xen-command-line.pandoc precedence over `scan`. · line 2688
Quoted 1 line
docs/misc/xen-command-line.pandoc +0
-1-loading path.The removal of a command line (sub)option should come with a CHANGELOG.md entry.
Will be fixed in v7
Quoted 7 lines
Quoted 7 lines
xen/arch/x86/cpu/microcode/core.c +0
-0@@ -90,6 +90,11 @@ struct ucode_mod_blob {size_t size; };
Quoted 8 lines
xen/arch/x86/cpu/microcode/core.c struct ucode_mod_blob { · line 95
Quoted 3 lines
xen/arch/x86/cpu/microcode/core.c +3
-0+struct patch_with_flags { +unsigned int flags; +struct microcode_patch *patch;Pointer-to-const? If the const was omitted here just because of
microcode_free_patch(), then I think the issue should be taken care of there.
This struct is required as is, I initially added a similar struct with const (which was removed in v6).
updated control_thread_fn()
-static int control_thread_fn(const struct microcode_patch *patch) +static int control_thread_fn(struct microcode_patch *patch,
+ unsigned int flags)
Quoted 10 lines
(quoted diff) +0
-0@@ -237,7 +238,11 @@ static DEFINE_PER_CPU(int, loading_err);xen/arch/x86/cpu/microcode/core.c static DEFINE_PER_CPU(int, loading_err); · line 241
Quoted 5 lines
xen/arch/x86/cpu/microcode/core.c +1
-1*/ static cpumask_t cpu_callin_map;static atomic_t cpu_out, cpu_updated; -static const struct microcode_patch *nmi_patch =ZERO_BLOCK_PTR ; +static struct patch_with_flags nmi_patch_with_flags =Could the variable name perhaps continue to be "
nmi_patch"? Or be simply "nmi_arg" or some such?
Sure, will keep it as nmi_patch
Quoted 10 lines
xen/arch/x86/cpu/microcode/core.c static DEFINE_PER_CPU(int, loading_err); · line 243
Quoted 3 lines
xen/arch/x86/cpu/microcode/core.c +2
-0+{ + .flags = 0,Nit: This isn't really needed.
Quoted 4 lines
xen/arch/x86/cpu/microcode/core.c +0
-0@@ -379,7 +386,8 @@ static int secondary_nmi_work(void)return wait_for_state (LOADING_EXIT ) ?0 : -EBUSY ; }
Quoted 7 lines
xen/arch/x86/cpu/microcode/core.c static int secondary_nmi_work(void) · line 391
Quoted 4 lines
xen/arch/x86/cpu/microcode/core.c +2
-1-static int primary_thread_work (const struct microcode_patch *patch) +static int primary_thread_work (struct microcode_patch *patch, +unsigned int flags) {Why is this change needed?
This will be reverted in v7
Quoted 11 lines
xen/arch/x86/cpu/microcode/core.c static int secondary_thread_fn(void) · line 459
Quoted 8 lines
xen/arch/x86/cpu/microcode/core.c +2
-1@@ -446,7 +455,8 @@ static int secondary_thread_fn(void)return this_cpu (loading_err); } -static int primary_thread_fn (const struct microcode_patch *patch) +static int primary_thread_fn (struct microcode_patch *patch, +unsigned int flags)Same here.
This will be reverted in v7
Quoted 3 lines
Jan
Thanks,
Fouad
Re: [PATCH v6 4/4] x86/ucode: Utilize ucode_force and remove opt_ucode_allow_same
Quoted 19 lines · Fouad Hilly
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Fouad Hilly
xen/arch/x86/cpu/microcode/core.c +0
-0@@ -90,6 +90,11 @@ struct ucode_mod_blob {size_t size; };Quoted 7 lines
xen/arch/x86/cpu/microcode/core.c struct ucode_mod_blob { · line 95
Quoted 3 lines
xen/arch/x86/cpu/microcode/core.c +3
-0+struct patch_with_flags { +unsigned int flags; +struct microcode_patch *patch;Pointer-to-const? If the const was omitted here just because of
microcode_free_patch(), then I think the issue should be taken care of there.This struct is required as is, I initially added a similar struct with const (which was removed in v6).
updatedcontrol_thread_fn()
xen/arch/x86/cpu/microcode/core.c static int primary_thread_fn(const struct microcode_patch *patch) · line 483
Quoted 3 lines
xen/arch/x86/cpu/microcode/core.c +2
-1-static int control_thread_fn (const struct microcode_patch *patch) +static int control_thread_fn (struct microcode_patch *patch, +unsigned int flags)
And why's that change necessary, other than to cater for the omitted const in the struct?
Jan
Re: [PATCH v6 4/4] x86/ucode: Utilize ucode_force and remove opt_ucode_allow_same
Quoted 17 lines · Jan Beulich
Quoted 16 lines · Fouad Hilly
Quoted 14 lines · Jan Beulich
xen/arch/x86/cpu/microcode/core.c struct ucode_mod_blob { · line 95
Quoted 9 lines · Fouad Hilly
xen/arch/x86/cpu/microcode/core.c +3
-0@@ -90,6 +90,11 @@ struct ucode_mod_blob {size_t size; }; +struct patch_with_flags { +unsigned int flags; +struct microcode_patch *patch;Pointer-to-const? If the const was omitted here just because of
microcode_free_patch(), then I think the issue should be taken care of there.
Quoted 10 lines
xen/arch/x86/cpu/microcode/core.c static int primary_thread_fn(const struct microcode_patch *patch) · line 483
Quoted 6 lines
This struct is required as is, I initially added a similar struct with const (which was removed in v6).
updatedcontrol_thread_fn()xen/arch/x86/cpu/microcode/core.c +2
-1-static int control_thread_fn (const struct microcode_patch *patch) +static int control_thread_fn (struct microcode_patch *patch, +unsigned int flags)And why's that change necessary, other than to cater for the omitted const in the struct?
I see your point, I will keep const and update microcode_free_patch() as needed in v7.
Quoted 3 lines
Jan
Thanks,
Fouad