Re: [linux-pm] [PATCH 1/2] Hibernate: Take overlapping zones into account

Previous thread: [PATCH] Fix __pfn_to_page(pfn) for CONFIG_DISCONTIGMEM=y by Rafael J. Wysocki on Saturday, November 8, 2008 - 5:53 am. (6 messages)

Next thread: [PATCH -next] Hibernate: Do not oops on resume if image data are incorrect by Rafael J. Wysocki on Saturday, November 8, 2008 - 5:57 am. (2 messages)
From: Rafael J. Wysocki
Date: Saturday, November 8, 2008 - 5:56 am

Hi Len,

Please add this patch to the suspend branch.

Thanks,
Rafael


---
From: Rafael J. Wysocki <rjw@sisk.pl>
Subject: Hibernate: Take overlapping zones into account

It has been requested to make hibernation work with memory
hotplugging enabled and for this purpose the hibernation code has to
be reworked to take the possible overlapping of zones into account.
Thus, rework the hibernation memory bitmaps code to prevent
duplication of PFNs from occuring and add checks to make sure that
one page frame will not be marked as saveable many times.

Additionally, use list.h lists instead of open-coded lists to
implement the memory bitmaps.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Pavel Machek <pavel@suse.cz>
Cc: Dave Hansen <dave@linux.vnet.ibm.com>
Cc: Andy Whitcroft <apw@shadowen.org>
---
 kernel/power/snapshot.c |  331 ++++++++++++++++++++++++------------------------
 1 file changed, 169 insertions(+), 162 deletions(-)

Index: linux-2.6/kernel/power/snapshot.c
===================================================================
--- linux-2.6.orig/kernel/power/snapshot.c
+++ linux-2.6/kernel/power/snapshot.c
@@ -25,6 +25,7 @@
 #include <linux/syscalls.h>
 #include <linux/console.h>
 #include <linux/highmem.h>
+#include <linux/list.h>
 
 #include <asm/uaccess.h>
 #include <asm/mmu_context.h>
@@ -192,12 +193,6 @@ static void *chain_alloc(struct chain_al
 	return ret;
 }
 
-static void chain_free(struct chain_allocator *ca, int clear_page_nosave)
-{
-	free_list_of_pages(ca->chain, clear_page_nosave);
-	memset(ca, 0, sizeof(struct chain_allocator));
-}
-
 /**
  *	Data types related to memory bitmaps.
  *
@@ -233,7 +228,7 @@ static void chain_free(struct chain_allo
 #define BM_BITS_PER_BLOCK	(PAGE_SIZE << 3)
 
 struct bm_block {
-	struct bm_block *next;		/* next element of the list */
+	struct list_head hook;	/* hook into a list of bitmap blocks */
 	unsigned long start_pfn;	/* pfn represented by the first bit */
 	unsigned long end_pfn;	/* pfn ...
From: Len Brown
Date: Tuesday, November 11, 2008 - 11:07 am

Please re-send a checkpatch clean version.

Also, the comments on this patch (and the next) are mal-formed.
The commit message must be before the first "---" and the throw-away
comments must be after it, rather thant the reverse.

I ask others to get this right, so it seems most fair that I do the
same for you -- otherwise your next patch will have the same problems
and others will follow your example of not sending the "perfect patch"

thanks,
--

From: Rafael J. Wysocki
Date: Tuesday, November 11, 2008 - 1:30 pm

OK, here you go.  The following two messages contain the updated patches
(still, 4 out of the 5 checkpatch.pl "errors" in the first patch were plain
wrong IMO).

Thanks,
Rafael

--

From: Rafael J. Wysocki
Date: Tuesday, November 11, 2008 - 1:32 pm

From: Rafael J. Wysocki <rjw@sisk.pl>
Subject: Hibernate: Do not oops on resume if image data are incorrect

During resume from hibernation using the userland interface image
data are being passed from the used space process to the kernel.
These data need not be valid, but currently the kernel sometimes
oopses if it gets invalid image data, which is wrong.  Make the
kernel return error codes to the user space in such cases.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@suse.cz>
---
 kernel/power/snapshot.c |   43 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 32 insertions(+), 11 deletions(-)

Index: linux-2.6/kernel/power/snapshot.c
===================================================================
--- linux-2.6.orig/kernel/power/snapshot.c
+++ linux-2.6/kernel/power/snapshot.c
@@ -528,6 +528,14 @@ static int memory_bm_test_bit(struct mem
 	return test_bit(bit, addr);
 }
 
+static bool memory_bm_pfn_present(struct memory_bitmap *bm, unsigned long pfn)
+{
+	void *addr;
+	unsigned int bit;
+
+	return !memory_bm_find_bit(bm, pfn, &addr, &bit);
+}
+
 /**
  *	memory_bm_next_pfn - find the pfn that corresponds to the next set bit
  *	in the bitmap @bm.  If the pfn cannot be found, BM_END_OF_MAP is
@@ -1465,9 +1473,7 @@ load_header(struct swsusp_info *info)
  *	unpack_orig_pfns - for each element of @buf[] (1 page at a time) set
  *	the corresponding bit in the memory bitmap @bm
  */
-
-static inline void
-unpack_orig_pfns(unsigned long *buf, struct memory_bitmap *bm)
+static int unpack_orig_pfns(unsigned long *buf, struct memory_bitmap *bm)
 {
 	int j;
 
@@ -1475,8 +1481,13 @@ unpack_orig_pfns(unsigned long *buf, str
 		if (unlikely(buf[j] == BM_END_OF_MAP))
 			break;
 
-		memory_bm_set_bit(bm, buf[j]);
+		if (memory_bm_pfn_present(bm, buf[j]))
+			memory_bm_set_bit(bm, buf[j]);
+		else
+			return -EFAULT;
 	}
+
+	return 0;
 }
 
 /* List of "safe" pages that may be used to store data loaded from the ...
From: Rafael J. Wysocki
Date: Tuesday, November 11, 2008 - 1:31 pm

From: Rafael J. Wysocki <rjw@sisk.pl>
Subject: Hibernate: Take overlapping zones into account

It has been requested to make hibernation work with memory
hotplugging enabled and for this purpose the hibernation code has to
be reworked to take the possible overlapping of zones into account.
Thus, rework the hibernation memory bitmaps code to prevent
duplication of PFNs from occuring and add checks to make sure that
one page frame will not be marked as saveable many times.

Additionally, use list.h lists instead of open-coded lists to
implement the memory bitmaps.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Pavel Machek <pavel@suse.cz>
Cc: Dave Hansen <dave@linux.vnet.ibm.com>
Cc: Andy Whitcroft <apw@shadowen.org>
---
 kernel/power/snapshot.c |  326 ++++++++++++++++++++++++------------------------
 1 file changed, 166 insertions(+), 160 deletions(-)

Index: linux-2.6/kernel/power/snapshot.c
===================================================================
--- linux-2.6.orig/kernel/power/snapshot.c
+++ linux-2.6/kernel/power/snapshot.c
@@ -25,6 +25,7 @@
 #include <linux/syscalls.h>
 #include <linux/console.h>
 #include <linux/highmem.h>
+#include <linux/list.h>
 
 #include <asm/uaccess.h>
 #include <asm/mmu_context.h>
@@ -192,12 +193,6 @@ static void *chain_alloc(struct chain_al
 	return ret;
 }
 
-static void chain_free(struct chain_allocator *ca, int clear_page_nosave)
-{
-	free_list_of_pages(ca->chain, clear_page_nosave);
-	memset(ca, 0, sizeof(struct chain_allocator));
-}
-
 /**
  *	Data types related to memory bitmaps.
  *
@@ -233,7 +228,7 @@ static void chain_free(struct chain_allo
 #define BM_BITS_PER_BLOCK	(PAGE_SIZE << 3)
 
 struct bm_block {
-	struct bm_block *next;		/* next element of the list */
+	struct list_head hook;	/* hook into a list of bitmap blocks */
 	unsigned long start_pfn;	/* pfn represented by the first bit */
 	unsigned long end_pfn;	/* pfn represented by the last bit plus 1 */
 	unsigned long *data;	/* bitmap representing ...
From: Nigel Cunningham
Date: Tuesday, November 11, 2008 - 2:25 pm

Hi Rafael.


Is list_add_tail right? You seem to be relying on the list being ordered


Is anything above here related to the hotplug memory support? If not,

Regards,

Nigel

--

From: Rafael J. Wysocki
Date: Tuesday, November 11, 2008 - 4:30 pm

Unfortunately, the first part of the patch introduces a potentially dangerous
situation that is only prevented by the second part.

Namely, if there are overlapping zones, the first part will only cause the
"true" pages to be saved.  Assume that the "true" PFN is in the second of the
two overlapping zones.  Then, on resume the bit corresponding to this PFN will
be set in the first zone and the ordering of pages in the image will be
invalid.  That's why the second part is necessary in the same patch.

Thanks,
Rafael
--

From: Rafael J. Wysocki
Date: Friday, November 14, 2008 - 5:32 pm

Yes, I do and it is right.  From list.h:

/**
 * list_add_tail - add a new entry
 * @new: new entry to be added
 * @head: list head to add it before
 *


This one I already answered.

Thanks,
Rafael
--


thanks, i've stashed them on the suspend branch.

I assume you'll be replying to nigel and that there

send that observation to the checkpatch maintainers then.

thanks,
-len


--

From: Rafael J. Wysocki
Date: Friday, November 14, 2008 - 6:01 pm

Hi Len,

Please replace the "Hibernate: Take overlapping zones into account" patch
(commit 7bff0a928535512dc61cfc81c8ce5dd2a0e53f19 in the suspend branch) with
the new version in the following message.

The old version introduces a tiny memory leak in create_mem_extents().

Thanks,
Rafael

--

From: Rafael J. Wysocki
Date: Friday, November 14, 2008 - 6:02 pm

From: Rafael J. Wysocki <rjw@sisk.pl>
Subject: Hibernate: Take overlapping zones into account (rev. 2)

It has been requested to make hibernation work with memory
hotplugging enabled and for this purpose the hibernation code has to
be reworked to take the possible overlapping of zones into account.
Thus, rework the hibernation memory bitmaps code to prevent
duplication of PFNs from occuring and add checks to make sure that
one page frame will not be marked as saveable many times.

Additionally, use list.h lists instead of open-coded lists to
implement the memory bitmaps.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Pavel Machek <pavel@suse.cz>
Cc: Dave Hansen <dave@linux.vnet.ibm.com>
Cc: Andy Whitcroft <apw@shadowen.org>
Cc: Nigel Cunningham <ncunningham@crca.org.au>
---
 kernel/power/snapshot.c |  327 ++++++++++++++++++++++++------------------------
 1 file changed, 167 insertions(+), 160 deletions(-)

Index: linux-2.6/kernel/power/snapshot.c
===================================================================
--- linux-2.6.orig/kernel/power/snapshot.c
+++ linux-2.6/kernel/power/snapshot.c
@@ -25,6 +25,7 @@
 #include <linux/syscalls.h>
 #include <linux/console.h>
 #include <linux/highmem.h>
+#include <linux/list.h>
 
 #include <asm/uaccess.h>
 #include <asm/mmu_context.h>
@@ -192,12 +193,6 @@ static void *chain_alloc(struct chain_al
 	return ret;
 }
 
-static void chain_free(struct chain_allocator *ca, int clear_page_nosave)
-{
-	free_list_of_pages(ca->chain, clear_page_nosave);
-	memset(ca, 0, sizeof(struct chain_allocator));
-}
-
 /**
  *	Data types related to memory bitmaps.
  *
@@ -233,7 +228,7 @@ static void chain_free(struct chain_allo
 #define BM_BITS_PER_BLOCK	(PAGE_SIZE << 3)
 
 struct bm_block {
-	struct bm_block *next;		/* next element of the list */
+	struct list_head hook;	/* hook into a list of bitmap blocks */
 	unsigned long start_pfn;	/* pfn represented by the first bit */
 	unsigned long end_pfn;	/* pfn represented by the last bit ...
From: Len Brown
Date: Wednesday, November 26, 2008 - 4:04 pm

done.

previous version has been replaced with this version.
also, suspend branch is now rebased to latest linus top of tree.

thanks,
-Len


--

From: Rafael J. Wysocki
Date: Wednesday, November 26, 2008 - 4:11 pm

Thanks a lot Len!

Rafael
--

Previous thread: [PATCH] Fix __pfn_to_page(pfn) for CONFIG_DISCONTIGMEM=y by Rafael J. Wysocki on Saturday, November 8, 2008 - 5:53 am. (6 messages)

Next thread: [PATCH -next] Hibernate: Do not oops on resume if image data are incorrect by Rafael J. Wysocki on Saturday, November 8, 2008 - 5:57 am. (2 messages)