[edk2-devel] [PATCH v2 0/3] XCODE5 toolchain binary patching fix

Lendacky, Thomas posted 3 patches 3 years, 11 months ago
Failed in applying to current master (apply log)
There is a newer version of this series
OvmfPkg/OvmfPkgIa32.dsc                       |   4 +
OvmfPkg/OvmfPkgIa32X64.dsc                    |   4 +
OvmfPkg/OvmfPkgX64.dsc                        |   4 +
OvmfPkg/OvmfXen.dsc                           |   4 +
UefiCpuPkg/UefiCpuPkg.dsc                     |   5 +
.../DxeCpuExceptionHandlerLib.inf             |   2 +-
.../PeiCpuExceptionHandlerLib.inf             |   2 +-
.../SmmCpuExceptionHandlerLib.inf             |   2 +-
.../Xcode5SecPeiCpuExceptionHandlerLib.inf    |  54 +++
.../X64/ExceptionHandlerAsm.nasm              |  25 +-
.../X64/Xcode5ExceptionHandlerAsm.nasm        | 396 ++++++++++++++++++
.../Xcode5SecPeiCpuExceptionHandlerLib.uni    |  17 +
12 files changed, 497 insertions(+), 22 deletions(-)
create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf
create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm
create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.uni
[edk2-devel] [PATCH v2 0/3] XCODE5 toolchain binary patching fix
Posted by Lendacky, Thomas 3 years, 11 months ago
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2340

Commit 2db0ccc2d7fe ("UefiCpuPkg: Update CpuExceptionHandlerLib pass
XCODE5 tool chain") introduced binary patching in the
ExceptionHandlerAsm.nasm in order to support the XCODE5 toolchain.
However, the CpuExceptionHandlerLib can be used during SEC phase which
would result in binary patching of flash.

This series creates a new CpuExceptionHandlerLib file to support
the required binary patching for the XCODE5 toolchain, while reverting
the changes from commit 2db0ccc2d7fe in the standard file. As the Pei,
Dxe and SMM versions of the library operate in memory (as opposed to
flash), only the SEC/PEI version is of the library is updated to use the
version of the ExceptionHandlerAsm.nasm that does not perform binary
patching.

This is accomplished in phases:
  - Create a new XCODE5 specific version of the ExceptionHandlerAsm.nasm
    file and update all CpuExceptionHandler INF files to use it while also
    creating a new SEC/PEI CpuExceptionHandler INF file specifically for
    the XCODE5 toolchain.
  - Update all package DSC files that use the SecPeiCpuExceptionHandlerLib
    version of the library to use the XCODE5 version of the library,
    Xcode5SecPeiCpuExceptionHandlerLib, when the XCODE5 toolchain is used.
  - Revert the changes made by commit 2db0ccc2d7fe in the standard file
    and update the SecPeiCpuExceptionHandlerLib.inf file to use the
    standard file.

I don't have access to an XCODE5 toolchain setup, so I have not tested
this with XCODE5. I would like to request that someone who does please
test this.

Also, will this change have an impact on any of the platform builds
outside of this tree? In other words, should the new INF be the one that
uses the reverted ExceptionHandlerAsm.nasm file and it be called something
like BaseSecPeiCpuExceptionHandlerLib.inf?

---

These patches are based on commit:
befd18fca68b ("EmbeddedPkg/EmbeddedPkg.dsc: remove some stale component references")

Cc: Andrew Fish <afish@apple.com>
Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Julien Grall <julien@xen.org>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Ray Ni <ray.ni@intel.com>

Changes since v1:
- Only apply the revert to the Sec/Pei CpuExceptionHandler library and
  leave the Pei, Dxe and Smm versions using the binary patching version.
- Generate a unique file GUID for the new library INF file and create
  a corresponding UNI file.
- Remove any references to SEV-ES (original patches accidentally submitted
  from wrong tree).

Tom Lendacky (3):
  UefiCpuPkg/CpuExceptionHandler: Make XCODE5 changes toolchain specific
  OvmfPkg: Use toolchain appropriate CpuExceptionHandlerLib
  UefiCpuPkg/CpuExceptionHandler: Revert CpuExceptionHandler binary
    patching

 OvmfPkg/OvmfPkgIa32.dsc                       |   4 +
 OvmfPkg/OvmfPkgIa32X64.dsc                    |   4 +
 OvmfPkg/OvmfPkgX64.dsc                        |   4 +
 OvmfPkg/OvmfXen.dsc                           |   4 +
 UefiCpuPkg/UefiCpuPkg.dsc                     |   5 +
 .../DxeCpuExceptionHandlerLib.inf             |   2 +-
 .../PeiCpuExceptionHandlerLib.inf             |   2 +-
 .../SmmCpuExceptionHandlerLib.inf             |   2 +-
 .../Xcode5SecPeiCpuExceptionHandlerLib.inf    |  54 +++
 .../X64/ExceptionHandlerAsm.nasm              |  25 +-
 .../X64/Xcode5ExceptionHandlerAsm.nasm        | 396 ++++++++++++++++++
 .../Xcode5SecPeiCpuExceptionHandlerLib.uni    |  17 +
 12 files changed, 497 insertions(+), 22 deletions(-)
 create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf
 create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm
 create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.uni

-- 
2.17.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#58719): https://edk2.groups.io/g/devel/message/58719
Mute This Topic: https://groups.io/mt/74032330/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH v2 0/3] XCODE5 toolchain binary patching fix
Posted by Laszlo Ersek 3 years, 11 months ago
On 05/06/20 18:32, Tom Lendacky wrote:
>
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2340
>
> Commit 2db0ccc2d7fe ("UefiCpuPkg: Update CpuExceptionHandlerLib pass
> XCODE5 tool chain") introduced binary patching in the
> ExceptionHandlerAsm.nasm in order to support the XCODE5 toolchain.
> However, the CpuExceptionHandlerLib can be used during SEC phase which
> would result in binary patching of flash.
>
> This series creates a new CpuExceptionHandlerLib file to support the
> required binary patching for the XCODE5 toolchain, while reverting the
> changes from commit 2db0ccc2d7fe in the standard file. As the Pei, Dxe
> and SMM versions of the library operate in memory (as opposed to
> flash), only the SEC/PEI version is of the library is updated to use
> the version of the ExceptionHandlerAsm.nasm that does not perform
> binary patching.
>
> This is accomplished in phases:
>   - Create a new XCODE5 specific version of the
>     ExceptionHandlerAsm.nasm file and update all CpuExceptionHandler
>     INF files to use it while also creating a new SEC/PEI
>     CpuExceptionHandler INF file specifically for the XCODE5
>     toolchain.
>   - Update all package DSC files that use the
>     SecPeiCpuExceptionHandlerLib version of the library to use the
>     XCODE5 version of the library, Xcode5SecPeiCpuExceptionHandlerLib,
>     when the XCODE5 toolchain is used.
>   - Revert the changes made by commit 2db0ccc2d7fe in the standard
>     file and update the SecPeiCpuExceptionHandlerLib.inf file to use
>     the standard file.
>
> I don't have access to an XCODE5 toolchain setup, so I have not tested
> this with XCODE5. I would like to request that someone who does please
> test this.
>
> Also, will this change have an impact on any of the platform builds
> outside of this tree?

This series takes care of all the "SecPeiCpuExceptionHandlerLib.inf"
occurrences in edk2.

Regarding edk2-platforms, with master being at 644e223bb371
("Platform/RaspberryPi: create DXE phase SerialPortLib version for
RPi3", 2020-05-06):

$ git grep -l \
      'UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf'

Platform/Intel/MinPlatformPkg/Include/Dsc/CorePeiLib.dsc
Platform/Intel/QuarkPlatformPkg/Quark.dsc
Platform/Intel/QuarkPlatformPkg/QuarkMin.dsc
Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc
Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc

I don't know what's best for these platforms: an XCODE5-compatible
source code that does the wrong thing when run from flash, or an
XCODE5-incompatible source code that does the right thing.

If all of these platforms lived in edk2 proper, I would suggest
inserting patches for them just before patch#3 in this series --
similarly to your OvmfPkg patch. But, these platforms live outside of
edk2, and I don't know if they are ever built with XCODE5...

... You could propose a separate edk2-platforms series:

Platform/Intel/MinPlatformPkg/Include/Dsc/CorePeiLib.dsc
  Chasel Chiu <chasel.chiu@intel.com>
  Nate DeSimone <nathaniel.l.desimone@intel.com>
  Liming Gao <liming.gao@intel.com>

Platform/Intel/QuarkPlatformPkg/Quark.dsc
  Michael D Kinney <michael.d.kinney@intel.com>
  Kelly Steele <kelly.steele@intel.com>

Platform/Intel/QuarkPlatformPkg/QuarkMin.dsc
  Michael D Kinney <michael.d.kinney@intel.com>
  Kelly Steele <kelly.steele@intel.com>

Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc
  Zailiang Sun <zailiang.sun@intel.com>
  Yi Qian <yi.qian@intel.com>

Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc
  Zailiang Sun <zailiang.sun@intel.com>
  Yi Qian <yi.qian@intel.com>

and we could then delay just the pushing of patch#3 in this series until
the edk2-platforms patches have been merged too.

> In other words, should the new INF be the one that uses the reverted
> ExceptionHandlerAsm.nasm file and it be called something like
> BaseSecPeiCpuExceptionHandlerLib.inf?

Keeping the current (= self-patching) logic associated with the current
filename ("SecPeiCpuExceptionHandlerLib.inf") would certainly eliminate
the headache about out-of-tree platforms. But it would also mean we'd
have to use a special prefix for the *non-broken* SEC INF file. And that
irks me quite a bit. The quirk is in the patching variant, and IMO that
should be reflected by the file name.

Thanks
Laszlo


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#58743): https://edk2.groups.io/g/devel/message/58743
Mute This Topic: https://groups.io/mt/74032330/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-