Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4826127imu; Sun, 25 Nov 2018 10:58:37 -0800 (PST) X-Google-Smtp-Source: AFSGD/WPDDXpwU9dBcSTpMM/AGtHSZOzFiOZJgmvq6LUB5KDXhYzXD/Y4TBR5H6WyM7dXrv5I2St X-Received: by 2002:a63:f201:: with SMTP id v1mr20368256pgh.232.1543172317407; Sun, 25 Nov 2018 10:58:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543172317; cv=none; d=google.com; s=arc-20160816; b=F4ShBzetyrwn7w64LQ357d8DZ9QnarrhCD8rtDmjX5uN+ScVgrvgPt1B4dJbMaGgf9 lD2udO5XNpD+2cKQsaDq27PIKBgMtyMkW470rF/svQ4iMXLuB+LwiHhe8tjnUfq0+UtL jl5ambgxZPJtx69czfmCm/OFQM5ePR85g8TNK/5NkIIhyCMUpsLEHnjVZ98t8xgZjd4H d73xbxHLsUCQ4OS56AN4fmDmWXw/4k4/7Cmxcrqs63dQTezFNlTMTvXZI/ItU6TX05OZ WVex3Psov886OhCzgpx/wzAK52vNjrudOg7QYpZcL0ONGEVqynMC1RWVcfgqqnqcjZS9 jM6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :references:subject:cc:to:from:date:user-agent:message-id; bh=U1LAVfA7R9wUxN1uIhTmIrryMDc2N1obl+Itu5lj7vQ=; b=0M7HaqrS9PXUWCFISzbjsnWz19GwvxT4MijFSuuVtsrZVzq001JY5kJ138skpEAFd7 8cjctOcEHyyTcdb3dBYYNunpcFN7k+cPyc6G7tJUB/ik6EiAvi8I5oPzsrYb4Bhp6gxq SGBjvYs8zseBrkK445ExPQIC0+b59xr5UZ83DaGcWnJ1s7u25N65zKMYTziJ+DxAQ0si JmAJmAcGCCSggJsEqeqOKHUuQA+linyADd/lZQ5aEG+CEPvMKD7HuXK+6i05gsDnuLe9 m4QHVCylBxiQYhgC+R6iXQ28tC0yuua1BPSAh3p6zN1jYJM92pGMtB6PSQIYoaz+33Wc 7QBg== 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 n2si63727699pgr.67.2018.11.25.10.58.22; Sun, 25 Nov 2018 10:58:37 -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 S1727551AbeKZFtS (ORCPT + 99 others); Mon, 26 Nov 2018 00:49:18 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:52963 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727456AbeKZFtS (ORCPT ); Mon, 26 Nov 2018 00:49:18 -0500 Received: from localhost ([127.0.0.1] helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1gQzb3-0003US-Ab; Sun, 25 Nov 2018 19:57:33 +0100 Message-Id: <20181125185005.759457117@linutronix.de> User-Agent: quilt/0.65 Date: Sun, 25 Nov 2018 19:33:52 +0100 From: Thomas Gleixner To: LKML Cc: x86@kernel.org, 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 , Greg KH , Dave Stewart , Kees Cook Subject: [patch V2 24/28] x86/speculation: Prepare arch_smt_update() for PRCTL mode References: <20181125183328.318175777@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline; filename=x86-speculation-Prepare-arch-smt-update-for-PRCTL-mode.patch Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- v1 -> v2: s/app2app/user/. Mark smp function argument __unused --- 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 @@ -530,40 +530,44 @@ static void __init spectre_v2_select_mit 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("Spectre v2 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); }