From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) (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 755363AE70B for ; Wed, 25 Feb 2026 16:34:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772037280; cv=none; b=JP9VC6WGa16/ycolR3ilECKL2VnvFg7KzCTemDcYObxB9CrN2aXYGCRGrilhzk5LRzBk8O7uxQn7CvqY8GtIjjmu5lBGYl3ZPh6akzcPUDVlvCvFFVOuQkTDxhGCLtYArVVijS/Tbvz+jpVDBadLakPNTT4/jxQIB+H3YaNzl58= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772037280; c=relaxed/simple; bh=jelsogJBzN8xdAQ/OvSk5lfPtRJSgoM9AIUj11KW2Wc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=T6lHSNIiQBhf1b0MA7oCBTwgAHv88W/ufz7yuL4jFysWXkSau7F9SloCfFxZY3klc56FfwLPKjMLYJEvm4I1wK7kspD3NsiTggM6G6SRlHtshEFWG6mg1M2yIdRNAmZZGxaq+1jewNR6IYxZa/nHOmCD2Bz+AssiNB7kPHdBp9Y= 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=ARffEX5Y; arc=none smtp.client-ip=209.85.218.73 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="ARffEX5Y" Received: by mail-ej1-f73.google.com with SMTP id a640c23a62f3a-b934e96af9dso43264766b.3 for ; Wed, 25 Feb 2026 08:34:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772037278; x=1772642078; 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=ARffEX5YHdxiq8LrGUk96fvPdN3w5WwACFS49yWY95l1o3disRbq5ZjHKQFTEQPsaJ 1iQn6qwXA+gyFb9Z1c6myVvGXrQRvu726dp+6wIEbVQvrQEcey2Oem8e3Hh8phfnkxYl fxK7LYmMyaJ3n3+cUeIKs5KIuBEulLADtQsiCtPQschcovXIVe+b0UdQ64ssTwzj8z2Y C3M5lJgC9AKyY7U1u91GQwT6dCJVktoft92KKNwjwNYgO8n3hOMvVBJilOUztwqVzwF6 xs4Jlc+PxlxQfMZYCrcHTLskwbqqhRut2aODpsIFK8PNMoDn6UiO+EfcsM950YUVY8nw df7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772037278; x=1772642078; 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=r5PbGwsCyq9Pdm449kXEU3PUWfdqDjXpvzN3fkwmNJMUs51hmSyWDmHKzSAqVCnhar lfNo221CVSO0Yx2XwM6JNtiR6D5QIZR7WUHk3Jw89I3SKh+qXCLRWPG7eOJbEEMfZpEs DrWJkGi6LltYa+6qjDg+g2MKt7/7w0aZVeAD0WmlvfkUrChsTghNJ+K/kdDTf38cciG6 iBomyWQWNxiumiD4EoKXxyEuCuFAe7eM9naA9gM+TcRfski1L1tBByOg1zLdsupMif+5 B3ZZ4ePB0k7ZfHxh2/RnW79q5prrihJ8OHM5b1h+HoOHxENWJbKuxYDhXxYE7UhZz9Dr xZvQ== X-Forwarded-Encrypted: i=1; AJvYcCUZEv7MYdWzcrNjg6YpqUwzHCfhfU0IiHQrcopx94Si76AERZwSs6n+O8PVM94joANWLacEAOTQ6DDiHj4=@vger.kernel.org X-Gm-Message-State: AOJu0YwWdBZmDQadXkP33JMJZwK20me6jI8pXfNLZcEyeBc6xQfo37AX V8pZbf082ZTHrm29X+gw+uT8sUeuuD0oTXy0I+MvxxWfgyrFj/sfHwOyM6ogtebJ6iuMhnn1vGA gNHOWQ83m0DtNGw== X-Received: from edge11-n2.prod.google.com ([2002:a05:6402:a54b:20b0:65a:3506:7e8]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:3e05:b0:b83:95c8:15d0 with SMTP id a640c23a62f3a-b9081c1880bmr1179838266b.52.1772037277341; Wed, 25 Feb 2026 08:34:37 -0800 (PST) Date: Wed, 25 Feb 2026 16:34:26 +0000 In-Reply-To: <20260225-page_alloc-unmapped-v1-0-e8808a03cd66@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260225-page_alloc-unmapped-v1-0-e8808a03cd66@google.com> X-Mailer: b4 0.14.3 Message-ID: <20260225-page_alloc-unmapped-v1-1-e8808a03cd66@google.com> Subject: [PATCH RFC 01/19] x86/mm: split out preallocate_sub_pgd() From: Brendan Jackman To: Borislav Petkov , Dave Hansen , Peter Zijlstra , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Vlastimil Babka , Wei Xu , Johannes Weiner , Zi Yan 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" 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 +#include #include #include /* for struct page */ #include @@ -128,6 +129,38 @@ static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pud, ___pud_free_tlb(tlb, pud); } +/* 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 = "p4d"; + p4d = 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 = "pud"; + pud = 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 *p4d) { 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; for (addr = VMALLOC_START; addr <= VMEMORY_END; addr = ALIGN(addr + 1, PGDIR_SIZE)) { - pgd_t *pgd = pgd_offset_k(addr); - p4d_t *p4d; - pud_t *pud; - - lvl = "p4d"; - p4d = 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 = "pud"; - pud = 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); } void __init arch_mm_preinit(void) -- 2.51.2