public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 0/2] Quality improvement of MtrrLib
@ 2018-01-10  5:40 Ruiyu Ni
  2018-01-10  5:40 ` [PATCH 1/2] UefiCpuPkg/MtrrLib: Fix a MTRR calculation bug Ruiyu Ni
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ruiyu Ni @ 2018-01-10  5:40 UTC (permalink / raw)
  To: edk2-devel

The patch set fixes two bugs in MtrrLib.
With the two fixes, randomly generated 10000000 memory settings
can be set correctly.

Ruiyu Ni (2):
  UefiCpuPkg/MtrrLib: Fix a MTRR calculation bug
  UefiCpuPkg/MtrrLib: Fix an assertion bug

 UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

-- 
2.15.1.windows.2



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] UefiCpuPkg/MtrrLib: Fix a MTRR calculation bug
  2018-01-10  5:40 [PATCH 0/2] Quality improvement of MtrrLib Ruiyu Ni
@ 2018-01-10  5:40 ` Ruiyu Ni
  2018-01-10  5:40 ` [PATCH 2/2] UefiCpuPkg/MtrrLib: Fix an assertion bug Ruiyu Ni
  2018-01-10 12:33 ` [PATCH 0/2] Quality improvement of MtrrLib Dong, Eric
  2 siblings, 0 replies; 4+ messages in thread
From: Ruiyu Ni @ 2018-01-10  5:40 UTC (permalink / raw)
  To: edk2-devel; +Cc: Star Zeng

80                   A8   B0   B8   C0
+----------WB--------+-UC-+-WT-+-WB-+

For above memory settings, current code caused the final MTRR
settings miss [A8, B0, UC] when default memory type is UC.

The root cause is the code only checks the mandatory weight
between A8 to B0, but skips to check the optional weight.
The patch fixes this issue.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
---
 UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
index fafa15fd63..768d4d5cff 100644
--- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
+++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
@@ -47,7 +47,7 @@ typedef struct {
   UINT64                 Address;
   UINT64                 Alignment;
   UINT64                 Length;
-  UINT8                  Type : 7;
+  MTRR_MEMORY_CACHE_TYPE Type : 7;
 
   //
   // Temprary use for calculating the best MTRR settings.
@@ -1429,7 +1429,7 @@ MtrrLibCalculateSubtractivePath (
           while (SubStart != SubStop) {
             Status = MtrrLibAppendVariableMtrr (
               Mtrrs, MtrrCapacity, MtrrCount,
-              Vertices[SubStart].Address, Vertices[SubStart].Length, (MTRR_MEMORY_CACHE_TYPE) Vertices[SubStart].Type
+              Vertices[SubStart].Address, Vertices[SubStart].Length, Vertices[SubStart].Type
             );
             if (RETURN_ERROR (Status)) {
               return Status;
@@ -1450,10 +1450,11 @@ MtrrLibCalculateSubtractivePath (
             Pre = Vertices[Cur].Previous;
             SubStop = Pre;
 
-            if (Weight[M (Pre, Cur)] != 0) {
+            if (Weight[M (Pre, Cur)] + Weight[O (Pre, Cur)] != 0) {
               Status = MtrrLibAppendVariableMtrr (
                 Mtrrs, MtrrCapacity, MtrrCount,
-                Vertices[Pre].Address, Vertices[Cur].Address - Vertices[Pre].Address, LowestPrecedentType
+                Vertices[Pre].Address, Vertices[Cur].Address - Vertices[Pre].Address,
+                (Pre != Cur - 1) ? LowestPrecedentType : Vertices[Pre].Type
               );
               if (RETURN_ERROR (Status)) {
                 return Status;
-- 
2.15.1.windows.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] UefiCpuPkg/MtrrLib: Fix an assertion bug
  2018-01-10  5:40 [PATCH 0/2] Quality improvement of MtrrLib Ruiyu Ni
  2018-01-10  5:40 ` [PATCH 1/2] UefiCpuPkg/MtrrLib: Fix a MTRR calculation bug Ruiyu Ni
@ 2018-01-10  5:40 ` Ruiyu Ni
  2018-01-10 12:33 ` [PATCH 0/2] Quality improvement of MtrrLib Dong, Eric
  2 siblings, 0 replies; 4+ messages in thread
From: Ruiyu Ni @ 2018-01-10  5:40 UTC (permalink / raw)
  To: edk2-devel; +Cc: Star Zeng, Eric Dong

0                     40          f0         100
+---WT--+--UC--+--WT--+-----WB----+----UC----+

When calculating the shortest path from 0 to 100, the
MtrrLibCalculateLeastMtrrs() is called to update the
Vertices.Previous.
When calculating the shortest path from 0 to 40,
MtrrLibCalculateLeastMtrrs() is called recursively to update the
Vertices.Previous.
The second call corrupt the Previous value that will be used
later.
The patch removes the code that corrupts Previous.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
---
 UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
index 768d4d5cff..30b0df030b 100644
--- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
+++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
@@ -1171,7 +1171,6 @@ MtrrLibCalculateLeastMtrrs (
 
   for (Index = Start; Index <= Stop; Index++) {
     Vertices[Index].Visited = FALSE;
-    Vertices[Index].Previous = VertexCount;
     Mandatory = Weight[M(Start,Index)];
     Vertices[Index].Weight = Mandatory;
     if (Mandatory != MAX_WEIGHT) {
-- 
2.15.1.windows.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] Quality improvement of MtrrLib
  2018-01-10  5:40 [PATCH 0/2] Quality improvement of MtrrLib Ruiyu Ni
  2018-01-10  5:40 ` [PATCH 1/2] UefiCpuPkg/MtrrLib: Fix a MTRR calculation bug Ruiyu Ni
  2018-01-10  5:40 ` [PATCH 2/2] UefiCpuPkg/MtrrLib: Fix an assertion bug Ruiyu Ni
@ 2018-01-10 12:33 ` Dong, Eric
  2 siblings, 0 replies; 4+ messages in thread
From: Dong, Eric @ 2018-01-10 12:33 UTC (permalink / raw)
  To: Ni, Ruiyu, edk2-devel@lists.01.org

Reviewed-by: Eric Dong <eric.dong@intel.com>

-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ruiyu Ni
Sent: Wednesday, January 10, 2018 1:40 PM
To: edk2-devel@lists.01.org
Subject: [edk2] [PATCH 0/2] Quality improvement of MtrrLib

The patch set fixes two bugs in MtrrLib.
With the two fixes, randomly generated 10000000 memory settings can be set correctly.

Ruiyu Ni (2):
  UefiCpuPkg/MtrrLib: Fix a MTRR calculation bug
  UefiCpuPkg/MtrrLib: Fix an assertion bug

 UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

--
2.15.1.windows.2

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-01-10 12:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-10  5:40 [PATCH 0/2] Quality improvement of MtrrLib Ruiyu Ni
2018-01-10  5:40 ` [PATCH 1/2] UefiCpuPkg/MtrrLib: Fix a MTRR calculation bug Ruiyu Ni
2018-01-10  5:40 ` [PATCH 2/2] UefiCpuPkg/MtrrLib: Fix an assertion bug Ruiyu Ni
2018-01-10 12:33 ` [PATCH 0/2] Quality improvement of MtrrLib Dong, Eric

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox