Virtio features acknowledged by guest
cover Virtio features acknowledged by guest
In some situations (for instance, debug), we want to be able to see the features that were confirmed by the guest. At the same time, we would like to do this safely, without the possibility of setting bits of guest features from the outside.
Maxim Davydov (8):
qdev-properties: Add read-only 64 bit property
virtio: Add tracking of the common virtio guest features
virtio-gpu: Add tracking of the virtio guest feature bits
virtio-serial: Add tracking of the virtio guest feature bits
virtio-net: Add tracking of the virtio guest feature bits
scsi: Add tracking of the acknowledged feature bits
virtio-blk: Add tracking of the virtio guest feature bits
virtio-balloon: Add tracking of the virtio guest feature bits
hw/block/virtio-blk.c | 20 ++++--- hw/char/virtio-serial-bus.c | 5 +- hw/core/qdev-properties.c | 32 +++++++++++ hw/display/vhost-user-gpu.c | 3 +- hw/display/virtio-gpu.c | 8 +-- hw/net/virtio-net.c | 118 +++++++++++++++++++++++++---------------- hw/scsi/vhost-scsi.c | 6 +-- hw/scsi/vhost-user-scsi.c | 18 +++---- hw/scsi/virtio-scsi.c | 10 ++-- hw/virtio/virtio-balloon.c | 20 ++++--- hw/virtio/virtio.c | 2 +- include/hw/qdev-properties.h | 5 ++ include/hw/virtio/virtio-gpu.h | 10 ++-- include/hw/virtio/virtio.h | 39 +++++++++----- 14 files changed, 193 insertions(+), 103 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/8 qdev-properties: Add read-only 64 bit property
In some situations, we need a property that tracks the bit but can't change it (for instance, guest features of virtio device).
--- hw/core/qdev-properties.c | 32 ++++++++++++++++++++++++++++++++ include/hw/qdev-properties.h | 5 +++++ 2 files changed, 37 insertions(+)
hw/core/qdev-properties.c +32 -0
@@ -231,6 +231,38 @@ const PropertyInfo qdev_prop_bit64 = { .set_default_value = set_default_value_bool, }; +/* Read-only Bit64 */ + +static void prop_set_read_only_bit64 (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +return ; +} + +static uint64_t qdev_get_prop_read_only_mask64 (Property *prop) +{ +assert (prop->info == &qdev_prop_read_only_bit64); +return 0x1ull << prop->bitnr; +} + +static void prop_get_read_only_bit64 (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +Property *prop = opaque; +uint64_t *p =object_field_prop_ptr (obj, prop); +bool value = (*p &qdev_get_prop_read_only_mask64 (prop)) !=0 ; + +visit_type_bool (v, name, &value, errp); +} + +const PropertyInfo qdev_prop_read_only_bit64 = { + .name ="bool" , + .description ="on/off" , + .get = prop_get_read_only_bit64, + .set = prop_set_read_only_bit64, + .set_default_value = set_default_value_bool, +}; +/* --- bool --- */ static void get_bool(Object *obj, Visitor *v, const char *name, void *opaque,
include/hw/qdev-properties.h +5 -0
@@ -46,6 +46,7 @@ struct PropertyInfo {extern const PropertyInfo qdev_prop_bit;extern const PropertyInfo qdev_prop_bit64; +extern const PropertyInfo qdev_prop_read_only_bit64;extern const PropertyInfo qdev_prop_bool;extern const PropertyInfo qdev_prop_enum;extern const PropertyInfo qdev_prop_uint8;
@@ -102,6 +103,10 @@ extern const PropertyInfo qdev_prop_link; .set_default = true, \ .defval.u = (bool)_defval) +#define DEFINE_PROP_READ_ONLY_BIT64 (_name, _state, _field, _bit) \ + DEFINE_PROP(_name, _state, _field, qdev_prop_read_only_bit64, uint64_t, \ + .bitnr = (_bit)) +#define PROP_ARRAY_LEN_PREFIX "len-"/**
Signature · 1 line
1.8.3.1
PATCH 2/8 virtio: Add tracking of the common virtio guest features
In reply to Maxim DavydovIt implements common virtio features via macros that, by defining the virtio guest feature bit and the virtio host feature bit, allow you to checks acknowledged virtio features by the guest.
--- hw/virtio/virtio.c | 2 +- include/hw/virtio/virtio.h | 39 ++++++++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 14 deletions(-)
hw/virtio/virtio.c +1 -1
@@ -3717,7 +3717,7 @@ static void virtio_device_instance_finalize(Object *obj) }static Property virtio_properties[] = { -DEFINE_VIRTIO_COMMON_FEATURES (VirtIODevice, host_features), +DEFINE_VIRTIO_COMMON_FEATURES (VirtIODevice, host_features, guest_features),DEFINE_PROP_BOOL ("use-started" , VirtIODevice, use_started, true),DEFINE_PROP_BOOL ("use-disabled-flag" , VirtIODevice, use_disabled_flag, true), DEFINE_PROP_BOOL("x-disable-legacy-check", VirtIODevice,
include/hw/virtio/virtio.h +26 -13
@@ -277,19 +277,32 @@ typedef struct virtio_input_conf virtio_input_conf;typedef struct VirtIOSCSIConf VirtIOSCSIConf ;typedef struct VirtIORNGConf VirtIORNGConf ; -#define DEFINE_VIRTIO_COMMON_FEATURES (_state, _field) \ - DEFINE_PROP_BIT64("indirect_desc", _state, _field, \ - VIRTIO_RING_F_INDIRECT_DESC, true), \ - DEFINE_PROP_BIT64("event_idx", _state, _field, \ - VIRTIO_RING_F_EVENT_IDX, true), \ - DEFINE_PROP_BIT64("notify_on_empty", _state, _field, \ - VIRTIO_F_NOTIFY_ON_EMPTY, true), \ - DEFINE_PROP_BIT64("any_layout", _state, _field, \ - VIRTIO_F_ANY_LAYOUT, true), \ - DEFINE_PROP_BIT64("iommu_platform", _state, _field, \ - VIRTIO_F_IOMMU_PLATFORM, false), \ - DEFINE_PROP_BIT64("packed", _state, _field, \ - VIRTIO_F_RING_PACKED, false) +#define DEFINE_VIRTIO_FEATURE_BIT (_name, _state, _host_field, _guest_field, \ + _bit, _defval) \ + DEFINE_PROP_BIT(_name, _state, _host_field, _bit, _defval), \ + DEFINE_PROP_READ_ONLY_BIT64("acknowledged_by_guest_" _name, _state, \ + _guest_field, _bit) + +#define DEFINE_VIRTIO_FEATURE_BIT64 (_name, _state, _host_field, _guest_field, \ + _bit, _defval) \ + DEFINE_PROP_BIT64(_name, _state, _host_field, _bit, _defval), \ + DEFINE_PROP_READ_ONLY_BIT64("acknowledged_by_guest_" _name, _state, \ + _guest_field, _bit) + +#define DEFINE_VIRTIO_COMMON_FEATURES (_state, _host_field, _guest_field) \ + DEFINE_VIRTIO_FEATURE_BIT64("indirect_desc", _state, _host_field, \ + _guest_field, VIRTIO_RING_F_INDIRECT_DESC, \ + true), \ + DEFINE_VIRTIO_FEATURE_BIT64("event_idx", _state, _host_field, \ + _guest_field, VIRTIO_RING_F_EVENT_IDX, true), \ + DEFINE_VIRTIO_FEATURE_BIT64("notify_on_empty", _state, _host_field, \ + _guest_field, VIRTIO_F_NOTIFY_ON_EMPTY, true), \ + DEFINE_VIRTIO_FEATURE_BIT64("any_layout", _state, _host_field, \ + _guest_field, VIRTIO_F_ANY_LAYOUT, true), \ + DEFINE_VIRTIO_FEATURE_BIT64("iommu_platform", _state, _host_field, \ + _guest_field, VIRTIO_F_IOMMU_PLATFORM, false), \ + DEFINE_VIRTIO_FEATURE_BIT64("packed", _state, _host_field, \ + _guest_field, VIRTIO_F_RING_PACKED, false)hwaddr virtio_queue_get_desc_addr (VirtIODevice *vdev,int n);bool virtio_queue_enabled_legacy (VirtIODevice *vdev,int n);
Signature · 1 line
1.8.3.1
PATCH 3/8 virtio-gpu: Add tracking of the virtio guest feature bits
In reply to Maxim DavydovAdd tracking of the bits acknowledged by the guest
--- hw/display/vhost-user-gpu.c | 3 ++- hw/display/virtio-gpu.c | 8 +++++--- include/hw/virtio/virtio-gpu.h | 10 +++++----- 3 files changed, 12 insertions(+), 9 deletions(-)
hw/display/vhost-user-gpu.c +2 -1
@@ -566,7 +566,8 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Error **errp) }static Property vhost_user_gpu_properties[] = { -VIRTIO_GPU_BASE_PROPERTIES (VhostUserGPU, parent_obj.conf), +VIRTIO_GPU_BASE_PROPERTIES (VhostUserGPU, parent_obj.conf, + parent_obj.parent_obj.guest_features),DEFINE_PROP_END_OF_LIST (), };
hw/display/virtio-gpu.c +5 -3
@@ -1387,11 +1387,13 @@ static const VMStateDescription vmstate_virtio_gpu = { };static Property virtio_gpu_properties[] = { -VIRTIO_GPU_BASE_PROPERTIES (VirtIOGPU, parent_obj.conf), +VIRTIO_GPU_BASE_PROPERTIES (VirtIOGPU, parent_obj.conf, + parent_obj.parent_obj.guest_features),DEFINE_PROP_SIZE ("max_hostmem" , VirtIOGPU, conf_max_hostmem,256 * MiB), -DEFINE_PROP_BIT ("blob" , VirtIOGPU, parent_obj.conf.flags, -VIRTIO_GPU_FLAG_BLOB_ENABLED , false), +DEFINE_VIRTIO_FEATURE_BIT ("blob" , VirtIOGPU, parent_obj.conf.flags, + parent_obj.parent_obj.guest_features, +VIRTIO_GPU_FLAG_BLOB_ENABLED , false),DEFINE_PROP_END_OF_LIST (), };
include/hw/virtio/virtio-gpu.h +5 -5
@@ -143,11 +143,11 @@ struct VirtIOGPUBaseClass {void (*gl_flushed)(VirtIOGPUBase *g); }; -#define VIRTIO_GPU_BASE_PROPERTIES (_state, _conf) \ - DEFINE_PROP_UINT32("max_outputs", _state, _conf.max_outputs, 1), \ - DEFINE_PROP_BIT("edid", _state, _conf.flags, \ - VIRTIO_GPU_FLAG_EDID_ENABLED, true), \ - DEFINE_PROP_UINT32("xres", _state, _conf.xres, 1024), \ +#define VIRTIO_GPU_BASE_PROPERTIES (_state, _conf, _guest_field) \ + DEFINE_PROP_UINT32("max_outputs", _state, _conf.max_outputs, 1), \ + DEFINE_VIRTIO_FEATURE_BIT("edid", _state, _conf.flags, _guest_field, \ + VIRTIO_GPU_FLAG_EDID_ENABLED, true), \ + DEFINE_PROP_UINT32("xres", _state, _conf.xres, 1024), \ DEFINE_PROP_UINT32("yres", _state, _conf.yres, 768) typedef struct VGPUDMABuf {
Signature · 1 line
1.8.3.1
PATCH 4/8 virtio-serial: Add tracking of the virtio guest feature bits
In reply to Maxim DavydovAdd tracking of the VIRTIO_CONSOLE_F_EMERG_WRITE acknowledged by the guest.
--- hw/char/virtio-serial-bus.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/char/virtio-serial-bus.c +3 -2
@@ -1159,8 +1159,9 @@ static const VMStateDescription vmstate_virtio_console = {static Property virtio_serial_properties[] = {DEFINE_PROP_UINT32 ("max_ports" , VirtIOSerial, serial.max_virtserial_ports,31 ), -DEFINE_PROP_BIT64 ("emergency-write" , VirtIOSerial, host_features, -VIRTIO_CONSOLE_F_EMERG_WRITE , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("emergency-write" , VirtIOSerial, host_features, + parent_obj.guest_features, +VIRTIO_CONSOLE_F_EMERG_WRITE , true),DEFINE_PROP_END_OF_LIST (), };
Signature · 1 line
1.8.3.1
PATCH 5/8 virtio-net: Add tracking of the virtio guest feature bits
In reply to Maxim DavydovAdd tracking of the bits acknowledged by the guest
--- hw/net/virtio-net.c | 118 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 72 insertions(+), 46 deletions(-)
hw/net/virtio-net.c +72 -46
@@ -3562,52 +3562,78 @@ static const VMStateDescription vmstate_virtio_net = { };static Property virtio_net_properties[] = { -DEFINE_PROP_BIT64 ("csum" , VirtIONet, host_features, -VIRTIO_NET_F_CSUM , true), -DEFINE_PROP_BIT64 ("guest_csum" , VirtIONet, host_features, -VIRTIO_NET_F_GUEST_CSUM , true), -DEFINE_PROP_BIT64 ("gso" , VirtIONet, host_features,VIRTIO_NET_F_GSO , true), -DEFINE_PROP_BIT64 ("guest_tso4" , VirtIONet, host_features, -VIRTIO_NET_F_GUEST_TSO4 , true), -DEFINE_PROP_BIT64 ("guest_tso6" , VirtIONet, host_features, -VIRTIO_NET_F_GUEST_TSO6 , true), -DEFINE_PROP_BIT64 ("guest_ecn" , VirtIONet, host_features, -VIRTIO_NET_F_GUEST_ECN , true), -DEFINE_PROP_BIT64 ("guest_ufo" , VirtIONet, host_features, -VIRTIO_NET_F_GUEST_UFO , true), -DEFINE_PROP_BIT64 ("guest_announce" , VirtIONet, host_features, -VIRTIO_NET_F_GUEST_ANNOUNCE , true), -DEFINE_PROP_BIT64 ("host_tso4" , VirtIONet, host_features, -VIRTIO_NET_F_HOST_TSO4 , true), -DEFINE_PROP_BIT64 ("host_tso6" , VirtIONet, host_features, -VIRTIO_NET_F_HOST_TSO6 , true), -DEFINE_PROP_BIT64 ("host_ecn" , VirtIONet, host_features, -VIRTIO_NET_F_HOST_ECN , true), -DEFINE_PROP_BIT64 ("host_ufo" , VirtIONet, host_features, -VIRTIO_NET_F_HOST_UFO , true), -DEFINE_PROP_BIT64 ("mrg_rxbuf" , VirtIONet, host_features, -VIRTIO_NET_F_MRG_RXBUF , true), -DEFINE_PROP_BIT64 ("status" , VirtIONet, host_features, -VIRTIO_NET_F_STATUS , true), -DEFINE_PROP_BIT64 ("ctrl_vq" , VirtIONet, host_features, -VIRTIO_NET_F_CTRL_VQ , true), -DEFINE_PROP_BIT64 ("ctrl_rx" , VirtIONet, host_features, -VIRTIO_NET_F_CTRL_RX , true), -DEFINE_PROP_BIT64 ("ctrl_vlan" , VirtIONet, host_features, -VIRTIO_NET_F_CTRL_VLAN , true), -DEFINE_PROP_BIT64 ("ctrl_rx_extra" , VirtIONet, host_features, -VIRTIO_NET_F_CTRL_RX_EXTRA , true), -DEFINE_PROP_BIT64 ("ctrl_mac_addr" , VirtIONet, host_features, -VIRTIO_NET_F_CTRL_MAC_ADDR , true), -DEFINE_PROP_BIT64 ("ctrl_guest_offloads" , VirtIONet, host_features, -VIRTIO_NET_F_CTRL_GUEST_OFFLOADS , true), -DEFINE_PROP_BIT64 ("mq" , VirtIONet, host_features,VIRTIO_NET_F_MQ , false), -DEFINE_PROP_BIT64 ("rss" , VirtIONet, host_features, -VIRTIO_NET_F_RSS , false), -DEFINE_PROP_BIT64 ("hash" , VirtIONet, host_features, -VIRTIO_NET_F_HASH_REPORT , false), -DEFINE_PROP_BIT64 ("guest_rsc_ext" , VirtIONet, host_features, -VIRTIO_NET_F_RSC_EXT , false), +DEFINE_VIRTIO_FEATURE_BIT64 ("csum" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_CSUM , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("guest_csum" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_GUEST_CSUM , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("gso" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_GSO , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("guest_tso4" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_GUEST_TSO4 , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("guest_tso6" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_GUEST_TSO6 , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("guest_ecn" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_GUEST_ECN , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("guest_ufo" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_GUEST_UFO , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("guest_announce" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_GUEST_ANNOUNCE , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("host_tso4" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_HOST_TSO4 , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("host_tso6" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_HOST_TSO6 , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("host_ecn" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_HOST_ECN , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("host_ufo" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_HOST_UFO , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("mrg_rxbuf" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_MRG_RXBUF , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("status" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_STATUS , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("ctrl_vq" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_CTRL_VQ , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("ctrl_rx" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_CTRL_RX , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("ctrl_vlan" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_CTRL_VLAN , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("ctrl_rx_extra" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_CTRL_RX_EXTRA , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("ctrl_mac_addr" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_CTRL_MAC_ADDR , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("ctrl_guest_offloads" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_CTRL_GUEST_OFFLOADS , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("mq" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_MQ , false), +DEFINE_VIRTIO_FEATURE_BIT64 ("rss" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_RSS , false), +DEFINE_VIRTIO_FEATURE_BIT64 ("hash" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_HASH_REPORT , false), +DEFINE_VIRTIO_FEATURE_BIT64 ("guest_rsc_ext" , VirtIONet, host_features, + parent_obj.guest_features, +VIRTIO_NET_F_RSC_EXT , false),DEFINE_PROP_UINT32 ("rsc_interval" , VirtIONet, rsc_timeout,VIRTIO_NET_RSC_DEFAULT_INTERVAL ),DEFINE_NIC_PROPERTIES (VirtIONet, nic_conf),
Signature · 1 line
1.8.3.1
PATCH 6/8 scsi: Add tracking of the acknowledged feature bits
In reply to Maxim DavydovAdd tracking of the VIRTIO_SCSI_F_HOTPLUG, VIRTIO_SCSI_F_CHANGE and VIRTIO_SCSI_F_T10_PI bits acknowledged by the guest
--- hw/scsi/vhost-scsi.c | 6 +++--- hw/scsi/vhost-user-scsi.c | 18 +++++++++--------- hw/scsi/virtio-scsi.c | 10 ++++++---- 3 files changed, 18 insertions(+), 16 deletions(-)
hw/scsi/vhost-scsi.c +3 -3
@@ -277,9 +277,9 @@ static Property vhost_scsi_properties[] = {DEFINE_PROP_UINT32 ("max_sectors" , VirtIOSCSICommon, conf.max_sectors,0xFFFF ),DEFINE_PROP_UINT32 ("cmd_per_lun" , VirtIOSCSICommon, conf.cmd_per_lun,128 ), -DEFINE_PROP_BIT64 ("t10_pi" , VHostSCSICommon, host_features, -VIRTIO_SCSI_F_T10_PI , - false), +DEFINE_VIRTIO_FEATURE_BIT64 ("t10_pi" , VHostSCSICommon, + host_features, dev.acked_features, +VIRTIO_SCSI_F_T10_PI , false),DEFINE_PROP_BOOL ("migratable" , VHostSCSICommon, migratable, false), DEFINE_PROP_END_OF_LIST(), };
hw/scsi/vhost-user-scsi.c +9 -9
@@ -168,15 +168,15 @@ static Property vhost_user_scsi_properties[] = {DEFINE_PROP_UINT32 ("max_sectors" , VirtIOSCSICommon, conf.max_sectors,0xFFFF ),DEFINE_PROP_UINT32 ("cmd_per_lun" , VirtIOSCSICommon, conf.cmd_per_lun,128 ), -DEFINE_PROP_BIT64 ("hotplug" , VHostSCSICommon, host_features, -VIRTIO_SCSI_F_HOTPLUG , - true), -DEFINE_PROP_BIT64 ("param_change" , VHostSCSICommon, host_features, -VIRTIO_SCSI_F_CHANGE , - true), -DEFINE_PROP_BIT64 ("t10_pi" , VHostSCSICommon, host_features, -VIRTIO_SCSI_F_T10_PI , - false), +DEFINE_VIRTIO_FEATURE_BIT64 ("hotplug" , VHostSCSICommon, + host_features, dev.acked_features, +VIRTIO_SCSI_F_HOTPLUG , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("param_change" , VHostSCSICommon, + host_features, dev.acked_features, +VIRTIO_SCSI_F_CHANGE , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("t10_pi" , VHostSCSICommon, + host_features, dev.acked_features, +VIRTIO_SCSI_F_T10_PI , false), DEFINE_PROP_END_OF_LIST(), };
hw/scsi/virtio-scsi.c +6 -4
@@ -1061,10 +1061,12 @@ static Property virtio_scsi_properties[] = { 0xFFFF),DEFINE_PROP_UINT32 ("cmd_per_lun" , VirtIOSCSI, parent_obj.conf.cmd_per_lun,128 ), -DEFINE_PROP_BIT ("hotplug" , VirtIOSCSI, host_features, -VIRTIO_SCSI_F_HOTPLUG , true), -DEFINE_PROP_BIT ("param_change" , VirtIOSCSI, host_features, -VIRTIO_SCSI_F_CHANGE , true), +DEFINE_VIRTIO_FEATURE_BIT ("hotplug" , VirtIOSCSI, host_features, + parent_obj.parent_obj.guest_features, +VIRTIO_SCSI_F_HOTPLUG , true), +DEFINE_VIRTIO_FEATURE_BIT ("param_change" , VirtIOSCSI, host_features, + parent_obj.parent_obj.guest_features, +VIRTIO_SCSI_F_CHANGE , true),DEFINE_PROP_LINK ("iothread" , VirtIOSCSI, parent_obj.conf.iothread, TYPE_IOTHREAD, IOThread *), DEFINE_PROP_END_OF_LIST(),
Signature · 1 line
1.8.3.1
PATCH 7/8 virtio-blk: Add tracking of the virtio guest feature bits
In reply to Maxim DavydovAdd tracking of the bits acknowledged by the guests
--- hw/block/virtio-blk.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
hw/block/virtio-blk.c +12 -8
@@ -1287,11 +1287,13 @@ static Property virtio_blk_properties[] = {DEFINE_BLOCK_ERROR_PROPERTIES (VirtIOBlock, conf.conf),DEFINE_BLOCK_CHS_PROPERTIES (VirtIOBlock, conf.conf),DEFINE_PROP_STRING ("serial" , VirtIOBlock, conf.serial), -DEFINE_PROP_BIT64 ("config-wce" , VirtIOBlock, host_features, -VIRTIO_BLK_F_CONFIG_WCE , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("config-wce" , VirtIOBlock, host_features, + parent_obj.guest_features, +VIRTIO_BLK_F_CONFIG_WCE , true), #ifdef __linux__ -DEFINE_PROP_BIT64 ("scsi" , VirtIOBlock, host_features, -VIRTIO_BLK_F_SCSI , false), +DEFINE_VIRTIO_FEATURE_BIT64 ("scsi" , VirtIOBlock, host_features, + parent_obj.guest_features, +VIRTIO_BLK_F_SCSI , false), #endifDEFINE_PROP_BIT ("request-merging" , VirtIOBlock, conf.request_merging,0 , true),
@@ -1301,12 +1303,14 @@ static Property virtio_blk_properties[] = {DEFINE_PROP_BOOL ("seg-max-adjust" , VirtIOBlock, conf.seg_max_adjust, true),DEFINE_PROP_LINK ("iothread" , VirtIOBlock, conf.iothread,TYPE_IOTHREAD , IOThread *), -DEFINE_PROP_BIT64 ("discard" , VirtIOBlock, host_features, -VIRTIO_BLK_F_DISCARD , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("discard" , VirtIOBlock, host_features, + parent_obj.guest_features, +VIRTIO_BLK_F_DISCARD , true),DEFINE_PROP_BOOL ("report-discard-granularity" , VirtIOBlock, conf.report_discard_granularity, true), -DEFINE_PROP_BIT64 ("write-zeroes" , VirtIOBlock, host_features, -VIRTIO_BLK_F_WRITE_ZEROES , true), +DEFINE_VIRTIO_FEATURE_BIT64 ("write-zeroes" , VirtIOBlock, host_features, + parent_obj.guest_features, +VIRTIO_BLK_F_WRITE_ZEROES , true),DEFINE_PROP_UINT32 ("max-discard-sectors" , VirtIOBlock, conf.max_discard_sectors,BDRV_REQUEST_MAX_SECTORS ), DEFINE_PROP_UINT32("max-write-zeroes-sectors", VirtIOBlock,
Signature · 1 line
1.8.3.1
PATCH 8/8 virtio-balloon: Add tracking of the virtio guest feature bits
In reply to Maxim DavydovAdd tracking of the bits acknowledged by the guest
--- hw/virtio/virtio-balloon.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
hw/virtio/virtio-balloon.c +12 -8
@@ -1029,14 +1029,18 @@ static const VMStateDescription vmstate_virtio_balloon = { };static Property virtio_balloon_properties[] = { -DEFINE_PROP_BIT ("deflate-on-oom" , VirtIOBalloon, host_features, -VIRTIO_BALLOON_F_DEFLATE_ON_OOM , false), -DEFINE_PROP_BIT ("free-page-hint" , VirtIOBalloon, host_features, -VIRTIO_BALLOON_F_FREE_PAGE_HINT , false), -DEFINE_PROP_BIT ("page-poison" , VirtIOBalloon, host_features, -VIRTIO_BALLOON_F_PAGE_POISON , true), -DEFINE_PROP_BIT ("free-page-reporting" , VirtIOBalloon, host_features, -VIRTIO_BALLOON_F_REPORTING , false), +DEFINE_VIRTIO_FEATURE_BIT ("deflate-on-oom" , VirtIOBalloon, host_features, + parent_obj.guest_features, +VIRTIO_BALLOON_F_DEFLATE_ON_OOM , false), +DEFINE_VIRTIO_FEATURE_BIT ("free-page-hint" , VirtIOBalloon, host_features, + parent_obj.guest_features, +VIRTIO_BALLOON_F_FREE_PAGE_HINT , false), +DEFINE_VIRTIO_FEATURE_BIT ("page-poison" , VirtIOBalloon, host_features, + parent_obj.guest_features, +VIRTIO_BALLOON_F_PAGE_POISON , true), +DEFINE_VIRTIO_FEATURE_BIT ("free-page-reporting" , VirtIOBalloon, + host_features, parent_obj.guest_features, +VIRTIO_BALLOON_F_REPORTING , false),/* QEMU 4.0 accidentally changed the config size even when free-page-hint * is disabled, resulting in QEMU 3.1 migration incompatibility. This * property retains this quirk for QEMU 4.1 machine types.
Signature · 1 line
1.8.3.1
Quoted 15 lines · Maxim Davydov
In some situations (for instance, debug), we want to be able to see the features that were confirmed by the guest. At the same time, we would like to do this safely, without the possibility of setting bits of guest features from the outside.
Maxim Davydov (8):
qdev-properties: Add read-only 64 bit property
virtio: Add tracking of the common virtio guest features
virtio-gpu: Add tracking of the virtio guest feature bits
virtio-serial: Add tracking of the virtio guest feature bits
virtio-net: Add tracking of the virtio guest feature bits
scsi: Add tracking of the acknowledged feature bits
virtio-blk: Add tracking of the virtio guest feature bits
virtio-balloon: Add tracking of the virtio guest feature bits
Quoted 15 lines
hw/block/virtio-blk.c | 20 ++++--- hw/char/virtio-serial-bus.c | 5 +- hw/core/qdev-properties.c | 32 +++++++++++ hw/display/vhost-user-gpu.c | 3 +- hw/display/virtio-gpu.c | 8 +-- hw/net/virtio-net.c | 118 +++++++++++++++++++++++++---------------- hw/scsi/vhost-scsi.c | 6 +-- hw/scsi/vhost-user-scsi.c | 18 +++---- hw/scsi/virtio-scsi.c | 10 ++-- hw/virtio/virtio-balloon.c | 20 ++++--- hw/virtio/virtio.c | 2 +- include/hw/qdev-properties.h | 5 ++ include/hw/virtio/virtio-gpu.h | 10 ++-- include/hw/virtio/virtio.h | 39 +++++++++----- 14 files changed, 193 insertions(+), 103 deletions(-)
Hi Maxim,
The VIRTIO specification is designed to allow more than 64 feature bits. Currently all feature bits fit into 64 bits but that may not be the case in the future. Please use a representation that is capable of expanding in the future.
The Linux guest drivers have a string sysfs attribute that is formatted in binary ('0' and '1' characters). It's not easy for humans to read but it is capable of growing in the future.
Also, please take a look at Jonah Palmer's patch series that adds commands to introspect VIRTIO devices:
https://lore.kernel.org/qemu-devel/[email protected]/
I have CCed Jonah in case there is overlap between the two series that you can work together on.
Stefan