From nobody Fri Nov 14 06:40:03 2025 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585821857; cv=none; d=zohomail.com; s=zohoarc; b=c3fqAYF7pCll+HU1EDlNSCT0xbG9UL36qA3IXdQ2mFuMq59gfuOZYAir/k3iByd+EPcGTbwfxTf7czviYm3oVt8qI20+M2FQcFnNvnlYKpR/3w2/+Ho7BAEipYkHOdLuwdbLtnaGOoKoYtT/96oEeV+o2eIni1Fpg3CWTMWpceY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585821857; h=Content-Type: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=tvgfezloZrAjX420POU658d+F1XbXKjiVs06aMGcRJM=; b=UgvY4VAdvbK5mfqSJoNk2DUuhdJ0ugD2etCoPTZSmRQbNQw+eak3iI8VmCqd2p++RT0T7o8dsZhNHN0qglSv6Qsj22KclNkkj1bVJ3onpn3bRuWsMmMYx/Rsau2vbgojTa0GQCa5m0IWMwA21BxMB3KvlgIV+w4/XBzvppDnCLw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1585821857030478.91811354317906; Thu, 2 Apr 2020 03:04:17 -0700 (PDT) Received: from localhost ([::1]:36350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJwhr-0002Qv-IT for importer@patchew.org; Thu, 02 Apr 2020 06:04:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33818) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJwgw-0001Hw-OK for qemu-devel@nongnu.org; Thu, 02 Apr 2020 06:03:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJwgv-0000LZ-8f for qemu-devel@nongnu.org; Thu, 02 Apr 2020 06:03:18 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:37406 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJwgv-0000LP-4y for qemu-devel@nongnu.org; Thu, 02 Apr 2020 06:03:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-449-ooLDMRAuPS2XatEYKVdjIg-1; Thu, 02 Apr 2020 06:03:15 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5E1AB1084424; Thu, 2 Apr 2020 10:03:14 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-113-198.ams2.redhat.com [10.36.113.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 072755D9CD; Thu, 2 Apr 2020 10:03:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585821796; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tvgfezloZrAjX420POU658d+F1XbXKjiVs06aMGcRJM=; b=VNOs9HMszEGPpJLOrKyQ2ZPGss5C816qDxg84vi7ylbLogqLR+04mlUfauIxYjLBpY1B+G RVnx8hMJ4I8Sw9X3H37Oyjn+pvfdvWknowh4deLDQxDyx4B/4wQvxM0QPAlkDB3p7ICL38 IpP2o+Q6tsrozhX2Z0QVSKybtXt45UY= X-MC-Unique: ooLDMRAuPS2XatEYKVdjIg-1 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [RFC 1/5] qmp: add QMP command query-virtio Date: Thu, 2 Apr 2020 12:02:58 +0200 Message-Id: <20200402100302.833267-2-lvivier@redhat.com> In-Reply-To: <20200402100302.833267-1-lvivier@redhat.com> References: <20200402100302.833267-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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: Laurent Vivier , Thomas Huth , "Michael S. Tsirkin" , Markus Armbruster , "Dr. David Alan Gilbert" , Michael Roth , Paolo Bonzini 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 new command lists all the instances of VirtIODevice with their path and virtio type Signed-off-by: Laurent Vivier --- hw/virtio/Makefile.objs | 2 ++ hw/virtio/virtio-stub.c | 14 ++++++++++ hw/virtio/virtio.c | 27 +++++++++++++++++++ include/hw/virtio/virtio.h | 1 + qapi/Makefile.objs | 2 +- qapi/qapi-schema.json | 1 + qapi/virtio.json | 54 ++++++++++++++++++++++++++++++++++++++ tests/qtest/qmp-cmd-test.c | 1 + 8 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 hw/virtio/virtio-stub.c create mode 100644 qapi/virtio.json diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index 4e4d39a0a48f..0b649f120044 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -38,6 +38,8 @@ obj-$(CONFIG_VIRTIO_SERIAL) +=3D virtio-serial-pci.o endif else common-obj-y +=3D vhost-stub.o +common-obj-y +=3D virtio-stub.o endif =20 common-obj-$(CONFIG_ALL) +=3D vhost-stub.o +common-obj-$(CONFIG_ALL) +=3D virtio-stub.o diff --git a/hw/virtio/virtio-stub.c b/hw/virtio/virtio-stub.c new file mode 100644 index 000000000000..d9e4a815ecf1 --- /dev/null +++ b/hw/virtio/virtio-stub.c @@ -0,0 +1,14 @@ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qapi/qapi-commands-virtio.h" + +static void *qmp_virtio_unsupported(Error **errp) +{ + error_setg(errp, "Virtio is disabled"); + return NULL; +} + +VirtioInfoList *qmp_query_virtio(Error **errp) +{ + return qmp_virtio_unsupported(errp); +} diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index b6c8ef5bc025..3cebc3d169c8 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -13,6 +13,8 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/qapi-commands-virtio.h" +#include "qapi/qapi-visit-virtio.h" #include "cpu.h" #include "trace.h" #include "exec/address-spaces.h" @@ -28,6 +30,8 @@ #include "sysemu/dma.h" #include "sysemu/runstate.h" =20 +static QTAILQ_HEAD(, VirtIODevice) virtio_list; + /* * The alignment to use between consumer and producer parts of vring. * x86 pagesize again. This is the default, used by transports like PCI @@ -3628,6 +3632,7 @@ static void virtio_device_realize(DeviceState *dev, E= rror **errp) =20 vdev->listener.commit =3D virtio_memory_listener_commit; memory_listener_register(&vdev->listener, vdev->dma_as); + QTAILQ_INSERT_TAIL(&virtio_list, vdev, next); } =20 static void virtio_device_unrealize(DeviceState *dev, Error **errp) @@ -3646,6 +3651,7 @@ static void virtio_device_unrealize(DeviceState *dev,= Error **errp) } } =20 + QTAILQ_REMOVE(&virtio_list, vdev, next); g_free(vdev->bus_name); vdev->bus_name =3D NULL; } @@ -3802,6 +3808,8 @@ static void virtio_device_class_init(ObjectClass *kla= ss, void *data) vdc->stop_ioeventfd =3D virtio_device_stop_ioeventfd_impl; =20 vdc->legacy_features |=3D VIRTIO_LEGACY_FEATURES; + + QTAILQ_INIT(&virtio_list); } =20 bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev) @@ -3812,6 +3820,25 @@ bool virtio_device_ioeventfd_enabled(VirtIODevice *v= dev) return virtio_bus_ioeventfd_enabled(vbus); } =20 +VirtioInfoList *qmp_query_virtio(Error **errp) +{ + VirtioInfoList *list =3D NULL; + VirtioInfoList *node; + VirtIODevice *vdev; + + QTAILQ_FOREACH(vdev, &virtio_list, next) { + DeviceState *dev =3D DEVICE(vdev); + node =3D g_new0(VirtioInfoList, 1); + node->value =3D g_new(VirtioInfo, 1); + node->value->type =3D g_strdup(vdev->name); + node->value->path =3D g_strdup(dev->canonical_path); + node->next =3D list; + list =3D node; + } + + return list; +} + static const TypeInfo virtio_device_info =3D { .name =3D TYPE_VIRTIO_DEVICE, .parent =3D TYPE_DEVICE, diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index b69d51749635..65adce680188 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -111,6 +111,7 @@ struct VirtIODevice bool use_guest_notifier_mask; AddressSpace *dma_as; QLIST_HEAD(, VirtQueue) *vector_queues; + QTAILQ_ENTRY(VirtIODevice) next; }; =20 typedef struct VirtioDeviceClass { diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs index 4673ab7490df..4fae2e37cfc9 100644 --- a/qapi/Makefile.objs +++ b/qapi/Makefile.objs @@ -8,7 +8,7 @@ util-obj-y +=3D qapi-util.o QAPI_COMMON_MODULES =3D audio authz block-core block char common control c= rypto QAPI_COMMON_MODULES +=3D dump error introspect job machine migration misc QAPI_COMMON_MODULES +=3D net pragma qdev qom rdma rocker run-state sockets= tpm -QAPI_COMMON_MODULES +=3D trace transaction ui +QAPI_COMMON_MODULES +=3D trace transaction ui virtio QAPI_TARGET_MODULES =3D machine-target misc-target QAPI_MODULES =3D $(QAPI_COMMON_MODULES) $(QAPI_TARGET_MODULES) =20 diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json index 43b0ba0dea22..189f5a0a7383 100644 --- a/qapi/qapi-schema.json +++ b/qapi/qapi-schema.json @@ -84,3 +84,4 @@ { 'include': 'misc.json' } { 'include': 'misc-target.json' } { 'include': 'audio.json' } +{ 'include': 'virtio.json' } diff --git a/qapi/virtio.json b/qapi/virtio.json new file mode 100644 index 000000000000..2a95d08a8b9e --- /dev/null +++ b/qapi/virtio.json @@ -0,0 +1,54 @@ +## +# =3D Virtio devices +## + +## +# @VirtioInfo: +# +# Information about a given VirtIODevice +# +# @type: VirtIO device type. +# +# @path: VirtIO device canonical path. +# +# Since: 5.1 +# +## +{ 'struct': 'VirtioInfo', + 'data': { + 'path': 'str', + 'type': 'str' + } +} + +## +# @query-virtio: +# +# Return the list of all VirtIO devices +# +# Returns: list of @VirtioInfo +# +# Since: 5.1 +# +# Example: +# +# -> { "execute": "query-virtio" } +# <- { "return": [ +# { +# "path": "/machine/peripheral-anon/device[3]/virtio-backend", +# "type": "virtio-net" +# }, +# { +# "path": "/machine/peripheral-anon/device[1]/virtio-backend", +# "type": "virtio-serial" +# }, +# { +# "path": "/machine/peripheral-anon/device[0]/virtio-backend", +# "type": "virtio-blk" +# } +# ] +# } +# +## + +{ 'command': 'query-virtio', 'returns': ['VirtioInfo'] } diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c index 9f5228cd9951..c0342c3a3075 100644 --- a/tests/qtest/qmp-cmd-test.c +++ b/tests/qtest/qmp-cmd-test.c @@ -92,6 +92,7 @@ static bool query_is_blacklisted(const char *cmd) "query-gic-capabilities", /* arm */ /* Success depends on target-specific build configuration: */ "query-pci", /* CONFIG_PCI */ + "query-virtio", /* CONFIG_VIRTIO */ /* Success depends on launching SEV guest */ "query-sev-launch-measure", /* Success depends on Host or Hypervisor SEV support */ --=20 2.25.1 From nobody Fri Nov 14 06:40:03 2025 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585821940; cv=none; d=zohomail.com; s=zohoarc; b=BCRL6M83u3MydTtyq7GAoZdmjlDZ0qlKGblMfFIQCudVV565rPX7NnMpiUe05dpl1/jSt7deYeRBdx9auHt6OskNsPp9It2BA5A4fuD0yb9kkLNpAlO+Iip5TvfAdcPJpuknvJzajkmpPdhygIsri26FdYBc4eHE7IEgcCzHfcA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585821940; h=Content-Type: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=O3I/cokbs6mFo+fIVGu+390hXkIUUIIvuyOMxyh2eEc=; b=DxdAesnTvwZs3a278RM5bwSkavgn0hvM7oSMKzambInmU+6oWjy3NIjrMw7m9y4DcFKtlbaNIsSkodYnfWIAuNwiLa5JMFaGzOFCC6gSJieSv4px6JkvbxaadTBz9h8g2R4tDUTvP1i/FWFs3Y732s7PyxEpVcZ3vFWSzXbHkc0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1585821940792363.486303543586; Thu, 2 Apr 2020 03:05:40 -0700 (PDT) Received: from localhost ([::1]:36366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJwjD-0004jF-JH for importer@patchew.org; Thu, 02 Apr 2020 06:05:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33832) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJwgz-0001K3-8N for qemu-devel@nongnu.org; Thu, 02 Apr 2020 06:03:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJwgy-0000Rs-0s for qemu-devel@nongnu.org; Thu, 02 Apr 2020 06:03:21 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:22083 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJwgx-0000RF-Pu for qemu-devel@nongnu.org; Thu, 02 Apr 2020 06:03:19 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-410-1hTzJb0ZOhS8NcwnyZgGbA-1; Thu, 02 Apr 2020 06:03:17 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DFBE018A5526; Thu, 2 Apr 2020 10:03:16 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-113-198.ams2.redhat.com [10.36.113.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id B34E75DA66; Thu, 2 Apr 2020 10:03:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585821799; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O3I/cokbs6mFo+fIVGu+390hXkIUUIIvuyOMxyh2eEc=; b=gId4pP804dH1TjfLzNfD6e8PAhCiwXInsnZCI/kAgEvFX9EkBtHZNnPXTetIhxrKw0JtX9 PoMMEt0g5NFwiqz6GVyMYsmCvVF1LFtUXWecOrxuWTZ2l2jYeCbUs63YdBw4lvgr3eZTyS 0m4jHc5CHnXWoZXKNDRQFl7y3IvIjB8= X-MC-Unique: 1hTzJb0ZOhS8NcwnyZgGbA-1 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [RFC 2/5] qmp: add QMP command virtio-status Date: Thu, 2 Apr 2020 12:02:59 +0200 Message-Id: <20200402100302.833267-3-lvivier@redhat.com> In-Reply-To: <20200402100302.833267-1-lvivier@redhat.com> References: <20200402100302.833267-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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: Laurent Vivier , Thomas Huth , "Michael S. Tsirkin" , Markus Armbruster , "Dr. David Alan Gilbert" , Michael Roth , Paolo Bonzini 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 new command shows the status of a VirtIODevice (features, endianness and number of virtqueues) Signed-off-by: Laurent Vivier --- hw/virtio/virtio-stub.c | 5 ++++ hw/virtio/virtio.c | 51 ++++++++++++++++++++++++++++++++ qapi/virtio.json | 65 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) diff --git a/hw/virtio/virtio-stub.c b/hw/virtio/virtio-stub.c index d9e4a815ecf1..8fe2d6cd8892 100644 --- a/hw/virtio/virtio-stub.c +++ b/hw/virtio/virtio-stub.c @@ -12,3 +12,8 @@ VirtioInfoList *qmp_query_virtio(Error **errp) { return qmp_virtio_unsupported(errp); } + +VirtioStatus *qmp_virtio_status(const char* path, Error **errp) +{ + return qmp_virtio_unsupported(errp); +} diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 3cebc3d169c8..7f6e21e4ab2c 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3839,6 +3839,57 @@ VirtioInfoList *qmp_query_virtio(Error **errp) return list; } =20 +static VirtIODevice *virtio_device_find(const char *path) +{ + VirtIODevice *vdev; + + QTAILQ_FOREACH(vdev, &virtio_list, next) { + DeviceState *dev =3D DEVICE(vdev); + + if (strcmp(dev->canonical_path, path) !=3D 0) { + continue; + } + return vdev; + } + + return NULL; +} + +VirtioStatus *qmp_virtio_status(const char* path, Error **errp) +{ + VirtIODevice *vdev; + VirtioStatus *status; + + vdev =3D virtio_device_find(path); + if (vdev =3D=3D NULL) { + error_setg(errp, "Path %s is not a VirtIO device", path); + return NULL; + } + + status =3D g_new0(VirtioStatus, 1); + status->guest_features =3D vdev->guest_features; + status->host_features =3D vdev->host_features; + status->backend_features =3D vdev->backend_features; + status->device_id =3D vdev->device_id; + + switch (vdev->device_endian) { + case VIRTIO_DEVICE_ENDIAN_LITTLE: + status->device_endian =3D g_strdup("little"); + break; + case VIRTIO_DEVICE_ENDIAN_BIG: + status->device_endian =3D g_strdup("big"); + break; + case VIRTIO_DEVICE_ENDIAN_UNKNOWN: + default: + status->device_endian =3D g_strdup("unknown"); + break; + } + + status->num_vqs =3D virtio_get_num_queues(vdev); + + return status; +} + static const TypeInfo virtio_device_info =3D { .name =3D TYPE_VIRTIO_DEVICE, .parent =3D TYPE_DEVICE, diff --git a/qapi/virtio.json b/qapi/virtio.json index 2a95d08a8b9e..2af4d95b9893 100644 --- a/qapi/virtio.json +++ b/qapi/virtio.json @@ -52,3 +52,68 @@ ## =20 { 'command': 'query-virtio', 'returns': ['VirtioInfo'] } + +## +# @VirtioStatus: +# +# @device_id: VirtIODevice status +# +# @device_endian: VirtIODevice device_endian +# +# @guest_features: VirtIODevice guest_features +# +# @host_features: VirtIODevice host_features +# +# @backend_features: VirtIODevice backend_features +# +# @num_vqs: number of VirtIODevice queues +# +# Since: 5.1 +# +## + +{ 'struct': 'VirtioStatus', + 'data': { + 'device_id': 'int', + 'device_endian': 'str', + 'guest_features': 'uint64', + 'host_features': 'uint64', + 'backend_features': 'uint64', + 'num_vqs': 'uint16' + } +} + +## +# @virtio-status: +# +# Return the status of virtio device +# +# @path: QOBject path of the VirtIODevice +# +# Returns: status of the VirtIODevice +# +# Since: 5.1 +# +# Example: +# +# -> { "execute": "virtio-status", +# "arguments": { +# "path": "/machine/peripheral-anon/device[3]/virtio-backend" +# } +# } +# <- { "return": { +# "backend_features": 0, +# "guest_features": 5111807911, +# "num_vqs": 3, +# "host_features": 6337593319, +# "device_endian": "little", +# "device_id": 1 +# } +# } +# +## + +{ 'command': 'virtio-status', + 'data': { 'path': 'str' }, + 'returns': 'VirtioStatus' +} --=20 2.25.1 From nobody Fri Nov 14 06:40:03 2025 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585821945; cv=none; d=zohomail.com; s=zohoarc; b=gfoCLY9FDYJi1dh2umZPz8HaiEXIHT99XuYlaDjihpgkLXoDVQwdN9A0f3eyX5RT/k0V9Z5EN1Qt2bqjdlAYsExAKfC7xBt8wRO2Br1e6yPgpXJ+pBWA9JSdrhIyEVlca+sqlu5RRWSfnSQDNGrA/j0b6c4BpxeEhmmwFy6DBMI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585821945; h=Content-Type: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=Kep3V9mG5AJTYZhlUeT2WOe008YTZEEiwjQV6Q9cMjM=; b=M36SAb6Rwb0h7MTz4VeQW19r4mndcsUVObAw1FM6EkimnLJQxn8LCp++jycUxW8xhHg0WZARGFM475i6U/QQrpEnPCqh5Sm42+NSN72mzZCaqodsfJQY2FJFHm8M3bnniBFb2F7EVNltXxCGSFC034mt1KWRfceN0YZRj5ToXpI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1585821945421123.64367100191089; Thu, 2 Apr 2020 03:05:45 -0700 (PDT) Received: from localhost ([::1]:36368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJwjI-0004o6-5N for importer@patchew.org; Thu, 02 Apr 2020 06:05:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33846) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJwh3-0001RC-OI for qemu-devel@nongnu.org; Thu, 02 Apr 2020 06:03:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJwh2-0000Uf-CR for qemu-devel@nongnu.org; Thu, 02 Apr 2020 06:03:25 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:38912 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJwh2-0000TO-8o for qemu-devel@nongnu.org; Thu, 02 Apr 2020 06:03:24 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-220-QymQzCAcOsuahTgZarNpnw-1; Thu, 02 Apr 2020 06:03:20 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8E27F8017F5; Thu, 2 Apr 2020 10:03:19 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-113-198.ams2.redhat.com [10.36.113.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4413B5DA2C; Thu, 2 Apr 2020 10:03:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585821803; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kep3V9mG5AJTYZhlUeT2WOe008YTZEEiwjQV6Q9cMjM=; b=N3GSzdjGxmwQNtOMw63/E+cmJB8zYyTo5OltD+1NTwSMLf7QJyZlA0g6uH/9VycEWu/Qw4 f46qZNEcl9M8LacX66ZHG/Y+IYyuPP31KsXA/sIp7amU6PMIVimw+b04QSPP9wqyDuRsrs Q6sat3ugFBiSpoj3QclypAPhebHjDFM= X-MC-Unique: QymQzCAcOsuahTgZarNpnw-1 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [RFC 3/5] qmp: add QMP command virtio-queue-status Date: Thu, 2 Apr 2020 12:03:00 +0200 Message-Id: <20200402100302.833267-4-lvivier@redhat.com> In-Reply-To: <20200402100302.833267-1-lvivier@redhat.com> References: <20200402100302.833267-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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: Laurent Vivier , Thomas Huth , "Michael S. Tsirkin" , Markus Armbruster , "Dr. David Alan Gilbert" , Michael Roth , Paolo Bonzini 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 new command shows internal status of a VirtQueue. (vrings and indexes). Signed-off-by: Laurent Vivier --- hw/virtio/virtio-stub.c | 6 +++ hw/virtio/virtio.c | 35 +++++++++++++++ qapi/virtio.json | 98 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+) diff --git a/hw/virtio/virtio-stub.c b/hw/virtio/virtio-stub.c index 8fe2d6cd8892..5b4ed6fd531e 100644 --- a/hw/virtio/virtio-stub.c +++ b/hw/virtio/virtio-stub.c @@ -17,3 +17,9 @@ VirtioStatus *qmp_virtio_status(const char* path, Error *= *errp) { return qmp_virtio_unsupported(errp); } + +VirtQueueStatus *qmp_virtio_queue_status(const char *path, uint16_t queue, + Error **errp) +{ + return qmp_virtio_unsupported(errp); +} diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 7f6e21e4ab2c..271d4ca3417f 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3855,6 +3855,41 @@ static VirtIODevice *virtio_device_find(const char *= path) return NULL; } =20 +VirtQueueStatus *qmp_virtio_queue_status(const char *path, uint16_t queue, + Error **errp) +{ + VirtIODevice *vdev; + VirtQueueStatus *status; + + vdev =3D virtio_device_find(path); + if (vdev =3D=3D NULL) { + error_setg(errp, "Path %s is not a VirtIO device", path); + return NULL; + } + + if (queue >=3D VIRTIO_QUEUE_MAX || !virtio_queue_get_num(vdev, queue))= { + error_setg(errp, "Invalid virtqueue number %d", queue); + return NULL; + } + + status =3D g_new0(VirtQueueStatus, 1); + status->queue_index =3D vdev->vq[queue].queue_index; + status->inuse =3D vdev->vq[queue].inuse; + status->vring_num =3D vdev->vq[queue].vring.num; + status->vring_num_default =3D vdev->vq[queue].vring.num_default; + status->vring_align =3D vdev->vq[queue].vring.align; + status->vring_desc =3D vdev->vq[queue].vring.desc; + status->vring_avail =3D vdev->vq[queue].vring.avail; + status->vring_used =3D vdev->vq[queue].vring.used; + status->last_avail_idx =3D vdev->vq[queue].last_avail_idx; + status->shadow_avail_idx =3D vdev->vq[queue].shadow_avail_idx; + status->used_idx =3D vdev->vq[queue].used_idx; + status->signalled_used =3D vdev->vq[queue].signalled_used; + status->signalled_used_valid =3D vdev->vq[queue].signalled_used_valid; + + return status; +} + VirtioStatus *qmp_virtio_status(const char* path, Error **errp) { VirtIODevice *vdev; diff --git a/qapi/virtio.json b/qapi/virtio.json index 2af4d95b9893..ab70500d919b 100644 --- a/qapi/virtio.json +++ b/qapi/virtio.json @@ -117,3 +117,101 @@ 'data': { 'path': 'str' }, 'returns': 'VirtioStatus' } + +## +# @VirtQueueStatus: +# +# Status of a VirtQueue +# +# @queue_index: VirtQueue queue_index +# +# @inuse: VirtQueue inuse +# +# @vring_num: VirtQueue vring.num +# +# @vring_num_default: VirtQueue vring.num_default +# +# @vring_align: VirtQueue vring.align +# +# @vring_desc: VirtQueue vring.desc +# +# @vring_avail: VirtQueue vring.avail +# +# @vring_used: VirtQueue vring.used +# +# @last_avail_idx: VirtQueue last_avail_idx +# +# @shadow_avail_idx: VirtQueue shadow_avail_idx +# +# @used_idx: VirtQueue used_idx +# +# @signalled_used: VirtQueue signalled_used +# +# @signalled_used_valid: VirtQueue signalled_used_valid +# +# Since: 5.1 +# +## + +{ 'struct': 'VirtQueueStatus', + 'data': { + 'queue_index': 'uint16', + 'inuse': 'uint32', + 'vring_num': 'int', + 'vring_num_default': 'int', + 'vring_align': 'int', + 'vring_desc': 'uint64', + 'vring_avail': 'uint64', + 'vring_used': 'uint64', + 'last_avail_idx': 'uint16', + 'shadow_avail_idx': 'uint16', + 'used_idx': 'uint16', + 'signalled_used': 'uint16', + 'signalled_used_valid': 'uint16' + } +} + +## +# @virtio-queue-status: +# +# Return the status of a given VirtQueue +# +# @path: QOBject path of the VirtIODevice +# +# @queue: queue number to examine +# +# Returns: Status of the VirtQueue +# +# Since: 5.1 +# +# Example: +# +# -> { "execute": "virtio-queue-status", +# "arguments": { +# "path": "/machine/peripheral-anon/device[3]/virtio-backend", +# "queue": 0 +# } +# } +# <- { "return": { +# "signalled_used": 373, +# "inuse": 0, +# "vring_desc": 864411648, +# "vring_num_default": 256, +# "signalled_used_valid": 1, +# "vring_avail": 864415744, +# "last_avail_idx": 373, +# "queue_index": 0, +# "vring_used": 864416320, +# "shadow_avail_idx": 619, +# "used_idx": 373, +# "vring_num": 256, +# "vring_align": 4096 +# } +# } +# +## + +{ 'command': 'virtio-queue-status', + 'data': { 'path': 'str', 'queue': 'uint16' }, + 'returns': 'VirtQueueStatus' +} --=20 2.25.1 From nobody Fri Nov 14 06:40:03 2025 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585821872; cv=none; d=zohomail.com; s=zohoarc; b=YCxsxbRNp/ITCKv5c3i5ky5KP6Dsba+O5DNT+EL2YU+akL6zv/PgTMGK7k5vBmnSiSEuTruLrxHBr+ShI4Pdz10Or2TWQQUsZibLYIENZYRr4Y805OFjeulgcT0J8IbOChcRHgnHzpDYxPJCHbAmM9kiALEbGgl224ds4y0Zyf8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585821872; h=Content-Type: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=y90R9B+sf9jiqO/bPRDIc8KgaAKqA+0F5s8vPipXh24=; b=JQag0BgTXqZ7CCLQu4ik2LHuD+1u5DfwBxQjbYaiibl+EkuvR5NWrYyzeY5HClW13vM8NUWOuBTeb3ldYEp+nY86aGdVsChsptB2lLETTk0lIhKBCXO2CY1KsMWY2x4B2m5WrtFcjD3ZxLNCbPmAd7BsV/YisHJLyip4gznpCfQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1585821872294814.4183132830619; Thu, 2 Apr 2020 03:04:32 -0700 (PDT) Received: from localhost ([::1]:36352 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJwi6-0002rm-Rp for importer@patchew.org; Thu, 02 Apr 2020 06:04:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33862) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJwh6-0001WE-QP for qemu-devel@nongnu.org; Thu, 02 Apr 2020 06:03:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJwh5-0000Vc-2a for qemu-devel@nongnu.org; Thu, 02 Apr 2020 06:03:28 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:35739 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJwh4-0000VR-Us for qemu-devel@nongnu.org; Thu, 02 Apr 2020 06:03:27 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-184-pl439HljPsKIi2N_sKJEZQ-1; Thu, 02 Apr 2020 06:03:23 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 353B48017F3; Thu, 2 Apr 2020 10:03:22 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-113-198.ams2.redhat.com [10.36.113.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id E399A5DA76; Thu, 2 Apr 2020 10:03:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585821806; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y90R9B+sf9jiqO/bPRDIc8KgaAKqA+0F5s8vPipXh24=; b=DvbYu3Tc0oM1wq6Ce1jZGjJDmlLqSz4+pnk/OTazh6a1jk2pz/4vDd96Dj2NSZ/Gw7pLNN T4Ejq8gWtjeSw9zQsWFthXUSS5cgxAXeEMgUUK5GtcDVBndPOzfrityagDjj7ZVZx0Ndeu Hr65yquq/77blVWuy3sqw3gjZfbCOTc= X-MC-Unique: pl439HljPsKIi2N_sKJEZQ-1 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [RFC 4/5] qmp: add QMP command virtio-queue-element Date: Thu, 2 Apr 2020 12:03:01 +0200 Message-Id: <20200402100302.833267-5-lvivier@redhat.com> In-Reply-To: <20200402100302.833267-1-lvivier@redhat.com> References: <20200402100302.833267-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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: Laurent Vivier , Thomas Huth , "Michael S. Tsirkin" , Markus Armbruster , "Dr. David Alan Gilbert" , Michael Roth , Paolo Bonzini 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 new command shows the information of a VirtQueue element. Signed-off-by: Laurent Vivier --- hw/virtio/virtio-stub.c | 7 ++++ hw/virtio/virtio.c | 85 +++++++++++++++++++++++++++++++++++++++++ qapi/virtio.json | 85 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+) diff --git a/hw/virtio/virtio-stub.c b/hw/virtio/virtio-stub.c index 5b4ed6fd531e..693f5eac409f 100644 --- a/hw/virtio/virtio-stub.c +++ b/hw/virtio/virtio-stub.c @@ -23,3 +23,10 @@ VirtQueueStatus *qmp_virtio_queue_status(const char *pat= h, uint16_t queue, { return qmp_virtio_unsupported(errp); } + +VirtioQueueElement *qmp_virtio_queue_element(const char* path, uint16_t qu= eue, + bool has_index, uint16_t inde= x, + Error **errp) +{ + return qmp_virtio_unsupported(errp); +} diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 271d4ca3417f..28848b9e64cf 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3925,6 +3925,91 @@ VirtioStatus *qmp_virtio_status(const char* path, Er= ror **errp) return status; } =20 +VirtioQueueElement *qmp_virtio_queue_element(const char* path, uint16_t qu= eue, + bool has_index, uint16_t inde= x, + Error **errp) +{ + VirtIODevice *vdev; + VirtQueue *vq; + VirtioQueueElement *element; + + vdev =3D virtio_device_find(path); + if (vdev =3D=3D NULL) { + error_setg(errp, "Path %s is not a VirtIO device", path); + return NULL; + } + + if (queue >=3D VIRTIO_QUEUE_MAX || !virtio_queue_get_num(vdev, queue))= { + error_setg(errp, "Invalid virtqueue number %d", queue); + return NULL; + } + vq =3D &vdev->vq[queue]; + + if (virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) { + error_setg(errp, "Packed ring not supported"); + return NULL; + } else { + unsigned int head, i, max; + VRingMemoryRegionCaches *caches; + MemoryRegionCache *desc_cache; + VRingDesc desc; + + RCU_READ_LOCK_GUARD(); + if (virtio_queue_empty_rcu(vq)) { + error_setg(errp, "Queue is empty"); + return NULL; + } + /* + * Needed after virtio_queue_empty(), see comment in + * virtqueue_num_heads(). + */ + smp_rmb(); + + max =3D vq->vring.num; + + if (vq->inuse >=3D vq->vring.num) { + error_setg(errp, "Queue size exceeded"); + return NULL; + } + + if (!has_index) { + head =3D vring_avail_ring(vq, vq->last_avail_idx % vq->vring.n= um); + } else { + head =3D vring_avail_ring(vq, index % vq->vring.num); + } + i =3D head; + + caches =3D vring_get_region_caches(vq); + if (!caches) { + error_setg(errp, "Region caches not initialized"); + return NULL; + } + + if (caches->desc.len < max * sizeof(VRingDesc)) { + error_setg(errp, "Cannot map descriptor ring"); + return NULL; + } + + desc_cache =3D &caches->desc; + vring_split_desc_read(vdev, &desc, desc_cache, i); + if (desc.flags & VRING_DESC_F_INDIRECT) { + error_setg(errp, "Unsupported indirect buffer feature"); + return NULL; + } + + element =3D g_new0(VirtioQueueElement, 1); + element->index =3D head; + element->ndescs =3D 1; + element->descs =3D g_new0(VirtioRingDescList, 1); + element->descs->value =3D g_new0(VirtioRingDesc, 1); + element->descs->value->addr =3D desc.addr; + element->descs->value->len =3D desc.len; + element->descs->value->flags =3D desc.flags; + } + + return element; +} + static const TypeInfo virtio_device_info =3D { .name =3D TYPE_VIRTIO_DEVICE, .parent =3D TYPE_DEVICE, diff --git a/qapi/virtio.json b/qapi/virtio.json index ab70500d919b..3e8865511217 100644 --- a/qapi/virtio.json +++ b/qapi/virtio.json @@ -215,3 +215,88 @@ 'data': { 'path': 'str', 'queue': 'uint16' }, 'returns': 'VirtQueueStatus' } + +## +# @VirtioRingDesc: +# +# @addr: guest physical address of the descriptor data +# +# @len: length of the descriptor data +# +# @flags: descriptor flags (write-only, read-only, ...) +# +# Since: 5.1 +# +## + +{ 'struct': 'VirtioRingDesc', + 'data': { + 'addr': 'uint64', + 'len': 'uint32', + 'flags': 'uint16' + } +} + +## +# @VirtioQueueElement: +# +# @index: index of the element in the queue +# +# @len: length of the element data +# +# @ndescs: number of descriptors +# +# @descs: list of the descriptors +# +# Since: 5.1 +# +## + +{ 'struct': 'VirtioQueueElement', + 'data': { + 'index': 'uint32', + 'len': 'uint32', + 'ndescs': 'uint32', + 'descs': ['VirtioRingDesc'] + } +} + +## +# @virtio-queue-element: +# +# Return the information about an element queue (by default head) +# +# @path: QOBject path of the VirtIODevice +# +# @queue: queue number to examine +# +# @index: the index in the queue, by default head +# +# Returns: the element information +# +# Since: 5.1 +# +# Example: +# +# -> { "execute": "virtio-queue-element", +# "arguments": { +# "path": "/machine/peripheral-anon/device[3]/virtio-backend", +# "queue": 0 +# } +# } +# -> { "return": { +# "index": 109, +# "len": 0, +# "ndescs": 1, +# "descs": [ +# { "flags": 2, "len": 2048, "addr": 853145600 } +# ] +# } +# } +# +## + +{ 'command': 'virtio-queue-element', + 'data': { 'path': 'str', 'queue': 'uint16', '*index': 'uint16' }, + 'returns': 'VirtioQueueElement' +} --=20 2.25.1 From nobody Fri Nov 14 06:40:03 2025 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585822024; cv=none; d=zohomail.com; s=zohoarc; b=l+QrHmqXDYIrASI7gNAF6L02vDg+WYXRWoTX9Ckbl88owmbTezQclxG4nMmeu7rqRIQGYqCDLfDMWvnZb2N943aEfNHwUWFvGytuRvvPbmEy3e7eHYGuruQgD9ZoCSXOXxSAZzJNWxpT/2sg8aJvgh53l1nNrXPPWGt1Kq/MknI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585822024; h=Content-Type: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=oyR+Fb8NPCcaSj6z5odo744T7i6AULnc2fVc7wIjzUs=; b=EqkEjroAg9O96eRFv5nvDEoPHVwIw2UeoRM+3y4bNMKLTsbCGz3A97DRTM9ocRfvk+3gVIXhk95v5PTpLjQMXFHL5cwbi10dHZ2zuLr0Bi/LuJeNheap8s7CsvAD7CTr7ajjTHb0mlaR+yliUn6l0ijYGnxq5UUbkmw5g7TxrWU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1585822024000511.2705298728073; Thu, 2 Apr 2020 03:07:04 -0700 (PDT) Received: from localhost ([::1]:36388 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJwkY-0006Bl-KE for importer@patchew.org; Thu, 02 Apr 2020 06:07:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33873) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJwh8-0001ZC-LF for qemu-devel@nongnu.org; Thu, 02 Apr 2020 06:03:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJwh6-0000WG-Fh for qemu-devel@nongnu.org; Thu, 02 Apr 2020 06:03:30 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:27963 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJwh6-0000WA-Ak for qemu-devel@nongnu.org; Thu, 02 Apr 2020 06:03:28 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-206-RBxLpcNbMdOB2ITkCTsQ7g-1; Thu, 02 Apr 2020 06:03:26 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2345B800D5C; Thu, 2 Apr 2020 10:03:25 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-113-198.ams2.redhat.com [10.36.113.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C3F05DA76; Thu, 2 Apr 2020 10:03:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585821808; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oyR+Fb8NPCcaSj6z5odo744T7i6AULnc2fVc7wIjzUs=; b=Xau213ac/R17bDv8QAsBLguvGE7rbEcAL3YgWg8Tq3HbMTuqZtHgBs3cSuOwQIBt+3Yft+ v2tqlSQGBG4Ayz7ftJWK9niBVVVZNLiDTjfW20LCLhSdR2j2/lhWUdmIwahAV1OShym9cR 0EbGCrBiE6N7ejcf+vuONK5CYD7w8R4= X-MC-Unique: RBxLpcNbMdOB2ITkCTsQ7g-1 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [RFC 5/5] hmp: add virtio commands Date: Thu, 2 Apr 2020 12:03:02 +0200 Message-Id: <20200402100302.833267-6-lvivier@redhat.com> In-Reply-To: <20200402100302.833267-1-lvivier@redhat.com> References: <20200402100302.833267-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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: Laurent Vivier , Thomas Huth , "Michael S. Tsirkin" , Markus Armbruster , "Dr. David Alan Gilbert" , Michael Roth , Paolo Bonzini 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 patch implements HMP version of the virtio QMP commands Signed-off-by: Laurent Vivier --- Makefile | 2 +- Makefile.target | 7 +- docs/system/monitor.rst | 2 + hmp-commands-virtio.hx | 148 ++++++++++++++++++++++++++++++++++++++++ hmp-commands.hx | 10 +++ hw/virtio/virtio.c | 115 +++++++++++++++++++++++++++++++ include/monitor/hmp.h | 4 ++ monitor/misc.c | 17 +++++ 8 files changed, 302 insertions(+), 3 deletions(-) create mode 100644 hmp-commands-virtio.hx diff --git a/Makefile b/Makefile index 84ef88160006..5f70ea16a566 100644 --- a/Makefile +++ b/Makefile @@ -1100,7 +1100,7 @@ $(MANUAL_BUILDDIR)/interop/index.html: $(call manual-= deps,interop) $(MANUAL_BUILDDIR)/specs/index.html: $(call manual-deps,specs) $(call build-manual,specs,html) =20 -$(MANUAL_BUILDDIR)/system/index.html: $(call manual-deps,system) $(SRC_PAT= H)/hmp-commands.hx $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/qemu-option= s.hx +$(MANUAL_BUILDDIR)/system/index.html: $(call manual-deps,system) $(SRC_PAT= H)/hmp-commands.hx $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/qemu-option= s.hx $(SRC_PATH)/hmp-commands-virtio.hx $(call build-manual,system,html) =20 $(MANUAL_BUILDDIR)/tools/index.html: $(call manual-deps,tools) $(SRC_PATH)= /qemu-img-cmds.hx $(SRC_PATH)/docs/qemu-option-trace.rst.inc diff --git a/Makefile.target b/Makefile.target index 8ed1eba95b9c..66d3ff9bc350 100644 --- a/Makefile.target +++ b/Makefile.target @@ -171,7 +171,7 @@ else obj-y +=3D hw/$(TARGET_BASE_ARCH)/ endif =20 -generated-files-y +=3D hmp-commands.h hmp-commands-info.h +generated-files-y +=3D hmp-commands.h hmp-commands-info.h hmp-commands-vir= tio.h generated-files-y +=3D config-devices.h =20 endif # CONFIG_SOFTMMU @@ -220,10 +220,13 @@ hmp-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PAT= H)/scripts/hxtool hmp-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/= hxtool $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$(= TARGET_DIR)$@") =20 +hmp-commands-virtio.h: $(SRC_PATH)/hmp-commands-virtio.hx $(SRC_PATH)/scri= pts/hxtool + $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$(= TARGET_DIR)$@") + clean: clean-target rm -f *.a *~ $(PROGS) rm -f $(shell find . -name '*.[od]') - rm -f hmp-commands.h gdbstub-xml.c + rm -f hmp-commands.h hmp-commands-virtio.h gdbstub-xml.c rm -f trace/generated-helpers.c trace/generated-helpers.c-timestamp ifdef CONFIG_TRACE_SYSTEMTAP rm -f *.stp diff --git a/docs/system/monitor.rst b/docs/system/monitor.rst index 0bcd5da21644..985c3f51ffe7 100644 --- a/docs/system/monitor.rst +++ b/docs/system/monitor.rst @@ -21,6 +21,8 @@ The following commands are available: =20 .. hxtool-doc:: hmp-commands.hx =20 +.. hxtool-doc:: hmp-commands-virtio.hx + .. hxtool-doc:: hmp-commands-info.hx =20 Integer expressions diff --git a/hmp-commands-virtio.hx b/hmp-commands-virtio.hx new file mode 100644 index 000000000000..a8d49f0b2b46 --- /dev/null +++ b/hmp-commands-virtio.hx @@ -0,0 +1,148 @@ +HXCOMM Use DEFHEADING() to define headings in both help text and rST. +HXCOMM Text between SRST and ERST is copied to the rST version and +HXCOMM discarded from C version. +HXCOMM DEF(command, args, callback, arg_string, help) is used to construct +HXCOMM monitor info commands +HXCOMM HXCOMM can be used for comments, discarded from both rST and C. +HXCOMM +HXCOMM In this file, generally SRST fragments should have two extra +HXCOMM spaces of indent, so that the documentation list item for "virtio c= md" +HXCOMM appears inside the documentation list item for the top level +HXCOMM "virtio" documentation entry. The exception is the first SRST +HXCOMM fragment that defines that top level entry. + +SRST +``virtio`` *subcommand* + Show various information about virtio. + +ERST + + { + .name =3D "query", + .args_type =3D "", + .params =3D "", + .help =3D "List all available virtio devices", + .cmd =3D hmp_virtio_query, + .flags =3D "p", + }, + +SRST + ``virtio query`` + List all available virtio devices + + Example: + + List all available virtio devices in the machine:: + + (qemu) virtio query + /machine/peripheral-anon/device[3]/virtio-backend [virtio-net] + /machine/peripheral-anon/device[1]/virtio-backend [virtio-serial] + /machine/peripheral-anon/device[0]/virtio-backend [virtio-blk] + +ERST + + { + .name =3D "status", + .args_type =3D "path:s", + .params =3D "path", + .help =3D "Display status of a given virtio device", + .cmd =3D hmp_virtio_status, + .flags =3D "p", + }, + +SRST + ``virtio status`` *path* + Display status of a given virtio device + + Example: + + Dump the status of the first virtio device:: + + (qemu) virtio status /machine/peripheral-anon/device[3]/virtio-backe= nd + /machine/peripheral-anon/device[3]/virtio-backend: + Device Id: 1 + Guest features: 0x0000000130afffa7 + Host features: 0x0000000179bfffe7 + Backend features: 0x0000000000000000 + Endianness: little + VirtQueues: 3 + +ERST + + { + .name =3D "queue-status", + .args_type =3D "path:s,queue:i", + .params =3D "path queue", + .help =3D "Display status of a given virtio queue", + .cmd =3D hmp_virtio_queue_status, + .flags =3D "p", + }, + +SRST + ``virtio queue-status`` *path* *queue* + Display status of a given virtio queue + + Example: + + Dump the status of the first queue of the first virtio device:: + + (qemu) virtio queue-status /machine/peripheral-anon/device[3]/virtio= -backend 0 + /machine/peripheral-anon/device[3]/virtio-backend: + index: 0 + inuse: 0 + last_avail_idx: 61 + shadow_avail_idx: 292 + signalled_used: 61 + signalled_used_valid: 1 + VRing: + num: 256 + num_default: 256 + align: 4096 + desc: 0x000000006c352000 + avail: 0x000000006c353000 + used: 0x000000006c353240 + +ERST + + { + .name =3D "queue-element", + .args_type =3D "path:s,queue:i,index:i?", + .params =3D "path queue [index]", + .help =3D "Display element of a given virtio queue", + .cmd =3D hmp_virtio_queue_element, + .flags =3D "p", + }, + +SRST + ``virtio queue-element`` *path* *queue* [*index*] + Display element of a given virtio queue + + Example: + + Dump the information of the head element of the first queue of + the first virtio device:: + + (qemu) virtio queue-element/machine/peripheral-anon/device[3]/virtio= -backend 0 + index: 67 + ndescs: 1 + descs: addr 0x6fe69800 len 1536 (write-only) + + (qemu) xp/128bx 0x6fe69800 + 000000006fe69800: 0x02 0x00 0x00 0x00 0x00 0x00 0x00 0x00 + 000000006fe69808: 0x00 0x00 0x01 0x00 0x52 0x54 0x00 0x12 + 000000006fe69810: 0x34 0x56 0x52 0x54 0x00 0x09 0x51 0xde + 000000006fe69818: 0x08 0x00 0x45 0x00 0x00 0x4c 0x8f 0x32 + + device[3] is a virtio-net device and we can see in the element buffer = the + MAC address of the card:: + + [root@localhost ~]# ip link show ens4 + 2: ens4: mtu 1500 qdisc fq_codel s= tate UP m0 + link/ether 52:54:00:12:34:56 brd ff:ff:ff:ff:ff:ff + + and the MAC address of the gateway:: + + [root@localhost ~]# arp -a + _gateway (192.168.122.1) at 52:54:00:09:51:de [ether] on ens4 + +ERST diff --git a/hmp-commands.hx b/hmp-commands.hx index 7f0f3974ad90..14568b406dbc 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1804,6 +1804,16 @@ SRST Set QOM property *property* of object at location *path* to value *value* ERST =20 + { + .name =3D "virtio", + .args_type =3D "name:S?", + .params =3D "[cmd]", + .help =3D "show various information about virtio", + .cmd =3D hmp_virtio_help, + .sub_table =3D hmp_virtio_cmds, + .flags =3D "p", + }, + { .name =3D "info", .args_type =3D "item:s?", diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 28848b9e64cf..d52d41169fb4 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -29,6 +29,9 @@ #include "hw/virtio/virtio-access.h" #include "sysemu/dma.h" #include "sysemu/runstate.h" +#include "monitor/hmp.h" +#include "monitor/monitor.h" +#include "qapi/qmp/qdict.h" =20 static QTAILQ_HEAD(, VirtIODevice) virtio_list; =20 @@ -3839,6 +3842,29 @@ VirtioInfoList *qmp_query_virtio(Error **errp) return list; } =20 +void hmp_virtio_query(Monitor *mon, const QDict *qdict) +{ + Error *err =3D NULL; + VirtioInfoList *l =3D qmp_query_virtio(&err); + + if (err !=3D NULL) { + hmp_handle_error(mon, err); + return; + } + + if (l =3D=3D NULL) { + monitor_printf(mon, "No VirtIO devices\n"); + return; + } + + while (l) { + monitor_printf(mon, "%s [%s]\n", l->value->path, l->value->type); + l =3D l->next; + } + + qapi_free_VirtioInfoList(l); +} + static VirtIODevice *virtio_device_find(const char *path) { VirtIODevice *vdev; @@ -3890,6 +3916,36 @@ VirtQueueStatus *qmp_virtio_queue_status(const char = *path, uint16_t queue, return status; } =20 +void hmp_virtio_queue_status(Monitor *mon, const QDict *qdict) +{ + Error *err =3D NULL; + const char *path =3D qdict_get_try_str(qdict, "path"); + int queue =3D qdict_get_int(qdict, "queue"); + VirtQueueStatus *s =3D qmp_virtio_queue_status(path, queue, &err); + + if (err !=3D NULL) { + hmp_handle_error(mon, err); + return; + } + monitor_printf(mon, "%s:\n", path); + monitor_printf(mon, " index: %d\n", s->queue_index); + monitor_printf(mon, " inuse: %d\n", s->inuse); + monitor_printf(mon, " last_avail_idx: %d\n", s->last_avail_idx); + monitor_printf(mon, " shadow_avail_idx: %d\n", s->shadow_avail_id= x); + monitor_printf(mon, " signalled_used: %d\n", s->signalled_used); + monitor_printf(mon, " signalled_used_valid: %d\n", + s->signalled_used_valid); + monitor_printf(mon, " VRing:\n"); + monitor_printf(mon, " num: %"PRId64"\n", s->vring_num); + monitor_printf(mon, " num_default: %"PRId64"\n", s->vring_num_defau= lt); + monitor_printf(mon, " align: %"PRId64"\n", s->vring_align); + monitor_printf(mon, " desc: 0x%016"PRIx64"\n", s->vring_desc= ); + monitor_printf(mon, " avail: 0x%016"PRIx64"\n", s->vring_avai= l); + monitor_printf(mon, " used: 0x%016"PRIx64"\n", s->vring_used= ); + + qapi_free_VirtQueueStatus(s); +} + VirtioStatus *qmp_virtio_status(const char* path, Error **errp) { VirtIODevice *vdev; @@ -3925,6 +3981,31 @@ VirtioStatus *qmp_virtio_status(const char* path, Er= ror **errp) return status; } =20 +void hmp_virtio_status(Monitor *mon, const QDict *qdict) +{ + Error *err =3D NULL; + const char *path =3D qdict_get_try_str(qdict, "path"); + VirtioStatus *s =3D qmp_virtio_status(path, &err); + + if (err !=3D NULL) { + hmp_handle_error(mon, err); + return; + } + + monitor_printf(mon, "%s:\n", path); + monitor_printf(mon, " Device Id: %"PRId64"\n", s->device_id); + monitor_printf(mon, " Guest features: 0x%016"PRIx64"\n", + s->guest_features); + monitor_printf(mon, " Host features: 0x%016"PRIx64"\n", + s->host_features); + monitor_printf(mon, " Backend features: 0x%016"PRIx64"\n", + s->backend_features); + monitor_printf(mon, " Endianness: %s\n", s->device_endian); + monitor_printf(mon, " VirtQueues: %d\n", s->num_vqs); + + qapi_free_VirtioStatus(s); +} + VirtioQueueElement *qmp_virtio_queue_element(const char* path, uint16_t qu= eue, bool has_index, uint16_t inde= x, Error **errp) @@ -4010,6 +4091,40 @@ VirtioQueueElement *qmp_virtio_queue_element(const c= har* path, uint16_t queue, return element; } =20 +void hmp_virtio_queue_element(Monitor *mon, const QDict *qdict) +{ + Error *err =3D NULL; + const char *path =3D qdict_get_try_str(qdict, "path"); + int queue =3D qdict_get_int(qdict, "queue"); + int index =3D qdict_get_try_int(qdict, "index", -1); + VirtioQueueElement *element; + VirtioRingDescList *list; + + element =3D qmp_virtio_queue_element(path, queue, index !=3D -1, index= , &err); + if (err !=3D NULL) { + hmp_handle_error(mon, err); + return; + } + + monitor_printf(mon, "index: %d\n", element->index); + monitor_printf(mon, "ndescs: %d\n", element->ndescs); + monitor_printf(mon, "descs: "); + + list =3D element->descs; + while (list) { + monitor_printf(mon, "addr 0x%"PRIx64" len %d %s", list->value->add= r, + list->value->len, list->value->flags & + VRING_DESC_F_WRITE ? "(write-only)" : "(read-only)"= ); + list =3D list->next; + if (list) { + monitor_printf(mon, ", "); + } + } + monitor_printf(mon, "\n"); + + qapi_free_VirtioQueueElement(element); +} + static const TypeInfo virtio_device_info =3D { .name =3D TYPE_VIRTIO_DEVICE, .parent =3D TYPE_DEVICE, diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index e33ca5a911a5..9f1c118dde31 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -98,6 +98,10 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *= qdict); void hmp_qom_list(Monitor *mon, const QDict *qdict); void hmp_qom_set(Monitor *mon, const QDict *qdict); void hmp_info_qom_tree(Monitor *mon, const QDict *dict); +void hmp_virtio_query(Monitor *mon, const QDict *qdict); +void hmp_virtio_status(Monitor *mon, const QDict *qdict); +void hmp_virtio_queue_status(Monitor *mon, const QDict *qdict); +void hmp_virtio_queue_element(Monitor *mon, const QDict *qdict); void object_add_completion(ReadLineState *rs, int nb_args, const char *str= ); void object_del_completion(ReadLineState *rs, int nb_args, const char *str= ); void device_add_completion(ReadLineState *rs, int nb_args, const char *str= ); diff --git a/monitor/misc.c b/monitor/misc.c index 6c45fa490ff5..5eacfa7079fc 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -23,6 +23,7 @@ */ =20 #include "qemu/osdep.h" +#include "config-devices.h" #include "monitor-internal.h" #include "cpu.h" #include "monitor/qdev.h" @@ -232,6 +233,15 @@ static void hmp_info_help(Monitor *mon, const QDict *q= dict) help_cmd(mon, "info"); } =20 +static void hmp_virtio_help(Monitor *mon, const QDict *qdict) +{ +#if defined(CONFIG_VIRTIO) + help_cmd(mon, "virtio"); +#else + monitor_printf(mon, "Virtio is disabled\n"); +#endif +} + static void monitor_init_qmp_commands(void) { /* @@ -1683,6 +1693,13 @@ static HMPCommand hmp_info_cmds[] =3D { { NULL, NULL, }, }; =20 +static HMPCommand hmp_virtio_cmds[] =3D { +#if defined(CONFIG_VIRTIO) +#include "hmp-commands-virtio.h" +#endif + { NULL, NULL, }, +}; + /* hmp_cmds and hmp_info_cmds would be sorted at runtime */ HMPCommand hmp_cmds[] =3D { #include "hmp-commands.h" --=20 2.25.1