This library may be used with the caches and MMU off, while the
hypervisor has the caches enabled. So add explicit cache
maintenance to deal with the potential incoherency.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <[email protected]>
---
 OvmfPkg/Library/XenHypercallLib/XenHypercall.c      | 15 +++++++++++++++
 OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf |  3 +++
 2 files changed, 18 insertions(+)

diff --git a/OvmfPkg/Library/XenHypercallLib/XenHypercall.c 
b/OvmfPkg/Library/XenHypercallLib/XenHypercall.c
index ecc757cf707c..00ba9e64b406 100644
--- a/OvmfPkg/Library/XenHypercallLib/XenHypercall.c
+++ b/OvmfPkg/Library/XenHypercallLib/XenHypercall.c
@@ -20,6 +20,7 @@
 
 #include <Library/DebugLib.h>
 #include <Library/XenHypercallLib.h>
+#include <Library/CacheMaintenanceLib.h>
 
 UINT64
 XenHypercallHvmGetParam (
@@ -31,6 +32,13 @@ XenHypercallHvmGetParam (
 
   Parameter.domid = DOMID_SELF;
   Parameter.index = Index;
+
+  //
+  // We may be running with the MMU and caches off, so invalidate any copies
+  // of Parameter in the cache before passing it to the hypervisor.
+  //
+  InvalidateDataCacheRange (&Parameter, sizeof(Parameter));
+
   Error = XenHypercall2 (__HYPERVISOR_hvm_op,
                          HVMOP_get_param, (INTN) &Parameter);
   if (Error != 0) {
@@ -39,6 +47,13 @@ XenHypercallHvmGetParam (
             Error, Index));
     return 0;
   }
+
+  //
+  // We may be running with the MMU and caches off, so force the updated
+  // Parameter to be visible in main memory.
+  //
+  WriteBackDataCacheRange (&Parameter, sizeof(Parameter));
+
   return Parameter.value;
 }
 
diff --git a/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf 
b/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf
index f4503a4b01f4..8175ba6d3186 100644
--- a/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf
+++ b/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf
@@ -62,5 +62,8 @@
   HobLib
   DebugLib
 
+[LibraryClasses]
+  CacheMaintenanceLib
+
 [Guids.IA32, Guids.X64]
   gEfiXenInfoGuid
-- 
1.8.3.2


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to