x86/mm/cpa: Fix populate_pgd(): Stop trying to deallocate failed PUDs
[cascardo/linux.git] / arch / x86 / mm / pageattr.c
index 7a1f7bb..2bc6ea1 100644 (file)
@@ -746,18 +746,6 @@ static bool try_to_free_pmd_page(pmd_t *pmd)
        return true;
 }
 
-static bool try_to_free_pud_page(pud_t *pud)
-{
-       int i;
-
-       for (i = 0; i < PTRS_PER_PUD; i++)
-               if (!pud_none(pud[i]))
-                       return false;
-
-       free_page((unsigned long)pud);
-       return true;
-}
-
 static bool unmap_pte_range(pmd_t *pmd, unsigned long start, unsigned long end)
 {
        pte_t *pte = pte_offset_kernel(pmd, start);
@@ -871,16 +859,6 @@ static void unmap_pud_range(pgd_t *pgd, unsigned long start, unsigned long end)
         */
 }
 
-static void unmap_pgd_range(pgd_t *root, unsigned long addr, unsigned long end)
-{
-       pgd_t *pgd_entry = root + pgd_index(addr);
-
-       unmap_pud_range(pgd_entry, addr, end);
-
-       if (try_to_free_pud_page((pud_t *)pgd_page_vaddr(*pgd_entry)))
-               pgd_clear(pgd_entry);
-}
-
 static int alloc_pte_page(pmd_t *pmd)
 {
        pte_t *pte = (pte_t *)get_zeroed_page(GFP_KERNEL | __GFP_NOTRACK);
@@ -1113,7 +1091,7 @@ static int populate_pgd(struct cpa_data *cpa, unsigned long addr)
 
        ret = populate_pud(cpa, addr, pgd_entry, pgprot);
        if (ret < 0) {
-               unmap_pgd_range(cpa->pgd, addr,
+               unmap_pud_range(pgd_entry, addr,
                                addr + (cpa->numpages << PAGE_SHIFT));
                return ret;
        }
@@ -1185,7 +1163,7 @@ repeat:
                return __cpa_process_fault(cpa, address, primary);
 
        old_pte = *kpte;
-       if (!pte_val(old_pte))
+       if (pte_none(old_pte))
                return __cpa_process_fault(cpa, address, primary);
 
        if (level == PG_LEVEL_4K) {
@@ -1991,12 +1969,6 @@ out:
        return retval;
 }
 
-void kernel_unmap_pages_in_pgd(pgd_t *root, unsigned long address,
-                              unsigned numpages)
-{
-       unmap_pgd_range(root, address, address + (numpages << PAGE_SHIFT));
-}
-
 /*
  * The testcases use internal knowledge of the implementation that shouldn't
  * be exposed to the rest of the kernel. Include these directly here.