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 341D9D8110E for ; Mon, 27 Nov 2023 18:18:43 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=Za0NNsvD/ZpkT7qzEZS4e+CwCydXt8juxV82oQFSNRM=; 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=1701109121; v=1; b=Fv09JwWIgxB4QKXjMctC4wtwBtC3YH3UCOtO0duI+IOEEssmjuso562YVPlrxDlpmWbzSgsk AWK2QA5hgzM3nzsSMUuP1wjaEtJtlsUYO6A1+NtdPa0awDuyQvLhtggjuma9DTI/a0ghgQIDN72 R5TQn/Y0QMjZvEYWNPwxhCp4= X-Received: by 127.0.0.2 with SMTP id r4bYYY7687511xxM2sJZvWGZ; Mon, 27 Nov 2023 10:18:41 -0800 X-Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by mx.groups.io with SMTP id smtpd.web11.102326.1701109118181864929 for ; Mon, 27 Nov 2023 10:18:38 -0800 X-Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-285b88b9917so1219252a91.1 for ; Mon, 27 Nov 2023 10:18:38 -0800 (PST) X-Gm-Message-State: BJAQlHvmlXLCXxZ5qyQZGwLFx7686176AA= X-Google-Smtp-Source: AGHT+IE/3E4qi9iCDor6j+fcu6i9NAqipYS9gPTFBfQ6334xs9DnprRMl84D6M9om6QxXXa5YD18Fg== X-Received: by 2002:a17:90a:49c1:b0:285:6565:fd15 with SMTP id l1-20020a17090a49c100b002856565fd15mr11672796pjm.12.1701109117369; Mon, 27 Nov 2023 10:18:37 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 10:18:37 -0800 (PST) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v5 10/16] MdeModulePkg: Fix MAT SplitRecord() Logic Date: Mon, 27 Nov 2023 10:18:08 -0800 Message-ID: <20231127181818.411-11-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=Fv09JwWI; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.com (policy=none) SplitRecord() does not handle the case where a memory descriptor describes an image region plus extra pages before or after the image region. This patch fixes this case by carving off the unrelated regions into their own descriptors. Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi Signed-off-by: Taylor Beebe Reviewed-by: Liming Gao --- MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c | 56 ++++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c index 7c0ecd07c1bb..9d4082280bf5 100644 --- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c @@ -323,7 +323,6 @@ SplitRecord ( UINT64 PhysicalEnd; UINTN NewRecordCount; UINTN TotalNewRecordCount; - BOOLEAN IsLastRecordData; if (MaxSplitRecordCount == 0) { CopyMem (NewRecord, OldRecord, DescriptorSize); @@ -344,35 +343,16 @@ SplitRecord ( NewImageRecord = GetImageRecordByAddress (PhysicalStart, PhysicalEnd - PhysicalStart, ImageRecordList); if (NewImageRecord == NULL) { // - // No more image covered by this range, stop + // No more images cover this range, check if we've reached the end of the old descriptor. If not, + // add the remaining range to the new descriptor list. // - if ((PhysicalEnd > PhysicalStart) && (ImageRecord != NULL)) { - // - // If this is still address in this record, need record. - // - NewRecord = PREVIOUS_MEMORY_DESCRIPTOR (NewRecord, DescriptorSize); - IsLastRecordData = FALSE; - if ((NewRecord->Attribute & EFI_MEMORY_XP) != 0) { - IsLastRecordData = TRUE; - } - - if (IsLastRecordData) { - // - // Last record is DATA, just merge it. - // - NewRecord->NumberOfPages = EfiSizeToPages (PhysicalEnd - NewRecord->PhysicalStart); - } else { - // - // Last record is CODE, create a new DATA entry. - // - NewRecord = NEXT_MEMORY_DESCRIPTOR (NewRecord, DescriptorSize); - NewRecord->Type = TempRecord.Type; - NewRecord->PhysicalStart = TempRecord.PhysicalStart; - NewRecord->VirtualStart = 0; - NewRecord->NumberOfPages = TempRecord.NumberOfPages; - NewRecord->Attribute = TempRecord.Attribute | EFI_MEMORY_XP; - TotalNewRecordCount++; - } + if (PhysicalEnd > PhysicalStart) { + NewRecord->Type = TempRecord.Type; + NewRecord->PhysicalStart = PhysicalStart; + NewRecord->VirtualStart = 0; + NewRecord->NumberOfPages = EfiSizeToPages (PhysicalEnd - PhysicalStart); + NewRecord->Attribute = TempRecord.Attribute; + TotalNewRecordCount++; } break; @@ -380,6 +360,24 @@ SplitRecord ( ImageRecord = NewImageRecord; + // + // Update PhysicalStart to exclude the portion before the image buffer + // + if (TempRecord.PhysicalStart < ImageRecord->ImageBase) { + NewRecord->Type = TempRecord.Type; + NewRecord->PhysicalStart = TempRecord.PhysicalStart; + NewRecord->VirtualStart = 0; + NewRecord->NumberOfPages = EfiSizeToPages (ImageRecord->ImageBase - TempRecord.PhysicalStart); + NewRecord->Attribute = TempRecord.Attribute; + TotalNewRecordCount++; + + PhysicalStart = ImageRecord->ImageBase; + TempRecord.PhysicalStart = PhysicalStart; + TempRecord.NumberOfPages = EfiSizeToPages (PhysicalEnd - PhysicalStart); + + NewRecord = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)NewRecord + DescriptorSize); + } + // // Set new record // -- 2.42.0.windows.2 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111747): https://edk2.groups.io/g/devel/message/111747 Mute This Topic: https://groups.io/mt/102834917/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-