linux/drivers/mmc/core
Ulf Hansson 17a17bf506 mmc: core: Fix hanging on I/O during system suspend for removable cards
The mmc core uses a PM notifier to temporarily during system suspend, turn
off the card detection mechanism for removal/insertion of (e)MMC/SD/SDIO
cards. Additionally, the notifier may be used to remove an SDIO card
entirely, if a corresponding SDIO functional driver don't have the system
suspend/resume callbacks assigned. This behaviour has been around for a
very long time.

However, a recent bug report tells us there are problems with this
approach. More precisely, when receiving the PM_SUSPEND_PREPARE
notification, we may end up hanging on I/O to be completed, thus also
preventing the system from getting suspended.

In the end what happens, is that the cancel_delayed_work_sync() in
mmc_pm_notify() ends up waiting for mmc_rescan() to complete - and since
mmc_rescan() wants to claim the host, it needs to wait for the I/O to be
completed first.

Typically, this problem is triggered in Android, if there is ongoing I/O
while the user decides to suspend, resume and then suspend the system
again. This due to that after the resume, an mmc_rescan() work gets punted
to the workqueue, which job is to verify that the card remains inserted
after the system has resumed.

To fix this problem, userspace needs to become frozen to suspend the I/O,
prior to turning off the card detection mechanism. Therefore, let's drop
the PM notifiers for mmc subsystem altogether and rely on the card
detection to be turned off/on as a part of the system_freezable_wq, that we
are already using.

Moreover, to allow and SDIO card to be removed during system suspend, let's
manage this from a ->prepare() callback, assigned at the mmc_host_class
level. In this way, we can use the parent device (the mmc_host_class
device), to remove the card device that is the child, in the
device_prepare() phase.

Reported-by: Kiwoong Kim <kwmad.kim@samsung.com>
Cc: stable@vger.kernel.org # v4.5+
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20210310152900.149380-1-ulf.hansson@linaro.org
Reviewed-by: Kiwoong Kim <kwmad.kim@samsung.com>
2021-03-30 11:42:03 +02:00
..
block.c mmc: core: Remove mq->use_cqe from the struct mmc_queue 2021-03-30 11:42:02 +02:00
block.h mmc: block: Remove code no longer needed after the switch to blk-mq 2017-12-11 13:02:22 +01:00
bus.c mmc: cqhci: Fix random crash when remove mmc module/card 2021-03-09 10:00:52 +01:00
bus.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
card.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 194 2019-05-30 11:29:22 -07:00
core.c mmc: core: Fix hanging on I/O during system suspend for removable cards 2021-03-30 11:42:03 +02:00
core.h mmc: core: Fix hanging on I/O during system suspend for removable cards 2021-03-30 11:42:03 +02:00
crypto.c mmc: core: Add basic support for inline encryption 2021-02-01 12:02:33 +01:00
crypto.h mmc: core: Add basic support for inline encryption 2021-02-01 12:02:33 +01:00
debugfs.c mmc: core: Use DEFINE_DEBUGFS_ATTRIBUTE instead of DEFINE_SIMPLE_ATTRIBUTE 2020-05-28 11:21:01 +02:00
host.c mmc: core: Fix hanging on I/O during system suspend for removable cards 2021-03-30 11:42:03 +02:00
host.h mmc: core: Initial support for SD express card/host 2020-11-16 11:59:28 +01:00
Kconfig mmc: core: Add basic support for inline encryption 2021-02-01 12:02:33 +01:00
Makefile mmc: core: Add basic support for inline encryption 2021-02-01 12:02:33 +01:00
mmc.c mmc: core: Fix partition switch time for eMMC 2021-03-09 10:00:52 +01:00
mmc_ops.c mmc: core: Reduce code duplication to mmc_spi_send_{csd|cid} 2021-03-30 11:41:58 +02:00
mmc_ops.h mmc: core: Re-work the code for eMMC sanitize 2020-03-26 14:45:31 +01:00
mmc_test.c mmc: mmc_test: use erase_arg for mmc_erase command 2021-02-12 12:07:03 +01:00
pwrseq.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 194 2019-05-30 11:29:22 -07:00
pwrseq.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 194 2019-05-30 11:29:22 -07:00
pwrseq_emmc.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 194 2019-05-30 11:29:22 -07:00
pwrseq_sd8787.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157 2019-05-30 11:26:37 -07:00
pwrseq_simple.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 194 2019-05-30 11:29:22 -07:00
queue.c mmc: core: Remove mq->use_cqe from the struct mmc_queue 2021-03-30 11:42:02 +02:00
queue.h mmc: core: Remove mq->use_cqe from the struct mmc_queue 2021-03-30 11:42:02 +02:00
quirks.h mmc: core: Mark fixups as __maybe_unused 2020-07-13 12:18:25 +02:00
regulator.c mmc: core: Add missing documetation for 'mmc' and 'ios' 2020-07-13 12:18:25 +02:00
sd.c mmc: core: Set read only for SD cards with permanent write protect bit 2021-03-30 11:41:59 +02:00
sd.h mmc: core: remove unused host parameter of mmc_sd_get_csd() 2021-02-01 11:54:48 +01:00
sd_ops.c mmc: core: Initial support for SD express card/host 2020-11-16 11:59:28 +01:00
sd_ops.h mmc: core: Initial support for SD express card/host 2020-11-16 11:59:28 +01:00
sdio.c mmc: core: Fix hanging on I/O during system suspend for removable cards 2021-03-30 11:42:03 +02:00
sdio_bus.c mmc: sdio: Export SDIO revision and info strings to userspace 2020-09-07 09:11:29 +02:00
sdio_bus.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
sdio_cis.c mmc: core: Limit retries when analyse of SDIO tuples fails 2021-02-01 11:13:06 +01:00
sdio_cis.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
sdio_io.c mmc: core: Provide description for sdio_set_host_pm_flags()'s 'flag' arg 2020-07-13 12:18:25 +02:00
sdio_irq.c sched,mmc: Convert to sched_set_fifo*() 2020-06-15 14:10:22 +02:00
sdio_ops.c mmc: sdio: Use mmc_pre_req() / mmc_post_req() 2020-09-07 08:57:44 +02:00
sdio_ops.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
sdio_uart.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
slot-gpio.c mmc: core: Remove mmc_gpiod_request_*(invert_gpio) 2019-12-18 13:37:07 +01:00
slot-gpio.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 194 2019-05-30 11:29:22 -07:00