From nobody Sun May 5 22:20:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+61039+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61039+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1591777072; cv=none; d=zohomail.com; s=zohoarc; b=d+fud/YXs9o3qSGqmlKu70G8JR6Z3lwlLrQOiUN1aUPrSNgBtsAf8xRvTzmripHd8jrsRCHrYQjtGe7fk/ucjxKY29t02HpdglkuN4u+QXJWlYtINXyeX0rqltme0aVyL0+wsdokKTWy3O1mghACkovfyVCodfAl+t9TfgAk7O8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591777072; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=IsAwvLEEZMfSrlCe8SPtz/TsAezC61lNbyGj0ykxx2E=; b=mHsIGPGfejrYWNalxA+S0b5/Wnx+wJV7/OXYuOoaVw9Un9nnoZ/mAYdLLrDdnNnx+M8XLtr+/uhcmUBXG2c2fkMsua6TqUcprhrgaLS+dsA+ubHEGb+7Xkm7RgVqkbpk1x9PnLXwNUrRdJOkCX4Q2l4YMCNHYsVYSYZEdMZof6k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61039+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1591777072849791.5123334988925; Wed, 10 Jun 2020 01:17:52 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id aOqxYY1788612xYKce9cIGie; Wed, 10 Jun 2020 01:17:52 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.6037.1591777071280815162 for ; Wed, 10 Jun 2020 01:17:51 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D195C31B; Wed, 10 Jun 2020 01:17:50 -0700 (PDT) X-Received: from localhost.localdomain (unknown [10.37.8.184]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3F5A73F6CF; Wed, 10 Jun 2020 01:17:49 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Michael D Kinney , Liming Gao , Jiewen Yao , Sami Mujawar , Ilias Apalodimas Subject: [edk2-devel] [PATCH 1/5] MdePkg/BasePrintLib: avoid absolute addresses for error strings Date: Wed, 10 Jun 2020 10:17:36 +0200 Message-Id: <20200610081740.54581-2-ard.biesheuvel@arm.com> In-Reply-To: <20200610081740.54581-1-ard.biesheuvel@arm.com> References: <20200610081740.54581-1-ard.biesheuvel@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ard.biesheuvel@arm.com X-Gm-Message-State: yLGadosLfQpPdmFJXpCPJAEex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1591777072; bh=XlOdwPesJKBlMfp7NyfR2baHxDsPoR5yH5EMyw9lWfI=; h=Cc:Date:From:Reply-To:Subject:To; b=xZ5fAEQFKdfGaT8Paqb8lEECAlTsA5qsdLQOrtliThRzFpk/l1b8v3J8oMd07G9mATT 3VNytCtfmplHUbKN3e4K7hnErXP3vkd9r3gOcwPyXrxJVZ4tvzROZBRNXFZNIj6BKJ7+S QwDGdfDk3cj8/RyTlhEz2AXb52HUqfWLkiY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The mStatusString[] is constructed as an array of pointer-to-char, which means that on X64 or AARCH64, it is emitted as a single linear list of 64-bit quantities, each containing the absolute address of one of the string literals in memory. This means that each string takes up 8 bytes of additional space, along with 2 bytes of relocation data. It also means that the array cannot be used until PE/COFF relocation has completed, and so the following invocation Status =3D PeCoffLoaderRelocateImage (&ImageContext); ASSERT_EFI_ERROR (Status); that we will be introducing into StandaloneMmCore entrypoint for AARCH64 to relocate the executable on the fly is guaranteed to return bogus output or crash, which is less than helpful. So fix both issues, by emitting mStatusString as an array of char arrays instead. The memory footprint increases from 955 to 975 bytes, but given that in the latter case, the overhead consists of 410 NUL characters rather than 390 bytes worth of absolute addresses and relocation records, the impact on a compressed image is actually positive. For example, when building ArmVirtQemu.dsc in RELEASE mode for AARCH64 with the GCC5 profile, I get: Before FV Space Information FVMAIN [99%Full] 4784768 total, 4784720 used, 48 free FVMAIN_COMPACT [38%Full] 2093056 total, 811560 used, 1281496 free After FV Space Information FVMAIN [99%Full] 4780672 total, 4780624 used, 48 free FVMAIN_COMPACT [38%Full] 2093056 total, 813488 used, 1279568 free So the compressed image is 4 KB smaller, whereas the entire image is < 2 KB larger, which is in the order of 0.2 % Signed-off-by: Ard Biesheuvel Tested-by: Ilias Apalodimas --- MdePkg/Library/BasePrintLib/PrintLibInternal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.c b/MdePkg/Librar= y/BasePrintLib/PrintLibInternal.c index b6ec5ac4fbb9..c8b932c7e07a 100644 --- a/MdePkg/Library/BasePrintLib/PrintLibInternal.c +++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.c @@ -27,7 +27,7 @@ =20 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexStr[] =3D {'0','1','2','3','= 4','5','6','7','8','9','A','B','C','D','E','F'}; =20 -GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 * CONST mStatusString[] =3D { +GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mStatusString[][25] =3D { "Success", // RETURN_SUCCESS =3D 0 "Warning Unknown Glyph", // RETURN_WARN_UNKNOWN_GLYPH =3D 1 "Warning Delete Failure", // RETURN_WARN_DELETE_FAILURE =3D 2 --=20 2.26.2 -=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 (#61039): https://edk2.groups.io/g/devel/message/61039 Mute This Topic: https://groups.io/mt/74792288/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 5 22:20:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+61040+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61040+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1591777076; cv=none; d=zohomail.com; s=zohoarc; b=eNrxouivrGbez1ZHfAvEto8DgeDA+LmZrCMDDHQf7CjS05kwSzZbLn2xsM/3ZnqPtTktC1b82AwBQaXSxofVSuBk23iI/xcqAZeSNTtSzrsSt+vwYHBle/jc4jdhbKfogi8Hot7j0sABwC+f6y/0dRgMa+ZVEY94K/dPsH5Czwo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591777076; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=AIvT/PYY9HcxKQrms+IOrNZTl3nnDYns/vVgov5+Cng=; b=RuJ+ZlNS118m8bkmnfutMv7zYQMER8LYc2G96eJENM2ycq5UKWh8SbxZMW8gRN6RjWZbr/Oyxd3lOog9U5Awz2kMtrtTmQKOv4d/csL2p18EMlhNbsYkVW1tOX1zPD1PhAdUbhbCkFKbjIZYw4C9nPlOQm66fHfGuyjx7eYxAxM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61040+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1591777076750619.2374508457632; Wed, 10 Jun 2020 01:17:56 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id VC5UYY1788612xGND0PcIQbm; Wed, 10 Jun 2020 01:17:54 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.6174.1591777073791619059 for ; Wed, 10 Jun 2020 01:17:53 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C72751F1; Wed, 10 Jun 2020 01:17:52 -0700 (PDT) X-Received: from localhost.localdomain (unknown [10.37.8.184]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 332183F6CF; Wed, 10 Jun 2020 01:17:51 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Michael D Kinney , Liming Gao , Jiewen Yao , Sami Mujawar , Ilias Apalodimas Subject: [edk2-devel] [PATCH 2/5] StandaloneMmPkg/Core: fix bogus FV pointer in DEBUG string Date: Wed, 10 Jun 2020 10:17:37 +0200 Message-Id: <20200610081740.54581-3-ard.biesheuvel@arm.com> In-Reply-To: <20200610081740.54581-1-ard.biesheuvel@arm.com> References: <20200610081740.54581-1-ard.biesheuvel@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ard.biesheuvel@arm.com X-Gm-Message-State: hz0TsCL6abjQ5CYNOUBqDc7Ex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1591777074; bh=C8Nn/P/CZq+tRsxg7GfQQM2My2J6jceV0pM1W5qQXqE=; h=Cc:Date:From:Reply-To:Subject:To; b=ipO7xkqBdyqQgQb7C953IjaaHbTZZHc+Y0s6FzCBP6YgqyKRTHHWD18T2+ymze1UCIR hI8EsEzmHWo6BS83umHgchf80qHmWn37yusEj8aeIiHPXgdF803qLfuvrm77FEHT7CYa1 lq+rKYiBq8lBll7PZ6LoqBvwvP+Q+KcLtto= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" FvIsBeingProcessed () emits a DEBUG print with the intent to print the memory address of the FV that is being processed, but instead, it prints the contents of an uninitialized stack variable. Signed-off-by: Ard Biesheuvel Reviewed-by: Jiewen Yao Reviewed-by: Sami Mujawar Tested-by: Ilias Apalodimas --- StandaloneMmPkg/Core/Dispatcher.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StandaloneMmPkg/Core/Dispatcher.c b/StandaloneMmPkg/Core/Dispa= tcher.c index 2f795d01dc1f..c99e6c04c8de 100644 --- a/StandaloneMmPkg/Core/Dispatcher.c +++ b/StandaloneMmPkg/Core/Dispatcher.c @@ -816,7 +816,7 @@ FvIsBeingProcessed ( { KNOWN_FWVOL *KnownFwVol; =20 - DEBUG ((DEBUG_INFO, "FvIsBeingProcessed - 0x%08x\n", KnownFwVol)); + DEBUG ((DEBUG_INFO, "FvIsBeingProcessed - 0x%08x\n", FwVolHeader)); =20 KnownFwVol =3D AllocatePool (sizeof (KNOWN_FWVOL)); ASSERT (KnownFwVol !=3D NULL); --=20 2.26.2 -=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 (#61040): https://edk2.groups.io/g/devel/message/61040 Mute This Topic: https://groups.io/mt/74792289/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 5 22:20:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+61041+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61041+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1591777077; cv=none; d=zohomail.com; s=zohoarc; b=EZiN3DiAlNOJiLGYvhJXnYeBA6jTm/4Hib19R3ZqBrcaWRo9TdObLIa8dPX18iEQgxHxTOs11SG4uDI679PmTcyWnRdo7vmJJa1xzM8FrOAhMp4qL8WcfD6YsE8wMGQ1+xbPBSqBnPfsru4JRP0tkOYnxdrF1MPGKAkJRfLbo58= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591777077; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=X3buvI+N62XmyDcGxu6W6GeBBYBLJa/7kk9OcMcGSPo=; b=J70n2JVQjNfkDE+Ne3Tm8QH0rWqPltpSKu3tNGthvw2k4Ywu2vjnEYP/amJjA2Fa+r1vKgcmnEq4LSt1mFjBynmrYw5LX5hp771Lx0aXynwtb79U1SYSGMwtRMEO3QBi9PZ7GrasMaQAsu5OD8E8pRX0CukeH6Likj+JEp7SkaY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61041+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1591777077033129.49940069913225; Wed, 10 Jun 2020 01:17:57 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id LAaKYY1788612xf3JInZCY6q; Wed, 10 Jun 2020 01:17:55 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.6040.1591777075183025162 for ; Wed, 10 Jun 2020 01:17:55 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BD1C31045; Wed, 10 Jun 2020 01:17:54 -0700 (PDT) X-Received: from localhost.localdomain (unknown [10.37.8.184]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 281283F6CF; Wed, 10 Jun 2020 01:17:52 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Michael D Kinney , Liming Gao , Jiewen Yao , Sami Mujawar , Ilias Apalodimas Subject: [edk2-devel] [PATCH 3/5] StandaloneMmPkg/Core: add missing GUID reference Date: Wed, 10 Jun 2020 10:17:38 +0200 Message-Id: <20200610081740.54581-4-ard.biesheuvel@arm.com> In-Reply-To: <20200610081740.54581-1-ard.biesheuvel@arm.com> References: <20200610081740.54581-1-ard.biesheuvel@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ard.biesheuvel@arm.com X-Gm-Message-State: xPfw8S0FIhYGi7UicIqoaMgcx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1591777075; bh=XlYIGzFRXucsULVdI7sMoz0p1glmVN+TOffAcVelbJI=; h=Cc:Date:From:Reply-To:Subject:To; b=NgwNyjS6H4f2OS0/+Ih6qXCCmPqNZhCxJ4Wa22rWoSBpXDW/1kepydenHdEnrII1jO3 oXmZfgtWfVEBornRgKSp7TdP0gU5oTyN+fGkwwJJCchCbftFICbapoSvJdbjGUOCXjLc2 ProPxe83J9e0Cqcbvzq2L1hjv3/Y1e64rjQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The Standalone core uses gEfiHobMemoryAllocModuleGuid, but failed to declare this in its INF. Signed-off-by: Ard Biesheuvel Reviewed-by: Jiewen Yao Reviewed-by: Sami Mujawar Tested-by: Ilias Apalodimas --- StandaloneMmPkg/Core/StandaloneMmCore.inf | 1 + 1 file changed, 1 insertion(+) diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.inf b/StandaloneMmPkg/Co= re/StandaloneMmCore.inf index 7d590b49bd3f..d17ff9965bdc 100644 --- a/StandaloneMmPkg/Core/StandaloneMmCore.inf +++ b/StandaloneMmPkg/Core/StandaloneMmCore.inf @@ -69,6 +69,7 @@ [Guids] gEdkiiMemoryProfileGuid gZeroGuid ## SOMETIMES_CONSUMES ##= GUID gEfiHobListGuid + gEfiHobMemoryAllocModuleGuid gMmCoreDataHobGuid gMmFvDispatchGuid gEfiEventLegacyBootGuid --=20 2.26.2 -=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 (#61041): https://edk2.groups.io/g/devel/message/61041 Mute This Topic: https://groups.io/mt/74792290/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 5 22:20:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+61042+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61042+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1591777078; cv=none; d=zohomail.com; s=zohoarc; b=TGHDxZmDVbgOygM5vHVT8b4UzbGwKjAXFh4Rpid6fbG3zZREiLYFYJoBqbNyBzkGPqXJrFDcyQUiYmeIzYPj6FYtRU/7IqdegwlA3ua9nYlBh3eufRxLG0KM3Lksl/011zYa8qU+Gcb1fnj+1Dk2ucFsMw6qvn3mo+cE/Pgn+9c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591777078; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=3tVbVHdPfBzy0inUlnXfRq3MWzFA3/YBRdI4fYpRVug=; b=QSxmqF/mDBzjLvnzo9jY0NRxhw1mHBCoGB3Bp4Neyiud9p5Zq9yscdN2qLzMX52VdUWGAxczokLGGqexZHop3clwpMocf0CkE1Odm4AXwQYOWDORPAj7wm4XtlFwl1zQYPsl96iGketQXS62FzPnV6nCHI37W19Ua7Lq3QQK/dU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61042+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1591777078082475.7297014790994; Wed, 10 Jun 2020 01:17:58 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id p6eJYY1788612xnShqRFDecy; Wed, 10 Jun 2020 01:17:57 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.6158.1591777077029646352 for ; Wed, 10 Jun 2020 01:17:57 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B10EC1F1; Wed, 10 Jun 2020 01:17:56 -0700 (PDT) X-Received: from localhost.localdomain (unknown [10.37.8.184]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1D8AC3F6CF; Wed, 10 Jun 2020 01:17:54 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Michael D Kinney , Liming Gao , Jiewen Yao , Sami Mujawar , Ilias Apalodimas Subject: [edk2-devel] [PATCH 4/5] StandaloneMmPkg: generate position independent code for StMM core Date: Wed, 10 Jun 2020 10:17:39 +0200 Message-Id: <20200610081740.54581-5-ard.biesheuvel@arm.com> In-Reply-To: <20200610081740.54581-1-ard.biesheuvel@arm.com> References: <20200610081740.54581-1-ard.biesheuvel@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ard.biesheuvel@arm.com X-Gm-Message-State: PZqdFqxNF6Ab537wMcMdDCXbx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1591777077; bh=hl32pT37hDbcPkAiaQ31nDHGh7uM5MY/YH0CBs2GnuE=; h=Cc:Date:From:Reply-To:Subject:To; b=r6q58wy8xRGJs67Rq8GukIPVc24CHNOkLgkVRjBTiFqoefvRgg0TWNc5nSkjqA0EaYh dGgMf9taIHfUha7FMyWyfqv7yElH1ZtIYtkDUPXbKZ2Z3eY5Qi2nv2TfJzoq8Y8CMjPS5 9Evu82ZwHSyKCnklfVYcelnEE6CN65SKQqM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The standalone MM core runs in a restricted environment that is set up by a higher privilege level, and which may not allow memory regions to be writable and executable at the same time. This means that making the StMM core self-relocatable requires that all the targets of the relocation fixups are outside of the executable region of the image, given that we cannot remap the executable code writable from the executable code itself without losing those execute permissions. So instead, use the existing toolchain support to ensure that position independent code is used where possible, and that all the remaining relocated quantities are emitted into the data section. (Note that staticallly initialized const pointers will be emitted into the .data.rel.ro section, which gets pulled into the .data section by our linker script) To ensure that we don't pick up any absolute references in executable code inadvertently (e.g., in assembler code), add the '-z text' linker option which will force the build to fail in this case. Signed-off-by: Ard Biesheuvel Acked-by: Jiewen Yao Tested-by: Ilias Apalodimas --- StandaloneMmPkg/Core/StandaloneMmCore.inf = | 4 ++++ StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPo= int.inf | 3 +++ 2 files changed, 7 insertions(+) diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.inf b/StandaloneMmPkg/Co= re/StandaloneMmCore.inf index d17ff9965bdc..87bf6e9440a7 100644 --- a/StandaloneMmPkg/Core/StandaloneMmCore.inf +++ b/StandaloneMmPkg/Core/StandaloneMmCore.inf @@ -75,3 +75,7 @@ [Guids] gEfiEventLegacyBootGuid gEfiEventExitBootServicesGuid gEfiEventReadyToBootGuid + +[BuildOptions] + GCC:*_*_*_CC_FLAGS =3D -fpie + GCC:*_*_*_DLINK_FLAGS =3D -Wl,-z,text,-Bsymbolic,-pie diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneM= mCoreEntryPoint.inf b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/St= andaloneMmCoreEntryPoint.inf index 891c292e92f8..7d6ee4e08ecb 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEn= tryPoint.inf +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEn= tryPoint.inf @@ -48,3 +48,6 @@ [Guids] gEfiMmPeiMmramMemoryReserveGuid gEfiStandaloneMmNonSecureBufferGuid gEfiArmTfCpuDriverEpDescriptorGuid + +[BuildOptions] + GCC:*_*_*_CC_FLAGS =3D -fpie --=20 2.26.2 -=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 (#61042): https://edk2.groups.io/g/devel/message/61042 Mute This Topic: https://groups.io/mt/74792291/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 5 22:20:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+61043+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61043+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1591777079; cv=none; d=zohomail.com; s=zohoarc; b=fSEo7FdtmfCforEZenL2c1eeBb5z/5TLRJR/fpWhf4cjj9aKh5k7Bfj+/EPfb+YqKTwiegsu2OwDnQVtxDgOBUCwl7Xf/9M74P3sV+06YVNTM+d2xh+uxN0p63d+tt4Lu8eggM6sOKbVUHlNHV8iKC+2Rs2cV5W83j/5M7t88iY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591777079; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ZytpzQk1O+TptUu8GV/DfEUIhCAcaR4vPkn+F5dtKa0=; b=aN5EwRijVrII8jtuVUDpX5XJMA0UigPDVH0/HIUYWDCTKX7oqr3HyJ2SPIgE9hdsp9H15+4eScelymVQQcv5qRQVn2C8WgOMya0HDTd1cB6Om4VJ9iEKTY6iUYhP7JiDN4ueDgATlOvJ895PTzfNtD3Vu8S1ft52/0nX7SuVug0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61043+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1591777079902794.0634736938747; Wed, 10 Jun 2020 01:17:59 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id P5qjYY1788612xybuQ39rQI4; Wed, 10 Jun 2020 01:17:59 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.6159.1591777078941542949 for ; Wed, 10 Jun 2020 01:17:59 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9C90931B; Wed, 10 Jun 2020 01:17:58 -0700 (PDT) X-Received: from localhost.localdomain (unknown [10.37.8.184]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 116533F6CF; Wed, 10 Jun 2020 01:17:56 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Michael D Kinney , Liming Gao , Jiewen Yao , Sami Mujawar , Ilias Apalodimas Subject: [edk2-devel] [PATCH 5/5] StandaloneMmPkg/StandaloneMmCoreEntryPoint: relocate StMM core on the fly Date: Wed, 10 Jun 2020 10:17:40 +0200 Message-Id: <20200610081740.54581-6-ard.biesheuvel@arm.com> In-Reply-To: <20200610081740.54581-1-ard.biesheuvel@arm.com> References: <20200610081740.54581-1-ard.biesheuvel@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ard.biesheuvel@arm.com X-Gm-Message-State: gGVAYmO2s6JCHfMMCGgdsuzax1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1591777079; bh=po9XjGAs/iJdon+lBA2/0dQxTTFfpxkkG25omhQ9DEE=; h=Cc:Date:From:Reply-To:Subject:To; b=BL27qAdVo8EG4hLOaa2b8wHxz2FJHGt4eJ3/ttSCnbIRJQyJj+whZDl3LKTB1gB67i2 5ZIaGpc97mEWFLZdkKnGwfwn8PSAqlOO8nySwTHqSHYj3XMdqFEQKIdR/MWiN9fnH37us kayheNnndGtjkWomL7vmcNRaKuhK8UlW/Fg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Apply PE/COFF fixups when starting up the standalone MM core, so that it can execute at any address regardless of the link time address. Note that this requires the PE/COFF image to be emitted with its relocation section preserved. Special care is taken to ensure that TE images are dealt with correctly as well. Signed-off-by: Ard Biesheuvel Acked-by: Jiewen Yao Reviewed-by: Sami Mujawar Tested-by: Ilias Apalodimas --- StandaloneMmPkg/Include/Library/AArch64/StandaloneMmCoreEntryPoint.h = | 2 ++ StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/SetPermissions.= c | 11 +++++++--- StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCor= eEntryPoint.c | 22 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/StandaloneMmPkg/Include/Library/AArch64/StandaloneMmCoreEntryP= oint.h b/StandaloneMmPkg/Include/Library/AArch64/StandaloneMmCoreEntryPoint= .h index 494bcf3dc28f..a3420699e6f1 100644 --- a/StandaloneMmPkg/Include/Library/AArch64/StandaloneMmCoreEntryPoint.h +++ b/StandaloneMmPkg/Include/Library/AArch64/StandaloneMmCoreEntryPoint.h @@ -82,6 +82,7 @@ EFI_STATUS EFIAPI UpdateMmFoundationPeCoffPermissions ( IN CONST PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, + IN EFI_PHYSICAL_ADDRESS ImageBase, IN UINT32 SectionHeaderOffset, IN CONST UINT16 NumberOfSections, IN REGION_PERMISSION_UPDATE_FUNC TextUpdater, @@ -107,6 +108,7 @@ EFIAPI GetStandaloneMmCorePeCoffSections ( IN VOID *TeData, IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, + OUT EFI_PHYSICAL_ADDRESS *ImageBase, IN OUT UINT32 *SectionHeaderOffset, IN OUT UINT16 *NumberOfSections ); diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/Set= Permissions.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/= SetPermissions.c index 00f49c9d0558..bf9650d54629 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/SetPermiss= ions.c +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/SetPermiss= ions.c @@ -29,6 +29,7 @@ EFI_STATUS EFIAPI UpdateMmFoundationPeCoffPermissions ( IN CONST PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, + IN EFI_PHYSICAL_ADDRESS ImageBase, IN UINT32 SectionHeaderOffset, IN CONST UINT16 NumberOfSections, IN REGION_PERMISSION_UPDATE_FUNC TextUpdater, @@ -87,7 +88,7 @@ UpdateMmFoundationPeCoffPermissions ( // if it is a writeable section then mark it appropriately as well. // if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_MEM_EXECUTE) =3D=3D= 0) { - Base =3D ImageContext->ImageAddress + SectionHeader.VirtualAddress; + Base =3D ImageBase + SectionHeader.VirtualAddress; =20 TextUpdater (Base, SectionHeader.Misc.VirtualSize); =20 @@ -153,6 +154,7 @@ STATIC EFI_STATUS GetPeCoffSectionInformation ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, + OUT EFI_PHYSICAL_ADDRESS *ImageBase, OUT UINT32 *SectionHeaderOffset, OUT UINT16 *NumberOfSections ) @@ -212,6 +214,7 @@ GetPeCoffSectionInformation ( return Status; } =20 + *ImageBase =3D ImageContext->ImageAddress; if (!ImageContext->IsTeImage) { ASSERT (Hdr.Pe32->Signature =3D=3D EFI_IMAGE_NT_SIGNATURE); =20 @@ -232,7 +235,7 @@ GetPeCoffSectionInformation ( } else { *SectionHeaderOffset =3D (UINTN)(sizeof (EFI_TE_IMAGE_HEADER)); *NumberOfSections =3D Hdr.Te->NumberOfSections; - ImageContext->ImageAddress -=3D (UINT32)Hdr.Te->StrippedSize - sizeof = (EFI_TE_IMAGE_HEADER); + *ImageBase -=3D (UINT32)Hdr.Te->StrippedSize - sizeof (EFI_TE_IMAGE_HE= ADER); } return RETURN_SUCCESS; } @@ -242,6 +245,7 @@ EFIAPI GetStandaloneMmCorePeCoffSections ( IN VOID *TeData, IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, + OUT EFI_PHYSICAL_ADDRESS *ImageBase, IN OUT UINT32 *SectionHeaderOffset, IN OUT UINT16 *NumberOfSections ) @@ -255,7 +259,8 @@ GetStandaloneMmCorePeCoffSections ( =20 DEBUG ((DEBUG_INFO, "Found Standalone MM PE data - 0x%x\n", TeData)); =20 - Status =3D GetPeCoffSectionInformation (ImageContext, SectionHeaderOffse= t, NumberOfSections); + Status =3D GetPeCoffSectionInformation (ImageContext, ImageBase, + SectionHeaderOffset, NumberOfSections); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "Unable to locate Standalone MM Core PE-COFF Sect= ion information - %r\n", Status)); return Status; diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/Sta= ndaloneMmCoreEntryPoint.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPo= int/AArch64/StandaloneMmCoreEntryPoint.c index 20723385113f..9cecfa667b90 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/Standalone= MmCoreEntryPoint.c +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/Standalone= MmCoreEntryPoint.c @@ -225,6 +225,7 @@ _ModuleEntryPoint ( VOID *HobStart; VOID *TeData; UINTN TeDataSize; + EFI_PHYSICAL_ADDRESS ImageBase; =20 // Get Secure Partition Manager Version Information Status =3D GetSpmVersion (); @@ -253,6 +254,7 @@ _ModuleEntryPoint ( Status =3D GetStandaloneMmCorePeCoffSections ( TeData, &ImageContext, + &ImageBase, &SectionHeaderOffset, &NumberOfSections ); @@ -261,10 +263,21 @@ _ModuleEntryPoint ( goto finish; } =20 + // + // ImageBase may deviate from ImageContext.ImageAddress if we are dealing + // with a TE image, in which case the latter points to the actual offset + // of the image, whereas ImageBase refers to the address where the image + // would start if the stripped PE headers were still in place. In either + // case, we need to fix up ImageBase so it refers to the actual current + // load address. + // + ImageBase +=3D (UINTN)TeData - ImageContext.ImageAddress; + // Update the memory access permissions of individual sections in the // Standalone MM core module Status =3D UpdateMmFoundationPeCoffPermissions ( &ImageContext, + ImageBase, SectionHeaderOffset, NumberOfSections, ArmSetMemoryRegionNoExec, @@ -276,6 +289,15 @@ _ModuleEntryPoint ( goto finish; } =20 + if (ImageContext.ImageAddress !=3D (UINTN)TeData) { + ImageContext.ImageAddress =3D (UINTN)TeData; + ArmSetMemoryRegionNoExec (ImageBase, SIZE_4KB); + ArmClearMemoryRegionReadOnly (ImageBase, SIZE_4KB); + + Status =3D PeCoffLoaderRelocateImage (&ImageContext); + ASSERT_EFI_ERROR (Status); + } + // // Create Hoblist based upon boot information passed by privileged softw= are // --=20 2.26.2 -=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 (#61043): https://edk2.groups.io/g/devel/message/61043 Mute This Topic: https://groups.io/mt/74792292/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-