From: Yi Sun <yi.sun@unisoc.com>
To: <axboe@kernel.dk>, <mst@redhat.com>, <jasowang@redhat.com>
Cc: <xuanzhuo@linux.alibaba.com>, <pbonzini@redhat.com>,
<stefanha@redhat.com>, <virtualization@lists.linux.dev>,
<linux-block@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<yi.sun@unisoc.com>, <zhiguo.niu@unisoc.com>,
<hongyu.jin@unisoc.com>, <sunyibuaa@gmail.com>
Subject: [PATCH 1/2] blk-mq: introduce blk_mq_tagset_wait_request_completed()
Date: Mon, 22 Jan 2024 19:07:21 +0800 [thread overview]
Message-ID: <20240122110722.690223-2-yi.sun@unisoc.com> (raw)
In-Reply-To: <20240122110722.690223-1-yi.sun@unisoc.com>
In some cases, it is necessary to wait for all requests to become complete
status before performing other operations. Otherwise, these requests will never
be processed successfully.
For example, when the virtio device is in hibernation, the virtqueues
will be deleted. It must be ensured that virtqueue is not in use before being deleted.
Otherwise the requests in the virtqueue will be lost. This function can ensure
that all requests have been taken out of the virtqueues.
Prepare for fixing this kind of issue by introducing
blk_mq_tagset_wait_request_completed().
Signed-off-by: Yi Sun <yi.sun@unisoc.com>
---
block/blk-mq-tag.c | 29 +++++++++++++++++++++++++++++
include/linux/blk-mq.h | 1 +
2 files changed, 30 insertions(+)
diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c
index cc57e2dd9a0b..cb0ef5f66c61 100644
--- a/block/blk-mq-tag.c
+++ b/block/blk-mq-tag.c
@@ -479,6 +479,35 @@ void blk_mq_tagset_wait_completed_request(struct blk_mq_tag_set *tagset)
}
EXPORT_SYMBOL(blk_mq_tagset_wait_completed_request);
+static bool blk_mq_tagset_count_inflight_rqs(struct request *rq, void *data)
+{
+ unsigned int *count = data;
+
+ if (blk_mq_request_started(rq) && !blk_mq_request_completed(rq))
+ (*count)++;
+ return true;
+}
+
+/**
+ * blk_mq_tagset_wait_request_completed - Wait for all inflight requests
+ * to become completed.
+ *
+ * Note: This function has to be run after all IO queues are shutdown.
+ */
+void blk_mq_tagset_wait_request_completed(struct blk_mq_tag_set *tagset)
+{
+ while (true) {
+ unsigned int count = 0;
+
+ blk_mq_tagset_busy_iter(tagset,
+ blk_mq_tagset_count_inflight_rqs, &count);
+ if (!count)
+ break;
+ msleep(20);
+ }
+}
+EXPORT_SYMBOL(blk_mq_tagset_wait_request_completed);
+
/**
* blk_mq_queue_tag_busy_iter - iterate over all requests with a driver tag
* @q: Request queue to examine.
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index a676e116085f..17768e154193 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -891,6 +891,7 @@ void blk_mq_run_hw_queues(struct request_queue *q, bool async);
void blk_mq_delay_run_hw_queues(struct request_queue *q, unsigned long msecs);
void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
busy_tag_iter_fn *fn, void *priv);
+void blk_mq_tagset_wait_request_completed(struct blk_mq_tag_set *tagset);
void blk_mq_tagset_wait_completed_request(struct blk_mq_tag_set *tagset);
void blk_mq_freeze_queue(struct request_queue *q);
void blk_mq_unfreeze_queue(struct request_queue *q);
--
2.25.1
next prev parent reply other threads:[~2024-01-22 11:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-22 11:07 [PATCH 0/2] Fix requests loss during virtio-blk device suspend Yi Sun
2024-01-22 11:07 ` Yi Sun [this message]
2024-01-23 18:45 ` [PATCH 1/2] blk-mq: introduce blk_mq_tagset_wait_request_completed() kernel test robot
2024-01-23 19:14 ` Keith Busch
2024-01-24 11:22 ` yi sun
2024-01-24 17:17 ` Keith Busch
2024-01-22 11:07 ` [PATCH 2/2] virtio-blk: Ensure no requests in virtqueues before deleting vqs Yi Sun
2024-01-22 15:42 ` Stefan Hajnoczi
2024-01-23 3:27 ` yi sun
2024-01-23 15:09 ` Stefan Hajnoczi
2024-01-24 7:38 ` yi sun
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=20240122110722.690223-2-yi.sun@unisoc.com \
--to=yi.sun@unisoc.com \
--cc=axboe@kernel.dk \
--cc=hongyu.jin@unisoc.com \
--cc=jasowang@redhat.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=stefanha@redhat.com \
--cc=sunyibuaa@gmail.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.com \
--cc=zhiguo.niu@unisoc.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).