linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Pierre Ossman <drzeus-mmc@drzeus.cx>,
	Zdenek Kabelac <zdenek.kabelac@gmail.com>,
	Kernel development list <linux-kernel@vger.kernel.org>,
	pm list <linux-pm@lists.linux-foundation.org>,
	Pavel Machek <pavel@ucw.cz>
Subject: Re: [Bug 10030] Suspend doesn't work when SD card is inserted
Date: Sun, 24 Feb 2008 21:25:43 +0100	[thread overview]
Message-ID: <200802242125.44032.rjw@sisk.pl> (raw)
In-Reply-To: <200802241433.20755.rjw@sisk.pl>

On Sunday, 24 of February 2008, Rafael J. Wysocki wrote:
> On Sunday, 24 of February 2008, Alan Stern wrote:
> > On Sun, 24 Feb 2008, Rafael J. Wysocki wrote:
> > 
> > > On Sunday, 24 of February 2008, Alan Stern wrote:
> > > > On Sat, 23 Feb 2008, Rafael J. Wysocki wrote:
> > > > 
> > > > > Ultimately no, it's not.  However, we are now late in the -rc2 time frame and
> > > > > the release of -rc3 seems to be imminent.  At this point, IMO, that's the
> > > > > safest thing to do.  BTW, appended is the patch I'd like to get applied.
> > > > 
> > > > In the interest of having a safe release, I guess you're right.
> > > 
> > > That's what I'm concerned about at the moment.  I'm afraid there won't be
> > > enough time to nail down all the issues (there may be some we're not even
> > > aware of).
> > 
> > All right.  You'll need to enlarge your big reversal patch by reverting 
> > commit 4145ed6dc597a9bea5f6ae8c574653b2de10620f.
> 
> Thanks for the hint.
> 
> In fact, I had to add a couple of fixes in device_power_down() and
> dpm_suspend().  The entire patch is appended.

I hope it's fine by everyone to push the patch below to Greg for 2.6.25.

Thanks,
Rafael


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

Remove the code that acquires all device semaphores from the suspend
code path as it causes multiple problems to appear (most notably,
http://bugzilla.kernel.org/show_bug.cgi?id=10030) and revert the
change introduced by commit 4145ed6dc597a9bea5f6ae8c574653b2de10620f
depending on the code being removed.

Remove pm_sleep_lock()/pm_sleep_unlock() from device add to avoid
the issue reported at http://bugzilla.kernel.org/show_bug.cgi?id=9874.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/base/core.c       |    8 ---
 drivers/base/power/main.c |   97 +++-------------------------------------------
 drivers/usb/core/usb.c    |    2 
 3 files changed, 8 insertions(+), 99 deletions(-)

Index: linux-2.6/drivers/base/power/main.c
===================================================================
--- linux-2.6.orig/drivers/base/power/main.c
+++ linux-2.6/drivers/base/power/main.c
@@ -48,7 +48,6 @@
  */
 
 LIST_HEAD(dpm_active);
-static LIST_HEAD(dpm_locked);
 static LIST_HEAD(dpm_off);
 static LIST_HEAD(dpm_off_irq);
 static LIST_HEAD(dpm_destroy);
@@ -81,28 +80,6 @@ void device_pm_add(struct device *dev)
  */
 void device_pm_remove(struct device *dev)
 {
-	/*
-	 * If this function is called during a suspend, it will be blocked,
-	 * because we're holding the device's semaphore at that time, which may
-	 * lead to a deadlock.  In that case we want to print a warning.
-	 * However, it may also be called by unregister_dropped_devices() with
-	 * the device's semaphore released, in which case the warning should
-	 * not be printed.
-	 */
-	if (down_trylock(&dev->sem)) {
-		if (down_read_trylock(&pm_sleep_rwsem)) {
-			/* No suspend in progress, wait on dev->sem */
-			down(&dev->sem);
-			up_read(&pm_sleep_rwsem);
-		} else {
-			/* Suspend in progress, we may deadlock */
-			dev_warn(dev, "Suspicious %s during suspend\n",
-				__FUNCTION__);
-			dump_stack();
-			/* The user has been warned ... */
-			down(&dev->sem);
-		}
-	}
 	pr_debug("PM: Removing info for %s:%s\n",
 		 dev->bus ? dev->bus->name : "No Bus",
 		 kobject_name(&dev->kobj));
@@ -110,7 +87,6 @@ void device_pm_remove(struct device *dev
 	dpm_sysfs_remove(dev);
 	list_del_init(&dev->power.entry);
 	mutex_unlock(&dpm_list_mtx);
-	up(&dev->sem);
 }
 
 /**
@@ -266,7 +242,7 @@ static void dpm_resume(void)
 		struct list_head *entry = dpm_off.next;
 		struct device *dev = to_device(entry);
 
-		list_move_tail(entry, &dpm_locked);
+		list_move_tail(entry, &dpm_active);
 		mutex_unlock(&dpm_list_mtx);
 		resume_device(dev);
 		mutex_lock(&dpm_list_mtx);
@@ -275,25 +251,6 @@ static void dpm_resume(void)
 }
 
 /**
- *	unlock_all_devices - Release each device's semaphore
- *
- *	Go through the dpm_off list.  Put each device on the dpm_active
- *	list and unlock it.
- */
-static void unlock_all_devices(void)
-{
-	mutex_lock(&dpm_list_mtx);
-	while (!list_empty(&dpm_locked)) {
-		struct list_head *entry = dpm_locked.prev;
-		struct device *dev = to_device(entry);
-
-		list_move(entry, &dpm_active);
-		up(&dev->sem);
-	}
-	mutex_unlock(&dpm_list_mtx);
-}
-
-/**
  *	unregister_dropped_devices - Unregister devices scheduled for removal
  *
  *	Unregister all devices on the dpm_destroy list.
@@ -305,7 +262,6 @@ static void unregister_dropped_devices(v
 		struct list_head *entry = dpm_destroy.next;
 		struct device *dev = to_device(entry);
 
-		up(&dev->sem);
 		mutex_unlock(&dpm_list_mtx);
 		/* This also removes the device from the list */
 		device_unregister(dev);
@@ -324,7 +280,6 @@ void device_resume(void)
 {
 	might_sleep();
 	dpm_resume();
-	unlock_all_devices();
 	unregister_dropped_devices();
 	up_write(&pm_sleep_rwsem);
 }
@@ -388,18 +343,15 @@ int device_power_down(pm_message_t state
 		struct list_head *entry = dpm_off.prev;
 		struct device *dev = to_device(entry);
 
-		list_del_init(&dev->power.entry);
 		error = suspend_device_late(dev, state);
 		if (error) {
 			printk(KERN_ERR "Could not power down device %s: "
 					"error %d\n",
 					kobject_name(&dev->kobj), error);
-			if (list_empty(&dev->power.entry))
-				list_add(&dev->power.entry, &dpm_off);
 			break;
 		}
-		if (list_empty(&dev->power.entry))
-			list_add(&dev->power.entry, &dpm_off_irq);
+		if (!list_empty(&dev->power.entry))
+			list_move(&dev->power.entry, &dpm_off_irq);
 	}
 
 	if (!error)
@@ -461,11 +413,10 @@ static int dpm_suspend(pm_message_t stat
 	int error = 0;
 
 	mutex_lock(&dpm_list_mtx);
-	while (!list_empty(&dpm_locked)) {
-		struct list_head *entry = dpm_locked.prev;
+	while (!list_empty(&dpm_active)) {
+		struct list_head *entry = dpm_active.prev;
 		struct device *dev = to_device(entry);
 
-		list_del_init(&dev->power.entry);
 		mutex_unlock(&dpm_list_mtx);
 		error = suspend_device(dev, state);
 		if (error) {
@@ -476,14 +427,11 @@ static int dpm_suspend(pm_message_t stat
 					(error == -EAGAIN ?
 					" (please convert to suspend_late)" :
 					""));
-			mutex_lock(&dpm_list_mtx);
-			if (list_empty(&dev->power.entry))
-				list_add(&dev->power.entry, &dpm_locked);
 			break;
 		}
 		mutex_lock(&dpm_list_mtx);
-		if (list_empty(&dev->power.entry))
-			list_add(&dev->power.entry, &dpm_off);
+		if (!list_empty(&dev->power.entry))
+			list_move(&dev->power.entry, &dpm_off);
 	}
 	mutex_unlock(&dpm_list_mtx);
 
@@ -491,36 +439,6 @@ static int dpm_suspend(pm_message_t stat
 }
 
 /**
- *	lock_all_devices - Acquire every device's semaphore
- *
- *	Go through the dpm_active list. Carefully lock each device's
- *	semaphore and put it in on the dpm_locked list.
- */
-static void lock_all_devices(void)
-{
-	mutex_lock(&dpm_list_mtx);
-	while (!list_empty(&dpm_active)) {
-		struct list_head *entry = dpm_active.next;
-		struct device *dev = to_device(entry);
-
-		/* Required locking order is dev->sem first,
-		 * then dpm_list_mutex.  Hence this awkward code.
-		 */
-		get_device(dev);
-		mutex_unlock(&dpm_list_mtx);
-		down(&dev->sem);
-		mutex_lock(&dpm_list_mtx);
-
-		if (list_empty(entry))
-			up(&dev->sem);		/* Device was removed */
-		else
-			list_move_tail(entry, &dpm_locked);
-		put_device(dev);
-	}
-	mutex_unlock(&dpm_list_mtx);
-}
-
-/**
  *	device_suspend - Save state and stop all devices in system.
  *	@state: new power management state
  *
@@ -533,7 +451,6 @@ int device_suspend(pm_message_t state)
 
 	might_sleep();
 	down_write(&pm_sleep_rwsem);
-	lock_all_devices();
 	error = dpm_suspend(state);
 	if (error)
 		device_resume();
Index: linux-2.6/drivers/usb/core/usb.c
===================================================================
--- linux-2.6.orig/drivers/usb/core/usb.c
+++ linux-2.6/drivers/usb/core/usb.c
@@ -234,7 +234,7 @@ static int ksuspend_usb_init(void)
 	 * singlethreaded.  Its job doesn't justify running on more
 	 * than one CPU.
 	 */
-	ksuspend_usb_wq = create_singlethread_workqueue("ksuspend_usbd");
+	ksuspend_usb_wq = create_freezeable_workqueue("ksuspend_usbd");
 	if (!ksuspend_usb_wq)
 		return -ENOMEM;
 	return 0;
Index: linux-2.6/drivers/base/core.c
===================================================================
--- linux-2.6.orig/drivers/base/core.c
+++ linux-2.6/drivers/base/core.c
@@ -770,13 +770,6 @@ int device_add(struct device *dev)
 	struct class_interface *class_intf;
 	int error;
 
-	error = pm_sleep_lock();
-	if (error) {
-		dev_warn(dev, "Suspicious %s during suspend\n", __FUNCTION__);
-		dump_stack();
-		return error;
-	}
-
 	dev = get_device(dev);
 	if (!dev || !strlen(dev->bus_id)) {
 		error = -EINVAL;
@@ -843,7 +836,6 @@ int device_add(struct device *dev)
 	}
  Done:
 	put_device(dev);
-	pm_sleep_unlock();
 	return error;
  BusError:
 	device_pm_remove(dev);

  reply	other threads:[~2008-02-24 20:27 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20080219232338.E9A24108068@picon.linux-foundation.org>
2008-02-20 16:42 ` [Bug 10030] Suspend doesn't work when SD card is inserted Alan Stern
2008-02-20 17:30   ` Pierre Ossman
2008-02-20 19:26     ` Alan Stern
2008-02-20 20:51       ` Pierre Ossman
2008-02-20 20:58         ` Rafael J. Wysocki
2008-02-20 21:06         ` Alan Stern
2008-02-20 22:15           ` Rafael J. Wysocki
2008-02-20 22:24             ` Alan Stern
2008-02-20 22:41               ` Rafael J. Wysocki
2008-02-21  0:02               ` Rafael J. Wysocki
2008-02-21 16:27                 ` Alan Stern
2008-02-21 16:38                   ` Rafael J. Wysocki
2008-02-21 17:48                     ` Alan Stern
2008-02-21 22:47                       ` Rafael J. Wysocki
2008-02-21 23:05                         ` Alan Stern
2008-02-23  1:30                           ` Rafael J. Wysocki
2008-02-23  4:39                             ` Alan Stern
2008-02-23 20:16                               ` Rafael J. Wysocki
2008-02-23 23:29                                 ` Alan Stern
2008-02-24  0:19                                   ` Rafael J. Wysocki
2008-02-24  3:25                                     ` Alan Stern
2008-02-24  4:26                                       ` [linux-pm] " Alan Stern
2008-02-24 14:00                                         ` Rafael J. Wysocki
2008-02-24 15:33                                           ` Bugs in MMC [was: [Bug 10030] Suspend doesn't work when SD card is inserted] Alan Stern
2008-02-25 17:41                                             ` Pierre Ossman
2008-02-25 17:58                                               ` Alan Stern
2008-02-25 18:31                                                 ` Pierre Ossman
2008-02-25 20:00                                                   ` Alan Stern
2008-03-01 14:11                                                     ` Pierre Ossman
2008-03-01 14:36                                                       ` Alan Stern
2008-03-01 14:47                                                         ` Pierre Ossman
2008-02-25 22:51                                               ` Felipe Balbi
2008-03-03 21:59                                               ` David Brownell
2008-03-04  6:03                                                 ` Pierre Ossman
2008-03-04  9:44                                                   ` David Brownell
2008-03-04  9:58                                                     ` Pierre Ossman
2008-03-06 21:23                                                       ` David Brownell
2008-03-04 17:53                                                     ` Alan Stern
2008-03-04 18:53                                                       ` David Brownell
2008-03-04 19:51                                                         ` Alan Stern
2008-03-04 20:30                                                           ` David Brownell
2008-03-04 21:00                                                             ` Alan Stern
2008-03-06 15:55                                                               ` Pavel Machek
2008-03-06 20:33                                                                 ` Alan Stern
2008-03-06 20:53                                                                   ` Zdenek Kabelac
2008-03-06 21:31                                                                     ` Rafael J. Wysocki
2008-03-04 17:50                                                 ` Alan Stern
2008-02-24 13:33                                       ` [Bug 10030] Suspend doesn't work when SD card is inserted Rafael J. Wysocki
2008-02-24 20:25                                         ` Rafael J. Wysocki [this message]
2008-02-24 20:45                                           ` Alan Stern
2008-02-24 20:56                                             ` Rafael J. Wysocki
2008-02-24 21:11                                               ` Alan Stern
2008-02-24 22:18                                                 ` Rafael J. Wysocki
2008-02-24 13:51                                       ` Rafael J. Wysocki
2008-02-24 19:27                                         ` Alan Stern
2008-02-24 19:42                                           ` Zdenek Kabelac
2008-02-24 20:09                                             ` Rafael J. Wysocki
2008-02-24 18:21                                       ` Pavel Machek
2008-02-24 19:03                                         ` Alan Stern
2008-02-24 20:11                                           ` Pavel Machek
2008-02-24 20:33                                             ` Alan Stern
2008-02-24 21:42                                               ` Pavel Machek
2008-02-24 22:21                                                 ` Rafael J. Wysocki
2008-02-25  2:21                                                   ` Alan Stern
2008-02-25 11:41                                                     ` Rafael J. Wysocki
     [not found]                                                       ` <c4e36d110802250402q7312a488idf752e07db7504e8@mail.gmail.com>
2008-02-25 12:31                                                         ` Rafael J. Wysocki
2008-02-25  2:19                                                 ` Alan Stern
2008-02-25  9:03                                                   ` using long instead of atomic_t when only set/read is required (was Re: [Bug 10030] Suspend doesn't work when SD card is inserted) Pavel Machek
2008-02-25 14:46                                                     ` Alan Stern
2008-03-03 12:08                                                       ` [patch] Re: using long instead of atomic_t when only set/read is required Pavel Machek
2008-03-03 15:42                                                         ` Alan Stern
2008-03-03 15:53                                                           ` Alan Cox
2008-03-03 17:11                                                             ` Alan Stern
2008-03-03 17:26                                                               ` Linus Torvalds
2008-03-03 17:44                                                                 ` Pavel Machek
2008-03-03 19:27                                                                   ` Alan Stern
2008-03-06 15:58                                                                 ` Mark Lord
2008-03-06 16:11                                                                   ` Linus Torvalds
2008-03-06 16:27                                                                     ` Mark Lord
2008-03-03 17:16                                                             ` Nick Piggin
2008-03-03 17:31                                                               ` Paul E. McKenney
2008-03-03 17:33                                                               ` Alan Cox
2008-03-03 17:22                                                           ` Paul E. McKenney
2008-03-03 15:48                                                         ` Alan Cox
2008-03-03 17:24                                                           ` Pavel Machek
2008-03-03 20:27                                                             ` Rafael J. Wysocki
2008-03-03 21:12                                                               ` Paul E. McKenney
2008-03-03 22:23                                                               ` Linus Torvalds
2008-03-04 23:32                                                             ` Peter Hartley
2008-03-04 23:54                                                               ` Rafael J. Wysocki
2008-03-05  0:26                                                                 ` Paul E. McKenney
2008-02-25 11:40                                                   ` [Bug 10030] Suspend doesn't work when SD card is inserted Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200802242125.44032.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=drzeus-mmc@drzeus.cx \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=pavel@ucw.cz \
    --cc=stern@rowland.harvard.edu \
    --cc=zdenek.kabelac@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).