From nobody Wed Nov 27 04:35:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1701075635; cv=none; d=zohomail.com; s=zohoarc; b=WwDOljykrs53C9HvpESXmoMVvxSSEoeDm3BH/egtCCNBJOr/z9IeUeLCBFY/EOS2x1035f7aAAxC3XOGJ4BC0gb9fICfG9012TT6y9NXlfnRsvmBJDCcOccBmkwLS2P8Y+uY9m0C+1rr8+4wwyfqsTCjdJOF3Jk2C/mvMHzdwck= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701075635; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=qlLcGE49x20put7Po+TMfj+/AujYOwf5FbyhtttvTBI=; b=XIAGrVd8DTzDpWa4GmR2RyaVWtmhg0emVlIG7gkrgiV+t91/5XMwUXve3Tas5JP3/h/tTgCAJsxUWkA4MPfmy1ot3N2+zLbTKFZ06Gh92f5Tev2uz31pt2/zQybuxJPzExS/dGlq0+DLUIxPUcLhLtmDMJWacroyMj6ZgIeHMmE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701075635183244.40375995266982; Mon, 27 Nov 2023 01:00:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7XRp-0002u6-Rd; Mon, 27 Nov 2023 03:58:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7XRk-0002tC-Ve; Mon, 27 Nov 2023 03:58:29 -0500 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7XRi-0000RQ-Hv; Mon, 27 Nov 2023 03:58:28 -0500 Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-285d32c6f07so422643a91.1; Mon, 27 Nov 2023 00:58:25 -0800 (PST) Received: from fedlinux.. ([106.84.128.244]) by smtp.gmail.com with ESMTPSA id ci8-20020a17090afc8800b0027d0adf653bsm6906901pjb.7.2023.11.27.00.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 00:58:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701075504; x=1701680304; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qlLcGE49x20put7Po+TMfj+/AujYOwf5FbyhtttvTBI=; b=XU0jbsJ6AZrBsVjPlvagEhKO5/At8Jwwx66s+1zsSaRuBa/atS7if5exceJMgk3sIZ DyT2GY14KNgS0f+VtN3tWCU1TVG3+J9XjaiUmQyqNvfWRTkZm0j5dF2G8y/EUwJeTtIH XUvLK4GlbMGLt6rK/AcqHPrE9jgJqNMbH5ePsMDlsVgg/RGMNhZ5dZVlYlA3LZSToE/Y IyBW9gm/LxssQW9xDArrSieYqTElDGBgAjhgg3DpP16ETWdTfqq/Bu1HKdscJS4ODU3z FP4F7BXwuovcFvZQsQI0tFvkj4IqOcX8AMuYxq/Xoxae+/a+4TwcirepGVq0a9Ew9k9U /tnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701075504; x=1701680304; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qlLcGE49x20put7Po+TMfj+/AujYOwf5FbyhtttvTBI=; b=erxyeP6aG2vkMgVPHXsQDP8PjSSt0jcgG8q+/fjZjvgfU6AFx24vcwpw+/DX/Zjrnz hmJ2Qb0LMu3LUA80opceVNSZ51CeTLAIZXjNo0DywgFLt1vrRQGORYL3iIecnzHHqb8T I4XdccOYXLgkWatPGbbJd+Y32jEwS2lgIqmh05fcgB5q3toAMr3dX7d0mJmmnDeWSbTS cM1jLiVfwU7HTX762wSVuFzjislBp604ZXkej2f5ozXmCTnfSSg4YFVU9KMsRvY82jZw /ZgUGZm8kcvGkYt/Jl1geUk3saEi/bJ3JQ/nwD4zWxrtwn+sKcQ+lnSI7G6uYLche5oJ gHsw== X-Gm-Message-State: AOJu0YzTp28fJrWSdPsiOuafurtSivmsndYSLc8b2pDaITEHEKTxPNak qIN3rN5rJ1Ou8bU27SmMAHfyx3WM87cLjg== X-Google-Smtp-Source: AGHT+IHaZ+bkJCMYqjqqwssV8Y9lc+WNyeVkf5iZQ+1tEUNTh9jpNefJVkMH02JturbWrhLnPRXkVg== X-Received: by 2002:a17:90b:1d0f:b0:285:a2af:31aa with SMTP id on15-20020a17090b1d0f00b00285a2af31aamr4838294pjb.37.1701075504087; Mon, 27 Nov 2023 00:58:24 -0800 (PST) From: Sam Li To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, Klaus Jensen , qemu-block@nongnu.org, hare@suse.de, David Hildenbrand , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Keith Busch , Hanna Reitz , dmitry.fomichev@wdc.com, Kevin Wolf , Markus Armbruster , Eric Blake , Peter Xu , Paolo Bonzini , dlemoal@kernel.org, Sam Li Subject: [RFC v2 7/7] hw/nvme: make ZDED persistent Date: Mon, 27 Nov 2023 16:56:41 +0800 Message-Id: <20231127085641.3729-8-faithilikerun@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231127085641.3729-1-faithilikerun@gmail.com> References: <20231127085641.3729-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x1032.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1701075637318000003 Content-Type: text/plain; charset="utf-8" Zone descriptor extension data (ZDED) is not persistent across QEMU restarts. The zone descriptor extension valid bit (ZDEV) is part of zone attributes, which sets to one when the ZDED is associated with the zone. With the qcow2 img as the backing file, the NVMe ZNS device stores the zone attributes at the following eight bit of zone type bit of write pointers for each zone. The ZDED is stored as part of zoned metadata as write pointers. Signed-off-by: Sam Li --- block/qcow2.c | 45 ++++++++++++++++++++++++++++++++++++ hw/nvme/ctrl.c | 1 + include/block/block-common.h | 1 + 3 files changed, 47 insertions(+) diff --git a/block/qcow2.c b/block/qcow2.c index 74d2e2bf39..861a8f9f06 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -25,6 +25,7 @@ #include "qemu/osdep.h" =20 #include "block/qdict.h" +#include "block/nvme.h" #include "sysemu/block-backend.h" #include "qemu/main-loop.h" #include "qemu/module.h" @@ -235,6 +236,17 @@ static inline BlockZoneState qcow2_get_zone_state(Bloc= kDriverState *bs, return BLK_ZS_NOT_WP; } =20 +static inline void qcow2_set_za(uint64_t *wp, uint8_t za) +{ + /* + * The zone attribute takes up one byte. Store it after the zoned + * bit. + */ + uint64_t addr =3D *wp; + addr |=3D ((uint64_t)za << 51); + *wp =3D addr; +} + /* * Write the new wp value to the dedicated location of the image file. */ @@ -4990,6 +5002,36 @@ unlock: return ret; } =20 +static int qcow2_zns_set_zded(BlockDriverState *bs, uint32_t index) +{ + BDRVQcow2State *s =3D bs->opaque; + int ret; + + qemu_co_mutex_lock(&bs->wps->colock); + uint64_t *wp =3D &bs->wps->wp[index]; + BlockZoneState zs =3D qcow2_get_zone_state(bs, index); + if (zs =3D=3D BLK_ZS_EMPTY) { + ret =3D qcow2_check_zone_resources(bs, zs); + if (ret < 0) { + goto unlock; + } + + qcow2_set_za(wp, NVME_ZA_ZD_EXT_VALID); + ret =3D qcow2_write_wp_at(bs, wp, index); + if (ret < 0) { + error_report("Failed to set zone extension at 0x%" PRIx64 "", = *wp); + goto unlock; + } + s->nr_zones_closed++; + qemu_co_mutex_unlock(&bs->wps->colock); + return ret; + } + +unlock: + qemu_co_mutex_unlock(&bs->wps->colock); + return NVME_ZONE_INVAL_TRANSITION; +} + static int coroutine_fn qcow2_co_zone_mgmt(BlockDriverState *bs, BlockZone= Op op, int64_t offset, int64_t len) { @@ -5046,6 +5088,9 @@ static int coroutine_fn qcow2_co_zone_mgmt(BlockDrive= rState *bs, BlockZoneOp op, case BLK_ZO_OFFLINE: /* There are no transitions from the offline state to any other st= ate */ break; + case BLK_ZO_SET_ZDED: + ret =3D qcow2_zns_set_zded(bs, index); + break; default: error_report("Unsupported zone op: 0x%x", op); ret =3D -ENOTSUP; diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index f65a87646e..c33e24e303 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -3474,6 +3474,7 @@ static uint16_t nvme_zone_mgmt_send(NvmeCtrl *n, Nvme= Request *req) break; =20 case NVME_ZONE_ACTION_SET_ZD_EXT: + op =3D BLK_ZO_SET_ZDED; int zd_ext_size =3D blk_get_zd_ext_size(blk); trace_pci_nvme_set_descriptor_extension(slba, zone_idx); if (all || !zd_ext_size) { diff --git a/include/block/block-common.h b/include/block/block-common.h index ea213c3887..b61541599f 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -91,6 +91,7 @@ typedef enum BlockZoneOp { BLK_ZO_FINISH, BLK_ZO_RESET, BLK_ZO_OFFLINE, + BLK_ZO_SET_ZDED, } BlockZoneOp; =20 typedef enum BlockZoneModel { --=20 2.40.1