[BUGFIX][PATCH] fix corruption of hibernation caused by reusing swap at saving image

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: KAMEZAWA Hiroyuki
Date: Tuesday, August 3, 2010 - 6:50 pm

This patch is created against 2.6.35. CC'ed stable.
Thank you for all helps.

=
From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

Since 2.6.31, swap_map[]'s refcounting was changed to show that
a used swap entry is just for swap-cache, can be reused.
Then, while scanning free entry in swap_map[], a swap entry may
be able to be reclaimed and reused. It was by the commit
c9e444103b5e7a5a3519f9913f59767f92e33baf.

But this caused deta corruption at hibernation. Considering how
the image is saved, the calls of try_to_reclaim_swap() changes the
status of memory and there will be inconsitency between saved-memory-image's
swap_map[] / memmap / swapper_space because memory is saved per page with
swap-allocation per page.

This patch is for avoiding bug by not reclaiming swap-entry at hibernation.
This is a quick fix for backporting.

Cc: stable@kernel.org
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Reported-by: Ondreg Zary <linux@rainbow-software.org>
Tested-by: Andrea Gelmini <andrea.gelmini@gmail.com>
Acked-by: Hugh Dickins <hughd@google.com>
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
---
 mm/swapfile.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Index: linux-2.6.35.org/mm/swapfile.c
===================================================================
--- linux-2.6.35.org.orig/mm/swapfile.c
+++ linux-2.6.35.org/mm/swapfile.c
@@ -318,8 +318,10 @@ checks:
 	if (offset > si->highest_bit)
 		scan_base = offset = si->lowest_bit;
 
-	/* reuse swap entry of cache-only swap if not busy. */
-	if (vm_swap_full() && si->swap_map[offset] == SWAP_HAS_CACHE) {
+	/* reuse swap entry of cache-only swap if not hibernation. */
+	if (vm_swap_full()
+		&& usage == SWAP_HAS_CACHE
+		&& si->swap_map[offset] == SWAP_HAS_CACHE) {
 		int swap_was_freed;
 		spin_unlock(&swap_lock);
 		swap_was_freed = __try_to_reclaim_swap(si, offset);

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Memory corruption during hibernation since 2.6.31, Ondrej Zary, (Wed Jul 28, 2:20 pm)
Re: Memory corruption during hibernation since 2.6.31, Rafael J. Wysocki, (Wed Jul 28, 2:34 pm)
Re: Memory corruption during hibernation since 2.6.31, Ondrej Zary, (Wed Jul 28, 2:38 pm)
Re: Memory corruption during hibernation since 2.6.31, KAMEZAWA Hiroyuki, (Wed Jul 28, 6:06 pm)
Re: Memory corruption during hibernation since 2.6.31, KAMEZAWA Hiroyuki, (Wed Jul 28, 7:51 pm)
Re: Memory corruption during hibernation since 2.6.31, KAMEZAWA Hiroyuki, (Wed Jul 28, 9:23 pm)
Re: Memory corruption during hibernation since 2.6.31, KOSAKI Motohiro, (Wed Jul 28, 10:23 pm)
Re: Memory corruption during hibernation since 2.6.31, KAMEZAWA Hiroyuki, (Wed Jul 28, 10:24 pm)
Re: Memory corruption during hibernation since 2.6.31, KOSAKI Motohiro, (Wed Jul 28, 10:30 pm)
Re: Memory corruption during hibernation since 2.6.31, Ondrej Zary, (Thu Jul 29, 10:33 am)
Re: Memory corruption during hibernation since 2.6.31, Hugh Dickins, (Thu Jul 29, 11:44 am)
Re: Memory corruption during hibernation since 2.6.31, Andrea Arcangeli, (Thu Jul 29, 11:55 am)
Re: Memory corruption during hibernation since 2.6.31, Rafael J. Wysocki, (Thu Jul 29, 4:29 pm)
Re: Memory corruption during hibernation since 2.6.31, Rafael J. Wysocki, (Thu Jul 29, 4:40 pm)
Re: Memory corruption during hibernation since 2.6.31, KAMEZAWA Hiroyuki, (Thu Jul 29, 5:01 pm)
Re: Memory corruption during hibernation since 2.6.31, KAMEZAWA Hiroyuki, (Thu Jul 29, 8:36 pm)
Re: Memory corruption during hibernation since 2.6.31, Hugh Dickins, (Thu Jul 29, 8:54 pm)
Re: Memory corruption during hibernation since 2.6.31, Hugh Dickins, (Thu Jul 29, 9:02 pm)
Re: Memory corruption during hibernation since 2.6.31, Hugh Dickins, (Thu Jul 29, 9:10 pm)
Re: Memory corruption during hibernation since 2.6.31, KAMEZAWA Hiroyuki, (Thu Jul 29, 9:14 pm)
Re: Memory corruption during hibernation since 2.6.31, Balbir Singh, (Thu Jul 29, 9:18 pm)
Re: Memory corruption during hibernation since 2.6.31, Hugh Dickins, (Thu Jul 29, 9:32 pm)
Re: Memory corruption during hibernation since 2.6.31, Hugh Dickins, (Thu Jul 29, 9:46 pm)
Re: Memory corruption during hibernation since 2.6.31, Balbir Singh, (Thu Jul 29, 11:37 pm)
Re: Memory corruption during hibernation since 2.6.31, KAMEZAWA Hiroyuki, (Fri Jul 30, 3:43 am)
Re: Memory corruption during hibernation since 2.6.31, Hugh Dickins, (Fri Jul 30, 11:16 am)
[RFC][PATCH -mm] hibernation: freeze swap at hibernation ( ..., KAMEZAWA Hiroyuki, (Sun Aug 1, 11:02 pm)
Re: Memory corruption during hibernation since 2.6.31, Andrea Gelmini, (Tue Aug 3, 3:50 am)
Re: Memory corruption during hibernation since 2.6.31, KAMEZAWA Hiroyuki, (Tue Aug 3, 4:36 pm)
[BUGFIX][PATCH] fix corruption of hibernation caused by re ..., KAMEZAWA Hiroyuki, (Tue Aug 3, 6:50 pm)
[PATCH -mm] hibernation: freeze swap at hibernation v2, KAMEZAWA Hiroyuki, (Tue Aug 3, 9:57 pm)
Re: [PATCH -mm] hibernation: freeze swap at hibernation v2, KAMEZAWA Hiroyuki, (Wed Aug 4, 5:32 pm)
Re: Memory corruption during hibernation since 2.6.31, Andrea Gelmini, (Thu Aug 5, 4:41 am)
Re: Memory corruption during hibernation since 2.6.31, Pavel Machek, (Mon Aug 9, 12:26 am)