Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8129247imu; Tue, 4 Dec 2018 03:31:04 -0800 (PST) X-Google-Smtp-Source: AFSGD/XIMXAfmhAYLtlO/D6gAY/Q+dbO7Mmo9V0A9atE6og3pLlOwRZH/NmOGceVJD3GoGJRUrap X-Received: by 2002:a63:a41:: with SMTP id z1mr16436234pgk.117.1543923064287; Tue, 04 Dec 2018 03:31:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543923064; cv=none; d=google.com; s=arc-20160816; b=QDtWhgCSztvO3+GGiFJ/EWhHL5QlP9nzjnyzzn6ZSFq7R0AFYF0udmQaeyUfH976ok ajWrLj7Wh4EHXbYy4VFLjqO1/DnS+sJKIlNS0kNlmmOhh3NVAOpPZizD7JuvUs3ojif4 s9SXQGqtFptwg7K1J/+rEl80TOpKQ9nqdskfe2tmzwypagOBJceWIkzitlhOTDlCyn6c +uAPYiPYWADSLnDAqPzdTz+Rfn1qk7KrHFogK8tMFEClMkSKvkh5o62wfyJHOzeoCVuY KPgKb8nNgrK/b+bMXKa7ekKYLWcOPBVzgf6V2Zy+rCjBQ/Va5UIDZXwkoHeyL/cBxVKb dq5A== 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=exQE8SQv11Ugg7Wn/SnUHXMlras+yWIWZlQcwcjZr8Q=; b=cM38+/z3tlv2r49r/DdgDoTGX9RbdB0BUIPYpqOR5RRLbk3vt1MtEl5DyBF+CPYaZ0 N3ypAS991SmBPWX7a9jsQBpgNRelTCxUWj/PfP4h5fzaBuOOvAfc2IQNGUz5cdxfrJuT ts87/snJ1slSyj2Z2xSVVRWJ3DHeH/v7gR+/79p3c9sXt8/DxuKus/ZG32WvRYOZnAsA 4UfJIiZfNAztd8MjwMO1XoDtGM83SVbdgBxOeidelLWEkh1ob9x1fPXRTIFqh8NesB01 7Bg7eRiD7BZAq+98zu7meoBlOH7fdg1nRyDlvV+g4CbppSwH0dOlcLi1udKTNTGehJ// NVug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=y6ckdp+2; 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 o7si15240254pgg.118.2018.12.04.03.30.49; Tue, 04 Dec 2018 03:31:04 -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=y6ckdp+2; 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 S1726734AbeLDK51 (ORCPT + 99 others); Tue, 4 Dec 2018 05:57:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:41230 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726718AbeLDK5X (ORCPT ); Tue, 4 Dec 2018 05:57:23 -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 6D96C2146D; Tue, 4 Dec 2018 10:57:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543921041; bh=P7psbqmqRAIT3xF1xOmH2JA8sbEbZnhWRMvVo6L1Td8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y6ckdp+2e1c7/0QEAnznyXkp9fz4J1QMH5B+xFyp6FdZytlgJ5YqL2bWfKj8Yz9sO Sz0FpUpDed6lHRLSMt56Psj4xxq3dKTIUoBr7szhLKdeQvI+WfDP+RMe7sg9J8bbKf YfGPzG2EVEiSq2aRPQyGvYHweHwujgJLRgY4UWlQ= 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 057/139] x86/speculation: Prepare arch_smt_update() for PRCTL mode Date: Tue, 4 Dec 2018 11:48:58 +0100 Message-Id: <20181204103652.316353783@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 6893a959d7fdebbab5f5aa112c277d5a44435ba1 upstream 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 Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/bugs.c | 46 ++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -528,40 +528,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); }