From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (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 7CBA737E5FB for ; Sun, 26 Jul 2026 22:23:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.72 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785104613; cv=none; b=gOgoEnkk7aCdV9nKtn5p/YREbG+TBboNjYusbJrHe6u9Wk21hXPRQdOmxJqXtEY+r60jqqUObn81bdlkcySw4FdpMHxDwacfcQX7RSVKiqEWlKxNvv5DwST7AqBu+gLzhpGv7ScAqA3NGLA/oYp8AmROfoY3I8TSlKxFHr2fYbc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785104613; c=relaxed/simple; bh=4aG/qCgQgQnEXJFCgKeba2pYhOuXL7/Kpo3lpBjhbvI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fx/NzHZsX0BQScj8qq7N5LfAiUosuUXhfsSNJ8uIRTzS3Lvxrcjparo/LTfpujeFCN38aekL7z7CqrL5XBlN4RFLuvQT3nzyjvFueF6ajpsJZ8UkTRSDObdxi7hjwqSK3Y0pCjP262AO4SMdy3T38raWmyhoWiYD8j9iOXT9QyQ= 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=VXJ2B+F2; arc=none smtp.client-ip=209.85.128.72 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="VXJ2B+F2" Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-495689bfcc8so16259465e9.1 for ; Sun, 26 Jul 2026 15:23:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785104610; x=1785709410; 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=cIdD2acc/jIdSlYsMupzJ9xAswr0y0V2LMVp6mKkzVY=; b=VXJ2B+F2I+iedNLU+N5ZqPQatul9FlCVAcWbrBtze+wMKl0ydePP83ydm2mVv5fxb1 v5zrI5Y5+FW9Wkhm1amOlqInDxEhGws6fqvkA6mGpuxUBjVD3bUNs3KTjf2eBUxEaVvN ZREAT8f5mAKLMxPTYPdviepM0X//ojAKZ6RCopEggez4uhFCGPhJJPfPDHLp+4hMmrYy 373pqjJaJ1xEY4SXkqUhQFVn+PVV+PQA1MdTgUZXH34O0a1dS5N2Vv/WpM9an1HKh7Fo nHhGJoVy+dDv3X2asWS+EE+roKhYpgcdMvYNh66qStmR8cP3u0SGLia33ja6YjtlKH3o 1nxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785104610; x=1785709410; 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=cIdD2acc/jIdSlYsMupzJ9xAswr0y0V2LMVp6mKkzVY=; b=bcIOz/gD5MT7XpRhYHVqRkctj+tjNG4Ix7ktWq5WHM/NqfkDI15vyeo9CkjrVjTmgs gomBYhf0l3it81JTUxcDDGJMcMieL+Zess7DwsTmLNT/HvAWH5LLgXrSl8A2cbOxN4CR owlzIFfqhoVfMCYaoSt9E/Lf8LRsRalARq9aCrMVPq8PCM7bWdLqWEmKLSxKf0fXvAh5 Z52aOK0b5dCKuUxOJA/hemB11HhGshkD8e3zoEzEwFghXXF+gl8VF9ILTmeXrbL9sflZ JhrygWOGnZiJqQvG1Sr7H5uoPvgcmDEjdQziLcZv9fe3iI1ahzEp+v6PySQOJvPedwOG TxwQ== X-Forwarded-Encrypted: i=1; AHgh+RqS77H8jjFt8EfrRhAHxtwBqFGEWeMYznY2o3SksTCScMRy6szIlgbO+vK7vFOloyRk5gKz0ckpQA418qs=@vger.kernel.org X-Gm-Message-State: AOJu0YznTeDfZPjUzTpjLNHHgM3qXWxqLPKPj0bWfkf0hOWbXuyAidkT KOb+c8xU/uslFX6UZcPN/Mr7/+ny4oAA34FhInTntOrF/UwHDzGS8AjplpBDoenBScve4oKFHex +xcfPTSjL50nKFg== X-Received: from wmbe10.prod.google.com ([2002:a05:600c:590a:b0:493:ad14:710b]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:820e:b0:493:e365:ace9 with SMTP id 5b1f17b1804b1-496b56e6603mr73573705e9.11.1785104609676; Sun, 26 Jul 2026 15:23:29 -0700 (PDT) Date: Sun, 26 Jul 2026 22:22:39 +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-6-6f5729aa9832@google.com> Subject: [PATCH v3 06/26] x86/tlb: Expose some flush function declarations to modules 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 commit bfe3d8f6313d ("x86/tlb: Restrict access to tlbstate") some low-level logic (the important detail here is flush_tlb_info) was hidden from modules, along with functions associated with that data. Later, the set of functions defined here changed and there are now a bunch of flush_tlb_*() functions that do not depend on x86 internals like flush_tlb_info. This leads to some build fragility: KVM (which can be a module) cares about TLB flushing and includes {linux->asm}/mmu_context.h which includes asm/tlb.h and asm/tlbflush.h. This x86 TLB code expects these helpers to be defined (e.g. tlb_flush() calls flush_tlb_mm_range()). Modules probably shouldn't call these helpers - luckily this is already enforced by the lack of EXPORT_SYMBOL(). Therefore keep things simple and just expose the declarations anyway to prevent build failures. Signed-off-by: Brendan Jackman --- arch/x86/include/asm/tlbflush.h | 43 +++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h index 0545fe75c3fa1..56cff03b65aa2 100644 --- a/arch/x86/include/asm/tlbflush.h +++ b/arch/x86/include/asm/tlbflush.h @@ -251,7 +251,6 @@ struct flush_tlb_info { u8 trim_cpumask; }; -void flush_tlb_local(void); void flush_tlb_one_user(unsigned long addr); void flush_tlb_one_kernel(unsigned long addr); void flush_tlb_multi(const struct cpumask *cpumask, @@ -325,26 +324,6 @@ static inline void mm_clear_asid_transition(struct mm_struct *mm) { } static inline bool mm_in_asid_transition(struct mm_struct *mm) { return false; } #endif /* CONFIG_BROADCAST_TLB_FLUSH */ -#define flush_tlb_mm(mm) \ - flush_tlb_mm_range(mm, 0UL, TLB_FLUSH_ALL, 0UL, true) - -#define flush_tlb_range(vma, start, end) \ - flush_tlb_mm_range((vma)->vm_mm, start, end, \ - ((vma)->vm_flags & VM_HUGETLB) \ - ? huge_page_shift(hstate_vma(vma)) \ - : PAGE_SHIFT, true) - -extern void flush_tlb_all(void); -extern void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, - unsigned long end, unsigned int stride_shift, - bool freed_tables); -extern void flush_tlb_kernel_range(unsigned long start, unsigned long end); - -static inline void flush_tlb_page(struct vm_area_struct *vma, unsigned long a) -{ - flush_tlb_mm_range(vma->vm_mm, a, a + PAGE_SIZE, PAGE_SHIFT, false); -} - static inline bool arch_tlbbatch_should_defer(struct mm_struct *mm) { bool should_defer = false; @@ -513,4 +492,26 @@ static inline void __native_tlb_flush_global(unsigned long cr4) native_write_cr4(cr4 ^ X86_CR4_PGE); native_write_cr4(cr4); } + +#define flush_tlb_mm(mm) \ + flush_tlb_mm_range(mm, 0UL, TLB_FLUSH_ALL, 0UL, true) + +#define flush_tlb_range(vma, start, end) \ + flush_tlb_mm_range((vma)->vm_mm, start, end, \ + ((vma)->vm_flags & VM_HUGETLB) \ + ? huge_page_shift(hstate_vma(vma)) \ + : PAGE_SHIFT, true) + +void flush_tlb_local(void); +extern void flush_tlb_all(void); +extern void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, + unsigned long end, unsigned int stride_shift, + bool freed_tables); +extern void flush_tlb_kernel_range(unsigned long start, unsigned long end); + +static inline void flush_tlb_page(struct vm_area_struct *vma, unsigned long a) +{ + flush_tlb_mm_range(vma->vm_mm, a, a + PAGE_SIZE, PAGE_SHIFT, false); +} + #endif /* _ASM_X86_TLBFLUSH_H */ -- 2.54.0