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.31; helo=mga06.intel.com; envelope-from=jordan.l.justen@intel.com; receiver=edk2-devel@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 4E8FB21A070B8 for ; Sun, 17 Feb 2019 20:12:00 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Feb 2019 20:12:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,383,1544515200"; d="scan'208";a="321197977" Received: from mmdandap-mobl1.amr.corp.intel.com (HELO jljusten-skl.amr.corp.intel.com) ([10.254.8.66]) by fmsmga005.fm.intel.com with ESMTP; 17 Feb 2019 20:11:59 -0800 From: Jordan Justen To: edk2-devel@lists.01.org Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Anthony Perard , Julien Grall Date: Sun, 17 Feb 2019 20:11:36 -0800 Message-Id: <20190218041141.21363-6-jordan.l.justen@intel.com> X-Mailer: git-send-email 2.20.0.rc1 In-Reply-To: <20190218041141.21363-1-jordan.l.justen@intel.com> References: <20190218041141.21363-1-jordan.l.justen@intel.com> MIME-Version: 1.0 Subject: [PATCH 05/10] OvmfPkg/Sec: Swap TemporaryRam Stack and Heap locations 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: Mon, 18 Feb 2019 04:12:00 -0000 Content-Transfer-Encoding: 8bit Apparently something depends on the heap being above the stack after TemporaryRamMigration. This is the opposite order that OVMF has always used for TempRam before migration to permanent ram. In 42a83e80f37c (svn r10770), Mike changed OVMF's TemporaryRamMigration to swap the locations of heap and stack during the migration. Rather than doing the swap during TemporaryRamMigration, this change causes OVMF to boot with TemporaryRam setup with heap being above the stack. Then, during TemporaryRamMigration, we can directly copy all of TemporaryRam. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Anthony Perard Cc: Julien Grall --- OvmfPkg/Sec/Ia32/SecEntry.nasm | 2 +- OvmfPkg/Sec/SecMain.c | 39 +++++++++++++++++----------------- OvmfPkg/Sec/X64/SecEntry.nasm | 2 +- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/OvmfPkg/Sec/Ia32/SecEntry.nasm b/OvmfPkg/Sec/Ia32/SecEntry.nasm index 03501969eb..61917b9eef 100644 --- a/OvmfPkg/Sec/Ia32/SecEntry.nasm +++ b/OvmfPkg/Sec/Ia32/SecEntry.nasm @@ -57,7 +57,7 @@ ASM_PFX(_ModuleEntryPoint): ; Load temporary RAM stack based on PCDs ; %define SEC_TOP_OF_STACK (FixedPcdGet32 (PcdOvmfSecPeiTempRamBase) + \ - FixedPcdGet32 (PcdOvmfSecPeiTempRamSize)) + (FixedPcdGet32 (PcdOvmfSecPeiTempRamSize) / 2)) mov eax, SEC_TOP_OF_STACK mov esp, eax nop diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index f7fec3d8c0..46ac739862 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -1,7 +1,7 @@ /** @file Main SEC phase code. Transitions to PEI. - Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.
(C) Copyright 2016 Hewlett Packard Enterprise Development LP
This program and the accompanying materials @@ -779,15 +779,15 @@ SecCoreStartupWithStack ( #endif // - // |-------------| <-- TopOfCurrentStack - // | Stack | 32k // |-------------| // | Heap | 32k + // |-------------| <-- TopOfCurrentStack + // | Stack | 32k // |-------------| <-- SecCoreData.TemporaryRamBase // ASSERT ((UINTN) (PcdGet32 (PcdOvmfSecPeiTempRamBase) + - PcdGet32 (PcdOvmfSecPeiTempRamSize)) == + (PcdGet32 (PcdOvmfSecPeiTempRamSize) / 2)) == (UINTN) TopOfCurrentStack); // @@ -795,14 +795,17 @@ SecCoreStartupWithStack ( // SecCoreData.DataSize = sizeof(EFI_SEC_PEI_HAND_OFF); - SecCoreData.TemporaryRamSize = (UINTN) PcdGet32 (PcdOvmfSecPeiTempRamSize); - SecCoreData.TemporaryRamBase = (VOID*)((UINT8 *)TopOfCurrentStack - SecCoreData.TemporaryRamSize); + SecCoreData.TemporaryRamBase = + (VOID*)(UINTN) PcdGet32 (PcdOvmfSecPeiTempRamBase); + SecCoreData.TemporaryRamSize = (UINTN) PcdGet32 (PcdOvmfSecPeiTempRamSize); - SecCoreData.PeiTemporaryRamBase = SecCoreData.TemporaryRamBase; - SecCoreData.PeiTemporaryRamSize = SecCoreData.TemporaryRamSize >> 1; + SecCoreData.PeiTemporaryRamBase = + (UINT8*)(VOID*)(UINTN) PcdGet32 (PcdOvmfSecPeiTempRamBase) + + ((UINTN) PcdGet32 (PcdOvmfSecPeiTempRamSize) / 2); + SecCoreData.PeiTemporaryRamSize = PcdGet32 (PcdOvmfSecPeiTempRamSize) / 2; - SecCoreData.StackBase = (UINT8 *)SecCoreData.TemporaryRamBase + SecCoreData.PeiTemporaryRamSize; - SecCoreData.StackSize = SecCoreData.TemporaryRamSize >> 1; + SecCoreData.StackBase = (VOID*)(UINTN) PcdGet32 (PcdOvmfSecPeiTempRamBase); + SecCoreData.StackSize = PcdGet32 (PcdOvmfSecPeiTempRamSize) / 2; SecCoreData.BootFirmwareVolumeBase = BootFv; SecCoreData.BootFirmwareVolumeSize = (UINTN) BootFv->FvLength; @@ -895,10 +898,10 @@ TemporaryRamMigration ( (UINT64)CopySize )); - OldHeap = (VOID*)(UINTN)TemporaryMemoryBase; + OldHeap = (VOID*)((UINTN)TemporaryMemoryBase + (CopySize >> 1)); NewHeap = (VOID*)((UINTN)PermanentMemoryBase + (CopySize >> 1)); - OldStack = (VOID*)((UINTN)TemporaryMemoryBase + (CopySize >> 1)); + OldStack = (VOID*)(UINTN)TemporaryMemoryBase; NewStack = (VOID*)(UINTN)PermanentMemoryBase; DebugAgentContext.HeapMigrateOffset = (UINTN)NewHeap - (UINTN)OldHeap; @@ -908,15 +911,13 @@ TemporaryRamMigration ( InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, (VOID *) &DebugAgentContext, NULL); // - // Migrate Heap + // Migrate the whole temporary memory to permenent memory. // - CopyMem (NewHeap, OldHeap, CopySize >> 1); + CopyMem( + (VOID*)(UINTN)PermanentMemoryBase, + (VOID*)(UINTN)TemporaryMemoryBase, + CopySize); - // - // Migrate Stack - // - CopyMem (NewStack, OldStack, CopySize >> 1); - // // Rebase IDT table in permanent memory // diff --git a/OvmfPkg/Sec/X64/SecEntry.nasm b/OvmfPkg/Sec/X64/SecEntry.nasm index d76adcffd8..dd603d6eb0 100644 --- a/OvmfPkg/Sec/X64/SecEntry.nasm +++ b/OvmfPkg/Sec/X64/SecEntry.nasm @@ -59,7 +59,7 @@ ASM_PFX(_ModuleEntryPoint): ; Load temporary RAM stack based on PCDs ; %define SEC_TOP_OF_STACK (FixedPcdGet32 (PcdOvmfSecPeiTempRamBase) + \ - FixedPcdGet32 (PcdOvmfSecPeiTempRamSize)) + (FixedPcdGet32 (PcdOvmfSecPeiTempRamSize) / 2)) mov rsp, SEC_TOP_OF_STACK nop -- 2.20.0.rc1