From nobody Thu Dec 18 08:07:39 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=1665426777; cv=none; d=zohomail.com; s=zohoarc; b=bwGIuk19HZqsCIpjZuOC+SeXXGhuI/ZBNDIP2dpnwZS6PpnQmhqH97B1raj+vBcVuKFGTVqbuyitWtyStLE7O6LKewllOA7LA87HznfCdtA6ACMh4jYvNcybvLim8vFL3GSYphY8Gc+nDtGeNbFdmVkOgeXzgSby8HdrnW21IFY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665426777; 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=Q2DyAjwNZswdZe2s9M+8f99z0iOSnLYVgOO5uF3ZNss=; b=XshSv9NTIBa6SBtB76NNyeScZ9N6O00XDlMLXlfmMCrV/oDy2XZtbtrZ3L/ja0bAwRaq2Cti0RaAwVMLtrQeXHfigkkBrNYlRhjv0tyc4ZxgbGo/IG/9ZS9yYozVVMXN4tkT3lDRHG+IVKLOxBOcBMNmXI1qcs8BoA0M8QQ2Mr4= 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 1665426777787310.31021434775903; Mon, 10 Oct 2022 11:32:57 -0700 (PDT) Received: from localhost ([::1]:59018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ohxaC-0001a2-7r for importer@patchew.org; Mon, 10 Oct 2022 14:32:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohwcb-0003Bv-GU for qemu-devel@nongnu.org; Mon, 10 Oct 2022 13:31:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32032) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohwcV-0007Gj-As for qemu-devel@nongnu.org; Mon, 10 Oct 2022 13:31:20 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-278-k9-yF9x1MyqUXWd6bf8_oQ-1; Mon, 10 Oct 2022 13:31:12 -0400 Received: by mail-wr1-f69.google.com with SMTP id s4-20020adfbc04000000b0022e03fc10a9so2956286wrg.15 for ; Mon, 10 Oct 2022 10:31:12 -0700 (PDT) Received: from redhat.com ([2.55.183.131]) by smtp.gmail.com with ESMTPSA id j26-20020adfd21a000000b0022cc0a2cbecsm9272521wrh.15.2022.10.10.10.31.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 10:31:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665423073; 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=Q2DyAjwNZswdZe2s9M+8f99z0iOSnLYVgOO5uF3ZNss=; b=W+itwOzYpeHhkphzxKq0jnpzj9mZr5cio9PGYdskrYRHMN6R5dOBrwxLs72DsWwA1hUdYF 1k5OSCran03yRPPC5EvXUbxpWcBiJj/9ZvtQ2muVH5b4CS6RzuBWXy6c3tOdw+VhtaBEjc DTN9yjZTbpzC5Ksy34r23+wTiYyrbRA= X-MC-Unique: k9-yF9x1MyqUXWd6bf8_oQ-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=Q2DyAjwNZswdZe2s9M+8f99z0iOSnLYVgOO5uF3ZNss=; b=XHSBjB/FLpN8l4tiKwzfsNK/GT7tM7aAJ7yd1WwkbCo718LUIvepMK0T+hYD60Ody/ cnkA73cR9cGPGKWad3OzV4pLRSGDJUPI0meh4ItJk3acmC4QtACbyG311dy81rPz309T IL/eEMy2fgB8fUrJmWwV7H6aOKSFAahicMrwrDRMqUWGjItS6pE0f5u6472Rtd0z+w9H qDNHyEVHbScQO+qVaNl8sKBQUWqALkg42z8+FTLziEKe4fxCstUfBCxv4O5mUCL/WSNZ 4D12JuFlJQ303Zjpv+Kd13HjH95wiDpQwSKVdpsLhNp8ZEcIDE3WpyuUIlvyv94+ygTd YM7w== X-Gm-Message-State: ACrzQf2LAZQCP3j0BfLeRZcXk+qadTdCQL/kwP3bvsBTzaDevoLAQt6I SXjEJi8zyIuV06PSNXqGBur/ShBjkSRo/D1aVx/DAT/F/IVHgYs9oBZQNXskzwhfyyphjyZQIsD 3CoBTVjwZGkAj6gSMsgZYTZSAS0+XQ7m7FTTN+x3ysfSmR1915Xyzy+ZWm8OH X-Received: by 2002:a05:600c:1e26:b0:3b4:a688:3c23 with SMTP id ay38-20020a05600c1e2600b003b4a6883c23mr13514080wmb.73.1665423070871; Mon, 10 Oct 2022 10:31:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM448UykqrQtiu1+YOWgqq3i7H3ttBNZJU5Izf/n/o1FtvSJ1dVhPeX4TI9MjL8KIlzKIg0OEA== X-Received: by 2002:a05:600c:1e26:b0:3b4:a688:3c23 with SMTP id ay38-20020a05600c1e2600b003b4a6883c23mr13514044wmb.73.1665423070300; Mon, 10 Oct 2022 10:31:10 -0700 (PDT) Date: Mon, 10 Oct 2022 13:31:05 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Laurent Vivier , Jonah Palmer , Eric Blake , Markus Armbruster Subject: [PULL 33/55] qmp: add QMP commands for virtio/vhost queue-status Message-ID: <20221010172813.204597-34-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.133.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: 1665426778298100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Laurent Vivier These new commands show the internal status of a VirtIODevice's VirtQueue and a vhost device's vhost_virtqueue (if active). Signed-off-by: Laurent Vivier Signed-off-by: Jonah Palmer Message-Id: <1660220684-24909-5-git-send-email-jonah.palmer@oracle.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- qapi/virtio.json | 256 ++++++++++++++++++++++++++++++++++++++++ hw/virtio/virtio-stub.c | 14 +++ hw/virtio/virtio.c | 103 ++++++++++++++++ 3 files changed, 373 insertions(+) diff --git a/qapi/virtio.json b/qapi/virtio.json index c9c8201e66..d9050f3584 100644 --- a/qapi/virtio.json +++ b/qapi/virtio.json @@ -499,3 +499,259 @@ 'data': { 'transports': [ 'str' ], '*dev-features': [ 'str' ], '*unknown-dev-features': 'uint64' } } + +## +# @VirtQueueStatus: +# +# Information of a VirtIODevice VirtQueue, including most members of +# the VirtQueue data structure. +# +# @name: Name of the VirtIODevice that uses this 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 (descriptor area) +# +# @vring-avail: VirtQueue vring.avail (driver area) +# +# @vring-used: VirtQueue vring.used (device area) +# +# @last-avail-idx: VirtQueue last_avail_idx or return of vhost_dev +# vhost_get_vring_base (if vhost active) +# +# @shadow-avail-idx: VirtQueue shadow_avail_idx +# +# @used-idx: VirtQueue used_idx +# +# @signalled-used: VirtQueue signalled_used +# +# @signalled-used-valid: VirtQueue signalled_used_valid flag +# +# Since: 7.1 +# +## + +{ 'struct': 'VirtQueueStatus', + 'data': { 'name': 'str', + 'queue-index': 'uint16', + 'inuse': 'uint32', + 'vring-num': 'uint32', + 'vring-num-default': 'uint32', + 'vring-align': 'uint32', + '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': 'bool' } } + +## +# @x-query-virtio-queue-status: +# +# Return the status of a given VirtIODevice's VirtQueue +# +# @path: VirtIODevice canonical QOM path +# +# @queue: VirtQueue index to examine +# +# Features: +# @unstable: This command is meant for debugging. +# +# Returns: VirtQueueStatus of the VirtQueue +# +# Notes: last_avail_idx will not be displayed in the case where +# the selected VirtIODevice has a running vhost device and +# the VirtIODevice VirtQueue index (queue) does not exist for +# the corresponding vhost device vhost_virtqueue. Also, +# shadow_avail_idx will not be displayed in the case where +# the selected VirtIODevice has a running vhost device. +# +# Since: 7.1 +# +# Examples: +# +# 1. Get VirtQueueStatus for virtio-vsock (vhost-vsock running) +# +# -> { "execute": "x-query-virtio-queue-status", +# "arguments": { "path": "/machine/peripheral/vsock0/virtio-backend", +# "queue": 1 } +# } +# <- { "return": { +# "signalled-used": 0, +# "inuse": 0, +# "name": "vhost-vsock", +# "vring-align": 4096, +# "vring-desc": 5217370112, +# "signalled-used-valid": false, +# "vring-num-default": 128, +# "vring-avail": 5217372160, +# "queue-index": 1, +# "last-avail-idx": 0, +# "vring-used": 5217372480, +# "used-idx": 0, +# "vring-num": 128 +# } +# } +# +# 2. Get VirtQueueStatus for virtio-serial (no vhost) +# +# -> { "execute": "x-query-virtio-queue-status", +# "arguments": { "path": "/machine/peripheral-anon/device[0]/virtio-b= ackend", +# "queue": 20 } +# } +# <- { "return": { +# "signalled-used": 0, +# "inuse": 0, +# "name": "virtio-serial", +# "vring-align": 4096, +# "vring-desc": 5182074880, +# "signalled-used-valid": false, +# "vring-num-default": 128, +# "vring-avail": 5182076928, +# "queue-index": 20, +# "last-avail-idx": 0, +# "vring-used": 5182077248, +# "used-idx": 0, +# "shadow-avail-idx": 0, +# "vring-num": 128 +# } +# } +# +## + +{ 'command': 'x-query-virtio-queue-status', + 'data': { 'path': 'str', 'queue': 'uint16' }, + 'returns': 'VirtQueueStatus', + 'features': [ 'unstable' ] } + +## +# @VirtVhostQueueStatus: +# +# Information of a vhost device's vhost_virtqueue, including most +# members of the vhost_dev vhost_virtqueue data structure. +# +# @name: Name of the VirtIODevice that uses this vhost_virtqueue +# +# @kick: vhost_virtqueue kick +# +# @call: vhost_virtqueue call +# +# @desc: vhost_virtqueue desc +# +# @avail: vhost_virtqueue avail +# +# @used: vhost_virtqueue used +# +# @num: vhost_virtqueue num +# +# @desc-phys: vhost_virtqueue desc_phys (descriptor area phys. addr.) +# +# @desc-size: vhost_virtqueue desc_size +# +# @avail-phys: vhost_virtqueue avail_phys (driver area phys. addr.) +# +# @avail-size: vhost_virtqueue avail_size +# +# @used-phys: vhost_virtqueue used_phys (device area phys. addr.) +# +# @used-size: vhost_virtqueue used_size +# +# Since: 7.1 +# +## + +{ 'struct': 'VirtVhostQueueStatus', + 'data': { 'name': 'str', + 'kick': 'int', + 'call': 'int', + 'desc': 'uint64', + 'avail': 'uint64', + 'used': 'uint64', + 'num': 'int', + 'desc-phys': 'uint64', + 'desc-size': 'uint32', + 'avail-phys': 'uint64', + 'avail-size': 'uint32', + 'used-phys': 'uint64', + 'used-size': 'uint32' } } + +## +# @x-query-virtio-vhost-queue-status: +# +# Return information of a given vhost device's vhost_virtqueue +# +# @path: VirtIODevice canonical QOM path +# +# @queue: vhost_virtqueue index to examine +# +# Features: +# @unstable: This command is meant for debugging. +# +# Returns: VirtVhostQueueStatus of the vhost_virtqueue +# +# Since: 7.1 +# +# Examples: +# +# 1. Get vhost_virtqueue status for vhost-crypto +# +# -> { "execute": "x-query-virtio-vhost-queue-status", +# "arguments": { "path": "/machine/peripheral/crypto0/virtio-backend", +# "queue": 0 } +# } +# <- { "return": { +# "avail-phys": 5216124928, +# "name": "virtio-crypto", +# "used-phys": 5216127040, +# "avail-size": 2054, +# "desc-size": 16384, +# "used-size": 8198, +# "desc": 140141447430144, +# "num": 1024, +# "call": 0, +# "avail": 140141447446528, +# "desc-phys": 5216108544, +# "used": 140141447448640, +# "kick": 0 +# } +# } +# +# 2. Get vhost_virtqueue status for vhost-vsock +# +# -> { "execute": "x-query-virtio-vhost-queue-status", +# "arguments": { "path": "/machine/peripheral/vsock0/virtio-backend", +# "queue": 0 } +# } +# <- { "return": { +# "avail-phys": 5182261248, +# "name": "vhost-vsock", +# "used-phys": 5182261568, +# "avail-size": 262, +# "desc-size": 2048, +# "used-size": 1030, +# "desc": 140141413580800, +# "num": 128, +# "call": 0, +# "avail": 140141413582848, +# "desc-phys": 5182259200, +# "used": 140141413583168, +# "kick": 0 +# } +# } +# +## + +{ 'command': 'x-query-virtio-vhost-queue-status', + 'data': { 'path': 'str', 'queue': 'uint16' }, + 'returns': 'VirtVhostQueueStatus', + 'features': [ 'unstable' ] } diff --git a/hw/virtio/virtio-stub.c b/hw/virtio/virtio-stub.c index 0b432e8de7..13e5f93652 100644 --- a/hw/virtio/virtio-stub.c +++ b/hw/virtio/virtio-stub.c @@ -17,3 +17,17 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path= , Error **errp) { return qmp_virtio_unsupported(errp); } + +VirtVhostQueueStatus *qmp_x_query_virtio_vhost_queue_status(const char *pa= th, + uint16_t queue, + Error **errp) +{ + return qmp_virtio_unsupported(errp); +} + +VirtQueueStatus *qmp_x_query_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 6c530567b0..da869e7b51 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -4679,6 +4679,109 @@ VirtioStatus *qmp_x_query_virtio_status(const char = *path, Error **errp) return status; } =20 +VirtVhostQueueStatus *qmp_x_query_virtio_vhost_queue_status(const char *pa= th, + uint16_t queue, + Error **errp) +{ + VirtIODevice *vdev; + VirtVhostQueueStatus *status; + + vdev =3D virtio_device_find(path); + if (vdev =3D=3D NULL) { + error_setg(errp, "Path %s is not a VirtIODevice", path); + return NULL; + } + + if (!vdev->vhost_started) { + error_setg(errp, "Error: vhost device has not started yet"); + return NULL; + } + + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); + struct vhost_dev *hdev =3D vdc->get_vhost(vdev); + + if (queue < hdev->vq_index || queue >=3D hdev->vq_index + hdev->nvqs) { + error_setg(errp, "Invalid vhost virtqueue number %d", queue); + return NULL; + } + + status =3D g_new0(VirtVhostQueueStatus, 1); + status->name =3D g_strdup(vdev->name); + status->kick =3D hdev->vqs[queue].kick; + status->call =3D hdev->vqs[queue].call; + status->desc =3D (uintptr_t)hdev->vqs[queue].desc; + status->avail =3D (uintptr_t)hdev->vqs[queue].avail; + status->used =3D (uintptr_t)hdev->vqs[queue].used; + status->num =3D hdev->vqs[queue].num; + status->desc_phys =3D hdev->vqs[queue].desc_phys; + status->desc_size =3D hdev->vqs[queue].desc_size; + status->avail_phys =3D hdev->vqs[queue].avail_phys; + status->avail_size =3D hdev->vqs[queue].avail_size; + status->used_phys =3D hdev->vqs[queue].used_phys; + status->used_size =3D hdev->vqs[queue].used_size; + + return status; +} + +VirtQueueStatus *qmp_x_query_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 VirtIODevice", 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->name =3D g_strdup(vdev->name); + 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->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; + + if (vdev->vhost_started) { + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); + struct vhost_dev *hdev =3D vdc->get_vhost(vdev); + + /* check if vq index exists for vhost as well */ + if (queue >=3D hdev->vq_index && queue < hdev->vq_index + hdev->nv= qs) { + status->has_last_avail_idx =3D true; + + int vhost_vq_index =3D + hdev->vhost_ops->vhost_get_vq_index(hdev, queue); + struct vhost_vring_state state =3D { + .index =3D vhost_vq_index, + }; + + status->last_avail_idx =3D + hdev->vhost_ops->vhost_get_vring_base(hdev, &state); + } + } else { + status->has_shadow_avail_idx =3D true; + status->has_last_avail_idx =3D true; + status->last_avail_idx =3D vdev->vq[queue].last_avail_idx; + status->shadow_avail_idx =3D vdev->vq[queue].shadow_avail_idx; + } + + return status; +} + static const TypeInfo virtio_device_info =3D { .name =3D TYPE_VIRTIO_DEVICE, .parent =3D TYPE_DEVICE, --=20 MST