Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm: move tlb_flush_pending inline helpers to mm_inline.h

linux/mm_types.h should only define structure definitions, to make it
cheap to include elsewhere. The atomic_t helper function definitions
are particularly large, so it's better to move the helpers using those
into the existing linux/mm_inline.h and only include that where needed.

As a follow-up, we may want to go through all the indirect includes in
mm_types.h and reduce them as much as possible.

Link: https://lkml.kernel.org/r/20211207125710.2503446-2-arnd@kernel.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Colin Cross <ccross@google.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Peter Xu <peterx@redhat.com>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Yu Zhao <yuzhao@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Eric Biederman <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Arnd Bergmann and committed by
Linus Torvalds
36090def 17fca131

+137 -130
+1 -1
arch/x86/include/asm/pgtable.h
··· 752 752 return true; 753 753 754 754 if ((pte_flags(a) & _PAGE_PROTNONE) && 755 - mm_tlb_flush_pending(mm)) 755 + atomic_read(&mm->tlb_flush_pending)) 756 756 return true; 757 757 758 758 return false;
-45
include/linux/mm.h
··· 424 424 */ 425 425 extern pgprot_t protection_map[16]; 426 426 427 - /** 428 - * enum fault_flag - Fault flag definitions. 429 - * @FAULT_FLAG_WRITE: Fault was a write fault. 430 - * @FAULT_FLAG_MKWRITE: Fault was mkwrite of existing PTE. 431 - * @FAULT_FLAG_ALLOW_RETRY: Allow to retry the fault if blocked. 432 - * @FAULT_FLAG_RETRY_NOWAIT: Don't drop mmap_lock and wait when retrying. 433 - * @FAULT_FLAG_KILLABLE: The fault task is in SIGKILL killable region. 434 - * @FAULT_FLAG_TRIED: The fault has been tried once. 435 - * @FAULT_FLAG_USER: The fault originated in userspace. 436 - * @FAULT_FLAG_REMOTE: The fault is not for current task/mm. 437 - * @FAULT_FLAG_INSTRUCTION: The fault was during an instruction fetch. 438 - * @FAULT_FLAG_INTERRUPTIBLE: The fault can be interrupted by non-fatal signals. 439 - * 440 - * About @FAULT_FLAG_ALLOW_RETRY and @FAULT_FLAG_TRIED: we can specify 441 - * whether we would allow page faults to retry by specifying these two 442 - * fault flags correctly. Currently there can be three legal combinations: 443 - * 444 - * (a) ALLOW_RETRY and !TRIED: this means the page fault allows retry, and 445 - * this is the first try 446 - * 447 - * (b) ALLOW_RETRY and TRIED: this means the page fault allows retry, and 448 - * we've already tried at least once 449 - * 450 - * (c) !ALLOW_RETRY and !TRIED: this means the page fault does not allow retry 451 - * 452 - * The unlisted combination (!ALLOW_RETRY && TRIED) is illegal and should never 453 - * be used. Note that page faults can be allowed to retry for multiple times, 454 - * in which case we'll have an initial fault with flags (a) then later on 455 - * continuous faults with flags (b). We should always try to detect pending 456 - * signals before a retry to make sure the continuous page faults can still be 457 - * interrupted if necessary. 458 - */ 459 - enum fault_flag { 460 - FAULT_FLAG_WRITE = 1 << 0, 461 - FAULT_FLAG_MKWRITE = 1 << 1, 462 - FAULT_FLAG_ALLOW_RETRY = 1 << 2, 463 - FAULT_FLAG_RETRY_NOWAIT = 1 << 3, 464 - FAULT_FLAG_KILLABLE = 1 << 4, 465 - FAULT_FLAG_TRIED = 1 << 5, 466 - FAULT_FLAG_USER = 1 << 6, 467 - FAULT_FLAG_REMOTE = 1 << 7, 468 - FAULT_FLAG_INSTRUCTION = 1 << 8, 469 - FAULT_FLAG_INTERRUPTIBLE = 1 << 9, 470 - }; 471 - 472 427 /* 473 428 * The default fault flags that should be used by most of the 474 429 * arch-specific page fault handlers.
+86
include/linux/mm_inline.h
··· 2 2 #ifndef LINUX_MM_INLINE_H 3 3 #define LINUX_MM_INLINE_H 4 4 5 + #include <linux/atomic.h> 5 6 #include <linux/huge_mm.h> 6 7 #include <linux/swap.h> 7 8 #include <linux/string.h> ··· 185 184 return true; 186 185 } 187 186 #endif /* CONFIG_ANON_VMA_NAME */ 187 + 188 + static inline void init_tlb_flush_pending(struct mm_struct *mm) 189 + { 190 + atomic_set(&mm->tlb_flush_pending, 0); 191 + } 192 + 193 + static inline void inc_tlb_flush_pending(struct mm_struct *mm) 194 + { 195 + atomic_inc(&mm->tlb_flush_pending); 196 + /* 197 + * The only time this value is relevant is when there are indeed pages 198 + * to flush. And we'll only flush pages after changing them, which 199 + * requires the PTL. 200 + * 201 + * So the ordering here is: 202 + * 203 + * atomic_inc(&mm->tlb_flush_pending); 204 + * spin_lock(&ptl); 205 + * ... 206 + * set_pte_at(); 207 + * spin_unlock(&ptl); 208 + * 209 + * spin_lock(&ptl) 210 + * mm_tlb_flush_pending(); 211 + * .... 212 + * spin_unlock(&ptl); 213 + * 214 + * flush_tlb_range(); 215 + * atomic_dec(&mm->tlb_flush_pending); 216 + * 217 + * Where the increment if constrained by the PTL unlock, it thus 218 + * ensures that the increment is visible if the PTE modification is 219 + * visible. After all, if there is no PTE modification, nobody cares 220 + * about TLB flushes either. 221 + * 222 + * This very much relies on users (mm_tlb_flush_pending() and 223 + * mm_tlb_flush_nested()) only caring about _specific_ PTEs (and 224 + * therefore specific PTLs), because with SPLIT_PTE_PTLOCKS and RCpc 225 + * locks (PPC) the unlock of one doesn't order against the lock of 226 + * another PTL. 227 + * 228 + * The decrement is ordered by the flush_tlb_range(), such that 229 + * mm_tlb_flush_pending() will not return false unless all flushes have 230 + * completed. 231 + */ 232 + } 233 + 234 + static inline void dec_tlb_flush_pending(struct mm_struct *mm) 235 + { 236 + /* 237 + * See inc_tlb_flush_pending(). 238 + * 239 + * This cannot be smp_mb__before_atomic() because smp_mb() simply does 240 + * not order against TLB invalidate completion, which is what we need. 241 + * 242 + * Therefore we must rely on tlb_flush_*() to guarantee order. 243 + */ 244 + atomic_dec(&mm->tlb_flush_pending); 245 + } 246 + 247 + static inline bool mm_tlb_flush_pending(struct mm_struct *mm) 248 + { 249 + /* 250 + * Must be called after having acquired the PTL; orders against that 251 + * PTLs release and therefore ensures that if we observe the modified 252 + * PTE we must also observe the increment from inc_tlb_flush_pending(). 253 + * 254 + * That is, it only guarantees to return true if there is a flush 255 + * pending for _this_ PTL. 256 + */ 257 + return atomic_read(&mm->tlb_flush_pending); 258 + } 259 + 260 + static inline bool mm_tlb_flush_nested(struct mm_struct *mm) 261 + { 262 + /* 263 + * Similar to mm_tlb_flush_pending(), we must have acquired the PTL 264 + * for which there is a TLB flush pending in order to guarantee 265 + * we've seen both that PTE modification and the increment. 266 + * 267 + * (no requirement on actually still holding the PTL, that is irrelevant) 268 + */ 269 + return atomic_read(&mm->tlb_flush_pending) > 1; 270 + } 271 + 188 272 189 273 #endif
+45 -84
include/linux/mm_types.h
··· 692 692 extern void tlb_gather_mmu_fullmm(struct mmu_gather *tlb, struct mm_struct *mm); 693 693 extern void tlb_finish_mmu(struct mmu_gather *tlb); 694 694 695 - static inline void init_tlb_flush_pending(struct mm_struct *mm) 696 - { 697 - atomic_set(&mm->tlb_flush_pending, 0); 698 - } 699 - 700 - static inline void inc_tlb_flush_pending(struct mm_struct *mm) 701 - { 702 - atomic_inc(&mm->tlb_flush_pending); 703 - /* 704 - * The only time this value is relevant is when there are indeed pages 705 - * to flush. And we'll only flush pages after changing them, which 706 - * requires the PTL. 707 - * 708 - * So the ordering here is: 709 - * 710 - * atomic_inc(&mm->tlb_flush_pending); 711 - * spin_lock(&ptl); 712 - * ... 713 - * set_pte_at(); 714 - * spin_unlock(&ptl); 715 - * 716 - * spin_lock(&ptl) 717 - * mm_tlb_flush_pending(); 718 - * .... 719 - * spin_unlock(&ptl); 720 - * 721 - * flush_tlb_range(); 722 - * atomic_dec(&mm->tlb_flush_pending); 723 - * 724 - * Where the increment if constrained by the PTL unlock, it thus 725 - * ensures that the increment is visible if the PTE modification is 726 - * visible. After all, if there is no PTE modification, nobody cares 727 - * about TLB flushes either. 728 - * 729 - * This very much relies on users (mm_tlb_flush_pending() and 730 - * mm_tlb_flush_nested()) only caring about _specific_ PTEs (and 731 - * therefore specific PTLs), because with SPLIT_PTE_PTLOCKS and RCpc 732 - * locks (PPC) the unlock of one doesn't order against the lock of 733 - * another PTL. 734 - * 735 - * The decrement is ordered by the flush_tlb_range(), such that 736 - * mm_tlb_flush_pending() will not return false unless all flushes have 737 - * completed. 738 - */ 739 - } 740 - 741 - static inline void dec_tlb_flush_pending(struct mm_struct *mm) 742 - { 743 - /* 744 - * See inc_tlb_flush_pending(). 745 - * 746 - * This cannot be smp_mb__before_atomic() because smp_mb() simply does 747 - * not order against TLB invalidate completion, which is what we need. 748 - * 749 - * Therefore we must rely on tlb_flush_*() to guarantee order. 750 - */ 751 - atomic_dec(&mm->tlb_flush_pending); 752 - } 753 - 754 - static inline bool mm_tlb_flush_pending(struct mm_struct *mm) 755 - { 756 - /* 757 - * Must be called after having acquired the PTL; orders against that 758 - * PTLs release and therefore ensures that if we observe the modified 759 - * PTE we must also observe the increment from inc_tlb_flush_pending(). 760 - * 761 - * That is, it only guarantees to return true if there is a flush 762 - * pending for _this_ PTL. 763 - */ 764 - return atomic_read(&mm->tlb_flush_pending); 765 - } 766 - 767 - static inline bool mm_tlb_flush_nested(struct mm_struct *mm) 768 - { 769 - /* 770 - * Similar to mm_tlb_flush_pending(), we must have acquired the PTL 771 - * for which there is a TLB flush pending in order to guarantee 772 - * we've seen both that PTE modification and the increment. 773 - * 774 - * (no requirement on actually still holding the PTL, that is irrelevant) 775 - */ 776 - return atomic_read(&mm->tlb_flush_pending) > 1; 777 - } 778 - 779 695 struct vm_fault; 780 696 781 697 /** ··· 805 889 typedef struct { 806 890 unsigned long val; 807 891 } swp_entry_t; 892 + 893 + /** 894 + * enum fault_flag - Fault flag definitions. 895 + * @FAULT_FLAG_WRITE: Fault was a write fault. 896 + * @FAULT_FLAG_MKWRITE: Fault was mkwrite of existing PTE. 897 + * @FAULT_FLAG_ALLOW_RETRY: Allow to retry the fault if blocked. 898 + * @FAULT_FLAG_RETRY_NOWAIT: Don't drop mmap_lock and wait when retrying. 899 + * @FAULT_FLAG_KILLABLE: The fault task is in SIGKILL killable region. 900 + * @FAULT_FLAG_TRIED: The fault has been tried once. 901 + * @FAULT_FLAG_USER: The fault originated in userspace. 902 + * @FAULT_FLAG_REMOTE: The fault is not for current task/mm. 903 + * @FAULT_FLAG_INSTRUCTION: The fault was during an instruction fetch. 904 + * @FAULT_FLAG_INTERRUPTIBLE: The fault can be interrupted by non-fatal signals. 905 + * 906 + * About @FAULT_FLAG_ALLOW_RETRY and @FAULT_FLAG_TRIED: we can specify 907 + * whether we would allow page faults to retry by specifying these two 908 + * fault flags correctly. Currently there can be three legal combinations: 909 + * 910 + * (a) ALLOW_RETRY and !TRIED: this means the page fault allows retry, and 911 + * this is the first try 912 + * 913 + * (b) ALLOW_RETRY and TRIED: this means the page fault allows retry, and 914 + * we've already tried at least once 915 + * 916 + * (c) !ALLOW_RETRY and !TRIED: this means the page fault does not allow retry 917 + * 918 + * The unlisted combination (!ALLOW_RETRY && TRIED) is illegal and should never 919 + * be used. Note that page faults can be allowed to retry for multiple times, 920 + * in which case we'll have an initial fault with flags (a) then later on 921 + * continuous faults with flags (b). We should always try to detect pending 922 + * signals before a retry to make sure the continuous page faults can still be 923 + * interrupted if necessary. 924 + */ 925 + enum fault_flag { 926 + FAULT_FLAG_WRITE = 1 << 0, 927 + FAULT_FLAG_MKWRITE = 1 << 1, 928 + FAULT_FLAG_ALLOW_RETRY = 1 << 2, 929 + FAULT_FLAG_RETRY_NOWAIT = 1 << 3, 930 + FAULT_FLAG_KILLABLE = 1 << 4, 931 + FAULT_FLAG_TRIED = 1 << 5, 932 + FAULT_FLAG_USER = 1 << 6, 933 + FAULT_FLAG_REMOTE = 1 << 7, 934 + FAULT_FLAG_INSTRUCTION = 1 << 8, 935 + FAULT_FLAG_INTERRUPTIBLE = 1 << 9, 936 + }; 808 937 809 938 #endif /* _LINUX_MM_TYPES_H */
+1
mm/ksm.c
··· 15 15 16 16 #include <linux/errno.h> 17 17 #include <linux/mm.h> 18 + #include <linux/mm_inline.h> 18 19 #include <linux/fs.h> 19 20 #include <linux/mman.h> 20 21 #include <linux/sched.h>
+1
mm/mapping_dirty_helpers.c
··· 3 3 #include <linux/hugetlb.h> 4 4 #include <linux/bitops.h> 5 5 #include <linux/mmu_notifier.h> 6 + #include <linux/mm_inline.h> 6 7 #include <asm/cacheflush.h> 7 8 #include <asm/tlbflush.h> 8 9
+1
mm/memory.c
··· 41 41 42 42 #include <linux/kernel_stat.h> 43 43 #include <linux/mm.h> 44 + #include <linux/mm_inline.h> 44 45 #include <linux/sched/mm.h> 45 46 #include <linux/sched/coredump.h> 46 47 #include <linux/sched/numa_balancing.h>
+1
mm/mmu_gather.c
··· 3 3 #include <linux/kernel.h> 4 4 #include <linux/mmdebug.h> 5 5 #include <linux/mm_types.h> 6 + #include <linux/mm_inline.h> 6 7 #include <linux/pagemap.h> 7 8 #include <linux/rcupdate.h> 8 9 #include <linux/smp.h>
+1
mm/pgtable-generic.c
··· 10 10 #include <linux/pagemap.h> 11 11 #include <linux/hugetlb.h> 12 12 #include <linux/pgtable.h> 13 + #include <linux/mm_inline.h> 13 14 #include <asm/tlb.h> 14 15 15 16 /*