From patchwork Mon Apr 20 10:41:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 284199 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB12BC3815B for ; Mon, 20 Apr 2020 10:43:45 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 869912071C for ; Mon, 20 Apr 2020 10:43:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aU9Y3eER" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 869912071C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:33114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQTtw-0005oD-O2 for qemu-devel@archiver.kernel.org; Mon, 20 Apr 2020 06:43:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57942 helo=eggs1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQTso-0004o2-Nn for qemu-devel@nongnu.org; Mon, 20 Apr 2020 06:42:35 -0400 Received: from Debian-exim by eggs1p.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQTso-0004rs-5s for qemu-devel@nongnu.org; Mon, 20 Apr 2020 06:42:34 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:57823 helo=us-smtp-1.mimecast.com) by eggs1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jQTsn-0004qj-Q8 for qemu-devel@nongnu.org; Mon, 20 Apr 2020 06:42:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587379353; 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=vCGzhKbty4eQXbbnWs7ryss1xr0QCytOXCwAkMh2gAg=; b=aU9Y3eERO91et7+ge+BOmvtmsyzR81fb3u4XoY11hbTU7lNQ3Jd5usBf9grWSty9y6xNhE XM8tasNY23EkDhKlkaz2sXXhzEEwfPQkFoIHkbF2j5oju1zN3EJPuMBJqLMElJj63kwgZP orvsv9f0xvq+wj8xuBYY1nIQ8SW/bgM= 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-366-uiCaMniPNrOiNLBPR6bqLw-1; Mon, 20 Apr 2020 06:42:28 -0400 X-MC-Unique: uiCaMniPNrOiNLBPR6bqLw-1 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 B0DD918CA241; Mon, 20 Apr 2020 10:42:27 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-114-254.ams2.redhat.com [10.36.114.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D9C35DDA5; Mon, 20 Apr 2020 10:42:06 +0000 (UTC) From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [RFC v2 1/6] qmp: add QMP command query-virtio Date: Mon, 20 Apr 2020 12:41:40 +0200 Message-Id: <20200420104145.205297-2-lvivier@redhat.com> In-Reply-To: <20200420104145.205297-1-lvivier@redhat.com> References: <20200420104145.205297-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 Received-SPF: pass client-ip=205.139.110.120; envelope-from=lvivier@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs1p.gnu.org: First seen = 2020/04/20 04:32:42 X-ACL-Warn: Detected OS = 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 , Fam Zheng , Thomas Huth , qemu-block@nongnu.org, Amit Shah , Markus Armbruster , Jason Wang , "Michael S. Tsirkin" , David Hildenbrand , Michael Roth , Max Reitz , Eric Auger , Gerd Hoffmann , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lure?= =?utf-8?q?au?= , Paolo Bonzini , Kevin Wolf , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This new command lists all the instances of VirtIODevice with their path and virtio type Signed-off-by: Laurent Vivier --- Notes: v2: introduce VirtioType enum hw/virtio/Makefile.objs | 2 ++ hw/virtio/virtio-stub.c | 14 ++++++++ hw/virtio/virtio.c | 28 ++++++++++++++++ include/hw/virtio/virtio.h | 1 + qapi/Makefile.objs | 2 +- qapi/qapi-schema.json | 1 + qapi/virtio.json | 68 ++++++++++++++++++++++++++++++++++++++ tests/qtest/qmp-cmd-test.c | 1 + 8 files changed, 116 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) += virtio-serial-pci.o endif else common-obj-y += vhost-stub.o +common-obj-y += virtio-stub.o endif common-obj-$(CONFIG_ALL) += vhost-stub.o +common-obj-$(CONFIG_ALL) += 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..4955fbe5a71b 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -13,6 +13,8 @@ #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" +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, Error **errp) vdev->listener.commit = virtio_memory_listener_commit; memory_listener_register(&vdev->listener, vdev->dma_as); + QTAILQ_INSERT_TAIL(&virtio_list, vdev, next); } static void virtio_device_unrealize(DeviceState *dev, Error **errp) @@ -3646,6 +3651,7 @@ static void virtio_device_unrealize(DeviceState *dev, Error **errp) } } + QTAILQ_REMOVE(&virtio_list, vdev, next); g_free(vdev->bus_name); vdev->bus_name = NULL; } @@ -3802,6 +3808,8 @@ static void virtio_device_class_init(ObjectClass *klass, void *data) vdc->stop_ioeventfd = virtio_device_stop_ioeventfd_impl; vdc->legacy_features |= VIRTIO_LEGACY_FEATURES; + + QTAILQ_INIT(&virtio_list); } bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev) @@ -3812,6 +3820,26 @@ bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev) return virtio_bus_ioeventfd_enabled(vbus); } +VirtioInfoList *qmp_query_virtio(Error **errp) +{ + VirtioInfoList *list = NULL; + VirtioInfoList *node; + VirtIODevice *vdev; + + QTAILQ_FOREACH(vdev, &virtio_list, next) { + DeviceState *dev = DEVICE(vdev); + node = g_new0(VirtioInfoList, 1); + node->value = g_new(VirtioInfo, 1); + node->value->path = g_strdup(dev->canonical_path); + node->value->type = qapi_enum_parse(&VirtioType_lookup, vdev->name, + VIRTIO_TYPE_UNKNOWN, NULL); + node->next = list; + list = node; + } + + return list; +} + static const TypeInfo virtio_device_info = { .name = TYPE_VIRTIO_DEVICE, .parent = 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; }; 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 += qapi-util.o QAPI_COMMON_MODULES = audio authz block-core block char common control crypto QAPI_COMMON_MODULES += dump error introspect job machine migration misc QAPI_COMMON_MODULES += net pragma qdev qom rdma rocker run-state sockets tpm -QAPI_COMMON_MODULES += trace transaction ui +QAPI_COMMON_MODULES += trace transaction ui virtio QAPI_TARGET_MODULES = machine-target misc-target QAPI_MODULES = $(QAPI_COMMON_MODULES) $(QAPI_TARGET_MODULES) 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..fa3c7961ecff --- /dev/null +++ b/qapi/virtio.json @@ -0,0 +1,68 @@ +## +# = Virtio devices +## + +## +# @VirtioType: +# +# An enumeration of Virtio device types. +# +# Since: 5.1.0 +## +{ 'enum': 'VirtioType', + 'data': [ 'unknown', 'virtio-9p', 'virtio-blk', 'virtio-serial', + 'virtio-gpu', 'virtio-input', 'virtio-net', 'virtio-scsi', + 'vhost-user-fs', 'vhost-vsock', 'virtio-balloon', 'virtio-crypto', + 'virtio-iommu', 'virtio-pmem', 'virtio-rng' ] +} + +## +# @VirtioInfo: +# +# Information about a given VirtIODevice +# +# @path: VirtIO device canonical path. +# +# @type: VirtIO device type. +# +# Since: 5.1 +# +## +{ 'struct': 'VirtioInfo', + 'data': { + 'path': 'str', + 'type': 'VirtioType' + } +} + +## +# @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 */