MdeModulePkg/Variable: Check EFI_MEMORY_RUNTIME attribute before setting it
authorBrijesh Singh <brijesh.singh@amd.com>
Wed, 4 Jul 2018 02:02:16 +0000 (10:02 +0800)
committerStar Zeng <star.zeng@intel.com>
Wed, 4 Jul 2018 14:21:00 +0000 (22:21 +0800)
Set the EFI_MEMORY_RUNTIME attribute in FtwNotificationEvent() only if
the attribute is not already present. This will ensure that the attributes
set by the platform drivers (e.g Ovmf pflash) is not lost.

Cc: Dong Eric <eric.dong@intel.com>
Cc: Justen Jordan L <jordan.l.justen@intel.com>
Cc: Zeng Star <star.zeng@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Reviewed-by: Star Zeng <star.zeng@intel.com>
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c

index 6b04f4f..2318617 100644 (file)
@@ -412,13 +412,15 @@ FtwNotificationEvent (
   if (EFI_ERROR (Status)) {\r
     DEBUG ((DEBUG_WARN, "Variable driver failed to get flash memory attribute.\n"));\r
   } else {\r
-    Status = gDS->SetMemorySpaceAttributes (\r
-                    BaseAddress,\r
-                    Length,\r
-                    GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME\r
-                    );\r
-    if (EFI_ERROR (Status)) {\r
-      DEBUG ((DEBUG_WARN, "Variable driver failed to add EFI_MEMORY_RUNTIME attribute to Flash.\n"));\r
+    if ((GcdDescriptor.Attributes & EFI_MEMORY_RUNTIME) == 0) {\r
+      Status = gDS->SetMemorySpaceAttributes (\r
+                      BaseAddress,\r
+                      Length,\r
+                      GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME\r
+                      );\r
+      if (EFI_ERROR (Status)) {\r
+        DEBUG ((DEBUG_WARN, "Variable driver failed to add EFI_MEMORY_RUNTIME attribute to Flash.\n"));\r
+      }\r
     }\r
   }\r
 \r