]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/Gcd: Filter gCpu->SetMemoryAttributes() calls
authorKinney, Michael D <michael.d.kinney@intel.com>
Mon, 2 Apr 2018 22:40:24 +0000 (06:40 +0800)
committerStar Zeng <star.zeng@intel.com>
Thu, 5 Apr 2018 01:04:58 +0000 (09:04 +0800)
This patch fixes an issue with VlvTbltDevicePkg introduced
by commit 5b91bf82c67b586b9588cbe4bbffa1588f6b5926.

The history is as below.
To support heap guard feature, 14dde9e903bb9a719ebb8f3381da72b19509bc36
added support for SetMemorySpaceAttributes() to handle page attributes,
but after that, a combination of CPU arch attributes and other attributes
was not allowed anymore, for example, UC + RUNTIME. It is a regression.
Then 5b91bf82c67b586b9588cbe4bbffa1588f6b5926 was to fix the regression,
and we thought 0 CPU arch attributes may be used to clear CPU arch
attributes, so 0 CPU arch attributes was allowed to be sent to
gCpu->SetMemoryAttributes().

But some implementation of CPU driver may return error for 0 CPU arch
attributes. That fails the case that caller just calls
SetMemorySpaceAttributes() with none CPU arch attributes (for example,
RUNTIME), and the purpose of the case is not to clear CPU arch attributes.

This patch filters the call to gCpu->SetMemoryAttributes()
if the requested attributes is 0.  It also removes the #define
INVALID_CPU_ARCH_ATTRIBUTES that is no longer used.

Cc: Heyi Guo <heyi.guo@linaro.org>
Cc: Yi Li <phoenix.liyi@huawei.com>
Cc: Renhao Liang <liangrenhao@huawei.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
MdeModulePkg/Core/Dxe/Gcd/Gcd.c

index 907245a3f512c2eeb5424cdf166744b57c1df2ce..31ddf9c3bb516e7dd34b92813f408d993c36aa7a 100644 (file)
@@ -48,8 +48,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define NONEXCLUSIVE_MEMORY_ATTRIBUTES (EFI_MEMORY_XP | EFI_MEMORY_RP | \\r
                                         EFI_MEMORY_RO)\r
 \r
 #define NONEXCLUSIVE_MEMORY_ATTRIBUTES (EFI_MEMORY_XP | EFI_MEMORY_RP | \\r
                                         EFI_MEMORY_RO)\r
 \r
-#define INVALID_CPU_ARCH_ATTRIBUTES   0xffffffff\r
-\r
 //\r
 // Module Variables\r
 //\r
 //\r
 // Module Variables\r
 //\r
@@ -873,7 +871,21 @@ CoreConvertSpace (
     // Call CPU Arch Protocol to attempt to set attributes on the range\r
     //\r
     CpuArchAttributes = ConverToCpuArchAttributes (Attributes);\r
     // Call CPU Arch Protocol to attempt to set attributes on the range\r
     //\r
     CpuArchAttributes = ConverToCpuArchAttributes (Attributes);\r
-    if (CpuArchAttributes != INVALID_CPU_ARCH_ATTRIBUTES) {\r
+    //\r
+    // CPU arch attributes include page attributes and cache attributes. \r
+    // Only page attributes supports to be cleared, but not cache attributes.\r
+    // Caller is expected to use GetMemorySpaceDescriptor() to get the current\r
+    // attributes, AND/OR attributes, and then calls SetMemorySpaceAttributes()\r
+    // to set the new attributes.\r
+    // So 0 CPU arch attributes should not happen as memory should always have\r
+    // a cache attribute (no matter UC or WB, etc). \r
+    //\r
+    // Here, 0 CPU arch attributes will be filtered to be compatible with the\r
+    // case that caller just calls SetMemorySpaceAttributes() with none CPU\r
+    // arch attributes (for example, RUNTIME) as the purpose of the case is not\r
+    // to clear CPU arch attributes.\r
+    //\r
+    if (CpuArchAttributes != 0) {\r
       if (gCpu == NULL) {\r
         Status = EFI_NOT_AVAILABLE_YET;\r
       } else {\r
       if (gCpu == NULL) {\r
         Status = EFI_NOT_AVAILABLE_YET;\r
       } else {\r
@@ -936,6 +948,13 @@ CoreConvertSpace (
     // Set attributes operation\r
     //\r
     case GCD_SET_ATTRIBUTES_MEMORY_OPERATION:\r
     // Set attributes operation\r
     //\r
     case GCD_SET_ATTRIBUTES_MEMORY_OPERATION:\r
+      if (CpuArchAttributes == 0) {\r
+        //\r
+        // Keep original CPU arch attributes when caller just calls\r
+        // SetMemorySpaceAttributes() with none CPU arch attributes (for example, RUNTIME).\r
+        //\r
+        Attributes |= (Entry->Attributes & (EXCLUSIVE_MEMORY_ATTRIBUTES | NONEXCLUSIVE_MEMORY_ATTRIBUTES));\r
+      }\r
       Entry->Attributes = Attributes;\r
       break;\r
     //\r
       Entry->Attributes = Attributes;\r
       break;\r
     //\r