efi/x86: Free efi_pgd with free_pages()
Commitd9e9a64180
("x86/mm/pti: Allocate a separate user PGD") changed the PGD allocation to allocate PGD_ALLOCATION_ORDER pages, so in the error path it should be freed using free_pages() rather than free_page(). Commit06ace26f4e
("x86/efi: Free efi_pgd with free_pages()") fixed one instance of this, but missed another. Move the freeing out-of-line to avoid code duplication and fix this bug. Fixes:d9e9a64180
("x86/mm/pti: Allocate a separate user PGD") Link: https://lore.kernel.org/r/20201110163919.1134431-1-nivedita@alum.mit.edu Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
This commit is contained in:
parent
fe5186cf12
commit
c2fe61d8be
|
@ -78,28 +78,30 @@ int __init efi_alloc_page_tables(void)
|
||||||
gfp_mask = GFP_KERNEL | __GFP_ZERO;
|
gfp_mask = GFP_KERNEL | __GFP_ZERO;
|
||||||
efi_pgd = (pgd_t *)__get_free_pages(gfp_mask, PGD_ALLOCATION_ORDER);
|
efi_pgd = (pgd_t *)__get_free_pages(gfp_mask, PGD_ALLOCATION_ORDER);
|
||||||
if (!efi_pgd)
|
if (!efi_pgd)
|
||||||
return -ENOMEM;
|
goto fail;
|
||||||
|
|
||||||
pgd = efi_pgd + pgd_index(EFI_VA_END);
|
pgd = efi_pgd + pgd_index(EFI_VA_END);
|
||||||
p4d = p4d_alloc(&init_mm, pgd, EFI_VA_END);
|
p4d = p4d_alloc(&init_mm, pgd, EFI_VA_END);
|
||||||
if (!p4d) {
|
if (!p4d)
|
||||||
free_page((unsigned long)efi_pgd);
|
goto free_pgd;
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
pud = pud_alloc(&init_mm, p4d, EFI_VA_END);
|
pud = pud_alloc(&init_mm, p4d, EFI_VA_END);
|
||||||
if (!pud) {
|
if (!pud)
|
||||||
if (pgtable_l5_enabled())
|
goto free_p4d;
|
||||||
free_page((unsigned long) pgd_page_vaddr(*pgd));
|
|
||||||
free_pages((unsigned long)efi_pgd, PGD_ALLOCATION_ORDER);
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
efi_mm.pgd = efi_pgd;
|
efi_mm.pgd = efi_pgd;
|
||||||
mm_init_cpumask(&efi_mm);
|
mm_init_cpumask(&efi_mm);
|
||||||
init_new_context(NULL, &efi_mm);
|
init_new_context(NULL, &efi_mm);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
free_p4d:
|
||||||
|
if (pgtable_l5_enabled())
|
||||||
|
free_page((unsigned long)pgd_page_vaddr(*pgd));
|
||||||
|
free_pgd:
|
||||||
|
free_pages((unsigned long)efi_pgd, PGD_ALLOCATION_ORDER);
|
||||||
|
fail:
|
||||||
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue