2 * NVMe block driver based on vfio
4 * Copyright 2016 - 2018 Red Hat, Inc.
7 * Fam Zheng <famz@redhat.com>
8 * Paolo Bonzini <pbonzini@redhat.com>
10 * This work is licensed under the terms of the GNU GPL, version 2 or later.
11 * See the COPYING file in the top-level directory.
14 #include "qemu/osdep.h"
15 #include <linux/vfio.h>
16 #include "qapi/error.h"
17 #include "qapi/qmp/qdict.h"
18 #include "qapi/qmp/qstring.h"
19 #include "qemu/error-report.h"
20 #include "qemu/main-loop.h"
21 #include "qemu/module.h"
22 #include "qemu/cutils.h"
23 #include "qemu/option.h"
24 #include "qemu/vfio-helpers.h"
25 #include "block/block_int.h"
26 #include "sysemu/replay.h"
29 #include "block/nvme.h"
31 #define NVME_SQ_ENTRY_BYTES 64
32 #define NVME_CQ_ENTRY_BYTES 16
33 #define NVME_QUEUE_SIZE 128
34 #define NVME_DOORBELL_SIZE 4096
37 * We have to leave one slot empty as that is the full queue case where
40 #define NVME_NUM_REQS (NVME_QUEUE_SIZE - 1)
42 typedef struct BDRVNVMeState BDRVNVMeState
;
48 /* Hardware MMIO register */
49 volatile uint32_t *doorbell
;
53 BlockCompletionFunc
*cb
;
57 uint64_t prp_list_iova
;
58 int free_req_next
; /* q->reqs[] index of next free req */
64 /* Read from I/O code path, initialized under BQL */
68 /* Fields protected by BQL */
69 uint8_t *prp_list_pages
;
71 /* Fields protected by @lock */
72 CoQueue free_req_queue
;
76 NVMeRequest reqs
[NVME_NUM_REQS
];
80 /* Thread-safe, no lock necessary */
81 QEMUBH
*completion_bh
;
85 #define INDEX_IO(n) (1 + n)
87 /* This driver shares a single MSIX IRQ for the admin and I/O queues */
89 MSIX_SHARED_IRQ_IDX
= 0,
93 struct BDRVNVMeState
{
94 AioContext
*aio_context
;
96 /* Memory mapped registers */
101 /* The submission/completion queue pairs.
105 NVMeQueuePair
**queues
;
108 /* How many uint32_t elements does each doorbell entry take. */
109 size_t doorbell_scale
;
110 bool write_cache_supported
;
111 EventNotifier irq_notifier
[MSIX_IRQ_COUNT
];
113 uint64_t nsze
; /* Namespace size reported by identify command */
114 int nsid
; /* The namespace id to read/write data. */
117 uint64_t max_transfer
;
120 bool supports_write_zeroes
;
121 bool supports_discard
;
123 CoMutex dma_map_lock
;
124 CoQueue dma_flush_queue
;
126 /* Total size of mapped qiov, accessed under dma_map_lock */
129 /* PCI address (required for nvme_refresh_filename()) */
133 uint64_t completion_errors
;
134 uint64_t aligned_accesses
;
135 uint64_t unaligned_accesses
;
139 #define NVME_BLOCK_OPT_DEVICE "device"
140 #define NVME_BLOCK_OPT_NAMESPACE "namespace"
142 static void nvme_process_completion_bh(void *opaque
);
144 static QemuOptsList runtime_opts
= {
146 .head
= QTAILQ_HEAD_INITIALIZER(runtime_opts
.head
),
149 .name
= NVME_BLOCK_OPT_DEVICE
,
150 .type
= QEMU_OPT_STRING
,
151 .help
= "NVMe PCI device address",
154 .name
= NVME_BLOCK_OPT_NAMESPACE
,
155 .type
= QEMU_OPT_NUMBER
,
156 .help
= "NVMe namespace",
158 { /* end of list */ }
162 static void nvme_init_queue(BDRVNVMeState
*s
, NVMeQueue
*q
,
163 int nentries
, int entry_bytes
, Error
**errp
)
168 bytes
= ROUND_UP(nentries
* entry_bytes
, s
->page_size
);
169 q
->head
= q
->tail
= 0;
170 q
->queue
= qemu_try_memalign(s
->page_size
, bytes
);
172 error_setg(errp
, "Cannot allocate queue");
175 memset(q
->queue
, 0, bytes
);
176 r
= qemu_vfio_dma_map(s
->vfio
, q
->queue
, bytes
, false, &q
->iova
);
178 error_setg(errp
, "Cannot map queue");
182 static void nvme_free_queue_pair(NVMeQueuePair
*q
)
184 if (q
->completion_bh
) {
185 qemu_bh_delete(q
->completion_bh
);
187 qemu_vfree(q
->prp_list_pages
);
188 qemu_vfree(q
->sq
.queue
);
189 qemu_vfree(q
->cq
.queue
);
190 qemu_mutex_destroy(&q
->lock
);
194 static void nvme_free_req_queue_cb(void *opaque
)
196 NVMeQueuePair
*q
= opaque
;
198 qemu_mutex_lock(&q
->lock
);
199 while (qemu_co_enter_next(&q
->free_req_queue
, &q
->lock
)) {
200 /* Retry all pending requests */
202 qemu_mutex_unlock(&q
->lock
);
205 static NVMeQueuePair
*nvme_create_queue_pair(BDRVNVMeState
*s
,
206 AioContext
*aio_context
,
211 Error
*local_err
= NULL
;
213 uint64_t prp_list_iova
;
215 q
= g_try_new0(NVMeQueuePair
, 1);
219 q
->prp_list_pages
= qemu_try_memalign(s
->page_size
,
220 s
->page_size
* NVME_NUM_REQS
);
221 if (!q
->prp_list_pages
) {
224 memset(q
->prp_list_pages
, 0, s
->page_size
* NVME_NUM_REQS
);
225 qemu_mutex_init(&q
->lock
);
228 qemu_co_queue_init(&q
->free_req_queue
);
229 q
->completion_bh
= aio_bh_new(aio_context
, nvme_process_completion_bh
, q
);
230 r
= qemu_vfio_dma_map(s
->vfio
, q
->prp_list_pages
,
231 s
->page_size
* NVME_NUM_REQS
,
232 false, &prp_list_iova
);
236 q
->free_req_head
= -1;
237 for (i
= 0; i
< NVME_NUM_REQS
; i
++) {
238 NVMeRequest
*req
= &q
->reqs
[i
];
240 req
->free_req_next
= q
->free_req_head
;
241 q
->free_req_head
= i
;
242 req
->prp_list_page
= q
->prp_list_pages
+ i
* s
->page_size
;
243 req
->prp_list_iova
= prp_list_iova
+ i
* s
->page_size
;
246 nvme_init_queue(s
, &q
->sq
, size
, NVME_SQ_ENTRY_BYTES
, &local_err
);
248 error_propagate(errp
, local_err
);
251 q
->sq
.doorbell
= &s
->doorbells
[idx
* s
->doorbell_scale
].sq_tail
;
253 nvme_init_queue(s
, &q
->cq
, size
, NVME_CQ_ENTRY_BYTES
, &local_err
);
255 error_propagate(errp
, local_err
);
258 q
->cq
.doorbell
= &s
->doorbells
[idx
* s
->doorbell_scale
].cq_head
;
262 nvme_free_queue_pair(q
);
267 static void nvme_kick(NVMeQueuePair
*q
)
269 BDRVNVMeState
*s
= q
->s
;
271 if (s
->plugged
|| !q
->need_kick
) {
274 trace_nvme_kick(s
, q
->index
);
275 assert(!(q
->sq
.tail
& 0xFF00));
276 /* Fence the write to submission queue entry before notifying the device. */
278 *q
->sq
.doorbell
= cpu_to_le32(q
->sq
.tail
);
279 q
->inflight
+= q
->need_kick
;
283 /* Find a free request element if any, otherwise:
284 * a) if in coroutine context, try to wait for one to become available;
285 * b) if not in coroutine, return NULL;
287 static NVMeRequest
*nvme_get_free_req(NVMeQueuePair
*q
)
291 qemu_mutex_lock(&q
->lock
);
293 while (q
->free_req_head
== -1) {
294 if (qemu_in_coroutine()) {
295 trace_nvme_free_req_queue_wait(q
);
296 qemu_co_queue_wait(&q
->free_req_queue
, &q
->lock
);
298 qemu_mutex_unlock(&q
->lock
);
303 req
= &q
->reqs
[q
->free_req_head
];
304 q
->free_req_head
= req
->free_req_next
;
305 req
->free_req_next
= -1;
307 qemu_mutex_unlock(&q
->lock
);
312 static void nvme_put_free_req_locked(NVMeQueuePair
*q
, NVMeRequest
*req
)
314 req
->free_req_next
= q
->free_req_head
;
315 q
->free_req_head
= req
- q
->reqs
;
319 static void nvme_wake_free_req_locked(NVMeQueuePair
*q
)
321 if (!qemu_co_queue_empty(&q
->free_req_queue
)) {
322 replay_bh_schedule_oneshot_event(q
->s
->aio_context
,
323 nvme_free_req_queue_cb
, q
);
327 /* Insert a request in the freelist and wake waiters */
328 static void nvme_put_free_req_and_wake(NVMeQueuePair
*q
, NVMeRequest
*req
)
330 qemu_mutex_lock(&q
->lock
);
331 nvme_put_free_req_locked(q
, req
);
332 nvme_wake_free_req_locked(q
);
333 qemu_mutex_unlock(&q
->lock
);
336 static inline int nvme_translate_error(const NvmeCqe
*c
)
338 uint16_t status
= (le16_to_cpu(c
->status
) >> 1) & 0xFF;
340 trace_nvme_error(le32_to_cpu(c
->result
),
341 le16_to_cpu(c
->sq_head
),
342 le16_to_cpu(c
->sq_id
),
344 le16_to_cpu(status
));
359 static bool nvme_process_completion(NVMeQueuePair
*q
)
361 BDRVNVMeState
*s
= q
->s
;
362 bool progress
= false;
367 trace_nvme_process_completion(s
, q
->index
, q
->inflight
);
369 trace_nvme_process_completion_queue_plugged(s
, q
->index
);
374 * Support re-entrancy when a request cb() function invokes aio_poll().
375 * Pending completions must be visible to aio_poll() so that a cb()
376 * function can wait for the completion of another request.
378 * The aio_poll() loop will execute our BH and we'll resume completion
381 qemu_bh_schedule(q
->completion_bh
);
383 assert(q
->inflight
>= 0);
384 while (q
->inflight
) {
388 c
= (NvmeCqe
*)&q
->cq
.queue
[q
->cq
.head
* NVME_CQ_ENTRY_BYTES
];
389 if ((le16_to_cpu(c
->status
) & 0x1) == q
->cq_phase
) {
392 ret
= nvme_translate_error(c
);
394 s
->stats
.completion_errors
++;
396 q
->cq
.head
= (q
->cq
.head
+ 1) % NVME_QUEUE_SIZE
;
398 q
->cq_phase
= !q
->cq_phase
;
400 cid
= le16_to_cpu(c
->cid
);
401 if (cid
== 0 || cid
> NVME_QUEUE_SIZE
) {
402 fprintf(stderr
, "Unexpected CID in completion queue: %" PRIu32
"\n",
406 trace_nvme_complete_command(s
, q
->index
, cid
);
407 preq
= &q
->reqs
[cid
- 1];
409 assert(req
.cid
== cid
);
411 nvme_put_free_req_locked(q
, preq
);
412 preq
->cb
= preq
->opaque
= NULL
;
414 qemu_mutex_unlock(&q
->lock
);
415 req
.cb(req
.opaque
, ret
);
416 qemu_mutex_lock(&q
->lock
);
420 /* Notify the device so it can post more completions. */
422 *q
->cq
.doorbell
= cpu_to_le32(q
->cq
.head
);
423 nvme_wake_free_req_locked(q
);
426 qemu_bh_cancel(q
->completion_bh
);
431 static void nvme_process_completion_bh(void *opaque
)
433 NVMeQueuePair
*q
= opaque
;
436 * We're being invoked because a nvme_process_completion() cb() function
437 * called aio_poll(). The callback may be waiting for further completions
438 * so notify the device that it has space to fill in more completions now.
441 *q
->cq
.doorbell
= cpu_to_le32(q
->cq
.head
);
442 nvme_wake_free_req_locked(q
);
444 nvme_process_completion(q
);
447 static void nvme_trace_command(const NvmeCmd
*cmd
)
451 if (!trace_event_get_state_backends(TRACE_NVME_SUBMIT_COMMAND_RAW
)) {
454 for (i
= 0; i
< 8; ++i
) {
455 uint8_t *cmdp
= (uint8_t *)cmd
+ i
* 8;
456 trace_nvme_submit_command_raw(cmdp
[0], cmdp
[1], cmdp
[2], cmdp
[3],
457 cmdp
[4], cmdp
[5], cmdp
[6], cmdp
[7]);
461 static void nvme_submit_command(NVMeQueuePair
*q
, NVMeRequest
*req
,
462 NvmeCmd
*cmd
, BlockCompletionFunc cb
,
467 req
->opaque
= opaque
;
468 cmd
->cid
= cpu_to_le32(req
->cid
);
470 trace_nvme_submit_command(q
->s
, q
->index
, req
->cid
);
471 nvme_trace_command(cmd
);
472 qemu_mutex_lock(&q
->lock
);
473 memcpy((uint8_t *)q
->sq
.queue
+
474 q
->sq
.tail
* NVME_SQ_ENTRY_BYTES
, cmd
, sizeof(*cmd
));
475 q
->sq
.tail
= (q
->sq
.tail
+ 1) % NVME_QUEUE_SIZE
;
478 nvme_process_completion(q
);
479 qemu_mutex_unlock(&q
->lock
);
482 static void nvme_cmd_sync_cb(void *opaque
, int ret
)
489 static int nvme_cmd_sync(BlockDriverState
*bs
, NVMeQueuePair
*q
,
492 AioContext
*aio_context
= bdrv_get_aio_context(bs
);
494 int ret
= -EINPROGRESS
;
495 req
= nvme_get_free_req(q
);
499 nvme_submit_command(q
, req
, cmd
, nvme_cmd_sync_cb
, &ret
);
501 AIO_WAIT_WHILE(aio_context
, ret
== -EINPROGRESS
);
505 static void nvme_identify(BlockDriverState
*bs
, int namespace, Error
**errp
)
507 BDRVNVMeState
*s
= bs
->opaque
;
517 .opcode
= NVME_ADM_CMD_IDENTIFY
,
518 .cdw10
= cpu_to_le32(0x1),
521 id
= qemu_try_memalign(s
->page_size
, sizeof(*id
));
523 error_setg(errp
, "Cannot allocate buffer for identify response");
526 r
= qemu_vfio_dma_map(s
->vfio
, id
, sizeof(*id
), true, &iova
);
528 error_setg(errp
, "Cannot map buffer for DMA");
532 memset(id
, 0, sizeof(*id
));
533 cmd
.dptr
.prp1
= cpu_to_le64(iova
);
534 if (nvme_cmd_sync(bs
, s
->queues
[INDEX_ADMIN
], &cmd
)) {
535 error_setg(errp
, "Failed to identify controller");
539 if (le32_to_cpu(id
->ctrl
.nn
) < namespace) {
540 error_setg(errp
, "Invalid namespace");
543 s
->write_cache_supported
= le32_to_cpu(id
->ctrl
.vwc
) & 0x1;
544 s
->max_transfer
= (id
->ctrl
.mdts
? 1 << id
->ctrl
.mdts
: 0) * s
->page_size
;
545 /* For now the page list buffer per command is one page, to hold at most
546 * s->page_size / sizeof(uint64_t) entries. */
547 s
->max_transfer
= MIN_NON_ZERO(s
->max_transfer
,
548 s
->page_size
/ sizeof(uint64_t) * s
->page_size
);
550 oncs
= le16_to_cpu(id
->ctrl
.oncs
);
551 s
->supports_write_zeroes
= !!(oncs
& NVME_ONCS_WRITE_ZEROES
);
552 s
->supports_discard
= !!(oncs
& NVME_ONCS_DSM
);
554 memset(id
, 0, sizeof(*id
));
556 cmd
.nsid
= cpu_to_le32(namespace);
557 if (nvme_cmd_sync(bs
, s
->queues
[INDEX_ADMIN
], &cmd
)) {
558 error_setg(errp
, "Failed to identify namespace");
562 s
->nsze
= le64_to_cpu(id
->ns
.nsze
);
563 lbaf
= &id
->ns
.lbaf
[NVME_ID_NS_FLBAS_INDEX(id
->ns
.flbas
)];
565 if (NVME_ID_NS_DLFEAT_WRITE_ZEROES(id
->ns
.dlfeat
) &&
566 NVME_ID_NS_DLFEAT_READ_BEHAVIOR(id
->ns
.dlfeat
) ==
567 NVME_ID_NS_DLFEAT_READ_BEHAVIOR_ZEROES
) {
568 bs
->supported_write_flags
|= BDRV_REQ_MAY_UNMAP
;
572 error_setg(errp
, "Namespaces with metadata are not yet supported");
576 if (lbaf
->ds
< BDRV_SECTOR_BITS
|| lbaf
->ds
> 12 ||
577 (1 << lbaf
->ds
) > s
->page_size
)
579 error_setg(errp
, "Namespace has unsupported block size (2^%d)",
584 s
->blkshift
= lbaf
->ds
;
586 qemu_vfio_dma_unmap(s
->vfio
, id
);
590 static bool nvme_poll_queue(NVMeQueuePair
*q
)
592 bool progress
= false;
594 const size_t cqe_offset
= q
->cq
.head
* NVME_CQ_ENTRY_BYTES
;
595 NvmeCqe
*cqe
= (NvmeCqe
*)&q
->cq
.queue
[cqe_offset
];
598 * Do an early check for completions. q->lock isn't needed because
599 * nvme_process_completion() only runs in the event loop thread and
600 * cannot race with itself.
602 if ((le16_to_cpu(cqe
->status
) & 0x1) == q
->cq_phase
) {
606 qemu_mutex_lock(&q
->lock
);
607 while (nvme_process_completion(q
)) {
611 qemu_mutex_unlock(&q
->lock
);
616 static bool nvme_poll_queues(BDRVNVMeState
*s
)
618 bool progress
= false;
621 for (i
= 0; i
< s
->nr_queues
; i
++) {
622 if (nvme_poll_queue(s
->queues
[i
])) {
629 static void nvme_handle_event(EventNotifier
*n
)
631 BDRVNVMeState
*s
= container_of(n
, BDRVNVMeState
,
632 irq_notifier
[MSIX_SHARED_IRQ_IDX
]);
634 trace_nvme_handle_event(s
);
635 event_notifier_test_and_clear(n
);
639 static bool nvme_add_io_queue(BlockDriverState
*bs
, Error
**errp
)
641 BDRVNVMeState
*s
= bs
->opaque
;
642 int n
= s
->nr_queues
;
645 int queue_size
= NVME_QUEUE_SIZE
;
647 q
= nvme_create_queue_pair(s
, bdrv_get_aio_context(bs
),
648 n
, queue_size
, errp
);
653 .opcode
= NVME_ADM_CMD_CREATE_CQ
,
654 .dptr
.prp1
= cpu_to_le64(q
->cq
.iova
),
655 .cdw10
= cpu_to_le32(((queue_size
- 1) << 16) | (n
& 0xFFFF)),
656 .cdw11
= cpu_to_le32(0x3),
658 if (nvme_cmd_sync(bs
, s
->queues
[INDEX_ADMIN
], &cmd
)) {
659 error_setg(errp
, "Failed to create CQ io queue [%d]", n
);
663 .opcode
= NVME_ADM_CMD_CREATE_SQ
,
664 .dptr
.prp1
= cpu_to_le64(q
->sq
.iova
),
665 .cdw10
= cpu_to_le32(((queue_size
- 1) << 16) | (n
& 0xFFFF)),
666 .cdw11
= cpu_to_le32(0x1 | (n
<< 16)),
668 if (nvme_cmd_sync(bs
, s
->queues
[INDEX_ADMIN
], &cmd
)) {
669 error_setg(errp
, "Failed to create SQ io queue [%d]", n
);
672 s
->queues
= g_renew(NVMeQueuePair
*, s
->queues
, n
+ 1);
677 nvme_free_queue_pair(q
);
681 static bool nvme_poll_cb(void *opaque
)
683 EventNotifier
*e
= opaque
;
684 BDRVNVMeState
*s
= container_of(e
, BDRVNVMeState
,
685 irq_notifier
[MSIX_SHARED_IRQ_IDX
]);
687 trace_nvme_poll_cb(s
);
688 return nvme_poll_queues(s
);
691 static int nvme_init(BlockDriverState
*bs
, const char *device
, int namespace,
694 BDRVNVMeState
*s
= bs
->opaque
;
695 AioContext
*aio_context
= bdrv_get_aio_context(bs
);
699 uint64_t deadline
, now
;
700 Error
*local_err
= NULL
;
701 volatile NvmeBar
*regs
= NULL
;
703 qemu_co_mutex_init(&s
->dma_map_lock
);
704 qemu_co_queue_init(&s
->dma_flush_queue
);
705 s
->device
= g_strdup(device
);
707 s
->aio_context
= bdrv_get_aio_context(bs
);
708 ret
= event_notifier_init(&s
->irq_notifier
[MSIX_SHARED_IRQ_IDX
], 0);
710 error_setg(errp
, "Failed to init event notifier");
714 s
->vfio
= qemu_vfio_open_pci(device
, errp
);
720 regs
= qemu_vfio_pci_map_bar(s
->vfio
, 0, 0, sizeof(NvmeBar
),
721 PROT_READ
| PROT_WRITE
, errp
);
726 /* Perform initialize sequence as described in NVMe spec "7.6.1
727 * Initialization". */
729 cap
= le64_to_cpu(regs
->cap
);
730 if (!NVME_CAP_CSS(cap
)) {
731 error_setg(errp
, "Device doesn't support NVMe command set");
736 s
->page_size
= MAX(4096, 1 << NVME_CAP_MPSMIN(cap
));
737 s
->doorbell_scale
= (4 << NVME_CAP_DSTRD(cap
)) / sizeof(uint32_t);
738 bs
->bl
.opt_mem_alignment
= s
->page_size
;
739 timeout_ms
= MIN(500 * NVME_CAP_TO(cap
), 30000);
741 /* Reset device to get a clean state. */
742 regs
->cc
= cpu_to_le32(le32_to_cpu(regs
->cc
) & 0xFE);
743 /* Wait for CSTS.RDY = 0. */
744 deadline
= qemu_clock_get_ns(QEMU_CLOCK_REALTIME
) + timeout_ms
* SCALE_MS
;
745 while (NVME_CSTS_RDY(le32_to_cpu(regs
->csts
))) {
746 if (qemu_clock_get_ns(QEMU_CLOCK_REALTIME
) > deadline
) {
747 error_setg(errp
, "Timeout while waiting for device to reset (%"
755 s
->doorbells
= qemu_vfio_pci_map_bar(s
->vfio
, 0, sizeof(NvmeBar
),
756 NVME_DOORBELL_SIZE
, PROT_WRITE
, errp
);
762 /* Set up admin queue. */
763 s
->queues
= g_new(NVMeQueuePair
*, 1);
764 s
->queues
[INDEX_ADMIN
] = nvme_create_queue_pair(s
, aio_context
, 0,
767 if (!s
->queues
[INDEX_ADMIN
]) {
772 QEMU_BUILD_BUG_ON(NVME_QUEUE_SIZE
& 0xF000);
773 regs
->aqa
= cpu_to_le32((NVME_QUEUE_SIZE
<< AQA_ACQS_SHIFT
) |
774 (NVME_QUEUE_SIZE
<< AQA_ASQS_SHIFT
));
775 regs
->asq
= cpu_to_le64(s
->queues
[INDEX_ADMIN
]->sq
.iova
);
776 regs
->acq
= cpu_to_le64(s
->queues
[INDEX_ADMIN
]->cq
.iova
);
778 /* After setting up all control registers we can enable device now. */
779 regs
->cc
= cpu_to_le32((ctz32(NVME_CQ_ENTRY_BYTES
) << CC_IOCQES_SHIFT
) |
780 (ctz32(NVME_SQ_ENTRY_BYTES
) << CC_IOSQES_SHIFT
) |
782 /* Wait for CSTS.RDY = 1. */
783 now
= qemu_clock_get_ns(QEMU_CLOCK_REALTIME
);
784 deadline
= now
+ timeout_ms
* SCALE_MS
;
785 while (!NVME_CSTS_RDY(le32_to_cpu(regs
->csts
))) {
786 if (qemu_clock_get_ns(QEMU_CLOCK_REALTIME
) > deadline
) {
787 error_setg(errp
, "Timeout while waiting for device to start (%"
795 ret
= qemu_vfio_pci_init_irq(s
->vfio
, s
->irq_notifier
,
796 VFIO_PCI_MSIX_IRQ_INDEX
, errp
);
800 aio_set_event_notifier(bdrv_get_aio_context(bs
),
801 &s
->irq_notifier
[MSIX_SHARED_IRQ_IDX
],
802 false, nvme_handle_event
, nvme_poll_cb
);
804 nvme_identify(bs
, namespace, &local_err
);
806 error_propagate(errp
, local_err
);
811 /* Set up command queues. */
812 if (!nvme_add_io_queue(bs
, errp
)) {
817 qemu_vfio_pci_unmap_bar(s
->vfio
, 0, (void *)regs
, 0, sizeof(NvmeBar
));
820 /* Cleaning up is done in nvme_file_open() upon error. */
824 /* Parse a filename in the format of nvme://XXXX:XX:XX.X/X. Example:
826 * nvme://0000:44:00.0/1
828 * where the "nvme://" is a fixed form of the protocol prefix, the middle part
829 * is the PCI address, and the last part is the namespace number starting from
830 * 1 according to the NVMe spec. */
831 static void nvme_parse_filename(const char *filename
, QDict
*options
,
834 int pref
= strlen("nvme://");
836 if (strlen(filename
) > pref
&& !strncmp(filename
, "nvme://", pref
)) {
837 const char *tmp
= filename
+ pref
;
839 const char *namespace;
841 const char *slash
= strchr(tmp
, '/');
843 qdict_put_str(options
, NVME_BLOCK_OPT_DEVICE
, tmp
);
846 device
= g_strndup(tmp
, slash
- tmp
);
847 qdict_put_str(options
, NVME_BLOCK_OPT_DEVICE
, device
);
849 namespace = slash
+ 1;
850 if (*namespace && qemu_strtoul(namespace, NULL
, 10, &ns
)) {
851 error_setg(errp
, "Invalid namespace '%s', positive number expected",
855 qdict_put_str(options
, NVME_BLOCK_OPT_NAMESPACE
,
856 *namespace ? namespace : "1");
860 static int nvme_enable_disable_write_cache(BlockDriverState
*bs
, bool enable
,
864 BDRVNVMeState
*s
= bs
->opaque
;
866 .opcode
= NVME_ADM_CMD_SET_FEATURES
,
867 .nsid
= cpu_to_le32(s
->nsid
),
868 .cdw10
= cpu_to_le32(0x06),
869 .cdw11
= cpu_to_le32(enable
? 0x01 : 0x00),
872 ret
= nvme_cmd_sync(bs
, s
->queues
[INDEX_ADMIN
], &cmd
);
874 error_setg(errp
, "Failed to configure NVMe write cache");
879 static void nvme_close(BlockDriverState
*bs
)
882 BDRVNVMeState
*s
= bs
->opaque
;
884 for (i
= 0; i
< s
->nr_queues
; ++i
) {
885 nvme_free_queue_pair(s
->queues
[i
]);
888 aio_set_event_notifier(bdrv_get_aio_context(bs
),
889 &s
->irq_notifier
[MSIX_SHARED_IRQ_IDX
],
891 event_notifier_cleanup(&s
->irq_notifier
[MSIX_SHARED_IRQ_IDX
]);
892 qemu_vfio_pci_unmap_bar(s
->vfio
, 0, (void *)s
->doorbells
,
893 sizeof(NvmeBar
), NVME_DOORBELL_SIZE
);
894 qemu_vfio_close(s
->vfio
);
899 static int nvme_file_open(BlockDriverState
*bs
, QDict
*options
, int flags
,
906 BDRVNVMeState
*s
= bs
->opaque
;
908 bs
->supported_write_flags
= BDRV_REQ_FUA
;
910 opts
= qemu_opts_create(&runtime_opts
, NULL
, 0, &error_abort
);
911 qemu_opts_absorb_qdict(opts
, options
, &error_abort
);
912 device
= qemu_opt_get(opts
, NVME_BLOCK_OPT_DEVICE
);
914 error_setg(errp
, "'" NVME_BLOCK_OPT_DEVICE
"' option is required");
919 namespace = qemu_opt_get_number(opts
, NVME_BLOCK_OPT_NAMESPACE
, 1);
920 ret
= nvme_init(bs
, device
, namespace, errp
);
925 if (flags
& BDRV_O_NOCACHE
) {
926 if (!s
->write_cache_supported
) {
928 "NVMe controller doesn't support write cache configuration");
931 ret
= nvme_enable_disable_write_cache(bs
, !(flags
& BDRV_O_NOCACHE
),
944 static int64_t nvme_getlength(BlockDriverState
*bs
)
946 BDRVNVMeState
*s
= bs
->opaque
;
947 return s
->nsze
<< s
->blkshift
;
950 static uint32_t nvme_get_blocksize(BlockDriverState
*bs
)
952 BDRVNVMeState
*s
= bs
->opaque
;
953 assert(s
->blkshift
>= BDRV_SECTOR_BITS
&& s
->blkshift
<= 12);
954 return UINT32_C(1) << s
->blkshift
;
957 static int nvme_probe_blocksizes(BlockDriverState
*bs
, BlockSizes
*bsz
)
959 uint32_t blocksize
= nvme_get_blocksize(bs
);
960 bsz
->phys
= blocksize
;
961 bsz
->log
= blocksize
;
965 /* Called with s->dma_map_lock */
966 static coroutine_fn
int nvme_cmd_unmap_qiov(BlockDriverState
*bs
,
970 BDRVNVMeState
*s
= bs
->opaque
;
972 s
->dma_map_count
-= qiov
->size
;
973 if (!s
->dma_map_count
&& !qemu_co_queue_empty(&s
->dma_flush_queue
)) {
974 r
= qemu_vfio_dma_reset_temporary(s
->vfio
);
976 qemu_co_queue_restart_all(&s
->dma_flush_queue
);
982 /* Called with s->dma_map_lock */
983 static coroutine_fn
int nvme_cmd_map_qiov(BlockDriverState
*bs
, NvmeCmd
*cmd
,
984 NVMeRequest
*req
, QEMUIOVector
*qiov
)
986 BDRVNVMeState
*s
= bs
->opaque
;
987 uint64_t *pagelist
= req
->prp_list_page
;
992 assert(QEMU_IS_ALIGNED(qiov
->size
, s
->page_size
));
993 assert(qiov
->size
/ s
->page_size
<= s
->page_size
/ sizeof(uint64_t));
994 for (i
= 0; i
< qiov
->niov
; ++i
) {
998 r
= qemu_vfio_dma_map(s
->vfio
,
999 qiov
->iov
[i
].iov_base
,
1000 qiov
->iov
[i
].iov_len
,
1002 if (r
== -ENOMEM
&& retry
) {
1004 trace_nvme_dma_flush_queue_wait(s
);
1005 if (s
->dma_map_count
) {
1006 trace_nvme_dma_map_flush(s
);
1007 qemu_co_queue_wait(&s
->dma_flush_queue
, &s
->dma_map_lock
);
1009 r
= qemu_vfio_dma_reset_temporary(s
->vfio
);
1020 for (j
= 0; j
< qiov
->iov
[i
].iov_len
/ s
->page_size
; j
++) {
1021 pagelist
[entries
++] = cpu_to_le64(iova
+ j
* s
->page_size
);
1023 trace_nvme_cmd_map_qiov_iov(s
, i
, qiov
->iov
[i
].iov_base
,
1024 qiov
->iov
[i
].iov_len
/ s
->page_size
);
1027 s
->dma_map_count
+= qiov
->size
;
1029 assert(entries
<= s
->page_size
/ sizeof(uint64_t));
1034 cmd
->dptr
.prp1
= pagelist
[0];
1038 cmd
->dptr
.prp1
= pagelist
[0];
1039 cmd
->dptr
.prp2
= pagelist
[1];
1042 cmd
->dptr
.prp1
= pagelist
[0];
1043 cmd
->dptr
.prp2
= cpu_to_le64(req
->prp_list_iova
+ sizeof(uint64_t));
1046 trace_nvme_cmd_map_qiov(s
, cmd
, req
, qiov
, entries
);
1047 for (i
= 0; i
< entries
; ++i
) {
1048 trace_nvme_cmd_map_qiov_pages(s
, i
, pagelist
[i
]);
1052 /* No need to unmap [0 - i) iovs even if we've failed, since we don't
1053 * increment s->dma_map_count. This is okay for fixed mapping memory areas
1054 * because they are already mapped before calling this function; for
1055 * temporary mappings, a later nvme_cmd_(un)map_qiov will reclaim by
1056 * calling qemu_vfio_dma_reset_temporary when necessary. */
1066 static void nvme_rw_cb_bh(void *opaque
)
1068 NVMeCoData
*data
= opaque
;
1069 qemu_coroutine_enter(data
->co
);
1072 static void nvme_rw_cb(void *opaque
, int ret
)
1074 NVMeCoData
*data
= opaque
;
1077 /* The rw coroutine hasn't yielded, don't try to enter. */
1080 replay_bh_schedule_oneshot_event(data
->ctx
, nvme_rw_cb_bh
, data
);
1083 static coroutine_fn
int nvme_co_prw_aligned(BlockDriverState
*bs
,
1084 uint64_t offset
, uint64_t bytes
,
1090 BDRVNVMeState
*s
= bs
->opaque
;
1091 NVMeQueuePair
*ioq
= s
->queues
[INDEX_IO(0)];
1094 uint32_t cdw12
= (((bytes
>> s
->blkshift
) - 1) & 0xFFFF) |
1095 (flags
& BDRV_REQ_FUA
? 1 << 30 : 0);
1097 .opcode
= is_write
? NVME_CMD_WRITE
: NVME_CMD_READ
,
1098 .nsid
= cpu_to_le32(s
->nsid
),
1099 .cdw10
= cpu_to_le32((offset
>> s
->blkshift
) & 0xFFFFFFFF),
1100 .cdw11
= cpu_to_le32(((offset
>> s
->blkshift
) >> 32) & 0xFFFFFFFF),
1101 .cdw12
= cpu_to_le32(cdw12
),
1104 .ctx
= bdrv_get_aio_context(bs
),
1105 .ret
= -EINPROGRESS
,
1108 trace_nvme_prw_aligned(s
, is_write
, offset
, bytes
, flags
, qiov
->niov
);
1109 assert(s
->nr_queues
> 1);
1110 req
= nvme_get_free_req(ioq
);
1113 qemu_co_mutex_lock(&s
->dma_map_lock
);
1114 r
= nvme_cmd_map_qiov(bs
, &cmd
, req
, qiov
);
1115 qemu_co_mutex_unlock(&s
->dma_map_lock
);
1117 nvme_put_free_req_and_wake(ioq
, req
);
1120 nvme_submit_command(ioq
, req
, &cmd
, nvme_rw_cb
, &data
);
1122 data
.co
= qemu_coroutine_self();
1123 while (data
.ret
== -EINPROGRESS
) {
1124 qemu_coroutine_yield();
1127 qemu_co_mutex_lock(&s
->dma_map_lock
);
1128 r
= nvme_cmd_unmap_qiov(bs
, qiov
);
1129 qemu_co_mutex_unlock(&s
->dma_map_lock
);
1134 trace_nvme_rw_done(s
, is_write
, offset
, bytes
, data
.ret
);
1138 static inline bool nvme_qiov_aligned(BlockDriverState
*bs
,
1139 const QEMUIOVector
*qiov
)
1142 BDRVNVMeState
*s
= bs
->opaque
;
1144 for (i
= 0; i
< qiov
->niov
; ++i
) {
1145 if (!QEMU_PTR_IS_ALIGNED(qiov
->iov
[i
].iov_base
, s
->page_size
) ||
1146 !QEMU_IS_ALIGNED(qiov
->iov
[i
].iov_len
, s
->page_size
)) {
1147 trace_nvme_qiov_unaligned(qiov
, i
, qiov
->iov
[i
].iov_base
,
1148 qiov
->iov
[i
].iov_len
, s
->page_size
);
1155 static int nvme_co_prw(BlockDriverState
*bs
, uint64_t offset
, uint64_t bytes
,
1156 QEMUIOVector
*qiov
, bool is_write
, int flags
)
1158 BDRVNVMeState
*s
= bs
->opaque
;
1160 uint8_t *buf
= NULL
;
1161 QEMUIOVector local_qiov
;
1163 assert(QEMU_IS_ALIGNED(offset
, s
->page_size
));
1164 assert(QEMU_IS_ALIGNED(bytes
, s
->page_size
));
1165 assert(bytes
<= s
->max_transfer
);
1166 if (nvme_qiov_aligned(bs
, qiov
)) {
1167 s
->stats
.aligned_accesses
++;
1168 return nvme_co_prw_aligned(bs
, offset
, bytes
, qiov
, is_write
, flags
);
1170 s
->stats
.unaligned_accesses
++;
1171 trace_nvme_prw_buffered(s
, offset
, bytes
, qiov
->niov
, is_write
);
1172 buf
= qemu_try_memalign(s
->page_size
, bytes
);
1177 qemu_iovec_init(&local_qiov
, 1);
1179 qemu_iovec_to_buf(qiov
, 0, buf
, bytes
);
1181 qemu_iovec_add(&local_qiov
, buf
, bytes
);
1182 r
= nvme_co_prw_aligned(bs
, offset
, bytes
, &local_qiov
, is_write
, flags
);
1183 qemu_iovec_destroy(&local_qiov
);
1184 if (!r
&& !is_write
) {
1185 qemu_iovec_from_buf(qiov
, 0, buf
, bytes
);
1191 static coroutine_fn
int nvme_co_preadv(BlockDriverState
*bs
,
1192 uint64_t offset
, uint64_t bytes
,
1193 QEMUIOVector
*qiov
, int flags
)
1195 return nvme_co_prw(bs
, offset
, bytes
, qiov
, false, flags
);
1198 static coroutine_fn
int nvme_co_pwritev(BlockDriverState
*bs
,
1199 uint64_t offset
, uint64_t bytes
,
1200 QEMUIOVector
*qiov
, int flags
)
1202 return nvme_co_prw(bs
, offset
, bytes
, qiov
, true, flags
);
1205 static coroutine_fn
int nvme_co_flush(BlockDriverState
*bs
)
1207 BDRVNVMeState
*s
= bs
->opaque
;
1208 NVMeQueuePair
*ioq
= s
->queues
[INDEX_IO(0)];
1211 .opcode
= NVME_CMD_FLUSH
,
1212 .nsid
= cpu_to_le32(s
->nsid
),
1215 .ctx
= bdrv_get_aio_context(bs
),
1216 .ret
= -EINPROGRESS
,
1219 assert(s
->nr_queues
> 1);
1220 req
= nvme_get_free_req(ioq
);
1222 nvme_submit_command(ioq
, req
, &cmd
, nvme_rw_cb
, &data
);
1224 data
.co
= qemu_coroutine_self();
1225 if (data
.ret
== -EINPROGRESS
) {
1226 qemu_coroutine_yield();
1233 static coroutine_fn
int nvme_co_pwrite_zeroes(BlockDriverState
*bs
,
1236 BdrvRequestFlags flags
)
1238 BDRVNVMeState
*s
= bs
->opaque
;
1239 NVMeQueuePair
*ioq
= s
->queues
[INDEX_IO(0)];
1242 uint32_t cdw12
= ((bytes
>> s
->blkshift
) - 1) & 0xFFFF;
1244 if (!s
->supports_write_zeroes
) {
1249 .opcode
= NVME_CMD_WRITE_ZEROES
,
1250 .nsid
= cpu_to_le32(s
->nsid
),
1251 .cdw10
= cpu_to_le32((offset
>> s
->blkshift
) & 0xFFFFFFFF),
1252 .cdw11
= cpu_to_le32(((offset
>> s
->blkshift
) >> 32) & 0xFFFFFFFF),
1256 .ctx
= bdrv_get_aio_context(bs
),
1257 .ret
= -EINPROGRESS
,
1260 if (flags
& BDRV_REQ_MAY_UNMAP
) {
1264 if (flags
& BDRV_REQ_FUA
) {
1268 cmd
.cdw12
= cpu_to_le32(cdw12
);
1270 trace_nvme_write_zeroes(s
, offset
, bytes
, flags
);
1271 assert(s
->nr_queues
> 1);
1272 req
= nvme_get_free_req(ioq
);
1275 nvme_submit_command(ioq
, req
, &cmd
, nvme_rw_cb
, &data
);
1277 data
.co
= qemu_coroutine_self();
1278 while (data
.ret
== -EINPROGRESS
) {
1279 qemu_coroutine_yield();
1282 trace_nvme_rw_done(s
, true, offset
, bytes
, data
.ret
);
1287 static int coroutine_fn
nvme_co_pdiscard(BlockDriverState
*bs
,
1291 BDRVNVMeState
*s
= bs
->opaque
;
1292 NVMeQueuePair
*ioq
= s
->queues
[INDEX_IO(0)];
1295 QEMUIOVector local_qiov
;
1299 .opcode
= NVME_CMD_DSM
,
1300 .nsid
= cpu_to_le32(s
->nsid
),
1301 .cdw10
= cpu_to_le32(0), /*number of ranges - 0 based*/
1302 .cdw11
= cpu_to_le32(1 << 2), /*deallocate bit*/
1306 .ctx
= bdrv_get_aio_context(bs
),
1307 .ret
= -EINPROGRESS
,
1310 if (!s
->supports_discard
) {
1314 assert(s
->nr_queues
> 1);
1316 buf
= qemu_try_memalign(s
->page_size
, s
->page_size
);
1320 memset(buf
, 0, s
->page_size
);
1321 buf
->nlb
= cpu_to_le32(bytes
>> s
->blkshift
);
1322 buf
->slba
= cpu_to_le64(offset
>> s
->blkshift
);
1325 qemu_iovec_init(&local_qiov
, 1);
1326 qemu_iovec_add(&local_qiov
, buf
, 4096);
1328 req
= nvme_get_free_req(ioq
);
1331 qemu_co_mutex_lock(&s
->dma_map_lock
);
1332 ret
= nvme_cmd_map_qiov(bs
, &cmd
, req
, &local_qiov
);
1333 qemu_co_mutex_unlock(&s
->dma_map_lock
);
1336 nvme_put_free_req_and_wake(ioq
, req
);
1340 trace_nvme_dsm(s
, offset
, bytes
);
1342 nvme_submit_command(ioq
, req
, &cmd
, nvme_rw_cb
, &data
);
1344 data
.co
= qemu_coroutine_self();
1345 while (data
.ret
== -EINPROGRESS
) {
1346 qemu_coroutine_yield();
1349 qemu_co_mutex_lock(&s
->dma_map_lock
);
1350 ret
= nvme_cmd_unmap_qiov(bs
, &local_qiov
);
1351 qemu_co_mutex_unlock(&s
->dma_map_lock
);
1358 trace_nvme_dsm_done(s
, offset
, bytes
, ret
);
1360 qemu_iovec_destroy(&local_qiov
);
1367 static int nvme_reopen_prepare(BDRVReopenState
*reopen_state
,
1368 BlockReopenQueue
*queue
, Error
**errp
)
1373 static void nvme_refresh_filename(BlockDriverState
*bs
)
1375 BDRVNVMeState
*s
= bs
->opaque
;
1377 snprintf(bs
->exact_filename
, sizeof(bs
->exact_filename
), "nvme://%s/%i",
1378 s
->device
, s
->nsid
);
1381 static void nvme_refresh_limits(BlockDriverState
*bs
, Error
**errp
)
1383 BDRVNVMeState
*s
= bs
->opaque
;
1385 bs
->bl
.opt_mem_alignment
= s
->page_size
;
1386 bs
->bl
.request_alignment
= s
->page_size
;
1387 bs
->bl
.max_transfer
= s
->max_transfer
;
1390 static void nvme_detach_aio_context(BlockDriverState
*bs
)
1392 BDRVNVMeState
*s
= bs
->opaque
;
1394 for (int i
= 0; i
< s
->nr_queues
; i
++) {
1395 NVMeQueuePair
*q
= s
->queues
[i
];
1397 qemu_bh_delete(q
->completion_bh
);
1398 q
->completion_bh
= NULL
;
1401 aio_set_event_notifier(bdrv_get_aio_context(bs
),
1402 &s
->irq_notifier
[MSIX_SHARED_IRQ_IDX
],
1406 static void nvme_attach_aio_context(BlockDriverState
*bs
,
1407 AioContext
*new_context
)
1409 BDRVNVMeState
*s
= bs
->opaque
;
1411 s
->aio_context
= new_context
;
1412 aio_set_event_notifier(new_context
, &s
->irq_notifier
[MSIX_SHARED_IRQ_IDX
],
1413 false, nvme_handle_event
, nvme_poll_cb
);
1415 for (int i
= 0; i
< s
->nr_queues
; i
++) {
1416 NVMeQueuePair
*q
= s
->queues
[i
];
1419 aio_bh_new(new_context
, nvme_process_completion_bh
, q
);
1423 static void nvme_aio_plug(BlockDriverState
*bs
)
1425 BDRVNVMeState
*s
= bs
->opaque
;
1426 assert(!s
->plugged
);
1430 static void nvme_aio_unplug(BlockDriverState
*bs
)
1433 BDRVNVMeState
*s
= bs
->opaque
;
1436 for (i
= INDEX_IO(0); i
< s
->nr_queues
; i
++) {
1437 NVMeQueuePair
*q
= s
->queues
[i
];
1438 qemu_mutex_lock(&q
->lock
);
1440 nvme_process_completion(q
);
1441 qemu_mutex_unlock(&q
->lock
);
1445 static void nvme_register_buf(BlockDriverState
*bs
, void *host
, size_t size
)
1448 BDRVNVMeState
*s
= bs
->opaque
;
1450 ret
= qemu_vfio_dma_map(s
->vfio
, host
, size
, false, NULL
);
1452 /* FIXME: we may run out of IOVA addresses after repeated
1453 * bdrv_register_buf/bdrv_unregister_buf, because nvme_vfio_dma_unmap
1454 * doesn't reclaim addresses for fixed mappings. */
1455 error_report("nvme_register_buf failed: %s", strerror(-ret
));
1459 static void nvme_unregister_buf(BlockDriverState
*bs
, void *host
)
1461 BDRVNVMeState
*s
= bs
->opaque
;
1463 qemu_vfio_dma_unmap(s
->vfio
, host
);
1466 static BlockStatsSpecific
*nvme_get_specific_stats(BlockDriverState
*bs
)
1468 BlockStatsSpecific
*stats
= g_new(BlockStatsSpecific
, 1);
1469 BDRVNVMeState
*s
= bs
->opaque
;
1471 stats
->driver
= BLOCKDEV_DRIVER_NVME
;
1472 stats
->u
.nvme
= (BlockStatsSpecificNvme
) {
1473 .completion_errors
= s
->stats
.completion_errors
,
1474 .aligned_accesses
= s
->stats
.aligned_accesses
,
1475 .unaligned_accesses
= s
->stats
.unaligned_accesses
,
1481 static const char *const nvme_strong_runtime_opts
[] = {
1482 NVME_BLOCK_OPT_DEVICE
,
1483 NVME_BLOCK_OPT_NAMESPACE
,
1488 static BlockDriver bdrv_nvme
= {
1489 .format_name
= "nvme",
1490 .protocol_name
= "nvme",
1491 .instance_size
= sizeof(BDRVNVMeState
),
1493 .bdrv_co_create_opts
= bdrv_co_create_opts_simple
,
1494 .create_opts
= &bdrv_create_opts_simple
,
1496 .bdrv_parse_filename
= nvme_parse_filename
,
1497 .bdrv_file_open
= nvme_file_open
,
1498 .bdrv_close
= nvme_close
,
1499 .bdrv_getlength
= nvme_getlength
,
1500 .bdrv_probe_blocksizes
= nvme_probe_blocksizes
,
1502 .bdrv_co_preadv
= nvme_co_preadv
,
1503 .bdrv_co_pwritev
= nvme_co_pwritev
,
1505 .bdrv_co_pwrite_zeroes
= nvme_co_pwrite_zeroes
,
1506 .bdrv_co_pdiscard
= nvme_co_pdiscard
,
1508 .bdrv_co_flush_to_disk
= nvme_co_flush
,
1509 .bdrv_reopen_prepare
= nvme_reopen_prepare
,
1511 .bdrv_refresh_filename
= nvme_refresh_filename
,
1512 .bdrv_refresh_limits
= nvme_refresh_limits
,
1513 .strong_runtime_opts
= nvme_strong_runtime_opts
,
1514 .bdrv_get_specific_stats
= nvme_get_specific_stats
,
1516 .bdrv_detach_aio_context
= nvme_detach_aio_context
,
1517 .bdrv_attach_aio_context
= nvme_attach_aio_context
,
1519 .bdrv_io_plug
= nvme_aio_plug
,
1520 .bdrv_io_unplug
= nvme_aio_unplug
,
1522 .bdrv_register_buf
= nvme_register_buf
,
1523 .bdrv_unregister_buf
= nvme_unregister_buf
,
1526 static void bdrv_nvme_init(void)
1528 bdrv_register(&bdrv_nvme
);
1531 block_init(bdrv_nvme_init
);