Skip to contentSkip to conversation

Make suspend and resume safe for md-on-SCSI

PATCH NAK Bart Van Assche 4 participants 43 messages Sep 25, 2017 – Oct 2, 2017

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

v4 cover Make suspend and resume safe for md-on-SCSI

Hello Jens,

It is known that during the resume following a hibernate, especially when using an md RAID1 array created on top of SCSI devices, sometimes the system hangs instead of coming up properly. This patch series fixes this problem. This patch series is an alternative for Ming Lei's "[PATCH V5 0/10] block/scsi: safe SCSI quiescing" patch series. The advantages of this patch series are:
- Easier to review because no new race conditions are introduced between queue freezing and blk_cleanup_queue(). As the discussion that followed Ming's patch series shows the correctness of the new code is hard to verify.
- No new freeze modes and hence no new freeze mode variables.

These patches have been tested on top of a merge of the block layer for-next branch and Linus' master tree. Linus' master tree includes patch "KVM: x86: Fix the NULL pointer parameter in check_cr_write()" but the block layer for-next branch not yet.

Please consider these changes for kernel v4.15.

Thanks,

Bart.

Changes between v3 and v4:
- Made sure that this patch series not only works for scsi-mq but also for the legacy SCSI stack.
- Removed an smp_rmb()/smp_wmb() pair from the hot path and added a comment that explains why that is safe.
- Reordered the patches in this patch series.

Changes between v2 and v3:
- Made md kernel threads freezable.
- Changed the approach for quiescing SCSI devices again.
- Addressed Ming's review comments.

Changes compared to v1 of this patch series:
- Changed the approach and rewrote the patch series.

Bart Van Assche (6):
md: Make md resync and reshape threads freezable
block: Convert RQF_PREEMPT into REQ_PREEMPT
block: Add the QUEUE_FLAG_PREEMPT_ONLY request queue flag
scsi-mq: Reduce suspend latency
scsi: Set QUEUE_FLAG_PREEMPT_ONLY while quiesced
block: Make SCSI device suspend and resume work reliably

Ming Lei (1):
block: Make q_usage_counter also track legacy requests

 block/blk-core.c          | 60 +++++++++++++++++++++++++++++++++++++++++------
 block/blk-mq-debugfs.c    |  2 +-
 block/blk-mq.c            | 14 ++++-------
 block/blk-timeout.c       |  2 +-
 drivers/ide/ide-atapi.c   |  3 +--
 drivers/ide/ide-io.c      |  2 +-
 drivers/ide/ide-pm.c      |  4 ++--
 drivers/md/md.c           | 21 ++++++++++-------
 drivers/scsi/scsi_lib.c   | 30 +++++++++++++++---------
 fs/block_dev.c            |  4 ++--
 include/linux/blk_types.h |  6 +++++
 include/linux/blkdev.h    | 10 ++++----
 12 files changed, 109 insertions(+), 49 deletions(-)
Signature · 1 line
2.14.1
#1 lore raw

PATCH v4 1/7 md: Make md resync and reshape threads freezable

Some people use the md driver on laptops and use the suspend and resume functionality. Since it is essential that submitting of new I/O requests stops before device quiescing starts, make the md resync and reshape threads freezable.

Cc Shaohua Li <[email protected]>
Cc Ming Lei <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Johannes Thumshirn <[email protected]>
---
 drivers/md/md.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
drivers/md/md.c +13 -8
index 08fcaebc61bd..26a12bd0db65 100644
@@ -66,6 +66,7 @@
 #include <linux/raid/md_u.h>
 #include <linux/slab.h>
 #include <linux/percpu-refcount.h>
+#include <linux/freezer.h>
 
 #include <trace/events/block.h>
 #include "md.h"
@@ -7424,6 +7425,7 @@ static int md_thread(void *arg)
 	 */
 
 	allow_signal(SIGKILL);
+	set_freezable();
 	while (!kthread_should_stop()) {
 
 		/* We need to wait INTERRUPTIBLE so that
@@ -7434,7 +7436,7 @@ static int md_thread(void *arg)
 		if (signal_pending(current))
 			flush_signals(current);
 
-		wait_event_interruptible_timeout
+		wait_event_freezable_timeout
 			(thread->wqueue,
 			 test_bit(THREAD_WAKEUP, &thread->flags)
 			 || kthread_should_stop() || kthread_should_park(),
@@ -8133,6 +8135,8 @@ void md_do_sync(struct md_thread *thread)
 		return;
 	}
 
+	set_freezable();
+
 	if (mddev_is_clustered(mddev)) {
 		ret = md_cluster_ops->resync_start(mddev);
 		if (ret)
@@ -8324,7 +8328,7 @@ void md_do_sync(struct md_thread *thread)
 		     mddev->curr_resync_completed > mddev->resync_max
 			    )) {
 			/* time to update curr_resync_completed */
-			wait_event(mddev->recovery_wait,
+			wait_event_freezable(mddev->recovery_wait,
 				   atomic_read(&mddev->recovery_active) == 0);
 			mddev->curr_resync_completed = j;
 			if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery) &&
@@ -8342,10 +8346,10 @@ void md_do_sync(struct md_thread *thread)
 			 * to avoid triggering warnings.
 			 */
 			flush_signals(current); /* just in case */
-			wait_event_interruptible(mddev->recovery_wait,
-						 mddev->resync_max > j
-						 || test_bit(MD_RECOVERY_INTR,
-							     &mddev->recovery));
+			wait_event_freezable(mddev->recovery_wait,
+					     mddev->resync_max > j ||
+					     test_bit(MD_RECOVERY_INTR,
+						      &mddev->recovery));
 		}
 
 		if (test_bit(MD_RECOVERY_INTR, &mddev->recovery))
@@ -8421,7 +8425,7 @@ void md_do_sync(struct md_thread *thread)
 				 * Give other IO more of a chance.
 				 * The faster the devices, the less we wait.
 				 */
-				wait_event(mddev->recovery_wait,
+				wait_event_freezable(mddev->recovery_wait,
 					   !atomic_read(&mddev->recovery_active));
 			}
 		}
@@ -8433,7 +8437,8 @@ void md_do_sync(struct md_thread *thread)
 	 * this also signals 'finished resyncing' to md_stop
 	 */
 	blk_finish_plug(&plug);
-	wait_event(mddev->recovery_wait, !atomic_read(&mddev->recovery_active));
+	wait_event_freezable(mddev->recovery_wait,
+			     !atomic_read(&mddev->recovery_active));
 
 	if (!test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) &&
 	    !test_bit(MD_RECOVERY_INTR, &mddev->recovery) &&
Signature · 1 line
2.14.1
#20 lore raw

PATCH v4 3/7 block: Convert RQF_PREEMPT into REQ_PREEMPT

In reply to Bart Van Assche

This patch does not change any functionality but makes the REQ_PREEMPT flag available to blk_get_request(). A later patch will add code to blk_get_request() that checks the REQ_PREEMPT flag. Note: the IDE sense_rq request is allocated statically so there is no blk_get_request() call that corresponds to this request.

Cc Ming Lei <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Johannes Thumshirn <[email protected]>
---
 block/blk-mq-debugfs.c    |  2 +-
 drivers/ide/ide-atapi.c   |  3 +--
 drivers/ide/ide-io.c      |  2 +-
 drivers/ide/ide-pm.c      |  4 ++--
 drivers/scsi/scsi_lib.c   | 11 ++++++-----
 include/linux/blk_types.h |  6 ++++++
 include/linux/blkdev.h    |  3 ---
 7 files changed, 17 insertions(+), 14 deletions(-)
block/blk-mq-debugfs.c +1 -1
index 980e73095643..62ac248a4984 100644
@@ -266,6 +266,7 @@ static const char *const cmd_flag_name[] = {
 	CMD_FLAG_NAME(BACKGROUND),
 	CMD_FLAG_NAME(NOUNMAP),
 	CMD_FLAG_NAME(NOWAIT),
+	CMD_FLAG_NAME(PREEMPT),
 };
 #undef CMD_FLAG_NAME
 
@@ -279,7 +280,6 @@ static const char *const rqf_name[] = {
 	RQF_NAME(MIXED_MERGE),
 	RQF_NAME(MQ_INFLIGHT),
 	RQF_NAME(DONTPREP),
-	RQF_NAME(PREEMPT),
 	RQF_NAME(COPY_USER),
 	RQF_NAME(FAILED),
 	RQF_NAME(QUIET),
drivers/ide/ide-atapi.c +1 -2
index 14d1e7d9a1d6..1258739d5fa1 100644
@@ -211,9 +211,8 @@ void ide_prep_sense(ide_drive_t *drive, struct request *rq)
 	}
 
 	sense_rq->rq_disk = rq->rq_disk;
-	sense_rq->cmd_flags = REQ_OP_DRV_IN;
+	sense_rq->cmd_flags = REQ_OP_DRV_IN | REQ_PREEMPT;
 	ide_req(sense_rq)->type = ATA_PRIV_SENSE;
-	sense_rq->rq_flags |= RQF_PREEMPT;
 
 	req->cmd[0] = GPCMD_REQUEST_SENSE;
 	req->cmd[4] = cmd_len;
drivers/ide/ide-io.c +1 -1
index 3a234701d92c..06ffccd0fb10 100644
@@ -539,7 +539,7 @@ void do_ide_request(struct request_queue *q)
 		 */
 		if ((drive->dev_flags & IDE_DFLAG_BLOCKED) &&
 		    ata_pm_request(rq) == 0 &&
-		    (rq->rq_flags & RQF_PREEMPT) == 0) {
+		    (rq->cmd_flags & REQ_PREEMPT) == 0) {
 			/* there should be no pending command at this point */
 			ide_unlock_port(hwif);
 			goto plug_device;
drivers/ide/ide-pm.c +2 -2
index 544f02d673ca..f8d2709dcd56 100644
@@ -89,9 +89,9 @@ int generic_ide_resume(struct device *dev)
 	}
 
 	memset(&rqpm, 0, sizeof(rqpm));
-	rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, __GFP_RECLAIM);
+	rq = blk_get_request(drive->queue, REQ_OP_DRV_IN | REQ_PREEMPT,
+			     __GFP_RECLAIM);
 	ide_req(rq)->type = ATA_PRIV_PM_RESUME;
-	rq->rq_flags |= RQF_PREEMPT;
 	rq->special = &rqpm;
 	rqpm.pm_step = IDE_PM_START_RESUME;
 	rqpm.pm_state = PM_EVENT_ON;
drivers/scsi/scsi_lib.c +6 -5
index 9cf6a80fe297..62f905b22821 100644
@@ -253,8 +253,9 @@ int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
 	int ret = DRIVER_ERROR << 24;
 
 	req = blk_get_request(sdev->request_queue,
-			data_direction == DMA_TO_DEVICE ?
-			REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN, __GFP_RECLAIM);
+			      (data_direction == DMA_TO_DEVICE ?
+			       REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN) | REQ_PREEMPT,
+			      __GFP_RECLAIM);
 	if (IS_ERR(req))
 		return ret;
 	rq = scsi_req(req);
@@ -268,7 +269,7 @@ int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
 	rq->retries = retries;
 	req->timeout = timeout;
 	req->cmd_flags |= flags;
-	req->rq_flags |= rq_flags | RQF_QUIET | RQF_PREEMPT;
+	req->rq_flags |= rq_flags | RQF_QUIET;
 
 	/*
 	 * head injection *required* here otherwise quiesce won't work
@@ -1301,7 +1302,7 @@ scsi_prep_state_check(struct scsi_device *sdev, struct request *req)
 			/*
 			 * If the devices is blocked we defer normal commands.
 			 */
-			if (!(req->rq_flags & RQF_PREEMPT))
+			if (!(req->cmd_flags & REQ_PREEMPT))
 				ret = BLKPREP_DEFER;
 			break;
 		default:
@@ -1310,7 +1311,7 @@ scsi_prep_state_check(struct scsi_device *sdev, struct request *req)
 			 * special commands.  In particular any user initiated
 			 * command is not allowed.
 			 */
-			if (!(req->rq_flags & RQF_PREEMPT))
+			if (!(req->cmd_flags & REQ_PREEMPT))
 				ret = BLKPREP_KILL;
 			break;
 		}
include/linux/blk_types.h +6 -0
index a2d2aa709cef..b6b6bf44e462 100644
@@ -229,6 +229,11 @@ enum req_flag_bits {
 	__REQ_NOUNMAP,		/* do not free blocks when zeroing */
 
 	__REQ_NOWAIT,           /* Don't wait if request will block */
+	/*
+	 * set for "ide_preempt" requests and also for requests for which the
+	 * SCSI "quiesce" state must be ignored.
+	 */
+	__REQ_PREEMPT,
 	__REQ_NR_BITS,		/* stops here */
 };
 
@@ -248,6 +253,7 @@ enum req_flag_bits {
 
 #define REQ_NOUNMAP		(1ULL << __REQ_NOUNMAP)
 #define REQ_NOWAIT		(1ULL << __REQ_NOWAIT)
+#define REQ_PREEMPT		(1ULL << __REQ_PREEMPT)
 
 #define REQ_FAILFAST_MASK \
 	(REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER)
include/linux/blkdev.h +0 -3
index 460294bb0fa5..cd26901a6e25 100644
@@ -96,9 +96,6 @@ typedef __u32 __bitwise req_flags_t;
 #define RQF_MQ_INFLIGHT		((__force req_flags_t)(1 << 6))
 /* don't call prep for this one */
 #define RQF_DONTPREP		((__force req_flags_t)(1 << 7))
-/* set for "ide_preempt" requests and also for requests for which the SCSI
-   "quiesce" state must be ignored. */
-#define RQF_PREEMPT		((__force req_flags_t)(1 << 8))
 /* contains copies of user pages */
 #define RQF_COPY_USER		((__force req_flags_t)(1 << 9))
 /* vaguely specified driver internal error.  Ignored by the block layer */
Signature · 1 line
2.14.1
#23 lore raw

PATCH v4 4/7 block: Add the QUEUE_FLAG_PREEMPT_ONLY request queue flag

In reply to Bart Van Assche

This flag will be used in the next patch to let the block layer core know whether or not a SCSI request queue has been quiesced. A quiesced SCSI queue namely only processes RQF_PREEMPT requests.

Cc Ming Lei <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Johannes Thumshirn <[email protected]>
---
 block/blk-core.c       | 13 +++++++++++++
 include/linux/blkdev.h |  5 +++++
 2 files changed, 18 insertions(+)
block/blk-core.c +13 -0
index fef7133f8b0e..9111a8f9c7a1 100644
@@ -346,6 +346,19 @@ void blk_sync_queue(struct request_queue *q)
 }
 EXPORT_SYMBOL(blk_sync_queue);
 
+void blk_set_preempt_only(struct request_queue *q, bool preempt_only)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(q->queue_lock, flags);
+	if (preempt_only)
+		queue_flag_set(QUEUE_FLAG_PREEMPT_ONLY, q);
+	else
+		queue_flag_clear(QUEUE_FLAG_PREEMPT_ONLY, q);
+	spin_unlock_irqrestore(q->queue_lock, flags);
+}
+EXPORT_SYMBOL(blk_set_preempt_only);
+
 /**
  * __blk_run_queue_uncond - run a queue whether or not it has been stopped
  * @q:	The queue to run
include/linux/blkdev.h +5 -0
index cd26901a6e25..5bd87599eed0 100644
@@ -627,6 +627,7 @@ struct request_queue {
 #define QUEUE_FLAG_REGISTERED  26	/* queue has been registered to a disk */
 #define QUEUE_FLAG_SCSI_PASSTHROUGH 27	/* queue supports SCSI commands */
 #define QUEUE_FLAG_QUIESCED    28	/* queue has been quiesced */
+#define QUEUE_FLAG_PREEMPT_ONLY	29	/* only process REQ_PREEMPT requests */
 
 #define QUEUE_FLAG_DEFAULT	((1 << QUEUE_FLAG_IO_STAT) |		\
 				 (1 << QUEUE_FLAG_STACKABLE)	|	\
@@ -731,6 +732,10 @@ static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)
 	((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \
 			     REQ_FAILFAST_DRIVER))
 #define blk_queue_quiesced(q)	test_bit(QUEUE_FLAG_QUIESCED, &(q)->queue_flags)
+#define blk_queue_preempt_only(q)				\
+	test_bit(QUEUE_FLAG_PREEMPT_ONLY, &(q)->queue_flags)
+
+extern void blk_set_preempt_only(struct request_queue *q, bool preempt_only);
 
 static inline bool blk_account_rq(struct request *rq)
 {
Signature · 1 line
2.14.1
#27 lore raw

PATCH v4 5/7 scsi: Reduce suspend latency

In reply to Bart Van Assche

Avoid that it can take 200 ms too long to wait for requests to finish. Note: blk_mq_freeze_queue() uses a wait queue to wait for ongoing requests to finish.

Cc Martin K. Petersen <[email protected]>
Cc Ming Lei <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Johannes Thumshirn <[email protected]>
---
 drivers/scsi/scsi_lib.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/scsi/scsi_lib.c +3 -5
index 62f905b22821..c261498606c4 100644
@@ -2927,6 +2927,7 @@ static void scsi_wait_for_queuecommand(struct scsi_device *sdev)
 int
 scsi_device_quiesce(struct scsi_device *sdev)
 {
+	struct request_queue *q = sdev->request_queue;
 	int err;
 
 	mutex_lock(&sdev->state_mutex);
@@ -2936,11 +2937,8 @@ scsi_device_quiesce(struct scsi_device *sdev)
 	if (err)
 		return err;
 
-	scsi_run_queue(sdev->request_queue);
-	while (atomic_read(&sdev->device_busy)) {
-		msleep_interruptible(200);
-		scsi_run_queue(sdev->request_queue);
-	}
+	blk_mq_freeze_queue(q);
+	blk_mq_unfreeze_queue(q);
 	return 0;
 }
 EXPORT_SYMBOL(scsi_device_quiesce);
Signature · 1 line
2.14.1
#33 lore raw

PATCH v4 7/7 block: Make SCSI device suspend and resume work reliably

In reply to Bart Van Assche

It is essential during suspend and resume that neither the filesystem state nor the filesystem metadata in RAM changes. This is why while the hibernation image is being written or restored that SCSI devices are quiesced. The SCSI core quiesces devices through scsi_device_quiesce() and scsi_device_resume(). In the SDEV_QUIESCE state execution of non-preempt requests is deferred. This is realized by returning BLKPREP_DEFER from inside scsi_prep_state_check() for quiesced SCSI devices. Avoid that a full queue prevents power management requests to be submitted by deferring allocation of non-preempt requests for devices in the quiesced state. This patch has been tested by running the following commands and by verifying that after resume the fio job is still running:

for d in /sys/class/block/sd*[a-z]; do
hcil=$(readlink "$d/device")
hcil=${hcil#../../../}
echo 4 > "$d/queue/nr_requests"
echo 1 > "/sys/class/scsi_device/$hcil/device/queue_depth"
done
bdev=$(readlink /dev/disk/by-uuid/5217d83f-213e-4b42-b86e-20013325ba6c) bdev=${bdev#../../}
hcil=$(readlink "/sys/block/$bdev/device")
hcil=${hcil#../../../}
fio --name="$bdev" --filename="/dev/$bdev" --buffered=0 --bs=512 --rw=randread \
--ioengine=libaio --numjobs=4 --iodepth=16 --iodepth_batch=1 --thread \
--loops=$((2**31)) &
pid=$!
sleep 1
systemctl hibernate
sleep 10
kill $pid

References: "I/O hangs after resuming from suspend-to-ram" (https://marc.info/?l=linux-block&m=150340235201348).

Cc Martin K. Petersen <[email protected]>
Cc Ming Lei <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Johannes Thumshirn <[email protected]>
---
 block/blk-core.c       | 41 +++++++++++++++++++++++++++++++----------
 block/blk-mq.c         |  4 ++--
 block/blk-timeout.c    |  2 +-
 fs/block_dev.c         |  4 ++--
 include/linux/blkdev.h |  2 +-
 5 files changed, 37 insertions(+), 16 deletions(-)
block/blk-core.c +31 -10
index 9111a8f9c7a1..01b7afee58f0 100644
@@ -351,10 +351,12 @@ void blk_set_preempt_only(struct request_queue *q, bool preempt_only)
 	unsigned long flags;
 
 	spin_lock_irqsave(q->queue_lock, flags);
-	if (preempt_only)
+	if (preempt_only) {
 		queue_flag_set(QUEUE_FLAG_PREEMPT_ONLY, q);
-	else
+	} else {
 		queue_flag_clear(QUEUE_FLAG_PREEMPT_ONLY, q);
+		wake_up_all(&q->mq_freeze_wq);
+	}
 	spin_unlock_irqrestore(q->queue_lock, flags);
 }
 EXPORT_SYMBOL(blk_set_preempt_only);
@@ -776,13 +778,31 @@ struct request_queue *blk_alloc_queue(gfp_t gfp_mask)
 }
 EXPORT_SYMBOL(blk_alloc_queue);
 
-int blk_queue_enter(struct request_queue *q, bool nowait)
+/**
+ * blk_queue_enter() - try to increase q->q_usage_counter
+ * @q: request queue pointer
+ * @nowait: if the queue is frozen, do not wait until it is unfrozen
+ * @preempt: if QUEUE_FLAG_PREEMPT_ONLY has been set, do not wait until that
+ *	flag has been cleared
+ */
+int blk_queue_enter(struct request_queue *q, bool nowait, bool preempt)
 {
 	while (true) {
 		int ret;
 
-		if (percpu_ref_tryget_live(&q->q_usage_counter))
-			return 0;
+		if (percpu_ref_tryget_live(&q->q_usage_counter)) {
+			/*
+			 * Since setting the PREEMPT_ONLY flag is followed
+			 * by a switch of q_usage_counter from per-cpu to
+			 * atomic mode and back to per-cpu and since the
+			 * switch to atomic mode uses call_rcu_sched(), it
+			 * is not necessary to call smp_rmb() here.
+			 */
+			if (preempt || !blk_queue_preempt_only(q))
+				return 0;
+			else
+				percpu_ref_put(&q->q_usage_counter);
+		}
 
 		if (nowait)
 			return -EBUSY;
@@ -797,7 +817,8 @@ int blk_queue_enter(struct request_queue *q, bool nowait)
 		smp_rmb();
 
 		ret = wait_event_interruptible(q->mq_freeze_wq,
-				!atomic_read(&q->mq_freeze_depth) ||
+				(atomic_read(&q->mq_freeze_depth) == 0 &&
+				 (preempt || !blk_queue_preempt_only(q))) ||
 				blk_queue_dying(q));
 		if (blk_queue_dying(q))
 			return -ENODEV;
@@ -1416,7 +1437,7 @@ static struct request *blk_old_get_request(struct request_queue *q,
 	create_io_context(gfp_mask, q->node);
 
 	ret = blk_queue_enter(q, !(gfp_mask & __GFP_DIRECT_RECLAIM) ||
-			      (op & REQ_NOWAIT));
+			      (op & REQ_NOWAIT), op & REQ_PREEMPT);
 	if (ret)
 		return ERR_PTR(ret);
 	spin_lock_irq(q->queue_lock);
@@ -2184,6 +2205,7 @@ blk_qc_t generic_make_request(struct bio *bio)
 	 */
 	struct bio_list bio_list_on_stack[2];
 	blk_qc_t ret = BLK_QC_T_NONE;
+	const bool nowait = bio->bi_opf & REQ_NOWAIT;
 
 	if (!generic_make_request_checks(bio))
 		goto out;
@@ -2223,7 +2245,7 @@ blk_qc_t generic_make_request(struct bio *bio)
 	do {
 		struct request_queue *q = bio->bi_disk->queue;
 
-		if (likely(blk_queue_enter(q, bio->bi_opf & REQ_NOWAIT) == 0)) {
+		if (likely(blk_queue_enter(q, nowait, false) == 0)) {
 			struct bio_list lower, same;
 
 			/* Create a fresh bio_list for all subordinate requests */
@@ -2248,8 +2270,7 @@ blk_qc_t generic_make_request(struct bio *bio)
 			bio_list_merge(&bio_list_on_stack[0], &same);
 			bio_list_merge(&bio_list_on_stack[0], &bio_list_on_stack[1]);
 		} else {
-			if (unlikely(!blk_queue_dying(q) &&
-					(bio->bi_opf & REQ_NOWAIT)))
+			if (unlikely(!blk_queue_dying(q) && nowait))
 				bio_wouldblock_error(bio);
 			else
 				bio_io_error(bio);
block/blk-mq.c +2 -2
index 10c1f49f663d..cbf7bf7e3d13 100644
@@ -384,7 +384,7 @@ struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,
 	struct request *rq;
 	int ret;
 
-	ret = blk_queue_enter(q, flags & BLK_MQ_REQ_NOWAIT);
+	ret = blk_queue_enter(q, flags & BLK_MQ_REQ_NOWAIT, op & REQ_PREEMPT);
 	if (ret)
 		return ERR_PTR(ret);
 
@@ -423,7 +423,7 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
 	if (hctx_idx >= q->nr_hw_queues)
 		return ERR_PTR(-EIO);
 
-	ret = blk_queue_enter(q, true);
+	ret = blk_queue_enter(q, true, op & REQ_PREEMPT);
 	if (ret)
 		return ERR_PTR(ret);
 
block/blk-timeout.c +1 -1
index 17ec83bb0900..0dfdc975473a 100644
@@ -134,7 +134,7 @@ void blk_timeout_work(struct work_struct *work)
 	struct request *rq, *tmp;
 	int next_set = 0;
 
-	if (blk_queue_enter(q, true))
+	if (blk_queue_enter(q, true, true))
 		return;
 	spin_lock_irqsave(q->queue_lock, flags);
 
fs/block_dev.c +2 -2
index 93d088ffc05c..e9ca45087a40 100644
@@ -674,7 +674,7 @@ int bdev_read_page(struct block_device *bdev, sector_t sector,
 	if (!ops->rw_page || bdev_get_integrity(bdev))
 		return result;
 
-	result = blk_queue_enter(bdev->bd_queue, false);
+	result = blk_queue_enter(bdev->bd_queue, false, false);
 	if (result)
 		return result;
 	result = ops->rw_page(bdev, sector + get_start_sect(bdev), page, false);
@@ -710,7 +710,7 @@ int bdev_write_page(struct block_device *bdev, sector_t sector,
 
 	if (!ops->rw_page || bdev_get_integrity(bdev))
 		return -EOPNOTSUPP;
-	result = blk_queue_enter(bdev->bd_queue, false);
+	result = blk_queue_enter(bdev->bd_queue, false, false);
 	if (result)
 		return result;
 
include/linux/blkdev.h +1 -1
index 5bd87599eed0..a025597c378a 100644
@@ -964,7 +964,7 @@ extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t,
 extern int sg_scsi_ioctl(struct request_queue *, struct gendisk *, fmode_t,
 			 struct scsi_ioctl_command __user *);
 
-extern int blk_queue_enter(struct request_queue *q, bool nowait);
+extern int blk_queue_enter(struct request_queue *q, bool nowait, bool preempt);
 extern void blk_queue_exit(struct request_queue *q);
 extern void blk_start_queue(struct request_queue *q);
 extern void blk_start_queue_async(struct request_queue *q);
Signature · 1 line
2.14.1
#16 lore raw

PATCH v4 2/7 block: Make q_usage_counter also track legacy requests

In reply to Bart Van Assche

From: Ming Lei <[email protected]>

This patch makes it possible to pause request allocation for the legacy block layer by calling blk_mq_freeze_queue() and blk_mq_unfreeze_queue().

[ bvanassche: Combined two patches into one, edited a comment and made sure
REQ_NOWAIT is handled properly in blk_old_get_request() ]

Cc Ming Lei <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Johannes Thumshirn <[email protected]>
---
 block/blk-core.c | 12 ++++++++++++
 block/blk-mq.c   | 10 ++--------
 2 files changed, 14 insertions(+), 8 deletions(-)
block/blk-core.c +12 -0
index aebe676225e6..fef7133f8b0e 100644
@@ -610,6 +610,9 @@ void blk_set_queue_dying(struct request_queue *q)
 		}
 		spin_unlock_irq(q->queue_lock);
 	}
+
+	/* Make blk_queue_enter() reexamine the DYING flag. */
+	wake_up_all(&q->mq_freeze_wq);
 }
 EXPORT_SYMBOL_GPL(blk_set_queue_dying);
 
@@ -1392,16 +1395,22 @@ static struct request *blk_old_get_request(struct request_queue *q,
 					   unsigned int op, gfp_t gfp_mask)
 {
 	struct request *rq;
+	int ret = 0;
 
 	WARN_ON_ONCE(q->mq_ops);
 
 	/* create ioc upfront */
 	create_io_context(gfp_mask, q->node);
 
+	ret = blk_queue_enter(q, !(gfp_mask & __GFP_DIRECT_RECLAIM) ||
+			      (op & REQ_NOWAIT));
+	if (ret)
+		return ERR_PTR(ret);
 	spin_lock_irq(q->queue_lock);
 	rq = get_request(q, op, NULL, gfp_mask);
 	if (IS_ERR(rq)) {
 		spin_unlock_irq(q->queue_lock);
+		blk_queue_exit(q);
 		return rq;
 	}
 
@@ -1573,6 +1582,7 @@ void __blk_put_request(struct request_queue *q, struct request *req)
 		blk_free_request(rl, req);
 		freed_request(rl, sync, rq_flags);
 		blk_put_rl(rl);
+		blk_queue_exit(q);
 	}
 }
 EXPORT_SYMBOL_GPL(__blk_put_request);
@@ -1854,8 +1864,10 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio)
 	 * Grab a free request. This is might sleep but can not fail.
 	 * Returns with the queue unlocked.
 	 */
+	blk_queue_enter_live(q);
 	req = get_request(q, bio->bi_opf, bio, GFP_NOIO);
 	if (IS_ERR(req)) {
+		blk_queue_exit(q);
 		__wbt_done(q->rq_wb, wb_acct);
 		if (PTR_ERR(req) == -ENOMEM)
 			bio->bi_status = BLK_STS_RESOURCE;
block/blk-mq.c +2 -8
index 98a18609755e..10c1f49f663d 100644
@@ -125,7 +125,8 @@ void blk_freeze_queue_start(struct request_queue *q)
 	freeze_depth = atomic_inc_return(&q->mq_freeze_depth);
 	if (freeze_depth == 1) {
 		percpu_ref_kill(&q->q_usage_counter);
-		blk_mq_run_hw_queues(q, false);
+		if (q->mq_ops)
+			blk_mq_run_hw_queues(q, false);
 	}
 }
 EXPORT_SYMBOL_GPL(blk_freeze_queue_start);
@@ -255,13 +256,6 @@ void blk_mq_wake_waiters(struct request_queue *q)
 	queue_for_each_hw_ctx(q, hctx, i)
 		if (blk_mq_hw_queue_mapped(hctx))
 			blk_mq_tag_wakeup_all(hctx->tags, true);
-
-	/*
-	 * If we are called because the queue has now been marked as
-	 * dying, we need to ensure that processes currently waiting on
-	 * the queue are notified as well.
-	 */
-	wake_up_all(&q->mq_freeze_wq);
 }
 
 bool blk_mq_can_queue(struct blk_mq_hw_ctx *hctx)
Signature · 1 line
2.14.1
#31 lore raw

PATCH v4 6/7 scsi: Set QUEUE_FLAG_PREEMPT_ONLY while quiesced

In reply to Bart Van Assche

Make the quiesce state visible to the block layer for the next patch in this series.

Cc Martin K. Petersen <[email protected]>
Cc Ming Lei <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Johannes Thumshirn <[email protected]>
---
 drivers/scsi/scsi_lib.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/scsi/scsi_lib.c +5 -1
index c261498606c4..309369d8fe01 100644
@@ -2932,6 +2932,8 @@ scsi_device_quiesce(struct scsi_device *sdev)
 
 	mutex_lock(&sdev->state_mutex);
 	err = scsi_device_set_state(sdev, SDEV_QUIESCE);
+	if (err == 0)
+		blk_set_preempt_only(q, true);
 	mutex_unlock(&sdev->state_mutex);
 
 	if (err)
@@ -2960,8 +2962,10 @@ void scsi_device_resume(struct scsi_device *sdev)
 	 */
 	mutex_lock(&sdev->state_mutex);
 	if (sdev->sdev_state == SDEV_QUIESCE &&
-	    scsi_device_set_state(sdev, SDEV_RUNNING) == 0)
+	    scsi_device_set_state(sdev, SDEV_RUNNING) == 0) {
+		blk_set_preempt_only(sdev->request_queue, false);
 		scsi_run_queue(sdev->request_queue);
+	}
 	mutex_unlock(&sdev->state_mutex);
 }
 EXPORT_SYMBOL(scsi_device_resume);
Signature · 1 line
2.14.1
#34 lore raw

Re: [PATCH v4 7/7] block: Make SCSI device suspend and resume work reliably

In reply to Bart Van Assche
Quoted 84 lines · Bart Van Assche

It is essential during suspend and resume that neither the filesystem state nor the filesystem metadata in RAM changes. This is why while the hibernation image is being written or restored that SCSI devices are quiesced. The SCSI core quiesces devices through scsi_device_quiesce() and scsi_device_resume(). In the SDEV_QUIESCE state execution of non-preempt requests is deferred. This is realized by returning BLKPREP_DEFER from inside scsi_prep_state_check() for quiesced SCSI devices. Avoid that a full queue prevents power management requests to be submitted by deferring allocation of non-preempt requests for devices in the quiesced state. This patch has been tested by running the following commands and by verifying that after resume the fio job is still running:

for d in /sys/class/block/sd*[a-z]; do
hcil=$(readlink "$d/device")
hcil=${hcil#../../../}
echo 4 > "$d/queue/nr_requests"
echo 1 > "/sys/class/scsi_device/$hcil/device/queue_depth"
done
bdev=$(readlink /dev/disk/by-uuid/5217d83f-213e-4b42-b86e-20013325ba6c) bdev=${bdev#../../}
hcil=$(readlink "/sys/block/$bdev/device")
hcil=${hcil#../../../}
fio --name="$bdev" --filename="/dev/$bdev" --buffered=0 --bs=512 --rw=randread \
--ioengine=libaio --numjobs=4 --iodepth=16 --iodepth_batch=1 --thread \
--loops=$((2**31)) &
pid=$!
sleep 1
systemctl hibernate
sleep 10
kill $pid

References: "I/O hangs after resuming from suspend-to-ram" (https://marc.info/?l=linux-block&m=150340235201348).

Cc Martin K. Petersen <[email protected]>
Cc Ming Lei <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Johannes Thumshirn <[email protected]>
---
 block/blk-core.c       | 41 +++++++++++++++++++++++++++++++----------
 block/blk-mq.c         |  4 ++--
 block/blk-timeout.c    |  2 +-
 fs/block_dev.c         |  4 ++--
 include/linux/blkdev.h |  2 +-
 5 files changed, 37 insertions(+), 16 deletions(-)
block/blk-core.c +12 -3
index 9111a8f9c7a1..01b7afee58f0 100644
@@ -351,10 +351,12 @@ void blk_set_preempt_only(struct request_queue *q, bool preempt_only)
 	unsigned long flags;
 
 	spin_lock_irqsave(q->queue_lock, flags);
-	if (preempt_only)
+	if (preempt_only) {
 		queue_flag_set(QUEUE_FLAG_PREEMPT_ONLY, q);
-	else
+	} else {
 		queue_flag_clear(QUEUE_FLAG_PREEMPT_ONLY, q);
+		wake_up_all(&q->mq_freeze_wq);
+	}
 	spin_unlock_irqrestore(q->queue_lock, flags);
 }
 EXPORT_SYMBOL(blk_set_preempt_only);
@@ -776,13 +778,31 @@ struct request_queue *blk_alloc_queue(gfp_t gfp_mask)
 }
 EXPORT_SYMBOL(blk_alloc_queue);
 
-int blk_queue_enter(struct request_queue *q, bool nowait)
+/**
+ * blk_queue_enter() - try to increase q->q_usage_counter
+ * @q: request queue pointer
+ * @nowait: if the queue is frozen, do not wait until it is unfrozen
+ * @preempt: if QUEUE_FLAG_PREEMPT_ONLY has been set, do not wait until that
+ *	flag has been cleared
+ */
+int blk_queue_enter(struct request_queue *q, bool nowait, bool preempt)
 {
 	while (true) {
 		int ret;
 

block/blk-core.c struct request_queue *blk_alloc_queue(gfp_t gfp_mask) · line 800

Quoted 10 lines
block/blk-core.c +8 -2
-		if (percpu_ref_tryget_live(&q->q_usage_counter))
-			return 0;
+		if (percpu_ref_tryget_live(&q->q_usage_counter)) {
+			/*
+			 * Since setting the PREEMPT_ONLY flag is followed
+			 * by a switch of q_usage_counter from per-cpu to
+			 * atomic mode and back to per-cpu and since the
+			 * switch to atomic mode uses call_rcu_sched(), it
+			 * is not necessary to call smp_rmb() here.
+			 */

rcu_read_lock is held only inside percpu_ref_tryget_live().

Without one explicit barrier(smp_mb) between getting the refcounter and reading the preempt only flag, the two operations(writing to refcounter and reading the flag) can be reordered, so unfreeze/unfreeze may be completed before this IO is completed.

Quoted 127 lines
block/blk-core.c +11 -5
+			if (preempt || !blk_queue_preempt_only(q))
+				return 0;
+			else
+				percpu_ref_put(&q->q_usage_counter);
+		}
 
 		if (nowait)
 			return -EBUSY;
@@ -797,7 +817,8 @@ int blk_queue_enter(struct request_queue *q, bool nowait)
 		smp_rmb();
 
 		ret = wait_event_interruptible(q->mq_freeze_wq,
-				!atomic_read(&q->mq_freeze_depth) ||
+				(atomic_read(&q->mq_freeze_depth) == 0 &&
+				 (preempt || !blk_queue_preempt_only(q))) ||
 				blk_queue_dying(q));
 		if (blk_queue_dying(q))
 			return -ENODEV;
@@ -1416,7 +1437,7 @@ static struct request *blk_old_get_request(struct request_queue *q,
 	create_io_context(gfp_mask, q->node);
 
 	ret = blk_queue_enter(q, !(gfp_mask & __GFP_DIRECT_RECLAIM) ||
-			      (op & REQ_NOWAIT));
+			      (op & REQ_NOWAIT), op & REQ_PREEMPT);
 	if (ret)
 		return ERR_PTR(ret);
 	spin_lock_irq(q->queue_lock);
@@ -2184,6 +2205,7 @@ blk_qc_t generic_make_request(struct bio *bio)
 	 */
 	struct bio_list bio_list_on_stack[2];
 	blk_qc_t ret = BLK_QC_T_NONE;
+	const bool nowait = bio->bi_opf & REQ_NOWAIT;
 
 	if (!generic_make_request_checks(bio))
 		goto out;
@@ -2223,7 +2245,7 @@ blk_qc_t generic_make_request(struct bio *bio)
 	do {
 		struct request_queue *q = bio->bi_disk->queue;
 
-		if (likely(blk_queue_enter(q, bio->bi_opf & REQ_NOWAIT) == 0)) {
+		if (likely(blk_queue_enter(q, nowait, false) == 0)) {
 			struct bio_list lower, same;
 
 			/* Create a fresh bio_list for all subordinate requests */
@@ -2248,8 +2270,7 @@ blk_qc_t generic_make_request(struct bio *bio)
 			bio_list_merge(&bio_list_on_stack[0], &same);
 			bio_list_merge(&bio_list_on_stack[0], &bio_list_on_stack[1]);
 		} else {
-			if (unlikely(!blk_queue_dying(q) &&
-					(bio->bi_opf & REQ_NOWAIT)))
+			if (unlikely(!blk_queue_dying(q) && nowait))
 				bio_wouldblock_error(bio);
 			else
 				bio_io_error(bio);
block/blk-mq.c +2 -2
index 10c1f49f663d..cbf7bf7e3d13 100644
@@ -384,7 +384,7 @@ struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,
 	struct request *rq;
 	int ret;
 
-	ret = blk_queue_enter(q, flags & BLK_MQ_REQ_NOWAIT);
+	ret = blk_queue_enter(q, flags & BLK_MQ_REQ_NOWAIT, op & REQ_PREEMPT);
 	if (ret)
 		return ERR_PTR(ret);
 
@@ -423,7 +423,7 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
 	if (hctx_idx >= q->nr_hw_queues)
 		return ERR_PTR(-EIO);
 
-	ret = blk_queue_enter(q, true);
+	ret = blk_queue_enter(q, true, op & REQ_PREEMPT);
 	if (ret)
 		return ERR_PTR(ret);
 
block/blk-timeout.c +1 -1
index 17ec83bb0900..0dfdc975473a 100644
@@ -134,7 +134,7 @@ void blk_timeout_work(struct work_struct *work)
 	struct request *rq, *tmp;
 	int next_set = 0;
 
-	if (blk_queue_enter(q, true))
+	if (blk_queue_enter(q, true, true))
 		return;
 	spin_lock_irqsave(q->queue_lock, flags);
 
fs/block_dev.c +2 -2
index 93d088ffc05c..e9ca45087a40 100644
@@ -674,7 +674,7 @@ int bdev_read_page(struct block_device *bdev, sector_t sector,
 	if (!ops->rw_page || bdev_get_integrity(bdev))
 		return result;
 
-	result = blk_queue_enter(bdev->bd_queue, false);
+	result = blk_queue_enter(bdev->bd_queue, false, false);
 	if (result)
 		return result;
 	result = ops->rw_page(bdev, sector + get_start_sect(bdev), page, false);
@@ -710,7 +710,7 @@ int bdev_write_page(struct block_device *bdev, sector_t sector,
 
 	if (!ops->rw_page || bdev_get_integrity(bdev))
 		return -EOPNOTSUPP;
-	result = blk_queue_enter(bdev->bd_queue, false);
+	result = blk_queue_enter(bdev->bd_queue, false, false);
 	if (result)
 		return result;
 
include/linux/blkdev.h +1 -1
index 5bd87599eed0..a025597c378a 100644
@@ -964,7 +964,7 @@ extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t,
 extern int sg_scsi_ioctl(struct request_queue *, struct gendisk *, fmode_t,
 			 struct scsi_ioctl_command __user *);
 
-extern int blk_queue_enter(struct request_queue *q, bool nowait);
+extern int blk_queue_enter(struct request_queue *q, bool nowait, bool preempt);
 extern void blk_queue_exit(struct request_queue *q);
 extern void blk_start_queue(struct request_queue *q);
 extern void blk_start_queue_async(struct request_queue *q);
Signature · 1 line
2.14.1
Signature · 1 line
Ming
#2 lore raw

Re: [PATCH v4 1/7] md: Make md resync and reshape threads freezable

In reply to Bart Van Assche
Quoted 4 lines · Bart Van Assche

Some people use the md driver on laptops and use the suspend and resume functionality. Since it is essential that submitting of new I/O requests stops before device quiescing starts, make the md resync and reshape threads freezable.

As I explained, if SCSI quiesce is safe, this patch shouldn't be needed.

The issue isn't MD specific, and in theory can be triggered on all devices. And you can see the I/O hang report on BTRFS(RAID) without MD involved:

	https://marc.info/?l=linux-block&m=150634883816965&w=2

So please remove this patch from the patchset.

--
Ming

#3 lore raw

Re: [PATCH v4 1/7] md: Make md resync and reshape threads freezable

T24gVHVlLCAyMDE3LTA5LTI2IGF0IDA3OjA0ICswODAwLCBNaW5nIExlaSB3cm90ZToNCj4gT24g TW9uLCBTZXAgMjUsIDIwMTcgYXQgMDE6Mjk6MThQTSAtMDcwMCwgQmFydCBWYW4gQXNzY2hlIHdy b3RlOg0KPiA+IFNvbWUgcGVvcGxlIHVzZSB0aGUgbWQgZHJpdmVyIG9uIGxhcHRvcHMgYW5kIHVz ZSB0aGUgc3VzcGVuZCBhbmQNCj4gPiByZXN1bWUgZnVuY3Rpb25hbGl0eS4gU2luY2UgaXQgaXMg ZXNzZW50aWFsIHRoYXQgc3VibWl0dGluZyBvZg0KPiA+IG5ldyBJL08gcmVxdWVzdHMgc3RvcHMg YmVmb3JlIGRldmljZSBxdWllc2Npbmcgc3RhcnRzLCBtYWtlIH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GhlIHByZWVtcHQgb25seSBmbGFnLCB0aGUgdHdvIG9wZXJhdGlvbnMod3JpdGluZyB0bw0K PiByZWZjb3VudGVyIGFuZCByZWFkaW5nIHRoZSBmbGFnKSBjYW4gYmUgcmVvcmRlcmVkLCBzbw0K PiB1bmZyZWV6ZS91bmZyZWV6ZSBtYXkgYmUgY29tcGxldGVkIGJlZm9yZSB0aGlzIElPIGlzIGNv bXBsZXRlZC4NCg0KU29ycnkgYnV0IEkgZGlzYWdyZWUuIEknbSB1c2luZyBSQ1UgdG8gYWNoaWV2 ZSB0aGUgc2FtZSBlZmZlY3QgYXMgYSBiYXJyaWVyDQphbmQgdG8gbW92ZSB0aGUgY29zdCBvZiB0 aGUgYmFycmllciBmcm9tIHRoZSByZWFkZXIgdG8gdGhlIHVwZGF0ZXIuIFNlZSBhbHNvDQpQYXVs IEUuIE1jS2VubmV5LCBNYXRoaWV1IERlc25veWVycywgTGFpIEppYW5nc2hhbiwgYW5kIEpvc2gg VHJpcGxldHQsDQpUaGUgUkNVLWJhcnJpZXIgbWVuYWdlcmllLCBMV04ubmV0LCBOb3ZlbWJlciAx MiwgMjAxMw0KKGh0dHBzOi8vbHduLm5ldC9BcnRpY2xlcy81NzM0OTcvKS4NCg0KQmFydC4=

#4 lore raw

Re: [PATCH v4 1/7] md: Make md resync and reshape threads freezable

In reply to Bart Van Assche
Quoted 10 lines · Bart Van Assche
Quoted 9 lines · Ming Lei
Quoted 4 lines · Bart Van Assche

Some people use the md driver on laptops and use the suspend and resume functionality. Since it is essential that submitting of new I/O requests stops before device quiescing starts, make the md resync and reshape threads freezable.

As I explained, if SCSI quiesce is safe, this patch shouldn't be needed.

Quoted 8 lines
Quoted 5 lines

The issue isn't MD specific, and in theory can be triggered on all devices. And you can see the I/O hang report on BTRFS(RAID) without MD involved:

	https://marc.info/?l=linux-block&m=150634883816965&w=2

What makes you think that this patch is not necessary once SCSI quiesce has been made safe? Does this mean that you have not tested suspend and

If we want to make SCSI quiesce safe, we have to drain up all submitted I/O and prevent new I/O from being submitted, that is enough to deal with MD's resync too.

Quoted 2 lines

resume while md RAID 1 resync was in progress? This patch is necessary to avoid that suspend locks up while md RAID 1 resync is in progress.

I tested my patchset on RAID10 when resync in progress, not see any issue during suspend/resume, without any MD's change. I will test RAID1's later, but I don't think there is difference compared with RAID10 because my patchset can make the queue being quiesced totally.

The upstream report did not mention that the resync is in progress:

	https://marc.info/?l=linux-block&m=150402198315951&w=2

I want to make the patchset(make SCSI quiesce safe) focusing on this SCSI quiesce issue.

Maybe with this MD patch, the original report becomes quite difficult to reproduce, that doesn't mean this MD patch fixes this kind of issue. What I really cares is that your changes on BLOCK/SCSI can fix this issue.

Signature · 1 line
Ming
Reviewed-by on v4 2/7
#17 lore raw

Re: [PATCH v4 2/7] block: Make q_usage_counter also track legacy requests

In reply to Bart Van Assche
Quoted 14 lines · Bart Van Assche

From: Ming Lei <[email protected]>

This patch makes it possible to pause request allocation for the legacy block layer by calling blk_mq_freeze_queue() and blk_mq_unfreeze_queue().

[ bvanassche: Combined two patches into one, edited a comment and made sure
REQ_NOWAIT is handled properly in blk_old_get_request() ]

Cc Ming Lei <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Johannes Thumshirn <[email protected]>
Quoted 5 lines
---
 block/blk-core.c | 12 ++++++++++++
 block/blk-mq.c   | 10 ++--------
 2 files changed, 14 insertions(+), 8 deletions(-)

I actually had a customer reoport hitting a q_usage_counter underflow, so this is a real bugfix. And I'd advocate to have it pushed independently on the overall patchset, if it should be delayed even further.

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
[email protected]			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
Reviewed-by on v4 1/7
#8 lore raw

Re: [PATCH v4 1/7] md: Make md resync and reshape threads freezable

In reply to Bart Van Assche
Quoted 12 lines · Bart Van Assche

Some people use the md driver on laptops and use the suspend and resume functionality. Since it is essential that submitting of new I/O requests stops before device quiescing starts, make the md resync and reshape threads freezable.

Cc Shaohua Li <[email protected]>
Cc Ming Lei <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Johannes Thumshirn <[email protected]>
Quoted 4 lines
---
 drivers/md/md.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
[email protected]			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
#5 lore raw

Re: [PATCH v4 1/7] md: Make md resync and reshape threads freezable

In reply to Ming Lei
Quoted 24 lines · Ming Lei
Quoted 10 lines · Bart Van Assche
Quoted 9 lines · Ming Lei
Quoted 4 lines · Bart Van Assche

Some people use the md driver on laptops and use the suspend and resume functionality. Since it is essential that submitting of new I/O requests stops before device quiescing starts, make the md resync and reshape threads freezable.

As I explained, if SCSI quiesce is safe, this patch shouldn't be needed.

Quoted 8 lines
Quoted 5 lines

The issue isn't MD specific, and in theory can be triggered on all devices. And you can see the I/O hang report on BTRFS(RAID) without MD involved:

	https://marc.info/?l=linux-block&m=150634883816965&w=2

What makes you think that this patch is not necessary once SCSI quiesce has been made safe? Does this mean that you have not tested suspend and

If we want to make SCSI quiesce safe, we have to drain up all submitted I/O and prevent new I/O from being submitted, that is enough to deal with MD's resync too.

Quoted 7 lines
Quoted 2 lines

resume while md RAID 1 resync was in progress? This patch is necessary to avoid that suspend locks up while md RAID 1 resync is in progress.

I tested my patchset on RAID10 when resync in progress, not see any issue during suspend/resume, without any MD's change. I will test RAID1's later, but I don't think there is difference compared with RAID10 because my patchset can make the queue being quiesced totally.

I am pretty sure that suspend/resume can survive when resync in progress with my patchset applied on RAID1, without any MD change.

There are reports on suspend/resume on btrfs(RAID) and revalidate path in scsi_transport_spi device, so the issue isn't MD specific again.

If your patchset depends on this MD change, something should be wrong in the following patches. Now I need to take a close look.

Signature · 1 line
Ming
#36 lore raw

Re: [PATCH v4 7/7] block: Make SCSI device suspend and resume work reliably

In reply to Bart Van Assche
Quoted 25 lines · Bart Van Assche
Quoted 19 lines · Ming Lei
Quoted 5 lines · Bart Van Assche
block/blk-core.c +1 -0
+int blk_queue_enter(struct request_queue *q, bool nowait, bool preempt)
 {
 	while (true) {
 		int ret;
 

block/blk-core.c struct request_queue *blk_alloc_queue(gfp_t gfp_mask) · line 800

Quoted 10 lines
block/blk-core.c +8 -2
-		if (percpu_ref_tryget_live(&q->q_usage_counter))
-			return 0;
+		if (percpu_ref_tryget_live(&q->q_usage_counter)) {
+			/*
+			 * Since setting the PREEMPT_ONLY flag is followed
+			 * by a switch of q_usage_counter from per-cpu to
+			 * atomic mode and back to per-cpu and since the
+			 * switch to atomic mode uses call_rcu_sched(), it
+			 * is not necessary to call smp_rmb() here.
+			 */

rcu_read_lock is held only inside percpu_ref_tryget_live().

Quoted 4 lines

Without one explicit barrier(smp_mb) between getting the refcounter and reading the preempt only flag, the two operations(writing to refcounter and reading the flag) can be reordered, so unfreeze/unfreeze may be completed before this IO is completed.

Quoted 5 lines

Sorry but I disagree. I'm using RCU to achieve the same effect as a barrier and to move the cost of the barrier from the reader to the updater. See also Paul E. McKenney, Mathieu Desnoyers, Lai Jiangshan, and Josh Triplett, The RCU-barrier menagerie, LWN.net, November 12, 2013
(https://lwn.net/Articles/573497/).

Let me explain it in a bit details:

1) in SCSI quiesce path:

We can think there is one synchronize_rcu() in freeze/unfreeze.

Let's see the RCU document:

Documentation/RCU/whatisRCU.txt:

void synchronize_rcu(void);

Marks the end of updater code and the beginning of reclaimer code. It does this by blocking until all pre-existing RCU read-side critical sections on all CPUs have completed. Note that synchronize_rcu() will -not- necessarily wait for any subsequent RCU read-side critical sections to complete. For example, consider the following sequence of events:

So synchronize_rcu() in SCSI quiesce path just waits for completion of pre-existing read-side critical section, and subsequent RCU read-side critical sections won't be waited.

2) in normal I/O path of blk_enter_queue()

- only rcu read lock is held in percpu_ref_tryget_live(), and the lock is released when this helper returns.

- there isn't explicit barrier(smp_mb()) between percpu_ref_tryget_live() and checking flag of preempt only, so writing to percpu_ref counter and reading the preempt flag can be reordered as the following:

-- check flag of preempt only

current process preempt out now, and just at the exact time, SCSI quiesce is run from another process, then freeze/unfreeze is completed because no pre-exit read-side critical sections, and the percpu_ref isn't held too.

finally this process is preeempt in, and try to grab one ref and submit I/O after SCSI is quiesced(which shouldn't be allowed)

-- percpu_ref_tryget_live()

Signature · 1 line
Ming
#18 lore raw

Re: [PATCH v4 2/7] block: Make q_usage_counter also track legacy requests

In reply to Bart Van Assche
Quoted 7 lines · Bart Van Assche

From: Ming Lei <[email protected]>

This patch makes it possible to pause request allocation for the legacy block layer by calling blk_mq_freeze_queue() and blk_mq_unfreeze_queue().

Quoted 8 lines

[ bvanassche: Combined two patches into one, edited a comment and made sure
REQ_NOWAIT is handled properly in blk_old_get_request() ]

Cc Ming Lei <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Johannes Thumshirn <[email protected]>

---

Thanks for considering block legacy path in this version!

Signature · 1 line
Ming
#38 lore raw
In reply to Bart Van Assche
Quoted 8 lines · Bart Van Assche

Hello Jens,

It is known that during the resume following a hibernate, especially when using an md RAID1 array created on top of SCSI devices, sometimes the system hangs instead of coming up properly. This patch series fixes this problem. This patch series is an alternative for Ming Lei's "[PATCH V5 0/10] block/scsi: safe SCSI quiescing" patch series. The advantages of this patch series are:

No, if you only address issue on MD device, that is definitely not alternative of my patchset.

Guys have verified that my patches can fix either MD and non-MD(btrfs/raid, transport_spi) case. And my patchset can fix this kind of issue on any SCSI device, w/w.o MD.

Signature · 1 line
Ming
#9 lore raw

Re: [PATCH v4 1/7] md: Make md resync and reshape threads freezable

In reply to Bart Van Assche
Quoted 100 lines · Bart Van Assche

Some people use the md driver on laptops and use the suspend and resume functionality. Since it is essential that submitting of new I/O requests stops before device quiescing starts, make the md resync and reshape threads freezable.

Cc Shaohua Li <[email protected]>
Cc Ming Lei <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Johannes Thumshirn <[email protected]>
---
 drivers/md/md.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
drivers/md/md.c +13 -8
index 08fcaebc61bd..26a12bd0db65 100644
@@ -66,6 +66,7 @@
 #include <linux/raid/md_u.h>
 #include <linux/slab.h>
 #include <linux/percpu-refcount.h>
+#include <linux/freezer.h>
 
 #include <trace/events/block.h>
 #include "md.h"
@@ -7424,6 +7425,7 @@ static int md_thread(void *arg)
 	 */
 
 	allow_signal(SIGKILL);
+	set_freezable();
 	while (!kthread_should_stop()) {
 
 		/* We need to wait INTERRUPTIBLE so that
@@ -7434,7 +7436,7 @@ static int md_thread(void *arg)
 		if (signal_pending(current))
 			flush_signals(current);
 
-		wait_event_interruptible_timeout
+		wait_event_freezable_timeout
 			(thread->wqueue,
 			 test_bit(THREAD_WAKEUP, &thread->flags)
 			 || kthread_should_stop() || kthread_should_park(),
@@ -8133,6 +8135,8 @@ void md_do_sync(struct md_thread *thread)
 		return;
 	}
 
+	set_freezable();
+
 	if (mddev_is_clustered(mddev)) {
 		ret = md_cluster_ops->resync_start(mddev);
 		if (ret)
@@ -8324,7 +8328,7 @@ void md_do_sync(struct md_thread *thread)
 		     mddev->curr_resync_completed > mddev->resync_max
 			    )) {
 			/* time to update curr_resync_completed */
-			wait_event(mddev->recovery_wait,
+			wait_event_freezable(mddev->recovery_wait,
 				   atomic_read(&mddev->recovery_active) == 0);
 			mddev->curr_resync_completed = j;
 			if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery) &&
@@ -8342,10 +8346,10 @@ void md_do_sync(struct md_thread *thread)
 			 * to avoid triggering warnings.
 			 */
 			flush_signals(current); /* just in case */
-			wait_event_interruptible(mddev->recovery_wait,
-						 mddev->resync_max > j
-						 || test_bit(MD_RECOVERY_INTR,
-							     &mddev->recovery));
+			wait_event_freezable(mddev->recovery_wait,
+					     mddev->resync_max > j ||
+					     test_bit(MD_RECOVERY_INTR,
+						      &mddev->recovery));
 		}
 
 		if (test_bit(MD_RECOVERY_INTR, &mddev->recovery))
@@ -8421,7 +8425,7 @@ void md_do_sync(struct md_thread *thread)
 				 * Give other IO more of a chance.
 				 * The faster the devices, the less we wait.
 				 */
-				wait_event(mddev->recovery_wait,
+				wait_event_freezable(mddev->recovery_wait,
 					   !atomic_read(&mddev->recovery_active));
 			}
 		}
@@ -8433,7 +8437,8 @@ void md_do_sync(struct md_thread *thread)
 	 * this also signals 'finished resyncing' to md_stop
 	 */
 	blk_finish_plug(&plug);
-	wait_event(mddev->recovery_wait, !atomic_read(&mddev->recovery_active));
+	wait_event_freezable(mddev->recovery_wait,
+			     !atomic_read(&mddev->recovery_active));
 
 	if (!test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) &&
 	    !test_bit(MD_RECOVERY_INTR, &mddev->recovery) &&
Signature · 1 line
2.14.1

Just test this patch a bit and the following failure of freezing task is triggered during suspend:

[   38.903513] PM: suspend entry (deep)
[   38.904443] PM: Syncing filesystems ... done.
[   38.983591] Freezing user space processes ... (elapsed 0.002 seconds) done.
[   38.987522] OOM killer disabled.
[   38.987962] Freezing remaining freezable tasks ...
[   58.998872] Freezing of tasks failed after 20.008 seconds (1 tasks refusing to freeze, wq_busy=0):
[   59.002539] md127_resync    D    0  1618      2 0x80000000
[   59.004954] Call Trace:
[   59.006162]  __schedule+0x41f/0xa50
[   59.007704]  schedule+0x3d/0x90
[   59.009305]  raid1_sync_request+0x2da/0xd10 [raid1]
[   59.011505]  ? remove_wait_queue+0x70/0x70
[   59.013352]  md_do_sync+0xdfa/0x12c0
[   59.014955]  ? remove_wait_queue+0x70/0x70
[   59.016336]  md_thread+0x1a8/0x1e0
[   59.016770]  ? md_thread+0x1a8/0x1e0
[   59.017250]  kthread+0x155/0x190
[   59.017662]  ? sync_speed_show+0xa0/0xa0
[   59.018217]  ? kthread_create_on_node+0x70/0x70
[   59.018858]  ret_from_fork+0x2a/0x40
[   59.019403] Restarting kernel threads ... done.
[   59.024586] OOM killer enabled.
[   59.025124] Restarting tasks ... done.
[   59.045906] PM: suspend exit
[   97.919428] systemd-journald[227]: Sent WATCHDOG=1 notification.
[  101.002695] md: md127: data-check done.
Signature · 1 line
Ming
#39 lore raw
In reply to Ming Lei

T24gVHVlLCAyMDE3LTA5LTI2IGF0IDE3OjE1ICswODAwLCBNaW5nIExlaSB3cm90ZToNCj4gTm8s IGlmIHlvdSBvbmx5IGFkZHJlc3MgaXNzdWUgb24gTUQgZGV2aWNlLCB0aGF0IGlzIGRlZmluaXRl bHkgbm90DQo+IGFsdGVybmF0aXZlIG9mIG15IHBhdGNoc2V0Lg0KDQpBIGNsYXJpZmljYXRpb246 IG15IHBhdGNoIHNlcmllcyBub3Qgb25seSBmaXhlcyBzdXNwZW5kIGFuZCByZXN1bWUgZm9yIG1k LW9uLVNDU0kNCmJ1dCBhbHNvIGZvciBhbGwgb3RoZXIgc2NlbmFyaW8ncyBpbiB3aGljaCByZXN1 bWUgbG9ja3MgdXAgZHVlIHRvIG5vIHRhZyBiZWluZw0KYXZhaWxhYmxlIHdoZW4gdGhlIFNDU0kg Y29yZSB0cmllcyB0byBleGVjdXRlIGEgcG93ZXIgbWFuYWdlbWVudCBjb21tYW5kLg0KDQpCYXJ0 Lg==

#6 lore raw

Re: [PATCH v4 1/7] md: Make md resync and reshape threads freezable

In reply to Ming Lei

T24gVHVlLCAyMDE3LTA5LTI2IGF0IDE2OjEzICswODAwLCBNaW5nIExlaSB3cm90ZToNCj4gSSBh bSBwcmV0dHkgc3VyZSB0aGF0IHN1c3BlbmQvcmVzdW1lIGNhbiBzdXJ2aXZlIHdoZW4gcmVzeW5j IGluIHByb2dyZXNzDQo+IHd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Lg==

#10 lore raw

Re: [PATCH v4 1/7] md: Make md resync and reshape threads freezable

In reply to Ming Lei

T24gVHVlLCAyMDE3LTA5LTI2IGF0IDE5OjE3ICswODAwLCBNaW5nIExlaSB3cm90ZToNCj4gSnVz dCB0ZXN0IHRoaXMgcGF0Y2ggYSBiaXQgYW5kIHRoZSBmb2xsb3dpbmcgZmFpbHVyZSBvZiBmcmVl emluZyB0YXNrDQo+IGlzIHRyaWdnZXJlZCBkdXJpbmcgc3VzcGVuZDogWyAuLi4gXQ0KDQpXaGF0 IGtlcm5lbCB2ZXJzaW9uIGRpZCB5b3Ugc3RhcnQgZnJvbSBhbmQgd2hpY2ggcGF0Y2hlcyB3ZXJl IGFwcGxpZWQgb24gdG9wIG9mDQp0aGF0IGtlcm5lbD8gT25seSBwYXRjaCAxLzcgb3IgYWxsIHNl dmVuIHBhdGNoZXM/IFdoYXQgc3RvcmFnZSBjb25maWd1cmF0aW9uIGRpZA0KeW91IHVzZSBpbiB5 b3VyIHRlc3QgYW5kIHdoYXQgY29tbWFuZChzKSBkaWQgeW91IHVzZSB0byB0cmlnZ2VyIHN1c3Bl bmQ/DQoNCkJhcnQu

#37 lore raw

Re: [PATCH v4 7/7] block: Make SCSI device suspend and resume work reliably

In reply to Ming Lei

T24gVHVlLCAyMDE3LTA5LTI2IGF0IDE2OjMyICswODAwLCBNaW5nIExlaSB3cm90ZToNCj4gT24g TW9uLCBTZXAgMjUsIDIwMTcgYXQgMTE6MTM6NDdQTSArMDAwMCwgQmFydCBWYW4gQXNzY2hlIHdy b3RlOg0KPiA+IFNvcnJ5IGJ1dCBJIGRpc2FncmVlLiBJJ20gdXNpbmcgUkNVIHRvIGFjaGlldmUg dGhlIHNhbWUgZWZmZWN0IGFzIGEgYmFycmllcg0KPiA+IGFuZCB0byBtb3ZlIHRoZSBjb3N0IG9m IHRoZSBiYXJyaWVyIGZyb20gdGhlIHJlYWRlciB0byB0aGUgdXBkYXRlci4gU2VlIGFsc28NCj4g PiBQYXVsIEUuIE1jS2VubmV5LCBNYXRoaWV1IERlc25veWVycywgTGFpIEppYW5nc2hhbiwgYW5k IEpvc2ggVHJpcGxldHQsDQo+ID4gVGhlIFJDVS1iYXJyaWVyIG1lbmFnZXJpZSwgTFdOLm5ldCwg Tm92ZW1iZXIgMTIsIDIwMTMNCj4gPiAoaHR0cHM6Ly9sd24ubmV0L0FydGljbGVzLzU3MzQ5Ny8p Lg0KPiANCj4gTGV0IG1lIGV4cGxhaW4gaXQgaW4gYSBiaXQgZGV0YWlsczogWyAuLi4gXQ0KDQpU aGUgYXBwcm9hY2ggSSB1c2VkIGluIHBhdGNoIDcvNyBpcyBpZGVudGljYWwgdG8gb25lIG9mIHRo ZSBhcHByb2FjaGVzIGV4cGxhaW5lZA0KaW4gdGhlIGFydGljbGUgSSByZWZlcnJlZCB0by4gSWYg eW91IGRvIG5vdCBhZ3JlZSB0aGF0IHRoYXQgYXBwcm9hY2ggaXMgc2FmZSB0aGF0DQptZWFucyB0 aGF0IHlvdSBkbyBub3QgbmVpdGhlciBhZ3JlZSB3aXRoIFBhdWwgTWNLZW5uZXkncyB2aWV3IG9u IGhvdyBSQ1Ugd29ya3MuDQpEbyB5b3UgcmVhbGx5IHRoaW5rIHRoYXQgeW91IGtub3cgbW9yZSBh Ym91dCBSQ1UgdGhhbiBQYXVsIE1jS2VubmV5Pw0KDQpCYXJ0Lg==

#40 lore raw
In reply to Bart Van Assche
Quoted 6 lines · Bart Van Assche
Quoted 2 lines · Ming Lei

No, if you only address issue on MD device, that is definitely not alternative of my patchset.

A clarification: my patch series not only fixes suspend and resume for md-on-SCSI but also for all other scenario's in which resume locks up due to no tag being

I do care about if this patchset can fix non-MD cases, like btrfs/raid, or transport_spi, both are real reports. Could you make sure if your patchset can cover this non-MD devices?

Quoted 1 line

available when the SCSI core tries to execute a power management command.

Firstly your cover letter title is 'Make suspend and resume safe for md-on-SCSI', that makes me a bit nervous since it is for md-on-SCSI.

Secondly if your changes on block/SCSI can work on both MD and non-MD, why is MD so special to be dealt with by the 1st MD patch? Can we remove it from this patchset? I am pretty sure that my patchset needn't any MD specific change.

Signature · 1 line
Ming
#11 lore raw

Re: [PATCH v4 1/7] md: Make md resync and reshape threads freezable

In reply to Bart Van Assche
Quoted 6 lines · Bart Van Assche
Quoted 2 lines · Ming Lei

Just test this patch a bit and the following failure of freezing task is triggered during suspend: [ ... ]

What kernel version did you start from and which patches were applied on top of that kernel? Only patch 1/7 or all seven patches? What storage configuration did

It is v4.14-rc1+, and top commit is 8d93c7a43157, with all your 7 patches applied.

Quoted 1 line

you use in your test and what command(s) did you use to trigger suspend?

Follows my pm test script:

#!/bin/sh

echo check > /sys/block/md127/md/sync_action

mkfs.ext4 -F /dev/md127

mount /dev/md0 /mnt/data

dd if=/dev/zero of=/mnt/data/d1.img bs=4k count=128k&

echo 9 > /proc/sys/kernel/printk
echo devices > /sys/power/pm_test
echo mem > /sys/power/state

wait
umount /mnt/data

Storage setting:

	sudo mdadm --create /dev/md/test /dev/sda /dev/sdb --level=1 --raid-devices=2
	both /dev/sda and /dev/sdb are virtio-scsi.
Signature · 1 line
Ming
#7 lore raw

Re: [PATCH v4 1/7] md: Make md resync and reshape threads freezable

In reply to Bart Van Assche
Quoted 7 lines · Bart Van Assche
Quoted 2 lines · Ming Lei

I am pretty sure that suspend/resume can survive when resync in progress with my patchset applied on RAID1, without any MD change.

The above shows that you do not understand how suspend and resume works. In the documents in the directory Documentation/power it is explained clearly that I/O must be stopped before the hibernation image is generation to avoid

No, I don't use hibernation, and just use suspend/resume(s2r).

Quoted 10 lines

hard to repair filesystem corruption. Although md is not a filesystem I think this also applies to md since md keeps some state information in RAM and some state information on disk. It is essential that all that state information is in consistent.

Quoted 2 lines

If your patchset depends on this MD change, something should be wrong in the following patches. Now I need to take a close look.

The later patches that make SCSI quiesce and resume safe do not depend on this change.

Are you sure?

If I remove the 1st patch, system suspend/resume will hang with all your other 6 patchset.

Signature · 1 line
Ming
#41 lore raw
In reply to Ming Lei

T24gVHV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Ckl0IGlz IGVhc3kgdG8gc2VlIHRoYXQgdGhpcyBwYXRjaCBzZXJpZXMgYWxzbyBjb3ZlcnMgU0NTSSBwYXJh bGxlbCBkb21haW4NCnZhbGlkYXRpb24uDQoNClJlZ2FyZGluZyBCVFJGUyBSQUlEOiB5b3Ugc2hv dWxkIGtub3cgdGhhdCBmaWxlc3lzdGVtcyBhcmUgcmVzcG9uc2libGUgZm9yDQppbXBsZW1lbnRp bmcgZnJlZXplIC8gdGhhdyBzdXBwb3J0IHRoZW1zZWx2ZXMuIEkgdGhpbmsgYSBmaWxlc3lzdGVt IG11c3QNCnN1cnJvdW5kIG1ldGFkYXRhIG9wZXJhdGlvbnMgYnkgc2Jfc3RhcnRfd3JpdGUoKSAv IHNiX2VuZF93cml0ZSgpIGFuZCB0aGF0DQppdCBvcHRpb25hbGx5IGNhbiBwcm92aWRlIGZyZWV6 ZV9zdXBlciAvIHRoYXdfc3VwZXIgY2FsbGJhY2tzIGluDQpzdHJ1Y3Qgc3VwZXJfb3BlcmF0aW9u cy4gSW4gdGhlIEJUUkZTIGNoYW5nZWxvZyB0aGVyZSBhcmUgc2V2ZXJhbCBmaXhlcw0Kd2l0aCBy ZWdhcmQgdG8gZnJlZXplIC8gdGhhdyBzbyBJIHRoaW5rIHRoaXMgYXNwZWN0IG9mIEJUUkZTIGhh cyBiZWVuIHRlc3RlZC4NCg0KQmFydC4=

#28 lore raw

Re: [PATCH v4 5/7] scsi: Reduce suspend latency

In reply to Bart Van Assche
Quoted 28 lines · Bart Van Assche

Avoid that it can take 200 ms too long to wait for requests to finish. Note: blk_mq_freeze_queue() uses a wait queue to wait for ongoing requests to finish.

Cc Martin K. Petersen <[email protected]>
Cc Ming Lei <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Johannes Thumshirn <[email protected]>
---
 drivers/scsi/scsi_lib.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/scsi/scsi_lib.c +1 -0
index 62f905b22821..c261498606c4 100644
@@ -2927,6 +2927,7 @@ static void scsi_wait_for_queuecommand(struct scsi_device *sdev)
 int
 scsi_device_quiesce(struct scsi_device *sdev)
 {
+	struct request_queue *q = sdev->request_queue;
 	int err;
 
 	mutex_lock(&sdev->state_mutex);
@@ -2936,11 +2937,8 @@ scsi_device_quiesce(struct scsi_device *sdev)
 	if (err)

drivers/scsi/scsi_lib.c scsi_device_quiesce(struct scsi_device *sdev) · line 2942

Quoted 10 lines
drivers/scsi/scsi_lib.c +2 -5
 		return err;
 
-	scsi_run_queue(sdev->request_queue);
-	while (atomic_read(&sdev->device_busy)) {
-		msleep_interruptible(200);
-		scsi_run_queue(sdev->request_queue);
-	}
+	blk_mq_freeze_queue(q);
+	blk_mq_unfreeze_queue(q);
 	return 0;

I see the serious issue now with this patch, and it should have been found much earlier, just because the setting quiesce isn't shown in the patch. Sorry for finding it so late.

Once the patch is applied, scsi_device_quiesce() becomes the following shape:

        mutex_lock(&sdev->state_mutex);
        err = scsi_device_set_state(sdev, SDEV_QUIESCE);
        if (err == 0)
                blk_set_preempt_only(q, true);
        mutex_unlock(&sdev->state_mutex);

        if (err)
                return err;

        blk_mq_freeze_queue(q);
        blk_mq_unfreeze_queue(q);

Any requests allocated before scsi_device_set_state() and dispatched after scsi_device_set_state() can't be drained up any more, then blk_mq_freeze_queue() will wait forever for the drain up, so not only this patchset can't fix the current quiesce issue, but also introduces new I/O hang in scsi_device_quiesce().

Now this approach looks broken fundamentally.

NAK.

Signature · 1 line
Ming
#42 lore raw
In reply to Bart Van Assche
Quoted 9 lines · Bart Van Assche
Quoted 8 lines · Ming Lei
Quoted 7 lines · Bart Van Assche
Quoted 2 lines · Ming Lei

No, if you only address issue on MD device, that is definitely not alternative of my patchset.

A clarification: my patch series not only fixes suspend and resume for md-on-SCSI but also for all other scenario's in which resume locks up due to no tag being available when the SCSI core tries to execute a power management command.>

Quoted 8 lines
Quoted 3 lines

I do care about if this patchset can fix non-MD cases, like btrfs/raid, or transport_spi, both are real reports. Could you make sure if your patchset can cover this non-MD devices?

Yes, I'm sure this patch series covers non-MD devices.

It is easy to see that this patch series also covers SCSI parallel domain validation.

Now I don't believe this patchset can do that, see my comment on your patch 5:

https://www.mail-archive.com/[email protected]/msg13624.html

More worse, your patch introduces a new I/O hang inside SCSI quiesce.

Quoted 9 lines

Regarding BTRFS RAID: you should know that filesystems are responsible for implementing freeze / thaw support themselves. I think a filesystem must surround metadata operations by sb_start_write() / sb_end_write() and that it optionally can provide freeze_super / thaw_super callbacks in struct super_operations. In the BTRFS changelog there are several fixes with regard to freeze / thaw so I think this aspect of BTRFS has been tested.

Bart.

Signature · 1 line
Ming
#12 lore raw

Re: [PATCH v4 1/7] md: Make md resync and reshape threads freezable

In reply to Ming Lei

T24gVHVlLCAyMDE3LTA5LTI2IGF0IDIyOjU5ICswODAwLCBNaW5nIExlaSB3cm90ZToNCj4gT24g VHVlLCBTZXAgMjYsIDIwMTcgYXQgMDI6NDI6MDdQTSArMDAwMCwgQmFydCBWYW4gQXNzY2hlIHdy b3RlOg0KPiA+IE9uIFR1ZSwgMjAxNy0wOS0yNiBhdCAxOToxNyArMDgwMCwgTWluZyBMZWkgd3Jv dGU6DQo+ID4gPiBKdXN0IHRlc3QgdGhpcyBwYXRjaCBhIGJpdCBhbmQgdGhlIGZvbGxvd2luZyBm YWlsdXJlIG9mIGZyZWV6aW5nIHRhc2sNCj4gPiA+IGlzIHRyaWdnZXJlZCBkdXJpbmcgc3VzcGVu ZDogWyAuLi4gXQ0KPiA+IA0KPiA+IFdoYXQga2VybmVsIHZlcnNpb24gZGlkIHlvdSBzdGFydCBm cm9tIGFuZCB3aGljaCBwYXRjaGVzIHdlcmUgYXBwbGllZCBvbiB0b3Agb2YNCj4gPiB0aGF0IGtl cm5lbD8gT25seSBwYXRjaCAxLzcgb3IgYWxsIHNldmVuIHBhdGNoZXM/IFdoYXQgc3RvcmFnZSBj b25maWd1cmF0aW9uIGRpZA0KPiANCj4gSXQgaXM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mV3IEkvTyBoYW5nIGluIHNjc2lfZGV2aWNlX3F1aWVzY2UoKS4NCg0K VGhhdCdzIGEgZ29vZCBjYXRjaCwgYnV0IGZvcnR1bmF0ZWx5IHRoaXMgaXMgdmVyeSBlYXN5IHRv IGZpeDogbW92ZSB0aGUNCmJsa19tcV9mcmVlemVfcXVldWUoKSBjYWxsIGJlZm9yZSB0aGUgbXV0 ZXhfbG9jaygpIGFuZCBzY3NpX2RldmljZV9zZXRfc3RhdGUoKQ0KY2FsbHMuIFRoZSBlcnJvciBw YXRoIHdpbGwgYWxzbyBuZWVkIHNvbWUgYWRqdXN0bWVudC4NCg0KQmFydC4=

#30 lore raw

Re: [PATCH v4 5/7] scsi: Reduce suspend latency

Quoted 19 lines · Bart Van Assche
Quoted 12 lines · Ming Lei
        mutex_lock(&sdev->state_mutex);
        err = scsi_device_set_state(sdev, SDEV_QUIESCE);
        if (err == 0)
                blk_set_preempt_only(q, true);
        mutex_unlock(&sdev->state_mutex);

        if (err)
                return err;

        blk_mq_freeze_queue(q);
        blk_mq_unfreeze_queue(q);
Quoted 5 lines

Any requests allocated before scsi_device_set_state() and dispatched after scsi_device_set_state() can't be drained up any more, then blk_mq_freeze_queue() will wait forever for the drain up, so not only this patchset can't fix the current quiesce issue, but also introduces new I/O hang in scsi_device_quiesce().

Quoted 3 lines

That's a good catch, but fortunately this is very easy to fix: move the blk_mq_freeze_queue() call before the mutex_lock() and scsi_device_set_state() calls. The error path will also need some adjustment.

I am also working towards that direction, patches have been ready.

Signature · 1 line
Ming
#13 lore raw

Re: [PATCH v4 1/7] md: Make md resync and reshape threads freezable

In reply to Bart Van Assche
Quoted 35 lines · Bart Van Assche
Quoted 34 lines · Ming Lei
Quoted 6 lines · Bart Van Assche
Quoted 2 lines · Ming Lei

Just test this patch a bit and the following failure of freezing task is triggered during suspend: [ ... ]

What kernel version did you start from and which patches were applied on top of that kernel? Only patch 1/7 or all seven patches? What storage configuration did

It is v4.14-rc1+, and top commit is 8d93c7a43157, with all your 7 patches applied.

Quoted 1 line

you use in your test and what command(s) did you use to trigger suspend?

Follows my pm test script:

#!/bin/sh

echo check > /sys/block/md127/md/sync_action

mkfs.ext4 -F /dev/md127

mount /dev/md0 /mnt/data

dd if=/dev/zero of=/mnt/data/d1.img bs=4k count=128k&

echo 9 > /proc/sys/kernel/printk
echo devices > /sys/power/pm_test
echo mem > /sys/power/state

wait
umount /mnt/data

Storage setting:

Quoted 8 lines
Quoted 2 lines
	sudo mdadm --create /dev/md/test /dev/sda /dev/sdb --level=1 --raid-devices=2
	both /dev/sda and /dev/sdb are virtio-scsi.

Thanks for the detailed reply. I have been able to reproduce the freeze failure you reported. The output of SysRq-t learned me that the md reboot notifier was waiting for the frozen md sync thread and that this caused the freeze failure. So I have started testing the patch below instead of the patch at the start of this e-mail thread:

OK, thanks for figuring out the reason.

With current linus tree, SCSI I/O is prevented from being dispatch to device during suspend by SCSI quiesce, and will be dispatched again in resume. With Safe SCSI quiesce[1], any underlying IO request will stop at blk_queue_enter() during suspend, and restart from there during resume.

For other non-SCSI driver, their .suspend/.resume often handles I/O in similar way, for example, NVMe queue will be frozen in .suspend, and unfreeze in .resume.

So could you explain a bit which kind of bug this patch fixes?

[1] https://marc.info/?l=linux-block&m=150649136519281&w=2

Signature · 1 line
Ming
#21 lore raw

Re: [PATCH v4 3/7] block: Convert RQF_PREEMPT into REQ_PREEMPT

In reply to Bart Van Assche

This looks ok to me, or at least better than the version from Ming to archive the same. I kinda hate to add more REQ_* flags than really nessecary though. Maybe instead of the mapping to REQ_* as suggested to ming blk_queue_enter should instead take the BLK_MQ_REQ_* flags and we'll add BLK_MQ_REQ_PREEMPT, and pass those to blk_get_request. If it wasn't for Linus beeing angry due to block churn I'd be very tempted to suggest that.

#22 lore raw

Re: [PATCH v4 3/7] block: Convert RQF_PREEMPT into REQ_PREEMPT

Quoted 7 lines · Christoph Hellwig

This looks ok to me, or at least better than the version from Ming to archive the same. I kinda hate to add more REQ_* flags than really nessecary though. Maybe instead of the mapping to REQ_* as suggested to ming blk_queue_enter should instead take the BLK_MQ_REQ_* flags and we'll add BLK_MQ_REQ_PREEMPT, and pass those to blk_get_request. If it wasn't for Linus beeing angry due to block churn I'd be very tempted to suggest that.

Actually, based on the next patch in the series from Ming we could add a blk_get_request_flags() or similar that takes the BLK_MQ_REQ_* flags, which would be my preferred method.

#24 lore raw

Re: [PATCH v4 4/7] block: Add the QUEUE_FLAG_PREEMPT_ONLY request queue flag

In reply to Bart Van Assche

block/blk-core.c void blk_sync_queue(struct request_queue *q) · line 360

Quoted 12 lines
block/blk-core.c +12 -0
+void blk_set_preempt_only(struct request_queue *q, bool preempt_only)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(q->queue_lock, flags);
+	if (preempt_only)
+		queue_flag_set(QUEUE_FLAG_PREEMPT_ONLY, q);
+	else
+		queue_flag_clear(QUEUE_FLAG_PREEMPT_ONLY, q);
+	spin_unlock_irqrestore(q->queue_lock, flags);
+}
+EXPORT_SYMBOL(blk_set_preempt_only);

Why do we even need this helper? The lock doesn't make sense to me, and it would just much easier to set/clear the flag from the driver.

Reviewed-by on v4 6/7
#32 lore raw

Re: [PATCH v4 6/7] scsi: Set QUEUE_FLAG_PREEMPT_ONLY while quiesced

In reply to Bart Van Assche
Quoted 2 lines · Bart Van Assche

Make the quiesce state visible to the block layer for the next patch in this series.

This looks like the more correct version as everything is under state_mutex.

Except for the fact that I'd like to get rid of the blk_set_preempt_only helper this looks good:

#14 lore raw

Re: [PATCH v4 1/7] md: Make md resync and reshape threads freezable

In reply to Ming Lei

T24gV2VkLCAyMDE3LTA5LTI3IGF0IDE5OjAwICswODAwLCBNaW5nIExlaSB3cm90ZToNCj4gV2l0 aCBjdXJyZW50IGxpbnVzIHRyZWUsIFNDU0kgSS9PIGlzIHByZXZlbnRlZCBmcm9tIGJlaW5nIGRp c3BhdGNoIHRvDQo+IGRldmljZSBkdXJpbmcgc3VzcGVuZCBieSBTQ1NJIHF1aWVzY2UsIGFuZCB3 aWx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8NCnNldCBhbmQgY2xlYXIgZmxhZ3Mg aXQgaXMgZXNzZW50aWFsIHRvIHByb3RlY3QgY2FsbHMgb2YgdGhlc2UgZnVuY3Rpb25zIHdpdGgN CnRoZSBxdWV1ZSBsb2NrLiBPdGhlcndpc2UgZmxhZyB1cGRhdGVzIGNvdWxkIGdldCBsb3N0IGR1 ZSB0byBjb25jdXJyZW50DQpxdWV1ZV9mbGFnX3NldCgpIG9yIHF1ZXVlX2ZsYWdfY2xlYXIoKSBj YWxscy4NCg0KT25lIG9mIHRoZSByZWFzb25zIHdoeSBJIGludHJvZHVjZWQgdGhpcyBoZWxwZXIg ZnVuY3Rpb24gaXMgdG8ga2VlcCB0aGUNCndha2VfdXBfYWxsKCZxLT5tcV9mcmVlemVfd3EpIGNh bGwgdGhhdCBpcyBhZGRlZCB0byB0aGlzIGZ1bmN0aW9uIGJ5IGEgbGF0ZXINCnBhdGNoIGluIHRo ZSBibG9jayBsYXllci4NCg0KQmFydC4=

#26 lore raw

Re: [PATCH v4 4/7] block: Add the QUEUE_FLAG_PREEMPT_ONLY request queue flag

Quoted 8 lines · Bart Van Assche

Since queue_flag_set() and queue_flag_clear() use non-atomic primitives to set and clear flags it is essential to protect calls of these functions with the queue lock. Otherwise flag updates could get lost due to concurrent queue_flag_set() or queue_flag_clear() calls.

One of the reasons why I introduced this helper function is to keep the wake_up_all(&q->mq_freeze_wq) call that is added to this function by a later patch in the block layer.

Oh, despite the _unlocked versions existing it doesn't do any atomic ops. Yeah, we'll need the queue lock then.

But please split it into one helper for setting the queue blocked and to clear it, especially if the clear needs to do an additional wake_up.