]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/Variable: Update to consume SpeculationBarrier
authorHao Wu <hao.a.wu@intel.com>
Fri, 21 Dec 2018 02:30:22 +0000 (10:30 +0800)
committerHao Wu <hao.a.wu@intel.com>
Tue, 25 Dec 2018 01:16:11 +0000 (09:16 +0800)
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1417

Since BaseLib API AsmLfence() is a x86 arch specific API and should be
avoided using in generic codes, this commit replaces the usage of
AsmLfence() with arch-generic API SpeculationBarrier().

Please note that speculation execution barriers are intended to be
asserted for SMM codes, hence, this commit still preserve an empty
implementation of the speculation execution barrier for the DXE codes.

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
MdeModulePkg/Universal/Variable/RuntimeDxe/LoadFenceDxe.c [deleted file]
MdeModulePkg/Universal/Variable/RuntimeDxe/LoadFenceSmm.c [deleted file]
MdeModulePkg/Universal/Variable/RuntimeDxe/PrivilegePolymorphic.h
MdeModulePkg/Universal/Variable/RuntimeDxe/SpeculationBarrierDxe.c [new file with mode: 0644]
MdeModulePkg/Universal/Variable/RuntimeDxe/SpeculationBarrierSmm.c [new file with mode: 0644]
MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf

diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/LoadFenceDxe.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/LoadFenceDxe.c
deleted file mode 100644 (file)
index 0f64ee0..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/** @file\r
-  Serialize operation on all load-from-memory instructions (DXE version).\r
-\r
-Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#include "Variable.h"\r
-\r
-/**\r
-  This service is consumed by the variable modules to perform a serializing\r
-  operation on all load-from-memory instructions that were issued prior to the\r
-  call of this function.\r
-\r
-**/\r
-VOID\r
-MemoryLoadFence (\r
-  VOID\r
-  )\r
-{\r
-  //\r
-  // Do nothing.\r
-  //\r
-}\r
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/LoadFenceSmm.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/LoadFenceSmm.c
deleted file mode 100644 (file)
index 4b0d7e3..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/** @file\r
-  Serialize operation on all load-from-memory instructions (SMM version).\r
-\r
-Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#include <Library/BaseLib.h>\r
-#include "Variable.h"\r
-\r
-/**\r
-  This service is consumed by the variable modules to perform a serializing\r
-  operation on all load-from-memory instructions that were issued prior to the\r
-  call of this function.\r
-\r
-**/\r
-VOID\r
-MemoryLoadFence (\r
-  VOID\r
-  )\r
-{\r
-  AsmLfence ();\r
-}\r
index a324ad23650fbf6f5ccce01b6072aab2beea053f..7af22a4ad67157e824aa4c087501eb030a2e5b56 100644 (file)
@@ -85,13 +85,15 @@ SetVariableCheckHandlerMor (
   );\r
 \r
 /**\r
-  This service is consumed by the variable modules to perform a serializing\r
-  operation on all load-from-memory instructions that were issued prior to the\r
-  call of this function.\r
+  This service is consumed by the variable modules to place a barrier to stop\r
+  speculative execution.\r
+\r
+  Ensures that no later instruction will execute speculatively, until all prior\r
+  instructions have completed.\r
 \r
 **/\r
 VOID\r
-MemoryLoadFence (\r
+VariableSpeculationBarrier (\r
   VOID\r
   );\r
 \r
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/SpeculationBarrierDxe.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/SpeculationBarrierDxe.c
new file mode 100644 (file)
index 0000000..bc3f695
--- /dev/null
@@ -0,0 +1,33 @@
+/** @file\r
+  Barrier to stop speculative execution (DXE version).\r
+\r
+Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "Variable.h"\r
+\r
+/**\r
+  This service is consumed by the variable modules to place a barrier to stop\r
+  speculative execution.\r
+\r
+  Ensures that no later instruction will execute speculatively, until all prior\r
+  instructions have completed.\r
+\r
+**/\r
+VOID\r
+VariableSpeculationBarrier (\r
+  VOID\r
+  )\r
+{\r
+  //\r
+  // Do nothing.\r
+  //\r
+}\r
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/SpeculationBarrierSmm.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/SpeculationBarrierSmm.c
new file mode 100644 (file)
index 0000000..dbc20f6
--- /dev/null
@@ -0,0 +1,32 @@
+/** @file\r
+  Barrier to stop speculative execution (SMM version).\r
+\r
+Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Library/BaseLib.h>\r
+#include "Variable.h"\r
+\r
+/**\r
+  This service is consumed by the variable modules to place a barrier to stop\r
+  speculative execution.\r
+\r
+  Ensures that no later instruction will execute speculatively, until all prior\r
+  instructions have completed.\r
+\r
+**/\r
+VOID\r
+VariableSpeculationBarrier (\r
+  VOID\r
+  )\r
+{\r
+  SpeculationBarrier ();\r
+}\r
index d100b1dcc552b196409b400926cab54f553e36d2..443cf07144a1215bc8c37ce03ca77e9e2d11f41d 100644 (file)
@@ -3201,11 +3201,11 @@ VariableServiceSetVariable (
       return EFI_SECURITY_VIOLATION;\r
     }\r
     //\r
-    // The MemoryLoadFence() call here is to ensure the above sanity check\r
-    // for the EFI_VARIABLE_AUTHENTICATION_2 descriptor has been completed\r
+    // The VariableSpeculationBarrier() call here is to ensure the above sanity\r
+    // check for the EFI_VARIABLE_AUTHENTICATION_2 descriptor has been completed\r
     // before the execution of subsequent codes.\r
     //\r
-    MemoryLoadFence ();\r
+    VariableSpeculationBarrier ();\r
     PayloadSize = DataSize - AUTHINFO2_SIZE (Data);\r
   } else {\r
     PayloadSize = DataSize;\r
index 868981ccaf30b61dc3c4b21299a0881f09ea8e5f..7ef8a97f5d6a678d5f1643b872b6d2ff5ef06824 100644 (file)
@@ -46,7 +46,7 @@
   TcgMorLockDxe.c\r
   VarCheck.c\r
   VariableExLib.c\r
-  LoadFenceDxe.c\r
+  SpeculationBarrierDxe.c\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
index 6dc19c24dbc23276369a2da7bee091af93b17500..8c53f84ff6e8e61d85e989716a66cfd70adffaf1 100644 (file)
@@ -538,11 +538,11 @@ SmmVariableHandler (
       }\r
 \r
       //\r
-      // The MemoryLoadFence() call here is to ensure the previous range/content\r
-      // checks for the CommBuffer have been completed before the subsequent\r
-      // consumption of the CommBuffer content.\r
+      // The VariableSpeculationBarrier() call here is to ensure the previous\r
+      // range/content checks for the CommBuffer have been completed before the\r
+      // subsequent consumption of the CommBuffer content.\r
       //\r
-      MemoryLoadFence ();\r
+      VariableSpeculationBarrier ();\r
       if (SmmVariableHeader->NameSize < sizeof (CHAR16) || SmmVariableHeader->Name[SmmVariableHeader->NameSize/sizeof (CHAR16) - 1] != L'\0') {\r
         //\r
         // Make sure VariableName is A Null-terminated string.\r
@@ -638,11 +638,11 @@ SmmVariableHandler (
       }\r
 \r
       //\r
-      // The MemoryLoadFence() call here is to ensure the previous range/content\r
-      // checks for the CommBuffer have been completed before the subsequent\r
-      // consumption of the CommBuffer content.\r
+      // The VariableSpeculationBarrier() call here is to ensure the previous\r
+      // range/content checks for the CommBuffer have been completed before the\r
+      // subsequent consumption of the CommBuffer content.\r
       //\r
-      MemoryLoadFence ();\r
+      VariableSpeculationBarrier ();\r
       if (SmmVariableHeader->NameSize < sizeof (CHAR16) || SmmVariableHeader->Name[SmmVariableHeader->NameSize/sizeof (CHAR16) - 1] != L'\0') {\r
         //\r
         // Make sure VariableName is A Null-terminated string.\r
@@ -779,11 +779,11 @@ SmmVariableHandler (
       }\r
 \r
       //\r
-      // The MemoryLoadFence() call here is to ensure the previous range/content\r
-      // checks for the CommBuffer have been completed before the subsequent\r
-      // consumption of the CommBuffer content.\r
+      // The VariableSpeculationBarrier() call here is to ensure the previous\r
+      // range/content checks for the CommBuffer have been completed before the\r
+      // subsequent consumption of the CommBuffer content.\r
       //\r
-      MemoryLoadFence ();\r
+      VariableSpeculationBarrier ();\r
       if (CommVariableProperty->NameSize < sizeof (CHAR16) || CommVariableProperty->Name[CommVariableProperty->NameSize/sizeof (CHAR16) - 1] != L'\0') {\r
         //\r
         // Make sure VariableName is A Null-terminated string.\r
index 2fe72ff8a442e7df5f8dda5de27503f28d5e08c1..db7d220e06df7ada8df38a29ec87f023a8b6906c 100644 (file)
@@ -54,7 +54,7 @@
   PrivilegePolymorphic.h\r
   VariableExLib.c\r
   TcgMorLockSmm.c\r
-  LoadFenceSmm.c\r
+  SpeculationBarrierSmm.c\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r