]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - kernel/cpu.c
cdrom: Fix info leak/OOB read in cdrom_ioctl_drive_status
[mirror_ubuntu-bionic-kernel.git] / kernel / cpu.c
index feea51ea45a480b97c798b42a1ecd99520194345..f760063fb1647b73ccd91635d2b9dc3c1fb9578f 100644 (file)
@@ -351,6 +351,8 @@ EXPORT_SYMBOL_GPL(cpu_hotplug_enable);
 enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED;
 EXPORT_SYMBOL_GPL(cpu_smt_control);
 
+static bool cpu_smt_available __read_mostly;
+
 void __init cpu_smt_disable(bool force)
 {
        if (cpu_smt_control == CPU_SMT_FORCE_DISABLED ||
@@ -367,14 +369,28 @@ void __init cpu_smt_disable(bool force)
 
 /*
  * The decision whether SMT is supported can only be done after the full
- * CPU identification. Called from architecture code.
+ * CPU identification. Called from architecture code before non boot CPUs
+ * are brought up.
  */
-void __init cpu_smt_check_topology(void)
+void __init cpu_smt_check_topology_early(void)
 {
        if (!topology_smt_supported())
                cpu_smt_control = CPU_SMT_NOT_SUPPORTED;
 }
 
+/*
+ * If SMT was disabled by BIOS, detect it here, after the CPUs have been
+ * brought online. This ensures the smt/l1tf sysfs entries are consistent
+ * with reality. cpu_smt_available is set to true during the bringup of non
+ * boot CPUs when a SMT sibling is detected. Note, this may overwrite
+ * cpu_smt_control's previous setting.
+ */
+void __init cpu_smt_check_topology(void)
+{
+       if (!cpu_smt_available)
+               cpu_smt_control = CPU_SMT_NOT_SUPPORTED;
+}
+
 static int __init smt_cmdline_disable(char *str)
 {
        cpu_smt_disable(str && !strcmp(str, "force"));
@@ -384,10 +400,18 @@ early_param("nosmt", smt_cmdline_disable);
 
 static inline bool cpu_smt_allowed(unsigned int cpu)
 {
-       if (cpu_smt_control == CPU_SMT_ENABLED)
+       if (topology_is_primary_thread(cpu))
                return true;
 
-       if (topology_is_primary_thread(cpu))
+       /*
+        * If the CPU is not a 'primary' thread and the booted_once bit is
+        * set then the processor has SMT support. Store this information
+        * for the late check of SMT support in cpu_smt_check_topology().
+        */
+       if (per_cpu(cpuhp_state, cpu).booted_once)
+               cpu_smt_available = true;
+
+       if (cpu_smt_control == CPU_SMT_ENABLED)
                return true;
 
        /*
@@ -2137,15 +2161,6 @@ static const struct attribute_group cpuhp_smt_attr_group = {
 
 static int __init cpu_smt_state_init(void)
 {
-       /*
-        * If SMT was disabled by BIOS, detect it here, after the CPUs have
-        * been brought online.  This ensures the smt/l1tf sysfs entries are
-        * consistent with reality.  Note this may overwrite cpu_smt_control's
-        * previous setting.
-        */
-       if (topology_max_smt_threads() == 1)
-               cpu_smt_control = CPU_SMT_NOT_SUPPORTED;
-
        return sysfs_create_group(&cpu_subsys.dev_root->kobj,
                                  &cpuhp_smt_attr_group);
 }
@@ -2264,6 +2279,6 @@ void __init boot_cpu_init(void)
  */
 void __init boot_cpu_state_init(void)
 {
-       this_cpu_write(cpuhp_state.booted_once, true);
-       this_cpu_write(cpuhp_state.state, CPUHP_ONLINE);
+       per_cpu_ptr(&cpuhp_state, smp_processor_id())->booted_once = true;
+       per_cpu_ptr(&cpuhp_state, smp_processor_id())->state = CPUHP_ONLINE;
 }