From patchwork Sun Feb 28 16:10:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minwoo Im X-Patchwork-Id: 1445289 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=udqT+C0E; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DpVnS54nYz9sCD for ; Mon, 1 Mar 2021 04:31:56 +1100 (AEDT) Received: from localhost ([::1]:43898 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGPv8-0000fu-LE for incoming@patchwork.ozlabs.org; Sun, 28 Feb 2021 12:31:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58418) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGPle-0007pP-Qg; Sun, 28 Feb 2021 12:22:08 -0500 Received: from mail-qv1-xf36.google.com ([2607:f8b0:4864:20::f36]:40241) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lGPlW-00047p-My; Sun, 28 Feb 2021 12:22:05 -0500 Received: by mail-qv1-xf36.google.com with SMTP id x13so1083999qvj.7; Sun, 28 Feb 2021 09:21:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vq7m2qWiz2ZKHd4pw2FvIWA7GNMpRgNfXW9Pd8y/Wng=; b=udqT+C0EKRMR4rnXzfcSR/1CFFSnk+w83g9GFb8HkFm5PirYQYvO2AQ2mNrijjK0yp /8wDIB3pLRD8f6N0FxEBhcIxqyiz1i6+zt9w/kQbMWlbNqBxUwgTdg+1lYuAKjNI0pkd kojrUssmwNdbAqbuMVBOX1Ovha3FNt9Q8rs4xQrOIoQ9UyB5cieHp2IXknsC2/xo1WD7 myvw+trwc56OxeD6e5ilTwJ9NXJPXqsnWy/69Wbyk5UrXuKoAf5Xjt+ScPP7Pq7vAK+R DTOAzdDAogoe6y7+T03beqd6OMjf6o0eZsGtIpbgY8j3DlOmCnMZWUuWYLfFDyo4diKU Jd1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vq7m2qWiz2ZKHd4pw2FvIWA7GNMpRgNfXW9Pd8y/Wng=; b=VVsGmlu+3VgMAkrMm73TYmCr+ryWZXER+JytYRqTqFuiC0b3A7KERgsORLaVvZLZaV X5euBsl+mga12/vgqCohkV4GmkMDBbvdaGWo9DRLm0GFD7/ZA6p2XlGu9jdXqTTu3KzN D7RoSDMkm9PBzpdOnAncGfYzXCjIo474e/C3Qpzoyn+NeQrXpHNi8L6OrHeL3x6biEr+ Ye33CPCfy0wQ9mom64/T31oyjwbpdNB4gA2wv1+ON792MvUzPgOLrACmVvxKZ615YWMt QqRXw94S37MH7XobenjyCyqTa6DkONJdiqZ40pEQ19PdcDrpJfi9GHBK4AVQ+DU7P3XN hAxA== X-Gm-Message-State: AOAM530hH834mOed9ZbzZ0TS3mkNKG4V+VV2WrDhICw/LQRUj+bAfJle ge5AtyNGfr2q9xeJ9pn+teBcm7sPUm0toQ== X-Google-Smtp-Source: ABdhPJwAtyiU2RLHxL3mTfGRimBxR/XR8BbPZsQpWcySpVS6Ud4e9WDXE3LyVVWJ9isXTtfWtG1GrA== X-Received: by 2002:a17:902:207:b029:e4:471d:82a with SMTP id 7-20020a1709020207b02900e4471d082amr11717124plc.24.1614528670146; Sun, 28 Feb 2021 08:11:10 -0800 (PST) Received: from localhost.localdomain ([211.108.35.36]) by smtp.gmail.com with ESMTPSA id x11sm14389781pja.46.2021.02.28.08.11.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Feb 2021 08:11:09 -0800 (PST) From: Minwoo Im To: qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH V3 1/8] hw/block/nvme: support namespace detach Date: Mon, 1 Mar 2021 01:10:53 +0900 Message-Id: <20210228161100.54015-2-minwoo.im.dev@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210228161100.54015-1-minwoo.im.dev@gmail.com> References: <20210228161100.54015-1-minwoo.im.dev@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::f36; envelope-from=minwoo.im.dev@gmail.com; helo=mail-qv1-xf36.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Kevin Wolf , Klaus Jensen , Max Reitz , Klaus Jensen , Minwoo Im , Keith Busch Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Given that now we have nvme-subsys device supported, we can manage namespace allocated, but not attached: detached. This patch introduced a parameter for nvme-ns device named 'detached'. This parameter indicates whether the given namespace device is detached from a entire NVMe subsystem('subsys' given case, shared namespace) or a controller('bus' given case, private namespace). - Allocated namespace 1) Shared ns in the subsystem 'subsys0': -device nvme-ns,id=ns1,drive=blknvme0,nsid=1,subsys=subsys0,detached=true 2) Private ns for the controller 'nvme0' of the subsystem 'subsys0': -device nvme-subsys,id=subsys0 -device nvme,serial=foo,id=nvme0,subsys=subsys0 -device nvme-ns,id=ns1,drive=blknvme0,nsid=1,bus=nvme0,detached=true 3) (Invalid case) Controller 'nvme0' has no subsystem to manage ns: -device nvme,serial=foo,id=nvme0 -device nvme-ns,id=ns1,drive=blknvme0,nsid=1,bus=nvme0,detached=true Signed-off-by: Minwoo Im Tested-by: Klaus Jensen Reviewed-by: Klaus Jensen --- hw/block/nvme-ns.c | 1 + hw/block/nvme-ns.h | 1 + hw/block/nvme-subsys.h | 1 + hw/block/nvme.c | 41 +++++++++++++++++++++++++++++++++++++++-- hw/block/nvme.h | 22 ++++++++++++++++++++++ 5 files changed, 64 insertions(+), 2 deletions(-) diff --git a/hw/block/nvme-ns.c b/hw/block/nvme-ns.c index 0e8760020483..eda6a0c003a4 100644 --- a/hw/block/nvme-ns.c +++ b/hw/block/nvme-ns.c @@ -399,6 +399,7 @@ static Property nvme_ns_props[] = { DEFINE_BLOCK_PROPERTIES(NvmeNamespace, blkconf), DEFINE_PROP_LINK("subsys", NvmeNamespace, subsys, TYPE_NVME_SUBSYS, NvmeSubsystem *), + DEFINE_PROP_BOOL("detached", NvmeNamespace, params.detached, false), DEFINE_PROP_UINT32("nsid", NvmeNamespace, params.nsid, 0), DEFINE_PROP_UUID("uuid", NvmeNamespace, params.uuid), DEFINE_PROP_UINT16("mssrl", NvmeNamespace, params.mssrl, 128), diff --git a/hw/block/nvme-ns.h b/hw/block/nvme-ns.h index 7af6884862b5..b0c00e115d81 100644 --- a/hw/block/nvme-ns.h +++ b/hw/block/nvme-ns.h @@ -26,6 +26,7 @@ typedef struct NvmeZone { } NvmeZone; typedef struct NvmeNamespaceParams { + bool detached; uint32_t nsid; QemuUUID uuid; diff --git a/hw/block/nvme-subsys.h b/hw/block/nvme-subsys.h index ccf6a71398d3..890d118117dc 100644 --- a/hw/block/nvme-subsys.h +++ b/hw/block/nvme-subsys.h @@ -23,6 +23,7 @@ typedef struct NvmeSubsystem { uint8_t subnqn[256]; NvmeCtrl *ctrls[NVME_SUBSYS_MAX_CTRLS]; + /* Allocated namespaces for this subsystem */ NvmeNamespace *namespaces[NVME_SUBSYS_MAX_NAMESPACES]; } NvmeSubsystem; diff --git a/hw/block/nvme.c b/hw/block/nvme.c index edd0b85c10ce..f6aeae081840 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -23,7 +23,7 @@ * max_ioqpairs=, \ * aerl=, aer_max_queued=, \ * mdts=,zoned.append_size_limit=, \ - * subsys= \ + * subsys=,detached= * -device nvme-ns,drive=,bus=,nsid=,\ * zoned=, \ * subsys= @@ -82,6 +82,13 @@ * controllers in the subsystem. Otherwise, `bus` must be given to attach * this namespace to a specified single controller as a non-shared namespace. * + * - `detached` + * Not to attach the namespace device to controllers in the NVMe subsystem + * during boot-up. If not given, namespaces are all attahced to all + * controllers in the subsystem by default. + * It's mutual exclusive with 'bus' parameter. It's only valid in case + * `subsys` is provided. + * * Setting `zoned` to true selects Zoned Command Set at the namespace. * In this case, the following namespace properties are available to configure * zoned operation: @@ -4613,6 +4620,20 @@ static void nvme_init_state(NvmeCtrl *n) n->aer_reqs = g_new0(NvmeRequest *, n->params.aerl + 1); } +static int nvme_attach_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp) +{ + if (nvme_ns_is_attached(n, ns)) { + error_setg(errp, + "namespace %d is already attached to controller %d", + nvme_nsid(ns), n->cntlid); + return -1; + } + + nvme_ns_attach(n, ns); + + return 0; +} + int nvme_register_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp) { uint32_t nsid = nvme_nsid(ns); @@ -4644,7 +4665,23 @@ int nvme_register_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp) trace_pci_nvme_register_namespace(nsid); - n->namespaces[nsid - 1] = ns; + /* + * If subsys is not given, namespae is always attached to the controller + * because there's no subsystem to manage namespace allocation. + */ + if (!n->subsys) { + if (ns->params.detached) { + error_setg(errp, + "detached needs nvme-subsys specified nvme or nvme-ns"); + return -1; + } + + return nvme_attach_namespace(n, ns, errp); + } else { + if (!ns->params.detached) { + return nvme_attach_namespace(n, ns, errp); + } + } return 0; } diff --git a/hw/block/nvme.h b/hw/block/nvme.h index f45ace0cff5b..51b8739b4d1e 100644 --- a/hw/block/nvme.h +++ b/hw/block/nvme.h @@ -174,6 +174,10 @@ typedef struct NvmeCtrl { NvmeSubsystem *subsys; NvmeNamespace namespace; + /* + * Attached namespaces to this controller. If subsys is not given, all + * namespaces in this list will always be attached. + */ NvmeNamespace *namespaces[NVME_MAX_NAMESPACES]; NvmeSQueue **sq; NvmeCQueue **cq; @@ -192,6 +196,24 @@ static inline NvmeNamespace *nvme_ns(NvmeCtrl *n, uint32_t nsid) return n->namespaces[nsid - 1]; } +static inline bool nvme_ns_is_attached(NvmeCtrl *n, NvmeNamespace *ns) +{ + int nsid; + + for (nsid = 1; nsid <= n->num_namespaces; nsid++) { + if (nvme_ns(n, nsid) == ns) { + return true; + } + } + + return false; +} + +static inline void nvme_ns_attach(NvmeCtrl *n, NvmeNamespace *ns) +{ + n->namespaces[nvme_nsid(ns) - 1] = ns; +} + static inline NvmeCQueue *nvme_cq(NvmeRequest *req) { NvmeSQueue *sq = req->sq; From patchwork Sun Feb 28 16:10:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minwoo Im X-Patchwork-Id: 1445290 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Brzq+QG9; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DpW3S4mvzz9sCD for ; Mon, 1 Mar 2021 04:44:03 +1100 (AEDT) Received: from localhost ([::1]:56454 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGQ6q-0006R9-0t for incoming@patchwork.ozlabs.org; Sun, 28 Feb 2021 12:44:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54402) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGQ5t-0006Q5-1c; Sun, 28 Feb 2021 12:43:01 -0500 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]:39290) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lGQ5n-0003dj-5S; Sun, 28 Feb 2021 12:43:00 -0500 Received: by mail-oi1-x22e.google.com with SMTP id z126so15678669oiz.6; Sun, 28 Feb 2021 09:42:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Xx3N5y7JG2qOh4yXzByki8P97nwo4NHi+PzHZAl9Mjk=; b=Brzq+QG9Ui8dhZuRgFdAXDkzGtXynsTqKPwJXhtjcnt9eLuVts9cNKdqoJVYOUYaF9 183+4xEQdUDzK7xLU2sOR968Sm4CM1oS5dCbbpTM8uZ/BPSiNSsFL6ooKyaYZ8WGzP8Y CwP1Ze6Rb1SN2MLw9V7LSoG31wHf8YzOJ3PQ/NtJBhTWoZZTVdEmGZwlRWqM78VpLjmS fu5g1gFXlOr0TjzZXcW1/tNg0ooGQHtvzy1GwaliF6T37h0nGEWwiangWI/nRGzCnze0 wfRU6IbRkRft5b3B3YyGUOElAR7VSLoEQx+APp8YIvdTMN6OE4GFuEVCnTOeftbB3+jR 1GnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Xx3N5y7JG2qOh4yXzByki8P97nwo4NHi+PzHZAl9Mjk=; b=ETTlGPgeqd93KQJClbmNdBLjRtnWtET7QO6IZ+6sJnwpdZxm+IQrrFZcdHR/mkzZdq n8s++ls2OQSy+W853UiCzjxwlep5X4/5cIIEEtt7D6xhZcc1nqWaXECrmVYHYQ1sP06y iCPVuub3at0jJqWiN/KcPOJjmoZOmiuTw4bKRDyhwyYA5/ZQ87T/AR+vr4kgn2qdiw55 aEDLIZ6s4N+ehMHXwUvHIahNQYnnNWckWkU0ajePIaOX4+1J9I5zQGjXvGkA8rXDrsIw RABI+oZRld0KZCV0txl+SddVGXTE6ZfP2ytR3mQTvwROgHDe/TitcK78mX/DIh6KSW01 y/Ww== X-Gm-Message-State: AOAM532r4a6TgAy/UpA14btUOr+/HbpMh89jYXlPytOarY9pF15yPF7O fl3AaIa0ferCMyYMEujNlKtQkYHu89bPkw== X-Google-Smtp-Source: ABdhPJyCpPQoQq5p/h4lvqHH8qPAHnliu7iOFvuaRf3w9OhP4dksRuLT6mMj7VrJ9P12ESZjRuul7A== X-Received: by 2002:a17:90a:65c4:: with SMTP id i4mr12812856pjs.132.1614528672486; Sun, 28 Feb 2021 08:11:12 -0800 (PST) Received: from localhost.localdomain ([211.108.35.36]) by smtp.gmail.com with ESMTPSA id x11sm14389781pja.46.2021.02.28.08.11.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Feb 2021 08:11:12 -0800 (PST) From: Minwoo Im To: qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH V3 2/8] hw/block/nvme: fix namespaces array to 1-based Date: Mon, 1 Mar 2021 01:10:54 +0900 Message-Id: <20210228161100.54015-3-minwoo.im.dev@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210228161100.54015-1-minwoo.im.dev@gmail.com> References: <20210228161100.54015-1-minwoo.im.dev@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22e; envelope-from=minwoo.im.dev@gmail.com; helo=mail-oi1-x22e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Kevin Wolf , Klaus Jensen , Max Reitz , Klaus Jensen , Minwoo Im , Keith Busch Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" subsys->namespaces array used to be sized to NVME_SUBSYS_MAX_NAMESPACES. But subsys->namespaces are being accessed with 1-based namespace id which means the very first array entry will always be empty(NULL). Signed-off-by: Minwoo Im Tested-by: Klaus Jensen Reviewed-by: Klaus Jensen --- hw/block/nvme-subsys.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/block/nvme-subsys.h b/hw/block/nvme-subsys.h index 890d118117dc..574774390c4c 100644 --- a/hw/block/nvme-subsys.h +++ b/hw/block/nvme-subsys.h @@ -24,7 +24,7 @@ typedef struct NvmeSubsystem { NvmeCtrl *ctrls[NVME_SUBSYS_MAX_CTRLS]; /* Allocated namespaces for this subsystem */ - NvmeNamespace *namespaces[NVME_SUBSYS_MAX_NAMESPACES]; + NvmeNamespace *namespaces[NVME_SUBSYS_MAX_NAMESPACES + 1]; } NvmeSubsystem; int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp); From patchwork Sun Feb 28 16:10:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minwoo Im X-Patchwork-Id: 1445287 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=CJuiEWYX; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DpVfn1lXRz9sCD for ; Mon, 1 Mar 2021 04:26:08 +1100 (AEDT) Received: from localhost ([::1]:58590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGPpW-0002vB-Sw for incoming@patchwork.ozlabs.org; Sun, 28 Feb 2021 12:26:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59520) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGPn4-0001Ly-6f; Sun, 28 Feb 2021 12:23:34 -0500 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]:46433) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lGPn2-0004ge-8D; Sun, 28 Feb 2021 12:23:33 -0500 Received: by mail-io1-xd36.google.com with SMTP id u8so15133233ior.13; Sun, 28 Feb 2021 09:23:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3H9nCPAN+eetY3PbT+hXYiOLp/9UGr7Ra/URtIKWm8g=; b=CJuiEWYXsX6VrG+1egdK+T5IfX6GEbFNA6i6wqzXjsV8eGp7GT61F1oNCwpwoThi+B ZhFpAruCnXheP4IyjCXJDPkpKEXr+aId0Xn+9rzExEM5wA6JTfYSNc6ojxPlGgzrGlZC GjuJFRXzpiRpl1L5aHZW8PmJQmKW+J+5g7etEV9e3bgtKOPswD/ZS7D9Re0noqmkqUsB TUV9XERChFiWHDV0lhhcmun4CGuncWwj+FePfZndC+u+r/+oV++L5C1fjLE9/zHdwrIJ QykdhCpB6Q2tkxHciy8Ga0KdQD/sdhrS9JLujX5M7O4b7Y7qJmfJ74zNzFRedeVxPnBH SpoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3H9nCPAN+eetY3PbT+hXYiOLp/9UGr7Ra/URtIKWm8g=; b=FrI6OkMhzVk/pLo6SDl+2hA+nvXC+6pzXV3CZFZ3u6VLHuZvNKzy709Qm/QV1egWnb S6P9D8qAXjmwUhKTILiPJrpCJfOa9wWWNyfvr/egjApen5g5rhKkqEFYcFBSrn6v45IJ rXlosy09eCdjzYn5DHUL/kkmoGXPiioOJ4CgQrm2gEAD1/YK7PwsShPnDBQbnFnG4KF+ NakVOLYIJmiBL7S80z4SOgJIJMhMiLXr4qD0dzQbanQScIbl+7H+8PeGH8fkt4SamJtT fMbnjbjbklHgvHv/1cC6dPbDhtsbC7a5ZqKTNETEHMQUYC/+qT3iw1kdsU+0jWlxt4GP Fi4w== X-Gm-Message-State: AOAM531wMtDAov3/X0ssPbLz+ZTf2Cq1oOgbapu8zZxRP8FG/D8fK0Pq WAYhwHtsXuUOmRNkQHBa7DidkydCnGK+Vg== X-Google-Smtp-Source: ABdhPJylsOXkwOblA+SOU85OIcg0qEpY9joI9YB/YwbuhuDy4N3N8GL45jsqBcPrbH3+clsgH+At7Q== X-Received: by 2002:a63:d057:: with SMTP id s23mr991210pgi.171.1614528674857; Sun, 28 Feb 2021 08:11:14 -0800 (PST) Received: from localhost.localdomain ([211.108.35.36]) by smtp.gmail.com with ESMTPSA id x11sm14389781pja.46.2021.02.28.08.11.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Feb 2021 08:11:14 -0800 (PST) From: Minwoo Im To: qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH V3 3/8] hw/block/nvme: fix allocated namespace list to 256 Date: Mon, 1 Mar 2021 01:10:55 +0900 Message-Id: <20210228161100.54015-4-minwoo.im.dev@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210228161100.54015-1-minwoo.im.dev@gmail.com> References: <20210228161100.54015-1-minwoo.im.dev@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::d36; envelope-from=minwoo.im.dev@gmail.com; helo=mail-io1-xd36.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Kevin Wolf , Klaus Jensen , Max Reitz , Klaus Jensen , Minwoo Im , Keith Busch Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Expand allocated namespace list (subsys->namespaces) to have 256 entries which is a value lager than at least NVME_MAX_NAMESPACES which is for attached namespace list in a controller. Allocated namespace list should at least larger than attached namespace list. n->num_namespaces = NVME_MAX_NAMESPACES; The above line will set the NN field by id->nn so that the subsystem should also prepare at least this number of namespace list entries. Signed-off-by: Minwoo Im Tested-by: Klaus Jensen Reviewed-by: Klaus Jensen --- hw/block/nvme-subsys.h | 2 +- hw/block/nvme.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/block/nvme-subsys.h b/hw/block/nvme-subsys.h index 574774390c4c..8a0732b22316 100644 --- a/hw/block/nvme-subsys.h +++ b/hw/block/nvme-subsys.h @@ -14,7 +14,7 @@ OBJECT_CHECK(NvmeSubsystem, (obj), TYPE_NVME_SUBSYS) #define NVME_SUBSYS_MAX_CTRLS 32 -#define NVME_SUBSYS_MAX_NAMESPACES 32 +#define NVME_SUBSYS_MAX_NAMESPACES 256 typedef struct NvmeCtrl NvmeCtrl; typedef struct NvmeNamespace NvmeNamespace; diff --git a/hw/block/nvme.h b/hw/block/nvme.h index 51b8739b4d1e..7599d6b1a41b 100644 --- a/hw/block/nvme.h +++ b/hw/block/nvme.h @@ -10,6 +10,12 @@ #define NVME_DEFAULT_ZONE_SIZE (128 * MiB) #define NVME_DEFAULT_MAX_ZA_SIZE (128 * KiB) +/* + * Subsystem namespace list for allocated namespaces should be larger than + * attached namespace list in a controller. + */ +QEMU_BUILD_BUG_ON(NVME_MAX_NAMESPACES > NVME_SUBSYS_MAX_NAMESPACES); + typedef struct NvmeParams { char *serial; uint32_t num_queues; /* deprecated since 5.1 */ From patchwork Sun Feb 28 16:10:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minwoo Im X-Patchwork-Id: 1445286 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Dd64XgWP; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DpVfD2P2kz9sCD for ; Mon, 1 Mar 2021 04:25:40 +1100 (AEDT) Received: from localhost ([::1]:57792 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGPp3-0002aq-NJ for incoming@patchwork.ozlabs.org; Sun, 28 Feb 2021 12:25:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59316) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGPmY-0000uk-Pp; Sun, 28 Feb 2021 12:23:03 -0500 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]:37591) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lGPmW-0004X6-MF; Sun, 28 Feb 2021 12:23:02 -0500 Received: by mail-oi1-x235.google.com with SMTP id l133so15646574oib.4; Sun, 28 Feb 2021 09:22:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lCBwqwdK/I3/mqTdNwTMTiyi+JpI3avrUWNQ+CAnFSU=; b=Dd64XgWPQmNheVmnCdn8BNPRgAEfLcH8S+cI51ZlF108mLP9u53KmA6E7C+73zcLMZ sOrPz9ls6s8LyiLpUsT7p1iYE0XkSgCIQByMKOyQtrmMvwSu/mXI3Ga8dox4whxLGbxw OFRxDef744H9u/paKFqG3jK8y67rOAyofgxwtGo5/WwLeyGgKWCDhXC2Hud9VjRJK4Ci E+4NbLCZWlQLzpnO/Bq2s0FHkwn3F5e1aY571m+pZQN0KqZT0QACL+BcbmQdR+cofZRW 7cbu2jEn557heNLb7UkEqYN8ajvAsB9CRrZOXPIUzs3xQM8vaCJv9cwYGnd7WJvbn17K X2Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lCBwqwdK/I3/mqTdNwTMTiyi+JpI3avrUWNQ+CAnFSU=; b=XwX5QfUtDQEeNzr1UouIFW6301LoiXKtWxgPma+7jkVUO/Wrm0U/rvLcQOzGpGOs5D CHNbgP2FcaoUUy9+g+nlTnoua5yX+x42LVImYBGfxPMCVaXXdsbm+ib/XbDDz9VeqTL9 aY9Nx+j/2dSPMAPceRcxXU1wiAseSBcqaQb24dOqnTPtXK0giGn+nGiSxYvWIEnLotju rcokF10eP/iAtmamcBFmJonMn472d23rYGONMAr4GFZHZ/eLjnUUhrOyFWYNHpSziSIg PLBOlRnq1jBWZJi2pO5mVuQocoa1sQkC7pguriOy7vJvOQ7BRzrQ36j6VUXH9xyZKRt2 xuLw== X-Gm-Message-State: AOAM532NBULGv5wFNVHFwpr5B+CCU+JC+YuXze9Eag2518TRg0xs1AuE 6ogzoav9CoDmJ/L9qb6EhYTfNCcUmmneiA== X-Google-Smtp-Source: ABdhPJzUfkJ4Y8ItF/Og00dBqiLyJN3CCGvWYnU98cP9oetmygJsCzCRopHPuB0Teb2/XTEM/1Vh5Q== X-Received: by 2002:a17:90a:5b0c:: with SMTP id o12mr13224382pji.68.1614528677238; Sun, 28 Feb 2021 08:11:17 -0800 (PST) Received: from localhost.localdomain ([211.108.35.36]) by smtp.gmail.com with ESMTPSA id x11sm14389781pja.46.2021.02.28.08.11.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Feb 2021 08:11:16 -0800 (PST) From: Minwoo Im To: qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH V3 4/8] hw/block/nvme: support allocated namespace type Date: Mon, 1 Mar 2021 01:10:56 +0900 Message-Id: <20210228161100.54015-5-minwoo.im.dev@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210228161100.54015-1-minwoo.im.dev@gmail.com> References: <20210228161100.54015-1-minwoo.im.dev@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::235; envelope-from=minwoo.im.dev@gmail.com; helo=mail-oi1-x235.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Kevin Wolf , Klaus Jensen , Max Reitz , Klaus Jensen , Minwoo Im , Keith Busch Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From NVMe spec 1.4b "6.1.5. NSID and Namespace Relationships" defines valid namespace types: - Unallocated: Not exists in the NVMe subsystem - Allocated: Exists in the NVMe subsystem - Inactive: Not attached to the controller - Active: Attached to the controller This patch added support for allocated, but not attached namespace type: !nvme_ns(n, nsid) && nvme_subsys_ns(n->subsys, nsid) nvme_ns() returns attached namespace instance of the given controller and nvme_subsys_ns() returns allocated namespace instance in the subsystem. Signed-off-by: Minwoo Im Tested-by: Klaus Jensen Reviewed-by: Klaus Jensen --- hw/block/nvme-subsys.h | 13 +++++++++ hw/block/nvme.c | 63 +++++++++++++++++++++++++++++++----------- 2 files changed, 60 insertions(+), 16 deletions(-) diff --git a/hw/block/nvme-subsys.h b/hw/block/nvme-subsys.h index 8a0732b22316..14627f9ccb41 100644 --- a/hw/block/nvme-subsys.h +++ b/hw/block/nvme-subsys.h @@ -30,4 +30,17 @@ typedef struct NvmeSubsystem { int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp); int nvme_subsys_register_ns(NvmeNamespace *ns, Error **errp); +/* + * Return allocated namespace of the specified nsid in the subsystem. + */ +static inline NvmeNamespace *nvme_subsys_ns(NvmeSubsystem *subsys, + uint32_t nsid) +{ + if (!subsys) { + return NULL; + } + + return subsys->namespaces[nsid]; +} + #endif /* NVME_SUBSYS_H */ diff --git a/hw/block/nvme.c b/hw/block/nvme.c index f6aeae081840..53c4d59e09a7 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -3225,7 +3225,7 @@ static uint16_t nvme_identify_ctrl_csi(NvmeCtrl *n, NvmeRequest *req) return NVME_INVALID_FIELD | NVME_DNR; } -static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeRequest *req) +static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeRequest *req, bool active) { NvmeNamespace *ns; NvmeIdentify *c = (NvmeIdentify *)&req->cmd; @@ -3239,7 +3239,14 @@ static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeRequest *req) ns = nvme_ns(n, nsid); if (unlikely(!ns)) { - return nvme_rpt_empty_id_struct(n, req); + if (!active) { + ns = nvme_subsys_ns(n->subsys, nsid); + if (!ns) { + return nvme_rpt_empty_id_struct(n, req); + } + } else { + return nvme_rpt_empty_id_struct(n, req); + } } if (c->csi == NVME_CSI_NVM && nvme_csi_has_nvm_support(ns)) { @@ -3250,7 +3257,8 @@ static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeRequest *req) return NVME_INVALID_CMD_SET | NVME_DNR; } -static uint16_t nvme_identify_ns_csi(NvmeCtrl *n, NvmeRequest *req) +static uint16_t nvme_identify_ns_csi(NvmeCtrl *n, NvmeRequest *req, + bool active) { NvmeNamespace *ns; NvmeIdentify *c = (NvmeIdentify *)&req->cmd; @@ -3264,7 +3272,14 @@ static uint16_t nvme_identify_ns_csi(NvmeCtrl *n, NvmeRequest *req) ns = nvme_ns(n, nsid); if (unlikely(!ns)) { - return nvme_rpt_empty_id_struct(n, req); + if (!active) { + ns = nvme_subsys_ns(n->subsys, nsid); + if (!ns) { + return nvme_rpt_empty_id_struct(n, req); + } + } else { + return nvme_rpt_empty_id_struct(n, req); + } } if (c->csi == NVME_CSI_NVM && nvme_csi_has_nvm_support(ns)) { @@ -3277,7 +3292,8 @@ static uint16_t nvme_identify_ns_csi(NvmeCtrl *n, NvmeRequest *req) return NVME_INVALID_FIELD | NVME_DNR; } -static uint16_t nvme_identify_nslist(NvmeCtrl *n, NvmeRequest *req) +static uint16_t nvme_identify_nslist(NvmeCtrl *n, NvmeRequest *req, + bool active) { NvmeNamespace *ns; NvmeIdentify *c = (NvmeIdentify *)&req->cmd; @@ -3302,7 +3318,14 @@ static uint16_t nvme_identify_nslist(NvmeCtrl *n, NvmeRequest *req) for (i = 1; i <= n->num_namespaces; i++) { ns = nvme_ns(n, i); if (!ns) { - continue; + if (!active) { + ns = nvme_subsys_ns(n->subsys, i); + if (!ns) { + continue; + } + } else { + continue; + } } if (ns->params.nsid <= min_nsid) { continue; @@ -3316,7 +3339,8 @@ static uint16_t nvme_identify_nslist(NvmeCtrl *n, NvmeRequest *req) return nvme_dma(n, list, data_len, DMA_DIRECTION_FROM_DEVICE, req); } -static uint16_t nvme_identify_nslist_csi(NvmeCtrl *n, NvmeRequest *req) +static uint16_t nvme_identify_nslist_csi(NvmeCtrl *n, NvmeRequest *req, + bool active) { NvmeNamespace *ns; NvmeIdentify *c = (NvmeIdentify *)&req->cmd; @@ -3342,7 +3366,14 @@ static uint16_t nvme_identify_nslist_csi(NvmeCtrl *n, NvmeRequest *req) for (i = 1; i <= n->num_namespaces; i++) { ns = nvme_ns(n, i); if (!ns) { - continue; + if (!active) { + ns = nvme_subsys_ns(n->subsys, i); + if (!ns) { + continue; + } + } else { + continue; + } } if (ns->params.nsid <= min_nsid || c->csi != ns->csi) { continue; @@ -3422,25 +3453,25 @@ static uint16_t nvme_identify(NvmeCtrl *n, NvmeRequest *req) switch (le32_to_cpu(c->cns)) { case NVME_ID_CNS_NS: - /* fall through */ + return nvme_identify_ns(n, req, true); case NVME_ID_CNS_NS_PRESENT: - return nvme_identify_ns(n, req); + return nvme_identify_ns(n, req, false); case NVME_ID_CNS_CS_NS: - /* fall through */ + return nvme_identify_ns_csi(n, req, true); case NVME_ID_CNS_CS_NS_PRESENT: - return nvme_identify_ns_csi(n, req); + return nvme_identify_ns_csi(n, req, false); 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 */ + return nvme_identify_nslist(n, req, true); case NVME_ID_CNS_NS_PRESENT_LIST: - return nvme_identify_nslist(n, req); + return nvme_identify_nslist(n, req, false); case NVME_ID_CNS_CS_NS_ACTIVE_LIST: - /* fall through */ + return nvme_identify_nslist_csi(n, req, true); case NVME_ID_CNS_CS_NS_PRESENT_LIST: - return nvme_identify_nslist_csi(n, req); + return nvme_identify_nslist_csi(n, req, false); case NVME_ID_CNS_NS_DESCR_LIST: return nvme_identify_ns_descr_list(n, req); case NVME_ID_CNS_IO_COMMAND_SET: From patchwork Sun Feb 28 16:10:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minwoo Im X-Patchwork-Id: 1445283 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=PaBhxRoo; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DpVRX5g1Qz9sVF for ; Mon, 1 Mar 2021 04:16:23 +1100 (AEDT) Received: from localhost ([::1]:36446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGPg3-0000hS-NJ for incoming@patchwork.ozlabs.org; Sun, 28 Feb 2021 12:16:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51010) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGPbL-00070m-Vh; Sun, 28 Feb 2021 12:11:28 -0500 Received: from mail-vk1-xa2d.google.com ([2607:f8b0:4864:20::a2d]:46992) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lGPat-0004Z5-Uz; Sun, 28 Feb 2021 12:11:27 -0500 Received: by mail-vk1-xa2d.google.com with SMTP id j188so3058169vke.13; Sun, 28 Feb 2021 09:10:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OH12zHTNa1+rFtRT+eM9US7bQe2aUxLhBVK+rXJzT1s=; b=PaBhxRoohqf25cUBP8MP61izblaiqRITmyX+xpOyKvZeN8JKwfwNvt0lZe4HhyN7gu +m0DoW6yYzaYOk0DYl7+3nD69+ZMpHGGNS1cl96T9rSqnsNhfnv/l/jk1F1ZTmJFeYm0 4TdEvf69KVygi+3jOkkurVIJeI+D7q3CnR14YAYUjd5JrorPyBLmR7A1u9WBeRdy1dZr 3+ITeAzhwCErzRfijayZQHUWL0BhARB+oRXNxOzEEhpfGwMEgK+6VlGB5lAQhcmJadDz /ZQNXwy0HEHOYviAd2sxaT18VyNa0O89b1YaouD8BiDG5WdbO3vLNVhXwmdYQQzEwUb/ 7ZzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OH12zHTNa1+rFtRT+eM9US7bQe2aUxLhBVK+rXJzT1s=; b=mXCi0gaPNYrFdCENldmh7GLez65Pt+oJ9b71cgyMdXCt0bfg73x/X5x3nfgNaRr9+v pZ1z/VyCiCmLAbNSp64o+vjKm7k2JNnvZkv7u70G7i+oczhbEk7dIBDtUEJ38DLr5HEd PTc1KF/j5C1nt/scasCFnH+WRFb5TfKdF5J/sXjgcqKB2Jq2CU/GuJqLGNZfPA6dR86c 8oOPaKSbry1KEpgXzAm8A0DeAEypbsUd/cH9hfIgoWE4CiM7bSqJxc6zpQ1AmExktOSW V5xFsl1BIAgeDLze8gWhou/mjd9MSJmedv9bilWDzPl8XLIwC/eVIBpkGgCGTPs2o4vx 7WNA== X-Gm-Message-State: AOAM533oHX3IjneJrxDPBo4pjWUbqG1/wDL+k3e6h+rxh7QYqikf8Sie MaC3Qn3S2da48Gk13llLeI0SnXmhdD1pIQ== X-Google-Smtp-Source: ABdhPJxjRPd58QOt6ppQ4JsFmIICHdilIvTjyrdN/i+3NBtPrE7IGiuRWAziYMTdS2MKconj3UuKxQ== X-Received: by 2002:aa7:93d2:0:b029:1ee:1433:85b7 with SMTP id y18-20020aa793d20000b02901ee143385b7mr11279823pff.12.1614528679515; Sun, 28 Feb 2021 08:11:19 -0800 (PST) Received: from localhost.localdomain ([211.108.35.36]) by smtp.gmail.com with ESMTPSA id x11sm14389781pja.46.2021.02.28.08.11.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Feb 2021 08:11:19 -0800 (PST) From: Minwoo Im To: qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH V3 5/8] hw/block/nvme: refactor nvme_select_ns_iocs Date: Mon, 1 Mar 2021 01:10:57 +0900 Message-Id: <20210228161100.54015-6-minwoo.im.dev@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210228161100.54015-1-minwoo.im.dev@gmail.com> References: <20210228161100.54015-1-minwoo.im.dev@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::a2d; envelope-from=minwoo.im.dev@gmail.com; helo=mail-vk1-xa2d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Kevin Wolf , Klaus Jensen , Max Reitz , Klaus Jensen , Minwoo Im , Keith Busch Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patch has no functional changes. This patch just refactored nvme_select_ns_iocs() to iterate the attached namespaces of the controlller and make it invoke __nvme_select_ns_iocs(). Signed-off-by: Minwoo Im Tested-by: Klaus Jensen Reviewed-by: Klaus Jensen --- hw/block/nvme.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 53c4d59e09a7..b18ab0ef810f 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -4000,6 +4000,25 @@ static void nvme_ctrl_shutdown(NvmeCtrl *n) } } +static void __nvme_select_ns_iocs(NvmeCtrl *n, NvmeNamespace *ns) +{ + ns->iocs = nvme_cse_iocs_none; + switch (ns->csi) { + case NVME_CSI_NVM: + if (NVME_CC_CSS(n->bar.cc) != NVME_CC_CSS_ADMIN_ONLY) { + ns->iocs = nvme_cse_iocs_nvm; + } + break; + case NVME_CSI_ZONED: + if (NVME_CC_CSS(n->bar.cc) == NVME_CC_CSS_CSI) { + ns->iocs = nvme_cse_iocs_zoned; + } else if (NVME_CC_CSS(n->bar.cc) == NVME_CC_CSS_NVM) { + ns->iocs = nvme_cse_iocs_nvm; + } + break; + } +} + static void nvme_select_ns_iocs(NvmeCtrl *n) { NvmeNamespace *ns; @@ -4010,21 +4029,8 @@ static void nvme_select_ns_iocs(NvmeCtrl *n) if (!ns) { continue; } - ns->iocs = nvme_cse_iocs_none; - switch (ns->csi) { - case NVME_CSI_NVM: - if (NVME_CC_CSS(n->bar.cc) != NVME_CC_CSS_ADMIN_ONLY) { - ns->iocs = nvme_cse_iocs_nvm; - } - break; - case NVME_CSI_ZONED: - if (NVME_CC_CSS(n->bar.cc) == NVME_CC_CSS_CSI) { - ns->iocs = nvme_cse_iocs_zoned; - } else if (NVME_CC_CSS(n->bar.cc) == NVME_CC_CSS_NVM) { - ns->iocs = nvme_cse_iocs_nvm; - } - break; - } + + __nvme_select_ns_iocs(n, ns); } } From patchwork Sun Feb 28 16:10:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minwoo Im X-Patchwork-Id: 1445291 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=HVADzPSs; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DpWDq1H27z9sCD for ; Mon, 1 Mar 2021 04:52:11 +1100 (AEDT) Received: from localhost ([::1]:38464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGQEj-00034m-4X for incoming@patchwork.ozlabs.org; Sun, 28 Feb 2021 12:52:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGQEG-00030w-1z; Sun, 28 Feb 2021 12:51:40 -0500 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]:42497) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lGQED-0003DY-TY; Sun, 28 Feb 2021 12:51:39 -0500 Received: by mail-pg1-x529.google.com with SMTP id o38so9987735pgm.9; Sun, 28 Feb 2021 09:51:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6uJdErSE1C1h/gmj0xkomziSvRUlZNQsTrL31Svboa0=; b=HVADzPSs7g+A6+Y5QLQ4Svh+BqH/gJstGj6sFv0MXA+NZ3P2IMNyphyyNDU+3JFnWr hs4XRasp34tvggxupkwgaSxdjeOfVYuboITCkBXtj+ayItEGW7ZLOlhrXZUDGbc0rxIQ ZxW6QY0KUZDoIi8aA4olJ4gGpjqIjR6iDK8ns3/4PwWnPfi3xt5qjuWMaylLNK4DTipi RGqoLOAWEUeNQhEHUacC3kMHQ20GWiAyUEfmQ8YVxZKRLB7zUZ3+EQPvGE5d0QnF62Vm jdmjzhhKDvK9n5AadXe7fdG/iagiCV2zfyjsvye+RAfNyhMYRhUvdu9tEK2s7sDUDeje HCHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6uJdErSE1C1h/gmj0xkomziSvRUlZNQsTrL31Svboa0=; b=rIKWzi5oUaWglQk4gmPyBLI4MgTw8WL/YGH4fwTG4VmJBxDAO1vRxmmzkFGXnCbz/y Ewx25lvqDIjBPdGZETe2nFZ5dwEUjwkhc4U/9fEVo++w9DX9XQ65RDiNAXttH9OFc6I0 T47nY+qefYffnU59K9NTDMQob9sqNplidTLmmj/l1Zf1uxXjUadLEh/2fgmyJyOwbDNK bePtQ9U70lRSdiLmUZgZyywHshxi7E/e4jIKHetxwwcUqE4H8DJZ69ic1ZqENlyf+gin XuBHss8lfnrcU11zWNY392HHsve+4JoKnQegjXGypEl+TvdTBK7c4AcTH3qBeRXQ/Xwo kf2A== X-Gm-Message-State: AOAM531jPfhirnNZbX+cabXpdya1hMP42r383RwdXnkKeaJJF058clIi Yk9ZUfmwOaJh0sdpM6YdfJ+8PQsMXwk4iw== X-Google-Smtp-Source: ABdhPJyWLdLSofJQCgF6nzZWfdz1+FK6wvomO+wdfDs6X1LqTmRZK2YsF1UXNNfVBG0mnOEq74RjNg== X-Received: by 2002:aa7:80c6:0:b029:1b6:92ae:a199 with SMTP id a6-20020aa780c60000b02901b692aea199mr11250162pfn.71.1614528681685; Sun, 28 Feb 2021 08:11:21 -0800 (PST) Received: from localhost.localdomain ([211.108.35.36]) by smtp.gmail.com with ESMTPSA id x11sm14389781pja.46.2021.02.28.08.11.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Feb 2021 08:11:21 -0800 (PST) From: Minwoo Im To: qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH V3 6/8] hw/block/nvme: support namespace attachment command Date: Mon, 1 Mar 2021 01:10:58 +0900 Message-Id: <20210228161100.54015-7-minwoo.im.dev@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210228161100.54015-1-minwoo.im.dev@gmail.com> References: <20210228161100.54015-1-minwoo.im.dev@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=minwoo.im.dev@gmail.com; helo=mail-pg1-x529.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Keith Busch , Klaus Jensen , Minwoo Im , Kevin Wolf , Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patch supports Namespace Attachment command for the pre-defined nvme-ns device nodes. Of course, attach/detach namespace should only be supported in case 'subsys' is given. This is because if we detach a namespace from a controller, somebody needs to manage the detached, but allocated namespace in the NVMe subsystem. As command effect for the namespace attachment command is registered, the host will be notified that namespace inventory is changed so that host will rescan the namespace inventory after this command. For example, kernel driver manages this command effect via passthru IOCTL. Signed-off-by: Minwoo Im --- hw/block/nvme-subsys.h | 10 +++++++ hw/block/nvme.c | 61 +++++++++++++++++++++++++++++++++++++++++- hw/block/nvme.h | 5 ++++ hw/block/trace-events | 2 ++ include/block/nvme.h | 6 +++++ 5 files changed, 83 insertions(+), 1 deletion(-) diff --git a/hw/block/nvme-subsys.h b/hw/block/nvme-subsys.h index 14627f9ccb41..ef4bec928eae 100644 --- a/hw/block/nvme-subsys.h +++ b/hw/block/nvme-subsys.h @@ -30,6 +30,16 @@ typedef struct NvmeSubsystem { int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp); int nvme_subsys_register_ns(NvmeNamespace *ns, Error **errp); +static inline NvmeCtrl *nvme_subsys_ctrl(NvmeSubsystem *subsys, + uint32_t cntlid) +{ + if (!subsys) { + return NULL; + } + + return subsys->ctrls[cntlid]; +} + /* * Return allocated namespace of the specified nsid in the subsystem. */ diff --git a/hw/block/nvme.c b/hw/block/nvme.c index b18ab0ef810f..68c2e63d9412 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -187,6 +187,7 @@ static const uint32_t nvme_cse_acs[256] = { [NVME_ADM_CMD_SET_FEATURES] = NVME_CMD_EFF_CSUPP, [NVME_ADM_CMD_GET_FEATURES] = NVME_CMD_EFF_CSUPP, [NVME_ADM_CMD_ASYNC_EV_REQ] = NVME_CMD_EFF_CSUPP, + [NVME_ADM_CMD_NS_ATTACHMENT] = NVME_CMD_EFF_CSUPP | NVME_CMD_EFF_NIC, }; static const uint32_t nvme_cse_iocs_none[256]; @@ -3868,6 +3869,62 @@ static uint16_t nvme_aer(NvmeCtrl *n, NvmeRequest *req) return NVME_NO_COMPLETE; } +static void __nvme_select_ns_iocs(NvmeCtrl *n, NvmeNamespace *ns); +static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req) +{ + NvmeNamespace *ns; + NvmeCtrl *ctrl; + uint16_t list[NVME_CONTROLLER_LIST_SIZE] = {}; + uint32_t nsid = le32_to_cpu(req->cmd.nsid); + uint32_t dw10 = le32_to_cpu(req->cmd.cdw10); + bool attach = !(dw10 & 0xf); + uint16_t *nr_ids = &list[0]; + uint16_t *ids = &list[1]; + uint16_t ret; + int i; + + trace_pci_nvme_ns_attachment(nvme_cid(req), dw10 & 0xf); + + ns = nvme_subsys_ns(n->subsys, nsid); + if (!ns) { + return NVME_INVALID_FIELD | NVME_DNR; + } + + ret = nvme_dma(n, (uint8_t *)list, 4096, + DMA_DIRECTION_TO_DEVICE, req); + if (ret) { + return ret; + } + + if (!*nr_ids) { + return NVME_NS_CTRL_LIST_INVALID | NVME_DNR; + } + + for (i = 0; i < *nr_ids; i++) { + ctrl = nvme_subsys_ctrl(n->subsys, ids[i]); + if (!ctrl) { + return NVME_NS_CTRL_LIST_INVALID | NVME_DNR; + } + + if (attach) { + if (nvme_ns_is_attached(ctrl, ns)) { + return NVME_NS_ALREADY_ATTACHED | NVME_DNR; + } + + nvme_ns_attach(ctrl, ns); + __nvme_select_ns_iocs(ctrl, ns); + } else { + if (!nvme_ns_is_attached(ctrl, ns)) { + return NVME_NS_NOT_ATTACHED | NVME_DNR; + } + + nvme_ns_detach(ctrl, ns); + } + } + + return NVME_SUCCESS; +} + static uint16_t nvme_admin_cmd(NvmeCtrl *n, NvmeRequest *req) { trace_pci_nvme_admin_cmd(nvme_cid(req), nvme_sqid(req), req->cmd.opcode, @@ -3899,6 +3956,8 @@ static uint16_t nvme_admin_cmd(NvmeCtrl *n, NvmeRequest *req) return nvme_get_feature(n, req); case NVME_ADM_CMD_ASYNC_EV_REQ: return nvme_aer(n, req); + case NVME_ADM_CMD_NS_ATTACHMENT: + return nvme_ns_attachment(n, req); default: assert(false); } @@ -4865,7 +4924,7 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev) id->mdts = n->params.mdts; id->ver = cpu_to_le32(NVME_SPEC_VER); - id->oacs = cpu_to_le16(0); + id->oacs = cpu_to_le16(NVME_OACS_NS_MGMT); id->cntrltype = 0x1; /* diff --git a/hw/block/nvme.h b/hw/block/nvme.h index 7599d6b1a41b..74a00ab21a55 100644 --- a/hw/block/nvme.h +++ b/hw/block/nvme.h @@ -220,6 +220,11 @@ static inline void nvme_ns_attach(NvmeCtrl *n, NvmeNamespace *ns) n->namespaces[nvme_nsid(ns) - 1] = ns; } +static inline void nvme_ns_detach(NvmeCtrl *n, NvmeNamespace *ns) +{ + n->namespaces[nvme_nsid(ns) - 1] = NULL; +} + static inline NvmeCQueue *nvme_cq(NvmeRequest *req) { NvmeSQueue *sq = req->sq; diff --git a/hw/block/trace-events b/hw/block/trace-events index 25ba51ea5405..98d542c999e2 100644 --- a/hw/block/trace-events +++ b/hw/block/trace-events @@ -82,6 +82,8 @@ pci_nvme_aer(uint16_t cid) "cid %"PRIu16"" pci_nvme_aer_aerl_exceeded(void) "aerl exceeded" pci_nvme_aer_masked(uint8_t type, uint8_t mask) "type 0x%"PRIx8" mask 0x%"PRIx8"" pci_nvme_aer_post_cqe(uint8_t typ, uint8_t info, uint8_t log_page) "type 0x%"PRIx8" info 0x%"PRIx8" lid 0x%"PRIx8"" +pci_nvme_ns_attachment(uint16_t cid, uint8_t sel) "cid %"PRIu16", sel=0x%"PRIx8"" +pci_nvme_ns_attachment_attach(uint16_t cntlid, uint32_t nsid) "cntlid=0x%"PRIx16", nsid=0x%"PRIx32"" pci_nvme_enqueue_event(uint8_t typ, uint8_t info, uint8_t log_page) "type 0x%"PRIx8" info 0x%"PRIx8" lid 0x%"PRIx8"" pci_nvme_enqueue_event_noqueue(int queued) "queued %d" pci_nvme_enqueue_event_masked(uint8_t typ) "type 0x%"PRIx8"" diff --git a/include/block/nvme.h b/include/block/nvme.h index b23f3ae2279f..339784d9c23a 100644 --- a/include/block/nvme.h +++ b/include/block/nvme.h @@ -566,6 +566,7 @@ enum NvmeAdminCommands { NVME_ADM_CMD_ASYNC_EV_REQ = 0x0c, NVME_ADM_CMD_ACTIVATE_FW = 0x10, NVME_ADM_CMD_DOWNLOAD_FW = 0x11, + NVME_ADM_CMD_NS_ATTACHMENT = 0x15, NVME_ADM_CMD_FORMAT_NVM = 0x80, NVME_ADM_CMD_SECURITY_SEND = 0x81, NVME_ADM_CMD_SECURITY_RECV = 0x82, @@ -836,6 +837,9 @@ enum NvmeStatusCodes { NVME_FEAT_NOT_CHANGEABLE = 0x010e, NVME_FEAT_NOT_NS_SPEC = 0x010f, NVME_FW_REQ_SUSYSTEM_RESET = 0x0110, + NVME_NS_ALREADY_ATTACHED = 0x0118, + NVME_NS_NOT_ATTACHED = 0x011A, + NVME_NS_CTRL_LIST_INVALID = 0x011C, NVME_CONFLICTING_ATTRS = 0x0180, NVME_INVALID_PROT_INFO = 0x0181, NVME_WRITE_TO_RO = 0x0182, @@ -951,6 +955,7 @@ typedef struct QEMU_PACKED NvmePSD { uint8_t resv[16]; } NvmePSD; +#define NVME_CONTROLLER_LIST_SIZE 2048 #define NVME_IDENTIFY_DATA_SIZE 4096 enum NvmeIdCns { @@ -1045,6 +1050,7 @@ enum NvmeIdCtrlOacs { NVME_OACS_SECURITY = 1 << 0, NVME_OACS_FORMAT = 1 << 1, NVME_OACS_FW = 1 << 2, + NVME_OACS_NS_MGMT = 1 << 3, }; enum NvmeIdCtrlOncs { From patchwork Sun Feb 28 16:10:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minwoo Im X-Patchwork-Id: 1445292 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=aYoFFtbO; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DpWHc10VJz9sCD for ; Mon, 1 Mar 2021 04:54:36 +1100 (AEDT) Received: from localhost ([::1]:43574 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGQH4-0005Je-4N for incoming@patchwork.ozlabs.org; Sun, 28 Feb 2021 12:54:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38994) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGQGd-0005ID-0r; Sun, 28 Feb 2021 12:54:07 -0500 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]:42196) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lGQGb-0004QT-7N; Sun, 28 Feb 2021 12:54:06 -0500 Received: by mail-oi1-x22b.google.com with SMTP id l64so15686951oig.9; Sun, 28 Feb 2021 09:54:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/bDgLjN9XoSDZfs2ys3Q5e4zjKCIZLsSnNZGjcGkc6U=; b=aYoFFtbOXpE88gZTTdyGX59RM6FAygqeIzfXm06HtBy4noWgPAjKXu7c8IwQRg1FBl x/xZRHzLIqnGR0jWweEcH/dZnO4IgvgavwSg+56DhpwiuoOjWxQud5573zkUB9gOhk1g mCisUde6hBE9xNyDWeMxvNnpmLdTDVfA2uVfBxiry70AH9R4+shtXAoMA4NtXo1GmjSG yNlT/qPH8Ik3dyKa+puHlzSENfs32ZC+5cRooFwieNpgcEBL2Ke34zfFZ2iekxbUNcqh DK/rVF1WEaQVMhBYtoyOczmnllSeZN4O/uJ68quXhmU7VocLF1QbUfllPCUKagpm8DJ1 KiUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/bDgLjN9XoSDZfs2ys3Q5e4zjKCIZLsSnNZGjcGkc6U=; b=pJKkO2wBCQ+Ro6H8V9bkG9lqwSuveU1Alw4N5zWBrNTR9hI/oJ+lyT2ZP/Fk4mXEC7 zI0p7KHAwglCOeMKZD3Gr7oXTcnh8GSsGR0ZWmXPy7Uqe+B1QwlsYe2WRuUQ35OrBRPm b0dfPGQDcOzuPUpHFMruT2xdMMh1pfAhcfnoN+UNCe5tEPgbPQ/+MaKDoARZmaDIuz96 rV4AJRXVQasewtNWx/FM0H0FUZKnEVWz/BE6eIiIqiEjMBtEWCljCdG2th1xDREozYUE cPlhxt0POJgZWzZaePwBxmMYyuPWkSMU+nljELJ2VqKNv7Nu2rsZdhBvVA+tULPfp6qC 1bOw== X-Gm-Message-State: AOAM5301TaUyIJuO/fhpH/yF7ffbCctkOAQkBESOes9xSD94J4v+SVad mOxYT4gbm1ufQqXr5stqJGzjBpQRnOTd2Q== X-Google-Smtp-Source: ABdhPJwxNqZbmMnYwEN27QUfze1g/5O4SuKwJB7Zmv9CzpxV7/jUHB/V5qDwZPi5jvTvJZpA0o70Zg== X-Received: by 2002:a17:90a:2e89:: with SMTP id r9mr12827584pjd.95.1614528683918; Sun, 28 Feb 2021 08:11:23 -0800 (PST) Received: from localhost.localdomain ([211.108.35.36]) by smtp.gmail.com with ESMTPSA id x11sm14389781pja.46.2021.02.28.08.11.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Feb 2021 08:11:23 -0800 (PST) From: Minwoo Im To: qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH V3 7/8] hw/block/nvme: support changed namespace asyncrohous event Date: Mon, 1 Mar 2021 01:10:59 +0900 Message-Id: <20210228161100.54015-8-minwoo.im.dev@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210228161100.54015-1-minwoo.im.dev@gmail.com> References: <20210228161100.54015-1-minwoo.im.dev@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22b; envelope-from=minwoo.im.dev@gmail.com; helo=mail-oi1-x22b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Keith Busch , Klaus Jensen , Minwoo Im , Kevin Wolf , Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" If namespace inventory is changed due to some reasons (e.g., namespace attachment/detachment), controller can send out event notifier to the host to manage namespaces. This patch sends out the AEN to the host after either attach or detach namespaces from controllers. To support clear of the event from the controller, this patch also implemented Get Log Page command for Changed Namespace List log type. To return namespace id list through the command, when namespace inventory is updated, id is added to the per-controller list (changed_ns_list). To indicate the support of this async event, this patch set OAES(Optional Asynchronous Events Supported) in Identify Controller data structure. Signed-off-by: Minwoo Im --- hw/block/nvme.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ hw/block/nvme.h | 7 +++++++ include/block/nvme.h | 7 +++++++ 3 files changed, 58 insertions(+) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 68c2e63d9412..fc06f806e58e 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -2980,6 +2980,32 @@ static uint16_t nvme_error_info(NvmeCtrl *n, uint8_t rae, uint32_t buf_len, DMA_DIRECTION_FROM_DEVICE, req); } +static uint16_t nvme_changed_nslist(NvmeCtrl *n, uint8_t rae, uint32_t buf_len, + uint64_t off, NvmeRequest *req) +{ + uint32_t nslist[1024]; + uint32_t trans_len; + NvmeChangedNs *ns, *next; + int i = 0; + + memset(nslist, 0x0, sizeof(nslist)); + trans_len = MIN(sizeof(nslist) - off, buf_len); + + QTAILQ_FOREACH_SAFE(ns, &n->changed_ns_list, entry, next) { + nslist[i++] = ns->nsid; + + QTAILQ_REMOVE(&n->changed_ns_list, ns, entry); + g_free(ns); + } + + if (!rae) { + nvme_clear_events(n, NVME_AER_TYPE_NOTICE); + } + + return nvme_dma(n, ((uint8_t *)nslist) + off, trans_len, + DMA_DIRECTION_FROM_DEVICE, req); +} + static uint16_t nvme_cmd_effects(NvmeCtrl *n, uint8_t csi, uint32_t buf_len, uint64_t off, NvmeRequest *req) { @@ -3064,6 +3090,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_CHANGED_NSLIST: + return nvme_changed_nslist(n, rae, len, off, req); case NVME_LOG_CMD_EFFECTS: return nvme_cmd_effects(n, csi, len, off, req); default: @@ -3882,6 +3910,7 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req) uint16_t *ids = &list[1]; uint16_t ret; int i; + NvmeChangedNs *changed_nsid; trace_pci_nvme_ns_attachment(nvme_cid(req), dw10 & 0xf); @@ -3920,6 +3949,18 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req) nvme_ns_detach(ctrl, ns); } + + /* + * Add namespace id to the changed namespace id list for event clearing + * via Get Log Page command. + */ + changed_nsid = g_new(NvmeChangedNs, 1); + changed_nsid->nsid = nsid; + QTAILQ_INSERT_TAIL(&ctrl->changed_ns_list, changed_nsid, entry); + + nvme_enqueue_event(ctrl, NVME_AER_TYPE_NOTICE, + NVME_AER_INFO_NOTICE_NS_ATTR_CHANGED, + NVME_LOG_CHANGED_NSLIST); } return NVME_SUCCESS; @@ -4714,6 +4755,7 @@ static void nvme_init_state(NvmeCtrl *n) n->features.temp_thresh_hi = NVME_TEMPERATURE_WARNING; n->starttime_ms = qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL); n->aer_reqs = g_new0(NvmeRequest *, n->params.aerl + 1); + QTAILQ_INIT(&n->changed_ns_list); } static int nvme_attach_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp) @@ -4910,6 +4952,8 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev) id->cntlid = cpu_to_le16(n->cntlid); + id->oaes = cpu_to_le32(NVME_OAES_NS_ATTR); + id->rab = 6; if (n->params.use_intel_id) { diff --git a/hw/block/nvme.h b/hw/block/nvme.h index 74a00ab21a55..d5eaea003ea5 100644 --- a/hw/block/nvme.h +++ b/hw/block/nvme.h @@ -132,6 +132,11 @@ typedef struct NvmeFeatureVal { uint32_t async_config; } NvmeFeatureVal; +typedef struct NvmeChangedNs { + uint32_t nsid; + QTAILQ_ENTRY(NvmeChangedNs) entry; +} NvmeChangedNs; + typedef struct NvmeCtrl { PCIDevice parent_obj; MemoryRegion bar0; @@ -177,6 +182,8 @@ typedef struct NvmeCtrl { QTAILQ_HEAD(, NvmeAsyncEvent) aer_queue; int aer_queued; + QTAILQ_HEAD(, NvmeChangedNs) changed_ns_list; /* Changed NS list log */ + NvmeSubsystem *subsys; NvmeNamespace namespace; diff --git a/include/block/nvme.h b/include/block/nvme.h index 339784d9c23a..eb0b31e949c2 100644 --- a/include/block/nvme.h +++ b/include/block/nvme.h @@ -760,6 +760,7 @@ typedef struct QEMU_PACKED NvmeCopySourceRange { enum NvmeAsyncEventRequest { NVME_AER_TYPE_ERROR = 0, NVME_AER_TYPE_SMART = 1, + NVME_AER_TYPE_NOTICE = 2, NVME_AER_TYPE_IO_SPECIFIC = 6, NVME_AER_TYPE_VENDOR_SPECIFIC = 7, NVME_AER_INFO_ERR_INVALID_DB_REGISTER = 0, @@ -771,6 +772,7 @@ enum NvmeAsyncEventRequest { NVME_AER_INFO_SMART_RELIABILITY = 0, NVME_AER_INFO_SMART_TEMP_THRESH = 1, NVME_AER_INFO_SMART_SPARE_THRESH = 2, + NVME_AER_INFO_NOTICE_NS_ATTR_CHANGED = 0, }; typedef struct QEMU_PACKED NvmeAerResult { @@ -940,6 +942,7 @@ enum NvmeLogIdentifier { NVME_LOG_ERROR_INFO = 0x01, NVME_LOG_SMART_INFO = 0x02, NVME_LOG_FW_SLOT_INFO = 0x03, + NVME_LOG_CHANGED_NSLIST = 0x04, NVME_LOG_CMD_EFFECTS = 0x05, }; @@ -1046,6 +1049,10 @@ typedef struct NvmeIdCtrlZoned { uint8_t rsvd1[4095]; } NvmeIdCtrlZoned; +enum NvmeIdCtrlOaes { + NVME_OAES_NS_ATTR = 1 << 8, +}; + enum NvmeIdCtrlOacs { NVME_OACS_SECURITY = 1 << 0, NVME_OACS_FORMAT = 1 << 1, From patchwork Sun Feb 28 16:11:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minwoo Im X-Patchwork-Id: 1445288 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=tgw95vfH; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DpVkP45sGz9sCD for ; Mon, 1 Mar 2021 04:29:17 +1100 (AEDT) Received: from localhost ([::1]:39810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGPsZ-00079W-FS for incoming@patchwork.ozlabs.org; Sun, 28 Feb 2021 12:29:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGPfp-0001p4-Le; Sun, 28 Feb 2021 12:16:05 -0500 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:45210) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lGPfg-0008Fv-2H; Sun, 28 Feb 2021 12:16:05 -0500 Received: by mail-pg1-x536.google.com with SMTP id p21so9955826pgl.12; Sun, 28 Feb 2021 09:15:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/N+LQlyS49238I2Z5vttSrl07LTW96QPPv3xEPBssx4=; b=tgw95vfHxT1G7qoXHN6dtsT8zFdQ7subnN6y3q4DxIA8oTjDvlNYCmYFRhuthg50Co 4T/2iNTtX2vUB4Y47glMRbrertq4XCRIvektSnCJE0hHuF0GNyug50SyBGmioOULkOkF MWBqsYAXNddxerZfOn01NtcyCJb6j3XB12EDv0G5Wqdge4h+zowcG1rJ7oCS3rO62rSb aDWvQa5azB+jL1dwi3HgxM8lhOmY4RJx/Yn5UQ31Wf9VFqDuzNCmStvqTkIbg3NOVXua lxStliK0BIDWGlp3Lfgy4TP724Ndv3JqEW6X3N+hfiQhd5eqOkW+ELecCOz26V3fiWN7 ZQ+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/N+LQlyS49238I2Z5vttSrl07LTW96QPPv3xEPBssx4=; b=scH3MtXI1hB1OcVBZD5/VkEauHw2RKcojeUQB1jw59WTezEWYbMWXoLiKkxZSpUtRr +UL9SMX/JXVP6RgEo522KpcRIWgS8yxnioTrrOnc+qK0UmuJ4lVT5Ki6BhTgA2EUlAWE OdIRyR/u0muc3XtmA1o3JNZEbBR/lsuJL1tETRNs2PMZNsYmZhaaaw8enxFct5KXIcdH XTX7uUvyUAXGFuhawyoMFEnCuMq0xBqSJPxtUatOEP+Y5lZ4l7a86pZ1Acs9+F+Q0QyL Oz9y+JVW+jFky18WHpiZOgXHqY1zqu+U9A6Cs6E/7eAQzIaKsyAcJdwjO/DzvE4c1XhW M60w== X-Gm-Message-State: AOAM530H6++XgNWoGqB3tw+RuDKb1d3xxW8kusESXZVHyTXK9kFKNi4k +ODAQeKWfg1gImT8MRC/Tx+HnVDRYSTuSg== X-Google-Smtp-Source: ABdhPJztQrUVQxtHe17eR+m3MOIc8TQEGTOnlWLBhZHs5rqFoUZlr0zFEFQZJtHgFo1f0YPwjdVmEQ== X-Received: by 2002:a62:4c1:0:b029:1ee:70e1:75c1 with SMTP id 184-20020a6204c10000b02901ee70e175c1mr3911515pfe.23.1614528686326; Sun, 28 Feb 2021 08:11:26 -0800 (PST) Received: from localhost.localdomain ([211.108.35.36]) by smtp.gmail.com with ESMTPSA id x11sm14389781pja.46.2021.02.28.08.11.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Feb 2021 08:11:26 -0800 (PST) From: Minwoo Im To: qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH V3 8/8] hw/block/nvme: support Identify NS Attached Controller List Date: Mon, 1 Mar 2021 01:11:00 +0900 Message-Id: <20210228161100.54015-9-minwoo.im.dev@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210228161100.54015-1-minwoo.im.dev@gmail.com> References: <20210228161100.54015-1-minwoo.im.dev@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=minwoo.im.dev@gmail.com; helo=mail-pg1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Kevin Wolf , Klaus Jensen , Max Reitz , Klaus Jensen , Minwoo Im , Keith Busch Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Support Identify command for Namespace attached controller list. This command handler will traverse the controller instances in the given subsystem to figure out whether the specified nsid is attached to the controllers or not. The 4096bytes Identify data will return with the first entry (16bits) indicating the number of the controller id entries. So, the data can hold up to 2047 entries for the controller ids. Signed-off-by: Minwoo Im Tested-by: Klaus Jensen Reviewed-by: Klaus Jensen --- hw/block/nvme.c | 42 ++++++++++++++++++++++++++++++++++++++++++ hw/block/trace-events | 1 + include/block/nvme.h | 1 + 3 files changed, 44 insertions(+) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index fc06f806e58e..202fc94d0bb2 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -3286,6 +3286,46 @@ static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeRequest *req, bool active) return NVME_INVALID_CMD_SET | NVME_DNR; } +static uint16_t nvme_identify_ns_attached_list(NvmeCtrl *n, NvmeRequest *req) +{ + NvmeIdentify *c = (NvmeIdentify *)&req->cmd; + uint16_t min_id = le16_to_cpu(c->ctrlid); + uint16_t list[NVME_CONTROLLER_LIST_SIZE] = {}; + uint16_t *ids = &list[1]; + NvmeNamespace *ns; + NvmeCtrl *ctrl; + int cntlid, nr_ids = 0; + + trace_pci_nvme_identify_ns_attached_list(min_id); + + if (c->nsid == NVME_NSID_BROADCAST) { + return NVME_INVALID_FIELD | NVME_DNR; + } + + ns = nvme_subsys_ns(n->subsys, c->nsid); + if (!ns) { + return NVME_INVALID_FIELD | NVME_DNR; + } + + for (cntlid = min_id; cntlid < ARRAY_SIZE(n->subsys->ctrls); cntlid++) { + ctrl = nvme_subsys_ctrl(n->subsys, cntlid); + if (!ctrl) { + continue; + } + + if (!nvme_ns_is_attached(ctrl, ns)) { + continue; + } + + ids[nr_ids++] = cntlid; + } + + list[0] = nr_ids; + + return nvme_dma(n, (uint8_t *)list, sizeof(list), + DMA_DIRECTION_FROM_DEVICE, req); +} + static uint16_t nvme_identify_ns_csi(NvmeCtrl *n, NvmeRequest *req, bool active) { @@ -3485,6 +3525,8 @@ static uint16_t nvme_identify(NvmeCtrl *n, NvmeRequest *req) return nvme_identify_ns(n, req, true); case NVME_ID_CNS_NS_PRESENT: return nvme_identify_ns(n, req, false); + case NVME_ID_CNS_NS_ATTACHED_CTRL_LIST: + return nvme_identify_ns_attached_list(n, req); case NVME_ID_CNS_CS_NS: return nvme_identify_ns_csi(n, req, true); case NVME_ID_CNS_CS_NS_PRESENT: diff --git a/hw/block/trace-events b/hw/block/trace-events index 98d542c999e2..2628d69c7879 100644 --- a/hw/block/trace-events +++ b/hw/block/trace-events @@ -64,6 +64,7 @@ pci_nvme_del_cq(uint16_t cqid) "deleted completion queue, cqid=%"PRIu16"" pci_nvme_identify_ctrl(void) "identify controller" pci_nvme_identify_ctrl_csi(uint8_t csi) "identify controller, csi=0x%"PRIx8"" pci_nvme_identify_ns(uint32_t ns) "nsid %"PRIu32"" +pci_nvme_identify_ns_attached_list(uint16_t cntid) "cntid=%"PRIu16"" pci_nvme_identify_ns_csi(uint32_t ns, uint8_t csi) "nsid=%"PRIu32", csi=0x%"PRIx8"" pci_nvme_identify_nslist(uint32_t ns) "nsid %"PRIu32"" pci_nvme_identify_nslist_csi(uint16_t ns, uint8_t csi) "nsid=%"PRIu16", csi=0x%"PRIx8"" diff --git a/include/block/nvme.h b/include/block/nvme.h index eb0b31e949c2..b18945913927 100644 --- a/include/block/nvme.h +++ b/include/block/nvme.h @@ -971,6 +971,7 @@ enum NvmeIdCns { NVME_ID_CNS_CS_NS_ACTIVE_LIST = 0x07, NVME_ID_CNS_NS_PRESENT_LIST = 0x10, NVME_ID_CNS_NS_PRESENT = 0x11, + NVME_ID_CNS_NS_ATTACHED_CTRL_LIST = 0x12, NVME_ID_CNS_CS_NS_PRESENT_LIST = 0x1a, NVME_ID_CNS_CS_NS_PRESENT = 0x1b, NVME_ID_CNS_IO_COMMAND_SET = 0x1c,