Received: by 10.192.165.156 with SMTP id m28csp36347imm; Tue, 10 Apr 2018 15:53:05 -0700 (PDT) X-Google-Smtp-Source: AIpwx482msq56y1A82mo4gTbQfB1fsQfc362budBrRphw3Z1meNFQQPdiqHsHqFgvTy3Tp/e7f4/ X-Received: by 2002:a17:902:10c:: with SMTP id 12-v6mr2263629plb.405.1523400785411; Tue, 10 Apr 2018 15:53:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523400785; cv=none; d=google.com; s=arc-20160816; b=eSNa5wzCbXh9aWR3gSAxCIyBFx4tYGMdSekRmUE+af2Hf84Wj61x5EBfQcRFCh1Bhl eVCLF43WHYv7tUFq7UxBV2BXJM3d1KQ6CBkMt1Fwkl24sE8BY3JsiBUHKy1B+zqjJin4 fbWaThVNPbOF3lWAwqo29OF15WuMboxvhHGwiRU/iVylT0MelfnnUZfnYZuxgJd0ieLw gfVibbcaq/N9AkS5QGHkNRt1WVo4E9U9d7SmCGxJuTCMPdgr7RHddYKRF+Vz18sO2Ah9 78pp1v2e5wndQeP193ZN4bgpIFLfO6Kq2kxJVjnxzpTPlJgikSMYQDG6oS+JoMh8VbGa SdsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=UPr7zMI/E2/ifqFMbRRaecHTiVb99Ohkp74Lqfe/9YM=; b=oFb2yAW/xZQ4L1RnuQoP3SInIKswgfuII89eESHnsAVMVsd0LsEgOtql2r+i/zMAPZ XtNtj+zixXAEccmGjW1fgnBC7PWAMJ1YwK8VWz4KMTJJWZCmuNhXU1j+sYbtNQTs0ajH N7RnQfi2TPfBI35o7Hj+03yIxDwIn1s2ZQGpPCBoG4FExzHiAL4ZFKzjdSskT8MsF1yd ktOEwFK5g3OwsiixMNk1UGHpPW2pDxpN4vP6gDSjY8J92wfELWkX0MrNQdrnwzdBYUeN mSo8IiYMpj6efBQKopitr5TKdN2uowqkKh+DQ54R9LmHEyiOaLQniAW6ZZzSu43E+mfb zRYw== 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 t21si2855750pfi.221.2018.04.10.15.52.28; Tue, 10 Apr 2018 15:53:05 -0700 (PDT) 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 S1755996AbeDJWid (ORCPT + 99 others); Tue, 10 Apr 2018 18:38:33 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44842 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755969AbeDJWi3 (ORCPT ); Tue, 10 Apr 2018 18:38:29 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 8E022CC4; Tue, 10 Apr 2018 22:38:28 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ashok Raj , Borislav Petkov , Thomas Gleixner , Tom Lendacky , Arjan Van De Ven Subject: [PATCH 4.14 089/138] x86/microcode/intel: Check microcode revision before updating sibling threads Date: Wed, 11 Apr 2018 00:24:39 +0200 Message-Id: <20180410212912.530443736@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180410212902.121524696@linuxfoundation.org> References: <20180410212902.121524696@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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: Ashok Raj commit c182d2b7d0ca48e0d6ff16f7d883161238c447ed upstream. 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 Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/microcode/intel.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) --- 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 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_ { 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_ 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_ prev_rev = rev; } - c = &cpu_data(cpu); - uci->cpu_sig.rev = rev; c->microcode = rev;