public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [PATCH v4 00/14] Add ImagePropertiesRecordLib and Fix MAT Bugs
@ 2023-08-04 19:46 Taylor Beebe
  2023-08-04 19:46 ` [edk2-devel] [PATCH v4 01/14] MdeModulePkg: Add ImagePropertiesRecordLib Taylor Beebe
                   ` (14 more replies)
  0 siblings, 15 replies; 24+ messages in thread
From: Taylor Beebe @ 2023-08-04 19:46 UTC (permalink / raw)
  To: devel
  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, Liming Gao, Rahul Kumar, Ray Ni,
	Sami Mujawar, Sean Rhodes

From: Taylor Beebe <taylor.d.beebe@gmail.com>

v4:
- Expose additional functions in the Library API
- Add NULL checks to library functions and return a
  status where applicable.

v3:
- Refactor patch series so the transition of logic from the DXE
  MAT logic to the new library is more clear.
- Update function headers to improve clarity and follow EDK2
  standards.
- Add Create and Delete functions for Image Properties Records
  and redirect some of the SMM and DXE MAT code to use these
  functions.
- Update/Add DumpImageRecords() to print the image name and code
  sections of each runtime image which will be put in the MAT.
  The DXE and SMM MAT logic will now invoke the DumpImageRecords()
  on DEBUG builds at the EndOfDxe event to install the MAT.

v2:
- A one-line change in patch 3 was moved to patch 9 for correctness.

Reference: https://github.com/tianocore/edk2/pull/4590
Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=4492

The UEFI and SMM MAT logic contains duplicate logic for manipulating image
properties records which is used to track runtime images.
This patch series adds a new library, ImagePropertiesRecordLib,
which consolidates this logic and fixes the bugs which currently exist in
the MAT logic.

The first patch adds the ImagePropertiesRecordLib implementation which
is a copy of the UEFI MAT logic with minor modifications to remove the
reliance on globabl variables and make the code unit testable.

The second patch adds a unit test for the ImagePropertiesRecordLib. The
logic tests various potential layouts of the EFI memory map and runtime
images. 3/4 of these tests will fail which demonstrates the MAT logic
bugs.

The third patch fixes the logic in the ImagePropertiesRecordLib so
that all of the unit tests pass and the MAT logic can be fixed by
using the library.

The remaining patches add library instances to DSC files and remove
the image properties record logic from the SMM and UEFI MAT logic.

Cc: Andrew Fish <afish@apple.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Guo Dong <guo.dong@intel.com>
Cc: Gua Guo <gua.guo@intel.com>
Cc: James Lu <james.lu@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Sean Rhodes <sean@starlabs.systems>

Taylor Beebe (14):
  MdeModulePkg: Add ImagePropertiesRecordLib
  ArmVirtPkg: Add ImagePropertiesRecordLib Instance
  EmulatorPkg: Add ImagePropertiesRecordLib Instance
  OvmfPkg: Add ImagePropertiesRecordLib Instance
  UefiPayloadPkg: Add ImagePropertiesRecordLib Instance
  MdeModulePkg: Update MemoryAttributesTable.c to Reduce Global Variable
    Use
  MdeModulePkg: Move Some DXE MAT Logic to ImagePropertiesRecordLib
  MdeModulePkg: Add ImagePropertiesRecordLib Host-Based Unit Test
  MdeModulePkg: Fix Bugs in MAT Logic
  MdeModulePkg: Add NULL checks and Return Status to
    ImagePropertiesRecordLib
  UefiCpuPkg: Use Attribute From SMM MemoryAttributesTable if Nonzero
  MdeModulePkg: Transition SMM MAT Logic to Use ImagePropertiesRecordLib
  MdeModulePkg: Add Logic to Create/Delete Image Properties Records
  MdeModulePkg: Update DumpImageRecord() in ImagePropertiesRecordLib

 MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c                                              |  967 +----------------
 MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c                                                   |   24 +-
 MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c                                             |  958 +---------------
 MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c                        | 1144 ++++++++++++++++++++
 MdeModulePkg/Library/ImagePropertiesRecordLib/UnitTest/ImagePropertiesRecordLibUnitTestHost.c   |  938 ++++++++++++++++
 UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c                                              |   19 +-
 ArmVirtPkg/ArmVirt.dsc.inc                                                                      |    1 +
 EmulatorPkg/EmulatorPkg.dsc                                                                     |    1 +
 MdeModulePkg/Core/Dxe/DxeMain.h                                                                 |   20 -
 MdeModulePkg/Core/Dxe/DxeMain.inf                                                               |    1 +
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf                                                       |    1 +
 MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h                                         |  234 ++++
 MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf                      |   31 +
 MdeModulePkg/Library/ImagePropertiesRecordLib/UnitTest/ImagePropertiesRecordLibUnitTestHost.inf |   35 +
 MdeModulePkg/MdeModulePkg.dec                                                                   |    5 +
 MdeModulePkg/MdeModulePkg.dsc                                                                   |    2 +
 MdeModulePkg/Test/MdeModulePkgHostTest.dsc                                                      |    6 +
 OvmfPkg/AmdSev/AmdSevX64.dsc                                                                    |    1 +
 OvmfPkg/Bhyve/BhyveX64.dsc                                                                      |    1 +
 OvmfPkg/CloudHv/CloudHvX64.dsc                                                                  |    1 +
 OvmfPkg/IntelTdx/IntelTdxX64.dsc                                                                |    1 +
 OvmfPkg/Microvm/MicrovmX64.dsc                                                                  |    1 +
 OvmfPkg/OvmfPkgIa32.dsc                                                                         |    1 +
 OvmfPkg/OvmfPkgIa32X64.dsc                                                                      |    1 +
 OvmfPkg/OvmfPkgX64.dsc                                                                          |    1 +
 OvmfPkg/OvmfXen.dsc                                                                             |    1 +
 OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc                                                             |    1 +
 UefiPayloadPkg/UefiPayloadPkg.dsc                                                               |    1 +
 28 files changed, 2524 insertions(+), 1874 deletions(-)
 create mode 100644 MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c
 create mode 100644 MdeModulePkg/Library/ImagePropertiesRecordLib/UnitTest/ImagePropertiesRecordLibUnitTestHost.c
 create mode 100644 MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h
 create mode 100644 MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf
 create mode 100644 MdeModulePkg/Library/ImagePropertiesRecordLib/UnitTest/ImagePropertiesRecordLibUnitTestHost.inf

-- 
2.41.0.windows.3



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107586): https://edk2.groups.io/g/devel/message/107586
Mute This Topic: https://groups.io/mt/100553430/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 24+ messages in thread
* [edk2-devel] [PATCH v4 00/14] Add ImagePropertiesRecordLib and Fix MAT Bugs
@ 2023-11-03 17:16 Taylor Beebe
  2023-11-03 17:16 ` [edk2-devel] [PATCH v4 05/14] UefiPayloadPkg: Add ImagePropertiesRecordLib Instance Taylor Beebe
  0 siblings, 1 reply; 24+ messages in thread
From: Taylor Beebe @ 2023-11-03 17:16 UTC (permalink / raw)
  To: devel
  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, Liming Gao, Rahul Kumar, Ray Ni,
	Sami Mujawar, Sean Rhodes, Lazlo Ersek

v4:
- Expose additional functions in the Library API
- Add NULL checks to library functions and return a
  status where applicable.

v3:
- Refactor patch series so the transition of logic from the DXE
  MAT logic to the new library is more clear.
- Update function headers to improve clarity and follow EDK2
  standards.
- Add Create and Delete functions for Image Properties Records
  and redirect some of the SMM and DXE MAT code to use these
  functions.
- Update/Add DumpImageRecords() to print the image name and code
  sections of each runtime image which will be put in the MAT.
  The DXE and SMM MAT logic will now invoke the DumpImageRecords()
  on DEBUG builds at the EndOfDxe event to install the MAT.

v2:
- A one-line change in patch 3 was moved to patch 9 for correctness.

Reference: https://github.com/tianocore/edk2/pull/4590
Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=4492

The UEFI and SMM MAT logic contains duplicate logic for manipulating image
properties records which is used to track runtime images.
This patch series adds a new library, ImagePropertiesRecordLib,
which consolidates this logic and fixes the bugs which currently exist in
the MAT logic.

The first patch adds the ImagePropertiesRecordLib implementation which
is a copy of the UEFI MAT logic with minor modifications to remove the
reliance on globabl variables and make the code unit testable.

The second patch adds a unit test for the ImagePropertiesRecordLib. The
logic tests various potential layouts of the EFI memory map and runtime
images. 3/4 of these tests will fail which demonstrates the MAT logic
bugs.

The third patch fixes the logic in the ImagePropertiesRecordLib so
that all of the unit tests pass and the MAT logic can be fixed by
using the library.

The remaining patches add library instances to DSC files and remove
the image properties record logic from the SMM and UEFI MAT logic.

Cc: Andrew Fish <afish@apple.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Guo Dong <guo.dong@intel.com>
Cc: Gua Guo <gua.guo@intel.com>
Cc: James Lu <james.lu@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Sean Rhodes <sean@starlabs.systems>
Cc: Lazlo Ersek <lersek@redhat.com>

Taylor Beebe (14):
  MdeModulePkg: Add ImagePropertiesRecordLib
  ArmVirtPkg: Add ImagePropertiesRecordLib Instance
  EmulatorPkg: Add ImagePropertiesRecordLib Instance
  OvmfPkg: Add ImagePropertiesRecordLib Instance
  UefiPayloadPkg: Add ImagePropertiesRecordLib Instance
  MdeModulePkg: Update MemoryAttributesTable.c to Reduce Global Variable
    Use
  MdeModulePkg: Move Some DXE MAT Logic to ImagePropertiesRecordLib
  MdeModulePkg: Add ImagePropertiesRecordLib Host-Based Unit Test
  MdeModulePkg: Fix Bugs in MAT Logic
  MdeModulePkg: Add NULL checks and Return Status to
    ImagePropertiesRecordLib
  UefiCpuPkg: Use Attribute From SMM MemoryAttributesTable if Nonzero
  MdeModulePkg: Transition SMM MAT Logic to Use ImagePropertiesRecordLib
  MdeModulePkg: Add Logic to Create/Delete Image Properties Records
  MdeModulePkg: Update DumpImageRecord() in ImagePropertiesRecordLib

 MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c                                              |  967 +----------------
 MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c                                                   |   24 +-
 MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c                                             |  958 +---------------
 MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c                        | 1144 ++++++++++++++++++++
 MdeModulePkg/Library/ImagePropertiesRecordLib/UnitTest/ImagePropertiesRecordLibUnitTestHost.c   |  938 ++++++++++++++++
 UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c                                              |   19 +-
 ArmVirtPkg/ArmVirt.dsc.inc                                                                      |    1 +
 EmulatorPkg/EmulatorPkg.dsc                                                                     |    1 +
 MdeModulePkg/Core/Dxe/DxeMain.h                                                                 |   20 -
 MdeModulePkg/Core/Dxe/DxeMain.inf                                                               |    1 +
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf                                                       |    1 +
 MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h                                         |  234 ++++
 MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf                      |   31 +
 MdeModulePkg/Library/ImagePropertiesRecordLib/UnitTest/ImagePropertiesRecordLibUnitTestHost.inf |   35 +
 MdeModulePkg/MdeModulePkg.dec                                                                   |    5 +
 MdeModulePkg/MdeModulePkg.dsc                                                                   |    2 +
 MdeModulePkg/Test/MdeModulePkgHostTest.dsc                                                      |    6 +
 OvmfPkg/AmdSev/AmdSevX64.dsc                                                                    |    1 +
 OvmfPkg/Bhyve/BhyveX64.dsc                                                                      |    1 +
 OvmfPkg/CloudHv/CloudHvX64.dsc                                                                  |    1 +
 OvmfPkg/IntelTdx/IntelTdxX64.dsc                                                                |    1 +
 OvmfPkg/Microvm/MicrovmX64.dsc                                                                  |    1 +
 OvmfPkg/OvmfPkgIa32.dsc                                                                         |    1 +
 OvmfPkg/OvmfPkgIa32X64.dsc                                                                      |    1 +
 OvmfPkg/OvmfPkgX64.dsc                                                                          |    1 +
 OvmfPkg/OvmfXen.dsc                                                                             |    1 +
 OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc                                                             |    1 +
 UefiPayloadPkg/UefiPayloadPkg.dsc                                                               |    1 +
 28 files changed, 2524 insertions(+), 1874 deletions(-)
 create mode 100644 MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c
 create mode 100644 MdeModulePkg/Library/ImagePropertiesRecordLib/UnitTest/ImagePropertiesRecordLibUnitTestHost.c
 create mode 100644 MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h
 create mode 100644 MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf
 create mode 100644 MdeModulePkg/Library/ImagePropertiesRecordLib/UnitTest/ImagePropertiesRecordLibUnitTestHost.inf

-- 
2.42.0.windows.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#110648): https://edk2.groups.io/g/devel/message/110648
Mute This Topic: https://groups.io/mt/102368839/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2023-11-03 17:17 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-04 19:46 [edk2-devel] [PATCH v4 00/14] Add ImagePropertiesRecordLib and Fix MAT Bugs Taylor Beebe
2023-08-04 19:46 ` [edk2-devel] [PATCH v4 01/14] MdeModulePkg: Add ImagePropertiesRecordLib Taylor Beebe
2023-08-04 19:46 ` [edk2-devel] [PATCH v4 02/14] ArmVirtPkg: Add ImagePropertiesRecordLib Instance Taylor Beebe
2023-10-24  0:07   ` Michael D Kinney
2023-08-04 19:46 ` [edk2-devel] [PATCH v4 03/14] EmulatorPkg: " Taylor Beebe
2023-10-24  0:08   ` Michael D Kinney
2023-08-04 19:46 ` [edk2-devel] [PATCH v4 04/14] OvmfPkg: " Taylor Beebe
2023-10-24  0:08   ` Michael D Kinney
2023-10-24  0:45   ` Yao, Jiewen
2023-08-04 19:46 ` [edk2-devel] [PATCH v4 05/14] UefiPayloadPkg: " Taylor Beebe
2023-10-24  0:09   ` Michael D Kinney
2023-10-24  0:11     ` Guo, Gua
2023-08-04 19:46 ` [edk2-devel] [PATCH v4 06/14] MdeModulePkg: Update MemoryAttributesTable.c to Reduce Global Variable Use Taylor Beebe
2023-08-04 19:46 ` [edk2-devel] [PATCH v4 07/14] MdeModulePkg: Move Some DXE MAT Logic to ImagePropertiesRecordLib Taylor Beebe
2023-08-04 19:46 ` [edk2-devel] [PATCH v4 08/14] MdeModulePkg: Add ImagePropertiesRecordLib Host-Based Unit Test Taylor Beebe
2023-08-04 19:46 ` [edk2-devel] [PATCH v4 09/14] MdeModulePkg: Fix Bugs in MAT Logic Taylor Beebe
2023-08-04 19:46 ` [edk2-devel] [PATCH v4 10/14] MdeModulePkg: Add NULL checks and Return Status to ImagePropertiesRecordLib Taylor Beebe
2023-08-04 19:46 ` [edk2-devel] [PATCH v4 11/14] UefiCpuPkg: Use Attribute From SMM MemoryAttributesTable if Nonzero Taylor Beebe
2023-08-04 19:46 ` [edk2-devel] [PATCH v4 12/14] MdeModulePkg: Transition SMM MAT Logic to Use ImagePropertiesRecordLib Taylor Beebe
2023-08-04 19:46 ` [edk2-devel] [PATCH v4 13/14] MdeModulePkg: Add Logic to Create/Delete Image Properties Records Taylor Beebe
2023-08-04 19:46 ` [edk2-devel] [PATCH v4 14/14] MdeModulePkg: Update DumpImageRecord() in ImagePropertiesRecordLib Taylor Beebe
     [not found] ` <177845D23ACA42F9.19347@groups.io>
2023-11-01 20:11   ` [edk2-devel] [PATCH v4 11/14] UefiCpuPkg: Use Attribute From SMM MemoryAttributesTable if Nonzero Taylor Beebe
2023-11-02 11:33     ` Laszlo Ersek
  -- strict thread matches above, loose matches on Subject: below --
2023-11-03 17:16 [edk2-devel] [PATCH v4 00/14] Add ImagePropertiesRecordLib and Fix MAT Bugs Taylor Beebe
2023-11-03 17:16 ` [edk2-devel] [PATCH v4 05/14] UefiPayloadPkg: Add ImagePropertiesRecordLib Instance Taylor Beebe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox