Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4665261pxj; Wed, 12 May 2021 10:23:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiqgFXtaIMMqXkvWYpLepWwCaheSCd/7FbAmeq+U+URVbynb0l8FdkDfNPklwuyd/r6TOg X-Received: by 2002:a17:906:58d6:: with SMTP id e22mr38940248ejs.216.1620840181625; Wed, 12 May 2021 10:23:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620840181; cv=none; d=google.com; s=arc-20160816; b=E4HTpbzeFSNVIr8aR0fzU9GIulc7KV8mafBQP32Vz+8F2cyAfLnj+6FkVrz2i2K6JU gx+w7UeVczH1yRkL5rrKVHmP/tFaN04FNg608YvdhriXxAtboLhyFg5s8ISANlAuXpYD b5NnW3bHzRw/zGKznAnfgYacuetkTd4NsSIMMH96ESCF6aVDcuAinX71qWfaysoPsdSW i4+2ozxxtgORJwQOJORzvoVlU9K6SdLJbVvMGuH+36K1n7A/4Uic1ujce/QP9da2LoUx mAzcD/2G1zU98v6LKJjtfFOGl4GsPS7iu1GAIFgvnE1W3liTPkWtFU1YWT6D6fcarLhK RmWg== 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=isL6espbjHRl9Vnr8BgaTc9cPHudPD2XJkqIj5u91xZBAtOvvoqhn4l2/7TQ6yDfd0 zr0LA4hOgEptHr5CJN4zjY5bjmCHVJk5QuhqBc8KhT/haPmbsF7N9dJNguf8smd4BOTq G33ZG4z/I49UrZDqk4a3kLpDHzGUdL5XMwxwAANLxGy/bz8lNyEQCaHRYg0zuHD8gKRS 4lz5dZ2hw5H+09mOw684/R/E1rT2UXh/faQ7EHp7xsemhicjbIpwlNFuksyn05qxpPzY cPU7YH2Fo2kdyOIdU65wgWaL7I4rxfEE6o8L2xiezMgk2iLWhegwclwqsUCUPg6q9LE8 2o+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YllFA5QN; 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 fy8si478274ejb.54.2021.05.12.10.22.36; Wed, 12 May 2021 10:23:01 -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=YllFA5QN; 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 S1345856AbhELRMK (ORCPT + 99 others); Wed, 12 May 2021 13:12:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:48112 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235378AbhELP7l (ORCPT ); Wed, 12 May 2021 11:59:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7FDAA61CC5; Wed, 12 May 2021 15:32:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620833538; bh=o5oqbkMVJmjlAf0Eu5IO1+PBt/2w4iV8hZ4r1VQk++g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YllFA5QNhvBg5XY5U7ojsOTedOutv1ffLPqZjmZIyHQp2SRhmaOswPTaOyh9DzBbX abGGIJy+kmG2kQf9PY8zXQUURh9AeJVfkQjLW9MBy8Ad7mi/VUFlcI9mxqlOT0ERqy u3hy89MS8azYuxGdt3rEChie6b/pozblXyhi4ji8= 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.11 190/601] x86/microcode: Check for offline CPUs before requesting new microcode Date: Wed, 12 May 2021 16:44:27 +0200 Message-Id: <20210512144834.091897794@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144827.811958675@linuxfoundation.org> References: <20210512144827.811958675@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