From: Jesper Wendel Devantier <foss@defmacro.it>
To: Klaus Jensen <its@irrelevant.dk>
Cc: qemu-devel@nongnu.org, Keith Busch <kbusch@kernel.org>,
qemu-block@nongnu.org, Klaus Jensen <k.jensen@samsung.com>,
qemu-stable@nongnu.org
Subject: Re: [PATCH 1/3] hw/nvme: fix open zone zrwa allocation
Date: Thu, 19 Nov 2026 11:09:56 +0000 [thread overview]
Message-ID: <20261119120956.0-foss@defmacro.it> (raw)
In-Reply-To: <20261118-fix-4520-v1-1-dfa182213376@samsung.com>
On Wed, 18 Nov 2026 13:45:34 +0100, Klaus Jensen <its@irrelevant.dk> wrote:
> From: Klaus Jensen <k.jensen@samsung.com>
>
> nvme_zrm_open_flags incorrectly allocates a ZRWA resource regardless of
> the zone state. A ZRWA resource shall only be allocated if
>
> a) there are available ZRWA resources; and
> b) the zone is empty.
>
> Fix the state machine and error out early.
>
> Cc: qemu-stable@nongnu.org
> Link: https://gitlab.com/qemu-project/qemu/-/work_items/4520
> Fixes: e321b4cdc2dd ("hw/nvme: add support for zoned random write area")
> Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
> ---
> hw/nvme/ctrl.c | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
> index 5e8788a257da..16860ccd9520 100644
> --- a/hw/nvme/ctrl.c
> +++ b/hw/nvme/ctrl.c
> @@ -2038,10 +2038,19 @@ enum {
> static uint16_t nvme_zrm_open_flags(NvmeCtrl *n, NvmeNamespace *ns,
> NvmeZone *zone, int flags)
> {
> + NvmeZoneState state = nvme_get_zone_state(zone);
> +
> + bool zrwaa =
> + (flags & NVME_ZRM_ZRWA) && !(zone->d.za & NVME_ZA_ZRWA_VALID);
> +
> int act = 0;
> uint16_t status;
>
> - switch (nvme_get_zone_state(zone)) {
> + if (zrwaa && state != NVME_ZONE_STATE_EMPTY) {
> + return NVME_INVALID_ZONE_OP | NVME_DNR;
> + }
> +
> + switch (state) {
> case NVME_ZONE_STATE_EMPTY:
> act = 1;
>
> @@ -2051,8 +2060,7 @@ static uint16_t nvme_zrm_open_flags(NvmeCtrl *n, NvmeNamespace *ns,
> if (n->params.auto_transition_zones) {
> nvme_zrm_auto_transition_zone(ns);
> }
> - status = nvme_zns_check_resources(ns, act, 1,
> - (flags & NVME_ZRM_ZRWA) ? 1 : 0);
> + status = nvme_zns_check_resources(ns, act, 1, zrwaa);
> if (status) {
> return status;
> }
> @@ -2080,7 +2088,7 @@ static uint16_t nvme_zrm_open_flags(NvmeCtrl *n, NvmeNamespace *ns,
> /* fallthrough */
>
> case NVME_ZONE_STATE_EXPLICITLY_OPEN:
> - if (flags & NVME_ZRM_ZRWA) {
> + if (zrwaa) {
> ns->zns.numzrwa--;
>
> zone->d.za |= NVME_ZA_ZRWA_VALID;
>
> --
> 2.53.0
>
>
>
Reviewed-by: Jesper Wendel Devantier <foss@defmacro.it>
next prev parent reply other threads:[~2026-11-19 11:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 12:45 [PATCH 0/3] hw/nvme: zns/zrwa fixes Klaus Jensen
2026-11-18 12:45 ` [PATCH 1/3] hw/nvme: fix open zone zrwa allocation Klaus Jensen
2026-11-19 11:09 ` Jesper Wendel Devantier [this message]
2026-11-18 12:45 ` [PATCH 2/3] hw/nvme: bound zrwa flush by the write area and zone write boundary Klaus Jensen
2026-11-19 11:38 ` Jesper Wendel Devantier
2026-11-18 12:45 ` [PATCH 3/3] hw/nvme: advance zone write pointer only once the write is committed Klaus Jensen
2026-11-19 11:35 ` Jesper Wendel Devantier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119120956.0-foss@defmacro.it \
--to=foss@defmacro.it \
--cc=its@irrelevant.dk \
--cc=k.jensen@samsung.com \
--cc=kbusch@kernel.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.