From nobody Fri May 10 12:23:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1607463388; cv=none; d=zohomail.com; s=zohoarc; b=H0QMg5DW9Bi8D2/sSBajK/ds1gT1vJzl6yEvKmbAeUmk5LBwYZLwy7FPjGDmwfZD8/lZ9yLI00QVNas05GYmyMS6fXhMLYR4CPNwG6yvhS6lxdCfa5LeFStBZbqqLx2nyR5T8Mv0c20x1nmENc4frOHq4AHXTtmtZZlrJ7AnUMY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607463388; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=F6pCs27Cs/qYONEonlX2syuormBbQhW7cng7iJLTqPA=; b=h5WEBXCoFKP9PxxaKesTI9SAqXraYKI7MljNcca95KRpSQAaojiftQK1C25O95BUMJW/Us2hyjLd7O4qeItv1cQyJXz80t3H9gOYOIwkO3fBtwSLOnSVuxwGsMocC3FtNmj+TUme61tqlQZxYO8dHTzOo/rzfntTCnz6M3SH9bk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1607463388619630.4858897094855; Tue, 8 Dec 2020 13:36:28 -0800 (PST) Received: from localhost ([::1]:42302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmkep-0004U2-F4 for importer@patchew.org; Tue, 08 Dec 2020 16:36:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjDs-0002Iz-B1; Tue, 08 Dec 2020 15:04:32 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:42903) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjDo-00062i-0T; Tue, 08 Dec 2020 15:04:32 -0500 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Dec 2020 04:20:18 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2020 11:48:15 -0800 Received: from unknown (HELO redsun50.ssa.fujisawa.hgst.com) ([10.149.66.24]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Dec 2020 12:04:14 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1607458837; x=1638994837; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mWK+22Kmhk/Y80IP57/JzcVDNviZIN9jOWB1YrTJ4pg=; b=Lftq/VJsyioi3Bac2zHj1xSyniHvo8s0RSJ79d0/SStzENiFSXAhRPmd MDZVxKBUk4nrQVdSS3c6Swyx1ctEW0N9pbdbN0XtUk5meIvs2foGxUHO3 oWe/3Yy3kIr2QPg2fLFoYNl692JAFdXOefR3j/aoXyCHzvjv8zUtoXPxH j1Ym59tBGgoW/Ou/grKOME+N6apcHYkw7h3WMOgop4FaMAk42MRQzpgay 83ZXGGsXqransxIx3ENrR9sXmJ3r+vp9gWRKCuu4/ZJXoEg0VaSlp/iWJ /i5Ki7rba/mVtsgAmYZIA7Elw2dSz1T7QoOrUrb+XZ9gdS41nqfNfGtiG Q==; IronPort-SDR: nWgMqC3gDqfL2sRf8WIjyhuBvHL6KctuSknhiCmy4sJB2wRAcmreZSTZhCWQGh4cZUBfNLRuSj g+gCMqPi1QxF+B0t26KUONnJj3y0Rm37vVmDNug/oQB8mtqbwtxtUIExEYeeZnrza10SacAa1v q4Cq/Kl7PuYaMRzeft0jLdcdMR1vA+yQPdyAggVDwlT66WPBZunjKSyS6h1QsmESaFeXWIkmmp cy0BCAd+SN7SPWzQSmC542N/CdL5TqBj2EDjk08ohWbgcmjWJBbtfyGhMZrNOlPpJd100EN3Gp 4ps= X-IronPort-AV: E=Sophos;i="5.78,403,1599494400"; d="scan'208";a="258433442" IronPort-SDR: 2UdwTTShbnNWx2H1fwBEL/aKww5aV5ZlBZsVyI0q+rEQ4wVVByb3FwMh/0uTphPb0g6n/iWfai jv9iAIa3+aq6g4+o+aIXLecQaeOmrztzg= IronPort-SDR: MESOnBAxpJpue1WUIHSosTKTg+Vro/fn3hDXktJ+0NHEF9gG0P/JJcY3baxBn4VmuxwDXoJASh SfR8dvtXAsZw== WDCIronportException: Internal From: Dmitry Fomichev To: Keith Busch , Klaus Jensen , Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Max Reitz , Maxim Levitsky , Fam Zheng Subject: [PATCH v11 01/13] hw/block/nvme: Process controller reset and shutdown differently Date: Wed, 9 Dec 2020 05:03:58 +0900 Message-Id: <20201208200410.27900-2-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201208200410.27900-1-dmitry.fomichev@wdc.com> References: <20201208200410.27900-1-dmitry.fomichev@wdc.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=68.232.143.124; envelope-from=prvs=604abd949=dmitry.fomichev@wdc.com; helo=esa2.hgst.iphmx.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Niklas Cassel , Damien Le Moal , qemu-block@nongnu.org, Dmitry Fomichev , qemu-devel@nongnu.org, Alistair Francis , Matias Bjorling Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Controller 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. Suggested-by: Klaus Jensen Signed-off-by: Dmitry Fomichev Reviewed-by: Keith Busch Reviewed-by: Klaus Jensen --- hw/block/nvme-ns.h | 2 +- hw/block/nvme-ns.c | 2 +- hw/block/nvme.c | 24 ++++++++++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/hw/block/nvme-ns.h b/hw/block/nvme-ns.h index 44bf6271b7..ed3d7e65d5 100644 --- a/hw/block/nvme-ns.h +++ b/hw/block/nvme-ns.h @@ -73,6 +73,6 @@ typedef struct NvmeCtrl NvmeCtrl; =20 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); =20 #endif /* NVME_NS_H */ diff --git a/hw/block/nvme-ns.c b/hw/block/nvme-ns.c index 847069a66e..9b95e2ed33 100644 --- a/hw/block/nvme-ns.c +++ b/hw/block/nvme-ns.c @@ -130,7 +130,7 @@ void nvme_ns_drain(NvmeNamespace *ns) blk_drain(ns->blkconf.blk); } =20 -void nvme_ns_flush(NvmeNamespace *ns) +void nvme_ns_shutdown(NvmeNamespace *ns) { blk_flush(ns->blkconf.blk); } diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 59990e00bc..10acb7e7f0 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -2197,6 +2197,20 @@ static void nvme_clear_ctrl(NvmeCtrl *n) n->aer_queued =3D 0; n->outstanding_aers =3D 0; n->qs_created =3D false; +} + +static void nvme_ctrl_reset(NvmeCtrl *n) +{ + nvme_clear_ctrl(n); + n->bar.cc =3D 0; +} + +static void nvme_ctrl_shutdown(NvmeCtrl *n) +{ + NvmeNamespace *ns; + int i; + + nvme_clear_ctrl(n); =20 for (i =3D 1; i <=3D n->num_namespaces; i++) { ns =3D nvme_ns(n, i); @@ -2204,10 +2218,8 @@ static void nvme_clear_ctrl(NvmeCtrl *n) continue; } =20 - nvme_ns_flush(ns); + nvme_ns_shutdown(ns); } - - n->bar.cc =3D 0; } =20 static int nvme_start_ctrl(NvmeCtrl *n) @@ -2374,12 +2386,12 @@ static void nvme_write_bar(NvmeCtrl *n, hwaddr offs= et, 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 &=3D ~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 =3D data; n->bar.csts |=3D 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 =3D NVME(pci_dev); =20 - nvme_clear_ctrl(n); + nvme_ctrl_shutdown(n); g_free(n->cq); g_free(n->sq); g_free(n->aer_reqs); --=20 2.28.0 From nobody Fri May 10 12:23:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1607462430; cv=none; d=zohomail.com; s=zohoarc; b=l3Em3wzzd0HGUi/vvMOvd4BFY2dAu3jBdhDppmMaxJ1XS08yalQ6cur9DRQpZ3itfZIlCdfqgG1j1lsCB97xSKnahHjZ6/F79aEbDUyvfdh2a/yWK8gsru+1JmfPsT/nPiMdAJQX12NMJjTJVo+e4R3ifOEwmkL4NC11bfoiEJU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607462430; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RF9u/LoU2NNZt7svzOypsHb8epc80WPlj/ZtIF76kiU=; b=Cs2x+GJ0cmq9nZdi1Kl1M3O2UF7RAtiIQE6JAUNkqkOKDUDVF4UZo/aicwfV4pCTL4CuspHd84BHID9SoVnxgC/wuInGdvIdmAhBMvYzRbSYBhfFUL8qXGXqF2ITc0TnYD9SjV23HiXdaWRa+xPADfqJxYL3NygiAA5ksrKPSIk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1607462430085878.436233209577; Tue, 8 Dec 2020 13:20:30 -0800 (PST) Received: from localhost ([::1]:60544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmkPM-0005D5-To for importer@patchew.org; Tue, 08 Dec 2020 16:20:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56170) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjDr-0002Ga-6r; Tue, 08 Dec 2020 15:04:31 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:42913) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjDp-00063N-4K; Tue, 08 Dec 2020 15:04:30 -0500 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Dec 2020 04:20:22 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2020 11:48:18 -0800 Received: from unknown (HELO redsun50.ssa.fujisawa.hgst.com) ([10.149.66.24]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Dec 2020 12:04:16 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1607458839; x=1638994839; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ieXWxlmMiIpuZg8igJhMo3iCP4Zg9qx00ZOT4/8XGT4=; b=N1oafuPWGkuK0ASsKOWtOZSIvm4gsB6BW52ddHP4WhftxnDiBvXKIARo cq+UfmiPqeOfMRvErflE1GF6L1uolJ6ajUANNGyoJj6M8smHOX5YbbjZB edjWPLwSF2m1RmVcfTV+/pnRVStkJOMrCRFxGhbNdeMkvqjMMulXeM3cL RqRaKjM9T3luhQOxF857d5xuE/c6KHBYI70dJaLpffbMmBYnL8pAN13EX 2nET4g2fe2jwb+ajPyED6O/cq5ae1gzmonJSJk5O6jV+0NEWrRC5h+9AE UPw9sSLgLEfHJa/lQHHwqRfH3mDakGyeON9JTHXnXZFXrj64lOB7UzFnw w==; IronPort-SDR: ovQPYQ/sJB1HWUFGJBExr/BNvtLLnnBN7P2ocIqKm0uPBUzwXNc/2heo+r1hDQ4g1lPFGW1QLQ O7eRMYSIrKidpKb3nEASJPdK6akEivhbgGINVaTKj7w4Liqv+HVmGwrAyNzi4iCfXubFWorHY+ QzfuJ8MkWeZE+0kGKZHoSct0VyKMnnogMdFKwZ63FyR0L3YoaWnWTXtmBBAMcuouI/txqalkYK YkN09KSrAqVwwfUcuX2RKfXV1EBY9dN1jcsn9H2XYfFI5AZJ5C7scg9BekP1C72RmTqRvOy5Qj B4w= X-IronPort-AV: E=Sophos;i="5.78,403,1599494400"; d="scan'208";a="258433445" IronPort-SDR: 54btB6mII4N9VP/QHDDz7YlHm8/028CwHS6UBMrsBqt7uFe9SFlHH8q60JjZ7yRrci/7G4dA9Y ohkWmHx1J/nPR4z9kTWp/xctbvaJXpvcs= IronPort-SDR: JuvUoaiz8+DhCwkNYoD1vxd8/PUUAEsnYflsBmzx9XUecLxIEQAqMNc45goYjCCpuKJd8e6DMv Qm8wfMB0oSPw== WDCIronportException: Internal From: Dmitry Fomichev To: Keith Busch , Klaus Jensen , Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Max Reitz , Maxim Levitsky , Fam Zheng Subject: [PATCH v11 02/13] hw/block/nvme: Generate namespace UUIDs Date: Wed, 9 Dec 2020 05:03:59 +0900 Message-Id: <20201208200410.27900-3-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201208200410.27900-1-dmitry.fomichev@wdc.com> References: <20201208200410.27900-1-dmitry.fomichev@wdc.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=68.232.143.124; envelope-from=prvs=604abd949=dmitry.fomichev@wdc.com; helo=esa2.hgst.iphmx.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Niklas Cassel , Damien Le Moal , qemu-block@nongnu.org, Dmitry Fomichev , qemu-devel@nongnu.org, Alistair Francis , Matias Bjorling Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" In 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. Suggested-by: Klaus Jensen Signed-off-by: Dmitry Fomichev Reviewed-by: Klaus Jensen Reviewed-by: Keith Busch Reviewed-by: Niklas Cassel --- hw/block/nvme-ns.h | 1 + hw/block/nvme-ns.c | 1 + hw/block/nvme.c | 9 +++++---- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/hw/block/nvme-ns.h b/hw/block/nvme-ns.h index ed3d7e65d5..aeca810fc7 100644 --- a/hw/block/nvme-ns.h +++ b/hw/block/nvme-ns.h @@ -21,6 +21,7 @@ =20 typedef struct NvmeNamespaceParams { uint32_t nsid; + QemuUUID uuid; } NvmeNamespaceParams; =20 typedef struct NvmeNamespace { diff --git a/hw/block/nvme-ns.c b/hw/block/nvme-ns.c index 9b95e2ed33..6349aa30be 100644 --- a/hw/block/nvme-ns.c +++ b/hw/block/nvme-ns.c @@ -152,6 +152,7 @@ static void nvme_ns_realize(DeviceState *dev, Error **e= rrp) static Property nvme_ns_props[] =3D { 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(), }; =20 diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 10acb7e7f0..a30fe75620 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -1662,6 +1662,7 @@ static uint16_t nvme_identify_nslist(NvmeCtrl *n, Nvm= eRequest *req) =20 static uint16_t nvme_identify_ns_descr_list(NvmeCtrl *n, NvmeRequest *req) { + NvmeNamespace *ns; NvmeIdentify *c =3D (NvmeIdentify *)&req->cmd; uint32_t nsid =3D 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; } =20 - if (unlikely(!nvme_ns(n, nsid))) { + ns =3D nvme_ns(n, nsid); + if (unlikely(!ns)) { return NVME_INVALID_FIELD | NVME_DNR; } =20 @@ -1690,12 +1692,11 @@ static uint16_t nvme_identify_ns_descr_list(NvmeCtr= l *n, NvmeRequest *req) /* * Because the NGUID and EUI64 fields are 0 in the Identify Namespace = data * structure, a Namespace UUID (nidt =3D 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 =3D NVME_NIDT_UUID; ns_descrs->uuid.hdr.nidl =3D 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); =20 return nvme_dma(n, list, NVME_IDENTIFY_DATA_SIZE, DMA_DIRECTION_FROM_DEVICE, req); --=20 2.28.0 From nobody Fri May 10 12:23:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1607461242; cv=none; d=zohomail.com; s=zohoarc; b=J7gtt7iD9CTaZhHZe08B1FL1VttfQcYEkYGSv9PQEbiPBDij+1vukp1ZWWHjyDLaWSZDgZHuAnLNGO4945Oep9dn4eQtFIrgd/xH690zlwAx6M6Vna/7dnlAhPTcqNN98xpmfELIU1y0DFl6RI0oeeLsR700wSf73D8TDrjiuuE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607461242; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JbP5f76ugFeoywDCZjNBOtr+2h03/auhn5qZito/FqA=; b=gp74QFuil1rfZyaiaZd9s1dyRA7LMUH4M7n+ZIMyWeucTjcAR0morXT+KFNOr8MKvfnpAafbHyuqiTuI1Gg+JtTHMACHN0pnFyC8mx9RsJbUA4mV7nXakaW/4UI0tT+NV/DCKVdWRrIZaRF0NJ6+A5gJ5LjWVAvGx6wglnsKHFQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1607461242313454.8140941049186; Tue, 8 Dec 2020 13:00:42 -0800 (PST) Received: from localhost ([::1]:47014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmk6B-0003mV-1w for importer@patchew.org; Tue, 08 Dec 2020 16:00:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56208) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjDu-0002N6-7B; Tue, 08 Dec 2020 15:04:34 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:42913) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjDs-00063N-14; Tue, 08 Dec 2020 15:04:33 -0500 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Dec 2020 04:20:26 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2020 11:48:20 -0800 Received: from unknown (HELO redsun50.ssa.fujisawa.hgst.com) ([10.149.66.24]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Dec 2020 12:04:19 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1607458843; x=1638994843; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WN9rxSJmPOaKc1IWU0IELjzAmafaEWKsmbujTqyg47I=; b=X2J+P6MnVp0eNWnuvRwCo9mdKWmVo0c2NUIy0ycJdVPzoUGOltYHahTz Aharigt9cFEkOStBWYzdEeVeaUK3D9d2gtp5v1RKBPfFfrD/okHNGV1RF R5Eyew5VeBgKB2aBztoPB9iexfuMIO0SRKdUuNEFwB7kT8M3Mti1Tq6s+ jtPws/mgyDElodAC6QQa5xKtPRPNgs12Z0QpOkHU66PO7OWrMxDtxDaW4 FTxvNHlK8ZtXA9or15ZTqi3lAxbF8KtbOfsfJWHAWhWWLHDbO9VI3uXgS 3PFh9Y/CPb6AcXu6l+PXXTMg07pGzgjywcNpm3DfDM1MxRpnHXhTF+5mt g==; IronPort-SDR: /JmbuVZkDfPqY9BZiNpl/bm4iFkehS895/CX0QVs7fGBghfxormqikPKPpKWzpuRxHQQrv10zf vdevMrUVGuYEY8y4FOM5mPiiF18H9eR2HjV8EuQ4XLFT2Lxz//dqJYCcoTWKaq8xKGCMK1dDFA OJAg5tkEWPrMpdOv6qxTcqR+WCHbJ+aD3QT04X2y90jA95i+ne6pJqBkE3VUgwJuxyHllsiOkT ep7/6l/9LqTHCoWMkKQ03Dq2ynFEH5Rq6E/fOYWp+AOJayAtyuhxIKkIZUYtOK95Het+n17p7I e98= X-IronPort-AV: E=Sophos;i="5.78,403,1599494400"; d="scan'208";a="258433447" IronPort-SDR: 00Mw79/fuE7TDmXyzQQTXCbCQuHUUj8IrsdoUmmwwEZg1/rHaG7FpQPVUB4wnYKnZ0X5HLhqo3 pxMIPDixhK9LbweXhITAizfe6hetlTvVc= IronPort-SDR: r2+Xz9+tdwO3jD4bmXfkCtAddc3cKwKQ7yrqdvJflNfe7FjzSUEOSGaQY4P0nQUaLF0nkjY3d4 oHYx4rhqbozw== WDCIronportException: Internal From: Dmitry Fomichev To: Keith Busch , Klaus Jensen , Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Max Reitz , Maxim Levitsky , Fam Zheng Subject: [PATCH v11 03/13] hw/block/nvme: Separate read and write handlers Date: Wed, 9 Dec 2020 05:04:00 +0900 Message-Id: <20201208200410.27900-4-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201208200410.27900-1-dmitry.fomichev@wdc.com> References: <20201208200410.27900-1-dmitry.fomichev@wdc.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=68.232.143.124; envelope-from=prvs=604abd949=dmitry.fomichev@wdc.com; helo=esa2.hgst.iphmx.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Niklas Cassel , Damien Le Moal , qemu-block@nongnu.org, Dmitry Fomichev , qemu-devel@nongnu.org, Alistair Francis , Matias Bjorling Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The 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. Signed-off-by: Dmitry Fomichev Reviewed-by: Niklas Cassel Acked-by: Klaus Jensen Reviewed-by: Keith Busch Reviewed-by: Klaus Jensen --- hw/block/nvme.c | 107 ++++++++++++++++++++++++++++-------------- hw/block/trace-events | 3 +- 2 files changed, 74 insertions(+), 36 deletions(-) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index a30fe75620..897c2d04e5 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -1073,6 +1073,61 @@ static uint16_t nvme_flush(NvmeCtrl *n, NvmeRequest = *req) return NVME_NO_COMPLETE; } =20 +static uint16_t nvme_read(NvmeCtrl *n, NvmeRequest *req) +{ + NvmeRwCmd *rw =3D (NvmeRwCmd *)&req->cmd; + NvmeNamespace *ns =3D req->ns; + uint64_t slba =3D le64_to_cpu(rw->slba); + uint32_t nlb =3D (uint32_t)le16_to_cpu(rw->nlb) + 1; + uint64_t data_size =3D nvme_l2b(ns, nlb); + uint64_t data_offset; + BlockBackend *blk =3D ns->blkconf.blk; + uint16_t status; + + trace_pci_nvme_read(nvme_cid(req), nvme_nsid(ns), nlb, data_size, slba= ); + + status =3D nvme_check_mdts(n, data_size); + if (status) { + trace_pci_nvme_err_mdts(nvme_cid(req), data_size); + goto invalid; + } + + status =3D 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 =3D nvme_map_dptr(n, data_size, req); + if (status) { + goto invalid; + } + + if (NVME_ERR_REC_DULBE(ns->features.err_rec)) { + status =3D nvme_check_dulbe(ns, slba, nlb); + if (status) { + goto invalid; + } + } + + data_offset =3D nvme_l2b(ns, slba); + + block_acct_start(blk_get_stats(blk), &req->acct, data_size, + BLOCK_ACCT_READ); + if (req->qsg.sg) { + req->aiocb =3D dma_blk_read(blk, &req->qsg, data_offset, + BDRV_SECTOR_SIZE, nvme_rw_cb, req); + } else { + req->aiocb =3D 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 =3D (NvmeRwCmd *)&req->cmd; @@ -1098,22 +1153,19 @@ static uint16_t nvme_write_zeroes(NvmeCtrl *n, Nvme= Request *req) return NVME_NO_COMPLETE; } =20 -static uint16_t nvme_rw(NvmeCtrl *n, NvmeRequest *req) +static uint16_t nvme_write(NvmeCtrl *n, NvmeRequest *req) { NvmeRwCmd *rw =3D (NvmeRwCmd *)&req->cmd; NvmeNamespace *ns =3D req->ns; - uint32_t nlb =3D (uint32_t)le16_to_cpu(rw->nlb) + 1; uint64_t slba =3D le64_to_cpu(rw->slba); - + uint32_t nlb =3D (uint32_t)le16_to_cpu(rw->nlb) + 1; uint64_t data_size =3D nvme_l2b(ns, nlb); - uint64_t data_offset =3D nvme_l2b(ns, slba); - enum BlockAcctType acct =3D req->cmd.opcode =3D=3D NVME_CMD_WRITE ? - BLOCK_ACCT_WRITE : BLOCK_ACCT_READ; + uint64_t data_offset; BlockBackend *blk =3D ns->blkconf.blk; uint16_t status; =20 - 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); =20 status =3D nvme_check_mdts(n, data_size); if (status) { @@ -1127,43 +1179,27 @@ static uint16_t nvme_rw(NvmeCtrl *n, NvmeRequest *r= eq) goto invalid; } =20 - if (acct =3D=3D BLOCK_ACCT_READ) { - if (NVME_ERR_REC_DULBE(ns->features.err_rec)) { - status =3D nvme_check_dulbe(ns, slba, nlb); - if (status) { - goto invalid; - } - } - } - status =3D nvme_map_dptr(n, data_size, req); if (status) { goto invalid; } =20 - block_acct_start(blk_get_stats(blk), &req->acct, data_size, acct); + data_offset =3D nvme_l2b(ns, slba); + + block_acct_start(blk_get_stats(blk), &req->acct, data_size, + BLOCK_ACCT_WRITE); if (req->qsg.sg) { - if (acct =3D=3D BLOCK_ACCT_WRITE) { - req->aiocb =3D dma_blk_write(blk, &req->qsg, data_offset, - BDRV_SECTOR_SIZE, nvme_rw_cb, req); - } else { - req->aiocb =3D dma_blk_read(blk, &req->qsg, data_offset, - BDRV_SECTOR_SIZE, nvme_rw_cb, req); - } + req->aiocb =3D dma_blk_write(blk, &req->qsg, data_offset, + BDRV_SECTOR_SIZE, nvme_rw_cb, req); } else { - if (acct =3D=3D BLOCK_ACCT_WRITE) { - req->aiocb =3D blk_aio_pwritev(blk, data_offset, &req->iov, 0, - nvme_rw_cb, req); - } else { - req->aiocb =3D blk_aio_preadv(blk, data_offset, &req->iov, 0, - nvme_rw_cb, req); - } + req->aiocb =3D blk_aio_pwritev(blk, data_offset, &req->iov, 0, + nvme_rw_cb, req); } return NVME_NO_COMPLETE; =20 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; } =20 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: diff --git a/hw/block/trace-events b/hw/block/trace-events index af2d0cb28f..6233f801e1 100644 --- a/hw/block/trace-events +++ b/hw/block/trace-events @@ -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" t= ype 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, u= int64_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, u= int64_t lba) "cid %"PRIu16" nsid %"PRIu32" nlb %"PRIu32" count %"PRIu64" lb= a 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" n= lb %"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 ze= roed %d" --=20 2.28.0 From nobody Fri May 10 12:23:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1607462639; cv=none; d=zohomail.com; s=zohoarc; b=jU5ZsnQWznEFfqQj7Wmpot3htZkS+Na7foxB80TX+V25vxEjCVwGmnW7gamCnAn5ig4ThM8qjw5fuLU+gd2kM77BakuU6WoKij6uTSUkV4MjXnxqsnZ7ztcJb2Sz+iDTktbaT2idV0INZLdxoceflZGl1nXN90VxdmdHoxnx05g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607462639; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RFArs/kvAArTxsV4mfL8yvIpWcFF+2jxx1LojpcPFpg=; b=MM4xyRlU9qNmZndaFD847d33Yg2WxTlyJbFAbBJc0Vo3g1y0SJYId2EP8U7WDQ+YMIoJK8ka9cThhcSWgi45sWGHAKpwbqF44BrNRfRJgwDFmEY8RSHrzpo8pl07jpfpf0Gohk6fyD1Gitn/jdlob947w5ul892VjVbQuTX/LE0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1607462639433738.5973310614759; Tue, 8 Dec 2020 13:23:59 -0800 (PST) Received: from localhost ([::1]:40606 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmkSk-0000Id-9k for importer@patchew.org; Tue, 08 Dec 2020 16:23:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjDu-0002OA-Qm; Tue, 08 Dec 2020 15:04:34 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:42896) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjDs-000629-P6; Tue, 08 Dec 2020 15:04:34 -0500 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Dec 2020 04:20:29 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2020 11:48:22 -0800 Received: from unknown (HELO redsun50.ssa.fujisawa.hgst.com) ([10.149.66.24]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Dec 2020 12:04:21 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1607458844; x=1638994844; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+v9W57PMsdL/aempgbqFy3DHU0gTHA8DKGNqfzjXIN8=; b=mP0y2uhUL1NtkaIFY3Ekdm1sMKgvnkDuE2GMSVcYGwaNcljIRLJpIPqv WROVsZzcBQDeuU2sGQQYGsLC6PWB8Mb/UXE/T6A437FXC67xHInvD0HaJ 75spy52CfldzdS6nB+BXQKVtjvDWagHKJGQ+UFjzpg7OmdMDTEI+pNcV5 nB8F8v5jtqRhXovRAMSlmHZhro3rlglZp1aJH9UMI6LrOwbsgQ+HtWKdH ykXvPsfdqya/HWvJKJSm7rs1zrWXFU82VOdiHUdRXgnS47CzRjiVAYovy KMoRtY4fxocs51G5q+Obe2BjtoF26rTwRuysflGMxavEVA/7JYAJLtYhR w==; IronPort-SDR: izRADeXg/lP6PvPPb6drXxDRpRgRVHMi8u6brPo3EpyRzxxB+CpAJnzZ8dl6DAo5wqkUwS+Dhc SpRUZ4u+KwslUEjGPLaj4in5G4Vrq20LvHQyPj1JHlVa/efkp2WZGwlbbZVTgD+J95Kn1p0uYk XtZ0COr3dbe2Eu+PTLcBq6ZaKT3v4iEz8GAsprIOslhTHgWjP7Av1xeRGMEoT96t8kJVCsMokC W2OSq5v+i6IGnYdRRXBEZEvQfgIyToIbFf8xYqvyTlXddMsw2ATVbaqd5InXHbTfVLQ5+ZManY ruE= X-IronPort-AV: E=Sophos;i="5.78,403,1599494400"; d="scan'208";a="258433451" IronPort-SDR: 9vUYP8Zfn6Alx8lDdySGcQy55Ve1HqZijh91b1yLXd5Iu33GcjNHo33WoKzaPLUP5yrG12CBGZ DjC0aNImIBYMaAhxQf0mUfocUBpx8Rhhg= IronPort-SDR: s8WMawC3LVpttSOt1ik+ZLk4Qc/f6r21qZ5bULO6Jp7xbww9DYYKueI9YQs0xtOHd8i9wodZ9r QvJht1ZZBr0w== WDCIronportException: Internal From: Dmitry Fomichev To: Keith Busch , Klaus Jensen , Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Max Reitz , Maxim Levitsky , Fam Zheng Subject: [PATCH v11 04/13] hw/block/nvme: Combine nvme_write_zeroes() and nvme_write() Date: Wed, 9 Dec 2020 05:04:01 +0900 Message-Id: <20201208200410.27900-5-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201208200410.27900-1-dmitry.fomichev@wdc.com> References: <20201208200410.27900-1-dmitry.fomichev@wdc.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=68.232.143.124; envelope-from=prvs=604abd949=dmitry.fomichev@wdc.com; helo=esa2.hgst.iphmx.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Niklas Cassel , Damien Le Moal , qemu-block@nongnu.org, Dmitry Fomichev , qemu-devel@nongnu.org, Alistair Francis , Matias Bjorling Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Move 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. Signed-off-by: Dmitry Fomichev Reviewed-by: Niklas Cassel Acked-by: Klaus Jensen Reviewed-by: Keith Busch Reviewed-by: Klaus Jensen --- hw/block/nvme.c | 78 ++++++++++++++++++++----------------------- hw/block/trace-events | 1 - 2 files changed, 36 insertions(+), 43 deletions(-) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 897c2d04e5..986917dabf 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -1128,32 +1128,7 @@ invalid: return status | NVME_DNR; } =20 -static uint16_t nvme_write_zeroes(NvmeCtrl *n, NvmeRequest *req) -{ - NvmeRwCmd *rw =3D (NvmeRwCmd *)&req->cmd; - NvmeNamespace *ns =3D req->ns; - uint64_t slba =3D le64_to_cpu(rw->slba); - uint32_t nlb =3D (uint32_t)le16_to_cpu(rw->nlb) + 1; - uint64_t offset =3D nvme_l2b(ns, slba); - uint32_t count =3D nvme_l2b(ns, nlb); - uint16_t status; - - trace_pci_nvme_write_zeroes(nvme_cid(req), nvme_nsid(ns), slba, nlb); - - status =3D 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 =3D blk_aio_pwrite_zeroes(req->ns->blkconf.blk, offset, cou= nt, - 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 =3D (NvmeRwCmd *)&req->cmd; NvmeNamespace *ns =3D 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); =20 - status =3D nvme_check_mdts(n, data_size); - if (status) { - trace_pci_nvme_err_mdts(nvme_cid(req), data_size); - goto invalid; + if (!wrz) { + status =3D nvme_check_mdts(n, data_size); + if (status) { + trace_pci_nvme_err_mdts(nvme_cid(req), data_size); + goto invalid; + } } =20 status =3D nvme_check_bounds(n, ns, slba, nlb); @@ -1179,21 +1156,28 @@ static uint16_t nvme_write(NvmeCtrl *n, NvmeRequest= *req) goto invalid; } =20 - status =3D nvme_map_dptr(n, data_size, req); - if (status) { - goto invalid; - } - data_offset =3D nvme_l2b(ns, slba); =20 - block_acct_start(blk_get_stats(blk), &req->acct, data_size, - BLOCK_ACCT_WRITE); - if (req->qsg.sg) { - req->aiocb =3D dma_blk_write(blk, &req->qsg, data_offset, - BDRV_SECTOR_SIZE, nvme_rw_cb, req); + if (!wrz) { + status =3D 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 =3D dma_blk_write(blk, &req->qsg, data_offset, + BDRV_SECTOR_SIZE, nvme_rw_cb, req); + } else { + req->aiocb =3D blk_aio_pwritev(blk, data_offset, &req->iov, 0, + nvme_rw_cb, req); + } } else { - req->aiocb =3D 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_WRI= TE); + req->aiocb =3D blk_aio_pwrite_zeroes(blk, data_offset, data_size, + BDRV_REQ_MAY_UNMAP, nvme_rw_cb, + req); } return NVME_NO_COMPLETE; =20 @@ -1202,6 +1186,16 @@ invalid: return status | NVME_DNR; } =20 +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 =3D le32_to_cpu(req->cmd.nsid); diff --git a/hw/block/trace-events b/hw/block/trace-events index 6233f801e1..02a7c3044c 100644 --- a/hw/block/trace-events +++ b/hw/block/trace-events @@ -43,7 +43,6 @@ pci_nvme_admin_cmd(uint16_t cid, uint16_t sqid, uint8_t o= pcode, const char *opna pci_nvme_read(uint16_t cid, uint32_t nsid, uint32_t nlb, uint64_t count, u= int64_t lba) "cid %"PRIu16" nsid %"PRIu32" nlb %"PRIu32" count %"PRIu64" lb= a 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" n= lb %"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 ze= roed %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"" --=20 2.28.0 From nobody Fri May 10 12:23:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1607462235; cv=none; d=zohomail.com; s=zohoarc; b=iq1RkDAcPQUQS+aY+Brwjf1KdTM79x7wDvatIR6u6yTR3LHJrL6Oorr48BfmaCI3nwWsEL/+gV06VoWvxgVZwHE9CpccRSZ9jpGKF6exZQj7aKR0MLE0/9cJQFlo16MoVd6I7nfPBS2nurvWy7z0NnY6JOABsTtQNqhtijhDKdI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607462235; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nG9vbTQaToQHRWUawSzslJ6li/HR9wkB+cKYpsGxOB0=; b=U7bnrhiOPBPiVm3cLnwcPjn53cCE99Yl1+93WljGO2rq8HE5EsuqLAGpuYHn9559dDZbjh0rntu+hHYAz5SaTsQzEBLnVIOPhBTaLkZKSp3X/Qo0tcAA03RNn6G3khWOV9iotdKD6x0rgaafgRSmX3UbFnYgEOznYK5IzM5pzCk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1607462235681869.8312213482934; Tue, 8 Dec 2020 13:17:15 -0800 (PST) Received: from localhost ([::1]:53674 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmkMD-0002C6-44 for importer@patchew.org; Tue, 08 Dec 2020 16:17:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjDw-0002Pd-92; Tue, 08 Dec 2020 15:04:36 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:42903) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjDt-00062i-9G; Tue, 08 Dec 2020 15:04:36 -0500 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Dec 2020 04:20:33 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2020 11:48:25 -0800 Received: from unknown (HELO redsun50.ssa.fujisawa.hgst.com) ([10.149.66.24]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Dec 2020 12:04:23 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1607458845; x=1638994845; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+rshqe8t84JiuEYHtk4GKvUqvXSusfBr4811+sR55Tw=; b=mGsKKDMH+cdiVbMR1QdR16YFIIcM9Wp/1D5lO8OpImlKwxXUz1bVNilo xHjzHVvgUvx3p5VEqLy0eqWkMORqv2EI4S4izFwCsb6qLt57EF4U9XkT+ /WuNghKR2ZjkHIMyvoDANcFsXydDMBIf3ca2PDqPq+ggLE1az2Zk1g6rb BZ4JbKDE05Guzity6l89EEH4VXXvlqyzbybSG8SNTJHgPN+5zgobGxuBP xYK4b4+MKkI+lOR5KqILBMPkANZHe1nT5vVHnsbdD8r8tPwPd9kAFxjES 8bWQi/eXmIreDuN06+29LPmi9qLI085OlezMExuKzrlGQSuLdMTfDSyiC Q==; IronPort-SDR: oVPDmWlKpBJfTwurPsN79zZuZgq1893P0gB3ryWujCnQZ4T5Ynqs5DzB+I7Pzy83OZD8rPycXl K2/yqdRS0noMHpHBSNXvKJT339kxYv9CSlIfU6aFQP6h23TCSV9otfAcUVPDTsDzyvdfKEzhsl 9+fdtk/Ax3BzLA7RR1fe5AqDkuv0FdyJr+2+wZPYW+YCOwcGd2lhc2DA9EbbsA5IByIrPMMsrG xhwKiLN6uWwC+xwp+i8HCpbbwSPnOGaxkOKFDGOYV3NBw9vfFJ23HMKvwM0jasnGVI4P1N8z8J 1JY= X-IronPort-AV: E=Sophos;i="5.78,403,1599494400"; d="scan'208";a="258433456" IronPort-SDR: BtD/lsDPDTh2hAMuY3ux5T1YThOOYTty82pDKdD7hveRpYpecprjQd+b3ti08GkwXdTstJX6rS WRkyQvl1OVD11b7x/cAl0xBTqdwpRkXCs= IronPort-SDR: IaAMr3M7gdAmDhAPSvJRQa5X8F3wrh+xiDGwgO75kNNX6AiHmsEu05Tlh1vD4GIPfHY90rxEil mRddXq02whEg== WDCIronportException: Internal From: Dmitry Fomichev To: Keith Busch , Klaus Jensen , Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Max Reitz , Maxim Levitsky , Fam Zheng Subject: [PATCH v11 05/13] hw/block/nvme: Add Commands Supported and Effects log Date: Wed, 9 Dec 2020 05:04:02 +0900 Message-Id: <20201208200410.27900-6-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201208200410.27900-1-dmitry.fomichev@wdc.com> References: <20201208200410.27900-1-dmitry.fomichev@wdc.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=68.232.143.124; envelope-from=prvs=604abd949=dmitry.fomichev@wdc.com; helo=esa2.hgst.iphmx.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Niklas Cassel , Damien Le Moal , qemu-block@nongnu.org, Dmitry Fomichev , qemu-devel@nongnu.org, Alistair Francis , Matias Bjorling Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This 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. Signed-off-by: Dmitry Fomichev Reviewed-by: Niklas Cassel Reviewed-by: Keith Busch Reviewed-by: Klaus Jensen --- 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(-) diff --git a/hw/block/nvme-ns.h b/hw/block/nvme-ns.h index aeca810fc7..bdeaf1c0de 100644 --- a/hw/block/nvme-ns.h +++ b/hw/block/nvme-ns.h @@ -30,6 +30,7 @@ typedef struct NvmeNamespace { int32_t bootindex; int64_t size; NvmeIdNs id_ns; + const uint32_t *iocs; =20 NvmeNamespaceParams params; =20 diff --git a/include/block/nvme.h b/include/block/nvme.h index e95ff6ca9b..422c98a297 100644 --- a/include/block/nvme.h +++ b/include/block/nvme.h @@ -746,10 +746,27 @@ enum NvmeSmartWarn { NVME_SMART_FAILED_VOLATILE_MEDIA =3D 1 << 4, }; =20 +typedef struct NvmeEffectsLog { + uint32_t acs[256]; + uint32_t iocs[256]; + uint8_t resv[2048]; +} NvmeEffectsLog; + +enum { + NVME_CMD_EFF_CSUPP =3D 1 << 0, + NVME_CMD_EFF_LBCC =3D 1 << 1, + NVME_CMD_EFF_NCC =3D 1 << 2, + NVME_CMD_EFF_NIC =3D 1 << 3, + NVME_CMD_EFF_CCC =3D 1 << 4, + NVME_CMD_EFF_CSE_MASK =3D 3 << 16, + NVME_CMD_EFF_UUID_SEL =3D 1 << 19, +}; + enum NvmeLogIdentifier { NVME_LOG_ERROR_INFO =3D 0x01, NVME_LOG_SMART_INFO =3D 0x02, NVME_LOG_FW_SLOT_INFO =3D 0x03, + NVME_LOG_CMD_EFFECTS =3D 0x05, }; =20 typedef struct QEMU_PACKED NvmePSD { @@ -862,6 +879,7 @@ enum NvmeIdCtrlFrmw { =20 enum NvmeIdCtrlLpa { NVME_LPA_NS_SMART =3D 1 << 0, + NVME_LPA_CSE =3D 1 << 1, NVME_LPA_EXTENDED =3D 1 << 2, }; =20 @@ -1070,6 +1088,7 @@ static inline void _nvme_check_size(void) QEMU_BUILD_BUG_ON(sizeof(NvmeErrorLog) !=3D 64); QEMU_BUILD_BUG_ON(sizeof(NvmeFwSlotInfoLog) !=3D 512); QEMU_BUILD_BUG_ON(sizeof(NvmeSmartLog) !=3D 512); + QEMU_BUILD_BUG_ON(sizeof(NvmeEffectsLog) !=3D 4096); QEMU_BUILD_BUG_ON(sizeof(NvmeIdCtrl) !=3D 4096); QEMU_BUILD_BUG_ON(sizeof(NvmeIdNs) !=3D 4096); QEMU_BUILD_BUG_ON(sizeof(NvmeSglDescriptor) !=3D 16); diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 986917dabf..0b047f2069 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -112,6 +112,28 @@ static const uint32_t nvme_feature_cap[NVME_FID_MAX] = =3D { [NVME_TIMESTAMP] =3D NVME_FEAT_CAP_CHANGE, }; =20 +static const uint32_t nvme_cse_acs[256] =3D { + [NVME_ADM_CMD_DELETE_SQ] =3D NVME_CMD_EFF_CSUPP, + [NVME_ADM_CMD_CREATE_SQ] =3D NVME_CMD_EFF_CSUPP, + [NVME_ADM_CMD_GET_LOG_PAGE] =3D NVME_CMD_EFF_CSUPP, + [NVME_ADM_CMD_DELETE_CQ] =3D NVME_CMD_EFF_CSUPP, + [NVME_ADM_CMD_CREATE_CQ] =3D NVME_CMD_EFF_CSUPP, + [NVME_ADM_CMD_IDENTIFY] =3D NVME_CMD_EFF_CSUPP, + [NVME_ADM_CMD_ABORT] =3D NVME_CMD_EFF_CSUPP, + [NVME_ADM_CMD_SET_FEATURES] =3D NVME_CMD_EFF_CSUPP, + [NVME_ADM_CMD_GET_FEATURES] =3D NVME_CMD_EFF_CSUPP, + [NVME_ADM_CMD_ASYNC_EV_REQ] =3D NVME_CMD_EFF_CSUPP, +}; + +static const uint32_t nvme_cse_iocs_none[256]; + +static const uint32_t nvme_cse_iocs_nvm[256] =3D { + [NVME_CMD_FLUSH] =3D NVME_CMD_EFF_CSUPP | NVME_CMD_EFF_= LBCC, + [NVME_CMD_WRITE_ZEROES] =3D NVME_CMD_EFF_CSUPP | NVME_CMD_EFF_= LBCC, + [NVME_CMD_WRITE] =3D NVME_CMD_EFF_CSUPP | NVME_CMD_EFF_= LBCC, + [NVME_CMD_READ] =3D NVME_CMD_EFF_CSUPP, +}; + static void nvme_process_sq(void *opaque); =20 static uint16_t nvme_cid(NvmeRequest *req) @@ -1203,10 +1225,6 @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeRequest= *req) trace_pci_nvme_io_cmd(nvme_cid(req), nsid, nvme_sqid(req), req->cmd.opcode, nvme_io_opc_str(req->cmd.opcode= )); =20 - if (NVME_CC_CSS(n->bar.cc) =3D=3D NVME_CC_CSS_ADMIN_ONLY) { - return NVME_INVALID_OPCODE | NVME_DNR; - } - if (!nvme_nsid_valid(n, nsid)) { return NVME_INVALID_NSID | NVME_DNR; } @@ -1216,6 +1234,11 @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeRequest= *req) return NVME_INVALID_FIELD | NVME_DNR; } =20 + if (!(req->ns->iocs[req->cmd.opcode] & NVME_CMD_EFF_CSUPP)) { + trace_pci_nvme_err_invalid_opc(req->cmd.opcode); + return NVME_INVALID_OPCODE | NVME_DNR; + } + switch (req->cmd.opcode) { case NVME_CMD_FLUSH: return nvme_flush(n, req); @@ -1228,8 +1251,7 @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeRequest = *req) case NVME_CMD_DSM: return nvme_dsm(n, req); default: - trace_pci_nvme_err_invalid_opc(req->cmd.opcode); - return NVME_INVALID_OPCODE | NVME_DNR; + assert(false); } } =20 @@ -1466,6 +1488,37 @@ static uint16_t nvme_error_info(NvmeCtrl *n, uint8_t= rae, uint32_t buf_len, DMA_DIRECTION_FROM_DEVICE, req); } =20 +static uint16_t nvme_cmd_effects(NvmeCtrl *n, uint32_t buf_len, + uint64_t off, NvmeRequest *req) +{ + NvmeEffectsLog log =3D {}; + const uint32_t *src_iocs =3D NULL; + uint32_t trans_len; + + if (off >=3D sizeof(log)) { + trace_pci_nvme_err_invalid_log_page_offset(off, sizeof(log)); + return NVME_INVALID_FIELD | NVME_DNR; + } + + switch (NVME_CC_CSS(n->bar.cc)) { + case NVME_CC_CSS_NVM: + src_iocs =3D nvme_cse_iocs_nvm; + case NVME_CC_CSS_ADMIN_ONLY: + break; + } + + memcpy(log.acs, nvme_cse_acs, sizeof(nvme_cse_acs)); + + if (src_iocs) { + memcpy(log.iocs, src_iocs, sizeof(log.iocs)); + } + + trans_len =3D MIN(sizeof(log) - off, buf_len); + + return nvme_dma(n, ((uint8_t *)&log) + off, trans_len, + DMA_DIRECTION_FROM_DEVICE, req); +} + static uint16_t nvme_get_log(NvmeCtrl *n, NvmeRequest *req) { NvmeCmd *cmd =3D &req->cmd; @@ -1509,6 +1562,8 @@ static uint16_t nvme_get_log(NvmeCtrl *n, NvmeRequest= *req) return nvme_smart_info(n, rae, len, off, req); case NVME_LOG_FW_SLOT_INFO: return nvme_fw_log_info(n, len, off, req); + case NVME_LOG_CMD_EFFECTS: + return nvme_cmd_effects(n, len, off, req); default: trace_pci_nvme_err_invalid_log_page(nvme_cid(req), lid); return NVME_INVALID_FIELD | NVME_DNR; @@ -2131,6 +2186,11 @@ static uint16_t nvme_admin_cmd(NvmeCtrl *n, NvmeRequ= est *req) trace_pci_nvme_admin_cmd(nvme_cid(req), nvme_sqid(req), req->cmd.opcod= e, nvme_adm_opc_str(req->cmd.opcode)); =20 + if (!(nvme_cse_acs[req->cmd.opcode] & NVME_CMD_EFF_CSUPP)) { + trace_pci_nvme_err_invalid_admin_opc(req->cmd.opcode); + return NVME_INVALID_OPCODE | NVME_DNR; + } + switch (req->cmd.opcode) { case NVME_ADM_CMD_DELETE_SQ: return nvme_del_sq(n, req); @@ -2153,8 +2213,7 @@ static uint16_t nvme_admin_cmd(NvmeCtrl *n, NvmeReque= st *req) case NVME_ADM_CMD_ASYNC_EV_REQ: return nvme_aer(n, req); default: - trace_pci_nvme_err_invalid_admin_opc(req->cmd.opcode); - return NVME_INVALID_OPCODE | NVME_DNR; + assert(false); } } =20 @@ -2254,6 +2313,23 @@ static void nvme_ctrl_shutdown(NvmeCtrl *n) } } =20 +static void nvme_select_ns_iocs(NvmeCtrl *n) +{ + NvmeNamespace *ns; + int i; + + for (i =3D 1; i <=3D n->num_namespaces; i++) { + ns =3D nvme_ns(n, i); + if (!ns) { + continue; + } + ns->iocs =3D nvme_cse_iocs_none; + if (NVME_CC_CSS(n->bar.cc) !=3D NVME_CC_CSS_ADMIN_ONLY) { + ns->iocs =3D nvme_cse_iocs_nvm; + } + } +} + static int nvme_start_ctrl(NvmeCtrl *n) { uint32_t page_bits =3D NVME_CC_MPS(n->bar.cc) + 12; @@ -2352,6 +2428,8 @@ static int nvme_start_ctrl(NvmeCtrl *n) =20 QTAILQ_INIT(&n->aer_queue); =20 + nvme_select_ns_iocs(n); + return 0; } =20 @@ -2959,7 +3037,7 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pc= i_dev) id->acl =3D 3; id->aerl =3D n->params.aerl; id->frmw =3D (NVME_NUM_FW_SLOTS << 1) | NVME_FRMW_SLOT1_RO; - id->lpa =3D NVME_LPA_NS_SMART | NVME_LPA_EXTENDED; + id->lpa =3D NVME_LPA_NS_SMART | NVME_LPA_CSE | NVME_LPA_EXTENDED; =20 /* recommended default value (~70 C) */ id->wctemp =3D cpu_to_le16(NVME_TEMPERATURE_WARNING); diff --git a/hw/block/trace-events b/hw/block/trace-events index 02a7c3044c..22e0108c9d 100644 --- a/hw/block/trace-events +++ b/hw/block/trace-events @@ -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%"PRIx= 8"" pci_nvme_err_invalid_lba_range(uint64_t start, uint64_t len, uint64_t limi= t) "Invalid LBA start=3D%"PRIu64" len=3D%"PRIu64" limit=3D%"PRIu64"" +pci_nvme_err_invalid_log_page_offset(uint64_t ofs, uint64_t size) "must be= <=3D %"PRIu64", got %"PRIu64"" pci_nvme_err_invalid_del_sq(uint16_t qid) "invalid submission queue deleti= on, sid=3D%"PRIu16"" pci_nvme_err_invalid_create_sq_cqid(uint16_t cqid) "failed creating submis= sion queue, invalid cqid=3D%"PRIu16"" pci_nvme_err_invalid_create_sq_sqid(uint16_t sqid) "failed creating submis= sion queue, invalid sqid=3D%"PRIu16"" --=20 2.28.0 From nobody Fri May 10 12:23:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1607462481; cv=none; d=zohomail.com; s=zohoarc; b=Qz0QhZ/ZLMH+GeEbWG9D0IwVH1nrakQVwoUBzFi717Pf+IatSENlTiwc6iOw4g6jfBSBX2oK7Q1zK8m7ZMN1f59NeJap8YwI6pjI10ikWQpgf4Vc3V8bm61rCFsavlAhQhEsHldsOfRxMP9I/cMTP2pmagozCqMoZI/5TTdiSbA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607462481; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qIpKCa434HCKudm0+TARpBB0DkkX50GIsgvLgttlD0g=; b=am1ZL5SbQ1xwlF38TQIeDmpiHCQ9uA9uEpu//Nywjyrnrl9k4RIwVHmPVxrjGyRgLUOtxBjbh5Sfkkyr7NnykbUHCA2LiPmbOHJV59Z3D9KvQUZrxVJg1eW5kukJE6zssJvT8eAjibWsYKW+vOclyfAHeQRFSdTtjRMferNJwxg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1607462481246669.797337890674; Tue, 8 Dec 2020 13:21:21 -0800 (PST) Received: from localhost ([::1]:33996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmkQC-0005vH-0Z for importer@patchew.org; Tue, 08 Dec 2020 16:21:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56326) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjE3-0002TO-Cz; Tue, 08 Dec 2020 15:04:43 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:42913) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjDu-00063N-VV; Tue, 08 Dec 2020 15:04:41 -0500 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Dec 2020 04:20:36 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2020 11:48:27 -0800 Received: from unknown (HELO redsun50.ssa.fujisawa.hgst.com) ([10.149.66.24]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Dec 2020 12:04:26 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1607458848; x=1638994848; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cW9oKL1Nn9iXWSyT8CEv7pvigNi6tEczvQ0pfZmfPOo=; b=ou3SIJVTZ2MGBvoBvJZwPnkY/zvwYqYnDwy6gDfFTdRE5s2yAPpJMNnG DU3qjE8TDflQNvtPU6ZRlugBxBFAJQ202o7GXgRJjEgwdtbMePKAcoRpv fYoeC1m/hCN+SRZXdoSPqO0kSWMPmoqTI4kZwMQcIE9H8kgb2yg4PWMwV V2x2DwfifeyzPq8pxaPmVbdyMdUBC0xGzHwH46YgFA9DhVmX80rh0Ag+j nJ22rEmNB2ob3KJRfWH2HTOGxZre6kFyNea+cL91quIe9OVg3tC8n7uO/ JsJc+lHVV7OFXsOqdjoIZTQqz5kaNCqn+88zQ+FHB/RBL7kUH9tnpKdpj g==; IronPort-SDR: 2W0T2WSjJ9cBcyZNcpUgKDFGNK1CWUrYeUsr4ss0Fzkj37VxW+Pw6siSbEazKd6MNoYUOxYKK2 vzsCcAX27Gb3gHZeb0x2apA8r/qIkStsovn5FF4Iq52SoTjkWuIdTayXAwJvVCXFf8mgE0Y61j t1Vj+6u26xEribO6V7mVG11d0a4ZrRgUuvRaJND5VbMQnFgBIaWtY/3nCO6uA+0cANjXieDYkO 637cvHmdtldHmNfxF7Md8oHndfmx679ayFl9wFDd60Pc7p8K4AxNyf/a2y3ScDkfODpXOwR/sr 5+s= X-IronPort-AV: E=Sophos;i="5.78,403,1599494400"; d="scan'208";a="258433458" IronPort-SDR: 6KpgUy7gSzb+Y0kCoeZN0MmImaENHfQ7rRuomXC4ZWO5Xtpl//JMSpc9P/F3u9jb08PGhpHMBs 23GD7CyojU3t77ZsMBx96i4tc0CSFbwPM= IronPort-SDR: xIzMfA1RMd6OHouMUtwylftbBhJxk6t0+tpU2PLTN7+ALogV3MHxO3szIHLDAdo1A2pCj0Uz1Q x7newvYPxosA== WDCIronportException: Internal From: Dmitry Fomichev To: Keith Busch , Klaus Jensen , Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Max Reitz , Maxim Levitsky , Fam Zheng Subject: [PATCH v11 06/13] hw/block/nvme: Add support for Namespace Types Date: Wed, 9 Dec 2020 05:04:03 +0900 Message-Id: <20201208200410.27900-7-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201208200410.27900-1-dmitry.fomichev@wdc.com> References: <20201208200410.27900-1-dmitry.fomichev@wdc.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=68.232.143.124; envelope-from=prvs=604abd949=dmitry.fomichev@wdc.com; helo=esa2.hgst.iphmx.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Niklas Cassel , Damien Le Moal , qemu-block@nongnu.org, Dmitry Fomichev , qemu-devel@nongnu.org, Alistair Francis , Matias Bjorling Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Niklas Cassel 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. Signed-off-by: Niklas Cassel Signed-off-by: Dmitry Fomichev Reviewed-by: Keith Busch Reviewed-by: Klaus Jensen --- 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(-) diff --git a/hw/block/nvme-ns.h b/hw/block/nvme-ns.h index bdeaf1c0de..bdbc98c2ec 100644 --- a/hw/block/nvme-ns.h +++ b/hw/block/nvme-ns.h @@ -31,6 +31,7 @@ typedef struct NvmeNamespace { int64_t size; NvmeIdNs id_ns; const uint32_t *iocs; + uint8_t csi; =20 NvmeNamespaceParams params; =20 diff --git a/include/block/nvme.h b/include/block/nvme.h index 422c98a297..890977db4b 100644 --- a/include/block/nvme.h +++ b/include/block/nvme.h @@ -84,6 +84,7 @@ enum NvmeCapMask { =20 enum NvmeCapCss { NVME_CAP_CSS_NVM =3D 1 << 0, + NVME_CAP_CSS_CSI_SUPP =3D 1 << 6, NVME_CAP_CSS_ADMIN_ONLY =3D 1 << 7, }; =20 @@ -117,9 +118,25 @@ enum NvmeCcMask { =20 enum NvmeCcCss { NVME_CC_CSS_NVM =3D 0x0, + NVME_CC_CSS_CSI =3D 0x6, NVME_CC_CSS_ADMIN_ONLY =3D 0x7, }; =20 +#define NVME_SET_CC_EN(cc, val) \ + (cc |=3D (uint32_t)((val) & CC_EN_MASK) << CC_EN_SHIFT) +#define NVME_SET_CC_CSS(cc, val) \ + (cc |=3D (uint32_t)((val) & CC_CSS_MASK) << CC_CSS_SHIFT) +#define NVME_SET_CC_MPS(cc, val) \ + (cc |=3D (uint32_t)((val) & CC_MPS_MASK) << CC_MPS_SHIFT) +#define NVME_SET_CC_AMS(cc, val) \ + (cc |=3D (uint32_t)((val) & CC_AMS_MASK) << CC_AMS_SHIFT) +#define NVME_SET_CC_SHN(cc, val) \ + (cc |=3D (uint32_t)((val) & CC_SHN_MASK) << CC_SHN_SHIFT) +#define NVME_SET_CC_IOSQES(cc, val) \ + (cc |=3D (uint32_t)((val) & CC_IOSQES_MASK) << CC_IOSQES_SHIFT) +#define NVME_SET_CC_IOCQES(cc, val) \ + (cc |=3D (uint32_t)((val) & CC_IOCQES_MASK) << CC_IOCQES_SHIFT) + enum NvmeCstsShift { CSTS_RDY_SHIFT =3D 0, CSTS_CFS_SHIFT =3D 1, @@ -534,8 +551,13 @@ typedef struct QEMU_PACKED NvmeIdentify { uint64_t rsvd2[2]; uint64_t prp1; uint64_t prp2; - uint32_t cns; - uint32_t rsvd11[5]; + uint8_t cns; + uint8_t rsvd10; + uint16_t ctrlid; + uint16_t nvmsetid; + uint8_t rsvd11; + uint8_t csi; + uint32_t rsvd12[4]; } NvmeIdentify; =20 typedef struct QEMU_PACKED NvmeRwCmd { @@ -656,6 +678,7 @@ enum NvmeStatusCodes { NVME_SGL_DESCR_TYPE_INVALID =3D 0x0011, NVME_INVALID_USE_OF_CMB =3D 0x0012, NVME_INVALID_PRP_OFFSET =3D 0x0013, + NVME_CMD_SET_CMB_REJECTED =3D 0x002b, NVME_LBA_RANGE =3D 0x0080, NVME_CAP_EXCEEDED =3D 0x0081, NVME_NS_NOT_READY =3D 0x0082, @@ -783,11 +806,15 @@ typedef struct QEMU_PACKED NvmePSD { =20 #define NVME_IDENTIFY_DATA_SIZE 4096 =20 -enum { - NVME_ID_CNS_NS =3D 0x0, - NVME_ID_CNS_CTRL =3D 0x1, - NVME_ID_CNS_NS_ACTIVE_LIST =3D 0x2, - NVME_ID_CNS_NS_DESCR_LIST =3D 0x3, +enum NvmeIdCns { + NVME_ID_CNS_NS =3D 0x00, + NVME_ID_CNS_CTRL =3D 0x01, + NVME_ID_CNS_NS_ACTIVE_LIST =3D 0x02, + NVME_ID_CNS_NS_DESCR_LIST =3D 0x03, + NVME_ID_CNS_CS_NS =3D 0x05, + NVME_ID_CNS_CS_CTRL =3D 0x06, + NVME_ID_CNS_CS_NS_ACTIVE_LIST =3D 0x07, + NVME_ID_CNS_IO_COMMAND_SET =3D 0x1c, }; =20 typedef struct QEMU_PACKED NvmeIdCtrl { @@ -938,6 +965,7 @@ enum NvmeFeatureIds { NVME_WRITE_ATOMICITY =3D 0xa, NVME_ASYNCHRONOUS_EVENT_CONF =3D 0xb, NVME_TIMESTAMP =3D 0xe, + NVME_COMMAND_SET_PROFILE =3D 0x19, NVME_SOFTWARE_PROGRESS_MARKER =3D 0x80, NVME_FID_MAX =3D 0x100, }; @@ -1027,18 +1055,26 @@ typedef struct QEMU_PACKED NvmeIdNsDescr { uint8_t rsvd2[2]; } NvmeIdNsDescr; =20 -enum { - NVME_NIDT_EUI64_LEN =3D 8, - NVME_NIDT_NGUID_LEN =3D 16, - NVME_NIDT_UUID_LEN =3D 16, +enum NvmeNsIdentifierLength { + NVME_NIDL_EUI64 =3D 8, + NVME_NIDL_NGUID =3D 16, + NVME_NIDL_UUID =3D 16, + NVME_NIDL_CSI =3D 1, }; =20 enum NvmeNsIdentifierType { - NVME_NIDT_EUI64 =3D 0x1, - NVME_NIDT_NGUID =3D 0x2, - NVME_NIDT_UUID =3D 0x3, + NVME_NIDT_EUI64 =3D 0x01, + NVME_NIDT_NGUID =3D 0x02, + NVME_NIDT_UUID =3D 0x03, + NVME_NIDT_CSI =3D 0x04, }; =20 +enum NvmeCsi { + NVME_CSI_NVM =3D 0x00, +}; + +#define NVME_SET_CSI(vec, csi) (vec |=3D (uint8_t)(1 << (csi))) + /*Deallocate Logical Block Features*/ #define NVME_ID_NS_DLFEAT_GUARD_CRC(dlfeat) ((dlfeat) & 0x10) #define NVME_ID_NS_DLFEAT_WRITE_ZEROES(dlfeat) ((dlfeat) & 0x08) diff --git a/hw/block/nvme-ns.c b/hw/block/nvme-ns.c index 6349aa30be..961cc81923 100644 --- a/hw/block/nvme-ns.c +++ b/hw/block/nvme-ns.c @@ -43,6 +43,8 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp) =20 id_ns->nsze =3D cpu_to_le64(nvme_ns_nlbas(ns)); =20 + ns->csi =3D NVME_CSI_NVM; + /* no thin provisioning */ id_ns->ncap =3D id_ns->nsze; id_ns->nuse =3D id_ns->ncap; diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 0b047f2069..16eed37533 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -1488,7 +1488,7 @@ static uint16_t nvme_error_info(NvmeCtrl *n, uint8_t = rae, uint32_t buf_len, DMA_DIRECTION_FROM_DEVICE, req); } =20 -static uint16_t nvme_cmd_effects(NvmeCtrl *n, uint32_t buf_len, +static uint16_t nvme_cmd_effects(NvmeCtrl *n, uint8_t csi, uint32_t buf_le= n, uint64_t off, NvmeRequest *req) { NvmeEffectsLog log =3D {}; @@ -1503,8 +1503,15 @@ static uint16_t nvme_cmd_effects(NvmeCtrl *n, uint32= _t buf_len, switch (NVME_CC_CSS(n->bar.cc)) { case NVME_CC_CSS_NVM: src_iocs =3D nvme_cse_iocs_nvm; + /* fall through */ case NVME_CC_CSS_ADMIN_ONLY: break; + case NVME_CC_CSS_CSI: + switch (csi) { + case NVME_CSI_NVM: + src_iocs =3D nvme_cse_iocs_nvm; + break; + } } =20 memcpy(log.acs, nvme_cse_acs, sizeof(nvme_cse_acs)); @@ -1530,6 +1537,7 @@ static uint16_t nvme_get_log(NvmeCtrl *n, NvmeRequest= *req) uint8_t lid =3D dw10 & 0xff; uint8_t lsp =3D (dw10 >> 8) & 0xf; uint8_t rae =3D (dw10 >> 15) & 0x1; + uint8_t csi =3D le32_to_cpu(cmd->cdw14) >> 24; uint32_t numdl, numdu; uint64_t off, lpol, lpou; size_t len; @@ -1563,7 +1571,7 @@ static uint16_t nvme_get_log(NvmeCtrl *n, NvmeRequest= *req) case NVME_LOG_FW_SLOT_INFO: return nvme_fw_log_info(n, len, off, req); case NVME_LOG_CMD_EFFECTS: - return nvme_cmd_effects(n, len, off, req); + return nvme_cmd_effects(n, csi, len, off, req); default: trace_pci_nvme_err_invalid_log_page(nvme_cid(req), lid); return NVME_INVALID_FIELD | NVME_DNR; @@ -1677,6 +1685,13 @@ static uint16_t nvme_create_cq(NvmeCtrl *n, NvmeRequ= est *req) return NVME_SUCCESS; } =20 +static uint16_t nvme_rpt_empty_id_struct(NvmeCtrl *n, NvmeRequest *req) +{ + uint8_t id[NVME_IDENTIFY_DATA_SIZE] =3D {}; + + return nvme_dma(n, id, sizeof(id), DMA_DIRECTION_FROM_DEVICE, req); +} + static uint16_t nvme_identify_ctrl(NvmeCtrl *n, NvmeRequest *req) { trace_pci_nvme_identify_ctrl(); @@ -1685,11 +1700,23 @@ static uint16_t nvme_identify_ctrl(NvmeCtrl *n, Nvm= eRequest *req) DMA_DIRECTION_FROM_DEVICE, req); } =20 +static uint16_t nvme_identify_ctrl_csi(NvmeCtrl *n, NvmeRequest *req) +{ + NvmeIdentify *c =3D (NvmeIdentify *)&req->cmd; + + trace_pci_nvme_identify_ctrl_csi(c->csi); + + if (c->csi =3D=3D NVME_CSI_NVM) { + return nvme_rpt_empty_id_struct(n, req); + } + + return NVME_INVALID_FIELD | NVME_DNR; +} + static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeRequest *req) { NvmeNamespace *ns; NvmeIdentify *c =3D (NvmeIdentify *)&req->cmd; - NvmeIdNs *id_ns, inactive =3D { 0 }; uint32_t nsid =3D le32_to_cpu(c->nsid); =20 trace_pci_nvme_identify_ns(nsid); @@ -1700,23 +1727,46 @@ static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeR= equest *req) =20 ns =3D nvme_ns(n, nsid); if (unlikely(!ns)) { - id_ns =3D &inactive; - } else { - id_ns =3D &ns->id_ns; + return nvme_rpt_empty_id_struct(n, req); } =20 - return nvme_dma(n, (uint8_t *)id_ns, sizeof(NvmeIdNs), + return nvme_dma(n, (uint8_t *)&ns->id_ns, sizeof(NvmeIdNs), DMA_DIRECTION_FROM_DEVICE, req); } =20 +static uint16_t nvme_identify_ns_csi(NvmeCtrl *n, NvmeRequest *req) +{ + NvmeNamespace *ns; + NvmeIdentify *c =3D (NvmeIdentify *)&req->cmd; + uint32_t nsid =3D le32_to_cpu(c->nsid); + + trace_pci_nvme_identify_ns_csi(nsid, c->csi); + + if (!nvme_nsid_valid(n, nsid) || nsid =3D=3D NVME_NSID_BROADCAST) { + return NVME_INVALID_NSID | NVME_DNR; + } + + ns =3D nvme_ns(n, nsid); + if (unlikely(!ns)) { + return nvme_rpt_empty_id_struct(n, req); + } + + if (c->csi =3D=3D NVME_CSI_NVM) { + return nvme_rpt_empty_id_struct(n, req); + } + + return NVME_INVALID_FIELD | NVME_DNR; +} + static uint16_t nvme_identify_nslist(NvmeCtrl *n, NvmeRequest *req) { + NvmeNamespace *ns; NvmeIdentify *c =3D (NvmeIdentify *)&req->cmd; - static const int data_len =3D NVME_IDENTIFY_DATA_SIZE; uint32_t min_nsid =3D le32_to_cpu(c->nsid); - uint32_t *list; - uint16_t ret; - int j =3D 0; + uint8_t list[NVME_IDENTIFY_DATA_SIZE] =3D {}; + static const int data_len =3D sizeof(list); + uint32_t *list_ptr =3D (uint32_t *)list; + int i, j =3D 0; =20 trace_pci_nvme_identify_nslist(min_nsid); =20 @@ -1730,20 +1780,61 @@ static uint16_t nvme_identify_nslist(NvmeCtrl *n, N= vmeRequest *req) return NVME_INVALID_NSID | NVME_DNR; } =20 - list =3D g_malloc0(data_len); - for (int i =3D 1; i <=3D n->num_namespaces; i++) { - if (i <=3D min_nsid || !nvme_ns(n, i)) { + for (i =3D 1; i <=3D n->num_namespaces; i++) { + ns =3D nvme_ns(n, i); + if (!ns) { continue; } - list[j++] =3D cpu_to_le32(i); + if (ns->params.nsid <=3D min_nsid) { + continue; + } + list_ptr[j++] =3D cpu_to_le32(ns->params.nsid); if (j =3D=3D data_len / sizeof(uint32_t)) { break; } } - ret =3D nvme_dma(n, (uint8_t *)list, data_len, DMA_DIRECTION_FROM_DEVI= CE, - req); - g_free(list); - return ret; + + return nvme_dma(n, list, data_len, DMA_DIRECTION_FROM_DEVICE, req); +} + +static uint16_t nvme_identify_nslist_csi(NvmeCtrl *n, NvmeRequest *req) +{ + NvmeNamespace *ns; + NvmeIdentify *c =3D (NvmeIdentify *)&req->cmd; + uint32_t min_nsid =3D le32_to_cpu(c->nsid); + uint8_t list[NVME_IDENTIFY_DATA_SIZE] =3D {}; + static const int data_len =3D sizeof(list); + uint32_t *list_ptr =3D (uint32_t *)list; + int i, j =3D 0; + + trace_pci_nvme_identify_nslist_csi(min_nsid, c->csi); + + /* + * Same as in nvme_identify_nslist(), 0xffffffff/0xfffffffe are invali= d. + */ + if (min_nsid >=3D NVME_NSID_BROADCAST - 1) { + return NVME_INVALID_NSID | NVME_DNR; + } + + if (c->csi !=3D NVME_CSI_NVM) { + return NVME_INVALID_FIELD | NVME_DNR; + } + + for (i =3D 1; i <=3D n->num_namespaces; i++) { + ns =3D nvme_ns(n, i); + if (!ns) { + continue; + } + if (ns->params.nsid <=3D min_nsid) { + continue; + } + list_ptr[j++] =3D cpu_to_le32(ns->params.nsid); + if (j =3D=3D data_len / sizeof(uint32_t)) { + break; + } + } + + return nvme_dma(n, list, data_len, DMA_DIRECTION_FROM_DEVICE, req); } =20 static uint16_t nvme_identify_ns_descr_list(NvmeCtrl *n, NvmeRequest *req) @@ -1751,13 +1842,17 @@ static uint16_t nvme_identify_ns_descr_list(NvmeCtr= l *n, NvmeRequest *req) NvmeNamespace *ns; NvmeIdentify *c =3D (NvmeIdentify *)&req->cmd; uint32_t nsid =3D le32_to_cpu(c->nsid); - uint8_t list[NVME_IDENTIFY_DATA_SIZE]; + uint8_t list[NVME_IDENTIFY_DATA_SIZE] =3D {}; =20 struct data { struct { NvmeIdNsDescr hdr; - uint8_t v[16]; + uint8_t v[NVME_NIDL_UUID]; } uuid; + struct { + NvmeIdNsDescr hdr; + uint8_t v; + } csi; }; =20 struct data *ns_descrs =3D (struct data *)list; @@ -1773,19 +1868,31 @@ static uint16_t nvme_identify_ns_descr_list(NvmeCtr= l *n, NvmeRequest *req) return NVME_INVALID_FIELD | NVME_DNR; } =20 - memset(list, 0x0, sizeof(list)); - /* * Because the NGUID and EUI64 fields are 0 in the Identify Namespace = data * structure, a Namespace UUID (nidt =3D 0x3) must be reported in the * Namespace Identification Descriptor. Add the namespace UUID here. */ ns_descrs->uuid.hdr.nidt =3D NVME_NIDT_UUID; - ns_descrs->uuid.hdr.nidl =3D NVME_NIDT_UUID_LEN; - memcpy(&ns_descrs->uuid.v, ns->params.uuid.data, NVME_NIDT_UUID_LEN); + ns_descrs->uuid.hdr.nidl =3D NVME_NIDL_UUID; + memcpy(&ns_descrs->uuid.v, ns->params.uuid.data, NVME_NIDL_UUID); =20 - return nvme_dma(n, list, NVME_IDENTIFY_DATA_SIZE, - DMA_DIRECTION_FROM_DEVICE, req); + ns_descrs->csi.hdr.nidt =3D NVME_NIDT_CSI; + ns_descrs->csi.hdr.nidl =3D NVME_NIDL_CSI; + ns_descrs->csi.v =3D ns->csi; + + return nvme_dma(n, list, sizeof(list), DMA_DIRECTION_FROM_DEVICE, req); +} + +static uint16_t nvme_identify_cmd_set(NvmeCtrl *n, NvmeRequest *req) +{ + uint8_t list[NVME_IDENTIFY_DATA_SIZE] =3D {}; + static const int data_len =3D sizeof(list); + + trace_pci_nvme_identify_cmd_set(); + + NVME_SET_CSI(*list, NVME_CSI_NVM); + return nvme_dma(n, list, data_len, DMA_DIRECTION_FROM_DEVICE, req); } =20 static uint16_t nvme_identify(NvmeCtrl *n, NvmeRequest *req) @@ -1795,12 +1902,20 @@ static uint16_t nvme_identify(NvmeCtrl *n, NvmeRequ= est *req) switch (le32_to_cpu(c->cns)) { case NVME_ID_CNS_NS: return nvme_identify_ns(n, req); + case NVME_ID_CNS_CS_NS: + 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: return nvme_identify_nslist(n, req); + case NVME_ID_CNS_CS_NS_ACTIVE_LIST: + return nvme_identify_nslist_csi(n, req); case NVME_ID_CNS_NS_DESCR_LIST: return nvme_identify_ns_descr_list(n, req); + case NVME_ID_CNS_IO_COMMAND_SET: + return nvme_identify_cmd_set(n, req); default: trace_pci_nvme_err_invalid_identify_cns(le32_to_cpu(c->cns)); return NVME_INVALID_FIELD | NVME_DNR; @@ -1994,7 +2109,9 @@ defaults: if (iv =3D=3D n->admin_cq.vector) { result |=3D NVME_INTVC_NOCOALESCING; } - + break; + case NVME_COMMAND_SET_PROFILE: + result =3D 0; break; default: result =3D nvme_feature_default[fid]; @@ -2156,6 +2273,12 @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeRe= quest *req) break; case NVME_TIMESTAMP: return nvme_set_feature_timestamp(n, req); + case NVME_COMMAND_SET_PROFILE: + if (dw11 & 0x1ff) { + trace_pci_nvme_err_invalid_iocsci(dw11 & 0x1ff); + return NVME_CMD_SET_CMB_REJECTED | NVME_DNR; + } + break; default: return NVME_FEAT_NOT_CHANGEABLE | NVME_DNR; } @@ -2324,8 +2447,12 @@ static void nvme_select_ns_iocs(NvmeCtrl *n) continue; } ns->iocs =3D nvme_cse_iocs_none; - if (NVME_CC_CSS(n->bar.cc) !=3D NVME_CC_CSS_ADMIN_ONLY) { - ns->iocs =3D nvme_cse_iocs_nvm; + switch (ns->csi) { + case NVME_CSI_NVM: + if (NVME_CC_CSS(n->bar.cc) !=3D NVME_CC_CSS_ADMIN_ONLY) { + ns->iocs =3D nvme_cse_iocs_nvm; + } + break; } } } @@ -3066,6 +3193,7 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pc= i_dev) NVME_CAP_SET_CQR(n->bar.cap, 1); NVME_CAP_SET_TO(n->bar.cap, 0xf); NVME_CAP_SET_CSS(n->bar.cap, NVME_CAP_CSS_NVM); + NVME_CAP_SET_CSS(n->bar.cap, NVME_CAP_CSS_CSI_SUPP); NVME_CAP_SET_CSS(n->bar.cap, NVME_CAP_CSS_ADMIN_ONLY); NVME_CAP_SET_MPSMAX(n->bar.cap, 4); =20 diff --git a/hw/block/trace-events b/hw/block/trace-events index 22e0108c9d..8b697664d3 100644 --- a/hw/block/trace-events +++ b/hw/block/trace-events @@ -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=3D%"PRIu16"" pci_nvme_del_cq(uint16_t cqid) "deleted completion queue, cqid=3D%"PRIu16"" pci_nvme_identify_ctrl(void) "identify controller" +pci_nvme_identify_ctrl_csi(uint8_t csi) "identify controller, csi=3D0x%"PR= Ix8"" pci_nvme_identify_ns(uint32_t ns) "nsid %"PRIu32"" +pci_nvme_identify_ns_csi(uint32_t ns, uint8_t csi) "nsid=3D%"PRIu32", csi= =3D0x%"PRIx8"" pci_nvme_identify_nslist(uint32_t ns) "nsid %"PRIu32"" +pci_nvme_identify_nslist_csi(uint16_t ns, uint8_t csi) "nsid=3D%"PRIu16", = csi=3D0x%"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, uint= 32_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, ui= nt32_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 0= x%"PRIx8"" pci_nvme_err_invalid_admin_opc(uint8_t opc) "invalid admin opcode 0x%"PRIx= 8"" pci_nvme_err_invalid_lba_range(uint64_t start, uint64_t len, uint64_t limi= t) "Invalid LBA start=3D%"PRIu64" len=3D%"PRIu64" limit=3D%"PRIu64"" pci_nvme_err_invalid_log_page_offset(uint64_t ofs, uint64_t size) "must be= <=3D %"PRIu64", got %"PRIu64"" +pci_nvme_err_invalid_iocsci(uint32_t idx) "unsupported command set combina= tion index %"PRIu32"" pci_nvme_err_invalid_del_sq(uint16_t qid) "invalid submission queue deleti= on, sid=3D%"PRIu16"" pci_nvme_err_invalid_create_sq_cqid(uint16_t cqid) "failed creating submis= sion queue, invalid cqid=3D%"PRIu16"" pci_nvme_err_invalid_create_sq_sqid(uint16_t sqid) "failed creating submis= sion queue, invalid sqid=3D%"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) "complet= ion queue doorbell write value beyond queue size, cqid=3D%"PRIu32", new_hea= d=3D%"PRIu16", ignoring" pci_nvme_ub_db_wr_invalid_sq(uint32_t qid) "submission queue doorbell writ= e for nonexistent queue, sqid=3D%"PRIu32", ignoring" pci_nvme_ub_db_wr_invalid_sqtail(uint32_t qid, uint16_t new_tail) "submiss= ion queue doorbell write value beyond queue size, sqid=3D%"PRIu32", new_hea= d=3D%"PRIu16", ignoring" +pci_nvme_ub_unknown_css_value(void) "unknown value in cc.css field" =20 # xen-block.c xen_block_realize(const char *type, uint32_t disk, uint32_t partition) "%s= d%up%u" --=20 2.28.0 From nobody Fri May 10 12:23:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1607462703; cv=none; d=zohomail.com; s=zohoarc; b=Q8v1FNJ+lsr9jJJIoRsdpO6WSAnSLq2+HMorqP9Ma9TsMd2bKhz391RKjrbn2aGl11oIg3D0v90Jkcw1/96ZucclrnPjb9kqa0r3yo+LwkNvFJ7WKWli8Yr09ThCYnmFJXT0g5/LG+kihjuwB7e9oTf9uR53dl4BeV9Bdwo8fz8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607462703; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MA0R6ay+FcfepK3djo7GOrfbr+j7mZwJKqLPRQ4jxNM=; b=FlhvSV8FdD4f55yqCnf9R1tvuP8Mg4asGWg4IN+zNpn1LmBM1m3M7s7+f/azgm2j4biVvRj3e6WzhG9XSZGkG9t6I26zhWs1LxHK+bdUGv9VKGLuU8jhPa6+NJTjx04Z0M5RrAtE+mxxCEUwYpT9qXay09fZE48dVts+gYGA6xc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1607462703625676.7613069466237; Tue, 8 Dec 2020 13:25:03 -0800 (PST) Received: from localhost ([::1]:56438 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmkAL-0007qK-Ih for importer@patchew.org; Tue, 08 Dec 2020 16:04:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjDx-0002R0-RK; Tue, 08 Dec 2020 15:04:37 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:42896) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjDv-000629-Iv; Tue, 08 Dec 2020 15:04:37 -0500 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Dec 2020 04:20:40 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2020 11:48:30 -0800 Received: from unknown (HELO redsun50.ssa.fujisawa.hgst.com) ([10.149.66.24]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Dec 2020 12:04:28 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1607458849; x=1638994849; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7zkUdrCfjJq4A0ejq53u0yiqE5z8aP+1Lipkloowanw=; b=rF4c9GXZdcG1w2UAIkeLxnOin3KXTYAA1b+okyuxfB7end+qU+cMwgD7 5ToUnP6NVwi9tk5XrkmRILVWXA9MigI6x0HAfZUNk8mJVE8VwrrJoQ6xm GyyKj4o8AzBzz9pV0QdvTcd1eBT9PhAjxOrxKzuUnhsQ0+tZWm/nwnjfH eLFe+qx5EXIgoRMk4g7KrY1v6CZ+bcQ5b51kjKklfJN4HXElEe5jhJ/Eo hOad5t39tRM8T360QSnVRGnSZWfwvSm/se8bodZIs9zCcCLXoUVb0oQE4 +VIr6w6GmsMl8KAOkhTR7fRkJOSwY4RQ/XP60Iaj4uEA2FID6ScV3tcqi Q==; IronPort-SDR: XI3YJkJnygOTsWzJJ5d0kc/TIh4Fzzsh6cLxV3pcuT4E1W+DUtkFXJulDCsfErrXaYHZhImXxd eL9L6GCfqYPM3lhgRUxOlrSjEcceia0OAmWvIohNH5jTsBiWn95Sn6UXBCx2KNxM6AwOtoJDOI Ag0x8Q7n7NwzYYGaMVUvoitLu+q8OIArO6vSrYAdT+kjNy5UYFJWJ+c7jnvJZ94D0p6zFbDWOR E+9m8ReBWuzxEioBUSGGH3rJkGEiGDV6dqu94nHEl3pQ3vjRgG6490qnQiWFHEM1UF7BZW/8Iw TgU= X-IronPort-AV: E=Sophos;i="5.78,403,1599494400"; d="scan'208";a="258433460" IronPort-SDR: ThQHFExGLNtUVcJaIgalxUuYRQdlM5siBYztQ5v1I/QSfxuQ0mSR2P+YlicyPnVB1DvRn38ErN gYECzIZLjL2FTOEzZ336FQ4/F77U+DCk0= IronPort-SDR: R8d887QAVYE6J1eLgZNwbgE8yaa3gAV9hGFwSVbcCJIswSJQYuxE39GEbqW1G3AhlElQ52psYr APZ9r9ZZ228A== WDCIronportException: Internal From: Dmitry Fomichev To: Keith Busch , Klaus Jensen , Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Max Reitz , Maxim Levitsky , Fam Zheng Subject: [PATCH v11 07/13] hw/block/nvme: Support allocated CNS command variants Date: Wed, 9 Dec 2020 05:04:04 +0900 Message-Id: <20201208200410.27900-8-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201208200410.27900-1-dmitry.fomichev@wdc.com> References: <20201208200410.27900-1-dmitry.fomichev@wdc.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=68.232.143.124; envelope-from=prvs=604abd949=dmitry.fomichev@wdc.com; helo=esa2.hgst.iphmx.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Niklas Cassel , Damien Le Moal , qemu-block@nongnu.org, Dmitry Fomichev , qemu-devel@nongnu.org, Alistair Francis , Matias Bjorling Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Niklas Cassel 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. Signed-off-by: Niklas Cassel Signed-off-by: Dmitry Fomichev Reviewed-by: Keith Busch Reviewed-by: Klaus Jensen --- include/block/nvme.h | 20 ++++++++++++-------- hw/block/nvme.c | 8 ++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/include/block/nvme.h b/include/block/nvme.h index 890977db4b..29d826ab19 100644 --- a/include/block/nvme.h +++ b/include/block/nvme.h @@ -807,14 +807,18 @@ typedef struct QEMU_PACKED NvmePSD { #define NVME_IDENTIFY_DATA_SIZE 4096 =20 enum NvmeIdCns { - NVME_ID_CNS_NS =3D 0x00, - NVME_ID_CNS_CTRL =3D 0x01, - NVME_ID_CNS_NS_ACTIVE_LIST =3D 0x02, - NVME_ID_CNS_NS_DESCR_LIST =3D 0x03, - NVME_ID_CNS_CS_NS =3D 0x05, - NVME_ID_CNS_CS_CTRL =3D 0x06, - NVME_ID_CNS_CS_NS_ACTIVE_LIST =3D 0x07, - NVME_ID_CNS_IO_COMMAND_SET =3D 0x1c, + NVME_ID_CNS_NS =3D 0x00, + NVME_ID_CNS_CTRL =3D 0x01, + NVME_ID_CNS_NS_ACTIVE_LIST =3D 0x02, + NVME_ID_CNS_NS_DESCR_LIST =3D 0x03, + NVME_ID_CNS_CS_NS =3D 0x05, + NVME_ID_CNS_CS_CTRL =3D 0x06, + NVME_ID_CNS_CS_NS_ACTIVE_LIST =3D 0x07, + NVME_ID_CNS_NS_PRESENT_LIST =3D 0x10, + NVME_ID_CNS_NS_PRESENT =3D 0x11, + NVME_ID_CNS_CS_NS_PRESENT_LIST =3D 0x1a, + NVME_ID_CNS_CS_NS_PRESENT =3D 0x1b, + NVME_ID_CNS_IO_COMMAND_SET =3D 0x1c, }; =20 typedef struct QEMU_PACKED NvmeIdCtrl { diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 16eed37533..7035896649 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -1901,16 +1901,24 @@ static uint16_t nvme_identify(NvmeCtrl *n, NvmeRequ= est *req) =20 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); --=20 2.28.0 From nobody Fri May 10 12:23:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1607462794; cv=none; d=zohomail.com; s=zohoarc; b=Apn/TIFCHTc4k38zydW41tsg39rRzi4zBMpr5DgeLtOAGjiZfees7fThUfWn7ebdD91JN9eailUJcvHK4mCQYSLMI1EnpkcsnrURTKWXKWxH4fyp6rKfK6TwZT1QcmxX2YCsYjjIrvbFt4F5pfWNkdjjdy459vpzX/Ch/ssRMUo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607462794; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0V9Y7DavBKQm1yWNBZwgRemf9TJCaHF0jPjwHg9CEcc=; b=j5Vrq8f49mno5dTWMqS0llN2ZEWrMBUuZhvwGHBcnFxDpceEu1pLSsl69zs/4uiCVH+wqjL9GG38bQzWGojPJyRhvzmVfLTXzOk3fdlfr++z7PPHPc9LaDC4eFX9Xo6LeuT/M+PS73g/b1iqMxIzt+46+8Xj1orEeGSpJXJr/pU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1607462794691488.69169593644506; Tue, 8 Dec 2020 13:26:34 -0800 (PST) Received: from localhost ([::1]:36792 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmkDm-000380-W4 for importer@patchew.org; Tue, 08 Dec 2020 16:08:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjE0-0002Sg-19; Tue, 08 Dec 2020 15:04:41 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:42903) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjDw-00062i-V3; Tue, 08 Dec 2020 15:04:39 -0500 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Dec 2020 04:20:44 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2020 11:48:32 -0800 Received: from unknown (HELO redsun50.ssa.fujisawa.hgst.com) ([10.149.66.24]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Dec 2020 12:04:31 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1607458851; x=1638994851; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yECLRmoQrfOVSBLC5ZL4ZWs46Z8eo1EYdx7ccsy96A4=; b=EG3Nvwr/0Ck4kWcs39NTKpSuqn9lkcjg53hahG045qGyPGBLidLZGxXX nYKehrJkqFvt9grFVIi6CfLnpowlL/fMYCq2iwkSVyhGf4w0P7/ji0tuO uI2a+5avyBxcNaLip+eZpTZ946CwrzHz/Dg4aIAU7PDGpZr60VcMqHzh2 4dyhHsyIt6tPeYLdjwXaS38IMhqnZRjjbZbwxlnIDTqWjSnfNlrxjlmyZ qLU8gX5irrQJtUKZOnK6E3Cj2c/EEuAxd8RtcOcWnIfmyO48TNeS/km9b a8wjy7xTZ+y2zU+kBAtp/68HqRe5TqvOHguWLe6RjM5BobD4hs3+SgX4k g==; IronPort-SDR: AcSalXwo8tkjAF60hDqLOjMr1FtTIKkLWWirN7ZI+6ysbgs7mNVGmaYcCTPtP1t5Ok9AX44vBS pHuhGZjY6jO/bmvptoNro3DMhZK4IwAa8NumVLTGGhHyXVT2icTQXc2wVB2lOrRaJbuxv3rxlq yBgMmASYOf9y7GT1+btMrsXopiYgFQ589UA4oeCx8hO0QdPBu0T0kmCm7VNu1EI5/ztiyp+ups cRPwdBVY9KY0ADwCLANTBdM7EUFDVAtU9yLcU/6hOuqcAFxsSG0K/n2+nxyl2FHz9IG92OEBOW LRE= X-IronPort-AV: E=Sophos;i="5.78,403,1599494400"; d="scan'208";a="258433462" IronPort-SDR: dIblBzoSG9i+Ou1UxeYIsyYktME3NlHgGeujd+Ly3lKhgwdfI3qx79O1+iFVx7fTFo+HQ9AgGk HKHmq/JdQFkPXzTDhoRuTuzau0R5e5beA= IronPort-SDR: 6DSh740VjKYsHfiaW7Dm1OmdOB+VD5FFWExEaqVVVUQIDSOurAAcm8e50khweVFZIant2ISBb4 oPuzomyR8uOA== WDCIronportException: Internal From: Dmitry Fomichev To: Keith Busch , Klaus Jensen , Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Max Reitz , Maxim Levitsky , Fam Zheng Subject: [PATCH v11 08/13] block/nvme: Make ZNS-related definitions Date: Wed, 9 Dec 2020 05:04:05 +0900 Message-Id: <20201208200410.27900-9-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201208200410.27900-1-dmitry.fomichev@wdc.com> References: <20201208200410.27900-1-dmitry.fomichev@wdc.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=68.232.143.124; envelope-from=prvs=604abd949=dmitry.fomichev@wdc.com; helo=esa2.hgst.iphmx.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Niklas Cassel , Damien Le Moal , qemu-block@nongnu.org, Dmitry Fomichev , qemu-devel@nongnu.org, Alistair Francis , Matias Bjorling Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Define values and structures that are needed to support Zoned Namespace Command Set (NVMe TP 4053). Signed-off-by: Dmitry Fomichev Reviewed-by: Keith Busch Reviewed-by: Klaus Jensen --- include/block/nvme.h | 114 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-) diff --git a/include/block/nvme.h b/include/block/nvme.h index 29d826ab19..a9165402d6 100644 --- a/include/block/nvme.h +++ b/include/block/nvme.h @@ -489,6 +489,9 @@ enum NvmeIoCommands { NVME_CMD_COMPARE =3D 0x05, NVME_CMD_WRITE_ZEROES =3D 0x08, NVME_CMD_DSM =3D 0x09, + NVME_CMD_ZONE_MGMT_SEND =3D 0x79, + NVME_CMD_ZONE_MGMT_RECV =3D 0x7a, + NVME_CMD_ZONE_APPEND =3D 0x7d, }; =20 typedef struct QEMU_PACKED NvmeDeleteQ { @@ -648,9 +651,13 @@ typedef struct QEMU_PACKED NvmeAerResult { uint8_t resv; } NvmeAerResult; =20 +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 =3D 0x0012, NVME_INVALID_PRP_OFFSET =3D 0x0013, NVME_CMD_SET_CMB_REJECTED =3D 0x002b, + NVME_INVALID_CMD_SET =3D 0x002c, NVME_LBA_RANGE =3D 0x0080, NVME_CAP_EXCEEDED =3D 0x0081, NVME_NS_NOT_READY =3D 0x0082, @@ -703,6 +711,14 @@ enum NvmeStatusCodes { NVME_CONFLICTING_ATTRS =3D 0x0180, NVME_INVALID_PROT_INFO =3D 0x0181, NVME_WRITE_TO_RO =3D 0x0182, + NVME_ZONE_BOUNDARY_ERROR =3D 0x01b8, + NVME_ZONE_FULL =3D 0x01b9, + NVME_ZONE_READ_ONLY =3D 0x01ba, + NVME_ZONE_OFFLINE =3D 0x01bb, + NVME_ZONE_INVALID_WRITE =3D 0x01bc, + NVME_ZONE_TOO_MANY_ACTIVE =3D 0x01bd, + NVME_ZONE_TOO_MANY_OPEN =3D 0x01be, + NVME_ZONE_INVAL_TRANSITION =3D 0x01bf, NVME_WRITE_FAULT =3D 0x0280, NVME_UNRECOVERED_READ =3D 0x0281, NVME_E2E_GUARD_ERROR =3D 0x0282, @@ -888,6 +904,11 @@ typedef struct QEMU_PACKED NvmeIdCtrl { uint8_t vs[1024]; } NvmeIdCtrl; =20 +typedef struct NvmeIdCtrlZoned { + uint8_t zasl; + uint8_t rsvd1[4095]; +} NvmeIdCtrlZoned; + enum NvmeIdCtrlOacs { NVME_OACS_SECURITY =3D 1 << 0, NVME_OACS_FORMAT =3D 1 << 1, @@ -1016,6 +1037,12 @@ typedef struct QEMU_PACKED NvmeLBAF { uint8_t rp; } NvmeLBAF; =20 +typedef struct QEMU_PACKED NvmeLBAFE { + uint64_t zsze; + uint8_t zdes; + uint8_t rsvd9[7]; +} NvmeLBAFE; + #define NVME_NSID_BROADCAST 0xffffffff =20 typedef struct QEMU_PACKED NvmeIdNs { @@ -1075,10 +1102,24 @@ enum NvmeNsIdentifierType { =20 enum NvmeCsi { NVME_CSI_NVM =3D 0x00, + NVME_CSI_ZONED =3D 0x02, }; =20 #define NVME_SET_CSI(vec, csi) (vec |=3D (uint8_t)(1 << (csi))) =20 +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 =3D 8, }; =20 +enum NvmeZoneAttr { + NVME_ZA_FINISHED_BY_CTLR =3D 1 << 0, + NVME_ZA_FINISH_RECOMMENDED =3D 1 << 1, + NVME_ZA_RESET_RECOMMENDED =3D 1 << 2, + NVME_ZA_ZD_EXT_VALID =3D 1 << 7, +}; + +typedef struct QEMU_PACKED NvmeZoneReportHeader { + uint64_t nr_zones; + uint8_t rsvd[56]; +} NvmeZoneReportHeader; + +enum NvmeZoneReceiveAction { + NVME_ZONE_REPORT =3D 0, + NVME_ZONE_REPORT_EXTENDED =3D 1, +}; + +enum NvmeZoneReportType { + NVME_ZONE_REPORT_ALL =3D 0, + NVME_ZONE_REPORT_EMPTY =3D 1, + NVME_ZONE_REPORT_IMPLICITLY_OPEN =3D 2, + NVME_ZONE_REPORT_EXPLICITLY_OPEN =3D 3, + NVME_ZONE_REPORT_CLOSED =3D 4, + NVME_ZONE_REPORT_FULL =3D 5, + NVME_ZONE_REPORT_READ_ONLY =3D 6, + NVME_ZONE_REPORT_OFFLINE =3D 7, +}; + +enum NvmeZoneType { + NVME_ZONE_TYPE_RESERVED =3D 0x00, + NVME_ZONE_TYPE_SEQ_WRITE =3D 0x02, +}; + +enum NvmeZoneSendAction { + NVME_ZONE_ACTION_RSD =3D 0x00, + NVME_ZONE_ACTION_CLOSE =3D 0x01, + NVME_ZONE_ACTION_FINISH =3D 0x02, + NVME_ZONE_ACTION_OPEN =3D 0x03, + NVME_ZONE_ACTION_RESET =3D 0x04, + NVME_ZONE_ACTION_OFFLINE =3D 0x05, + NVME_ZONE_ACTION_SET_ZD_EXT =3D 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 =3D 0x00, + NVME_ZONE_STATE_EMPTY =3D 0x01, + NVME_ZONE_STATE_IMPLICITLY_OPEN =3D 0x02, + NVME_ZONE_STATE_EXPLICITLY_OPEN =3D 0x03, + NVME_ZONE_STATE_CLOSED =3D 0x04, + NVME_ZONE_STATE_READ_ONLY =3D 0x0D, + NVME_ZONE_STATE_FULL =3D 0x0E, + NVME_ZONE_STATE_OFFLINE =3D 0x0F, +}; + static inline void _nvme_check_size(void) { QEMU_BUILD_BUG_ON(sizeof(NvmeBar) !=3D 4096); QEMU_BUILD_BUG_ON(sizeof(NvmeAerResult) !=3D 4); + QEMU_BUILD_BUG_ON(sizeof(NvmeZonedResult) !=3D 8); QEMU_BUILD_BUG_ON(sizeof(NvmeCqe) !=3D 16); QEMU_BUILD_BUG_ON(sizeof(NvmeDsmRange) !=3D 16); QEMU_BUILD_BUG_ON(sizeof(NvmeCmd) !=3D 64); @@ -1130,8 +1237,13 @@ static inline void _nvme_check_size(void) QEMU_BUILD_BUG_ON(sizeof(NvmeSmartLog) !=3D 512); QEMU_BUILD_BUG_ON(sizeof(NvmeEffectsLog) !=3D 4096); QEMU_BUILD_BUG_ON(sizeof(NvmeIdCtrl) !=3D 4096); + QEMU_BUILD_BUG_ON(sizeof(NvmeIdCtrlZoned) !=3D 4096); + QEMU_BUILD_BUG_ON(sizeof(NvmeLBAF) !=3D 4); + QEMU_BUILD_BUG_ON(sizeof(NvmeLBAFE) !=3D 16); QEMU_BUILD_BUG_ON(sizeof(NvmeIdNs) !=3D 4096); + QEMU_BUILD_BUG_ON(sizeof(NvmeIdNsZoned) !=3D 4096); QEMU_BUILD_BUG_ON(sizeof(NvmeSglDescriptor) !=3D 16); QEMU_BUILD_BUG_ON(sizeof(NvmeIdNsDescr) !=3D 4); + QEMU_BUILD_BUG_ON(sizeof(NvmeZoneDescr) !=3D 64); } #endif --=20 2.28.0 From nobody Fri May 10 12:23:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1607462886; cv=none; d=zohomail.com; s=zohoarc; b=XblYE45D0+Hd8zUq3wpgcpIGxu7QGerqW+4ogTc+Rn3KpVI60HT6Pgnq9x7mxg/3uEbjem3bBaimFxrMExKY7KHSbPglP0CXmTSorp+oICeLyg9MvX0op7moqkMrRV+LLLlM1kliJ6WdJHUrJgN2nuQmrlpb+SfeBvOlr3bjAlQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607462886; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FBtGWBKmIXu9mf5QPUvjXVX2eiOfCfkj4MhXIGIEPTU=; b=ColFEEjx+9rxKuY56DzfvE6na3SeLYJ4XdM4+Ikbtqs/fOvh4a5g+AGdsJxmO7qBEplR5kgRG5k95RrzZiy6IX0oUEfflyjvYKyYgSIVH6ddS8D6XUFxET6ufng3rzsO0XiKz4JaQyc1uqBs4NLl0niLpToUoSw2C36nkMdwhMU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1607462886870902.7459980106981; Tue, 8 Dec 2020 13:28:06 -0800 (PST) Received: from localhost ([::1]:49526 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmkWj-00041b-Hv for importer@patchew.org; Tue, 08 Dec 2020 16:28:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56368) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjE7-0002Wf-DQ; Tue, 08 Dec 2020 15:04:49 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:42896) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjDy-000629-J9; Tue, 08 Dec 2020 15:04:45 -0500 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Dec 2020 04:20:48 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2020 11:48:35 -0800 Received: from unknown (HELO redsun50.ssa.fujisawa.hgst.com) ([10.149.66.24]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Dec 2020 12:04:33 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1607458853; x=1638994853; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XnyM6+sxvIWPlGEelMVKlxPxs9R4pnXdxRqQH4iQh/c=; b=lp/1mB54YWIwm0Wn/TF3ioCLNtSAURnakgRIO2l00v//oUz3h/Jtvwc2 5vqOp7U1lihmyGSxucYW19Y1ecNdq7CgMSyF8YHcDhujC5RDX8a2UQzLk e35sdhz1/0QXtqrG5VPEm0g8udUavhI28ABqHX/YYdnue3DWybohF0KkY osypTUJgfORe+/z1gp1kEaRBzOM/Dw/o4Lgv6EyXCCWToQr4hMS3jAAgH x5X/ia5IUlgLksddVQEKcIUL0FxYBM9AiRUeI+6HXLxMxR99T+EXW2Oir SpI6A8HPz8M+wYpdKvWQ2QemnyZ/+OxmPMJsNx+aL9nIqd/1tuhzvZlx6 Q==; IronPort-SDR: w1ZxjCWVehdtwK/70Oq579SaNANQdbYoKJkGYBJ+MrpxzjDLnEJcsbYz1yahOu6qQwQM2eYqCn b5HyzcZB7eFMUV6sMme7J37OMX/DpY9TcWkC+7RwOwJipYzk7/xgDoqFPvU5MjpNt1uHvI5DTN NHrM9PGQxzcw+hkQi+unnWY2FT5KUu3hX+C8IZ0S0HbbgrGAGDrNLdhZ4OvLq5xennwzXn/akA jD30aNFsGpx45eb472lnbyf3q1osHthzQ/1ivYrlFXOKsv9+70sxNZ6ORrxsEivoOfHtNc66ve jQc= X-IronPort-AV: E=Sophos;i="5.78,403,1599494400"; d="scan'208";a="258433466" IronPort-SDR: GqafW/AaDXok4ipz04H5igEdY4rIipe0wBlK9zf16rA0qTTjKn4hRxfxW6qrXJkNCzQ9qY+rKC Oe0Hqs/zFAGmTe/5DbyA5BANW4930i6Vs= IronPort-SDR: fXPmjOLdhuw/2ZaT6xVbsQs63EH3rUPSlMQUSU187055jsHBRmzp+LKYDwv9vJt7MOhW6CtfNq 9m2/EGYXM6rg== WDCIronportException: Internal From: Dmitry Fomichev To: Keith Busch , Klaus Jensen , Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Max Reitz , Maxim Levitsky , Fam Zheng Subject: [PATCH v11 09/13] hw/block/nvme: Support Zoned Namespace Command Set Date: Wed, 9 Dec 2020 05:04:06 +0900 Message-Id: <20201208200410.27900-10-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201208200410.27900-1-dmitry.fomichev@wdc.com> References: <20201208200410.27900-1-dmitry.fomichev@wdc.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=68.232.143.124; envelope-from=prvs=604abd949=dmitry.fomichev@wdc.com; helo=esa2.hgst.iphmx.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Niklas Cassel , Damien Le Moal , qemu-block@nongnu.org, Dmitry Fomichev , qemu-devel@nongnu.org, Alistair Francis , Matias Bjorling Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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. 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. 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 Reviewed-by: Niklas Cassel Reviewed-by: Keith Busch Reviewed-by: Klaus Jensen --- 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(-) diff --git a/hw/block/nvme-ns.h b/hw/block/nvme-ns.h index bdbc98c2ec..388381dda0 100644 --- a/hw/block/nvme-ns.h +++ b/hw/block/nvme-ns.h @@ -19,9 +19,20 @@ #define NVME_NS(obj) \ OBJECT_CHECK(NvmeNamespace, (obj), TYPE_NVME_NS) =20 +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; =20 typedef struct NvmeNamespace { @@ -33,6 +44,17 @@ typedef struct NvmeNamespace { const uint32_t *iocs; uint8_t csi; =20 + 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; =20 struct { @@ -74,8 +96,38 @@ static inline size_t nvme_l2b(NvmeNamespace *ns, uint64_= t lba) =20 typedef struct NvmeCtrl NvmeCtrl; =20 +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 =3D 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 =3D nvme_get_zone_state(zone); + + return st !=3D NVME_ZONE_STATE_FULL && + st !=3D NVME_ZONE_STATE_READ_ONLY && + st !=3D 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); =20 #endif /* NVME_NS_H */ diff --git a/hw/block/nvme.h b/hw/block/nvme.h index 574333caa3..b7fbcca39d 100644 --- a/hw/block/nvme.h +++ b/hw/block/nvme.h @@ -6,6 +6,9 @@ =20 #define NVME_MAX_NAMESPACES 256 =20 +#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; =20 typedef struct NvmeAsyncEvent { @@ -149,6 +153,8 @@ typedef struct NvmeCtrl { QTAILQ_HEAD(, NvmeAsyncEvent) aer_queue; int aer_queued; =20 + uint8_t zasl; + NvmeNamespace namespace; NvmeNamespace *namespaces[NVME_MAX_NAMESPACES]; NvmeSQueue **sq; diff --git a/hw/block/nvme-ns.c b/hw/block/nvme-ns.c index 961cc81923..1df45bbe35 100644 --- a/hw/block/nvme-ns.c +++ b/hw/block/nvme-ns.c @@ -25,6 +25,7 @@ #include "hw/qdev-properties.h" #include "hw/qdev-core.h" =20 +#include "trace.h" #include "nvme.h" #include "nvme-ns.h" =20 @@ -96,6 +97,147 @@ static int nvme_ns_init_blk(NvmeCtrl *n, NvmeNamespace = *ns, Error **errp) return 0; } =20 +static int nvme_ns_zoned_check_calc_geometry(NvmeNamespace *ns, Error **er= rp) +{ + uint64_t zone_size, zone_cap; + uint32_t lbasz =3D ns->blkconf.logical_block_size; + + /* Make sure that the values of ZNS properties are sane */ + if (ns->params.zone_size_bs) { + zone_size =3D ns->params.zone_size_bs; + } else { + zone_size =3D NVME_DEFAULT_ZONE_SIZE; + } + if (ns->params.zone_cap_bs) { + zone_cap =3D ns->params.zone_cap_bs; + } else { + zone_cap =3D zone_size; + } + if (zone_cap > zone_size) { + error_setg(errp, "zone capacity %luB exceeds zone size %luB", + zone_cap, zone_size); + return -1; + } + if (zone_size < lbasz) { + error_setg(errp, "zone size %luB too small, must be at least %uB", + zone_size, lbasz); + return -1; + } + if (zone_cap < lbasz) { + error_setg(errp, "zone capacity %luB too small, must be at least %= uB", + zone_cap, lbasz); + return -1; + } + + /* + * Save the main zone geometry values to avoid + * calculating them later again. + */ + ns->zone_size =3D zone_size / lbasz; + ns->zone_capacity =3D zone_cap / lbasz; + ns->num_zones =3D ns->size / lbasz / ns->zone_size; + return 0; +} + +static void nvme_ns_zoned_init_state(NvmeNamespace *ns) +{ + uint64_t start =3D 0, zone_size =3D ns->zone_size; + uint64_t capacity =3D ns->num_zones * zone_size; + NvmeZone *zone; + int i; + + ns->zone_array =3D g_new0(NvmeZone, ns->num_zones); + + QTAILQ_INIT(&ns->exp_open_zones); + QTAILQ_INIT(&ns->imp_open_zones); + QTAILQ_INIT(&ns->closed_zones); + QTAILQ_INIT(&ns->full_zones); + + zone =3D ns->zone_array; + for (i =3D 0; i < ns->num_zones; i++, zone++) { + if (start + zone_size > capacity) { + zone_size =3D capacity - start; + } + zone->d.zt =3D NVME_ZONE_TYPE_SEQ_WRITE; + nvme_set_zone_state(zone, NVME_ZONE_STATE_EMPTY); + zone->d.za =3D 0; + zone->d.zcap =3D ns->zone_capacity; + zone->d.zslba =3D start; + zone->d.wp =3D start; + zone->w_ptr =3D start; + start +=3D zone_size; + } + + ns->zone_size_log2 =3D 0; + if (is_power_of_2(ns->zone_size)) { + ns->zone_size_log2 =3D 63 - clz64(ns->zone_size); + } +} + +static void nvme_ns_init_zoned(NvmeCtrl *n, NvmeNamespace *ns, int lba_ind= ex) +{ + NvmeIdNsZoned *id_ns_z; + + nvme_ns_zoned_init_state(ns); + + id_ns_z =3D g_malloc0(sizeof(NvmeIdNsZoned)); + + /* MAR/MOR are zeroes-based, 0xffffffff means no limit */ + id_ns_z->mar =3D 0xffffffff; + id_ns_z->mor =3D 0xffffffff; + id_ns_z->zoc =3D 0; + id_ns_z->ozcs =3D ns->params.cross_zone_read ? 0x01 : 0x00; + + id_ns_z->lbafe[lba_index].zsze =3D cpu_to_le64(ns->zone_size); + id_ns_z->lbafe[lba_index].zdes =3D 0; + + ns->csi =3D NVME_CSI_ZONED; + ns->id_ns.nsze =3D cpu_to_le64(ns->num_zones * ns->zone_size); + ns->id_ns.ncap =3D ns->id_ns.nsze; + ns->id_ns.nuse =3D ns->id_ns.ncap; + + ns->id_ns_zoned =3D id_ns_z; +} + +static void nvme_clear_zone(NvmeNamespace *ns, NvmeZone *zone) +{ + uint8_t state; + + zone->w_ptr =3D zone->d.wp; + state =3D nvme_get_zone_state(zone); + if (zone->d.wp !=3D zone->d.zslba) { + if (state !=3D NVME_ZONE_STATE_CLOSED) { + trace_pci_nvme_clear_ns_close(state, zone->d.zslba); + nvme_set_zone_state(zone, NVME_ZONE_STATE_CLOSED); + } + QTAILQ_INSERT_HEAD(&ns->closed_zones, zone, entry); + } else { + trace_pci_nvme_clear_ns_reset(state, zone->d.zslba); + nvme_set_zone_state(zone, NVME_ZONE_STATE_EMPTY); + } +} + +/* + * Close all the zones that are currently open. + */ +static void nvme_zoned_ns_shutdown(NvmeNamespace *ns) +{ + NvmeZone *zone, *next; + + QTAILQ_FOREACH_SAFE(zone, &ns->closed_zones, entry, next) { + QTAILQ_REMOVE(&ns->closed_zones, zone, entry); + nvme_clear_zone(ns, zone); + } + QTAILQ_FOREACH_SAFE(zone, &ns->imp_open_zones, entry, next) { + QTAILQ_REMOVE(&ns->imp_open_zones, zone, entry); + nvme_clear_zone(ns, zone); + } + QTAILQ_FOREACH_SAFE(zone, &ns->exp_open_zones, entry, next) { + QTAILQ_REMOVE(&ns->exp_open_zones, zone, entry); + nvme_clear_zone(ns, zone); + } +} + static int nvme_ns_check_constraints(NvmeNamespace *ns, Error **errp) { if (!ns->blkconf.blk) { @@ -119,6 +261,12 @@ int nvme_ns_setup(NvmeCtrl *n, NvmeNamespace *ns, Erro= r **errp) if (nvme_ns_init(ns, errp)) { return -1; } + if (ns->params.zoned) { + if (nvme_ns_zoned_check_calc_geometry(ns, errp) !=3D 0) { + return -1; + } + nvme_ns_init_zoned(n, ns, 0); + } =20 if (nvme_register_namespace(n, ns, errp)) { return -1; @@ -135,6 +283,17 @@ void nvme_ns_drain(NvmeNamespace *ns) void nvme_ns_shutdown(NvmeNamespace *ns) { blk_flush(ns->blkconf.blk); + if (ns->params.zoned) { + nvme_zoned_ns_shutdown(ns); + } +} + +void nvme_ns_cleanup(NvmeNamespace *ns) +{ + if (ns->params.zoned) { + g_free(ns->id_ns_zoned); + g_free(ns->zone_array); + } } =20 static void nvme_ns_realize(DeviceState *dev, Error **errp) @@ -155,6 +314,12 @@ static Property nvme_ns_props[] =3D { DEFINE_BLOCK_PROPERTIES(NvmeNamespace, blkconf), DEFINE_PROP_UINT32("nsid", NvmeNamespace, params.nsid, 0), DEFINE_PROP_UUID("uuid", NvmeNamespace, params.uuid), + DEFINE_PROP_BOOL("zoned", NvmeNamespace, params.zoned, false), + DEFINE_PROP_SIZE("zoned.zsze", NvmeNamespace, params.zone_size_bs, + NVME_DEFAULT_ZONE_SIZE), + 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_END_OF_LIST(), }; =20 diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 7035896649..d1c57cb322 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -134,6 +134,16 @@ static const uint32_t nvme_cse_iocs_nvm[256] =3D { [NVME_CMD_READ] =3D NVME_CMD_EFF_CSUPP, }; =20 +static const uint32_t nvme_cse_iocs_zoned[256] =3D { + [NVME_CMD_FLUSH] =3D NVME_CMD_EFF_CSUPP | NVME_CMD_EFF_= LBCC, + [NVME_CMD_WRITE_ZEROES] =3D NVME_CMD_EFF_CSUPP | NVME_CMD_EFF_= LBCC, + [NVME_CMD_WRITE] =3D NVME_CMD_EFF_CSUPP | NVME_CMD_EFF_= LBCC, + [NVME_CMD_READ] =3D NVME_CMD_EFF_CSUPP, + [NVME_CMD_ZONE_APPEND] =3D NVME_CMD_EFF_CSUPP | NVME_CMD_EFF_= LBCC, + [NVME_CMD_ZONE_MGMT_SEND] =3D NVME_CMD_EFF_CSUPP | NVME_CMD_EFF_= LBCC, + [NVME_CMD_ZONE_MGMT_RECV] =3D NVME_CMD_EFF_CSUPP, +}; + static void nvme_process_sq(void *opaque); =20 static uint16_t nvme_cid(NvmeRequest *req) @@ -150,6 +160,48 @@ static uint16_t nvme_sqid(NvmeRequest *req) return le16_to_cpu(req->sq->sqid); } =20 +static void nvme_assign_zone_state(NvmeNamespace *ns, NvmeZone *zone, + enum NvmeZoneState state) +{ + if (QTAILQ_IN_USE(zone, entry)) { + switch (nvme_get_zone_state(zone)) { + case NVME_ZONE_STATE_EXPLICITLY_OPEN: + QTAILQ_REMOVE(&ns->exp_open_zones, zone, entry); + break; + case NVME_ZONE_STATE_IMPLICITLY_OPEN: + QTAILQ_REMOVE(&ns->imp_open_zones, zone, entry); + break; + case NVME_ZONE_STATE_CLOSED: + QTAILQ_REMOVE(&ns->closed_zones, zone, entry); + break; + case NVME_ZONE_STATE_FULL: + QTAILQ_REMOVE(&ns->full_zones, zone, entry); + default: + ; + } + } + + nvme_set_zone_state(zone, state); + + switch (state) { + case NVME_ZONE_STATE_EXPLICITLY_OPEN: + QTAILQ_INSERT_TAIL(&ns->exp_open_zones, zone, entry); + break; + case NVME_ZONE_STATE_IMPLICITLY_OPEN: + QTAILQ_INSERT_TAIL(&ns->imp_open_zones, zone, entry); + break; + case NVME_ZONE_STATE_CLOSED: + QTAILQ_INSERT_TAIL(&ns->closed_zones, zone, entry); + break; + case NVME_ZONE_STATE_FULL: + QTAILQ_INSERT_TAIL(&ns->full_zones, zone, entry); + case NVME_ZONE_STATE_READ_ONLY: + break; + default: + zone->d.za =3D 0; + } +} + static bool nvme_addr_is_cmb(NvmeCtrl *n, hwaddr addr) { hwaddr low =3D n->ctrl_mem.addr; @@ -944,6 +996,201 @@ static uint16_t nvme_check_dulbe(NvmeNamespace *ns, u= int64_t slba, return NVME_SUCCESS; } =20 +static inline uint32_t nvme_zone_idx(NvmeNamespace *ns, uint64_t slba) +{ + return ns->zone_size_log2 > 0 ? slba >> ns->zone_size_log2 : + slba / ns->zone_size; +} + +static inline NvmeZone *nvme_get_zone_by_slba(NvmeNamespace *ns, uint64_t = slba) +{ + uint32_t zone_idx =3D nvme_zone_idx(ns, slba); + + assert(zone_idx < ns->num_zones); + return &ns->zone_array[zone_idx]; +} + +static uint16_t nvme_check_zone_state_for_write(NvmeZone *zone) +{ + uint16_t status; + + switch (nvme_get_zone_state(zone)) { + case NVME_ZONE_STATE_EMPTY: + case NVME_ZONE_STATE_IMPLICITLY_OPEN: + case NVME_ZONE_STATE_EXPLICITLY_OPEN: + case NVME_ZONE_STATE_CLOSED: + status =3D NVME_SUCCESS; + break; + case NVME_ZONE_STATE_FULL: + status =3D NVME_ZONE_FULL; + break; + case NVME_ZONE_STATE_OFFLINE: + status =3D NVME_ZONE_OFFLINE; + break; + case NVME_ZONE_STATE_READ_ONLY: + status =3D NVME_ZONE_READ_ONLY; + break; + default: + assert(false); + } + + return status; +} + +static uint16_t nvme_check_zone_write(NvmeCtrl *n, NvmeNamespace *ns, + NvmeZone *zone, uint64_t slba, + uint32_t nlb, bool append) +{ + uint16_t status; + + if (unlikely((slba + nlb) > nvme_zone_wr_boundary(zone))) { + status =3D NVME_ZONE_BOUNDARY_ERROR; + } else { + status =3D nvme_check_zone_state_for_write(zone); + } + + if (status !=3D NVME_SUCCESS) { + trace_pci_nvme_err_zone_write_not_ok(slba, nlb, status); + } else { + assert(nvme_wp_is_valid(zone)); + if (append) { + if (unlikely(slba !=3D zone->d.zslba)) { + trace_pci_nvme_err_append_not_at_start(slba, zone->d.zslba= ); + status =3D NVME_ZONE_INVALID_WRITE; + } + if (nvme_l2b(ns, nlb) > (n->page_size << n->zasl)) { + trace_pci_nvme_err_append_too_large(slba, nlb, n->zasl); + status =3D NVME_INVALID_FIELD; + } + } else if (unlikely(slba !=3D zone->w_ptr)) { + trace_pci_nvme_err_write_not_at_wp(slba, zone->d.zslba, + zone->w_ptr); + status =3D NVME_ZONE_INVALID_WRITE; + } + } + + return status; +} + +static uint16_t nvme_check_zone_state_for_read(NvmeZone *zone) +{ + uint16_t status; + + switch (nvme_get_zone_state(zone)) { + case NVME_ZONE_STATE_EMPTY: + case NVME_ZONE_STATE_IMPLICITLY_OPEN: + case NVME_ZONE_STATE_EXPLICITLY_OPEN: + case NVME_ZONE_STATE_FULL: + case NVME_ZONE_STATE_CLOSED: + case NVME_ZONE_STATE_READ_ONLY: + status =3D NVME_SUCCESS; + break; + case NVME_ZONE_STATE_OFFLINE: + status =3D NVME_ZONE_OFFLINE; + break; + default: + assert(false); + } + + return status; +} + +static uint16_t nvme_check_zone_read(NvmeNamespace *ns, uint64_t slba, + uint32_t nlb) +{ + NvmeZone *zone =3D nvme_get_zone_by_slba(ns, slba); + uint64_t bndry =3D nvme_zone_rd_boundary(ns, zone); + uint64_t end =3D slba + nlb; + uint16_t status; + + status =3D nvme_check_zone_state_for_read(zone); + if (status !=3D NVME_SUCCESS) { + ; + } else if (unlikely(end > bndry)) { + if (!ns->params.cross_zone_read) { + status =3D NVME_ZONE_BOUNDARY_ERROR; + } else { + /* + * Read across zone boundary - check that all subsequent + * zones that are being read have an appropriate state. + */ + do { + zone++; + status =3D nvme_check_zone_state_for_read(zone); + if (status !=3D NVME_SUCCESS) { + break; + } + } while (end > nvme_zone_rd_boundary(ns, zone)); + } + } + + return status; +} + +static void nvme_finalize_zoned_write(NvmeNamespace *ns, NvmeRequest *req, + bool failed) +{ + NvmeRwCmd *rw =3D (NvmeRwCmd *)&req->cmd; + NvmeZone *zone; + NvmeZonedResult *res =3D (NvmeZonedResult *)&req->cqe; + uint64_t slba; + uint32_t nlb; + + slba =3D le64_to_cpu(rw->slba); + nlb =3D le16_to_cpu(rw->nlb) + 1; + zone =3D nvme_get_zone_by_slba(ns, slba); + + if (failed) { + res->slba =3D 0; + zone->d.wp +=3D nlb; + } else if (zone->w_ptr =3D=3D nvme_zone_wr_boundary(zone)) { + switch (nvme_get_zone_state(zone)) { + case NVME_ZONE_STATE_IMPLICITLY_OPEN: + case NVME_ZONE_STATE_EXPLICITLY_OPEN: + case NVME_ZONE_STATE_CLOSED: + case NVME_ZONE_STATE_EMPTY: + nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_FULL); + /* fall through */ + case NVME_ZONE_STATE_FULL: + break; + default: + assert(false); + } + zone->d.wp =3D zone->w_ptr; + } else { + zone->d.wp +=3D nlb; + } +} + +static uint64_t nvme_advance_zone_wp(NvmeNamespace *ns, NvmeZone *zone, + uint32_t nlb) +{ + uint64_t result =3D zone->w_ptr; + uint8_t zs; + + zone->w_ptr +=3D nlb; + + if (zone->w_ptr < nvme_zone_wr_boundary(zone)) { + zs =3D nvme_get_zone_state(zone); + switch (zs) { + case NVME_ZONE_STATE_EMPTY: + case NVME_ZONE_STATE_CLOSED: + nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_IMPLICITLY_OP= EN); + } + } + + return result; +} + +static inline bool nvme_is_write(NvmeRequest *req) +{ + NvmeRwCmd *rw =3D (NvmeRwCmd *)&req->cmd; + + return rw->opcode =3D=3D NVME_CMD_WRITE || + rw->opcode =3D=3D NVME_CMD_ZONE_APPEND || + rw->opcode =3D=3D NVME_CMD_WRITE_ZEROES; +} + static void nvme_rw_cb(void *opaque, int ret) { NvmeRequest *req =3D opaque; @@ -957,6 +1204,10 @@ static void nvme_rw_cb(void *opaque, int ret) =20 trace_pci_nvme_rw_cb(nvme_cid(req), blk_name(blk)); =20 + if (ns->params.zoned && nvme_is_write(req)) { + nvme_finalize_zoned_write(ns, req, ret !=3D 0); + } + if (!ret) { block_acct_done(stats, acct); } else { @@ -1120,6 +1371,14 @@ static uint16_t nvme_read(NvmeCtrl *n, NvmeRequest *= req) goto invalid; } =20 + if (ns->params.zoned) { + status =3D nvme_check_zone_read(ns, slba, nlb); + if (status !=3D NVME_SUCCESS) { + trace_pci_nvme_err_zone_read_not_ok(slba, nlb, status); + goto invalid; + } + } + status =3D nvme_map_dptr(n, data_size, req); if (status) { goto invalid; @@ -1150,7 +1409,8 @@ invalid: return status | NVME_DNR; } =20 -static uint16_t nvme_do_write(NvmeCtrl *n, NvmeRequest *req, bool wrz) +static uint16_t nvme_do_write(NvmeCtrl *n, NvmeRequest *req, bool append, + bool wrz) { NvmeRwCmd *rw =3D (NvmeRwCmd *)&req->cmd; NvmeNamespace *ns =3D req->ns; @@ -1158,6 +1418,8 @@ static uint16_t nvme_do_write(NvmeCtrl *n, NvmeReques= t *req, bool wrz) uint32_t nlb =3D (uint32_t)le16_to_cpu(rw->nlb) + 1; uint64_t data_size =3D nvme_l2b(ns, nlb); uint64_t data_offset; + NvmeZone *zone; + NvmeZonedResult *res =3D (NvmeZonedResult *)&req->cqe; BlockBackend *blk =3D ns->blkconf.blk; uint16_t status; =20 @@ -1178,6 +1440,25 @@ static uint16_t nvme_do_write(NvmeCtrl *n, NvmeReque= st *req, bool wrz) goto invalid; } =20 + if (ns->params.zoned) { + zone =3D nvme_get_zone_by_slba(ns, slba); + + status =3D nvme_check_zone_write(n, ns, zone, slba, nlb, append); + if (status !=3D NVME_SUCCESS) { + goto invalid; + } + + if (append) { + slba =3D zone->w_ptr; + } + + res->slba =3D nvme_advance_zone_wp(ns, zone, nlb); + } else if (append) { + trace_pci_nvme_err_invalid_opc(rw->opcode); + status =3D NVME_INVALID_OPCODE; + goto invalid; + } + data_offset =3D nvme_l2b(ns, slba); =20 if (!wrz) { @@ -1210,12 +1491,445 @@ invalid: =20 static inline uint16_t nvme_write(NvmeCtrl *n, NvmeRequest *req) { - return nvme_do_write(n, req, false); + return nvme_do_write(n, req, false, false); } =20 static inline uint16_t nvme_write_zeroes(NvmeCtrl *n, NvmeRequest *req) { - return nvme_do_write(n, req, true); + return nvme_do_write(n, req, false, true); +} + +static inline uint16_t nvme_zone_append(NvmeCtrl *n, NvmeRequest *req) +{ + return nvme_do_write(n, req, true, false); +} + +static uint16_t nvme_get_mgmt_zone_slba_idx(NvmeNamespace *ns, NvmeCmd *c, + uint64_t *slba, uint32_t *zone= _idx) +{ + uint32_t dw10 =3D le32_to_cpu(c->cdw10); + uint32_t dw11 =3D le32_to_cpu(c->cdw11); + + if (!ns->params.zoned) { + trace_pci_nvme_err_invalid_opc(c->opcode); + return NVME_INVALID_OPCODE | NVME_DNR; + } + + *slba =3D ((uint64_t)dw11) << 32 | dw10; + if (unlikely(*slba >=3D ns->id_ns.nsze)) { + trace_pci_nvme_err_invalid_lba_range(*slba, 0, ns->id_ns.nsze); + *slba =3D 0; + return NVME_LBA_RANGE | NVME_DNR; + } + + *zone_idx =3D nvme_zone_idx(ns, *slba); + assert(*zone_idx < ns->num_zones); + + return NVME_SUCCESS; +} + +typedef uint16_t (*op_handler_t)(NvmeNamespace *, NvmeZone *, + enum NvmeZoneState); + +enum NvmeZoneProcessingMask { + NVME_PROC_CURRENT_ZONE =3D 0, + NVME_PROC_IMP_OPEN_ZONES =3D 1 << 0, + NVME_PROC_EXP_OPEN_ZONES =3D 1 << 1, + NVME_PROC_CLOSED_ZONES =3D 1 << 2, + NVME_PROC_READ_ONLY_ZONES =3D 1 << 3, + NVME_PROC_FULL_ZONES =3D 1 << 4, +}; + +static uint16_t nvme_open_zone(NvmeNamespace *ns, NvmeZone *zone, + enum NvmeZoneState state) +{ + switch (state) { + case NVME_ZONE_STATE_EMPTY: + case NVME_ZONE_STATE_CLOSED: + case NVME_ZONE_STATE_IMPLICITLY_OPEN: + nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_EXPLICITLY_OPEN); + /* fall through */ + case NVME_ZONE_STATE_EXPLICITLY_OPEN: + return NVME_SUCCESS; + default: + return NVME_ZONE_INVAL_TRANSITION; + } +} + +static uint16_t nvme_close_zone(NvmeNamespace *ns, NvmeZone *zone, + enum NvmeZoneState state) +{ + switch (state) { + case NVME_ZONE_STATE_EXPLICITLY_OPEN: + case NVME_ZONE_STATE_IMPLICITLY_OPEN: + nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_CLOSED); + /* fall through */ + case NVME_ZONE_STATE_CLOSED: + return NVME_SUCCESS; + default: + return NVME_ZONE_INVAL_TRANSITION; + } +} + +static uint16_t nvme_finish_zone(NvmeNamespace *ns, NvmeZone *zone, + enum NvmeZoneState state) +{ + switch (state) { + case NVME_ZONE_STATE_EXPLICITLY_OPEN: + case NVME_ZONE_STATE_IMPLICITLY_OPEN: + case NVME_ZONE_STATE_CLOSED: + case NVME_ZONE_STATE_EMPTY: + zone->w_ptr =3D nvme_zone_wr_boundary(zone); + zone->d.wp =3D zone->w_ptr; + nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_FULL); + /* fall through */ + case NVME_ZONE_STATE_FULL: + return NVME_SUCCESS; + default: + return NVME_ZONE_INVAL_TRANSITION; + } +} + +static uint16_t nvme_reset_zone(NvmeNamespace *ns, NvmeZone *zone, + enum NvmeZoneState state) +{ + switch (state) { + case NVME_ZONE_STATE_EXPLICITLY_OPEN: + case NVME_ZONE_STATE_IMPLICITLY_OPEN: + case NVME_ZONE_STATE_CLOSED: + case NVME_ZONE_STATE_FULL: + zone->w_ptr =3D zone->d.zslba; + zone->d.wp =3D zone->w_ptr; + nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_EMPTY); + /* fall through */ + case NVME_ZONE_STATE_EMPTY: + return NVME_SUCCESS; + default: + return NVME_ZONE_INVAL_TRANSITION; + } +} + +static uint16_t nvme_offline_zone(NvmeNamespace *ns, NvmeZone *zone, + enum NvmeZoneState state) +{ + switch (state) { + case NVME_ZONE_STATE_READ_ONLY: + nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_OFFLINE); + /* fall through */ + case NVME_ZONE_STATE_OFFLINE: + return NVME_SUCCESS; + default: + return NVME_ZONE_INVAL_TRANSITION; + } +} + +static uint16_t nvme_bulk_proc_zone(NvmeNamespace *ns, NvmeZone *zone, + enum NvmeZoneProcessingMask proc_mask, + op_handler_t op_hndlr) +{ + uint16_t status =3D NVME_SUCCESS; + enum NvmeZoneState zs =3D nvme_get_zone_state(zone); + bool proc_zone; + + switch (zs) { + case NVME_ZONE_STATE_IMPLICITLY_OPEN: + proc_zone =3D proc_mask & NVME_PROC_IMP_OPEN_ZONES; + break; + case NVME_ZONE_STATE_EXPLICITLY_OPEN: + proc_zone =3D proc_mask & NVME_PROC_EXP_OPEN_ZONES; + break; + case NVME_ZONE_STATE_CLOSED: + proc_zone =3D proc_mask & NVME_PROC_CLOSED_ZONES; + break; + case NVME_ZONE_STATE_READ_ONLY: + proc_zone =3D proc_mask & NVME_PROC_READ_ONLY_ZONES; + break; + case NVME_ZONE_STATE_FULL: + proc_zone =3D proc_mask & NVME_PROC_FULL_ZONES; + break; + default: + proc_zone =3D false; + } + + if (proc_zone) { + status =3D op_hndlr(ns, zone, zs); + } + + return status; +} + +static uint16_t nvme_do_zone_op(NvmeNamespace *ns, NvmeZone *zone, + enum NvmeZoneProcessingMask proc_mask, + op_handler_t op_hndlr) +{ + NvmeZone *next; + uint16_t status =3D NVME_SUCCESS; + int i; + + if (!proc_mask) { + status =3D op_hndlr(ns, zone, nvme_get_zone_state(zone)); + } else { + if (proc_mask & NVME_PROC_CLOSED_ZONES) { + QTAILQ_FOREACH_SAFE(zone, &ns->closed_zones, entry, next) { + status =3D nvme_bulk_proc_zone(ns, zone, proc_mask, op_hnd= lr); + if (status !=3D NVME_SUCCESS) { + goto out; + } + } + } + if (proc_mask & NVME_PROC_IMP_OPEN_ZONES) { + QTAILQ_FOREACH_SAFE(zone, &ns->imp_open_zones, entry, next) { + status =3D nvme_bulk_proc_zone(ns, zone, proc_mask, op_hnd= lr); + if (status !=3D NVME_SUCCESS) { + goto out; + } + } + } + if (proc_mask & NVME_PROC_EXP_OPEN_ZONES) { + QTAILQ_FOREACH_SAFE(zone, &ns->exp_open_zones, entry, next) { + status =3D nvme_bulk_proc_zone(ns, zone, proc_mask, op_hnd= lr); + if (status !=3D NVME_SUCCESS) { + goto out; + } + } + } + if (proc_mask & NVME_PROC_FULL_ZONES) { + QTAILQ_FOREACH_SAFE(zone, &ns->full_zones, entry, next) { + status =3D nvme_bulk_proc_zone(ns, zone, proc_mask, op_hnd= lr); + if (status !=3D NVME_SUCCESS) { + goto out; + } + } + } + + if (proc_mask & NVME_PROC_READ_ONLY_ZONES) { + for (i =3D 0; i < ns->num_zones; i++, zone++) { + status =3D nvme_bulk_proc_zone(ns, zone, proc_mask, op_hnd= lr); + if (status !=3D NVME_SUCCESS) { + goto out; + } + } + } + } + +out: + return status; +} + +static uint16_t nvme_zone_mgmt_send(NvmeCtrl *n, NvmeRequest *req) +{ + NvmeCmd *cmd =3D (NvmeCmd *)&req->cmd; + NvmeNamespace *ns =3D req->ns; + NvmeZone *zone; + uint32_t dw13 =3D le32_to_cpu(cmd->cdw13); + uint64_t slba =3D 0; + uint32_t zone_idx =3D 0; + uint16_t status; + uint8_t action; + bool all; + enum NvmeZoneProcessingMask proc_mask =3D NVME_PROC_CURRENT_ZONE; + + action =3D dw13 & 0xff; + all =3D dw13 & 0x100; + + req->status =3D NVME_SUCCESS; + + if (!all) { + status =3D nvme_get_mgmt_zone_slba_idx(ns, cmd, &slba, &zone_idx); + if (status) { + return status; + } + } + + zone =3D &ns->zone_array[zone_idx]; + if (slba !=3D zone->d.zslba) { + trace_pci_nvme_err_unaligned_zone_cmd(action, slba, zone->d.zslba); + return NVME_INVALID_FIELD | NVME_DNR; + } + + switch (action) { + + case NVME_ZONE_ACTION_OPEN: + if (all) { + proc_mask =3D NVME_PROC_CLOSED_ZONES; + } + trace_pci_nvme_open_zone(slba, zone_idx, all); + status =3D nvme_do_zone_op(ns, zone, proc_mask, nvme_open_zone); + break; + + case NVME_ZONE_ACTION_CLOSE: + if (all) { + proc_mask =3D NVME_PROC_IMP_OPEN_ZONES | NVME_PROC_EXP_OPEN_ZO= NES; + } + trace_pci_nvme_close_zone(slba, zone_idx, all); + status =3D nvme_do_zone_op(ns, zone, proc_mask, nvme_close_zone); + break; + + case NVME_ZONE_ACTION_FINISH: + if (all) { + proc_mask =3D NVME_PROC_IMP_OPEN_ZONES | NVME_PROC_EXP_OPEN_ZO= NES | + NVME_PROC_CLOSED_ZONES; + } + trace_pci_nvme_finish_zone(slba, zone_idx, all); + status =3D nvme_do_zone_op(ns, zone, proc_mask, nvme_finish_zone); + break; + + case NVME_ZONE_ACTION_RESET: + if (all) { + proc_mask =3D NVME_PROC_IMP_OPEN_ZONES | NVME_PROC_EXP_OPEN_ZO= NES | + NVME_PROC_CLOSED_ZONES | NVME_PROC_FULL_ZONES; + } + trace_pci_nvme_reset_zone(slba, zone_idx, all); + status =3D nvme_do_zone_op(ns, zone, proc_mask, nvme_reset_zone); + break; + + case NVME_ZONE_ACTION_OFFLINE: + if (all) { + proc_mask =3D NVME_PROC_READ_ONLY_ZONES; + } + trace_pci_nvme_offline_zone(slba, zone_idx, all); + status =3D nvme_do_zone_op(ns, zone, proc_mask, nvme_offline_zone); + break; + + case NVME_ZONE_ACTION_SET_ZD_EXT: + trace_pci_nvme_set_descriptor_extension(slba, zone_idx); + return NVME_INVALID_FIELD | NVME_DNR; + break; + + default: + trace_pci_nvme_err_invalid_mgmt_action(action); + status =3D NVME_INVALID_FIELD; + } + + if (status =3D=3D NVME_ZONE_INVAL_TRANSITION) { + trace_pci_nvme_err_invalid_zone_state_transition(action, slba, + zone->d.za); + } + if (status) { + status |=3D NVME_DNR; + } + + return status; +} + +static bool nvme_zone_matches_filter(uint32_t zafs, NvmeZone *zl) +{ + enum NvmeZoneState zs =3D nvme_get_zone_state(zl); + + switch (zafs) { + case NVME_ZONE_REPORT_ALL: + return true; + case NVME_ZONE_REPORT_EMPTY: + return zs =3D=3D NVME_ZONE_STATE_EMPTY; + case NVME_ZONE_REPORT_IMPLICITLY_OPEN: + return zs =3D=3D NVME_ZONE_STATE_IMPLICITLY_OPEN; + case NVME_ZONE_REPORT_EXPLICITLY_OPEN: + return zs =3D=3D NVME_ZONE_STATE_EXPLICITLY_OPEN; + case NVME_ZONE_REPORT_CLOSED: + return zs =3D=3D NVME_ZONE_STATE_CLOSED; + case NVME_ZONE_REPORT_FULL: + return zs =3D=3D NVME_ZONE_STATE_FULL; + case NVME_ZONE_REPORT_READ_ONLY: + return zs =3D=3D NVME_ZONE_STATE_READ_ONLY; + case NVME_ZONE_REPORT_OFFLINE: + return zs =3D=3D NVME_ZONE_STATE_OFFLINE; + default: + return false; + } +} + +static uint16_t nvme_zone_mgmt_recv(NvmeCtrl *n, NvmeRequest *req) +{ + NvmeCmd *cmd =3D (NvmeCmd *)&req->cmd; + NvmeNamespace *ns =3D req->ns; + /* cdw12 is zero-based number of dwords to return. Convert to bytes */ + uint32_t data_size =3D (le32_to_cpu(cmd->cdw12) + 1) << 2; + uint32_t dw13 =3D le32_to_cpu(cmd->cdw13); + uint32_t zone_idx, zra, zrasf, partial; + uint64_t max_zones, nr_zones =3D 0; + uint16_t status; + uint64_t slba, capacity =3D nvme_ns_nlbas(ns); + NvmeZoneDescr *z; + NvmeZone *zone; + NvmeZoneReportHeader *header; + void *buf, *buf_p; + size_t zone_entry_sz; + + req->status =3D NVME_SUCCESS; + + status =3D nvme_get_mgmt_zone_slba_idx(ns, cmd, &slba, &zone_idx); + if (status) { + return status; + } + + zra =3D dw13 & 0xff; + if (zra !=3D NVME_ZONE_REPORT) { + return NVME_INVALID_FIELD | NVME_DNR; + } + + zrasf =3D (dw13 >> 8) & 0xff; + if (zrasf > NVME_ZONE_REPORT_OFFLINE) { + return NVME_INVALID_FIELD | NVME_DNR; + } + + if (data_size < sizeof(NvmeZoneReportHeader)) { + return NVME_INVALID_FIELD | NVME_DNR; + } + + status =3D nvme_check_mdts(n, data_size); + if (status) { + trace_pci_nvme_err_mdts(nvme_cid(req), data_size); + return status; + } + + partial =3D (dw13 >> 16) & 0x01; + + zone_entry_sz =3D sizeof(NvmeZoneDescr); + + max_zones =3D (data_size - sizeof(NvmeZoneReportHeader)) / zone_entry_= sz; + buf =3D g_malloc0(data_size); + + zone =3D &ns->zone_array[zone_idx]; + for (; slba < capacity; slba +=3D ns->zone_size) { + if (partial && nr_zones >=3D max_zones) { + break; + } + if (nvme_zone_matches_filter(zrasf, zone++)) { + nr_zones++; + } + } + header =3D (NvmeZoneReportHeader *)buf; + header->nr_zones =3D cpu_to_le64(nr_zones); + + buf_p =3D buf + sizeof(NvmeZoneReportHeader); + for (; zone_idx < ns->num_zones && max_zones > 0; zone_idx++) { + zone =3D &ns->zone_array[zone_idx]; + if (nvme_zone_matches_filter(zrasf, zone)) { + z =3D (NvmeZoneDescr *)buf_p; + buf_p +=3D sizeof(NvmeZoneDescr); + + z->zt =3D zone->d.zt; + z->zs =3D zone->d.zs; + z->zcap =3D cpu_to_le64(zone->d.zcap); + z->zslba =3D cpu_to_le64(zone->d.zslba); + z->za =3D zone->d.za; + + if (nvme_wp_is_valid(zone)) { + z->wp =3D cpu_to_le64(zone->d.wp); + } else { + z->wp =3D cpu_to_le64(~0ULL); + } + + max_zones--; + } + } + + status =3D nvme_dma(n, (uint8_t *)buf, data_size, + DMA_DIRECTION_FROM_DEVICE, req); + + g_free(buf); + + return status; } =20 static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeRequest *req) @@ -1244,12 +1958,18 @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeReques= t *req) return nvme_flush(n, req); case NVME_CMD_WRITE_ZEROES: return nvme_write_zeroes(n, req); + case NVME_CMD_ZONE_APPEND: + return nvme_zone_append(n, req); case NVME_CMD_WRITE: return nvme_write(n, req); case NVME_CMD_READ: return nvme_read(n, req); case NVME_CMD_DSM: return nvme_dsm(n, req); + 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: assert(false); } @@ -1511,6 +2231,9 @@ static uint16_t nvme_cmd_effects(NvmeCtrl *n, uint8_t= csi, uint32_t buf_len, case NVME_CSI_NVM: src_iocs =3D nvme_cse_iocs_nvm; break; + case NVME_CSI_ZONED: + src_iocs =3D nvme_cse_iocs_zoned; + break; } } =20 @@ -1692,6 +2415,16 @@ static uint16_t nvme_rpt_empty_id_struct(NvmeCtrl *n= , NvmeRequest *req) return nvme_dma(n, id, sizeof(id), DMA_DIRECTION_FROM_DEVICE, req); } =20 +static inline bool nvme_csi_has_nvm_support(NvmeNamespace *ns) +{ + switch (ns->csi) { + case NVME_CSI_NVM: + case NVME_CSI_ZONED: + return true; + } + return false; +} + static uint16_t nvme_identify_ctrl(NvmeCtrl *n, NvmeRequest *req) { trace_pci_nvme_identify_ctrl(); @@ -1703,11 +2436,18 @@ static uint16_t nvme_identify_ctrl(NvmeCtrl *n, Nvm= eRequest *req) static uint16_t nvme_identify_ctrl_csi(NvmeCtrl *n, NvmeRequest *req) { NvmeIdentify *c =3D (NvmeIdentify *)&req->cmd; + NvmeIdCtrlZoned id =3D {}; =20 trace_pci_nvme_identify_ctrl_csi(c->csi); =20 if (c->csi =3D=3D NVME_CSI_NVM) { return nvme_rpt_empty_id_struct(n, req); + } else if (c->csi =3D=3D NVME_CSI_ZONED) { + if (n->params.zasl_bs) { + id.zasl =3D n->zasl; + } + return nvme_dma(n, (uint8_t *)&id, sizeof(id), + DMA_DIRECTION_FROM_DEVICE, req); } =20 return NVME_INVALID_FIELD | NVME_DNR; @@ -1730,8 +2470,12 @@ static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeRe= quest *req) return nvme_rpt_empty_id_struct(n, req); } =20 - return nvme_dma(n, (uint8_t *)&ns->id_ns, sizeof(NvmeIdNs), - DMA_DIRECTION_FROM_DEVICE, req); + if (c->csi =3D=3D NVME_CSI_NVM && nvme_csi_has_nvm_support(ns)) { + return nvme_dma(n, (uint8_t *)&ns->id_ns, sizeof(NvmeIdNs), + DMA_DIRECTION_FROM_DEVICE, req); + } + + return NVME_INVALID_CMD_SET | NVME_DNR; } =20 static uint16_t nvme_identify_ns_csi(NvmeCtrl *n, NvmeRequest *req) @@ -1751,8 +2495,11 @@ static uint16_t nvme_identify_ns_csi(NvmeCtrl *n, Nv= meRequest *req) return nvme_rpt_empty_id_struct(n, req); } =20 - if (c->csi =3D=3D NVME_CSI_NVM) { + if (c->csi =3D=3D NVME_CSI_NVM && nvme_csi_has_nvm_support(ns)) { return nvme_rpt_empty_id_struct(n, req); + } else if (c->csi =3D=3D NVME_CSI_ZONED && ns->csi =3D=3D NVME_CSI_ZON= ED) { + return nvme_dma(n, (uint8_t *)ns->id_ns_zoned, sizeof(NvmeIdNsZone= d), + DMA_DIRECTION_FROM_DEVICE, req); } =20 return NVME_INVALID_FIELD | NVME_DNR; @@ -1816,7 +2563,7 @@ static uint16_t nvme_identify_nslist_csi(NvmeCtrl *n,= NvmeRequest *req) return NVME_INVALID_NSID | NVME_DNR; } =20 - if (c->csi !=3D NVME_CSI_NVM) { + if (c->csi !=3D NVME_CSI_NVM && c->csi !=3D NVME_CSI_ZONED) { return NVME_INVALID_FIELD | NVME_DNR; } =20 @@ -1825,7 +2572,7 @@ static uint16_t nvme_identify_nslist_csi(NvmeCtrl *n,= NvmeRequest *req) if (!ns) { continue; } - if (ns->params.nsid <=3D min_nsid) { + if (ns->params.nsid <=3D min_nsid || c->csi !=3D ns->csi) { continue; } list_ptr[j++] =3D cpu_to_le32(ns->params.nsid); @@ -1892,6 +2639,8 @@ static uint16_t nvme_identify_cmd_set(NvmeCtrl *n, Nv= meRequest *req) trace_pci_nvme_identify_cmd_set(); =20 NVME_SET_CSI(*list, NVME_CSI_NVM); + NVME_SET_CSI(*list, NVME_CSI_ZONED); + return nvme_dma(n, list, data_len, DMA_DIRECTION_FROM_DEVICE, req); } =20 @@ -2461,6 +3210,13 @@ static void nvme_select_ns_iocs(NvmeCtrl *n) ns->iocs =3D nvme_cse_iocs_nvm; } break; + case NVME_CSI_ZONED: + if (NVME_CC_CSS(n->bar.cc) =3D=3D NVME_CC_CSS_CSI) { + ns->iocs =3D nvme_cse_iocs_zoned; + } else if (NVME_CC_CSS(n->bar.cc) =3D=3D NVME_CC_CSS_NVM) { + ns->iocs =3D nvme_cse_iocs_nvm; + } + break; } } } @@ -2559,6 +3315,17 @@ static int nvme_start_ctrl(NvmeCtrl *n) nvme_init_sq(&n->admin_sq, n, n->bar.asq, 0, 0, NVME_AQA_ASQS(n->bar.aqa) + 1); =20 + if (!n->params.zasl_bs) { + n->zasl =3D n->params.mdts; + } else { + if (n->params.zasl_bs < n->page_size) { + trace_pci_nvme_err_startfail_zasl_too_small(n->params.zasl_bs, + n->page_size); + return -1; + } + n->zasl =3D 31 - clz32(n->params.zasl_bs / n->page_size); + } + nvme_set_timestamp(n, 0ULL); =20 QTAILQ_INIT(&n->aer_queue); @@ -2983,6 +3750,13 @@ static void nvme_check_constraints(NvmeCtrl *n, Erro= r **errp) =20 host_memory_backend_set_mapped(n->pmrdev, true); } + + if (n->params.zasl_bs) { + if (!is_power_of_2(n->params.zasl_bs)) { + error_setg(errp, "zone append size limit has to be a power of = 2"); + return; + } + } } =20 static void nvme_init_state(NvmeCtrl *n) @@ -3247,8 +4021,20 @@ static void nvme_realize(PCIDevice *pci_dev, Error *= *errp) static void nvme_exit(PCIDevice *pci_dev) { NvmeCtrl *n =3D NVME(pci_dev); + NvmeNamespace *ns; + int i; =20 nvme_ctrl_shutdown(n); + + for (i =3D 1; i <=3D n->num_namespaces; i++) { + ns =3D nvme_ns(n, i); + if (!ns) { + continue; + } + + nvme_ns_cleanup(ns); + } + g_free(n->cq); g_free(n->sq); g_free(n->aer_reqs); @@ -3276,6 +4062,8 @@ static Property nvme_props[] =3D { DEFINE_PROP_UINT32("aer_max_queued", NvmeCtrl, params.aer_max_queued, = 64), DEFINE_PROP_UINT8("mdts", NvmeCtrl, params.mdts, 7), DEFINE_PROP_BOOL("use-intel-id", NvmeCtrl, params.use_intel_id, false), + DEFINE_PROP_SIZE32("zoned.append_size_limit", NvmeCtrl, params.zasl_bs, + NVME_DEFAULT_MAX_ZA_SIZE), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/hw/block/trace-events b/hw/block/trace-events index 8b697664d3..63db3a353e 100644 --- a/hw/block/trace-events +++ b/hw/block/trace-events @@ -93,6 +93,14 @@ pci_nvme_mmio_start_success(void) "setting controller en= able 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=3D%"PRIu64", idx=3D%"PRIu32", all=3D%"PRIi32"" +pci_nvme_close_zone(uint64_t slba, uint32_t zone_idx, int all) "close zone= , slba=3D%"PRIu64", idx=3D%"PRIu32", all=3D%"PRIi32"" +pci_nvme_finish_zone(uint64_t slba, uint32_t zone_idx, int all) "finish zo= ne, slba=3D%"PRIu64", idx=3D%"PRIu32", all=3D%"PRIi32"" +pci_nvme_reset_zone(uint64_t slba, uint32_t zone_idx, int all) "reset zone= , slba=3D%"PRIu64", idx=3D%"PRIu32", all=3D%"PRIi32"" +pci_nvme_offline_zone(uint64_t slba, uint32_t zone_idx, int all) "offline = zone, slba=3D%"PRIu64", idx=3D%"PRIu32", all=3D%"PRIi32"" +pci_nvme_set_descriptor_extension(uint64_t slba, uint32_t zone_idx) "set z= one descriptor extension, slba=3D%"PRIu64", idx=3D%"PRIu32"" +pci_nvme_clear_ns_close(uint32_t state, uint64_t slba) "zone state=3D%"PRI= u32", slba=3D%"PRIu64" transitioned to Closed state" +pci_nvme_clear_ns_reset(uint32_t state, uint64_t slba) "zone state=3D%"PRI= u32", slba=3D%"PRIu64" transitioned to Empty state" =20 # 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%"PRIx= 8"" pci_nvme_err_invalid_lba_range(uint64_t start, uint64_t len, uint64_t limi= t) "Invalid LBA start=3D%"PRIu64" len=3D%"PRIu64" limit=3D%"PRIu64"" pci_nvme_err_invalid_log_page_offset(uint64_t ofs, uint64_t size) "must be= <=3D %"PRIu64", got %"PRIu64"" +pci_nvme_err_unaligned_zone_cmd(uint8_t action, uint64_t slba, uint64_t zs= lba) "unaligned zone op 0x%"PRIx32", got slba=3D%"PRIu64", zslba=3D%"PRIu64= "" +pci_nvme_err_invalid_zone_state_transition(uint8_t action, uint64_t slba, = uint8_t attrs) "action=3D0x%"PRIx8", slba=3D%"PRIu64", attrs=3D0x%"PRIx32"" +pci_nvme_err_write_not_at_wp(uint64_t slba, uint64_t zone, uint64_t wp) "w= riting at slba=3D%"PRIu64", zone=3D%"PRIu64", but wp=3D%"PRIu64"" +pci_nvme_err_append_not_at_start(uint64_t slba, uint64_t zone) "appending = at slba=3D%"PRIu64", but zone=3D%"PRIu64"" +pci_nvme_err_zone_write_not_ok(uint64_t slba, uint32_t nlb, uint32_t statu= s) "slba=3D%"PRIu64", nlb=3D%"PRIu32", status=3D0x%"PRIx16"" +pci_nvme_err_zone_read_not_ok(uint64_t slba, uint32_t nlb, uint32_t status= ) "slba=3D%"PRIu64", nlb=3D%"PRIu32", status=3D0x%"PRIx16"" +pci_nvme_err_append_too_large(uint64_t slba, uint32_t nlb, uint8_t zasl) "= slba=3D%"PRIu64", nlb=3D%"PRIu32", zasl=3D%"PRIu8"" pci_nvme_err_invalid_iocsci(uint32_t idx) "unsupported command set combina= tion index %"PRIu32"" pci_nvme_err_invalid_del_sq(uint16_t qid) "invalid submission queue deleti= on, sid=3D%"PRIu16"" pci_nvme_err_invalid_create_sq_cqid(uint16_t cqid) "failed creating submis= sion queue, invalid cqid=3D%"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 in= valid command set selected:%u" pci_nvme_err_startfail_asqent_sz_zero(void) "nvme_start_ctrl failed becaus= e the admin submission queue size is zero" pci_nvme_err_startfail_acqent_sz_zero(void) "nvme_start_ctrl failed becaus= e the admin completion queue size is zero" +pci_nvme_err_startfail_zasl_too_small(uint32_t zasl, uint32_t pagesz) "nvm= e_start_ctrl failed because zone append size limit %"PRIu32" is too small, = needs to be >=3D %"PRIu32"" pci_nvme_err_startfail(void) "setting controller enable bit failed" +pci_nvme_err_invalid_mgmt_action(int action) "action=3D0x%"PRIx8"" =20 # Traces for undefined behavior pci_nvme_ub_mmiowr_misaligned32(uint64_t offset) "MMIO write not 32-bit al= igned, offset=3D0x%"PRIx64"" --=20 2.28.0 From nobody Fri May 10 12:23:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1607463186; cv=none; d=zohomail.com; s=zohoarc; b=VH3aUwYxTl04l+p7tMToL+SCE2osnZFMV0MHCT7AqitWe88jYFR7A4Yr4t+KqozkimTbZcN/5fBIfGq6W6puxTzPB3rt3QVvEmyWRsxg5bnxTC+hTjV753vIvw8WcQyPAavC33Bgvo/nZ1TGXuPf96zLGxHAgBm8ARR7lHRIjPE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607463186; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IcXqVqQgprN6vuc59r9fbEMhG70ny75EMbUaFXCy2Ls=; b=Nv90pJYU2omzYEW6uiQiczW3xZWIwoXrTKgRdGucmDDkEsj9COXpMghfHgJlWCk2eOJRtFr3NQgZRGyrRQWElDEr1okRPAPbncjnkuksJSAePloz7XRe5MhRwwhT//d8/1fn7Z/T3JBcJbt9GkPhC43wpZZz8T1F5qrasbgaUSw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1607463186001381.18692699798567; Tue, 8 Dec 2020 13:33:06 -0800 (PST) Received: from localhost ([::1]:59298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmkbY-0008EZ-7H for importer@patchew.org; Tue, 08 Dec 2020 16:33:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56426) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjED-0002bI-6H; Tue, 08 Dec 2020 15:04:53 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:42903) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjE1-00062i-VQ; Tue, 08 Dec 2020 15:04:52 -0500 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Dec 2020 04:20:51 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2020 11:48:37 -0800 Received: from unknown (HELO redsun50.ssa.fujisawa.hgst.com) ([10.149.66.24]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Dec 2020 12:04:36 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1607458858; x=1638994858; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OLGX0xngCO6Our+nf6pD0c4JnA9mM74HF1AfqLGmux0=; b=FL03Q2TC9InZMRpL07W/J0q+m0DoQbltZobBszsevOPLntyF1IZf+dmp tbbdNm3aim21Mrhorrn8LRlehMNWoAuAA8Uk76V2FD2tX/CQpVk9Z4u4S uR766uLyX5VHoxanpAb5+g72cbtkQoYuYNH29xCo+iud7YOTHCx1Oj6cV 1UMRGk78JcUa3Got3QJi/7nUWNNnKB0kE/0Kr0+74qoTlYSmoenQyMKuF ENinuOfzgGk+m87TKWlySB+YPaZ4GcKw2q5SzmzBdidAhftzGI7PFT/RH jHkbLXgimJXpEcX8FJNJ4PyMLvfCexRBCdQu5HftT5EhNKvZ3/WgliNRu Q==; IronPort-SDR: qBQd2rtvJymyGEhGQ7m1AxbvwQJAWgeghGrCI4/9ymarcfhK2bSRTRxk2LfuENqVkZjFWI7CEE WAyzeOjqmX2EioDvLnQCBbVLfsncX3xbau2WGeg+72Xz5ELT0MMNCacshu0eUoXKs3e1qZQNaD P47gdnlROeW3SK9ficQpjWCh7B8mHKcdssqwHNyNSIjcLp/K3irRtHjHbUwkakGJg2o5bUm4b+ 2oPWEXB1WXAqc4igf0pkEKInxgQlvBS4QNBzdhzjKbWgjASQzxFnKzktQWtnOjFoKtXaNKNYaf M94= X-IronPort-AV: E=Sophos;i="5.78,403,1599494400"; d="scan'208";a="258433468" IronPort-SDR: PEnBLwWzEeHxxq9wVOfeZQTfIPgrlTSDYRAPb6DxLW0xBgK++ELUrKfZH2me1iCkVRGCCjGs1M 903eQQ3KWD7I/238Ppby/jtgsyA3b4OZs= IronPort-SDR: YM9qPhs63aCO5hJoOxeuPXnc0mDhDT+L9EG/+tt9oCaraqULoEA4I+JK1qsX0N2ShprNTpQsb5 LWPvPKJ/m8Vw== WDCIronportException: Internal From: Dmitry Fomichev To: Keith Busch , Klaus Jensen , Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Max Reitz , Maxim Levitsky , Fam Zheng Subject: [PATCH v11 10/13] hw/block/nvme: Introduce max active and open zone limits Date: Wed, 9 Dec 2020 05:04:07 +0900 Message-Id: <20201208200410.27900-11-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201208200410.27900-1-dmitry.fomichev@wdc.com> References: <20201208200410.27900-1-dmitry.fomichev@wdc.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=68.232.143.124; envelope-from=prvs=604abd949=dmitry.fomichev@wdc.com; helo=esa2.hgst.iphmx.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Niklas Cassel , Damien Le Moal , qemu-block@nongnu.org, Dmitry Fomichev , qemu-devel@nongnu.org, Alistair Francis , Matias Bjorling Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add 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. Signed-off-by: Hans Holmberg Signed-off-by: Dmitry Fomichev Reviewed-by: Niklas Cassel Reviewed-by: Keith Busch Reviewed-by: Klaus Jensen --- 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(-) diff --git a/hw/block/nvme-ns.h b/hw/block/nvme-ns.h index 388381dda0..7e1fd26909 100644 --- a/hw/block/nvme-ns.h +++ b/hw/block/nvme-ns.h @@ -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; =20 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; =20 NvmeNamespaceParams params; =20 @@ -125,6 +129,43 @@ static inline bool nvme_wp_is_valid(NvmeZone *zone) st !=3D NVME_ZONE_STATE_OFFLINE; } =20 +static inline void nvme_aor_inc_open(NvmeNamespace *ns) +{ + assert(ns->nr_open_zones >=3D 0); + if (ns->params.max_open_zones) { + ns->nr_open_zones++; + assert(ns->nr_open_zones <=3D 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 >=3D 0); +} + +static inline void nvme_aor_inc_active(NvmeNamespace *ns) +{ + assert(ns->nr_active_zones >=3D 0); + if (ns->params.max_active_zones) { + ns->nr_active_zones++; + assert(ns->nr_active_zones <=3D 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 >=3D ns->nr_open_zones); + } + assert(ns->nr_active_zones >=3D 0); +} + int nvme_ns_setup(NvmeCtrl *n, NvmeNamespace *ns, Error **errp); void nvme_ns_drain(NvmeNamespace *ns); void nvme_ns_shutdown(NvmeNamespace *ns); diff --git a/hw/block/nvme-ns.c b/hw/block/nvme-ns.c index 1df45bbe35..aaef69fb47 100644 --- a/hw/block/nvme-ns.c +++ b/hw/block/nvme-ns.c @@ -136,6 +136,21 @@ static int nvme_ns_zoned_check_calc_geometry(NvmeNames= pace *ns, Error **errp) ns->zone_size =3D zone_size / lbasz; ns->zone_capacity =3D zone_cap / lbasz; ns->num_zones =3D 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; } =20 @@ -183,8 +198,8 @@ static void nvme_ns_init_zoned(NvmeCtrl *n, NvmeNamespa= ce *ns, int lba_index) id_ns_z =3D g_malloc0(sizeof(NvmeIdNsZoned)); =20 /* MAR/MOR are zeroes-based, 0xffffffff means no limit */ - id_ns_z->mar =3D 0xffffffff; - id_ns_z->mor =3D 0xffffffff; + id_ns_z->mar =3D cpu_to_le32(ns->params.max_active_zones - 1); + id_ns_z->mor =3D cpu_to_le32(ns->params.max_open_zones - 1); id_ns_z->zoc =3D 0; id_ns_z->ozcs =3D ns->params.cross_zone_read ? 0x01 : 0x00; =20 @@ -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) =20 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 =3D=3D 0); } =20 static int nvme_ns_check_constraints(NvmeNamespace *ns, Error **errp) @@ -320,6 +343,10 @@ static Property nvme_ns_props[] =3D { 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(), }; =20 diff --git a/hw/block/nvme.c b/hw/block/nvme.c index d1c57cb322..8b97b713a3 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -202,6 +202,26 @@ static void nvme_assign_zone_state(NvmeNamespace *ns, = NvmeZone *zone, } } =20 +/* + * Check if we can open a zone without exceeding open/active limits. + * AOR stands for "Active and Open Resources" (see TP 4053 section 2.5). + */ +static int nvme_aor_check(NvmeNamespace *ns, uint32_t act, uint32_t opn) +{ + if (ns->params.max_active_zones !=3D 0 && + ns->nr_active_zones + act > ns->params.max_active_zones) { + trace_pci_nvme_err_insuff_active_res(ns->params.max_active_zones); + return NVME_ZONE_TOO_MANY_ACTIVE | NVME_DNR; + } + if (ns->params.max_open_zones !=3D 0 && + ns->nr_open_zones + opn > ns->params.max_open_zones) { + trace_pci_nvme_err_insuff_open_res(ns->params.max_open_zones); + return NVME_ZONE_TOO_MANY_OPEN | NVME_DNR; + } + + return NVME_SUCCESS; +} + static bool nvme_addr_is_cmb(NvmeCtrl *n, hwaddr addr) { hwaddr low =3D n->ctrl_mem.addr; @@ -1127,6 +1147,40 @@ static uint16_t nvme_check_zone_read(NvmeNamespace *= ns, uint64_t slba, return status; } =20 +static void nvme_auto_transition_zone(NvmeNamespace *ns) +{ + NvmeZone *zone; + + if (ns->params.max_open_zones && + ns->nr_open_zones =3D=3D ns->params.max_open_zones) { + zone =3D QTAILQ_FIRST(&ns->imp_open_zones); + if (zone) { + /* + * Automatically close this implicitly open zone. + */ + QTAILQ_REMOVE(&ns->imp_open_zones, zone, entry); + nvme_aor_dec_open(ns); + nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_CLOSED); + } + } +} + +static uint16_t nvme_auto_open_zone(NvmeNamespace *ns, NvmeZone *zone) +{ + uint16_t status =3D NVME_SUCCESS; + uint8_t zs =3D nvme_get_zone_state(zone); + + if (zs =3D=3D NVME_ZONE_STATE_EMPTY) { + nvme_auto_transition_zone(ns); + status =3D nvme_aor_check(ns, 1, 1); + } else if (zs =3D=3D NVME_ZONE_STATE_CLOSED) { + nvme_auto_transition_zone(ns); + status =3D nvme_aor_check(ns, 0, 1); + } + + return status; +} + static void nvme_finalize_zoned_write(NvmeNamespace *ns, NvmeRequest *req, bool failed) { @@ -1147,7 +1201,11 @@ static void nvme_finalize_zoned_write(NvmeNamespace = *ns, NvmeRequest *req, switch (nvme_get_zone_state(zone)) { case NVME_ZONE_STATE_IMPLICITLY_OPEN: case NVME_ZONE_STATE_EXPLICITLY_OPEN: + nvme_aor_dec_open(ns); + /* fall through */ case NVME_ZONE_STATE_CLOSED: + nvme_aor_dec_active(ns); + /* fall through */ case NVME_ZONE_STATE_EMPTY: nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_FULL); /* fall through */ @@ -1174,7 +1232,10 @@ static uint64_t nvme_advance_zone_wp(NvmeNamespace *= ns, NvmeZone *zone, zs =3D nvme_get_zone_state(zone); switch (zs) { case NVME_ZONE_STATE_EMPTY: + nvme_aor_inc_active(ns); + /* fall through */ case NVME_ZONE_STATE_CLOSED: + nvme_aor_inc_open(ns); nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_IMPLICITLY_OP= EN); } } @@ -1448,6 +1509,11 @@ static uint16_t nvme_do_write(NvmeCtrl *n, NvmeReque= st *req, bool append, goto invalid; } =20 + status =3D nvme_auto_open_zone(ns, zone); + if (status !=3D NVME_SUCCESS) { + goto invalid; + } + if (append) { slba =3D zone->w_ptr; } @@ -1543,9 +1609,26 @@ enum NvmeZoneProcessingMask { static uint16_t nvme_open_zone(NvmeNamespace *ns, NvmeZone *zone, enum NvmeZoneState state) { + uint16_t status; + switch (state) { case NVME_ZONE_STATE_EMPTY: + status =3D nvme_aor_check(ns, 1, 0); + if (status !=3D NVME_SUCCESS) { + return status; + } + nvme_aor_inc_active(ns); + /* fall through */ case NVME_ZONE_STATE_CLOSED: + status =3D nvme_aor_check(ns, 0, 1); + if (status !=3D NVME_SUCCESS) { + if (state =3D=3D NVME_ZONE_STATE_EMPTY) { + nvme_aor_dec_active(ns); + } + return status; + } + nvme_aor_inc_open(ns); + /* fall through */ case NVME_ZONE_STATE_IMPLICITLY_OPEN: nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_EXPLICITLY_OPEN); /* fall through */ @@ -1562,6 +1645,7 @@ static uint16_t nvme_close_zone(NvmeNamespace *ns, Nv= meZone *zone, switch (state) { case NVME_ZONE_STATE_EXPLICITLY_OPEN: case NVME_ZONE_STATE_IMPLICITLY_OPEN: + nvme_aor_dec_open(ns); nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_CLOSED); /* fall through */ case NVME_ZONE_STATE_CLOSED: @@ -1577,7 +1661,11 @@ static uint16_t nvme_finish_zone(NvmeNamespace *ns, = NvmeZone *zone, switch (state) { case NVME_ZONE_STATE_EXPLICITLY_OPEN: case NVME_ZONE_STATE_IMPLICITLY_OPEN: + nvme_aor_dec_open(ns); + /* fall through */ case NVME_ZONE_STATE_CLOSED: + nvme_aor_dec_active(ns); + /* fall through */ case NVME_ZONE_STATE_EMPTY: zone->w_ptr =3D nvme_zone_wr_boundary(zone); zone->d.wp =3D zone->w_ptr; @@ -1596,7 +1684,11 @@ static uint16_t nvme_reset_zone(NvmeNamespace *ns, N= vmeZone *zone, switch (state) { case NVME_ZONE_STATE_EXPLICITLY_OPEN: case NVME_ZONE_STATE_IMPLICITLY_OPEN: + nvme_aor_dec_open(ns); + /* fall through */ case NVME_ZONE_STATE_CLOSED: + nvme_aor_dec_active(ns); + /* fall through */ case NVME_ZONE_STATE_FULL: zone->w_ptr =3D zone->d.zslba; zone->d.wp =3D zone->w_ptr; diff --git a/hw/block/trace-events b/hw/block/trace-events index 63db3a353e..0b8564e028 100644 --- a/hw/block/trace-events +++ b/hw/block/trace-events @@ -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 statu= s) "slba=3D%"PRIu64", nlb=3D%"PRIu32", status=3D0x%"PRIx16"" pci_nvme_err_zone_read_not_ok(uint64_t slba, uint32_t nlb, uint32_t status= ) "slba=3D%"PRIu64", nlb=3D%"PRIu32", status=3D0x%"PRIx16"" pci_nvme_err_append_too_large(uint64_t slba, uint32_t nlb, uint8_t zasl) "= slba=3D%"PRIu64", nlb=3D%"PRIu32", zasl=3D%"PRIu8"" +pci_nvme_err_insuff_active_res(uint32_t max_active) "max_active=3D%"PRIu32= " zone limit exceeded" +pci_nvme_err_insuff_open_res(uint32_t max_open) "max_open=3D%"PRIu32" zone= limit exceeded" pci_nvme_err_invalid_iocsci(uint32_t idx) "unsupported command set combina= tion index %"PRIu32"" pci_nvme_err_invalid_del_sq(uint16_t qid) "invalid submission queue deleti= on, sid=3D%"PRIu16"" pci_nvme_err_invalid_create_sq_cqid(uint16_t cqid) "failed creating submis= sion queue, invalid cqid=3D%"PRIu16"" --=20 2.28.0 From nobody Fri May 10 12:23:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1607463887; cv=none; d=zohomail.com; s=zohoarc; b=e+ujjufCxSlUgPs5J0UytpmR9DcQtU1g5PK0wrHcZcVrbI/RWUDww2CYEQfl3EB1a+3EM3ZNMn2hgJLTPLrc8Pg8Qi+JbhQy5F7FJV2y1n0XYFvzudCqmRt0vxSyVZrMRMG3RMrZGnQaQW8y70UfhnhH+tVEmlCVNXniV9TzW/8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607463887; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qpp/aAG84rxk60WCisZA1p9VxLXklzQvqyJ6PTcQPRg=; b=nr/hthrog4qlYeq82zXnTf5JShjmnozaveofwSAZKRUlMu/eBcsoz4aECmu+tEAapc7w9bszFFcg3msE8ntxecFMxLs2pqcP+bn6/xgPAsK2+7bBu3BNKR7f1KoX1QUVH7vuUQO4oZVBkJBSMrGNaOUk6SCfAxCXDhn8jdKhdpM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1607463887231287.07309560350575; Tue, 8 Dec 2020 13:44:47 -0800 (PST) Received: from localhost ([::1]:45874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmkHb-00078b-UB for importer@patchew.org; Tue, 08 Dec 2020 16:12:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjEE-0002dO-1Y; Tue, 08 Dec 2020 15:04:54 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:42913) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjE5-00063N-P1; Tue, 08 Dec 2020 15:04:53 -0500 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Dec 2020 04:20:55 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2020 11:48:39 -0800 Received: from unknown (HELO redsun50.ssa.fujisawa.hgst.com) ([10.149.66.24]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Dec 2020 12:04:38 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1607458864; x=1638994864; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YYdJbstkh+aRV4BM+aA/DjDY5eQaoZFmh58Kl1dML9g=; b=mC/WVapf43jfjUw38hMUc6VUs4wnNef01aCyeeC53QL5hL9RT7C+xKV5 sQjjR+uXRG7s2rbzuTQ1CKeEU/Utnvyn40wWrvvc0HdM5tAe9sx1WVmDW iHnXXuTI1xUr04DlYB4Glg64vcX+ro2fF16E9OoSvANpwlX7T6tsvw8Nl RND0pfy8XFau9vTEoMNBzJHrlGhpciMmH+sPTa4ohLCl0o5n3D+SaLkTp xxiJ8ShNKotWFrOQ+ANKliPc3R6aaR+PBPEDd7ev7+9IsuHVY2PDi7yEu GRd8ZfwscA1BIxin0PMP6bXIsHi/cMjsw6YRPZ4DJcPNCeJwtjv+ZKD1K A==; IronPort-SDR: x55pw8SIEQIst9auC6VBoaLGH0qYIhArQb5hgNXgmcVbk1lqOa8qabQIgHWUq9q0s5wUQDRqFc iejKzNqH8qmOEIWdmI0775aG/D+9dukRjL12gvNxku2Hvd/kC9Fn6Go1zoGvKhUT7kMYsBdirp vDU7Vf34dzr+xcYABtHKx1x4twi4DaVW/6SOVNh1SU8UYZ5m10URWPpI1eix1Ziw0F6b6qnTQA 0p48vK0J8p1m/3aS3Z7F+OwbPy1CP18cgb899qcUjbRiR3GtrhBXfIEDRzr+aJMb+3tA0pX3/s nlQ= X-IronPort-AV: E=Sophos;i="5.78,403,1599494400"; d="scan'208";a="258433473" IronPort-SDR: /h/AIaYrN1w37Qf+imYVyZjtL9sVaFcKSKynG+xpUS+QIlUGKrDNTx6Ap9wu3RbMZm9JXJhH8y wjQ+kYfsTnvkv4ovYks3I75FpW+nFwkTQ= IronPort-SDR: gL5ce9xBDatBaNKS7dXprJPV3tQX/ctaXuFN0hILrr4wik1aO0F/UD/OxLgaMAIJh8ow2zInux Sd66413xhRiA== WDCIronportException: Internal From: Dmitry Fomichev To: Keith Busch , Klaus Jensen , Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Max Reitz , Maxim Levitsky , Fam Zheng Subject: [PATCH v11 11/13] hw/block/nvme: Support Zone Descriptor Extensions Date: Wed, 9 Dec 2020 05:04:08 +0900 Message-Id: <20201208200410.27900-12-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201208200410.27900-1-dmitry.fomichev@wdc.com> References: <20201208200410.27900-1-dmitry.fomichev@wdc.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=68.232.143.124; envelope-from=prvs=604abd949=dmitry.fomichev@wdc.com; helo=esa2.hgst.iphmx.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Niklas Cassel , Damien Le Moal , qemu-block@nongnu.org, Dmitry Fomichev , qemu-devel@nongnu.org, Alistair Francis , Matias Bjorling Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Zone 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. Signed-off-by: Hans Holmberg Signed-off-by: Dmitry Fomichev Reviewed-by: Klaus Jensen Reviewed-by: Niklas Cassel Reviewed-by: Keith Busch --- 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(-) diff --git a/hw/block/nvme-ns.h b/hw/block/nvme-ns.h index 7e1fd26909..f8f3c28c36 100644 --- a/hw/block/nvme-ns.h +++ b/hw/block/nvme-ns.h @@ -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; =20 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; =20 @@ -129,6 +131,12 @@ static inline bool nvme_wp_is_valid(NvmeZone *zone) st !=3D NVME_ZONE_STATE_OFFLINE; } =20 +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 >=3D 0); diff --git a/hw/block/nvme-ns.c b/hw/block/nvme-ns.c index aaef69fb47..c5a7bafcf7 100644 --- a/hw/block/nvme-ns.c +++ b/hw/block/nvme-ns.c @@ -151,6 +151,18 @@ static int nvme_ns_zoned_check_calc_geometry(NvmeNames= pace *ns, Error **errp) return -1; } =20 + 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; } =20 @@ -162,6 +174,10 @@ static void nvme_ns_zoned_init_state(NvmeNamespace *ns) int i; =20 ns->zone_array =3D g_new0(NvmeZone, ns->num_zones); + if (ns->params.zd_extension_size) { + ns->zd_extensions =3D g_malloc0(ns->params.zd_extension_size * + ns->num_zones); + } =20 QTAILQ_INIT(&ns->exp_open_zones); QTAILQ_INIT(&ns->imp_open_zones); @@ -204,7 +220,8 @@ static void nvme_ns_init_zoned(NvmeCtrl *n, NvmeNamespa= ce *ns, int lba_index) id_ns_z->ozcs =3D ns->params.cross_zone_read ? 0x01 : 0x00; =20 id_ns_z->lbafe[lba_index].zsze =3D cpu_to_le64(ns->zone_size); - id_ns_z->lbafe[lba_index].zdes =3D 0; + id_ns_z->lbafe[lba_index].zdes =3D + ns->params.zd_extension_size >> 6; /* Units of 64B */ =20 ns->csi =3D NVME_CSI_ZONED; ns->id_ns.nsze =3D cpu_to_le64(ns->num_zones * ns->zone_size); @@ -220,7 +237,8 @@ static void nvme_clear_zone(NvmeNamespace *ns, NvmeZone= *zone) =20 zone->w_ptr =3D zone->d.wp; state =3D nvme_get_zone_state(zone); - if (zone->d.wp !=3D zone->d.zslba) { + if (zone->d.wp !=3D zone->d.zslba || + (zone->d.za & NVME_ZA_ZD_EXT_VALID)) { if (state !=3D 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); } } =20 @@ -347,6 +366,8 @@ static Property nvme_ns_props[] =3D { 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(), }; =20 diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 8b97b713a3..c2336bfd67 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -1715,6 +1715,25 @@ static uint16_t nvme_offline_zone(NvmeNamespace *ns,= NvmeZone *zone, } } =20 +static uint16_t nvme_set_zd_ext(NvmeNamespace *ns, NvmeZone *zone) +{ + uint16_t status; + uint8_t state =3D nvme_get_zone_state(zone); + + if (state =3D=3D NVME_ZONE_STATE_EMPTY) { + status =3D nvme_aor_check(ns, 1, 0); + if (status !=3D NVME_SUCCESS) { + return status; + } + nvme_aor_inc_active(ns); + zone->d.za |=3D NVME_ZA_ZD_EXT_VALID; + nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_CLOSED); + return NVME_SUCCESS; + } + + return NVME_ZONE_INVAL_TRANSITION; +} + static uint16_t nvme_bulk_proc_zone(NvmeNamespace *ns, NvmeZone *zone, enum NvmeZoneProcessingMask proc_mask, op_handler_t op_hndlr) @@ -1813,6 +1832,7 @@ static uint16_t nvme_zone_mgmt_send(NvmeCtrl *n, Nvme= Request *req) NvmeCmd *cmd =3D (NvmeCmd *)&req->cmd; NvmeNamespace *ns =3D req->ns; NvmeZone *zone; + uint8_t *zd_ext; uint32_t dw13 =3D le32_to_cpu(cmd->cdw13); uint64_t slba =3D 0; uint32_t zone_idx =3D 0; @@ -1885,7 +1905,22 @@ static uint16_t nvme_zone_mgmt_send(NvmeCtrl *n, Nvm= eRequest *req) =20 case NVME_ZONE_ACTION_SET_ZD_EXT: trace_pci_nvme_set_descriptor_extension(slba, zone_idx); - return NVME_INVALID_FIELD | NVME_DNR; + if (all || !ns->params.zd_extension_size) { + return NVME_INVALID_FIELD | NVME_DNR; + } + zd_ext =3D nvme_get_zd_extension(ns, zone_idx); + status =3D nvme_dma(n, zd_ext, ns->params.zd_extension_size, + DMA_DIRECTION_TO_DEVICE, req); + if (status) { + trace_pci_nvme_err_zd_extension_map_error(zone_idx); + return status; + } + + status =3D nvme_set_zd_ext(ns, zone); + if (status =3D=3D NVME_SUCCESS) { + trace_pci_nvme_zd_extension_set(zone_idx); + return status; + } break; =20 default: @@ -1955,7 +1990,10 @@ static uint16_t nvme_zone_mgmt_recv(NvmeCtrl *n, Nvm= eRequest *req) } =20 zra =3D dw13 & 0xff; - if (zra !=3D NVME_ZONE_REPORT) { + if (zra !=3D NVME_ZONE_REPORT && zra !=3D NVME_ZONE_REPORT_EXTENDED) { + return NVME_INVALID_FIELD | NVME_DNR; + } + if (zra =3D=3D NVME_ZONE_REPORT_EXTENDED && !ns->params.zd_extension_s= ize) { return NVME_INVALID_FIELD | NVME_DNR; } =20 @@ -1977,6 +2015,9 @@ static uint16_t nvme_zone_mgmt_recv(NvmeCtrl *n, Nvme= Request *req) partial =3D (dw13 >> 16) & 0x01; =20 zone_entry_sz =3D sizeof(NvmeZoneDescr); + if (zra =3D=3D NVME_ZONE_REPORT_EXTENDED) { + zone_entry_sz +=3D ns->params.zd_extension_size; + } =20 max_zones =3D (data_size - sizeof(NvmeZoneReportHeader)) / zone_entry_= sz; buf =3D g_malloc0(data_size); @@ -2012,6 +2053,14 @@ static uint16_t nvme_zone_mgmt_recv(NvmeCtrl *n, Nvm= eRequest *req) z->wp =3D cpu_to_le64(~0ULL); } =20 + if (zra =3D=3D NVME_ZONE_REPORT_EXTENDED) { + if (zone->d.za & NVME_ZA_ZD_EXT_VALID) { + memcpy(buf_p, nvme_get_zd_extension(ns, zone_idx), + ns->params.zd_extension_size); + } + buf_p +=3D ns->params.zd_extension_size; + } + max_zones--; } } diff --git a/hw/block/trace-events b/hw/block/trace-events index 0b8564e028..0b7a132c88 100644 --- a/hw/block/trace-events +++ b/hw/block/trace-events @@ -99,6 +99,7 @@ pci_nvme_finish_zone(uint64_t slba, uint32_t zone_idx, in= t all) "finish zone, sl pci_nvme_reset_zone(uint64_t slba, uint32_t zone_idx, int all) "reset zone= , slba=3D%"PRIu64", idx=3D%"PRIu32", all=3D%"PRIi32"" pci_nvme_offline_zone(uint64_t slba, uint32_t zone_idx, int all) "offline = zone, slba=3D%"PRIu64", idx=3D%"PRIu32", all=3D%"PRIi32"" pci_nvme_set_descriptor_extension(uint64_t slba, uint32_t zone_idx) "set z= one descriptor extension, slba=3D%"PRIu64", idx=3D%"PRIu32"" +pci_nvme_zd_extension_set(uint32_t zone_idx) "set descriptor extension for= zone_idx=3D%"PRIu32"" pci_nvme_clear_ns_close(uint32_t state, uint64_t slba) "zone state=3D%"PRI= u32", slba=3D%"PRIu64" transitioned to Closed state" pci_nvme_clear_ns_reset(uint32_t state, uint64_t slba) "zone state=3D%"PRI= u32", slba=3D%"PRIu64" transitioned to Empty state" =20 @@ -128,6 +129,7 @@ pci_nvme_err_zone_read_not_ok(uint64_t slba, uint32_t n= lb, uint32_t status) "slb pci_nvme_err_append_too_large(uint64_t slba, uint32_t nlb, uint8_t zasl) "= slba=3D%"PRIu64", nlb=3D%"PRIu32", zasl=3D%"PRIu8"" pci_nvme_err_insuff_active_res(uint32_t max_active) "max_active=3D%"PRIu32= " zone limit exceeded" pci_nvme_err_insuff_open_res(uint32_t max_open) "max_open=3D%"PRIu32" zone= limit exceeded" +pci_nvme_err_zd_extension_map_error(uint32_t zone_idx) "can't map descript= or extension for zone_idx=3D%"PRIu32"" pci_nvme_err_invalid_iocsci(uint32_t idx) "unsupported command set combina= tion index %"PRIu32"" pci_nvme_err_invalid_del_sq(uint16_t qid) "invalid submission queue deleti= on, sid=3D%"PRIu16"" pci_nvme_err_invalid_create_sq_cqid(uint16_t cqid) "failed creating submis= sion queue, invalid cqid=3D%"PRIu16"" --=20 2.28.0 From nobody Fri May 10 12:23:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1607463332; cv=none; d=zohomail.com; s=zohoarc; b=XXLNTv8bfaJ3jWJTRZZh1yFZPmpJRowQWVvJs5bLm4OlClDZGnLVhVdoJZAXQpeZLyWUdEp9zVd9LrECL0NGC80y6NCw5bg6RtdNPk3B4OWtfsvhgNbXKo7h7wP6XkUeRqTf8hTQc0vvxsagriHMMQqpnqwR7u9cIeFkbbUbBaw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607463332; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OVhJbvc3Zu1PfXqY+rVRguNfGlTOeIEyQOXTMWu9Fl8=; b=R5m0N6LpEp2ModxzK6McC5suvy0cM1+PxAr+4Amoodbu8hxQonDxVpFJv1scLdB7dRzNemiIfM1NSrkI2zfXV13ehb6OOAjnvhulWIRtP4Y9v8FmCUk8kQHpJM3q7riWGByEOaBg5q2sit0x5yxeDC1qBz3xy8BnZsxB/aDUdcI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1607463332155114.55254657824798; Tue, 8 Dec 2020 13:35:32 -0800 (PST) Received: from localhost ([::1]:39298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmkdu-0003BI-Un for importer@patchew.org; Tue, 08 Dec 2020 16:35:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjEV-00033E-I0; Tue, 08 Dec 2020 15:05:11 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:42896) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjET-000629-IE; Tue, 08 Dec 2020 15:05:11 -0500 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Dec 2020 04:20:58 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2020 11:48:42 -0800 Received: from unknown (HELO redsun50.ssa.fujisawa.hgst.com) ([10.149.66.24]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Dec 2020 12:04:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1607458900; x=1638994900; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=T/oSkf5co6fKvQt3ZORqKoEh2faB4xCiTnvi9Se7Pwo=; b=ahDKvG51EE/UeYTtAiJ5piTlOXoQxomjqLzRxEcTdGmk+SO4WT9RvGJ5 9VngavzGCH0IsGgu7LkNNn4MQYUc4V5/fNUm5YmfzlTe2JFrNuhga8cUx 0tXj+2XvBdE5Vl2Zz9tyOtV+gcPmqRoOlIZSQJcCnmIOacfxpyIIV8rd3 k0IelwsZoxeWSIHiTATj5a2bhfCkUiAlGVDPR6Li+RrV6KZ/3ilk0PB6U cAO4XalwCXjMCpuS0f/Bap8IrgrPSExO2gRm1QE+nYX73BmmF3Xe+SImM jSiCEihQuuMdbkhk4/smhUw/y9urySzELfLItZ5Hx7Lsy6aw3zEsFq7Ri Q==; IronPort-SDR: vCkdPSrDu/kh+0MIpd84p/9FGpaYY4ovrc5067ENglRKruViDGwWXv448bA3hSVpdPOift4c0c WpzCmmLtCwN1xTUUUdphuQCsH5XqYajLCApA05GrvKqNFx9Ss4KTjlanMabMEqjG1OizigcGa1 IxbOUuIJU+I7XqK9tqGVk3XERnkhzo3u3uQKmkELHFcMB5G16gvzXhs1s9vpucs8FCOD+i26qk DPAQ9d47mBCVC0N0GKMBIGJcl8+7ANqXBZYsZLyeaHYIbAaLq8VdJI+z8+CyQ045fdeq2TGiLy lbI= X-IronPort-AV: E=Sophos;i="5.78,403,1599494400"; d="scan'208";a="258433477" IronPort-SDR: kLil+wDbz/CMxTAWNBREH5HjQUIZ9EMSnrHOf+LNr9Z7RYlRXt4qibJKOcrG3iRDPTPXghSsDj rsNQk3gmb7R86bIX1kAXvRPJ4qE//Z+1o= IronPort-SDR: +DIUjFUUA0kSevVfoDjEXtqlL9UZAsQbuSDvENZrbpKOlCTlj/Dc7rp0zMWZ1ww7/RkPJwQosl IBdttgjOSVDQ== WDCIronportException: Internal From: Dmitry Fomichev To: Keith Busch , Klaus Jensen , Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Max Reitz , Maxim Levitsky , Fam Zheng Subject: [PATCH v11 12/13] hw/block/nvme: Add injection of Offline/Read-Only zones Date: Wed, 9 Dec 2020 05:04:09 +0900 Message-Id: <20201208200410.27900-13-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201208200410.27900-1-dmitry.fomichev@wdc.com> References: <20201208200410.27900-1-dmitry.fomichev@wdc.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=68.232.143.124; envelope-from=prvs=604abd949=dmitry.fomichev@wdc.com; helo=esa2.hgst.iphmx.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Niklas Cassel , Damien Le Moal , qemu-block@nongnu.org, Dmitry Fomichev , qemu-devel@nongnu.org, Alistair Francis , Matias Bjorling Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Dmitry Fomichev Reviewed-by: Niklas Cassel Reviewed-by: Keith Busch Reviewed-by: Klaus Jensen --- hw/block/nvme-ns.h | 2 ++ hw/block/nvme-ns.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/hw/block/nvme-ns.h b/hw/block/nvme-ns.h index f8f3c28c36..1196865b7a 100644 --- a/hw/block/nvme-ns.h +++ b/hw/block/nvme-ns.h @@ -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; =20 typedef struct NvmeNamespace { diff --git a/hw/block/nvme-ns.c b/hw/block/nvme-ns.c index c5a7bafcf7..0a8b741bc9 100644 --- a/hw/block/nvme-ns.c +++ b/hw/block/nvme-ns.c @@ -21,6 +21,7 @@ #include "sysemu/sysemu.h" #include "sysemu/block-backend.h" #include "qapi/error.h" +#include "crypto/random.h" =20 #include "hw/qdev-properties.h" #include "hw/qdev-core.h" @@ -163,6 +164,21 @@ static int nvme_ns_zoned_check_calc_geometry(NvmeNames= pace *ns, Error **errp) } } =20 + if (ns->params.max_open_zones < ns->num_zones) { + if (ns->params.nr_offline_zones > + ns->num_zones - ns->params.max_open_zones) { + error_setg(errp, "offline_zones value %u is too large", + ns->params.nr_offline_zones); + return -1; + } + if (ns->params.nr_rdonly_zones + ns->params.nr_offline_zones > + ns->num_zones - ns->params.max_open_zones) { + error_setg(errp, "rdonly_zones value %u is too large", + ns->params.nr_rdonly_zones); + return -1; + } + } + return 0; } =20 @@ -171,7 +187,9 @@ static void nvme_ns_zoned_init_state(NvmeNamespace *ns) uint64_t start =3D 0, zone_size =3D ns->zone_size; uint64_t capacity =3D ns->num_zones * zone_size; NvmeZone *zone; + uint32_t rnd; int i; + uint16_t zs; =20 ns->zone_array =3D g_new0(NvmeZone, ns->num_zones); if (ns->params.zd_extension_size) { @@ -203,6 +221,37 @@ static void nvme_ns_zoned_init_state(NvmeNamespace *ns) if (is_power_of_2(ns->zone_size)) { ns->zone_size_log2 =3D 63 - clz64(ns->zone_size); } + + /* If required, make some zones Offline or Read Only */ + + for (i =3D 0; i < ns->params.nr_offline_zones; i++) { + do { + qcrypto_random_bytes(&rnd, sizeof(rnd), NULL); + rnd %=3D ns->num_zones; + } while (rnd < ns->params.max_open_zones); + zone =3D &ns->zone_array[rnd]; + zs =3D nvme_get_zone_state(zone); + if (zs !=3D NVME_ZONE_STATE_OFFLINE) { + nvme_set_zone_state(zone, NVME_ZONE_STATE_OFFLINE); + } else { + i--; + } + } + + for (i =3D 0; i < ns->params.nr_rdonly_zones; i++) { + do { + qcrypto_random_bytes(&rnd, sizeof(rnd), NULL); + rnd %=3D ns->num_zones; + } while (rnd < ns->params.max_open_zones); + zone =3D &ns->zone_array[rnd]; + zs =3D nvme_get_zone_state(zone); + if (zs !=3D NVME_ZONE_STATE_OFFLINE && + zs !=3D NVME_ZONE_STATE_READ_ONLY) { + nvme_set_zone_state(zone, NVME_ZONE_STATE_READ_ONLY); + } else { + i--; + } + } } =20 static void nvme_ns_init_zoned(NvmeCtrl *n, NvmeNamespace *ns, int lba_ind= ex) @@ -368,6 +417,10 @@ static Property nvme_ns_props[] =3D { params.max_open_zones, 0), DEFINE_PROP_UINT32("zoned.descr_ext_size", NvmeNamespace, params.zd_extension_size, 0), + DEFINE_PROP_UINT32("zoned.offline_zones", NvmeNamespace, + params.nr_offline_zones, 0), + DEFINE_PROP_UINT32("zoned.rdonly_zones", NvmeNamespace, + params.nr_rdonly_zones, 0), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.28.0 From nobody Fri May 10 12:23:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1607462692; cv=none; d=zohomail.com; s=zohoarc; b=BrwFPKvMUdXUa0B1e3WMSU3pPNn8UpuN2FFge3bInMr/x+JVTB+H+VrNzWIPhR3Tego4K8B5W7I4nZzWmPTTRt0m8tTOCnKKdO/yk+3f7Pqufe66Kh7/vduWGmSyO2eXcNB+t1wmJ0jLTrR41/PABo15LWAv7fs9IZc8v1PB7cs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607462692; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Kv3zNTub/HuZjYkHZrPRnUvA2dPzpYJH06/TmMI81+A=; b=iMMP0eiW+IkvH25ORCjSNGqW63BeLpcKjOBwPZ8rdFTq/VX9CgllpySZ34pgPq886lczSctkvfW0AG7yEgbB1OodOVF0oikR0J0/2KsmDnvZ+0IrXu3Oi4BFQ9nzN6j22iCGZhTLzg1vWBZux88TfUcRr4PfHjbSoy6eHYHpB94= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1607462692790863.6173236581304; Tue, 8 Dec 2020 13:24:52 -0800 (PST) Received: from localhost ([::1]:43850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmkTb-0001bt-L3 for importer@patchew.org; Tue, 08 Dec 2020 16:24:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjEa-00037v-07; Tue, 08 Dec 2020 15:05:16 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:42903) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmjEX-00062i-Vy; Tue, 08 Dec 2020 15:05:15 -0500 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Dec 2020 04:21:02 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2020 11:48:44 -0800 Received: from unknown (HELO redsun50.ssa.fujisawa.hgst.com) ([10.149.66.24]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Dec 2020 12:04:43 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1607458907; x=1638994907; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/IGJYqm9RK5e5DNI9iQEd33TlkrwUOrLHugKF2LwdZs=; b=SIQ6/HGR3R5cNYLanBE4bxDesHQqequ/OHS9purbnZAQbZKZKkAg09uO N2r2y3PqxZg87PemuVrckJ6iYNu2h9F4OBUafEOlKOszSWuATtvuwmrjG LNJ+hkoX4DiFPRj5F/lK2xrmZ+G51Apm8mbi6zgCyWODrULqPp04Fhsq7 E9HvOIEM5jHBMjbDeBP9bxT27EN9Tskn6N36+41cUd3c3bUNNpYSINYdl 2byn059DpTALHOriUxKXCDVWpX74IwgQo6foPSD5jSsD2Pssl6xUbPS2j HdABQWVuW/QVv15swCNnmmv4TdcoxyokNTg0Apdh7pOdzOSokOfDHzV+6 w==; IronPort-SDR: LSRq+Jg4DmY6y0e0vhTQ3yPec5h51C2EYNrPxqGBUKl5E3qOsMvb2eSciuApATphO0NZQZhD/6 ICIC9jAyTCsTOVpAjwTMTPm2fXZQSCwd2gA2rswrQY3lqzIpUTAmtb0XqlX44Ff4hmJrVvI9r2 Tdep25WJMAR+DPCi01botIMe/OMMBtvtfR7rWkUJ6eW8qE28WffWMebkg2aWjo0akPLUeC1iRz aoBfLsXaf6wMvHJMw9cReI6WbxqYM5DVBAQPe4AYpkESTsNZgc1F/JcWwzAvfNAFMbxDSP0awu Z6Q= X-IronPort-AV: E=Sophos;i="5.78,403,1599494400"; d="scan'208";a="258433482" IronPort-SDR: N7PNgYjW0lzh43UmaDjyt5KCfSqaubk1hVi3irV0E6+GretKHaLJ9cWIvabXmdte01p91F/FSV UqrhdG7KiiRqzfDR0bDYfwjlXLLftB3qo= IronPort-SDR: dI51EYu48+jrtAm2M+F+CyUIeJPtAm732Rbfu0dbsdK6ySdfnPQjkks/qRE9r5QuuI6fDZrmdA cy0dExN7juHg== WDCIronportException: Internal From: Dmitry Fomichev To: Keith Busch , Klaus Jensen , Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Max Reitz , Maxim Levitsky , Fam Zheng Subject: [PATCH v11 13/13] hw/block/nvme: Document zoned parameters in usage text Date: Wed, 9 Dec 2020 05:04:10 +0900 Message-Id: <20201208200410.27900-14-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201208200410.27900-1-dmitry.fomichev@wdc.com> References: <20201208200410.27900-1-dmitry.fomichev@wdc.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=68.232.143.124; envelope-from=prvs=604abd949=dmitry.fomichev@wdc.com; helo=esa2.hgst.iphmx.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Niklas Cassel , Damien Le Moal , qemu-block@nongnu.org, Dmitry Fomichev , qemu-devel@nongnu.org, Alistair Francis , Matias Bjorling Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Added 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. Signed-off-by: Dmitry Fomichev Reviewed-by: Niklas Cassel Reviewed-by: Keith Busch Reviewed-by: Klaus Jensen --- hw/block/nvme.c | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index c2336bfd67..fbb69c82c6 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -9,7 +9,7 @@ */ =20 /** - * 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=3D,] \ * max_ioqpairs=3D, \ * aerl=3D, aer_max_queued=3D, \ - * mdts=3D - * -device nvme-ns,drive=3D,bus=3Dbus_name,nsid=3D + * mdts=3D,zoned.append_size_limit=3D \ + * -device nvme-ns,drive=3D,bus=3D,nsid=3D,\ + * zoned=3D * * 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 nu= mber - * of concurrently outstanding Asynchronous Event Request commands suppo= ert + * of concurrently outstanding Asynchronous Event Request commands suppo= rt * 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 numbe= r 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 =3D log2( / ), some values assig= ned + * 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 m= ake + * 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 confi= gure + * zoned operation: + * zoned.zsze=3D + * The number may be followed by K, M, G as in kilo-, mega- or gig= a-. + * + * zoned.zcap=3D + * The value 0 (default) forces zone capacity to be the same as zo= ne + * size. The value of this property may not exceed zone size. + * + * zoned.descr_ext_size=3D + * This value needs to be specified in 64B units. If it is zero, + * namespace(s) will not support zone descriptor extensions. + * + * zoned.max_active=3D + * The default value means there is no limit to the number of + * concurrently active zones. + * + * zoned.max_open=3D + * The default value means there is no limit to the number of + * concurrently open zones. + * + * zoned.offline_zones=3D + * + * zoned.rdonly_zones=3D + * + * zoned.cross_zone_read=3D + * Setting this property to true enables Read Across Zone Boundari= es. */ =20 #include "qemu/osdep.h" --=20 2.28.0