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.88; helo=mga01.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 94A8021A09130 for ; Mon, 27 Aug 2018 20:28:10 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Aug 2018 20:28:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,297,1531810800"; d="scan'208,217";a="228176758" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga004.jf.intel.com with ESMTP; 27 Aug 2018 20:24:41 -0700 Received: from fmsmsx157.amr.corp.intel.com (10.18.116.73) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 27 Aug 2018 20:24:41 -0700 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX157.amr.corp.intel.com (10.18.116.73) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 27 Aug 2018 20:24:40 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.240]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.143]) with mapi id 14.03.0319.002; Tue, 28 Aug 2018 11:24:39 +0800 From: "Wang, Jian J" To: "Dong, Eric" , "edk2-devel@lists.01.org" CC: Laszlo Ersek , "Ni, Ruiyu" Thread-Topic: [PATCH v2 2/4] UefiCpuPkg/CpuExceptionHandlerLib: Setup single step in #PF handler Thread-Index: AQHUPmyIL5/vVUNm+U6pJLM7UYJO0qTUf4yg Date: Tue, 28 Aug 2018 03:24:38 +0000 Message-ID: References: <20180821030515.10156-1-jian.j.wang@intel.com> <20180821030515.10156-3-jian.j.wang@intel.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZjEzYmNlYWItNmZlMS00OTZhLWExYmYtMmJmZDU5ZDljYzZiIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiRmh5WFk1Z3JsOVhRbEh4R2ZXWEhOeFwvempPR09yeUI4aXVHWEQ3RW13UGR2TmxHWGVyd3lMMjc0ekpMRDdhaSsifQ== x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: Re: [PATCH v2 2/4] UefiCpuPkg/CpuExceptionHandlerLib: Setup single step in #PF handler 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: Tue, 28 Aug 2018 03:28:10 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Thanks. Since there're just some minor changes, I'll not provide v3 patches and push the changes to master soon. Regards, Jian From: Dong, Eric Sent: Tuesday, August 28, 2018 9:15 AM To: Wang, Jian J ; edk2-devel@lists.01.org Cc: Laszlo Ersek ; Ni, Ruiyu Subject: RE: [PATCH v2 2/4] UefiCpuPkg/CpuExceptionHandlerLib: Setup single= step in #PF handler Reviewed-by: Eric Dong > > -----Original Message----- > From: Wang, Jian J > Sent: Tuesday, August 21, 2018 11:05 AM > To: edk2-devel@lists.01.org > Cc: Dong, Eric >; Laszlo = Ersek >; Ni, > Ruiyu > > Subject: [PATCH v2 2/4] UefiCpuPkg/CpuExceptionHandlerLib: Setup single > step in #PF handler > > > v2 changes: > > n/a > > Once the #PF handler has set the page to be 'present', there should be a = way > to reset it to 'not-present'. 'TF' bit in EFLAGS can be used for this pur= pose. 'TF' > bit will be set in interrupted function context so that it can be trigger= ed once > the cpu control returns back to the instruction causing #PF and re-execut= e it. > > This is an necessary step to implement non-stop mode for Heap Guard and > NULL Pointer Detection feature. > > Cc: Eric Dong > > Cc: Laszlo Ersek > > Cc: Ruiyu Ni > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Jian J Wang > > --- > .../Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nasm | 7 > +++++++ > .../Library/CpuExceptionHandlerLib/Ia32/ExceptionTssEntryAsm.nasm | 4 += -- > - > .../Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm | 4 > ++++ > 3 files changed, 12 insertions(+), 3 deletions(-) > > diff --git > a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.na > sm > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.na > sm > index 45d6474091..6fcf5fb23f 100644 > --- > a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.na > sm > +++ > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm > +++ .nasm > @@ -383,6 +383,13 @@ ErrorCodeAndVectorOnStack: > pop dword [ebp - 4] > mov esp, ebp > pop ebp > + > +; Enable TF bit after page fault handler runs > + cmp dword [esp], 14 ; #PF? > + jne .5 > + bts dword [esp + 16], 8 ; EFLAGS > + > +.5: > add esp, 8 > cmp dword [esp - 16], 0 ; check > EXCEPTION_HANDLER_CONTEXT.OldIdtHandler > jz DoReturn > diff --git > a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionTssEntryAsm.n > asm > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionTssEntryAsm.n > asm > index 62bcedea1a..7aac29c7e7 100644 > --- > a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionTssEntryAsm.n > asm > +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionTssEntryAs > +++ m.nasm > @@ -355,10 +355,8 @@ o16 mov [ecx + IA32_TSS._SS], ax > movzx ebx, word [ecx + IA32_TSS._CS] > mov [eax - 0x8], ebx ; create CS in old stac= k > mov ebx, dword [ecx + IA32_TSS.EFLAGS] > - bts ebx, 8 > + bts ebx, 8 ; Set TF > mov [eax - 0x4], ebx ; create eflags in old = stack > - mov dword [ecx + IA32_TSS.EFLAGS], ebx ; update eflags in old = TSS > - mov eax, dword [ecx + IA32_TSS._ESP] ; Get old stack pointer > sub eax, 0xc ; minus 12 byte > mov dword [ecx + IA32_TSS._ESP], eax ; Set new stack pointer > > diff --git > a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.na > sm > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.na > sm > index 7b97810d10..f842af2336 100644 > --- > a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.na > sm > +++ > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm. > +++ nasm > @@ -336,6 +336,10 @@ HasErrorCode: > pop r15 > > mov rsp, rbp > + cmp qword [rbp + 8], 14 ; #PF? > + jne .1 > + bts qword [rsp + 40], 8 ; RFLAGS.TF > +.1: > pop rbp > add rsp, 16 > cmp qword [rsp - 32], 0 ; check > EXCEPTION_HANDLER_CONTEXT.OldIdtHandler > -- > 2.16.2.windows.1