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 2F316AC0EE6 for ; Wed, 16 Aug 2023 08:56:07 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=7baSs20b22xMc5iyQ41IV+rLF0C19Ipc1j/A5txosSQ=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:Message-ID:Date:User-Agent:Subject:To:CC:References:From:In-Reply-To:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1692176166; v=1; b=IutZSYVUCxuaw6gzTFEsoBZqFjAR2IQzTyhJITpvXSD4io6ImcEcsAfMtAjaYWPM4zFhdc3W jmOAuZZcHInykA9lb+j4Vevs0Cwy34orB3vvCZeJu7fXNAi4lYwxmWOtolJY+hfJWAVvGlws53U d2RvNxGlGlr4z3E33SYWrz1k= X-Received: by 127.0.0.2 with SMTP id v7FIYY7687511xvIyPNPFAY8; Wed, 16 Aug 2023 01:56:06 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.104]) by mx.groups.io with SMTP id smtpd.web10.156831.1692176165888294144 for ; Wed, 16 Aug 2023 01:56:06 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T8BRM4q+iw1P3BYF27mBBK06k5WSUzt5bUlBfdrqk79OJTmeKbhpKrHquYmxZSL/PPl5F20FTd8sjqdF0QfkdNs9555vybJG4wwHLyEl7CGx8cHXNVn5jLKGjcrXnsMjmjBs4msnEkudvEcbIF9LtCjMBPGWZBr3b7lTJ9aMHRoqyvTJDLeH3skgfYUhCEmNAQuPm7yHPOOqJ1IqHRvScn4tukCxkIhGB+vYhHa9/hUuy5aeEibRdMIw/klCCOs9mXp84s3h7CW29GXQv4LgzpWfg0z2YrzBacWO7tltrnUBF58d+3KdyZ038O8Kv36POac/K28AxF20QOWwnw5rXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aWAinjOq4s+a1Fbcq5IJHuCqiKXK6duIrVzsyNWAQ/I=; b=M0NikS4zkv5kBJYcrUWAj4I5fxwpbiRRU8bWotSXI35JKVD8sVEOrmc1B/Eb9X5fSi9/LOk7c13HWJSvuVzXN7/4OCyWp/dfY1CGFXGxFdInZ4C/Z1JQx+7CIFYOhbd88RPbjE8JiOLmkMaw2x8WhdtpvaEE19Pp3Nf4tJmSAQ/wtnSkdA/VsUFkA2wWYMaugD0+Mo+LHfPTJugdqiaqUF4FXcf6BnGNEroZvVWgu/HgjDCxgSvuvOJpf92lS1n/i8NdXlMH0Y/kLsQT6/vVZp8TTueMd1tDUzcFTQdiPVmzEeEsTbnh/Ik0ZIXVQe6OMLDfvPzdr+gxeBWxQkjkGw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=amperemail.onmicrosoft.com; dkim=pass header.d=amperemail.onmicrosoft.com; arc=none X-Received: from PH0PR01MB7287.prod.exchangelabs.com (2603:10b6:510:10a::21) by BL3PR01MB6946.prod.exchangelabs.com (2603:10b6:208:359::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.29; Wed, 16 Aug 2023 08:56:03 +0000 X-Received: from PH0PR01MB7287.prod.exchangelabs.com ([fe80::47db:e2da:2ade:2e19]) by PH0PR01MB7287.prod.exchangelabs.com ([fe80::47db:e2da:2ade:2e19%5]) with mapi id 15.20.6678.025; Wed, 16 Aug 2023 08:56:03 +0000 Message-ID: <0e0bc14c-88a1-21a8-0be7-34ed023e1127@amperemail.onmicrosoft.com> Date: Wed, 16 Aug 2023 15:55:52 +0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [edk2-devel] [PATCH v1 2/2] StandaloneMmPkg: Fix HOB space and heap space conflicted issue To: devel@edk2.groups.io, huangming@linux.alibaba.com, ardb@kernel.org CC: Sami Mujawar , Ard Biesheuvel , Jiewen Yao , Supreeth Venkatesh , ming.huang-@outlook.com References: <20220209122558.60329-1-huangming@linux.alibaba.com> <20220209122558.60329-3-huangming@linux.alibaba.com> <14f25a95-7153-4eec-8804-a3da768ccb11@linux.alibaba.com> From: "Nhi Pham via groups.io" In-Reply-To: <14f25a95-7153-4eec-8804-a3da768ccb11@linux.alibaba.com> X-ClientProxiedBy: SI1PR02CA0025.apcprd02.prod.outlook.com (2603:1096:4:1f4::13) To PH0PR01MB7287.prod.exchangelabs.com (2603:10b6:510:10a::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR01MB7287:EE_|BL3PR01MB6946:EE_ X-MS-Office365-Filtering-Correlation-Id: c84493f1-5a20-4165-972c-08db9e369e7d X-LD-Processed: 3bc2b170-fd94-476d-b0ce-4229bdc904a7,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: l0tXApSfFMjXLp53Cu33ZdjHEmTr9MIToKraxNgsvzHVAo9J29/waJlT2zQYVRGcIX0K4ULzjxOxUDBpf8IvBSfpsicuoHZEsa1L2bbkYUaUZa5sbT/gnannmfm3GS8m+2VlpV6QTYH5st7BpT7UGsAM/71ITeB6mEUY05uvq2YcsNR64P6NtvFuRdqaKI84Z0o58a8raQIiN9bRu6WV7aiVNrZA5DLuASItT91xuW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2NLTWw5ZEVGSjVpczVWR2VS?= =?utf-8?B?aVRpd01nOUxSZytZaXJwb3VsNllsb2h6SE1yVFhGcDh1WU5JdkpORVFlbTlw?= =?utf-8?B?S0dnSzJoMEFyM0FLKzdZZXh1S04wWlFYUjJLWU94ek93M3hPRGEzTEZHdXhl?= =?utf-8?B?bVFkcjB0SjhIYWpDSTBCR0lkaFdzY1c2aTdmOFEzaE9ZWGU5Sk9CR1VRRmlk?= =?utf-8?B?cHY4N1hFc1NvVVhFN2wvclRmTVBqU2xXV29xL0ZjL0orUkQ3cTRxUW5vU2JP?= =?utf-8?B?ODF3QnMram1ZSndkRVErZFpMeHEwenNmZy9yZ0ZENnVMK1psN1YzRDZ1MWVM?= =?utf-8?B?dWVqVDVtOGJzYlF2YktGRFhaeFNkWDZ2dXU5TkFBZmNkN21yaEJuK2RGb2xT?= =?utf-8?B?WmY3QUZrV3l0V2dCV2hMM1pnenY3TnV0Q1N0WG9FNThEU3BQRHpadWxFSE9u?= =?utf-8?B?UFRlb0tPYVo3VitaNHByK3VHUXNiQ0hXNEpIenRUODVjYlArRFdyQitPenll?= =?utf-8?B?bXdWUTJzM2RYbmt2Z2ttOGw1UEtCWkJJNDBROG02TGpyb3R0TU03YkFtNSth?= =?utf-8?B?aVZHeGk5MzZJMmpQbURmRytkQTVPRWppakZ1RVNsSVovb3FHc1F5bHBBRFBO?= =?utf-8?B?NDdUQkJscGxHZk5BaUdnSnFjR3BGNkw0VmowaWpDcmdhVGJOTHpNcEhOdWI5?= =?utf-8?B?a3pkOTRQUDNORUd4Y0VLajZsMGdWRzZZVU1mRFB1andHYU55ankxa1hnZVNK?= =?utf-8?Q?CV0QytCXkxe0kx3wKdejLcM=3D?= X-OriginatorOrg: amperemail.onmicrosoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: c84493f1-5a20-4165-972c-08db9e369e7d X-MS-Exchange-CrossTenant-AuthSource: PH0PR01MB7287.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2023 08:56:02.9958 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UMf8sOZA+JzsLToLF1pHylZPuLtxBdsDKblxCYuxHiPijCCrkexPyIGOACmezNezI6lO5ZnYvTgiT1p4tVQrasOkU7b1r+7LtcCWgkM7WXs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR01MB6946 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,nhi@os.amperecomputing.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 1cs6hHgxTEZpqYpkAzKzfKIZx7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=IutZSYVU; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}"); dmarc=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 Hi Ard and Ming, I have been seeing an issue with StandaloneMM HobLib that can be fixed=20 by this patch as well. The function CreateHob() in the HobLib instance=20 StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.inf= =20 does not work at all. The HobList is early created by the=20 StandaloneMmCoreEntryPoint then it is relocated on the heap memory by=20 StandaloneMmCore. But the FreeMemoryTop and FreeMemoryBottom are not=20 updated accordingly and the HOB free memory top is overlapped with the=20 heap space. This causes the CreateHob() function to not work as=20 expected. Introducing the PcdMemoryHobSize is reasonable to fix this issue. I tested this patch in my end. Tested-by: Nhi Pham Thanks, -Nhi On 5/12/2022 5:09 PM, Ming Huang via groups.io wrote: > > =E5=9C=A8 5/3/22 5:10 PM, Ard Biesheuvel =E5=86=99=E9=81=93: >> On Wed, 9 Feb 2022 at 13:26, Ming Huang wr= ote: >>> The heap space will be rewrote if a StandloneMmPkg module create HOB >>> by BuildGuidHob() interface and write data to HOB space. >> Can you elaborate? What is supposed to happen and why, and what is >> happening instead? > I tried my best to explain the issue: > > -----------------------------<--HandOffHob->EfiFreeMemoryTop > | | > | | > | | > | | > | | > | | > | mMmMemoryMap | > |---------------------------|<--HandOffHob->EfiFreeMemoryBottom > | HobEnd | > |---------------------------|<--HandOffHob->EfiEndOfHobList > | | > | Hob #1 | > -----------------------------<--MmHobStart > 1 The mMmMemoryMap which use for free page is on above the HobEnd. > 2 Create a hob by BuildGuidHob(), the HobEnd will move up and cover > the structure or list using by free page. > > After this patch, there is a pre-allocation space for creating hob. > > -----------------------------<--HandOffHob->EfiFreeMemoryTop > | | > | | > | | > | | > | mMmMemoryMap | > |---------------------------|<--HandOffHob->EfiFreeMemoryBottom > | Hob free space | by PcdMemoryHobSize > |---------------------------| > | HobEnd | > |---------------------------|<--HandOffHob->EfiEndOfHobList > | | > | Hob #1 | > -----------------------------<--MmHobStart > >>> Add a PCD PcdMemoryHobSize for pre-allocation a space to create HOB to >>> fix this issue. >>> >>> Signed-off-by: Ming Huang >>> --- >>> StandaloneMmPkg/Core/StandaloneMmCore.c | 17 ++++++++++++++++- >>> StandaloneMmPkg/Core/StandaloneMmCore.inf | 3 +++ >>> StandaloneMmPkg/StandaloneMmPkg.dec | 2 ++ >>> 3 files changed, 21 insertions(+), 1 deletion(-) >>> >>> diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.c b/StandaloneMmPkg/= Core/StandaloneMmCore.c >>> index d221f1d111..1cf259d946 100644 >>> --- a/StandaloneMmPkg/Core/StandaloneMmCore.c >>> +++ b/StandaloneMmPkg/Core/StandaloneMmCore.c >>> @@ -512,6 +512,9 @@ StandaloneMmMain ( >>> EFI_MMRAM_DESCRIPTOR *MmramRanges; >>> UINTN MmramRangeCount; >>> EFI_HOB_FIRMWARE_VOLUME *BfvHob; >>> + EFI_HOB_HANDOFF_INFO_TABLE *HandOffHobNew; >>> + EFI_HOB_HANDOFF_INFO_TABLE *HandOffHobOrg; >>> + UINT64 MaxHobSize =3D PcdGet64 (PcdMemoryHo= bSize); >>> >>> ProcessLibraryConstructorList (HobStart, &gMmCoreMmst); >>> >>> @@ -619,10 +622,22 @@ StandaloneMmMain ( >>> // >>> HobSize =3D GetHobListSize (HobStart); >>> DEBUG ((DEBUG_INFO, "HobSize - 0x%x\n", HobSize)); >>> - MmHobStart =3D AllocatePool (HobSize); >>> + ASSERT (HobSize <=3D MaxHobSize); >>> + MmHobStart =3D AllocatePool (MaxHobSize); >>> DEBUG ((DEBUG_INFO, "MmHobStart - 0x%x\n", MmHobStart)); >>> ASSERT (MmHobStart !=3D NULL); >>> CopyMem (MmHobStart, HobStart, HobSize); >>> + // >>> + // Initlialize the new HOB table >>> + // >>> + HandOffHobOrg =3D (EFI_HOB_HANDOFF_INFO_TABLE *)HobStart; >>> + HandOffHobNew =3D (EFI_HOB_HANDOFF_INFO_TABLE *)MmHobStart; >>> + HandOffHobNew->EfiEndOfHobList =3D (EFI_PHYSICAL_ADDRESS)MmHobStart = + >>> + (HandOffHobOrg->EfiEndOfHobList - (EFI_PHYSICAL_ADDRESS)HobStart); >>> + HandOffHobNew->EfiFreeMemoryBottom =3D HandOffHobNew->EfiEndOfHobLis= t + >>> + sizeof (EFI_HOB_GENERIC_HEADER)= ; >>> + HandOffHobNew->EfiFreeMemoryTop =3D (EFI_PHYSICAL_ADDRESS)MmHobStart= + MaxHobSize; >>> + >>> Status =3D MmInstallConfigurationTable (&gMmCoreMmst, &gEfiHobListG= uid, MmHobStart, HobSize); >>> ASSERT_EFI_ERROR (Status); >>> >>> diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.inf b/StandaloneMmPk= g/Core/StandaloneMmCore.inf >>> index c44b9ff333..37e6135d73 100644 >>> --- a/StandaloneMmPkg/Core/StandaloneMmCore.inf >>> +++ b/StandaloneMmPkg/Core/StandaloneMmCore.inf >>> @@ -76,6 +76,9 @@ >>> gEfiEventExitBootServicesGuid >>> gEfiEventReadyToBootGuid >>> >>> +[FixedPcd] >>> + gStandaloneMmPkgTokenSpaceGuid.PcdMemoryHobSize >>> + >>> # >>> # This configuration fails for CLANGPDB, which does not support PIE i= n the GCC >>> # sense. Such however is required for ARM family StandaloneMmCore >>> diff --git a/StandaloneMmPkg/StandaloneMmPkg.dec b/StandaloneMmPkg/Stan= daloneMmPkg.dec >>> index 46784d94e4..cf554676e2 100644 >>> --- a/StandaloneMmPkg/StandaloneMmPkg.dec >>> +++ b/StandaloneMmPkg/StandaloneMmPkg.dec >>> @@ -48,3 +48,5 @@ >>> gEfiStandaloneMmNonSecureBufferGuid =3D { 0xf00497e3, 0xbfa2, = 0x41a1, { 0x9d, 0x29, 0x54, 0xc2, 0xe9, 0x37, 0x21, 0xc5 }} >>> gEfiArmTfCpuDriverEpDescriptorGuid =3D { 0x6ecbd5a1, 0xc0f8, = 0x4702, { 0x83, 0x01, 0x4f, 0xc2, 0xc5, 0x47, 0x0a, 0x51 }} >>> >>> +[PcdsFixedAtBuild] >>> + gStandaloneMmPkgTokenSpaceGuid.PcdMemoryHobSize|0x00000000|UINT64|0x= 00000004 >>> -- >>> 2.17.1 >>> >> >> >> > >=20 > > -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107793): https://edk2.groups.io/g/devel/message/107793 Mute This Topic: https://groups.io/mt/89020085/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-