-
-#include <asm/pgtable.h>
-#include <asm/tlbflush.h>
-
-/*
- * Called with mm->page_table_lock held to protect against other
- * threads/the swapper from ripping pte's out from under us.
- */
-
-static void msync_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
- unsigned long addr, unsigned long end)
-{
- struct mm_struct *mm = vma->vm_mm;
- pte_t *pte;
- int progress = 0;
-
-again:
- pte = pte_offset_map(pmd, addr);
- do {
- unsigned long pfn;
- struct page *page;
-
- if (progress >= 64) {
- progress = 0;
- if (need_resched() ||
- need_lockbreak(&mm->page_table_lock))
- break;
- }
- progress++;
- if (!pte_present(*pte))
- continue;
- if (!pte_maybe_dirty(*pte))
- continue;
- pfn = pte_pfn(*pte);
- if (unlikely(!pfn_valid(pfn))) {
- print_bad_pte(vma, *pte, addr);
- continue;
- }
- page = pfn_to_page(pfn);
-
- if (ptep_clear_flush_dirty(vma, addr, pte) ||
- page_test_and_clear_dirty(page))
- set_page_dirty(page);
- progress += 3;
- } while (pte++, addr += PAGE_SIZE, addr != end);
- pte_unmap(pte - 1);
- cond_resched_lock(&mm->page_table_lock);
- if (addr != end)
- goto again;
-}
-
-static inline void msync_pmd_range(struct vm_area_struct *vma, pud_t *pud,
- unsigned long addr, unsigned long end)
-{
- pmd_t *pmd;
- unsigned long next;
-
- pmd = pmd_offset(pud, addr);
- do {
- next = pmd_addr_end(addr, end);
- if (pmd_none_or_clear_bad(pmd))
- continue;
- msync_pte_range(vma, pmd, addr, next);
- } while (pmd++, addr = next, addr != end);
-}
-
-static inline void msync_pud_range(struct vm_area_struct *vma, pgd_t *pgd,
- unsigned long addr, unsigned long end)
-{
- pud_t *pud;
- unsigned long next;
-
- pud = pud_offset(pgd, addr);
- do {
- next = pud_addr_end(addr, end);
- if (pud_none_or_clear_bad(pud))
- continue;
- msync_pmd_range(vma, pud, addr, next);
- } while (pud++, addr = next, addr != end);
-}
-
-static void msync_page_range(struct vm_area_struct *vma,
- unsigned long addr, unsigned long end)
-{
- struct mm_struct *mm = vma->vm_mm;
- pgd_t *pgd;
- unsigned long next;
-
- /* For hugepages we can't go walking the page table normally,
- * but that's ok, hugetlbfs is memory based, so we don't need
- * to do anything more on an msync().
- * Can't do anything with VM_RESERVED regions either.
- */
- if (vma->vm_flags & (VM_HUGETLB|VM_RESERVED))
- return;
-
- BUG_ON(addr >= end);
- pgd = pgd_offset(mm, addr);
- flush_cache_range(vma, addr, end);
- spin_lock(&mm->page_table_lock);
- do {
- next = pgd_addr_end(addr, end);
- if (pgd_none_or_clear_bad(pgd))
- continue;
- msync_pud_range(vma, pgd, addr, next);
- } while (pgd++, addr = next, addr != end);
- spin_unlock(&mm->page_table_lock);
-}