x86/mtrr: Avoid repeated save of MTRRs on boot-time CPU bringup
authorDavid Woodhouse <dwmw@amazon.co.uk>
Tue, 14 Dec 2021 14:49:11 +0000 (14:49 +0000)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Thu, 16 Dec 2021 19:47:54 +0000 (19:47 +0000)
There's no need to repeatedly save the BSP's MTRRs for each AP we bring
up at boot time. And there's no need to use smp_call_function_single()
even for the one time we *do* want to do it.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
arch/x86/kernel/cpu/mtrr/mtrr.c

index 2746cac9d8a946229031e5d60653dacbb90a4066..2884017586f1e2a59dba11c63f0a387c3987da28 100644 (file)
@@ -814,11 +814,20 @@ void mtrr_ap_init(void)
  */
 void mtrr_save_state(void)
 {
+       static bool mtrr_saved;
        int first_cpu;
 
        if (!mtrr_enabled())
                return;
 
+       if (system_state < SYSTEM_RUNNING) {
+               if (!mtrr_saved) {
+                       mtrr_save_fixed_ranges(NULL);
+                       mtrr_saved = true;
+               }
+               return;
+       }
+
        first_cpu = cpumask_first(cpu_online_mask);
        smp_call_function_single(first_cpu, mtrr_save_fixed_ranges, NULL, 1);
 }