From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=63.147.10.40; helo=atlmailgw1.ami.com; envelope-from=felixp@ami.com; receiver=edk2-devel@lists.01.org Received: from atlmailgw1.ami.com (atlmailgw1.ami.com [63.147.10.40]) (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 B7DCE2118F78B for ; Thu, 29 Nov 2018 16:35:48 -0800 (PST) X-AuditID: ac1060b2-0c9ff70000000d42-7b-5c0085e38a98 Received: from atlms1.us.megatrends.com (atlms1.us.megatrends.com [172.16.96.144]) (using TLS with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (Client did not present a certificate) by atlmailgw1.ami.com (Symantec Messaging Gateway) with SMTP id 8E.8C.03394.3E5800C5; Thu, 29 Nov 2018 19:35:47 -0500 (EST) Received: from Felix7.us.megatrends.com (172.16.99.93) by atlms1.us.megatrends.com (172.16.96.144) with Microsoft SMTP Server id 14.3.408.0; Thu, 29 Nov 2018 19:35:46 -0500 From: Felix Polyudov To: CC: , , Date: Thu, 29 Nov 2018 19:35:46 -0500 Message-ID: <20181130003546.28252-1-felixp@ami.com> X-Mailer: git-send-email 2.10.0.windows.1 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrHIsWRmVeSWpSXmKPExsWyRiBhgu7jVoYYg3l/+Cz2HDrKbLH5RbDF smM7WCxe9qxmd2DxWLznJZNH9+x/LB7v911lC2COamC0SczLyy9JLElVSEktTrZVCijKLEtM rlRSyEyxVTJUUijISUxOzU3NK7FVSiwoSM1LUbLjUsAANkBlmXkKqXnJ+SmZeem2Sp7B/roW FqaWuoZKdiEZqQqZeWn5RbmJJZn5eQrJ+XklQNWpKUBRhYQuzozH75IKrohUrD9wjKmBcZtA FyMnh4SAiUT/yZ8sXYxcHEICu5gkLv1ognI2MEpcmNHMBFLFJqAqsWXiKhYQW0RAVuJP5ycw m1nARWLHhePMILawgLvE1G+7wGwWoPptiw+A2bwCxhLNVzezQWzTlJg+6zVUXFDi5MwnUHMk JA6+eAEWFxKQljj78DfjBEbeWUjKZiEpW8DItIpRKLEkJzcxMye93FAvMTdTLzk/dxMjJHo2 7WBsuWh+iFGAg1GJh9e4iiFGiDWxrLgy9xCjBAezkgjvxxKgEG9KYmVValF+fFFpTmrxIUYn oLMnMktxg4INGA/xxgYGUqIwjqGJmYm5kbmhpYm5sbGSOG++2qcoIYF0YHxmp6YWpBbBDGHi 4JRqYHzUp/H60Qu+RW6Cyn/kZyy0inyT/Ubn1/XCHuup4sypz61EZp6tVPiWqvX5h/iynO5d D/c3SWpbSXo+Ze1rEVmQZ1cV73L9sqm/qfM/7lMmrjmrjotOsfF1e/2mL3bDNv+Lc3nexRYc /Lowh2P3Pfa7fW9ZIg/NbCiw/LJoswd/hqD063zV3UosxRmJhlrMRcWJANklpP7BAgAA Subject: [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 00:35:49 -0000 Content-Type: text/plain 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. 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(-) 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 = ApStackSize * MaxLogicalProcessorNumber; BufferSize += MonitorFilterSize * MaxLogicalProcessorNumber; BufferSize += ApResetVectorSize; + BufferSize += sizeof(UINTN); BufferSize = ALIGN_VALUE (BufferSize, 8); BufferSize += VolatileRegisters.Idtr.Limit + 1; BufferSize += 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 = (UINT8 *) (Buffer + ApStackSize * MaxLogicalProcessorNumber); BackupBufferAddr = (UINTN) MonitorBuffer + MonitorFilterSize * MaxLogicalProcessorNumber; - ApIdtBase = ALIGN_VALUE (BackupBufferAddr + ApResetVectorSize, 8); + ApIdtBase = ALIGN_VALUE (BackupBufferAddr + ApResetVectorSize + sizeof(UINTN), 8); CpuMpData = (CPU_MP_DATA *) (ApIdtBase + VolatileRegisters.Idtr.Limit + 1); CpuMpData->Buffer = Buffer; CpuMpData->CpuApStackSize = ApStackSize; @@ -1653,6 +1656,11 @@ MpInitLibInitialize ( Buffer + BufferSize); // + // Initialize PEI Services table pointer. Copy the address from BSP. + // + *(UINTN*)(ApIdtBase - sizeof(UINTN)) = *(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 CpuMpData by using IDTR.BASE + IDTR.LIMIT + 1 // -- 2.10.0.windows.1 Please consider the environment before printing this email. The information contained in this message may be confidential and proprietary to American Megatrends, Inc. This communication is intended to be read only 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 that any distribution of this message, in any form, is strictly prohibited. Please promptly notify the sender by reply e-mail or by telephone at 770-246-8600, and then delete or destroy all copies of the transmission.