From patchwork Thu Apr 2 10:03:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1265509 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DvbYu3Tc; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48tJYr22CLz9sRN for ; Thu, 2 Apr 2020 21:04:00 +1100 (AEDT) Received: from localhost ([::1]:36346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJwha-0001cD-1q for incoming@patchwork.ozlabs.org; Thu, 02 Apr 2020 06:03:58 -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 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= 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 X-MC-Unique: pl439HljPsKIi2N_sKJEZQ-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 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 *path, uint16_t queue, { return qmp_virtio_unsupported(errp); } + +VirtioQueueElement *qmp_virtio_queue_element(const char* path, uint16_t queue, + bool has_index, uint16_t index, + 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, Error **errp) return status; } +VirtioQueueElement *qmp_virtio_queue_element(const char* path, uint16_t queue, + bool has_index, uint16_t index, + Error **errp) +{ + VirtIODevice *vdev; + VirtQueue *vq; + VirtioQueueElement *element; + + vdev = virtio_device_find(path); + if (vdev == NULL) { + error_setg(errp, "Path %s is not a VirtIO device", path); + return NULL; + } + + if (queue >= VIRTIO_QUEUE_MAX || !virtio_queue_get_num(vdev, queue)) { + error_setg(errp, "Invalid virtqueue number %d", queue); + return NULL; + } + vq = &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 = vq->vring.num; + + if (vq->inuse >= vq->vring.num) { + error_setg(errp, "Queue size exceeded"); + return NULL; + } + + if (!has_index) { + head = vring_avail_ring(vq, vq->last_avail_idx % vq->vring.num); + } else { + head = vring_avail_ring(vq, index % vq->vring.num); + } + i = head; + + caches = 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 = &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 = g_new0(VirtioQueueElement, 1); + element->index = head; + element->ndescs = 1; + element->descs = g_new0(VirtioRingDescList, 1); + element->descs->value = g_new0(VirtioRingDesc, 1); + element->descs->value->addr = desc.addr; + element->descs->value->len = desc.len; + element->descs->value->flags = desc.flags; + } + + return element; +} + static const TypeInfo virtio_device_info = { .name = TYPE_VIRTIO_DEVICE, .parent = 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' +}