From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web10.8864.1651569048689224031 for ; Tue, 03 May 2022 02:10:49 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Wkkw2YQj; spf=pass (domain: kernel.org, ip: 145.40.68.75, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 33313B81A96 for ; Tue, 3 May 2022 09:10:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE969C385A9 for ; Tue, 3 May 2022 09:10:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651569045; bh=z/jWrVjgNG1hlMluyEFmkToRm52HfIwiXSWpDnJFC88=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Wkkw2YQj9GTEh2LzXGRQnE+P1X8oSHzOpsm4lPzaoCZHY4MYU+x9IdjD5fpmH4y8g 9+j0FVRhSt5uv/SAKgV4sewHGnQYiFaIK8MasLcK0H7GCib2v7+Mxd9SvpAtaIBtAK LxRomtHbAoGFoM2vHyppyWVSkLtt8wfDlAun9W7GUlSZvMALXYvkgRRaeEAFGywLkK np7+hN5eldZFkpa3QClvu8F9fi8a7EWn/SU6O/sHx3/H2G46fAGkFrmFeX8thP8aQO KNzmhUffq1GlEIxPrHsck2ldhKE3mDtR+0vehR1NUmOVpwwbsOpRp2ET+/RzeML9x7 YPX6+5RASkw8Q== Received: by mail-oo1-f46.google.com with SMTP id y22-20020a4acb96000000b0035eb01f5b65so2239421ooq.5 for ; Tue, 03 May 2022 02:10:44 -0700 (PDT) X-Gm-Message-State: AOAM532zB5eRNLGUsTBhaTevDVW+l3OxlvyeTvBjCP0s8qECTkuedxc/ J15tFW19XJgPp42Aity0ctRQjI1fyqSOQ2+2Kwc= X-Google-Smtp-Source: ABdhPJxfN2/HsFS8Kg3Pjs2qJ+PWbfwnw2+lpDhrPoXiPdesmFrgVxswXdy+YVI3IZYXxiAIRQDrXSlW2uFnVVYonSs= X-Received: by 2002:a4a:314f:0:b0:35e:9802:1ce5 with SMTP id v15-20020a4a314f000000b0035e98021ce5mr5348960oog.60.1651569044008; Tue, 03 May 2022 02:10:44 -0700 (PDT) MIME-Version: 1.0 References: <20220209122558.60329-1-huangming@linux.alibaba.com> <20220209122558.60329-3-huangming@linux.alibaba.com> In-Reply-To: <20220209122558.60329-3-huangming@linux.alibaba.com> From: "Ard Biesheuvel" Date: Tue, 3 May 2022 11:10:32 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v1 2/2] StandaloneMmPkg: Fix HOB space and heap space conflicted issue To: Ming Huang Cc: edk2-devel-groups-io , Sami Mujawar , Ard Biesheuvel , Jiewen Yao , Supreeth Venkatesh , ming.huang-@outlook.com Content-Type: text/plain; charset="UTF-8" On Wed, 9 Feb 2022 at 13:26, Ming Huang wrote: > > 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? > 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 = PcdGet64 (PcdMemoryHobSize); > > ProcessLibraryConstructorList (HobStart, &gMmCoreMmst); > > @@ -619,10 +622,22 @@ StandaloneMmMain ( > // > HobSize = GetHobListSize (HobStart); > DEBUG ((DEBUG_INFO, "HobSize - 0x%x\n", HobSize)); > - MmHobStart = AllocatePool (HobSize); > + ASSERT (HobSize <= MaxHobSize); > + MmHobStart = AllocatePool (MaxHobSize); > DEBUG ((DEBUG_INFO, "MmHobStart - 0x%x\n", MmHobStart)); > ASSERT (MmHobStart != NULL); > CopyMem (MmHobStart, HobStart, HobSize); > + // > + // Initlialize the new HOB table > + // > + HandOffHobOrg = (EFI_HOB_HANDOFF_INFO_TABLE *)HobStart; > + HandOffHobNew = (EFI_HOB_HANDOFF_INFO_TABLE *)MmHobStart; > + HandOffHobNew->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS)MmHobStart + > + (HandOffHobOrg->EfiEndOfHobList - (EFI_PHYSICAL_ADDRESS)HobStart); > + HandOffHobNew->EfiFreeMemoryBottom = HandOffHobNew->EfiEndOfHobList + > + sizeof (EFI_HOB_GENERIC_HEADER); > + HandOffHobNew->EfiFreeMemoryTop = (EFI_PHYSICAL_ADDRESS)MmHobStart + MaxHobSize; > + > Status = MmInstallConfigurationTable (&gMmCoreMmst, &gEfiHobListGuid, MmHobStart, HobSize); > ASSERT_EFI_ERROR (Status); > > diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.inf b/StandaloneMmPkg/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 in the GCC > # sense. Such however is required for ARM family StandaloneMmCore > diff --git a/StandaloneMmPkg/StandaloneMmPkg.dec b/StandaloneMmPkg/StandaloneMmPkg.dec > index 46784d94e4..cf554676e2 100644 > --- a/StandaloneMmPkg/StandaloneMmPkg.dec > +++ b/StandaloneMmPkg/StandaloneMmPkg.dec > @@ -48,3 +48,5 @@ > gEfiStandaloneMmNonSecureBufferGuid = { 0xf00497e3, 0xbfa2, 0x41a1, { 0x9d, 0x29, 0x54, 0xc2, 0xe9, 0x37, 0x21, 0xc5 }} > gEfiArmTfCpuDriverEpDescriptorGuid = { 0x6ecbd5a1, 0xc0f8, 0x4702, { 0x83, 0x01, 0x4f, 0xc2, 0xc5, 0x47, 0x0a, 0x51 }} > > +[PcdsFixedAtBuild] > + gStandaloneMmPkgTokenSpaceGuid.PcdMemoryHobSize|0x00000000|UINT64|0x00000004 > -- > 2.17.1 >