[edk2] [PATCH 3/4] UefiCpuPkg/MtrrLib: Handle one setting request covering all memory

Ruiyu Ni posted 4 patches 6 years, 11 months ago
[edk2] [PATCH 3/4] UefiCpuPkg/MtrrLib: Handle one setting request covering all memory
Posted by Ruiyu Ni 6 years, 11 months ago
*SetMemoryAttribute*() API cannot handle the setting request that
looks like <0, MAX_ADDRESS, Type>. The buggy parameter checking
logic returns Unsupported for this case.
The patch fixes the checking logic to handle such case.

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

diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
index 566a4cb67b..54f703606b 100644
--- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
+++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
@@ -2270,8 +2270,13 @@ MtrrSetMemoryAttributesInMtrrSettings (
       goto Exit;
     }
     if (((Ranges[Index].BaseAddress & ~MtrrValidAddressMask) != 0) ||
-        ((Ranges[Index].Length & ~MtrrValidAddressMask) != 0)
+        ((((Ranges[Index].BaseAddress + Ranges[Index].Length) & ~MtrrValidAddressMask) != 0) &&
+          (Ranges[Index].BaseAddress + Ranges[Index].Length) != MtrrValidBitsMask + 1)
         ) {
+      //
+      // Either the BaseAddress or the Limit doesn't follow the alignment requirement.
+      // Note: It's still valid if Limit doesn't follow the alignment requirement but equals to MAX Address.
+      //
       Status = RETURN_UNSUPPORTED;
       goto Exit;
     }
-- 
2.15.1.windows.2

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