From: "Fan, Jeff" <jeff.fan@intel.com>
To: "Ni, Ruiyu" <ruiyu.ni@intel.com>,
"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Subject: Re: [PATCH] UefiCpuPkg/MtrrLib: Don't report OutOfResource when MTRR is enough
Date: Fri, 5 May 2017 02:17:28 +0000 [thread overview]
Message-ID: <542CF652F8836A4AB8DBFAAD40ED192A4C5BBA90@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <20170505021546.193068-1-ruiyu.ni@intel.com>
Reviewed-by: Jeff Fan <jeff.fan@intel.com>
-----Original Message-----
From: Ni, Ruiyu
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 is enough
The MTRR calculation algorithm contains a bug that when left subtraction cannot produce better MTRR solution, it forgets to restore the BaseAddress/Length so that MtrrLibGetMtrrNumber() returns bigger value of actual required MTRR numbers.
As a result, the MtrrLib reports OutOfResource but actually the MTRR is enough.
MEMORY_RANGE mC[] = {
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 <ruiyu.ni@intel.com>
Cc: Jeff Fan <jeff.fan@intel.com>
---
UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/MtrrLib/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;
*SubLeft = 0;
*SubRight = 0;
@@ -861,6 +863,9 @@ MtrrLibGetMtrrNumber (
// Get the optimal left subtraction solution.
//
if (BaseAddress != 0) {
+
+ OriginalBaseAddress = BaseAddress;
+ OriginalLength = Length;
SubtractiveBaseAddress = 0;
SubtractiveLength = 0;
//
@@ -915,7 +920,10 @@ MtrrLibGetMtrrNumber (
//
if (*SubLeft != 0) {
BaseAddress = SubtractiveBaseAddress;
- Length = SubtractiveLength;
+ Length = SubtractiveLength;
+ } else {
+ BaseAddress = OriginalBaseAddress;
+ Length = OriginalLength;
}
}
--
2.12.2.windows.2
prev parent reply other threads:[~2017-05-05 2:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-05 2:15 [PATCH] UefiCpuPkg/MtrrLib: Don't report OutOfResource when MTRR is enough Ruiyu Ni
2017-05-05 2:17 ` Fan, Jeff [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=542CF652F8836A4AB8DBFAAD40ED192A4C5BBA90@shsmsx102.ccr.corp.intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox