hw/block/nvme: Support Namespace Types and Zoned Namespace Command Set
PATCH v11 3/13 hw/block/nvme: Separate read and write handlers
In reply to Dmitry FomichevThe majority of code in nvme_rw() is becoming read- or write-specific. Move these parts to two separate handlers, nvme_read() and nvme_write() to make the code more readable and to remove multiple is_write checks that has been present in the i/o path.
This is a refactoring patch, no change in functionality.
--- hw/block/nvme.c | 107 ++++++++++++++++++++++++++++-------------- hw/block/trace-events | 3 +- 2 files changed, 74 insertions(+), 36 deletions(-)
hw/block/nvme.c +72 -35
@@ -1073,6 +1073,61 @@ static uint16_t nvme_flush(NvmeCtrl *n, NvmeRequest *req)return NVME_NO_COMPLETE ; } +static uint16_t nvme_read (NvmeCtrl *n,NvmeRequest *req) +{ +NvmeRwCmd *rw = (NvmeRwCmd *)&req->cmd; +NvmeNamespace *ns = req->ns; +uint64_t slba =le64_to_cpu (rw->slba); +uint32_t nlb = (uint32_t )le16_to_cpu (rw->nlb) +1 ; +uint64_t data_size =nvme_l2b (ns, nlb); +uint64_t data_offset; +BlockBackend *blk = ns->blkconf.blk; +uint16_t status; + +trace_pci_nvme_read (nvme_cid (req),nvme_nsid (ns), nlb, data_size, slba); + + status =nvme_check_mdts (n, data_size); +if (status) { +trace_pci_nvme_err_mdts (nvme_cid (req), data_size); + goto invalid; + } + + status =nvme_check_bounds (n, ns, slba, nlb); +if (status) { +trace_pci_nvme_err_invalid_lba_range (slba, nlb, ns->id_ns.nsze); + goto invalid; + } + + status =nvme_map_dptr (n, data_size, req); +if (status) { + goto invalid; + } + +if (NVME_ERR_REC_DULBE (ns->features.err_rec)) { + status =nvme_check_dulbe (ns, slba, nlb); +if (status) { + goto invalid; + } + } + + data_offset =nvme_l2b (ns, slba); + +block_acct_start (blk_get_stats (blk), &req->acct, data_size, +BLOCK_ACCT_READ ); +if (req->qsg.sg) { + req->aiocb =dma_blk_read (blk, &req->qsg, data_offset, +BDRV_SECTOR_SIZE , nvme_rw_cb, req); + }else { + req->aiocb =blk_aio_preadv (blk, data_offset, &req->iov,0 , + nvme_rw_cb, req); + } +return NVME_NO_COMPLETE ; + +invalid: +block_acct_invalid (blk_get_stats (blk),BLOCK_ACCT_READ ); +return status |NVME_DNR ; +} +static uint16_t nvme_write_zeroes (NvmeCtrl *n,NvmeRequest *req) {NvmeRwCmd *rw = (NvmeRwCmd *)&req->cmd;
@@ -1098,22 +1153,19 @@ static uint16_t nvme_write_zeroes(NvmeCtrl *n, NvmeRequest *req)return NVME_NO_COMPLETE ; } -static uint16_t nvme_rw (NvmeCtrl *n,NvmeRequest *req) +static uint16_t nvme_write (NvmeCtrl *n,NvmeRequest *req) {NvmeRwCmd *rw = (NvmeRwCmd *)&req->cmd;NvmeNamespace *ns = req->ns; -uint32_t nlb = (uint32_t )le16_to_cpu (rw->nlb) +1 ;uint64_t slba =le64_to_cpu (rw->slba); - +uint32_t nlb = (uint32_t )le16_to_cpu (rw->nlb) +1 ;uint64_t data_size =nvme_l2b (ns, nlb); -uint64_t data_offset =nvme_l2b (ns, slba); -enum BlockAcctType acct = req->cmd.opcode ==NVME_CMD_WRITE ? -BLOCK_ACCT_WRITE :BLOCK_ACCT_READ ; +uint64_t data_offset;BlockBackend *blk = ns->blkconf.blk;uint16_t status; -trace_pci_nvme_rw (nvme_cid (req),nvme_io_opc_str (rw->opcode), -nvme_nsid (ns), nlb, data_size, slba); +trace_pci_nvme_write (nvme_cid (req),nvme_io_opc_str (rw->opcode), +nvme_nsid (ns), nlb, data_size, slba); status =nvme_check_mdts (n, data_size);if (status) {
@@ -1127,43 +1179,27 @@ static uint16_t nvme_rw(NvmeCtrl *n, NvmeRequest *req) goto invalid; } -if (acct ==BLOCK_ACCT_READ ) { -if (NVME_ERR_REC_DULBE (ns->features.err_rec)) { - status =nvme_check_dulbe (ns, slba, nlb); -if (status) { - goto invalid; - } - } - } - status =nvme_map_dptr (n, data_size, req);if (status) { goto invalid; } -block_acct_start (blk_get_stats (blk), &req->acct, data_size, acct); + data_offset =nvme_l2b (ns, slba); + +block_acct_start (blk_get_stats (blk), &req->acct, data_size, +BLOCK_ACCT_WRITE );if (req->qsg.sg) { -if (acct ==BLOCK_ACCT_WRITE ) { - req->aiocb =dma_blk_write (blk, &req->qsg, data_offset, -BDRV_SECTOR_SIZE , nvme_rw_cb, req); - }else { - req->aiocb =dma_blk_read (blk, &req->qsg, data_offset, -BDRV_SECTOR_SIZE , nvme_rw_cb, req); - } + req->aiocb =dma_blk_write (blk, &req->qsg, data_offset, +BDRV_SECTOR_SIZE , nvme_rw_cb, req); }else { -if (acct ==BLOCK_ACCT_WRITE ) { - req->aiocb =blk_aio_pwritev (blk, data_offset, &req->iov,0 , - nvme_rw_cb, req); - }else { - req->aiocb =blk_aio_preadv (blk, data_offset, &req->iov,0 , - nvme_rw_cb, req); - } + req->aiocb =blk_aio_pwritev (blk, data_offset, &req->iov,0 , + nvme_rw_cb, req); }return NVME_NO_COMPLETE ; invalid: -block_acct_invalid (blk_get_stats (ns->blkconf.blk), acct); -return status; +block_acct_invalid (blk_get_stats (blk),BLOCK_ACCT_WRITE ); +return status |NVME_DNR ; }static uint16_t nvme_io_cmd (NvmeCtrl *n,NvmeRequest *req)
@@ -1192,8 +1228,9 @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeRequest *req)case NVME_CMD_WRITE_ZEROES :return nvme_write_zeroes (n, req);case NVME_CMD_WRITE : +return nvme_write (n, req);case NVME_CMD_READ : -return nvme_rw (n, req); +return nvme_read (n, req);case NVME_CMD_DSM :return nvme_dsm (n, req);default :
hw/block/trace-events +2 -1
@@ -40,7 +40,8 @@ pci_nvme_map_prp(uint64_t trans_len, uint32_t len, uint64_t prp1, uint64_t prp2, pci_nvme_map_sgl(uint16_t cid, uint8_t typ, uint64_t len) "cid %"PRIu16" 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_rw(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_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_write_zeroes(uint16_t cid, uint32_t nsid, uint64_t slba, uint32_t nlb) "cid %"PRIu16" nsid %"PRIu32" slba %"PRIu64" nlb %"PRIu32"" 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"
Signature · 1 line
2.28.0
PATCH v11 7/13 hw/block/nvme: Support allocated CNS command variants
In reply to Dmitry FomichevFrom: Niklas Cassel <[email protected]>
Many CNS commands have "allocated" command variants. These include a namespace as long as it is allocated, that is a namespace is included regardless if it is active (attached) or not.
While these commands are optional (they are mandatory for controllers supporting the namespace attachment command), our QEMU implementation is more complete by actually providing support for these CNS values.
However, since our QEMU model currently does not support the namespace attachment command, these new allocated CNS commands will return the same result as the active CNS command variants.
The reason for not hooking up this command completely is because the NVMe specification requires the namespace management command to be supported if the namespace attachment command is supported.
--- include/block/nvme.h | 20 ++++++++++++-------- hw/block/nvme.c | 8 ++++++++ 2 files changed, 20 insertions(+), 8 deletions(-)
include/block/nvme.h +12 -8
@@ -807,14 +807,18 @@ typedef struct QEMU_PACKED NvmePSD {#define NVME_IDENTIFY_DATA_SIZE 4096enum NvmeIdCns { -NVME_ID_CNS_NS =0x00 , -NVME_ID_CNS_CTRL =0x01 , -NVME_ID_CNS_NS_ACTIVE_LIST =0x02 , -NVME_ID_CNS_NS_DESCR_LIST =0x03 , -NVME_ID_CNS_CS_NS =0x05 , -NVME_ID_CNS_CS_CTRL =0x06 , -NVME_ID_CNS_CS_NS_ACTIVE_LIST =0x07 , -NVME_ID_CNS_IO_COMMAND_SET =0x1c , +NVME_ID_CNS_NS =0x00 , +NVME_ID_CNS_CTRL =0x01 , +NVME_ID_CNS_NS_ACTIVE_LIST =0x02 , +NVME_ID_CNS_NS_DESCR_LIST =0x03 , +NVME_ID_CNS_CS_NS =0x05 , +NVME_ID_CNS_CS_CTRL =0x06 , +NVME_ID_CNS_CS_NS_ACTIVE_LIST =0x07 , +NVME_ID_CNS_NS_PRESENT_LIST =0x10 , +NVME_ID_CNS_NS_PRESENT =0x11 , +NVME_ID_CNS_CS_NS_PRESENT_LIST =0x1a , +NVME_ID_CNS_CS_NS_PRESENT =0x1b , +NVME_ID_CNS_IO_COMMAND_SET =0x1c , }; typedef struct QEMU_PACKED NvmeIdCtrl {
hw/block/nvme.c +8 -0
@@ -1901,16 +1901,24 @@ static uint16_t nvme_identify(NvmeCtrl *n, NvmeRequest *req)switch (le32_to_cpu (c->cns)) {case NVME_ID_CNS_NS : +/* fall through */ +case NVME_ID_CNS_NS_PRESENT :return nvme_identify_ns (n, req);case NVME_ID_CNS_CS_NS : +/* fall through */ +case NVME_ID_CNS_CS_NS_PRESENT :return nvme_identify_ns_csi (n, req);case NVME_ID_CNS_CTRL :return nvme_identify_ctrl (n, req);case NVME_ID_CNS_CS_CTRL :return nvme_identify_ctrl_csi (n, req);case NVME_ID_CNS_NS_ACTIVE_LIST : +/* fall through */ +case NVME_ID_CNS_NS_PRESENT_LIST :return nvme_identify_nslist (n, req);case NVME_ID_CNS_CS_NS_ACTIVE_LIST : +/* fall through */ +case NVME_ID_CNS_CS_NS_PRESENT_LIST :return nvme_identify_nslist_csi (n, req);case NVME_ID_CNS_NS_DESCR_LIST :return nvme_identify_ns_descr_list (n, req);
Signature · 1 line
2.28.0
PATCH v11 8/13 block/nvme: Make ZNS-related definitions
In reply to Dmitry FomichevDefine values and structures that are needed to support Zoned Namespace Command Set (NVMe TP 4053).
--- include/block/nvme.h | 114 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-)
include/block/nvme.h +113 -1
@@ -489,6 +489,9 @@ enum NvmeIoCommands {NVME_CMD_COMPARE =0x05 ,NVME_CMD_WRITE_ZEROES =0x08 ,NVME_CMD_DSM =0x09 , +NVME_CMD_ZONE_MGMT_SEND =0x79 , +NVME_CMD_ZONE_MGMT_RECV =0x7a , + NVME_CMD_ZONE_APPEND = 0x7d, }; typedef struct QEMU_PACKED NvmeDeleteQ {
@@ -648,9 +651,13 @@ typedef struct QEMU_PACKED NvmeAerResult {uint8_t resv; } NvmeAerResult; +typedef struct QEMU_PACKED NvmeZonedResult { +uint64_t slba; +} NvmeZonedResult; + typedef struct QEMU_PACKED NvmeCqe {uint32_t result; -uint32_t rsvd; +uint32_t dw1;uint16_t sq_head;uint16_t sq_id;uint16_t cid;
@@ -679,6 +686,7 @@ enum NvmeStatusCodes {NVME_INVALID_USE_OF_CMB =0x0012 ,NVME_INVALID_PRP_OFFSET =0x0013 ,NVME_CMD_SET_CMB_REJECTED =0x002b , +NVME_INVALID_CMD_SET =0x002c ,NVME_LBA_RANGE =0x0080 ,NVME_CAP_EXCEEDED =0x0081 , NVME_NS_NOT_READY = 0x0082,
@@ -703,6 +711,14 @@ enum NvmeStatusCodes {NVME_CONFLICTING_ATTRS =0x0180 ,NVME_INVALID_PROT_INFO =0x0181 ,NVME_WRITE_TO_RO =0x0182 , +NVME_ZONE_BOUNDARY_ERROR =0x01b8 , +NVME_ZONE_FULL =0x01b9 , +NVME_ZONE_READ_ONLY =0x01ba , +NVME_ZONE_OFFLINE =0x01bb , +NVME_ZONE_INVALID_WRITE =0x01bc , +NVME_ZONE_TOO_MANY_ACTIVE =0x01bd , +NVME_ZONE_TOO_MANY_OPEN =0x01be , +NVME_ZONE_INVAL_TRANSITION =0x01bf ,NVME_WRITE_FAULT =0x0280 ,NVME_UNRECOVERED_READ =0x0281 , NVME_E2E_GUARD_ERROR = 0x0282,
@@ -888,6 +904,11 @@ typedef struct QEMU_PACKED NvmeIdCtrl {uint8_t vs[1024 ]; } NvmeIdCtrl; +typedef struct NvmeIdCtrlZoned { +uint8_t zasl; +uint8_t rsvd1[4095 ]; +}NvmeIdCtrlZoned ; +enum NvmeIdCtrlOacs {NVME_OACS_SECURITY =1 <<0 ,NVME_OACS_FORMAT =1 <<1 ,
@@ -1016,6 +1037,12 @@ typedef struct QEMU_PACKED NvmeLBAF {uint8_t rp; } NvmeLBAF; +typedef struct QEMU_PACKED NvmeLBAFE { +uint64_t zsze; +uint8_t zdes; +uint8_t rsvd9[7 ]; +} NvmeLBAFE; +#define NVME_NSID_BROADCAST 0xffffffff typedef struct QEMU_PACKED NvmeIdNs {
@@ -1075,10 +1102,24 @@ enum NvmeNsIdentifierType {enum NvmeCsi {NVME_CSI_NVM =0x00 , +NVME_CSI_ZONED =0x02 , };#define NVME_SET_CSI (vec, csi) (vec |= (uint8_t)(1 << (csi))) +typedef struct QEMU_PACKED NvmeIdNsZoned { +uint16_t zoc; +uint16_t ozcs; +uint32_t mar; +uint32_t mor; +uint32_t rrl; +uint32_t frl; +uint8_t rsvd20[2796 ]; +NvmeLBAFE lbafe[16 ]; +uint8_t rsvd3072[768 ]; +uint8_t vs[256 ]; +} NvmeIdNsZoned; +/*Deallocate Logical Block Features*/ #define NVME_ID_NS_DLFEAT_GUARD_CRC (dlfeat) ((dlfeat) & 0x10)#define NVME_ID_NS_DLFEAT_WRITE_ZEROES (dlfeat) ((dlfeat) & 0x08)
@@ -1111,10 +1152,76 @@ enum NvmeIdNsDps { DPS_FIRST_EIGHT = 8, }; +enum NvmeZoneAttr { +NVME_ZA_FINISHED_BY_CTLR =1 <<0 , +NVME_ZA_FINISH_RECOMMENDED =1 <<1 , +NVME_ZA_RESET_RECOMMENDED =1 <<2 , +NVME_ZA_ZD_EXT_VALID =1 <<7 , +}; + +typedef struct QEMU_PACKED NvmeZoneReportHeader { +uint64_t nr_zones; +uint8_t rsvd[56 ]; +} NvmeZoneReportHeader; + +enum NvmeZoneReceiveAction { +NVME_ZONE_REPORT =0 , +NVME_ZONE_REPORT_EXTENDED =1 , +}; + +enum NvmeZoneReportType { +NVME_ZONE_REPORT_ALL =0 , +NVME_ZONE_REPORT_EMPTY =1 , +NVME_ZONE_REPORT_IMPLICITLY_OPEN =2 , +NVME_ZONE_REPORT_EXPLICITLY_OPEN =3 , +NVME_ZONE_REPORT_CLOSED =4 , +NVME_ZONE_REPORT_FULL =5 , +NVME_ZONE_REPORT_READ_ONLY =6 , +NVME_ZONE_REPORT_OFFLINE =7 , +}; + +enum NvmeZoneType { +NVME_ZONE_TYPE_RESERVED =0x00 , +NVME_ZONE_TYPE_SEQ_WRITE =0x02 , +}; + +enum NvmeZoneSendAction { +NVME_ZONE_ACTION_RSD =0x00 , +NVME_ZONE_ACTION_CLOSE =0x01 , +NVME_ZONE_ACTION_FINISH =0x02 , +NVME_ZONE_ACTION_OPEN =0x03 , +NVME_ZONE_ACTION_RESET =0x04 , +NVME_ZONE_ACTION_OFFLINE =0x05 , +NVME_ZONE_ACTION_SET_ZD_EXT =0x10 , +}; + +typedef struct QEMU_PACKED NvmeZoneDescr { +uint8_t zt; +uint8_t zs; +uint8_t za; +uint8_t rsvd3[5 ]; +uint64_t zcap; +uint64_t zslba; +uint64_t wp; +uint8_t rsvd32[32 ]; +} NvmeZoneDescr; + +enum NvmeZoneState { +NVME_ZONE_STATE_RESERVED =0x00 , +NVME_ZONE_STATE_EMPTY =0x01 , +NVME_ZONE_STATE_IMPLICITLY_OPEN =0x02 , +NVME_ZONE_STATE_EXPLICITLY_OPEN =0x03 , +NVME_ZONE_STATE_CLOSED =0x04 , +NVME_ZONE_STATE_READ_ONLY =0x0D , +NVME_ZONE_STATE_FULL =0x0E , +NVME_ZONE_STATE_OFFLINE =0x0F , +}; +static inline void _nvme_check_size (void ) {QEMU_BUILD_BUG_ON (sizeof (NvmeBar) !=4096 );QEMU_BUILD_BUG_ON (sizeof (NvmeAerResult) !=4 ); +QEMU_BUILD_BUG_ON (sizeof (NvmeZonedResult) !=8 );QEMU_BUILD_BUG_ON (sizeof (NvmeCqe) !=16 );QEMU_BUILD_BUG_ON (sizeof (NvmeDsmRange) !=16 );QEMU_BUILD_BUG_ON (sizeof (NvmeCmd) !=64 );
@@ -1130,8 +1237,13 @@ static inline void _nvme_check_size(void)QEMU_BUILD_BUG_ON (sizeof (NvmeSmartLog) !=512 );QEMU_BUILD_BUG_ON (sizeof (NvmeEffectsLog) !=4096 );QEMU_BUILD_BUG_ON (sizeof (NvmeIdCtrl) !=4096 ); +QEMU_BUILD_BUG_ON (sizeof (NvmeIdCtrlZoned) !=4096 ); +QEMU_BUILD_BUG_ON (sizeof (NvmeLBAF) !=4 ); +QEMU_BUILD_BUG_ON (sizeof (NvmeLBAFE) !=16 );QEMU_BUILD_BUG_ON (sizeof (NvmeIdNs) !=4096 ); +QEMU_BUILD_BUG_ON (sizeof (NvmeIdNsZoned) !=4096 );QEMU_BUILD_BUG_ON (sizeof (NvmeSglDescriptor) !=16 );QEMU_BUILD_BUG_ON (sizeof (NvmeIdNsDescr) !=4 ); + QEMU_BUILD_BUG_ON(sizeof(NvmeZoneDescr) != 64); }#endif
Signature · 1 line
2.28.0
PATCH v11 11/13 hw/block/nvme: Support Zone Descriptor Extensions
In reply to Dmitry FomichevZone Descriptor Extension is a label that can be assigned to a zone. It can be set to an Empty zone and it stays assigned until the zone is reset.
This commit adds a new optional module property, "zoned.descr_ext_size". Its value must be a multiple of 64 bytes. If this value is non-zero, it becomes possible to assign extensions of that size to any Empty zones. The default value for this property is 0, therefore setting extensions is disabled by default.
--- hw/block/nvme-ns.h | 8 +++++++ hw/block/nvme-ns.c | 25 ++++++++++++++++++-- hw/block/nvme.c | 53 +++++++++++++++++++++++++++++++++++++++++-- hw/block/trace-events | 2 ++ 4 files changed, 84 insertions(+), 4 deletions(-)
hw/block/nvme-ns.h +8 -0
@@ -35,6 +35,7 @@ typedef struct NvmeNamespaceParams {uint64_t zone_cap_bs;uint32_t max_active_zones;uint32_t max_open_zones; +uint32_t zd_extension_size; } NvmeNamespaceParams; typedef struct NvmeNamespace {
@@ -56,6 +57,7 @@ typedef struct NvmeNamespace {uint64_t zone_size;uint64_t zone_capacity;uint32_t zone_size_log2; +uint8_t *zd_extensions;int32_t nr_open_zones;int32_t nr_active_zones;
@@ -129,6 +131,12 @@ static inline bool nvme_wp_is_valid(NvmeZone *zone) st !=NVME_ZONE_STATE_OFFLINE ; } +static inline uint8_t *nvme_get_zd_extension (NvmeNamespace *ns, +uint32_t zone_idx) +{ +return &ns->zd_extensions[zone_idx * ns->params.zd_extension_size]; +} +static inline void nvme_aor_inc_open (NvmeNamespace *ns) {assert (ns->nr_open_zones >=0 );
hw/block/nvme-ns.c +23 -2
@@ -151,6 +151,18 @@ static int nvme_ns_zoned_check_calc_geometry(NvmeNamespace *ns, Error **errp)return -1 ; } +if (ns->params.zd_extension_size) { +if (ns->params.zd_extension_size &0x3f ) { +error_setg (errp, +"zone descriptor extension size must be a multiple of 64B" ); +return -1 ; + } +if ((ns->params.zd_extension_size >>6 ) >0xff ) { +error_setg (errp,"zone descriptor extension size is too large" ); +return -1 ; + } + } +return 0 ; }
@@ -162,6 +174,10 @@ static void nvme_ns_zoned_init_state(NvmeNamespace *ns)int i; ns->zone_array =g_new0 (NvmeZone, ns->num_zones); +if (ns->params.zd_extension_size) { + ns->zd_extensions =g_malloc0 (ns->params.zd_extension_size * + ns->num_zones); + }QTAILQ_INIT (&ns->exp_open_zones);QTAILQ_INIT (&ns->imp_open_zones);
@@ -204,7 +220,8 @@ static void nvme_ns_init_zoned(NvmeCtrl *n, NvmeNamespace *ns, int lba_index) id_ns_z->ozcs = ns->params.cross_zone_read ?0x01 :0x00 ; id_ns_z->lbafe[lba_index].zsze =cpu_to_le64 (ns->zone_size); - id_ns_z->lbafe[lba_index].zdes =0 ; + id_ns_z->lbafe[lba_index].zdes = + ns->params.zd_extension_size >>6 ;/* Units of 64B */ ns->csi =NVME_CSI_ZONED ; ns->id_ns.nsze =cpu_to_le64 (ns->num_zones * ns->zone_size);
@@ -220,7 +237,8 @@ static void nvme_clear_zone(NvmeNamespace *ns, NvmeZone *zone) zone->w_ptr = zone->d.wp; state =nvme_get_zone_state (zone); -if (zone->d.wp != zone->d.zslba) { +if (zone->d.wp != zone->d.zslba || + (zone->d.za &NVME_ZA_ZD_EXT_VALID )) {if (state !=NVME_ZONE_STATE_CLOSED ) {trace_pci_nvme_clear_ns_close (state, zone->d.zslba);nvme_set_zone_state (zone,NVME_ZONE_STATE_CLOSED );
@@ -316,6 +334,7 @@ void nvme_ns_cleanup(NvmeNamespace *ns)if (ns->params.zoned) {g_free (ns->id_ns_zoned);g_free (ns->zone_array); +g_free (ns->zd_extensions); } }
@@ -347,6 +366,8 @@ static Property nvme_ns_props[] = { params.max_active_zones, 0),DEFINE_PROP_UINT32 ("zoned.max_open" , NvmeNamespace, params.max_open_zones,0 ), +DEFINE_PROP_UINT32 ("zoned.descr_ext_size" , NvmeNamespace, + params.zd_extension_size,0 ), DEFINE_PROP_END_OF_LIST(), };
hw/block/nvme.c +51 -2
89 lines not on this page · raw message
hw/block/trace-events +2 -0
@@ -99,6 +99,7 @@ pci_nvme_finish_zone(uint64_t slba, uint32_t zone_idx, int all) "finish zone, sl pci_nvme_reset_zone(uint64_t slba, uint32_t zone_idx, int all) "reset zone, slba=%"PRIu64", idx=%"PRIu32", all=%"PRIi32"" pci_nvme_offline_zone(uint64_t slba, uint32_t zone_idx, int all) "offline zone, slba=%"PRIu64", idx=%"PRIu32", all=%"PRIi32"" pci_nvme_set_descriptor_extension(uint64_t slba, uint32_t zone_idx) "set zone descriptor extension, slba=%"PRIu64", idx=%"PRIu32"" +pci_nvme_zd_extension_set(uint32_t zone_idx) "set descriptor extension for zone_idx=%"PRIu32"" pci_nvme_clear_ns_close(uint32_t state, uint64_t slba) "zone state=%"PRIu32", slba=%"PRIu64" transitioned to Closed state" pci_nvme_clear_ns_reset(uint32_t state, uint64_t slba) "zone state=%"PRIu32", slba=%"PRIu64" transitioned to Empty state"
@@ -128,6 +129,7 @@ pci_nvme_err_zone_read_not_ok(uint64_t slba, uint32_t nlb, uint32_t status) "slb pci_nvme_err_append_too_large(uint64_t slba, uint32_t nlb, uint8_t zasl) "slba=%"PRIu64", nlb=%"PRIu32", zasl=%"PRIu8"" pci_nvme_err_insuff_active_res(uint32_t max_active) "max_active=%"PRIu32" zone limit exceeded" pci_nvme_err_insuff_open_res(uint32_t max_open) "max_open=%"PRIu32" zone limit exceeded" +pci_nvme_err_zd_extension_map_error(uint32_t zone_idx) "can't map descriptor extension for zone_idx=%"PRIu32"" pci_nvme_err_invalid_iocsci(uint32_t idx) "unsupported command set combination index %"PRIu32"" pci_nvme_err_invalid_del_sq(uint16_t qid) "invalid submission queue deletion, sid=%"PRIu16"" pci_nvme_err_invalid_create_sq_cqid(uint16_t cqid) "failed creating submission queue, invalid cqid=%"PRIu16""
Signature · 1 line
2.28.0
PATCH v11 5/13 hw/block/nvme: Add Commands Supported and Effects log
In reply to Dmitry FomichevThis log page becomes necessary to implement to allow checking for Zone Append command support in Zoned Namespace Command Set.
This commit adds the code to report this log page for NVM Command Set only. The parts that are specific to zoned operation will be added later in the series.
All incoming admin and i/o commands are now only processed if their corresponding support bits are set in this log. This provides an easy way to control what commands to support and what not to depending on set CC.CSS.
--- hw/block/nvme-ns.h | 1 + include/block/nvme.h | 19 +++++++++ hw/block/nvme.c | 96 +++++++++++++++++++++++++++++++++++++++---- hw/block/trace-events | 1 + 4 files changed, 108 insertions(+), 9 deletions(-)
hw/block/nvme-ns.h +1 -0
@@ -30,6 +30,7 @@ typedef struct NvmeNamespace {int32_t bootindex;int64_t size;NvmeIdNs id_ns; +const uint32_t *iocs;NvmeNamespaceParams params;
include/block/nvme.h +19 -0
@@ -746,10 +746,27 @@ enum NvmeSmartWarn { NVME_SMART_FAILED_VOLATILE_MEDIA = 1 << 4, }; +typedef struct NvmeEffectsLog { +uint32_t acs[256 ]; +uint32_t iocs[256 ]; +uint8_t resv[2048 ]; +}NvmeEffectsLog ; + +enum { +NVME_CMD_EFF_CSUPP =1 <<0 , +NVME_CMD_EFF_LBCC =1 <<1 , +NVME_CMD_EFF_NCC =1 <<2 , +NVME_CMD_EFF_NIC =1 <<3 , +NVME_CMD_EFF_CCC =1 <<4 , +NVME_CMD_EFF_CSE_MASK =3 <<16 , +NVME_CMD_EFF_UUID_SEL =1 <<19 , +}; +enum NvmeLogIdentifier {NVME_LOG_ERROR_INFO =0x01 ,NVME_LOG_SMART_INFO =0x02 ,NVME_LOG_FW_SLOT_INFO =0x03 , +NVME_LOG_CMD_EFFECTS =0x05 , }; typedef struct QEMU_PACKED NvmePSD {
@@ -862,6 +879,7 @@ enum NvmeIdCtrlFrmw {enum NvmeIdCtrlLpa {NVME_LPA_NS_SMART =1 <<0 , +NVME_LPA_CSE =1 <<1 ,NVME_LPA_EXTENDED =1 <<2 , };
@@ -1070,6 +1088,7 @@ static inline void _nvme_check_size(void)QEMU_BUILD_BUG_ON (sizeof (NvmeErrorLog) !=64 );QEMU_BUILD_BUG_ON (sizeof (NvmeFwSlotInfoLog) !=512 );QEMU_BUILD_BUG_ON (sizeof (NvmeSmartLog) !=512 ); +QEMU_BUILD_BUG_ON (sizeof (NvmeEffectsLog) !=4096 );QEMU_BUILD_BUG_ON (sizeof (NvmeIdCtrl) !=4096 );QEMU_BUILD_BUG_ON (sizeof (NvmeIdNs) !=4096 );QEMU_BUILD_BUG_ON (sizeof (NvmeSglDescriptor) !=16 );
hw/block/nvme.c +87 -9
162 lines not on this page · raw message
hw/block/trace-events +1 -0
@@ -106,6 +106,7 @@ pci_nvme_err_invalid_prp2_align(uint64_t prp2) "PRP2 is not page aligned: 0x%"PR pci_nvme_err_invalid_opc(uint8_t opc) "invalid opcode 0x%"PRIx8"" pci_nvme_err_invalid_admin_opc(uint8_t opc) "invalid admin opcode 0x%"PRIx8"" pci_nvme_err_invalid_lba_range(uint64_t start, uint64_t len, uint64_t limit) "Invalid LBA start=%"PRIu64" len=%"PRIu64" limit=%"PRIu64"" +pci_nvme_err_invalid_log_page_offset(uint64_t ofs, uint64_t size) "must be <= %"PRIu64", got %"PRIu64"" pci_nvme_err_invalid_del_sq(uint16_t qid) "invalid submission queue deletion, sid=%"PRIu16"" pci_nvme_err_invalid_create_sq_cqid(uint16_t cqid) "failed creating submission queue, invalid cqid=%"PRIu16"" pci_nvme_err_invalid_create_sq_sqid(uint16_t sqid) "failed creating submission queue, invalid sqid=%"PRIu16""
Signature · 1 line
2.28.0
PATCH v11 2/13 hw/block/nvme: Generate namespace UUIDs
In reply to Dmitry FomichevIn NVMe 1.4, a namespace must report an ID descriptor of UUID type if it doesn't support EUI64 or NGUID. Add a new namespace property, "uuid", that provides the user the option to either specify the UUID explicitly or have a UUID generated automatically every time a namespace is initialized.
--- hw/block/nvme-ns.h | 1 + hw/block/nvme-ns.c | 1 + hw/block/nvme.c | 9 +++++---- 3 files changed, 7 insertions(+), 4 deletions(-)
hw/block/nvme-ns.h +1 -0
@@ -21,6 +21,7 @@typedef struct NvmeNamespaceParams {uint32_t nsid; +QemuUUID uuid; }NvmeNamespaceParams ; typedef struct NvmeNamespace {
hw/block/nvme-ns.c +1 -0
@@ -152,6 +152,7 @@ static void nvme_ns_realize(DeviceState *dev, Error **errp)static Property nvme_ns_props[] = {DEFINE_BLOCK_PROPERTIES (NvmeNamespace, blkconf),DEFINE_PROP_UINT32 ("nsid" , NvmeNamespace, params.nsid,0 ), +DEFINE_PROP_UUID ("uuid" , NvmeNamespace, params.uuid),DEFINE_PROP_END_OF_LIST (), };
hw/block/nvme.c +5 -4
@@ -1662,6 +1662,7 @@ static uint16_t nvme_identify_nslist(NvmeCtrl *n, NvmeRequest *req)static uint16_t nvme_identify_ns_descr_list (NvmeCtrl *n,NvmeRequest *req) { +NvmeNamespace *ns;NvmeIdentify *c = (NvmeIdentify *)&req->cmd;uint32_t nsid =le32_to_cpu (c->nsid);uint8_t list[NVME_IDENTIFY_DATA_SIZE ];
@@ -1681,7 +1682,8 @@ static uint16_t nvme_identify_ns_descr_list(NvmeCtrl *n, NvmeRequest *req)return NVME_INVALID_NSID |NVME_DNR ; } -if (unlikely (!nvme_ns (n, nsid))) { + ns =nvme_ns (n, nsid); +if (unlikely (!ns)) {return NVME_INVALID_FIELD |NVME_DNR ; }
@@ -1690,12 +1692,11 @@ static uint16_t nvme_identify_ns_descr_list(NvmeCtrl *n, NvmeRequest *req)/* * Because the NGUID and EUI64 fields are 0 in the Identify Namespace data * structure, a Namespace UUID (nidt = 0x3) must be reported in the -* Namespace Identification Descriptor. Add a very basic Namespace UUID -* here. +* Namespace Identification Descriptor. Add the namespace UUID here. */ ns_descrs->uuid.hdr.nidt =NVME_NIDT_UUID ; ns_descrs->uuid.hdr.nidl =NVME_NIDT_UUID_LEN ; -stl_be_p (&ns_descrs->uuid.v, nsid); +memcpy (&ns_descrs->uuid.v, ns->params.uuid.data,NVME_NIDT_UUID_LEN );return nvme_dma (n, list,NVME_IDENTIFY_DATA_SIZE ,DMA_DIRECTION_FROM_DEVICE , req);
Signature · 1 line
2.28.0
PATCH v11 6/13 hw/block/nvme: Add support for Namespace Types
In reply to Dmitry FomichevFrom: Niklas Cassel <[email protected]>
Define the structures and constants required to implement Namespace Types support.
Namespace Types introduce a new command set, "I/O Command Sets", that allows the host to retrieve the command sets associated with a namespace. Introduce support for the command set and enable detection for the NVM Command Set.
The new workflows for identify commands rely heavily on zero-filled identify structs. E.g., certain CNS commands are defined to return a zero-filled identify struct when an inactive namespace NSID is supplied.
Add a helper function in order to avoid code duplication when reporting zero-filled identify structures.
--- hw/block/nvme-ns.h | 1 + include/block/nvme.h | 64 ++++++++++---- hw/block/nvme-ns.c | 2 + hw/block/nvme.c | 188 +++++++++++++++++++++++++++++++++++------- hw/block/trace-events | 6 ++ 5 files changed, 217 insertions(+), 44 deletions(-)
hw/block/nvme-ns.h +1 -0
@@ -31,6 +31,7 @@ typedef struct NvmeNamespace {int64_t size;NvmeIdNs id_ns;const uint32_t *iocs; +uint8_t csi;NvmeNamespaceParams params;
include/block/nvme.h +50 -14
114 lines not on this page · raw message
hw/block/nvme-ns.c +2 -0
@@ -43,6 +43,8 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp) id_ns->nsze =cpu_to_le64 (nvme_ns_nlbas (ns)); + ns->csi =NVME_CSI_NVM ; +/* no thin provisioning */ id_ns->ncap = id_ns->nsze; id_ns->nuse = id_ns->ncap;
hw/block/nvme.c +158 -30
317 lines not on this page · raw message
hw/block/trace-events +6 -0
@@ -52,8 +52,12 @@ pci_nvme_create_cq(uint64_t addr, uint16_t cqid, uint16_t vector, uint16_t size, pci_nvme_del_sq(uint16_t qid) "deleting submission queue sqid=%"PRIu16"" pci_nvme_del_cq(uint16_t cqid) "deleted completion queue, cqid=%"PRIu16"" pci_nvme_identify_ctrl(void) "identify controller" +pci_nvme_identify_ctrl_csi(uint8_t csi) "identify controller, csi=0x%"PRIx8"" pci_nvme_identify_ns(uint32_t ns) "nsid %"PRIu32"" +pci_nvme_identify_ns_csi(uint32_t ns, uint8_t csi) "nsid=%"PRIu32", csi=0x%"PRIx8"" pci_nvme_identify_nslist(uint32_t ns) "nsid %"PRIu32"" +pci_nvme_identify_nslist_csi(uint16_t ns, uint8_t csi) "nsid=%"PRIu16", csi=0x%"PRIx8"" +pci_nvme_identify_cmd_set(void) "identify i/o command set" pci_nvme_identify_ns_descr_list(uint32_t ns) "nsid %"PRIu32"" pci_nvme_get_log(uint16_t cid, uint8_t lid, uint8_t lsp, uint8_t rae, uint32_t len, uint64_t off) "cid %"PRIu16" lid 0x%"PRIx8" lsp 0x%"PRIx8" rae 0x%"PRIx8" len %"PRIu32" off %"PRIu64"" pci_nvme_getfeat(uint16_t cid, uint32_t nsid, uint8_t fid, uint8_t sel, uint32_t cdw11) "cid %"PRIu16" nsid 0x%"PRIx32" fid 0x%"PRIx8" sel 0x%"PRIx8" cdw11 0x%"PRIx32""
@@ -107,6 +111,7 @@ pci_nvme_err_invalid_opc(uint8_t opc) "invalid opcode 0x%"PRIx8"" pci_nvme_err_invalid_admin_opc(uint8_t opc) "invalid admin opcode 0x%"PRIx8"" pci_nvme_err_invalid_lba_range(uint64_t start, uint64_t len, uint64_t limit) "Invalid LBA start=%"PRIu64" len=%"PRIu64" limit=%"PRIu64"" pci_nvme_err_invalid_log_page_offset(uint64_t ofs, uint64_t size) "must be <= %"PRIu64", got %"PRIu64"" +pci_nvme_err_invalid_iocsci(uint32_t idx) "unsupported command set combination index %"PRIu32"" pci_nvme_err_invalid_del_sq(uint16_t qid) "invalid submission queue deletion, sid=%"PRIu16"" pci_nvme_err_invalid_create_sq_cqid(uint16_t cqid) "failed creating submission queue, invalid cqid=%"PRIu16"" pci_nvme_err_invalid_create_sq_sqid(uint16_t sqid) "failed creating submission queue, invalid sqid=%"PRIu16""
@@ -163,6 +168,7 @@ pci_nvme_ub_db_wr_invalid_cq(uint32_t qid) "completion queue doorbell write for pci_nvme_ub_db_wr_invalid_cqhead(uint32_t qid, uint16_t new_head) "completion queue doorbell write value beyond queue size, cqid=%"PRIu32", new_head=%"PRIu16", ignoring" pci_nvme_ub_db_wr_invalid_sq(uint32_t qid) "submission queue doorbell write for nonexistent queue, sqid=%"PRIu32", ignoring" pci_nvme_ub_db_wr_invalid_sqtail(uint32_t qid, uint16_t new_tail) "submission queue doorbell write value beyond queue size, sqid=%"PRIu32", new_head=%"PRIu16", ignoring" +pci_nvme_ub_unknown_css_value(void) "unknown value in cc.css field" # xen-block.c xen_block_realize(const char *type, uint32_t disk, uint32_t partition) "%s d%up%u"
Signature · 1 line
2.28.0
PATCH v11 4/13 hw/block/nvme: Combine nvme_write_zeroes() and nvme_write()
In reply to Dmitry FomichevMove write processing to nvme_do_write() that now handles both WRITE and WRITE ZEROES. Both nvme_write() and nvme_write_zeroes() become inline helper functions.
--- hw/block/nvme.c | 78 ++++++++++++++++++++----------------------- hw/block/trace-events | 1 - 2 files changed, 36 insertions(+), 43 deletions(-)
hw/block/nvme.c +36 -42
@@ -1128,32 +1128,7 @@ invalid:return status |NVME_DNR ; } -static uint16_t nvme_write_zeroes (NvmeCtrl *n,NvmeRequest *req) -{ -NvmeRwCmd *rw = (NvmeRwCmd *)&req->cmd; -NvmeNamespace *ns = req->ns; -uint64_t slba =le64_to_cpu (rw->slba); -uint32_t nlb = (uint32_t )le16_to_cpu (rw->nlb) +1 ; -uint64_t offset =nvme_l2b (ns, slba); -uint32_t count =nvme_l2b (ns, nlb); -uint16_t status; - -trace_pci_nvme_write_zeroes (nvme_cid (req),nvme_nsid (ns), slba, nlb); - - status =nvme_check_bounds (n, ns, slba, nlb); -if (status) { -trace_pci_nvme_err_invalid_lba_range (slba, nlb, ns->id_ns.nsze); -return status; - } - -block_acct_start (blk_get_stats (req->ns->blkconf.blk), &req->acct,0 , -BLOCK_ACCT_WRITE ); - req->aiocb =blk_aio_pwrite_zeroes (req->ns->blkconf.blk, offset, count, -BDRV_REQ_MAY_UNMAP , nvme_rw_cb, req); -return NVME_NO_COMPLETE ; -} - -static uint16_t nvme_write (NvmeCtrl *n,NvmeRequest *req) +static uint16_t nvme_do_write (NvmeCtrl *n,NvmeRequest *req,bool wrz) {NvmeRwCmd *rw = (NvmeRwCmd *)&req->cmd;NvmeNamespace *ns = req->ns;
@@ -1167,10 +1142,12 @@ static uint16_t nvme_write(NvmeCtrl *n, NvmeRequest *req)trace_pci_nvme_write (nvme_cid (req),nvme_io_opc_str (rw->opcode),nvme_nsid (ns), nlb, data_size, slba); - status =nvme_check_mdts (n, data_size); -if (status) { -trace_pci_nvme_err_mdts (nvme_cid (req), data_size); - goto invalid; +if (!wrz) { + status =nvme_check_mdts (n, data_size); +if (status) { +trace_pci_nvme_err_mdts (nvme_cid (req), data_size); + goto invalid; + } } status =nvme_check_bounds (n, ns, slba, nlb);
@@ -1179,21 +1156,28 @@ static uint16_t nvme_write(NvmeCtrl *n, NvmeRequest *req) goto invalid; } - status =nvme_map_dptr (n, data_size, req); -if (status) { - goto invalid; - } - data_offset =nvme_l2b (ns, slba); -block_acct_start (blk_get_stats (blk), &req->acct, data_size, -BLOCK_ACCT_WRITE ); -if (req->qsg.sg) { - req->aiocb =dma_blk_write (blk, &req->qsg, data_offset, -BDRV_SECTOR_SIZE , nvme_rw_cb, req); +if (!wrz) { + status =nvme_map_dptr (n, data_size, req); +if (status) { + goto invalid; + } + +block_acct_start (blk_get_stats (blk), &req->acct, data_size, +BLOCK_ACCT_WRITE ); +if (req->qsg.sg) { + req->aiocb =dma_blk_write (blk, &req->qsg, data_offset, +BDRV_SECTOR_SIZE , nvme_rw_cb, req); + }else { + req->aiocb =blk_aio_pwritev (blk, data_offset, &req->iov,0 , + nvme_rw_cb, req); + } }else { - req->aiocb =blk_aio_pwritev (blk, data_offset, &req->iov,0 , - nvme_rw_cb, req); +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); }return NVME_NO_COMPLETE ;
@@ -1202,6 +1186,16 @@ invalid:return status |NVME_DNR ; } +static inline uint16_t nvme_write (NvmeCtrl *n,NvmeRequest *req) +{ +return nvme_do_write (n, req, false); +} + +static inline uint16_t nvme_write_zeroes (NvmeCtrl *n,NvmeRequest *req) +{ +return nvme_do_write (n, req, true); +} +static uint16_t nvme_io_cmd (NvmeCtrl *n,NvmeRequest *req) {uint32_t nsid =le32_to_cpu (req->cmd.nsid);
hw/block/trace-events +0 -1
@@ -43,7 +43,6 @@ 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_write_zeroes(uint16_t cid, uint32_t nsid, uint64_t slba, uint32_t nlb) "cid %"PRIu16" nsid %"PRIu32" slba %"PRIu64" nlb %"PRIu32"" 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""
Signature · 1 line
2.28.0
PATCH v11 13/13 hw/block/nvme: Document zoned parameters in usage text
In reply to Dmitry FomichevAdded brief descriptions of the new device properties that are now available to users to configure features of Zoned Namespace Command Set in the emulator.
This patch is for documentation only, no functionality change.
--- hw/block/nvme.c | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-)
hw/block/nvme.c +42 -5
@@ -9,7 +9,7 @@*/ /** -* Reference Specs: http://www.nvmexpress.org, 1.2, 1.1, 1.0e +* Reference Specs: http://www.nvmexpress.org, 1.4, 1.3, 1.2, 1.1, 1.0e * * https://nvmexpress.org/developers/nvme-specification/ */
@@ -22,8 +22,9 @@* [pmrdev=<mem_backend_file_id>,] \ * max_ioqpairs=<N[optional]>, \ * aerl=<N[optional]>, aer_max_queued=<N[optional]>, \ -* mdts=<N[optional]> -* -device nvme-ns,drive=<drive_id>,bus=bus_name,nsid=<nsid> +* mdts=<N[optional]>,zoned.append_size_limit=<N[optional]> \ +* -device nvme-ns,drive=<drive_id>,bus=<bus_name>,nsid=<nsid>,\ +* zoned=<true|false[optional]> * * Note cmb_size_mb denotes size of CMB in MB. CMB is assumed to be at * offset 0 in BAR2 and supports only WDS, RDS and SQS for now.
@@ -41,14 +42,50 @@* ~~~~~~~~~~~~~~~~~~~~~~ * - `aerl` * The Asynchronous Event Request Limit (AERL). Indicates the maximum number -* of concurrently outstanding Asynchronous Event Request commands suppoert +* of concurrently outstanding Asynchronous Event Request commands support * by the controller. This is a 0's based value. * * - `aer_max_queued` * This is the maximum number of events that the device will enqueue for -* completion when there are no oustanding AERs. When the maximum number of +* completion when there are no outstanding AERs. When the maximum number of * enqueued events are reached, subsequent events will be dropped. * +* - `zoned.append_size_limit` +* The maximum I/O size in bytes that is allowed in Zone Append command. +* The default is 128KiB. Since internally this this value is maintained as +* ZASL = log2(<maximum append size> / <page size>), some values assigned +* to this property may be rounded down and result in a lower maximum ZA +* data size being in effect. By setting this property to 0, users can make +* ZASL to be equal to MDTS. This property only affects zoned namespaces. +* +* Setting `zoned` to true selects Zoned Command Set at the namespace. +* In this case, the following namespace properties are available to configure +* zoned operation: +* zoned.zsze=<zone size in bytes, default: 128MiB> +* The number may be followed by K, M, G as in kilo-, mega- or giga-. +* +* zoned.zcap=<zone capacity in bytes, default: zone size> +* The value 0 (default) forces zone capacity to be the same as zone +* size. The value of this property may not exceed zone size. +* +* zoned.descr_ext_size=<zone descriptor extension size, default 0> +* This value needs to be specified in 64B units. If it is zero, +* namespace(s) will not support zone descriptor extensions. +* +* zoned.max_active=<Maximum Active Resources (zones), default: 0> +* The default value means there is no limit to the number of +* concurrently active zones. +* +* zoned.max_open=<Maximum Open Resources (zones), default: 0> +* The default value means there is no limit to the number of +* concurrently open zones. +* +* zoned.offline_zones=<the number of offline zones to inject, default: 0> +* +* zoned.rdonly_zones=<the number of read-only zones to inject, default: 0> +* +* zoned.cross_zone_read=<enable RAZB, default: false> +* Setting this property to true enables Read Across Zone Boundaries. */ #include "qemu/osdep.h"
Signature · 1 line
2.28.0
PATCH v11 9/13 hw/block/nvme: Support Zoned Namespace Command Set
In reply to Dmitry FomichevThe emulation code has been changed to advertise NVM Command Set when "zoned" device property is not set (default) and Zoned Namespace Command Set otherwise.
Define values and structures that are needed to support Zoned Namespace Command Set (NVMe TP 4053) in PCI NVMe controller emulator. Define trace events where needed in newly introduced code.
In order to improve scalability, all open, closed and full zones are organized in separate linked lists. Consequently, almost all zone operations don't require scanning of the entire zone array (which potentially can be quite large) - it is only necessary to enumerate one or more zone lists.
Handlers for three new NVMe commands introduced in Zoned Namespace Command Set specification are added, namely for Zone Management Receive, Zone Management Send and Zone Append.
Device initialization code has been extended to create a proper configuration for zoned operation using device properties.
Read/Write command handler is modified to only allow writes at the write pointer if the namespace is zoned. For Zone Append command, writes implicitly happen at the write pointer and the starting write pointer value is returned as the result of the command. Write Zeroes handler is modified to add zoned checks that are identical to those done as a part of Write flow.
Subsequent commits in this series add ZDE support and checks for active and open zone limits.
--- hw/block/nvme-ns.h | 52 +++ hw/block/nvme.h | 6 + hw/block/nvme-ns.c | 165 +++++++++ hw/block/nvme.c | 804 +++++++++++++++++++++++++++++++++++++++++- hw/block/trace-events | 17 + 5 files changed, 1036 insertions(+), 8 deletions(-)
hw/block/nvme-ns.h +52 -0
@@ -19,9 +19,20 @@#define NVME_NS (obj) \ OBJECT_CHECK(NvmeNamespace, (obj), TYPE_NVME_NS) +typedef struct NvmeZone { +NvmeZoneDescr d; +uint64_t w_ptr; +QTAILQ_ENTRY (NvmeZone) entry; +}NvmeZone ; +typedef struct NvmeNamespaceParams {uint32_t nsid;QemuUUID uuid; + +bool zoned; +bool cross_zone_read; +uint64_t zone_size_bs; +uint64_t zone_cap_bs; }NvmeNamespaceParams ; typedef struct NvmeNamespace {
@@ -33,6 +44,17 @@ typedef struct NvmeNamespace {const uint32_t *iocs;uint8_t csi; +NvmeIdNsZoned *id_ns_zoned; +NvmeZone *zone_array; + QTAILQ_HEAD(, NvmeZone) exp_open_zones; + QTAILQ_HEAD(, NvmeZone) imp_open_zones; + QTAILQ_HEAD(, NvmeZone) closed_zones; + QTAILQ_HEAD(, NvmeZone) full_zones; +uint32_t num_zones; +uint64_t zone_size; +uint64_t zone_capacity; +uint32_t zone_size_log2; +NvmeNamespaceParams params;struct {
@@ -74,8 +96,38 @@ static inline size_t nvme_l2b(NvmeNamespace *ns, uint64_t lba)typedef struct NvmeCtrl NvmeCtrl ; +static inline enum NvmeZoneState nvme_get_zone_state (NvmeZone *zone) +{ +return zone->d.zs >>4 ; +} + +static inline void nvme_set_zone_state (NvmeZone *zone,enum NvmeZoneState state) +{ + zone->d.zs = state <<4 ; +} + +static inline uint64_t nvme_zone_rd_boundary (NvmeNamespace *ns,NvmeZone *zone) +{ +return zone->d.zslba + ns->zone_size; +} + +static inline uint64_t nvme_zone_wr_boundary (NvmeZone *zone) +{ +return zone->d.zslba + zone->d.zcap; +} + +static inline bool nvme_wp_is_valid (NvmeZone *zone) +{ +uint8_t st =nvme_get_zone_state (zone); + +return st !=NVME_ZONE_STATE_FULL && + st !=NVME_ZONE_STATE_READ_ONLY && + st !=NVME_ZONE_STATE_OFFLINE ; +} +int nvme_ns_setup (NvmeCtrl *n,NvmeNamespace *ns,Error **errp);void nvme_ns_drain (NvmeNamespace *ns);void nvme_ns_shutdown (NvmeNamespace *ns); +void nvme_ns_cleanup (NvmeNamespace *ns);#endif /* NVME_NS_H */
hw/block/nvme.h +6 -0
@@ -6,6 +6,9 @@#define NVME_MAX_NAMESPACES 256 +#define NVME_DEFAULT_ZONE_SIZE (128 * MiB) +#define NVME_DEFAULT_MAX_ZA_SIZE (128 * KiB) + typedef struct NvmeParams { char *serial; uint32_t num_queues; /* deprecated since 5.1 */
@@ -16,6 +19,7 @@ typedef struct NvmeParams {uint32_t aer_max_queued;uint8_t mdts;bool use_intel_id; +uint32_t zasl_bs; } NvmeParams; typedef struct NvmeAsyncEvent {
@@ -149,6 +153,8 @@ typedef struct NvmeCtrl { QTAILQ_HEAD(, NvmeAsyncEvent) aer_queue;int aer_queued; +uint8_t zasl; +NvmeNamespace namespace;NvmeNamespace *namespaces[NVME_MAX_NAMESPACES ];NvmeSQueue **sq;
hw/block/nvme-ns.c +165 -0
195 lines not on this page · raw message
hw/block/nvme.c +796 -8
960 lines not on this page · raw message
hw/block/trace-events +17 -0
@@ -93,6 +93,14 @@ pci_nvme_mmio_start_success(void) "setting controller enable bit succeeded" pci_nvme_mmio_stopped(void) "cleared controller enable bit" pci_nvme_mmio_shutdown_set(void) "shutdown bit set" pci_nvme_mmio_shutdown_cleared(void) "shutdown bit cleared" +pci_nvme_open_zone(uint64_t slba, uint32_t zone_idx, int all) "open zone, slba=%"PRIu64", idx=%"PRIu32", all=%"PRIi32"" +pci_nvme_close_zone(uint64_t slba, uint32_t zone_idx, int all) "close zone, slba=%"PRIu64", idx=%"PRIu32", all=%"PRIi32"" +pci_nvme_finish_zone(uint64_t slba, uint32_t zone_idx, int all) "finish zone, slba=%"PRIu64", idx=%"PRIu32", all=%"PRIi32"" +pci_nvme_reset_zone(uint64_t slba, uint32_t zone_idx, int all) "reset zone, slba=%"PRIu64", idx=%"PRIu32", all=%"PRIi32"" +pci_nvme_offline_zone(uint64_t slba, uint32_t zone_idx, int all) "offline zone, slba=%"PRIu64", idx=%"PRIu32", all=%"PRIi32"" +pci_nvme_set_descriptor_extension(uint64_t slba, uint32_t zone_idx) "set zone descriptor extension, slba=%"PRIu64", idx=%"PRIu32"" +pci_nvme_clear_ns_close(uint32_t state, uint64_t slba) "zone state=%"PRIu32", slba=%"PRIu64" transitioned to Closed state" +pci_nvme_clear_ns_reset(uint32_t state, uint64_t slba) "zone state=%"PRIu32", slba=%"PRIu64" transitioned to Empty state" # nvme traces for error conditions pci_nvme_err_mdts(uint16_t cid, size_t len) "cid %"PRIu16" len %zu"
@@ -111,6 +119,13 @@ pci_nvme_err_invalid_opc(uint8_t opc) "invalid opcode 0x%"PRIx8"" pci_nvme_err_invalid_admin_opc(uint8_t opc) "invalid admin opcode 0x%"PRIx8"" pci_nvme_err_invalid_lba_range(uint64_t start, uint64_t len, uint64_t limit) "Invalid LBA start=%"PRIu64" len=%"PRIu64" limit=%"PRIu64"" pci_nvme_err_invalid_log_page_offset(uint64_t ofs, uint64_t size) "must be <= %"PRIu64", got %"PRIu64"" +pci_nvme_err_unaligned_zone_cmd(uint8_t action, uint64_t slba, uint64_t zslba) "unaligned zone op 0x%"PRIx32", got slba=%"PRIu64", zslba=%"PRIu64"" +pci_nvme_err_invalid_zone_state_transition(uint8_t action, uint64_t slba, uint8_t attrs) "action=0x%"PRIx8", slba=%"PRIu64", attrs=0x%"PRIx32"" +pci_nvme_err_write_not_at_wp(uint64_t slba, uint64_t zone, uint64_t wp) "writing at slba=%"PRIu64", zone=%"PRIu64", but wp=%"PRIu64"" +pci_nvme_err_append_not_at_start(uint64_t slba, uint64_t zone) "appending at slba=%"PRIu64", but zone=%"PRIu64"" +pci_nvme_err_zone_write_not_ok(uint64_t slba, uint32_t nlb, uint32_t status) "slba=%"PRIu64", nlb=%"PRIu32", status=0x%"PRIx16"" +pci_nvme_err_zone_read_not_ok(uint64_t slba, uint32_t nlb, uint32_t status) "slba=%"PRIu64", nlb=%"PRIu32", status=0x%"PRIx16"" +pci_nvme_err_append_too_large(uint64_t slba, uint32_t nlb, uint8_t zasl) "slba=%"PRIu64", nlb=%"PRIu32", zasl=%"PRIu8"" pci_nvme_err_invalid_iocsci(uint32_t idx) "unsupported command set combination index %"PRIu32"" pci_nvme_err_invalid_del_sq(uint16_t qid) "invalid submission queue deletion, sid=%"PRIu16"" pci_nvme_err_invalid_create_sq_cqid(uint16_t cqid) "failed creating submission queue, invalid cqid=%"PRIu16""
@@ -144,7 +159,9 @@ pci_nvme_err_startfail_sqent_too_large(uint8_t log2ps, uint8_t maxlog2ps) "nvme_ pci_nvme_err_startfail_css(uint8_t css) "nvme_start_ctrl failed because invalid command set selected:%u" pci_nvme_err_startfail_asqent_sz_zero(void) "nvme_start_ctrl failed because the admin submission queue size is zero" pci_nvme_err_startfail_acqent_sz_zero(void) "nvme_start_ctrl failed because the admin completion queue size is zero" +pci_nvme_err_startfail_zasl_too_small(uint32_t zasl, uint32_t pagesz) "nvme_start_ctrl failed because zone append size limit %"PRIu32" is too small, needs to be >= %"PRIu32"" pci_nvme_err_startfail(void) "setting controller enable bit failed" +pci_nvme_err_invalid_mgmt_action(int action) "action=0x%"PRIx8"" # Traces for undefined behavior pci_nvme_ub_mmiowr_misaligned32(uint64_t offset) "MMIO write not 32-bit aligned, offset=0x%"PRIx64""
Signature · 1 line
2.28.0
PATCH v11 10/13 hw/block/nvme: Introduce max active and open zone limits
In reply to Dmitry FomichevAdd two module properties, "zoned.max_active" and "zoned.max_open" to control the maximum number of zones that can be active or open. Once these variables are set to non-default values, these limits are checked during I/O and Too Many Active or Too Many Open command status is returned if they are exceeded.
--- hw/block/nvme-ns.h | 41 +++++++++++++++++++ hw/block/nvme-ns.c | 31 ++++++++++++++- hw/block/nvme.c | 92 +++++++++++++++++++++++++++++++++++++++++++ hw/block/trace-events | 2 + 4 files changed, 164 insertions(+), 2 deletions(-)
hw/block/nvme-ns.h +41 -0
@@ -33,6 +33,8 @@ typedef struct NvmeNamespaceParams {bool cross_zone_read;uint64_t zone_size_bs;uint64_t zone_cap_bs; +uint32_t max_active_zones; +uint32_t max_open_zones; } NvmeNamespaceParams; typedef struct NvmeNamespace {
@@ -54,6 +56,8 @@ typedef struct NvmeNamespace {uint64_t zone_size;uint64_t zone_capacity;uint32_t zone_size_log2; +int32_t nr_open_zones; +int32_t nr_active_zones;NvmeNamespaceParams params;
@@ -125,6 +129,43 @@ static inline bool nvme_wp_is_valid(NvmeZone *zone) st !=NVME_ZONE_STATE_OFFLINE ; } +static inline void nvme_aor_inc_open (NvmeNamespace *ns) +{ +assert (ns->nr_open_zones >=0 ); +if (ns->params.max_open_zones) { + ns->nr_open_zones++; +assert (ns->nr_open_zones <= ns->params.max_open_zones); + } +} + +static inline void nvme_aor_dec_open (NvmeNamespace *ns) +{ +if (ns->params.max_open_zones) { +assert (ns->nr_open_zones >0 ); + ns->nr_open_zones--; + } +assert (ns->nr_open_zones >=0 ); +} + +static inline void nvme_aor_inc_active (NvmeNamespace *ns) +{ +assert (ns->nr_active_zones >=0 ); +if (ns->params.max_active_zones) { + ns->nr_active_zones++; +assert (ns->nr_active_zones <= ns->params.max_active_zones); + } +} + +static inline void nvme_aor_dec_active (NvmeNamespace *ns) +{ +if (ns->params.max_active_zones) { +assert (ns->nr_active_zones >0 ); + ns->nr_active_zones--; +assert (ns->nr_active_zones >= ns->nr_open_zones); + } +assert (ns->nr_active_zones >=0 ); +} +int nvme_ns_setup (NvmeCtrl *n,NvmeNamespace *ns,Error **errp);void nvme_ns_drain (NvmeNamespace *ns);void nvme_ns_shutdown (NvmeNamespace *ns);
hw/block/nvme-ns.c +29 -2
@@ -136,6 +136,21 @@ static int nvme_ns_zoned_check_calc_geometry(NvmeNamespace *ns, Error **errp) ns->zone_size = zone_size / lbasz; ns->zone_capacity = zone_cap / lbasz; ns->num_zones = ns->size / lbasz / ns->zone_size; + +/* Do a few more sanity checks of ZNS properties */ +if (ns->params.max_open_zones > ns->num_zones) { +error_setg (errp, +"max_open_zones value %u exceeds the number of zones %u" , + ns->params.max_open_zones, ns->num_zones); +return -1 ; + } +if (ns->params.max_active_zones > ns->num_zones) { +error_setg (errp, +"max_active_zones value %u exceeds the number of zones %u" , + ns->params.max_active_zones, ns->num_zones); +return -1 ; + } +return 0 ; }
@@ -183,8 +198,8 @@ static void nvme_ns_init_zoned(NvmeCtrl *n, NvmeNamespace *ns, int lba_index) id_ns_z =g_malloc0 (sizeof (NvmeIdNsZoned));/* MAR/MOR are zeroes-based, 0xffffffff means no limit */ - id_ns_z->mar =0xffffffff ; - id_ns_z->mor =0xffffffff ; + id_ns_z->mar =cpu_to_le32 (ns->params.max_active_zones -1 ); + id_ns_z->mor =cpu_to_le32 (ns->params.max_open_zones -1 ); id_ns_z->zoc =0 ; id_ns_z->ozcs = ns->params.cross_zone_read ?0x01 :0x00 ;
@@ -210,6 +225,7 @@ static void nvme_clear_zone(NvmeNamespace *ns, NvmeZone *zone)trace_pci_nvme_clear_ns_close (state, zone->d.zslba);nvme_set_zone_state (zone,NVME_ZONE_STATE_CLOSED ); } +nvme_aor_inc_active (ns);QTAILQ_INSERT_HEAD (&ns->closed_zones, zone, entry); }else {trace_pci_nvme_clear_ns_reset (state, zone->d.zslba);
@@ -226,16 +242,23 @@ static void nvme_zoned_ns_shutdown(NvmeNamespace *ns) QTAILQ_FOREACH_SAFE(zone, &ns->closed_zones, entry, next) {QTAILQ_REMOVE (&ns->closed_zones, zone, entry); +nvme_aor_dec_active (ns);nvme_clear_zone (ns, zone); } QTAILQ_FOREACH_SAFE(zone, &ns->imp_open_zones, entry, next) {QTAILQ_REMOVE (&ns->imp_open_zones, zone, entry); +nvme_aor_dec_open (ns); +nvme_aor_dec_active (ns);nvme_clear_zone (ns, zone); } QTAILQ_FOREACH_SAFE(zone, &ns->exp_open_zones, entry, next) {QTAILQ_REMOVE (&ns->exp_open_zones, zone, entry); +nvme_aor_dec_open (ns); +nvme_aor_dec_active (ns);nvme_clear_zone (ns, zone); } + +assert (ns->nr_open_zones ==0 ); }static int nvme_ns_check_constraints (NvmeNamespace *ns,Error **errp)
@@ -320,6 +343,10 @@ static Property nvme_ns_props[] = {DEFINE_PROP_SIZE ("zoned.zcap" , NvmeNamespace, params.zone_cap_bs,0 ),DEFINE_PROP_BOOL ("zoned.cross_read" , NvmeNamespace, params.cross_zone_read, false), +DEFINE_PROP_UINT32 ("zoned.max_active" , NvmeNamespace, + params.max_active_zones,0 ), +DEFINE_PROP_UINT32 ("zoned.max_open" , NvmeNamespace, + params.max_open_zones,0 ), DEFINE_PROP_END_OF_LIST(), };
hw/block/nvme.c +92 -0
153 lines not on this page · raw message
hw/block/trace-events +2 -0
@@ -126,6 +126,8 @@ pci_nvme_err_append_not_at_start(uint64_t slba, uint64_t zone) "appending at slb pci_nvme_err_zone_write_not_ok(uint64_t slba, uint32_t nlb, uint32_t status) "slba=%"PRIu64", nlb=%"PRIu32", status=0x%"PRIx16"" pci_nvme_err_zone_read_not_ok(uint64_t slba, uint32_t nlb, uint32_t status) "slba=%"PRIu64", nlb=%"PRIu32", status=0x%"PRIx16"" pci_nvme_err_append_too_large(uint64_t slba, uint32_t nlb, uint8_t zasl) "slba=%"PRIu64", nlb=%"PRIu32", zasl=%"PRIu8"" +pci_nvme_err_insuff_active_res(uint32_t max_active) "max_active=%"PRIu32" zone limit exceeded" +pci_nvme_err_insuff_open_res(uint32_t max_open) "max_open=%"PRIu32" zone limit exceeded" pci_nvme_err_invalid_iocsci(uint32_t idx) "unsupported command set combination index %"PRIu32"" pci_nvme_err_invalid_del_sq(uint16_t qid) "invalid submission queue deletion, sid=%"PRIu16"" pci_nvme_err_invalid_create_sq_cqid(uint16_t cqid) "failed creating submission queue, invalid cqid=%"PRIu16""
Signature · 1 line
2.28.0
v11 cover hw/block/nvme: Support Namespace Types and Zoned Namespace Command Set
v10 -> v11:
- Address review comments by Klaus.
- Add a patch to separate the handling of controller reset and subsystem shutdown. Place the patch at the beginning of the series so it can be picked up separately.
- Rebase on the current nvme-next branch.
v9 -> v10:
- Correctly check for MDTS in Zone Management Receive handler.
- Change Klaus' "Reviewed-by" email in UUID patch.
v8 -> v9:
- Move the modifications to "include/block/nvme.h" made to introduce ZNS-related definitions to a separate patch.
- Add a new struct, NvmeZonedResult, along the same lines as the existing NvmeAerResult, to carry Zone Append LBA returned to the host. Now, there is no need to modify NvmeCqe struct except renaming DW1 field from "rsvd" to "dw1".
- Add check for MDTS in Zone Management Receive handler.
- Remove checks for ns->attached since the value of this flag is always true for now.
- Rebase to the current quemu-nvme/nvme-next branch.
v7 -> v8:
- Move refactoring commits to the front of the series.
- Remove "attached" and "fill_pattern" device properties.
- Only close open zones upon subsystem shutdown, not when CC.EN flag is set to 0. Avoid looping through all zones by iterating through lists of open and closed zones.
- Improve bulk processing of zones aka zoned operations with "all" flag set. Avoid looping through the entire zone array for all zone operations except Offline Zone.
- Prefix ZNS-related property names with "zoned.". The "zoned" Boolean property is retained to turn on zoned command set as it is much more intuitive and user-friendly compared to setting a magic number value to csi property.
- Address review comments.
- Remove unused trace events.
v6 -> v7:
- Introduce ns->iocs initialization function earlier in the series, in CSE Log patch.
- Set NVM iocs for zoned namespaces when CC.CSS is set to NVME_CC_CSS_NVM.
- Clean up code in CSE log handler.
v5 -> v6:
- Remove zoned state persistence code. Replace position-independent zone lists with QTAILQs.
- Close all open zones upon clearing of the controller. This is a similar procedure to the one previously performed upon powering up with zone persistence.
- Squash NS Types and ZNS triplets of commits to keep definitions and trace event definitions together with the implementation code.
- Move namespace UUID generation to a separate patch. Add the new "uuid" property as suggested by Klaus.
- Rework Commands and Effects patch to make sure that the log is always in sync with the actual set of commands supported.
- Add two refactoring commits at the end of the series to optimize read and write i/o path.
- Incorporate feedback from Keith, Klaus and Niklas:
* fix rebase errors in nvme_identify_ns_descr_list()
* remove unnecessary code from nvme_write_bar()
* move csi to NvmeNamespace and use it from the beginning in NSTypes patch
* change zone read processing to cover all corner cases with RAZB=1
* sync w_ptr and d.wp in case of a i/o error at the preceding zone
* reword the commit message in active/inactive patch with the new text from Niklas
* correct dlfeat reporting depending on the fill pattern set
* add more checks for "attached" n/s parameter to prevent i/o and get/set features on inactive namespaces
* Use DEFINE_PROP_SIZE and DEFINE_PROP_SIZE32 for zone size/capacity and ZASL respectively
* Improve zone size and capacity validation
* Correctly report NSZE
v4 -> v5:
- Rebase to the current qemu-nvme.
- Use HostMemoryBackendFile as the backing storage for persistent zone metadata.
- Fix the issue with filling the valid data in the next zone if RAZB is enabled.
v3 -> v4:
- Fix bugs introduced in v2/v3 for QD > 1 operation. Now, all writes to a zone happen at the new write pointer variable, zone->w_ptr, that is advanced right after submitting the backend i/o. The existing zone->d.wp variable is updated upon the successful write completion and it is used for zone reporting. Some code has been split from nvme_finalize_zoned_write() function to a new function, nvme_advance_zone_wp().
- Make the code compile under mingw. Switch to using QEMU API for mmap/msync, i.e. memory_region...(). Since mmap is not available in mingw (even though there is mman-win32 library available on Github), conditional compilation is added around these calls to avoid undefined symbols under mingw. A better fix would be to add stub functions to softmmu/memory.c for the case when CONFIG_POSIX is not defined, but such change is beyond the scope of this patchset and it can be made in a separate patch.
- Correct permission mask used to open zone metadata file.
- Fold "Define 64 bit cqe.result" patch into ZNS commit.
- Use clz64/clz32 instead of defining nvme_ilog2() function.
- Simplify rpt_empty_id_struct() code, move nvme_fill_data() back to ZNS patch.
- Fix a power-on processing bug.
- Rename NVME_CMD_ZONE_APND to NVME_CMD_ZONE_APPEND.
- Make the list of review comments addressed in v2 of the series (see below).
v2 -> v3:
- Moved nvme_fill_data() function to the NSTypes patch as it is now used there to output empty namespace identify structs.
- Fixed typo in Maxim's email address.
v1 -> v2:
- Rebased on top of qemu-nvme/next branch.
- Incorporated feedback from Klaus and Alistair.
* Allow a subset of CSE log to be read, not the entire log
* Assign admin command entries in CSE log to ACS fields
* Set LPA bit 1 to indicate support of CSE log page
* Rename CC.CSS value CSS_ALL_NSTYPES (110b) to CSS_CSI
* Move the code to assign lbaf.ds to a separate patch
* Remove the change in firmware revision
* Change "driver" to "device" in comments and annotations
* Rename ZAMDS to ZASL
* Correct a few format expressions and some wording in trace event definitions
* Remove validation code to return NVME_CAP_EXCEEDED error
* Make ZASL to be equal to MDTS if "zone_append_size_limit" module parameter is not set
* Clean up nvme_zoned_init_ctrl() to make size calculations less confusing
* Avoid changing module parameters, use separate n/s variables if additional calculations are necessary to convert parameters to running values
* Use NVME_DEFAULT_ZONE_SIZE to assign the default zone size value
* Use default 0 for zone capacity meaning that zone capacity will be equal to zone size by default
* Issue warnings if user MAR/MOR values are too large and have to be adjusted
* Use unsigned values for MAR/MOR
- Dropped "Simulate Zone Active excursions" patch. Excursion behavior may depend on the internal controller architecture and therefore be vendor-specific.
- Dropped support for Zone Attributes and zoned AENs for now. These features can be added in a future series.
- NS Types support is extended to handle active/inactive namespaces.
- Update the write pointer after backing storage I/O completion, not before. This makes the emulation to run correctly in case of backing device failures.
- Avoid division in the I/O path if the device zone size is a power of two (the most common case). Zone index then can be calculated by using bit shift.
- A few reported bugs have been fixed.
- Indentation in function definitions has been changed to make it the same as the rest of the code.
Zoned Namespace (ZNS) Command Set is a newly introduced command set published by the NVM Express, Inc. organization as TP 4053. The main design goals of ZNS are to provide hardware designers the means to reduce NVMe controller complexity and to allow achieving a better I/O latency and throughput. SSDs that implement this interface are commonly known as ZNS SSDs.
This command set is implementing a zoned storage model, similarly to ZAC/ZBC. As such, there is already support in Linux, allowing one to perform the majority of tasks needed for managing ZNS SSDs.
The Zoned Namespace Command Set relies on another TP, known as Namespace Types (NVMe TP 4056), which introduces support for having multiple command sets per namespace.
Both ZNS and Namespace Types specifications can be downloaded by visiting the following link -
https://nvmexpress.org/wp-content/uploads/NVM-Express-1.4-Ratified-TPs.zip
This patch series adds Namespace Types support and zoned namespace emulation capability to the existing NVMe PCI device.
Based-on: <[email protected]> Dmitry Fomichev (11):
hw/block/nvme: Process controller reset and shutdown differently hw/block/nvme: Generate namespace UUIDs hw/block/nvme: Separate read and write handlers hw/block/nvme: Combine nvme_write_zeroes() and nvme_write() hw/block/nvme: Add Commands Supported and Effects log block/nvme: Make ZNS-related definitions hw/block/nvme: Support Zoned Namespace Command Set hw/block/nvme: Introduce max active and open zone limits hw/block/nvme: Support Zone Descriptor Extensions hw/block/nvme: Add injection of Offline/Read-Only zones hw/block/nvme: Document zoned parameters in usage text
Niklas Cassel (2):
hw/block/nvme: Add support for Namespace Types hw/block/nvme: Support allocated CNS command variants
hw/block/nvme-ns.h | 108 +++- hw/block/nvme.h | 6 + include/block/nvme.h | 201 +++++- hw/block/nvme-ns.c | 271 +++++++- hw/block/nvme.c | 1432 ++++++++++++++++++++++++++++++++++++++--- hw/block/trace-events | 32 +- 6 files changed, 1927 insertions(+), 123 deletions(-)
Signature · 1 line
2.28.0
PATCH v11 12/13 hw/block/nvme: Add injection of Offline/Read-Only zones
ZNS specification defines two zone conditions for the zones that no longer can function properly, possibly because of flash wear or other internal fault. It is useful to be able to "inject" a small number of such zones for testing purposes.
This commit defines two optional device properties, "offline_zones" and "rdonly_zones". Users can assign non-zero values to these variables to specify the number of zones to be initialized as Offline or Read-Only. The actual number of injected zones may be smaller than the requested amount - Read-Only and Offline counts are expected to be much smaller than the total number of zones on a drive.
--- hw/block/nvme-ns.h | 2 ++ hw/block/nvme-ns.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+)
hw/block/nvme-ns.h +2 -0
@@ -36,6 +36,8 @@ typedef struct NvmeNamespaceParams {uint32_t max_active_zones;uint32_t max_open_zones;uint32_t zd_extension_size; +uint32_t nr_offline_zones; +uint32_t nr_rdonly_zones; } NvmeNamespaceParams; typedef struct NvmeNamespace {
hw/block/nvme-ns.c +53 -0
84 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH v11 1/13 hw/block/nvme: Process controller reset and shutdown differently
In reply to Dmitry FomichevController reset ans subsystem shutdown are handled very much the same in the current code, but some of the steps should be different in these two cases.
Introduce two new functions, nvme_reset_ctrl() and nvme_shutdown_ctrl(), to separate some portions of the code from nvme_clear_ctrl(). The steps that are made different between reset and shutdown are that BAR.CC is not reset to zero upon the shutdown and namespace data is flushed to backing storage as a part of shutdown handling, but not upon reset.
--- hw/block/nvme-ns.h | 2 +- hw/block/nvme-ns.c | 2 +- hw/block/nvme.c | 24 ++++++++++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-)
hw/block/nvme-ns.h +1 -1
@@ -73,6 +73,6 @@ typedef struct NvmeCtrl NvmeCtrl;int nvme_ns_setup (NvmeCtrl *n,NvmeNamespace *ns,Error **errp);void nvme_ns_drain (NvmeNamespace *ns); -void nvme_ns_flush (NvmeNamespace *ns); +void nvme_ns_shutdown (NvmeNamespace *ns);#endif /* NVME_NS_H */
hw/block/nvme-ns.c +1 -1
@@ -130,7 +130,7 @@ void nvme_ns_drain(NvmeNamespace *ns)blk_drain (ns->blkconf.blk); } -void nvme_ns_flush (NvmeNamespace *ns) +void nvme_ns_shutdown (NvmeNamespace *ns) {blk_flush (ns->blkconf.blk); }
hw/block/nvme.c +18 -6
@@ -2197,6 +2197,20 @@ static void nvme_clear_ctrl(NvmeCtrl *n) n->aer_queued =0 ; n->outstanding_aers =0 ; n->qs_created = false; +} + +static void nvme_ctrl_reset (NvmeCtrl *n) +{ +nvme_clear_ctrl (n); + n->bar.cc =0 ; +} + +static void nvme_ctrl_shutdown (NvmeCtrl *n) +{ +NvmeNamespace *ns; +int i; + +nvme_clear_ctrl (n);for (i =1 ; i <= n->num_namespaces; i++) { ns =nvme_ns (n, i);
@@ -2204,10 +2218,8 @@ static void nvme_clear_ctrl(NvmeCtrl *n)continue ; } -nvme_ns_flush (ns); +nvme_ns_shutdown (ns); } - - n->bar.cc =0 ; }static int nvme_start_ctrl (NvmeCtrl *n)
@@ -2374,12 +2386,12 @@ static void nvme_write_bar(NvmeCtrl *n, hwaddr offset, uint64_t data, } }else if (!NVME_CC_EN (data) &&NVME_CC_EN (n->bar.cc)) {trace_pci_nvme_mmio_stopped (); -nvme_clear_ctrl (n); +nvme_ctrl_reset (n); n->bar.csts &= ~NVME_CSTS_READY ; }if (NVME_CC_SHN (data) && !(NVME_CC_SHN (n->bar.cc))) {trace_pci_nvme_mmio_shutdown_set (); -nvme_clear_ctrl (n); +nvme_ctrl_shutdown (n); n->bar.cc = data; n->bar.csts |=NVME_CSTS_SHST_COMPLETE ; }else if (!NVME_CC_SHN (data) &&NVME_CC_SHN (n->bar.cc)) {
@@ -2990,7 +3002,7 @@ static void nvme_exit(PCIDevice *pci_dev) {NvmeCtrl *n =NVME (pci_dev); -nvme_clear_ctrl (n); +nvme_ctrl_shutdown (n);g_free (n->cq);g_free (n->sq);g_free (n->aer_reqs);
Signature · 1 line
2.28.0
Re: [PATCH v11 08/13] block/nvme: Make ZNS-related definitions
In reply to Dmitry FomichevCC for Stefan (nvme block driver co-maintainer).
Quoted 205 lines · Dmitry Fomichev
Define values and structures that are needed to support Zoned Namespace Command Set (NVMe TP 4053).
Signed-off-by Dmitry Fomichev <[email protected]>--- include/block/nvme.h | 114 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-)include/block/nvme.h +113
-1@@ -489,6 +489,9 @@ enum NvmeIoCommands {NVME_CMD_COMPARE =0x05 ,NVME_CMD_WRITE_ZEROES =0x08 ,NVME_CMD_DSM =0x09 , +NVME_CMD_ZONE_MGMT_SEND =0x79 , +NVME_CMD_ZONE_MGMT_RECV =0x7a , + NVME_CMD_ZONE_APPEND = 0x7d, }; typedef struct QEMU_PACKED NvmeDeleteQ {@@ -648,9 +651,13 @@ typedef struct QEMU_PACKED NvmeAerResult {uint8_t resv; } NvmeAerResult; +typedef struct QEMU_PACKED NvmeZonedResult { +uint64_t slba; +} NvmeZonedResult; + typedef struct QEMU_PACKED NvmeCqe {uint32_t result; -uint32_t rsvd; +uint32_t dw1;uint16_t sq_head;uint16_t sq_id;uint16_t cid;@@ -679,6 +686,7 @@ enum NvmeStatusCodes {NVME_INVALID_USE_OF_CMB =0x0012 ,NVME_INVALID_PRP_OFFSET =0x0013 ,NVME_CMD_SET_CMB_REJECTED =0x002b , +NVME_INVALID_CMD_SET =0x002c ,NVME_LBA_RANGE =0x0080 ,NVME_CAP_EXCEEDED =0x0081 , NVME_NS_NOT_READY = 0x0082,@@ -703,6 +711,14 @@ enum NvmeStatusCodes {NVME_CONFLICTING_ATTRS =0x0180 ,NVME_INVALID_PROT_INFO =0x0181 ,NVME_WRITE_TO_RO =0x0182 , +NVME_ZONE_BOUNDARY_ERROR =0x01b8 , +NVME_ZONE_FULL =0x01b9 , +NVME_ZONE_READ_ONLY =0x01ba , +NVME_ZONE_OFFLINE =0x01bb , +NVME_ZONE_INVALID_WRITE =0x01bc , +NVME_ZONE_TOO_MANY_ACTIVE =0x01bd , +NVME_ZONE_TOO_MANY_OPEN =0x01be , +NVME_ZONE_INVAL_TRANSITION =0x01bf ,NVME_WRITE_FAULT =0x0280 ,NVME_UNRECOVERED_READ =0x0281 , NVME_E2E_GUARD_ERROR = 0x0282,@@ -888,6 +904,11 @@ typedef struct QEMU_PACKED NvmeIdCtrl {uint8_t vs[1024 ]; } NvmeIdCtrl; +typedef struct NvmeIdCtrlZoned { +uint8_t zasl; +uint8_t rsvd1[4095 ]; +}NvmeIdCtrlZoned ; +enum NvmeIdCtrlOacs {NVME_OACS_SECURITY =1 <<0 ,NVME_OACS_FORMAT =1 <<1 ,@@ -1016,6 +1037,12 @@ typedef struct QEMU_PACKED NvmeLBAF {uint8_t rp; } NvmeLBAF; +typedef struct QEMU_PACKED NvmeLBAFE { +uint64_t zsze; +uint8_t zdes; +uint8_t rsvd9[7 ]; +} NvmeLBAFE; +#define NVME_NSID_BROADCAST 0xffffffff typedef struct QEMU_PACKED NvmeIdNs {@@ -1075,10 +1102,24 @@ enum NvmeNsIdentifierType {enum NvmeCsi {NVME_CSI_NVM =0x00 , +NVME_CSI_ZONED =0x02 , };#define NVME_SET_CSI (vec, csi) (vec |= (uint8_t)(1 << (csi))) +typedef struct QEMU_PACKED NvmeIdNsZoned { +uint16_t zoc; +uint16_t ozcs; +uint32_t mar; +uint32_t mor; +uint32_t rrl; +uint32_t frl; +uint8_t rsvd20[2796 ]; +NvmeLBAFE lbafe[16 ]; +uint8_t rsvd3072[768 ]; +uint8_t vs[256 ]; +} NvmeIdNsZoned; +/*Deallocate Logical Block Features*/ #define NVME_ID_NS_DLFEAT_GUARD_CRC (dlfeat) ((dlfeat) & 0x10)#define NVME_ID_NS_DLFEAT_WRITE_ZEROES (dlfeat) ((dlfeat) & 0x08)@@ -1111,10 +1152,76 @@ enum NvmeIdNsDps { DPS_FIRST_EIGHT = 8, }; +enum NvmeZoneAttr { +NVME_ZA_FINISHED_BY_CTLR =1 <<0 , +NVME_ZA_FINISH_RECOMMENDED =1 <<1 , +NVME_ZA_RESET_RECOMMENDED =1 <<2 , +NVME_ZA_ZD_EXT_VALID =1 <<7 , +}; + +typedef struct QEMU_PACKED NvmeZoneReportHeader { +uint64_t nr_zones; +uint8_t rsvd[56 ]; +} NvmeZoneReportHeader; + +enum NvmeZoneReceiveAction { +NVME_ZONE_REPORT =0 , +NVME_ZONE_REPORT_EXTENDED =1 , +}; + +enum NvmeZoneReportType { +NVME_ZONE_REPORT_ALL =0 , +NVME_ZONE_REPORT_EMPTY =1 , +NVME_ZONE_REPORT_IMPLICITLY_OPEN =2 , +NVME_ZONE_REPORT_EXPLICITLY_OPEN =3 , +NVME_ZONE_REPORT_CLOSED =4 , +NVME_ZONE_REPORT_FULL =5 , +NVME_ZONE_REPORT_READ_ONLY =6 , +NVME_ZONE_REPORT_OFFLINE =7 , +}; + +enum NvmeZoneType { +NVME_ZONE_TYPE_RESERVED =0x00 , +NVME_ZONE_TYPE_SEQ_WRITE =0x02 , +}; + +enum NvmeZoneSendAction { +NVME_ZONE_ACTION_RSD =0x00 , +NVME_ZONE_ACTION_CLOSE =0x01 , +NVME_ZONE_ACTION_FINISH =0x02 , +NVME_ZONE_ACTION_OPEN =0x03 , +NVME_ZONE_ACTION_RESET =0x04 , +NVME_ZONE_ACTION_OFFLINE =0x05 , +NVME_ZONE_ACTION_SET_ZD_EXT =0x10 , +}; + +typedef struct QEMU_PACKED NvmeZoneDescr { +uint8_t zt; +uint8_t zs; +uint8_t za; +uint8_t rsvd3[5 ]; +uint64_t zcap; +uint64_t zslba; +uint64_t wp; +uint8_t rsvd32[32 ]; +} NvmeZoneDescr; + +enum NvmeZoneState { +NVME_ZONE_STATE_RESERVED =0x00 , +NVME_ZONE_STATE_EMPTY =0x01 , +NVME_ZONE_STATE_IMPLICITLY_OPEN =0x02 , +NVME_ZONE_STATE_EXPLICITLY_OPEN =0x03 , +NVME_ZONE_STATE_CLOSED =0x04 , +NVME_ZONE_STATE_READ_ONLY =0x0D , +NVME_ZONE_STATE_FULL =0x0E , +NVME_ZONE_STATE_OFFLINE =0x0F , +}; +static inline void _nvme_check_size (void ) {QEMU_BUILD_BUG_ON (sizeof (NvmeBar) !=4096 );QEMU_BUILD_BUG_ON (sizeof (NvmeAerResult) !=4 ); +QEMU_BUILD_BUG_ON (sizeof (NvmeZonedResult) !=8 );QEMU_BUILD_BUG_ON (sizeof (NvmeCqe) !=16 );QEMU_BUILD_BUG_ON (sizeof (NvmeDsmRange) !=16 );QEMU_BUILD_BUG_ON (sizeof (NvmeCmd) !=64 );@@ -1130,8 +1237,13 @@ static inline void _nvme_check_size(void)QEMU_BUILD_BUG_ON (sizeof (NvmeSmartLog) !=512 );QEMU_BUILD_BUG_ON (sizeof (NvmeEffectsLog) !=4096 );QEMU_BUILD_BUG_ON (sizeof (NvmeIdCtrl) !=4096 ); +QEMU_BUILD_BUG_ON (sizeof (NvmeIdCtrlZoned) !=4096 ); +QEMU_BUILD_BUG_ON (sizeof (NvmeLBAF) !=4 ); +QEMU_BUILD_BUG_ON (sizeof (NvmeLBAFE) !=16 );QEMU_BUILD_BUG_ON (sizeof (NvmeIdNs) !=4096 ); +QEMU_BUILD_BUG_ON (sizeof (NvmeIdNsZoned) !=4096 );QEMU_BUILD_BUG_ON (sizeof (NvmeSglDescriptor) !=16 );QEMU_BUILD_BUG_ON (sizeof (NvmeIdNsDescr) !=4 ); + QEMU_BUILD_BUG_ON(sizeof(NvmeZoneDescr) != 64); }#endif Signature · 1 line
2.28.0
Signature · 1 line
One of us - No more doubt, silence or taboo about mental illness.
Hi Dmitry,
By and large, this looks OK to me. There are still some issues here and there, and some comments of mine that you did not address, but I will follow up with patches to fix that. Let's get this merged.
It looks like the nvme-next you rebased on is slightly old and missing two commits:
"hw/block/nvme: remove superfluous NvmeCtrl parameter" and "hw/block/nvme: pull aio error handling"
It caused a couple of conflicts, but nothing that I couldn't fix up.
Since I didn't manage to convince anyone about the zsze and zcap parameters being in terms of LBAs, I'll revert that to be 'zoned.zone_size' and 'zoned.zone_capacity'.
Finally, would you accept that we skip "hw/block/nvme: Add injection of Offline/Read-Only zones" for now? I'd like to discuss it a bit since I think the random injects feels a bit ad-hoc. Back when I did OCSSD emulation with Hans, we did something like this for setting up state through a descriptor text file - I think we should explore something like that before we lock down the two parameters. I'll amend the final documentation commit to not include those parameters.
Sounds good?
Otherwise, I think this is mergeable to nvme-next. So, for the series (excluding "hw/block/nvme: Add injection of Offline/Read-Only zones"):
Quoted 255 lines · Dmitry Fomichev
v10 -> v11:
- Address review comments by Klaus.
- Add a patch to separate the handling of controller reset and subsystem shutdown. Place the patch at the beginning of the series so it can be picked up separately.
- Rebase on the current nvme-next branch.
v9 -> v10:
- Correctly check for MDTS in Zone Management Receive handler.
- Change Klaus' "Reviewed-by" email in UUID patch.
v8 -> v9:
- Move the modifications to "
include/block/nvme.h" made to introduce ZNS-related definitions to a separate patch.- Add a new struct, NvmeZonedResult, along the same lines as the existing NvmeAerResult, to carry Zone Append LBA returned to the host. Now, there is no need to modify NvmeCqe struct except renaming DW1 field from "rsvd" to "dw1".
- Add check for MDTS in Zone Management Receive handler.
- Remove checks for
ns->attachedsince the value of this flag is always true for now.- Rebase to the current quemu-nvme/nvme-next branch.
v7 -> v8:
- Move refactoring commits to the front of the series.
- Remove "attached" and "
fill_pattern" device properties.- Only close open zones upon subsystem shutdown, not when CC.EN flag is set to 0. Avoid looping through all zones by iterating through lists of open and closed zones.
- Improve bulk processing of zones aka zoned operations with "all" flag set. Avoid looping through the entire zone array for all zone operations except Offline Zone.
- Prefix ZNS-related property names with "zoned.". The "zoned" Boolean property is retained to turn on zoned command set as it is much more intuitive and user-friendly compared to setting a magic number value to csi property.
- Address review comments.
- Remove unused trace events.
v6 -> v7:
- Introduce
ns->iocsinitialization function earlier in the series, in CSE Log patch.- Set NVM iocs for zoned namespaces when CC.CSS is set to
NVME_CC_CSS_NVM.- Clean up code in CSE log handler.
v5 -> v6:
- Remove zoned state persistence code. Replace position-independent zone lists with QTAILQs.
- Close all open zones upon clearing of the controller. This is a similar procedure to the one previously performed upon powering up with zone persistence.
- Squash NS Types and ZNS triplets of commits to keep definitions and trace event definitions together with the implementation code.
- Move namespace UUID generation to a separate patch. Add the new "uuid" property as suggested by Klaus.
- Rework Commands and Effects patch to make sure that the log is always in sync with the actual set of commands supported.
- Add two refactoring commits at the end of the series to optimize read and write i/o path.
- Incorporate feedback from Keith, Klaus and Niklas:
* fix rebase errors in
nvme_identify_ns_descr_list()
* remove unnecessary code fromnvme_write_bar()
* move csi to NvmeNamespace and use it from the beginning in NSTypes patch
* change zone read processing to cover all corner cases with RAZB=1
* syncw_ptrand d.wp in case of a i/o error at the preceding zone
* reword the commit message in active/inactive patch with the new text from Niklas
* correct dlfeat reporting depending on the fill pattern set
* add more checks for "attached" n/s parameter to prevent i/o and get/set features on inactive namespaces
* UseDEFINE_PROP_SIZEandDEFINE_PROP_SIZE32for zone size/capacity and ZASL respectively
* Improve zone size and capacity validation
* Correctly report NSZEv4 -> v5:
- Rebase to the current qemu-nvme.
- Use HostMemoryBackendFile as the backing storage for persistent zone metadata.
- Fix the issue with filling the valid data in the next zone if RAZB is enabled.
v3 -> v4:
- Fix bugs introduced in v2/v3 for QD > 1 operation. Now, all writes to a zone happen at the new write pointer variable,
zone->w_ptr, that is advanced right after submitting the backend i/o. The existingzone->d.wpvariable is updated upon the successful write completion and it is used for zone reporting. Some code has been split fromnvme_finalize_zoned_write()function to a new function,nvme_advance_zone_wp().- Make the code compile under mingw. Switch to using QEMU API for mmap/msync, i.e. memory_region...(). Since mmap is not available in mingw (even though there is mman-win32 library available on Github), conditional compilation is added around these calls to avoid undefined symbols under mingw. A better fix would be to add stub functions to
softmmu/memory.cfor the case whenCONFIG_POSIXis not defined, but such change is beyond the scope of this patchset and it can be made in a separate patch.- Correct permission mask used to open zone metadata file.
- Fold "Define 64 bit cqe.result" patch into ZNS commit.
- Use clz64/clz32 instead of defining
nvme_ilog2()function.- Simplify
rpt_empty_id_struct()code, movenvme_fill_data()back to ZNS patch.- Fix a power-on processing bug.
- Rename
NVME_CMD_ZONE_APNDtoNVME_CMD_ZONE_APPEND.- Make the list of review comments addressed in v2 of the series (see below).
v2 -> v3:
- Moved
nvme_fill_data()function to the NSTypes patch as it is now used there to output empty namespace identify structs.
- Fixed typo in Maxim's email address.v1 -> v2:
- Rebased on top of qemu-nvme/next branch.
- Incorporated feedback from Klaus and Alistair.
* Allow a subset of CSE log to be read, not the entire log
* Assign admin command entries in CSE log to ACS fields
* Set LPA bit 1 to indicate support of CSE log page
* Rename CC.CSS valueCSS_ALL_NSTYPES(110b) toCSS_CSI
* Move the code to assign lbaf.ds to a separate patch
* Remove the change in firmware revision
* Change "driver" to "device" in comments and annotations
* Rename ZAMDS to ZASL
* Correct a few format expressions and some wording in trace event definitions
* Remove validation code to returnNVME_CAP_EXCEEDEDerror
* Make ZASL to be equal to MDTS if "zone_append_size_limit" module parameter is not set
* Clean upnvme_zoned_init_ctrl()to make size calculations less confusing
* Avoid changing module parameters, use separate n/s variables if additional calculations are necessary to convert parameters to running values
* UseNVME_DEFAULT_ZONE_SIZEto assign the default zone size value
* Use default 0 for zone capacity meaning that zone capacity will be equal to zone size by default
* Issue warnings if user MAR/MOR values are too large and have to be adjusted
* Use unsigned values for MAR/MOR
- Dropped "Simulate Zone Active excursions" patch. Excursion behavior may depend on the internal controller architecture and therefore be vendor-specific.
- Dropped support for Zone Attributes and zoned AENs for now. These features can be added in a future series.
- NS Types support is extended to handle active/inactive namespaces.
- Update the write pointer after backing storage I/O completion, not before. This makes the emulation to run correctly in case of backing device failures.
- Avoid division in the I/O path if the device zone size is a power of two (the most common case). Zone index then can be calculated by using bit shift.
- A few reported bugs have been fixed.
- Indentation in function definitions has been changed to make it the same as the rest of the code.Zoned Namespace (ZNS) Command Set is a newly introduced command set published by the NVM Express, Inc. organization as TP 4053. The main design goals of ZNS are to provide hardware designers the means to reduce NVMe controller complexity and to allow achieving a better I/O latency and throughput. SSDs that implement this interface are commonly known as ZNS SSDs.
This command set is implementing a zoned storage model, similarly to ZAC/ZBC. As such, there is already support in Linux, allowing one to perform the majority of tasks needed for managing ZNS SSDs.
The Zoned Namespace Command Set relies on another TP, known as Namespace Types (NVMe TP 4056), which introduces support for having multiple command sets per namespace.
Both ZNS and Namespace Types specifications can be downloaded by visiting the following link -
https://nvmexpress.org/wp-content/uploads/NVM-Express-1.4-Ratified-TPs.zip
This patch series adds Namespace Types support and zoned namespace emulation capability to the existing NVMe PCI device.
Based-on: <[email protected]> Dmitry Fomichev (11):
hw/block/nvme: Process controller reset and shutdown differently hw/block/nvme: Generate namespace UUIDs hw/block/nvme: Separate read and write handlers hw/block/nvme: Combinenvme_write_zeroes()andnvme_write()hw/block/nvme: Add Commands Supported and Effects log block/nvme: Make ZNS-related definitions hw/block/nvme: Support Zoned Namespace Command Set hw/block/nvme: Introduce max active and open zone limits hw/block/nvme: Support Zone Descriptor Extensions hw/block/nvme: Add injection of Offline/Read-Only zones hw/block/nvme: Document zoned parameters in usage textNiklas Cassel (2):
hw/block/nvme: Add support for Namespace Types hw/block/nvme: Support allocated CNS command variantshw/block/nvme-ns.h | 108 +++- hw/block/nvme.h | 6 + include/block/nvme.h | 201 +++++- hw/block/nvme-ns.c | 271 +++++++- hw/block/nvme.c | 1432 ++++++++++++++++++++++++++++++++++++++--- hw/block/trace-events | 32 +- 6 files changed, 1927 insertions(+), 123 deletions(-)Signature · 1 line
2.28.0
Signature · 1 line
One of us - No more doubt, silence or taboo about mental illness.
Quoted 41 lines
-----Original Message-----
From: Klaus Jensen <[email protected]>
Sent: Wednesday, December 9, 2020 4:58 AM
To: Dmitry Fomichev <[email protected]>
Cc: Keith Busch <[email protected]>; Klaus Jensen <[email protected]>; Kevin Wolf <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Max Reitz <[email protected]>; Maxim Levitsky <[email protected]>; Fam Zheng <[email protected]>; Niklas Cassel <[email protected]>; Damien Le Moal <[email protected]>; [email protected]; qemu- [email protected]; Alistair Francis <[email protected]>; Matias Bjorling <[email protected]>
Subject: Re: [PATCH v11 00/13] hw/block/nvme: Support Namespace Types and Zoned Namespace Command SetHi Dmitry,
By and large, this looks OK to me. There are still some issues here and there, and some comments of mine that you did not address, but I will follow up with patches to fix that. Let's get this merged.
It looks like the nvme-next you rebased on is slightly old and missing two commits:
"hw/block/nvme: remove superfluous NvmeCtrl parameter" and "hw/block/nvme: pull aio error handling"
It caused a couple of conflicts, but nothing that I couldn't fix up.
Since I didn't manage to convince anyone about the zsze and zcap parameters being in terms of LBAs, I'll revert that to be 'zoned.zone_size' and 'zoned.zone_capacity'.
Finally, would you accept that we skip "hw/block/nvme: Add injection of Offline/Read-Only zones" for now? I'd like to discuss it a bit since I think the random injects feels a bit ad-hoc. Back when I did OCSSD emulation with Hans, we did something like this for setting up state through a descriptor text file - I think we should explore something like that before we lock down the two parameters. I'll amend the final documentation commit to not include those parameters.
Quoted 1 line
Sounds good?
Klaus,
Sounds great! Sure, we can leave out the injection patch. It was made to increase our internal test coverage, but it is not ideal. Since the zones are injected randomly, there is no consistency between test runs and it is impossible to reliably create many specific test cases (e.g. the first or the last zone is offline). The descriptor input file seems like a much more flexible and capable approach. If you have something in works, I'll be happy to discuss or review.
Thank you for your very thorough reviews!
Cheers,
Dmitry
Quoted 268 lines
Otherwise, I think this is mergeable to nvme-next. So, for the series (excluding "hw/block/nvme: Add injection of Offline/Read-Only zones"):
Reviewed-by Klaus Jensen <[email protected]>Quoted 89 lines · Dmitry Fomichev
v10 -> v11:
- Address review comments by Klaus.
- Add a patch to separate the handling of controller reset and subsystem shutdown. Place the patch at the beginning of the series so it can be picked up separately.
- Rebase on the current nvme-next branch.
v9 -> v10:
- Correctly check for MDTS in Zone Management Receive handler.
- Change Klaus' "Reviewed-by" email in UUID patch.
v8 -> v9:
- Move the modifications to "
include/block/nvme.h" made to introduce ZNS-related definitions to a separate patch.- Add a new struct, NvmeZonedResult, along the same lines as the existing NvmeAerResult, to carry Zone Append LBA returned to the host. Now, there is no need to modify NvmeCqe struct except renaming DW1 field from "rsvd" to "dw1".
- Add check for MDTS in Zone Management Receive handler.
- Remove checks for
ns->attachedsince the value of this flag is always true for now.- Rebase to the current quemu-nvme/nvme-next branch.
v7 -> v8:
- Move refactoring commits to the front of the series.
- Remove "attached" and "
fill_pattern" device properties.- Only close open zones upon subsystem shutdown, not when CC.EN flag is set to 0. Avoid looping through all zones by iterating through lists of open and closed zones.
- Improve bulk processing of zones aka zoned operations with "all" flag set. Avoid looping through the entire zone array for all zone operations except Offline Zone.
- Prefix ZNS-related property names with "zoned.". The "zoned" Boolean property is retained to turn on zoned command set as it is much more intuitive and user-friendly compared to setting a magic number value to csi property.
- Address review comments.
- Remove unused trace events.
v6 -> v7:
- Introduce
ns->iocsinitialization function earlier in the series, in CSE Log patch.- Set NVM iocs for zoned namespaces when CC.CSS is set to
NVME_CC_CSS_NVM.- Clean up code in CSE log handler.
v5 -> v6:
- Remove zoned state persistence code. Replace position-independent zone lists with QTAILQs.
- Close all open zones upon clearing of the controller. This is a similar procedure to the one previously performed upon powering up with zone persistence.
- Squash NS Types and ZNS triplets of commits to keep definitions and trace event definitions together with the implementation code.
- Move namespace UUID generation to a separate patch. Add the new "uuid" property as suggested by Klaus.
- Rework Commands and Effects patch to make sure that the log is always in sync with the actual set of commands supported.
- Add two refactoring commits at the end of the series to optimize read and write i/o path.
- Incorporate feedback from Keith, Klaus and Niklas:
Quoted 12 lines
* fix rebase errors in
nvme_identify_ns_descr_list()
* remove unnecessary code fromnvme_write_bar()
* move csi to NvmeNamespace and use it from the beginning in NSTypes patch
* change zone read processing to cover all corner cases with RAZB=1
* syncw_ptrand d.wp in case of a i/o error at the preceding zone
* reword the commit message in active/inactive patch with the new text from Niklas
* correct dlfeat reporting depending on the fill pattern set
* add more checks for "attached" n/s parameter to prevent i/o and get/set features on inactive namespaces
* UseDEFINE_PROP_SIZEandDEFINE_PROP_SIZE32for zonesize/capacity
Quoted 111 lines
and ZASL respectively
* Improve zone size and capacity validation
* Correctly report NSZEv4 -> v5:
- Rebase to the current qemu-nvme.
- Use HostMemoryBackendFile as the backing storage for persistent zone metadata.
- Fix the issue with filling the valid data in the next zone if RAZB is enabled.
v3 -> v4:
- Fix bugs introduced in v2/v3 for QD > 1 operation. Now, all writes to a zone happen at the new write pointer variable,
zone->w_ptr, that is advanced right after submitting the backend i/o. The existingzone->d.wpvariable is updated upon the successful write completion and it is used for zone reporting. Some code has been split fromnvme_finalize_zoned_write()function to a new function,nvme_advance_zone_wp().- Make the code compile under mingw. Switch to using QEMU API for mmap/msync, i.e. memory_region...(). Since mmap is not available in mingw (even though there is mman-win32 library available on Github), conditional compilation is added around these calls to avoid undefined symbols under mingw. A better fix would be to add stub functions to
softmmu/memory.cfor the case whenCONFIG_POSIXis not defined, but such change is beyond the scope of this patchset and it can be made in a separate patch.- Correct permission mask used to open zone metadata file.
- Fold "Define 64 bit cqe.result" patch into ZNS commit.
- Use clz64/clz32 instead of defining
nvme_ilog2()function.- Simplify
rpt_empty_id_struct()code, movenvme_fill_data()back to ZNS patch.- Fix a power-on processing bug.
- Rename
NVME_CMD_ZONE_APNDtoNVME_CMD_ZONE_APPEND.- Make the list of review comments addressed in v2 of the series (see below).
v2 -> v3:
- Moved
nvme_fill_data()function to the NSTypes patch as it is now used there to output empty namespace identify structs.
- Fixed typo in Maxim's email address.v1 -> v2:
- Rebased on top of qemu-nvme/next branch.
- Incorporated feedback from Klaus and Alistair.
* Allow a subset of CSE log to be read, not the entire log
* Assign admin command entries in CSE log to ACS fields
* Set LPA bit 1 to indicate support of CSE log page
* Rename CC.CSS valueCSS_ALL_NSTYPES(110b) toCSS_CSI
* Move the code to assign lbaf.ds to a separate patch
* Remove the change in firmware revision
* Change "driver" to "device" in comments and annotations
* Rename ZAMDS to ZASL
* Correct a few format expressions and some wording in trace event definitions
* Remove validation code to returnNVME_CAP_EXCEEDEDerror
* Make ZASL to be equal to MDTS if "zone_append_size_limit" module parameter is not set
* Clean upnvme_zoned_init_ctrl()to make size calculations less confusing
* Avoid changing module parameters, use separate n/s variables if additional calculations are necessary to convert parameters to running values
* UseNVME_DEFAULT_ZONE_SIZEto assign the default zone size value
* Use default 0 for zone capacity meaning that zone capacity will be equal to zone size by default
* Issue warnings if user MAR/MOR values are too large and have to be adjusted
* Use unsigned values for MAR/MOR
- Dropped "Simulate Zone Active excursions" patch. Excursion behavior may depend on the internal controller architecture and therefore be vendor-specific.
- Dropped support for Zone Attributes and zoned AENs for now. These features can be added in a future series.
- NS Types support is extended to handle active/inactive namespaces.
- Update the write pointer after backing storage I/O completion, not before. This makes the emulation to run correctly in case of backing device failures.
- Avoid division in the I/O path if the device zone size is a power of two (the most common case). Zone index then can be calculated by using bit shift.
- A few reported bugs have been fixed.
- Indentation in function definitions has been changed to make it the same as the rest of the code.Zoned Namespace (ZNS) Command Set is a newly introduced command set published by the NVM Express, Inc. organization as TP 4053. The main design goals of ZNS are to provide hardware designers the means to reduce NVMe controller complexity and to allow achieving a better I/O latency and throughput. SSDs that implement this interface are commonly known as ZNS SSDs.
This command set is implementing a zoned storage model, similarly to ZAC/ZBC. As such, there is already support in Linux, allowing one to perform the majority of tasks needed for managing ZNS SSDs.
Quoted 8 lines
The Zoned Namespace Command Set relies on another TP, known as Namespace Types (NVMe TP 4056), which introduces support for having multiple command sets per namespace.
Both ZNS and Namespace Types specifications can be downloaded by visiting the following link -
https://nvmexpress.org/wp-content/uploads/NVM-Express-1.4-Ratified-
TPs.zip
Quoted 23 lines
This patch series adds Namespace Types support and zoned namespace emulation capability to the existing NVMe PCI device.
Based-on: <[email protected]> Dmitry Fomichev (11):
hw/block/nvme: Process controller reset and shutdown differently hw/block/nvme: Generate namespace UUIDs hw/block/nvme: Separate read and write handlers hw/block/nvme: Combinenvme_write_zeroes()andnvme_write()hw/block/nvme: Add Commands Supported and Effects log block/nvme: Make ZNS-related definitions hw/block/nvme: Support Zoned Namespace Command Set hw/block/nvme: Introduce max active and open zone limits hw/block/nvme: Support Zone Descriptor Extensions hw/block/nvme: Add injection of Offline/Read-Only zones hw/block/nvme: Document zoned parameters in usage textNiklas Cassel (2):
hw/block/nvme: Add support for Namespace Types hw/block/nvme: Support allocated CNS command variantsQuoted 5 lines
hw/block/nvme-ns.h | 108 +++- hw/block/nvme.h | 6 + include/block/nvme.h | 201 +++++- hw/block/nvme-ns.c | 271 +++++++- hw/block/nvme.c | 1432++++++++++++++++++++++++++++++++++++++---
Quoted 7 lines
hw/block/trace-events | 32 +- 6 files changed, 1927 insertions(+), 123 deletions(-)--
2.28.0--
One of us - No more doubt, silence or taboo about mental illness.
Quoted 43 lines · Dmitry Fomichev
Quoted 41 lines
-----Original Message-----
From: Klaus Jensen <[email protected]>
Sent: Wednesday, December 9, 2020 4:58 AM
To: Dmitry Fomichev <[email protected]>
Cc: Keith Busch <[email protected]>; Klaus Jensen <[email protected]>; Kevin Wolf <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Max Reitz <[email protected]>; Maxim Levitsky <[email protected]>; Fam Zheng <[email protected]>; Niklas Cassel <[email protected]>; Damien Le Moal <[email protected]>; [email protected]; qemu- [email protected]; Alistair Francis <[email protected]>; Matias Bjorling <[email protected]>
Subject: Re: [PATCH v11 00/13] hw/block/nvme: Support Namespace Types and Zoned Namespace Command SetHi Dmitry,
By and large, this looks OK to me. There are still some issues here and there, and some comments of mine that you did not address, but I will follow up with patches to fix that. Let's get this merged.
It looks like the nvme-next you rebased on is slightly old and missing two commits:
"hw/block/nvme: remove superfluous NvmeCtrl parameter" and "hw/block/nvme: pull aio error handling"
It caused a couple of conflicts, but nothing that I couldn't fix up.
Since I didn't manage to convince anyone about the zsze and zcap parameters being in terms of LBAs, I'll revert that to be 'zoned.zone_size' and 'zoned.zone_capacity'.
Finally, would you accept that we skip "hw/block/nvme: Add injection of Offline/Read-Only zones" for now? I'd like to discuss it a bit since I think the random injects feels a bit ad-hoc. Back when I did OCSSD emulation with Hans, we did something like this for setting up state through a descriptor text file - I think we should explore something like that before we lock down the two parameters. I'll amend the final documentation commit to not include those parameters.
Quoted 1 line
Sounds good?
Quoted 7 lines
Klaus,
Sounds great! Sure, we can leave out the injection patch. It was made to increase our internal test coverage, but it is not ideal. Since the zones are injected randomly, there is no consistency between test runs and it is impossible to reliably create many specific test cases (e.g. the first or the last zone is offline).
Yes, exactly.
Quoted 4 lines
The descriptor input file seems like a much more
flexible and capable approach. If you have something in works, I'll be happy to discuss or review.
Sure, I'll rip some stuff from OCSSD and cook up a patch.
Quoted 2 lines
Thank you for your very thorough reviews!
Thanks for contributing this.
Keith, you wanna take a look an give this an Ack or so?
Stefan Hajnoczi
Acked-byRe: [PATCH v11 08/13] block/nvme: Make ZNS-related definitions
In reply to Klaus JensenQuoted 200 lines · Klaus Jensen
CC for Stefan (nvme block driver co-maintainer).
Quoted 197 lines · Dmitry Fomichev
Define values and structures that are needed to support Zoned Namespace Command Set (NVMe TP 4053).
Signed-off-by Dmitry Fomichev <[email protected]>--- include/block/nvme.h | 114 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-)include/block/nvme.h +112
-1@@ -489,6 +489,9 @@ enum NvmeIoCommands {NVME_CMD_COMPARE =0x05 ,NVME_CMD_WRITE_ZEROES =0x08 ,NVME_CMD_DSM =0x09 , +NVME_CMD_ZONE_MGMT_SEND =0x79 , +NVME_CMD_ZONE_MGMT_RECV =0x7a , + NVME_CMD_ZONE_APPEND = 0x7d, }; typedef struct QEMU_PACKED NvmeDeleteQ {@@ -648,9 +651,13 @@ typedef struct QEMU_PACKED NvmeAerResult {uint8_t resv; } NvmeAerResult; +typedef struct QEMU_PACKED NvmeZonedResult { +uint64_t slba; +} NvmeZonedResult; + typedef struct QEMU_PACKED NvmeCqe {uint32_t result; -uint32_t rsvd; +uint32_t dw1;uint16_t sq_head;uint16_t sq_id;uint16_t cid;@@ -679,6 +686,7 @@ enum NvmeStatusCodes {NVME_INVALID_USE_OF_CMB =0x0012 ,NVME_INVALID_PRP_OFFSET =0x0013 ,NVME_CMD_SET_CMB_REJECTED =0x002b , +NVME_INVALID_CMD_SET =0x002c ,NVME_LBA_RANGE =0x0080 ,NVME_CAP_EXCEEDED =0x0081 , NVME_NS_NOT_READY = 0x0082,@@ -703,6 +711,14 @@ enum NvmeStatusCodes {NVME_CONFLICTING_ATTRS =0x0180 ,NVME_INVALID_PROT_INFO =0x0181 ,NVME_WRITE_TO_RO =0x0182 , +NVME_ZONE_BOUNDARY_ERROR =0x01b8 , +NVME_ZONE_FULL =0x01b9 , +NVME_ZONE_READ_ONLY =0x01ba , +NVME_ZONE_OFFLINE =0x01bb , +NVME_ZONE_INVALID_WRITE =0x01bc , +NVME_ZONE_TOO_MANY_ACTIVE =0x01bd , +NVME_ZONE_TOO_MANY_OPEN =0x01be , +NVME_ZONE_INVAL_TRANSITION =0x01bf ,NVME_WRITE_FAULT =0x0280 ,NVME_UNRECOVERED_READ =0x0281 , NVME_E2E_GUARD_ERROR = 0x0282,@@ -888,6 +904,11 @@ typedef struct QEMU_PACKED NvmeIdCtrl {uint8_t vs[1024 ]; } NvmeIdCtrl; +typedef struct NvmeIdCtrlZoned { +uint8_t zasl; +uint8_t rsvd1[4095 ]; +}NvmeIdCtrlZoned ; +enum NvmeIdCtrlOacs {NVME_OACS_SECURITY =1 <<0 ,NVME_OACS_FORMAT =1 <<1 ,@@ -1016,6 +1037,12 @@ typedef struct QEMU_PACKED NvmeLBAF {uint8_t rp; } NvmeLBAF; +typedef struct QEMU_PACKED NvmeLBAFE { +uint64_t zsze; +uint8_t zdes; +uint8_t rsvd9[7 ]; +} NvmeLBAFE; +#define NVME_NSID_BROADCAST 0xffffffff typedef struct QEMU_PACKED NvmeIdNs {@@ -1075,10 +1102,24 @@ enum NvmeNsIdentifierType {enum NvmeCsi {NVME_CSI_NVM =0x00 , +NVME_CSI_ZONED =0x02 , };#define NVME_SET_CSI (vec, csi) (vec |= (uint8_t)(1 << (csi))) +typedef struct QEMU_PACKED NvmeIdNsZoned { +uint16_t zoc; +uint16_t ozcs; +uint32_t mar; +uint32_t mor; +uint32_t rrl; +uint32_t frl; +uint8_t rsvd20[2796 ]; +NvmeLBAFE lbafe[16 ]; +uint8_t rsvd3072[768 ]; +uint8_t vs[256 ]; +} NvmeIdNsZoned; +/*Deallocate Logical Block Features*/ #define NVME_ID_NS_DLFEAT_GUARD_CRC (dlfeat) ((dlfeat) & 0x10)#define NVME_ID_NS_DLFEAT_WRITE_ZEROES (dlfeat) ((dlfeat) & 0x08)@@ -1111,10 +1152,76 @@ enum NvmeIdNsDps { DPS_FIRST_EIGHT = 8, }; +enum NvmeZoneAttr { +NVME_ZA_FINISHED_BY_CTLR =1 <<0 , +NVME_ZA_FINISH_RECOMMENDED =1 <<1 , +NVME_ZA_RESET_RECOMMENDED =1 <<2 , +NVME_ZA_ZD_EXT_VALID =1 <<7 , +}; + +typedef struct QEMU_PACKED NvmeZoneReportHeader { +uint64_t nr_zones; +uint8_t rsvd[56 ]; +} NvmeZoneReportHeader; + +enum NvmeZoneReceiveAction { +NVME_ZONE_REPORT =0 , +NVME_ZONE_REPORT_EXTENDED =1 , +}; + +enum NvmeZoneReportType { +NVME_ZONE_REPORT_ALL =0 , +NVME_ZONE_REPORT_EMPTY =1 , +NVME_ZONE_REPORT_IMPLICITLY_OPEN =2 , +NVME_ZONE_REPORT_EXPLICITLY_OPEN =3 , +NVME_ZONE_REPORT_CLOSED =4 , +NVME_ZONE_REPORT_FULL =5 , +NVME_ZONE_REPORT_READ_ONLY =6 , +NVME_ZONE_REPORT_OFFLINE =7 , +}; + +enum NvmeZoneType { +NVME_ZONE_TYPE_RESERVED =0x00 , +NVME_ZONE_TYPE_SEQ_WRITE =0x02 , +}; + +enum NvmeZoneSendAction { +NVME_ZONE_ACTION_RSD =0x00 , +NVME_ZONE_ACTION_CLOSE =0x01 , +NVME_ZONE_ACTION_FINISH =0x02 , +NVME_ZONE_ACTION_OPEN =0x03 , +NVME_ZONE_ACTION_RESET =0x04 , +NVME_ZONE_ACTION_OFFLINE =0x05 , +NVME_ZONE_ACTION_SET_ZD_EXT =0x10 , +}; + +typedef struct QEMU_PACKED NvmeZoneDescr { +uint8_t zt; +uint8_t zs; +uint8_t za; +uint8_t rsvd3[5 ]; +uint64_t zcap; +uint64_t zslba; +uint64_t wp; +uint8_t rsvd32[32 ]; +} NvmeZoneDescr; + +enum NvmeZoneState { +NVME_ZONE_STATE_RESERVED =0x00 , +NVME_ZONE_STATE_EMPTY =0x01 , +NVME_ZONE_STATE_IMPLICITLY_OPEN =0x02 , +NVME_ZONE_STATE_EXPLICITLY_OPEN =0x03 , +NVME_ZONE_STATE_CLOSED =0x04 , +NVME_ZONE_STATE_READ_ONLY =0x0D , +NVME_ZONE_STATE_FULL =0x0E , +NVME_ZONE_STATE_OFFLINE =0x0F , +}; +static inline void _nvme_check_size (void ) {QEMU_BUILD_BUG_ON (sizeof (NvmeBar) !=4096 );QEMU_BUILD_BUG_ON (sizeof (NvmeAerResult) !=4 ); +QEMU_BUILD_BUG_ON (sizeof (NvmeZonedResult) !=8 );QEMU_BUILD_BUG_ON (sizeof (NvmeCqe) !=16 );QEMU_BUILD_BUG_ON (sizeof (NvmeDsmRange) !=16 );QEMU_BUILD_BUG_ON (sizeof (NvmeCmd) !=64 );@@ -1130,8 +1237,13 @@ static inline void _nvme_check_size(void)QEMU_BUILD_BUG_ON (sizeof (NvmeSmartLog) !=512 );QEMU_BUILD_BUG_ON (sizeof (NvmeEffectsLog) !=4096 );QEMU_BUILD_BUG_ON (sizeof (NvmeIdCtrl) !=4096 ); +QEMU_BUILD_BUG_ON (sizeof (NvmeIdCtrlZoned) !=4096 ); +QEMU_BUILD_BUG_ON (sizeof (NvmeLBAF) !=4 ); +QEMU_BUILD_BUG_ON (sizeof (NvmeLBAFE) !=16 );QEMU_BUILD_BUG_ON (sizeof (NvmeIdNs) !=4096 ); +QEMU_BUILD_BUG_ON (sizeof (NvmeIdNsZoned) !=4096 );QEMU_BUILD_BUG_ON (sizeof (NvmeSglDescriptor) !=16 );
Quoted 11 lines
Quoted 8 lines
include/block/nvme.h +1
-0QEMU_BUILD_BUG_ON (sizeof (NvmeIdNsDescr) !=4 ); + QEMU_BUILD_BUG_ON(sizeof(NvmeZoneDescr) != 64); }#endif Signature · 1 line
2.28.0Signature · 1 line
One of us - No more doubt, silence or taboo about mental illness.
Quoted 26 lines · Klaus Jensen
Hi Dmitry,
By and large, this looks OK to me. There are still some issues here and there, and some comments of mine that you did not address, but I will follow up with patches to fix that. Let's get this merged.
It looks like the nvme-next you rebased on is slightly old and missing two commits:
"hw/block/nvme: remove superfluous NvmeCtrl parameter" and "hw/block/nvme: pull aio error handling"
It caused a couple of conflicts, but nothing that I couldn't fix up.
Since I didn't manage to convince anyone about the zsze and zcap parameters being in terms of LBAs, I'll revert that to be 'zoned.zone_size' and 'zoned.zone_capacity'.
Finally, would you accept that we skip "hw/block/nvme: Add injection of Offline/Read-Only zones" for now? I'd like to discuss it a bit since I think the random injects feels a bit ad-hoc. Back when I did OCSSD emulation with Hans, we did something like this for setting up state through a descriptor text file - I think we should explore something like that before we lock down the two parameters. I'll amend the final documentation commit to not include those parameters.
Quoted 7 lines
Sounds good?
Otherwise, I think this is mergeable to nvme-next. So, for the series (excluding "hw/block/nvme: Add injection of Offline/Read-Only zones"):
Reviewed-by Klaus Jensen <[email protected]>
I've applied this series to my local nvme-next. Our repo host is unavailable this morning (infradead.org), but I will push as soon as possible.
Thanks!
Klaus