From nobody Thu Dec 18 08:06:56 2025 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1665426353; cv=none; d=zohomail.com; s=zohoarc; b=HbOB5rUGilfqLa/639ojMOrCeqbjwLApTzq3YNDTD7Rjy5pUPpoX7aobeKTTPMB+39V5Yke1BqQ8nviaED+odDKCqLeu6xupOQyRG0XQ5BFymDp4E6jSu/V/4NxSglY+hAvwN8/Qwjjs/+P6zW6Y9+RriPdJxSVFoX16Klm1+fw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665426353; h=Content-Type: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=71fByqtzz3V1myRZTp6mDfuO9MkyXBsQaGOmLHOchvQ=; b=ISHzgPdlnmggxB7dzR+WPdDJTtshlNE8dHnAPCBBUnPh/BzISozlJQPwArsxs5+i+c+SgxwZP365fbvYcSEAi2iGj0549lJ2F3BYeu0b9ec1peBdv9dzDBkdZrPTHzIGDCYa/WHz0yU74XPSjloa41mmS3SU+3QHG1MNyaevKJc= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665426353840814.159966522816; Mon, 10 Oct 2022 11:25:53 -0700 (PDT) Received: from localhost ([::1]:58366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ohxTJ-0004C2-Ri for importer@patchew.org; Mon, 10 Oct 2022 14:25:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohwcV-00032t-JK for qemu-devel@nongnu.org; Mon, 10 Oct 2022 13:31:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:34258) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohwcN-0007AX-IL for qemu-devel@nongnu.org; Mon, 10 Oct 2022 13:31:13 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-131-d5DhNTgMNGC-9EyZ8kbKqA-1; Mon, 10 Oct 2022 13:31:02 -0400 Received: by mail-wm1-f70.google.com with SMTP id k2-20020a05600c1c8200b003c3dd3aa638so4809337wms.1 for ; Mon, 10 Oct 2022 10:31:02 -0700 (PDT) Received: from redhat.com ([2.55.183.131]) by smtp.gmail.com with ESMTPSA id j39-20020a05600c48a700b003a5537bb2besm10313662wmp.25.2022.10.10.10.30.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 10:30:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665423063; 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: in-reply-to:in-reply-to:references:references; bh=71fByqtzz3V1myRZTp6mDfuO9MkyXBsQaGOmLHOchvQ=; b=Pkaqc9EvWGZxIOAMso2v3l/7Lm9ZWpojr4Ptrx0rZyb6S6Iwp7pjHZt2978+wD9Vt32IG5 BHWL7VEj8pQ0lRKQJkOEZXK6nq4hKdIG1w2H63slPNhitgQcicQudXBf2Vj8h2vkA7s1ru tgRMXIBVIKou+2DhCBqJ9jDJLezLofM= X-MC-Unique: d5DhNTgMNGC-9EyZ8kbKqA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=71fByqtzz3V1myRZTp6mDfuO9MkyXBsQaGOmLHOchvQ=; b=sHjjYh8t30nQx76qTn3xhx2ni+saEKr2x65U0L1KpTgaN3aqwgD+tgfDqapZicMH4z GBz1B9spNeVe7BnBgyeuBGpSlQ4bAo6BvbTTgmxf4J135y1ZLL2yj3COZQze0T4UzZYD uVq/lltGtKgwMw/GzaerI1Nz0oB9kBHt7Zx5wHyiKn0xRj9BF4sPSNm6FKNyVZ/TpMAr MuPixNW5bls2ERB51vH/igmVfsfBsaSGVlJUg8W7fbAkvVgEPuIgn7MU79m3610KqceY 5+DH6e8FYPCDzXj66HEmp/eugJBKw6brNbrFG0Fj+27mMm5SvA9FMeMR20axPA7kr2E3 BT+A== X-Gm-Message-State: ACrzQf2Rcs+mGacTemRnTvyMhXQgDKkT66OIiarzvk8/KS3tfSy0iTSb 6GBHt8ocpO+FjFR0wazcoJdEYl+WV6+1sh3EoaV0ENpHez5dhkdwhqwXT05VTHHKUsP8KkjTfIO 0XI6xbifRCZGCBz3Dz5JaZZLq7LyQHxKxu73YclFW0fF1akff442ShF2MclRd X-Received: by 2002:a5d:6483:0:b0:22e:4804:8be4 with SMTP id o3-20020a5d6483000000b0022e48048be4mr11902375wri.528.1665423060807; Mon, 10 Oct 2022 10:31:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM71peGiPCzSVRO5O8wl0158+Q1fRpC2Hgpm4ALaRfQCVRblqGSKexVcH5bCujlTOpT9OQE+2A== X-Received: by 2002:a5d:6483:0:b0:22e:4804:8be4 with SMTP id o3-20020a5d6483000000b0022e48048be4mr11902348wri.528.1665423060372; Mon, 10 Oct 2022 10:31:00 -0700 (PDT) Date: Mon, 10 Oct 2022 13:30:56 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Laurent Vivier , Jonah Palmer , Eric Blake , Markus Armbruster Subject: [PULL 31/55] qmp: add QMP command x-query-virtio-status Message-ID: <20221010172813.204597-32-mst@redhat.com> References: <20221010172813.204597-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20221010172813.204597-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665426355838100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Laurent Vivier This new command shows the status of a VirtIODevice, including its corresponding vhost device's status (if active). Next patch will improve output by decoding feature bits, including vhost device's feature bits (backend, protocol, acked, and features). Also will decode status bits of a VirtIODevice. [Jonah: From patch v12; added a check to @virtio_device_find to ensure synchronicity between @virtio_list and the devices in the QOM composition tree.] Signed-off-by: Laurent Vivier Signed-off-by: Jonah Palmer Message-Id: <1660220684-24909-3-git-send-email-jonah.palmer@oracle.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- qapi/virtio.json | 222 ++++++++++++++++++++++++++++++++++++++++ hw/virtio/virtio-stub.c | 5 + hw/virtio/virtio.c | 104 +++++++++++++++++++ 3 files changed, 331 insertions(+) diff --git a/qapi/virtio.json b/qapi/virtio.json index 03896e423f..c86b3bc635 100644 --- a/qapi/virtio.json +++ b/qapi/virtio.json @@ -66,3 +66,225 @@ { 'command': 'x-query-virtio', 'returns': [ 'VirtioInfo' ], 'features': [ 'unstable' ] } + +## +# @VhostStatus: +# +# Information about a vhost device. This information will only be +# displayed if the vhost device is active. +# +# @n-mem-sections: vhost_dev n_mem_sections +# +# @n-tmp-sections: vhost_dev n_tmp_sections +# +# @nvqs: vhost_dev nvqs (number of virtqueues being used) +# +# @vq-index: vhost_dev vq_index +# +# @features: vhost_dev features +# +# @acked-features: vhost_dev acked_features +# +# @backend-features: vhost_dev backend_features +# +# @protocol-features: vhost_dev protocol_features +# +# @max-queues: vhost_dev max_queues +# +# @backend-cap: vhost_dev backend_cap +# +# @log-enabled: vhost_dev log_enabled flag +# +# @log-size: vhost_dev log_size +# +# Since: 7.1 +# +## + +{ 'struct': 'VhostStatus', + 'data': { 'n-mem-sections': 'int', + 'n-tmp-sections': 'int', + 'nvqs': 'uint32', + 'vq-index': 'int', + 'features': 'uint64', + 'acked-features': 'uint64', + 'backend-features': 'uint64', + 'protocol-features': 'uint64', + 'max-queues': 'uint64', + 'backend-cap': 'uint64', + 'log-enabled': 'bool', + 'log-size': 'uint64' } } + +## +# @VirtioStatus: +# +# Full status of the virtio device with most VirtIODevice members. +# Also includes the full status of the corresponding vhost device +# if the vhost device is active. +# +# @name: VirtIODevice name +# +# @device-id: VirtIODevice ID +# +# @vhost-started: VirtIODevice vhost_started flag +# +# @guest-features: VirtIODevice guest_features +# +# @host-features: VirtIODevice host_features +# +# @backend-features: VirtIODevice backend_features +# +# @device-endian: VirtIODevice device_endian +# +# @num-vqs: VirtIODevice virtqueue count. This is the number of active +# virtqueues being used by the VirtIODevice. +# +# @status: VirtIODevice configuration status (VirtioDeviceStatus) +# +# @isr: VirtIODevice ISR +# +# @queue-sel: VirtIODevice queue_sel +# +# @vm-running: VirtIODevice vm_running flag +# +# @broken: VirtIODevice broken flag +# +# @disabled: VirtIODevice disabled flag +# +# @use-started: VirtIODevice use_started flag +# +# @started: VirtIODevice started flag +# +# @start-on-kick: VirtIODevice start_on_kick flag +# +# @disable-legacy-check: VirtIODevice disabled_legacy_check flag +# +# @bus-name: VirtIODevice bus_name +# +# @use-guest-notifier-mask: VirtIODevice use_guest_notifier_mask flag +# +# @vhost-dev: Corresponding vhost device info for a given VirtIODevice. +# Present if the given VirtIODevice has an active vhost +# device. +# +# Since: 7.1 +# +## + +{ 'struct': 'VirtioStatus', + 'data': { 'name': 'str', + 'device-id': 'uint16', + 'vhost-started': 'bool', + 'device-endian': 'str', + 'guest-features': 'uint64', + 'host-features': 'uint64', + 'backend-features': 'uint64', + 'num-vqs': 'int', + 'status': 'uint8', + 'isr': 'uint8', + 'queue-sel': 'uint16', + 'vm-running': 'bool', + 'broken': 'bool', + 'disabled': 'bool', + 'use-started': 'bool', + 'started': 'bool', + 'start-on-kick': 'bool', + 'disable-legacy-check': 'bool', + 'bus-name': 'str', + 'use-guest-notifier-mask': 'bool', + '*vhost-dev': 'VhostStatus' } } + +## +# @x-query-virtio-status: +# +# Poll for a comprehensive status of a given virtio device +# +# @path: Canonical QOM path of the VirtIODevice +# +# Features: +# @unstable: This command is meant for debugging. +# +# Returns: VirtioStatus of the virtio device +# +# Since: 7.1 +# +# Examples: +# +# 1. Poll for the status of virtio-crypto (no vhost-crypto active) +# +# -> { "execute": "x-query-virtio-status", +# "arguments": { "path": "/machine/peripheral/crypto0/virtio-backend"= } +# } +# <- { "return": { +# "device-endian": "little", +# "bus-name": "", +# "disable-legacy-check": false, +# "name": "virtio-crypto", +# "started": true, +# "device-id": 20, +# "backend-features": 0, +# "start-on-kick": false, +# "isr": 1, +# "broken": false, +# "status": 15, +# "num-vqs": 2, +# "guest-features": 5100273664, +# "host-features": 6325010432, +# "use-guest-notifier-mask": true, +# "vm-running": true, +# "queue-sel": 1, +# "disabled": false, +# "vhost-started": false, +# "use-started": true +# } +# } +# +# 2. Poll for the status of virtio-net (vhost-net is active) +# +# -> { "execute": "x-query-virtio-status", +# "arguments": { "path": "/machine/peripheral-anon/device[1]/virtio-b= ackend" } +# } +# <- { "return": { +# "device-endian": "little", +# "bus-name": "", +# "disabled-legacy-check": false, +# "name": "virtio-net", +# "started": true, +# "device-id": 1, +# "vhost-dev": { +# "n-tmp-sections": 4, +# "n-mem-sections": 4, +# "max-queues": 1, +# "backend-cap": 2, +# "log-size": 0, +# "backend-features": 0, +# "nvqs": 2, +# "protocol-features": 0, +# "vq-index": 0, +# "log-enabled": false, +# "acked-features": 5100306432, +# "features": 13908344832 +# }, +# "backend-features": 6337593319, +# "start-on-kick": false, +# "isr": 1, +# "broken": false, +# "status": 15, +# "num-vqs": 3, +# "guest-features": 5111807911, +# "host-features": 6337593319, +# "use-guest-notifier-mask": true, +# "vm-running": true, +# "queue-sel": 2, +# "disabled": false, +# "vhost-started": true, +# "use-started": true +# } +# } +# +## + +{ 'command': 'x-query-virtio-status', + 'data': { 'path': 'str' }, + 'returns': 'VirtioStatus', + 'features': [ 'unstable' ] } diff --git a/hw/virtio/virtio-stub.c b/hw/virtio/virtio-stub.c index 05a81edc92..0b432e8de7 100644 --- a/hw/virtio/virtio-stub.c +++ b/hw/virtio/virtio-stub.c @@ -12,3 +12,8 @@ VirtioInfoList *qmp_x_query_virtio(Error **errp) { return qmp_virtio_unsupported(errp); } + +VirtioStatus *qmp_x_query_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 4fc7c80d3f..696e19126a 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3948,6 +3948,110 @@ VirtioInfoList *qmp_x_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; + } + + Error *err =3D NULL; + QObject *obj =3D qmp_qom_get(dev->canonical_path, "realized", &err= ); + if (err =3D=3D NULL) { + GString *is_realized =3D qobject_to_json_pretty(obj, true); + /* virtio device is NOT realized, remove it from list */ + if (!strncmp(is_realized->str, "false", 4)) { + g_string_free(is_realized, true); + qobject_unref(obj); + QTAILQ_REMOVE(&virtio_list, vdev, next); + return NULL; + } + g_string_free(is_realized, true); + } else { + /* virtio device doesn't exist in QOM tree */ + QTAILQ_REMOVE(&virtio_list, vdev, next); + qobject_unref(obj); + return NULL; + } + /* device exists in QOM tree & is realized */ + qobject_unref(obj); + return vdev; + } + return NULL; +} + +VirtioStatus *qmp_x_query_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 VirtIODevice", path); + return NULL; + } + + status =3D g_new0(VirtioStatus, 1); + status->name =3D g_strdup(vdev->name); + status->device_id =3D vdev->device_id; + status->vhost_started =3D vdev->vhost_started; + status->guest_features =3D vdev->guest_features; + status->host_features =3D vdev->host_features; + status->backend_features =3D vdev->backend_features; + + 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; + default: + status->device_endian =3D g_strdup("unknown"); + break; + } + + status->num_vqs =3D virtio_get_num_queues(vdev); + status->status =3D vdev->status; + status->isr =3D vdev->isr; + status->queue_sel =3D vdev->queue_sel; + status->vm_running =3D vdev->vm_running; + status->broken =3D vdev->broken; + status->disabled =3D vdev->disabled; + status->use_started =3D vdev->use_started; + status->started =3D vdev->started; + status->start_on_kick =3D vdev->start_on_kick; + status->disable_legacy_check =3D vdev->disable_legacy_check; + status->bus_name =3D g_strdup(vdev->bus_name); + status->use_guest_notifier_mask =3D vdev->use_guest_notifier_mask; + status->has_vhost_dev =3D vdev->vhost_started; + + if (vdev->vhost_started) { + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); + struct vhost_dev *hdev =3D vdc->get_vhost(vdev); + + status->vhost_dev =3D g_new0(VhostStatus, 1); + status->vhost_dev->n_mem_sections =3D hdev->n_mem_sections; + status->vhost_dev->n_tmp_sections =3D hdev->n_tmp_sections; + status->vhost_dev->nvqs =3D hdev->nvqs; + status->vhost_dev->vq_index =3D hdev->vq_index; + status->vhost_dev->features =3D hdev->features; + status->vhost_dev->acked_features =3D hdev->acked_features; + status->vhost_dev->backend_features =3D hdev->backend_features; + status->vhost_dev->protocol_features =3D hdev->protocol_features; + status->vhost_dev->max_queues =3D hdev->max_queues; + status->vhost_dev->backend_cap =3D hdev->backend_cap; + status->vhost_dev->log_enabled =3D hdev->log_enabled; + status->vhost_dev->log_size =3D hdev->log_size; + } + + return status; +} + static const TypeInfo virtio_device_info =3D { .name =3D TYPE_VIRTIO_DEVICE, .parent =3D TYPE_DEVICE, --=20 MST