From nobody Wed Aug 26 23:41:54 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=posteo.net ARC-Seal: i=1; a=rsa-sha256; t=1779445832; cv=none; d=zohomail.com; s=zohoarc; b=OUyVPlxQmXAoaAE3nNEvqAZduNrxb2R8QjMzqHIbXZjh8Sn00c87TT7jkkMirmmn/IiYhRZbZUuO7w5mSnsH/+9MjbAwKQfTuoubmojeika/vdPg3AY9uJi0Tl24Zd3Lw/vWWHraGjZIA91T5dDXjzC3zLziWZAMTUXHGYhgtcg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779445832; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=O7kEDERCXmt2AhuexqxHG0yR53P6PmbKGP3KLII922U=; b=gwjeIPNHu+3ekGo0zNl4E3VNhYaWP9koxBN/kKbzb+BjKI4mHyzvYNmFN9QqURwK5fhkEBUyFd4PIjScpfNO545pwnm/WJhOxeK3U4TjkFVyFCcxjGU2CmGcr8hTZO4J64Nc8j4/8z8jFwfPmEkLcPqA/NNWBbGWzlhvPONxGrs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177944583264584.23128263429601; Fri, 22 May 2026 03:30:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQN8O-0002XT-AP; Fri, 22 May 2026 06:29:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQN87-0002UM-Tw for qemu-devel@nongnu.org; Fri, 22 May 2026 06:29:24 -0400 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQN84-0004qt-Nl for qemu-devel@nongnu.org; Fri, 22 May 2026 06:29:23 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 659DC240101 for ; Fri, 22 May 2026 12:29:19 +0200 (CEST) Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4gMM2j6ZFzz9rxD; Fri, 22 May 2026 12:29:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=posteo.net; s=2017; t=1779445759; bh=O7kEDERCXmt2AhuexqxHG0yR53P6PmbKGP3KLII922U=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:From; b=XbWLVAd7wTfsIZw10+KmtbdgwPUtJz8KGAGYnBnUo1ndnddlcjRos2bXetiQEzSAe PPpXlUhk3RW6mQrgE3/P5hIhpFMINLM526S0XsDjQNAUD09x69AD+fBxTbjiYjwPA5 Q1EDggBqcg/vOsT2dEuwcSFMSn3VTj2E+ViUQw3kUh2CoFIXIVQCi1kdOSkBHlEOIV 73Hv45a7PnlfamFS/wlHDFSsdenrifpt+qRfAQWkUw+q0/Rs/3zbQSfPpWULsIOrYD +y7H1uGzoNXHB+br1FbdDgvgwGo94E0zpkVYFw3hjBgHsCglv4uTj4Biujbxzeae3r J7EtB5itLnyzw== From: Mateusz Nowicki To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , Keith Busch , Klaus Jensen , Jesper Devantier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Zhao Liu , Eric Blake , Markus Armbruster , qemu-block@nongnu.org Subject: [PATCH v3 1/2] hw/nvme: add 'info nvme' HMP command Date: Fri, 22 May 2026 10:29:18 +0000 Message-ID: <20260522102821.16766-2-mateusz.nowicki@posteo.net> In-Reply-To: <20260522102821.16766-1-mateusz.nowicki@posteo.net> References: <20260522102821.16766-1-mateusz.nowicki@posteo.net> 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=lists1p.gnu.org; Received-SPF: pass client-ip=185.67.36.66; envelope-from=mateusz.nowicki@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, 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.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @posteo.net) X-ZM-MESSAGEID: 1779445838247154100 Content-Type: text/plain; charset="utf-8" Add an 'info nvme' HMP command for inspecting emulated NVMe controllers from the QEMU monitor. For each NVMe controller in the QOM tree the command prints: - PCI BDF, vendor/device ID and BAR0 base address; - Identify Controller fields visible to the host driver: SN, MN, FR and CNTLID; - the CC, CSTS and AQA registers (raw 32-bit values); - the number of admin and active I/O submission/completion queues. Useful when debugging the Linux NVMe driver against the QEMU emulation without attaching gdb to the QEMU process. Example: (qemu) info nvme /machine/peripheral-anon/device[0] PCI: BDF 00:04.0 VID=3D8086 DID=3D5845 BAR0=3D0x00000000feb50000 ID: SN=3DNVME0001 MN=3DQEMU NVMe Ctrl FR=3D... CNTLID=3D0x0000 CC: 0x00460001 CSTS: 0x00000001 AQA: 0x001f001f Queues: 1 admin + 4 IO SQ / 4 IO CQ Signed-off-by: Mateusz Nowicki Acked-by: Dr. David Alan Gilbert Acked-by: Markus Armbruster --- hmp-commands-info.hx | 13 ++++++++ hw/nvme/meson.build | 2 +- hw/nvme/monitor.c | 76 ++++++++++++++++++++++++++++++++++++++++++++ qapi/machine.json | 17 ++++++++++ 4 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 hw/nvme/monitor.c diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index 82134eb6c2..b984691c3c 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -340,6 +340,19 @@ SRST Show guest USB devices. ERST =20 + { + .name =3D "nvme", + .args_type =3D "", + .params =3D "", + .help =3D "show emulated NVMe controllers", + .cmd_info_hrt =3D qmp_x_query_nvme, + }, + +SRST + ``info nvme`` + Show emulated NVMe controllers. +ERST + { .name =3D "usbhost", .args_type =3D "", diff --git a/hw/nvme/meson.build b/hw/nvme/meson.build index 7d5caa53c2..33dee048b0 100644 --- a/hw/nvme/meson.build +++ b/hw/nvme/meson.build @@ -1 +1 @@ -system_ss.add(when: 'CONFIG_NVME_PCI', if_true: files('ctrl.c', 'dif.c', '= ns.c', 'subsys.c', 'nguid.c')) \ No newline at end of file +system_ss.add(when: 'CONFIG_NVME_PCI', if_true: files('ctrl.c', 'dif.c', '= ns.c', 'subsys.c', 'nguid.c', 'monitor.c')) diff --git a/hw/nvme/monitor.c b/hw/nvme/monitor.c new file mode 100644 index 0000000000..4f70bfe3ec --- /dev/null +++ b/hw/nvme/monitor.c @@ -0,0 +1,76 @@ +/* + * QEMU NVMe Controller monitor commands + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qapi/qapi-commands-machine.h" +#include "qapi/type-helpers.h" +#include "hw/pci/pci.h" + +#include "nvme.h" + +static int collect_one(Object *obj, void *opaque) +{ + GString *buf =3D opaque; + NvmeCtrl *n; + PCIDevice *pci; + pcibus_t bar0; + unsigned io_sq =3D 0, io_cq =3D 0; + + if (!object_dynamic_cast(obj, TYPE_NVME)) { + return 0; + } + n =3D NVME(obj); + pci =3D PCI_DEVICE(n); + bar0 =3D pci_get_bar_addr(pci, 0); + + for (unsigned i =3D 1; i <=3D n->conf_ioqpairs; i++) { + if (n->sq && n->sq[i]) { + io_sq++; + } + if (n->cq && n->cq[i]) { + io_cq++; + } + } + + g_string_append_printf(buf, "%s\n", object_get_canonical_path(obj)); + g_string_append_printf(buf, + " PCI: BDF %02x:%02x.%x VID=3D%04x DID=3D%04x ", + pci_dev_bus_num(pci), PCI_SLOT(pci->devfn), PCI_FUNC(pci->devfn), + pci_get_word(pci->config + PCI_VENDOR_ID), + pci_get_word(pci->config + PCI_DEVICE_ID)); + if (bar0 =3D=3D PCI_BAR_UNMAPPED) { + g_string_append(buf, "BAR0=3Dunmapped\n"); + } else { + g_string_append_printf(buf, "BAR0=3D0x%016" PRIx64 "\n", + (uint64_t)bar0); + } + g_string_append_printf(buf, + " ID: SN=3D%.20s MN=3D%.40s FR=3D%.8s CNTLID=3D0x%04x\n", + n->id_ctrl.sn, n->id_ctrl.mn, n->id_ctrl.fr, n->cntlid); + g_string_append_printf(buf, " CC: 0x%08x\n", + ldl_le_p(&n->bar.cc)); + g_string_append_printf(buf, " CSTS: 0x%08x\n", + ldl_le_p(&n->bar.csts)); + g_string_append_printf(buf, " AQA: 0x%08x\n", + ldl_le_p(&n->bar.aqa)); + g_string_append_printf(buf, + " Queues: 1 admin + %u IO SQ / %u IO CQ\n", io_sq, io_cq); + return 0; +} + +HumanReadableText *qmp_x_query_nvme(Error **errp) +{ + g_autoptr(GString) buf =3D g_string_new(""); + + object_child_foreach_recursive(object_get_root(), collect_one, buf); + + if (buf->len =3D=3D 0) { + g_string_append(buf, "no NVMe controllers\n"); + } + + return human_readable_text_from_str(buf); +} diff --git a/qapi/machine.json b/qapi/machine.json index 685e4e29b8..d4a589e768 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -1772,6 +1772,23 @@ 'returns': 'HumanReadableText', 'features': [ 'unstable' ] } =20 +## +# @x-query-nvme: +# +# Query state of emulated NVMe controllers. +# +# Features: +# +# @unstable: This command is meant for debugging. +# +# Returns: NVMe controller state as human-readable text +# +# Since: 11.1 +## +{ 'command': 'x-query-nvme', + 'returns': 'HumanReadableText', + 'features': [ 'unstable' ] } + ## # @SmbiosEntryPointType: # --=20 2.53.0