From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (NAM02-SN1-obe.outbound.protection.outlook.com [40.107.96.79]) by mx.groups.io with SMTP id smtpd.web09.29559.1656615989941554460 for ; Thu, 30 Jun 2022 12:06:30 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nvidia.com header.s=selector2 header.b=HJFk05NO; 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.96.79, mailfrom: jbrasen@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SxoZM0H2HlKE+fYm107dwboNcw6MNEfBzJkxNnf2L604QrATRrghhb+gSU3Fnur/d2Ama9ixH4g1Lb2A8n/gubFl5ri0JBjiJQ2VVxvMk7GgT/2Shj8p8y4fhaPbLo0E0LFRufBnubC1kY5c3xL+s1iQMEXAejaH3Jtct+tBU2Zx5kc1lC3d+nFCPEEDTaIokFYh9ZQ9N8zqFxJphItgd2W6ybSUjpW761wi4TsXBc8+9oeKIfVKtwnj2qrDO2ucZgnqmhNA1G2lHoFu9/um6d+dtXqSdQjnaMtdk8puueNJ/hoTJbMCEVeI0d1OALSz4Aq+sOKJSsCpWFFPU2LThg== 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=Ile4TbqNbX8Y4UTgiflhOx/UfU2N/pFr5HE2f2ga9NI=; b=I26tJvx5CkuYQ7dY8UsjE7XtorKBV8xEuas85mfgjGVcqiuyLZiP4EOBS1H3cYMeLDY7C59W1dTO4TAGhLOdDJyxF9bXEtl3CS08Upgmka05UconjpItz6fPg4TtSFASZYYnm9wvgcoG/VYSQh+VvS/nyovrmKz0itiV+AoDBg0dx3itf+0Nj2qMokxjgNR52rMRoY0Z4mAyKMCxSgMTdn7abNI4VcK30pSpyJxeefAbiaMerTSJmsiFRoqzSe3K11AgatHwTIH+wvzjiVZNffkfOkRKNm7sGE9gZ7omPkneh0e/WIaRvKXkSTRzQqQdvIzVxHAPIdve74bVfNZn+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=hpe.com 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=Ile4TbqNbX8Y4UTgiflhOx/UfU2N/pFr5HE2f2ga9NI=; b=HJFk05NOdc/OM14X+zB/xRV0fSZn+Y1uIfCIMCck/+L6t6wB2cpAjL194GXHaEricn+AhHDgpwjT1HUAO2wNhgBXPh4puyEbnkDceI77i7MjSr+6WE7rGZMxFVCeo7rPKcctaixqFLKiQ0k+BbcN5Dr2Q1eVAOmEkG9XADsJTvpv6VMrz0eglh8NpPg8J0zVhjW9BLr+lbibWgcKSpLV1vVBq5HJg9sHrHjKXMyUlViCReiIKFXMQbe5OBKdB5ttpPIAECAH17Te7RnL663HzhPZfHd9vuDCG5D0kQnAsRueGL/gHKKQktffcWLL1FFUo8tv7d5ZZLoJcEJYI8/L9A== Received: from BN9P220CA0017.NAMP220.PROD.OUTLOOK.COM (2603:10b6:408:13e::22) by LV2PR12MB5870.namprd12.prod.outlook.com (2603:10b6:408:175::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14; Thu, 30 Jun 2022 19:06:28 +0000 Received: from BN8NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:408:13e:cafe::6d) by BN9P220CA0017.outlook.office365.com (2603:10b6:408:13e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14 via Frontend Transport; Thu, 30 Jun 2022 19:06:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) 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 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.234) by BN8NAM11FT008.mail.protection.outlook.com (10.13.177.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5395.17 via Frontend Transport; Thu, 30 Jun 2022 19:06:27 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Thu, 30 Jun 2022 19:06:27 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Thu, 30 Jun 2022 12:06:26 -0700 Received: from perses.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Thu, 30 Jun 2022 12:06:25 -0700 From: "Jeff Brasen" To: CC: , , , , Jeff Brasen Subject: [PATCH] EmbeddedPkg/PrePiMemoryAllocationLib: Add check for space on offset allocation Date: Thu, 30 Jun 2022 13:06:35 -0600 Message-ID: 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-Office365-Filtering-Correlation-Id: de086b4a-221d-4580-e3e0-08da5acba28f X-MS-TrafficTypeDiagnostic: LV2PR12MB5870:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: p1rGewyz87xdql1nguIuxC3Xnl/De36acn9/CUE3qJvx/zO2kNaoNyedEOb13g6ssGZXN9gqt2XDw4LSXg0Yyi7+ChHuMNwVIF+TnGsRGuoDess2AcGsnfx1mGovhpJEio33BSV8k6w8R4vvV2j4raLcnsuS4EzwRXPFN/DVFNdoiqjTYW2eVpyiK2qLLtYbTz1Xo1G1vrdR6u4VyebnxMJrKLd0EDy3pQDDxF7nmxKyoKr73YKMsdp/4Zwe8OtqzSjK98zWUW0q1R2pLikckauXbnVE3rDG3oeRNL/n3GK9xBEr4oJCdFk0fk1Y7x4xV8HmYj6W5zNV48DZs/2BXb0Qq1UUYIyTJVd1d85dr7Io8ZoErbWnJX8DEKzKeXs2VOiLouP0AWE4rRpUWWRBXl29PdvJ6pUVrMWg0eGVZWwixzXza/S+//9lRhQLmAaWu2mPgp4H9jZTh5pK5wzc7oTScCTsx+10Jvz9oI+JbJdGo4MLyujBkP9y7K6vgBxulrjYhnztTQzBugShxC5gGfCc5vdFJ1TeKovCSyXs7FUhdm70/7KxvbCijxrwlNgD/uG3pUx9C9IGMcn+cC9pQmcB17GK8bIUJs4RU0GpjxbQI92VeRkegt50+ELBHIYhelcnlMFeyV6TH56J7vPmtslBQJVEombOaiEw+ZnqT6Kve5lb8k9YHgm+DJZ9bmYoL1ij/vvfKdsYjFGnygso2xFk/2Tqm/oHfhPWq/ctV6amU0tPO8XoP5Pkg9An71zOWsdXrw137+JrB6uBN5RKYCoe59gkcEIKAdOFrACHKOgYU2Q9rvL3sfwqEgUPGU1JZ1+CuPCg+PO3m9VM+rU2p6CrXV/H5PYLs79dzVpvoYI= X-Forefront-Antispam-Report: CIP:12.22.5.234;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(6029001)(4636009)(396003)(136003)(346002)(376002)(39860400002)(46966006)(36840700001)(40470700004)(86362001)(36860700001)(7696005)(26005)(2906002)(41300700001)(6666004)(82310400005)(5660300002)(8936002)(40460700003)(478600001)(47076005)(4326008)(186003)(426003)(356005)(36756003)(6916009)(2616005)(336012)(70586007)(70206006)(107886003)(54906003)(83380400001)(81166007)(8676002)(316002)(296002)(82740400003)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jun 2022 19:06:27.6671 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: de086b4a-221d-4580-e3e0-08da5acba28f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.234];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5870 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 Signed-off-by: Jeff Brasen =0D ---=0D .../MemoryAllocationLib.c | 53 +++++++++++--------=0D 1 file changed, 30 insertions(+), 23 deletions(-)=0D =0D diff --git a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationL= ib.c b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c=0D index 78f8da5e95..1956d644c3 100644=0D --- a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c=0D +++ b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c=0D @@ -38,37 +38,44 @@ AllocatePages (=0D =0D Hob.Raw =3D GetHobList ();=0D =0D - // Check to see if on 4k boundary=0D Offset =3D Hob.HandoffInformationTable->EfiFreeMemoryTop & 0xFFF;=0D + //=0D + // Verify that there is sufficient memory to satisfy the allocation and = padding prior to updating anything=0D + //=0D + if ((Hob.HandoffInformationTable->EfiFreeMemoryTop - ((Pages * EFI_PAGE_= SIZE) + sizeof (EFI_HOB_MEMORY_ALLOCATION)) - Offset) < Hob.HandoffInformat= ionTable->EfiFreeMemoryBottom) {=0D + if (Offset !=3D 0) {=0D + DEBUG ((DEBUG_ERROR, "Offset applied without enough space\r\n"));=0D + } else {=0D + DEBUG ((DEBUG_ERROR, "Out of memory\r\n"));=0D + }=0D +=0D + ASSERT (FALSE);=0D + return 0;=0D + }=0D +=0D + // Check to see if on 4k boundary=0D if (Offset !=3D 0) {=0D // If not aligned, make the allocation aligned.=0D Hob.HandoffInformationTable->EfiFreeMemoryTop -=3D Offset;=0D }=0D =0D //=0D - // Verify that there is sufficient memory to satisfy the allocation=0D + // Update the PHIT to reflect the memory usage=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 - EfiBootServicesData=0D - );=0D - return (VOID *)(UINTN)Hob.HandoffInformationTable->EfiFreeMemoryTop;=0D - }=0D + Hob.HandoffInformationTable->EfiFreeMemoryTop -=3D Pages * EFI_PAGE_SIZE= ;=0D +=0D + // This routine used to create a memory allocation HOB a la PEI, but tha= t'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 + EfiBootServicesData=0D + );=0D + return (VOID *)(UINTN)Hob.HandoffInformationTable->EfiFreeMemoryTop;=0D }=0D =0D /**=0D -- =0D 2.25.1=0D =0D