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.126; helo=mga18.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (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 C82A121197073 for ; Thu, 29 Nov 2018 19:42:52 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Nov 2018 19:42:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,297,1539673200"; d="scan'208";a="117035608" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga004.fm.intel.com with ESMTP; 29 Nov 2018 19:42:51 -0800 Received: from fmsmsx161.amr.corp.intel.com (10.18.125.9) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 29 Nov 2018 19:42:51 -0800 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX161.amr.corp.intel.com (10.18.125.9) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 29 Nov 2018 19:42:51 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.203]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.46]) with mapi id 14.03.0415.000; Fri, 30 Nov 2018 11:42:48 +0800 From: "Ni, Ruiyu" To: Felix Polyudov , "edk2-devel@lists.01.org" CC: "Dong, Eric" , "lersek@redhat.com" , "'Andrew Fish (afish@apple.com)'" Thread-Topic: [Patch] UefiCpuPkg/MpLib: Fix PEI Services Table pointer on AP Thread-Index: AQHUiESqdZMmaBa1iEGzadKB8Qq5QKVnrGJg Date: Fri, 30 Nov 2018 03:42:48 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5BF35F8E@SHSMSX104.ccr.corp.intel.com> References: <20181130003546.28252-1-felixp@ami.com> In-Reply-To: <20181130003546.28252-1-felixp@ami.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiODQ4ZmViNTYtNjFjZC00ZjBjLWJkYmQtNmE1Y2MxNzMyM2NiIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiQnRMTUlsdkd0dGZcL2QxM0FkeVdJMWowdW9ZU3JrWUc3enJFelJnVmJGV3pialZ0ZjhBeW40dVFWOGpmSzBcL1hwIn0= 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 Subject: Re: [Patch] UefiCpuPkg/MpLib: Fix PEI Services Table pointer on AP 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, 30 Nov 2018 03:42:53 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Felix, I disagree:) Sorry about that. :) The commit you mentioned might be made by me (didn't checked). Because I aimed to avoid calling PEI services from AP. That's a violation o= f PI spec and not safe by design. The AP calling standard services concern was raised by Andrew initially. Thanks, Ray > -----Original Message----- > From: Felix Polyudov [mailto:felixp@ami.com] > Sent: Friday, November 30, 2018 8:36 AM > To: edk2-devel@lists.01.org > Cc: Dong, Eric ; Ni, Ruiyu ; > lersek@redhat.com > Subject: [Patch] UefiCpuPkg/MpLib: Fix PEI Services Table pointer on AP >=20 > According to PI specification PEI Services table pointer is stored right = before ITD > base. Starting from commit c563077a380437c1 BSP and AP have different IDT > instances. > PEI Services table pointer was not initialized in the AP IDT instance. > As a result, any attempt to use functions from PeiServicesTablePointerLib= or > PeiServicesLib on AP caused CPU exception. >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Felix Polyudov > --- > UefiCpuPkg/Library/MpInitLib/MpLib.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) >=20 > diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c > b/UefiCpuPkg/Library/MpInitLib/MpLib.c > index 7f4d6e6..0e3e362 100644 > --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c > +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c > @@ -1567,6 +1567,7 @@ MpInitLibInitialize ( > BufferSize =3D ApStackSize * MaxLogicalProcessorNumber; > BufferSize +=3D MonitorFilterSize * MaxLogicalProcessorNumber; > BufferSize +=3D ApResetVectorSize; > + BufferSize +=3D sizeof(UINTN); > BufferSize =3D ALIGN_VALUE (BufferSize, 8); > BufferSize +=3D VolatileRegisters.Idtr.Limit + 1; > BufferSize +=3D sizeof (CPU_MP_DATA); > @@ -1587,6 +1588,8 @@ MpInitLibInitialize ( > // Backup Buffer > // +--------------------+ > // Padding > + // +--------------------+ > + // PEI Services Table Pointer > // +--------------------+ <-- ApIdtBase (8-byte boundary) > // AP IDT All APs share one separate IDT. So AP can= get address of > CPU_MP_DATA from IDT Base. > // +--------------------+ <-- CpuMpData > @@ -1599,7 +1602,7 @@ MpInitLibInitialize ( > // > MonitorBuffer =3D (UINT8 *) (Buffer + ApStackSize * > MaxLogicalProcessorNumber); > BackupBufferAddr =3D (UINTN) MonitorBuffer + MonitorFilterSize * > MaxLogicalProcessorNumber; > - ApIdtBase =3D ALIGN_VALUE (BackupBufferAddr + ApResetVectorSize= , 8); > + ApIdtBase =3D ALIGN_VALUE (BackupBufferAddr + ApResetVectorSize= + > sizeof(UINTN), 8); > CpuMpData =3D (CPU_MP_DATA *) (ApIdtBase + VolatileRegisters.Id= tr.Limit + > 1); > CpuMpData->Buffer =3D Buffer; > CpuMpData->CpuApStackSize =3D ApStackSize; > @@ -1653,6 +1656,11 @@ MpInitLibInitialize ( > Buffer + BufferSize); >=20 > // > + // Initialize PEI Services table pointer. Copy the address from BSP. > + // > + *(UINTN*)(ApIdtBase - sizeof(UINTN)) =3D > + *(UINTN*)(VolatileRegisters.Idtr.Base - sizeof (UINTN)); > + > + // > // Duplicate BSP's IDT to APs. > // All APs share one separate IDT. So AP can get the address of CpuMpD= ata by > using IDTR.BASE + IDTR.LIMIT + 1 > // > -- > 2.10.0.windows.1 >=20 >=20 >=20 > Please consider the environment before printing this email. >=20 > The information contained in this message may be confidential and proprie= tary > to American Megatrends, Inc. This communication is intended to be read o= nly > by the individual or entity to whom it is addressed or by their designee.= If the > reader of this message is not the intended recipient, you are on notice t= hat any > distribution of this message, in any form, is strictly prohibited. Pleas= e promptly > notify the sender by reply e-mail or by telephone at 770-246-8600, and th= en > delete or destroy all copies of the transmission.