From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=ray.ni@intel.com; receiver=edk2-devel@lists.01.org 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 1A63321959CB2 for ; Fri, 29 Mar 2019 02:36:06 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Mar 2019 02:36:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,284,1549958400"; d="scan'208";a="311417535" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga005.jf.intel.com with ESMTP; 29 Mar 2019 02:36:05 -0700 Received: from fmsmsx152.amr.corp.intel.com (10.18.125.5) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 29 Mar 2019 02:36:04 -0700 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by FMSMSX152.amr.corp.intel.com (10.18.125.5) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 29 Mar 2019 02:36:04 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.74]) by shsmsx102.ccr.corp.intel.com ([169.254.2.163]) with mapi id 14.03.0415.000; Fri, 29 Mar 2019 17:36:02 +0800 From: "Ni, Ray" To: "Vanguput, Narendra K" , "edk2-devel@lists.01.org" CC: "Yao, Jiewen" , "Dong, Eric" , Laszlo Ersek Thread-Topic: [edk2] [PATCH v6] UefiCpuPkg\CpuSmm: Save & restore CR2 on-demand paging in SMM Thread-Index: AQHU5ewOCD2FNsb+3UylxFuHdBq0IqYiEDEQ///CXQCAAIfaMA== Date: Fri, 29 Mar 2019 09:36:01 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5C0A33C3@SHSMSX104.ccr.corp.intel.com> References: <20190329045815.23616-1-narendra.k.vanguput@intel.com> <734D49CCEBEEF84792F5B80ED585239D5C0A2E7E@SHSMSX104.ccr.corp.intel.com> <020B34E8430BB544AB9E0330B597780A664EACE5@BGSMSX102.gar.corp.intel.com> In-Reply-To: <020B34E8430BB544AB9E0330B597780A664EACE5@BGSMSX102.gar.corp.intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v6] UefiCpuPkg\CpuSmm: Save & restore CR2 on-demand paging in SMM X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Mar 2019 09:36:06 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Yes. With below "Cr2 !=3D0" removed from final commit, Reviewed-by: Ray Ni = > > +RestoreCr2 ( > > + UINTN Cr2 > > + ) > > +{ > > + if ((!mCpuSmmStaticPageTable) && (Cr2 !=3D 0)) { > > + AsmWriteCr2 (Cr2); > > + } > > +} > -----Original Message----- > From: Vanguput, Narendra K > Sent: Friday, March 29, 2019 5:32 PM > To: Ni, Ray ; edk2-devel@lists.01.org > Cc: Yao, Jiewen ; Dong, Eric ; > Laszlo Ersek > Subject: RE: [edk2] [PATCH v6] UefiCpuPkg\CpuSmm: Save & restore CR2 on- > demand paging in SMM >=20 > Hi Ray, >=20 > While programming, I thought this cannot be 0 as in SDM, it says page-fau= lt > linear address. > >> CR2 - Contains the page-fault linear address (the linear address that > caused a page fault). >=20 > So added a check for 0. >=20 > Now as the function is changed like program into CR2 register based on in= put > parameter and checking for 0 is up to caller of this function. And also w= e > don't need to require for checking 0 means, will remove it. Please confir= m. >=20 > Thanks, > Naren >=20 > -----Original Message----- > From: Ni, Ray > Sent: Friday, March 29, 2019 10:40 AM > To: Vanguput, Narendra K ; edk2- > devel@lists.01.org > Cc: Yao, Jiewen ; Dong, Eric ; > Laszlo Ersek > Subject: RE: [edk2] [PATCH v6] UefiCpuPkg\CpuSmm: Save & restore CR2 on- > demand paging in SMM >=20 > > + if ((!mCpuSmmStaticPageTable) && (Cr2 !=3D 0)) { >=20 > Can the "Cr2 !=3D 0" be removed? >=20 > > -----Original Message----- > > From: edk2-devel On Behalf Of > > nkvangup > > Sent: Friday, March 29, 2019 12:58 PM > > To: edk2-devel@lists.01.org > > Cc: Yao, Jiewen ; Dong, Eric > > ; Laszlo Ersek > > Subject: [edk2] [PATCH v6] UefiCpuPkg\CpuSmm: Save & restore CR2 on- > > demand paging in SMM > > > > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1593 > > > > For every SMI occurrence, save and restore CR2 register only when SMM > > on- demand paging support is enabled in 64 bit operation mode. > > This is not a bug but to have better improvement of code. > > > > Patch5 is updated with separate functions for Save and Restore of CR2 > > based on review feedback. > > > > Contributed-under: TianoCore Contribution Agreement 1.1 > > Signed-off-by: Vanguput Narendra K > > Cc: Eric Dong > > Cc: Ray Ni > > Cc: Laszlo Ersek > > Cc: Yao Jiewen > > --- > > UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c | 26 > > ++++++++++++++++++++++++++ > > UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 9 ++++++--- > > UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 22 > > ++++++++++++++++++++++ > > UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c | 30 > > ++++++++++++++++++++++++++++++ > > 4 files changed, 84 insertions(+), 3 deletions(-) > > > > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c > > b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c > > index b734a1ea8c..af96e42982 100644 > > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c > > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c > > @@ -316,3 +316,29 @@ SetPageTableAttributes ( > > > > return ; > > } > > + > > +/** > > + This function returns with no action for 32 bit. > > + > > + @param[in] *Cr2 Pointer to variable to hold CR2 register value > > +**/ VOID > > +SaveCr2 ( > > + UINTN *Cr2 > > + ) > > +{ > > + return ; > > +} > > + > > +/** > > + This function returns with no action for 32 bit. > > + > > + @param[in] Cr2 Value to write into CR2 register **/ VOID > > +RestoreCr2 ( > > + UINTN Cr2 > > + ) > > +{ > > + return ; > > +} > > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c > > b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c > > index 3b0b3b52ac..ce70f77709 100644 > > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c > > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c > > @@ -1112,9 +1112,11 @@ SmiRendezvous ( > > ASSERT(CpuIndex < mMaxNumberOfCpus); > > > > // > > - // Save Cr2 because Page Fault exception in SMM may override its > > value > > + // Save Cr2 because Page Fault exception in SMM may override its > > + value, // when using on-demand paging for above 4G memory. > > // > > - Cr2 =3D AsmReadCr2 (); > > + Cr2 =3D 0; > > + SaveCr2 (&Cr2); > > > > // > > // Perform CPU specific entry hooks @@ -1253,10 +1255,11 @@ > > SmiRendezvous ( > > > > Exit: > > SmmCpuFeaturesRendezvousExit (CpuIndex); > > + > > // > > // Restore Cr2 > > // > > - AsmWriteCr2 (Cr2); > > + RestoreCr2 (Cr2); > > } > > > > /** > > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > > b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > > index 84efb22981..c9d147c8a1 100644 > > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > > @@ -1243,4 +1243,26 @@ EFIAPI > > PiSmmCpuSmiEntryFixupAddress ( > > ); > > > > +/** > > + This function reads CR2 register when on-demand paging is enabled > > + for 64 bit and no action for 32 bit. > > + > > + @param[in] *Cr2 Pointer to variable to hold CR2 register value > > +**/ VOID > > +SaveCr2 ( > > + UINTN *Cr2 > > + ); > > + > > +/** > > + This function writes into CR2 register when on-demand paging is > > +enabled > > + for 64 bit and no action for 32 bit. > > + > > + @param[in] Cr2 Value to write into CR2 register **/ VOID > > +RestoreCr2 ( > > + UINTN Cr2 > > + ); > > + > > #endif > > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c > > b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c > > index 2c77cb47a4..6cb44fbbe5 100644 > > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c > > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c > > @@ -1053,3 +1053,33 @@ SetPageTableAttributes ( > > > > return ; > > } > > + > > +/** > > + This function reads CR2 register when on-demand paging is enabled > > + > > + @param[in] *Cr2 Pointer to variable to hold CR2 register value > > +**/ VOID > > +SaveCr2 ( > > + UINTN *Cr2 > > + ) > > +{ > > + if (!mCpuSmmStaticPageTable) { > > + *Cr2 =3D AsmReadCr2 (); > > + } > > +} > > + > > +/** > > + This function restores CR2 register when on-demand paging is > > +enabled > > + > > + @param[in] Cr2 Value to write into CR2 register **/ VOID > > +RestoreCr2 ( > > + UINTN Cr2 > > + ) > > +{ > > + if ((!mCpuSmmStaticPageTable) && (Cr2 !=3D 0)) { > > + AsmWriteCr2 (Cr2); > > + } > > +} > > -- > > 2.16.2.windows.1 > > > > _______________________________________________ > > edk2-devel mailing list > > edk2-devel@lists.01.org > > https://lists.01.org/mailman/listinfo/edk2-devel