~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/mm/mapping_dirty_helpers.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /mm/mapping_dirty_helpers.c (Version linux-6.11.5) and /mm/mapping_dirty_helpers.c (Version linux-5.16.20)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2 #include <linux/pagewalk.h>                         2 #include <linux/pagewalk.h>
  3 #include <linux/hugetlb.h>                          3 #include <linux/hugetlb.h>
  4 #include <linux/bitops.h>                           4 #include <linux/bitops.h>
  5 #include <linux/mmu_notifier.h>                     5 #include <linux/mmu_notifier.h>
  6 #include <linux/mm_inline.h>                   << 
  7 #include <asm/cacheflush.h>                         6 #include <asm/cacheflush.h>
  8 #include <asm/tlbflush.h>                           7 #include <asm/tlbflush.h>
  9                                                     8 
 10 /**                                                 9 /**
 11  * struct wp_walk - Private struct for pagetab     10  * struct wp_walk - Private struct for pagetable walk callbacks
 12  * @range: Range for mmu notifiers                 11  * @range: Range for mmu notifiers
 13  * @tlbflush_start: Address of first modified      12  * @tlbflush_start: Address of first modified pte
 14  * @tlbflush_end: Address of last modified pte     13  * @tlbflush_end: Address of last modified pte + 1
 15  * @total: Total number of modified ptes           14  * @total: Total number of modified ptes
 16  */                                                15  */
 17 struct wp_walk {                                   16 struct wp_walk {
 18         struct mmu_notifier_range range;           17         struct mmu_notifier_range range;
 19         unsigned long tlbflush_start;              18         unsigned long tlbflush_start;
 20         unsigned long tlbflush_end;                19         unsigned long tlbflush_end;
 21         unsigned long total;                       20         unsigned long total;
 22 };                                                 21 };
 23                                                    22 
 24 /**                                                23 /**
 25  * wp_pte - Write-protect a pte                    24  * wp_pte - Write-protect a pte
 26  * @pte: Pointer to the pte                        25  * @pte: Pointer to the pte
 27  * @addr: The start of protecting virtual addr     26  * @addr: The start of protecting virtual address
 28  * @end: The end of protecting virtual address     27  * @end: The end of protecting virtual address
 29  * @walk: pagetable walk callback argument         28  * @walk: pagetable walk callback argument
 30  *                                                 29  *
 31  * The function write-protects a pte and recor     30  * The function write-protects a pte and records the range in
 32  * virtual address space of touched ptes for e     31  * virtual address space of touched ptes for efficient range TLB flushes.
 33  */                                                32  */
 34 static int wp_pte(pte_t *pte, unsigned long ad     33 static int wp_pte(pte_t *pte, unsigned long addr, unsigned long end,
 35                   struct mm_walk *walk)            34                   struct mm_walk *walk)
 36 {                                                  35 {
 37         struct wp_walk *wpwalk = walk->private     36         struct wp_walk *wpwalk = walk->private;
 38         pte_t ptent = ptep_get(pte);           !!  37         pte_t ptent = *pte;
 39                                                    38 
 40         if (pte_write(ptent)) {                    39         if (pte_write(ptent)) {
 41                 pte_t old_pte = ptep_modify_pr     40                 pte_t old_pte = ptep_modify_prot_start(walk->vma, addr, pte);
 42                                                    41 
 43                 ptent = pte_wrprotect(old_pte)     42                 ptent = pte_wrprotect(old_pte);
 44                 ptep_modify_prot_commit(walk->     43                 ptep_modify_prot_commit(walk->vma, addr, pte, old_pte, ptent);
 45                 wpwalk->total++;                   44                 wpwalk->total++;
 46                 wpwalk->tlbflush_start = min(w     45                 wpwalk->tlbflush_start = min(wpwalk->tlbflush_start, addr);
 47                 wpwalk->tlbflush_end = max(wpw     46                 wpwalk->tlbflush_end = max(wpwalk->tlbflush_end,
 48                                            add     47                                            addr + PAGE_SIZE);
 49         }                                          48         }
 50                                                    49 
 51         return 0;                                  50         return 0;
 52 }                                                  51 }
 53                                                    52 
 54 /**                                                53 /**
 55  * struct clean_walk - Private struct for the      54  * struct clean_walk - Private struct for the clean_record_pte function.
 56  * @base: struct wp_walk we derive from            55  * @base: struct wp_walk we derive from
 57  * @bitmap_pgoff: Address_space Page offset of     56  * @bitmap_pgoff: Address_space Page offset of the first bit in @bitmap
 58  * @bitmap: Bitmap with one bit for each page      57  * @bitmap: Bitmap with one bit for each page offset in the address_space range
 59  * covered.                                        58  * covered.
 60  * @start: Address_space page offset of first      59  * @start: Address_space page offset of first modified pte relative
 61  * to @bitmap_pgoff                                60  * to @bitmap_pgoff
 62  * @end: Address_space page offset of last mod     61  * @end: Address_space page offset of last modified pte relative
 63  * to @bitmap_pgoff                                62  * to @bitmap_pgoff
 64  */                                                63  */
 65 struct clean_walk {                                64 struct clean_walk {
 66         struct wp_walk base;                       65         struct wp_walk base;
 67         pgoff_t bitmap_pgoff;                      66         pgoff_t bitmap_pgoff;
 68         unsigned long *bitmap;                     67         unsigned long *bitmap;
 69         pgoff_t start;                             68         pgoff_t start;
 70         pgoff_t end;                               69         pgoff_t end;
 71 };                                                 70 };
 72                                                    71 
 73 #define to_clean_walk(_wpwalk) container_of(_w     72 #define to_clean_walk(_wpwalk) container_of(_wpwalk, struct clean_walk, base)
 74                                                    73 
 75 /**                                                74 /**
 76  * clean_record_pte - Clean a pte and record i     75  * clean_record_pte - Clean a pte and record its address space offset in a
 77  * bitmap                                          76  * bitmap
 78  * @pte: Pointer to the pte                        77  * @pte: Pointer to the pte
 79  * @addr: The start of virtual address to be c     78  * @addr: The start of virtual address to be clean
 80  * @end: The end of virtual address to be clea     79  * @end: The end of virtual address to be clean
 81  * @walk: pagetable walk callback argument         80  * @walk: pagetable walk callback argument
 82  *                                                 81  *
 83  * The function cleans a pte and records the r     82  * The function cleans a pte and records the range in
 84  * virtual address space of touched ptes for e     83  * virtual address space of touched ptes for efficient TLB flushes.
 85  * It also records dirty ptes in a bitmap repr     84  * It also records dirty ptes in a bitmap representing page offsets
 86  * in the address_space, as well as the first      85  * in the address_space, as well as the first and last of the bits
 87  * touched.                                        86  * touched.
 88  */                                                87  */
 89 static int clean_record_pte(pte_t *pte, unsign     88 static int clean_record_pte(pte_t *pte, unsigned long addr,
 90                             unsigned long end,     89                             unsigned long end, struct mm_walk *walk)
 91 {                                                  90 {
 92         struct wp_walk *wpwalk = walk->private     91         struct wp_walk *wpwalk = walk->private;
 93         struct clean_walk *cwalk = to_clean_wa     92         struct clean_walk *cwalk = to_clean_walk(wpwalk);
 94         pte_t ptent = ptep_get(pte);           !!  93         pte_t ptent = *pte;
 95                                                    94 
 96         if (pte_dirty(ptent)) {                    95         if (pte_dirty(ptent)) {
 97                 pgoff_t pgoff = ((addr - walk-     96                 pgoff_t pgoff = ((addr - walk->vma->vm_start) >> PAGE_SHIFT) +
 98                         walk->vma->vm_pgoff -      97                         walk->vma->vm_pgoff - cwalk->bitmap_pgoff;
 99                 pte_t old_pte = ptep_modify_pr     98                 pte_t old_pte = ptep_modify_prot_start(walk->vma, addr, pte);
100                                                    99 
101                 ptent = pte_mkclean(old_pte);     100                 ptent = pte_mkclean(old_pte);
102                 ptep_modify_prot_commit(walk->    101                 ptep_modify_prot_commit(walk->vma, addr, pte, old_pte, ptent);
103                                                   102 
104                 wpwalk->total++;                  103                 wpwalk->total++;
105                 wpwalk->tlbflush_start = min(w    104                 wpwalk->tlbflush_start = min(wpwalk->tlbflush_start, addr);
106                 wpwalk->tlbflush_end = max(wpw    105                 wpwalk->tlbflush_end = max(wpwalk->tlbflush_end,
107                                            add    106                                            addr + PAGE_SIZE);
108                                                   107 
109                 __set_bit(pgoff, cwalk->bitmap    108                 __set_bit(pgoff, cwalk->bitmap);
110                 cwalk->start = min(cwalk->star    109                 cwalk->start = min(cwalk->start, pgoff);
111                 cwalk->end = max(cwalk->end, p    110                 cwalk->end = max(cwalk->end, pgoff + 1);
112         }                                         111         }
113                                                   112 
114         return 0;                                 113         return 0;
115 }                                                 114 }
116                                                   115 
117 /*                                                116 /*
118  * wp_clean_pmd_entry - The pagewalk pmd callb    117  * wp_clean_pmd_entry - The pagewalk pmd callback.
119  *                                                118  *
120  * Dirty-tracking should take place on the PTE    119  * Dirty-tracking should take place on the PTE level, so
121  * WARN() if encountering a dirty huge pmd.       120  * WARN() if encountering a dirty huge pmd.
122  * Furthermore, never split huge pmds, since t    121  * Furthermore, never split huge pmds, since that currently
123  * causes dirty info loss. The pagefault handl    122  * causes dirty info loss. The pagefault handler should do
124  * that if needed.                                123  * that if needed.
125  */                                               124  */
126 static int wp_clean_pmd_entry(pmd_t *pmd, unsi    125 static int wp_clean_pmd_entry(pmd_t *pmd, unsigned long addr, unsigned long end,
127                               struct mm_walk *    126                               struct mm_walk *walk)
128 {                                                 127 {
129         pmd_t pmdval = pmdp_get_lockless(pmd); !! 128         pmd_t pmdval = pmd_read_atomic(pmd);
130                                                   129 
131         /* Do not split a huge pmd, present or !! 130         if (!pmd_trans_unstable(&pmdval))
132         if (pmd_trans_huge(pmdval) || pmd_devm !! 131                 return 0;
133                 WARN_ON(pmd_write(pmdval) || p !! 132 
134                 walk->action = ACTION_CONTINUE !! 133         if (pmd_none(pmdval)) {
                                                   >> 134                 walk->action = ACTION_AGAIN;
                                                   >> 135                 return 0;
135         }                                         136         }
                                                   >> 137 
                                                   >> 138         /* Huge pmd, present or migrated */
                                                   >> 139         walk->action = ACTION_CONTINUE;
                                                   >> 140         if (pmd_trans_huge(pmdval) || pmd_devmap(pmdval))
                                                   >> 141                 WARN_ON(pmd_write(pmdval) || pmd_dirty(pmdval));
                                                   >> 142 
136         return 0;                                 143         return 0;
137 }                                                 144 }
138                                                   145 
139 /*                                                146 /*
140  * wp_clean_pud_entry - The pagewalk pud callb    147  * wp_clean_pud_entry - The pagewalk pud callback.
141  *                                                148  *
142  * Dirty-tracking should take place on the PTE    149  * Dirty-tracking should take place on the PTE level, so
143  * WARN() if encountering a dirty huge puds.      150  * WARN() if encountering a dirty huge puds.
144  * Furthermore, never split huge puds, since t    151  * Furthermore, never split huge puds, since that currently
145  * causes dirty info loss. The pagefault handl    152  * causes dirty info loss. The pagefault handler should do
146  * that if needed.                                153  * that if needed.
147  */                                               154  */
148 static int wp_clean_pud_entry(pud_t *pud, unsi    155 static int wp_clean_pud_entry(pud_t *pud, unsigned long addr, unsigned long end,
149                               struct mm_walk *    156                               struct mm_walk *walk)
150 {                                                 157 {
151 #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_P << 
152         pud_t pudval = READ_ONCE(*pud);           158         pud_t pudval = READ_ONCE(*pud);
153                                                   159 
154         /* Do not split a huge pud */          !! 160         if (!pud_trans_unstable(&pudval))
155         if (pud_trans_huge(pudval) || pud_devm !! 161                 return 0;
156                 WARN_ON(pud_write(pudval) || p !! 162 
157                 walk->action = ACTION_CONTINUE !! 163         if (pud_none(pudval)) {
                                                   >> 164                 walk->action = ACTION_AGAIN;
                                                   >> 165                 return 0;
158         }                                         166         }
                                                   >> 167 
                                                   >> 168 #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
                                                   >> 169         /* Huge pud */
                                                   >> 170         walk->action = ACTION_CONTINUE;
                                                   >> 171         if (pud_trans_huge(pudval) || pud_devmap(pudval))
                                                   >> 172                 WARN_ON(pud_write(pudval) || pud_dirty(pudval));
159 #endif                                            173 #endif
                                                   >> 174 
160         return 0;                                 175         return 0;
161 }                                                 176 }
162                                                   177 
163 /*                                                178 /*
164  * wp_clean_pre_vma - The pagewalk pre_vma cal    179  * wp_clean_pre_vma - The pagewalk pre_vma callback.
165  *                                                180  *
166  * The pre_vma callback performs the cache flu    181  * The pre_vma callback performs the cache flush, stages the tlb flush
167  * and calls the necessary mmu notifiers.         182  * and calls the necessary mmu notifiers.
168  */                                               183  */
169 static int wp_clean_pre_vma(unsigned long star    184 static int wp_clean_pre_vma(unsigned long start, unsigned long end,
170                             struct mm_walk *wa    185                             struct mm_walk *walk)
171 {                                                 186 {
172         struct wp_walk *wpwalk = walk->private    187         struct wp_walk *wpwalk = walk->private;
173                                                   188 
174         wpwalk->tlbflush_start = end;             189         wpwalk->tlbflush_start = end;
175         wpwalk->tlbflush_end = start;             190         wpwalk->tlbflush_end = start;
176                                                   191 
177         mmu_notifier_range_init(&wpwalk->range    192         mmu_notifier_range_init(&wpwalk->range, MMU_NOTIFY_PROTECTION_PAGE, 0,
178                                 walk->mm, star !! 193                                 walk->vma, walk->mm, start, end);
179         mmu_notifier_invalidate_range_start(&w    194         mmu_notifier_invalidate_range_start(&wpwalk->range);
180         flush_cache_range(walk->vma, start, en    195         flush_cache_range(walk->vma, start, end);
181                                                   196 
182         /*                                        197         /*
183          * We're not using tlb_gather_mmu() si    198          * We're not using tlb_gather_mmu() since typically
184          * only a small subrange of PTEs are a    199          * only a small subrange of PTEs are affected, whereas
185          * tlb_gather_mmu() records the full r    200          * tlb_gather_mmu() records the full range.
186          */                                       201          */
187         inc_tlb_flush_pending(walk->mm);          202         inc_tlb_flush_pending(walk->mm);
188                                                   203 
189         return 0;                                 204         return 0;
190 }                                                 205 }
191                                                   206 
192 /*                                                207 /*
193  * wp_clean_post_vma - The pagewalk post_vma c    208  * wp_clean_post_vma - The pagewalk post_vma callback.
194  *                                                209  *
195  * The post_vma callback performs the tlb flus    210  * The post_vma callback performs the tlb flush and calls necessary mmu
196  * notifiers.                                     211  * notifiers.
197  */                                               212  */
198 static void wp_clean_post_vma(struct mm_walk *    213 static void wp_clean_post_vma(struct mm_walk *walk)
199 {                                                 214 {
200         struct wp_walk *wpwalk = walk->private    215         struct wp_walk *wpwalk = walk->private;
201                                                   216 
202         if (mm_tlb_flush_nested(walk->mm))        217         if (mm_tlb_flush_nested(walk->mm))
203                 flush_tlb_range(walk->vma, wpw    218                 flush_tlb_range(walk->vma, wpwalk->range.start,
204                                 wpwalk->range.    219                                 wpwalk->range.end);
205         else if (wpwalk->tlbflush_end > wpwalk    220         else if (wpwalk->tlbflush_end > wpwalk->tlbflush_start)
206                 flush_tlb_range(walk->vma, wpw    221                 flush_tlb_range(walk->vma, wpwalk->tlbflush_start,
207                                 wpwalk->tlbflu    222                                 wpwalk->tlbflush_end);
208                                                   223 
209         mmu_notifier_invalidate_range_end(&wpw    224         mmu_notifier_invalidate_range_end(&wpwalk->range);
210         dec_tlb_flush_pending(walk->mm);          225         dec_tlb_flush_pending(walk->mm);
211 }                                                 226 }
212                                                   227 
213 /*                                                228 /*
214  * wp_clean_test_walk - The pagewalk test_walk    229  * wp_clean_test_walk - The pagewalk test_walk callback.
215  *                                                230  *
216  * Won't perform dirty-tracking on COW, read-o    231  * Won't perform dirty-tracking on COW, read-only or HUGETLB vmas.
217  */                                               232  */
218 static int wp_clean_test_walk(unsigned long st    233 static int wp_clean_test_walk(unsigned long start, unsigned long end,
219                               struct mm_walk *    234                               struct mm_walk *walk)
220 {                                                 235 {
221         unsigned long vm_flags = READ_ONCE(wal    236         unsigned long vm_flags = READ_ONCE(walk->vma->vm_flags);
222                                                   237 
223         /* Skip non-applicable VMAs */            238         /* Skip non-applicable VMAs */
224         if ((vm_flags & (VM_SHARED | VM_MAYWRI    239         if ((vm_flags & (VM_SHARED | VM_MAYWRITE | VM_HUGETLB)) !=
225             (VM_SHARED | VM_MAYWRITE))            240             (VM_SHARED | VM_MAYWRITE))
226                 return 1;                         241                 return 1;
227                                                   242 
228         return 0;                                 243         return 0;
229 }                                                 244 }
230                                                   245 
231 static const struct mm_walk_ops clean_walk_ops    246 static const struct mm_walk_ops clean_walk_ops = {
232         .pte_entry = clean_record_pte,            247         .pte_entry = clean_record_pte,
233         .pmd_entry = wp_clean_pmd_entry,          248         .pmd_entry = wp_clean_pmd_entry,
234         .pud_entry = wp_clean_pud_entry,          249         .pud_entry = wp_clean_pud_entry,
235         .test_walk = wp_clean_test_walk,          250         .test_walk = wp_clean_test_walk,
236         .pre_vma = wp_clean_pre_vma,              251         .pre_vma = wp_clean_pre_vma,
237         .post_vma = wp_clean_post_vma             252         .post_vma = wp_clean_post_vma
238 };                                                253 };
239                                                   254 
240 static const struct mm_walk_ops wp_walk_ops =     255 static const struct mm_walk_ops wp_walk_ops = {
241         .pte_entry = wp_pte,                      256         .pte_entry = wp_pte,
242         .pmd_entry = wp_clean_pmd_entry,          257         .pmd_entry = wp_clean_pmd_entry,
243         .pud_entry = wp_clean_pud_entry,          258         .pud_entry = wp_clean_pud_entry,
244         .test_walk = wp_clean_test_walk,          259         .test_walk = wp_clean_test_walk,
245         .pre_vma = wp_clean_pre_vma,              260         .pre_vma = wp_clean_pre_vma,
246         .post_vma = wp_clean_post_vma             261         .post_vma = wp_clean_post_vma
247 };                                                262 };
248                                                   263 
249 /**                                               264 /**
250  * wp_shared_mapping_range - Write-protect all    265  * wp_shared_mapping_range - Write-protect all ptes in an address space range
251  * @mapping: The address_space we want to writ    266  * @mapping: The address_space we want to write protect
252  * @first_index: The first page offset in the     267  * @first_index: The first page offset in the range
253  * @nr: Number of incremental page offsets to     268  * @nr: Number of incremental page offsets to cover
254  *                                                269  *
255  * Note: This function currently skips transhu    270  * Note: This function currently skips transhuge page-table entries, since
256  * it's intended for dirty-tracking on the PTE    271  * it's intended for dirty-tracking on the PTE level. It will warn on
257  * encountering transhuge write-enabled entrie    272  * encountering transhuge write-enabled entries, though, and can easily be
258  * extended to handle them as well.               273  * extended to handle them as well.
259  *                                                274  *
260  * Return: The number of ptes actually write-p    275  * Return: The number of ptes actually write-protected. Note that
261  * already write-protected ptes are not counte    276  * already write-protected ptes are not counted.
262  */                                               277  */
263 unsigned long wp_shared_mapping_range(struct a    278 unsigned long wp_shared_mapping_range(struct address_space *mapping,
264                                       pgoff_t     279                                       pgoff_t first_index, pgoff_t nr)
265 {                                                 280 {
266         struct wp_walk wpwalk = { .total = 0 }    281         struct wp_walk wpwalk = { .total = 0 };
267                                                   282 
268         i_mmap_lock_read(mapping);                283         i_mmap_lock_read(mapping);
269         WARN_ON(walk_page_mapping(mapping, fir    284         WARN_ON(walk_page_mapping(mapping, first_index, nr, &wp_walk_ops,
270                                   &wpwalk));      285                                   &wpwalk));
271         i_mmap_unlock_read(mapping);              286         i_mmap_unlock_read(mapping);
272                                                   287 
273         return wpwalk.total;                      288         return wpwalk.total;
274 }                                                 289 }
275 EXPORT_SYMBOL_GPL(wp_shared_mapping_range);       290 EXPORT_SYMBOL_GPL(wp_shared_mapping_range);
276                                                   291 
277 /**                                               292 /**
278  * clean_record_shared_mapping_range - Clean a    293  * clean_record_shared_mapping_range - Clean and record all ptes in an
279  * address space range                            294  * address space range
280  * @mapping: The address_space we want to clea    295  * @mapping: The address_space we want to clean
281  * @first_index: The first page offset in the     296  * @first_index: The first page offset in the range
282  * @nr: Number of incremental page offsets to     297  * @nr: Number of incremental page offsets to cover
283  * @bitmap_pgoff: The page offset of the first    298  * @bitmap_pgoff: The page offset of the first bit in @bitmap
284  * @bitmap: Pointer to a bitmap of at least @n    299  * @bitmap: Pointer to a bitmap of at least @nr bits. The bitmap needs to
285  * cover the whole range @first_index..@first_    300  * cover the whole range @first_index..@first_index + @nr.
286  * @start: Pointer to number of the first set     301  * @start: Pointer to number of the first set bit in @bitmap.
287  * is modified as new bits are set by the func    302  * is modified as new bits are set by the function.
288  * @end: Pointer to the number of the last set    303  * @end: Pointer to the number of the last set bit in @bitmap.
289  * none set. The value is modified as new bits    304  * none set. The value is modified as new bits are set by the function.
290  *                                                305  *
291  * When this function returns there is no guar !! 306  * Note: When this function returns there is no guarantee that a CPU has
292  * not already dirtied new ptes. However it wi    307  * not already dirtied new ptes. However it will not clean any ptes not
293  * reported in the bitmap. The guarantees are     308  * reported in the bitmap. The guarantees are as follows:
294  *                                             !! 309  * a) All ptes dirty when the function starts executing will end up recorded
295  * * All ptes dirty when the function starts e !! 310  *    in the bitmap.
296  *   in the bitmap.                            !! 311  * b) All ptes dirtied after that will either remain dirty, be recorded in the
297  * * All ptes dirtied after that will either r !! 312  *    bitmap or both.
298  *   bitmap or both.                           << 
299  *                                                313  *
300  * If a caller needs to make sure all dirty pt    314  * If a caller needs to make sure all dirty ptes are picked up and none
301  * additional are added, it first needs to wri    315  * additional are added, it first needs to write-protect the address-space
302  * range and make sure new writers are blocked    316  * range and make sure new writers are blocked in page_mkwrite() or
303  * pfn_mkwrite(). And then after a TLB flush f    317  * pfn_mkwrite(). And then after a TLB flush following the write-protection
304  * pick up all dirty bits.                        318  * pick up all dirty bits.
305  *                                                319  *
306  * This function currently skips transhuge pag    320  * This function currently skips transhuge page-table entries, since
307  * it's intended for dirty-tracking on the PTE    321  * it's intended for dirty-tracking on the PTE level. It will warn on
308  * encountering transhuge dirty entries, thoug    322  * encountering transhuge dirty entries, though, and can easily be extended
309  * to handle them as well.                        323  * to handle them as well.
310  *                                                324  *
311  * Return: The number of dirty ptes actually c    325  * Return: The number of dirty ptes actually cleaned.
312  */                                               326  */
313 unsigned long clean_record_shared_mapping_rang    327 unsigned long clean_record_shared_mapping_range(struct address_space *mapping,
314                                                   328                                                 pgoff_t first_index, pgoff_t nr,
315                                                   329                                                 pgoff_t bitmap_pgoff,
316                                                   330                                                 unsigned long *bitmap,
317                                                   331                                                 pgoff_t *start,
318                                                   332                                                 pgoff_t *end)
319 {                                                 333 {
320         bool none_set = (*start >= *end);         334         bool none_set = (*start >= *end);
321         struct clean_walk cwalk = {               335         struct clean_walk cwalk = {
322                 .base = { .total = 0 },           336                 .base = { .total = 0 },
323                 .bitmap_pgoff = bitmap_pgoff,     337                 .bitmap_pgoff = bitmap_pgoff,
324                 .bitmap = bitmap,                 338                 .bitmap = bitmap,
325                 .start = none_set ? nr : *star    339                 .start = none_set ? nr : *start,
326                 .end = none_set ? 0 : *end,       340                 .end = none_set ? 0 : *end,
327         };                                        341         };
328                                                   342 
329         i_mmap_lock_read(mapping);                343         i_mmap_lock_read(mapping);
330         WARN_ON(walk_page_mapping(mapping, fir    344         WARN_ON(walk_page_mapping(mapping, first_index, nr, &clean_walk_ops,
331                                   &cwalk.base)    345                                   &cwalk.base));
332         i_mmap_unlock_read(mapping);              346         i_mmap_unlock_read(mapping);
333                                                   347 
334         *start = cwalk.start;                     348         *start = cwalk.start;
335         *end = cwalk.end;                         349         *end = cwalk.end;
336                                                   350 
337         return cwalk.base.total;                  351         return cwalk.base.total;
338 }                                                 352 }
339 EXPORT_SYMBOL_GPL(clean_record_shared_mapping_    353 EXPORT_SYMBOL_GPL(clean_record_shared_mapping_range);
340                                                   354 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php