From mboxrd@z Thu Jan 1 00:00:00 1970 From: akpm@linux-foundation.org Subject: [patch 5/8] mmc: fix hang if card was removed during suspend and unsafe resume was enabled Date: Wed, 10 Feb 2010 13:56:39 -0800 Message-ID: <201002102156.o1ALudbX001270@imap1.linux-foundation.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit Return-path: Received: from smtp1.linux-foundation.org ([140.211.169.13]:55283 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755507Ab0BJV5S (ORCPT ); Wed, 10 Feb 2010 16:57:18 -0500 Sender: linux-mmc-owner@vger.kernel.org List-Id: linux-mmc@vger.kernel.org To: torvalds@linux-foundation.org Cc: akpm@linux-foundation.org, maximlevitsky@gmail.com, dwmw2@infradead.org, ext-jorg.2.schummer@nokia.com, linux-mmc@vger.kernel.org, nico@fluxnic.net, rjw@sisk.pl, stable@kernel.org From: Maxim Levitsky Presently the following operations lead to a hang: -> Have a kernel with CONFIG_MMC_UNSAFE_RESUME -> Insert MMC/SD card -> Suspend/hibernate the system -> While system is hibernated/suspended pull the card off -> Resume the system -> Hang [] ? prepare_to_wait+0x2a/0x90 [] ? trace_hardirqs_on+0xd/0x10 [] ? _raw_spin_unlock_irqrestore+0x42/0x80 [] ? bdi_sched_wait+0x0/0x20 [] bdi_sched_wait+0xe/0x20 [] __wait_on_bit+0x5f/0x90 [] ? bdi_sched_wait+0x0/0x20 [] out_of_line_wait_on_bit+0x78/0x90 [] ? wake_bit_function+0x0/0x40 [] ? bdi_queue_work+0xa3/0xe0 [] bdi_sync_writeback+0x6f/0x80 [] sync_inodes_sb+0x22/0x120 [] __sync_filesystem+0x82/0x90 [] sync_filesystem+0x4b/0x70 [] fsync_bdev+0x2e/0x60 [] invalidate_partition+0x2e/0x50 [] del_gendisk+0x3f/0x140 [] mmc_blk_remove+0x33/0x60 [mmc_block] [] mmc_bus_remove+0x17/0x20 [] __device_release_driver+0x66/0xc0 [] device_release_driver+0x2d/0x40 [] bus_remove_device+0xb5/0x120 [] device_del+0x12f/0x1a0 [] mmc_remove_card+0x5b/0x90 [] mmc_sd_remove+0x27/0x50 [] mmc_resume_host+0x10c/0x140 [] sdhci_resume_host+0x69/0xa0 [sdhci] [] sdhci_pci_resume+0x8e/0xb0 [sdhci_pci] because del_gendisk() tries to perform writeout when some devices are in the suspended state. If CONFIG_MMC_UNSAFE_RESUME is set, mmc core allows the user to suspend/resume the card normally assuming he won't change the card or modify it in another system. The former case is actually handled quite well. If CONFIG_MMC_UNSAFE_RESUME isn't set, it removes the card during suspend, and I now think (and will test) that this will still hang the system this time on suspend. Fix that by removing the code that did that in mmc_resume_host. It is possible because card detection logic will kick it later and remove the card. Also make mtd workqueue freezeable, so it won't attempt to add/remove the card while userspace is frozen. Signed-off-by: Maxim Levitsky Cc: "Rafael J. Wysocki" Cc: David Woodhouse Cc: Jorg Schummer Cc: Nicolas Pitre Cc: Cc: Signed-off-by: Andrew Morton --- drivers/mmc/core/core.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff -puN drivers/mmc/core/core.c~mmc-fix-hang-if-card-was-removed-during-suspend-and-unsafe-resume-was-enabled drivers/mmc/core/core.c --- a/drivers/mmc/core/core.c~mmc-fix-hang-if-card-was-removed-during-suspend-and-unsafe-resume-was-enabled +++ a/drivers/mmc/core/core.c @@ -1257,7 +1257,6 @@ int mmc_suspend_host(struct mmc_host *ho if (host->caps & MMC_CAP_DISABLE) cancel_delayed_work(&host->disable); cancel_delayed_work(&host->detect); - mmc_flush_scheduled_work(); mmc_bus_get(host); if (host->bus_ops && !host->bus_dead) { @@ -1300,15 +1299,11 @@ int mmc_resume_host(struct mmc_host *hos mmc_select_voltage(host, host->ocr); BUG_ON(!host->bus_ops->resume); err = host->bus_ops->resume(host); + if (err) { printk(KERN_WARNING "%s: error %d during resume " "(card was removed?)\n", mmc_hostname(host), err); - if (host->bus_ops->remove) - host->bus_ops->remove(host); - mmc_claim_host(host); - mmc_detach_bus(host); - mmc_release_host(host); /* no need to bother upper layers */ err = 0; } @@ -1332,7 +1327,7 @@ static int __init mmc_init(void) { int ret; - workqueue = create_singlethread_workqueue("kmmcd"); + workqueue = create_freezeable_workqueue("kmmcd"); if (!workqueue) return -ENOMEM; _