Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8107237imu; Tue, 4 Dec 2018 03:07:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/U6wRfFMOYy6gImqMoM/AX9GbdVdek7rWyCAI8XZVQgLrn5iHxJCURpJ/qUjUwS5iYRolFA X-Received: by 2002:a63:9402:: with SMTP id m2mr15755416pge.93.1543921649227; Tue, 04 Dec 2018 03:07:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543921649; cv=none; d=google.com; s=arc-20160816; b=h5iyFfqnIeeYuKBJmKqMOmE/pq/yPm6d81bXl02J7p+9jOD1LMv1T76Q2MlDf18WTW Eu30aCg+T5doykDqDwerWTGTG6ITb+UPPOV+xT//TiIZYc1tcp5U1TujN4eJzbGShwwB 3o/2xbQKpdyq2tG+u7SMZXXqYNoXWGBS6YliLpQdIKOTbqrjME+P9f1ow3mnDPkJp+FV I0LgjgATG33JoEEE/1ifgSp5pfS0LpRPAE++7XI55LSgjwlyHBkSZTNDwtlu7dT93dYF QeY68yN06DG2bIrusC6tuN8JixEow/bYXNgnppVxIbrntN3Pqwc73FheDbkbz+dKb208 8tYQ== 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=l4sUDgNzMdpp0TWltY3hg/s5+XeOILmb7R5wnMqtgjU=; b=HAKtzQjuGBl7Yl2fLmXyVSxAFE8hBhE6388dlaYkE8njEakIa4E9Q7ZWpVaFb/oaPN 4ceUQ/EhirJOIFY0xOKTQPi425qggXVIiNkHGE06LQfFiKCnmVKZocESpaRWpuJ+e2L0 8R3Ek71Hw6niNswF2m6kom2wlsSgMUkCdRrvuEoP90zh2TJti3YoJ/YeJpMI1vFjHxKK viP/+1hNLlizkLOCxQGrJU8zlM7BeGwCqe3Lh5pi9FQOtnpcId1TCoj8b7KK7bQ9b2SS yzcWdkYqb+n123bUe7CqaXHrE+PunoTwLOBsialHZI0MkRVUiqeepxgPAgGNyWdYbG6O 3lSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uUKxXYCY; 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 m3si14966273pgs.8.2018.12.04.03.07.13; Tue, 04 Dec 2018 03:07:29 -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=uUKxXYCY; 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 S1727714AbeLDLEy (ORCPT + 99 others); Tue, 4 Dec 2018 06:04:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:52132 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728048AbeLDLEs (ORCPT ); Tue, 4 Dec 2018 06:04:48 -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 4A38E21508; Tue, 4 Dec 2018 11:04:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543921487; bh=PNw2xhZ5F/JA0yP349XyWIHBlvw8ZEXnLpExiYK2fUw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uUKxXYCYf0ekTOoD02hqHDb5p0dst9KNu4NiEmfrRsYZyhORyMQAfoxUFneg3JWDb TDL62ZBHP/D12n4+31c1WqX/kkRZpy3AjN3vQgCPswGH7EIjqHQZjdsffkhRTM5env 80i7Sfkbmqe0GAFX9Sol+CDjRf3c0CL/Gbrfm66c= 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.14 090/146] x86/speculation: Rework SMT state change Date: Tue, 4 Dec 2018 11:49:36 +0100 Message-Id: <20181204103730.454371353@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181204103726.750894136@linuxfoundation.org> References: <20181204103726.750894136@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.14-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 @@ -342,16 +343,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 @@ -347,6 +348,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); @@ -998,6 +1005,7 @@ out: * concurrent CPU hotplug via cpu_add_remove_lock. */ lockup_detector_cleanup(); + arch_smt_update(); return ret; } @@ -1126,6 +1134,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; } @@ -2045,12 +2054,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;