From nobody Sun Feb 8 14:35:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+111747+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111747+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1701109119; cv=none; d=zohomail.com; s=zohoarc; b=njfPx1U3PQFRZDY7pbZjJRcV3eZgmnqw0FuEnHWBhbaHVptaV1QVTRKYfRT5ZtMcVRgoRMFaN9Rp89Zd67KDWJ7Y9TMn2kqmJDMwxFjP/Nxx0FVZu6Z1dTsNDhkeEY81GsO/4ZsXp6IShR7kijWWamOgZYmPdDrKz05f98FIirA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701109119; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=LnJGqb1J+e8A5Dz0qqcNIzAAbiyadIYi7ycb5mrpIsk=; b=gFTnMm7kirZJvUXzEmM+2vQU19G3eDqykgoMksZkKe6iU87sStmXHrC4PI7uYVmZIi/9fV7A4GU/wQlQ0aSwCUxk8HKaoBqQtSzn1Zx+0fAHGvAcq81zbKSuV25U9rEoFbxD6Nxkvea5VtPX7C3kDiIzn7cT0TtX2ar9ZB2UC50= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111747+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1701109119667526.0111400562022; Mon, 27 Nov 2023 10:18:39 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=td6ZdkPQbzC+sYK6+y4K2/LWV3fY0wmx37c4gaa3gXY=; 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=1701109119; v=1; b=asw9ZcVOM9FQScLdMIEBuKm4/CalPQ4eFg/RR5KswRsG8oWKrB2qv1hHFa07qRYSB4zwi0RV nWzeX70vnGuDRCuD+vtGBhfXuHdsm+5K3PPuFDyHZg/6x8u61PwT4Cn9DuNyfICixOPLT+dlK7T 5H/8qYjnC8zk0Fv6ujW8d1qk= X-Received: by 127.0.0.2 with SMTP id 3bz6YY1788612xzUo3HEDMvW; Mon, 27 Nov 2023 10:18:39 -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: 4mndbGeQWUShDY6ziZ1d3CsQx1787277AA= 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: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1701109120298000038 Content-Type: text/plain; charset="utf-8" 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/ImagePropertiesR= ecordLib.c b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c index 7c0ecd07c1bb..9d4082280bf5 100644 --- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.c +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.c @@ -323,7 +323,6 @@ SplitRecord ( UINT64 PhysicalEnd; UINTN NewRecordCount; UINTN TotalNewRecordCount; - BOOLEAN IsLastRecordData; =20 if (MaxSplitRecordCount =3D=3D 0) { CopyMem (NewRecord, OldRecord, DescriptorSize); @@ -344,35 +343,16 @@ SplitRecord ( NewImageRecord =3D GetImageRecordByAddress (PhysicalStart, PhysicalEnd= - PhysicalStart, ImageRecordList); if (NewImageRecord =3D=3D NULL) { // - // No more image covered by this range, stop + // No more images cover this range, check if we've reached the end o= f the old descriptor. If not, + // add the remaining range to the new descriptor list. // - if ((PhysicalEnd > PhysicalStart) && (ImageRecord !=3D NULL)) { - // - // If this is still address in this record, need record. - // - NewRecord =3D PREVIOUS_MEMORY_DESCRIPTOR (NewRecord, Descri= ptorSize); - IsLastRecordData =3D FALSE; - if ((NewRecord->Attribute & EFI_MEMORY_XP) !=3D 0) { - IsLastRecordData =3D TRUE; - } - - if (IsLastRecordData) { - // - // Last record is DATA, just merge it. - // - NewRecord->NumberOfPages =3D EfiSizeToPages (PhysicalEnd - NewRe= cord->PhysicalStart); - } else { - // - // Last record is CODE, create a new DATA entry. - // - NewRecord =3D NEXT_MEMORY_DESCRIPTOR (NewRecord, = DescriptorSize); - NewRecord->Type =3D TempRecord.Type; - NewRecord->PhysicalStart =3D TempRecord.PhysicalStart; - NewRecord->VirtualStart =3D 0; - NewRecord->NumberOfPages =3D TempRecord.NumberOfPages; - NewRecord->Attribute =3D TempRecord.Attribute | EFI_MEMORY_X= P; - TotalNewRecordCount++; - } + if (PhysicalEnd > PhysicalStart) { + NewRecord->Type =3D TempRecord.Type; + NewRecord->PhysicalStart =3D PhysicalStart; + NewRecord->VirtualStart =3D 0; + NewRecord->NumberOfPages =3D EfiSizeToPages (PhysicalEnd - Physica= lStart); + NewRecord->Attribute =3D TempRecord.Attribute; + TotalNewRecordCount++; } =20 break; @@ -380,6 +360,24 @@ SplitRecord ( =20 ImageRecord =3D NewImageRecord; =20 + // + // Update PhysicalStart to exclude the portion before the image buffer + // + if (TempRecord.PhysicalStart < ImageRecord->ImageBase) { + NewRecord->Type =3D TempRecord.Type; + NewRecord->PhysicalStart =3D TempRecord.PhysicalStart; + NewRecord->VirtualStart =3D 0; + NewRecord->NumberOfPages =3D EfiSizeToPages (ImageRecord->ImageBase = - TempRecord.PhysicalStart); + NewRecord->Attribute =3D TempRecord.Attribute; + TotalNewRecordCount++; + + PhysicalStart =3D ImageRecord->ImageBase; + TempRecord.PhysicalStart =3D PhysicalStart; + TempRecord.NumberOfPages =3D EfiSizeToPages (PhysicalEnd - PhysicalS= tart); + + NewRecord =3D (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)NewRecord + Descrip= torSize); + } + // // Set new record // --=20 2.42.0.windows.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 (#111747): https://edk2.groups.io/g/devel/message/111747 Mute This Topic: https://groups.io/mt/102834917/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-