|
|
2bc292 |
From 6989be9d0aa08470f8b287c243dc4bf027d5fbcf Mon Sep 17 00:00:00 2001
|
|
|
2bc292 |
From: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
2bc292 |
Date: Wed, 8 Dec 2021 15:22:46 +0000
|
|
|
2bc292 |
Subject: [PATCH 1/2] block/nvme: fix infinite loop in nvme_free_req_queue_cb()
|
|
|
2bc292 |
MIME-Version: 1.0
|
|
|
2bc292 |
Content-Type: text/plain; charset=UTF-8
|
|
|
2bc292 |
Content-Transfer-Encoding: 8bit
|
|
|
2bc292 |
|
|
|
2bc292 |
RH-Author: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
2bc292 |
RH-MergeRequest: 58: block/nvme: fix infinite loop in nvme_free_req_queue_cb()
|
|
|
2bc292 |
RH-Commit: [1/1] 544b3f310d791a20c63b51947de0c6cbb60b0d5b (stefanha/centos-stream-qemu-kvm)
|
|
|
2bc292 |
RH-Bugzilla: 2024544
|
|
|
2bc292 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
2bc292 |
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
|
|
|
2bc292 |
RH-Acked-by: Hanna Reitz <hreitz@redhat.com>
|
|
|
2bc292 |
|
|
|
2bc292 |
When the request free list is exhausted the coroutine waits on
|
|
|
2bc292 |
q->free_req_queue for the next free request. Whenever a request is
|
|
|
2bc292 |
completed a BH is scheduled to invoke nvme_free_req_queue_cb() and wake
|
|
|
2bc292 |
up waiting coroutines.
|
|
|
2bc292 |
|
|
|
2bc292 |
1. nvme_get_free_req() waits for a free request:
|
|
|
2bc292 |
|
|
|
2bc292 |
while (q->free_req_head == -1) {
|
|
|
2bc292 |
...
|
|
|
2bc292 |
trace_nvme_free_req_queue_wait(q->s, q->index);
|
|
|
2bc292 |
qemu_co_queue_wait(&q->free_req_queue, &q->lock);
|
|
|
2bc292 |
...
|
|
|
2bc292 |
}
|
|
|
2bc292 |
|
|
|
2bc292 |
2. nvme_free_req_queue_cb() wakes up the coroutine:
|
|
|
2bc292 |
|
|
|
2bc292 |
while (qemu_co_enter_next(&q->free_req_queue, &q->lock)) {
|
|
|
2bc292 |
^--- infinite loop when free_req_head == -1
|
|
|
2bc292 |
}
|
|
|
2bc292 |
|
|
|
2bc292 |
nvme_free_req_queue_cb() and the coroutine form an infinite loop when
|
|
|
2bc292 |
q->free_req_head == -1. Fix this by checking q->free_req_head in
|
|
|
2bc292 |
nvme_free_req_queue_cb(). If the free request list is exhausted, don't
|
|
|
2bc292 |
wake waiting coroutines. Eventually an in-flight request will complete
|
|
|
2bc292 |
and the BH will be scheduled again, guaranteeing forward progress.
|
|
|
2bc292 |
|
|
|
2bc292 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
2bc292 |
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
|
|
|
2bc292 |
Message-id: 20211208152246.244585-1-stefanha@redhat.com
|
|
|
2bc292 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
2bc292 |
(cherry picked from commit cf4fbc3030c974fff726756a7ceef8386cdf500b)
|
|
|
2bc292 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
2bc292 |
---
|
|
|
2bc292 |
block/nvme.c | 5 +++--
|
|
|
2bc292 |
1 file changed, 3 insertions(+), 2 deletions(-)
|
|
|
2bc292 |
|
|
|
2bc292 |
diff --git a/block/nvme.c b/block/nvme.c
|
|
|
2bc292 |
index e4f336d79c..fa360b9b3c 100644
|
|
|
2bc292 |
--- a/block/nvme.c
|
|
|
2bc292 |
+++ b/block/nvme.c
|
|
|
2bc292 |
@@ -206,8 +206,9 @@ static void nvme_free_req_queue_cb(void *opaque)
|
|
|
2bc292 |
NVMeQueuePair *q = opaque;
|
|
|
2bc292 |
|
|
|
2bc292 |
qemu_mutex_lock(&q->lock);
|
|
|
2bc292 |
- while (qemu_co_enter_next(&q->free_req_queue, &q->lock)) {
|
|
|
2bc292 |
- /* Retry all pending requests */
|
|
|
2bc292 |
+ while (q->free_req_head != -1 &&
|
|
|
2bc292 |
+ qemu_co_enter_next(&q->free_req_queue, &q->lock)) {
|
|
|
2bc292 |
+ /* Retry waiting requests */
|
|
|
2bc292 |
}
|
|
|
2bc292 |
qemu_mutex_unlock(&q->lock);
|
|
|
2bc292 |
}
|
|
|
2bc292 |
--
|
|
|
2bc292 |
2.27.0
|
|
|
2bc292 |
|