From nobody Mon Dec 23 18:42:49 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 1515468961891439.4445039500399; Mon, 8 Jan 2018 19:36:01 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9CC332222758A; Mon, 8 Jan 2018 19:30:48 -0800 (PST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 9F78E21F833AA for ; Mon, 8 Jan 2018 19:30:46 -0800 (PST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Jan 2018 19:35:56 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.19]) by fmsmga004.fm.intel.com with ESMTP; 08 Jan 2018 19:35:55 -0800 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=192.55.52.43; helo=mga05.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,334,1511856000"; d="scan'208";a="19407609" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Tue, 9 Jan 2018 11:35:50 +0800 Message-Id: <20180109033552.378192-3-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.15.1.windows.2 In-Reply-To: <20180109033552.378192-1-ruiyu.ni@intel.com> References: <20180109033552.378192-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 2/4] UefiCpuPkg/MtrrLib: Fix bug that may calculate wrong MTRR result X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eric Dong , Star Zeng 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" Code forgot to initialize the optional weight between adjacent vertices. It caused wrong MTRR result was calculated for some memory settings. The logic was incorrectly removed when converting from POC code. The patch adds back the initialization. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Cc: Eric Dong Cc: Star Zeng --- UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 37 ++++++++++++++++++++++++--------= ---- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/Mtrr= Lib/MtrrLib.c index b83d768c5f..566a4cb67b 100644 --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c @@ -1583,20 +1583,33 @@ MtrrLibCalculateMtrrs ( Vector[VectorCount - 1].Address =3D Base1; =20 Weight =3D (UINT8 *) &Vector[VectorCount]; - // - // Set mandatory weight between any vector to max - // Set optional weight and between any vector and self->self to 0 - // E.g.: - // 00 FF FF FF - // 00 00 FF FF - // 00 00 00 FF - // 00 00 00 00 - // for (VectorIndex =3D 0; VectorIndex < VectorCount; VectorIndex++) { + // + // Set optional weight between vertices and self->self to 0 + // SetMem (&Weight[M(VectorIndex, 0)], VectorIndex + 1, 0); - if (VectorIndex !=3D VectorCount - 1) { - Weight[M (VectorIndex, VectorIndex + 1)] =3D (DefaultType =3D=3D Vec= tor[VectorIndex].Type) ? 0 : 1; - SetMem (&Weight[M (VectorIndex, VectorIndex + 2)], VectorCount - Vec= torIndex - 2, MAX_WEIGHT); + // + // Set mandatory weight between vectors to MAX_WEIGHT + // + SetMem (&Weight[M (VectorIndex, VectorIndex + 1)], VectorCount - Vecto= rIndex - 1, MAX_WEIGHT); + + // Final result looks like: + // 00 FF FF FF + // 00 00 FF FF + // 00 00 00 FF + // 00 00 00 00 + } + + // + // Set mandatory weight and optional weight for adjacent vertices + // + for (VectorIndex =3D 0; VectorIndex < VectorCount - 1; VectorIndex++) { + if (Vector[VectorIndex].Type !=3D DefaultType) { + Weight[M (VectorIndex, VectorIndex + 1)] =3D 1; + Weight[O (VectorIndex, VectorIndex + 1)] =3D 0; + } else { + Weight[M (VectorIndex, VectorIndex + 1)] =3D 0; + Weight[O (VectorIndex, VectorIndex + 1)] =3D 1; } } =20 --=20 2.15.1.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel