Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1451710iob; Thu, 5 May 2022 01:17:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZsapip4GT5c7Iyuzpg84yJSZwvXciGq1kqNPh3xahW52LeYpCv1PdUSXi2oqGdLr8DFqX X-Received: by 2002:a17:90b:3b4a:b0:1dc:4aba:5e6c with SMTP id ot10-20020a17090b3b4a00b001dc4aba5e6cmr4610419pjb.105.1651738646208; Thu, 05 May 2022 01:17:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651738646; cv=none; d=google.com; s=arc-20160816; b=G/Cqzw/t8IAlb/fCF2T+ClIOmjuxag7rlpsguiFiSJK0qlhTLtyuyY99v0vveWUl+y u86AOBw0Dr4D+OBKz/pUkP+G4hhIiFjsOmzof4zTO8qQcZPlIZO07v5Fleq1I1/sPcyT +BJuyM1MP3Z/qguVvGvvhK41pnG9MumAw22bgUq1QL9fQ8NEo1LSuQJ1HU5Bo5zjj2xt lzqmw5HmP4eNRxcIIQmhAwOJi28YrMsaGoEb+hPeMtGJ6+6yeOT+IaJSd0FDAhSv2QNU NhWU5wBMcY/iRA2gcwGHisNaIQRjdL2lmBlwmDrwW4XS4IF/CY3I1HP1KnIzVP0pL4js vogQ== 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=m4T7QVBz/u+I4f+pvI0yVP6VYq8VG92RhbbvW6jkoLo=; b=x7eU75FWgRBJfVzffSv/Vdu81y7vKpn4XFfW2lhVLE3QmdvWYQB0Hkvkx9IbPKPTPW lhYdQ0QrnrauUi7aX7/k7ULbudiN+Z+5BAMjbXL8v8oJYMJQxkCbwDlgnzYd5wDW+8g/ bpJJmIvAb4M7D872BJMgAOcbZif6Yo2G77nk+7FnR+O1yzgD2pA3T2/fxOX0f+BVQICa Nfy0+k7/8o73NKMdPSqU6/xbdUz4fE8lSFVOj2ISX8Y3/uB0QvBxATokT4KA8UzLydaD L3d6l8cua2wTJhAYWO7XBFocuOReJZiKv3rtjQfnxeik5+AVtrz3gquV4NAzMmrxqj0e x6VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HJ1xY0ai; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r5-20020a63fc45000000b003ab2440ce56si808565pgk.207.2022.05.05.01.17.12; Thu, 05 May 2022 01:17:26 -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=@linuxfoundation.org header.s=korg header.b=HJ1xY0ai; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347916AbiEDR2V (ORCPT + 99 others); Wed, 4 May 2022 13:28:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356059AbiEDRJA (ORCPT ); Wed, 4 May 2022 13:09:00 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 884D4527FC; Wed, 4 May 2022 09:54:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D6D93B827A1; Wed, 4 May 2022 16:54:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 830E7C385AA; Wed, 4 May 2022 16:54:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651683288; bh=RBMnnnhTdU5vF+pNpaHECS7/w9g/gvmTy+FUbpj082Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HJ1xY0aiGyjvyz9Sj8X1Gbc0fDvICyCvY/pJV+qJ64hsT5STVFUzTljXOekp8HHEr 9oz+Rw+MQ+xI6oQS0mEWNMHX0+enJD3rBXAP0tKl1eHYBmaAlFMeZrXOuAB5UkqTGN 0mYGNq73++V1kcqOMRYpL5Ujo6C2X4+vuzJaEwjA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Kyle D. Pelton" , Borislav Petkov , Pawan Gupta Subject: [PATCH 5.15 154/177] x86/cpu: Load microcode during restore_processor_state() Date: Wed, 4 May 2022 18:45:47 +0200 Message-Id: <20220504153107.184337271@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504153053.873100034@linuxfoundation.org> References: <20220504153053.873100034@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Borislav Petkov commit f9e14dbbd454581061c736bf70bf5cbb15ac927c upstream. When resuming from system sleep state, restore_processor_state() restores the boot CPU MSRs. These MSRs could be emulated by microcode. If microcode is not loaded yet, writing to emulated MSRs leads to unchecked MSR access error: ... PM: Calling lapic_suspend+0x0/0x210 unchecked MSR access error: WRMSR to 0x10f (tried to write 0x0...0) at rIP: ... (native_write_msr) Call Trace: ? restore_processor_state x86_acpi_suspend_lowlevel acpi_suspend_enter suspend_devices_and_enter pm_suspend.cold state_store kobj_attr_store sysfs_kf_write kernfs_fop_write_iter new_sync_write vfs_write ksys_write __x64_sys_write do_syscall_64 entry_SYSCALL_64_after_hwframe RIP: 0033:0x7fda13c260a7 To ensure microcode emulated MSRs are available for restoration, load the microcode on the boot CPU before restoring these MSRs. [ Pawan: write commit message and productize it. ] Fixes: e2a1256b17b1 ("x86/speculation: Restore speculation related MSRs during S3 resume") Reported-by: Kyle D. Pelton Signed-off-by: Borislav Petkov Signed-off-by: Pawan Gupta Tested-by: Kyle D. Pelton Cc: stable@vger.kernel.org Link: https://bugzilla.kernel.org/show_bug.cgi?id=215841 Link: https://lore.kernel.org/r/4350dfbf785cd482d3fafa72b2b49c83102df3ce.1650386317.git.pawan.kumar.gupta@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/microcode.h | 2 ++ arch/x86/kernel/cpu/microcode/core.c | 6 +++--- arch/x86/power/cpu.c | 10 +++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) --- a/arch/x86/include/asm/microcode.h +++ b/arch/x86/include/asm/microcode.h @@ -132,10 +132,12 @@ extern void load_ucode_ap(void); void reload_early_microcode(void); extern bool get_builtin_firmware(struct cpio_data *cd, const char *name); extern bool initrd_gone; +void microcode_bsp_resume(void); #else static inline void __init load_ucode_bsp(void) { } static inline void load_ucode_ap(void) { } static inline void reload_early_microcode(void) { } +static inline void microcode_bsp_resume(void) { } static inline bool get_builtin_firmware(struct cpio_data *cd, const char *name) { return false; } #endif --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -775,9 +775,9 @@ static struct subsys_interface mc_cpu_in }; /** - * mc_bp_resume - Update boot CPU microcode during resume. + * microcode_bsp_resume - Update boot CPU microcode during resume. */ -static void mc_bp_resume(void) +void microcode_bsp_resume(void) { int cpu = smp_processor_id(); struct ucode_cpu_info *uci = ucode_cpu_info + cpu; @@ -789,7 +789,7 @@ static void mc_bp_resume(void) } static struct syscore_ops mc_syscore_ops = { - .resume = mc_bp_resume, + .resume = microcode_bsp_resume, }; static int mc_cpu_starting(unsigned int cpu) --- a/arch/x86/power/cpu.c +++ b/arch/x86/power/cpu.c @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef CONFIG_X86_32 __visible unsigned long saved_context_ebx; @@ -262,11 +263,18 @@ static void notrace __restore_processor_ x86_platform.restore_sched_clock_state(); mtrr_bp_restore(); perf_restore_debug_store(); - msr_restore_context(ctxt); c = &cpu_data(smp_processor_id()); if (cpu_has(c, X86_FEATURE_MSR_IA32_FEAT_CTL)) init_ia32_feat_ctl(c); + + microcode_bsp_resume(); + + /* + * This needs to happen after the microcode has been updated upon resume + * because some of the MSRs are "emulated" in microcode. + */ + msr_restore_context(ctxt); } /* Needed by apm.c */