From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.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 3D5663D649D for ; Wed, 25 Feb 2026 16:34:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772037282; cv=none; b=h6avQhFY9voBnoNgq8EldyZYAw2i8t86HfK7nsDQgNJfTd08XB14hQpeKurmBo01I2refmPMLC5Y5Mj6CQPykEG6gxtNX0AJmHQUE2GAG3kMtPKo58DFXGmL7kppQzuXjoYRdBgx4qeFMZ6mYVW8MvnDSZY+HDBMxyWYovI4HfU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772037282; c=relaxed/simple; bh=96u75QxW3ouXv5Xblrwn8o0N5ML2LNnfKVOMVo1ZNhE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KnIfRBEi7GIRq9ZNzMJNKTDUnvrYJoMMqvMxcUuWbKTSIHKDdXU/jFwNubAQ6PproJPO3+P2wnzQYf5+hqWFRFuyK+hmvCddTH+2KubxG+WJpT1BrNwN672xAs+ERzjHH2r6hvAg0NqzU13urACSwrJP+KCm2Hy13cJwMRLIiQA= 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=dVPY5zqj; arc=none smtp.client-ip=209.85.128.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="dVPY5zqj" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-483a24db6ecso73924065e9.1 for ; Wed, 25 Feb 2026 08:34:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772037280; x=1772642080; 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=WDhIQvWuRYWeMcMrzum83Q6jG6Th3ZjaaGYgK9BTHd4=; b=dVPY5zqjsj6cY1iLWwUr1VAxT4x7n+V8E+C2I5EALGp2fJkJF7fYFvzs1Rvj2g1naP 4dhE6U0astdg/HtQmnfIO0iiAQyhiekz8leVt9/9OsgrHtUs13wDRlBdcP4KbakplTvD +9lGy954d0Ai+i63H1Js+IdD0buJbuT+Nqzvqthd3qIpU5Emh2XFdbJ0bZ7UjVsVV5aH qYb9VwnI2eFn0iqb63EDVPjzW8nscrDJtvbE1bLD0OuDQscsqgtVGcPVtvAySnmjQSZv K1GrDEd26VItdJ/F0Hsbb6295Ht78qeYcikWYZ3CdmpM398Lza7uCqsGSl9o8WpPY3EQ rvbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772037280; x=1772642080; 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=WDhIQvWuRYWeMcMrzum83Q6jG6Th3ZjaaGYgK9BTHd4=; b=A/K0c+DGP2FsE0szaw5MIAA8S+mr2A9Omx/D/qbY5s6ujNd/slGNS5OfQo3SdkXnlR om3Pi6vDSvHomy791IggiFAre8bULc5gZggQPVzaJ8w55msEx1InLbGVNPr3c4UzRRUN hB4V34up0cCetrb/BcDAvAv7as9AGhyIrR5feo9kkc+eQ2u4DctpsGp2+PTtCseyRBWm tSK9nE+KYhCOmnDNYmZioRIk0eCfEhKh7vhKHAVDolAlNBfU2jBtPEUV4Vc6KbojTzoN YGXIqSjI3Z2zAVuyLyMrgKYLdp9/1Yp9EdPylWHwDkLGSez4+j58fN+fXHXCoCO1O3gi j3Xg== X-Forwarded-Encrypted: i=1; AJvYcCW/V6bM9E5AwHuYXzGhyFjCq7r/1UePVrgLy3JxqHWWi1BO/kxKybeeCWwLG20upxdCG3gRKknXZeIBy1A=@vger.kernel.org X-Gm-Message-State: AOJu0YyIbtWjMkFg8uAMluqA4VrOlxlaoNSRsgP1gJs42ib5oZ8RBmVc s2i5qvvUzY977TH+R+pwmJARHpaKaICW6ChhqTldtrASZFauUmYPhBDkNKFGey0yOmfQYf+SUkb ZU7jAW/LsdR32cA== X-Received: from wmbje2.prod.google.com ([2002:a05:600c:1f82:b0:480:6bd5:88b4]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4e46:b0:483:a8e9:201b with SMTP id 5b1f17b1804b1-483a95a3851mr276690895e9.0.1772037279527; Wed, 25 Feb 2026 08:34:39 -0800 (PST) Date: Wed, 25 Feb 2026 16:34:28 +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-3-e8808a03cd66@google.com> Subject: [PATCH RFC 03/19] x86/tlb: Expose some flush function declarations to modules 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" 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 5a3cdc439e38d..ee49724403ef9 100644 --- a/arch/x86/include/asm/tlbflush.h +++ b/arch/x86/include/asm/tlbflush.h @@ -229,7 +229,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, @@ -303,26 +302,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; @@ -487,4 +466,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.51.2