From patchwork Mon Apr 20 10:41:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 11498575 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB83192C for ; Mon, 20 Apr 2020 10:42:54 +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 673A12078E for ; Mon, 20 Apr 2020 10:42:54 +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="YpZAT+F7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 673A12078E 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQTt7-0005An-8W for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Apr 2020 06:42:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57910 helo=eggs1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQTsU-0004T1-W2 for qemu-devel@nongnu.org; Mon, 20 Apr 2020 06:42:15 -0400 Received: from Debian-exim by eggs1p.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQTsT-0004Uh-L6 for qemu-devel@nongnu.org; Mon, 20 Apr 2020 06:42:14 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:34703 helo=us-smtp-delivery-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 1jQTsT-0004R8-6c for qemu-devel@nongnu.org; Mon, 20 Apr 2020 06:42:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587379331; 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; bh=y5M70QA9uq+QauPrs/PlDIcwsg9GLecgOIVJ8aLpQgE=; b=YpZAT+F7b4cQNnUo/cdugJpC2Dljv5TMweTEuz9jR70uctdMt6i+wJum0oaMy77qG2RBIp 7whL6YDnzahMWsgWEzYGD7/AxqljgIVcQlJCxOgLTxfhF9KQlfGhfM5qHY0NNuSIezWVGK jIpSBSgU/G+KzmSZbS4nBmYQCHn+Bmw= 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-313-ai5arlI0Mven0aVVoTwXYQ-1; Mon, 20 Apr 2020 06:42:08 -0400 X-MC-Unique: ai5arlI0Mven0aVVoTwXYQ-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 C7B378017F3; Mon, 20 Apr 2020 10:42:06 +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 3FE1B5DA76; Mon, 20 Apr 2020 10:41:45 +0000 (UTC) From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [RFC v2 0/6] hmp,qmp: Add some commands to introspect virtio devices Date: Mon, 20 Apr 2020 12:41:39 +0200 Message-Id: <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=207.211.31.81; envelope-from=lvivier@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs1p.gnu.org: First seen = 2020/04/20 01:47:04 X-ACL-Warn: Detected OS = 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 , 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_Lureau?= , Paolo Bonzini , Kevin Wolf , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This series introduces new QMP/HMP commands to dump the status of a a virtio device at different levels. 1. Main command HMP Only: virtio [subcommand] Example: List all sub-commands: (qemu) virtio virtio query -- List all available virtio devices virtio status path -- Display status of a given virtio device virtio queue-status path queue -- Display status of a given virtio queue virtio queue-element path queue [index] -- Display element of a given virtio queue 2. List available virtio devices in the machine HMP Form: virtio query Example: (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] QMP Form: { 'command': 'query-virtio', 'returns': ['VirtioInfo'] } 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" } ] } 3. Display status of a given virtio device HMP Form: virtio status Example: (qemu) virtio status /machine/peripheral-anon/device[3]/virtio-backend /machine/peripheral-anon/device[3]/virtio-backend: Device Id: 1 Guest features: event-idx, indirect-desc, version-1 ctrl-mac-addr, guest-announce, ctrl-vlan, ctrl-rx, ctrl-vq, status, mrg-rxbuf, host-ufo, host-ecn, host-tso6, host-tso4, guest-ufo, guest-ecn, guest-tso6, guest-tso4, mac, ctrl-guest-offloads, guest-csum, csum Host features: event-idx, indirect-desc, bad-feature, version-1, any-layout, notify-on-empty gso, ctrl-mac-addr, guest-announce, ctrl-rx-extra, ctrl-vlan, ctrl-rx, ctrl-vq, status, mrg-rxbuf, host-ufo, host-ecn, host-tso6, host-tso4, guest-ufo, guest-ecn, guest-tso6, guest-tso4, mac, ctrl-guest-offloads, guest-csum, csum Backend features: Endianness: little VirtQueues: 3 QMP Form: { 'command': 'virtio-status', 'data': { 'path': 'str' }, 'returns': 'VirtioStatus' } Example: -> { "execute": "virtio-status", "arguments": { "path": "/machine/peripheral-anon/device[3]/virtio-backend" } } <- { "return": { "device-endian": "little", "device-id": 1, "backend-features": { "device": { "type": "virtio-net", "data": [] }, "unknown": 0, "transport": [] }, "num-vqs": 3, "guest-features": { "device": { "type": "virtio-net", "data": [ "ctrl-mac-addr", "guest-announce", "ctrl-vlan", "ctrl-rx", "ctrl-vq", "status", "mrg-rxbuf", "host-ufo", "host-ecn", "host-tso6", "host-tso4", "guest-ufo", "guest-ecn", "guest-tso6", "guest-tso4", "mac", "ctrl-guest-offloads", "guest-csum", "csum" ] }, "unknown": 0, "transport": [ "event-idx", "indirect-desc", "version-1" ] }, "host-features": { "device": { "type": "virtio-net", "data": [ "gso", "ctrl-mac-addr", "guest-announce", "ctrl-rx-extra", "ctrl-vlan", "ctrl-rx", "ctrl-vq", "status", "mrg-rxbuf", "host-ufo", "host-ecn", "host-tso6", "host-tso4", "guest-ufo", "guest-ecn", "guest-tso6", "guest-tso4", "mac", "ctrl-guest-offloads", "guest-csum", "csum" ] }, "unknown": 0, "transport": [ "event-idx", "indirect-desc", "bad-feature", "version-1", "any-layout", "notify-on-empty" ] } } } 4. Display status of a given virtio queue HMP Form: virtio queue-status Example: (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 QMP Form: { 'command': 'virtio-queue-status', 'data': { 'path': 'str', 'queue': 'uint16' }, 'returns': 'VirtQueueStatus' } 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 } } 5. Display element of a given virtio queue HMP Form: virtio queue-element [index] 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) (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 state 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 QMP Form: { 'command': 'virtio-queue-element', 'data': { 'path': 'str', 'queue': 'uint16', '*index': 'uint16' }, 'returns': 'VirtioQueueElement' } Example: -> { "execute": "virtio-queue-element", "arguments": { "path": "/machine/peripheral-anon/device[3]/virtio-backend", "queue": 0 } } -> { "return": { "index": 109, "ndescs": 1, "descs": [ { "flags": [ "write" ], "len": 1536, "addr": 853145600 } ] } } v2: introduce VirtioType enum use an enum for the endianness change field names to stick to naming conventions (s/_/-/) add a patch to decode feature bits don't check if the queue is empty to allow to displa old elements use enum for desc flags manage indirect desc decode device features in the HMP command Laurent Vivier (6): qmp: add QMP command query-virtio qmp: add QMP command virtio-status qmp: decode feature bits in virtio-status qmp: add QMP command virtio-queue-status qmp: add QMP command virtio-queue-element hmp: add virtio commands Makefile | 2 +- Makefile.target | 7 +- docs/system/monitor.rst | 2 + hmp-commands-virtio.hx | 160 +++++++++++ hmp-commands.hx | 10 + hw/block/virtio-blk.c | 23 ++ hw/char/virtio-serial-bus.c | 11 + hw/display/virtio-gpu-base.c | 10 + hw/net/virtio-net.c | 35 +++ hw/scsi/virtio-scsi.c | 12 + hw/virtio/Makefile.objs | 2 + hw/virtio/virtio-balloon.c | 13 + hw/virtio/virtio-iommu.c | 14 + hw/virtio/virtio-stub.c | 32 +++ hw/virtio/virtio.c | 537 +++++++++++++++++++++++++++++++++++ include/hw/virtio/virtio.h | 14 + include/monitor/hmp.h | 4 + monitor/misc.c | 17 ++ qapi/Makefile.objs | 2 +- qapi/qapi-schema.json | 1 + qapi/virtio.json | 502 ++++++++++++++++++++++++++++++++ tests/qtest/qmp-cmd-test.c | 1 + 22 files changed, 1407 insertions(+), 4 deletions(-) create mode 100644 hmp-commands-virtio.hx create mode 100644 hw/virtio/virtio-stub.c create mode 100644 qapi/virtio.json