Skip to contentSkip to conversation

ArmVirtPkg/ArmVirtQemu: always build XIP code with strict alignment

PATCH In review Ard Biesheuvel 2 participants 2 messages Apr 19, 2024 – Apr 22, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ArmVirtPkg/ArmVirtQemu: always build XIP code with strict alignment

From: Ard Biesheuvel <[email protected]>

The optimization that enabled entry with MMU and caches enabled at EL1 removed the strict alignment requirement for XIP code (roughly, any code that might execute with the MMU and caches off, which means SEC and PEI phase modules but also *all* BASE libraries), on the basis that QEMU can only run guest payloads at EL2 in TCG emulation, which used to ignore alignment violations, and execution at EL1 would always occur with the MMU enabled.

This assumption no longer holds: not only does QEMU now enforce strict alignment for memory accesses with device semantics, there are also cases where this code might execute at EL2 under virtualization (i.e., under NV2 nested virtualization) where the strict alignment is required too.

The latter case could be optimized too, by enabling VHE and pretending execution is occurring at EL1, which would allow the existing logic for entry with the MMU enabled to be reused. However, this would leave non-VHE CPUs behind.

So in summary, strict alignment needs to be enforced for any code that may execute with the MMU off, so drop the override that sets the XIP flags to the empty string.

Cc Jonathan Cameron <[email protected]>
Cc Richard Henderson <[email protected]>
Cc Philippe Mathieu-Daud� <[email protected]>
Cc Idan Horowitz <[email protected]>
---
 ArmVirtPkg/ArmVirtQemu.dsc | 2 --
 1 file changed, 2 deletions(-)
ArmVirtPkg/ArmVirtQemu.dsc +0 -1
index e48c75b5e99f..f6f78359552d 100644
@@ -124,8 +124,6 @@ [LibraryClasses.common.UEFI_DRIVER]
 [BuildOptions]
 
 !if $(CAVIUM_ERRATUM_27456) == TRUE
 
   GCC:*_*_AARCH64_PP_FLAGS = -DCAVIUM_ERRATUM_27456
 
-!else

- GCC:*_*_AARCH64_CC_XIPFLAGS ==

!endif

!include NetworkPkg/NetworkBuildOptions.dsc.inc

--
2.44.0.769.g3c40516874-goog

Tested-by Jonathan Cameron Reviewed-by Jonathan Cameron on v1 1/1
#1 lore raw
Quoted 25 lines · On Fri, 19 Apr 2024 19:50:13 +0200 Ard Biesheuvel <[email protected]> wrote:

From: Ard Biesheuvel <[email protected]>

The optimization that enabled entry with MMU and caches enabled at EL1 removed the strict alignment requirement for XIP code (roughly, any code that might execute with the MMU and caches off, which means SEC and PEI phase modules but also *all* BASE libraries), on the basis that QEMU can only run guest payloads at EL2 in TCG emulation, which used to ignore alignment violations, and execution at EL1 would always occur with the MMU enabled.

This assumption no longer holds: not only does QEMU now enforce strict alignment for memory accesses with device semantics, there are also cases where this code might execute at EL2 under virtualization (i.e., under NV2 nested virtualization) where the strict alignment is required too.

The latter case could be optimized too, by enabling VHE and pretending execution is occurring at EL1, which would allow the existing logic for entry with the MMU enabled to be reused. However, this would leave non-VHE CPUs behind.

So in summary, strict alignment needs to be enforced for any code that may execute with the MMU off, so drop the override that sets the XIP flags to the empty string.

Quoted 6 lines
Cc Jonathan Cameron <[email protected]>
Cc Richard Henderson <[email protected]>
Cc Philippe Mathieu-Daud� <[email protected]>
Cc Idan Horowitz <[email protected]>

This matches what I was testing with locally. Thanks sorting this out.

Quoted 28 lines
---
 ArmVirtPkg/ArmVirtQemu.dsc | 2 --
 1 file changed, 2 deletions(-)
ArmVirtPkg/ArmVirtQemu.dsc +0 -3
index e48c75b5e99f..f6f78359552d 100644
@@ -124,8 +124,6 @@ [LibraryClasses.common.UEFI_DRIVER]
 [BuildOptions]
 
 !if $(CAVIUM_ERRATUM_27456) == TRUE
 
   GCC:*_*_AARCH64_PP_FLAGS = -DCAVIUM_ERRATUM_27456
 
-!else
 
-  GCC:*_*_AARCH64_CC_XIPFLAGS ==
 
 !endif
 
 
 
 !include NetworkPkg/NetworkBuildOptions.dsc.inc
 
--

2.44.0.769.g3c40516874-goog