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 A5283780091 for ; Sun, 8 Oct 2023 19:20:53 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=lqeJ8PvxU1KTZKu47UVnrwfxnuIO7K9ah+hFFx4NGBg=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References:From:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Language; s=20140610; t=1696792852; v=1; b=RcyfcFjGeHQ+tm4PpK7dOJfFv4nSmz0Hu1YMa+ozutEpUwsA5PR9TQikW7+ZV1XoLxM4bPCp SbtgF7ltpnH75Yk5O+U7AR6TZtCg51uVo8DGp/oLFXi7RwfVRdnao1if9SdgvBxIMkNhQ1vZu8M urWpGlMkzVMEiAmQBxFzCEXg= X-Received: by 127.0.0.2 with SMTP id NCp4YY7687511xjlZRZqSpOC; Sun, 08 Oct 2023 12:20:52 -0700 X-Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by mx.groups.io with SMTP id smtpd.web10.44894.1696792851670396064 for ; Sun, 08 Oct 2023 12:20:51 -0700 X-Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-690b7cb71aeso2811185b3a.0 for ; Sun, 08 Oct 2023 12:20:51 -0700 (PDT) X-Gm-Message-State: QSgGxQeOirikVlPiOSpJNduXx7686176AA= X-Google-Smtp-Source: AGHT+IF4N1l2Xb9OsWboWkkI4KU954v34JCaExmigAQOWvL3AYm39QjaYOgGPXVyL1LqgWQ5pwfKog== X-Received: by 2002:a05:6a00:849:b0:68e:2c2a:5172 with SMTP id q9-20020a056a00084900b0068e2c2a5172mr15735985pfk.6.1696792850773; Sun, 08 Oct 2023 12:20:50 -0700 (PDT) X-Received: from [192.168.0.125] ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id z23-20020aa785d7000000b00690d64a0cb6sm4861693pfn.72.2023.10.08.12.20.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 08 Oct 2023 12:20:50 -0700 (PDT) Message-ID: Date: Sun, 8 Oct 2023 12:20:48 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: =?UTF-8?B?UmU6IOWbnuWkjTogW2VkazItZGV2ZWxdIFtQQVRDSCB2NCAwMC8xNF0gQWRkIEltYWdlUHJvcGVydGllc1JlY29yZExpYiBhbmQgRml4IE1BVCBCdWdz?= To: devel@edk2.groups.io, gaoliming@byosoft.com.cn, 'Ard Biesheuvel' Cc: 'Andrew Fish' , 'Ard Biesheuvel' , 'Dandan Bi' , 'Eric Dong' , 'Gerd Hoffmann' , 'Guo Dong' , 'Gua Guo' , 'James Lu' , 'Jian J Wang' , 'Jiewen Yao' , 'Jordan Justen' , 'Leif Lindholm' , 'Rahul Kumar' , 'Ray Ni' , 'Sami Mujawar' , 'Sean Rhodes' References: <177845D072580598.19347@groups.io> <177BEFB7EF58B50B.8497@groups.io> <17887E55BF3885BC.16687@groups.io> <83c03b0c-c8e8-44cf-8b45-761f31577153@gmail.com> <081601d9f8e3$2ac79d90$8056d8b0$@byosoft.com.cn> From: "Taylor Beebe" In-Reply-To: <081601d9f8e3$2ac79d90$8056d8b0$@byosoft.com.cn> 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-Type: multipart/alternative; boundary="------------Ss7u9iBr7z87plFNt9smwLqF" Content-Language: en-US X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=RcyfcFjG; 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 --------------Ss7u9iBr7z87plFNt9smwLqF Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 10/6/2023 10:57 PM, gaoliming via groups.io wrote: > Taylor: > I agree to add new ImagePropertiesRecordLib library for DxeCore and SmmCore. The impact is that platform needs to update their DSC with new library. > > Frankly, I have not understood MAT code in detail. So, I have no comments on this part. > > Last, what test have been done to verify the current functionality? TLDR: Patch 8 adds the unit test which invokes the lions share of the new library. The remaining functional changes were tested by output comparison. To provide context on how best to review this series, where the functional changes are, and how they were validated, here's a breakdown of each patch: Patch 1: Add the ImagePropertiesRecordLib definition and "blank" implementation. Patches 2-5: Add instances of the library to the platform DSC files. Patch 6: Updates the logic in Dxe/Misc/MemoryAttributesTable.c to use parameters passed in instead of referencing directly the global variables.                 This functionally changes nothing but allows the logic to be moved to a library. Patch 7: Move the Dxe/Misc/MemoryAttributesTable.c Image Properties Record manipulation logic to ImagePropertiesRecordLib -- still no functional changes. ------------ FUNCTIONAL CHANGES START ------------ Patch 8: Add ImagePropertiesRecordLibHostBasedUnitTest which tests the logic now in ImagePropertiesRecordLib and 3/4 of the tests fail to show that the logic is incorrect.                The test calls into the SplitTable() routine which is the most complex and invokes almost every other function in ImagePropertiesRecordLib. Patch 9: Fixes the issues in the logic resulting in ImagePropertiesRecordLibHostBasedUnitTest passing fully. The fixes change some logic in SpitTable() and SplitRecord() (which are tested by the unit test)                And increases the buffer size for the split table in Dxe/Misc/MemoryAttributesTable.c to fix another edge case. The rest of the exposed functions in ImagePropertiesRecordLib.h                are unchanged through this patch. Patch 10: Simply updates function headers, adds return status values to some functions, and adds NULL checks to sanity check the caller input. Patch 11: Makes a minor change to the SMM memory attribute logic to use the attributes present in the memory map created by the SplitTable() routine. This needs to be done because the original                   SMM MAT logic would manipulate the split memory map to change the memory type of loaded runtime image data sections to EfiRuntimeServicesData so it could apply XP and RO based                   on each entry EFI type. This process is unecessary, though, because the SplitTable() routine in PiSmmCore/MemoryAttributesTable.c already sets the XP and RO attributes                   appropriately on PE images, and EnforceMemoryMapAttribute() in PiSmmCore/MemoryAttributesTable.c sets the XP and RO attributes on the non PE runtime regions. All that to say, this                   is still output-wise the same as it was before. Patch 12: Update the SMM MAT logic to use ImagePropertiesRecordLib. If a direct comparison was done between the original DXE and SMM MAT logic, you would see many differences. Some bugs                  on the DXE side were actually fixed on the SMM side. For the rest, as best I can tell, there was no reason for the remaining differences. I also checked the SMM MAT table pre and post this                  patch series on OvmfPkg and found output the same. Patch 13: This patch consolidates the DXE and SMM logic for creating Image Properties Records into the library which is extremely close to the ProtectUefiImage() logic in MemoryProtection.c. If you're                   familiar to that logic, this should be easy to review. Patch 14: Just updates the DumpImageRecord() routine to be more helpful and print the loaded image .efi name. This info will be dumped for both DXE and SMM debug output and will help us find                  MAT issues easier in the future. Hope this helps :) -Taylor -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#109402): https://edk2.groups.io/g/devel/message/109402 Mute This Topic: https://groups.io/mt/101812772/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- --------------Ss7u9iBr7z87plFNt9smwLqF Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

On 10/6/2023 10:57 PM, gaoliming via groups.io wrote:

Taylor:
  I agree to add new ImagePropertiesRecordLib library for DxeCore and SmmCore. The impact is that platform needs to update their DSC with new library. 

  Frankly, I have not understood MAT code in detail. So, I have no comments on this part. 

  Last, what test have been done to verify the current functionality?

TLDR: Patch 8 adds the unit test which invokes the lions share of the new library. The remaining functional changes were tested by output comparison.


To provide context on how best to review this series, where the functional changes are, and how they were validated, here's a breakdown of each patch:

Patch 1: Add the ImagePropertiesRecordLib definition and "blank" implementation.

Patches 2-5: Add instances of the library to the platform DSC files.

Patch 6: Updates the logic in Dxe/Misc/MemoryAttributesTable.c to use parameters passed in instead of referencing directly the global variables.

                This functionally changes nothing but allows the logic to be moved to a library.

Patch 7: Move the Dxe/Misc/MemoryAttributesTable.c Image Properties Record manipulation logic to ImagePropertiesRecordLib -- still no functional changes.

------------ FUNCTIONAL CHANGES START ------------

Patch 8: Add ImagePropertiesRecordLibHostBasedUnitTest which tests the logic now in ImagePropertiesRecordLib and 3/4 of the tests fail to show that the logic is incorrect.

               The test calls into the SplitTable() routine which is the most complex and invokes almost every other function in ImagePropertiesRecordLib.

Patch 9: Fixes the issues in the logic resulting in ImagePropertiesRecordLibHostBasedUnitTest passing fully. The fixes change some logic in SpitTable() and SplitRecord() (which are tested by the unit test)

               And increases the buffer size for the split table in Dxe/Misc/MemoryAttributesTable.c to fix another edge case. The rest of the exposed functions in ImagePropertiesRecordLib.h

               are unchanged through this patch.

Patch 10: Simply updates function headers, adds return status values to some functions, and adds NULL checks to sanity check the caller input.

Patch 11: Makes a minor change to the SMM memory attribute logic to use the attributes present in the memory map created by the SplitTable() routine. This needs to be done because the original

                  SMM MAT logic would manipulate the split memory map to change the memory type of loaded runtime image data sections to EfiRuntimeServicesData so it could apply XP and RO based

                  on each entry EFI type. This process is unecessary, though, because the SplitTable() routine in PiSmmCore/MemoryAttributesTable.c already sets the XP and RO attributes

                  appropriately on PE images, and EnforceMemoryMapAttribute() in PiSmmCore/MemoryAttributesTable.c sets the XP and RO attributes on the non PE runtime regions. All that to say, this

                  is still output-wise the same as it was before.

Patch 12: Update the SMM MAT logic to use ImagePropertiesRecordLib. If a direct comparison was done between the original DXE and SMM MAT logic, you would see many differences. Some bugs

                 on the DXE side were actually fixed on the SMM side. For the rest, as best I can tell, there was no reason for the remaining differences. I also checked the SMM MAT table pre and post this

                 patch series on OvmfPkg and found output the same.

Patch 13: This patch consolidates the DXE and SMM logic for creating Image Properties Records into the library which is extremely close to the ProtectUefiImage() logic in MemoryProtection.c. If you're

                  familiar to that logic, this should be easy to review.

Patch 14: Just updates the DumpImageRecord() routine to be more helpful and print the loaded image .efi name. This info will be dumped for both DXE and SMM debug output and will help us find

                 MAT issues easier in the future.


Hope this helps :)

-Taylor

_._,_._,_

Groups.io Links:

You receive all messages sent to this group.

View/Reply Online (#109402) | | Mute This Topic | New Topic
Your Subscription | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--------------Ss7u9iBr7z87plFNt9smwLqF--