@@ -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"
@@ -48,6 +49,28 @@ static VirtIOFeature feature_sizes[] = {
{}
};
+qmp_virtio_feature_map_t blk_map[] = {
+#define FEATURE_ENTRY(name) \
+ { VIRTIO_BLK_F_##name, VIRTIO_BLK_FEATURE_##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
+#undef FEATURE_ENTRY
+ { -1, -1 }
+};
+
static void virtio_blk_set_config_size(VirtIOBlock *s, uint64_t host_features)
{
s->config_size = MAX(VIRTIO_BLK_CFG_SIZE,
@@ -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"
@@ -33,6 +34,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, VIRTIO_SERIAL_FEATURE_##name }
+ FEATURE_ENTRY(SIZE),
+ FEATURE_ENTRY(MULTIPORT),
+ FEATURE_ENTRY(EMERG_WRITE),
+#undef FEATURE_ENTRY
+ { -1, -1 }
+};
+
static struct VirtIOSerialDevices {
QLIST_HEAD(, VirtIOSerial) devices;
} vserdevices;
@@ -16,9 +16,19 @@
#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, VIRTIO_GPU_FEATURE_##name }
+ FEATURE_ENTRY(VIRGL),
+ FEATURE_ENTRY(EDID),
+#undef FEATURE_ENTRY
+ { -1, -1 }
+};
+
void
virtio_gpu_base_reset(VirtIOGPUBase *g)
{
@@ -35,6 +35,7 @@
#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"
@@ -85,6 +86,40 @@
#endif
+qmp_virtio_feature_map_t net_map[] = {
+#define FEATURE_ENTRY(name) \
+ { VIRTIO_NET_F_##name, VIRTIO_NET_FEATURE_##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(STANDBY),
+ FEATURE_ENTRY(SPEED_DUPLEX),
+#ifndef VIRTIO_NET_NO_LEGACY
+ FEATURE_ENTRY(GSO),
+#endif /* VIRTIO_NET_NO_LEGACY */
+#undef FEATURE_ENTRY
+ { -1, -1 }
+};
+
static inline __virtio16 *virtio_net_rsc_ext_num_packets(
struct virtio_net_hdr *hdr)
{
@@ -15,6 +15,7 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
+#include "qapi/qapi-visit-virtio.h"
#include "standard-headers/linux/virtio_ids.h"
#include "hw/virtio/virtio-scsi.h"
#include "migration/qemu-file-types.h"
@@ -28,6 +29,17 @@
#include "hw/virtio/virtio-bus.h"
#include "hw/virtio/virtio-access.h"
+qmp_virtio_feature_map_t scsi_map[] = {
+#define FEATURE_ENTRY(name) \
+ { VIRTIO_SCSI_F_##name, VIRTIO_SCSI_FEATURE_##name }
+ FEATURE_ENTRY(INOUT),
+ FEATURE_ENTRY(HOTPLUG),
+ FEATURE_ENTRY(CHANGE),
+ FEATURE_ENTRY(T10_PI),
+#undef FEATURE_ENTRY
+ { -1, -1 }
+};
+
static inline int virtio_scsi_get_lun(uint8_t *lun)
{
return ((lun[2] << 8) | lun[3]) & 0x3FFF;
@@ -26,6 +26,7 @@
#include "qapi/error.h"
#include "qapi/qapi-events-misc.h"
#include "qapi/visitor.h"
+#include "qapi/qapi-visit-virtio.h"
#include "trace.h"
#include "qemu/error-report.h"
#include "migration/misc.h"
@@ -33,6 +34,18 @@
#include "hw/virtio/virtio-bus.h"
#include "hw/virtio/virtio-access.h"
+qmp_virtio_feature_map_t balloon_map[] = {
+#define FEATURE_ENTRY(name) \
+ { VIRTIO_BALLOON_F_##name, VIRTIO_BALLOON_FEATURE_##name }
+ FEATURE_ENTRY(MUST_TELL_HOST),
+ FEATURE_ENTRY(STATS_VQ),
+ FEATURE_ENTRY(DEFLATE_ON_OOM),
+ FEATURE_ENTRY(FREE_PAGE_HINT),
+ FEATURE_ENTRY(PAGE_POISON),
+#undef FEATURE_ENTRY
+ { -1, -1 }
+};
+
#define BALLOON_PAGE_SIZE (1 << VIRTIO_BALLOON_PFN_SHIFT)
typedef struct PartiallyBalloonedPage {
@@ -25,6 +25,7 @@
#include "hw/virtio/virtio.h"
#include "sysemu/kvm.h"
#include "qapi/error.h"
+#include "qapi/qapi-visit-virtio.h"
#include "qemu/error-report.h"
#include "trace.h"
@@ -36,6 +37,19 @@
#include "hw/pci/pci_bus.h"
#include "hw/pci/pci.h"
+qmp_virtio_feature_map_t iommu_map[] = {
+#define FEATURE_ENTRY(name) \
+ { VIRTIO_IOMMU_F_##name, VIRTIO_IOMMU_FEATURE_##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, -1 }
+};
+
/* Max size */
#define VIOMMU_DEFAULT_QUEUE_SIZE 256
@@ -29,9 +29,30 @@
#include "hw/virtio/virtio-access.h"
#include "sysemu/dma.h"
#include "sysemu/runstate.h"
+#include "config-devices.h"
static QTAILQ_HEAD(, VirtIODevice) virtio_list;
+static qmp_virtio_feature_map_t transport_map[] = {
+#define FEATURE_ENTRY(name) \
+ { VIRTIO_F_##name, VIRTIO_TRANSPORT_FEATURE_##name }
+ FEATURE_ENTRY(NOTIFY_ON_EMPTY),
+ FEATURE_ENTRY(ANY_LAYOUT),
+ FEATURE_ENTRY(VERSION_1),
+ FEATURE_ENTRY(IOMMU_PLATFORM),
+ FEATURE_ENTRY(RING_PACKED),
+ FEATURE_ENTRY(ORDER_PLATFORM),
+ FEATURE_ENTRY(SR_IOV),
+ FEATURE_ENTRY(BAD_FEATURE),
+#undef FEATURE_ENTRY
+#define FEATURE_ENTRY(name) \
+ { VIRTIO_RING_F_##name, VIRTIO_TRANSPORT_FEATURE_##name }
+ FEATURE_ENTRY(INDIRECT_DESC),
+ FEATURE_ENTRY(EVENT_IDX),
+#undef FEATURE_ENTRY
+ { -1, -1 }
+};
+
/*
* The alignment to use between consumer and producer parts of vring.
* x86 pagesize again. This is the default, used by transports like PCI
@@ -3856,6 +3877,90 @@ static VirtIODevice *virtio_device_find(const char *path)
return NULL;
}
+#define CONVERT_FEATURES(type, map) \
+ ({ \
+ type *list = NULL; \
+ type *node; \
+ for (i = 0; map[i].virtio_bit != -1; i++) {\
+ bit = 1ULL << map[i].virtio_bit; \
+ if ((bitmap & bit) == 0) { \
+ continue; \
+ } \
+ node = g_new0(type, 1); \
+ node->value = map[i].qapi_virtio_enum; \
+ node->next = list; \
+ list = node; \
+ bitmap ^= bit; \
+ } \
+ list; \
+ })
+
+static VirtioStatusFeatures *qmp_decode_features(const char *name,
+ uint64_t bitmap)
+{
+ VirtioStatusFeatures *features;
+ uint64_t bit;
+ int i;
+
+ features = g_new0(VirtioStatusFeatures, 1);
+
+ /* transport features */
+ features->transport = CONVERT_FEATURES(VirtioTransportFeatureList, \
+ transport_map);
+
+ /* device features */
+ features->device = g_new0(VirtioDeviceFeatures, 1);
+ features->device->type = qapi_enum_parse(&VirtioDeviceFeaturesKind_lookup,
+ name, -1, NULL);
+ switch (features->device->type) {
+ case VIRTIO_DEVICE_FEATURES_KIND_VIRTIO_SERIAL:
+ features->device->u.virtio_serial.data =
+ CONVERT_FEATURES(VirtioSerialFeatureList, serial_map);
+ break;
+#ifdef CONFIG_VIRTIO_BLK
+ case VIRTIO_DEVICE_FEATURES_KIND_VIRTIO_BLK:
+ features->device->u.virtio_blk.data =
+ CONVERT_FEATURES(VirtioBlkFeatureList, blk_map);
+ break;
+#endif
+#ifdef CONFIG_VIRTIO_GPU
+ case VIRTIO_DEVICE_FEATURES_KIND_VIRTIO_GPU:
+ features->device->u.virtio_gpu.data =
+ CONVERT_FEATURES(VirtioGpuFeatureList, gpu_map);
+ break;
+#endif
+#ifdef CONFIG_VIRTIO_NET
+ case VIRTIO_DEVICE_FEATURES_KIND_VIRTIO_NET:
+ features->device->u.virtio_net.data =
+ CONVERT_FEATURES(VirtioNetFeatureList, net_map);
+ break;
+#endif
+#ifdef CONFIG_VIRTIO_SCSI
+ case VIRTIO_DEVICE_FEATURES_KIND_VIRTIO_SCSI:
+ features->device->u.virtio_scsi.data =
+ CONVERT_FEATURES(VirtioScsiFeatureList, scsi_map);
+ break;
+#endif
+#ifdef CONFIG_VIRTIO_BALLOON
+ case VIRTIO_DEVICE_FEATURES_KIND_VIRTIO_BALLOON:
+ features->device->u.virtio_balloon.data =
+ CONVERT_FEATURES(VirtioBalloonFeatureList, balloon_map);
+ break;
+#endif
+#ifdef CONFIG_VIRTIO_IOMMU
+ case VIRTIO_DEVICE_FEATURES_KIND_VIRTIO_IOMMU:
+ features->device->u.virtio_iommu.data =
+ CONVERT_FEATURES(VirtioIommuFeatureList, iommu_map);
+ break;
+#endif
+ default:
+ g_assert_not_reached();
+ }
+ features->unknown = bitmap;
+
+ return features;
+}
+
VirtioStatus *qmp_x_debug_virtio_status(const char* path, Error **errp)
{
VirtIODevice *vdev;
@@ -3868,9 +3973,12 @@ VirtioStatus *qmp_x_debug_virtio_status(const char* path, Error **errp)
}
status = g_new0(VirtioStatus, 1);
- status->guest_features = vdev->guest_features;
- status->host_features = vdev->host_features;
- status->backend_features = vdev->backend_features;
+ status->guest_features = qmp_decode_features(vdev->name,
+ vdev->guest_features);
+ status->host_features = qmp_decode_features(vdev->name,
+ vdev->host_features);
+ status->backend_features = qmp_decode_features(vdev->name,
+ vdev->backend_features);
status->device_id = vdev->device_id;
switch (vdev->device_endian) {
@@ -166,6 +166,19 @@ typedef struct VirtioDeviceClass {
bool (*primary_unplug_pending)(void *opaque);
} VirtioDeviceClass;
+typedef struct {
+ int virtio_bit;
+ int qapi_virtio_enum;
+} qmp_virtio_feature_map_t;
+
+extern qmp_virtio_feature_map_t serial_map[];
+extern qmp_virtio_feature_map_t blk_map[];
+extern qmp_virtio_feature_map_t gpu_map[];
+extern qmp_virtio_feature_map_t net_map[];
+extern qmp_virtio_feature_map_t scsi_map[];
+extern qmp_virtio_feature_map_t balloon_map[];
+extern qmp_virtio_feature_map_t iommu_map[];
+
void virtio_instance_init_common(Object *proxy_obj, void *data,
size_t vdev_size, const char *vdev_name);
@@ -78,6 +78,150 @@
'data': [ 'unknown', 'little', 'big' ]
}
+##
+# @VirtioTransportFeature:
+#
+# An enumeration of Virtio device transport features, including virtio-ring
+#
+# Since: 5.1
+##
+
+{ 'enum': 'VirtioTransportFeature',
+ 'data': [ 'notify-on-empty', 'any-layout', 'version-1', 'iommu-platform',
+ 'ring-packed', 'order-platform', 'sr-iov', 'indirect-desc',
+ 'event-idx', 'bad-feature' ]
+}
+
+##
+# @VirtioSerialFeature:
+#
+# An enumeration of Virtio serial features
+#
+# Since: 5.1
+##
+
+{ 'enum': 'VirtioSerialFeature',
+ 'data': [ 'size', 'multiport', 'emerg-write' ]
+}
+
+##
+# @VirtioBlkFeature:
+#
+# An enumeration of Virtio block features
+#
+# Since: 5.1
+##
+
+{ 'enum': 'VirtioBlkFeature',
+ 'data': [ 'size-max', 'seg-max', 'geometry', 'ro', 'blk-size', 'topology', 'mq', 'discard', 'write-zeroes', 'barrier', 'scsi', 'flush',
+ 'config-wce' ]
+}
+
+##
+# @VirtioGpuFeature:
+#
+# An enumeration of Virtio gpu features
+#
+# Since: 5.1
+##
+
+{ 'enum': 'VirtioGpuFeature',
+ 'data': [ 'virgl', 'edid' ]
+}
+
+##
+# @VirtioNetFeature:
+#
+# An enumeration of Virtio net features
+#
+# Since: 5.1
+##
+
+{ 'enum': 'VirtioNetFeature',
+ 'data': [ 'csum', 'guest-csum', 'ctrl-guest-offloads', 'mtu', 'mac',
+ 'guest-tso4', 'guest-tso6', 'guest-ecn', 'guest-ufo',
+ 'host-tso4', 'host-tso6', 'host-ecn', 'host-ufo', 'mrg-rxbuf',
+ 'status', 'ctrl-vq', 'ctrl-rx', 'ctrl-vlan', 'ctrl-rx-extra',
+ 'guest-announce', 'mq', 'ctrl-mac-addr', 'standby',
+ 'speed-duplex', 'gso' ]
+}
+
+##
+# @VirtioScsiFeature:
+#
+# An enumeration of Virtio scsi features
+#
+# Since: 5.1
+##
+
+{ 'enum': 'VirtioScsiFeature',
+ 'data': [ 'inout', 'hotplug', 'change', 't10-pi' ]
+}
+
+##
+# @VirtioBalloonFeature:
+#
+# An enumeration of Virtio balloon features
+#
+# Since: 5.1
+##
+
+{ 'enum': 'VirtioBalloonFeature',
+ 'data': [ 'must-tell-host', 'stats-vq', 'deflate-on-oom', 'free-page-hint',
+ 'page-poison' ]
+}
+
+##
+# @VirtioIommuFeature:
+#
+# An enumeration of Virtio iommu features
+#
+# Since: 5.1
+##
+
+{ 'enum': 'VirtioIommuFeature',
+ 'data': [ 'input-range', 'domain-range', 'map-unmap', 'bypass', 'probe',
+ 'mmio' ]
+}
+
+##
+# @VirtioDeviceFeatures:
+#
+# An union to define the list of features for a virtio device
+#
+# Since: 5.1
+##
+
+{ 'union': 'VirtioDeviceFeatures',
+ 'data': {
+ 'virtio-serial': [ 'VirtioSerialFeature' ],
+ 'virtio-blk': [ 'VirtioBlkFeature' ],
+ 'virtio-gpu': [ 'VirtioGpuFeature' ],
+ 'virtio-net': [ 'VirtioNetFeature' ],
+ 'virtio-scsi': [ 'VirtioScsiFeature' ],
+ 'virtio-balloon': [ 'VirtioBalloonFeature' ],
+ 'virtio-iommu': [ 'VirtioIommuFeature' ]
+ }
+}
+
+##
+# @VirtioStatusFeatures:
+#
+# @transport: the list of transport features of the virtio device
+#
+# @device: the list of the virtio device specific features
+#
+# @unknown: virtio bitmap of the undecoded features
+#
+# Since: 5.1
+##
+
+{ 'struct': 'VirtioStatusFeatures',
+ 'data': { 'transport': [ 'VirtioTransportFeature' ],
+ 'device': 'VirtioDeviceFeatures',
+ 'unknown': 'uint64' }
+}
+
##
# @VirtioStatus:
#
@@ -101,9 +245,9 @@
'data': {
'device-id': 'int',
'device-endian': 'VirtioStatusEndianness',
- 'guest-features': 'uint64',
- 'host-features': 'uint64',
- 'backend-features': 'uint64',
+ 'guest-features': 'VirtioStatusFeatures',
+ 'host-features': 'VirtioStatusFeatures',
+ 'backend-features': 'VirtioStatusFeatures',
'num-vqs': 'uint16'
}
}
@@ -123,18 +267,40 @@
#
# -> { "execute": "x-debug-virtio-status",
# "arguments": {
-# "path": "/machine/peripheral-anon/device[3]/virtio-backend"
+# "path": "/machine/peripheral-anon/device[1]/virtio-backend"
# }
# }
# <- { "return": {
-# "backend-features": 0,
-# "guest-features": 5111807911,
-# "num-vqs": 3,
-# "host-features": 6337593319,
# "device-endian": "little",
-# "device-id": 1
+# "device-id": 3,
+# "backend-features": {
+# "device": {
+# "type": "virtio-serial",
+# "data": []
+# },
+# "unknown": 0,
+# "transport": []
+# },
+# "num-vqs": 64,
+# "guest-features": {
+# "device": {
+# "type": "virtio-serial",
+# "data": [ "multiport" ]
+# },
+# "unknown": 0,
+# "transport": [ "event-idx", "indirect-desc", "version-1" ]
+# },
+# "host-features": {
+# "device": {
+# "type": "virtio-serial",
+# "data": [ "emerg-write", "multiport" ]
+# },
+# "unknown": 0,
+# "transport": [ "event-idx", "indirect-desc", "bad-feature",
+# "version-1", "any-layout", "notify-on-empty" ]
+# }
# }
-# }
+# }
#
##
Display feature names instead of a features bitmap for host, guest and backend. Decode features according device type, transport features are on the first line. Undecoded bits (if any) are stored in a separate field. Signed-off-by: Laurent Vivier <lvivier@redhat.com> --- 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/virtio-balloon.c | 13 +++ hw/virtio/virtio-iommu.c | 14 +++ hw/virtio/virtio.c | 114 ++++++++++++++++++++- include/hw/virtio/virtio.h | 13 +++ qapi/virtio.json | 186 +++++++++++++++++++++++++++++++++-- 10 files changed, 418 insertions(+), 13 deletions(-)