From patchwork Thu Nov 3 17:58:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashok Raj X-Patchwork-Id: 15067 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp684187wru; Thu, 3 Nov 2022 11:03:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6L7uEO5B6i6nwlX06O1v0KzAN5dAiYyWt/INwKL7x4tRkpLeI6Tizn+nVjkd06d1BBRpqi X-Received: by 2002:a17:90b:1bd2:b0:213:2d7:3162 with SMTP id oa18-20020a17090b1bd200b0021302d73162mr31820207pjb.91.1667498624638; Thu, 03 Nov 2022 11:03:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667498624; cv=none; d=google.com; s=arc-20160816; b=Tp2bu0xLHjjr8hdyvRoKn2r4QMmJx9oSKkHk8ZiblW3EkQq9Flm2+cU5zlyuNkzULt qjRFXkMDi5khgOkM6LD9e6vmuvinscpI6Wmgm3O/e2oMR+eh4yTe9Kn+SmWun+cnPwmL ved34bUnww097FRS+vnG/VhnU/jJcYLqo/CWVfiSiE/Tcwj5amlT9GlfCqbl8iFkR8Vn WWo87Q9gQWaYAMnm/NXLSfzlOm/wyMk1dol1SWQKpBeqSHiYl3LxXDDSkQuCDLq5gjNj 8vqoZxGJucWsdYwDxkpxOINTWRnc/hF6DwUHOYsKcVGA0lELDYRCIQDRI8jIp3XXkBZH oW7Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8vo5d4/69DGHvKHyq9fj89veEiD+jKq1OPZW9BTwcTs=; b=1HzJnZShaPalGBtUAOmBwM+XWExzgZBnnCvwgL2B+feFmdeiJ/f9rDMUm5WkLtPPnv JelzsCJ8KV2wRSZbW7HKSJQkZ3vw5Tr6b68UT0ujhY4NeAWS8ailxGKGF6+lrTF4AJTW KR3vVYg5O7KJPfUGsQdjh9d5rAnvWQSTMv7Fp3MzorPakKk/HunjEKeIR9EXy5ZUHqhq nzyoW5nz7JjjuDCfVeFZ96N00ULFUHORJMlMRBx8xVeLKsQ7/uQOmQU6rwhFrJbzfBy2 qTn6+q7e1Ibzx+p/UM+JkMv6nlMQ9hB3T2eJYq2xOUD1P96wbIMwUb3P+9jsd5XHrd4F X/8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LLMuadPU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t24-20020a634618000000b0046ff70b1cf3si1796006pga.463.2022.11.03.11.03.28; Thu, 03 Nov 2022 11:03:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LLMuadPU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232013AbiKCSAa (ORCPT + 99 others); Thu, 3 Nov 2022 14:00:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232070AbiKCR73 (ORCPT ); Thu, 3 Nov 2022 13:59:29 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B5F15F48 for ; Thu, 3 Nov 2022 10:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667498362; x=1699034362; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mK6qh3yJ3vr/2ZaLvzn6GOkotoEzPEIyO1PLPBrI3fk=; b=LLMuadPUnawCndMTQqgJceku9Kl57nmuAAYCV5IT8W3HlAfZvfe+ZtX7 6s5rci4S/N2UBod66MjupKWG+8O71OBHNa5ZH4voDZXv/jK/4zfMBS2oY xzeJ4dYipisAu9/PLD07ndN7a5bq4u44cTHigCHqkLWhn3kidg5JJUVt+ lsWFUcn16rOIqmcyf3X4MTIAruPlgVL5XXRcqqS0ltWBhIu49UX2fLdCE 09UjhKdo8EpoRHX98HUlP35qCElKytGC3Z55Ywhh/G5nqRKUQyCaSykIU UxybQhUHCr5hIO4IMir51GCG4xqV6sPPMrAOs7+qc9HVYdpus368vGF1J g==; X-IronPort-AV: E=McAfee;i="6500,9779,10520"; a="308476971" X-IronPort-AV: E=Sophos;i="5.96,134,1665471600"; d="scan'208";a="308476971" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2022 10:59:18 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10520"; a="809762562" X-IronPort-AV: E=Sophos;i="5.96,134,1665471600"; d="scan'208";a="809762562" Received: from araj-dh-work.jf.intel.com ([10.165.157.158]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2022 10:59:18 -0700 From: Ashok Raj To: Borislav Petkov , Thomas Gleixner Cc: "LKML Mailing List" , X86-kernel , Tony Luck , Dave Hansen , Arjan van de Ven , Andy Lutomirski , Jacon Jun Pan , Tom Lendacky , Kai Huang , Andrew Cooper , Ashok Raj Subject: [v2 08/13] x86/mce: Warn of a microcode update is in progress when MCE arrives Date: Thu, 3 Nov 2022 17:58:56 +0000 Message-Id: <20221103175901.164783-9-ashok.raj@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221103175901.164783-1-ashok.raj@intel.com> References: <20221103175901.164783-1-ashok.raj@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748499037914837273?= X-GMAIL-MSGID: =?utf-8?q?1748499037914837273?= Due to the nature of microcode updates to long flow instructions, its possible if an MCE is taken when microcode update is in progress could be dangerous. There is nothing the kernel can do to mitigate safely. Drop some bread crumbs to note that a MCE happened while a microcode update is also in progress. Suggested-by: Boris Petkov Reviewed-by: Tony Luck Signed-off-by: Ashok Raj --- arch/x86/include/asm/microcode.h | 2 ++ arch/x86/kernel/cpu/mce/core.c | 5 +++++ arch/x86/kernel/cpu/microcode/core.c | 9 +++++++++ 3 files changed, 16 insertions(+) diff --git a/arch/x86/include/asm/microcode.h b/arch/x86/include/asm/microcode.h index ffb46f2b0354..f16973fb7330 100644 --- a/arch/x86/include/asm/microcode.h +++ b/arch/x86/include/asm/microcode.h @@ -167,8 +167,10 @@ static inline void microcode_bsp_resume(void) { } #endif #ifdef CONFIG_MICROCODE_LATE_LOADING +extern int ucode_update_in_progress(void); extern void hold_sibling_in_nmi(void); #else +static inline int ucode_update_in_progress(void) { return 0; } static inline void hold_sibling_in_nmi(void) { } #endif diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index 2c8ec5c71712..67669686fab4 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -46,6 +46,7 @@ #include #include +#include #include #include #include @@ -1425,6 +1426,10 @@ noinstr void do_machine_check(struct pt_regs *regs) else if (unlikely(!mca_cfg.initialized)) return unexpected_machine_check(regs); + instrumentation_begin(); + if (ucode_update_in_progress()) + pr_warn("MCE triggered while microcode update is in progress\n"); + instrumentation_end(); if (mce_flags.skx_repmov_quirk && quirk_skylake_repmov()) goto clear; diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c index 6084a87ea8f3..6f59ffdf2881 100644 --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -327,6 +327,8 @@ void reload_early_microcode(void) static struct platform_device *microcode_pdev; #ifdef CONFIG_MICROCODE_LATE_LOADING +static int ucode_updating; + /* * Late loading dance. Why the heavy-handed stomp_machine effort? * @@ -556,6 +558,11 @@ static void microcode_check(struct cpuinfo_x86 *orig) pr_warn("x86/CPU: Please consider either early loading through initrd/built-in or a potential BIOS update.\n"); } +int ucode_update_in_progress(void) +{ + return ucode_updating; +} + /* * Reload microcode late on all CPUs. Wait for a sec until they * all gather together. @@ -578,7 +585,9 @@ static int microcode_reload_late(void) } copy_cpu_caps(&info); + ucode_updating = 1; ret = stop_machine_cpuslocked(__reload_late, NULL, cpu_online_mask); + ucode_updating = 0; if (ret == 0) microcode_check(&info);