mbox series

[edk2,v2,0/5] Abstract allocation of PEI accessible memory

Message ID 20180524090945.10289-1-ard.biesheuvel@linaro.org
Headers show
Series Abstract allocation of PEI accessible memory | expand

Message

Ard Biesheuvel May 24, 2018, 9:09 a.m. UTC
At the moment, FirmwarePerformanceTableDataDxe or DxeCorePerformanceLib
are unusable on systems such as AMD Seattle, because they unconditionally
attempt to allocate memory below 4 GB, and ASSERT() if this fails. On AMD
Seattle, no 32-bit addressable DRAM exists, and so the driver will always
assert, and crash a running DEBUG build.

The reason for this is that some platforms (i.e., X64 builds consisting of
a 32-bit PEI stage and 64-bit remaining stages) require these allocations
to be below 4 GB, and for some reason, open coding this practice throughout
the code without regard for other architectures has been regarded as an
acceptable approach.

Instead, I would like to propose the approach implemented in this series:
- create an abstracted EfiAllocatePeiAccessiblePages() routine in UefiLib
  that simply allocates pages from any region on all architectures except
  X64, and allocate below 4 GB for X64
- update the various call sites with calls to this new function.

The above is implemented in patches #3 - #6. Patches #1 and #2 are fixes
for issues that I observed in ArmVirtPkg and OvmfPkg while working on
these patches.

Code can be found here:
https://github.com/ardbiesheuvel/edk2/tree/allocate-pei-v2

Changes since v1:
- add Laszlo's ack to #1 - #2
- move EfiAllocatePeiPages() to DxeServicesLib and drop Efi prefix
- update implementation to take EfiFreeMemoryTop into account when built
  for X64

Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>

Ard Biesheuvel (5):
  OvmfPkg/PlatformBootManagerLib: add missing report status code call
  ArmVirtPkg/PlatformBootManagerLib: add missing report status code call
  MdePkg/DxeServicesLib: introduce AllocatePeiAccessiblePages routine
  MdeModulePkg/DxeCorePerformanceLib: use AllocatePeiAccessiblePages
  MdeModulePkg/FirmwarePerformanceDataTableDxe: use
    AllocatePeiAccessiblePages

 .../PlatformBootManagerLib.inf                |  1 +
 .../PlatformBootManagerLib/QemuKernel.c       |  4 ++
 .../DxeCorePerformanceLib.c                   | 45 ++-------------
 .../FirmwarePerformanceDxe.c                  | 51 +++--------------
 .../FirmwarePerformanceDxe.inf                |  1 +
 MdePkg/Include/Library/DxeServicesLib.h       | 23 +++++++-
 .../Library/DxeServicesLib/DxeServicesLib.c   | 55 +++++++++++++++++++
 .../Library/DxeServicesLib/DxeServicesLib.inf |  3 +
 .../PlatformBootManagerLib.inf                |  1 +
 .../PlatformBootManagerLib/QemuKernel.c       |  4 ++
 10 files changed, 104 insertions(+), 84 deletions(-)

-- 
2.17.0

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Comments

Kinney, Michael D May 24, 2018, 4:57 p.m. UTC | #1
Ard,

Thanks for the update.  This looks really close.

One comment is on the use of #ifdef MDE_CPU_X64
in a C file.

In general, the #ifdef for a specific type of CPU
should be limited to .h files and we should split
out CPU specific sources into their own source
files and use the INF file [Sources.<arch>] to
list the CPU specific source files.

Only other minor comment is that the summary still
mentions adding the new API to the UefiLib.

Mike


> -----Original Message-----

> From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]

> Sent: Thursday, May 24, 2018 2:10 AM

> To: edk2-devel@lists.01.org

> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>; Laszlo

> Ersek <lersek@redhat.com>; Leif Lindholm

> <leif.lindholm@linaro.org>; Kinney, Michael D

> <michael.d.kinney@intel.com>; Gao, Liming

> <liming.gao@intel.com>; Zeng, Star

> <star.zeng@intel.com>; Dong, Eric <eric.dong@intel.com>;

> Bi, Dandan <dandan.bi@intel.com>

> Subject: [PATCH v2 0/5] Abstract allocation of PEI

> accessible memory

> 

> At the moment, FirmwarePerformanceTableDataDxe or

> DxeCorePerformanceLib

> are unusable on systems such as AMD Seattle, because

> they unconditionally

> attempt to allocate memory below 4 GB, and ASSERT() if

> this fails. On AMD

> Seattle, no 32-bit addressable DRAM exists, and so the

> driver will always

> assert, and crash a running DEBUG build.

> 

> The reason for this is that some platforms (i.e., X64

> builds consisting of

> a 32-bit PEI stage and 64-bit remaining stages) require

> these allocations

> to be below 4 GB, and for some reason, open coding this

> practice throughout

> the code without regard for other architectures has been

> regarded as an

> acceptable approach.

> 

> Instead, I would like to propose the approach

> implemented in this series:

> - create an abstracted EfiAllocatePeiAccessiblePages()

> routine in UefiLib

>   that simply allocates pages from any region on all

> architectures except

>   X64, and allocate below 4 GB for X64

> - update the various call sites with calls to this new

> function.

> 

> The above is implemented in patches #3 - #6. Patches #1

> and #2 are fixes

> for issues that I observed in ArmVirtPkg and OvmfPkg

> while working on

> these patches.

> 

> Code can be found here:

> https://github.com/ardbiesheuvel/edk2/tree/allocate-pei-

> v2

> 

> Changes since v1:

> - add Laszlo's ack to #1 - #2

> - move EfiAllocatePeiPages() to DxeServicesLib and drop

> Efi prefix

> - update implementation to take EfiFreeMemoryTop into

> account when built

>   for X64

> 

> Cc: Laszlo Ersek <lersek@redhat.com>

> Cc: Leif Lindholm <leif.lindholm@linaro.org>

> Cc: Michael D Kinney <michael.d.kinney@intel.com>

> Cc: Liming Gao <liming.gao@intel.com>

> Cc: Star Zeng <star.zeng@intel.com>

> Cc: Eric Dong <eric.dong@intel.com>

> Cc: Dandan Bi <dandan.bi@intel.com>

> 

> Ard Biesheuvel (5):

>   OvmfPkg/PlatformBootManagerLib: add missing report

> status code call

>   ArmVirtPkg/PlatformBootManagerLib: add missing report

> status code call

>   MdePkg/DxeServicesLib: introduce

> AllocatePeiAccessiblePages routine

>   MdeModulePkg/DxeCorePerformanceLib: use

> AllocatePeiAccessiblePages

>   MdeModulePkg/FirmwarePerformanceDataTableDxe: use

>     AllocatePeiAccessiblePages

> 

>  .../PlatformBootManagerLib.inf                |  1 +

>  .../PlatformBootManagerLib/QemuKernel.c       |  4 ++

>  .../DxeCorePerformanceLib.c                   | 45 ++--

> -----------

>  .../FirmwarePerformanceDxe.c                  | 51 +++-

> -------------

>  .../FirmwarePerformanceDxe.inf                |  1 +

>  MdePkg/Include/Library/DxeServicesLib.h       | 23

> +++++++-

>  .../Library/DxeServicesLib/DxeServicesLib.c   | 55

> +++++++++++++++++++

>  .../Library/DxeServicesLib/DxeServicesLib.inf |  3 +

>  .../PlatformBootManagerLib.inf                |  1 +

>  .../PlatformBootManagerLib/QemuKernel.c       |  4 ++

>  10 files changed, 104 insertions(+), 84 deletions(-)

> 

> --

> 2.17.0


_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel