All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -mm 0/2] swsusp: Use GFP_KERNEL for creating basic data structures
@ 2007-03-17 22:22 Rafael J. Wysocki
  2007-03-17 22:24 ` [PATCH -mm 1/2] swsusp: Fix error paths in snapshot_open Rafael J. Wysocki
  2007-03-17 22:27 ` [PATCH -mm 2/2] swsusp: Use GFP_KERNEL for creating basic data structures Rafael J. Wysocki
  0 siblings, 2 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2007-03-17 22:22 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Pavel Machek, LKML

Hi,

The first of the following two patches fixes a bug in the swsusp's userland
interface and the second one makes swsusp use GFP_KERNEL allocations for
creating its basic memory bitmaps.

Greetings,
Rafael


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH -mm 1/2] swsusp: Fix error paths in snapshot_open
  2007-03-17 22:22 [PATCH -mm 0/2] swsusp: Use GFP_KERNEL for creating basic data structures Rafael J. Wysocki
@ 2007-03-17 22:24 ` Rafael J. Wysocki
  2007-03-18 12:13   ` Pavel Machek
  2007-03-17 22:27 ` [PATCH -mm 2/2] swsusp: Use GFP_KERNEL for creating basic data structures Rafael J. Wysocki
  1 sibling, 1 reply; 4+ messages in thread
From: Rafael J. Wysocki @ 2007-03-17 22:24 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Pavel Machek, LKML

From: Rafael J. Wysocki <rjw@sisk.pl>

We forget to increase device_available if there's an error in snapshot_open(),
so the snapshot device cannot be open at all after snapshot_open() has returned
an error.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 kernel/power/user.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Index: linux-2.6.21-rc4/kernel/power/user.c
===================================================================
--- linux-2.6.21-rc4.orig/kernel/power/user.c
+++ linux-2.6.21-rc4/kernel/power/user.c
@@ -49,12 +49,14 @@ static int snapshot_open(struct inode *i
 	if (!atomic_add_unless(&device_available, -1, 0))
 		return -EBUSY;
 
-	if ((filp->f_flags & O_ACCMODE) == O_RDWR)
+	if ((filp->f_flags & O_ACCMODE) == O_RDWR) {
+		atomic_inc(&device_available);
 		return -ENOSYS;
-
-	if(create_basic_memory_bitmaps())
+	}
+	if(create_basic_memory_bitmaps()) {
+		atomic_inc(&device_available);
 		return -ENOMEM;
-
+	}
 	nonseekable_open(inode, filp);
 	data = &snapshot_state;
 	filp->private_data = data;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH -mm 2/2] swsusp: Use GFP_KERNEL for creating basic data structures
  2007-03-17 22:22 [PATCH -mm 0/2] swsusp: Use GFP_KERNEL for creating basic data structures Rafael J. Wysocki
  2007-03-17 22:24 ` [PATCH -mm 1/2] swsusp: Fix error paths in snapshot_open Rafael J. Wysocki
@ 2007-03-17 22:27 ` Rafael J. Wysocki
  1 sibling, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2007-03-17 22:27 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Pavel Machek, LKML

From: Rafael J. Wysocki <rjw@sisk.pl>

Make swsusp call create_basic_memory_bitmaps() before processes are frozen, so
that GFP_KERNEL allocations can be made in it.  Additionally, ensure that the
swsusp's userland interface won't be used while either pm_suspend_disk()
or software_resume() is being executed.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 kernel/power/disk.c     |   37 ++++++++++++++++++++++++++-----------
 kernel/power/power.h    |    3 +++
 kernel/power/snapshot.c |    8 ++++----
 kernel/power/user.c     |   10 +++++-----
 4 files changed, 38 insertions(+), 20 deletions(-)

Index: linux-2.6.21-rc4/kernel/power/disk.c
===================================================================
--- linux-2.6.21-rc4.orig/kernel/power/disk.c
+++ linux-2.6.21-rc4/kernel/power/disk.c
@@ -119,28 +119,33 @@ int pm_suspend_disk(void)
 {
 	int error;
 
+	/* The snapshot device should not be opened while we're running */
+	if (!atomic_add_unless(&snapshot_device_available, -1, 0))
+		return -EBUSY;
+
+	/* Allocate memory management structures */
+	error = create_basic_memory_bitmaps();
+	if (error)
+		goto Exit;
+
 	error = prepare_processes();
 	if (error)
-		return error;
+		goto Finish;
 
 	if (pm_disk_mode == PM_DISK_TESTPROC) {
 		printk("swsusp debug: Waiting for 5 seconds.\n");
 		mdelay(5000);
 		goto Thaw;
 	}
-	/* Allocate memory management structures */
-	error = create_basic_memory_bitmaps();
-	if (error)
-		goto Thaw;
 
 	/* Free memory before shutting down devices. */
 	error = swsusp_shrink_memory();
 	if (error)
-		goto Finish;
+		goto Thaw;
 
 	error = platform_prepare();
 	if (error)
-		goto Finish;
+		goto Thaw;
 
 	suspend_console();
 	error = device_suspend(PMSG_FREEZE);
@@ -175,7 +180,7 @@ int pm_suspend_disk(void)
 			power_down(pm_disk_mode);
 		else {
 			swsusp_free();
-			goto Finish;
+			goto Thaw;
 		}
 	} else {
 		pr_debug("PM: Image restored successfully.\n");
@@ -188,10 +193,12 @@ int pm_suspend_disk(void)
 	platform_finish();
 	device_resume();
 	resume_console();
- Finish:
-	free_basic_memory_bitmaps();
  Thaw:
 	unprepare_processes();
+ Finish:
+	free_basic_memory_bitmaps();
+ Exit:
+	atomic_inc(&snapshot_device_available);
 	return error;
 }
 
@@ -239,9 +246,15 @@ static int software_resume(void)
 	if (error)
 		goto Unlock;
 
+	/* The snapshot device should not be opened while we're running */
+	if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
+		error = -EBUSY;
+		goto Unlock;
+	}
+
 	error = create_basic_memory_bitmaps();
 	if (error)
-		goto Unlock;
+		goto Finish;
 
 	pr_debug("PM: Preparing processes for restore.\n");
 	error = prepare_processes();
@@ -287,6 +300,8 @@ static int software_resume(void)
 	unprepare_processes();
  Done:
 	free_basic_memory_bitmaps();
+ Finish:
+	atomic_inc(&snapshot_device_available);
 	/* For success case, the suspend path will release the lock */
  Unlock:
 	mutex_unlock(&pm_mutex);
Index: linux-2.6.21-rc4/kernel/power/power.h
===================================================================
--- linux-2.6.21-rc4.orig/kernel/power/power.h
+++ linux-2.6.21-rc4/kernel/power/power.h
@@ -141,6 +141,9 @@ struct resume_swap_area {
 #define PMOPS_ENTER	2
 #define PMOPS_FINISH	3
 
+/* If unset, the snapshot device cannot be open. */
+extern atomic_t snapshot_device_available;
+
 /**
  *	The bitmap is used for tracing allocated swap pages
  *
Index: linux-2.6.21-rc4/kernel/power/snapshot.c
===================================================================
--- linux-2.6.21-rc4.orig/kernel/power/snapshot.c
+++ linux-2.6.21-rc4/kernel/power/snapshot.c
@@ -733,19 +733,19 @@ int create_basic_memory_bitmaps(void)
 
 	BUG_ON(forbidden_pages_map || free_pages_map);
 
-	bm1 = kzalloc(sizeof(struct memory_bitmap), GFP_ATOMIC);
+	bm1 = kzalloc(sizeof(struct memory_bitmap), GFP_KERNEL);
 	if (!bm1)
 		return -ENOMEM;
 
-	error = memory_bm_create(bm1, GFP_ATOMIC | __GFP_COLD, PG_ANY);
+	error = memory_bm_create(bm1, GFP_KERNEL, PG_ANY);
 	if (error)
 		goto Free_first_object;
 
-	bm2 = kzalloc(sizeof(struct memory_bitmap), GFP_ATOMIC);
+	bm2 = kzalloc(sizeof(struct memory_bitmap), GFP_KERNEL);
 	if (!bm2)
 		goto Free_first_bitmap;
 
-	error = memory_bm_create(bm2, GFP_ATOMIC | __GFP_COLD, PG_ANY);
+	error = memory_bm_create(bm2, GFP_KERNEL, PG_ANY);
 	if (error)
 		goto Free_second_object;
 
Index: linux-2.6.21-rc4/kernel/power/user.c
===================================================================
--- linux-2.6.21-rc4.orig/kernel/power/user.c
+++ linux-2.6.21-rc4/kernel/power/user.c
@@ -40,21 +40,21 @@ static struct snapshot_data {
 	char platform_suspend;
 } snapshot_state;
 
-static atomic_t device_available = ATOMIC_INIT(1);
+atomic_t snapshot_device_available = ATOMIC_INIT(1);
 
 static int snapshot_open(struct inode *inode, struct file *filp)
 {
 	struct snapshot_data *data;
 
-	if (!atomic_add_unless(&device_available, -1, 0))
+	if (!atomic_add_unless(&snapshot_device_available, -1, 0))
 		return -EBUSY;
 
 	if ((filp->f_flags & O_ACCMODE) == O_RDWR) {
-		atomic_inc(&device_available);
+		atomic_inc(&snapshot_device_available);
 		return -ENOSYS;
 	}
 	if(create_basic_memory_bitmaps()) {
-		atomic_inc(&device_available);
+		atomic_inc(&snapshot_device_available);
 		return -ENOMEM;
 	}
 	nonseekable_open(inode, filp);
@@ -92,7 +92,7 @@ static int snapshot_release(struct inode
 		enable_nonboot_cpus();
 		mutex_unlock(&pm_mutex);
 	}
-	atomic_inc(&device_available);
+	atomic_inc(&snapshot_device_available);
 	return 0;
 }
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -mm 1/2] swsusp: Fix error paths in snapshot_open
  2007-03-17 22:24 ` [PATCH -mm 1/2] swsusp: Fix error paths in snapshot_open Rafael J. Wysocki
@ 2007-03-18 12:13   ` Pavel Machek
  0 siblings, 0 replies; 4+ messages in thread
From: Pavel Machek @ 2007-03-18 12:13 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Andrew Morton, LKML

Hi!

> We forget to increase device_available if there's an error in snapshot_open(),
> so the snapshot device cannot be open at all after snapshot_open() has returned
> an error.
> 
> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>

ACK.

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-03-18 12:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-17 22:22 [PATCH -mm 0/2] swsusp: Use GFP_KERNEL for creating basic data structures Rafael J. Wysocki
2007-03-17 22:24 ` [PATCH -mm 1/2] swsusp: Fix error paths in snapshot_open Rafael J. Wysocki
2007-03-18 12:13   ` Pavel Machek
2007-03-17 22:27 ` [PATCH -mm 2/2] swsusp: Use GFP_KERNEL for creating basic data structures Rafael J. Wysocki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.