Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1232012imu; Wed, 28 Nov 2018 06:37:27 -0800 (PST) X-Google-Smtp-Source: AJdET5f4/+FnhoCiIipEhr7SEdolKXhIJJJyOPpCxKXlLOnk4DaQKKWa24auaYNUdVCtS4KD71dR X-Received: by 2002:a62:8dd9:: with SMTP id p86mr37290792pfk.143.1543415847515; Wed, 28 Nov 2018 06:37:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543415847; cv=none; d=google.com; s=arc-20160816; b=VfufxIShtrjkhEBGuujS1jhZ0iIHxVx8dJLVcqACoEcQfyEEZJXcUEsfVysta8cs79 64k2i9Bzb8T+TBE7TWdCsGUgbZQtFNI+XkXeOwl2SQy8bHUXSWplzlBvKG6sbV49zWlL bwirnfZ50SDbw8m12Lbw2FJH0j1Nbig3V3pIA+lhgmS6MbRhONbvycRnMWNKRuQbUR4g 4K2vgawDBA+GZhhFdglA+D2X0bC11gNpmJgufc3LfEjRrY37DBnzrYbnxtn7zjv6WKv5 PWNPw1m2UZ7Y8CK4Vj15rZzs80QOdFleiADWWiZGom7RSBD3KizrdoEXq4KVwcYPE+SY axSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=sIRV5KslAB6UKvosDJQm+ylsO1k6V8BpoqpzmYdm048=; b=L71wqRy2goyZFWVd3LKYfRZFQjNnAgUW8LqEbf0VLajBgLGrOjnhDVgJUk1r2CQ62b kXzCuz/UFfKyAGiUqltH9GsfwWcX/Gfq63rW8c70Hev+ihnPjeNWiIf/TX5tWEUv3Q3b PM+wNpvQF8gy9i2c7EcA5y63EwNEm4s8ZoIYPjXO6Jxh82UxQuLrzfg+oubwO7v5sc/g lvTDjw4WnHbaVpwoVFJOUnHnZToZGSOzOsVvtErrl+4HJRivIvBh1zfV3hwvlTgFw5gk /sCDbFRNdKy/Jd1Z0QnMRIBlSN/HgkfOOajR82k2wjaA6nrQd6PSll7ePZ0nAT2x42Gg ncdQ== 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 t12si7434915plq.190.2018.11.28.06.37.05; Wed, 28 Nov 2018 06:37:27 -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; 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 S1728759AbeK2Bgw (ORCPT + 99 others); Wed, 28 Nov 2018 20:36:52 -0500 Received: from terminus.zytor.com ([198.137.202.136]:44007 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728102AbeK2Bgv (ORCPT ); Wed, 28 Nov 2018 20:36:51 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id wASEYEGr2324116 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 28 Nov 2018 06:34:14 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id wASEYEwl2324113; Wed, 28 Nov 2018 06:34:14 -0800 Date: Wed, 28 Nov 2018 06:34:14 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Thomas Gleixner Message-ID: Cc: jkosina@suse.cz, tglx@linutronix.de, hpa@zytor.com, linux-kernel@vger.kernel.org, longman9394@gmail.com, dwmw@amazon.co.uk, luto@kernel.org, ak@linux.intel.com, gregkh@linuxfoundation.org, thomas.lendacky@amd.com, david.c.stewart@intel.com, torvalds@linux-foundation.org, dave.hansen@intel.com, arjan@linux.intel.com, jpoimboe@redhat.com, mingo@kernel.org, peterz@infradead.org, asit.k.mallick@intel.com, keescook@chromium.org, casey.schaufler@intel.com, tim.c.chen@linux.intel.com, aarcange@redhat.com, jcm@redhat.com Reply-To: casey.schaufler@intel.com, keescook@chromium.org, aarcange@redhat.com, jcm@redhat.com, tim.c.chen@linux.intel.com, dave.hansen@intel.com, asit.k.mallick@intel.com, peterz@infradead.org, mingo@kernel.org, arjan@linux.intel.com, jpoimboe@redhat.com, luto@kernel.org, dwmw@amazon.co.uk, longman9394@gmail.com, torvalds@linux-foundation.org, david.c.stewart@intel.com, gregkh@linuxfoundation.org, thomas.lendacky@amd.com, ak@linux.intel.com, jkosina@suse.cz, hpa@zytor.com, linux-kernel@vger.kernel.org, tglx@linutronix.de In-Reply-To: <20181125185005.759457117@linutronix.de> References: <20181125185005.759457117@linutronix.de> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/pti] x86/speculation: Prepare arch_smt_update() for PRCTL mode Git-Commit-ID: 6893a959d7fdebbab5f5aa112c277d5a44435ba1 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=1.5 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_24_48,FREEMAIL_FORGED_REPLYTO, FREEMAIL_REPLYTO_END_DIGIT autolearn=no autolearn_force=no version=3.4.2 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 6893a959d7fdebbab5f5aa112c277d5a44435ba1 Gitweb: https://git.kernel.org/tip/6893a959d7fdebbab5f5aa112c277d5a44435ba1 Author: Thomas Gleixner AuthorDate: Sun, 25 Nov 2018 19:33:52 +0100 Committer: Thomas Gleixner CommitDate: Wed, 28 Nov 2018 11:57:13 +0100 x86/speculation: Prepare arch_smt_update() for PRCTL mode The upcoming fine grained per task STIBP control needs to be updated on CPU hotplug as well. Split out the code which controls the strict mode so the prctl control code can be added later. Mark the SMP function call argument __unused 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/20181125185005.759457117@linutronix.de --- arch/x86/kernel/cpu/bugs.c | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index 29f40a92f5a8..9cab538e10f1 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -530,40 +530,44 @@ specv2_set_mode: arch_smt_update(); } -static bool stibp_needed(void) +static void update_stibp_msr(void * __unused) { - /* Enhanced IBRS makes using STIBP unnecessary. */ - if (spectre_v2_enabled == SPECTRE_V2_IBRS_ENHANCED) - return false; - - /* Check for strict user mitigation mode */ - return spectre_v2_user == SPECTRE_V2_USER_STRICT; + wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base); } -static void update_stibp_msr(void *info) +/* Update x86_spec_ctrl_base in case SMT state changed. */ +static void update_stibp_strict(void) { - wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base); + u64 mask = x86_spec_ctrl_base & ~SPEC_CTRL_STIBP; + + if (sched_smt_active()) + mask |= SPEC_CTRL_STIBP; + + if (mask == x86_spec_ctrl_base) + return; + + pr_info("Update user space SMT mitigation: STIBP %s\n", + mask & SPEC_CTRL_STIBP ? "always-on" : "off"); + x86_spec_ctrl_base = mask; + on_each_cpu(update_stibp_msr, NULL, 1); } void arch_smt_update(void) { - u64 mask; - - if (!stibp_needed()) + /* Enhanced IBRS implies STIBP. No update required. */ + if (spectre_v2_enabled == SPECTRE_V2_IBRS_ENHANCED) return; mutex_lock(&spec_ctrl_mutex); - mask = x86_spec_ctrl_base & ~SPEC_CTRL_STIBP; - if (sched_smt_active()) - mask |= SPEC_CTRL_STIBP; - - if (mask != x86_spec_ctrl_base) { - pr_info("Spectre v2 cross-process SMT mitigation: %s STIBP\n", - mask & SPEC_CTRL_STIBP ? "Enabling" : "Disabling"); - x86_spec_ctrl_base = mask; - on_each_cpu(update_stibp_msr, NULL, 1); + switch (spectre_v2_user) { + case SPECTRE_V2_USER_NONE: + break; + case SPECTRE_V2_USER_STRICT: + update_stibp_strict(); + break; } + mutex_unlock(&spec_ctrl_mutex); }