diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c index 1e57e58997..2701e07e97 100644 --- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c @@ -738,12 +738,22 @@ ArmMmuBaseLibConstructor ( ) { extern UINT32 ArmReplaceLiveTranslationEntrySize; + UINTN ArmReplaceLiveTranslationEntryEnd; VOID *Hob; Hob = GetFirstGuidHob (&gArmMmuReplaceLiveTranslationEntryFuncGuid); if (Hob != NULL) { mReplaceLiveEntryFunc = *(VOID **)GET_GUID_HOB_DATA (Hob); } 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 // with the MMU off so we have to ensure that it gets cleaned to the PoC diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuPeiLibConstructor.c b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuPeiLibConstructor.c index 5f50a605a3..e32d73f594 100644 --- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuPeiLibConstructor.c +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuPeiLibConstructor.c @@ -23,6 +23,7 @@ ArmMmuPeiLibConstructor ( { extern UINT32 ArmReplaceLiveTranslationEntrySize; VOID *ArmReplaceLiveTranslationEntryFunc; + UINTN ArmReplaceLiveTranslationEntryEnd; VOID *Hob; EFI_FV_FILE_INFO FileInfo; @@ -30,6 +31,16 @@ ArmMmuPeiLibConstructor ( 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); ASSERT_EFI_ERROR (Status); @@ -41,8 +52,7 @@ ArmMmuPeiLibConstructor ( // when not executing in place. // if (((UINTN)FileInfo.Buffer <= (UINTN)ArmReplaceLiveTranslationEntry) && - ((UINTN)FileInfo.Buffer + FileInfo.BufferSize >= - (UINTN)ArmReplaceLiveTranslationEntry + ArmReplaceLiveTranslationEntrySize)) + ((UINTN)FileInfo.Buffer + FileInfo.BufferSize >= ArmReplaceLiveTranslationEntryEnd)) { DEBUG ((DEBUG_INFO, "ArmMmuLib: skipping cache maintenance on XIP PEIM\n"));