From: "Johnson, Brian (EXL - Eagan)" <brian.johnson@hpe.com>
To: "Wang, Jian J" <jian.j.wang@intel.com>,
"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Justen@ml01.01.org" <Justen@ml01.01.org>,
Eric Dong <eric.dong@intel.com>,
"Kinney@ml01.01.org" <Kinney@ml01.01.org>,
Jordan L <jordan.l.justen@intel.com>,
"Wolman@ml01.01.org" <Wolman@ml01.01.org>,
Jiewen Yao <jiewen.yao@intel.com>,
Ayellet <ayellet.wolman@intel.com>,
Michael D <michael.d.kinney@intel.com>,
Laszlo Ersek <lersek@redhat.com>, Star Zeng <star.zeng@intel.com>
Subject: Re: [PATCH 4/4] OvmfPkg/QemuVideoDxe: Update QemuVideoDxe driver to bypass NULL pointer detection if enabled.
Date: Wed, 13 Sep 2017 16:33:44 +0000 [thread overview]
Message-ID: <DF4PR84MB0155CEA90D87B23EBC9E8F68E16E0@DF4PR84MB0155.NAMPRD84.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <20170913092507.12504-5-jian.j.wang@intel.com>
Acked-by: Brian J. Johnson <brian.johnson@hpe.com>
-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Wang, Jian J
Sent: Wednesday, September 13, 2017 4:25 AM
To: edk2-devel@lists.01.org
Cc: Justen@ml01.01.org; Eric Dong <eric.dong@intel.com>; Kinney@ml01.01.org; Jordan L <jordan.l.justen@intel.com>; Wolman@ml01.01.org; Jiewen Yao <jiewen.yao@intel.com>; Ayellet <ayellet.wolman@intel.com>; Michael D <michael.d.kinney@intel.com>; Laszlo Ersek <lersek@redhat.com>; Star Zeng <star.zeng@intel.com>
Subject: [edk2] [PATCH 4/4] OvmfPkg/QemuVideoDxe: Update QemuVideoDxe driver to bypass NULL pointer detection if enabled.
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 <jiewen.yao@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Justen, Jordan L <jordan.l.justen@intel.com>
Cc: Kinney, Michael D <michael.d.kinney@intel.com>
Cc: Wolman, Ayellet <ayellet.wolman@intel.com>
Suggested-by: Wolman, Ayellet <ayellet.wolman@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Wang, Jian J <jian.j.wang@intel.com>
---
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
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
next prev parent reply other threads:[~2017-09-13 16:30 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <Implement NULL pointer detection feature>
2017-09-13 9:25 ` [PATCH 0/4] Implement NULL pointer detection feature for special pool Wang, Jian J
2017-09-13 9:25 ` [PATCH 1/4] MdeModulePkg/Core: Implement NULL pointer detection in EDK-II Core Wang, Jian J
2017-09-13 16:33 ` Johnson, Brian (EXL - Eagan)
2017-09-14 1:37 ` Wang, Jian J
2017-09-13 17:28 ` Jordan Justen
2017-09-14 1:25 ` Wang, Jian J
2017-09-14 6:33 ` Jordan Justen
2017-09-14 6:51 ` Wang, Jian J
2017-09-14 8:22 ` Laszlo Ersek
2017-09-13 9:25 ` [PATCH 2/4] UefiCpuPkg/PiSmmCpuDxeSmm: Implement NULL pointer detection for SMM mode code Wang, Jian J
2017-09-13 16:33 ` Johnson, Brian (EXL - Eagan)
2017-09-14 1:31 ` Wang, Jian J
2017-09-13 17:31 ` Jordan Justen
2017-09-14 1:20 ` Wang, Jian J
2017-09-13 9:25 ` [PATCH 3/4] IntelFrameworkModulePkg/Csm: Update CSM code to temporarily bypass NULL pointer detection if enabled Wang, Jian J
2017-09-13 16:33 ` Johnson, Brian (EXL - Eagan)
2017-09-13 9:25 ` [PATCH 4/4] OvmfPkg/QemuVideoDxe: Update QemuVideoDxe driver to " Wang, Jian J
2017-09-13 16:33 ` Johnson, Brian (EXL - Eagan) [this message]
2017-09-13 23:34 ` Laszlo Ersek
2017-09-14 1:17 ` Wang, Jian J
2017-09-14 3:17 ` Wang, Jian J
2017-09-14 8:30 ` Laszlo Ersek
2017-09-14 8:38 ` Yao, Jiewen
2017-09-14 8:46 ` Wang, Jian J
2017-09-14 8:48 ` Yao, Jiewen
2017-09-14 8:54 ` Laszlo Ersek
2017-09-14 9:39 ` Zeng, Star
2017-09-14 9:55 ` Laszlo Ersek
2017-09-14 10:16 ` Zeng, Star
2017-09-15 0:15 ` Wang, Jian J
2017-09-15 6:05 ` Wang, Jian J
2017-09-15 6:28 ` Zeng, Star
2017-09-14 8:52 ` Laszlo Ersek
2017-09-14 5:50 ` Jordan Justen
2017-09-14 6:52 ` Wang, Jian J
2017-09-14 8:26 ` Laszlo Ersek
2017-09-13 8:07 Wang, Jian J
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DF4PR84MB0155CEA90D87B23EBC9E8F68E16E0@DF4PR84MB0155.NAMPRD84.PROD.OUTLOOK.COM \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox