Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8098262imu; Tue, 4 Dec 2018 02:59:25 -0800 (PST) X-Google-Smtp-Source: AFSGD/Ulwkh1RZ/R0IcM+AK0Q/Q/oRNiHEDk3AB5xIeT1sHNBicD0+bMClyF3XD0e+AsyNhlYCY7 X-Received: by 2002:a17:902:8d95:: with SMTP id v21mr19555614plo.162.1543921165147; Tue, 04 Dec 2018 02:59:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543921165; cv=none; d=google.com; s=arc-20160816; b=C5nWCNDv3lGEby35l301/kkkuQ0Kj1rZ18+X+v9PTW+Z8YLG06VXRiql/XSfXUiM4A 4HkMfHzOeKBK6SvMhOqJqKyPSOckvPEQxyYy4FuLLuXuBIvEgrnIka8Bbpf/mHp67y6y BgEtBztqtHxJPqMRyc0fWZPn7yYel7WzwzNgCWV9jKa8nMlwMMV2tNCJ11ckrVX9/abh D48BZjN1tbNR6yo0ahqeVamekkbZ/tSvagyf6G5Qmye3qhUzNXSIfVWUB+Z52a6nb11s 2SKPASHhf0YNBEBCpk0h7kf+OrM4PipRJV7XkW0aU6J/aPKIFVZlW7JVtpLnJAAKyYwS IuUw== 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=GUKWXIeQnpmdBAdRGXwJuzDFUXRTkhoSh87G1MhQFMg=; b=yVVksXoagPvT7rCmkvxpRtr/qtU7RBGJ6iZfup5eq2xvfQGGFbuHXDZbLCdjUE8Kww JjMM/1bLTLXfNjbqcfyhx4jXSFOncsgGtmE57PGx7OKMoVDH4UDu58/qCw1tzgp5D5gp e0buW76FIgyKh3Xv2gNYrSi6X1tgQ6TxlIW89Ai0biapbFf2w43J/RCyr1GLjMoVEbvi RP4NMuWQ0niXO/NYFKZyk4V5RDZ+R3dXSckn7cdt2ZaXu5CwesRKjF0q9C8i4mclJoHV UKXepjFY4B1K6CKmouNCqo4JIr7iSF6ZTAFSurHO82Tv42UEquFqkytrv/5QPlJ6W5et 9/nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=K9tHWG+D; 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 j66si18517634pfb.182.2018.12.04.02.59.10; Tue, 04 Dec 2018 02:59:25 -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=K9tHWG+D; 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 S1726835AbeLDK5s (ORCPT + 99 others); Tue, 4 Dec 2018 05:57:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:41838 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726819AbeLDK5q (ORCPT ); Tue, 4 Dec 2018 05:57:46 -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 2DBC52087F; Tue, 4 Dec 2018 10:57:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543921064; bh=5J0Ya1O2/H1U6NGHKVn2whSgrnRy4LgL72KBt/j/wcU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K9tHWG+DYnmo3O9ymUQNiD16RGllyCOZJr253xSyFYcmOrKxI4g7kogbgqgup1EDJ hGpaT8R3oOyXxOTJ58do7NYxqHh44fO+LemO4D8YGmUoMACL7ipVAWj7c3x6DLSfUq h3YdQoIq27eTRwDTxNWlFn0gTDYLSTLgMtCZ3DDE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tim Chen , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Andy Lutomirski , Linus Torvalds , Jiri Kosina , Tom Lendacky , Josh Poimboeuf , Andrea Arcangeli , David Woodhouse , Andi Kleen , Dave Hansen , Casey Schaufler , Asit Mallick , Arjan van de Ven , Jon Masters , Waiman Long , Dave Stewart , Kees Cook Subject: [PATCH 4.19 039/139] x86/speculation: Reorganize speculation control MSRs update Date: Tue, 4 Dec 2018 11:48:40 +0100 Message-Id: <20181204103651.589363082@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: Tim Chen tim.c.chen@linux.intel.com commit 01daf56875ee0cd50ed496a09b20eb369b45dfa5 upstream The logic to detect whether there's a change in the previous and next task's flag relevant to update speculation control MSRs is spread out across multiple functions. Consolidate all checks needed for updating speculation control MSRs into the new __speculation_ctrl_update() helper function. This makes it easy to pick the right speculation control MSR and the bits in MSR_IA32_SPEC_CTRL that need updating based on TIF flags changes. Originally-by: Thomas Lendacky Signed-off-by: Tim Chen 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: 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.151077005@linutronix.de Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/process.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -395,27 +395,40 @@ static __always_inline void amd_set_ssb_ wrmsrl(MSR_AMD64_VIRT_SPEC_CTRL, ssbd_tif_to_spec_ctrl(tifn)); } -static __always_inline void spec_ctrl_update_msr(unsigned long tifn) +/* + * Update the MSRs managing speculation control, during context switch. + * + * tifp: Previous task's thread flags + * tifn: Next task's thread flags + */ +static __always_inline void __speculation_ctrl_update(unsigned long tifp, + unsigned long tifn) { - u64 msr = x86_spec_ctrl_base | ssbd_tif_to_spec_ctrl(tifn); + u64 msr = x86_spec_ctrl_base; + bool updmsr = false; - wrmsrl(MSR_IA32_SPEC_CTRL, msr); -} + /* If TIF_SSBD is different, select the proper mitigation method */ + if ((tifp ^ tifn) & _TIF_SSBD) { + if (static_cpu_has(X86_FEATURE_VIRT_SSBD)) { + amd_set_ssb_virt_state(tifn); + } else if (static_cpu_has(X86_FEATURE_LS_CFG_SSBD)) { + amd_set_core_ssb_state(tifn); + } else if (static_cpu_has(X86_FEATURE_SPEC_CTRL_SSBD) || + static_cpu_has(X86_FEATURE_AMD_SSBD)) { + msr |= ssbd_tif_to_spec_ctrl(tifn); + updmsr = true; + } + } -static __always_inline void __speculation_ctrl_update(unsigned long tifn) -{ - if (static_cpu_has(X86_FEATURE_VIRT_SSBD)) - amd_set_ssb_virt_state(tifn); - else if (static_cpu_has(X86_FEATURE_LS_CFG_SSBD)) - amd_set_core_ssb_state(tifn); - else - spec_ctrl_update_msr(tifn); + if (updmsr) + wrmsrl(MSR_IA32_SPEC_CTRL, msr); } void speculation_ctrl_update(unsigned long tif) { + /* Forced update. Make sure all relevant TIF flags are different */ preempt_disable(); - __speculation_ctrl_update(tif); + __speculation_ctrl_update(~tif, tif); preempt_enable(); } @@ -451,8 +464,7 @@ void __switch_to_xtra(struct task_struct if ((tifp ^ tifn) & _TIF_NOCPUID) set_cpuid_faulting(!!(tifn & _TIF_NOCPUID)); - if ((tifp ^ tifn) & _TIF_SSBD) - __speculation_ctrl_update(tifn); + __speculation_ctrl_update(tifp, tifn); } /*