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 3aee8784da
commit 584d13a2eb
2 changed files with 22 additions and 2 deletions

View File

@ -731,12 +731,22 @@ ArmMmuBaseLibConstructor (
)
{
extern UINT32 ArmReplaceLiveTranslationEntrySize;
UINTN ArmReplaceLiveTranslationEntryEnd;
VOID *Hob;
Hob = GetFirstGuidHob (&gArmMmuReplaceLiveTranslationEntryFuncGuid);
if (Hob != NULL) {
mReplaceLiveEntryFunc = *(ARM_REPLACE_LIVE_TRANSLATION_ENTRY *)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

View File

@ -24,6 +24,7 @@ ArmMmuPeiLibConstructor (
{
extern UINT32 ArmReplaceLiveTranslationEntrySize;
ARM_REPLACE_LIVE_TRANSLATION_ENTRY ArmReplaceLiveTranslationEntryFunc;
UINTN ArmReplaceLiveTranslationEntryEnd;
VOID *Hob;
EFI_FV_FILE_INFO FileInfo;
@ -31,6 +32,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);
@ -42,8 +53,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"));