Merge branch 'x86-topology-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-block.git] / arch / x86 / kernel / cpu / common.c
index dad20bc891d500a22af3f447e49da9119630bbf8..309b6b9b49d4a92d74adae760d852a9293c9f826 100644 (file)
@@ -366,6 +366,25 @@ out:
        cr4_clear_bits(X86_CR4_UMIP);
 }
 
+DEFINE_STATIC_KEY_FALSE_RO(cr_pinning);
+EXPORT_SYMBOL(cr_pinning);
+unsigned long cr4_pinned_bits __ro_after_init;
+EXPORT_SYMBOL(cr4_pinned_bits);
+
+/*
+ * Once CPU feature detection is finished (and boot params have been
+ * parsed), record any of the sensitive CR bits that are set, and
+ * enable CR pinning.
+ */
+static void __init setup_cr_pinning(void)
+{
+       unsigned long mask;
+
+       mask = (X86_CR4_SMEP | X86_CR4_SMAP | X86_CR4_UMIP);
+       cr4_pinned_bits = this_cpu_read(cpu_tlbstate.cr4) & mask;
+       static_key_enable(&cr_pinning.key);
+}
+
 /*
  * Protection Keys are not available in 32-bit mode.
  */
@@ -1303,6 +1322,7 @@ static void validate_apic_and_package_id(struct cpuinfo_x86 *c)
                       cpu, apicid, c->initial_apicid);
        }
        BUG_ON(topology_update_package_map(c->phys_proc_id, cpu));
+       BUG_ON(topology_update_die_map(c->cpu_die_id, cpu));
 #else
        c->logical_proc_id = 0;
 #endif
@@ -1468,6 +1488,7 @@ void __init identify_boot_cpu(void)
        enable_sep_cpu();
 #endif
        cpu_detect_tlb(&boot_cpu_data);
+       setup_cr_pinning();
 }
 
 void identify_secondary_cpu(struct cpuinfo_x86 *c)