From nobody Fri Nov 1 22:38:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1507798107612671.4804510584618; Thu, 12 Oct 2017 01:48:27 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5E96421F38832; Thu, 12 Oct 2017 01:44:49 -0700 (PDT) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 023B921F38820 for ; Thu, 12 Oct 2017 01:44:47 -0700 (PDT) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP; 12 Oct 2017 01:48:18 -0700 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.7]) by FMSMGA003.fm.intel.com with ESMTP; 12 Oct 2017 01:48:17 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,365,1503385200"; d="scan'208";a="909212144" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Thu, 12 Oct 2017 16:48:10 +0800 Message-Id: <20171012084810.148196-5-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.12.2.windows.2 In-Reply-To: <20171012084810.148196-1-ruiyu.ni@intel.com> References: <20171012084810.148196-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 4/4] UefiCpuPkg/MtrrLib: Skip Base MSR access when the pair is invalid X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael D Kinney MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The patch optimized the MTRR access code to skip the Base MSR access when the Mask MSR indicates the pair is invalid. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Michael D Kinney --- UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/Mtrr= Lib/MtrrLib.c index a7adbafae3..2fd1d0153e 100644 --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c @@ -449,10 +449,13 @@ MtrrGetVariableMtrrWorker ( =20 for (Index =3D 0; Index < VariableMtrrCount; Index++) { if (MtrrSetting =3D=3D NULL) { - VariableSettings->Mtrr[Index].Base =3D - AsmReadMsr64 (MSR_IA32_MTRR_PHYSBASE0 + (Index << 1)); - VariableSettings->Mtrr[Index].Mask =3D - AsmReadMsr64 (MSR_IA32_MTRR_PHYSMASK0 + (Index << 1)); + VariableSettings->Mtrr[Index].Mask =3D AsmReadMsr64 (MSR_IA32_MTRR_P= HYSMASK0 + (Index << 1)); + // + // Skip to read the Base MSR when the Mask.V is not set. + // + if (((MSR_IA32_MTRR_PHYSMASK_REGISTER *)&VariableSettings->Mtrr[Inde= x].Mask)->Bits.V !=3D 0) { + VariableSettings->Mtrr[Index].Base =3D AsmReadMsr64 (MSR_IA32_MTRR= _PHYSBASE0 + (Index << 1)); + } } else { VariableSettings->Mtrr[Index].Base =3D MtrrSetting->Variables.Mtrr[I= ndex].Base; VariableSettings->Mtrr[Index].Mask =3D MtrrSetting->Variables.Mtrr[I= ndex].Mask; @@ -2540,14 +2543,14 @@ MtrrSetVariableMtrrWorker ( ASSERT (VariableMtrrCount <=3D ARRAY_SIZE (VariableSettings->Mtrr)); =20 for (Index =3D 0; Index < VariableMtrrCount; Index++) { - AsmWriteMsr64 ( - MSR_IA32_MTRR_PHYSBASE0 + (Index << 1), - VariableSettings->Mtrr[Index].Base - ); - AsmWriteMsr64 ( - MSR_IA32_MTRR_PHYSMASK0 + (Index << 1), - VariableSettings->Mtrr[Index].Mask - ); + // + // Mask MSR is always updated since caller might need to invalidate th= e MSR pair. + // Base MSR is skipped when Mask.V is not set. + // + AsmWriteMsr64 (MSR_IA32_MTRR_PHYSMASK0 + (Index << 1), VariableSetting= s->Mtrr[Index].Mask); + if (((MSR_IA32_MTRR_PHYSMASK_REGISTER *)&VariableSettings->Mtrr[Index]= .Mask)->Bits.V !=3D 0) { + AsmWriteMsr64 (MSR_IA32_MTRR_PHYSBASE0 + (Index << 1), VariableSetti= ngs->Mtrr[Index].Base); + } } } =20 @@ -2800,7 +2803,7 @@ MtrrDebugPrintAllMtrrsWorker ( } =20 for (Index =3D 0; Index < ARRAY_SIZE (Mtrrs->Variables.Mtrr); Index++)= { - if ((Mtrrs->Variables.Mtrr[Index].Mask & BIT11) =3D=3D 0) { + if (((MSR_IA32_MTRR_PHYSMASK_REGISTER *)&Mtrrs->Variables.Mtrr[Index= ].Mask)->Bits.V =3D=3D 0) { // // If mask is not valid, then do not display range // --=20 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel