Skip to contentSkip to conversation

nvme: Fix get/set number of queues feature, again

PATCH Applied Dan Aloni 4 participants 4 messages May 28, 2017 – Aug 22, 2017

lore
Share & tools
lore

Dan Aloni

author
#0 lore raw

PATCH 1/1 nvme: Fix get/set number of queues feature, again

The number of queues that should be return by the admin command should:

1) Only mention the number of non-admin queues.
2) It is zero-based, meaning that '0 == one non-admin queue',

     '1 == two non-admin queues', and so forth.

Because our num_queues means the number of queues _plus_ the admin queue, then the right calculation for the number returned from the admin command is num_queues - 2, combining the two requirements mentioned.

The issue was discovered by reducing num_queues from 64 to 8 and running a Linux VM with an SMP parameter larger than that (e.g. 22). It tries to utilize all queues, and therefore fails with an invalid queue number when trying to queue I/Os on the last queue.

CC Alex Friedman <[email protected]>
CC Keith Busch <[email protected]>
CC Stefan Hajnoczi <[email protected]>
---
 hw/block/nvme.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/block/nvme.c +2 -2
index 7428db9f0c91..08ddf3a39e2f 100644
@@ -573,7 +573,7 @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)
         result = blk_enable_write_cache(n->conf.blk);
         break;
     case NVME_NUMBER_OF_QUEUES:
-        result = cpu_to_le32((n->num_queues - 1) | ((n->num_queues - 1) << 16));
+        result = cpu_to_le32((n->num_queues - 2) | ((n->num_queues - 2) << 16));
         break;
     default:
         return NVME_INVALID_FIELD | NVME_DNR;
@@ -594,7 +594,7 @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)
         break;
     case NVME_NUMBER_OF_QUEUES:
         req->cqe.result =
-            cpu_to_le32((n->num_queues - 1) | ((n->num_queues - 1) << 16));
+            cpu_to_le32((n->num_queues - 2) | ((n->num_queues - 2) << 16));
         break;
     default:
         return NVME_INVALID_FIELD | NVME_DNR;
Signature · 1 line
2.9.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Dan Aloni

The number of queues that should be return by the admin command should:

1) Only mention the number of non-admin queues.
2) It is zero-based, meaning that '0 == one non-admin queue',

     '1 == two non-admin queues', and so forth.

Because our num_queues means the number of queues _plus_ the admin queue, then the right calculation for the number returned from the admin command is num_queues - 2, combining the two requirements mentioned.

The issue was discovered by reducing num_queues from 64 to 8 and running a Linux VM with an SMP parameter larger than that (e.g. 22). It tries to utilize all queues, and therefore fails with an invalid queue number when trying to queue I/Os on the last queue.

Quoted 4 lines
CC Alex Friedman <[email protected]>
CC Keith Busch <[email protected]>
CC Stefan Hajnoczi <[email protected]>

Looks good, thanks for the fix.

#3 lore raw
In reply to Dan Aloni
Quoted 15 lines · Dan Aloni

The number of queues that should be return by the admin command should:

1) Only mention the number of non-admin queues.
2) It is zero-based, meaning that '0 == one non-admin queue',

     '1 == two non-admin queues', and so forth.

Because our num_queues means the number of queues _plus_ the admin queue, then the right calculation for the number returned from the admin command is num_queues - 2, combining the two requirements mentioned.

The issue was discovered by reducing num_queues from 64 to 8 and running a Linux VM with an SMP parameter larger than that (e.g. 22). It tries to utilize all queues, and therefore fails with an invalid queue number when trying to queue I/Os on the last queue.

Quoted 7 lines
CC Alex Friedman <[email protected]>
CC Keith Busch <[email protected]>
CC Stefan Hajnoczi <[email protected]>
---
 hw/block/nvme.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Sorry for the delay. Please send future nvme.c patches through Kevin Wolf:

$ scripts/get_maintainer.pl -f hw/block/nvme.c
Keith Busch <[email protected]> (supporter:nvme)
Kevin Wolf <[email protected]> (supporter:Block layer core)
Max Reitz <[email protected]> (supporter:Block layer core)
[email protected] (open list:nvme)
[email protected] (open list:All patches CC here)

This patch will be in QEMU 2.11.

Thanks, applied to my block-next tree:
https://github.com/stefanha/qemu/commits/block-next

Stefan