LKML Archive on lore.kernel.org
 help / color / Atom feed
From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: Tejun Heo <tj@kernel.org>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	AceLan Kao <acelan.kao@canonical.com>,
	Jens Axboe <axboe@kernel.dk>, Jan Kara <jack@suse.cz>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org
Subject: System hangs if NVMe/SSD is removed during suspend
Date: Wed, 2 Oct 2019 15:21:36 +0300
Message-ID: <20191002122136.GD2819@lahna.fi.intel.com> (raw)

Hi Tejun,

In a system with Thunderbolt connected NVMe or SSD entering system
suspend, detaching the NVMe/SSD and resuming the system hangs (see also
https://bugzilla.kernel.org/show_bug.cgi?id=204385).

Triggering sysrq-w I see this:

[  113.093783] Workqueue: nvme-wq nvme_remove_dead_ctrl_work [nvme]
[  113.095156] Call Trace:
[  113.096234]  ? __schedule+0x2c5/0x630
[  113.097409]  ? wait_for_completion+0xa4/0x120
[  113.098639]  schedule+0x3e/0xc0
[  113.099769]  schedule_timeout+0x1c9/0x320
[  113.100973]  ? resched_curr+0x1f/0xd0
[  113.102146]  ? wait_for_completion+0xa4/0x120
[  113.103379]  wait_for_completion+0xc3/0x120
[  113.104595]  ? wake_up_q+0x60/0x60
[  113.105749]  __flush_work+0x131/0x1e0
[  113.106925]  ? flush_workqueue_prep_pwqs+0x130/0x130
[  113.108215]  bdi_unregister+0xb9/0x130
[  113.109403]  del_gendisk+0x2d2/0x2e0
[  113.110580]  nvme_ns_remove+0xed/0x110 [nvme_core]
[  113.111853]  nvme_remove_namespaces+0x96/0xd0 [nvme_core]
[  113.113177]  nvme_remove+0x5b/0x160 [nvme]
[  113.114391]  pci_device_remove+0x36/0x90
[  113.115590]  device_release_driver_internal+0xdf/0x1c0
[  113.116893]  nvme_remove_dead_ctrl_work+0x14/0x30 [nvme]
[  113.118217]  process_one_work+0x1c2/0x3f0
[  113.119434]  worker_thread+0x48/0x3e0
[  113.120619]  kthread+0x100/0x140
[  113.121772]  ? current_work+0x30/0x30
[  113.122955]  ? kthread_park+0x80/0x80
[  113.124142]  ret_from_fork+0x35/0x40

The exact place is in wb_shutdown():

        /*
         * Drain work list and shutdown the delayed_work.  !WB_registered
         * tells wb_workfn() that @wb is dying and its work_list needs to
         * be drained no matter what.
         */
        mod_delayed_work(bdi_wq, &wb->dwork, 0);
        flush_delayed_work(&wb->dwork);

Now bdi_wq is marked as WQ_FREEZABLE and at this time we are still
resuming devices so I think it is still frozen. This basically results
that the resume process is waiting for bdi_unregister() but it cannot
progress because its workqueue is still frozen.

I saw you "dealt" similar situation for libata with commit 85fbd722ad0f
("libata, freezer: avoid block device removal while system is frozen")
and that there was discussion around this here:

  https://marc.info/?l=linux-kernel&m=138695698516487

but from that discussion I don't see more generic solution to be
implemented.

Any ideas we should fix this properly?

I mean nowadays Thunderbolt connected storage is quite common and I
suppose situation like this might wery well happen, say you have a dock
with SSD connected and you disconnect it when the laptop is suspended.

I've been using following hack to prevent the issue but I'm quite sure
there is a better solution ;-)

Thanks in advance!

 drivers/ata/libata-scsi.c | 2 ++
 mm/backing-dev.c          | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 76d0f9de767b..3fea8d72f6f9 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -4791,6 +4791,7 @@ void ata_scsi_hotplug(struct work_struct *work)
 		return;
 	}
 
+#if 0
 	/*
 	 * XXX - UGLY HACK
 	 *
@@ -4810,6 +4811,7 @@ void ata_scsi_hotplug(struct work_struct *work)
 #ifdef CONFIG_FREEZER
 	while (pm_freezing)
 		msleep(10);
+#endif
 #endif
 
 	DPRINTK("ENTER\n");
diff --git a/mm/backing-dev.c b/mm/backing-dev.c
index e8e89158adec..8e77711d5dd0 100644
--- a/mm/backing-dev.c
+++ b/mm/backing-dev.c
@@ -236,8 +236,8 @@ static int __init default_bdi_init(void)
 {
 	int err;
 
-	bdi_wq = alloc_workqueue("writeback", WQ_MEM_RECLAIM | WQ_FREEZABLE |
-					      WQ_UNBOUND | WQ_SYSFS, 0);
+	bdi_wq = alloc_workqueue("writeback", WQ_MEM_RECLAIM | WQ_UNBOUND |
+					      WQ_SYSFS, 0);
 	if (!bdi_wq)
 		return -ENOMEM;

             reply index

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-02 12:21 Mika Westerberg [this message]
2019-10-03 16:50 ` Tejun Heo
2019-10-04  8:03   ` Mika Westerberg
2019-10-04  9:59     ` Rafael J. Wysocki
2019-10-04 11:01       ` Mika Westerberg
2019-10-04 13:32         ` Jens Axboe
2019-10-07 10:08           ` Jan Kara
2019-10-09 13:22             ` Rafael J. Wysocki

Reply instructions:

You may reply publically 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=20191002122136.GD2819@lahna.fi.intel.com \
    --to=mika.westerberg@linux.intel.com \
    --cc=acelan.kao@canonical.com \
    --cc=axboe@kernel.dk \
    --cc=gregkh@linuxfoundation.org \
    --cc=jack@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=tj@kernel.org \
    /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

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git