From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 4219D21EC8D0A for ; Wed, 27 Sep 2017 22:05:05 -0700 (PDT) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Sep 2017 22:08:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,448,1500966000"; d="scan'208";a="133078856" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga004.jf.intel.com with ESMTP; 27 Sep 2017 22:08:19 -0700 Received: from fmsmsx152.amr.corp.intel.com (10.18.125.5) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 27 Sep 2017 22:08:19 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX152.amr.corp.intel.com (10.18.125.5) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 27 Sep 2017 22:08:19 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.213]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.93]) with mapi id 14.03.0319.002; Thu, 28 Sep 2017 13:08:17 +0800 From: "Wang, Jian J" To: "Zeng, Star" , "edk2-devel@lists.01.org" CC: "Dong, Eric" , Laszlo Ersek , "Yao, Jiewen" , "Kinney, Michael D" , "Justen, Jordan L" , "Wolman, Ayellet" Thread-Topic: [PATCH v3 3/6] MdeModulePkg/Core/Dxe: Add EndOfDxe workaround Thread-Index: AQHTN/W09m1r5krJtU2o4axKcMCAQ6LJpMBAgAAZ8jA= Date: Thu, 28 Sep 2017 05:08:17 +0000 Message-ID: References: <20170928010353.11968-1-jian.j.wang@intel.com> <20170928010353.11968-4-jian.j.wang@intel.com> <0C09AFA07DD0434D9E2A0C6AEB0483103B97BEF7@shsmsx102.ccr.corp.intel.com> In-Reply-To: <0C09AFA07DD0434D9E2A0C6AEB0483103B97BEF7@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v3 3/6] MdeModulePkg/Core/Dxe: Add EndOfDxe workaround 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: Thu, 28 Sep 2017 05:05:06 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Thanks for the feedback. Please see my comments below. > -----Original Message----- > From: Zeng, Star > Sent: Thursday, September 28, 2017 11:35 AM > To: Wang, Jian J ; edk2-devel@lists.01.org > Cc: Dong, Eric ; Laszlo Ersek ; Y= ao, > Jiewen ; Kinney, Michael D > ; Justen, Jordan L ; > Wolman, Ayellet ; Zeng, Star > Subject: RE: [PATCH v3 3/6] MdeModulePkg/Core/Dxe: Add EndOfDxe > workaround >=20 > Some comments to this patch. >=20 > 1. How about using lower TPL TPL_CALLBACK instead of TPL_NOTIFY for the > notification? I think it's safe to use TPL_CALLBACK. > 2. Should GCD SetMemorySpaceCapabilities + SetMemorySpaceAttributes be > used instead of gCpu->SetMemoryAttributes()? Yes. Since the GCG out-of-sync issue has been fixed, GCD service should be used instead. >=20 > Thanks, > Star > -----Original Message----- > From: Wang, Jian J > Sent: Thursday, September 28, 2017 9:04 AM > To: edk2-devel@lists.01.org > Cc: Zeng, Star ; Dong, Eric ; L= aszlo > Ersek ; Yao, Jiewen ; Kinney, > Michael D ; Justen, Jordan L > ; Wolman, Ayellet > Subject: [PATCH v3 3/6] MdeModulePkg/Core/Dxe: Add EndOfDxe workaround >=20 > One of issue caused by enabling NULL pointer detection is that some PCI d= evice > OptionROM, binary drivers and binary OS boot loaders may have NULL pointe= r > access bugs, which will prevent BIOS from booting and is almost impossibl= e to > fix. BIT7 of PCD PcdNullPointerDetectionPropertyMask is used as a workaro= und > to indicate BIOS to disable NULL pointer detection right after event > gEfiEndOfDxeEventGroupGuid, and then let boot continue. >=20 > Cc: Star Zeng > Cc: Eric Dong > Cc: Laszlo Ersek > Cc: Jiewen Yao > Cc: Michael Kinney > Cc: Jordan Justen > Cc: Ayellet Wolman > Suggested-by: Ayellet Wolman > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Jian J Wang > --- > MdeModulePkg/Core/Dxe/DxeMain.inf | 1 + > MdeModulePkg/Core/Dxe/Mem/Page.c | 4 ++- > MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 48 > +++++++++++++++++++++++++++ > 3 files changed, 52 insertions(+), 1 deletion(-) >=20 > diff --git a/MdeModulePkg/Core/Dxe/DxeMain.inf > b/MdeModulePkg/Core/Dxe/DxeMain.inf > index 30d5984f7c..0a161ffd71 100644 > --- a/MdeModulePkg/Core/Dxe/DxeMain.inf > +++ b/MdeModulePkg/Core/Dxe/DxeMain.inf > @@ -192,6 +192,7 @@ > gEfiMdeModulePkgTokenSpaceGuid.PcdPropertiesTableEnable = ## > CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy = ## > CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy > ## CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask > ## CONSUMES >=20 > # [Hob] > # RESOURCE_DESCRIPTOR ## CONSUMES > diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c > b/MdeModulePkg/Core/Dxe/Mem/Page.c > index a142c79ee2..0468df3171 100644 > --- a/MdeModulePkg/Core/Dxe/Mem/Page.c > +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c > @@ -188,7 +188,9 @@ CoreAddRange ( > // used for other purposes. > // > if (Type =3D=3D EfiConventionalMemory && Start =3D=3D 0 && (End >=3D E= FI_PAGE_SIZE - > 1)) { > - SetMem ((VOID *)(UINTN)Start, EFI_PAGE_SIZE, 0); > + if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) =3D=3D 0)= { > + SetMem ((VOID *)(UINTN)Start, EFI_PAGE_SIZE, 0); > + } > } >=20 > // > diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c > b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c > index a73c4ccd64..73e3b269f3 100644 > --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c > +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c > @@ -995,6 +995,36 @@ MemoryProtectionExitBootServicesCallback ( > } > } >=20 > +/** > + Disable NULL pointer detection after EndOfDxe. This is a workaround > +resort in > + order to skip unfixable NULL pointer access issues detected in > +OptionROM or > + boot loaders. > + > + @param[in] Event The Event this notify function registered to. > + @param[in] Context Pointer to the context data registered to the Ev= ent. > +**/ > +VOID > +EFIAPI > +DisableNullDetectionAtTheEndOfDxe ( > + EFI_EVENT Event, > + VOID *Context > + ) > +{ > + EFI_STATUS Status; > + > + DEBUG ((DEBUG_INFO, "DisableNullDetectionAtTheEndOfDxe(): > + start\r\n")); // // Disable NULL pointer detection by enabling first > + 4K page // Status =3D gCpu->SetMemoryAttributes (gCpu, 0, > + EFI_PAGE_SIZE, 0); ASSERT_EFI_ERROR (Status); > + > + CoreCloseEvent (Event); > + DEBUG ((DEBUG_INFO, "DisableNullDetectionAtTheEndOfDxe(): end\r\n")); > + > + return; > +} > + > /** > Initialize Memory Protection support. > **/ > @@ -1006,6 +1036,7 @@ CoreInitializeMemoryProtection ( { > EFI_STATUS Status; > EFI_EVENT Event; > + EFI_EVENT EndOfDxeEvent; > VOID *Registration; >=20 > mImageProtectionPolicy =3D PcdGet32(PcdImageProtectionPolicy); > @@ -1044,6 +1075,23 @@ CoreInitializeMemoryProtection ( > ); > ASSERT_EFI_ERROR(Status); > } > + > + // > + // Register a callback to disable NULL pointer detection at EndOfDxe > + // if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT0|BIT7)) > + =3D=3D (BIT0|BIT7)) { > + Status =3D CoreCreateEventEx ( > + EVT_NOTIFY_SIGNAL, > + TPL_NOTIFY, > + DisableNullDetectionAtTheEndOfDxe, > + NULL, > + &gEfiEndOfDxeEventGroupGuid, > + &EndOfDxeEvent > + ); > + ASSERT_EFI_ERROR (Status); > + } > + > return ; > } >=20 > -- > 2.14.1.windows.1