hw/block/nvme: metadata and end-to-end data protection support
v2 cover hw/block/nvme: metadata and end-to-end data protection support
From: Klaus Jensen <[email protected]>
This is RFC v2 of a series that adds support for metadata and end-to-end data protection.
First, on the subject of metadata, in v1, support was restricted to extended logical blocks, which was pretty trivial to implement, but required special initialization and broke DULBE. In v2, metadata is always stored continuously at the end of the underlying block device. This has the advantage of not breaking DULBE since the data blocks remains aligned and allows bdrv_block_status to be used to determinate allocation status. It comes at the expense of complicating the extended LBA emulation, but on the other hand it also gains support for metadata transfered as a separate buffer.
The end-to-end data protection support blew up in terms of required changes. This is due to the fact that a bunch of new commands has been added to the device since v1 (zone append, compare, copy), and they all require various special handling for protection information. If potential reviewers would like it split up into multiple patches, each adding pi support to one command, shout out.
The core of the series (metadata and eedp) is preceeded by a set of patches that refactors mapping (yes, again) and tries to deal with the qsg/iov duality mess (maybe also again?).
Support fro metadata and end-to-end data protection is all joint work with Gollu Appalanaidu.
Klaus Jensen (8):
hw/block/nvme: remove redundant len member in compare context hw/block/nvme: remove block accounting for write zeroes hw/block/nvme: fix strerror printing
hw/block/nvme: try to deal with the iov/qsg duality hw/block/nvme: remove the req dependency in map functions hw/block/nvme: refactor nvme_dma
hw/block/nvme: add metadata support
hw/block/nvme: end-to-end data protection
hw/block/nvme-ns.h | 41 +- hw/block/nvme.h | 44 +- include/block/nvme.h | 26 +- hw/block/nvme-ns.c | 29 +- hw/block/nvme.c | 1687 +++++++++++++++++++++++++++++++++++------ hw/block/trace-events | 19 +- 6 files changed, 1574 insertions(+), 272 deletions(-)
Signature · 1 line
2.30.0
RFC PATCH v2 1/8 hw/block/nvme: remove redundant len member in compare context
From: Klaus Jensen <[email protected]>
The 'len' member of the nvme_compare_ctx struct is redundant since the same information is available in the 'iov' member.
--- hw/block/nvme.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
hw/block/nvme.c +4 -6
@@ -1656,7 +1656,6 @@ static void nvme_aio_copy_in_cb(void *opaque, int ret)struct nvme_compare_ctx {QEMUIOVector iov;uint8_t *bounce; -size_t len; };static void nvme_compare_cb (void *opaque,int ret)
@@ -1677,16 +1676,16 @@ static void nvme_compare_cb(void *opaque, int ret) goto out; } - buf =g_malloc (ctx->len); + buf =g_malloc (ctx->iov.size); - status =nvme_dma (nvme_ctrl (req), buf, ctx->len,DMA_DIRECTION_TO_DEVICE , - req); + status =nvme_dma (nvme_ctrl (req), buf, ctx->iov.size, +DMA_DIRECTION_TO_DEVICE , req);if (status) { req->status = status; goto out; } -if (memcmp (buf, ctx->bounce, ctx->len)) { +if (memcmp (buf, ctx->bounce, ctx->iov.size)) { req->status =NVME_CMP_FAILURE ; }
@@ -1924,7 +1923,6 @@ static uint16_t nvme_compare(NvmeCtrl *n, NvmeRequest *req) ctx = g_new(struct nvme_compare_ctx, 1); ctx->bounce = bounce; - ctx->len = len; req->opaque = ctx;
Signature · 1 line
2.30.0
Re: [PATCH RFC v2 1/8] hw/block/nvme: remove redundant len member in compare context
Quoted 6 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
The 'len' member of the
nvme_compare_ctxstruct is redundant since the same information is available in the 'iov' member.Signed-off-by Klaus Jensen <[email protected]>
RFC PATCH v2 2/8 hw/block/nvme: remove block accounting for write zeroes
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
A Write Zeroes commands should not be counted in either the 'Data Units Written' or in 'Host Write Commands' SMART/Health Information Log page.
--- hw/block/nvme.c | 1 - 1 file changed, 1 deletion(-)
hw/block/nvme.c +0 -1
@@ -2088,7 +2088,6 @@ static uint16_t nvme_do_write(NvmeCtrl *n, NvmeRequest *req, bool append, nvme_rw_cb, req); } }else { -block_acct_start (blk_get_stats (blk), &req->acct,0 ,BLOCK_ACCT_WRITE ); req->aiocb =blk_aio_pwrite_zeroes (blk, data_offset, data_size,BDRV_REQ_MAY_UNMAP , nvme_rw_cb, req);
Signature · 1 line
2.30.0
Re: [PATCH RFC v2 2/8] hw/block/nvme: remove block accounting for write zeroes
Quoted 6 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
A Write Zeroes commands should not be counted in either the 'Data Units Written' or in 'Host Write Commands' SMART/Health Information Log page.
Signed-off-by Klaus Jensen <[email protected]>
RFC PATCH v2 3/8 hw/block/nvme: fix strerror printing
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
Fix missing sign inversion.
--- hw/block/nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/nvme.c +1 -1
@@ -1150,7 +1150,7 @@ static void nvme_aio_err(NvmeRequest *req, int ret)break ; } -trace_pci_nvme_err_aio (nvme_cid (req),strerror (ret), status); +trace_pci_nvme_err_aio (nvme_cid (req),strerror (-ret), status);error_setg_errno (&local_err, -ret,"aio failed" );error_report_err (local_err);
Signature · 1 line
2.30.0
Re: [PATCH RFC v2 3/8] hw/block/nvme: fix strerror printing
Quoted 5 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Fix missing sign inversion.
Signed-off-by Klaus Jensen <[email protected]>
RFC PATCH v2 4/8 hw/block/nvme: try to deal with the iov/qsg duality
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
Introduce NvmeSg and try to deal with that pesky qsg/iov duality that haunts all the memory-related functions.
--- hw/block/nvme.h | 8 ++- hw/block/nvme.c | 171 ++++++++++++++++++++++++------------------------ 2 files changed, 90 insertions(+), 89 deletions(-)
hw/block/nvme.h +6 -2
@@ -29,6 +29,11 @@ typedef struct NvmeAsyncEvent {NvmeAerResult result; } NvmeAsyncEvent; +typedef struct NvmeSg { +QEMUSGList qsg; +QEMUIOVector iov; +}NvmeSg ; + typedef struct NvmeRequest { struct NvmeSQueue *sq; struct NvmeNamespace *ns;
@@ -38,8 +43,7 @@ typedef struct NvmeRequest {NvmeCqe cqe;NvmeCmd cmd;BlockAcctCookie acct; -QEMUSGList qsg; -QEMUIOVector iov; +NvmeSg sg;QTAILQ_ENTRY (NvmeRequest)entry; } NvmeRequest;
hw/block/nvme.c +84 -87
367 lines not on this page · raw message
Signature · 1 line
2.30.0
Re: [PATCH RFC v2 4/8] hw/block/nvme: try to deal with the iov/qsg duality
Quoted 16 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Introduce NvmeSg and try to deal with that pesky qsg/iov duality that haunts all the memory-related functions.
Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.h | 8 ++- hw/block/nvme.c | 171 ++++++++++++++++++++++++------------------------ 2 files changed, 90 insertions(+), 89 deletions(-)hw/block/nvme.h +0
-0
hw/block/nvme.h typedef struct NvmeAsyncEvent { · line 35
Quoted 7 lines
hw/block/nvme.h +4
-0@@ -29,6 +29,11 @@ typedef struct NvmeAsyncEvent {NvmeAerResult result; } NvmeAsyncEvent; +typedef struct NvmeSg { +QEMUSGList qsg; +QEMUIOVector iov; +}NvmeSg ;
It's always one or the other, right? If so, this could be a 'union' type, and then you'd just need an indicator field to say which type it is. There may be a meaninful memory savings that way since we potentially allocate thousands of these.
Re: [PATCH RFC v2 4/8] hw/block/nvme: try to deal with the iov/qsg duality
Quoted 20 lines · Keith Busch
Quoted 19 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Introduce NvmeSg and try to deal with that pesky qsg/iov duality that haunts all the memory-related functions.
Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.h | 8 ++- hw/block/nvme.c | 171 ++++++++++++++++++++++++------------------------ 2 files changed, 90 insertions(+), 89 deletions(-)hw/block/nvme.h +0
-0@@ -29,6 +29,11 @@ typedef struct NvmeAsyncEvent {NvmeAerResult result; } NvmeAsyncEvent;
Quoted 9 lines
hw/block/nvme.h typedef struct NvmeAsyncEvent { · line 35
Quoted 4 lines
hw/block/nvme.h +4
-0+typedef struct NvmeSg { +QEMUSGList qsg; +QEMUIOVector iov; +}NvmeSg ;It's always one or the other, right? If so, this could be a 'union' type, and then you'd just need an indicator field to say which type it is. There may be a meaninful memory savings that way since we potentially allocate thousands of these.
Yes, that's true.
I'll do that for v3!
RFC PATCH v2 5/8 hw/block/nvme: remove the req dependency in map functions
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
The PRP and SGL mapping functions does not have any particular need for the entire NvmeRequest as a parameter. Clean it up.
--- hw/block/nvme.c | 61 ++++++++++++++++++++++--------------------- hw/block/trace-events | 4 +-- 2 files changed, 33 insertions(+), 32 deletions(-)
hw/block/nvme.c +31 -30
@@ -516,8 +516,8 @@ static uint16_t nvme_map_addr(NvmeCtrl *n, NvmeSg *sg, hwaddr addr, size_t len)return NVME_SUCCESS ; } -static uint16_t nvme_map_prp (NvmeCtrl *n,uint64_t prp1,uint64_t prp2, -uint32_t len,NvmeRequest *req) +static uint16_t nvme_map_prp (NvmeCtrl *n,NvmeSg *sg,uint64_t prp1, +uint64_t prp2,uint32_t len) {hwaddr trans_len = n->page_size - (prp1 % n->page_size); trans_len =MIN (len, trans_len);
@@ -527,9 +527,9 @@ static uint16_t nvme_map_prp(NvmeCtrl *n, uint64_t prp1, uint64_t prp2,trace_pci_nvme_map_prp (trans_len, len, prp1, prp2, num_prps); -nvme_sg_init (n, &req->sg); +nvme_sg_init (n, sg); - status =nvme_map_addr (n, &req->sg, prp1, trans_len); + status =nvme_map_addr (n, sg, prp1, trans_len);if (status) { goto unmap; }
@@ -579,7 +579,7 @@ static uint16_t nvme_map_prp(NvmeCtrl *n, uint64_t prp1, uint64_t prp2, } trans_len =MIN (len, n->page_size); - status =nvme_map_addr (n, &req->sg, prp_ent, trans_len); + status =nvme_map_addr (n, sg, prp_ent, trans_len);if (status) { goto unmap; }
@@ -593,7 +593,7 @@ static uint16_t nvme_map_prp(NvmeCtrl *n, uint64_t prp1, uint64_t prp2, status =NVME_INVALID_PRP_OFFSET |NVME_DNR ; goto unmap; } - status =nvme_map_addr (n, &req->sg, prp2, len); + status =nvme_map_addr (n, sg, prp2, len);if (status) { goto unmap; }
@@ -603,7 +603,7 @@ static uint16_t nvme_map_prp(NvmeCtrl *n, uint64_t prp1, uint64_t prp2,return NVME_SUCCESS ; unmap: -nvme_sg_unmap (&req->sg); +nvme_sg_unmap (sg);return status; }
@@ -613,7 +613,7 @@ unmap:*/ static uint16_t nvme_map_sgl_data (NvmeCtrl *n,NvmeSg *sg,NvmeSglDescriptor *segment,uint64_t nsgld, -size_t *len,NvmeRequest *req) +size_t *len,NvmeCmd *cmd) {dma_addr_t addr, trans_len;uint32_t dlen;
@@ -624,7 +624,7 @@ static uint16_t nvme_map_sgl_data(NvmeCtrl *n, NvmeSg *sg,switch (type) {case NVME_SGL_DESCR_TYPE_BIT_BUCKET : -if (req->cmd.opcode ==NVME_CMD_WRITE ) { +if (cmd->opcode ==NVME_CMD_WRITE ) {continue ; }case NVME_SGL_DESCR_TYPE_DATA_BLOCK :
@@ -653,7 +653,7 @@ static uint16_t nvme_map_sgl_data(NvmeCtrl *n, NvmeSg *sg,break ; } -trace_pci_nvme_err_invalid_sgl_excess_length (nvme_cid (req)); +trace_pci_nvme_err_invalid_sgl_excess_length (dlen);return NVME_DATA_SGL_LEN_INVALID |NVME_DNR ; }
@@ -682,7 +682,7 @@ next: }static uint16_t nvme_map_sgl (NvmeCtrl *n,NvmeSg *sg,NvmeSglDescriptor sgl, -size_t len,NvmeRequest *req) +size_t len,NvmeCmd *cmd) {/* * Read the segment in chunks of 256 descriptors (one 4k page) to avoid
@@ -705,14 +705,14 @@ static uint16_t nvme_map_sgl(NvmeCtrl *n, NvmeSg *sg, NvmeSglDescriptor sgl, sgld = &sgl; addr =le64_to_cpu (sgl.addr); -trace_pci_nvme_map_sgl (nvme_cid (req),NVME_SGL_TYPE (sgl.type), len); +trace_pci_nvme_map_sgl (NVME_SGL_TYPE (sgl.type), len);/* * If the entire transfer can be described with a single data block it can * be mapped directly. */ if (NVME_SGL_TYPE (sgl.type) ==NVME_SGL_DESCR_TYPE_DATA_BLOCK ) { - status =nvme_map_sgl_data (n, sg, sgld,1 , &len, req); + status =nvme_map_sgl_data (n, sg, sgld,1 , &len, cmd);if (status) { goto unmap; }
@@ -751,7 +751,7 @@ static uint16_t nvme_map_sgl(NvmeCtrl *n, NvmeSg *sg, NvmeSglDescriptor sgl, } status =nvme_map_sgl_data (n, sg, segment,SEG_CHUNK_SIZE , - &len, req); + &len, cmd);if (status) { goto unmap; }
@@ -777,7 +777,7 @@ static uint16_t nvme_map_sgl(NvmeCtrl *n, NvmeSg *sg, NvmeSglDescriptor sgl,switch (NVME_SGL_TYPE (last_sgld->type)) {case NVME_SGL_DESCR_TYPE_DATA_BLOCK :case NVME_SGL_DESCR_TYPE_BIT_BUCKET : - status =nvme_map_sgl_data (n, sg, segment, nsgld, &len, req); + status =nvme_map_sgl_data (n, sg, segment, nsgld, &len, cmd);if (status) { goto unmap; }
@@ -804,7 +804,7 @@ static uint16_t nvme_map_sgl(NvmeCtrl *n, NvmeSg *sg, NvmeSglDescriptor sgl,* Do not map the last descriptor; it will be a Segment or Last Segment * descriptor and is handled by the next iteration. */ - status =nvme_map_sgl_data (n, sg, segment, nsgld -1 , &len, req); + status =nvme_map_sgl_data (n, sg, segment, nsgld -1 , &len, cmd);if (status) { goto unmap; }
@@ -824,24 +824,20 @@ unmap:return status; } -static uint16_t nvme_map_dptr (NvmeCtrl *n,size_t len,NvmeRequest *req) +static uint16_t nvme_map_dptr (NvmeCtrl *n,NvmeSg *sg,size_t len, +NvmeCmd *cmd) {uint64_t prp1, prp2; -switch (NVME_CMD_FLAGS_PSDT (req->cmd.flags)) { +switch (NVME_CMD_FLAGS_PSDT (cmd->flags)) {case NVME_PSDT_PRP : - prp1 =le64_to_cpu (req->cmd.dptr.prp1); - prp2 =le64_to_cpu (req->cmd.dptr.prp2); + prp1 =le64_to_cpu (cmd->dptr.prp1); + prp2 =le64_to_cpu (cmd->dptr.prp2); -return nvme_map_prp (n, prp1, prp2, len, req); +return nvme_map_prp (n, sg, prp1, prp2, len);case NVME_PSDT_SGL_MPTR_CONTIGUOUS :case NVME_PSDT_SGL_MPTR_SGL : -/* SGLs shall not be used for Admin commands in NVMe over PCIe */ -if (!req->sq->sqid) { -return NVME_INVALID_FIELD |NVME_DNR ; - } - -return nvme_map_sgl (n, &req->sg, req->cmd.dptr.sgl, len, req); +return nvme_map_sgl (n, sg, cmd->dptr.sgl, len, cmd);default :return NVME_INVALID_FIELD ; }
@@ -852,7 +848,7 @@ static uint16_t nvme_dma(NvmeCtrl *n, uint8_t *ptr, uint32_t len, {uint16_t status =NVME_SUCCESS ; - status =nvme_map_dptr (n, len, req); + status =nvme_map_dptr (n, &req->sg, len, &req->cmd);if (status) {return status; }
@@ -1985,7 +1981,7 @@ static uint16_t nvme_read(NvmeCtrl *n, NvmeRequest *req) } } - status =nvme_map_dptr (n, data_size, req); + status =nvme_map_dptr (n, &req->sg, data_size, &req->cmd);if (status) { goto invalid; }
@@ -2076,7 +2072,7 @@ static uint16_t nvme_do_write(NvmeCtrl *n, NvmeRequest *req, bool append, data_offset =nvme_l2b (ns, slba);if (!wrz) { - status =nvme_map_dptr (n, data_size, req); + status =nvme_map_dptr (n, &req->sg, data_size, &req->cmd);if (status) { goto invalid; }
@@ -3732,6 +3728,11 @@ static uint16_t nvme_admin_cmd(NvmeCtrl *n, NvmeRequest *req)return NVME_INVALID_OPCODE |NVME_DNR ; } +/* SGLs shall not be used for Admin commands in NVMe over PCIe */ +if (NVME_CMD_FLAGS_PSDT (req->cmd.flags) !=NVME_PSDT_PRP ) { +return NVME_INVALID_FIELD |NVME_DNR ; + } +switch (req->cmd.opcode) {case NVME_ADM_CMD_DELETE_SQ :return nvme_del_sq (n, req);
hw/block/trace-events +2 -2
@@ -37,7 +37,7 @@ pci_nvme_dma_read(uint64_t prp1, uint64_t prp2) "DMA read, prp1=0x%"PRIx64" prp2 pci_nvme_map_addr(uint64_t addr, uint64_t len) "addr 0x%"PRIx64" len %"PRIu64"" pci_nvme_map_addr_cmb(uint64_t addr, uint64_t len) "addr 0x%"PRIx64" len %"PRIu64"" pci_nvme_map_prp(uint64_t trans_len, uint32_t len, uint64_t prp1, uint64_t prp2, int num_prps) "trans_len %"PRIu64" len %"PRIu32" prp1 0x%"PRIx64" prp2 0x%"PRIx64" num_prps %d" -pci_nvme_map_sgl(uint16_t cid, uint8_t typ, uint64_t len) "cid %"PRIu16" type 0x%"PRIx8" len %"PRIu64"" +pci_nvme_map_sgl(uint8_t typ, uint64_t len) "type 0x%"PRIx8" len %"PRIu64"" pci_nvme_io_cmd(uint16_t cid, uint32_t nsid, uint16_t sqid, uint8_t opcode, const char *opname) "cid %"PRIu16" nsid %"PRIu32" sqid %"PRIu16" opc 0x%"PRIx8" opname '%s'" pci_nvme_admin_cmd(uint16_t cid, uint16_t sqid, uint8_t opcode, const char *opname) "cid %"PRIu16" sqid %"PRIu16" opc 0x%"PRIx8" opname '%s'" pci_nvme_read(uint16_t cid, uint32_t nsid, uint32_t nlb, uint64_t count, uint64_t lba) "cid %"PRIu16" nsid %"PRIu32" nlb %"PRIu32" count %"PRIu64" lba 0x%"PRIx64""
@@ -121,7 +121,7 @@ pci_nvme_err_aio(uint16_t cid, const char *errname, uint16_t status) "cid %"PRIu pci_nvme_err_copy_invalid_format(uint8_t format) "format 0x%"PRIx8"" pci_nvme_err_invalid_sgld(uint16_t cid, uint8_t typ) "cid %"PRIu16" type 0x%"PRIx8"" pci_nvme_err_invalid_num_sgld(uint16_t cid, uint8_t typ) "cid %"PRIu16" type 0x%"PRIx8"" -pci_nvme_err_invalid_sgl_excess_length(uint16_t cid) "cid %"PRIu16"" +pci_nvme_err_invalid_sgl_excess_length(uint32_t residual) "residual %"PRIu32"" pci_nvme_err_invalid_dma(void) "PRP/SGL is too small for transfer size" pci_nvme_err_invalid_prplist_ent(uint64_t prplist) "PRP list entry is not page aligned: 0x%"PRIx64"" pci_nvme_err_invalid_prp2_align(uint64_t prp2) "PRP2 is not page aligned: 0x%"PRIx64""
Signature · 1 line
2.30.0
RFC PATCH v2 6/8 hw/block/nvme: refactor nvme_dma
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
The nvme_dma function doesn't just do DMA (QEMUSGList-based) memory transfers; it also handles QEMUIOVector copies.
Introduce the NvmeTxDirection enum and rename to nvme_tx. Remove mapping of PRPs/SGLs from nvme_tx and instead assert that they have been mapped previously. This allows more fine-grained use in subsequent patches.
Add new (better named) helpers, nvme_{c2h,h2c}, that does both PRP/SGL mapping and transfer.
--- hw/block/nvme.c | 143 ++++++++++++++++++++++++++---------------------- 1 file changed, 77 insertions(+), 66 deletions(-)
hw/block/nvme.c +77 -66
@@ -843,48 +843,72 @@ static uint16_t nvme_map_dptr(NvmeCtrl *n, NvmeSg *sg, size_t len, } } -static uint16_t nvme_dma (NvmeCtrl *n,uint8_t *ptr,uint32_t len, -DMADirection dir,NvmeRequest *req) +typedef enum NvmeTxDirection { +NVME_TX_DIRECTION_TO_DEVICE =0 , +NVME_TX_DIRECTION_FROM_DEVICE =1 , +}NvmeTxDirection ; + +static uint16_t nvme_tx (NvmeCtrl *n,NvmeSg *sg,uint8_t *ptr,uint32_t len, +NvmeTxDirection dir) { -uint16_t status =NVME_SUCCESS ; +/* assert that exactly one of qsg and iov carries data */ +assert ((sg->qsg.nsg >0 ) != (sg->iov.niov >0 )); + +if (sg->qsg.nsg >0 ) { +uint64_t residual; + +if (dir ==NVME_TX_DIRECTION_TO_DEVICE ) { + residual =dma_buf_write (ptr, len, &sg->qsg); + }else { + residual =dma_buf_read (ptr, len, &sg->qsg); + } + +if (unlikely (residual)) { +trace_pci_nvme_err_invalid_dma (); +return NVME_INVALID_FIELD |NVME_DNR ; + } + }else { +size_t bytes; + +if (dir ==NVME_TX_DIRECTION_TO_DEVICE ) { + bytes =qemu_iovec_to_buf (&sg->iov,0 , ptr, len); + }else { + bytes =qemu_iovec_from_buf (&sg->iov,0 , ptr, len); + } + +if (unlikely (bytes != len)) { +trace_pci_nvme_err_invalid_dma (); +return NVME_INVALID_FIELD |NVME_DNR ; + } + } + +return NVME_SUCCESS ; +} + +static inline uint16_t nvme_c2h (NvmeCtrl *n,uint8_t *ptr,uint32_t len, +NvmeRequest *req) +{ +uint16_t status; status =nvme_map_dptr (n, &req->sg, len, &req->cmd);if (status) {return status; } -/* assert that only one of qsg and iov carries data */ -assert ((req->sg.qsg.nsg >0 ) != (req->sg.iov.niov >0 )); +return nvme_tx (n, &req->sg, ptr, len,NVME_TX_DIRECTION_FROM_DEVICE ); +} -if (req->sg.qsg.nsg >0 ) { -uint64_t residual; +static inline uint16_t nvme_h2c (NvmeCtrl *n,uint8_t *ptr,uint32_t len, +NvmeRequest *req) +{ +uint16_t status; -if (dir ==DMA_DIRECTION_TO_DEVICE ) { - residual =dma_buf_write (ptr, len, &req->sg.qsg); - }else { - residual =dma_buf_read (ptr, len, &req->sg.qsg); - } - -if (unlikely (residual)) { -trace_pci_nvme_err_invalid_dma (); - status =NVME_INVALID_FIELD |NVME_DNR ; - } - }else { -size_t bytes; - -if (dir ==DMA_DIRECTION_TO_DEVICE ) { - bytes =qemu_iovec_to_buf (&req->sg.iov,0 , ptr, len); - }else { - bytes =qemu_iovec_from_buf (&req->sg.iov,0 , ptr, len); - } - -if (unlikely (bytes != len)) { -trace_pci_nvme_err_invalid_dma (); - status =NVME_INVALID_FIELD |NVME_DNR ; - } + status =nvme_map_dptr (n, &req->sg, len, &req->cmd); +if (status) { +return status; } -return status; +return nvme_tx (n, &req->sg, ptr, len,NVME_TX_DIRECTION_TO_DEVICE ); } static inline void nvme_blk_read(BlockBackend *blk, int64_t offset,
@@ -1683,8 +1707,7 @@ static void nvme_compare_cb(void *opaque, int ret) buf =g_malloc (ctx->iov.size); - status =nvme_dma (nvme_ctrl (req), buf, ctx->iov.size, -DMA_DIRECTION_TO_DEVICE , req); + status =nvme_h2c (nvme_ctrl (req), buf, ctx->iov.size, req);if (status) { req->status = status; goto out;
@@ -1720,8 +1743,7 @@ static uint16_t nvme_dsm(NvmeCtrl *n, NvmeRequest *req)NvmeDsmRange range[nr];uintptr_t *discards = (uintptr_t *)&req->opaque; - status =nvme_dma (n, (uint8_t *)range,sizeof (range), -DMA_DIRECTION_TO_DEVICE , req); + status =nvme_h2c (n, (uint8_t *)range,sizeof (range), req);if (status) {return status; }
@@ -1803,8 +1825,8 @@ static uint16_t nvme_copy(NvmeCtrl *n, NvmeRequest *req) range =g_new (NvmeCopySourceRange, nr); - status =nvme_dma (n, (uint8_t *)range, nr *sizeof (NvmeCopySourceRange), -DMA_DIRECTION_TO_DEVICE , req); + status =nvme_h2c (n, (uint8_t *)range, nr *sizeof (NvmeCopySourceRange), + req);if (status) {return status; }
@@ -2413,8 +2435,7 @@ static uint16_t nvme_zone_mgmt_send(NvmeCtrl *n, NvmeRequest *req)return NVME_INVALID_FIELD |NVME_DNR ; } zd_ext =nvme_get_zd_extension (ns, zone_idx); - status =nvme_dma (n, zd_ext, ns->params.zd_extension_size, -DMA_DIRECTION_TO_DEVICE , req); + status =nvme_h2c (n, zd_ext, ns->params.zd_extension_size, req);if (status) {trace_pci_nvme_err_zd_extension_map_error (zone_idx);return status;
@@ -2569,8 +2590,7 @@ static uint16_t nvme_zone_mgmt_recv(NvmeCtrl *n, NvmeRequest *req) } } - status =nvme_dma (n, (uint8_t *)buf, data_size, -DMA_DIRECTION_FROM_DEVICE , req); + status =nvme_c2h (n, (uint8_t *)buf, data_size, req);g_free (buf);
@@ -2814,8 +2834,7 @@ static uint16_t nvme_smart_info(NvmeCtrl *n, uint8_t rae, uint32_t buf_len,nvme_clear_events (n,NVME_AER_TYPE_SMART ); } -return nvme_dma (n, (uint8_t *) &smart + off, trans_len, -DMA_DIRECTION_FROM_DEVICE , req); +return nvme_c2h (n, (uint8_t *) &smart + off, trans_len, req); } static uint16_t nvme_fw_log_info(NvmeCtrl *n, uint32_t buf_len, uint64_t off,
@@ -2833,8 +2852,7 @@ static uint16_t nvme_fw_log_info(NvmeCtrl *n, uint32_t buf_len, uint64_t off,strpadcpy ((char *)&fw_log.frs1,sizeof (fw_log.frs1),"1.0" ,' ' ); trans_len =MIN (sizeof (fw_log) - off, buf_len); -return nvme_dma (n, (uint8_t *) &fw_log + off, trans_len, -DMA_DIRECTION_FROM_DEVICE , req); +return nvme_c2h (n, (uint8_t *) &fw_log + off, trans_len, req); } static uint16_t nvme_error_info(NvmeCtrl *n, uint8_t rae, uint32_t buf_len,
@@ -2854,8 +2872,7 @@ static uint16_t nvme_error_info(NvmeCtrl *n, uint8_t rae, uint32_t buf_len,memset (&errlog,0x0 ,sizeof (errlog)); trans_len =MIN (sizeof (errlog) - off, buf_len); -return nvme_dma (n, (uint8_t *)&errlog, trans_len, -DMA_DIRECTION_FROM_DEVICE , req); +return nvme_c2h (n, (uint8_t *)&errlog, trans_len, req); } static uint16_t nvme_cmd_effects(NvmeCtrl *n, uint8_t csi, uint32_t buf_len,
@@ -2895,8 +2912,7 @@ static uint16_t nvme_cmd_effects(NvmeCtrl *n, uint8_t csi, uint32_t buf_len, trans_len =MIN (sizeof (log) - off, buf_len); -return nvme_dma (n, ((uint8_t *)&log) + off, trans_len, -DMA_DIRECTION_FROM_DEVICE , req); +return nvme_c2h (n, ((uint8_t *)&log) + off, trans_len, req); }static uint16_t nvme_get_log (NvmeCtrl *n,NvmeRequest *req)
@@ -3066,7 +3082,7 @@ static uint16_t nvme_rpt_empty_id_struct(NvmeCtrl *n, NvmeRequest *req) {uint8_t id[NVME_IDENTIFY_DATA_SIZE ] = {}; -return nvme_dma (n, id,sizeof (id),DMA_DIRECTION_FROM_DEVICE , req); +return nvme_c2h (n, id,sizeof (id), req); }static inline bool nvme_csi_has_nvm_support (NvmeNamespace *ns)
@@ -3083,8 +3099,7 @@ static uint16_t nvme_identify_ctrl(NvmeCtrl *n, NvmeRequest *req) {trace_pci_nvme_identify_ctrl (); -return nvme_dma (n, (uint8_t *)&n->id_ctrl,sizeof (n->id_ctrl), -DMA_DIRECTION_FROM_DEVICE , req); +return nvme_c2h (n, (uint8_t *)&n->id_ctrl,sizeof (n->id_ctrl), req); }static uint16_t nvme_identify_ctrl_csi (NvmeCtrl *n,NvmeRequest *req)
@@ -3100,8 +3115,7 @@ static uint16_t nvme_identify_ctrl_csi(NvmeCtrl *n, NvmeRequest *req)if (n->params.zasl_bs) { id.zasl = n->zasl; } -return nvme_dma (n, (uint8_t *)&id,sizeof (id), -DMA_DIRECTION_FROM_DEVICE , req); +return nvme_c2h (n, (uint8_t *)&id,sizeof (id), req); }return NVME_INVALID_FIELD |NVME_DNR ;
@@ -3125,8 +3139,7 @@ static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeRequest *req) }if (c->csi ==NVME_CSI_NVM &&nvme_csi_has_nvm_support (ns)) { -return nvme_dma (n, (uint8_t *)&ns->id_ns,sizeof (NvmeIdNs), -DMA_DIRECTION_FROM_DEVICE , req); +return nvme_c2h (n, (uint8_t *)&ns->id_ns,sizeof (NvmeIdNs), req); }return NVME_INVALID_CMD_SET |NVME_DNR ;
@@ -3152,8 +3165,8 @@ static uint16_t nvme_identify_ns_csi(NvmeCtrl *n, NvmeRequest *req)if (c->csi ==NVME_CSI_NVM &&nvme_csi_has_nvm_support (ns)) {return nvme_rpt_empty_id_struct (n, req); }else if (c->csi ==NVME_CSI_ZONED && ns->csi ==NVME_CSI_ZONED ) { -return nvme_dma (n, (uint8_t *)ns->id_ns_zoned,sizeof (NvmeIdNsZoned), -DMA_DIRECTION_FROM_DEVICE , req); +return nvme_c2h (n, (uint8_t *)ns->id_ns_zoned,sizeof (NvmeIdNsZoned), + req); }return NVME_INVALID_FIELD |NVME_DNR ;
@@ -3195,7 +3208,7 @@ static uint16_t nvme_identify_nslist(NvmeCtrl *n, NvmeRequest *req) } } -return nvme_dma (n, list, data_len,DMA_DIRECTION_FROM_DEVICE , req); +return nvme_c2h (n, list, data_len, req); }static uint16_t nvme_identify_nslist_csi (NvmeCtrl *n,NvmeRequest *req)
@@ -3235,7 +3248,7 @@ static uint16_t nvme_identify_nslist_csi(NvmeCtrl *n, NvmeRequest *req) } } -return nvme_dma (n, list, data_len,DMA_DIRECTION_FROM_DEVICE , req); +return nvme_c2h (n, list, data_len, req); }static uint16_t nvme_identify_ns_descr_list (NvmeCtrl *n,NvmeRequest *req)
@@ -3282,7 +3295,7 @@ static uint16_t nvme_identify_ns_descr_list(NvmeCtrl *n, NvmeRequest *req) ns_descrs->csi.hdr.nidl =NVME_NIDL_CSI ; ns_descrs->csi.v = ns->csi; -return nvme_dma (n, list,sizeof (list),DMA_DIRECTION_FROM_DEVICE , req); +return nvme_c2h (n, list,sizeof (list), req); }static uint16_t nvme_identify_cmd_set (NvmeCtrl *n,NvmeRequest *req)
@@ -3295,7 +3308,7 @@ static uint16_t nvme_identify_cmd_set(NvmeCtrl *n, NvmeRequest *req)NVME_SET_CSI (*list,NVME_CSI_NVM );NVME_SET_CSI (*list,NVME_CSI_ZONED ); -return nvme_dma (n, list, data_len,DMA_DIRECTION_FROM_DEVICE , req); +return nvme_c2h (n, list, data_len, req); }static uint16_t nvme_identify (NvmeCtrl *n,NvmeRequest *req)
@@ -3384,8 +3397,7 @@ static uint16_t nvme_get_feature_timestamp(NvmeCtrl *n, NvmeRequest *req) {uint64_t timestamp =nvme_get_timestamp (n); -return nvme_dma (n, (uint8_t *)×tamp,sizeof (timestamp), -DMA_DIRECTION_FROM_DEVICE , req); +return nvme_c2h (n, (uint8_t *)×tamp,sizeof (timestamp), req); }static uint16_t nvme_get_feature (NvmeCtrl *n,NvmeRequest *req)
@@ -3545,8 +3557,7 @@ static uint16_t nvme_set_feature_timestamp(NvmeCtrl *n, NvmeRequest *req)uint16_t ret;uint64_t timestamp; - ret =nvme_dma (n, (uint8_t *)×tamp,sizeof (timestamp), -DMA_DIRECTION_TO_DEVICE , req); + ret =nvme_h2c (n, (uint8_t *)×tamp,sizeof (timestamp), req);if (ret) {return ret; }
Signature · 1 line
2.30.0
RFC PATCH v2 7/8 hw/block/nvme: add metadata support
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
Add support for metadata in the form of extended logical blocks as well as a separate buffer of data. The new ms nvme-ns device parameter specifies the size of metadata per logical block in bytes. The mset nvme-ns device parameter controls whether metadata is transfered as part of an extended lba (set to '1') or in a separate buffer (set to '0', the default).
Regardsless of the scheme chosen with mset, metadata is stored at the end of the namespace backing block device. This requires the user provided PRP/SGLs to be walked and "split" into data and metadata scatter/gather lists if the extended logical block scheme is used, but has the advantage of not breaking the deallocated blocks support.
--- hw/block/nvme-ns.h | 39 ++- hw/block/nvme-ns.c | 18 +- hw/block/nvme.c | 652 ++++++++++++++++++++++++++++++++++++------ hw/block/trace-events | 4 +- 4 files changed, 618 insertions(+), 95 deletions(-)
hw/block/nvme-ns.h +33 -6
@@ -29,6 +29,9 @@ typedef struct NvmeNamespaceParams {uint32_t nsid;QemuUUID uuid; +uint16_t ms; +uint8_t mset; +uint16_t mssrl;uint32_t mcl;uint8_t msrc;
@@ -47,6 +50,7 @@ typedef struct NvmeNamespace {BlockConf blkconf;int32_t bootindex;int64_t size; +int64_t mdata_offset;NvmeIdNs id_ns;const uint32_t *iocs;uint8_t csi;
@@ -99,18 +103,41 @@ static inline uint8_t nvme_ns_lbads(NvmeNamespace *ns)return nvme_ns_lbaf (ns)->ds; } -/* calculate the number of LBAs that the namespace can accomodate */ -static inline uint64_t nvme_ns_nlbas (NvmeNamespace *ns) -{ -return ns->size >>nvme_ns_lbads (ns); -} -/* convert an LBA to the equivalent in bytes */ static inline size_t nvme_l2b (NvmeNamespace *ns,uint64_t lba) {return lba <<nvme_ns_lbads (ns); } +static inline size_t nvme_lsize (NvmeNamespace *ns) +{ +return 1 <<nvme_ns_lbads (ns); +} + +static inline uint16_t nvme_msize (NvmeNamespace *ns) +{ +return nvme_ns_lbaf (ns)->ms; +} + +static inline size_t nvme_m2b (NvmeNamespace *ns,uint64_t lba) +{ +return nvme_msize (ns) * lba; +} + +static inline bool nvme_ns_ext (NvmeNamespace *ns) +{ +return !!NVME_ID_NS_FLBAS_EXTENDED (ns->id_ns.flbas); +} + +/* calculate the number of LBAs that the namespace can accomodate */ +static inline uint64_t nvme_ns_nlbas (NvmeNamespace *ns) +{ +if (ns->params.ms) { +return ns->size / (nvme_lsize (ns) +nvme_msize (ns)); + } +return ns->size >>nvme_ns_lbads (ns); +} +typedef struct NvmeCtrl NvmeCtrl ;static inline NvmeZoneState nvme_get_zone_state (NvmeZone *zone)
hw/block/nvme-ns.c +16 -2
@@ -37,13 +37,25 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp)BlockDriverInfo bdi;NvmeIdNs *id_ns = &ns->id_ns;int lba_index =NVME_ID_NS_FLBAS_INDEX (ns->id_ns.flbas); -int npdg; +int npdg, nlbas; ns->id_ns.dlfeat =0x9 ; id_ns->lbaf[lba_index].ds =31 -clz32 (ns->blkconf.logical_block_size); + id_ns->lbaf[lba_index].ms = ns->params.ms; - id_ns->nsze =cpu_to_le64 (nvme_ns_nlbas (ns)); +if (ns->params.ms) { + id_ns->mc =0x3 ; + +if (ns->params.mset) { + id_ns->flbas |=0x10 ; + } + } + + nlbas =nvme_ns_nlbas (ns); + + id_ns->nsze =cpu_to_le64 (nlbas); + ns->mdata_offset =nvme_l2b (ns, nlbas); ns->csi =NVME_CSI_NVM ;
@@ -395,6 +407,8 @@ static Property nvme_ns_props[] = { NvmeSubsystem *),DEFINE_PROP_UINT32 ("nsid" , NvmeNamespace, params.nsid,0 ),DEFINE_PROP_UUID ("uuid" , NvmeNamespace, params.uuid), +DEFINE_PROP_UINT16 ("ms" , NvmeNamespace, params.ms,0 ), +DEFINE_PROP_UINT8 ("mset" , NvmeNamespace, params.mset,0 ),DEFINE_PROP_UINT16 ("mssrl" , NvmeNamespace, params.mssrl,128 ),DEFINE_PROP_UINT32 ("mcl" , NvmeNamespace, params.mcl,128 ), DEFINE_PROP_UINT8("msrc", NvmeNamespace, params.msrc, 127),
hw/block/nvme.c +566 -86
871 lines not on this page · raw message
hw/block/trace-events +3 -1
@@ -47,11 +47,13 @@ pci_nvme_copy(uint16_t cid, uint32_t nsid, uint16_t nr, uint8_t format) "cid %"P pci_nvme_copy_source_range(uint64_t slba, uint32_t nlb) "slba 0x%"PRIx64" nlb %"PRIu32"" pci_nvme_copy_in_complete(uint16_t cid) "cid %"PRIu16"" pci_nvme_copy_cb(uint16_t cid) "cid %"PRIu16"" +pci_nvme_rw_complete_cb(uint16_t cid, const char *blkname) "cid %"PRIu16" blk '%s'" pci_nvme_block_status(int64_t offset, int64_t bytes, int64_t pnum, int ret, bool zeroed) "offset %"PRId64" bytes %"PRId64" pnum %"PRId64" ret 0x%x zeroed %d" pci_nvme_dsm(uint16_t cid, uint32_t nsid, uint32_t nr, uint32_t attr) "cid %"PRIu16" nsid %"PRIu32" nr %"PRIu32" attr 0x%"PRIx32"" pci_nvme_dsm_deallocate(uint16_t cid, uint32_t nsid, uint64_t slba, uint32_t nlb) "cid %"PRIu16" nsid %"PRIu32" slba %"PRIu64" nlb %"PRIu32"" pci_nvme_compare(uint16_t cid, uint32_t nsid, uint64_t slba, uint32_t nlb) "cid %"PRIu16" nsid %"PRIu32" slba 0x%"PRIx64" nlb %"PRIu32"" -pci_nvme_compare_cb(uint16_t cid) "cid %"PRIu16"" +pci_nvme_compare_data_cb(uint16_t cid) "cid %"PRIu16"" +pci_nvme_compare_mdata_cb(uint16_t cid) "cid %"PRIu16"" pci_nvme_aio_discard_cb(uint16_t cid) "cid %"PRIu16"" pci_nvme_aio_copy_in_cb(uint16_t cid) "cid %"PRIu16"" pci_nvme_aio_zone_reset_cb(uint16_t cid, uint64_t zslba) "cid %"PRIu16" zslba 0x%"PRIx64""
Signature · 1 line
2.30.0
RFC PATCH v2 8/8 hw/block/nvme: end-to-end data protection
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
Add support for namespaces formatted with protection information. The type of end-to-end data protection (i.e. Type 1, Type 2 or Type 3) is selected with the pi nvme-ns device parameter. If the number of metadata bytes is larger than 8, the pil nvme-ns device parameter may be used to control the location of the 8-byte DIF tuple. The default pil value of '0', causes the DIF tuple to be transferred as the last 8 bytes of the metadata. Set to 1 to store this in the first eight bytes instead.
This patch is based on work by Gollu Appalanaidu.
--- hw/block/nvme-ns.h | 2 + hw/block/nvme.h | 36 +++ include/block/nvme.h | 26 +- hw/block/nvme-ns.c | 11 + hw/block/nvme.c | 731 ++++++++++++++++++++++++++++++++++++++++-- hw/block/trace-events | 11 + 6 files changed, 793 insertions(+), 24 deletions(-)
hw/block/nvme-ns.h +2 -0
@@ -31,6 +31,8 @@ typedef struct NvmeNamespaceParams {uint16_t ms;uint8_t mset; +uint8_t pi; +uint8_t pil;uint16_t mssrl;uint32_t mcl;
hw/block/nvme.h +36 -0
@@ -212,6 +212,42 @@ static inline NvmeCtrl *nvme_ctrl(NvmeRequest *req) return sq->ctrl; } +/* from Linux kernel (crypto/crct10dif_common.c) */ +static const uint16_t t10_dif_crc_table[256 ] = { +0x0000 ,0x8BB7 ,0x9CD9 ,0x176E ,0xB205 ,0x39B2 ,0x2EDC ,0xA56B , +0xEFBD ,0x640A ,0x7364 ,0xF8D3 ,0x5DB8 ,0xD60F ,0xC161 ,0x4AD6 , +0x54CD ,0xDF7A ,0xC814 ,0x43A3 ,0xE6C8 ,0x6D7F ,0x7A11 ,0xF1A6 , +0xBB70 ,0x30C7 ,0x27A9 ,0xAC1E ,0x0975 ,0x82C2 ,0x95AC ,0x1E1B , +0xA99A ,0x222D ,0x3543 ,0xBEF4 ,0x1B9F ,0x9028 ,0x8746 ,0x0CF1 , +0x4627 ,0xCD90 ,0xDAFE ,0x5149 ,0xF422 ,0x7F95 ,0x68FB ,0xE34C , +0xFD57 ,0x76E0 ,0x618E ,0xEA39 ,0x4F52 ,0xC4E5 ,0xD38B ,0x583C , +0x12EA ,0x995D ,0x8E33 ,0x0584 ,0xA0EF ,0x2B58 ,0x3C36 ,0xB781 , +0xD883 ,0x5334 ,0x445A ,0xCFED ,0x6A86 ,0xE131 ,0xF65F ,0x7DE8 , +0x373E ,0xBC89 ,0xABE7 ,0x2050 ,0x853B ,0x0E8C ,0x19E2 ,0x9255 , +0x8C4E ,0x07F9 ,0x1097 ,0x9B20 ,0x3E4B ,0xB5FC ,0xA292 ,0x2925 , +0x63F3 ,0xE844 ,0xFF2A ,0x749D ,0xD1F6 ,0x5A41 ,0x4D2F ,0xC698 , +0x7119 ,0xFAAE ,0xEDC0 ,0x6677 ,0xC31C ,0x48AB ,0x5FC5 ,0xD472 , +0x9EA4 ,0x1513 ,0x027D ,0x89CA ,0x2CA1 ,0xA716 ,0xB078 ,0x3BCF , +0x25D4 ,0xAE63 ,0xB90D ,0x32BA ,0x97D1 ,0x1C66 ,0x0B08 ,0x80BF , +0xCA69 ,0x41DE ,0x56B0 ,0xDD07 ,0x786C ,0xF3DB ,0xE4B5 ,0x6F02 , +0x3AB1 ,0xB106 ,0xA668 ,0x2DDF ,0x88B4 ,0x0303 ,0x146D ,0x9FDA , +0xD50C ,0x5EBB ,0x49D5 ,0xC262 ,0x6709 ,0xECBE ,0xFBD0 ,0x7067 , +0x6E7C ,0xE5CB ,0xF2A5 ,0x7912 ,0xDC79 ,0x57CE ,0x40A0 ,0xCB17 , +0x81C1 ,0x0A76 ,0x1D18 ,0x96AF ,0x33C4 ,0xB873 ,0xAF1D ,0x24AA , +0x932B ,0x189C ,0x0FF2 ,0x8445 ,0x212E ,0xAA99 ,0xBDF7 ,0x3640 , +0x7C96 ,0xF721 ,0xE04F ,0x6BF8 ,0xCE93 ,0x4524 ,0x524A ,0xD9FD , +0xC7E6 ,0x4C51 ,0x5B3F ,0xD088 ,0x75E3 ,0xFE54 ,0xE93A ,0x628D , +0x285B ,0xA3EC ,0xB482 ,0x3F35 ,0x9A5E ,0x11E9 ,0x0687 ,0x8D30 , +0xE232 ,0x6985 ,0x7EEB ,0xF55C ,0x5037 ,0xDB80 ,0xCCEE ,0x4759 , +0x0D8F ,0x8638 ,0x9156 ,0x1AE1 ,0xBF8A ,0x343D ,0x2353 ,0xA8E4 , +0xB6FF ,0x3D48 ,0x2A26 ,0xA191 ,0x04FA ,0x8F4D ,0x9823 ,0x1394 , +0x5942 ,0xD2F5 ,0xC59B ,0x4E2C ,0xEB47 ,0x60F0 ,0x779E ,0xFC29 , +0x4BA8 ,0xC01F ,0xD771 ,0x5CC6 ,0xF9AD ,0x721A ,0x6574 ,0xEEC3 , +0xA415 ,0x2FA2 ,0x38CC ,0xB37B ,0x1610 ,0x9DA7 ,0x8AC9 ,0x017E , +0x1F65 ,0x94D2 ,0x83BC ,0x080B ,0xAD60 ,0x26D7 ,0x31B9 ,0xBA0E , +0xF0D8 ,0x7B6F ,0x6C01 ,0xE7B6 ,0x42DD ,0xC96A ,0xDE04 ,0x55B3 +}; +int nvme_register_namespace (NvmeCtrl *n,NvmeNamespace *ns,Error **errp);#endif /* HW_NVME_H */
include/block/nvme.h +20 -6
@@ -695,12 +695,17 @@ enum {NVME_RW_DSM_LATENCY_LOW =3 <<4 ,NVME_RW_DSM_SEQ_REQ =1 <<6 ,NVME_RW_DSM_COMPRESSED =1 <<7 , +NVME_RW_PIREMAP =1 <<9 ,NVME_RW_PRINFO_PRACT =1 <<13 ,NVME_RW_PRINFO_PRCHK_GUARD =1 <<12 ,NVME_RW_PRINFO_PRCHK_APP =1 <<11 ,NVME_RW_PRINFO_PRCHK_REF =1 <<10 , + NVME_RW_PRINFO_PRCHK_MASK = 7 << 10, + }; +#define NVME_RW_PRINFO (control) ((control >> 10) & 0xf) + typedef struct QEMU_PACKED NvmeDsmCmd {uint8_t opcode;uint8_t flags;
@@ -1292,14 +1297,22 @@ typedef struct QEMU_PACKED NvmeIdNsZoned {#define NVME_ID_NS_DPC_TYPE_MASK 0x7enum NvmeIdNsDps { -DPS_TYPE_NONE =0 , -DPS_TYPE_1 =1 , -DPS_TYPE_2 =2 , -DPS_TYPE_3 =3 , -DPS_TYPE_MASK =0x7 , -DPS_FIRST_EIGHT =8 , +NVME_ID_NS_DPS_TYPE_NONE =0 , +NVME_ID_NS_DPS_TYPE_1 =1 , +NVME_ID_NS_DPS_TYPE_2 =2 , +NVME_ID_NS_DPS_TYPE_3 =3 , +NVME_ID_NS_DPS_TYPE_MASK =0x7 , +NVME_ID_NS_DPS_FIRST_EIGHT =8 , }; +#define NVME_ID_NS_DPS_TYPE (dps) (dps & NVME_ID_NS_DPS_TYPE_MASK) + +typedef struct NvmeDifTuple { +uint16_t guard; +uint16_t apptag; +uint32_t reftag; +}NvmeDifTuple ; +enum NvmeZoneAttr {NVME_ZA_FINISHED_BY_CTLR =1 <<0 ,NVME_ZA_FINISH_RECOMMENDED =1 <<1 ,
@@ -1395,5 +1408,6 @@ static inline void _nvme_check_size(void)QEMU_BUILD_BUG_ON (sizeof (NvmeSglDescriptor) !=16 );QEMU_BUILD_BUG_ON (sizeof (NvmeIdNsDescr) !=4 );QEMU_BUILD_BUG_ON (sizeof (NvmeZoneDescr) !=64 ); + QEMU_BUILD_BUG_ON(sizeof(NvmeDifTuple) != 8); }#endif
hw/block/nvme-ns.c +11 -0
@@ -50,6 +50,9 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp)if (ns->params.mset) { id_ns->flbas |=0x10 ; } + + id_ns->dpc =0x1f ; + id_ns->dps = (ns->params.pil <<3 ) | ns->params.pi; } nlbas =nvme_ns_nlbas (ns);
@@ -325,6 +328,12 @@ static int nvme_ns_check_constraints(NvmeNamespace *ns, Error **errp)return -1 ; } +if (ns->params.pi && !ns->params.ms) { +error_setg (errp,"at least 8 bytes of metadata required to enable " +"protection information" ); +return -1 ; + } +return 0 ; }
@@ -409,6 +418,8 @@ static Property nvme_ns_props[] = {DEFINE_PROP_UUID ("uuid" , NvmeNamespace, params.uuid),DEFINE_PROP_UINT16 ("ms" , NvmeNamespace, params.ms,0 ),DEFINE_PROP_UINT8 ("mset" , NvmeNamespace, params.mset,0 ), +DEFINE_PROP_UINT8 ("pi" , NvmeNamespace, params.pi,0 ), +DEFINE_PROP_UINT8 ("pil" , NvmeNamespace, params.pil,0 ),DEFINE_PROP_UINT16 ("mssrl" , NvmeNamespace, params.mssrl,128 ),DEFINE_PROP_UINT32 ("mcl" , NvmeNamespace, params.mcl,128 ), DEFINE_PROP_UINT8("msrc", NvmeNamespace, params.msrc, 127),
hw/block/nvme.c +713 -18
942 lines not on this page · raw message
hw/block/trace-events +11 -0
@@ -43,6 +43,17 @@ pci_nvme_admin_cmd(uint16_t cid, uint16_t sqid, uint8_t opcode, const char *opna pci_nvme_read(uint16_t cid, uint32_t nsid, uint32_t nlb, uint64_t count, uint64_t lba) "cid %"PRIu16" nsid %"PRIu32" nlb %"PRIu32" count %"PRIu64" lba 0x%"PRIx64"" pci_nvme_write(uint16_t cid, const char *verb, uint32_t nsid, uint32_t nlb, uint64_t count, uint64_t lba) "cid %"PRIu16" opname '%s' nsid %"PRIu32" nlb %"PRIu32" count %"PRIu64" lba 0x%"PRIx64"" pci_nvme_rw_cb(uint16_t cid, const char *blkname) "cid %"PRIu16" blk '%s'" +pci_nvme_e2e_rw(uint8_t pract) "pract 0x%"PRIx8"" +pci_nvme_e2e_rw_cb(uint16_t cid, const char *blkname) "cid %"PRIu16" blk '%s'" +pci_nvme_e2e_rw_mdata_in_cb(uint16_t cid, const char *blkname) "cid %"PRIu16" blk '%s'" +pci_nvme_e2e_rw_mdata_out_cb(uint16_t cid, const char *blkname) "cid %"PRIu16" blk '%s'" +pci_nvme_e2e_rw_check_cb(uint16_t cid, uint8_t prinfo, uint16_t apptag, uint16_t appmask, uint32_t reftag) "cid %"PRIu16" prinfo 0x%"PRIx8" apptag 0x%"PRIx16" appmask 0x%"PRIx16" reftag 0x%"PRIx32"" +pci_nvme_e2e_pract_generate_dif(size_t len, size_t lba_size, size_t chksum_len, uint16_t apptag, uint32_t reftag) "len %zu lba_size %zu chksum_len %zu apptag 0x%"PRIx16" reftag 0x%"PRIx32"" +pci_nvme_e2e_check(uint8_t prinfo, uint16_t chksum_len) "prinfo 0x%"PRIx8" chksum_len %"PRIu16"" +pci_nvme_e2e_prchk_disabled(uint16_t apptag, uint32_t reftag) "apptag 0x%"PRIx16" reftag 0x%"PRIx32"" +pci_nvme_e2e_prchk_guard(uint16_t guard, uint16_t crc) "guard 0x%"PRIx16" crc 0x%"PRIx16"" +pci_nvme_e2e_prchk_apptag(uint16_t apptag, uint16_t elbat, uint16_t elbatm) "apptag 0x%"PRIx16" elbat 0x%"PRIx16" elbatm 0x%"PRIx16"" +pci_nvme_e2e_prchk_reftag(uint32_t reftag, uint32_t elbrt) "reftag 0x%"PRIx32" elbrt 0x%"PRIx32"" pci_nvme_copy(uint16_t cid, uint32_t nsid, uint16_t nr, uint8_t format) "cid %"PRIu16" nsid %"PRIu32" nr %"PRIu16" format 0x%"PRIx8"" pci_nvme_copy_source_range(uint64_t slba, uint32_t nlb) "slba 0x%"PRIx64" nlb %"PRIu32"" pci_nvme_copy_in_complete(uint16_t cid) "cid %"PRIu16""
Signature · 1 line
2.30.0