QemuVideoDxe driver will install VBE SHIM into page 0. If NULL pointer 
detection is enabled, page 0 must be enabled temporarily before installing and 
disabled again afterwards. For Windows 7 boot, BIT7 of 
PcdNullPointerDetectionPropertyMask must still be set to avoid hang.

Cc: Jiewen Yao <[email protected]>
Cc: Eric Dong <[email protected]>
Cc: Star Zeng <[email protected]>
Cc: Laszlo Ersek <[email protected]>
Cc: Justen, Jordan L <[email protected]>
Cc: Kinney, Michael D <[email protected]>
Cc: Wolman, Ayellet <[email protected]>
Suggested-by: Wolman, Ayellet <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Wang, Jian J <[email protected]>
---
 OvmfPkg/QemuVideoDxe/Driver.c         | 15 ++++++++++++++-
 OvmfPkg/QemuVideoDxe/Qemu.h           | 16 ++++++++++++++++
 OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf |  2 ++
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/QemuVideoDxe/Driver.c b/OvmfPkg/QemuVideoDxe/Driver.c
index 0dce80e59b..ee0eed7214 100644
--- a/OvmfPkg/QemuVideoDxe/Driver.c
+++ b/OvmfPkg/QemuVideoDxe/Driver.c
@@ -194,6 +194,7 @@ QemuVideoControllerDriverStart (
   PCI_TYPE00                        Pci;
   QEMU_VIDEO_CARD                   *Card;
   EFI_PCI_IO_PROTOCOL               *ChildPciIo;
+  EFI_CPU_ARCH_PROTOCOL             *Cpu;
 
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
 
@@ -479,7 +480,19 @@ QemuVideoControllerDriverStart (
 #if defined MDE_CPU_IA32 || defined MDE_CPU_X64
   if (Private->Variant == QEMU_VIDEO_BOCHS_MMIO ||
       Private->Variant == QEMU_VIDEO_BOCHS) {
-    InstallVbeShim (Card->Name, Private->GraphicsOutput.Mode->FrameBufferBase);
+    //
+    // Prepare CPU arch protocol for NULL pointer detection
+    //
+    Status = gBS->LocateProtocol (
+                    &gEfiCpuArchProtocolGuid,
+                    NULL, 
+                    (VOID **) &Cpu
+                    );
+    ASSERT_EFI_ERROR (Status);
+
+    DISABLE_NULL_DETECTION(Cpu);
+      InstallVbeShim (Card->Name, 
Private->GraphicsOutput.Mode->FrameBufferBase);
+    ENABLE_NULL_DETECTION(Cpu);
   }
 #endif
 
diff --git a/OvmfPkg/QemuVideoDxe/Qemu.h b/OvmfPkg/QemuVideoDxe/Qemu.h
index 7fbb25b3ef..bb3bc6eb0f 100644
--- a/OvmfPkg/QemuVideoDxe/Qemu.h
+++ b/OvmfPkg/QemuVideoDxe/Qemu.h
@@ -25,6 +25,7 @@
 #include <Protocol/PciIo.h>
 #include <Protocol/DriverSupportedEfiVersion.h>
 #include <Protocol/DevicePath.h>
+#include <Protocol/Cpu.h>
 
 #include <Library/DebugLib.h>
 #include <Library/UefiDriverEntryPoint.h>
@@ -82,6 +83,21 @@ typedef struct {
 
 #define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER  0xffff
 
+//
+// VBE code will access memory between 0-4095 which will cause page fault 
exception 
+// if NULL pointer detection mechanism is enabled. Following macros can be 
used to 
+// disable/enable NULL pointer detection before/after accessing those memory.
+//
+#define NULL_DETECTION_ENABLED  ((PcdGet8(PcdNullPointerDetectionPropertyMask) 
& (BIT0|BIT7)) == BIT0)
+#define DISABLE_NULL_DETECTION(Cpu)                                            
 \
+  if (NULL_DETECTION_ENABLED) {                                                
 \
+    (Cpu)->SetMemoryAttributes((Cpu), 0, EFI_PAGE_SIZE, 0);                    
 \
+  }
+#define ENABLE_NULL_DETECTION(Cpu)                                             
 \
+  if (NULL_DETECTION_ENABLED) {                                                
 \
+    (Cpu)->SetMemoryAttributes((Cpu), 0, EFI_PAGE_SIZE, EFI_MEMORY_RP);        
 \
+  }
+
 //
 // QEMU Video Private Data Structure
 //
diff --git a/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf 
b/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf
index 7c7d429bca..5d166eb99c 100644
--- a/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf
+++ b/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf
@@ -72,7 +72,9 @@
   gEfiGraphicsOutputProtocolGuid                # PROTOCOL BY_START
   gEfiDevicePathProtocolGuid                    # PROTOCOL BY_START
   gEfiPciIoProtocolGuid                         # PROTOCOL TO_START
+  gEfiCpuArchProtocolGuid
 
 [Pcd]
   gOptionRomPkgTokenSpaceGuid.PcdDriverSupportedEfiVersion
+  gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask
 
-- 
2.14.1.windows.1

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to