* [PULL 0/1] nvme queue
@ 2024-11-08 8:16 Klaus Jensen
2024-11-08 8:16 ` [PULL 1/1] hw/nvme: fix handling of over-committed queues Klaus Jensen
2024-11-08 14:46 ` [PULL 0/1] nvme queue Peter Maydell
0 siblings, 2 replies; 5+ messages in thread
From: Klaus Jensen @ 2024-11-08 8:16 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Klaus Jensen
From: Klaus Jensen <k.jensen@samsung.com>
Hi,
The following changes since commit feef1866d1366d651e6a3cb8c9cf1a9aabb81395:
Merge tag 'pull-riscv-to-apply-20241107' of https://github.com/alistair23/qemu into staging (2024-11-07 15:08:05 +0000)
are available in the Git repository at:
https://gitlab.com/birkelund/qemu.git tags/pull-nvme-20241108
for you to fetch changes up to 9529aa6bb4d18763f5b4704cb4198bd25cbbee31:
hw/nvme: fix handling of over-committed queues (2024-11-08 09:14:30 +0100)
----------------------------------------------------------------
nvme queue
----------------------------------------------------------------
Klaus Jensen (1):
hw/nvme: fix handling of over-committed queues
hw/nvme/ctrl.c | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PULL 1/1] hw/nvme: fix handling of over-committed queues
2024-11-08 8:16 [PULL 0/1] nvme queue Klaus Jensen
@ 2024-11-08 8:16 ` Klaus Jensen
2024-11-08 14:46 ` [PULL 0/1] nvme queue Peter Maydell
1 sibling, 0 replies; 5+ messages in thread
From: Klaus Jensen @ 2024-11-08 8:16 UTC (permalink / raw)
To: qemu-devel
Cc: Peter Maydell, Klaus Jensen, qemu-stable, Waldemar Kozaczuk,
Keith Busch, Klaus Jensen, Jesper Devantier, qemu-block
From: Klaus Jensen <k.jensen@samsung.com>
If a host chooses to use the SQHD "hint" in the CQE to know if there is
room in the submission queue for additional commands, it may result in a
situation where there are not enough internal resources (struct
NvmeRequest) available to process the command. For a lack of a better
term, the host may "over-commit" the device (i.e., it may have more
inflight commands than the queue size).
For example, assume a queue with N entries. The host submits N commands
and all are picked up for processing, advancing the head and emptying
the queue. Regardless of which of these N commands complete first, the
SQHD field of that CQE will indicate to the host that the queue is
empty, which allows the host to issue N commands again. However, if the
device has not posted CQEs for all the previous commands yet, the device
will have less than N resources available to process the commands, so
queue processing is suspended.
And here lies an 11 year latent bug. In the absense of any additional
tail updates on the submission queue, we never schedule the processing
bottom-half again unless we observe a head update on an associated full
completion queue. This has been sufficient to handle N-to-1 SQ/CQ setups
(in the absense of over-commit of course). Incidentially, that "kick all
associated SQs" mechanism can now be killed since we now just schedule
queue processing when we return a processing resource to a non-empty
submission queue, which happens to cover both edge cases. However, we
must retain kicking the CQ if it was previously full.
So, apparently, no previous driver tested with hw/nvme has ever used
SQHD (e.g., neither the Linux NVMe driver or SPDK uses it). But then OSv
shows up with the driver that actually does. I salute you.
Fixes: f3c507adcd7b ("NVMe: Initial commit for new storage interface")
Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2388
Reported-by: Waldemar Kozaczuk <jwkozaczuk@gmail.com>
Reviewed-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
hw/nvme/ctrl.c | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 8e4612e03567..69bce20f6692 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -1520,9 +1520,16 @@ static void nvme_post_cqes(void *opaque)
stl_le_p(&n->bar.csts, NVME_CSTS_FAILED);
break;
}
+
QTAILQ_REMOVE(&cq->req_list, req, entry);
+
nvme_inc_cq_tail(cq);
nvme_sg_unmap(&req->sg);
+
+ if (QTAILQ_EMPTY(&sq->req_list) && !nvme_sq_empty(sq)) {
+ qemu_bh_schedule(sq->bh);
+ }
+
QTAILQ_INSERT_TAIL(&sq->req_list, req, entry);
}
if (cq->tail != cq->head) {
@@ -7981,7 +7988,6 @@ static void nvme_process_db(NvmeCtrl *n, hwaddr addr, int val)
/* Completion queue doorbell write */
uint16_t new_head = val & 0xffff;
- int start_sqs;
NvmeCQueue *cq;
qid = (addr - (0x1000 + (1 << 2))) >> 3;
@@ -8032,19 +8038,16 @@ static void nvme_process_db(NvmeCtrl *n, hwaddr addr, int val)
trace_pci_nvme_mmio_doorbell_cq(cq->cqid, new_head);
- start_sqs = nvme_cq_full(cq) ? 1 : 0;
- cq->head = new_head;
- if (!qid && n->dbbuf_enabled) {
- stl_le_pci_dma(pci, cq->db_addr, cq->head, MEMTXATTRS_UNSPECIFIED);
- }
- if (start_sqs) {
- NvmeSQueue *sq;
- QTAILQ_FOREACH(sq, &cq->sq_list, entry) {
- qemu_bh_schedule(sq->bh);
- }
+ /* scheduled deferred cqe posting if queue was previously full */
+ if (nvme_cq_full(cq)) {
qemu_bh_schedule(cq->bh);
}
+ cq->head = new_head;
+ if (!qid && n->dbbuf_enabled) {
+ stl_le_pci_dma(pci, cq->db_addr, cq->head, MEMTXATTRS_UNSPECIFIED);
+ }
+
if (cq->tail == cq->head) {
if (cq->irq_enabled) {
n->cq_pending--;
--
2.45.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PULL 0/1] nvme queue
2024-11-08 8:16 [PULL 0/1] nvme queue Klaus Jensen
2024-11-08 8:16 ` [PULL 1/1] hw/nvme: fix handling of over-committed queues Klaus Jensen
@ 2024-11-08 14:46 ` Peter Maydell
1 sibling, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2024-11-08 14:46 UTC (permalink / raw)
To: Klaus Jensen; +Cc: qemu-devel, Klaus Jensen
On Fri, 8 Nov 2024 at 08:16, Klaus Jensen <its@irrelevant.dk> wrote:
>
> From: Klaus Jensen <k.jensen@samsung.com>
>
> Hi,
>
> The following changes since commit feef1866d1366d651e6a3cb8c9cf1a9aabb81395:
>
> Merge tag 'pull-riscv-to-apply-20241107' of https://github.com/alistair23/qemu into staging (2024-11-07 15:08:05 +0000)
>
> are available in the Git repository at:
>
> https://gitlab.com/birkelund/qemu.git tags/pull-nvme-20241108
>
> for you to fetch changes up to 9529aa6bb4d18763f5b4704cb4198bd25cbbee31:
>
> hw/nvme: fix handling of over-committed queues (2024-11-08 09:14:30 +0100)
>
> ----------------------------------------------------------------
> nvme queue
>
> ----------------------------------------------------------------
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/9.2
for any user-visible changes.
-- PMM
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PULL 0/1] nvme queue
@ 2025-05-15 12:01 Klaus Jensen
2025-05-15 21:53 ` Stefan Hajnoczi
0 siblings, 1 reply; 5+ messages in thread
From: Klaus Jensen @ 2025-05-15 12:01 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Klaus Jensen
From: Klaus Jensen <k.jensen@samsung.com>
Hi,
The following changes since commit 864813878951b44e964eb4c012d832fd21f8cc0c:
Merge tag 'pull-loongarch-20250514' of https://github.com/gaosong715/qemu into staging (2025-05-14 07:16:57 -0400)
are available in the Git repository at:
https://gitlab.com/birkelund/qemu.git tags/pull-nvme-20250515
for you to fetch changes up to 0b1c23a582f7bc721a9b858c289a8d165152a6a0:
hw/nvme: fix nvme hotplugging (2025-05-15 12:18:06 +0200)
----------------------------------------------------------------
nvme queue
* fix nvme hotplugging
----------------------------------------------------------------
Klaus Jensen (1):
hw/nvme: fix nvme hotplugging
hw/nvme/subsys.c | 1 -
1 file changed, 1 deletion(-)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PULL 0/1] nvme queue
2025-05-15 12:01 Klaus Jensen
@ 2025-05-15 21:53 ` Stefan Hajnoczi
0 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2025-05-15 21:53 UTC (permalink / raw)
To: Klaus Jensen; +Cc: qemu-devel, Peter Maydell, Klaus Jensen
[-- Attachment #1: Type: text/plain, Size: 116 bytes --]
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/10.1 for any user-visible changes.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-05-17 22:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-08 8:16 [PULL 0/1] nvme queue Klaus Jensen
2024-11-08 8:16 ` [PULL 1/1] hw/nvme: fix handling of over-committed queues Klaus Jensen
2024-11-08 14:46 ` [PULL 0/1] nvme queue Peter Maydell
-- strict thread matches above, loose matches on Subject: below --
2025-05-15 12:01 Klaus Jensen
2025-05-15 21:53 ` Stefan Hajnoczi
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).