mbox series

[RFC,v2,0/6] hmp,qmp: Add some commands to introspect virtio devices

Message ID 20200420104145.205297-1-lvivier@redhat.com (mailing list archive)
Headers show
Series hmp,qmp: Add some commands to introspect virtio devices | expand

Message

Laurent Vivier April 20, 2020, 10:41 a.m. UTC
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 <path>

  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 <path> <queue>

  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 <path> <queue> [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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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

Comments

no-reply@patchew.org April 20, 2020, 3:05 p.m. UTC | #1
Patchew URL: https://patchew.org/QEMU/20200420104145.205297-1-lvivier@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Subject: [RFC v2 0/6] hmp,qmp: Add some commands to introspect virtio devices
Message-id: 20200420104145.205297-1-lvivier@redhat.com
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

From https://github.com/patchew-project/qemu
   20038cd..ff0507c  master     -> master
Switched to a new branch 'test'
eaf8d3f hmp: add virtio commands
cb4b58b qmp: add QMP command virtio-queue-element
e658c99 qmp: add QMP command virtio-queue-status
4d0287d qmp: decode feature bits in virtio-status
016ad6d qmp: add QMP command virtio-status
6816985 qmp: add QMP command query-virtio

=== OUTPUT BEGIN ===
1/6 Checking commit 68169851a4da (qmp: add QMP command query-virtio)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#27: 
new file mode 100644

total: 0 errors, 1 warnings, 180 lines checked

Patch 1/6 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
2/6 Checking commit 016ad6d70139 (qmp: add QMP command virtio-status)
3/6 Checking commit 4d0287d3f204 (qmp: decode feature bits in virtio-status)
4/6 Checking commit e658c99cb0bf (qmp: add QMP command virtio-queue-status)
5/6 Checking commit cb4b58babd76 (qmp: add QMP command virtio-queue-element)
6/6 Checking commit eaf8d3f50b01 (hmp: add virtio commands)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#67: 
new file mode 100644

ERROR: trailing whitespace
#149: FILE: hmp-commands-virtio.hx:78:
+        Backend features: $

ERROR: spaces required around that '*' (ctx:WxV)
#344: FILE: hw/virtio/virtio.c:4095:
+        type##FeatureList *list = features->device->u.field.data;          \
                           ^

total: 2 errors, 1 warnings, 480 lines checked

Patch 6/6 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20200420104145.205297-1-lvivier@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com
Kevin Wolf April 20, 2020, 3:55 p.m. UTC | #2
Am 20.04.2020 um 12:41 hat Laurent Vivier geschrieben:
> This series introduces new QMP/HMP commands to dump the status
> of a a virtio device at different levels.

What is the intended use case for these commands?

If it's just for debugging, should we add a x-debug- prefix to the QMP
commands to avoid making it a stable interface for which we must keep
backwards compatibility?

Kevin
Laurent Vivier April 21, 2020, 8:42 a.m. UTC | #3
On 20/04/2020 17:55, Kevin Wolf wrote:
> Am 20.04.2020 um 12:41 hat Laurent Vivier geschrieben:
>> This series introduces new QMP/HMP commands to dump the status
>> of a a virtio device at different levels.
> 
> What is the intended use case for these commands?
> 
> If it's just for debugging, should we add a x-debug- prefix to the QMP
> commands to avoid making it a stable interface for which we must keep
> backwards compatibility?

Yes, it's just for debugging so I will add a x-debug- prefix.

Thanks,
Laurent