Received: by 10.192.165.156 with SMTP id m28csp28906imm; Tue, 10 Apr 2018 15:43:08 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+mPeTvmBh+L/32JIuoW7+sr5nTfDbB7UOjzFQwiKsy3rCs/QO1LbtGy5hjWhJOkyOYEZfd X-Received: by 10.99.126.73 with SMTP id o9mr1608514pgn.168.1523400188755; Tue, 10 Apr 2018 15:43:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523400188; cv=none; d=google.com; s=arc-20160816; b=iAZn+08Q+t7+NcMTXf/O5f3M61bmyKeyV5qpmRvdbJpCDHEm0ZY4PW3JyBXjqT/8mX MYxQhjxxvkC1awGOcvTkSZaqYIkEooLznbfZJrnguK+Gl8g279QCpMYazIvDCi8JNHJa ySxpDf3A4FsOkpjq9zruPcCJ7GHSNEmjDc0diDg6R1VpRctB+F56lJ3k0hoE81Yo60VV epvDfqLEfuyxRFpIdHWUll2f6pv1gynh3AYREsDco7HvrfRWdR4Xnt7yE5KQV5qMOH7r y6LI9OHeB5IcFgAl3SY7PTgzCbAy0ay8C66hoTBL0+v1E7x6WjP5UrzKvCw/9CA8vTIv D5Tg== 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=cMPCguNW1ekNPpHgLXfdFRwyu8bLDN/NWXpOz8b23h4=; b=XEEAcEd4ectAwKEjcjpQeyG9uVl7pUFkWUqTws6dwBnCasO4A/K74lB71RKafFUkQ/ fBWQzXmGq59p79cNSWlbYZ6gL0idDtAjXKf+6L+5m5YQi/+RQlZiAxTqmFft3wq4fIBn WV5B1jloT8Io+p8BoMY1YcXJX+NRi9IbyLyY5EUkiIZASdjmJGBFiMoCFVdHTRiuv1+Q 6nyNfQrd/3pqLBl5dj0lolHV3s2wiWiRrCANZMNQ0pucOE9s2DHyROaZcvqm+fOKa4sG EdHRl3wqbwK770ENhosNYMOd8LyUq8mCiCsg4QGStHaEYIDVysbb2MX6cAKuB36wSIsV 0oEw== 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 18si2834515pfl.407.2018.04.10.15.42.32; Tue, 10 Apr 2018 15:43:08 -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 S1756011AbeDJWih (ORCPT + 99 others); Tue, 10 Apr 2018 18:38:37 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44872 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755969AbeDJWie (ORCPT ); Tue, 10 Apr 2018 18:38:34 -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 E7178408; Tue, 10 Apr 2018 22:38:33 +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 091/138] x86/microcode: Do not upload microcode if CPUs are offline Date: Wed, 11 Apr 2018 00:24:41 +0200 Message-Id: <20180410212912.759185934@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 30ec26da9967d0d785abc24073129a34c3211777 upstream. Avoid loading microcode if any of the CPUs are offline, and issue a warning. Having different microcode revisions on the system at any time is outright dangerous. [ Borislav: Massage changelog. ] Signed-off-by: Ashok Raj Signed-off-by: Borislav Petkov Signed-off-by: Thomas Gleixner Tested-by: Tom Lendacky Tested-by: Ashok Raj Reviewed-by: Tom Lendacky Cc: Arjan Van De Ven Link: http://lkml.kernel.org/r/1519352533-15992-4-git-send-email-ashok.raj@intel.com Link: https://lkml.kernel.org/r/20180228102846.13447-5-bp@alien8.de Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/microcode/core.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -486,6 +486,16 @@ static void __exit microcode_dev_exit(vo /* fake device for request_firmware */ static struct platform_device *microcode_pdev; +static int check_online_cpus(void) +{ + if (num_online_cpus() == num_present_cpus()) + return 0; + + pr_err("Not all CPUs online, aborting microcode update.\n"); + + return -EINVAL; +} + static enum ucode_state reload_for_cpu(int cpu) { struct ucode_cpu_info *uci = ucode_cpu_info + cpu; @@ -519,7 +529,13 @@ static ssize_t reload_store(struct devic return size; get_online_cpus(); + + ret = check_online_cpus(); + if (ret) + goto put; + mutex_lock(µcode_mutex); + for_each_online_cpu(cpu) { tmp_ret = reload_for_cpu(cpu); if (tmp_ret > UCODE_NFOUND) { @@ -538,6 +554,8 @@ static ssize_t reload_store(struct devic microcode_check(); mutex_unlock(µcode_mutex); + +put: put_online_cpus(); if (!ret)