Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp4805090ooa; Tue, 14 Aug 2018 10:47:30 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzshPebHoAxrBaCklWn1c2Xb37Aub0JvwSzgbffgfltodtgynWI8eJQEj0PEGAMzHyGQR6m X-Received: by 2002:a62:50ca:: with SMTP id g71-v6mr24389363pfj.244.1534268849963; Tue, 14 Aug 2018 10:47:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534268849; cv=none; d=google.com; s=arc-20160816; b=hCumX30U39rPfjZsdMVbQPe8M6yKCsRsRNv5fCaDiZ2E6RP0xnc1XgXFc959feulSV fTobh5SCRnRiUPkfpubT+iN81Pl7U/8bblRzHJ+CN5VtJhDdHMceHky8NCbxgzopVdt7 k4WhRJdkRKZoIPHrlG1yGcrBZtQ/Acopy9DhxoFJTGG9ItYNcUxYUsi8r7bSD5MupZbE Jl6o2sapVqcOy9x7ykChlvAbsrFa6lOnKwvfZl7e8Z6kzWXryySCR7JRU+Lh6GKcZ5+i mhgJm2Z7cHD/vf+SQALF2ivz3jRi2+klVM5t4jmoGFdlR0pOEdG1eAUdV684iscPcxYy +j/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=+s7y2U/O5rOjDt6F/OITuYgeOFqHStLmIbXGWasW358=; b=cFYBbEMA7l2vN/bADL0NEWo5uNmffTs1MwnIbPFQgKElT7GFGrCthgsNnpEyDPMCXs 0ms721c4hPAGeShAvcgXfOR9I6jOFGmNDDD8FdlrAABRFIt6yr0FX2gZ+VIeh9nZCjah Fo0YKuoYjUMJ8m0P1lnMsN1a09Hr1iyVa7jKWzyuAS94seX00Zpp1XOugfL2N4E91j7N kmrWKtJpUvHlJ30wOyQ3LoR6bkoq9wEUvWEvYMeYz/TNfPBpmTbE1sBApdLgTbiIPCCf yRuEvUxvYFPph4KNuqpHHPpzxw4zQ6lzsoJWQsChsVKGpiePvOgrYPxE9Le0EcHcwPTa Q4Ug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o126-v6si21322569pfb.20.2018.08.14.10.47.14; Tue, 14 Aug 2018 10:47:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390940AbeHNUdu (ORCPT + 99 others); Tue, 14 Aug 2018 16:33:50 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60266 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388101AbeHNUdu (ORCPT ); Tue, 14 Aug 2018 16:33:50 -0400 Received: from localhost (unknown [194.244.16.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 15D82CA5; Tue, 14 Aug 2018 17:45:37 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josh Poimboeuf , Thomas Gleixner , David Woodhouse Subject: [PATCH 4.9 100/107] cpu/hotplug: Fix SMT supported evaluation Date: Tue, 14 Aug 2018 19:18:03 +0200 Message-Id: <20180814171526.839719608@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180814171520.883143803@linuxfoundation.org> References: <20180814171520.883143803@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thomas Gleixner commit bc2d8d262cba5736332cbc866acb11b1c5748aa9 upstream Josh reported that the late SMT evaluation in cpu_smt_state_init() sets cpu_smt_control to CPU_SMT_NOT_SUPPORTED in case that 'nosmt' was supplied on the kernel command line as it cannot differentiate between SMT disabled by BIOS and SMT soft disable via 'nosmt'. That wreckages the state and makes the sysfs interface unusable. Rework this so that during bringup of the non boot CPUs the availability of SMT is determined in cpu_smt_allowed(). If a newly booted CPU is not a 'primary' thread then set the local cpu_smt_available marker and evaluate this explicitely right after the initial SMP bringup has finished. SMT evaulation on x86 is a trainwreck as the firmware has all the information _before_ booting the kernel, but there is no interface to query it. Fixes: 73d5e2b47264 ("cpu/hotplug: detect SMT disabled by BIOS") Reported-by: Josh Poimboeuf Signed-off-by: Thomas Gleixner Signed-off-by: David Woodhouse Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/bugs.c | 2 +- include/linux/cpu.h | 2 ++ kernel/cpu.c | 41 ++++++++++++++++++++++++++++------------- kernel/smp.c | 2 ++ 4 files changed, 33 insertions(+), 14 deletions(-) --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -61,7 +61,7 @@ void __init check_bugs(void) * identify_boot_cpu() initialized SMT support information, let the * core code know. */ - cpu_smt_check_topology(); + cpu_smt_check_topology_early(); if (!IS_ENABLED(CONFIG_SMP)) { pr_info("CPU: "); --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -267,10 +267,12 @@ enum cpuhp_smt_control { #if defined(CONFIG_SMP) && defined(CONFIG_HOTPLUG_SMT) extern enum cpuhp_smt_control cpu_smt_control; extern void cpu_smt_disable(bool force); +extern void cpu_smt_check_topology_early(void); extern void cpu_smt_check_topology(void); #else # define cpu_smt_control (CPU_SMT_ENABLED) static inline void cpu_smt_disable(bool force) { } +static inline void cpu_smt_check_topology_early(void) { } static inline void cpu_smt_check_topology(void) { } #endif --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -360,6 +360,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 || @@ -376,14 +378,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")); @@ -393,10 +409,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; /* @@ -2063,15 +2087,6 @@ static const struct attribute_group cpuh 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); } --- a/kernel/smp.c +++ b/kernel/smp.c @@ -564,6 +564,8 @@ void __init smp_init(void) cpu_up(cpu); } + /* Final decision about SMT support */ + cpu_smt_check_topology(); /* Any cleanup work */ smp_announce(); smp_cpus_done(setup_max_cpus);