From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.120, mailfrom: eric.dong@intel.com) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by groups.io with SMTP; Thu, 19 Sep 2019 23:39:57 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Sep 2019 23:39:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,527,1559545200"; d="scan'208";a="217559208" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by fmsmga002.fm.intel.com with ESMTP; 19 Sep 2019 23:39:53 -0700 Received: from fmsmsx157.amr.corp.intel.com (10.18.116.73) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 19 Sep 2019 23:39:50 -0700 Received: from shsmsx153.ccr.corp.intel.com (10.239.6.53) by FMSMSX157.amr.corp.intel.com (10.18.116.73) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 19 Sep 2019 23:39:50 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.113]) by SHSMSX153.ccr.corp.intel.com ([169.254.12.235]) with mapi id 14.03.0439.000; Fri, 20 Sep 2019 14:39:47 +0800 From: "Dong, Eric" To: "devel@edk2.groups.io" , "Lofgren, John E" Subject: Re: [edk2-devel] [Patch V3] UefiCpuPkg/CpuExceptionHandlerLib: Fix split lock Thread-Topic: [edk2-devel] [Patch V3] UefiCpuPkg/CpuExceptionHandlerLib: Fix split lock Thread-Index: AQHVbjfY6s0tmR91qUKHvxk1CfDePqc0H6WA Date: Fri, 20 Sep 2019 06:39:46 +0000 Message-ID: References: <20190918154323.20804-1-john.e.lofgren@intel.com> In-Reply-To: <20190918154323.20804-1-john.e.lofgren@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: eric.dong@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Eric Dong And pushed: SHA-1: f4c898f2b2db2819c519cdce05403d4ba0234979 Thanks, Eric > -----Original Message----- > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of Jo= hn > E Lofgren > Sent: Wednesday, September 18, 2019 11:43 PM > To: devel@edk2.groups.io > Subject: [edk2-devel] [Patch V3] UefiCpuPkg/CpuExceptionHandlerLib: Fix = split > lock >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2150 > V3 changes: > change to mov instruction (non locking instuction) instead > of xchg to simplify design. >=20 > V2 changes: > Add xchg 16 bit instructions to handle sgdt and sidt base > 63:48 bits and 47:32 bits. > Add comment to explain why xchg 64bit isnt being used >=20 > Split lock happens when a locking instruction is used on mis-aligned dat= a > that crosses two cachelines. If close source platform enables Alignment = Check > Exception(#AC), They can hit a double fault due to split lock being in > CpuExceptionHandlerLib. >=20 > sigt and sgdt saves 10 bytes to memory, 8 bytes is base and 2 bytes is l= imit. > The data is mis-aligned, can cross two cacheline, and a xchg > instruction(locking instuction) is being utilize. >=20 > Signed-off-by: John E Lofgren > --- > UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm > | 14 ++++++++------ > 1 file changed, 8 insertions(+), 6 deletions(-) >=20 > diff --git > a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nas > m > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nas > m > index 4db1a09f28..19198f2731 100644 > --- > a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nas > m > +++ > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nas > m > @@ -184,17 +184,19 @@ HasErrorCode: > push rax > push rax > sidt [rsp] > - xchg rax, [rsp + 2] > - xchg rax, [rsp] > - xchg rax, [rsp + 8] > + mov bx, word [rsp] > + mov rax, qword [rsp + 2] > + mov qword [rsp], rax > + mov word [rsp + 8], bx >=20 > xor rax, rax > push rax > push rax > sgdt [rsp] > - xchg rax, [rsp + 2] > - xchg rax, [rsp] > - xchg rax, [rsp + 8] > + mov bx, word [rsp] > + mov rax, qword [rsp + 2] > + mov qword [rsp], rax > + mov word [rsp + 8], bx >=20 > ;; UINT64 Ldtr, Tr; > xor rax, rax > -- > 2.16.2.windows.1 >=20 >=20 >=20