Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4594205pxj; Wed, 12 May 2021 08:53:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywRUCTtJW59d5kl2/jYgK9Cr9t1/O8jR6gf55/4nhAO5yadmzOQE6DPfdN1CtiWehAG01e X-Received: by 2002:a17:906:eda3:: with SMTP id sa3mr38660657ejb.415.1620834830282; Wed, 12 May 2021 08:53:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620834830; cv=none; d=google.com; s=arc-20160816; b=MXtbaOr+YE5HuIXWuGjKZR5goGgxGJt+G3dmf8nFKaHK7SHCgVh4RCUOQt0MZLwTSz eshVrxwd+V3VYCnAXh8L9BeGF69o8u/KhehrQ9SZxQZf21LcUY/NV4PSYgFDD/pj4u9I w5sAA/Dgk/6bXImKWd2/olL3lZQKjGj7DnMlCh5X/WYmsCLlWuaWrWbl/rMl/Db2CC2k EtESZyyJmB3ggyvt5IXU+KTvbIT5r72CO69J3hh3fekBahDowe6vERwtDzf5wxkexelh fWfoR0qw/rMIec+EEfk57T12SJQ7LSsxXrGC8Ixg6AdtV3EwG5qsOsvcRD9VZsFUvEXo IwJg== 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=YSlzsYTWklYdtWxiAYTkeYVirNSiSPC/FjgZ5cHEMyI=; b=o7R01J3pP8fCX/g/b5a9VnyvIdtXOysahTn6N5eZI9GjQJwDgJoRM9ZgVtItc40+Uj XIK0aLLRMnEHe8eYkJGb7b6oNcyqSmckcaLKQjGcZgA41s/EMgeblR1POI/SbYUjHl/N uCgcBN0+lh1SVByoXUvTWYQJfRFzxp33utrxYmQb+s0BGJ4Ggjx1cS8CXAne4HHN0CIB k4GmdsYCEI2ICC+lkGmWzDkwormVNNsQmwfdqTeC6fCbVqpFD+Qb52KI6LlsoR/7z4xv /DDztYpVIZiCOSciGr1GHCE0Ln1XVn8bxNbMW7NUjpIR4pZmqwXXH4E5C5PEGioMvwtB 2LZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fNTtQZcq; 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 g14si283885ejx.307.2021.05.12.08.53.26; Wed, 12 May 2021 08:53:50 -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=fNTtQZcq; 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 S237082AbhELPsI (ORCPT + 99 others); Wed, 12 May 2021 11:48:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:57874 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232512AbhELPW1 (ORCPT ); Wed, 12 May 2021 11:22:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 86678619AD; Wed, 12 May 2021 15:09:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832161; bh=o5oqbkMVJmjlAf0Eu5IO1+PBt/2w4iV8hZ4r1VQk++g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fNTtQZcqhPdrVeAv9heRWFfzfRmXRir/GJdzZvjpwMNsxFNTCpOWIWb3qEolmBY0i zmDrBZe+TL+tYKZuqFIwKKK4vzGxfIJctysY+nX8sIzGhQ5ku11KvFGw15krBUP9kI 2I1HpoiHdzUeUzZypsVrf5bX9kJbsiJp+tNtHOJc= 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 5.10 166/530] x86/microcode: Check for offline CPUs before requesting new microcode Date: Wed, 12 May 2021 16:44:36 +0200 Message-Id: <20210512144825.293147780@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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 ec6f0415bc6d..bbbd248fe913 100644 --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -629,16 +629,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