Skip to content

Commit

Permalink
mm: find_get_pages_contig fixlet
Browse files Browse the repository at this point in the history
Testing ->mapping and ->index without a ref is not stable as the page
may have been reused at this point.

Signed-off-by: Nick Piggin <npiggin@kernel.dk>
Reviewed-by: Wu Fengguang <fengguang.wu@intel.com>
Reviewed-by: Minchan Kim <minchan.kim@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Nick Piggin authored and Linus Torvalds committed Jan 14, 2011
1 parent f0bc0a6 commit 9cbb4cb
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions mm/filemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,6 @@ unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t index,
if (radix_tree_deref_retry(page))
goto restart;

if (page->mapping == NULL || page->index != index)
break;

if (!page_cache_get_speculative(page))
goto repeat;

Expand All @@ -849,6 +846,16 @@ unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t index,
goto repeat;
}

/*
* must check mapping and index after taking the ref.
* otherwise we can get both false positives and false
* negatives, which is just confusing to the caller.
*/
if (page->mapping == NULL || page->index != index) {
page_cache_release(page);
break;
}

pages[ret] = page;
ret++;
index++;
Expand Down

0 comments on commit 9cbb4cb

Please sign in to comment.