From: Andrew Cooper Date: Mon, 26 Oct 2020 15:32:12 +0000 (+0000) Subject: x86/ucode: Introduce ucode=allow-same for testing purposes X-Git-Tag: 4.15.0-rc1~166 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=6677b5a3577c16501fbc51a3341446905bd21c38;p=xen.git x86/ucode: Introduce ucode=allow-same for testing purposes Many CPUs will actually reload microcode when offered the same version as currently loaded. This allows for easy testing of the late microcode loading path. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line.pandoc index a713a0535c..4737c92bfe 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -2269,7 +2269,7 @@ logic applies: active by default. ### ucode -> `= List of [ | scan=, nmi= ]` +> `= List of [ | scan=, nmi=, allow-same= ]` Applicability: x86 Default: `nmi` @@ -2301,6 +2301,11 @@ 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) > `= ` diff --git a/xen/arch/x86/cpu/microcode/amd.c b/xen/arch/x86/cpu/microcode/amd.c index 7d2f57c4cb..5255028af7 100644 --- a/xen/arch/x86/cpu/microcode/amd.c +++ b/xen/arch/x86/cpu/microcode/amd.c @@ -174,6 +174,9 @@ static enum microcode_match_result compare_revisions( if ( new_rev > old_rev ) return NEW_UCODE; + if ( opt_ucode_allow_same && new_rev == old_rev ) + return NEW_UCODE; + return OLD_UCODE; } diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode/core.c index 18ebc07b13..ac3ceb567c 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -95,6 +95,8 @@ static bool_t __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; @@ -121,6 +123,8 @@ static int __init 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 ) diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcode/intel.c index 5fa2821cdb..f6d01490e0 100644 --- a/xen/arch/x86/cpu/microcode/intel.c +++ b/xen/arch/x86/cpu/microcode/intel.c @@ -232,6 +232,9 @@ static enum microcode_match_result compare_revisions( if ( new_rev > old_rev ) return NEW_UCODE; + if ( opt_ucode_allow_same && new_rev == old_rev ) + return NEW_UCODE; + /* * Treat pre-production as always applicable - anyone using pre-production * microcode knows what they are doing, and can keep any resulting pieces. diff --git a/xen/arch/x86/cpu/microcode/private.h b/xen/arch/x86/cpu/microcode/private.h index 9a15cdc879..c085a10268 100644 --- a/xen/arch/x86/cpu/microcode/private.h +++ b/xen/arch/x86/cpu/microcode/private.h @@ -3,6 +3,8 @@ #include +extern bool opt_ucode_allow_same; + enum microcode_match_result { OLD_UCODE, /* signature matched, but revision id is older or equal */ NEW_UCODE, /* signature matched, but revision id is newer */