* [PATCH 00/15] block/nvme: Improve debugging experience and minor fixes
@ 2020-10-14 15:57 Philippe Mathieu-Daudé
2020-10-14 15:57 ` [PATCH 01/15] block/nvme: Move nvme_poll_cb() earlier Philippe Mathieu-Daudé
` (14 more replies)
0 siblings, 15 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-14 15:57 UTC (permalink / raw)
To: qemu-devel
Cc: Fam Zheng, Kevin Wolf, qemu-block, Max Reitz, Stefan Hajnoczi,
Philippe Mathieu-Daudé
Another set of boring patches, in preparation of
supporting multiple queues (the next series).
Based-on: <20201014115253.25276-1-philmd@redhat.com>
"util/vfio-helpers: Improve debugging experience"
https://www.mail-archive.com/qemu-block@nongnu.org/msg75637.html
Philippe Mathieu-Daudé (15):
block/nvme: Move nvme_poll_cb() earlier
block/nvme: Trace nvme_poll_queue() per queue
block/nvme: Use unsigned integer for queue counter/size
block/nvme: Improve nvme_free_req_queue_wait() trace information
block/nvme: Trace queue pair creation/deletion
block/nvme: Make nvme_identify() return boolean indicating error
block/nvme: Make nvme_init_queue() return boolean indicating error
block/nvme: Pass AioContext argument to nvme_add_io_queue()
block/nvme: Introduce Completion Queue definitions
block/nvme: Use definitions instead of magic values in add_io_queue()
block/nvme: Trace controller capabilities
block/nvme: Simplify device reset
block/nvme: Simplify ADMIN queue access
block/nvme: Report warning with warn_report()
block/nvme: Set request_alignment at initialization
include/block/nvme.h | 17 ++++---
block/nvme.c | 116 +++++++++++++++++++++++++------------------
block/trace-events | 17 ++++---
3 files changed, 88 insertions(+), 62 deletions(-)
--
2.26.2
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 01/15] block/nvme: Move nvme_poll_cb() earlier
2020-10-14 15:57 [PATCH 00/15] block/nvme: Improve debugging experience and minor fixes Philippe Mathieu-Daudé
@ 2020-10-14 15:57 ` Philippe Mathieu-Daudé
2020-10-14 15:57 ` [PATCH 02/15] block/nvme: Trace nvme_poll_queue() per queue Philippe Mathieu-Daudé
` (13 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-14 15:57 UTC (permalink / raw)
To: qemu-devel
Cc: Fam Zheng, Kevin Wolf, qemu-block, Max Reitz, Stefan Hajnoczi,
Philippe Mathieu-Daudé
We are going to use this callback in nvme_add_io_queue()
in few commits. To avoid forward-declaring it, move it
before. No logical change.
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
block/nvme.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/block/nvme.c b/block/nvme.c
index 5f662c55bbe..a534c61b6b6 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -627,6 +627,16 @@ static void nvme_handle_event(EventNotifier *n)
nvme_poll_queues(s);
}
+static bool nvme_poll_cb(void *opaque)
+{
+ EventNotifier *e = opaque;
+ BDRVNVMeState *s = container_of(e, BDRVNVMeState,
+ irq_notifier[MSIX_SHARED_IRQ_IDX]);
+
+ trace_nvme_poll_cb(s);
+ return nvme_poll_queues(s);
+}
+
static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp)
{
BDRVNVMeState *s = bs->opaque;
@@ -669,16 +679,6 @@ out_error:
return false;
}
-static bool nvme_poll_cb(void *opaque)
-{
- EventNotifier *e = opaque;
- BDRVNVMeState *s = container_of(e, BDRVNVMeState,
- irq_notifier[MSIX_SHARED_IRQ_IDX]);
-
- trace_nvme_poll_cb(s);
- return nvme_poll_queues(s);
-}
-
static int nvme_init(BlockDriverState *bs, const char *device, int namespace,
Error **errp)
{
--
2.26.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 02/15] block/nvme: Trace nvme_poll_queue() per queue
2020-10-14 15:57 [PATCH 00/15] block/nvme: Improve debugging experience and minor fixes Philippe Mathieu-Daudé
2020-10-14 15:57 ` [PATCH 01/15] block/nvme: Move nvme_poll_cb() earlier Philippe Mathieu-Daudé
@ 2020-10-14 15:57 ` Philippe Mathieu-Daudé
2020-10-14 15:57 ` [PATCH 03/15] block/nvme: Use unsigned integer for queue counter/size Philippe Mathieu-Daudé
` (12 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-14 15:57 UTC (permalink / raw)
To: qemu-devel
Cc: Fam Zheng, Kevin Wolf, qemu-block, Max Reitz, Stefan Hajnoczi,
Philippe Mathieu-Daudé
As we want to enable multiple queues, report the event
in each nvme_poll_queue() call, rather than once in
the callback calling nvme_poll_queues().
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
block/nvme.c | 2 +-
block/trace-events | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/nvme.c b/block/nvme.c
index a534c61b6b6..7c253eafa7f 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -585,6 +585,7 @@ static bool nvme_poll_queue(NVMeQueuePair *q)
const size_t cqe_offset = q->cq.head * NVME_CQ_ENTRY_BYTES;
NvmeCqe *cqe = (NvmeCqe *)&q->cq.queue[cqe_offset];
+ trace_nvme_poll_queue(q->s, q->index);
/*
* Do an early check for completions. q->lock isn't needed because
* nvme_process_completion() only runs in the event loop thread and
@@ -633,7 +634,6 @@ static bool nvme_poll_cb(void *opaque)
BDRVNVMeState *s = container_of(e, BDRVNVMeState,
irq_notifier[MSIX_SHARED_IRQ_IDX]);
- trace_nvme_poll_cb(s);
return nvme_poll_queues(s);
}
diff --git a/block/trace-events b/block/trace-events
index 0e351c3fa3d..fa50af6b6f3 100644
--- a/block/trace-events
+++ b/block/trace-events
@@ -143,7 +143,7 @@ nvme_complete_command(void *s, int index, int cid) "s %p queue %d cid %d"
nvme_submit_command(void *s, int index, int cid) "s %p queue %d cid %d"
nvme_submit_command_raw(int c0, int c1, int c2, int c3, int c4, int c5, int c6, int c7) "%02x %02x %02x %02x %02x %02x %02x %02x"
nvme_handle_event(void *s) "s %p"
-nvme_poll_cb(void *s) "s %p"
+nvme_poll_queue(void *s, unsigned q_index) "s %p q #%u"
nvme_prw_aligned(void *s, int is_write, uint64_t offset, uint64_t bytes, int flags, int niov) "s %p is_write %d offset %"PRId64" bytes %"PRId64" flags %d niov %d"
nvme_write_zeroes(void *s, uint64_t offset, uint64_t bytes, int flags) "s %p offset %"PRId64" bytes %"PRId64" flags %d"
nvme_qiov_unaligned(const void *qiov, int n, void *base, size_t size, int align) "qiov %p n %d base %p size 0x%zx align 0x%x"
--
2.26.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 03/15] block/nvme: Use unsigned integer for queue counter/size
2020-10-14 15:57 [PATCH 00/15] block/nvme: Improve debugging experience and minor fixes Philippe Mathieu-Daudé
2020-10-14 15:57 ` [PATCH 01/15] block/nvme: Move nvme_poll_cb() earlier Philippe Mathieu-Daudé
2020-10-14 15:57 ` [PATCH 02/15] block/nvme: Trace nvme_poll_queue() per queue Philippe Mathieu-Daudé
@ 2020-10-14 15:57 ` Philippe Mathieu-Daudé
2020-10-14 15:57 ` [PATCH 04/15] block/nvme: Improve nvme_free_req_queue_wait() trace information Philippe Mathieu-Daudé
` (11 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-14 15:57 UTC (permalink / raw)
To: qemu-devel
Cc: Fam Zheng, Kevin Wolf, qemu-block, Max Reitz, Stefan Hajnoczi,
Philippe Mathieu-Daudé
We can not have negative queue count/size/index, use unsigned type.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
block/nvme.c | 24 +++++++++++-------------
block/trace-events | 10 +++++-----
2 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/block/nvme.c b/block/nvme.c
index 7c253eafa7f..d84206b598d 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -103,7 +103,7 @@ struct BDRVNVMeState {
* [1..]: io queues.
*/
NVMeQueuePair **queues;
- int nr_queues;
+ unsigned nr_queues;
size_t page_size;
/* How many uint32_t elements does each doorbell entry take. */
size_t doorbell_scale;
@@ -154,7 +154,7 @@ static QemuOptsList runtime_opts = {
};
static void nvme_init_queue(BDRVNVMeState *s, NVMeQueue *q,
- int nentries, int entry_bytes, Error **errp)
+ unsigned nentries, size_t entry_bytes, Error **errp)
{
size_t bytes;
int r;
@@ -198,7 +198,7 @@ static void nvme_free_req_queue_cb(void *opaque)
static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s,
AioContext *aio_context,
- int idx, int size,
+ unsigned idx, size_t size,
Error **errp)
{
int i, r;
@@ -640,10 +640,10 @@ static bool nvme_poll_cb(void *opaque)
static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp)
{
BDRVNVMeState *s = bs->opaque;
- int n = s->nr_queues;
+ unsigned n = s->nr_queues;
NVMeQueuePair *q;
NvmeCmd cmd;
- int queue_size = NVME_QUEUE_SIZE;
+ unsigned queue_size = NVME_QUEUE_SIZE;
q = nvme_create_queue_pair(s, bdrv_get_aio_context(bs),
n, queue_size, errp);
@@ -657,7 +657,7 @@ static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp)
.cdw11 = cpu_to_le32(0x3),
};
if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) {
- error_setg(errp, "Failed to create CQ io queue [%d]", n);
+ error_setg(errp, "Failed to create CQ io queue [%u]", n);
goto out_error;
}
cmd = (NvmeCmd) {
@@ -667,7 +667,7 @@ static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp)
.cdw11 = cpu_to_le32(0x1 | (n << 16)),
};
if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) {
- error_setg(errp, "Failed to create SQ io queue [%d]", n);
+ error_setg(errp, "Failed to create SQ io queue [%u]", n);
goto out_error;
}
s->queues = g_renew(NVMeQueuePair *, s->queues, n + 1);
@@ -869,10 +869,9 @@ static int nvme_enable_disable_write_cache(BlockDriverState *bs, bool enable,
static void nvme_close(BlockDriverState *bs)
{
- int i;
BDRVNVMeState *s = bs->opaque;
- for (i = 0; i < s->nr_queues; ++i) {
+ for (unsigned i = 0; i < s->nr_queues; ++i) {
nvme_free_queue_pair(s->queues[i]);
}
g_free(s->queues);
@@ -1380,7 +1379,7 @@ static void nvme_detach_aio_context(BlockDriverState *bs)
{
BDRVNVMeState *s = bs->opaque;
- for (int i = 0; i < s->nr_queues; i++) {
+ for (unsigned i = 0; i < s->nr_queues; i++) {
NVMeQueuePair *q = s->queues[i];
qemu_bh_delete(q->completion_bh);
@@ -1401,7 +1400,7 @@ static void nvme_attach_aio_context(BlockDriverState *bs,
aio_set_event_notifier(new_context, &s->irq_notifier[MSIX_SHARED_IRQ_IDX],
false, nvme_handle_event, nvme_poll_cb);
- for (int i = 0; i < s->nr_queues; i++) {
+ for (unsigned i = 0; i < s->nr_queues; i++) {
NVMeQueuePair *q = s->queues[i];
q->completion_bh =
@@ -1418,11 +1417,10 @@ static void nvme_aio_plug(BlockDriverState *bs)
static void nvme_aio_unplug(BlockDriverState *bs)
{
- int i;
BDRVNVMeState *s = bs->opaque;
assert(s->plugged);
s->plugged = false;
- for (i = INDEX_IO(0); i < s->nr_queues; i++) {
+ for (unsigned i = INDEX_IO(0); i < s->nr_queues; i++) {
NVMeQueuePair *q = s->queues[i];
qemu_mutex_lock(&q->lock);
nvme_kick(q);
diff --git a/block/trace-events b/block/trace-events
index fa50af6b6f3..3bb5a238601 100644
--- a/block/trace-events
+++ b/block/trace-events
@@ -134,13 +134,13 @@ qed_aio_write_postfill(void *s, void *acb, uint64_t start, size_t len, uint64_t
qed_aio_write_main(void *s, void *acb, int ret, uint64_t offset, size_t len) "s %p acb %p ret %d offset %"PRIu64" len %zu"
# nvme.c
-nvme_kick(void *s, int queue) "s %p queue %d"
+nvme_kick(void *s, unsigned q_index) "s %p q #%u"
nvme_dma_flush_queue_wait(void *s) "s %p"
nvme_error(int cmd_specific, int sq_head, int sqid, int cid, int status) "cmd_specific %d sq_head %d sqid %d cid %d status 0x%x"
-nvme_process_completion(void *s, int index, int inflight) "s %p queue %d inflight %d"
-nvme_process_completion_queue_plugged(void *s, int index) "s %p queue %d"
-nvme_complete_command(void *s, int index, int cid) "s %p queue %d cid %d"
-nvme_submit_command(void *s, int index, int cid) "s %p queue %d cid %d"
+nvme_process_completion(void *s, unsigned q_index, int inflight) "s %p q #%u inflight %d"
+nvme_process_completion_queue_plugged(void *s, unsigned q_index) "s %p q #%u"
+nvme_complete_command(void *s, unsigned q_index, int cid) "s %p q #%u cid %d"
+nvme_submit_command(void *s, unsigned q_index, int cid) "s %p q #%u cid %d"
nvme_submit_command_raw(int c0, int c1, int c2, int c3, int c4, int c5, int c6, int c7) "%02x %02x %02x %02x %02x %02x %02x %02x"
nvme_handle_event(void *s) "s %p"
nvme_poll_queue(void *s, unsigned q_index) "s %p q #%u"
--
2.26.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 04/15] block/nvme: Improve nvme_free_req_queue_wait() trace information
2020-10-14 15:57 [PATCH 00/15] block/nvme: Improve debugging experience and minor fixes Philippe Mathieu-Daudé
` (2 preceding siblings ...)
2020-10-14 15:57 ` [PATCH 03/15] block/nvme: Use unsigned integer for queue counter/size Philippe Mathieu-Daudé
@ 2020-10-14 15:57 ` Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 05/15] block/nvme: Trace queue pair creation/deletion Philippe Mathieu-Daudé
` (10 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-14 15:57 UTC (permalink / raw)
To: qemu-devel
Cc: Fam Zheng, Kevin Wolf, qemu-block, Max Reitz, Stefan Hajnoczi,
Philippe Mathieu-Daudé
What we want to trace is the block driver state and the queue index.
Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
block/nvme.c | 2 +-
block/trace-events | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/nvme.c b/block/nvme.c
index d84206b598d..e9410f2e0eb 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -286,7 +286,7 @@ static NVMeRequest *nvme_get_free_req(NVMeQueuePair *q)
while (q->free_req_head == -1) {
if (qemu_in_coroutine()) {
- trace_nvme_free_req_queue_wait(q);
+ trace_nvme_free_req_queue_wait(q->s, q->index);
qemu_co_queue_wait(&q->free_req_queue, &q->lock);
} else {
qemu_mutex_unlock(&q->lock);
diff --git a/block/trace-events b/block/trace-events
index 3bb5a238601..410789188cc 100644
--- a/block/trace-events
+++ b/block/trace-events
@@ -152,7 +152,7 @@ nvme_rw_done(void *s, int is_write, uint64_t offset, uint64_t bytes, int ret) "s
nvme_dsm(void *s, uint64_t offset, uint64_t bytes) "s %p offset %"PRId64" bytes %"PRId64""
nvme_dsm_done(void *s, uint64_t offset, uint64_t bytes, int ret) "s %p offset %"PRId64" bytes %"PRId64" ret %d"
nvme_dma_map_flush(void *s) "s %p"
-nvme_free_req_queue_wait(void *q) "q %p"
+nvme_free_req_queue_wait(void *s, unsigned q_index) "s %p q #%u"
nvme_cmd_map_qiov(void *s, void *cmd, void *req, void *qiov, int entries) "s %p cmd %p req %p qiov %p entries %d"
nvme_cmd_map_qiov_pages(void *s, int i, uint64_t page) "s %p page[%d] 0x%"PRIx64
nvme_cmd_map_qiov_iov(void *s, int i, void *page, int pages) "s %p iov[%d] %p pages %d"
--
2.26.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 05/15] block/nvme: Trace queue pair creation/deletion
2020-10-14 15:57 [PATCH 00/15] block/nvme: Improve debugging experience and minor fixes Philippe Mathieu-Daudé
` (3 preceding siblings ...)
2020-10-14 15:57 ` [PATCH 04/15] block/nvme: Improve nvme_free_req_queue_wait() trace information Philippe Mathieu-Daudé
@ 2020-10-14 15:58 ` Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 06/15] block/nvme: Make nvme_identify() return boolean indicating error Philippe Mathieu-Daudé
` (9 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-14 15:58 UTC (permalink / raw)
To: qemu-devel
Cc: Fam Zheng, Kevin Wolf, qemu-block, Max Reitz, Stefan Hajnoczi,
Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
block/nvme.c | 3 +++
block/trace-events | 2 ++
2 files changed, 5 insertions(+)
diff --git a/block/nvme.c b/block/nvme.c
index e9410f2e0eb..95f19e12cd6 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -175,6 +175,7 @@ static void nvme_init_queue(BDRVNVMeState *s, NVMeQueue *q,
static void nvme_free_queue_pair(NVMeQueuePair *q)
{
+ trace_nvme_free_queue_pair(q->index, q);
if (q->completion_bh) {
qemu_bh_delete(q->completion_bh);
}
@@ -210,6 +211,8 @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s,
if (!q) {
return NULL;
}
+ trace_nvme_create_queue_pair(idx, q, size, aio_context,
+ event_notifier_get_fd(s->irq_notifier));
q->prp_list_pages = qemu_try_memalign(s->page_size,
s->page_size * NVME_NUM_REQS);
if (!q->prp_list_pages) {
diff --git a/block/trace-events b/block/trace-events
index 410789188cc..6694c23e1c1 100644
--- a/block/trace-events
+++ b/block/trace-events
@@ -153,6 +153,8 @@ nvme_dsm(void *s, uint64_t offset, uint64_t bytes) "s %p offset %"PRId64" bytes
nvme_dsm_done(void *s, uint64_t offset, uint64_t bytes, int ret) "s %p offset %"PRId64" bytes %"PRId64" ret %d"
nvme_dma_map_flush(void *s) "s %p"
nvme_free_req_queue_wait(void *s, unsigned q_index) "s %p q #%u"
+nvme_create_queue_pair(unsigned q_index, void *q, unsigned size, void *aio_context, int fd) "index %u q %p size %u aioctx %p fd %d"
+nvme_free_queue_pair(unsigned q_index, void *q) "index %u q %p"
nvme_cmd_map_qiov(void *s, void *cmd, void *req, void *qiov, int entries) "s %p cmd %p req %p qiov %p entries %d"
nvme_cmd_map_qiov_pages(void *s, int i, uint64_t page) "s %p page[%d] 0x%"PRIx64
nvme_cmd_map_qiov_iov(void *s, int i, void *page, int pages) "s %p iov[%d] %p pages %d"
--
2.26.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 06/15] block/nvme: Make nvme_identify() return boolean indicating error
2020-10-14 15:57 [PATCH 00/15] block/nvme: Improve debugging experience and minor fixes Philippe Mathieu-Daudé
` (4 preceding siblings ...)
2020-10-14 15:58 ` [PATCH 05/15] block/nvme: Trace queue pair creation/deletion Philippe Mathieu-Daudé
@ 2020-10-14 15:58 ` Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 07/15] block/nvme: Make nvme_init_queue() " Philippe Mathieu-Daudé
` (8 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-14 15:58 UTC (permalink / raw)
To: qemu-devel
Cc: Fam Zheng, Kevin Wolf, qemu-block, Max Reitz, Stefan Hajnoczi,
Philippe Mathieu-Daudé
Just for consistency, following the example documented since
commit e3fe3988d7 ("error: Document Error API usage rules"),
return a boolean value indicating an error is set or not.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
block/nvme.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/block/nvme.c b/block/nvme.c
index 95f19e12cd6..95f8f8b360b 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -496,9 +496,11 @@ static int nvme_cmd_sync(BlockDriverState *bs, NVMeQueuePair *q,
return ret;
}
-static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp)
+/* Returns true on success, false on failure. */
+static bool nvme_identify(BlockDriverState *bs, int namespace, Error **errp)
{
BDRVNVMeState *s = bs->opaque;
+ bool ret = false;
union {
NvmeIdCtrl ctrl;
NvmeIdNs ns;
@@ -575,10 +577,13 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp)
goto out;
}
+ ret = true;
s->blkshift = lbaf->ds;
out:
qemu_vfio_dma_unmap(s->vfio, id);
qemu_vfree(id);
+
+ return ret;
}
static bool nvme_poll_queue(NVMeQueuePair *q)
--
2.26.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 07/15] block/nvme: Make nvme_init_queue() return boolean indicating error
2020-10-14 15:57 [PATCH 00/15] block/nvme: Improve debugging experience and minor fixes Philippe Mathieu-Daudé
` (5 preceding siblings ...)
2020-10-14 15:58 ` [PATCH 06/15] block/nvme: Make nvme_identify() return boolean indicating error Philippe Mathieu-Daudé
@ 2020-10-14 15:58 ` Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 08/15] block/nvme: Pass AioContext argument to nvme_add_io_queue() Philippe Mathieu-Daudé
` (7 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-14 15:58 UTC (permalink / raw)
To: qemu-devel
Cc: Fam Zheng, Kevin Wolf, qemu-block, Max Reitz, Stefan Hajnoczi,
Philippe Mathieu-Daudé
Just for consistency, following the example documented since
commit e3fe3988d7 ("error: Document Error API usage rules"),
return a boolean value indicating an error is set or not.
This simplifies a bit nvme_create_queue_pair().
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
block/nvme.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/block/nvme.c b/block/nvme.c
index 95f8f8b360b..523814a1243 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -153,7 +153,8 @@ static QemuOptsList runtime_opts = {
},
};
-static void nvme_init_queue(BDRVNVMeState *s, NVMeQueue *q,
+/* Returns true on success, false on failure. */
+static bool nvme_init_queue(BDRVNVMeState *s, NVMeQueue *q,
unsigned nentries, size_t entry_bytes, Error **errp)
{
size_t bytes;
@@ -164,13 +165,14 @@ static void nvme_init_queue(BDRVNVMeState *s, NVMeQueue *q,
q->queue = qemu_try_memalign(s->page_size, bytes);
if (!q->queue) {
error_setg(errp, "Cannot allocate queue");
- return;
+ return false;
}
memset(q->queue, 0, bytes);
r = qemu_vfio_dma_map(s->vfio, q->queue, bytes, false, &q->iova, errp);
if (r) {
error_prepend(errp, "Cannot map queue: ");
}
+ return r == 0;
}
static void nvme_free_queue_pair(NVMeQueuePair *q)
@@ -203,7 +205,6 @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s,
Error **errp)
{
int i, r;
- Error *local_err = NULL;
NVMeQueuePair *q;
uint64_t prp_list_iova;
@@ -240,16 +241,12 @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s,
req->prp_list_iova = prp_list_iova + i * s->page_size;
}
- nvme_init_queue(s, &q->sq, size, NVME_SQ_ENTRY_BYTES, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
+ if (!nvme_init_queue(s, &q->sq, size, NVME_SQ_ENTRY_BYTES, errp)) {
goto fail;
}
q->sq.doorbell = &s->doorbells[idx * s->doorbell_scale].sq_tail;
- nvme_init_queue(s, &q->cq, size, NVME_CQ_ENTRY_BYTES, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
+ if (!nvme_init_queue(s, &q->cq, size, NVME_CQ_ENTRY_BYTES, errp)) {
goto fail;
}
q->cq.doorbell = &s->doorbells[idx * s->doorbell_scale].cq_head;
--
2.26.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 08/15] block/nvme: Pass AioContext argument to nvme_add_io_queue()
2020-10-14 15:57 [PATCH 00/15] block/nvme: Improve debugging experience and minor fixes Philippe Mathieu-Daudé
` (6 preceding siblings ...)
2020-10-14 15:58 ` [PATCH 07/15] block/nvme: Make nvme_init_queue() " Philippe Mathieu-Daudé
@ 2020-10-14 15:58 ` Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 09/15] block/nvme: Introduce Completion Queue definitions Philippe Mathieu-Daudé
` (6 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-14 15:58 UTC (permalink / raw)
To: qemu-devel
Cc: Fam Zheng, Kevin Wolf, qemu-block, Max Reitz, Stefan Hajnoczi,
Philippe Mathieu-Daudé
We want to get ride of the BlockDriverState pointer at some point,
so pass aio_context along.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
block/nvme.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/block/nvme.c b/block/nvme.c
index 523814a1243..b841c5950c5 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -642,7 +642,9 @@ static bool nvme_poll_cb(void *opaque)
return nvme_poll_queues(s);
}
-static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp)
+/* Returns true on success, false on failure. */
+static bool nvme_add_io_queue(BlockDriverState *bs,
+ AioContext *aio_context, Error **errp)
{
BDRVNVMeState *s = bs->opaque;
unsigned n = s->nr_queues;
@@ -650,8 +652,7 @@ static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp)
NvmeCmd cmd;
unsigned queue_size = NVME_QUEUE_SIZE;
- q = nvme_create_queue_pair(s, bdrv_get_aio_context(bs),
- n, queue_size, errp);
+ q = nvme_create_queue_pair(s, aio_context, n, queue_size, errp);
if (!q) {
return false;
}
@@ -805,7 +806,7 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace,
}
/* Set up command queues. */
- if (!nvme_add_io_queue(bs, errp)) {
+ if (!nvme_add_io_queue(bs, aio_context, errp)) {
ret = -EIO;
}
out:
--
2.26.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 09/15] block/nvme: Introduce Completion Queue definitions
2020-10-14 15:57 [PATCH 00/15] block/nvme: Improve debugging experience and minor fixes Philippe Mathieu-Daudé
` (7 preceding siblings ...)
2020-10-14 15:58 ` [PATCH 08/15] block/nvme: Pass AioContext argument to nvme_add_io_queue() Philippe Mathieu-Daudé
@ 2020-10-14 15:58 ` Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 10/15] block/nvme: Use definitions instead of magic values in add_io_queue() Philippe Mathieu-Daudé
` (5 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-14 15:58 UTC (permalink / raw)
To: qemu-devel
Cc: Fam Zheng, Kevin Wolf, qemu-block, Max Reitz, Stefan Hajnoczi,
Philippe Mathieu-Daudé
Rename Submission Queue flags with 'Sq' and introduce
Completion Queue flag definitions.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
include/block/nvme.h | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/include/block/nvme.h b/include/block/nvme.h
index 65e68a82c89..079f884a2d3 100644
--- a/include/block/nvme.h
+++ b/include/block/nvme.h
@@ -491,6 +491,11 @@ typedef struct QEMU_PACKED NvmeCreateCq {
#define NVME_CQ_FLAGS_PC(cq_flags) (cq_flags & 0x1)
#define NVME_CQ_FLAGS_IEN(cq_flags) ((cq_flags >> 1) & 0x1)
+enum NvmeFlagsCq {
+ NVME_CQ_PC = 1,
+ NVME_CQ_IEN = 2,
+};
+
typedef struct QEMU_PACKED NvmeCreateSq {
uint8_t opcode;
uint8_t flags;
@@ -508,12 +513,12 @@ typedef struct QEMU_PACKED NvmeCreateSq {
#define NVME_SQ_FLAGS_PC(sq_flags) (sq_flags & 0x1)
#define NVME_SQ_FLAGS_QPRIO(sq_flags) ((sq_flags >> 1) & 0x3)
-enum NvmeQueueFlags {
- NVME_Q_PC = 1,
- NVME_Q_PRIO_URGENT = 0,
- NVME_Q_PRIO_HIGH = 1,
- NVME_Q_PRIO_NORMAL = 2,
- NVME_Q_PRIO_LOW = 3,
+enum NvmeFlagsSq {
+ NVME_SQ_PC = 1,
+ NVME_SQ_PRIO_URGENT = 0,
+ NVME_SQ_PRIO_HIGH = 1,
+ NVME_SQ_PRIO_NORMAL = 2,
+ NVME_SQ_PRIO_LOW = 3,
};
typedef struct QEMU_PACKED NvmeIdentify {
--
2.26.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 10/15] block/nvme: Use definitions instead of magic values in add_io_queue()
2020-10-14 15:57 [PATCH 00/15] block/nvme: Improve debugging experience and minor fixes Philippe Mathieu-Daudé
` (8 preceding siblings ...)
2020-10-14 15:58 ` [PATCH 09/15] block/nvme: Introduce Completion Queue definitions Philippe Mathieu-Daudé
@ 2020-10-14 15:58 ` Philippe Mathieu-Daudé
2020-10-15 10:57 ` Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 11/15] block/nvme: Trace controller capabilities Philippe Mathieu-Daudé
` (4 subsequent siblings)
14 siblings, 1 reply; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-14 15:58 UTC (permalink / raw)
To: qemu-devel
Cc: Fam Zheng, Kevin Wolf, qemu-block, Max Reitz, Stefan Hajnoczi,
Philippe Mathieu-Daudé
Replace magic values by definitions, and simplifiy since the
number of queues will never reach 64K.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
block/nvme.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/block/nvme.c b/block/nvme.c
index b841c5950c5..11fba2d754d 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -652,6 +652,7 @@ static bool nvme_add_io_queue(BlockDriverState *bs,
NvmeCmd cmd;
unsigned queue_size = NVME_QUEUE_SIZE;
+ assert(n <= UINT16_MAX);
q = nvme_create_queue_pair(s, aio_context, n, queue_size, errp);
if (!q) {
return false;
@@ -659,8 +660,8 @@ static bool nvme_add_io_queue(BlockDriverState *bs,
cmd = (NvmeCmd) {
.opcode = NVME_ADM_CMD_CREATE_CQ,
.dptr.prp1 = cpu_to_le64(q->cq.iova),
- .cdw10 = cpu_to_le32(((queue_size - 1) << 16) | (n & 0xFFFF)),
- .cdw11 = cpu_to_le32(0x3),
+ .cdw10 = cpu_to_le32(((queue_size - 1) << 16) | n),
+ .cdw11 = cpu_to_le32(NVME_CQ_IEN | NVME_CQ_PC),
};
if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) {
error_setg(errp, "Failed to create CQ io queue [%u]", n);
@@ -669,8 +670,8 @@ static bool nvme_add_io_queue(BlockDriverState *bs,
cmd = (NvmeCmd) {
.opcode = NVME_ADM_CMD_CREATE_SQ,
.dptr.prp1 = cpu_to_le64(q->sq.iova),
- .cdw10 = cpu_to_le32(((queue_size - 1) << 16) | (n & 0xFFFF)),
- .cdw11 = cpu_to_le32(0x1 | (n << 16)),
+ .cdw10 = cpu_to_le32(((queue_size - 1) << 16) | n),
+ .cdw11 = cpu_to_le32(NVME_SQ_PC | (n << 16)),
};
if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) {
error_setg(errp, "Failed to create SQ io queue [%u]", n);
--
2.26.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 11/15] block/nvme: Trace controller capabilities
2020-10-14 15:57 [PATCH 00/15] block/nvme: Improve debugging experience and minor fixes Philippe Mathieu-Daudé
` (9 preceding siblings ...)
2020-10-14 15:58 ` [PATCH 10/15] block/nvme: Use definitions instead of magic values in add_io_queue() Philippe Mathieu-Daudé
@ 2020-10-14 15:58 ` Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 12/15] block/nvme: Simplify device reset Philippe Mathieu-Daudé
` (3 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-14 15:58 UTC (permalink / raw)
To: qemu-devel
Cc: Fam Zheng, Kevin Wolf, qemu-block, Max Reitz, Stefan Hajnoczi,
Philippe Mathieu-Daudé
Controllers have different capabilities and report them in the
CAP register. We are particularly interested by the page size
limits.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
block/nvme.c | 10 ++++++++++
block/trace-events | 1 +
2 files changed, 11 insertions(+)
diff --git a/block/nvme.c b/block/nvme.c
index 11fba2d754d..fad727416ee 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -725,6 +725,16 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace,
* Initialization". */
cap = le64_to_cpu(regs->cap);
+ trace_nvme_controller_capability("Maximum Queue Entries Supported",
+ NVME_CAP_MQES(cap));
+ trace_nvme_controller_capability("Contiguous Queues Required",
+ NVME_CAP_CQR(cap));
+ trace_nvme_controller_capability("Subsystem Reset Supported",
+ NVME_CAP_NSSRS(cap));
+ trace_nvme_controller_capability("Memory Page Size Minimum",
+ NVME_CAP_MPSMIN(cap));
+ trace_nvme_controller_capability("Memory Page Size Maximum",
+ NVME_CAP_MPSMAX(cap));
if (!NVME_CAP_CSS(cap)) {
error_setg(errp, "Device doesn't support NVMe command set");
ret = -EINVAL;
diff --git a/block/trace-events b/block/trace-events
index 6694c23e1c1..8a24d7a8650 100644
--- a/block/trace-events
+++ b/block/trace-events
@@ -134,6 +134,7 @@ qed_aio_write_postfill(void *s, void *acb, uint64_t start, size_t len, uint64_t
qed_aio_write_main(void *s, void *acb, int ret, uint64_t offset, size_t len) "s %p acb %p ret %d offset %"PRIu64" len %zu"
# nvme.c
+nvme_controller_capability(const char *desc, uint64_t value) "%s: %"PRIu64
nvme_kick(void *s, unsigned q_index) "s %p q #%u"
nvme_dma_flush_queue_wait(void *s) "s %p"
nvme_error(int cmd_specific, int sq_head, int sqid, int cid, int status) "cmd_specific %d sq_head %d sqid %d cid %d status 0x%x"
--
2.26.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 12/15] block/nvme: Simplify device reset
2020-10-14 15:57 [PATCH 00/15] block/nvme: Improve debugging experience and minor fixes Philippe Mathieu-Daudé
` (10 preceding siblings ...)
2020-10-14 15:58 ` [PATCH 11/15] block/nvme: Trace controller capabilities Philippe Mathieu-Daudé
@ 2020-10-14 15:58 ` Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 13/15] block/nvme: Simplify ADMIN queue access Philippe Mathieu-Daudé
` (2 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-14 15:58 UTC (permalink / raw)
To: qemu-devel
Cc: Fam Zheng, Kevin Wolf, qemu-block, Max Reitz, Stefan Hajnoczi,
Philippe Mathieu-Daudé
Avoid multiple endianess conversion by using device endianess.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
block/nvme.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/block/nvme.c b/block/nvme.c
index fad727416ee..299fc82f40f 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -747,7 +747,7 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace,
timeout_ms = MIN(500 * NVME_CAP_TO(cap), 30000);
/* Reset device to get a clean state. */
- regs->cc = cpu_to_le32(le32_to_cpu(regs->cc) & 0xFE);
+ regs->cc &= const_le32(0xFE);
/* Wait for CSTS.RDY = 0. */
deadline = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + timeout_ms * SCALE_MS;
while (NVME_CSTS_RDY(le32_to_cpu(regs->csts))) {
--
2.26.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 13/15] block/nvme: Simplify ADMIN queue access
2020-10-14 15:57 [PATCH 00/15] block/nvme: Improve debugging experience and minor fixes Philippe Mathieu-Daudé
` (11 preceding siblings ...)
2020-10-14 15:58 ` [PATCH 12/15] block/nvme: Simplify device reset Philippe Mathieu-Daudé
@ 2020-10-14 15:58 ` Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 14/15] block/nvme: Report warning with warn_report() Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 15/15] block/nvme: Set request_alignment at initialization Philippe Mathieu-Daudé
14 siblings, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-14 15:58 UTC (permalink / raw)
To: qemu-devel
Cc: Fam Zheng, Kevin Wolf, qemu-block, Max Reitz, Stefan Hajnoczi,
Philippe Mathieu-Daudé
We don't need to dereference from BDRVNVMeState each time.
Use a NVMeQueuePair pointer to the admin queue and use it.
The nvme_init() becomes easier to review, matching the style
of nvme_add_io_queue().
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
block/nvme.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/block/nvme.c b/block/nvme.c
index 299fc82f40f..ea5180d8a27 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -690,6 +690,7 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace,
Error **errp)
{
BDRVNVMeState *s = bs->opaque;
+ NVMeQueuePair *q;
AioContext *aio_context = bdrv_get_aio_context(bs);
int ret;
uint64_t cap;
@@ -769,19 +770,20 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace,
/* Set up admin queue. */
s->queues = g_new(NVMeQueuePair *, 1);
- s->queues[INDEX_ADMIN] = nvme_create_queue_pair(s, aio_context, 0,
+ q = nvme_create_queue_pair(s, aio_context, 0,
NVME_QUEUE_SIZE,
errp);
- if (!s->queues[INDEX_ADMIN]) {
+ if (!q) {
ret = -EINVAL;
goto out;
}
+ s->queues[INDEX_ADMIN] = q;
s->nr_queues = 1;
QEMU_BUILD_BUG_ON(NVME_QUEUE_SIZE & 0xF000);
regs->aqa = cpu_to_le32((NVME_QUEUE_SIZE << AQA_ACQS_SHIFT) |
(NVME_QUEUE_SIZE << AQA_ASQS_SHIFT));
- regs->asq = cpu_to_le64(s->queues[INDEX_ADMIN]->sq.iova);
- regs->acq = cpu_to_le64(s->queues[INDEX_ADMIN]->cq.iova);
+ regs->asq = cpu_to_le64(q->sq.iova);
+ regs->acq = cpu_to_le64(q->cq.iova);
/* After setting up all control registers we can enable device now. */
regs->cc = cpu_to_le32((ctz32(NVME_CQ_ENTRY_BYTES) << CC_IOCQES_SHIFT) |
--
2.26.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 14/15] block/nvme: Report warning with warn_report()
2020-10-14 15:57 [PATCH 00/15] block/nvme: Improve debugging experience and minor fixes Philippe Mathieu-Daudé
` (12 preceding siblings ...)
2020-10-14 15:58 ` [PATCH 13/15] block/nvme: Simplify ADMIN queue access Philippe Mathieu-Daudé
@ 2020-10-14 15:58 ` Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 15/15] block/nvme: Set request_alignment at initialization Philippe Mathieu-Daudé
14 siblings, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-14 15:58 UTC (permalink / raw)
To: qemu-devel
Cc: Fam Zheng, Kevin Wolf, qemu-block, Max Reitz, Stefan Hajnoczi,
Philippe Mathieu-Daudé
Instead of displaying warning on stderr, use warn_report()
which also displays it on the monitor.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
block/nvme.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/nvme.c b/block/nvme.c
index ea5180d8a27..4d2b7fdf4f4 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -390,8 +390,8 @@ static bool nvme_process_completion(NVMeQueuePair *q)
}
cid = le16_to_cpu(c->cid);
if (cid == 0 || cid > NVME_QUEUE_SIZE) {
- fprintf(stderr, "Unexpected CID in completion queue: %" PRIu32 "\n",
- cid);
+ warn_report("NVMe: Unexpected CID in completion queue: %"PRIu32", "
+ "queue size: %u", cid, NVME_QUEUE_SIZE);
continue;
}
trace_nvme_complete_command(s, q->index, cid);
--
2.26.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 15/15] block/nvme: Set request_alignment at initialization
2020-10-14 15:57 [PATCH 00/15] block/nvme: Improve debugging experience and minor fixes Philippe Mathieu-Daudé
` (13 preceding siblings ...)
2020-10-14 15:58 ` [PATCH 14/15] block/nvme: Report warning with warn_report() Philippe Mathieu-Daudé
@ 2020-10-14 15:58 ` Philippe Mathieu-Daudé
14 siblings, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-14 15:58 UTC (permalink / raw)
To: qemu-devel
Cc: Fam Zheng, Kevin Wolf, qemu-block, Max Reitz, Stefan Hajnoczi,
Philippe Mathieu-Daudé
When introducing this driver in commit bdd6a90a9e5
("block: Add VFIO based NVMe driver") we correctly
set the request_alignment in nvme_refresh_limits()
but forgot to set it at initialization. Do it now.
Reported-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
block/nvme.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/block/nvme.c b/block/nvme.c
index 4d2b7fdf4f4..04608b49f56 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -745,6 +745,7 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace,
s->page_size = MAX(4096, 1 << NVME_CAP_MPSMIN(cap));
s->doorbell_scale = (4 << NVME_CAP_DSTRD(cap)) / sizeof(uint32_t);
bs->bl.opt_mem_alignment = s->page_size;
+ bs->bl.request_alignment = s->page_size;
timeout_ms = MIN(500 * NVME_CAP_TO(cap), 30000);
/* Reset device to get a clean state. */
--
2.26.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH 10/15] block/nvme: Use definitions instead of magic values in add_io_queue()
2020-10-14 15:58 ` [PATCH 10/15] block/nvme: Use definitions instead of magic values in add_io_queue() Philippe Mathieu-Daudé
@ 2020-10-15 10:57 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-15 10:57 UTC (permalink / raw)
To: qemu-devel; +Cc: Fam Zheng, Kevin Wolf, Stefan Hajnoczi, qemu-block, Max Reitz
On 10/14/20 5:58 PM, Philippe Mathieu-Daudé wrote:
> Replace magic values by definitions, and simplifiy since the
> number of queues will never reach 64K.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> block/nvme.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/block/nvme.c b/block/nvme.c
> index b841c5950c5..11fba2d754d 100644
> --- a/block/nvme.c
> +++ b/block/nvme.c
> @@ -652,6 +652,7 @@ static bool nvme_add_io_queue(BlockDriverState *bs,
> NvmeCmd cmd;
> unsigned queue_size = NVME_QUEUE_SIZE;
>
> + assert(n <= UINT16_MAX);
> q = nvme_create_queue_pair(s, aio_context, n, queue_size, errp);
> if (!q) {
> return false;
> @@ -659,8 +660,8 @@ static bool nvme_add_io_queue(BlockDriverState *bs,
> cmd = (NvmeCmd) {
> .opcode = NVME_ADM_CMD_CREATE_CQ,
> .dptr.prp1 = cpu_to_le64(q->cq.iova),
> - .cdw10 = cpu_to_le32(((queue_size - 1) << 16) | (n & 0xFFFF)),
> - .cdw11 = cpu_to_le32(0x3),
> + .cdw10 = cpu_to_le32(((queue_size - 1) << 16) | n),
We can use NVME_NUM_REQS here and drop the queue_size variable.
> + .cdw11 = cpu_to_le32(NVME_CQ_IEN | NVME_CQ_PC),
> };
> if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) {
> error_setg(errp, "Failed to create CQ io queue [%u]", n);
> @@ -669,8 +670,8 @@ static bool nvme_add_io_queue(BlockDriverState *bs,
> cmd = (NvmeCmd) {
> .opcode = NVME_ADM_CMD_CREATE_SQ,
> .dptr.prp1 = cpu_to_le64(q->sq.iova),
> - .cdw10 = cpu_to_le32(((queue_size - 1) << 16) | (n & 0xFFFF)),
> - .cdw11 = cpu_to_le32(0x1 | (n << 16)),
> + .cdw10 = cpu_to_le32(((queue_size - 1) << 16) | n),
> + .cdw11 = cpu_to_le32(NVME_SQ_PC | (n << 16)),
> };
> if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) {
> error_setg(errp, "Failed to create SQ io queue [%u]", n);
>
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2020-10-15 10:58 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-14 15:57 [PATCH 00/15] block/nvme: Improve debugging experience and minor fixes Philippe Mathieu-Daudé
2020-10-14 15:57 ` [PATCH 01/15] block/nvme: Move nvme_poll_cb() earlier Philippe Mathieu-Daudé
2020-10-14 15:57 ` [PATCH 02/15] block/nvme: Trace nvme_poll_queue() per queue Philippe Mathieu-Daudé
2020-10-14 15:57 ` [PATCH 03/15] block/nvme: Use unsigned integer for queue counter/size Philippe Mathieu-Daudé
2020-10-14 15:57 ` [PATCH 04/15] block/nvme: Improve nvme_free_req_queue_wait() trace information Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 05/15] block/nvme: Trace queue pair creation/deletion Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 06/15] block/nvme: Make nvme_identify() return boolean indicating error Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 07/15] block/nvme: Make nvme_init_queue() " Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 08/15] block/nvme: Pass AioContext argument to nvme_add_io_queue() Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 09/15] block/nvme: Introduce Completion Queue definitions Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 10/15] block/nvme: Use definitions instead of magic values in add_io_queue() Philippe Mathieu-Daudé
2020-10-15 10:57 ` Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 11/15] block/nvme: Trace controller capabilities Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 12/15] block/nvme: Simplify device reset Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 13/15] block/nvme: Simplify ADMIN queue access Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 14/15] block/nvme: Report warning with warn_report() Philippe Mathieu-Daudé
2020-10-14 15:58 ` [PATCH 15/15] block/nvme: Set request_alignment at initialization Philippe Mathieu-Daudé
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.