From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 1859C21D492F5 for ; Wed, 13 Sep 2017 01:42:02 -0700 (PDT) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Sep 2017 01:44:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,386,1500966000"; d="scan'208";a="128281293" Received: from jwang36-mobl2.ccr.corp.intel.com (HELO jwang36-MOBL2.local) ([10.239.192.50]) by orsmga004.jf.intel.com with SMTP; 13 Sep 2017 01:44:59 -0700 Date: Wed, 13 Sep 2017 01:07:48 -0700 From: Wang, Jian J Sender: Wang, Jian J To: edk2-devel@lists.01.org Message-ID: X-Mailer: TortoiseGit MIME-Version: 1.0 Subject: [PATCH 4/4] OvmfPkg/QemuVideoDxe: Update QemuVideoDxe driver to bypass NULL pointer detection if enabled. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Sep 2017 08:42:02 -0000 Content-Type: text/plain; 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 Cc: Eric Dong Cc: Star Zeng Cc: Laszlo Ersek Cc: Justen, Jordan L Cc: Kinney, Michael D Cc: Wolman, Ayellet Suggested-by: Wolman, Ayellet Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Wang, Jian J --- 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 #include #include +#include #include #include @@ -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