Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8129376imu; Tue, 4 Dec 2018 03:31:10 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vs7136WxxrqGeqBN7M5IETQKFWHmRZxGPcuYQvIJWddL2dsG8rBQ3CDipni73mxemfiY/8 X-Received: by 2002:a62:6ec8:: with SMTP id j191mr19670305pfc.198.1543923070178; Tue, 04 Dec 2018 03:31:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543923070; cv=none; d=google.com; s=arc-20160816; b=Klz6RtRH8Za86tO8pincn0o+FJ8S39CVkfvIIX0jsOFxP9XvgbJ6wF7/SZdJBZT24A pdNROMDhfYX/9SDxort/Rm9kor8gNasoFWG8fASwQgZZfDt/fb3DouRwOUsGjMH/BOtx CTzU3rh/f0qDMAd40s97uTsKScMaTFVCrgXOvf1BNG8hfFg1kHM1I3eTR+77dXjBHE77 8Bp9Jfu7TIAAMq0lHbXiicJXDPb3v2YUuJU0dtDn4qsny1a+cLj34EsC9pn9hInyRqPH 9Ydl3S71Ak/iDWL3SmitAdPk4tX25loSK4IR/E/ZkUCxIxt8ZITTzcwMEES9qVayWwsn PK3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+byipVu/EK2u5u6Q3z8f85CZmG/iOmaXDAnw4uNRTqA=; b=FCn7hFqmbw6iS7KWzOIKMr3yzn26d+y4iTz9ofxgGKHvPUURaG2ahvcAqP2ZgKEcFt xR56DRHrn2RAC/zoOjiK/ER1etmYh94YR6fWb4F0s52MnjWcU3g245ulVYnRdBt9eNrh FDLL16Z+Jm358gu8bINWSff0at8oL0vsFC+YoAHzmW81wdkmaKib2coxzW7ratSS7+0V EpMZcScLT1zPKPINpDkZ3V1Gl6gqXHijHXOPwsHv8+XadbXU9JUQaPzEjhsMVX2bFsG3 gGTzRxFi0ARK2ysthb9NC3Jhzu79gJCL1Y/kiXvZYnKpnz9cN2jRlnb4Nolngw+K1x43 Hb5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SBfvC20Z; 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 f11si17183425plr.341.2018.12.04.03.30.55; Tue, 04 Dec 2018 03:31:10 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=SBfvC20Z; 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 S1726965AbeLDL3I (ORCPT + 99 others); Tue, 4 Dec 2018 06:29:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:42458 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726899AbeLDK6N (ORCPT ); Tue, 4 Dec 2018 05:58:13 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E18F6214D9; Tue, 4 Dec 2018 10:58:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543921092; bh=h35gAvBAbF4wT3Z6cTdkFy6ZBoIkpzHUErKRGyFPiY8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SBfvC20ZQP7vW2lHdKcCTIPdmH68oafDSy01ZuLfBQYkHmXqD13lu6wM6DVHz6oOC SZ+UJuqhbinlfaeZH0haE5aPuPGHm4S8nMPds1CN1GBQU/HDxqSF9e7mvf6gMqw5MU tgqyrib7cYMgL/keDgLzhHm8zb9v/twwzKKgTce4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Andy Lutomirski , Linus Torvalds , Jiri Kosina , Tom Lendacky , Josh Poimboeuf , Andrea Arcangeli , David Woodhouse , Tim Chen , Andi Kleen , Dave Hansen , Casey Schaufler , Asit Mallick , Arjan van de Ven , Jon Masters , Waiman Long , Dave Stewart , Kees Cook Subject: [PATCH 4.19 043/139] x86/speculation: Rework SMT state change Date: Tue, 4 Dec 2018 11:48:44 +0100 Message-Id: <20181204103651.756637894@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181204103649.950154335@linuxfoundation.org> References: <20181204103649.950154335@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thomas Gleixner tglx@linutronix.de commit a74cfffb03b73d41e08f84c2e5c87dec0ce3db9f upstream arch_smt_update() is only called when the sysfs SMT control knob is changed. This means that when SMT is enabled in the sysfs control knob the system is considered to have SMT active even if all siblings are offline. To allow finegrained control of the speculation mitigations, the actual SMT state is more interesting than the fact that siblings could be enabled. Rework the code, so arch_smt_update() is invoked from each individual CPU hotplug function, and simplify the update function while at it. Signed-off-by: Thomas Gleixner Reviewed-by: Ingo Molnar Cc: Peter Zijlstra Cc: Andy Lutomirski Cc: Linus Torvalds Cc: Jiri Kosina Cc: Tom Lendacky Cc: Josh Poimboeuf Cc: Andrea Arcangeli Cc: David Woodhouse Cc: Tim Chen Cc: Andi Kleen Cc: Dave Hansen Cc: Casey Schaufler Cc: Asit Mallick Cc: Arjan van de Ven Cc: Jon Masters Cc: Waiman Long Cc: Greg KH Cc: Dave Stewart Cc: Kees Cook Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20181125185004.521974984@linutronix.de Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/bugs.c | 11 +++++------ include/linux/sched/smt.h | 2 ++ kernel/cpu.c | 15 +++++++++------ 3 files changed, 16 insertions(+), 12 deletions(-) --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -343,16 +344,14 @@ void arch_smt_update(void) return; mutex_lock(&spec_ctrl_mutex); - mask = x86_spec_ctrl_base; - if (cpu_smt_control == CPU_SMT_ENABLED) + + mask = x86_spec_ctrl_base & ~SPEC_CTRL_STIBP; + if (sched_smt_active()) mask |= SPEC_CTRL_STIBP; - else - mask &= ~SPEC_CTRL_STIBP; if (mask != x86_spec_ctrl_base) { pr_info("Spectre v2 cross-process SMT mitigation: %s STIBP\n", - cpu_smt_control == CPU_SMT_ENABLED ? - "Enabling" : "Disabling"); + mask & SPEC_CTRL_STIBP ? "Enabling" : "Disabling"); x86_spec_ctrl_base = mask; on_each_cpu(update_stibp_msr, NULL, 1); } --- a/include/linux/sched/smt.h +++ b/include/linux/sched/smt.h @@ -15,4 +15,6 @@ static __always_inline bool sched_smt_ac static inline bool sched_smt_active(void) { return false; } #endif +void arch_smt_update(void); + #endif --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -346,6 +347,12 @@ void cpu_hotplug_enable(void) EXPORT_SYMBOL_GPL(cpu_hotplug_enable); #endif /* CONFIG_HOTPLUG_CPU */ +/* + * Architectures that need SMT-specific errata handling during SMT hotplug + * should override this. + */ +void __weak arch_smt_update(void) { } + #ifdef CONFIG_HOTPLUG_SMT enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED; EXPORT_SYMBOL_GPL(cpu_smt_control); @@ -982,6 +989,7 @@ out: * concurrent CPU hotplug via cpu_add_remove_lock. */ lockup_detector_cleanup(); + arch_smt_update(); return ret; } @@ -1110,6 +1118,7 @@ static int _cpu_up(unsigned int cpu, int ret = cpuhp_up_callbacks(cpu, st, target); out: cpus_write_unlock(); + arch_smt_update(); return ret; } @@ -2026,12 +2035,6 @@ static void cpuhp_online_cpu_device(unsi kobject_uevent(&dev->kobj, KOBJ_ONLINE); } -/* - * Architectures that need SMT-specific errata handling during SMT hotplug - * should override this. - */ -void __weak arch_smt_update(void) { }; - static int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) { int cpu, ret = 0;