From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (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 2DE3037649B for ; Sun, 26 Jul 2026 22:23:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.71 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785104611; cv=none; b=FRj3W2gbOaLN3zISLUZl/skKK2sTX+m2NazNUrxKo2zuAZjwlcw/Y6stOfOI/EQ3Hg02OVehlBf238N4S1b+cnrvpPLbOFPebjQhF6HS23YKDkLybkiSCGu5sePtDFzU5Di4OXs/GRNu6YQYhqjrMuq2XShNjNpGWAL3lA1aPHc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785104611; c=relaxed/simple; bh=I6uB4HTEflN76QSeApShWvAA6KEK07q2ezW3LMATluM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HC5o93OcKq5MLYjhC5huER035jSJHjp8OWDEwKOJd7+Ckz9MBM3NDntw+pLXq74gBlYVs4zJteCzNRdqT5hde+slA6MLHj0BAklVxmFRyNuryw+3dI82nqoFyat8Oa9hmBHNzn+AvbegjKWw+jVcviOvhw8tclYJXSaN8KlEoQQ= 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=gZTwHJGh; arc=none smtp.client-ip=209.85.128.71 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="gZTwHJGh" Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-49561facb1dso17687535e9.3 for ; Sun, 26 Jul 2026 15:23:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785104608; x=1785709408; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=x15ix7IWz4pwvtzNVrQxDVQH1foHe0j7v2jOQv7JDzE=; b=gZTwHJGhpznIJtJK/kFTr84KDfUWu+1sm1BWxYBepV4HLbl7ibBgZMsdmnbGydI5dj 2ruhM6gdEIGKhLF+IRreTx0gEYPEO/AhMpPsCJwL0ZE1c209XIzqbffqFw46abZHltlp us8XQESkf5mm9rOeV0bZ2B6IaljUeRlFlN3Fhe8xsk947Kvj/2PjlOr/Ud7G9uafMtMf qkbx8W92jdZ+CfDQchc7sSRsc9Xa98MVm8qo/Z/AQjbWx9rO7IGod9MCo2Krv3QdgyDj c5uagkF75rSUrf5EL8CVeyUGI2cURkQ+qAnAHCazdrZdMe21LGcNGVwWVOUvY7JXe/dc Yutg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785104608; x=1785709408; h=content-type: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:content-type; bh=x15ix7IWz4pwvtzNVrQxDVQH1foHe0j7v2jOQv7JDzE=; b=CM9LzjRn0Slp+LllpUif04WpTXRUwVOrwfNdHOHUIQftjlFRIOfoF34jWuy9QhsRfz qiqd+tUkDhBYqiOeq3S0djADKPsqdLtyjNOjsaB6tHwPvBFbsQxSKO7Ry4zUhIKYQlMj VfPgfPdp5DvuxBDCPTWYPUfZB47xK+KucRb9/xxRYRNvd5Hi0XcoX0OrGPNO37yOFlgk kRWy93/eA5lA6v+LwVdU6ryj2Gwg/fxdhg6yNwjPWuX4kVYm67NJuT+n6OL9k3dRl9dH SPnFrvlDJmH2glKcZSSj3WmXV342zV4AQ8KbU1JEOTvvxmxWvf0X8d3zx23S/QyAc1X6 a86w== X-Forwarded-Encrypted: i=1; AHgh+RpXyyn7f/Lg9Y73gxoD719iQq9Fheq6qIxtMPsHzsgW5saFUqnVshTT5Y67jYjjGmfexXNGlSIg6ZFK6VM=@vger.kernel.org X-Gm-Message-State: AOJu0YxS/4Magc+POmSWDlwxaUoiwicTLEayuy/Yc6DqxwzSsinvpwIm kRr1K1d50ApIVHN7XtBhaMYxcXAkrjLPmXWDQpeOjO+xdsamYAFY6bX6cb7eJbMb8EVvAIaqzXb otiJzQzhYXXwEdA== X-Received: from wmlv23.prod.google.com ([2002:a05:600c:2157:b0:495:5890:8f69]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:6296:b0:494:282:106c with SMTP id 5b1f17b1804b1-496b56fb438mr72282275e9.16.1785104608079; Sun, 26 Jul 2026 15:23:28 -0700 (PDT) Date: Sun, 26 Jul 2026 22:22:38 +0000 In-Reply-To: <20260726-page_alloc-unmapped-v3-0-6f5729aa9832@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260726-page_alloc-unmapped-v3-0-6f5729aa9832@google.com> X-Mailer: b4 0.16-dev Message-ID: <20260726-page_alloc-unmapped-v3-5-6f5729aa9832@google.com> Subject: [PATCH v3 05/26] x86: move PAE PMD preallocation defines to header From: Brendan Jackman To: Borislav Petkov , Dave Hansen , Peter Zijlstra , Andrew Morton , David Hildenbrand , Vlastimil Babka , Mike Rapoport , 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 , Will Deacon , rientjes@google.com, "Kalyazin, Nikita" , patrick.roy@linux.dev, "Itazuri, Takahiro" , Andy Lutomirski , David Kaplan , Thomas Gleixner , Yosry Ahmed , Patrick Bellasi , Reiji Watanabe , Sean Christopherson , Brendan Jackman Content-Type: text/plain; charset="utf-8" In a subsequent patch these defines will need to be referenced from a new file, move them as a separate patch for easy review. The comments have style violations (personal pronouns etc), do not fix them as this is just code movement. No functional change intended. Signed-off-by: Brendan Jackman --- arch/x86/include/asm/page.h | 32 ++++++++++++++++++++++++++++++++ arch/x86/mm/pgtable.c | 29 ----------------------------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h index 416dc88e35c15..4de4715c3b40f 100644 --- a/arch/x86/include/asm/page.h +++ b/arch/x86/include/asm/page.h @@ -78,6 +78,38 @@ static __always_inline u64 __is_canonical_address(u64 vaddr, u8 vaddr_bits) return __canonical_address(vaddr, vaddr_bits) == vaddr; } +#ifdef CONFIG_X86_PAE + +/* + * In PAE mode, we need to do a cr3 reload (=tlb flush) when + * updating the top-level pagetable entries to guarantee the + * processor notices the update. Since this is expensive, and + * all 4 top-level entries are used almost immediately in a + * new process's life, we just pre-populate them here. + */ +#define PREALLOCATED_PMDS PTRS_PER_PGD +/* + * "USER_PMDS" are the PMDs for the user copy of the page tables when + * PTI is enabled. They do not exist when PTI is disabled. Note that + * this is distinct from the user _portion_ of the kernel page tables + * which always exists. + * + * We allocate separate PMDs for the kernel part of the user page-table + * when PTI is enabled. We need them to map the per-process LDT into the + * user-space page-table. + */ +#define PREALLOCATED_USER_PMDS (boot_cpu_has(X86_FEATURE_PTI) ? KERNEL_PGD_PTRS : 0) +#define MAX_PREALLOCATED_USER_PMDS KERNEL_PGD_PTRS + +#else /* !CONFIG_X86_PAE */ + +/* No need to prepopulate any pagetable entries in non-PAE modes. */ +#define PREALLOCATED_PMDS 0 +#define PREALLOCATED_USER_PMDS 0 +#define MAX_PREALLOCATED_USER_PMDS 0 + +#endif /* CONFIG_X86_PAE */ + #endif /* __ASSEMBLER__ */ #include diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c index fdd3709509946..8f3505b1eefec 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -100,29 +100,6 @@ static void pgd_dtor(pgd_t *pgd) } #ifdef CONFIG_X86_PAE -/* - * In PAE mode, we need to do a cr3 reload (=tlb flush) when - * updating the top-level pagetable entries to guarantee the - * processor notices the update. Since this is expensive, and - * all 4 top-level entries are used almost immediately in a - * new process's life, we just pre-populate them here. - */ -#define PREALLOCATED_PMDS PTRS_PER_PGD - -/* - * "USER_PMDS" are the PMDs for the user copy of the page tables when - * PTI is enabled. They do not exist when PTI is disabled. Note that - * this is distinct from the user _portion_ of the kernel page tables - * which always exists. - * - * We allocate separate PMDs for the kernel part of the user page-table - * when PTI is enabled. We need them to map the per-process LDT into the - * user-space page-table. - */ -#define PREALLOCATED_USER_PMDS (boot_cpu_has(X86_FEATURE_PTI) ? \ - KERNEL_PGD_PTRS : 0) -#define MAX_PREALLOCATED_USER_PMDS KERNEL_PGD_PTRS - void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd) { paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT); @@ -139,12 +116,6 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd) */ flush_tlb_mm(mm); } -#else /* !CONFIG_X86_PAE */ - -/* No need to prepopulate any pagetable entries in non-PAE modes. */ -#define PREALLOCATED_PMDS 0 -#define PREALLOCATED_USER_PMDS 0 -#define MAX_PREALLOCATED_USER_PMDS 0 #endif /* CONFIG_X86_PAE */ static void free_pmds(struct mm_struct *mm, pmd_t *pmds[], int count) -- 2.54.0