ArmPkg/ArmMmuLib: ASSERT ArmReplaceLiveTranslationEntry alignment

This commit is contained in:
Marvin Häuser 2023-04-11 09:47:52 +02:00 committed by Mikhail Krichanov
parent 079070c748
commit c82eacb202
2 changed files with 22 additions and 2 deletions

View File

@ -738,12 +738,22 @@ ArmMmuBaseLibConstructor (
) )
{ {
extern UINT32 ArmReplaceLiveTranslationEntrySize; extern UINT32 ArmReplaceLiveTranslationEntrySize;
UINTN ArmReplaceLiveTranslationEntryEnd;
VOID *Hob; VOID *Hob;
Hob = GetFirstGuidHob (&gArmMmuReplaceLiveTranslationEntryFuncGuid); Hob = GetFirstGuidHob (&gArmMmuReplaceLiveTranslationEntryFuncGuid);
if (Hob != NULL) { if (Hob != NULL) {
mReplaceLiveEntryFunc = *(VOID **)GET_GUID_HOB_DATA (Hob); mReplaceLiveEntryFunc = *(VOID **)GET_GUID_HOB_DATA (Hob);
} else { } else {
ArmReplaceLiveTranslationEntryEnd = (UINTN)ArmReplaceLiveTranslationEntry + ArmReplaceLiveTranslationEntrySize;
//
// Align this routine to a log2 upper bound of its size, so that it is
// guaranteed not to cross a page or block boundary
// (see ArmMmuLibReplaceEntry.S).
//
ASSERT (IS_ALIGNED ((UINTN)ArmReplaceLiveTranslationEntry, 0x200));
ASSERT (((UINTN)ArmReplaceLiveTranslationEntry >> EFI_PAGE_SHIFT) == ((ArmReplaceLiveTranslationEntryEnd - 1) >> EFI_PAGE_SHIFT));
// //
// The ArmReplaceLiveTranslationEntry () helper function may be invoked // The ArmReplaceLiveTranslationEntry () helper function may be invoked
// with the MMU off so we have to ensure that it gets cleaned to the PoC // with the MMU off so we have to ensure that it gets cleaned to the PoC

View File

@ -23,6 +23,7 @@ ArmMmuPeiLibConstructor (
{ {
extern UINT32 ArmReplaceLiveTranslationEntrySize; extern UINT32 ArmReplaceLiveTranslationEntrySize;
VOID *ArmReplaceLiveTranslationEntryFunc; VOID *ArmReplaceLiveTranslationEntryFunc;
UINTN ArmReplaceLiveTranslationEntryEnd;
VOID *Hob; VOID *Hob;
EFI_FV_FILE_INFO FileInfo; EFI_FV_FILE_INFO FileInfo;
@ -30,6 +31,16 @@ ArmMmuPeiLibConstructor (
ASSERT (FileHandle != NULL); ASSERT (FileHandle != NULL);
ArmReplaceLiveTranslationEntryEnd = (UINTN)ArmReplaceLiveTranslationEntry + ArmReplaceLiveTranslationEntrySize;
//
// Align this routine to a log2 upper bound of its size, so that it is
// guaranteed not to cross a page or block boundary
// (see ArmMmuLibReplaceEntry.S).
//
ASSERT (IS_ALIGNED ((UINTN)ArmReplaceLiveTranslationEntry, 0x200));
ASSERT (((UINTN)ArmReplaceLiveTranslationEntry >> EFI_PAGE_SHIFT) == ((ArmReplaceLiveTranslationEntryEnd - 1) >> EFI_PAGE_SHIFT));
Status = (*PeiServices)->FfsGetFileInfo (FileHandle, &FileInfo); Status = (*PeiServices)->FfsGetFileInfo (FileHandle, &FileInfo);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
@ -41,8 +52,7 @@ ArmMmuPeiLibConstructor (
// when not executing in place. // when not executing in place.
// //
if (((UINTN)FileInfo.Buffer <= (UINTN)ArmReplaceLiveTranslationEntry) && if (((UINTN)FileInfo.Buffer <= (UINTN)ArmReplaceLiveTranslationEntry) &&
((UINTN)FileInfo.Buffer + FileInfo.BufferSize >= ((UINTN)FileInfo.Buffer + FileInfo.BufferSize >= ArmReplaceLiveTranslationEntryEnd))
(UINTN)ArmReplaceLiveTranslationEntry + ArmReplaceLiveTranslationEntrySize))
{ {
DEBUG ((DEBUG_INFO, "ArmMmuLib: skipping cache maintenance on XIP PEIM\n")); DEBUG ((DEBUG_INFO, "ArmMmuLib: skipping cache maintenance on XIP PEIM\n"));