Skip to content

Commit

Permalink
qmp: decode feature & status bits in virtio-status
Browse files Browse the repository at this point in the history
Display feature names instead of bitmaps for host, guest, and
backend for VirtIODevices.

Display status names instead of bitmaps for VirtIODevices.

Display feature names instead of bitmaps for backend, protocol,
acked, and features (hdev->features) for vhost devices.

Decode features according to device ID. Decode statuses
according to configuration status bitmap (config_status_map).
Decode vhost user protocol features according to vhost user
protocol bitmap (vhost_user_protocol_map).

Transport features are on the first line. Undecoded bits (if
any) are stored in a separate field.

Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
Message-Id: <1646658521-31652-6-git-send-email-jonah.palmer@oracle.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
  • Loading branch information
vivier authored and mstsirkin committed Mar 7, 2022
1 parent 8381eb8 commit 371bfea
Show file tree
Hide file tree
Showing 16 changed files with 646 additions and 29 deletions.
29 changes: 29 additions & 0 deletions hw/block/virtio-blk.c
Expand Up @@ -13,6 +13,7 @@

#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qapi/qapi-visit-virtio.h"
#include "qemu/iov.h"
#include "qemu/module.h"
#include "qemu/error-report.h"
Expand All @@ -33,10 +34,38 @@
#include "migration/qemu-file-types.h"
#include "hw/virtio/virtio-access.h"
#include "qemu/coroutine.h"
#include "standard-headers/linux/vhost_types.h"

/* Config size before the discard support (hide associated config fields) */
#define VIRTIO_BLK_CFG_SIZE offsetof(struct virtio_blk_config, \
max_discard_sectors)

qmp_virtio_feature_map_t blk_map[] = {
#define FEATURE_ENTRY(name) \
{ VIRTIO_BLK_F_##name, #name }
FEATURE_ENTRY(SIZE_MAX),
FEATURE_ENTRY(SEG_MAX),
FEATURE_ENTRY(GEOMETRY),
FEATURE_ENTRY(RO),
FEATURE_ENTRY(BLK_SIZE),
FEATURE_ENTRY(TOPOLOGY),
FEATURE_ENTRY(MQ),
FEATURE_ENTRY(DISCARD),
FEATURE_ENTRY(WRITE_ZEROES),
#ifndef VIRTIO_BLK_NO_LEGACY
FEATURE_ENTRY(BARRIER),
FEATURE_ENTRY(SCSI),
FEATURE_ENTRY(FLUSH),
FEATURE_ENTRY(CONFIG_WCE),
#endif /* !VIRTIO_BLK_NO_LEGACY */
#undef FEATURE_ENTRY
#define FEATURE_ENTRY(name) \
{ VHOST_F_##name, #name }
FEATURE_ENTRY(LOG_ALL),
#undef FEATURE_ENTRY
{ -1, "" }
};

/*
* Starting from the discard feature, we can use this array to properly
* set the config size depending on the features enabled.
Expand Down
11 changes: 11 additions & 0 deletions hw/char/virtio-serial-bus.c
Expand Up @@ -20,6 +20,7 @@

#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qapi/qapi-visit-virtio.h"
#include "qemu/iov.h"
#include "qemu/main-loop.h"
#include "qemu/module.h"
Expand All @@ -32,6 +33,16 @@
#include "hw/virtio/virtio-serial.h"
#include "hw/virtio/virtio-access.h"

qmp_virtio_feature_map_t serial_map[] = {
#define FEATURE_ENTRY(name) \
{ VIRTIO_CONSOLE_F_##name, #name }
FEATURE_ENTRY(SIZE),
FEATURE_ENTRY(MULTIPORT),
FEATURE_ENTRY(EMERG_WRITE),
#undef FEATURE_ENTRY
{ -1, "" }
};

static struct VirtIOSerialDevices {
QLIST_HEAD(, VirtIOSerial) devices;
} vserdevices;
Expand Down
18 changes: 17 additions & 1 deletion hw/display/virtio-gpu-base.c
Expand Up @@ -12,13 +12,29 @@
*/

#include "qemu/osdep.h"

#include "standard-headers/linux/vhost_types.h"
#include "hw/virtio/virtio-gpu.h"
#include "migration/blocker.h"
#include "qapi/error.h"
#include "qapi/qapi-visit-virtio.h"
#include "qemu/error-report.h"
#include "trace.h"

qmp_virtio_feature_map_t gpu_map[] = {
#define FEATURE_ENTRY(name) \
{ VIRTIO_GPU_F_##name, #name }
FEATURE_ENTRY(VIRGL),
FEATURE_ENTRY(EDID),
FEATURE_ENTRY(RESOURCE_UUID),
FEATURE_ENTRY(RESOURCE_BLOB),
#undef FEATURE_ENTRY
#define FEATURE_ENTRY(name) \
{ VHOST_F_##name, #name }
FEATURE_ENTRY(LOG_ALL),
#undef FEATURE_ENTRY
{ -1, "" }
};

void
virtio_gpu_base_reset(VirtIOGPUBase *g)
{
Expand Down
10 changes: 10 additions & 0 deletions hw/input/virtio-input.c
Expand Up @@ -6,6 +6,7 @@

#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qapi/qapi-visit-virtio.h"
#include "qemu/iov.h"
#include "qemu/module.h"
#include "trace.h"
Expand All @@ -14,10 +15,19 @@
#include "hw/qdev-properties.h"
#include "hw/virtio/virtio-input.h"

#include "standard-headers/linux/vhost_types.h"
#include "standard-headers/linux/input.h"

#define VIRTIO_INPUT_VM_VERSION 1

qmp_virtio_feature_map_t input_map[] = {
#define FEATURE_ENTRY(name) \
{ VHOST_F_##name, #name }
FEATURE_ENTRY(LOG_ALL),
#undef FEATURE_ENTRY
{ -1, "" }
};

/* ----------------------------------------------------------------- */

void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event)
Expand Down
47 changes: 47 additions & 0 deletions hw/net/virtio-net.c
Expand Up @@ -35,9 +35,11 @@
#include "hw/qdev-properties.h"
#include "qapi/qapi-types-migration.h"
#include "qapi/qapi-events-migration.h"
#include "qapi/qapi-visit-virtio.h"
#include "hw/virtio/virtio-access.h"
#include "migration/misc.h"
#include "standard-headers/linux/ethtool.h"
#include "standard-headers/linux/vhost_types.h"
#include "sysemu/sysemu.h"
#include "trace.h"
#include "monitor/qdev.h"
Expand Down Expand Up @@ -90,6 +92,51 @@
VIRTIO_NET_RSS_HASH_TYPE_TCP_EX | \
VIRTIO_NET_RSS_HASH_TYPE_UDP_EX)

qmp_virtio_feature_map_t net_map[] = {
#define FEATURE_ENTRY(name) \
{ VIRTIO_NET_F_##name, #name }
FEATURE_ENTRY(CSUM),
FEATURE_ENTRY(GUEST_CSUM),
FEATURE_ENTRY(CTRL_GUEST_OFFLOADS),
FEATURE_ENTRY(MTU),
FEATURE_ENTRY(MAC),
FEATURE_ENTRY(GUEST_TSO4),
FEATURE_ENTRY(GUEST_TSO6),
FEATURE_ENTRY(GUEST_ECN),
FEATURE_ENTRY(GUEST_UFO),
FEATURE_ENTRY(HOST_TSO4),
FEATURE_ENTRY(HOST_TSO6),
FEATURE_ENTRY(HOST_ECN),
FEATURE_ENTRY(HOST_UFO),
FEATURE_ENTRY(MRG_RXBUF),
FEATURE_ENTRY(STATUS),
FEATURE_ENTRY(CTRL_VQ),
FEATURE_ENTRY(CTRL_RX),
FEATURE_ENTRY(CTRL_VLAN),
FEATURE_ENTRY(CTRL_RX_EXTRA),
FEATURE_ENTRY(GUEST_ANNOUNCE),
FEATURE_ENTRY(MQ),
FEATURE_ENTRY(CTRL_MAC_ADDR),
FEATURE_ENTRY(HASH_REPORT),
FEATURE_ENTRY(RSS),
FEATURE_ENTRY(RSC_EXT),
FEATURE_ENTRY(STANDBY),
FEATURE_ENTRY(SPEED_DUPLEX),
#ifndef VIRTIO_NET_NO_LEGACY
FEATURE_ENTRY(GSO),
#endif /* VIRTIO_NET_NO_LEGACY */
#undef FEATURE_ENTRY
#define FEATURE_ENTRY(name) \
{ VHOST_NET_F_##name, #name }
FEATURE_ENTRY(VIRTIO_NET_HDR),
#undef FEATURE_ENTRY
#define FEATURE_ENTRY(name) \
{ VHOST_F_##name, #name }
FEATURE_ENTRY(LOG_ALL),
#undef FEATURE_ENTRY
{ -1, "" }
};

static const VirtIOFeature feature_sizes[] = {
{.flags = 1ULL << VIRTIO_NET_F_MAC,
.end = endof(struct virtio_net_config, mac)},
Expand Down
17 changes: 17 additions & 0 deletions hw/scsi/virtio-scsi.c
Expand Up @@ -15,7 +15,9 @@

#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qapi/qapi-visit-virtio.h"
#include "standard-headers/linux/virtio_ids.h"
#include "standard-headers/linux/vhost_types.h"
#include "hw/virtio/virtio-scsi.h"
#include "migration/qemu-file-types.h"
#include "qemu/error-report.h"
Expand All @@ -29,6 +31,21 @@
#include "hw/virtio/virtio-access.h"
#include "trace.h"

qmp_virtio_feature_map_t scsi_map[] = {
#define FEATURE_ENTRY(name) \
{ VIRTIO_SCSI_F_##name, #name }
FEATURE_ENTRY(INOUT),
FEATURE_ENTRY(HOTPLUG),
FEATURE_ENTRY(CHANGE),
FEATURE_ENTRY(T10_PI),
#undef FEATURE_ENTRY
#define FEATURE_ENTRY(name) \
{ VHOST_F_##name, #name }
FEATURE_ENTRY(LOG_ALL),
#undef FEATURE_ENTRY
{ -1, "" }
};

static inline int virtio_scsi_get_lun(uint8_t *lun)
{
return ((lun[2] << 8) | lun[3]) & 0x3FFF;
Expand Down
10 changes: 10 additions & 0 deletions hw/virtio/vhost-user-fs.c
Expand Up @@ -15,6 +15,7 @@
#include <sys/ioctl.h>
#include "standard-headers/linux/virtio_fs.h"
#include "qapi/error.h"
#include "qapi/qapi-visit-virtio.h"
#include "hw/qdev-properties.h"
#include "hw/qdev-properties-system.h"
#include "hw/virtio/virtio-bus.h"
Expand All @@ -23,6 +24,15 @@
#include "hw/virtio/vhost-user-fs.h"
#include "monitor/monitor.h"
#include "sysemu/sysemu.h"
#include "standard-headers/linux/vhost_types.h"

qmp_virtio_feature_map_t fs_map[] = {
#define FEATURE_ENTRY(name) \
{ VHOST_F_##name, #name }
FEATURE_ENTRY(LOG_ALL),
#undef FEATURE_ENTRY
{ -1, "" }
};

static const int user_feature_bits[] = {
VIRTIO_F_VERSION_1,
Expand Down
10 changes: 10 additions & 0 deletions hw/virtio/vhost-vsock-common.c
Expand Up @@ -11,12 +11,22 @@
#include "qemu/osdep.h"
#include "standard-headers/linux/virtio_vsock.h"
#include "qapi/error.h"
#include "qapi/qapi-visit-virtio.h"
#include "hw/virtio/virtio-access.h"
#include "qemu/error-report.h"
#include "hw/qdev-properties.h"
#include "hw/virtio/vhost-vsock.h"
#include "qemu/iov.h"
#include "monitor/monitor.h"
#include "standard-headers/linux/vhost_types.h"

qmp_virtio_feature_map_t vsock_map[] = {
#define FEATURE_ENTRY(name) \
{ VHOST_F_##name, #name }
FEATURE_ENTRY(LOG_ALL),
#undef FEATURE_ENTRY
{ -1, "" }
};

const int feature_bits[] = {
VIRTIO_VSOCK_F_SEQPACKET,
Expand Down
14 changes: 14 additions & 0 deletions hw/virtio/virtio-balloon.c
Expand Up @@ -28,6 +28,7 @@
#include "qapi/error.h"
#include "qapi/qapi-events-machine.h"
#include "qapi/visitor.h"
#include "qapi/qapi-visit-virtio.h"
#include "trace.h"
#include "qemu/error-report.h"
#include "migration/misc.h"
Expand All @@ -38,6 +39,19 @@

#define BALLOON_PAGE_SIZE (1 << VIRTIO_BALLOON_PFN_SHIFT)

qmp_virtio_feature_map_t balloon_map[] = {
#define FEATURE_ENTRY(name) \
{ VIRTIO_BALLOON_F_##name, #name }
FEATURE_ENTRY(MUST_TELL_HOST),
FEATURE_ENTRY(STATS_VQ),
FEATURE_ENTRY(DEFLATE_ON_OOM),
FEATURE_ENTRY(FREE_PAGE_HINT),
FEATURE_ENTRY(PAGE_POISON),
FEATURE_ENTRY(REPORTING),
#undef FEATURE_ENTRY
{ -1, "" }
};

typedef struct PartiallyBalloonedPage {
ram_addr_t base_gpa;
unsigned long *bitmap;
Expand Down
10 changes: 10 additions & 0 deletions hw/virtio/virtio-crypto.c
Expand Up @@ -16,17 +16,27 @@
#include "qemu/main-loop.h"
#include "qemu/module.h"
#include "qapi/error.h"
#include "qapi/qapi-visit-virtio.h"
#include "qemu/error-report.h"

#include "hw/virtio/virtio.h"
#include "hw/virtio/virtio-crypto.h"
#include "hw/qdev-properties.h"
#include "hw/virtio/virtio-access.h"
#include "standard-headers/linux/virtio_ids.h"
#include "standard-headers/linux/vhost_types.h"
#include "sysemu/cryptodev-vhost.h"

#define VIRTIO_CRYPTO_VM_VERSION 1

qmp_virtio_feature_map_t crypto_map[] = {
#define FEATURE_ENTRY(name) \
{ VHOST_F_##name, #name }
FEATURE_ENTRY(LOG_ALL),
#undef FEATURE_ENTRY
{ -1, "" }
};

/*
* Transfer virtqueue index to crypto queue index.
* The control virtqueue is after the data virtqueues
Expand Down
14 changes: 14 additions & 0 deletions hw/virtio/virtio-iommu.c
Expand Up @@ -26,6 +26,7 @@
#include "sysemu/kvm.h"
#include "sysemu/reset.h"
#include "qapi/error.h"
#include "qapi/qapi-visit-virtio.h"
#include "qemu/error-report.h"
#include "trace.h"

Expand All @@ -41,6 +42,19 @@
#define VIOMMU_DEFAULT_QUEUE_SIZE 256
#define VIOMMU_PROBE_SIZE 512

qmp_virtio_feature_map_t iommu_map[] = {
#define FEATURE_ENTRY(name) \
{ VIRTIO_IOMMU_F_##name, #name }
FEATURE_ENTRY(INPUT_RANGE),
FEATURE_ENTRY(DOMAIN_RANGE),
FEATURE_ENTRY(MAP_UNMAP),
FEATURE_ENTRY(BYPASS),
FEATURE_ENTRY(PROBE),
FEATURE_ENTRY(MMIO),
#undef FEATURE_ENTRY
{ -1, "" }
};

typedef struct VirtIOIOMMUDomain {
uint32_t id;
bool bypass;
Expand Down
11 changes: 11 additions & 0 deletions hw/virtio/virtio-mem.c
Expand Up @@ -25,13 +25,24 @@
#include "hw/virtio/virtio-mem.h"
#include "qapi/error.h"
#include "qapi/visitor.h"
#include "qapi/qapi-visit-virtio.h"
#include "exec/ram_addr.h"
#include "migration/misc.h"
#include "hw/boards.h"
#include "hw/qdev-properties.h"
#include CONFIG_DEVICES
#include "trace.h"

qmp_virtio_feature_map_t mem_map[] = {
#define FEATURE_ENTRY(name) \
{ VIRTIO_MEM_F_##name, #name }
#ifndef CONFIG_ACPI
FEATURE_ENTRY(ACPI_PXM),
#endif /* CONFIG_ACPI */
#undef FEATURE_ENTRY
{ -1, "" }
};

/*
* We only had legacy x86 guests that did not support
* VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE. Other targets don't have legacy guests.
Expand Down

0 comments on commit 371bfea

Please sign in to comment.