Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2843841pxb; Mon, 18 Apr 2022 09:23:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJww1nSh7zZj95C6WcnuJexcHNDI2PdZNqn8Q3FuOYsj+YXiFiSAMWEV2jIUzHgWs5dLv9yn X-Received: by 2002:a05:6402:438c:b0:423:f57a:596f with SMTP id o12-20020a056402438c00b00423f57a596fmr1936809edc.367.1650298980530; Mon, 18 Apr 2022 09:23:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650298980; cv=none; d=google.com; s=arc-20160816; b=D9rW8dQQnwF6hS3kgDmnXghtev5WftqvVy4jM7Cjqnz5qjcLg0bXLKqS96fMDNS8R9 gwfb2Ohl16q2oFxqMx4okCRc9d8ws2UfAD3GeV9GXODukuSuETIdG+mQ6ZXezbq7KLtA F3BZlhEsw4dZTbfc78WZSApKrinjY4PIStR2rUJzPwc6SVqZe3gHfBtHh+aYpCQIzowz g6RERc79YtXKpHeZG9gciMjaR5qZLTr9gdkoiMAQXqx149abJ789i3SgghB5VLVVpmkB NDK4qUHcON0qP/uAtOGjJy7R4iPaZrgMxtq2CQ9ByFpPPc4ATBFJoTwZZdyl8m+fnxEb NKUg== 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=YC+K53EVuEd0Gn8PJDjYF99l/kwaSqOl9lkghHLUgIg=; b=OezOge5/p/Sex58UOySpWjWXPgrc60w5V1FmJl4Tcx79HwGEOwIZWjLlhXB9Ob3RWO hn8LTc/DwCZlzo93Gf/7UNJbbkJJyTJC2XbGCrS0qjyq0W39ypF6cniL2O3tQfmjTb3j Gi47r56idzqmV46CRWVbeW3T1ToMSo4alPwKLHX3Mx6484XlRDlDOjaTtneyxWfEfIkf VRNsvaaZ4h9AXK9SSRdgCCfEuehkzm9ozUcPUiNwZuxXDtCLlscGj1Hav9OyYoW7Q65N +LyXTxzbVdPJPcQmIrUO79Hc6cnYwGzsbOMsLMJfuj5kUyYQL+Am7R3PcFUeSKIi2xyJ 9+Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Fm20q065; 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 m13-20020a056402510d00b00423f14d91ddsi1593089edd.324.2022.04.18.09.22.36; Mon, 18 Apr 2022 09:23:00 -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=Fm20q065; 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 S245432AbiDROC6 (ORCPT + 99 others); Mon, 18 Apr 2022 10:02:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244449AbiDRNo1 (ORCPT ); Mon, 18 Apr 2022 09:44:27 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BAED3F33B; Mon, 18 Apr 2022 05:59:59 -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 1C3C2B80E44; Mon, 18 Apr 2022 12:59:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D2B8C385A1; Mon, 18 Apr 2022 12:59:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650286796; bh=1m3xIrLcO5FIijhI2wj1F439x8Le5NCM2hWe+oEGa6s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fm20q065B9sfyYAMC2+g25FnrZ8yj0du2/kDTVdMh1cUMejUrLb57jdI2+GNgNOrk hbtIpkF1Od2j8QRONCHSMgMdlmdIUvlSes7Irq6RBmUAVQto9K2300UN8YtSTTsxaI KczD8ugvAOzpuqTK3yadkSfmlWUP15Q9mc3d+wZQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Hansen , Pawan Gupta , Borislav Petkov , Linus Torvalds Subject: [PATCH 4.14 247/284] x86/pm: Save the MSR validity status at context setup Date: Mon, 18 Apr 2022 14:13:48 +0200 Message-Id: <20220418121219.177917828@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121210.689577360@linuxfoundation.org> References: <20220418121210.689577360@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: Pawan Gupta commit 73924ec4d560257004d5b5116b22a3647661e364 upstream. The mechanism to save/restore MSRs during S3 suspend/resume checks for the MSR validity during suspend, and only restores the MSR if its a valid MSR. This is not optimal, as an invalid MSR will unnecessarily throw an exception for every suspend cycle. The more invalid MSRs, higher the impact will be. Check and save the MSR validity at setup. This ensures that only valid MSRs that are guaranteed to not throw an exception will be attempted during suspend. Fixes: 7a9c2dd08ead ("x86/pm: Introduce quirk framework to save/restore extra MSR registers around suspend/resume") Suggested-by: Dave Hansen Signed-off-by: Pawan Gupta Reviewed-by: Dave Hansen Acked-by: Borislav Petkov Cc: stable@vger.kernel.org Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- arch/x86/power/cpu.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/arch/x86/power/cpu.c +++ b/arch/x86/power/cpu.c @@ -41,7 +41,8 @@ static void msr_save_context(struct save struct saved_msr *end = msr + ctxt->saved_msrs.num; while (msr < end) { - msr->valid = !rdmsrl_safe(msr->info.msr_no, &msr->info.reg.q); + if (msr->valid) + rdmsrl(msr->info.msr_no, msr->info.reg.q); msr++; } } @@ -426,8 +427,10 @@ static int msr_build_context(const u32 * } for (i = saved_msrs->num, j = 0; i < total_num; i++, j++) { + u64 dummy; + msr_array[i].info.msr_no = msr_id[j]; - msr_array[i].valid = false; + msr_array[i].valid = !rdmsrl_safe(msr_id[j], &dummy); msr_array[i].info.reg.q = 0; } saved_msrs->num = total_num;