UefiCpuPkg/MtrrLib: Handle one setting request covering all memory
authorRuiyu Ni <ruiyu.ni@intel.com>
Tue, 9 Jan 2018 02:33:57 +0000 (10:33 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Wed, 10 Jan 2018 02:28:28 +0000 (10:28 +0800)
*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>
Reviewed-by: Eric Dong <eric.dong@intel.com>
UefiCpuPkg/Library/MtrrLib/MtrrLib.c

index 1f85ac7..333341f 100644 (file)
@@ -2270,8 +2270,13 @@ MtrrSetMemoryAttributesInMtrrSettings (
       goto Exit;\r
     }\r
     if (((Ranges[Index].BaseAddress & ~MtrrValidAddressMask) != 0) ||\r
-        ((Ranges[Index].Length & ~MtrrValidAddressMask) != 0)\r
+        ((((Ranges[Index].BaseAddress + Ranges[Index].Length) & ~MtrrValidAddressMask) != 0) &&\r
+          (Ranges[Index].BaseAddress + Ranges[Index].Length) != MtrrValidBitsMask + 1)\r
         ) {\r
+      //\r
+      // Either the BaseAddress or the Limit doesn't follow the alignment requirement.\r
+      // Note: It's still valid if Limit doesn't follow the alignment requirement but equals to MAX Address.\r
+      //\r
       Status = RETURN_UNSUPPORTED;\r
       goto Exit;\r
     }\r