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 BA7DD21F0DA4E for ; Mon, 5 Feb 2018 22:45:02 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Feb 2018 22:50:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,467,1511856000"; d="scan'208";a="32353389" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga002.jf.intel.com with ESMTP; 05 Feb 2018 22:50:44 -0800 Received: from fmsmsx117.amr.corp.intel.com (10.18.116.17) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 5 Feb 2018 22:50:44 -0800 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by fmsmsx117.amr.corp.intel.com (10.18.116.17) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 5 Feb 2018 22:50:43 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.116]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.130]) with mapi id 14.03.0319.002; Tue, 6 Feb 2018 14:50:42 +0800 From: "Wang, Jian J" To: "Yao, Jiewen" , "edk2-devel@lists.01.org" CC: "Ni, Ruiyu" , Laszlo Ersek , "Dong, Eric" Thread-Topic: [edk2] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: fix infinite loop issue in SMM profile Thread-Index: AQHTnvbspehPlHmI0kOiNRPp/a6/uaOWYcgAgACM39A= Date: Tue, 6 Feb 2018 06:50:42 +0000 Message-ID: References: <20180206030206.112-1-jian.j.wang@intel.com> <74D8A39837DF1E4DA445A8C0B3885C503AAB5D27@shsmsx102.ccr.corp.intel.com> In-Reply-To: <74D8A39837DF1E4DA445A8C0B3885C503AAB5D27@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMjE2OTlkZTktYWRkMS00MTgwLTllMjMtMTc3Zjc4NTI4NTBkIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjIuNS4xOCIsIlRydXN0ZWRMYWJlbEhhc2giOiJVZHRVNXNFbzVLRzJiNStnZ3B3UDZob3RcL25XR0U5czNBOHMxQ2VDVURpUnVxUmtJdHZhdktTUmxOcTVDU3orMyJ9 x-ctpclassification: CTP_NT 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] UefiCpuPkg/PiSmmCpuDxeSmm: fix infinite loop issue in SMM profile X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Feb 2018 06:45:03 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable They're following 3 pages: | Page before | Page triggering #PF | Page after | because all I need to do is to make sure that there's no non-present pages = during memory operation cross pages. Regards, Jian > -----Original Message----- > From: Yao, Jiewen > Sent: Tuesday, February 06, 2018 2:23 PM > To: Wang, Jian J ; edk2-devel@lists.01.org > Cc: Ni, Ruiyu ; Laszlo Ersek ; Don= g, > Eric > Subject: RE: [edk2] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: fix infinite loop > issue in SMM profile >=20 > Hi > May I know how "3" is calculated? >=20 > + RestorePageNumber =3D 3; >=20 > Thank you > Yao Jiewen >=20 >=20 > > -----Original Message----- > > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of = Jian > J > > Wang > > Sent: Tuesday, February 6, 2018 11:02 AM > > To: edk2-devel@lists.01.org > > Cc: Ni, Ruiyu ; Yao, Jiewen ; > Laszlo > > Ersek ; Dong, Eric > > Subject: [edk2] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: fix infinite loop is= sue > in > > SMM profile > > > > The infinite loop is caused by the memory instruction, such as > > "rep mov", operating on memory block crossing boundary of NON-PRESENT > > pages. Because the address triggering page fault set in CR2 will be in > > the first page, SmmProfilePFHandler() will only change the first page > > into PRESENT. The page following will be still in NON-PRESENT status. > > > > Since SmmProfilePFHandler() will setup single-step trap for the > > instruction causing #PF, when the handler returns back to the > > instruction and re-execute it, both #DB and #PF will be triggered > > because the instruction wants to access both first and second page > > but only first page is PRESENT. > > > > Normally #DB exception will be handled first and its handler will > > change first page back to NON-PRESENT status. Then #PF is handled > > and its handler will change first page to PRESENT status again and > > setup another single-step for the instruction triggering #PF. Then > > the whole system falls into an infinite loop and the memory operation > > will never move on. > > > > This patch fix above situation by always changing 3 pages to PRESENT > > status instead of just 1 page. Those 3 pages include the page before > > and after the page causing #PF because memory operation instruction > > may have direction flag (DF) set or cleared. > > > > Cc: Eric Dong > > Cc: Laszlo Ersek > > Cc: Ruiyu Ni > > Cc: Jiewen Yao > > Contributed-under: TianoCore Contribution Agreement 1.1 > > Signed-off-by: Jian J Wang > > --- > > UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c | 22 ++++++++++++++++++---- > > 1 file changed, 18 insertions(+), 4 deletions(-) > > > > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c > > b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c > > index 9588eaf029..8cdfc82a92 100644 > > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c > > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c > > @@ -1302,6 +1302,8 @@ SmmProfilePFHandler ( > > { > > UINT64 *PageTable; > > UINT64 PFAddress; > > + UINT64 RestoreAddress; > > + UINTN RestorePageNumber; > > UINTN CpuIndex; > > UINTN Index; > > UINT64 InstructionAddress; > > @@ -1331,10 +1333,22 @@ SmmProfilePFHandler ( > > PFAddress =3D AsmReadCr2 (); > > CpuIndex =3D GetCpuIndex (); > > > > - if (PFAddress <=3D 0xFFFFFFFF) { > > - RestorePageTableBelow4G (PageTable, PFAddress, CpuIndex, ErrorCode= ); > > - } else { > > - RestorePageTableAbove4G (PageTable, PFAddress, CpuIndex, ErrorCode= , > > &IsValidPFAddress); > > + // > > + // Memory operation cross pages, like "rep mov" instruction, will ca= use > > + // infinite loop between this and Debug Trap handler. Since the dire= ction > > + // of memory operation is unknown, the pages before and after curren= t > page > > + // should be taken into account as well. > > + // > > + RestorePageNumber =3D 3; > > + RestoreAddress =3D PFAddress - EFI_PAGE_SIZE; > > + while (RestorePageNumber > 0) { > > + if (RestoreAddress <=3D 0xFFFFFFFF) { > > + RestorePageTableBelow4G (PageTable, RestoreAddress, CpuIndex, > > ErrorCode); > > + } else { > > + RestorePageTableAbove4G (PageTable, RestoreAddress, CpuIndex, > > ErrorCode, &IsValidPFAddress); > > + } > > + RestoreAddress +=3D EFI_PAGE_SIZE; > > + RestorePageNumber--; > > } > > > > if (!IsValidPFAddress) { > > -- > > 2.14.1.windows.1 > > > > _______________________________________________ > > edk2-devel mailing list > > edk2-devel@lists.01.org > > https://lists.01.org/mailman/listinfo/edk2-devel