Hugh Dickins 68bdc8d647 mm: try_to_unuse check removing right swap
There's a possible race in try_to_unuse() which Nick Piggin led me to two
years ago.  Where it does lock_page() after read_swap_cache_async(), what
if another task removed that page from swapcache just before we locked it?

It would sail though the (*swap_map > 1) tests doing nothing (because it
could not have been removed from swapcache before its swap references were
gone), until it reaches the delete_from_swap_cache(page) near the bottom.

Now imagine that this page has been allocated to swap on a different swap
area while we dropped page lock (perhaps at the top, perhaps in unuse_mm):
we could wrongly remove from swap cache before the page has been written
to swap, so a subsequent do_swap_page() would read in stale data from
swap.

I think this case could not happen before: remove_exclusive_swap_page()
refused while page count was raised.  But now with reuse_swap_page() and
try_to_free_swap() removing from swap cache without minding page count, I
think it could happen - the previous patch argued that it was safe because
try_to_unuse() already ignored page count, but overlooked that it might be
breaking the assumptions in try_to_unuse() itself.

Signed-off-by: Hugh Dickins <hugh@veritas.com>
Cc: Lee Schermerhorn <lee.schermerhorn@hp.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Robin Holt <holt@sgi.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2009-01-06 15:59:03 -08:00
..
2008-12-29 11:27:46 +02:00
2009-01-06 15:58:59 -08:00
2008-10-20 08:50:26 -07:00
2008-12-29 11:27:46 +02:00
2008-10-23 08:55:02 -07:00
2008-11-14 11:29:12 +11:00
2007-10-20 01:27:18 +02:00
2009-01-06 15:59:02 -08:00
2008-04-28 08:58:18 -07:00
2008-12-20 09:15:47 +01:00
2009-01-05 17:44:42 -08:00
2008-07-28 16:30:21 -07:00
2009-01-05 17:44:42 -08:00
2009-01-05 11:54:28 -05:00
2009-01-05 11:54:28 -05:00
2008-06-12 18:05:41 -07:00
2009-01-01 10:12:29 +10:30
2007-10-20 01:27:18 +02:00
2009-01-01 10:12:29 +10:30
2009-01-01 10:12:29 +10:30
2008-11-30 10:03:35 -08:00
2009-01-01 10:12:29 +10:30