__split_large_page() returns 1 when it encounters an unexpected level, or when another CPU split the large page first.
split_large_page() frees the page table and returns 0 in both cases, and __change_page_attr() looks the address up and tries again. For an unexpected level it tries forever. Getting there would be a bug, because no mappings ever use P4D leaves. Still, a level CPA cannot split should fail the request rather than loop. Return -EINVAL for an unexpected level and pass it up to the caller. Signed-off-by: Mike Rapoport (Microsoft) <[email protected]> --- arch/x86/mm/pat/set_memory.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index db41f94f2355..217c739371ee 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -1178,7 +1178,7 @@ __split_large_page(struct cpa_data *cpa, pte_t *kpte, unsigned long address, break; default: - return 1; + return -EINVAL; } ref_prot = pgprot_clear_protnone_bits(ref_prot); @@ -1230,6 +1230,7 @@ static int split_large_page(struct cpa_data *cpa, pte_t *kpte, unsigned long address) { pte_t *pte; + int ret; spin_unlock(&cpa_lock); if (cpa->init_mm_read_locked) @@ -1241,8 +1242,11 @@ static int split_large_page(struct cpa_data *cpa, pte_t *kpte, if (!pte) return -ENOMEM; - if (__split_large_page(cpa, kpte, address, pte)) + ret = __split_large_page(cpa, kpte, address, pte); + if (ret) pte_free_kernel(&init_mm, pte); + if (ret < 0) + return ret; return 0; } -- 2.53.0
