[PATCH v5 09/14] hw/block/nvme: Support Zoned Namespace Command Set
The emulation code has been changed to advertise NVM Command Set when "zoned" device property is not set (default) and Zoned Namespace Command Set otherwise. 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. The code to support for Zone Descriptor Extensions is not included in this commit and ZDES 0 is always reported. A later commit in this series will add ZDE support. This commit doesn't yet include checks for active and open zone limits. It is assumed that there are no limits on either active or open zones. Signed-off-by: Niklas Cassel Signed-off-by: Hans Holmberg Signed-off-by: Ajay Joshi Signed-off-by: Chaitanya Kulkarni Signed-off-by: Matias Bjorling Signed-off-by: Aravind Ramesh Signed-off-by: Shin'ichiro Kawasaki Signed-off-by: Adam Manzanares Signed-off-by: Dmitry Fomichev --- block/nvme.c | 2 +- hw/block/nvme-ns.c | 185 - hw/block/nvme-ns.h | 6 +- hw/block/nvme.c | 872 +-- include/block/nvme.h | 6 +- 5 files changed, 1033 insertions(+), 38 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 05485fdd11..7a513c9a17 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -333,7 +333,7 @@ static inline int nvme_translate_error(const NvmeCqe *c) { uint16_t status = (le16_to_cpu(c->status) >> 1) & 0xFF; if (status) { -trace_nvme_error(le32_to_cpu(c->result), +trace_nvme_error(le32_to_cpu(c->result32), le16_to_cpu(c->sq_head), le16_to_cpu(c->sq_id), le16_to_cpu(c->cid), diff --git a/hw/block/nvme-ns.c b/hw/block/nvme-ns.c index 31b7f986c3..6d9dc9205b 100644 --- a/hw/block/nvme-ns.c +++ b/hw/block/nvme-ns.c @@ -33,14 +33,14 @@ static void nvme_ns_init(NvmeNamespace *ns) NvmeIdNs *id_ns = &ns->id_ns; if (blk_get_flags(ns->blkconf.blk) & BDRV_O_UNMAP) { -ns->id_ns.dlfeat = 0x9; +ns->id_ns.dlfeat = 0x8; } id_ns->lbaf[0].ds = BDRV_SECTOR_BITS; id_ns->nsze = cpu_to_le64(nvme_ns_nlbas(ns)); -ns->params.csi = NVME_CSI_NVM; +ns->csi = NVME_CSI_NVM; qemu_uuid_generate(&ns->params.uuid); /* TODO make UUIDs persistent */ /* no thin provisioning */ @@ -73,7 +73,162 @@ static int nvme_ns_init_blk(NvmeCtrl *n, NvmeNamespace *ns, Error **errp) } lba_index = NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas); -ns->id_ns.lbaf[lba_index].ds = 31 - clz32(n->conf.logical_block_size); +ns->id_ns.lbaf[lba_index].ds = 31 - clz32(ns->blkconf.logical_block_size); + +return 0; +} + +/* + * Add a zone to the tail of a zone list. + */ +void nvme_add_zone_tail(NvmeNamespace *ns, NvmeZoneList *zl, NvmeZone *zone) +{ +uint32_t idx = (uint32_t)(zone - ns->zone_array); + +assert(nvme_zone_not_in_list(zone)); + +if (!zl->size) { +zl->head = zl->tail = idx; +zone->next = zone->prev = NVME_ZONE_LIST_NIL; +} else { +ns->zone_array[zl->tail].next = idx; +zone->prev = zl->tail; +zone->next = NVME_ZONE_LIST_NIL; +zl->tail = idx; +} +zl->size++; +} + +/* + * Remove a zone from a zone list. The zone must be linked in the list. + */ +void nvme_remove_zone(NvmeNamespace *ns, NvmeZoneList *zl, NvmeZone *zone) +{ +uint32_t idx = (uint32_t)(zone - ns->zone_array); + +assert(!nvme_zone_not_in_list(zone)); + +--zl->size; +if (zl->size == 0) { +zl->head = NVME_ZONE_LIST_NIL; +zl->tail = NVME_ZONE_LIST_NIL; +} else if (idx == zl->head) { +zl->head = zone->next; +ns->zone_array[zl->head].prev = NVME_ZONE_LIST_NIL; +} else if (idx == zl->tail) { +zl->tail = zone->prev; +ns->zone_array[zl->tail].next = NVME_ZONE_LIST_NIL; +} else { +ns->zone_array[zone->next].prev = zone->prev; +ns->zone_array[zone->prev].next = zone->next; +} + +zone->prev = zone->next = 0; +} + +static int nvme_calc_zone_geometry(NvmeNamespace *ns, Error **errp) +{ +uint64_t zone_size, zone_cap; +uint32_t nz, lbasz = ns->blkconf.logical_block_size; + +if (ns->params.zone_size_mb) { +zone_size = ns->params.zone_size_mb; +} else { +zone_size = NVME_DEFAULT_ZONE_SIZE; +} +if (ns->params.zone_capacity_mb) { +zone_cap = ns->params.zone_capacity_mb; +} else { +zone_cap = zone_size; +
Re: [PATCH v5 09/14] hw/block/nvme: Support Zoned Namespace Command Set
On Sep 28 11:35, Dmitry Fomichev wrote: > The emulation code has been changed to advertise NVM Command Set when > "zoned" device property is not set (default) and Zoned Namespace > Command Set otherwise. > > 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. > > The code to support for Zone Descriptor Extensions is not included in > this commit and ZDES 0 is always reported. A later commit in this > series will add ZDE support. > > This commit doesn't yet include checks for active and open zone > limits. It is assumed that there are no limits on either active or > open zones. > > Signed-off-by: Niklas Cassel > Signed-off-by: Hans Holmberg > Signed-off-by: Ajay Joshi > Signed-off-by: Chaitanya Kulkarni > Signed-off-by: Matias Bjorling > Signed-off-by: Aravind Ramesh > Signed-off-by: Shin'ichiro Kawasaki > Signed-off-by: Adam Manzanares > Signed-off-by: Dmitry Fomichev > --- > block/nvme.c | 2 +- > hw/block/nvme-ns.c | 185 - > hw/block/nvme-ns.h | 6 +- > hw/block/nvme.c | 872 +-- > include/block/nvme.h | 6 +- > 5 files changed, 1033 insertions(+), 38 deletions(-) > > diff --git a/block/nvme.c b/block/nvme.c > index 05485fdd11..7a513c9a17 100644 > --- a/block/nvme.c > +++ b/block/nvme.c > @@ -1040,18 +1318,468 @@ static uint16_t nvme_rw(NvmeCtrl *n, NvmeRequest > *req) > goto invalid; > } > > +if (ns->params.zoned) { > +zone_idx = nvme_zone_idx(ns, slba); > +assert(zone_idx < ns->num_zones); > +zone = &ns->zone_array[zone_idx]; > + > +if (is_write) { > +status = nvme_check_zone_write(zone, slba, nlb); > +if (status != NVME_SUCCESS) { > +trace_pci_nvme_err_zone_write_not_ok(slba, nlb, status); > +goto invalid; > +} > + > +assert(nvme_wp_is_valid(zone)); > +if (append) { > +if (unlikely(slba != zone->d.zslba)) { > +trace_pci_nvme_err_append_not_at_start(slba, > zone->d.zslba); > +status = NVME_ZONE_INVALID_WRITE | NVME_DNR; > +goto invalid; > +} > +if (data_size > (n->page_size << n->zasl)) { > +trace_pci_nvme_err_append_too_large(slba, nlb, n->zasl); > +status = NVME_INVALID_FIELD | NVME_DNR; > +goto invalid; > +} > +slba = zone->w_ptr; > +} else if (unlikely(slba != zone->w_ptr)) { > +trace_pci_nvme_err_write_not_at_wp(slba, zone->d.zslba, > + zone->w_ptr); > +status = NVME_ZONE_INVALID_WRITE | NVME_DNR; > +goto invalid; > +} > +req->fill_ofs = -1LL; > +} else { > +status = nvme_check_zone_read(ns, zone, slba, nlb); > +if (status != NVME_SUCCESS) { > +trace_pci_nvme_err_zone_read_not_ok(slba, nlb, status); > +goto invalid; > +} > + > +if (slba + nlb > zone->w_ptr) { > +/* > + * All or some data is read above the WP. Need to > + * fill out the buffer area that has no backing data > + * with a predefined data pattern (zeros by default) > + */ > +if (slba >= zone->w_ptr) { > +req->fill_ofs = 0; > +} else { > +req->fill_ofs = nvme_l2b(ns, zone->w_ptr - slba); > +} > +req->fill_len = nvme_l2b(ns, > +nvme_zone_rd_boundary(ns, zone) - slba); OK then. Next edge case. Now what happens if the read crosses into a partially written zone and reads above the write pointer in that zone? signature.asc Description: PGP signature
Re: [PATCH v5 09/14] hw/block/nvme: Support Zoned Namespace Command Set
On Sep 28 11:35, Dmitry Fomichev wrote: > The emulation code has been changed to advertise NVM Command Set when > "zoned" device property is not set (default) and Zoned Namespace > Command Set otherwise. > > 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. > > The code to support for Zone Descriptor Extensions is not included in > this commit and ZDES 0 is always reported. A later commit in this > series will add ZDE support. > > This commit doesn't yet include checks for active and open zone > limits. It is assumed that there are no limits on either active or > open zones. > I think the fill_pattern feature stands separate, so it would be nice to extract that to a patch on its own. > Signed-off-by: Niklas Cassel > Signed-off-by: Hans Holmberg > Signed-off-by: Ajay Joshi > Signed-off-by: Chaitanya Kulkarni > Signed-off-by: Matias Bjorling > Signed-off-by: Aravind Ramesh > Signed-off-by: Shin'ichiro Kawasaki > Signed-off-by: Adam Manzanares > Signed-off-by: Dmitry Fomichev > --- > block/nvme.c | 2 +- > hw/block/nvme-ns.c | 185 - > hw/block/nvme-ns.h | 6 +- > hw/block/nvme.c | 872 +-- > include/block/nvme.h | 6 +- > 5 files changed, 1033 insertions(+), 38 deletions(-) > > diff --git a/hw/block/nvme-ns.h b/hw/block/nvme-ns.h > index 04172f083e..daa13546c4 100644 > --- a/hw/block/nvme-ns.h > +++ b/hw/block/nvme-ns.h > @@ -38,7 +38,6 @@ typedef struct NvmeZoneList { > > typedef struct NvmeNamespaceParams { > uint32_t nsid; > -uint8_t csi; > bool attached; > QemuUUID uuid; > > @@ -52,6 +51,7 @@ typedef struct NvmeNamespace { > DeviceState parent_obj; > BlockConfblkconf; > int32_t bootindex; > +uint8_t csi; > int64_t size; > NvmeIdNs id_ns; This should be squashed into the namespace types patch. > diff --git a/hw/block/nvme.c b/hw/block/nvme.c > index 63ad03d6d6..38e25a4d1f 100644 > --- a/hw/block/nvme.c > +++ b/hw/block/nvme.c > @@ -54,6 +54,7 @@ > #include "qemu/osdep.h" > #include "qemu/units.h" > #include "qemu/error-report.h" > +#include "crypto/random.h" I think this is not used until the offline/read-only zones injection patch, right? > +static bool nvme_finalize_zoned_write(NvmeNamespace *ns, NvmeRequest *req, > + bool failed) > +{ > +NvmeRwCmd *rw = (NvmeRwCmd *)&req->cmd; > +NvmeZone *zone; > +uint64_t slba, start_wp = req->cqe.result64; > +uint32_t nlb, zone_idx; > +uint8_t zs; > + > +if (rw->opcode != NVME_CMD_WRITE && > +rw->opcode != NVME_CMD_ZONE_APPEND && > +rw->opcode != NVME_CMD_WRITE_ZEROES) { > +return false; > +} > + > +slba = le64_to_cpu(rw->slba); > +nlb = le16_to_cpu(rw->nlb) + 1; > +zone_idx = nvme_zone_idx(ns, slba); > +assert(zone_idx < ns->num_zones); > +zone = &ns->zone_array[zone_idx]; > + > +if (!failed && zone->w_ptr < start_wp + nlb) { > +/* > + * A preceding queued write to the zone has failed, > + * now this write is not at the WP, fail it too. > + */ > +failed = true; > +} > + > +if (failed) { > +if (zone->w_ptr > start_wp) { > +zone->w_ptr = start_wp; > +} It is possible (though unlikely) that you already posted the CQE for the write that moved the WP to w_ptr - and now you are reverting it. This looks like a recipe for data corruption to me. Take this example. I use append, because if you have multiple regular writes in queue you're screwed anyway. w_ptr = 0, d.wp = 0 append 1 lba -> w_ptr = 1, start_wp = 0, issues aio A append 2 lbas -> w_ptr = 3, start_wp = 1, issues aio B aio B success -> d.wp = 2 (since you are adding nlb), Now, I totally do the same. Even though the zone descriptor write pointer gets "out of sync", it will be reconciled in the absence of failures and its fair to define that the host cannot expect a consistent view of the write pointer without quescing I/O. The problem is if a write then fails: aio A fails -> w_ptr > start_wp (3 > 1), so you revert to w_ptr = 1 That looks bad to me. I dont think this is ever reconciled? If another append then comes in: append 1 lba -> w_ptr = 2, start_wp = 1, issues aio C and overwrites
Re: [PATCH v5 09/14] hw/block/nvme: Support Zoned Namespace Command Set
On Sep 28 12:42, Klaus Jensen wrote: > On Sep 28 11:35, Dmitry Fomichev wrote: > > The emulation code has been changed to advertise NVM Command Set when > > "zoned" device property is not set (default) and Zoned Namespace > > Command Set otherwise. > > > > 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. > > > > The code to support for Zone Descriptor Extensions is not included in > > this commit and ZDES 0 is always reported. A later commit in this > > series will add ZDE support. > > > > This commit doesn't yet include checks for active and open zone > > limits. It is assumed that there are no limits on either active or > > open zones. > > > > I think the fill_pattern feature stands separate, so it would be nice to > extract that to a patch on its own. > Please disregard this. Since the fill_pattern feature is tightly bound to reading in zones, it doesnt really make sense to extract it. signature.asc Description: PGP signature
Re: [PATCH v5 09/14] hw/block/nvme: Support Zoned Namespace Command Set
On Sep 28 11:35, Dmitry Fomichev wrote: > The emulation code has been changed to advertise NVM Command Set when > "zoned" device property is not set (default) and Zoned Namespace > Command Set otherwise. > > 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. > > The code to support for Zone Descriptor Extensions is not included in > this commit and ZDES 0 is always reported. A later commit in this > series will add ZDE support. > > This commit doesn't yet include checks for active and open zone > limits. It is assumed that there are no limits on either active or > open zones. > > Signed-off-by: Niklas Cassel > Signed-off-by: Hans Holmberg > Signed-off-by: Ajay Joshi > Signed-off-by: Chaitanya Kulkarni > Signed-off-by: Matias Bjorling > Signed-off-by: Aravind Ramesh > Signed-off-by: Shin'ichiro Kawasaki > Signed-off-by: Adam Manzanares > Signed-off-by: Dmitry Fomichev > --- > block/nvme.c | 2 +- > hw/block/nvme-ns.c | 185 - > hw/block/nvme-ns.h | 6 +- > hw/block/nvme.c | 872 +-- > include/block/nvme.h | 6 +- > 5 files changed, 1033 insertions(+), 38 deletions(-) > > diff --git a/block/nvme.c b/block/nvme.c > index 05485fdd11..7a513c9a17 100644 > --- a/block/nvme.c > +++ b/block/nvme.c > +static int nvme_calc_zone_geometry(NvmeNamespace *ns, Error **errp) > +{ > +uint64_t zone_size, zone_cap; > +uint32_t nz, lbasz = ns->blkconf.logical_block_size; > + > +if (ns->params.zone_size_mb) { > +zone_size = ns->params.zone_size_mb; > +} else { > +zone_size = NVME_DEFAULT_ZONE_SIZE; > +} > +if (ns->params.zone_capacity_mb) { > +zone_cap = ns->params.zone_capacity_mb; > +} else { > +zone_cap = zone_size; > +} I think a check that zone_capacity_mb is less than or equal to zone_size_mb is missing earlier? > +static int nvme_zoned_init_ns(NvmeCtrl *n, NvmeNamespace *ns, int lba_index, > + Error **errp) > +{ > +NvmeIdNsZoned *id_ns_z; > + > +if (n->params.fill_pattern == 0) { > +ns->id_ns.dlfeat |= 0x01; > +} else if (n->params.fill_pattern == 0xff) { > +ns->id_ns.dlfeat |= 0x02; > +} > + > +if (nvme_calc_zone_geometry(ns, errp) != 0) { > +return -1; > +} > + > +nvme_init_zone_meta(ns); > + > +id_ns_z = g_malloc0(sizeof(NvmeIdNsZoned)); > + > +/* MAR/MOR are zeroes-based, 0x means no limit */ > +id_ns_z->mar = 0x; > +id_ns_z->mor = 0x; > +id_ns_z->zoc = 0; > +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; /* FIXME make helper */ > + > +ns->csi = NVME_CSI_ZONED; > +ns->id_ns.ncap = cpu_to_le64(ns->zone_capacity * ns->num_zones); > +ns->id_ns.nuse = ns->id_ns.ncap; > +ns->id_ns.nsze = ns->id_ns.ncap; > + NSZE should be in terms of ZSZE. We *can* report NCAP < NSZE if zcap != zsze, but that requires bit 1 set in NSFEAT and proper reporting of NUSE. > @@ -133,6 +304,14 @@ 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_BOOL("zoned", NvmeNamespace, params.zoned, false), > +DEFINE_PROP_UINT64("zone_size", NvmeNamespace, params.zone_size_mb, > + NVME_DEFAULT_ZONE_SIZE), > +DEFINE_PROP_UINT64("zone_capacity", NvmeNamespace, > + params.zone_capacity_mb, 0), There is a nice DEFINE_PROP_SIZE that handles sizes in a nice way (i.e. 1G, 1M). signature.asc Description: PGP signature
Re: [PATCH v5 09/14] hw/block/nvme: Support Zoned Namespace Command Set
On Mon, Sep 28, 2020 at 11:35:23AM +0900, Dmitry Fomichev wrote: > The emulation code has been changed to advertise NVM Command Set when > "zoned" device property is not set (default) and Zoned Namespace > Command Set otherwise. > > 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. > > The code to support for Zone Descriptor Extensions is not included in > this commit and ZDES 0 is always reported. A later commit in this > series will add ZDE support. > > This commit doesn't yet include checks for active and open zone > limits. It is assumed that there are no limits on either active or > open zones. > > Signed-off-by: Niklas Cassel > Signed-off-by: Hans Holmberg > Signed-off-by: Ajay Joshi > Signed-off-by: Chaitanya Kulkarni > Signed-off-by: Matias Bjorling > Signed-off-by: Aravind Ramesh > Signed-off-by: Shin'ichiro Kawasaki > Signed-off-by: Adam Manzanares > Signed-off-by: Dmitry Fomichev > --- > block/nvme.c | 2 +- > hw/block/nvme-ns.c | 185 - > hw/block/nvme-ns.h | 6 +- > hw/block/nvme.c | 872 +-- > include/block/nvme.h | 6 +- > 5 files changed, 1033 insertions(+), 38 deletions(-) > > diff --git a/block/nvme.c b/block/nvme.c > index 05485fdd11..7a513c9a17 100644 > --- a/block/nvme.c > +++ b/block/nvme.c > @@ -333,7 +333,7 @@ static inline int nvme_translate_error(const NvmeCqe *c) > { > uint16_t status = (le16_to_cpu(c->status) >> 1) & 0xFF; > if (status) { > -trace_nvme_error(le32_to_cpu(c->result), > +trace_nvme_error(le32_to_cpu(c->result32), > le16_to_cpu(c->sq_head), > le16_to_cpu(c->sq_id), > le16_to_cpu(c->cid), > diff --git a/hw/block/nvme-ns.c b/hw/block/nvme-ns.c > index 31b7f986c3..6d9dc9205b 100644 > --- a/hw/block/nvme-ns.c > +++ b/hw/block/nvme-ns.c > @@ -33,14 +33,14 @@ static void nvme_ns_init(NvmeNamespace *ns) > NvmeIdNs *id_ns = &ns->id_ns; > > if (blk_get_flags(ns->blkconf.blk) & BDRV_O_UNMAP) { > -ns->id_ns.dlfeat = 0x9; > +ns->id_ns.dlfeat = 0x8; You seem to change something that is NVM namespace specific here, why? If it is indeed needed, I assume that this change should be in a separate patch. > } > > id_ns->lbaf[0].ds = BDRV_SECTOR_BITS; > > id_ns->nsze = cpu_to_le64(nvme_ns_nlbas(ns)); > > -ns->params.csi = NVME_CSI_NVM; > +ns->csi = NVME_CSI_NVM; > qemu_uuid_generate(&ns->params.uuid); /* TODO make UUIDs persistent */ > > /* no thin provisioning */ > @@ -73,7 +73,162 @@ static int nvme_ns_init_blk(NvmeCtrl *n, NvmeNamespace > *ns, Error **errp) > } > > lba_index = NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas); > -ns->id_ns.lbaf[lba_index].ds = 31 - clz32(n->conf.logical_block_size); > +ns->id_ns.lbaf[lba_index].ds = 31 - > clz32(ns->blkconf.logical_block_size); > + > +return 0; > +} > + > +/* > + * Add a zone to the tail of a zone list. > + */ > +void nvme_add_zone_tail(NvmeNamespace *ns, NvmeZoneList *zl, NvmeZone *zone) > +{ > +uint32_t idx = (uint32_t)(zone - ns->zone_array); > + > +assert(nvme_zone_not_in_list(zone)); > + > +if (!zl->size) { > +zl->head = zl->tail = idx; > +zone->next = zone->prev = NVME_ZONE_LIST_NIL; > +} else { > +ns->zone_array[zl->tail].next = idx; > +zone->prev = zl->tail; > +zone->next = NVME_ZONE_LIST_NIL; > +zl->tail = idx; > +} > +zl->size++; > +} > + > +/* > + * Remove a zone from a zone list. The zone must be linked in the list. > + */ > +void nvme_remove_zone(NvmeNamespace *ns, NvmeZoneList *zl, NvmeZone *zone) > +{ > +uint32_t idx = (uint32_t)(zone - ns->zone_array); > + > +assert(!nvme_zone_not_in_list(zone)); > + > +--zl->size; > +if (zl->size == 0) { > +zl->head = NVME_ZONE_LIST_NIL; > +zl->tail = NVME_ZONE_LIST_NIL; > +} else if (idx == zl->head) { > +zl->head = zone->next; > +ns->zone_array[zl->head].prev = NVME_ZONE_LIST_NIL; > +} else if (idx == zl->tail) { > +zl->tail = zone->prev; > +ns->zone_array[zl->tail].next = NVME_ZONE_LIST_NIL; > +} else { > +ns->zone_array[zone->next].prev = zone->prev; > +ns->zone_array[zone->prev].next = zone->next; > +} > + >
Re: [PATCH v5 09/14] hw/block/nvme: Support Zoned Namespace Command Set
On Mon, Sep 28, 2020 at 11:35:23AM +0900, Dmitry Fomichev wrote: > The emulation code has been changed to advertise NVM Command Set when > "zoned" device property is not set (default) and Zoned Namespace > Command Set otherwise. > > 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. > > The code to support for Zone Descriptor Extensions is not included in > this commit and ZDES 0 is always reported. A later commit in this > series will add ZDE support. > > This commit doesn't yet include checks for active and open zone > limits. It is assumed that there are no limits on either active or > open zones. > > Signed-off-by: Niklas Cassel > Signed-off-by: Hans Holmberg > Signed-off-by: Ajay Joshi > Signed-off-by: Chaitanya Kulkarni > Signed-off-by: Matias Bjorling > Signed-off-by: Aravind Ramesh > Signed-off-by: Shin'ichiro Kawasaki > Signed-off-by: Adam Manzanares > Signed-off-by: Dmitry Fomichev > --- > block/nvme.c | 2 +- > hw/block/nvme-ns.c | 185 - > hw/block/nvme-ns.h | 6 +- > hw/block/nvme.c | 872 +-- > include/block/nvme.h | 6 +- > 5 files changed, 1033 insertions(+), 38 deletions(-) > > diff --git a/block/nvme.c b/block/nvme.c > index 05485fdd11..7a513c9a17 100644 > --- a/block/nvme.c > +++ b/block/nvme.c (snip) > @@ -1326,11 +2060,20 @@ static uint16_t nvme_cmd_effects(NvmeCtrl *n, > uint32_t buf_len, > acs[NVME_ADM_CMD_GET_LOG_PAGE] = NVME_CMD_EFFECTS_CSUPP; > acs[NVME_ADM_CMD_ASYNC_EV_REQ] = NVME_CMD_EFFECTS_CSUPP; > > -iocs[NVME_CMD_FLUSH] = NVME_CMD_EFFECTS_CSUPP | NVME_CMD_EFFECTS_LBCC; > -iocs[NVME_CMD_WRITE_ZEROES] = NVME_CMD_EFFECTS_CSUPP | > - NVME_CMD_EFFECTS_LBCC; > -iocs[NVME_CMD_WRITE] = NVME_CMD_EFFECTS_CSUPP | NVME_CMD_EFFECTS_LBCC; > -iocs[NVME_CMD_READ] = NVME_CMD_EFFECTS_CSUPP; > +if (NVME_CC_CSS(n->bar.cc) != CSS_ADMIN_ONLY) { > +iocs[NVME_CMD_FLUSH] = NVME_CMD_EFFECTS_CSUPP | > NVME_CMD_EFFECTS_LBCC; > +iocs[NVME_CMD_WRITE_ZEROES] = NVME_CMD_EFFECTS_CSUPP | > + NVME_CMD_EFFECTS_LBCC; > +iocs[NVME_CMD_WRITE] = NVME_CMD_EFFECTS_CSUPP | > NVME_CMD_EFFECTS_LBCC; > +iocs[NVME_CMD_READ] = NVME_CMD_EFFECTS_CSUPP; > +} > + > +if (csi == NVME_CSI_ZONED && NVME_CC_CSS(n->bar.cc) == CSS_CSI) { Actually, intead of naming the helper function, ctrl_has_zns_namespaces(), a better name might be ctrl_has_zns_support() Since this is what is used to set the bit in nvme_identify_cmd_set(), Then, I think that this should be: if (ctrl_has_zns_support() && csi == NVME_CSI_ZONED && NVME_CC_CSS(n->bar.cc) == CSS_CSI) { > +iocs[NVME_CMD_ZONE_APPEND] = NVME_CMD_EFFECTS_CSUPP | > + NVME_CMD_EFFECTS_LBCC; > +iocs[NVME_CMD_ZONE_MGMT_SEND] = NVME_CMD_EFFECTS_CSUPP; > +iocs[NVME_CMD_ZONE_MGMT_RECV] = NVME_CMD_EFFECTS_CSUPP; > +} > > trans_len = MIN(sizeof(cmd_eff_log) - off, buf_len); >
Re: [PATCH v5 09/14] hw/block/nvme: Support Zoned Namespace Command Set
On Sep 30 14:50, Niklas Cassel wrote: > On Mon, Sep 28, 2020 at 11:35:23AM +0900, Dmitry Fomichev wrote: > > The emulation code has been changed to advertise NVM Command Set when > > "zoned" device property is not set (default) and Zoned Namespace > > Command Set otherwise. > > > > 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. > > > > The code to support for Zone Descriptor Extensions is not included in > > this commit and ZDES 0 is always reported. A later commit in this > > series will add ZDE support. > > > > This commit doesn't yet include checks for active and open zone > > limits. It is assumed that there are no limits on either active or > > open zones. > > > > Signed-off-by: Niklas Cassel > > Signed-off-by: Hans Holmberg > > Signed-off-by: Ajay Joshi > > Signed-off-by: Chaitanya Kulkarni > > Signed-off-by: Matias Bjorling > > Signed-off-by: Aravind Ramesh > > Signed-off-by: Shin'ichiro Kawasaki > > Signed-off-by: Adam Manzanares > > Signed-off-by: Dmitry Fomichev > > --- > > block/nvme.c | 2 +- > > hw/block/nvme-ns.c | 185 - > > hw/block/nvme-ns.h | 6 +- > > hw/block/nvme.c | 872 +-- > > include/block/nvme.h | 6 +- > > 5 files changed, 1033 insertions(+), 38 deletions(-) > > > > diff --git a/block/nvme.c b/block/nvme.c > > index 05485fdd11..7a513c9a17 100644 > > --- a/block/nvme.c > > +++ b/block/nvme.c > > @@ -333,7 +333,7 @@ static inline int nvme_translate_error(const NvmeCqe *c) > > { > > uint16_t status = (le16_to_cpu(c->status) >> 1) & 0xFF; > > if (status) { > > -trace_nvme_error(le32_to_cpu(c->result), > > +trace_nvme_error(le32_to_cpu(c->result32), > > le16_to_cpu(c->sq_head), > > le16_to_cpu(c->sq_id), > > le16_to_cpu(c->cid), > > diff --git a/hw/block/nvme-ns.c b/hw/block/nvme-ns.c > > index 31b7f986c3..6d9dc9205b 100644 > > --- a/hw/block/nvme-ns.c > > +++ b/hw/block/nvme-ns.c > > @@ -33,14 +33,14 @@ static void nvme_ns_init(NvmeNamespace *ns) > > NvmeIdNs *id_ns = &ns->id_ns; > > > > if (blk_get_flags(ns->blkconf.blk) & BDRV_O_UNMAP) { > > -ns->id_ns.dlfeat = 0x9; > > +ns->id_ns.dlfeat = 0x8; > > You seem to change something that is NVM namespace specific here, why? > If it is indeed needed, I assume that this change should be in a separate > patch. > Stood out to me as well - and I thought it was sound enough, but now I'm not sure sure. DLFEAT is set to 0x8, which only signifies that Deallocate in Write Zeroes is supported. Previously, it would also signify that returned values would be 0x00 (DLFEAT 0x8 | 0x1). But since Dmitry added the fill_pattern parameter... > > +static int nvme_zoned_init_ns(NvmeCtrl *n, NvmeNamespace *ns, int > > lba_index, > > + Error **errp) > > +{ > > +NvmeIdNsZoned *id_ns_z; > > + > > +if (n->params.fill_pattern == 0) { > > +ns->id_ns.dlfeat |= 0x01; > > +} else if (n->params.fill_pattern == 0xff) { > > +ns->id_ns.dlfeat |= 0x02; > > +} ... then, when initialized, we look at the fill_pattern and set DLFEAT accordingly instead. But since fill_pattern only works for ZNS namespaces, I think dlfeat should still be 0x9 for NVM namespaces. For NVM namespaces, since neither DULBE or DSM is not supported, there is really only Write Zeroes that can explicitly "deallocate" a block, and since that *will* write zeroes no matter if DEAC is set or not, 0x00 pattern is guaranteed. signature.asc Description: PGP signature
Re: [PATCH v5 09/14] hw/block/nvme: Support Zoned Namespace Command Set
On Wed, 2020-09-30 at 07:59 +0200, Klaus Jensen wrote: > On Sep 28 11:35, Dmitry Fomichev wrote: > > The emulation code has been changed to advertise NVM Command Set when > > "zoned" device property is not set (default) and Zoned Namespace > > Command Set otherwise. > > > > 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. > > > > The code to support for Zone Descriptor Extensions is not included in > > this commit and ZDES 0 is always reported. A later commit in this > > series will add ZDE support. > > > > This commit doesn't yet include checks for active and open zone > > limits. It is assumed that there are no limits on either active or > > open zones. > > > > Signed-off-by: Niklas Cassel > > Signed-off-by: Hans Holmberg > > Signed-off-by: Ajay Joshi > > Signed-off-by: Chaitanya Kulkarni > > Signed-off-by: Matias Bjorling > > Signed-off-by: Aravind Ramesh > > Signed-off-by: Shin'ichiro Kawasaki > > Signed-off-by: Adam Manzanares > > Signed-off-by: Dmitry Fomichev > > --- > > block/nvme.c | 2 +- > > hw/block/nvme-ns.c | 185 - > > hw/block/nvme-ns.h | 6 +- > > hw/block/nvme.c | 872 +-- > > include/block/nvme.h | 6 +- > > 5 files changed, 1033 insertions(+), 38 deletions(-) > > > > diff --git a/block/nvme.c b/block/nvme.c > > index 05485fdd11..7a513c9a17 100644 > > --- a/block/nvme.c > > +++ b/block/nvme.c > > +static int nvme_calc_zone_geometry(NvmeNamespace *ns, Error **errp) > > +{ > > +uint64_t zone_size, zone_cap; > > +uint32_t nz, lbasz = ns->blkconf.logical_block_size; > > + > > +if (ns->params.zone_size_mb) { > > +zone_size = ns->params.zone_size_mb; > > +} else { > > +zone_size = NVME_DEFAULT_ZONE_SIZE; > > +} > > +if (ns->params.zone_capacity_mb) { > > +zone_cap = ns->params.zone_capacity_mb; > > +} else { > > +zone_cap = zone_size; > > +} > > I think a check that zone_capacity_mb is less than or equal to > zone_size_mb is missing earlier? The check is right below, but I now think it is better to compare byte sizes rather than numbers of LBAs. There are also checks missing for zone_size >= lbasz and zone_cap >= lbasz that I am adding. > > > +static int nvme_zoned_init_ns(NvmeCtrl *n, NvmeNamespace *ns, int > > lba_index, > > + Error **errp) > > +{ > > +NvmeIdNsZoned *id_ns_z; > > + > > +if (n->params.fill_pattern == 0) { > > +ns->id_ns.dlfeat |= 0x01; > > +} else if (n->params.fill_pattern == 0xff) { > > +ns->id_ns.dlfeat |= 0x02; > > +} > > + > > +if (nvme_calc_zone_geometry(ns, errp) != 0) { > > +return -1; > > +} > > + > > +nvme_init_zone_meta(ns); > > + > > +id_ns_z = g_malloc0(sizeof(NvmeIdNsZoned)); > > + > > +/* MAR/MOR are zeroes-based, 0x means no limit */ > > +id_ns_z->mar = 0x; > > +id_ns_z->mor = 0x; > > +id_ns_z->zoc = 0; > > +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; /* FIXME make helper */ > > + > > +ns->csi = NVME_CSI_ZONED; > > +ns->id_ns.ncap = cpu_to_le64(ns->zone_capacity * ns->num_zones); > > +ns->id_ns.nuse = ns->id_ns.ncap; > > +ns->id_ns.nsze = ns->id_ns.ncap; > > + > > NSZE should be in terms of ZSZE. We *can* report NCAP < NSZE if zcap != > zsze, but that requires bit 1 set in NSFEAT and proper reporting of > NUSE. Ok, will correct. I think it used to be this way, but got messed up during multiple transformations of this code. > > > @@ -133,6 +304,14 @@ 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_BOOL("zoned", NvmeNamespace, params.zoned, false), > > +DEFINE_PROP_UINT64("zone_size", NvmeNamespace, params.zone_size_mb, > > + NVME_DEFAULT_ZONE_SIZE), > > +DEFINE_PROP_UINT64("zone_capacity", NvmeNamespace, > > + params.zone_capacity_mb, 0), > > There is a nice DEFINE_PROP_SIZE that handles sizes in a nice way (i.e.
Re: [PATCH v5 09/14] hw/block/nvme: Support Zoned Namespace Command Set
On Wed, 2020-09-30 at 14:50 +, Niklas Cassel wrote: > On Mon, Sep 28, 2020 at 11:35:23AM +0900, Dmitry Fomichev wrote: > > The emulation code has been changed to advertise NVM Command Set when > > "zoned" device property is not set (default) and Zoned Namespace > > Command Set otherwise. > > > > 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. > > > > The code to support for Zone Descriptor Extensions is not included in > > this commit and ZDES 0 is always reported. A later commit in this > > series will add ZDE support. > > > > This commit doesn't yet include checks for active and open zone > > limits. It is assumed that there are no limits on either active or > > open zones. > > > > Signed-off-by: Niklas Cassel > > Signed-off-by: Hans Holmberg > > Signed-off-by: Ajay Joshi > > Signed-off-by: Chaitanya Kulkarni > > Signed-off-by: Matias Bjorling > > Signed-off-by: Aravind Ramesh > > Signed-off-by: Shin'ichiro Kawasaki > > Signed-off-by: Adam Manzanares > > Signed-off-by: Dmitry Fomichev > > --- > > block/nvme.c | 2 +- > > hw/block/nvme-ns.c | 185 - > > hw/block/nvme-ns.h | 6 +- > > hw/block/nvme.c | 872 +-- > > include/block/nvme.h | 6 +- > > 5 files changed, 1033 insertions(+), 38 deletions(-) > > > > diff --git a/block/nvme.c b/block/nvme.c > > index 05485fdd11..7a513c9a17 100644 > > --- a/block/nvme.c > > +++ b/block/nvme.c > > @@ -333,7 +333,7 @@ static inline int nvme_translate_error(const NvmeCqe *c) > > { > > uint16_t status = (le16_to_cpu(c->status) >> 1) & 0xFF; > > if (status) { > > -trace_nvme_error(le32_to_cpu(c->result), > > +trace_nvme_error(le32_to_cpu(c->result32), > > le16_to_cpu(c->sq_head), > > le16_to_cpu(c->sq_id), > > le16_to_cpu(c->cid), > > diff --git a/hw/block/nvme-ns.c b/hw/block/nvme-ns.c > > index 31b7f986c3..6d9dc9205b 100644 > > --- a/hw/block/nvme-ns.c > > +++ b/hw/block/nvme-ns.c > > @@ -33,14 +33,14 @@ static void nvme_ns_init(NvmeNamespace *ns) > > NvmeIdNs *id_ns = &ns->id_ns; > > > > if (blk_get_flags(ns->blkconf.blk) & BDRV_O_UNMAP) { > > -ns->id_ns.dlfeat = 0x9; > > +ns->id_ns.dlfeat = 0x8; > > You seem to change something that is NVM namespace specific here, why? > If it is indeed needed, I assume that this change should be in a separate > patch. > OK, this needs to be done in nvme_zoned_init_ns(). Thanks > > } > > > > id_ns->lbaf[0].ds = BDRV_SECTOR_BITS; > > uint16_t status; > > > > +header->nr_zones = cpu_to_le64(nr_zones); > > + > > +ret = nvme_dma(n, (uint8_t *)buf, len, DMA_DIRECTION_FROM_DEVICE, req); > > + > > +g_free(buf); > > + > > +return ret; > > +} > > + > > static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeRequest *req) > > { > > uint32_t nsid = le32_to_cpu(req->cmd.nsid); > > @@ -1073,9 +1801,15 @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeRequest > > *req) > > While you did make sure that we don't expose zone mgmt send/recv/zone append > in the cmd_effects log when CC.CSS != CSS_CSI, we also need to make sure we > return Invalid Command Opcode for any of those three commands, if a user tries > to use them anyway (while CC.CSS != CSI). > Yes, good catch. Only the commands that are marked as supported in Commands Supported and Effects log page are allowed to be executed. I am making some changes to ensure this. > > return nvme_flush(n, req); > > case NVME_CMD_WRITE_ZEROES: > > return nvme_write_zeroes(n, req); > > +case NVME_CMD_ZONE_APPEND: > > +return nvme_rw(n, req, true); > > case NVME_CMD_WRITE: > > case NVME_CMD_READ: > > -return nvme_rw(n, req); > > +return nvme_rw(n, req, false); > > +case NVME_CMD_ZONE_MGMT_SEND: > > +return nvme_zone_mgmt_send(n, req); > > +case NVME_CMD_ZONE_MGMT_RECV: > > +return nvme_zone_mgmt_recv(n, req); > > default: > > trace_pci_nvme_err_invalid_opc(req->cmd.opcode); > > return NVME_INVALID_OPCODE | NVME_DNR; > > @@ -1301,7 +2035,7 @@ static uint16_t nvme_error_info(NvmeCtrl *n, uint8_t > > rae, uint32_t buf_len, > > DMA_DIRECTION_FROM_DEVICE, req); > > } >
RE: [PATCH v5 09/14] hw/block/nvme: Support Zoned Namespace Command Set
> -Original Message- > From: Klaus Jensen > Sent: Monday, September 28, 2020 6:43 AM > To: Dmitry Fomichev > Cc: Keith Busch ; Klaus Jensen > ; Kevin Wolf ; Philippe > Mathieu-Daudé ; Maxim Levitsky > ; Fam Zheng ; Niklas Cassel > ; Damien Le Moal ; > qemu-block@nongnu.org; qemu-de...@nongnu.org; Alistair Francis > ; Matias Bjorling > Subject: Re: [PATCH v5 09/14] hw/block/nvme: Support Zoned Namespace > Command Set > > On Sep 28 11:35, Dmitry Fomichev wrote: > > The emulation code has been changed to advertise NVM Command Set > when > > "zoned" device property is not set (default) and Zoned Namespace > > Command Set otherwise. > > > > 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. > > > > The code to support for Zone Descriptor Extensions is not included in > > this commit and ZDES 0 is always reported. A later commit in this > > series will add ZDE support. > > > > This commit doesn't yet include checks for active and open zone > > limits. It is assumed that there are no limits on either active or > > open zones. > > > > I think the fill_pattern feature stands separate, so it would be nice to > extract that to a patch on its own. > > > Signed-off-by: Niklas Cassel > > Signed-off-by: Hans Holmberg > > Signed-off-by: Ajay Joshi > > Signed-off-by: Chaitanya Kulkarni > > Signed-off-by: Matias Bjorling > > Signed-off-by: Aravind Ramesh > > Signed-off-by: Shin'ichiro Kawasaki > > Signed-off-by: Adam Manzanares > > Signed-off-by: Dmitry Fomichev > > --- > > block/nvme.c | 2 +- > > hw/block/nvme-ns.c | 185 - > > hw/block/nvme-ns.h | 6 +- > > hw/block/nvme.c | 872 > +-- > > include/block/nvme.h | 6 +- > > 5 files changed, 1033 insertions(+), 38 deletions(-) > > > > diff --git a/hw/block/nvme-ns.h b/hw/block/nvme-ns.h > > index 04172f083e..daa13546c4 100644 > > --- a/hw/block/nvme-ns.h > > +++ b/hw/block/nvme-ns.h > > @@ -38,7 +38,6 @@ typedef struct NvmeZoneList { > > > > typedef struct NvmeNamespaceParams { > > uint32_t nsid; > > -uint8_t csi; > > bool attached; > > QemuUUID uuid; > > > > @@ -52,6 +51,7 @@ typedef struct NvmeNamespace { > > DeviceState parent_obj; > > BlockConfblkconf; > > int32_t bootindex; > > +uint8_t csi; > > int64_t size; > > NvmeIdNs id_ns; > > This should be squashed into the namespace types patch. > Yes, thanks. > > diff --git a/hw/block/nvme.c b/hw/block/nvme.c > > index 63ad03d6d6..38e25a4d1f 100644 > > --- a/hw/block/nvme.c > > +++ b/hw/block/nvme.c > > @@ -54,6 +54,7 @@ > > #include "qemu/osdep.h" > > #include "qemu/units.h" > > #include "qemu/error-report.h" > > +#include "crypto/random.h" > > I think this is not used until the offline/read-only zones injection > patch, right? > Indeed, will move. > > +static bool nvme_finalize_zoned_write(NvmeNamespace *ns, > NvmeRequest *req, > > + bool failed) > > +{ > > +NvmeRwCmd *rw = (NvmeRwCmd *)&req->cmd; > > +NvmeZone *zone; > > +uint64_t slba, start_wp = req->cqe.result64; > > +uint32_t nlb, zone_idx; > > +uint8_t zs; > > + > > +if (rw->opcode != NVME_CMD_WRITE && > > +rw->opcode != NVME_CMD_ZONE_APPEND && > > +rw->opcode != NVME_CMD_WRITE_ZEROES) { > > +return false; > > +} > > + > > +slba = le64_to_cpu(rw->slba); > > +nlb = le16_to_cpu(rw->nlb) + 1; > > +zone_idx = nvme_zone_idx(ns, slba); > > +assert(zone_idx < ns->num_zones); > > +zone = &ns->zone_a
Re: [PATCH v5 09/14] hw/block/nvme: Support Zoned Namespace Command Set
On Sun, Oct 04, 2020 at 11:57:07PM +, Dmitry Fomichev wrote: > On Wed, 2020-09-30 at 14:50 +, Niklas Cassel wrote: > > On Mon, Sep 28, 2020 at 11:35:23AM +0900, Dmitry Fomichev wrote: > > > The emulation code has been changed to advertise NVM Command Set when > > > "zoned" device property is not set (default) and Zoned Namespace > > > Command Set otherwise. > > > > > > 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. > > > > > > The code to support for Zone Descriptor Extensions is not included in > > > this commit and ZDES 0 is always reported. A later commit in this > > > series will add ZDE support. > > > > > > This commit doesn't yet include checks for active and open zone > > > limits. It is assumed that there are no limits on either active or > > > open zones. > > > > > > Signed-off-by: Niklas Cassel > > > Signed-off-by: Hans Holmberg > > > Signed-off-by: Ajay Joshi > > > Signed-off-by: Chaitanya Kulkarni > > > Signed-off-by: Matias Bjorling > > > Signed-off-by: Aravind Ramesh > > > Signed-off-by: Shin'ichiro Kawasaki > > > Signed-off-by: Adam Manzanares > > > Signed-off-by: Dmitry Fomichev > > > --- > > > block/nvme.c | 2 +- > > > hw/block/nvme-ns.c | 185 - > > > hw/block/nvme-ns.h | 6 +- > > > hw/block/nvme.c | 872 +-- > > > include/block/nvme.h | 6 +- > > > 5 files changed, 1033 insertions(+), 38 deletions(-) > > > > > > diff --git a/block/nvme.c b/block/nvme.c > > > index 05485fdd11..7a513c9a17 100644 > > > --- a/block/nvme.c > > > +++ b/block/nvme.c (snip) > > > > Please read my comment on nvme_identify_nslist_csi() before reading > > this comment. > > > > At least for this function, the specification is clear: > > > > "If the host requests a data structure for an I/O Command Set that the > > controller does not support, the controller shall abort the command with > > a status of Invalid Field in Command." > > > > If the controller supports the I/O command set == if the Command Set bit > > is set in the data struct returned by the nvme_identify_cmd_set(), > > so here we should do something like: > > > > } else if (->csi == NVME_CSI_ZONED && ctrl_has_zns_namespaces()) { > > ... > > } > > > > With this commit, the controller supports ZNS command set regardless of > the number of attached ZNS namespaces. It could be zero, but the controller > still supports it. I think it would be better not to change the behavior > of this command to depend on whether there are any ZNS namespaces added > or not. Ok, always having ZNS Command Set support, regardless if a user defines a zoned namespace on the QEMU command line or not, does simplify things. But then in nvme_identify_cmd_set(), you need to call NVME_SET_CSI(*list, NVME_CSI_ZONED) unconditionally. (Right now you loop though all namespaces, and only set the support bit if you find a zoned namespace.) > > Like I wrote in my review comment in the patch that added support for the > > new > > allocated CNS values, I prefer if we remove this for-loop completely, and > > simply set attached = true in nvme_ns_setup()/nvme_ns_init() instead. > > > > (I was considering if we should set attach = true in nvme_zoned_init_ns(), > > but because nvme_ns_setup()/nvme_ns_init() is called for all namespaces, > > including ZNS namespaces, I don't think that any additional code in > > nvme_zoned_init_ns() is warranted.) > > I think CC.CSS value is not available during namespace setup and if we > assign active flag in nvme_zoned_ns_setup(), zoned namespaces may end up > being active even if NVM Only command set is selected. So keeping this loop > seems like a good idea. It is true that CC.CSS is not yet available during namespace setup, but since the controller itself will never detach namespaces based on CC.CSS, why are we dependant on CC.CSS being available? Sure, once someone implements namespace management, they will need to read if a certain namespace is attached or detached from some persistent state, perhaps in the zone meta-data file, and set attached boolean in nvme_ns_init() accordingly, but I still don't see any dependance on CC.CSS even when namespace management is implemented. Kind regards, Niklas
RE: [PATCH v5 09/14] hw/block/nvme: Support Zoned Namespace Command Set
> -Original Message- > From: Niklas Cassel > Sent: Monday, October 5, 2020 7:41 AM > To: Dmitry Fomichev > Cc: Alistair Francis ; qemu-de...@nongnu.org; > Damien Le Moal ; f...@euphon.net; Matias > Bjorling ; qemu-block@nongnu.org; > kw...@redhat.com; mlevi...@redhat.com; k.jen...@samsung.com; > kbu...@kernel.org; phi...@redhat.com > Subject: Re: [PATCH v5 09/14] hw/block/nvme: Support Zoned Namespace > Command Set > > On Sun, Oct 04, 2020 at 11:57:07PM +, Dmitry Fomichev wrote: > > On Wed, 2020-09-30 at 14:50 +, Niklas Cassel wrote: > > > On Mon, Sep 28, 2020 at 11:35:23AM +0900, Dmitry Fomichev wrote: > > > > The emulation code has been changed to advertise NVM Command Set > when > > > > "zoned" device property is not set (default) and Zoned Namespace > > > > Command Set otherwise. > > > > > > > > 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. > > > > > > > > The code to support for Zone Descriptor Extensions is not included in > > > > this commit and ZDES 0 is always reported. A later commit in this > > > > series will add ZDE support. > > > > > > > > This commit doesn't yet include checks for active and open zone > > > > limits. It is assumed that there are no limits on either active or > > > > open zones. > > > > > > > > Signed-off-by: Niklas Cassel > > > > Signed-off-by: Hans Holmberg > > > > Signed-off-by: Ajay Joshi > > > > Signed-off-by: Chaitanya Kulkarni > > > > Signed-off-by: Matias Bjorling > > > > Signed-off-by: Aravind Ramesh > > > > Signed-off-by: Shin'ichiro Kawasaki > > > > Signed-off-by: Adam Manzanares > > > > Signed-off-by: Dmitry Fomichev > > > > --- > > > > block/nvme.c | 2 +- > > > > hw/block/nvme-ns.c | 185 - > > > > hw/block/nvme-ns.h | 6 +- > > > > hw/block/nvme.c | 872 > +-- > > > > include/block/nvme.h | 6 +- > > > > 5 files changed, 1033 insertions(+), 38 deletions(-) > > > > > > > > diff --git a/block/nvme.c b/block/nvme.c > > > > index 05485fdd11..7a513c9a17 100644 > > > > --- a/block/nvme.c > > > > +++ b/block/nvme.c > > (snip) > > > > > > > Please read my comment on nvme_identify_nslist_csi() before reading > > > this comment. > > > > > > At least for this function, the specification is clear: > > > > > > "If the host requests a data structure for an I/O Command Set that the > > > controller does not support, the controller shall abort the command with > > > a status of Invalid Field in Command." > > > > > > If the controller supports the I/O command set == if the Command Set bit > > > is set in the data struct returned by the nvme_identify_cmd_set(), > > > so here we should do something like: > > > > > > } else if (->csi == NVME_CSI_ZONED && ctrl_has_zns_namespaces()) { > > > ... > > > } > > > > > > > With this commit, the controller supports ZNS command set regardless of > > the number of attached ZNS namespaces. It could be zero, but the > controller > > still supports it. I think it would be better not to change the behavior > > of this command to depend on whether there are any ZNS namespaces > added > > or not. > > Ok, always having ZNS Command Set support, regardless if a user defines > a zoned namespace on the QEMU command line or not, does simplify things. > > But then in nvme_identify_cmd_set(), you need to call > NVME_SET_CSI(*list, NVME_CSI_ZONED) unconditiona