Received: by 10.223.185.116 with SMTP id b49csp6091289wrg; Thu, 8 Mar 2018 01:27:35 -0800 (PST) X-Google-Smtp-Source: AG47ELtXsfUPrLOUilkbYydPH4oZ2jVmD9fwuusJ+/+lpUgrLmQjcpq39QneEMDCpu2PnZ76DdC4 X-Received: by 10.98.82.144 with SMTP id g138mr25328488pfb.239.1520501255183; Thu, 08 Mar 2018 01:27:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520501255; cv=none; d=google.com; s=arc-20160816; b=vra3pGP5ByYaySmsqs/MLXcjc/1Pf2VPf/lj7sEe+jZf9nP/DP+s8D0O+9co3kMCg8 z1n4dZZF/Wo4V425oem5vFzDnSFn8SvHdww7hjB+H7q14a+bnMAJOq+dhKHDYDNKv8dp fgQHWA2cBDO6ZOjrNd+y7XVQuq8fAgTCpMcZrDxxZJVKjHq3g1QVswHOolRd5dA0d3Hy /mSr54yUjuRiIrtQtpY+IqfTTFMzQTqT6QuP4l4Yzq/L+UfnjZEnJKbJ7O+KIWJW8wly D1atTKEQZWFA6Fvjf2ItZBoBhOZAvpnRXVWFjvVNh7AgjJeoCP+1iAixjJwTYCxBNrTn M9jA== 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:arc-authentication-results; bh=+/fA1LOpQ1FOOX+ZbZSiTtmTLSongSGg7DrWlppB2Dc=; b=PY4JGr0adT2JJ9PCGYKQsnkNTfE+thecXXhTMgUcydkZdnUnR1g+3j4MltseA7cEM8 hP/ffSESIATs/+P0h5GFBomZ74SM078M+pH7P61khwr6+urrkwWojkI7U6e2in9ojCF8 BSWhPzyXG3lc6wWXhYCV+KvVduqaAEPie443xoFErhwMiePrs4x6VTP/S3tuM4mT/Wbr 2NXlO+KA7NgSh0dVKwXO0VfLjQeGK9ubDspDD9yklnkgpVWIP79HLJ2D1T424wRSm6Hg ahVcBxXKLs7sD1U2c9DoM7EchkElLYBfm/5v4r3L6tiXHb2UavudAkKxq9vsMM4eBrm1 u7QQ== 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 r8-v6si14351395plo.128.2018.03.08.01.27.20; Thu, 08 Mar 2018 01:27:35 -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 S1755559AbeCHJ0B (ORCPT + 99 others); Thu, 8 Mar 2018 04:26:01 -0500 Received: from terminus.zytor.com ([198.137.202.136]:49345 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754883AbeCHJZ7 (ORCPT ); Thu, 8 Mar 2018 04:25:59 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w289PlR4027313; Thu, 8 Mar 2018 01:25:47 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w289PlCC027306; Thu, 8 Mar 2018 01:25:47 -0800 Date: Thu, 8 Mar 2018 01:25:47 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Ashok Raj Message-ID: Cc: bp@suse.de, ashok.raj@intel.com, arjan.van.de.ven@intel.com, hpa@zytor.com, mingo@kernel.org, thomas.lendacky@amd.com, tglx@linutronix.de, linux-kernel@vger.kernel.org Reply-To: linux-kernel@vger.kernel.org, tglx@linutronix.de, thomas.lendacky@amd.com, mingo@kernel.org, hpa@zytor.com, arjan.van.de.ven@intel.com, bp@suse.de, ashok.raj@intel.com In-Reply-To: <20180228102846.13447-3-bp@alien8.de> References: <1519352533-15992-2-git-send-email-ashok.raj@intel.com> <20180228102846.13447-3-bp@alien8.de> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/pti] x86/microcode/intel: Check microcode revision before updating sibling threads Git-Commit-ID: c182d2b7d0ca48e0d6ff16f7d883161238c447ed 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=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) 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: c182d2b7d0ca48e0d6ff16f7d883161238c447ed Gitweb: https://git.kernel.org/tip/c182d2b7d0ca48e0d6ff16f7d883161238c447ed Author: Ashok Raj AuthorDate: Wed, 28 Feb 2018 11:28:41 +0100 Committer: Thomas Gleixner CommitDate: Thu, 8 Mar 2018 10:19:25 +0100 x86/microcode/intel: Check microcode revision before updating sibling threads After updating microcode on one of the threads of a core, the other thread sibling automatically gets the update since the microcode resources on a hyperthreaded core are shared between the two threads. Check the microcode revision on the CPU before performing a microcode update and thus save us the WRMSR 0x79 because it is a particularly expensive operation. [ Borislav: Massage changelog and coding style. ] Signed-off-by: Ashok Raj Signed-off-by: Borislav Petkov Signed-off-by: Thomas Gleixner Tested-by: Tom Lendacky Tested-by: Ashok Raj Cc: Arjan Van De Ven Link: http://lkml.kernel.org/r/1519352533-15992-2-git-send-email-ashok.raj@intel.com Link: https://lkml.kernel.org/r/20180228102846.13447-3-bp@alien8.de --- arch/x86/kernel/cpu/microcode/intel.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c index 923054a6b760..87bd6dc94081 100644 --- a/arch/x86/kernel/cpu/microcode/intel.c +++ b/arch/x86/kernel/cpu/microcode/intel.c @@ -589,6 +589,17 @@ static int apply_microcode_early(struct ucode_cpu_info *uci, bool early) if (!mc) return 0; + /* + * Save us the MSR write below - which is a particular expensive + * operation - when the other hyperthread has updated the microcode + * already. + */ + rev = intel_get_microcode_revision(); + if (rev >= mc->hdr.rev) { + uci->cpu_sig.rev = rev; + return UCODE_OK; + } + /* write microcode via MSR 0x79 */ native_wrmsrl(MSR_IA32_UCODE_WRITE, (unsigned long)mc->bits); @@ -776,7 +787,7 @@ static enum ucode_state apply_microcode_intel(int cpu) { struct microcode_intel *mc; struct ucode_cpu_info *uci; - struct cpuinfo_x86 *c; + struct cpuinfo_x86 *c = &cpu_data(cpu); static int prev_rev; u32 rev; @@ -793,6 +804,18 @@ static enum ucode_state apply_microcode_intel(int cpu) return UCODE_NFOUND; } + /* + * Save us the MSR write below - which is a particular expensive + * operation - when the other hyperthread has updated the microcode + * already. + */ + rev = intel_get_microcode_revision(); + if (rev >= mc->hdr.rev) { + uci->cpu_sig.rev = rev; + c->microcode = rev; + return UCODE_OK; + } + /* write microcode via MSR 0x79 */ wrmsrl(MSR_IA32_UCODE_WRITE, (unsigned long)mc->bits); @@ -813,8 +836,6 @@ static enum ucode_state apply_microcode_intel(int cpu) prev_rev = rev; } - c = &cpu_data(cpu); - uci->cpu_sig.rev = rev; c->microcode = rev;