On 9 September 2015 at 11:53, Heyi Guo <[email protected]> wrote:
> The code has a simple bug on calculating aligned page table address.
> We can just use AllocateAlignedPages in MemoryAllocationLib instead.
>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Heyi Guo <[email protected]>
> Cc: Leif Lindholm <[email protected]>
> Cc: Ard Biesheuvel <[email protected]>

Reviewed-by: Ard Biesheuvel <[email protected]>

> ---
>  ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c 
> b/ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c
> index 3d58d5d..b84f42a 100644
> --- a/ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c
> +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c
> @@ -377,11 +377,10 @@ GetBlockEntryListFromAddress (
>          }
>
>          // Create a new translation table
> -        TranslationTable = (UINT64*)AllocatePages 
> (EFI_SIZE_TO_PAGES((TT_ENTRY_COUNT * sizeof(UINT64)) + 
> TT_ALIGNMENT_DESCRIPTION_TABLE));
> +        TranslationTable = (UINT64*)AllocateAlignedPages 
> (EFI_SIZE_TO_PAGES(TT_ENTRY_COUNT * sizeof(UINT64)), 
> TT_ALIGNMENT_DESCRIPTION_TABLE);
>          if (TranslationTable == NULL) {
>            return NULL;
>          }
> -        TranslationTable = (UINT64*)((UINTN)TranslationTable & 
> TT_ADDRESS_MASK_DESCRIPTION_TABLE);
>
>          // Populate the newly created lower level table
>          SubTableBlockEntry = TranslationTable;
> @@ -405,11 +404,10 @@ GetBlockEntryListFromAddress (
>          //
>
>          // Create a new translation table
> -        TranslationTable = (UINT64*)AllocatePages 
> (EFI_SIZE_TO_PAGES((TT_ENTRY_COUNT * sizeof(UINT64)) + 
> TT_ALIGNMENT_DESCRIPTION_TABLE));
> +        TranslationTable = (UINT64*)AllocateAlignedPages 
> (EFI_SIZE_TO_PAGES(TT_ENTRY_COUNT * sizeof(UINT64)), 
> TT_ALIGNMENT_DESCRIPTION_TABLE);
>          if (TranslationTable == NULL) {
>            return NULL;
>          }
> -        TranslationTable = (UINT64*)((UINTN)TranslationTable & 
> TT_ADDRESS_MASK_DESCRIPTION_TABLE);
>
>          ZeroMem (TranslationTable, TT_ENTRY_COUNT * sizeof(UINT64));
>
> @@ -619,12 +617,11 @@ ArmConfigureMmu (
>    ArmSetTCR (TCR);
>
>    // Allocate pages for translation table
> -  TranslationTablePageCount = EFI_SIZE_TO_PAGES((RootTableEntryCount * 
> sizeof(UINT64)) + TT_ALIGNMENT_DESCRIPTION_TABLE);
> -  TranslationTable = AllocatePages (TranslationTablePageCount);
> +  TranslationTablePageCount = EFI_SIZE_TO_PAGES(RootTableEntryCount * 
> sizeof(UINT64));
> +  TranslationTable = (UINT64*)AllocateAlignedPages 
> (TranslationTablePageCount, TT_ALIGNMENT_DESCRIPTION_TABLE);
>    if (TranslationTable == NULL) {
>      return RETURN_OUT_OF_RESOURCES;
>    }
> -  TranslationTable = (VOID*)((UINTN)TranslationTable & 
> TT_ADDRESS_MASK_DESCRIPTION_TABLE);
>    // We set TTBR0 just after allocating the table to retrieve its location 
> from the subsequent
>    // functions without needing to pass this value across the functions. The 
> MMU is only enabled
>    // after the translation tables are populated.
> --
> 2.5.0
>
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to