From nobody Fri May 3 18:22:01 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 150820482112260.4560711515403; Mon, 16 Oct 2017 18:47:01 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 04E4D202E61A1; Mon, 16 Oct 2017 18:43:24 -0700 (PDT) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 6A0DF202E6180 for ; Mon, 16 Oct 2017 18:43:22 -0700 (PDT) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Oct 2017 18:46:57 -0700 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.7]) by orsmga005.jf.intel.com with ESMTP; 16 Oct 2017 18:46:56 -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.20; helo=mga02.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,389,1503385200"; d="scan'208";a="161228237" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Tue, 17 Oct 2017 09:46:54 +0800 Message-Id: <20171017014654.274700-1-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.12.2.windows.2 Subject: [edk2] [PATCH] UefiCpuPkg/MtrrLib: Fix MtrrDebugPrintAllMtrrsWorker to avoid hang 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: Laszlo Ersek 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" ARRAY_SIZE(Mtrrs->Variables.Mtrr) was used in MtrrDebugPrintAllMtrrsWorker() to parse the MTRR registers. Instead, the actual variable MTRR count should be used. Otherwise, the uninitialized random data in MtrrSetting may cause MtrrLibSetMemoryType() hang. Steven Shi found this bug in QEMU when using Q35 chip. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Cc: Steven Shi Cc: Laszlo Ersek Reviewed-by: Laszlo Ersek Reviewed-by: Steven Shi --- UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/Mtrr= Lib/MtrrLib.c index 2fd1d0153e..cb22558103 100644 --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c @@ -2776,6 +2776,7 @@ MtrrDebugPrintAllMtrrsWorker ( UINTN RangeCount; UINT64 MtrrValidBitsMask; UINT64 MtrrValidAddressMask; + UINT32 VariableMtrrCount; MTRR_MEMORY_RANGE Ranges[ ARRAY_SIZE (mMtrrLibFixedMtrrTable) * sizeof (UINT64) + 2 * ARRAY_SI= ZE (Mtrrs->Variables.Mtrr) + 1 ]; @@ -2785,6 +2786,8 @@ MtrrDebugPrintAllMtrrsWorker ( return; } =20 + VariableMtrrCount =3D GetVariableMtrrCountWorker (); + if (MtrrSetting !=3D NULL) { Mtrrs =3D MtrrSetting; } else { @@ -2802,7 +2805,7 @@ MtrrDebugPrintAllMtrrsWorker ( DEBUG((DEBUG_CACHE, "Fixed MTRR[%02d] : %016lx\n", Index, Mtrrs->F= ixed.Mtrr[Index])); } =20 - for (Index =3D 0; Index < ARRAY_SIZE (Mtrrs->Variables.Mtrr); Index++)= { + for (Index =3D 0; Index < VariableMtrrCount; Index++) { 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 @@ -2829,11 +2832,11 @@ MtrrDebugPrintAllMtrrsWorker ( RangeCount =3D 1; =20 MtrrLibGetRawVariableRanges ( - &Mtrrs->Variables, ARRAY_SIZE (Mtrrs->Variables.Mtrr), + &Mtrrs->Variables, VariableMtrrCount, MtrrValidBitsMask, MtrrValidAddressMask, RawVariableRanges ); MtrrLibApplyVariableMtrrs ( - RawVariableRanges, ARRAY_SIZE (RawVariableRanges), + RawVariableRanges, VariableMtrrCount, Ranges, ARRAY_SIZE (Ranges), &RangeCount ); =20 --=20 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel