Skip to content

Commit 68b5a65

Browse files
peterfeinertorvalds
authored andcommitted
mm: softdirty: respect VM_SOFTDIRTY in PTE holes
After a VMA is created with the VM_SOFTDIRTY flag set, /proc/pid/pagemap should report that the VMA's virtual pages are soft-dirty until VM_SOFTDIRTY is cleared (i.e., by the next write of "4" to /proc/pid/clear_refs). However, pagemap ignores the VM_SOFTDIRTY flag for virtual addresses that fall in PTE holes (i.e., virtual addresses that don't have a PMD, PUD, or PGD allocated yet). To observe this bug, use mmap to create a VMA large enough such that there's a good chance that the VMA will occupy an unused PMD, then test the soft-dirty bit on its pages. In practice, I found that a VMA that covered a PMD's worth of address space was big enough. This patch adds the necessary VMA lookup to the PTE hole callback in /proc/pid/pagemap's page walk and sets soft-dirty according to the VMAs' VM_SOFTDIRTY flag. Signed-off-by: Peter Feiner <pfeiner@google.com> Acked-by: Cyrill Gorcunov <gorcunov@openvz.org> Cc: Pavel Emelyanov <xemul@parallels.com> Cc: Hugh Dickins <hughd@google.com> Acked-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 3a91053 commit 68b5a65

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

‎fs/proc/task_mmu.c‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -925,15 +925,30 @@ static int pagemap_pte_hole(unsigned long start, unsigned long end,
925925
struct mm_walk *walk)
926926
{
927927
struct pagemapread *pm = walk->private;
928-
unsigned long addr;
928+
unsigned long addr = start;
929929
int err = 0;
930-
pagemap_entry_t pme = make_pme(PM_NOT_PRESENT(pm->v2));
931930

932-
for (addr = start; addr < end; addr += PAGE_SIZE) {
933-
err = add_to_pagemap(addr, &pme, pm);
934-
if (err)
935-
break;
931+
while (addr < end) {
932+
struct vm_area_struct *vma = find_vma(walk->mm, addr);
933+
pagemap_entry_t pme = make_pme(PM_NOT_PRESENT(pm->v2));
934+
unsigned long vm_end;
935+
936+
if (!vma) {
937+
vm_end = end;
938+
} else {
939+
vm_end = min(end, vma->vm_end);
940+
if (vma->vm_flags & VM_SOFTDIRTY)
941+
pme.pme |= PM_STATUS2(pm->v2, __PM_SOFT_DIRTY);
942+
}
943+
944+
for (; addr < vm_end; addr += PAGE_SIZE) {
945+
err = add_to_pagemap(addr, &pme, pm);
946+
if (err)
947+
goto out;
948+
}
936949
}
950+
951+
out:
937952
return err;
938953
}
939954

0 commit comments

Comments
 (0)