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