From nobody Mon Sep 16 20:02:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+108566+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+108566+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694579244; cv=none; d=zohomail.com; s=zohoarc; b=PXseErgM6h+GLrnfJbPedkvZJ7IlJiEVb6mGBql1GgYsKEh6vjsAnANEKNAHobNUAfVuuXt8iyXOsULemLN3r5cnOx2Z61pk90fZvLWx9/nntL+Hg5A4bul7djs2Xr/ceoH2WjYIqj6vjDSYTGzMf0HUtfYYHpyhn9S5OQRHkGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694579244; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=7DXbQiKdjOsUF1NuPI+hF4ooqydCm+c+Pksx3QJQ3O0=; b=c5bQKj+206duB7McdrSwtSHg5AjTW+OEslgGeXMN8BVT4O3G18/vfa4j4ej5wcCFPZxeeYCq1YD6PTmlOlZ4eMVtcJ0bd0ctqKRyKhOAssn1gx4c/uoXHlCRotYUjnOnDJL4Rovkd2uNnL8SnSBWPgXm59mhm3ya8AHRQscafyQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+108566+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1694579244457210.23050024696533; Tue, 12 Sep 2023 21:27:24 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=R/1DoDabtbxIZc/ykPAqtr9Z8sh55U4s/0v3VrEHsMU=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1694579244; v=1; b=KDs/8uvdzXS5RJEa51DIiyA3qTuaj8e9dWjdtqPHuwJfpLOFQqbC2BJxeCbQb+ID5OYzUUDk iEqIEQjnkctueoJY43T932OVSmkqjjCF9yea73xZYjNWv3QJWH4OwGnfTUtJZ7YZbgAzojJEQxC cKOBJcqqVADhf1aFySXp/Gvc= X-Received: by 127.0.0.2 with SMTP id UBTrYY1788612xAw91jBnd0B; Tue, 12 Sep 2023 21:27:24 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web11.4645.1694579216558329653 for ; Tue, 12 Sep 2023 21:27:23 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10831"; a="363595473" X-IronPort-AV: E=Sophos;i="6.02,142,1688454000"; d="scan'208";a="363595473" X-Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 21:27:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10831"; a="859093656" X-IronPort-AV: E=Sophos;i="6.02,142,1688454000"; d="scan'208";a="859093656" X-Received: from shwdeopenlab705.ccr.corp.intel.com ([10.239.55.100]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 21:27:21 -0700 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Ray Ni , Yuanhao Xie , Eric Dong , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH 10/16] UefiCpuPkg/MtrrLib: Fix MtrrSetAllMtrrs to handle absent fixed MTRRs. Date: Wed, 13 Sep 2023 12:26:33 +0800 Message-Id: <20230913042639.2066-11-yuanhao.xie@intel.com> In-Reply-To: <20230913042639.2066-1-yuanhao.xie@intel.com> References: <20230913042639.2066-1-yuanhao.xie@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,yuanhao.xie@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: R5vrjGf4f1dIMedp5PgqlyXdx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1694579245209100001 Content-Type: text/plain; charset="utf-8" From: Ray Ni Update MtrrSetAllMtrrs to not access fixed MTRRs if CPU doesn't support them. Signed-off-by: Ray Ni Signed-off-by: Yuanhao Xie Cc: Eric Dong Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/Include/Library/MtrrLib.h | 9 ++++++--- UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 26 ++++++++++++++++++++------ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/UefiCpuPkg/Include/Library/MtrrLib.h b/UefiCpuPkg/Include/Libr= ary/MtrrLib.h index 683d9f2c14..94cf615901 100644 --- a/UefiCpuPkg/Include/Library/MtrrLib.h +++ b/UefiCpuPkg/Include/Library/MtrrLib.h @@ -1,7 +1,7 @@ /** @file MTRR setting library =20 - Copyright (c) 2008 - 2020, Intel Corporation. All rights reserved.
+ Copyright (c) 2008 - 2023, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -214,9 +214,12 @@ MtrrGetAllMtrrs ( /** This function sets all MTRRs (variable and fixed) =20 - @param[in] MtrrSetting A buffer to hold all MTRRs content. + Note: The behavior of this function is to program everything in MtrrSett= ing to hardware. + MTRR might not be enabled due to enable bit is clear in MtrrSettin= g->MtrrDefType. =20 - @return The pointer of MtrrSetting + @param[in] MtrrSetting A buffer holding all MTRRs content. + + @retval The pointer of MtrrSetting =20 **/ MTRR_SETTINGS * diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/Mtrr= Lib/MtrrLib.c index b63c4b1c26..9a01f1417f 100644 --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c @@ -2868,7 +2868,10 @@ MtrrGetAllMtrrs ( } =20 /** - This function sets all MTRRs (variable and fixed) + This function sets all MTRRs includes Variable and Fixed. + + The behavior of this function is to program everything in MtrrSetting to= hardware. + MTRRs might not be enabled because the enable bit is clear in MtrrSettin= g->MtrrDefType. =20 @param[in] MtrrSetting A buffer holding all MTRRs content. =20 @@ -2881,21 +2884,32 @@ MtrrSetAllMtrrs ( IN MTRR_SETTINGS *MtrrSetting ) { - MTRR_CONTEXT MtrrContext; + BOOLEAN FixedMtrrSupported; + MSR_IA32_MTRR_DEF_TYPE_REGISTER *MtrrDefType; + MTRR_CONTEXT MtrrContext; =20 - if (!IsMtrrSupported ()) { + MtrrDefType =3D (MSR_IA32_MTRR_DEF_TYPE_REGISTER *)&MtrrSetting->MtrrDef= Type; + if (!MtrrLibIsMtrrSupported (&FixedMtrrSupported, NULL)) { return MtrrSetting; } =20 MtrrLibPreMtrrChange (&MtrrContext); =20 // - // Set fixed MTRRs + // Enabling the Fixed MTRR bit when unsupported is not allowed. + // + ASSERT (FixedMtrrSupported || (MtrrDefType->Bits.FE =3D=3D 0)); + + // + // If the hardware supports Fixed MTRR, it is sufficient + // to set MTRRs regardless of whether Fixed MTRR bit is enabled. // - MtrrSetFixedMtrrWorker (&MtrrSetting->Fixed); + if (FixedMtrrSupported) { + MtrrSetFixedMtrrWorker (&MtrrSetting->Fixed); + } =20 // - // Set variable MTRRs + // Set Variable MTRRs // MtrrSetVariableMtrrWorker (&MtrrSetting->Variables); =20 --=20 2.36.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#108566): https://edk2.groups.io/g/devel/message/108566 Mute This Topic: https://groups.io/mt/101331028/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-