Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8107854imu; Tue, 4 Dec 2018 03:08:05 -0800 (PST) X-Google-Smtp-Source: AFSGD/XaCxwvp2YB1GtEauI08T0CjMRtHBYEZRc1fg8MdBPpNMjQTVwTUWS/vbYMGDB1CQ280CiN X-Received: by 2002:a62:6cc8:: with SMTP id h191mr20279095pfc.89.1543921684992; Tue, 04 Dec 2018 03:08:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543921684; cv=none; d=google.com; s=arc-20160816; b=E+IEjlGKq8DOa8Ca9XcudTmF2btMP7U8rAQuPMxozGjNx/LHgpYJivR7ONaiP9QbA2 kAHQavGplvqgesRe7GG0/xlNwP4HPPbrDYG+IayzDGwsT7MZ2FWRdZg2TNlGNkVFeWAn x/qdyIEQsSLqVnNKrhENETl2AtMmMQuR6wlL+wCmOMMiGXHbC36WmhxFpYEegB9QfN9a SfBYkEK5IKs7gafNsNgHxTikoJlefJObtdVqyFy5xLFMC2ywweDT1KXrhvHJ2gAUOgLP HFDzo7vWbC990eFX340PYyNsiFEjOIS3extf/nWqPWXNui11pPZpwvHJhdTQmjl/Ri7n Y3Vw== 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=YmpmjeSCuhoeQBRuA2X70+Oj0AvkhLR8y1JruXagvy0=; b=KOfUAcm6dck4vpCNwoPgyROImA4YUJp1Xnvss8V7cHn5ExNLRhMdDelGyfjz5d3xIJ 496SApjiazkVTvNw3UfX6vBCRcY1AElHzGYtuje3y7tb6tKkPqmZX0XlDBjFK273fadn SqU/p5qpylPOwuI4vTKpJfacEicrqeCQWdAEL817K9aQSU2fAKtrj25seIAZc2HDyqPb yE0cFGwr/WPYtFnRBtySkLfYAw/9aDUP/tdGJmJwmQ+z9v7Mzy7FdzN4hxvFyzT87iA1 tRRVV5sj/tRIeETKExDiycrCQhR0QQaGwJVEMhkG+0ISfVgJfLYbn9rIY8Ygd64ViGd+ 7w9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WOsVsJMs; 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 e3si17322093pfe.203.2018.12.04.03.07.49; Tue, 04 Dec 2018 03:08: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=WOsVsJMs; 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 S1728066AbeLDLG6 (ORCPT + 99 others); Tue, 4 Dec 2018 06:06:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:55572 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726591AbeLDLGw (ORCPT ); Tue, 4 Dec 2018 06:06:52 -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 13A932146D; Tue, 4 Dec 2018 11:06:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543921611; bh=dHBP8a+IF1DIsqLksgUw0fWn3GTBvHBR3bFz1tnwiQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WOsVsJMsayyJIH5UQgsM1n5b9fPoKk+u33yVMFPJDAEQZ5Bs2DvroCNFQmnqF/rzA lk7+BM7SlcYXhv3e0E1Mk1EcfDjuCZEM5nStCRntxeug95I3XBZO9PXYC9ti4rSYP6 e7KZgWOMdQCmEelenRrzcUOTBjkRtX3HEKSYD99g= 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 104/146] x86/speculation: Prepare arch_smt_update() for PRCTL mode Date: Tue, 4 Dec 2018 11:49:50 +0100 Message-Id: <20181204103731.011693815@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 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 @@ -527,40 +527,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); }