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 9BAE7740037 for ; Mon, 27 Nov 2023 18:18:41 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=3CpwfZ6xmXWSMUeYOZoR6s6UUCOLJUXe8/qeQoXLRF8=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1701109120; v=1; b=RO8FJsTZEBmb1qdCt6/GtRcJNdnxjk0CY3gPoKZ+Ax1NUDIU1lfOiFIow0VqotI5vx/vauwy FewmwdA0a1elJlzFpCSMhG///SGwh3HsI8sKLVb9lD8VT08A+mrKeDwjY2Na2L/KJZS6KJJKqUE C6YrQl4FaYnXvo0kVTeE899o= X-Received: by 127.0.0.2 with SMTP id mOIcYY7687511xUo11hyZB9E; Mon, 27 Nov 2023 10:18:40 -0800 X-Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by mx.groups.io with SMTP id smtpd.web10.102526.1701109117593564691 for ; Mon, 27 Nov 2023 10:18:37 -0800 X-Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1cfa168faefso25658195ad.3 for ; Mon, 27 Nov 2023 10:18:37 -0800 (PST) X-Gm-Message-State: 5uSPUuUrNLqLH2axNHeXlFacx7686176AA= X-Google-Smtp-Source: AGHT+IGtmYKkslo+lPMKAPltfHeAwVO0Y9+6+mKE51tts5Fa/54vCnbRzTR8qBU5+mkwB8WH5Mh00Q== X-Received: by 2002:a17:902:e888:b0:1cf:c2b8:4772 with SMTP id w8-20020a170902e88800b001cfc2b84772mr6011252plg.18.1701109116917; Mon, 27 Nov 2023 10:18:36 -0800 (PST) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id c6-20020a170902c1c600b001cfd0ed1604sm2013259plc.87.2023.11.27.10.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 10:18:36 -0800 (PST) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v5 09/16] MdeModulePkg: Fix MAT Descriptor Count Calculation Date: Mon, 27 Nov 2023 10:18:07 -0800 Message-ID: <20231127181818.411-10-taylor.d.beebe@gmail.com> In-Reply-To: <20231127181818.411-1-taylor.d.beebe@gmail.com> References: <20231127181818.411-1-taylor.d.beebe@gmail.com> MIME-Version: 1.0 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,taylor.d.beebe@gmail.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=RO8FJsTZ; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.com (policy=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 |4K PAGE|DATA|CODE|DATA|CODE|DATA|4K PAGE| Say the above memory region is currently one memory map descriptor. The above image memory layout example contains two code sections oriented in a way that maximizes the number of descriptors which would be required to describe each section. NOTE: It's unlikely that a data section would ever be between two code sections, but it's still handled by the below formula for correctness. There are two code sections (let's say CodeSegmentMax == 2), three data sections, and two unrelated memory regions flanking the image. The number of required descriptors to describe this layout will be 2 * 2 + 3 == 7. This patch updates the calculations to account for the worst-case scenario. Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi Signed-off-by: Taylor Beebe Reviewed-by: Liming Gao --- MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c | 2 +- MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c index 51630f504ea1..af6c26244cc0 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c @@ -517,7 +517,7 @@ CoreGetMemoryMapWithSeparatedImageSection ( CoreAcquiremMemoryAttributesTableLock (); - AdditionalRecordCount = (2 * mImagePropertiesPrivateData.CodeSegmentCountMax + 1) * mImagePropertiesPrivateData.ImageRecordCount; + AdditionalRecordCount = (2 * mImagePropertiesPrivateData.CodeSegmentCountMax + 3) * mImagePropertiesPrivateData.ImageRecordCount; OldMemoryMapSize = *MemoryMapSize; Status = CoreGetMemoryMap (MemoryMapSize, MemoryMap, MapKey, DescriptorSize, DescriptorVersion); diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c index 9fb3b922038f..7c0ecd07c1bb 100644 --- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c @@ -277,7 +277,7 @@ GetMaxSplitRecordCount ( break; } - SplitRecordCount += (2 * ImageRecord->CodeSegmentCount + 1); + SplitRecordCount += (2 * ImageRecord->CodeSegmentCount + 3); PhysicalStart = ImageRecord->ImageBase + ImageRecord->ImageSize; } while ((ImageRecord != NULL) && (PhysicalStart < PhysicalEnd)); -- 2.42.0.windows.2 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111746): https://edk2.groups.io/g/devel/message/111746 Mute This Topic: https://groups.io/mt/102834916/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-