Skip to contentSkip to conversation

x86/ucode: Cmdline fixes/improvements

PATCH Superseded Andrew Cooper 2 participants 9 messages Feb 25, 2025 – Feb 27, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover x86/ucode: Cmdline fixes/improvements

Yet more fixes from the overhaul. This fixes cmdline parsing, rewrites the cmdline docs for clarity, then drops a cmdline option which is of dubious value.

No practical change.

Andrew Cooper (2):
x86/ucode: Adjust parse_ucode() to match other list handling x86/ucode: Drop the ucode=nmi option

 docs/misc/xen-command-line.pandoc | 64 ++++++++++++++++---------------
 xen/arch/x86/cpu/microcode/core.c | 58 +++++++++++++---------------
 2 files changed, 61 insertions(+), 61 deletions(-)
Signature · 1 line
2.39.5
#1 lore raw

PATCH 1/2 x86/ucode: Adjust parse_ucode() to match other list handling

parse_ucode() is abnormal compared to similar parsing elsewhere in Xen.

Invert the ucode_mod_forced check with respect to the "scan" and integer handling, so we can warn the user when we've elected to ignore the parameters, and yield -EINVAL for any unrecognised list element.

Rewrite the ucode= command line docs for clarity.

No practical change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 docs/misc/xen-command-line.pandoc | 56 ++++++++++++++++++-------------
 xen/arch/x86/cpu/microcode/core.c | 22 ++++++++----
 2 files changed, 47 insertions(+), 31 deletions(-)
docs/misc/xen-command-line.pandoc +32 -24
index 0c6225391d55..47674025249a 100644
@@ -2721,34 +2721,42 @@ performance.
    Alternatively, selecting `tsx=1` will re-enable TSX at the users own risk.
 
 ### ucode
-> `= List of [ <integer> | scan=<bool>, nmi=<bool> ]`
+> `= List of [ <integer>, scan=<bool>, nmi=<bool> ]`
 
     Applicability: x86
     Default: `scan` is selectable via Kconfig, `nmi=true`
 
-Controls for CPU microcode loading. For early loading, this parameter can
-specify how and where to find the microcode update blob. For late loading,
-this parameter specifies if the update happens within a NMI handler.
-
-'integer' specifies the CPU microcode update blob module index. When positive,
-this specifies the n-th module (in the GrUB entry, zero based) to be used
-for updating CPU micrcode. When negative, counting starts at the end of
-the modules in the GrUB entry (so with the blob commonly being last,
-one could specify `ucode=-1`). Note that the value of zero is not valid
-here (entry zero, i.e. the first module, is always the Dom0 kernel
-image). Note further that use of this option has an unspecified effect
-when used with xen.efi (there the concept of modules doesn't exist, and
-the blob gets specified via the `ucode=<filename>` config file/section
-entry; see [EFI configuration file description](efi.html)).
-
-'scan' instructs the hypervisor to scan the multiboot images for an cpio
-image that contains microcode. Depending on the platform the blob with the
-microcode in the cpio name space must be:
-  - on Intel: kernel/x86/microcode/GenuineIntel.bin
-  - on AMD  : kernel/x86/microcode/AuthenticAMD.bin
-When using xen.efi, the `ucode=<filename>` config file setting takes
-precedence over `scan`. The default value for `scan` is set with
-`CONFIG_UCODE_SCAN_DEFAULT`.
+Controls for CPU microcode loading.
+
+In order to load microcode at boot, Xen needs to find a suitable update
+amongst the modules provided by the bootloader.  Two kinds of microcode update
+are supported:
+
+ 1. Raw microcode containers.  The format of the container is CPU vendor
+    specific.
+
+ 2. CPIO archive.  This is Linux's preferred mechanism, and involves having
+    the raw containers expressed as files
+    (e.g. `kernel/x86/microcode/{GenuineIntel,AuthenticAMD}.bin`) in a CPIO
+    archive, typically prepended to the initrd.
+
+The `<integer>` and `scan=` options are mutually exclusive and select between
+these two options.  They are also invalid in EFI boots (see below).
+
+ *  The `<integer>` option nominates a specific multiboot module as a raw
+    container (option 1 above).  Valid options start from 1 (module 0 is
+    always the dom0 kernel).  A negative number may be used, and will
+    back-reference from the end of the module list.  i.e. `ucode=-1` will
+    nominate the final multiboot module.
+
+ *  The `scan=` option causes Xen to search all modules in order to find the
+    first CPIO archive containing the appropriate file (option 2 above).  The
+    default for this option can be chosen at build time via
+    `CONFIG_UCODE_SCAN_DEFAULT`.
+
+When booting xen.efi natively, the concept of multiboot modules doesn't exist.
+Instead, in the [EFI configuration file](efi.html), `ucode=<filename>` can be
+used to identify a file as a raw container (option 1 above).
 
 'nmi' determines late loading is performed in NMI handler or just in
 stop_machine context. In NMI handler, even NMIs are blocked, which is
xen/arch/x86/cpu/microcode/core.c +15 -7
index de00c22b4bd6..c8e14ed9b10c 100644
@@ -113,11 +113,6 @@ void __init microcode_set_module(unsigned int idx)
     ucode_mod_forced = 1;
 }
 
-/*
- * The format is '[<integer>|scan=<bool>, nmi=<bool>]'. Both options are
- * optional. If the EFI has forced which of the multiboot payloads is to be
- * used, only nmi=<bool> is parsed.
- */
 static int __init cf_check parse_ucode(const char *s)
 {
     const char *ss;
@@ -130,13 +125,24 @@ static int __init cf_check parse_ucode(const char *s)
 
         if ( (val = parse_boolean("nmi", s, ss)) >= 0 )
             ucode_in_nmi = val;
-        else if ( !ucode_mod_forced ) /* Not forced by EFI */
+        else if ( (val = parse_boolean("scan", s, ss)) >= 0 )
         {
-            if ( (val = parse_boolean("scan", s, ss)) >= 0 )
+            if ( ucode_mod_forced )
+                printk(XENLOG_WARNING
+                       "Ignoring ucode=%.*s setting; overridden by EFI\n",
+                       (int)(ss - s), s);
+            else
             {
                 opt_scan = val;
                 opt_mod_idx = 0;
             }
+        }
+        else if ( isdigit(s[0]) || s[0] == '-' )
+        {
+            if ( ucode_mod_forced )
+                printk(XENLOG_WARNING
+                       "Ignoring ucode=%.*s setting; overridden by EFI\n",
+                       (int)(ss - s), s);
             else
             {
                 const char *q;
@@ -151,6 +157,8 @@ static int __init cf_check parse_ucode(const char *s)
                     opt_scan = false;
             }
         }
+        else
+            rc = -EINVAL;
 
         s = ss + 1;
     } while ( *ss );
Signature · 1 line
2.39.5
#2 lore raw

Re: [PATCH 1/2] x86/ucode: Adjust parse_ucode() to match other list handling

docs/misc/xen-command-line.pandoc performance. · line 2724

Quoted 8 lines · Andrew Cooper
docs/misc/xen-command-line.pandoc +1 -1
@@ -2721,34 +2721,42 @@ performance.
    Alternatively, selecting `tsx=1` will re-enable TSX at the users own risk.
 
 ### ucode
-> `= List of [ <integer> | scan=<bool>, nmi=<bool> ]`
+> `= List of [ <integer>, scan=<bool>, nmi=<bool> ]`

While this makes doc fit present behavior, it is the behavior that is wrong. It was - afaict - broken by 5ed12565aa32 ("microcode: rendezvous CPUs in NMI handler and load ucode"). There should not be both an integer and "scan=". (Really we should have taken measures to stay consistent even if multiple "ucode=" were on the command line.) You actually say so ...

Quoted 32 lines
docs/misc/xen-command-line.pandoc +6 -23
     Applicability: x86
     Default: `scan` is selectable via Kconfig, `nmi=true`
 
-Controls for CPU microcode loading. For early loading, this parameter can
-specify how and where to find the microcode update blob. For late loading,
-this parameter specifies if the update happens within a NMI handler.
-
-'integer' specifies the CPU microcode update blob module index. When positive,
-this specifies the n-th module (in the GrUB entry, zero based) to be used
-for updating CPU micrcode. When negative, counting starts at the end of
-the modules in the GrUB entry (so with the blob commonly being last,
-one could specify `ucode=-1`). Note that the value of zero is not valid
-here (entry zero, i.e. the first module, is always the Dom0 kernel
-image). Note further that use of this option has an unspecified effect
-when used with xen.efi (there the concept of modules doesn't exist, and
-the blob gets specified via the `ucode=<filename>` config file/section
-entry; see [EFI configuration file description](efi.html)).
-
-'scan' instructs the hypervisor to scan the multiboot images for an cpio
-image that contains microcode. Depending on the platform the blob with the
-microcode in the cpio name space must be:
-  - on Intel: kernel/x86/microcode/GenuineIntel.bin
-  - on AMD  : kernel/x86/microcode/AuthenticAMD.bin
-When using xen.efi, the `ucode=<filename>` config file setting takes
-precedence over `scan`. The default value for `scan` is set with
-`CONFIG_UCODE_SCAN_DEFAULT`.
+Controls for CPU microcode loading.
+
+In order to load microcode at boot, Xen needs to find a suitable update
+amongst the modules provided by the bootloader.  Two kinds of microcode update
+are supported:
+

docs/misc/xen-command-line.pandoc performance. · line 2744

Quoted 10 lines
docs/misc/xen-command-line.pandoc +10 -0
+ 1. Raw microcode containers.  The format of the container is CPU vendor
+    specific.
+
+ 2. CPIO archive.  This is Linux's preferred mechanism, and involves having
+    the raw containers expressed as files
+    (e.g. `kernel/x86/microcode/{GenuineIntel,AuthenticAMD}.bin`) in a CPIO
+    archive, typically prepended to the initrd.
+
+The `<integer>` and `scan=` options are mutually exclusive and select between
+these two options.  They are also invalid in EFI boots (see below).

... here.

As to EFI boots: "scan=" ought to be usable there, as long as no "ucode=" was in the xen.efi config file. I think your code is correct in this regard, it's just the wording here which is too strict.

xen/arch/x86/cpu/microcode/core.c void __init microcode_set_module(unsigned int idx) · line 117

Quoted 8 lines
xen/arch/x86/cpu/microcode/core.c +0 -2
@@ -113,11 +113,6 @@ void __init microcode_set_module(unsigned int idx)
     ucode_mod_forced = 1;
 }
 
-/*
- * The format is '[<integer>|scan=<bool>, nmi=<bool>]'.

While personally I don't mind the removal, I think back at the time it was specifically asked to (also) put it here.

Jan

#3 lore raw

Re: [PATCH 1/2] x86/ucode: Adjust parse_ucode() to match other list handling

Quoted 6 lines · Jan Beulich
Quoted 5 lines · Andrew Cooper
docs/misc/xen-command-line.pandoc +0 -0
@@ -2721,34 +2721,42 @@ performance.
    Alternatively, selecting `tsx=1` will re-enable TSX at the users own risk.
 
Quoted 8 lines

docs/misc/xen-command-line.pandoc performance. · line 2724

Quoted 3 lines
docs/misc/xen-command-line.pandoc +1 -1
 ### ucode
-> `= List of [ <integer> | scan=<bool>, nmi=<bool> ]`
+> `= List of [ <integer>, scan=<bool>, nmi=<bool> ]`

While this makes doc fit present behavior, it is the behavior that is wrong. It was - afaict - broken by 5ed12565aa32 ("microcode: rendezvous CPUs in NMI handler and load ucode"). There should not be both an integer and "scan=". (Really we should have taken measures to stay consistent even if multiple "ucode=" were on the command line.) You actually say so ...

Yes that changed commit changed the behaviour.  We discussed it during c25c964634b1 ("x86/ucode: Enforce invariant about module selection").

"Wrong" is more complicated.  Neither behaviour is great, but we need regular comma separated operations.  (I know I'm deleting nmi= in the next patch but I need to introduce a new one for the AMD fix).

In the presence of comma separated options, one part being <integer> | scan=<bool> is pointless, because ucode=1,1,1 is valid, as is ucode=scan,scan,scan, and then all you've got is an overly complicated description of what is identical to other regular list operations.

For this corner case, it's simply easier to tell the user "don't do that", which is what we say elsewhere too.

Quoted 45 lines
Quoted 33 lines
docs/misc/xen-command-line.pandoc +6 -23
     Applicability: x86
     Default: `scan` is selectable via Kconfig, `nmi=true`
 
-Controls for CPU microcode loading. For early loading, this parameter can
-specify how and where to find the microcode update blob. For late loading,
-this parameter specifies if the update happens within a NMI handler.
-
-'integer' specifies the CPU microcode update blob module index. When positive,
-this specifies the n-th module (in the GrUB entry, zero based) to be used
-for updating CPU micrcode. When negative, counting starts at the end of
-the modules in the GrUB entry (so with the blob commonly being last,
-one could specify `ucode=-1`). Note that the value of zero is not valid
-here (entry zero, i.e. the first module, is always the Dom0 kernel
-image). Note further that use of this option has an unspecified effect
-when used with xen.efi (there the concept of modules doesn't exist, and
-the blob gets specified via the `ucode=<filename>` config file/section
-entry; see [EFI configuration file description](efi.html)).
-
-'scan' instructs the hypervisor to scan the multiboot images for an cpio
-image that contains microcode. Depending on the platform the blob with the
-microcode in the cpio name space must be:
-  - on Intel: kernel/x86/microcode/GenuineIntel.bin
-  - on AMD  : kernel/x86/microcode/AuthenticAMD.bin
-When using xen.efi, the `ucode=<filename>` config file setting takes
-precedence over `scan`. The default value for `scan` is set with
-`CONFIG_UCODE_SCAN_DEFAULT`.
+Controls for CPU microcode loading.
+
+In order to load microcode at boot, Xen needs to find a suitable update
+amongst the modules provided by the bootloader.  Two kinds of microcode update
+are supported:
+

docs/misc/xen-command-line.pandoc performance. · line 2744

Quoted 10 lines
docs/misc/xen-command-line.pandoc +10 -0
+ 1. Raw microcode containers.  The format of the container is CPU vendor
+    specific.
+
+ 2. CPIO archive.  This is Linux's preferred mechanism, and involves having
+    the raw containers expressed as files
+    (e.g. `kernel/x86/microcode/{GenuineIntel,AuthenticAMD}.bin`) in a CPIO
+    archive, typically prepended to the initrd.
+
+The `<integer>` and `scan=` options are mutually exclusive and select between
+these two options.  They are also invalid in EFI boots (see below).

... here.

Quoted 3 lines

As to EFI boots: "scan=" ought to be usable there, as long as no "ucode=" was in the xen.efi config file. I think your code is correct in this regard, it's just the wording here which is too strict.

There's still a sharp corner trying that, which is why I didn't address it.

With EFI, there's no order of modules, so scan is still ambiguous if you've got multiple CPIO archives.

Quoted 11 lines

xen/arch/x86/cpu/microcode/core.c void __init microcode_set_module(unsigned int idx) · line 117

Quoted 9 lines
xen/arch/x86/cpu/microcode/core.c +0 -2
@@ -113,11 +113,6 @@ void __init microcode_set_module(unsigned int idx)
     ucode_mod_forced = 1;
 }
 
-/*
- * The format is '[<integer>|scan=<bool>, nmi=<bool>]'.

While personally I don't mind the removal, I think back at the time it was specifically asked to (also) put it here.

It was stale for the whole time of allow-same=<bool>.  This patch was originally part of the post-"--force" cleanup series, but I deferred it because of the unanticipated fixes required for the boot module changes.

~Andrew

#4 lore raw

Re: [PATCH 1/2] x86/ucode: Adjust parse_ucode() to match other list handling

Quoted 23 lines · Andrew Cooper
Quoted 6 lines · Jan Beulich
Quoted 5 lines · Andrew Cooper
docs/misc/xen-command-line.pandoc +0 -0
@@ -2721,34 +2721,42 @@ performance.
    Alternatively, selecting `tsx=1` will re-enable TSX at the users own risk.
 
Quoted 8 lines

docs/misc/xen-command-line.pandoc performance. · line 2724

Quoted 3 lines
docs/misc/xen-command-line.pandoc +1 -1
 ### ucode
-> `= List of [ <integer> | scan=<bool>, nmi=<bool> ]`
+> `= List of [ <integer>, scan=<bool>, nmi=<bool> ]`

While this makes doc fit present behavior, it is the behavior that is wrong. It was - afaict - broken by 5ed12565aa32 ("microcode: rendezvous CPUs in NMI handler and load ucode"). There should not be both an integer and "scan=". (Really we should have taken measures to stay consistent even if multiple "ucode=" were on the command line.) You actually say so ...

Yes that changed commit changed the behaviour.  We discussed it during c25c964634b1 ("x86/ucode: Enforce invariant about module selection").

"Wrong" is more complicated.  Neither behaviour is great, but we need regular comma separated operations.  (I know I'm deleting nmi= in the next patch but I need to introduce a new one for the AMD fix).

Quoted 7 lines

In the presence of comma separated options, one part being <integer> | scan=<bool> is pointless, because ucode=1,1,1 is valid, as is ucode=scan,scan,scan, and then all you've got is an overly complicated description of what is identical to other regular list operations.

For this corner case, it's simply easier to tell the user "don't do that", which is what we say elsewhere too.

Hmm, while I don't like this, I'll accept it.

Quoted 44 lines
Quoted 44 lines
Quoted 32 lines
docs/misc/xen-command-line.pandoc +6 -23
     Applicability: x86
     Default: `scan` is selectable via Kconfig, `nmi=true`
 
-Controls for CPU microcode loading. For early loading, this parameter can
-specify how and where to find the microcode update blob. For late loading,
-this parameter specifies if the update happens within a NMI handler.
-
-'integer' specifies the CPU microcode update blob module index. When positive,
-this specifies the n-th module (in the GrUB entry, zero based) to be used
-for updating CPU micrcode. When negative, counting starts at the end of
-the modules in the GrUB entry (so with the blob commonly being last,
-one could specify `ucode=-1`). Note that the value of zero is not valid
-here (entry zero, i.e. the first module, is always the Dom0 kernel
-image). Note further that use of this option has an unspecified effect
-when used with xen.efi (there the concept of modules doesn't exist, and
-the blob gets specified via the `ucode=<filename>` config file/section
-entry; see [EFI configuration file description](efi.html)).
-
-'scan' instructs the hypervisor to scan the multiboot images for an cpio
-image that contains microcode. Depending on the platform the blob with the
-microcode in the cpio name space must be:
-  - on Intel: kernel/x86/microcode/GenuineIntel.bin
-  - on AMD  : kernel/x86/microcode/AuthenticAMD.bin
-When using xen.efi, the `ucode=<filename>` config file setting takes
-precedence over `scan`. The default value for `scan` is set with
-`CONFIG_UCODE_SCAN_DEFAULT`.
+Controls for CPU microcode loading.
+
+In order to load microcode at boot, Xen needs to find a suitable update
+amongst the modules provided by the bootloader.  Two kinds of microcode update
+are supported:
+

docs/misc/xen-command-line.pandoc performance. · line 2744

Quoted 10 lines
docs/misc/xen-command-line.pandoc +10 -0
+ 1. Raw microcode containers.  The format of the container is CPU vendor
+    specific.
+
+ 2. CPIO archive.  This is Linux's preferred mechanism, and involves having
+    the raw containers expressed as files
+    (e.g. `kernel/x86/microcode/{GenuineIntel,AuthenticAMD}.bin`) in a CPIO
+    archive, typically prepended to the initrd.
+
+The `<integer>` and `scan=` options are mutually exclusive and select between
+these two options.  They are also invalid in EFI boots (see below).

... here.

Quoted 8 lines
Quoted 3 lines

As to EFI boots: "scan=" ought to be usable there, as long as no "ucode=" was in the xen.efi config file. I think your code is correct in this regard, it's just the wording here which is too strict.

There's still a sharp corner trying that, which is why I didn't address it.

With EFI, there's no order of modules, so scan is still ambiguous if you've got multiple CPIO archives.

Is it? In the config file only one "ramdisk=" is permitted per section. (Or to be more precise, subsequent ones in the same section simply will be ignored. Like is the case for other similar settings, like "kernel=".)

Jan

#5 lore raw

PATCH 2/2 x86/ucode: Drop the ucode=nmi option

In reply to Andrew Cooper

This option is active by default, and despite what the documentation suggests about choosing ucode=no-nmi, it only controls whether the primary threads move into NMI context.

Sibling threads unconditionally move into NMI context, which is confirmed by an in-code comment.

Not discussed is the fact that the BSP never enters NMI context, which works only by luck (AMD CPUs, where we reload on sibling threads too, has working in-core rendezvous and doesn't require NMI cover on the primary thread for safety). This does want addressing, but requires more untangling first.

Overall, ucode=no-nmi is a misleading and pretty useless option. Drop it, and simplify the two users.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>

Despite the reasonably large diff in primary_thread_fn(), it's mostly just unindenting the block, and dropping the final call to primary_thread_work() which is made dead by this change.

---
 docs/misc/xen-command-line.pandoc |  8 ++-----
 xen/arch/x86/cpu/microcode/core.c | 38 +++++++++++--------------------
 2 files changed, 15 insertions(+), 31 deletions(-)
docs/misc/xen-command-line.pandoc +2 -6
index 47674025249a..9702c36b8c39 100644
@@ -2721,10 +2721,10 @@ performance.
    Alternatively, selecting `tsx=1` will re-enable TSX at the users own risk.
 
 ### ucode
-> `= List of [ <integer>, scan=<bool>, nmi=<bool> ]`
+> `= List of [ <integer>, scan=<bool ]`
 
     Applicability: x86
-    Default: `scan` is selectable via Kconfig, `nmi=true`
+    Default: `scan` is selectable via Kconfig
 
 Controls for CPU microcode loading.
 
@@ -2758,10 +2758,6 @@ When booting xen.efi natively, the concept of multiboot modules doesn't exist.
 Instead, in the [EFI configuration file](efi.html), `ucode=<filename>` can be
 used to identify a file as a raw container (option 1 above).
 
-'nmi' determines late loading is performed in NMI handler or just in
-stop_machine context. In NMI handler, even NMIs are blocked, which is
-considered safer. The default value is `true`.
-
 ### unrestricted_guest (Intel)
 > `= <boolean>`
 
xen/arch/x86/cpu/microcode/core.c +13 -25
index c8e14ed9b10c..4898920b9c52 100644
@@ -82,9 +82,6 @@ struct patch_with_flags {
     const struct microcode_patch *patch;
 };
 
-/* By default, ucode loading is done in NMI handler */
-static bool ucode_in_nmi = true;
-
 /* Protected by microcode_mutex */
 static struct microcode_patch *microcode_cache;
 
@@ -123,9 +120,7 @@ static int __init cf_check parse_ucode(const char *s)
         if ( !ss )
             ss = strchr(s, '\0');
 
-        if ( (val = parse_boolean("nmi", s, ss)) >= 0 )
-            ucode_in_nmi = val;
-        else if ( (val = parse_boolean("scan", s, ss)) >= 0 )
+        if ( (val = parse_boolean("scan", s, ss)) >= 0 )
         {
             if ( ucode_mod_forced )
                 printk(XENLOG_WARNING
@@ -297,12 +292,10 @@ static int cf_check microcode_nmi_callback(
         return 0;
 
     /*
-     * Primary threads load ucode in NMI handler on if ucode_in_nmi is true.
-     * Secondary threads are expected to stay in NMI handler regardless of
-     * ucode_in_nmi.
+     * The BSP doesn't enter NMI context for microcode loading, as it's the
+     * entity organising the rendezvous.
      */
-    if ( cpu == cpumask_first(&cpu_online_map) ||
-         (!ucode_in_nmi && primary_cpu) )
+    if ( cpu == cpumask_first(&cpu_online_map) )
         return 0;
 
     if ( primary_cpu )
@@ -343,22 +336,17 @@ static int primary_thread_fn(const struct microcode_patch *patch,
     if ( !wait_for_state(LOADING_CALLIN) )
         return -EBUSY;
 
-    if ( ucode_in_nmi )
-    {
-        self_nmi();
-
-        /*
-         * Wait for ucode loading is done in case that the NMI does not arrive
-         * synchronously, which may lead to a not-yet-updated error is returned
-         * below.
-         */
-        if ( unlikely(!wait_for_state(LOADING_EXIT)) )
-            ASSERT_UNREACHABLE();
+    self_nmi();
 
-        return this_cpu(loading_err);
-    }
+    /*
+     * Wait for ucode loading is done in case that the NMI does not arrive
+     * synchronously, which may lead to a not-yet-updated error is returned
+     * below.
+     */
+    if ( unlikely(!wait_for_state(LOADING_EXIT)) )
+        ASSERT_UNREACHABLE();
 
-    return primary_thread_work(patch, flags);
+    return this_cpu(loading_err);
 }
 
 static int control_thread_fn(const struct microcode_patch *patch,
Signature · 1 line
2.39.5
#6 lore raw

Re: [PATCH 2/2] x86/ucode: Drop the ucode=nmi option

Quoted 33 lines · Andrew Cooper

This option is active by default, and despite what the documentation suggests about choosing ucode=no-nmi, it only controls whether the primary threads move into NMI context.

Sibling threads unconditionally move into NMI context, which is confirmed by an in-code comment.

Not discussed is the fact that the BSP never enters NMI context, which works only by luck (AMD CPUs, where we reload on sibling threads too, has working in-core rendezvous and doesn't require NMI cover on the primary thread for safety). This does want addressing, but requires more untangling first.

Overall, ucode=no-nmi is a misleading and pretty useless option. Drop it, and simplify the two users.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>

Despite the reasonably large diff in primary_thread_fn(), it's mostly just unindenting the block, and dropping the final call to primary_thread_work() which is made dead by this change.

---
 docs/misc/xen-command-line.pandoc |  8 ++-----
 xen/arch/x86/cpu/microcode/core.c | 38 +++++++++++--------------------
 2 files changed, 15 insertions(+), 31 deletions(-)
docs/misc/xen-command-line.pandoc +0 -0
index 47674025249a..9702c36b8c39 100644

docs/misc/xen-command-line.pandoc performance. · line 2724

Quoted 5 lines
docs/misc/xen-command-line.pandoc +1 -1
@@ -2721,10 +2721,10 @@ performance.
    Alternatively, selecting `tsx=1` will re-enable TSX at the users own risk.
 
 ### ucode
-> `= List of [ <integer>, scan=<bool>, nmi=<bool> ]`
+> `= List of [ <integer>, scan=<bool ]`

With this (taking my comment on patch 1 into account as well) I think ...

docs/misc/xen-command-line.pandoc static int __init cf_check parse_ucode(const char *s) · line 126

Quoted 11 lines
docs/misc/xen-command-line.pandoc +1 -3
@@ -123,9 +120,7 @@ static int __init cf_check parse_ucode(const char *s)
         if ( !ss )
             ss = strchr(s, '\0');
 
-        if ( (val = parse_boolean("nmi", s, ss)) >= 0 )
-            ucode_in_nmi = val;
-        else if ( (val = parse_boolean("scan", s, ss)) >= 0 )
+        if ( (val = parse_boolean("scan", s, ss)) >= 0 )
         {
             if ( ucode_mod_forced )
                 printk(XENLOG_WARNING

... this function will want to transition back to what it was prior to the addition of the sub-option, preferably adjusted to account for the possibility of multiple "ucode=" on the command line, i.e. along the lines of

    if ( !strncmp(s, "scan", 4) )
    {
        ucode_scan = 1;
        ucode_mod_idx = 0;
    }
    else
    {
        ucode_scan = 0;
        ucode_mod_idx = simple_strtol(s, &q, 0);
    }

That would then make patch 1 kind of unnecessary.

Jan

#7 lore raw

Re: [PATCH 2/2] x86/ucode: Drop the ucode=nmi option

Quoted 68 lines · Jan Beulich
Quoted 33 lines · Andrew Cooper

This option is active by default, and despite what the documentation suggests about choosing ucode=no-nmi, it only controls whether the primary threads move into NMI context.

Sibling threads unconditionally move into NMI context, which is confirmed by an in-code comment.

Not discussed is the fact that the BSP never enters NMI context, which works only by luck (AMD CPUs, where we reload on sibling threads too, has working in-core rendezvous and doesn't require NMI cover on the primary thread for safety). This does want addressing, but requires more untangling first.

Overall, ucode=no-nmi is a misleading and pretty useless option. Drop it, and simplify the two users.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>

Despite the reasonably large diff in primary_thread_fn(), it's mostly just unindenting the block, and dropping the final call to primary_thread_work() which is made dead by this change.

---
 docs/misc/xen-command-line.pandoc |  8 ++-----
 xen/arch/x86/cpu/microcode/core.c | 38 +++++++++++--------------------
 2 files changed, 15 insertions(+), 31 deletions(-)
docs/misc/xen-command-line.pandoc +0 -0
index 47674025249a..9702c36b8c39 100644

docs/misc/xen-command-line.pandoc performance. · line 2724

Quoted 5 lines
docs/misc/xen-command-line.pandoc +1 -1
@@ -2721,10 +2721,10 @@ performance.
    Alternatively, selecting `tsx=1` will re-enable TSX at the users own risk.
 
 ### ucode
-> `= List of [ <integer>, scan=<bool>, nmi=<bool> ]`
+> `= List of [ <integer>, scan=<bool ]`

With this (taking my comment on patch 1 into account as well) I think ...

docs/misc/xen-command-line.pandoc static int __init cf_check parse_ucode(const char *s) · line 126

Quoted 11 lines
docs/misc/xen-command-line.pandoc +1 -3
@@ -123,9 +120,7 @@ static int __init cf_check parse_ucode(const char *s)
         if ( !ss )
             ss = strchr(s, '\0');
 
-        if ( (val = parse_boolean("nmi", s, ss)) >= 0 )
-            ucode_in_nmi = val;
-        else if ( (val = parse_boolean("scan", s, ss)) >= 0 )
+        if ( (val = parse_boolean("scan", s, ss)) >= 0 )
         {
             if ( ucode_mod_forced )
                 printk(XENLOG_WARNING

... this function will want to transition back to what it was prior to the addition of the sub-option, preferably adjusted to account for the possibility of multiple "ucode=" on the command line, i.e. along the lines of

    if ( !strncmp(s, "scan", 4) )
    {
        ucode_scan = 1;
        ucode_mod_idx = 0;
    }
    else
    {
        ucode_scan = 0;
        ucode_mod_idx = simple_strtol(s, &q, 0);
    }
Quoted 1 line

That would then make patch 1 kind of unnecessary.

As said, I need to introduce a new option for the AMD fix, so it needs to stay comma-separated.

~Andrew

Reviewed-by
#8 lore raw

Re: [PATCH 2/2] x86/ucode: Drop the ucode=nmi option

Quoted 69 lines · Andrew Cooper
Quoted 68 lines · Jan Beulich
Quoted 33 lines · Andrew Cooper

This option is active by default, and despite what the documentation suggests about choosing ucode=no-nmi, it only controls whether the primary threads move into NMI context.

Sibling threads unconditionally move into NMI context, which is confirmed by an in-code comment.

Not discussed is the fact that the BSP never enters NMI context, which works only by luck (AMD CPUs, where we reload on sibling threads too, has working in-core rendezvous and doesn't require NMI cover on the primary thread for safety). This does want addressing, but requires more untangling first.

Overall, ucode=no-nmi is a misleading and pretty useless option. Drop it, and simplify the two users.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>

Despite the reasonably large diff in primary_thread_fn(), it's mostly just unindenting the block, and dropping the final call to primary_thread_work() which is made dead by this change.

---
 docs/misc/xen-command-line.pandoc |  8 ++-----
 xen/arch/x86/cpu/microcode/core.c | 38 +++++++++++--------------------
 2 files changed, 15 insertions(+), 31 deletions(-)
docs/misc/xen-command-line.pandoc +0 -0
index 47674025249a..9702c36b8c39 100644

docs/misc/xen-command-line.pandoc performance. · line 2724

Quoted 5 lines
docs/misc/xen-command-line.pandoc +1 -1
@@ -2721,10 +2721,10 @@ performance.
    Alternatively, selecting `tsx=1` will re-enable TSX at the users own risk.
 
 ### ucode
-> `= List of [ <integer>, scan=<bool>, nmi=<bool> ]`
+> `= List of [ <integer>, scan=<bool ]`

With this (taking my comment on patch 1 into account as well) I think ...

docs/misc/xen-command-line.pandoc static int __init cf_check parse_ucode(const char *s) · line 126

Quoted 11 lines
docs/misc/xen-command-line.pandoc +1 -3
@@ -123,9 +120,7 @@ static int __init cf_check parse_ucode(const char *s)
         if ( !ss )
             ss = strchr(s, '\0');
 
-        if ( (val = parse_boolean("nmi", s, ss)) >= 0 )
-            ucode_in_nmi = val;
-        else if ( (val = parse_boolean("scan", s, ss)) >= 0 )
+        if ( (val = parse_boolean("scan", s, ss)) >= 0 )
         {
             if ( ucode_mod_forced )
                 printk(XENLOG_WARNING

... this function will want to transition back to what it was prior to the addition of the sub-option, preferably adjusted to account for the possibility of multiple "ucode=" on the command line, i.e. along the lines of

    if ( !strncmp(s, "scan", 4) )
    {
        ucode_scan = 1;
        ucode_mod_idx = 0;
    }
    else
    {
        ucode_scan = 0;
        ucode_mod_idx = simple_strtol(s, &q, 0);
    }
Quoted 4 lines
Quoted 1 line

That would then make patch 1 kind of unnecessary.

As said, I need to introduce a new option for the AMD fix, so it needs to stay comma-separated.

Right, and hence for the patch here

Patch 1 may still need a little bit of tweaking, though.

Jan