From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id A9288AC13B5 for ; Mon, 29 Jan 2024 18:58:20 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=1C/F7ywAAwmBk8opmdthAQhdgupfNr3gm9DkhmwvrEA=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706554699; v=1; b=vdZ14lB2kUXg0zFjqSJX40lh1uMB2vujodFRY2qnbZEJPx+mikS6SqWSvemgvFgljTrXlbr3 vu9n2LwwvE24hQU09GXDD9LnTNls1HWDBUf1hlyq1e7gbAx72255XV12Be+jDKjXj+O+4pR3Dlq Av6tVuJG9Oy8LrK4GzFEghTQ= X-Received: by 127.0.0.2 with SMTP id ibczYY7687511xgxBjBoewp1; Mon, 29 Jan 2024 10:58:19 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) by mx.groups.io with SMTP id smtpd.web11.3677.1706554698428677491 for ; Mon, 29 Jan 2024 10:58:18 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10968"; a="1984621" X-IronPort-AV: E=Sophos;i="6.05,227,1701158400"; d="scan'208";a="1984621" X-Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2024 10:58:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,227,1701158400"; d="scan'208";a="22192083" X-Received: from mdkinney-mobl.amr.corp.intel.com ([10.212.128.183]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2024 10:58:18 -0800 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Liming Gao , Aaron Li , Liu Yun , Andrew Fish , Laszlo Ersek Subject: [edk2-devel] [Patch v3 1/2] MdeModulePkg/Core/Dxe: Initialize GCD before RT memory allocations Date: Mon, 29 Jan 2024 10:58:07 -0800 Message-Id: <20240129185808.776-2-michael.d.kinney@intel.com> In-Reply-To: <20240129185808.776-1-michael.d.kinney@intel.com> References: <20240129185808.776-1-michael.d.kinney@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,michael.d.kinney@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: xzxxwvEiYm7vU70rCNJGH8X0x7686176AA= Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=vdZ14lB2; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Update the DxeMain initialization order to initialize GCD services before any runtime allocations are performed. This is required to prevent runtime data fragmentation when the UEFI System Table and UEFI Runtime Service Table are allocated before both the memory and GCD services are initialized. Cc: Liming Gao Cc: Aaron Li Cc: Liu Yun Cc: Andrew Fish Cc: Laszlo Ersek Signed-off-by: Michael D Kinney Reviewed-by: Liming Gao --- MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c | 23 ++++++++++++++--------- MdeModulePkg/Core/Dxe/Image/Image.c | 13 ++++++------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c index 0e0f9769b99d..17d510a287e5 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c +++ b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c @@ -276,6 +276,18 @@ DxeMain ( MemoryProfileInit (HobStart); + // + // Start the Image Services. + // + Status = CoreInitializeImageServices (HobStart); + ASSERT_EFI_ERROR (Status); + + // + // Initialize the Global Coherency Domain Services + // + Status = CoreInitializeGcdServices (&HobStart, MemoryBaseAddress, MemoryLength); + ASSERT_EFI_ERROR (Status); + // // Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData // Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table @@ -289,16 +301,9 @@ DxeMain ( gDxeCoreST->RuntimeServices = gDxeCoreRT; // - // Start the Image Services. + // Update DXE Core Loaded Image Protocol with allocated UEFI System Table // - Status = CoreInitializeImageServices (HobStart); - ASSERT_EFI_ERROR (Status); - - // - // Initialize the Global Coherency Domain Services - // - Status = CoreInitializeGcdServices (&HobStart, MemoryBaseAddress, MemoryLength); - ASSERT_EFI_ERROR (Status); + gDxeCoreLoadedImage->SystemTable = gDxeCoreST; // // Call constructor for all libraries diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c index 6bc3a549ae5e..f520c4885c3e 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -218,13 +218,12 @@ CoreInitializeImageServices ( // Image = &mCorePrivateImage; - Image->EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)DxeCoreEntryPoint; - Image->ImageBasePage = DxeCoreImageBaseAddress; - Image->NumberOfPages = (UINTN)(EFI_SIZE_TO_PAGES ((UINTN)(DxeCoreImageLength))); - Image->Tpl = gEfiCurrentTpl; - Image->Info.SystemTable = gDxeCoreST; - Image->Info.ImageBase = (VOID *)(UINTN)DxeCoreImageBaseAddress; - Image->Info.ImageSize = DxeCoreImageLength; + Image->EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)DxeCoreEntryPoint; + Image->ImageBasePage = DxeCoreImageBaseAddress; + Image->NumberOfPages = (UINTN)(EFI_SIZE_TO_PAGES ((UINTN)(DxeCoreImageLength))); + Image->Tpl = gEfiCurrentTpl; + Image->Info.ImageBase = (VOID *)(UINTN)DxeCoreImageBaseAddress; + Image->Info.ImageSize = DxeCoreImageLength; // // Install the protocol interfaces for this image -- 2.40.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#114733): https://edk2.groups.io/g/devel/message/114733 Mute This Topic: https://groups.io/mt/104038199/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-