From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 B44B621A134AE for ; Thu, 4 May 2017 19:17:31 -0700 (PDT) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga105.jf.intel.com with ESMTP; 04 May 2017 19:17:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,290,1491289200"; d="scan'208";a="83837523" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga004.jf.intel.com with ESMTP; 04 May 2017 19:17:31 -0700 Received: from fmsmsx121.amr.corp.intel.com (10.18.125.36) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 4 May 2017 19:17:31 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by fmsmsx121.amr.corp.intel.com (10.18.125.36) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 4 May 2017 19:17:31 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.246]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.193]) with mapi id 14.03.0319.002; Fri, 5 May 2017 10:17:29 +0800 From: "Fan, Jeff" To: "Ni, Ruiyu" , "edk2-devel@lists.01.org" Thread-Topic: [PATCH] UefiCpuPkg/MtrrLib: Don't report OutOfResource when MTRR is enough Thread-Index: AQHSxUWHg3cMOibQvke7/OJ+jzGoaKHlAN2w Date: Fri, 5 May 2017 02:17:28 +0000 Message-ID: <542CF652F8836A4AB8DBFAAD40ED192A4C5BBA90@shsmsx102.ccr.corp.intel.com> References: <20170505021546.193068-1-ruiyu.ni@intel.com> In-Reply-To: <20170505021546.193068-1-ruiyu.ni@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZGNhM2EyMDYtNzYzYy00Zjc1LTk1N2EtNWQzMGI4OTM4ODVhIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6IkN2VmlmenZ4bVkrVVdMZGV6Zk1XdU5GVnphUjlrVFwvY0Y0S0ZZNWx5XC90bz0ifQ== x-ctpclassification: CTP_IC x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] UefiCpuPkg/MtrrLib: Don't report OutOfResource when MTRR is enough 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: , X-List-Received-Date: Fri, 05 May 2017 02:17:31 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jeff Fan -----Original Message----- From: Ni, Ruiyu=20 Sent: Friday, May 05, 2017 10:16 AM To: edk2-devel@lists.01.org Cc: Fan, Jeff Subject: [PATCH] UefiCpuPkg/MtrrLib: Don't report OutOfResource when MTRR i= s enough The MTRR calculation algorithm contains a bug that when left subtraction ca= nnot produce better MTRR solution, it forgets to restore the BaseAddress/Le= ngth so that MtrrLibGetMtrrNumber() returns bigger value of actual required= MTRR numbers. As a result, the MtrrLib reports OutOfResource but actually the MTRR is eno= ugh. MEMORY_RANGE mC[] =3D { 0, 0x100000, CacheUncacheable, 0x100000, 0x89F00000, CacheWriteBack, 0x8A000000, 0x75000000, CacheUncacheable, 0xFF000000, 0x01000000, CacheWriteProtected, 0x100000000, 0x7F00000000, CacheUncacheable, 0xFC240000, 0x2000, CacheWriteCombining // <-- trigger the error }; Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Jeff Fan --- UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/Mtrr= Lib/MtrrLib.c index 9d1927262a..cf1af29936 100644 --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c @@ -851,6 +851,8 @@ MtrrLibGetMtrrNumber ( UINT64 SubtractiveLength; UINT64 BaseAlignment; UINT32 Index; + UINT64 OriginalBaseAddress; + UINT64 OriginalLength; =20 *SubLeft =3D 0; *SubRight =3D 0; @@ -861,6 +863,9 @@ MtrrLibGetMtrrNumber ( // Get the optimal left subtraction solution. // if (BaseAddress !=3D 0) { + + OriginalBaseAddress =3D BaseAddress; + OriginalLength =3D Length; SubtractiveBaseAddress =3D 0; SubtractiveLength =3D 0; // @@ -915,7 +920,10 @@ MtrrLibGetMtrrNumber ( // if (*SubLeft !=3D 0) { BaseAddress =3D SubtractiveBaseAddress; - Length =3D SubtractiveLength; + Length =3D SubtractiveLength; + } else { + BaseAddress =3D OriginalBaseAddress; + Length =3D OriginalLength; } } =20 -- 2.12.2.windows.2