x86/xen-ucode: Introduce --force option
v3 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 for testing. On top of that Intel is introducing "min rev", which will require a mechanism to override version checks
Fouad Hilly (5):
x86: Update x86 low level version check of microcode
x86: Refactor microcode_update() hypercall with flags
x86: Add usage() to print out usage message
x86: Use getopt to handle command line args
Add --force option to xen-ucode to override microcode version check
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 | 15 +++++-- xen/arch/x86/cpu/microcode/intel.c | 10 ++--- xen/arch/x86/include/asm/microcode.h | 3 +- xen/arch/x86/platform_hypercall.c | 12 +++++- xen/include/public/platform.h | 14 +++++++ 9 files changed, 103 insertions(+), 34 deletions(-)
Signature · 1 line
2.42.0
PATCH v3 1/5 x86: Update x86 low level version check of microcode
Update microcode version check at Intel and AMD Level by:
Preventing the low level code from sending errors if the microcode version is not a newer version. this is required to allow developers to do ucode loading testing, including the introduction of Intel "min rev" field, which requires an override mechanism for newer version checks. Even though the check for newer is removed at this level, it still exists at higher common level, where by default only newer version will be processed.
The option to override version check, will be added as part of this patch series.
Other errors will be handled as required at this level.
Keep all the required code at low level that checks for signature and CPU compatibility
---
[v3]
1- Update intel code to return errors in case of invalid microcode only. 2- Update code comments.
3- Update commit message and its description
[v2]
Update message description to better describe the changes
xen/arch/x86/cpu/microcode/amd.c | 7 +++---- xen/arch/x86/cpu/microcode/intel.c | 10 ++++------ 2 files changed, 7 insertions(+), 10 deletions(-)
xen/arch/x86/cpu/microcode/amd.c +3 -4
@@ -384,11 +384,10 @@ static struct microcode_patch *cf_check cpu_request_microcode( }/* -* If the new ucode covers current CPU, compare ucodes and store the -* one with higher revision. +* If the microcode covers current CPU, then store its +* revision. */ -if ( (microcode_fits (mc->patch) !=MIS_UCODE ) && - (!saved || (compare_header (mc->patch, saved) ==NEW_UCODE )) ) +if ( (microcode_fits (mc->patch) !=MIS_UCODE ) && !saved ) { saved = mc->patch; saved_size = mc->len;
xen/arch/x86/cpu/microcode/intel.c +4 -6
@@ -294,8 +294,7 @@ 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 ;wbinvd ();
@@ -355,11 +354,10 @@ static struct microcode_patch *cf_check cpu_request_microcode(break ;/* -* If the new update covers current CPU, compare updates and store the -* one with higher revision. +* If the microcode covers current CPU, then store its +* revision. */ -if ( (microcode_update_match (mc) !=MIS_UCODE ) && - (!saved ||compare_revisions (saved->rev, mc->rev) ==NEW_UCODE ) ) +if ( (microcode_update_match (mc) !=MIS_UCODE ) && !saved ) saved = mc; buf += blob_size;
Signature · 1 line
2.42.0
Re: [PATCH v3 1/5] x86: Update x86 low level version check of microcode
Quoted 5 lines · Fouad Hilly
Update microcode version check at Intel and AMD Level by:
Preventing the low level code from sending errors if the microcode version is not a newer version. this is required to allow developers to do ucode loading testing, including the introduction of Intel "min rev" field, which requires an override mechanism for newer version checks.
Won't "min rev" checking, for being Intel-only, require quite the opposite, i.e. leaving more of the checking to vendor specific code?
Quoted 5 lines
Even though
the check for newer is removed at this level, it still exists at higher common level, where by default only newer version will be processed. The option to override version check, will be added as part of this patch series.
Please avoid wording like "this patch", "this commit", and all the more "this patch series". Especially this last one will become completely meaningless once part of a commit message in the tree.
xen/arch/x86/cpu/microcode/amd.c static struct microcode_patch *cf_check cpu_request_microcode( · line 389
Quoted 11 lines
xen/arch/x86/cpu/microcode/amd.c +2
-2@@ -384,11 +384,10 @@ static struct microcode_patch *cf_check cpu_request_microcode( }/* -* If the new ucode covers current CPU, compare ucodes and store the -* one with higher revision. +* If the microcode covers current CPU, then store its +* revision. */
Nit: This can become a single line comment now, can't it? (Again then in Intel code.)
xen/arch/x86/cpu/microcode/intel.c static int cf_check apply_microcode(const struct microcode_patch *patch) · line 298
Quoted 10 lines
xen/arch/x86/cpu/microcode/intel.c +1
-2@@ -294,8 +294,7 @@ 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 ;
I continue to be in trouble with this change, despite the v3 adjustment you make: If this is needed here, why would a similar change not be needed for AMD?
Plus the original question remains: Is this actually valid to be changed right here? IOW despite the somewhat improved patch description I'm still having difficulty identifying which vendor-independent check this is redundant with. As opposed to the AMD change further up and ...
xen/arch/x86/cpu/microcode/intel.c static struct microcode_patch *cf_check cpu_request_microcode( · line 361
Quoted 13 lines
xen/arch/x86/cpu/microcode/intel.c +3
-4@@ -355,11 +354,10 @@ static struct microcode_patch *cf_check cpu_request_microcode(break ;/* -* If the new update covers current CPU, compare updates and store the -* one with higher revision. +* If the microcode covers current CPU, then store its +* revision. */ -if ( (microcode_update_match (mc) !=MIS_UCODE ) && - (!saved ||compare_revisions (saved->rev, mc->rev) ==NEW_UCODE ) ) +if ( (microcode_update_match (mc) !=MIS_UCODE ) && !saved ) saved = mc;
... this one, where I can see that they are about caching of ucode blobs, which looks to be dealt with by cache maintenance logic in microcode_update_helper() and microcode_update_cache().
Jan
Re: [PATCH v3 1/5] x86: Update x86 low level version check of microcode
Quoted 10 lines · Jan Beulich
Quoted 5 lines · Fouad Hilly
Update microcode version check at Intel and AMD Level by:
Preventing the low level code from sending errors if the microcode version is not a newer version. this is required to allow developers to do ucode loading testing, including the introduction of Intel "min rev" field, which requires an override mechanism for newer version checks.Won't "min rev" checking, for being Intel-only, require quite the opposite, i.e. leaving more of the checking to vendor specific code?
The checking of the microcode signature and if it is applicable to the CPU, will be at vendor code level i.e Intel\AMD.
"min_rev" mention to be removed. This change is for microcode downgrade capability.
Quoted 11 lines
Quoted 6 lines
Even though
the check for newer is removed at this level, it still exists at higher common level, where by default only newer version will be processed. The option to override version check, will be added as part of this patch series.Please avoid wording like "this patch", "this commit", and all the more "this patch series". Especially this last one will become completely meaningless once part of a commit message in the tree.
Noted and will be fixed in V4
Quoted 21 lines
xen/arch/x86/cpu/microcode/amd.c static struct microcode_patch *cf_check cpu_request_microcode( · line 389
Quoted 11 lines
xen/arch/x86/cpu/microcode/amd.c +2
-2@@ -384,11 +384,10 @@ static struct microcode_patch *cf_check cpu_request_microcode( }/* -* If the new ucode covers current CPU, compare ucodes and store the -* one with higher revision. +* If the microcode covers current CPU, then store its +* revision. */ Nit: This can become a single line comment now, can't it? (Again then in Intel code.)
Quoted 6 lines
xen/arch/x86/cpu/microcode/intel.c +0
-0@@ -294,8 +294,7 @@ static int cf_check apply_microcode(const struct microcode_patch *patch) result =microcode_update_match (patch);
Quoted 8 lines
xen/arch/x86/cpu/microcode/intel.c static int cf_check apply_microcode(const struct microcode_patch *patch) · line 298
Quoted 4 lines
xen/arch/x86/cpu/microcode/intel.c +1
-2-if ( result !=NEW_UCODE && - !(opt_ucode_allow_same && result ==SAME_UCODE ) ) +if ( result ==MIS_UCODE )return -EINVAL ;I continue to be in trouble with this change, despite the v3 adjustment you make: If this is needed here, why would a similar change not be needed for AMD?
Will be fixed in V4
Fouad
Quoted 25 lines
Plus the original question remains: Is this actually valid to be changed right here? IOW despite the somewhat improved patch description I'm still having difficulty identifying which vendor-independent check this is redundant with. As opposed to the AMD change further up and ...
xen/arch/x86/cpu/microcode/intel.c static struct microcode_patch *cf_check cpu_request_microcode( · line 361
Quoted 13 lines
xen/arch/x86/cpu/microcode/intel.c +3
-4@@ -355,11 +354,10 @@ static struct microcode_patch *cf_check cpu_request_microcode(break ;/* -* If the new update covers current CPU, compare updates and store the -* one with higher revision. +* If the microcode covers current CPU, then store its +* revision. */ -if ( (microcode_update_match (mc) !=MIS_UCODE ) && - (!saved ||compare_revisions (saved->rev, mc->rev) ==NEW_UCODE ) ) +if ( (microcode_update_match (mc) !=MIS_UCODE ) && !saved ) saved = mc;... this one, where I can see that they are about caching of ucode blobs, which looks to be dealt with by cache maintenance logic in
microcode_update_helper()andmicrocode_update_cache().Jan
PATCH v3 2/5 x86: Refactor microcode_update() hypercall with flags
In reply to Fouad HillyRefactor microcode_update() by adding a flags field. struct xenpf_microcode_update2 added with uint32_t flags field. Introduce XENPF_microcode_update2 hypercall to handle flags field. Introduce ucode_force_flag to microcode_update_helper.
---
[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 | 15 ++++++++++++--- xen/arch/x86/include/asm/microcode.h | 3 ++- xen/arch/x86/platform_hypercall.c | 12 +++++++++++- xen/include/public/platform.h | 14 ++++++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-)
xen/arch/x86/cpu/microcode/core.c +12 -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[]; };
@@ -580,6 +583,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_flag = buffer->flags ==XENPF_UCODE_FLAG_FORCE_SET ;/* cpu_online_map must not change during update */ if ( !get_cpu_maps () )
@@ -633,12 +637,12 @@ static long cf_check microcode_update_helper(void *data) microcode_cache);if ( result !=NEW_UCODE && - !(opt_ucode_allow_same && result ==SAME_UCODE ) ) + !((opt_ucode_allow_same || ucode_force_flag) && 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)" :"" ); + (opt_ucode_allow_same || ucode_force_flag) ?" (or the same)" :"" );microcode_free_patch (patch); ret = -ENOENT ;
@@ -708,11 +712,15 @@ 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 ( flags >1 ) +return -EINVAL ; +if ( len != (uint32_t )len )return -E2BIG ;
@@ -730,6 +738,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 +11 -1
@@ -311,7 +311,17 @@ 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 when set */ +#define XENPF_UCODE_FLAG_FORCE_SET 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 v3 2/5] x86: Refactor microcode_update() hypercall with flags
xen/arch/x86/cpu/microcode/core.c static long cf_check microcode_update_helper(void *data) · line 640
Quoted 6 lines · Fouad Hilly
xen/arch/x86/cpu/microcode/core.c +1
-1@@ -633,12 +637,12 @@ static long cf_check microcode_update_helper(void *data) microcode_cache);if ( result !=NEW_UCODE && - !(opt_ucode_allow_same && result ==SAME_UCODE ) ) + !((opt_ucode_allow_same || ucode_force_flag) && result ==SAME_UCODE ) )
Why would "force" not also allow a downgrade?
xen/arch/x86/cpu/microcode/core.c static long cf_check microcode_update_helper(void *data) · line 721
Quoted 12 lines
xen/arch/x86/cpu/microcode/core.c +3
-1@@ -708,11 +712,15 @@ 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 ( flags >1 )
How is one to connect this literal 1 with what is really meant here? Also would be nice if this check fit with other similar checks we do, i.e.
if ( flags & ~XENPF_UCODE_FLAG_FORCE_SET )
xen/arch/x86/cpu/microcode/core.c static long cf_check microcode_update_helper(void *data) · line 725
Quoted 4 lines
xen/arch/x86/cpu/microcode/core.c +2
-0+return -EINVAL ; +if ( len != (uint32_t )len )return -E2BIG ;
As an aside: Isn't this dead code, with the respective hypercall interface struct fields (now) both being uint32_t?
Quoted 8 lines
xen/arch/x86/platform_hypercall.c +1
-1@@ -311,7 +311,17 @@ 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 );
xen/arch/x86/platform_hypercall.c ret_t do_platform_op( · line 324
Quoted 10 lines
xen/arch/x86/platform_hypercall.c +10
-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);
Nit (style): Overlong line.
xen/include/public/platform.h struct xenpf_ucode_revision { · line 633
Quoted 13 lines
xen/include/public/platform.h +7
-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 when set */ +#define XENPF_UCODE_FLAG_FORCE_SET 1
Nit: What is "SET" in the identifier intended to mean?
Jan
Re: [PATCH v3 2/5] x86: Refactor microcode_update() hypercall with flags
Quoted 10 lines · Jan Beulich
xen/arch/x86/cpu/microcode/core.c static long cf_check microcode_update_helper(void *data) · line 640
Quoted 6 lines · Fouad Hilly
xen/arch/x86/cpu/microcode/core.c +1
-1@@ -633,12 +637,12 @@ static long cf_check microcode_update_helper(void *data) microcode_cache);if ( result !=NEW_UCODE && - !(opt_ucode_allow_same && result ==SAME_UCODE ) ) + !((opt_ucode_allow_same || ucode_force_flag) && result ==SAME_UCODE ) )Why would "force" not also allow a downgrade?
It should be allowed. Will be fixed in v4
Quoted 12 lines
Quoted 12 lines
xen/arch/x86/cpu/microcode/core.c +2
-1@@ -708,11 +712,15 @@ 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;
Quoted 6 lines
xen/arch/x86/cpu/microcode/core.c static long cf_check microcode_update_helper(void *data) · line 721
Quoted 1 line
xen/arch/x86/cpu/microcode/core.c +1
-0+if ( flags >1 )How is one to connect this literal 1 with what is really meant here? Also would be nice if this check fit with other similar checks we do, i.e.
if ( flags & ~XENPF_UCODE_FLAG_FORCE_SET )
Will be done in v4
Quoted 8 lines
xen/arch/x86/cpu/microcode/core.c static long cf_check microcode_update_helper(void *data) · line 725
Quoted 5 lines
xen/arch/x86/cpu/microcode/core.c +2
-0+return -EINVAL ; +if ( len != (uint32_t )len )return -E2BIG ;As an aside: Isn't this dead code, with the respective hypercall interface struct fields (now) both being
uint32_t?
Will be cleaned up in v4.
Quoted 28 lines
Quoted 9 lines
xen/arch/x86/platform_hypercall.c +1
-1@@ -311,7 +311,17 @@ 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 );xen/arch/x86/platform_hypercall.c ret_t do_platform_op( · line 324
Quoted 10 lines
xen/arch/x86/platform_hypercall.c +10
-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);Nit (style): Overlong line.
Quoted 6 lines
xen/include/public/platform.h +0
-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);
Quoted 9 lines
xen/include/public/platform.h struct xenpf_ucode_revision { · line 633
Quoted 7 lines
xen/include/public/platform.h +7
-0+/* 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 when set */ +#define XENPF_UCODE_FLAG_FORCE_SET 1Nit: What is "SET" in the identifier intended to mean?
"SET" to be removed in v4.
Quoted 2 lines
Jan
PATCH v3 3/5 x86: Add usage() to print out usage message
In reply to Fouad HillyRefactor xen-ucode tool by adding usage() to handle usage\help messages.
As we add more command options this will keep help\usage messages in a common block. Only generic error message is printed to stderr. usage and show_curr_cpu are printed to stdout.
---
[v3]
1- Reverted usage message.
2- Utilized usage().
[v2]
1- Improved message description.
2- Fixed formatting and indentation.
3- Error message to print to stderr.
tools/misc/xen-ucode.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
tools/misc/xen-ucode.c +9 -3
@@ -17,6 +17,13 @@ static xc_interface *xch;static const char intel_id[] ="GenuineIntel" ;static const char amd_id[] ="AuthenticAMD" ; +static void usage (const char *name) +{ +printf ("%s: Xen microcode updating tool\n" +"Usage: %s [<microcode file> | show-cpu-info]\n" , + name, name); +} +static void show_curr_cpu (FILE *f) {int ret;
@@ -89,9 +96,8 @@ int main(int argc, char *argv[])if ( argc <2 ) {fprintf (stderr, -"xen-ucode: Xen microcode updating tool\n" -"Usage: %s [<microcode file> | show-cpu-info]\n" , argv[0 ]); -show_curr_cpu (stderr); +"%s: unable to process command line arguments\n" , argv[0 ]); +usage (argv[0 ]);exit (2 ); }
Signature · 1 line
2.42.0
Re: [PATCH v3 3/5] x86: Add usage() to print out usage message
Quoted 10 lines · Fouad Hilly
Refactor xen-ucode tool by adding
usage()to handle usage\help messages.
As we add more command options this will keep help\usage messages in a common block. Only generic error message is printed to stderr. usage andshow_curr_cpuare printed to stdout.Signed-off-by Fouad Hilly <[email protected]>---
[v3]
1- Reverted usage message.
2- Utilizedusage().
Quoted 4 lines
[v2]
1- Improved message description.
2- Fixed formatting and indentation.
3- Error message to print to stderr.
Already on v2 I pointed out that this change wasn't really done. And now, in v3, ...
Quoted 8 lines
tools/misc/xen-ucode.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)tools/misc/xen-ucode.c +0
-0
tools/misc/xen-ucode.c static xc_interface *xch; · line 25
Quoted 9 lines
tools/misc/xen-ucode.c +6
-0@@ -17,6 +17,13 @@ static xc_interface *xch;static const char intel_id[] ="GenuineIntel" ;static const char amd_id[] ="AuthenticAMD" ; +static void usage (const char *name) +{ +printf ("%s: Xen microcode updating tool\n" +"Usage: %s [<microcode file> | show-cpu-info]\n" , + name, name); +}
... you're still unconditionally printing to stdout, when ...
Quoted 4 lines
tools/misc/xen-ucode.c +0
-0static void show_curr_cpu (FILE *f) {int ret;
tools/misc/xen-ucode.c int main(int argc, char *argv[]) · line 102
Quoted 10 lines
tools/misc/xen-ucode.c +2
-3@@ -89,9 +96,8 @@ int main(int argc, char *argv[])if ( argc <2 ) {fprintf (stderr, -"xen-ucode: Xen microcode updating tool\n" -"Usage: %s [<microcode file> | show-cpu-info]\n" , argv[0 ]); -show_curr_cpu (stderr); +"%s: unable to process command line arguments\n" , argv[0 ]); +usage (argv[0 ]);exit (2 ); }
... originally the usage message (correctly) went to stderr in this case. It ought to go to stdout only in response to something like a --help command line option.
Jan
Re: [PATCH v3 3/5] x86: Add usage() to print out usage message
Quoted 12 lines · Jan Beulich
Quoted 10 lines · Fouad Hilly
Refactor xen-ucode tool by adding
usage()to handle usage\help messages.
As we add more command options this will keep help\usage messages in a common block. Only generic error message is printed to stderr. usage andshow_curr_cpuare printed to stdout.Signed-off-by Fouad Hilly <[email protected]>---
[v3]
1- Reverted usage message.
2- Utilizedusage().
Quoted 8 lines
Quoted 4 lines
[v2]
1- Improved message description.
2- Fixed formatting and indentation.
3- Error message to print to stderr.Already on v2 I pointed out that this change wasn't really done. And now, in v3, ...
In V4 all printing within ext_err path will be printed to stder
Quoted 40 lines
Quoted 8 lines
tools/misc/xen-ucode.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)tools/misc/xen-ucode.c +0
-0tools/misc/xen-ucode.c static xc_interface *xch; · line 25
Quoted 9 lines
tools/misc/xen-ucode.c +6
-0@@ -17,6 +17,13 @@ static xc_interface *xch;static const char intel_id[] ="GenuineIntel" ;static const char amd_id[] ="AuthenticAMD" ; +static void usage (const char *name) +{ +printf ("%s: Xen microcode updating tool\n" +"Usage: %s [<microcode file> | show-cpu-info]\n" , + name, name); +}... you're still unconditionally printing to stdout, when ...
Quoted 4 lines
tools/misc/xen-ucode.c +0
-0static void show_curr_cpu (FILE *f) {int ret;tools/misc/xen-ucode.c int main(int argc, char *argv[]) · line 102
Quoted 10 lines
tools/misc/xen-ucode.c +2
-3@@ -89,9 +96,8 @@ int main(int argc, char *argv[])if ( argc <2 ) {fprintf (stderr, -"xen-ucode: Xen microcode updating tool\n" -"Usage: %s [<microcode file> | show-cpu-info]\n" , argv[0 ]); -show_curr_cpu (stderr); +"%s: unable to process command line arguments\n" , argv[0 ]); +usage (argv[0 ]);exit (2 ); }... originally the usage message (correctly) went to stderr in this case. It ought to go to stdout only in response to something like a --help command line option.
Jan
PATCH v3 4/5 x86: Use getopt to handle command line args
In reply to Fouad HillyUse getopt_long() to handle command line arguments. Introduce ext_err for common exit with errors.
---
[v3]
1- Exit with error prints erros only to stderr.
2- Remove argc checks.
3- Utilize optind.
[v2]
1- Removed unnecessary NULL initialization.
2- Used static at the beginning of type struct declaration. 3- Corrected switch\case indentations.
4- Removed redundant checks.
5- Corrected label indentation.
tools/misc/xen-ucode.c | 45 +++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 12 deletions(-)
tools/misc/xen-ucode.c +33 -12
@@ -11,6 +11,7 @@#include <sys/stat.h> #include <fcntl.h> #include <xenctrl.h> +#include <getopt.h> static xc_interface *xch;
@@ -20,7 +21,10 @@ static const char amd_id[] = "AuthenticAMD";static void usage (const char *name) {printf ("%s: Xen microcode updating tool\n" -"Usage: %s [<microcode file> | show-cpu-info]\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); }
@@ -84,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 )
@@ -93,21 +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, -"%s: unable to process command line arguments\n" , argv[0 ]); -usage (argv[0 ]); -exit (2 ); +switch (opt) + { +case 'h' : +usage (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 ) {
@@ -149,4 +164,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 (argv[0 ]); +exit (EXIT_FAILURE ); }
Signature · 1 line
2.42.0
Re: [PATCH v3 4/5] x86: Use getopt to handle command line args
Quoted 4 lines · Fouad Hilly
Use
getopt_long()to handle command line arguments. Introduceext_errfor common exit with errors.Signed-off-by Fouad Hilly <[email protected]>
Nit: Neither subject nor description make clear ...
Quoted 2 lines
tools/misc/xen-ucode.c | 45 +++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 12 deletions(-)
... what tool is actually being touched.
Jan
Re: [PATCH v3 4/5] x86: Use getopt to handle command line args
Quoted 5 lines · Jan Beulich
Quoted 3 lines · Fouad Hilly
Use
getopt_long()to handle command line arguments. Introduceext_errfor common exit with errors.
Quoted 8 lines
Quoted 1 line
Signed-off-by Fouad Hilly <[email protected]>Nit: Neither subject nor description make clear ...
Quoted 2 lines
tools/misc/xen-ucode.c | 45 +++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 12 deletions(-)... what tool is actually being touched.
Noted and will be fixed in V4
Quoted 2 lines
Jan
PATCH v3 5/5 Add --force option to xen-ucode to override 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.xc_microcode_update() refactored to accept flags and utilize xenpf_microcode_update2
---
[v3]
1- Message description updated.
2- xc_microcode_update() uses xenpf_microcode_update2 to pass flags.
[v2]
1- Changed data type from uint32_t to unsigned int.
2- Corrected line length.
3- Removed XENPF_UCODE_FLAG_FORCE_NOT_SET.
4- Corrected indentations.
5- Changed command line options to have the file name as first argument when applicable. 6- --force option doesn't require an argument anymore.
7- Used optint to access filename in argv.
tools/include/xenctrl.h | 3 ++- tools/libs/ctrl/xc_misc.c | 12 +++++++----- tools/misc/xen-ucode.c | 16 ++++++++++++---- 3 files changed, 21 insertions(+), 10 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 -4
@@ -13,6 +13,8 @@#include <xenctrl.h> #include <getopt.h> +#include <xen/platform.h> +static xc_interface *xch;static const char intel_id[] ="GenuineIntel" ;
@@ -21,10 +23,11 @@ static const char amd_id[] = "AuthenticAMD";static void usage (const char *name) {printf ("%s: Xen microcode updating tool\n" -"Usage: %s [<microcode file> | Options]\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" , +" -s, --show-cpu-info show CPU information and exit\n" +" -f, --force force to skip micorocde 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_flag =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_flag =XENPF_UCODE_FLAG_FORCE_SET ; +break ;default : goto ext_err; }
@@ -146,7 +154,7 @@ int main(int argc, char *argv[])exit (1 ); } - ret =xc_microcode_update (xch, buf, len); + ret =xc_microcode_update (xch, buf, len, ucode_flag);if ( ret ) { fprintf(stderr, "Failed to update microcode. (err: %s)\n",
Signature · 1 line
2.42.0
Re: [PATCH v3 5/5] Add --force option to xen-ucode to override microcode version check
tools/misc/xen-ucode.c static const char amd_id[] = "AuthenticAMD"; · line 30
Quoted 11 lines · Fouad Hilly
tools/misc/xen-ucode.c +3
-2@@ -21,10 +23,11 @@ static const char amd_id[] = "AuthenticAMD";static void usage (const char *name) { printf("%s: Xen microcode updating tool\n" - "Usage: %s [<microcode file> | Options]\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", + " -s, --show-cpu-info show CPU information and exit\n" + " -f, --force force to skip micorocde version check\n",
Besides (nit) the typo, isn't "version check" too broad here? Elsewhere in the series you mention Intel's "min_rev" addition. _That_ kind of version check probably shouldn't be permitted to skip? In which case maybe better "certain version checking" or some such?
Jan
Re: [PATCH v3 5/5] Add --force option to xen-ucode to override microcode version check
Quoted 18 lines · Jan Beulich
tools/misc/xen-ucode.c static const char amd_id[] = "AuthenticAMD"; · line 30
Quoted 11 lines · Fouad Hilly
tools/misc/xen-ucode.c +3
-2@@ -21,10 +23,11 @@ static const char amd_id[] = "AuthenticAMD";static void usage (const char *name) { printf("%s: Xen microcode updating tool\n" - "Usage: %s [<microcode file> | Options]\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", + " -s, --show-cpu-info show CPU information and exit\n" + " -f, --force force to skip micorocde version check\n",Besides (nit) the typo, isn't "version check" too broad here? Elsewhere in the series you mention Intel's "
min_rev" addition. _That_ kind of version check probably shouldn't be permitted to skip? In which case maybe better "certain version checking" or some such?
I will remove "min_rev" mention from this patch series. The main reason for this change is to allow developers to downgrade microcode.
Quoted 2 lines
Jan