From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (NAM04-BN8-obe.outbound.protection.outlook.com [40.107.100.69]) by mx.groups.io with SMTP id smtpd.web09.304.1663879237696905801 for ; Thu, 22 Sep 2022 13:40:38 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nvidia.com header.s=selector2 header.b=HrCILbXv; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: nvidia.com, ip: 40.107.100.69, mailfrom: jbrasen@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X0Z5x/dQIADZvX8/232QL6Ywh3F+bLH8mBqDJuWvt35C8fuDLMmbin/+NNpdzfel54unwtLodSYSsveJuDEZq25vMO2NvGXHnVGSUsJr+DI8iCQbZCDuDRQg/3yohKdzJRExH0Ut/x7dawnnGq6tlhgCLyZDUNEQ/lzDkeAQY4uti05KmO03Nu3GRA7XF0XB0hArnX8LihG0ju5gaPrcXDQKVoDP4c6yp2kbd8W29v7559kq7TCcvZVJ7Oj2VGCmwVcTl0za8Sv3x60GOSj82p2mbXsAd6chYGND78m0Oi7Fo0TLEWq7OomAMbhRt8wQm6Qet+GABetpQlS8gNT/3A== 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=NMhsutm0KkEPIWANXRUpUyG84uoKhHRByRYKvo/TiAU=; b=B5xZOjMRg6B3ikt8QqRkDkUYzVuVajPHlwPpjViE/6trpnvW0ryMEy5ZiK74aZ6gnIwYwFNUVy1c82Gbd3itX0MhU97k7Wj2UVAP3chIAxkfZOYF6ZI75Xt+SQU2zB/nRqZ3UjiGLHEr8a9yKyNKOxlCUBQy4qlHWtxhhwiR7KxWgT4XDEqHPHqsoKAWgfau+OXpRyCspRlk8Mgmk+6m+gfnoOt+5t2T/q5/4T9N0/v73DrnuvuyoFrY0DVBYV7Th12jFtD1n9XLWyyOlXcSO/4NLCBUkZXjbVwazK29eh6MtyhDOivNgfi4qpTX2vyT/g5gPw/9OMAwPFSb3SB2tA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NMhsutm0KkEPIWANXRUpUyG84uoKhHRByRYKvo/TiAU=; b=HrCILbXvNovRrFkviC7eaT0BGrhkK9ibIoYKHXKGGcZ5QU25S5GeCfIGayaCSURF+MHEaUyHe7AYHgtMLFr2QAI/UC4OxTJf7cLmuYcXTeAnur3LO8Sbn8xOEBqCCvn/e0AY2eXodHQgsY2GDpprF/ccx25jwJCj3onJTqueO0rt9i2hcXbXWcACRFUsXXY6pTPyAZql+2PzUdaA/+7L0SQgzIyiQHkqftISWfiGN0PFmu+1nYp0XxgwxRqOBaETe5b2AmbgBEIvwtPSrApuD4Qq0Ld/0bUKYtthD2VvNyCrZeht8SG6gtf9PYammTwy+t153mfco189dsMSMR4+6w== Received: from DM5PR08CA0039.namprd08.prod.outlook.com (2603:10b6:4:60::28) by PH7PR12MB6609.namprd12.prod.outlook.com (2603:10b6:510:213::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.19; Thu, 22 Sep 2022 20:40:35 +0000 Received: from DM6NAM11FT092.eop-nam11.prod.protection.outlook.com (2603:10b6:4:60:cafe::d2) by DM5PR08CA0039.outlook.office365.com (2603:10b6:4:60::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.19 via Frontend Transport; Thu, 22 Sep 2022 20:40:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by DM6NAM11FT092.mail.protection.outlook.com (10.13.173.44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.14 via Frontend Transport; Thu, 22 Sep 2022 20:40:34 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Thu, 22 Sep 2022 13:40:24 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Thu, 22 Sep 2022 13:40:23 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Thu, 22 Sep 2022 13:40:23 -0700 Received: from f153882e4be8.nvidia.com (10.127.8.13) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Thu, 22 Sep 2022 13:40:23 -0700 From: "Jeff Brasen" To: CC: , , , , Jeff Brasen Subject: [PATCH v3] EmbeddedPkg/PrePiMemoryAllocationLib: Add check for space on offset allocation Date: Thu, 22 Sep 2022 14:40:21 -0600 Message-ID: <38bfcc0559d4b02b629c07fbdc434e5f1971e0ff.1663879160.git.jbrasen@nvidia.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-NVConfidentiality: public Return-Path: jbrasen@nvidia.com X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT092:EE_|PH7PR12MB6609:EE_ X-MS-Office365-Filtering-Correlation-Id: 611dd71a-de3c-43c9-05bf-08da9cdab33a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1moMwvdBQudSOTiU+ZAW0XFI36ran6H9L0xDfYbwy4y87Q5V8Cu82IpUA3am8vL7R3qCqLhZXWEU+qPHOGo2P8Qb2Ybviv49ljHI15kSNpVUcO6Fc/Sc9wCsUUDo5NyEFlzuoyJ4pVRJ9pSQvpXd0QUOml8pRYg3qZcG9doVV6emxsaS5SmLlXuHM5PHhHljfiee3dVKdyACCQSWJpsqTnV6I8CQfbGN2eupeGOQ5FGrliR7UnOehmG2/2TKLgbBgxuaYfnKvtMRR+2JeLq0toy1/eN/hF1GVTNjkCN9vR1v/hgvLJAHvaAItFmY6ARDDDoxI80tbjQ0g7sfQHT0mwqPNwBPiQA2KErg5akNfgbrod//Ansl4Kps3tToPryz+ESLDDC14XFRP/3OWv3NJcPnxRfv32TOzzQBxIpEsSCU3NeiZzJ1AhUtblqB1R86LdzQ0MBMyqwEjOenqbefh2nul8xNNwEmldRwBPGlddBKilUCLbRsR2tAfw1wFfsJSdzqAtPOQBWBAgsXAphQQ1bfvFMGSLVSGoAhVEgkT2DZHUzU/yK/xwMt2JNbGHKwEpIcL2GSd4+XMX9yE35DPP1z9qYXntzRoBPs7Oj/Qs3786fuuUGMrcGgiJDGmW0EmFQJOEDx+icMtGWR5Aq8tqUNjKZL6/fOIMxI5oCA4ZDNLsLo4QOTXSHn3oKcH+ctPgclqnpDjuPyEfw7FOZZeFtGS8zPikDQfN8npPPet02XUWyHvBwcWDgd0BrSjFCALgyouI9zQJ7up3i6oXc+SQ== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230022)(6029001)(4636009)(136003)(346002)(39860400002)(376002)(396003)(451199015)(46966006)(36840700001)(40470700004)(82310400005)(478600001)(86362001)(40460700003)(36756003)(356005)(2906002)(36860700001)(336012)(5660300002)(82740400003)(70586007)(6916009)(4326008)(316002)(186003)(70206006)(8676002)(54906003)(8936002)(107886003)(83380400001)(47076005)(7636003)(41300700001)(426003)(40480700001)(2616005)(7696005)(26005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2022 20:40:34.8668 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 611dd71a-de3c-43c9-05bf-08da9cdab33a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT092.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6609 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Update check for enough space to occur prior to alignment offset.=0D This prevents cases where EfiFreeMemoryTop < EfiFreeMemoryBottom.=0D =0D Change-Id: I58c5d378523c881a4afc655e7ace4c009130c781=0D ---=0D .../MemoryAllocationLib.c | 48 ++++++++-----------=0D 1 file changed, 21 insertions(+), 27 deletions(-)=0D =0D diff --git a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationL= ib.c b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c=0D index 2cc2a71121..08a0add340 100644=0D --- a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c=0D +++ b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c=0D @@ -23,41 +23,35 @@ InternalAllocatePages (=0D )=0D {=0D EFI_PEI_HOB_POINTERS Hob;=0D - EFI_PHYSICAL_ADDRESS Offset;=0D + EFI_PHYSICAL_ADDRESS NewTop;=0D =0D Hob.Raw =3D GetHobList ();=0D =0D - // Check to see if on 4k boundary=0D - Offset =3D Hob.HandoffInformationTable->EfiFreeMemoryTop & 0xFFF;=0D - if (Offset !=3D 0) {=0D - // If not aligned, make the allocation aligned.=0D - Hob.HandoffInformationTable->EfiFreeMemoryTop -=3D Offset;=0D - }=0D + NewTop =3D Hob.HandoffInformationTable->EfiFreeMemoryTop & ~(EFI_PHYSIC= AL_ADDRESS)EFI_PAGE_MASK;=0D + NewTop -=3D Pages * EFI_PAGE_SIZE;=0D =0D //=0D // Verify that there is sufficient memory to satisfy the allocation=0D //=0D - if (Hob.HandoffInformationTable->EfiFreeMemoryTop - ((Pages * EFI_PAGE_S= IZE) + sizeof (EFI_HOB_MEMORY_ALLOCATION)) < Hob.HandoffInformationTable->E= fiFreeMemoryBottom) {=0D - return 0;=0D - } else {=0D - //=0D - // Update the PHIT to reflect the memory usage=0D - //=0D - Hob.HandoffInformationTable->EfiFreeMemoryTop -=3D Pages * EFI_PAGE_SI= ZE;=0D -=0D - // This routine used to create a memory allocation HOB a la PEI, but t= hat's not=0D - // necessary for us.=0D -=0D - //=0D - // Create a memory allocation HOB.=0D - //=0D - BuildMemoryAllocationHob (=0D - Hob.HandoffInformationTable->EfiFreeMemoryTop,=0D - Pages * EFI_PAGE_SIZE,=0D - MemoryType=0D - );=0D - return (VOID *)(UINTN)Hob.HandoffInformationTable->EfiFreeMemoryTop;=0D + if (NewTop < (Hob.HandoffInformationTable->EfiFreeMemoryBottom + sizeof = (EFI_HOB_MEMORY_ALLOCATION))) {=0D + return NULL;=0D }=0D +=0D + //=0D + // Update the PHIT to reflect the memory usage=0D + //=0D + Hob.HandoffInformationTable->EfiFreeMemoryTop =3D NewTop;=0D +=0D + //=0D + // Create a memory allocation HOB.=0D + //=0D + BuildMemoryAllocationHob (=0D + Hob.HandoffInformationTable->EfiFreeMemoryTop,=0D + Pages * EFI_PAGE_SIZE,=0D + MemoryType=0D + );=0D +=0D + return (VOID *)(UINTN)Hob.HandoffInformationTable->EfiFreeMemoryTop;=0D }=0D =0D /**=0D -- =0D 2.25.1=0D =0D