From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.132.183.28; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (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 0311B21B02847 for ; Thu, 7 Dec 2017 03:27:50 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7E74FC049E39; Thu, 7 Dec 2017 11:32:23 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-204.rdu2.redhat.com [10.10.120.204]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7C2D5DA6F; Thu, 7 Dec 2017 11:32:21 +0000 (UTC) To: Star Zeng , edk2-devel@lists.01.org Cc: Jiewen Yao , Eric Dong , Ruiyu Ni , Jian J Wang References: <1512643673-14320-1-git-send-email-star.zeng@intel.com> From: Laszlo Ersek Message-ID: Date: Thu, 7 Dec 2017 12:32:20 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <1512643673-14320-1-git-send-email-star.zeng@intel.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 07 Dec 2017 11:32:23 +0000 (UTC) Subject: Re: [PATCH] UefiCpuPkg PiSmmCpuDxeSmm: SMM profile and static paging mutual exclusion 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, 07 Dec 2017 11:27:51 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Hi Star, On 12/07/17 11:47, Star Zeng wrote: > SMM profile and static paging could not enabled at the same time, > this patch is add check and comments to make sure it. > > Similar comments are also added for the case of static paging and > heap guard for SMM. > > Cc: Jiewen Yao > Cc: Eric Dong > Cc: Ruiyu Ni > Cc: Jian J Wang > Cc: Laszlo Ersek > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Star Zeng > --- > UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c | 9 +++++++++ > UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c | 13 ++++++++++--- > UefiCpuPkg/UefiCpuPkg.dec | 6 +++++- > UefiCpuPkg/UefiCpuPkg.uni | 10 ++++++++-- > 4 files changed, 32 insertions(+), 6 deletions(-) > > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c > index 6e1ffe7c6287..939ac25a506c 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c > @@ -205,6 +205,15 @@ SetPageTableAttributes ( > // BIT3: SMM pool guard enabled > // > if ((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT3 | BIT2)) != 0) { > + DEBUG ((DEBUG_INFO, "Don't mark page table as read-only as heap guard is enabled\n")); > + return ; > + } > + > + // > + // Don't mark page table as read-only if SMM profile is enabled. > + // > + if (FeaturePcdGet (PcdCpuSmmProfileEnable)) { > + DEBUG ((DEBUG_INFO, "Don't mark page table as read-only as SMM profile is enabled\n")); > return ; > } > > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c > index 6478c6c3e355..0fe944fc18cc 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c > @@ -919,17 +919,24 @@ SetPageTableAttributes ( > // > // Don't do this if > // - no static page table; or > - // - SMM heap guard feature enabled > + // - SMM heap guard feature enabled; or > // BIT2: SMM page guard enabled > // BIT3: SMM pool guard enabled > + // - SMM profile feature enabled > // > if (!mCpuSmmStaticPageTable || > - (PcdGet8 (PcdHeapGuardPropertyMask) & (BIT3 | BIT2)) != 0) { > + ((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT3 | BIT2)) != 0) || > + FeaturePcdGet (PcdCpuSmmProfileEnable)) { > // > - // Static paging and heap guard should not be enabled at the same time. > + // Static paging and heap guard could not be enabled at the same time. > // > ASSERT (!(mCpuSmmStaticPageTable && > (PcdGet8 (PcdHeapGuardPropertyMask) & (BIT3 | BIT2)) != 0)); > + > + // > + // Static paging and SMM profile could not be enabled at the same time. > + // > + ASSERT (!(mCpuSmmStaticPageTable && FeaturePcdGet (PcdCpuSmmProfileEnable))); > return ; > } > > diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec > index d2965ba14c2d..36205ab63796 100644 > --- a/UefiCpuPkg/UefiCpuPkg.dec > +++ b/UefiCpuPkg/UefiCpuPkg.dec > @@ -84,6 +84,7 @@ [Protocols] > [PcdsFeatureFlag] > ## Indicates if SMM Profile will be enabled. > # If enabled, instruction executions in and data accesses to memory outside of SMRAM will be logged. > + # It could not be enabled at the same time with SMM profile feature (PcdCpuSmmStaticPageTable). > # This PCD is only for validation purpose. It should be set to false in production.

> # TRUE - SMM Profile will be enabled.
> # FALSE - SMM Profile will be disabled.
> @@ -225,8 +226,11 @@ [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] > gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate|0|UINT8|0x00000007 > > ## Indicates if SMM uses static page table. > - # If enabled, SMM will not use on-demand paging. SMM will build static page table for all memory.

> + # If enabled, SMM will not use on-demand paging. SMM will build static page table for all memory. > # This flag only impacts X64 build, because SMM alway builds static page table for IA32. > + # It could not be enabled at the same time with SMM profile feature (PcdCpuSmmProfileEnable). > + # It could not be enabled also at the same time with heap guard feature for SMM > + # (PcdHeapGuardPropertyMask in MdeModulePkg).

> # TRUE - SMM uses static page table for all memory.
> # FALSE - SMM uses static page table for below 4G memory and use on-demand paging for above 4G memory.
> # @Prompt Use static page table for all memory in SMM. > diff --git a/UefiCpuPkg/UefiCpuPkg.uni b/UefiCpuPkg/UefiCpuPkg.uni > index 9472b185e46e..013d2870a682 100644 > --- a/UefiCpuPkg/UefiCpuPkg.uni > +++ b/UefiCpuPkg/UefiCpuPkg.uni > @@ -53,7 +53,10 @@ > > #string STR_gUefiCpuPkgTokenSpaceGuid_PcdCpuSmmProfileEnable_PROMPT #language en-US "Enable SMM Profile" > > -#string STR_gUefiCpuPkgTokenSpaceGuid_PcdCpuSmmProfileEnable_HELP #language en-US "Indicates if SMM Profile will be enabled. If enabled, instruction executions in and data accesses to memory outside of SMRAM will be logged. This PCD is only for validation purpose. It should be set to false in production.

\n" > +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdCpuSmmProfileEnable_HELP #language en-US "Indicates if SMM Profile will be enabled.\n" > + "If enabled, instruction executions in and data accesses to memory outside of SMRAM will be logged.\n" > + "It could not be enabled at the same time with SMM profile feature (PcdCpuSmmStaticPageTable).\n" > + "This PCD is only for validation purpose. It should be set to false in production.

\n" > "TRUE - SMM Profile will be enabled.
\n" > "FALSE - SMM Profile will be disabled.
" > > @@ -150,8 +153,11 @@ > #string STR_gUefiCpuPkgTokenSpaceGuid_PcdCpuSmmStaticPageTable_PROMPT #language en-US "Use static page table for all memory in SMM." > > #string STR_gUefiCpuPkgTokenSpaceGuid_PcdCpuSmmStaticPageTable_HELP #language en-US "Indicates if SMM uses static page table.\n" > - "If enabled, SMM will not use on-demand paging. SMM will build static page table for all memory.

\n" > + "If enabled, SMM will not use on-demand paging. SMM will build static page table for all memory.\n" > "This flag only impacts X64 build, because SMM alway builds static page table for IA32.\n" > + "It could not be enabled at the same time with SMM profile feature (PcdCpuSmmProfileEnable).\n" > + "It could not be enabled also at the same time with heap guard feature for SMM\n" > + "(PcdHeapGuardPropertyMask in MdeModulePkg).

\n" > "TRUE - SMM uses static page table for all memory.
\n" > "FALSE - SMM uses static page table for below 4G memory and use on-demand paging for above 4G memory.
" > > This patch looks good to me; in particular I checked that PcdCpuSmmProfileEnable==FALSE does not lead to any observable changes in the code execution. I notice two typos however: (1) In PcdCpuSmmProfileEnable_HELP, we should not say: "It could not be enabled at the same time with SMM profile feature (PcdCpuSmmStaticPageTable)" We should say: "It could not be enabled at the same time with SMM static page table feature (PcdCpuSmmStaticPageTable)" (2) The same typo is present a bit higher up in the patch, in the DEC file, in the documentation of PcdCpuSmmProfileEnable. With those two typos fixed: Reviewed-by: Laszlo Ersek Thanks! Laszlo