Skip to content

Commit

Permalink
[PATCH] mm: fixup do_wp_page()
Browse files Browse the repository at this point in the history
Wrt. the recent modifications in do_wp_page() Hugh Dickins pointed out:

  "I now realize it's right to the first order (normal case) and to the
   second order (ptrace poke), but not to the third order (ptrace poke
   anon page here to be COWed - perhaps can't occur without intervening
   mprotects)."

This patch restores the old COW behaviour for anonymous pages.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Peter Zijlstra authored and Linus Torvalds committed Sep 26, 2006
1 parent e88dd6c commit ee6a645
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions mm/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1467,11 +1467,21 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma,
goto gotten;

/*
* Only catch write-faults on shared writable pages, read-only
* shared pages can get COWed by get_user_pages(.write=1, .force=1).
* Take out anonymous pages first, anonymous shared vmas are
* not dirty accountable.
*/
if (unlikely((vma->vm_flags & (VM_WRITE|VM_SHARED)) ==
if (PageAnon(old_page)) {
if (!TestSetPageLocked(old_page)) {
reuse = can_share_swap_page(old_page);
unlock_page(old_page);
}
} else if (unlikely((vma->vm_flags & (VM_WRITE|VM_SHARED)) ==
(VM_WRITE|VM_SHARED))) {
/*
* Only catch write-faults on shared writable pages,
* read-only shared pages can get COWed by
* get_user_pages(.write=1, .force=1).
*/
if (vma->vm_ops && vma->vm_ops->page_mkwrite) {
/*
* Notify the address space that the page is about to
Expand Down Expand Up @@ -1503,9 +1513,6 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma,
dirty_page = old_page;
get_page(dirty_page);
reuse = 1;
} else if (PageAnon(old_page) && !TestSetPageLocked(old_page)) {
reuse = can_share_swap_page(old_page);
unlock_page(old_page);
}

if (reuse) {
Expand Down

0 comments on commit ee6a645

Please sign in to comment.