From nobody Sat Apr 4 06:08:07 2026 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9381E3E6DDB for ; Fri, 20 Mar 2026 18:23:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774031021; cv=none; b=dCKr3d+iobS6F+gowLHYepSqWUbwK7hwlvPb/KTzfcJ9DZcAf7Dzp9SkU4v9otovK4VzIYlAxkRgzrWXdQTyWS6aWhM16I8DemHsfJmFMo6On6/iIQ7p7a//lgcbNQ1BxtzIDW2PjJQxtgr5i5zE/lKqQPcohub0yy928YcUweg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774031021; c=relaxed/simple; bh=jelsogJBzN8xdAQ/OvSk5lfPtRJSgoM9AIUj11KW2Wc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fUkbaO8D2/g+GBeTFKC2/LlQaT3EHNtt6ELALZjce3kdz77lXciB6XHkRXgEMu/0rRGrkBXxv/1JxBvk2f/hkRPK/ONKUdgAo3yd1HCHUGxP8NkTfraGsPNSAsfj0z/pjxdmJf4RWYFoPMlpHet0RhurBpq1kdPZ6aWnoXIFvHU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=qPowagmh; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qPowagmh" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-439c54e0f6aso1593255f8f.0 for ; Fri, 20 Mar 2026 11:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774031018; x=1774635818; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=VrqRFYhB7q55kvKhGXyA9CpUY7G4mfRc8hK/Uh4Zfu0=; b=qPowagmhGuW03DH+2sfh31BrxBN22B9Ump0sPv8ePRnGvx76o6mYvjosU7AkjTE+xC TK8d1YR4rfthQlQ26WGjX7GRLuU0Jwo1JMVitNuntB9KGTwX24O/D47WHq3k0VAANIU4 3Ei5AfknDYsXwrz2gv99QFvCKjkz1lFXmZs3iRpVgJ/xGnt7wYw/fMpOvVWcJNbv4O/s KIZuJczHlKUZqJi0QdIOI+NHcRwNytOwM4ZtSsrZ0/JNW51WC5RWOroxpRyrmTeYVjJq S59yNbDcBdwen2Kx+NJ9QtgMSmH+XzTWMz6TdA0Coall28IjAD4vmnvHgyzq1Gc82kC8 nOrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774031018; x=1774635818; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VrqRFYhB7q55kvKhGXyA9CpUY7G4mfRc8hK/Uh4Zfu0=; b=U4gAlWzU1k5/WNmIj+kpOQ2KyAdtym4XdxLP36MXjDEtCNAvX9FdW4Sk0eZ42s7rJG ycVkT0/dyH4uxu3HTn6f4CdDYKVyBRfDtloZK/1eGgkBiJXfI+JmqigCqRvp+PvkjaL7 Ne5ajoMlVJ6wTaT4niywr2YwwoA07/pidh8F101geoLcNUs50mhs17TZw8XkeDQoqCYO uE7HfCcyo2UNW/09spA62xAp9Uy/hY75GAYFA+TWZIDBDYpswhaJamsxtnMtLIDYCPAa O5VpEGEy9aO3EL4Z/XuEJBNCmK9KPgCl+oYWm3/SKfTHXwplL53npykOOsREBVPXoJb7 x+RA== X-Forwarded-Encrypted: i=1; AJvYcCVthSU2+MMwXgoWO5+KiRExdR59v9+1xeHxWL+MkJfBroOlw56pFs9pHAS8+6BtmvFJue1ulQjJhx8cJ4Y=@vger.kernel.org X-Gm-Message-State: AOJu0YxNRkKW6B74TbK+Bk7slIQIQIK+LwOCZfTZ5I8oAojmyEUDGjxT cfFqOibIKvNgoAptFtb6WOsEm3o6VwPIoeEFE/8qAlEO5vbX441Ez5ZwPPcHDV/7F5AWhAa9NGm K6/XPo5cMLxEAyw== X-Received: from wrbee10.prod.google.com ([2002:a05:6000:210a:b0:43b:3cda:aa8d]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:4021:b0:43b:566e:fad2 with SMTP id ffacd0b85a97d-43b64242eb2mr8417634f8f.9.1774031017657; Fri, 20 Mar 2026 11:23:37 -0700 (PDT) Date: Fri, 20 Mar 2026 18:23:25 +0000 In-Reply-To: <20260320-page_alloc-unmapped-v2-0-28bf1bd54f41@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260320-page_alloc-unmapped-v2-0-28bf1bd54f41@google.com> X-Mailer: b4 0.14.3 Message-ID: <20260320-page_alloc-unmapped-v2-1-28bf1bd54f41@google.com> Subject: [PATCH v2 01/22] x86/mm: split out preallocate_sub_pgd() From: Brendan Jackman To: Borislav Petkov , Dave Hansen , Peter Zijlstra , Andrew Morton , David Hildenbrand , Vlastimil Babka , Wei Xu , Johannes Weiner , Zi Yan , Lorenzo Stoakes Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, x86@kernel.org, rppt@kernel.org, Sumit Garg , derkling@google.com, reijiw@google.com, Will Deacon , rientjes@google.com, "Kalyazin, Nikita" , patrick.roy@linux.dev, "Itazuri, Takahiro" , Andy Lutomirski , David Kaplan , Thomas Gleixner , Brendan Jackman , Yosry Ahmed Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable This code will be needed elsewhere in a following patch. Split out the trivial code move for easy review. This changes the logging slightly: instead of panic() directly reporting the level of the failure, there is now a generic panic message which will be preceded by a separate warn that reports the level of the failure. This is a simple way to have this helper suit the needs of its new user as well as the existing one. Other than logging, no functional change intended. Signed-off-by: Brendan Jackman --- arch/x86/include/asm/pgalloc.h | 33 +++++++++++++++++++++++++++++++ arch/x86/mm/init_64.c | 44 +++++++-------------------------------= ---- 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h index c88691b15f3c6..3541b86c9c6b0 100644 --- a/arch/x86/include/asm/pgalloc.h +++ b/arch/x86/include/asm/pgalloc.h @@ -2,6 +2,7 @@ #ifndef _ASM_X86_PGALLOC_H #define _ASM_X86_PGALLOC_H =20 +#include #include #include /* for struct page */ #include @@ -128,6 +129,38 @@ static inline void __pud_free_tlb(struct mmu_gather *t= lb, pud_t *pud, ___pud_free_tlb(tlb, pud); } =20 +/* Allocate a pagetable pointed to by the top hardware level. */ +static inline int preallocate_sub_pgd(struct mm_struct *mm, unsigned long = addr) +{ + const char *lvl; + p4d_t *p4d; + pud_t *pud; + + lvl =3D "p4d"; + p4d =3D p4d_alloc(mm, pgd_offset_pgd(mm->pgd, addr), addr); + if (!p4d) + goto failed; + + if (pgtable_l5_enabled()) + return 0; + + /* + * On 4-level systems, the P4D layer is folded away and + * the above code does no preallocation. Below, go down + * to the pud _software_ level to ensure the second + * hardware level is allocated on 4-level systems too. + */ + lvl =3D "pud"; + pud =3D pud_alloc(mm, p4d, addr); + if (!pud) + goto failed; + return 0; + +failed: + pr_warn_ratelimited("Failed to preallocate %s\n", lvl); + return -ENOMEM; +} + #if CONFIG_PGTABLE_LEVELS > 4 static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, p4d_t *p= 4d) { diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index df2261fa4f985..79806386dc42f 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1318,46 +1318,16 @@ static void __init register_page_bootmem_info(void) static void __init preallocate_vmalloc_pages(void) { unsigned long addr; - const char *lvl; =20 for (addr =3D VMALLOC_START; addr <=3D VMEMORY_END; addr =3D ALIGN(addr += 1, PGDIR_SIZE)) { - pgd_t *pgd =3D pgd_offset_k(addr); - p4d_t *p4d; - pud_t *pud; - - lvl =3D "p4d"; - p4d =3D p4d_alloc(&init_mm, pgd, addr); - if (!p4d) - goto failed; - - if (pgtable_l5_enabled()) - continue; - - /* - * The goal here is to allocate all possibly required - * hardware page tables pointed to by the top hardware - * level. - * - * On 4-level systems, the P4D layer is folded away and - * the above code does no preallocation. Below, go down - * to the pud _software_ level to ensure the second - * hardware level is allocated on 4-level systems too. - */ - lvl =3D "pud"; - pud =3D pud_alloc(&init_mm, p4d, addr); - if (!pud) - goto failed; + if (preallocate_sub_pgd(&init_mm, addr)) { + /* + * The pages have to be there now or they will be + * missing in process page-tables later. + */ + panic("Failed to pre-allocate pagetables for vmalloc area\n"); + } } - - return; - -failed: - - /* - * The pages have to be there now or they will be missing in - * process page-tables later. - */ - panic("Failed to pre-allocate %s pages for vmalloc area\n", lvl); } =20 void __init arch_mm_preinit(void) --=20 2.51.2