lkml.org 
[lkml]   [2010]   [Aug]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [BUGFIX][PATCH] fix corruption of hibernation caused by reusing swap at saving image
On Wed, 4 Aug 2010 11:31:22 +0900
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> wrote:

> On Wed, 4 Aug 2010 10:50:54 +0900
> KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> wrote:
>
> > This patch is created against 2.6.35. CC'ed stable.
> > Thank you for all helps.
> >
>
> I'm sorry I now doubt this patch is wrong.

Changed the description.
Maybe the patch description/my understanding was wrong
but the patch itself should work.

==
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 resume.
The scenario is
- Assume a clean-swap cache, but mapped.
- at hibernation_snapshot[], clean-swap-cache is saved as
clean-swap-cache and swap_map[] is marked as SWAP_HAS_CACHE.
- then, save_image() is called. And reuse SWAP_HAS_CACHE entry
to save image, and break the contents.
After resume.
- the memory reclaim runs and finds clean-not-referenced-swap-cache
and discards it because it's marked as clean.
But here, the contents on disk and swap-cache is inconsistent.

Here, memory is corrupted.


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);


\
 
 \ /
  Last update: 2010-08-04 04:53    [W:0.086 / U:0.116 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site