Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp414741pxj; Thu, 20 May 2021 12:16:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlQINqYOMWzEVYsaxDQ0XKd0+cMBHLT64HhrP2plCuhbDnC57Q+X+tZLO1GoufishN8Zxz X-Received: by 2002:a50:d589:: with SMTP id v9mr6814835edi.126.1621538181421; Thu, 20 May 2021 12:16:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621538181; cv=none; d=google.com; s=arc-20160816; b=JNwN9KK08grIf6ffmN5rw08FLI6mjfpZDB2pk37wQYD665xs81zCsd8sNqfQZn37Sb XjdhSt9/7cLYqNkJvMEOlnHVqKEokmRbHewcfYS+wk4WY4INC5aJzGTB+Slgq1EnITm1 L63/2hvw1l7vn/mZ1x36X43l3ieEsW7P/y8miTB7smsMcDGJ8ZAy+1vfKFUtYrwi2ExF o39xyYjsq1eRa66HezRksNVc9ohFvZ6I1q8lsvAP1FrDM3ly56cd91mjaKs6cA6JCqjQ CKBaYGDqkG1Ss/DEpKXS/bw5WU510KpGzq+wXKjBnSNjsFKkGU/Q4AZ3GwCgbdCjdkJK uDCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Yg/yE+mspm+pySqKTS2NSEtOwFaHZsTaK6P6TsP17PY=; b=O4kbRyehdb8ngsEhfcICbD3J2iMkAkNUFJv5JzQn3Om6YjP0ARRIh0RvgmLdFCAeQv HxuhYoMvQZlgiaqekgHNpOkVm2/pRTr/PxHfu2ZrPYlW3G6AKe5rCYUKGzbP6wlNoyT9 AKrwPnYhyni5wOSACEurUt0uIaNBK6X1q7I16XfTfFhzoVGB7ODcvzk8/cdXb9FVdCCS iAs7040cOKrsndl7ioOQ2fzpw6DPH1Fc6wyaM56lp68kBHOfkruCAsjgG0fpPiXf0q5l Yk55gzFGI8zt5iUG3Vnj7vZGaGxn2tZjCrzH9jclIxz/P0/p/geigiLJxvNrRK0iC2VC Lc8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AxguqGI2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j23si3942868eje.99.2021.05.20.12.15.57; Thu, 20 May 2021 12:16:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AxguqGI2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236426AbhETKmJ (ORCPT + 99 others); Thu, 20 May 2021 06:42:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:55802 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236432AbhETK00 (ORCPT ); Thu, 20 May 2021 06:26:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0748A61C21; Thu, 20 May 2021 09:50:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504215; bh=7RWaWjYveePaY8Mpxqu4kZZKehtD0m+H22q+9jrGGSc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AxguqGI2wJ7Sv9Z0SShBW6uFqQN3oI0Q3byGixMZ/E9wL/TQJOgdCqkor+fE8YnjN JQ632rwOx/He6+I87d+EEy1QSFpeVeRYkBi0QdCzaL/zYGkpY86V9TKSUsVfVB0Cwy 3BLpmX3BV4M3xtrArjWhOPbnzGAK88yHpYFLiRqk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Otavio Pontes , Borislav Petkov , Tony Luck , Ashok Raj , Sasha Levin Subject: [PATCH 4.14 145/323] x86/microcode: Check for offline CPUs before requesting new microcode Date: Thu, 20 May 2021 11:20:37 +0200 Message-Id: <20210520092125.070854324@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Otavio Pontes [ Upstream commit 7189b3c11903667808029ec9766a6e96de5012a5 ] Currently, the late microcode loading mechanism checks whether any CPUs are offlined, and, in such a case, aborts the load attempt. However, this must be done before the kernel caches new microcode from the filesystem. Otherwise, when offlined CPUs are onlined later, those cores are going to be updated through the CPU hotplug notifier callback with the new microcode, while CPUs previously onine will continue to run with the older microcode. For example: Turn off one core (2 threads): echo 0 > /sys/devices/system/cpu/cpu3/online echo 0 > /sys/devices/system/cpu/cpu1/online Install the ucode fails because a primary SMT thread is offline: cp intel-ucode/06-8e-09 /lib/firmware/intel-ucode/ echo 1 > /sys/devices/system/cpu/microcode/reload bash: echo: write error: Invalid argument Turn the core back on echo 1 > /sys/devices/system/cpu/cpu3/online echo 1 > /sys/devices/system/cpu/cpu1/online cat /proc/cpuinfo |grep microcode microcode : 0x30 microcode : 0xde microcode : 0x30 microcode : 0xde The rationale for why the update is aborted when at least one primary thread is offline is because even if that thread is soft-offlined and idle, it will still have to participate in broadcasted MCE's synchronization dance or enter SMM, and in both examples it will execute instructions so it better have the same microcode revision as the other cores. [ bp: Heavily edit and extend commit message with the reasoning behind all this. ] Fixes: 30ec26da9967 ("x86/microcode: Do not upload microcode if CPUs are offline") Signed-off-by: Otavio Pontes Signed-off-by: Borislav Petkov Reviewed-by: Tony Luck Acked-by: Ashok Raj Link: https://lkml.kernel.org/r/20210319165515.9240-2-otavio.pontes@intel.com Signed-off-by: Sasha Levin --- arch/x86/kernel/cpu/microcode/core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c index 93c22e7ee424..51583a5d656d 100644 --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -627,16 +627,16 @@ static ssize_t reload_store(struct device *dev, if (val != 1) return size; - tmp_ret = microcode_ops->request_microcode_fw(bsp, µcode_pdev->dev, true); - if (tmp_ret != UCODE_NEW) - return size; - get_online_cpus(); ret = check_online_cpus(); if (ret) goto put; + tmp_ret = microcode_ops->request_microcode_fw(bsp, µcode_pdev->dev, true); + if (tmp_ret != UCODE_NEW) + goto put; + mutex_lock(µcode_mutex); ret = microcode_reload_late(); mutex_unlock(µcode_mutex); -- 2.30.2