Skip to contentSkip to conversation

PM: Fixes related to suspend and hibernation for 2.6.29

PATCH In review Rafael J. Wysocki 6 participants 35 messages Feb 14, 2009 – Feb 22, 2009

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

cover PM: Fixes related to suspend and hibernation for 2.6.29

Hi Len,

The following are fixes related to suspend and hibernation I have collected over the last couple of weeks. Some of them are in -mm. I think they all are 2.6.29 material.

1/9 and 2/9 fix hibernation regression caused by the async boot changes, I hope Greg will not object if they go through your tree.

3/9 fixes a long-standing hibernation issue that cause the resume partition to become unuseable after two consecutive failing attempts to hibernate.

4/9 fixes build of kprobes.c with CONFIG_PM unset.

5/9 and 6/9 clean up memory freeing code used during hibernation.

7/9 fixes a bug related to the use of PM notifiers during hibernation with the help of the user land interface.

8/9 and 9/9 fix the handling of consoles during suspend/hibernation.

Please add these patches to the suspend branch and push to Linus for 2.6.29.

Thanks,
Rafael

Signature · 3 lines
Everyone knows that debugging is twice as hard as writing a program
in the first place.  So if you're as clever as you can be when you write it,
how will you ever debug it? --- Brian Kernighan
#1 lore raw

PATCH 1/9 Consolidate driver_probe_done() loops into one place

From: Arjan van de Ven <[email protected]>

there's a few places that currently loop over driver_probe_done(), and I'm about to add another one. This patch abstracts it into a helper to reduce duplication.

---
 drivers/base/dd.c      |   17 +++++++++++++++++
 include/linux/device.h |    2 ++
 init/do_mounts.c       |   13 +++++++++----
 init/do_mounts_md.c    |    5 +++--
 4 files changed, 31 insertions(+), 6 deletions(-)
drivers/base/dd.c +17 -0
Index: linux-2.6/drivers/base/dd.c
===================================================================
@@ -18,9 +18,11 @@
  */
 
 #include <linux/device.h>
+#include <linux/delay.h>
 #include <linux/module.h>
 #include <linux/kthread.h>
 #include <linux/wait.h>
+#include <linux/async.h>
 
 #include "base.h"
 #include "power/power.h"
@@ -168,6 +170,21 @@ int driver_probe_done(void)
 }
 
 /**
+ * wait_for_device_probe
+ * Wait for device probing to be completed.
+ *
+ * Note: this function polls at 100 msec intervals.
+ */
+int wait_for_device_probe(void)
+{
+	/* wait for the known devices to complete their probing */
+	while (driver_probe_done() != 0)
+		msleep(100);
+	async_synchronize_full();
+	return 0;
+}
+
+/**
  * driver_probe_device - attempt to bind device & driver together
  * @drv: driver to bind a device to
  * @dev: device to try to bind to the driver
include/linux/device.h +2 -0
Index: linux-2.6/include/linux/device.h
===================================================================
@@ -147,6 +147,8 @@ extern void put_driver(struct device_dri
 extern struct device_driver *driver_find(const char *name,
 					 struct bus_type *bus);
 extern int driver_probe_done(void);
+extern int wait_for_device_probe(void);
+
 
 /* sysfs interface for exporting driver attributes */
 
init/do_mounts.c +9 -4
Index: linux-2.6/init/do_mounts.c
===================================================================
@@ -370,10 +370,14 @@ void __init prepare_namespace(void)
 		ssleep(root_delay);
 	}
 
-	/* wait for the known devices to complete their probing */
-	while (driver_probe_done() != 0)
-		msleep(100);
-	async_synchronize_full();
+	/*
+	 * wait for the known devices to complete their probing
+	 *
+	 * Note: this is a potential source of long boot delays.
+	 * For example, it is not atypical to wait 5 seconds here
+	 * for the touchpad of a laptop to initialize.
+	 */
+	wait_for_device_probe();
 
 	md_run_setup();
 
@@ -399,6 +403,7 @@ void __init prepare_namespace(void)
 		while (driver_probe_done() != 0 ||
 			(ROOT_DEV = name_to_dev_t(saved_root_name)) == 0)
 			msleep(100);
+		async_synchronize_full();
 	}
 
 	is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
init/do_mounts_md.c +3 -2
Index: linux-2.6/init/do_mounts_md.c
===================================================================
@@ -281,8 +281,9 @@ static void __init autodetect_raid(void)
 	 */
 	printk(KERN_INFO "md: Waiting for all devices to be available before autodetect\n");
 	printk(KERN_INFO "md: If you don't use raid, use raid=noautodetect\n");
-	while (driver_probe_done() < 0)
-		msleep(100);
+
+	wait_for_device_probe();
+
 	fd = sys_open("/dev/md0", 0, 0);
 	if (fd >= 0) {
 		sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
#2 lore raw

Re: [PATCH 1/9] Consolidate driver_probe_done() loops into one place

Quoted 8 lines · Rafael J. Wysocki

From: Arjan van de Ven <[email protected]>

there's a few places that currently loop over driver_probe_done(), and I'm about to add another one. This patch abstracts it into a helper to reduce duplication.

Fine with me if this goes through Len's tree.

thanks,

greg k-h

#3 lore raw

Re: [PATCH 1/9] Consolidate driver_probe_done() loops into one place

In reply to Rafael J. Wysocki

Hi,

Quoted 5 lines · Rafael J. Wysocki <rjw <at> sisk.pl> writes:

From: Arjan van de Ven <arjan <at> linux.intel.com>

there's a few places that currently loop over driver_probe_done(), and I'm about to add another one. This patch abstracts it into a helper to reduce duplication.

[snip]

Quoted 8 lines
drivers/base/dd.c +8 -0
+int wait_for_device_probe(void)
+{
+	/* wait for the known devices to complete their probing */
+	while (driver_probe_done() != 0)
+		msleep(100);
+	async_synchronize_full();
+	return 0;
+}

[snip]

Quoted 4 lines

Index: linux-2.6/init/do_mounts.c
===================================================================

init/do_mounts.c +0 -0

[snip]

init/do_mounts.c void __init prepare_namespace(void) · line 407

Quoted 6 lines
init/do_mounts.c +1 -0
@@ -399,6 +403,7 @@ void __init prepare_namespace(void)
 		while (driver_probe_done() != 0 ||
 			(ROOT_DEV = name_to_dev_t(saved_root_name)) == 0)
 			msleep(100);
+		async_synchronize_full();
 	}

Note that even this loop can be consolidated. The while loop above can be equivalently rewritten as

  while ((ROOT_DEV = name_to_dev_t(saved_root_name)) == 0)
    msleep(100);
  while (driver_probe_done() != 0)
    msleep(100);

which, with your patch applied is equivalent to

  while ((ROOT_DEV = name_to_dev_t(saved_root_name)) == 0)
    msleep(100);
  wait_for_device_probe();

- Hari

#4 lore raw

PATCH 2/9 PM/resume: wait for device probing to finish

In reply to Rafael J. Wysocki

From: Arjan van de Ven <[email protected]>

the resume code does not currently wait for device probing to finish. Even without async function calls this is dicey and not correct, but with async function calls during the boot sequence this is going to get hit more...

This patch adds the synchronization using the newly introduced helper.

---
 kernel/power/disk.c |   11 +++++++++++
 1 file changed, 11 insertions(+)
kernel/power/disk.c +11 -0
Index: linux-2.6/kernel/power/disk.c
===================================================================
@@ -595,6 +595,12 @@ static int software_resume(void)
 	unsigned int flags;
 
 	/*
+	 * If the user said "noresume".. bail out early.
+	 */
+	if (noresume)
+		return 0;
+
+	/*
 	 * name_to_dev_t() below takes a sysfs buffer mutex when sysfs
 	 * is configured into the kernel. Since the regular hibernate
 	 * trigger path is via sysfs which takes a buffer mutex before
@@ -610,6 +616,11 @@ static int software_resume(void)
 			mutex_unlock(&pm_mutex);
 			return -ENOENT;
 		}
+		/*
+		 * Some device discovery might still be in progress; we need
+		 * to wait for this to finish.
+		 */
+		wait_for_device_probe();
 		swsusp_resume_device = name_to_dev_t(resume_file);
 		pr_debug("PM: Resume from partition %s\n", resume_file);
 	} else {
#5 lore raw

PATCH 2/9 PM/resume: wait for device probing to finish

In reply to Rafael J. Wysocki

From: Arjan van de Ven <[email protected]>

the resume code does not currently wait for device probing to finish. Even without async function calls this is dicey and not correct, but with async function calls during the boot sequence this is going to get hit more...

This patch adds the synchronization using the newly introduced helper.

---
 kernel/power/disk.c |   11 +++++++++++
 1 file changed, 11 insertions(+)
kernel/power/disk.c +11 -0
Index: linux-2.6/kernel/power/disk.c
===================================================================
@@ -595,6 +595,12 @@ static int software_resume(void)
 	unsigned int flags;
 
 	/*
+	 * If the user said "noresume".. bail out early.
+	 */
+	if (noresume)
+		return 0;
+
+	/*
 	 * name_to_dev_t() below takes a sysfs buffer mutex when sysfs
 	 * is configured into the kernel. Since the regular hibernate
 	 * trigger path is via sysfs which takes a buffer mutex before
@@ -610,6 +616,11 @@ static int software_resume(void)
 			mutex_unlock(&pm_mutex);
 			return -ENOENT;
 		}
+		/*
+		 * Some device discovery might still be in progress; we need
+		 * to wait for this to finish.
+		 */
+		wait_for_device_probe();
 		swsusp_resume_device = name_to_dev_t(resume_file);
 		pr_debug("PM: Resume from partition %s\n", resume_file);
 	} else {
#6 lore raw

Re: [PATCH 2/9] PM/resume: wait for device probing to finish

Quoted 11 lines · Rafael J. Wysocki

From: Arjan van de Ven <[email protected]>

the resume code does not currently wait for device probing to finish. Even without async function calls this is dicey and not correct, but with async function calls during the boot sequence this is going to get hit more...

This patch adds the synchronization using the newly introduced helper.

Fine with me if this goes through Len's tree.

thanks,

greg k-h

#7 lore raw

Re: [PATCH 2/9] PM/resume: wait for device probing to finish

In reply to Rafael J. Wysocki
Quoted 11 lines · Rafael J. Wysocki

From: Arjan van de Ven <[email protected]>

the resume code does not currently wait for device probing to finish. Even without async function calls this is dicey and not correct, but with async function calls during the boot sequence this is going to get hit more...

This patch adds the synchronization using the newly introduced helper.

Fine with me if this goes through Len's tree.

thanks,

greg k-h

#8 lore raw

PATCH 3/9 PM/hibernate: fix "swap breaks after hibernation failures"

In reply to Rafael J. Wysocki

From: Alan Jenkins <[email protected]>

http://bugzilla.kernel.org/show_bug.cgi?id=12239

The image writing code dropped a reference to the current swap device. This doesn't show up if the hibernation succeeds - because it doesn't affect the image which gets resumed. But it means multiple _failed_ hibernations end up freeing the swap device while it is still use!

swsusp_write() finds the block device for the swap file using swap_type_of(). It then uses blkdev_get() / blkdev_put() to open and close the block device.

Unfortunately, blkdev_get() assumes ownership of the inode of the block_device passed to it. So blkdev_put() calls iput() on the inode. This is by design and other callers expect this behaviour. The fix is for swap_type_of() to take a reference on the inode using bdget().

---
 mm/swapfile.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/swapfile.c +2 -2
Index: linux-2.6/mm/swapfile.c
===================================================================
@@ -635,7 +635,7 @@ int swap_type_of(dev_t device, sector_t 
 
 		if (!bdev) {
 			if (bdev_p)
-				*bdev_p = sis->bdev;
+				*bdev_p = bdget(sis->bdev->bd_dev);
 
 			spin_unlock(&swap_lock);
 			return i;
@@ -647,7 +647,7 @@ int swap_type_of(dev_t device, sector_t 
 					struct swap_extent, list);
 			if (se->start_block == offset) {
 				if (bdev_p)
-					*bdev_p = sis->bdev;
+					*bdev_p = bdget(sis->bdev->bd_dev);
 
 				spin_unlock(&swap_lock);
 				bdput(bdev);
#9 lore raw

PATCH 4/9 PM: fix build for CONFIG_PM unset

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Compilation of kprobes.c with CONFIG_PM unset is broken due to some broken config dependncies. Fix that.

---

 kernel/Makefile       |    1 +
 kernel/power/Makefile |    2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
kernel/Makefile +1 -0
Index: linux-2.6/kernel/Makefile
===================================================================
@@ -51,6 +51,7 @@ obj-$(CONFIG_UID16) += uid16.o
 obj-$(CONFIG_MODULES) += module.o
 obj-$(CONFIG_KALLSYMS) += kallsyms.o
 obj-$(CONFIG_PM) += power/
+obj-$(CONFIG_FREEZER) += power/
 obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o
 obj-$(CONFIG_KEXEC) += kexec.o
 obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o
kernel/power/Makefile +1 -1
Index: linux-2.6/kernel/power/Makefile
===================================================================
@@ -3,7 +3,7 @@ ifeq ($(CONFIG_PM_DEBUG),y)
 EXTRA_CFLAGS	+=	-DDEBUG
 endif
 
-obj-y				:= main.o
+obj-$(CONFIG_PM)		+= main.o
 obj-$(CONFIG_PM_SLEEP)		+= console.o
 obj-$(CONFIG_FREEZER)		+= process.o
 obj-$(CONFIG_HIBERNATION)	+= swsusp.o disk.o snapshot.o swap.o user.o
#10 lore raw

PATCH 5/9 swsusp: dont fiddle with swappiness

In reply to Rafael J. Wysocki

From: Johannes Weiner <[email protected]>

sc.swappiness is not used in the swsusp memory shrinking path, do not set it.

---

 mm/vmscan.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
mm/vmscan.c +1 -4
Index: linux-2.6/mm/vmscan.c
===================================================================
@@ -2112,7 +2112,6 @@ unsigned long shrink_all_memory(unsigned
 		.may_swap = 0,
 		.swap_cluster_max = nr_pages,
 		.may_writepage = 1,
-		.swappiness = vm_swappiness,
 		.isolate_pages = isolate_pages_global,
 	};
 
@@ -2146,10 +2145,8 @@ unsigned long shrink_all_memory(unsigned
 		int prio;
 
 		/* Force reclaiming mapped pages in the passes #3 and #4 */
-		if (pass > 2) {
+		if (pass > 2)
 			sc.may_swap = 1;
-			sc.swappiness = 100;
-		}
 
 		for (prio = DEF_PRIORITY; prio >= 0; prio--) {
 			unsigned long nr_to_scan = nr_pages - ret;
#11 lore raw

PATCH 5/9 swsusp: dont fiddle with swappiness

In reply to Rafael J. Wysocki

From: Johannes Weiner <[email protected]>

sc.swappiness is not used in the swsusp memory shrinking path, do not set it.

---

 mm/vmscan.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
mm/vmscan.c +1 -4
Index: linux-2.6/mm/vmscan.c
===================================================================
@@ -2112,7 +2112,6 @@ unsigned long shrink_all_memory(unsigned
 		.may_swap = 0,
 		.swap_cluster_max = nr_pages,
 		.may_writepage = 1,
-		.swappiness = vm_swappiness,
 		.isolate_pages = isolate_pages_global,
 	};
 
@@ -2146,10 +2145,8 @@ unsigned long shrink_all_memory(unsigned
 		int prio;
 
 		/* Force reclaiming mapped pages in the passes #3 and #4 */
-		if (pass > 2) {
+		if (pass > 2)
 			sc.may_swap = 1;
-			sc.swappiness = 100;
-		}
 
 		for (prio = DEF_PRIORITY; prio >= 0; prio--) {
 			unsigned long nr_to_scan = nr_pages - ret;
#12 lore raw

PATCH 6/9 swsusp: clean up shrink_all_zones()

In reply to Rafael J. Wysocki

From: Johannes Weiner <[email protected]>

Move local variables to innermost possible scopes and use local variables to cache calculations/reads done more than once.

No change in functionality (intended).

---

 mm/vmscan.c |   23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
mm/vmscan.c +11 -12
Index: linux-2.6/mm/vmscan.c
===================================================================
@@ -2057,31 +2057,31 @@ static unsigned long shrink_all_zones(un
 				      int pass, struct scan_control *sc)
 {
 	struct zone *zone;
-	unsigned long nr_to_scan, ret = 0;
-	enum lru_list l;
+	unsigned long ret = 0;
 
 	for_each_zone(zone) {
+		enum lru_list l;
 
 		if (!populated_zone(zone))
 			continue;
-
 		if (zone_is_all_unreclaimable(zone) && prio != DEF_PRIORITY)
 			continue;
 
 		for_each_evictable_lru(l) {
+			enum zone_stat_item ls = NR_LRU_BASE + l;
+			unsigned long lru_pages = zone_page_state(zone, ls);
+
 			/* For pass = 0, we don't shrink the active list */
-			if (pass == 0 &&
-				(l == LRU_ACTIVE || l == LRU_ACTIVE_FILE))
+			if (pass == 0 && (l == LRU_ACTIVE_ANON ||
+						l == LRU_ACTIVE_FILE))
 				continue;
 
-			zone->lru[l].nr_scan +=
-				(zone_page_state(zone, NR_LRU_BASE + l)
-								>> prio) + 1;
+			zone->lru[l].nr_scan += (lru_pages >> prio) + 1;
 			if (zone->lru[l].nr_scan >= nr_pages || pass > 3) {
+				unsigned long nr_to_scan;
+
 				zone->lru[l].nr_scan = 0;
-				nr_to_scan = min(nr_pages,
-					zone_page_state(zone,
-							NR_LRU_BASE + l));
+				nr_to_scan = min(nr_pages, lru_pages);
 				ret += shrink_list(l, nr_to_scan, zone,
 								sc, prio);
 				if (ret >= nr_pages)
@@ -2089,7 +2089,6 @@ static unsigned long shrink_all_zones(un
 			}
 		}
 	}
-
 	return ret;
 }
 
#13 lore raw

PATCH 6/9 swsusp: clean up shrink_all_zones()

In reply to Rafael J. Wysocki

From: Johannes Weiner <[email protected]>

Move local variables to innermost possible scopes and use local variables to cache calculations/reads done more than once.

No change in functionality (intended).

---

 mm/vmscan.c |   23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
mm/vmscan.c +11 -12
Index: linux-2.6/mm/vmscan.c
===================================================================
@@ -2057,31 +2057,31 @@ static unsigned long shrink_all_zones(un
 				      int pass, struct scan_control *sc)
 {
 	struct zone *zone;
-	unsigned long nr_to_scan, ret = 0;
-	enum lru_list l;
+	unsigned long ret = 0;
 
 	for_each_zone(zone) {
+		enum lru_list l;
 
 		if (!populated_zone(zone))
 			continue;
-
 		if (zone_is_all_unreclaimable(zone) && prio != DEF_PRIORITY)
 			continue;
 
 		for_each_evictable_lru(l) {
+			enum zone_stat_item ls = NR_LRU_BASE + l;
+			unsigned long lru_pages = zone_page_state(zone, ls);
+
 			/* For pass = 0, we don't shrink the active list */
-			if (pass == 0 &&
-				(l == LRU_ACTIVE || l == LRU_ACTIVE_FILE))
+			if (pass == 0 && (l == LRU_ACTIVE_ANON ||
+						l == LRU_ACTIVE_FILE))
 				continue;
 
-			zone->lru[l].nr_scan +=
-				(zone_page_state(zone, NR_LRU_BASE + l)
-								>> prio) + 1;
+			zone->lru[l].nr_scan += (lru_pages >> prio) + 1;
 			if (zone->lru[l].nr_scan >= nr_pages || pass > 3) {
+				unsigned long nr_to_scan;
+
 				zone->lru[l].nr_scan = 0;
-				nr_to_scan = min(nr_pages,
-					zone_page_state(zone,
-							NR_LRU_BASE + l));
+				nr_to_scan = min(nr_pages, lru_pages);
 				ret += shrink_list(l, nr_to_scan, zone,
 								sc, prio);
 				if (ret >= nr_pages)
@@ -2089,7 +2089,6 @@ static unsigned long shrink_all_zones(un
 			}
 		}
 	}
-
 	return ret;
 }
 
#14 lore raw

PATCH 7/9 PM: Fix pm_notifiers during user mode hibernation

In reply to Rafael J. Wysocki

From: Andrey Borzenkov <[email protected]>

Snapshot device is opened with O_RDONLY during suspend and O_WRONLY durig resume. Make sure we also call notifiers with correct parameter telling them what we are really doing.

---

 kernel/power/user.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/power/user.c +4 -4
Index: linux-2.6/kernel/power/user.c
===================================================================
@@ -95,15 +95,15 @@ static int snapshot_open(struct inode *i
 		data->swap = swsusp_resume_device ?
 			swap_type_of(swsusp_resume_device, 0, NULL) : -1;
 		data->mode = O_RDONLY;
-		error = pm_notifier_call_chain(PM_RESTORE_PREPARE);
+		error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE);
 		if (error)
-			pm_notifier_call_chain(PM_POST_RESTORE);
+			pm_notifier_call_chain(PM_POST_HIBERNATION);
 	} else {
 		data->swap = -1;
 		data->mode = O_WRONLY;
-		error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE);
+		error = pm_notifier_call_chain(PM_RESTORE_PREPARE);
 		if (error)
-			pm_notifier_call_chain(PM_POST_HIBERNATION);
+			pm_notifier_call_chain(PM_POST_RESTORE);
 	}
 	if (error)
 		atomic_inc(&snapshot_device_available);
#15 lore raw

PATCH 7/9 PM: Fix pm_notifiers during user mode hibernation

In reply to Rafael J. Wysocki

From: Andrey Borzenkov <[email protected]>

Snapshot device is opened with O_RDONLY during suspend and O_WRONLY durig resume. Make sure we also call notifiers with correct parameter telling them what we are really doing.

---

 kernel/power/user.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/power/user.c +4 -4
Index: linux-2.6/kernel/power/user.c
===================================================================
@@ -95,15 +95,15 @@ static int snapshot_open(struct inode *i
 		data->swap = swsusp_resume_device ?
 			swap_type_of(swsusp_resume_device, 0, NULL) : -1;
 		data->mode = O_RDONLY;
-		error = pm_notifier_call_chain(PM_RESTORE_PREPARE);
+		error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE);
 		if (error)
-			pm_notifier_call_chain(PM_POST_RESTORE);
+			pm_notifier_call_chain(PM_POST_HIBERNATION);
 	} else {
 		data->swap = -1;
 		data->mode = O_WRONLY;
-		error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE);
+		error = pm_notifier_call_chain(PM_RESTORE_PREPARE);
 		if (error)
-			pm_notifier_call_chain(PM_POST_HIBERNATION);
+			pm_notifier_call_chain(PM_POST_RESTORE);
 	}
 	if (error)
 		atomic_inc(&snapshot_device_available);
#16 lore raw

PATCH 8/9 PM: Wait for console in resume

In reply to Rafael J. Wysocki

From: Arve Hjønnevåg <[email protected]>

Avoids later waking up to a blinking cursor if the device woke up and returned to sleep before the console switch happened.

---

 kernel/power/console.c |    6 ++++++
 1 file changed, 6 insertions(+)
kernel/power/console.c +6 -0
Index: linux-2.6/kernel/power/console.c
===================================================================
@@ -78,6 +78,12 @@ void pm_restore_console(void)
 	}
 	set_console(orig_fgconsole);
 	release_console_sem();
+
+	if (vt_waitactive(orig_fgconsole)) {
+		pr_debug("Resume: Can't switch VCs.");
+		return;
+	}
+
 	kmsg_redirect = orig_kmsg;
 }
 #endif
#17 lore raw

PATCH 8/9 PM: Wait for console in resume

In reply to Rafael J. Wysocki

From: Arve Hjønnevåg <[email protected]>

Avoids later waking up to a blinking cursor if the device woke up and returned to sleep before the console switch happened.

---

 kernel/power/console.c |    6 ++++++
 1 file changed, 6 insertions(+)
kernel/power/console.c +6 -0
Index: linux-2.6/kernel/power/console.c
===================================================================
@@ -78,6 +78,12 @@ void pm_restore_console(void)
 	}
 	set_console(orig_fgconsole);
 	release_console_sem();
+
+	if (vt_waitactive(orig_fgconsole)) {
+		pr_debug("Resume: Can't switch VCs.");
+		return;
+	}
+
 	kmsg_redirect = orig_kmsg;
 }
 #endif
#18 lore raw

PATCH 9/9 PM: Fix suspend_console and resume_console to use only one semaphore

In reply to Rafael J. Wysocki

From: Arve Hjønnevåg <[email protected]>

This fixes a race where a thread acquires the console while the console is suspended, and the console is resumed before this thread releases it. In this case, the secondary console semaphore would be left locked, and the primary semaphore would be released twice. This in turn would cause the console switch on suspend or resume to hang forever.

Note that suspend_console does not actually lock the console for clients that use acquire_console_sem, it only locks it for clients that use try_acquire_console_sem. If we change suspend_console to fully lock the console, then the kernel may deadlock on suspend. One client of try_acquire_console_sem is acquire_console_semaphore_for_printk, which uses it to prevent printk from using the console while it is suspended.

---

 kernel/printk.c |   15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
kernel/printk.c +9 -6
Index: linux-2.6/kernel/printk.c
===================================================================
@@ -73,7 +73,6 @@ EXPORT_SYMBOL(oops_in_progress);
  * driver system.
  */
 static DECLARE_MUTEX(console_sem);
-static DECLARE_MUTEX(secondary_console_sem);
 struct console *console_drivers;
 EXPORT_SYMBOL_GPL(console_drivers);
 
@@ -891,12 +890,14 @@ void suspend_console(void)
 	printk("Suspending console(s) (use no_console_suspend to debug)\n");
 	acquire_console_sem();
 	console_suspended = 1;
+	up(&console_sem);
 }
 
 void resume_console(void)
 {
 	if (!console_suspend_enabled)
 		return;
+	down(&console_sem);
 	console_suspended = 0;
 	release_console_sem();
 }
@@ -912,11 +913,9 @@ void resume_console(void)
 void acquire_console_sem(void)
 {
 	BUG_ON(in_interrupt());
-	if (console_suspended) {
-		down(&secondary_console_sem);
-		return;
-	}
 	down(&console_sem);
+	if (console_suspended)
+		return;
 	console_locked = 1;
 	console_may_schedule = 1;
 }
@@ -926,6 +925,10 @@ int try_acquire_console_sem(void)
 {
 	if (down_trylock(&console_sem))
 		return -1;
+	if (console_suspended) {
+		up(&console_sem);
+		return -1;
+	}
 	console_locked = 1;
 	console_may_schedule = 0;
 	return 0;
@@ -979,7 +982,7 @@ void release_console_sem(void)
 	unsigned wake_klogd = 0;
 
 	if (console_suspended) {
-		up(&secondary_console_sem);
+		up(&console_sem);
 		return;
 	}
 
#19 lore raw

PATCH 9/9 PM: Fix suspend_console and resume_console to use only one semaphore

In reply to Rafael J. Wysocki

From: Arve Hjønnevåg <[email protected]>

This fixes a race where a thread acquires the console while the console is suspended, and the console is resumed before this thread releases it. In this case, the secondary console semaphore would be left locked, and the primary semaphore would be released twice. This in turn would cause the console switch on suspend or resume to hang forever.

Note that suspend_console does not actually lock the console for clients that use acquire_console_sem, it only locks it for clients that use try_acquire_console_sem. If we change suspend_console to fully lock the console, then the kernel may deadlock on suspend. One client of try_acquire_console_sem is acquire_console_semaphore_for_printk, which uses it to prevent printk from using the console while it is suspended.

---

 kernel/printk.c |   15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
kernel/printk.c +9 -6
Index: linux-2.6/kernel/printk.c
===================================================================
@@ -73,7 +73,6 @@ EXPORT_SYMBOL(oops_in_progress);
  * driver system.
  */
 static DECLARE_MUTEX(console_sem);
-static DECLARE_MUTEX(secondary_console_sem);
 struct console *console_drivers;
 EXPORT_SYMBOL_GPL(console_drivers);
 
@@ -891,12 +890,14 @@ void suspend_console(void)
 	printk("Suspending console(s) (use no_console_suspend to debug)\n");
 	acquire_console_sem();
 	console_suspended = 1;
+	up(&console_sem);
 }
 
 void resume_console(void)
 {
 	if (!console_suspend_enabled)
 		return;
+	down(&console_sem);
 	console_suspended = 0;
 	release_console_sem();
 }
@@ -912,11 +913,9 @@ void resume_console(void)
 void acquire_console_sem(void)
 {
 	BUG_ON(in_interrupt());
-	if (console_suspended) {
-		down(&secondary_console_sem);
-		return;
-	}
 	down(&console_sem);
+	if (console_suspended)
+		return;
 	console_locked = 1;
 	console_may_schedule = 1;
 }
@@ -926,6 +925,10 @@ int try_acquire_console_sem(void)
 {
 	if (down_trylock(&console_sem))
 		return -1;
+	if (console_suspended) {
+		up(&console_sem);
+		return -1;
+	}
 	console_locked = 1;
 	console_may_schedule = 0;
 	return 0;
@@ -979,7 +982,7 @@ void release_console_sem(void)
 	unsigned wake_klogd = 0;
 
 	if (console_suspended) {
-		up(&secondary_console_sem);
+		up(&console_sem);
 		return;
 	}
 
reviewer
#20 lore raw
In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki

Hi Len,

The following are fixes related to suspend and hibernation I have collected over the last couple of weeks. Some of them are in -mm. I think they all are 2.6.29 material.

Quoted 7 lines

1/9 and 2/9 fix hibernation regression caused by the async boot changes, I hope Greg will not object if they go through your tree.

3/9 fixes a long-standing hibernation issue that cause the resume partition to become unuseable after two consecutive failing attempts to hibernate.

4/9 fixes build of kprobes.c with CONFIG_PM unset.

looks like this one added power/ twice --
and looks like akpm sent a fixed version of this to linus already?

Quoted 8 lines

5/9 and 6/9 clean up memory freeing code used during hibernation.

7/9 fixes a bug related to the use of PM notifiers during hibernation with the help of the user land interface.

8/9 and 9/9 fix the handling of consoles during suspend/hibernation.

Please add these patches to the suspend branch and push to Linus for 2.6.29.

All except #4 are now on the suspend branch.
thanks,
--
Len Brown, Intel Open Source Technology Center

reviewer
#21 lore raw
In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki

Hi Len,

The following are fixes related to suspend and hibernation I have collected over the last couple of weeks. Some of them are in -mm. I think they all are 2.6.29 material.

Quoted 7 lines

1/9 and 2/9 fix hibernation regression caused by the async boot changes, I hope Greg will not object if they go through your tree.

3/9 fixes a long-standing hibernation issue that cause the resume partition to become unuseable after two consecutive failing attempts to hibernate.

4/9 fixes build of kprobes.c with CONFIG_PM unset.

looks like this one added power/ twice --
and looks like akpm sent a fixed version of this to linus already?

Quoted 8 lines

5/9 and 6/9 clean up memory freeing code used during hibernation.

7/9 fixes a bug related to the use of PM notifiers during hibernation with the help of the user land interface.

8/9 and 9/9 fix the handling of consoles during suspend/hibernation.

Please add these patches to the suspend branch and push to Linus for 2.6.29.

All except #4 are now on the suspend branch.
thanks,
--
Len Brown, Intel Open Source Technology Center

#22 lore raw
Quoted 12 lines · Len Brown
Quoted 9 lines · Rafael J. Wysocki

Hi Len,

The following are fixes related to suspend and hibernation I have collected over the last couple of weeks. Some of them are in -mm. I think they all are 2.6.29 material.

1/9 and 2/9 fix hibernation regression caused by the async boot changes, I hope Greg will not object if they go through your tree.

Quoted 6 lines
Quoted 4 lines

3/9 fixes a long-standing hibernation issue that cause the resume partition to become unuseable after two consecutive failing attempts to hibernate.

4/9 fixes build of kprobes.c with CONFIG_PM unset.

looks like this one added power/ twice --

That was on purpose.

Quoted 1 line

and looks like akpm sent a fixed version of this to linus already?

Yes, he did.

Quoted 10 lines
Quoted 8 lines

5/9 and 6/9 clean up memory freeing code used during hibernation.

7/9 fixes a bug related to the use of PM notifiers during hibernation with the help of the user land interface.

8/9 and 9/9 fix the handling of consoles during suspend/hibernation.

Please add these patches to the suspend branch and push to Linus for 2.6.29.

All except #4 are now on the suspend branch.

1/9 and 2/9 are also in the Greg's tree, AFAICS.

Greg, do you intend to push them to Linus? In that case I think it's better if Len drops them.

Rafael

#23 lore raw
In reply to Len Brown
Quoted 12 lines · Len Brown
Quoted 9 lines · Rafael J. Wysocki

Hi Len,

The following are fixes related to suspend and hibernation I have collected over the last couple of weeks. Some of them are in -mm. I think they all are 2.6.29 material.

1/9 and 2/9 fix hibernation regression caused by the async boot changes, I hope Greg will not object if they go through your tree.

Quoted 6 lines
Quoted 4 lines

3/9 fixes a long-standing hibernation issue that cause the resume partition to become unuseable after two consecutive failing attempts to hibernate.

4/9 fixes build of kprobes.c with CONFIG_PM unset.

looks like this one added power/ twice --

That was on purpose.

Quoted 1 line

and looks like akpm sent a fixed version of this to linus already?

Yes, he did.

Quoted 10 lines
Quoted 8 lines

5/9 and 6/9 clean up memory freeing code used during hibernation.

7/9 fixes a bug related to the use of PM notifiers during hibernation with the help of the user land interface.

8/9 and 9/9 fix the handling of consoles during suspend/hibernation.

Please add these patches to the suspend branch and push to Linus for 2.6.29.

All except #4 are now on the suspend branch.

1/9 and 2/9 are also in the Greg's tree, AFAICS.

Greg, do you intend to push them to Linus? In that case I think it's better if Len drops them.

Rafael

#24 lore raw
Quoted 33 lines · Rafael J. Wysocki
Quoted 12 lines · Len Brown
Quoted 9 lines · Rafael J. Wysocki

Hi Len,

The following are fixes related to suspend and hibernation I have collected over the last couple of weeks. Some of them are in -mm. I think they all are 2.6.29 material.

1/9 and 2/9 fix hibernation regression caused by the async boot changes, I hope Greg will not object if they go through your tree.

Quoted 6 lines
Quoted 4 lines

3/9 fixes a long-standing hibernation issue that cause the resume partition to become unuseable after two consecutive failing attempts to hibernate.

4/9 fixes build of kprobes.c with CONFIG_PM unset.

looks like this one added power/ twice --

That was on purpose.

Quoted 1 line

and looks like akpm sent a fixed version of this to linus already?

Yes, he did.

Quoted 7 lines
Quoted 7 lines

5/9 and 6/9 clean up memory freeing code used during hibernation.

7/9 fixes a bug related to the use of PM notifiers during hibernation with the help of the user land interface.

8/9 and 9/9 fix the handling of consoles during suspend/hibernation.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Please add these patches to the suspend branch and push to Linus for 2.6.29.

All except #4 are now on the suspend branch.

1/9 and 2/9 are also in the Greg's tree, AFAICS.

Greg, do you intend to push them to Linus? In that case I think it's better if Len drops them.

I was not planning to send them for .29, sorry I got confused. I'll drop them from my tree and Len can send them all to Linus now.

Is that ok?

thanks,

greg k-h

#25 lore raw
In reply to Rafael J. Wysocki
Quoted 33 lines · Rafael J. Wysocki
Quoted 12 lines · Len Brown
Quoted 9 lines · Rafael J. Wysocki

Hi Len,

The following are fixes related to suspend and hibernation I have collected over the last couple of weeks. Some of them are in -mm. I think they all are 2.6.29 material.

1/9 and 2/9 fix hibernation regression caused by the async boot changes, I hope Greg will not object if they go through your tree.

Quoted 6 lines
Quoted 4 lines

3/9 fixes a long-standing hibernation issue that cause the resume partition to become unuseable after two consecutive failing attempts to hibernate.

4/9 fixes build of kprobes.c with CONFIG_PM unset.

looks like this one added power/ twice --

That was on purpose.

Quoted 1 line

and looks like akpm sent a fixed version of this to linus already?

Yes, he did.

Quoted 7 lines
Quoted 7 lines

5/9 and 6/9 clean up memory freeing code used during hibernation.

7/9 fixes a bug related to the use of PM notifiers during hibernation with the help of the user land interface.

8/9 and 9/9 fix the handling of consoles during suspend/hibernation.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Please add these patches to the suspend branch and push to Linus for 2.6.29.

All except #4 are now on the suspend branch.

1/9 and 2/9 are also in the Greg's tree, AFAICS.

Greg, do you intend to push them to Linus? In that case I think it's better if Len drops them.

I was not planning to send them for .29, sorry I got confused. I'll drop them from my tree and Len can send them all to Linus now.

Is that ok?

thanks,

greg k-h

#26 lore raw
Quoted 3 lines · Greg KH

I was not planning to send them for .29, sorry I got confused. I'll drop them from my tree and Len can send them all to Linus now.

they really really need to go into .29, they are a fix for a regression.

This patch exists for 6 weeks now as a fix for the regression.. why is it so hard to get it sent to Linus???

#27 lore raw
In reply to Greg KH
Quoted 3 lines · Greg KH

I was not planning to send them for .29, sorry I got confused. I'll drop them from my tree and Len can send them all to Linus now.

they really really need to go into .29, they are a fix for a regression.

This patch exists for 6 weeks now as a fix for the regression.. why is it so hard to get it sent to Linus???

#28 lore raw
Quoted 8 lines · Arjan van de Ven
Quoted 2 lines · Greg KH

I was not planning to send them for .29, sorry I got confused. I'll drop them from my tree and Len can send them all to Linus now.

they really really need to go into .29, they are a fix for a regression.

This patch exists for 6 weeks now as a fix for the regression.. why is it so hard to get it sent to Linus???

I think it's because both of us (Len and I) think the other is doing it :(

Ok, so, Len, are you willing to send these to Linus this week?

thanks,

greg k-h

#29 lore raw
In reply to Arjan van de Ven
Quoted 8 lines · Arjan van de Ven
Quoted 2 lines · Greg KH

I was not planning to send them for .29, sorry I got confused. I'll drop them from my tree and Len can send them all to Linus now.

they really really need to go into .29, they are a fix for a regression.

This patch exists for 6 weeks now as a fix for the regression.. why is it so hard to get it sent to Linus???

I think it's because both of us (Len and I) think the other is doing it :(

Ok, so, Len, are you willing to send these to Linus this week?

thanks,

greg k-h

#30 lore raw
Quoted 2 lines · Greg KH

Ok, so, Len, are you willing to send these to Linus this week?

I took them all, and added both of you to the cc, so if/when things break and get bisected to this series, both of you should be cc'd on the discussion.

Linus

reviewer
#31 lore raw
Quoted 4 lines

I took them all, and added both of you to the cc, so if/when things break and get bisected to this series, both of you should be cc'd on the discussion.

Okay, I'll delete them from my suspend branch.

thanks,
-Len

reviewer
#32 lore raw
In reply to Linus Torvalds
Quoted 4 lines

I took them all, and added both of you to the cc, so if/when things break and get bisected to this series, both of you should be cc'd on the discussion.

Okay, I'll delete them from my suspend branch.

thanks,
-Len

#33 lore raw
In reply to Linus Torvalds
Quoted 8 lines · Linus Torvalds
Quoted 2 lines · Greg KH

Ok, so, Len, are you willing to send these to Linus this week?

I took them all, and added both of you to the cc, so if/when things break and get bisected to this series, both of you should be cc'd on the discussion.

Thanks Linus! :-)

Rafael

#34 lore raw
In reply to Linus Torvalds
Quoted 8 lines · Linus Torvalds
Quoted 2 lines · Greg KH

Ok, so, Len, are you willing to send these to Linus this week?

I took them all, and added both of you to the cc, so if/when things break and get bisected to this series, both of you should be cc'd on the discussion.

Thanks Linus! :-)

Rafael