diff mbox series

[03/10] x86/ucode: Break early_microcode_load() out of early_microcode_init()

Message ID 20241028091856.2151603-4-andrew.cooper3@citrix.com (mailing list archive)
State New
Headers show
Series x86/ucode: Fix module-handling use-aftere-free's | expand

Commit Message

Andrew Cooper Oct. 28, 2024, 9:18 a.m. UTC
microcode_grab_module() and early_microcode_update_cpu() are logically one
task that passes state via static variables.

We intend to delete said static variables, so start by moving these functions
out of early_microcode_init().

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Daniel P. Smith <dpsmith@apertussolutions.com>
---
 xen/arch/x86/cpu/microcode/core.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

Comments

Jan Beulich Oct. 28, 2024, 1:40 p.m. UTC | #1
On 28.10.2024 10:18, Andrew Cooper wrote:
> microcode_grab_module() and early_microcode_update_cpu() are logically one
> task that passes state via static variables.
> 
> We intend to delete said static variables, so start by moving these functions
> out of early_microcode_init().
> 
> No functional change.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Acked-by: Jan Beulich <jbeulich@suse.com>

I expect I'll see later how this actually helps.

Jan
Daniel P. Smith Nov. 2, 2024, 4:07 p.m. UTC | #2
On 10/28/24 05:18, Andrew Cooper wrote:
> microcode_grab_module() and early_microcode_update_cpu() are logically one
> task that passes state via static variables.
> 
> We intend to delete said static variables, so start by moving these functions
> out of early_microcode_init().
> 
> No functional change.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Roger Pau Monné <roger.pau@citrix.com>
> CC: Daniel P. Smith <dpsmith@apertussolutions.com>
> ---

Reviewed-by: Daniel P. Smith <dpsmith@apertussolutions.com>
diff mbox series

Patch

diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode/core.c
index 3e815f1880af..d13f8338e4e6 100644
--- a/xen/arch/x86/cpu/microcode/core.c
+++ b/xen/arch/x86/cpu/microcode/core.c
@@ -854,6 +854,22 @@  static int __init early_microcode_update_cpu(void)
     return microcode_update_cpu(patch, 0);
 }
 
+/*
+ * There are several tasks:
+ * - Locate the ucode blob in the boot modules.
+ * - Parse and attempt in-place load.
+ * - Inform microcode_init_cache() of how to find the blob again.
+ */
+static int __init early_microcode_load(struct boot_info *bi)
+{
+    microcode_grab_module(bi);
+
+    if ( !ucode_mod.mod_end && !ucode_blob.size )
+        return 0;
+
+    return early_microcode_update_cpu();
+}
+
 int __init early_microcode_init(struct boot_info *bi)
 {
     const struct cpuinfo_x86 *c = &boot_cpu_data;
@@ -897,10 +913,7 @@  int __init early_microcode_init(struct boot_info *bi)
         return -ENODEV;
     }
 
-    microcode_grab_module(bi);
-
-    if ( ucode_mod.mod_end || ucode_blob.size )
-        rc = early_microcode_update_cpu();
+    rc = early_microcode_load(bi);
 
     /*
      * Some CPUID leaves and MSRs are only present after microcode updates