qemu: towards virtio-1 host support
Subsystems (2)
v6 cover qemu: towards virtio-1 host support
And yet another iteration of virtio-1 support in qemu, tested with the latest virtio kernel patches. Find it at
git://github.com/cohuck/qemu virtio-1
Changes from v5:
- fixed stupid bug in "virtio: support more feature bits": we need to define a proper prop backend for 64 bit wide handling...
- don't negotiate revision 1 unless VERSION_1 is offered
- use 64 bit wide features in the whole of vhost (patch can probably be merged into the 64 bit extension for the rest of the code)
The bug I suspected in the revision-specific feature handling turned out to be a messup on my side. There still seems to be something missing for vhost-net to support virtio-1.
Cornelia Huck (17):
virtio: cull virtio_bus_set_vdev_features
virtio: feature bit manipulation helpers
virtio: add feature checking helpers
virtio: support more feature bits
virtio: endianness checks for virtio 1.0 devices
virtio: allow virtio-1 queue layout
dataplane: allow virtio-1 devices s390x/virtio-ccw: support virtio-1 set_vq format
virtio: disallow late feature changes for virtio-1
virtio: allow to fail setting status s390x/virtio-ccw: enable virtio 1.0
virtio-net: no writeable mac for virtio-1
virtio-net: support longer header
virtio-net: enable virtio 1.0
virtio: support revision-specific features
virtio-blk: revision specific feature bits
vhost: 64 bit features
Thomas Huth (3):
linux-headers/virtio_config: Update with VIRTIO_F_VERSION_1 s390x/css: Add a callback for when subchannel gets disabled s390x/virtio-ccw: add virtio set-revision call
hw/9pfs/virtio-9p-device.c | 4 +- hw/block/dataplane/virtio-blk.c | 4 +- hw/block/virtio-blk.c | 44 +++-- hw/char/virtio-serial-bus.c | 6 +- hw/core/qdev-properties.c | 58 ++++++ hw/net/vhost_net.c | 12 +- hw/net/virtio-net.c | 100 ++++++----- hw/s390x/css.c | 12 ++ hw/s390x/css.h | 1 + hw/s390x/s390-virtio-bus.c | 3 +- hw/s390x/s390-virtio-bus.h | 2 +- hw/s390x/virtio-ccw.c | 234 ++++++++++++++++++------- hw/s390x/virtio-ccw.h | 13 +- hw/scsi/vhost-scsi.c | 3 +- hw/scsi/virtio-scsi-dataplane.c | 2 +- hw/scsi/virtio-scsi.c | 12 +- hw/virtio/Makefile.objs | 2 +- hw/virtio/dataplane/Makefile.objs | 2 +- hw/virtio/dataplane/vring.c | 96 +++++----- hw/virtio/vhost.c | 14 +- hw/virtio/virtio-balloon.c | 4 +- hw/virtio/virtio-bus.c | 24 ++- hw/virtio/virtio-mmio.c | 9 +- hw/virtio/virtio-pci.c | 7 +- hw/virtio/virtio-pci.h | 2 +- hw/virtio/virtio-rng.c | 2 +- hw/virtio/virtio.c | 120 +++++++++---- include/hw/qdev-properties.h | 12 ++ include/hw/virtio/dataplane/vring-accessors.h | 75 ++++++++ include/hw/virtio/dataplane/vring.h | 14 +- include/hw/virtio/vhost.h | 6 +- include/hw/virtio/virtio-access.h | 4 + include/hw/virtio/virtio-bus.h | 14 +- include/hw/virtio/virtio-net.h | 46 ++--- include/hw/virtio/virtio-scsi.h | 6 +- include/hw/virtio/virtio.h | 62 +++++-- include/net/vhost_net.h | 4 +- linux-headers/linux/virtio_config.h | 3 + 38 files changed, 727 insertions(+), 311 deletions(-) create mode 100644 include/hw/virtio/dataplane/vring-accessors.h
Signature · 1 line
1.7.9.5
RFC PATCH v6 1/20 linux-headers/virtio_config: Update with VIRTIO_F_VERSION_1
From: Thomas Huth <[email protected]>
Add the new VIRTIO_F_VERSION_1 definition to the virtio_config.h linux header.
--- linux-headers/linux/virtio_config.h | 3 +++ 1 file changed, 3 insertions(+)
linux-headers/linux/virtio_config.h +3 -0
@@ -54,4 +54,7 @@/* Can the device handle any descriptor layout? */ #define VIRTIO_F_ANY_LAYOUT 27 +/* v1.0 compliant. */ +#define VIRTIO_F_VERSION_1 32 +#endif /* _LINUX_VIRTIO_CONFIG_H */
Signature · 1 line
1.7.9.5
RFC PATCH v6 2/20 virtio: cull virtio_bus_set_vdev_features
In reply to Cornelia HuckThe only user of this function was virtio-ccw, and it should use virtio_set_features() like everybody else: We need to make sure that bad features are masked out properly, which this function did not do.
--- hw/s390x/virtio-ccw.c | 3 +-- hw/virtio/virtio-bus.c | 14 -------------- include/hw/virtio/virtio-bus.h | 3 --- 3 files changed, 1 insertion(+), 19 deletions(-)
hw/s390x/virtio-ccw.c +1 -2
@@ -400,8 +400,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) ccw.cda + sizeof(features.features)); features.features =ldl_le_phys (&address_space_memory, ccw.cda);if (features.index <ARRAY_SIZE (dev->host_features)) { -virtio_bus_set_vdev_features (&dev->bus, features.features); - vdev->guest_features = features.features; +virtio_set_features (vdev, features.features); }else {/* * If the guest supports more feature bits, assert that it
hw/virtio/virtio-bus.c +0 -14
@@ -109,20 +109,6 @@ uint32_t virtio_bus_get_vdev_features(VirtioBusState *bus,return k->get_features (vdev, requested_features); } -/* Set the features of the plugged device. */ -void virtio_bus_set_vdev_features (VirtioBusState *bus, -uint32_t requested_features) -{ -VirtIODevice *vdev =virtio_bus_get_device (bus); -VirtioDeviceClass *k; - -assert (vdev !=NULL ); - k =VIRTIO_DEVICE_GET_CLASS (vdev); -if (k->set_features !=NULL ) { - k->set_features (vdev, requested_features); - } -} -/* Get bad features of the plugged device. */ uint32_t virtio_bus_get_vdev_bad_features (VirtioBusState *bus) {
include/hw/virtio/virtio-bus.h +0 -3
@@ -84,9 +84,6 @@ size_t virtio_bus_get_vdev_config_len(VirtioBusState *bus);/* Get the features of the plugged device. */ uint32_t virtio_bus_get_vdev_features (VirtioBusState *bus,uint32_t requested_features); -/* Set the features of the plugged device. */ -void virtio_bus_set_vdev_features (VirtioBusState *bus, -uint32_t requested_features);/* Get bad features of the plugged device. */ uint32_t virtio_bus_get_vdev_bad_features (VirtioBusState *bus);/* Get config of the plugged device. */
Signature · 1 line
1.7.9.5
RFC PATCH v6 3/20 virtio: feature bit manipulation helpers
In reply to Cornelia HuckAdd virtio_{add,clear}_feature helper functions for manipulating a feature bits variable. This has some benefits over open coding:
- add check that the bit is in a sane range
- make it obvious at a glance what is going on
- have a central point to change when we want to extend feature bits
Convert existing code manipulating features to use the new helpers.
--- hw/9pfs/virtio-9p-device.c | 2 +- hw/block/virtio-blk.c | 16 ++++++++-------- hw/char/virtio-serial-bus.c | 2 +- hw/net/virtio-net.c | 34 +++++++++++++++++----------------- hw/s390x/virtio-ccw.c | 4 ++-- hw/virtio/virtio-mmio.c | 2 +- hw/virtio/virtio-pci.c | 4 ++-- include/hw/virtio/virtio.h | 12 ++++++++++++ 8 files changed, 44 insertions(+), 32 deletions(-)
hw/9pfs/virtio-9p-device.c +1 -1
@@ -23,7 +23,7 @@static uint32_t virtio_9p_get_features (VirtIODevice *vdev,uint32_t features) { - features |=1 <<VIRTIO_9P_MOUNT_TAG ; +virtio_add_feature (&features,VIRTIO_9P_MOUNT_TAG );return features; }
hw/block/virtio-blk.c +8 -8
@@ -568,20 +568,20 @@ static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features) {VirtIOBlock *s =VIRTIO_BLK (vdev); - features |= (1 <<VIRTIO_BLK_F_SEG_MAX ); - features |= (1 <<VIRTIO_BLK_F_GEOMETRY ); - features |= (1 <<VIRTIO_BLK_F_TOPOLOGY ); - features |= (1 <<VIRTIO_BLK_F_BLK_SIZE ); - features |= (1 <<VIRTIO_BLK_F_SCSI ); +virtio_add_feature (&features,VIRTIO_BLK_F_SEG_MAX ); +virtio_add_feature (&features,VIRTIO_BLK_F_GEOMETRY ); +virtio_add_feature (&features,VIRTIO_BLK_F_TOPOLOGY ); +virtio_add_feature (&features,VIRTIO_BLK_F_BLK_SIZE ); +virtio_add_feature (&features,VIRTIO_BLK_F_SCSI );if (s->conf.config_wce) { - features |= (1 <<VIRTIO_BLK_F_CONFIG_WCE ); +virtio_add_feature (&features,VIRTIO_BLK_F_CONFIG_WCE ); }if (blk_enable_write_cache (s->blk)) { - features |= (1 <<VIRTIO_BLK_F_WCE ); +virtio_add_feature (&features,VIRTIO_BLK_F_WCE ); }if (blk_is_read_only (s->blk)) { - features |=1 <<VIRTIO_BLK_F_RO ; +virtio_add_feature (&features,VIRTIO_BLK_F_RO ); }return features;
hw/char/virtio-serial-bus.c +1 -1
@@ -474,7 +474,7 @@ static uint32_t get_features(VirtIODevice *vdev, uint32_t features) vser =VIRTIO_SERIAL (vdev);if (vser->bus.max_nr_ports >1 ) { - features |= (1 <<VIRTIO_CONSOLE_F_MULTIPORT ); +virtio_add_feature (&features,VIRTIO_CONSOLE_F_MULTIPORT ); }return features; }
hw/net/virtio-net.c +17 -17
@@ -446,23 +446,23 @@ static uint32_t virtio_net_get_features(VirtIODevice *vdev, uint32_t features)VirtIONet *n =VIRTIO_NET (vdev);NetClientState *nc =qemu_get_queue (n->nic); - features |= (1 <<VIRTIO_NET_F_MAC ); +virtio_add_feature (&features,VIRTIO_NET_F_MAC );if (!peer_has_vnet_hdr (n)) { - features &= ~(0x1 <<VIRTIO_NET_F_CSUM ); - features &= ~(0x1 <<VIRTIO_NET_F_HOST_TSO4 ); - features &= ~(0x1 <<VIRTIO_NET_F_HOST_TSO6 ); - features &= ~(0x1 <<VIRTIO_NET_F_HOST_ECN ); +virtio_clear_feature (&features,VIRTIO_NET_F_CSUM ); +virtio_clear_feature (&features,VIRTIO_NET_F_HOST_TSO4 ); +virtio_clear_feature (&features,VIRTIO_NET_F_HOST_TSO6 ); +virtio_clear_feature (&features,VIRTIO_NET_F_HOST_ECN ); - features &= ~(0x1 <<VIRTIO_NET_F_GUEST_CSUM ); - features &= ~(0x1 <<VIRTIO_NET_F_GUEST_TSO4 ); - features &= ~(0x1 <<VIRTIO_NET_F_GUEST_TSO6 ); - features &= ~(0x1 <<VIRTIO_NET_F_GUEST_ECN ); +virtio_clear_feature (&features,VIRTIO_NET_F_GUEST_CSUM ); +virtio_clear_feature (&features,VIRTIO_NET_F_GUEST_TSO4 ); +virtio_clear_feature (&features,VIRTIO_NET_F_GUEST_TSO6 ); +virtio_clear_feature (&features,VIRTIO_NET_F_GUEST_ECN ); }if (!peer_has_vnet_hdr (n) || !peer_has_ufo (n)) { - features &= ~(0x1 <<VIRTIO_NET_F_GUEST_UFO ); - features &= ~(0x1 <<VIRTIO_NET_F_HOST_UFO ); +virtio_clear_feature (&features,VIRTIO_NET_F_GUEST_UFO ); +virtio_clear_feature (&features,VIRTIO_NET_F_HOST_UFO ); }if (!get_vhost_net (nc->peer)) {
@@ -477,11 +477,11 @@ static uint32_t virtio_net_bad_features(VirtIODevice *vdev)/* Linux kernel 2.6.25. It understood MAC (as everyone must), * but also these: */ - features |= (1 <<VIRTIO_NET_F_MAC ); - features |= (1 <<VIRTIO_NET_F_CSUM ); - features |= (1 <<VIRTIO_NET_F_HOST_TSO4 ); - features |= (1 <<VIRTIO_NET_F_HOST_TSO6 ); - features |= (1 <<VIRTIO_NET_F_HOST_ECN ); +virtio_add_feature (&features,VIRTIO_NET_F_MAC ); +virtio_add_feature (&features,VIRTIO_NET_F_CSUM ); +virtio_add_feature (&features,VIRTIO_NET_F_HOST_TSO4 ); +virtio_add_feature (&features,VIRTIO_NET_F_HOST_TSO6 ); +virtio_add_feature (&features,VIRTIO_NET_F_HOST_ECN );return features; }
@@ -1560,7 +1560,7 @@ static void virtio_net_guest_notifier_mask(VirtIODevice *vdev, int idx,void virtio_net_set_config_size (VirtIONet *n,uint32_t host_features) {int i, config_size =0 ; - host_features |= (1 <<VIRTIO_NET_F_MAC ); +virtio_add_feature (&host_features,VIRTIO_NET_F_MAC );for (i =0 ; feature_sizes[i].flags !=0 ; i++) {if (host_features & feature_sizes[i].flags) { config_size =MAX (feature_sizes[i].end, config_size);
hw/s390x/virtio-ccw.c +2 -2
@@ -743,8 +743,8 @@ static int virtio_ccw_device_init(VirtioCcwDevice *dev, VirtIODevice *vdev) dev->host_features[0 ] =virtio_bus_get_vdev_features (&dev->bus, dev->host_features[0 ]); - dev->host_features[0 ] |=0x1 <<VIRTIO_F_NOTIFY_ON_EMPTY ; - dev->host_features[0 ] |=0x1 <<VIRTIO_F_BAD_FEATURE ; +virtio_add_feature (&dev->host_features[0 ],VIRTIO_F_NOTIFY_ON_EMPTY ); +virtio_add_feature (&dev->host_features[0 ],VIRTIO_F_BAD_FEATURE );css_generate_sch_crws (sch->cssid, sch->ssid, sch->schid, parent->hotplugged,1 );
hw/virtio/virtio-mmio.c +1 -1
@@ -349,7 +349,7 @@ static void virtio_mmio_device_plugged(DeviceState *opaque) {VirtIOMMIOProxy *proxy =VIRTIO_MMIO (opaque); - proxy->host_features |= (0x1 <<VIRTIO_F_NOTIFY_ON_EMPTY ); +virtio_add_feature (&proxy->host_features,VIRTIO_F_NOTIFY_ON_EMPTY ); proxy->host_features =virtio_bus_get_vdev_features (&proxy->bus, proxy->host_features); }
hw/virtio/virtio-pci.c +2 -2
@@ -996,8 +996,8 @@ static void virtio_pci_device_plugged(DeviceState *d) proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD ; } - proxy->host_features |=0x1 <<VIRTIO_F_NOTIFY_ON_EMPTY ; - proxy->host_features |=0x1 <<VIRTIO_F_BAD_FEATURE ; +virtio_add_feature (&proxy->host_features,VIRTIO_F_NOTIFY_ON_EMPTY ); +virtio_add_feature (&proxy->host_features,VIRTIO_F_BAD_FEATURE ); proxy->host_features =virtio_bus_get_vdev_features (bus, proxy->host_features); }
include/hw/virtio/virtio.h +12 -0
@@ -266,6 +266,18 @@ void virtio_queue_set_host_notifier_fd_handler(VirtQueue *vq, bool assign,void virtio_queue_notify_vq (VirtQueue *vq);void virtio_irq (VirtQueue *vq); +static inline void virtio_add_feature (uint32_t *features,unsigned int fbit) +{ +assert (fbit <32 ); + *features |= (1 << fbit); +} + +static inline void virtio_clear_feature (uint32_t *features,unsigned int fbit) +{ +assert (fbit <32 ); + *features &= ~(1 << fbit); +} +static inline bool virtio_is_big_endian (VirtIODevice *vdev) {assert (vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_UNKNOWN );
Signature · 1 line
1.7.9.5
RFC PATCH v6 4/20 virtio: add feature checking helpers
In reply to Cornelia HuckAdd a helper function for checking whether a bit is set in the guest features for a vdev as well as one that works on a feature bit set.
Convert code that open-coded this: It cleans up the code and makes it easier to extend the guest feature bits.
--- hw/block/virtio-blk.c | 7 ++----- hw/char/virtio-serial-bus.c | 2 +- hw/net/virtio-net.c | 23 +++++++++++++---------- hw/scsi/virtio-scsi.c | 8 ++++---- hw/virtio/dataplane/vring.c | 10 +++++----- hw/virtio/virtio-balloon.c | 2 +- hw/virtio/virtio.c | 10 +++++----- include/hw/virtio/virtio.h | 11 +++++++++++ 8 files changed, 42 insertions(+), 31 deletions(-)
hw/block/virtio-blk.c +2 -5
@@ -590,7 +590,6 @@ static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features)static void virtio_blk_set_status (VirtIODevice *vdev,uint8_t status) {VirtIOBlock *s =VIRTIO_BLK (vdev); -uint32_t features;if (s->dataplane && !(status & (VIRTIO_CONFIG_S_DRIVER |VIRTIO_CONFIG_S_DRIVER_OK ))) {
@@ -601,8 +600,6 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)return ; } - features = vdev->guest_features; -/* A guest that supports VIRTIO_BLK_F_CONFIG_WCE must be able to send * cache flushes. Thus, the "auto writethrough" behavior is never * necessary for guests that support the VIRTIO_BLK_F_CONFIG_WCE feature.
@@ -618,10 +615,10 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)* * s->blk would erroneously be placed in writethrough mode. */ -if (!(features & (1 <<VIRTIO_BLK_F_CONFIG_WCE ))) { +if (!virtio_has_feature (vdev,VIRTIO_BLK_F_CONFIG_WCE )) {aio_context_acquire (blk_get_aio_context (s->blk));blk_set_enable_write_cache (s->blk, - !!(features & (1 <<VIRTIO_BLK_F_WCE ))); +virtio_has_feature (vdev,VIRTIO_BLK_F_WCE ));aio_context_release (blk_get_aio_context (s->blk)); } }
hw/char/virtio-serial-bus.c +1 -1
@@ -75,7 +75,7 @@ static VirtIOSerialPort *find_port_by_name(char *name)static bool use_multiport (VirtIOSerial *vser) {VirtIODevice *vdev =VIRTIO_DEVICE (vser); -return vdev->guest_features & (1 <<VIRTIO_CONSOLE_F_MULTIPORT ); +return virtio_has_feature (vdev,VIRTIO_CONSOLE_F_MULTIPORT ); } static size_t write_to_port(VirtIOSerialPort *port,
hw/net/virtio-net.c +13 -10
@@ -86,7 +86,7 @@ static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)memcpy (&netcfg, config, n->config_size); -if (!(vdev->guest_features >>VIRTIO_NET_F_CTRL_MAC_ADDR &1 ) && +if (!virtio_has_feature (vdev,VIRTIO_NET_F_CTRL_MAC_ADDR ) &&memcmp (netcfg.mac, n->mac,ETH_ALEN )) {memcpy (n->mac, netcfg.mac,ETH_ALEN );qemu_format_nic_info_str (qemu_get_queue (n->nic), n->mac);
@@ -305,7 +305,7 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc) info->multicast_table = str_list; info->vlan_table =get_vlan_table (n); -if (!((1 <<VIRTIO_NET_F_CTRL_VLAN ) & vdev->guest_features)) { +if (!virtio_has_feature (vdev,VIRTIO_NET_F_CTRL_VLAN )) { info->vlan =RX_STATE_ALL ; }else if (!info->vlan_table) { info->vlan =RX_STATE_NONE ;
@@ -519,9 +519,12 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)VirtIONet *n =VIRTIO_NET (vdev);int i; -virtio_net_set_multiqueue (n, !!(features & (1 <<VIRTIO_NET_F_MQ ))); +virtio_net_set_multiqueue (n, +__virtio_has_feature (features,VIRTIO_NET_F_MQ )); -virtio_net_set_mrg_rx_bufs (n, !!(features & (1 <<VIRTIO_NET_F_MRG_RXBUF ))); +virtio_net_set_mrg_rx_bufs (n, +__virtio_has_feature (features, +VIRTIO_NET_F_MRG_RXBUF ));if (n->has_vnet_hdr) { n->curr_guest_offloads =
@@ -538,7 +541,7 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)vhost_net_ack_features (get_vhost_net (nc->peer), features); } -if ((1 <<VIRTIO_NET_F_CTRL_VLAN ) & features) { +if (__virtio_has_feature (features,VIRTIO_NET_F_CTRL_VLAN )) {memset (n->vlans,0 ,MAX_VLAN >>3 ); }else {memset (n->vlans,0xff ,MAX_VLAN >>3 );
@@ -585,7 +588,7 @@ static int virtio_net_handle_offloads(VirtIONet *n, uint8_t cmd,uint64_t offloads;size_t s; -if (!((1 <<VIRTIO_NET_F_CTRL_GUEST_OFFLOADS ) & vdev->guest_features)) { +if (!virtio_has_feature (vdev,VIRTIO_NET_F_CTRL_GUEST_OFFLOADS )) {return VIRTIO_NET_ERR ; }
@@ -1378,7 +1381,7 @@ static void virtio_net_save_device(VirtIODevice *vdev, QEMUFile *f) } } -if ((1 <<VIRTIO_NET_F_CTRL_GUEST_OFFLOADS ) & vdev->guest_features) { +if (virtio_has_feature (vdev,VIRTIO_NET_F_CTRL_GUEST_OFFLOADS )) {qemu_put_be64 (f, n->curr_guest_offloads); } }
@@ -1486,7 +1489,7 @@ static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f, } } -if ((1 <<VIRTIO_NET_F_CTRL_GUEST_OFFLOADS ) & vdev->guest_features) { +if (virtio_has_feature (vdev,VIRTIO_NET_F_CTRL_GUEST_OFFLOADS )) { n->curr_guest_offloads =qemu_get_be64 (f); }else { n->curr_guest_offloads =virtio_net_supported_guest_offloads (n);
@@ -1513,8 +1516,8 @@ static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f,qemu_get_subqueue (n->nic, i)->link_down = link_down; } -if (vdev->guest_features & (0x1 <<VIRTIO_NET_F_GUEST_ANNOUNCE ) && - vdev->guest_features & (0x1 <<VIRTIO_NET_F_CTRL_VQ )) { +if (virtio_has_feature (vdev,VIRTIO_NET_F_GUEST_ANNOUNCE ) && +virtio_has_feature (vdev,VIRTIO_NET_F_CTRL_VQ )) { n->announce_counter =SELF_ANNOUNCE_ROUNDS ;timer_mod (n->announce_timer,qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL )); }
hw/scsi/virtio-scsi.c +4 -4
@@ -144,7 +144,7 @@ static int virtio_scsi_parse_req(VirtIOSCSIReq *req,* * TODO: always disable this workaround for virtio 1.0 devices. */ -if ((vdev->guest_features &VIRTIO_F_ANY_LAYOUT ) ==0 ) { +if (!virtio_has_feature (vdev,VIRTIO_F_ANY_LAYOUT )) { req_size = req->elem.out_sg[0 ].iov_len; resp_size = req->elem.in_sg[0 ].iov_len; }
@@ -748,7 +748,7 @@ static void virtio_scsi_change(SCSIBus *bus, SCSIDevice *dev, SCSISense sense)VirtIOSCSI *s =container_of (bus, VirtIOSCSI, bus);VirtIODevice *vdev =VIRTIO_DEVICE (s); -if (((vdev->guest_features >>VIRTIO_SCSI_F_CHANGE ) &1 ) && +if (virtio_has_feature (vdev,VIRTIO_SCSI_F_CHANGE ) && dev->type !=TYPE_ROM ) {virtio_scsi_push_event (s, dev,VIRTIO_SCSI_T_PARAM_CHANGE , sense.asc | (sense.ascq <<8 ));
@@ -769,7 +769,7 @@ static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev,blk_op_block_all (sd->conf.blk, s->blocker); } -if ((vdev->guest_features >>VIRTIO_SCSI_F_HOTPLUG ) &1 ) { +if (virtio_has_feature (vdev,VIRTIO_SCSI_F_HOTPLUG )) {virtio_scsi_push_event (s, sd,VIRTIO_SCSI_T_TRANSPORT_RESET ,VIRTIO_SCSI_EVT_RESET_RESCAN );
@@ -783,7 +783,7 @@ static void virtio_scsi_hotunplug(HotplugHandler *hotplug_dev, DeviceState *dev,VirtIOSCSI *s =VIRTIO_SCSI (vdev);SCSIDevice *sd =SCSI_DEVICE (dev); -if ((vdev->guest_features >>VIRTIO_SCSI_F_HOTPLUG ) &1 ) { +if (virtio_has_feature (vdev,VIRTIO_SCSI_F_HOTPLUG )) {virtio_scsi_push_event (s, sd,VIRTIO_SCSI_T_TRANSPORT_RESET ,VIRTIO_SCSI_EVT_RESET_REMOVED );
hw/virtio/dataplane/vring.c +5 -5
@@ -103,7 +103,7 @@ void vring_teardown(Vring *vring, VirtIODevice *vdev, int n)/* Disable guest->host notifies */ void vring_disable_notification (VirtIODevice *vdev,Vring *vring) { -if (!(vdev->guest_features & (1 <<VIRTIO_RING_F_EVENT_IDX ))) { +if (!virtio_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX )) { vring->vr.used->flags |=VRING_USED_F_NO_NOTIFY ; } }
@@ -114,7 +114,7 @@ void vring_disable_notification(VirtIODevice *vdev, Vring *vring)*/ bool vring_enable_notification (VirtIODevice *vdev,Vring *vring) { -if (vdev->guest_features & (1 <<VIRTIO_RING_F_EVENT_IDX )) { +if (virtio_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX )) {vring_avail_event (&vring->vr) = vring->vr.avail->idx; }else { vring->vr.used->flags &= ~VRING_USED_F_NO_NOTIFY ;
@@ -133,12 +133,12 @@ bool vring_should_notify(VirtIODevice *vdev, Vring *vring)* interrupts. */ smp_mb (); -if ((vdev->guest_features &VIRTIO_F_NOTIFY_ON_EMPTY ) && +if (virtio_has_feature (vdev,VIRTIO_F_NOTIFY_ON_EMPTY ) &&unlikely (vring->vr.avail->idx == vring->last_avail_idx)) {return true; } -if (!(vdev->guest_features &VIRTIO_RING_F_EVENT_IDX )) { +if (!virtio_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX )) {return !(vring->vr.avail->flags &VRING_AVAIL_F_NO_INTERRUPT ); } old = vring->signalled_used;
@@ -388,7 +388,7 @@ int vring_pop(VirtIODevice *vdev, Vring *vring,/* On success, increment avail index. */ vring->last_avail_idx++; -if (vdev->guest_features & (1 <<VIRTIO_RING_F_EVENT_IDX )) { +if (virtio_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX )) {vring_avail_event (&vring->vr) = vring->last_avail_idx; }
hw/virtio/virtio-balloon.c +1 -1
@@ -69,7 +69,7 @@ static inline void reset_stats(VirtIOBalloon *dev)static bool balloon_stats_supported (const VirtIOBalloon *s) {VirtIODevice *vdev =VIRTIO_DEVICE (s); -return vdev->guest_features & (1 <<VIRTIO_BALLOON_F_STATS_VQ ); +return virtio_has_feature (vdev,VIRTIO_BALLOON_F_STATS_VQ ); }static bool balloon_stats_enabled (const VirtIOBalloon *s)
hw/virtio/virtio.c +5 -5
@@ -217,7 +217,7 @@ static inline void vring_avail_event(VirtQueue *vq, uint16_t val)void virtio_queue_set_notification (VirtQueue *vq,int enable) { vq->notification = enable; -if (vq->vdev->guest_features & (1 <<VIRTIO_RING_F_EVENT_IDX )) { +if (virtio_has_feature (vq->vdev,VIRTIO_RING_F_EVENT_IDX )) {vring_avail_event (vq,vring_avail_idx (vq)); }else if (enable) {vring_used_flags_unset_bit (vq,VRING_USED_F_NO_NOTIFY );
@@ -468,7 +468,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem) max = vq->vring.num; i = head =virtqueue_get_head (vq, vq->last_avail_idx++); -if (vdev->guest_features & (1 <<VIRTIO_RING_F_EVENT_IDX )) { +if (virtio_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX )) {vring_avail_event (vq, vq->last_avail_idx); }
@@ -839,12 +839,12 @@ static bool vring_notify(VirtIODevice *vdev, VirtQueue *vq)/* We need to expose used array entries before checking used event. */ smp_mb ();/* Always notify when queue is empty (when feature acknowledge) */ -if (((vdev->guest_features & (1 <<VIRTIO_F_NOTIFY_ON_EMPTY )) && - !vq->inuse &&vring_avail_idx (vq) == vq->last_avail_idx)) { +if (virtio_has_feature (vdev,VIRTIO_F_NOTIFY_ON_EMPTY ) && + !vq->inuse &&vring_avail_idx (vq) == vq->last_avail_idx) {return true; } -if (!(vdev->guest_features & (1 <<VIRTIO_RING_F_EVENT_IDX ))) { +if (!virtio_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX )) {return !(vring_avail_flags (vq) &VRING_AVAIL_F_NO_INTERRUPT ); }
include/hw/virtio/virtio.h +11 -0
@@ -278,6 +278,17 @@ static inline void virtio_clear_feature(uint32_t *features, unsigned int fbit) *features &= ~(1 << fbit); } +static inline bool __virtio_has_feature (uint32_t features,unsigned int fbit) +{ +assert (fbit <32 ); +return !!(features & (1 << fbit)); +} + +static inline bool virtio_has_feature (VirtIODevice *vdev,unsigned int fbit) +{ +return __virtio_has_feature (vdev->guest_features, fbit); +} +static inline bool virtio_is_big_endian (VirtIODevice *vdev) {assert (vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_UNKNOWN );
Signature · 1 line
1.7.9.5
RFC PATCH v6 5/20 virtio: support more feature bits
In reply to Cornelia HuckWith virtio-1, we support more than 32 feature bits. Let's extend both host and guest features to 64, which should suffice for a while.
vhost and migration have been ignored for now.
--- hw/9pfs/virtio-9p-device.c | 2 +- hw/block/virtio-blk.c | 2 +- hw/char/virtio-serial-bus.c | 2 +- hw/core/qdev-properties.c | 58 +++++++++++++++++++++++++++++++++++++++ hw/net/virtio-net.c | 22 +++++++-------- hw/s390x/s390-virtio-bus.c | 3 +- hw/s390x/s390-virtio-bus.h | 2 +- hw/s390x/virtio-ccw.c | 39 +++++++++++++++----------- hw/s390x/virtio-ccw.h | 5 +--- hw/scsi/vhost-scsi.c | 3 +- hw/scsi/virtio-scsi.c | 4 +-- hw/virtio/virtio-balloon.c | 2 +- hw/virtio/virtio-bus.c | 6 ++-- hw/virtio/virtio-mmio.c | 4 +-- hw/virtio/virtio-pci.c | 3 +- hw/virtio/virtio-pci.h | 2 +- hw/virtio/virtio-rng.c | 2 +- hw/virtio/virtio.c | 13 +++++---- include/hw/qdev-properties.h | 12 ++++++++ include/hw/virtio/virtio-bus.h | 8 +++--- include/hw/virtio/virtio-net.h | 46 +++++++++++++++---------------- include/hw/virtio/virtio-scsi.h | 6 ++-- include/hw/virtio/virtio.h | 38 ++++++++++++++----------- 23 files changed, 184 insertions(+), 100 deletions(-)
hw/9pfs/virtio-9p-device.c +1 -1
@@ -21,7 +21,7 @@#include "virtio-9p-coth.h" #include "hw/virtio/virtio-access.h" -static uint32_t virtio_9p_get_features (VirtIODevice *vdev,uint32_t features) +static uint64_t virtio_9p_get_features (VirtIODevice *vdev,uint64_t features) {virtio_add_feature (&features,VIRTIO_9P_MOUNT_TAG );return features;
hw/block/virtio-blk.c +1 -1
@@ -564,7 +564,7 @@ static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config)aio_context_release (blk_get_aio_context (s->blk)); } -static uint32_t virtio_blk_get_features (VirtIODevice *vdev,uint32_t features) +static uint64_t virtio_blk_get_features (VirtIODevice *vdev,uint64_t features) {VirtIOBlock *s =VIRTIO_BLK (vdev);
hw/char/virtio-serial-bus.c +1 -1
@@ -467,7 +467,7 @@ static void handle_input(VirtIODevice *vdev, VirtQueue *vq) { } -static uint32_t get_features (VirtIODevice *vdev,uint32_t features) +static uint64_t get_features (VirtIODevice *vdev,uint64_t features) {VirtIOSerial *vser;
hw/core/qdev-properties.c +58 -0
64 lines not on this page · raw message
hw/net/virtio-net.c +11 -11
@@ -38,16 +38,16 @@ (offsetof(container, field) + sizeof(((container *)0)->field))typedef struct VirtIOFeature { -uint32_t flags; +uint64_t flags;size_t end; }VirtIOFeature ;static VirtIOFeature feature_sizes[] = { - {.flags =1 <<VIRTIO_NET_F_MAC , + {.flags =1ULL <<VIRTIO_NET_F_MAC , .end = endof(struct virtio_net_config, mac)}, - {.flags =1 <<VIRTIO_NET_F_STATUS , + {.flags =1ULL <<VIRTIO_NET_F_STATUS , .end = endof(struct virtio_net_config, status)}, - {.flags =1 <<VIRTIO_NET_F_MQ , + {.flags =1ULL <<VIRTIO_NET_F_MQ , .end = endof(struct virtio_net_config, max_virtqueue_pairs)}, {} };
@@ -441,7 +441,7 @@ static void virtio_net_set_queues(VirtIONet *n)static void virtio_net_set_multiqueue (VirtIONet *n,int multiqueue); -static uint32_t virtio_net_get_features (VirtIODevice *vdev,uint32_t features) +static uint64_t virtio_net_get_features (VirtIODevice *vdev,uint64_t features) {VirtIONet *n =VIRTIO_NET (vdev);NetClientState *nc =qemu_get_queue (n->nic);
@@ -471,9 +471,9 @@ static uint32_t virtio_net_get_features(VirtIODevice *vdev, uint32_t features)return vhost_net_get_features (get_vhost_net (nc->peer), features); } -static uint32_t virtio_net_bad_features (VirtIODevice *vdev) +static uint64_t virtio_net_bad_features (VirtIODevice *vdev) { -uint32_t features =0 ; +uint64_t features =0 ;/* Linux kernel 2.6.25. It understood MAC (as everyone must), * but also these: */
@@ -496,7 +496,7 @@ static void virtio_net_apply_guest_offloads(VirtIONet *n) !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_UFO))); } -static uint64_t virtio_net_guest_offloads_by_features (uint32_t features) +static uint64_t virtio_net_guest_offloads_by_features (uint64_t features) {static const uint64_t guest_offloads_mask = (1ULL << VIRTIO_NET_F_GUEST_CSUM) |
@@ -514,7 +514,7 @@ static inline uint64_t virtio_net_supported_guest_offloads(VirtIONet *n)return virtio_net_guest_offloads_by_features (vdev->guest_features); } -static void virtio_net_set_features (VirtIODevice *vdev,uint32_t features) +static void virtio_net_set_features (VirtIODevice *vdev,uint64_t features) {VirtIONet *n =VIRTIO_NET (vdev);int i;
@@ -1036,7 +1036,7 @@ static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf, size_treturn -1 ;error_report ("virtio-net unexpected empty queue: " "i %zd mergeable %d offset %zd, size %zd, " -"guest hdr len %zd, host hdr len %zd guest features 0x%x" , +"guest hdr len %zd, host hdr len %zd guest features 0x%lx" , i, n->mergeable_rx_bufs, offset, size, n->guest_hdr_len, n->host_hdr_len, vdev->guest_features);exit (1 );
@@ -1560,7 +1560,7 @@ static void virtio_net_guest_notifier_mask(VirtIODevice *vdev, int idx, vdev, idx, mask); } -void virtio_net_set_config_size (VirtIONet *n,uint32_t host_features) +void virtio_net_set_config_size (VirtIONet *n,uint64_t host_features) {int i, config_size =0 ;virtio_add_feature (&host_features,VIRTIO_NET_F_MAC );
hw/s390x/s390-virtio-bus.c +2 -1
@@ -490,9 +490,10 @@ static void virtio_s390_notify(DeviceState *d, uint16_t vector)s390_virtio_irq (0 , token); } -static unsigned virtio_s390_get_features (DeviceState *d) +static uint64_t virtio_s390_get_features (DeviceState *d) {VirtIOS390Device *dev =to_virtio_s390_device (d); +return dev->host_features; }
hw/s390x/s390-virtio-bus.h +1 -1
@@ -90,7 +90,7 @@ struct VirtIOS390Device {ram_addr_t feat_offs;uint8_t feat_len;VirtIODevice *vdev; -uint32_t host_features; +uint64_t host_features;VirtioBusState bus; };
hw/s390x/virtio-ccw.c +23 -16
@@ -371,8 +371,10 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) }else { features.index =ldub_phys (&address_space_memory, ccw.cda +sizeof (features.features)); -if (features.index <ARRAY_SIZE (dev->host_features)) { - features.features = dev->host_features[features.index]; +if (features.index ==0 ) { + features.features = (uint32_t )dev->host_features; + }else if (features.index ==1 ) { + features.features = (uint32_t )(dev->host_features >>32 ); }else {/* Return zeroes if the guest supports more feature bits. */ features.features =0 ;
@@ -399,8 +401,14 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) features.index =ldub_phys (&address_space_memory, ccw.cda +sizeof (features.features)); features.features =ldl_le_phys (&address_space_memory, ccw.cda); -if (features.index <ARRAY_SIZE (dev->host_features)) { -virtio_set_features (vdev, features.features); +if (features.index ==0 ) { +virtio_set_features (vdev, + (vdev->guest_features &0xffffffff00000000 ) | + features.features); + }else if (features.index ==1 ) { +virtio_set_features (vdev, + (vdev->guest_features &0x00000000ffffffff ) | + ((uint64_t )features.features <<32 )); }else {/* * If the guest supports more feature bits, assert that it
@@ -739,12 +747,12 @@ static int virtio_ccw_device_init(VirtioCcwDevice *dev, VirtIODevice *vdev) sch->id.cu_type =VIRTIO_CCW_CU_TYPE ; sch->id.cu_model = vdev->device_id; -/* Only the first 32 feature bits are used. */ - dev->host_features[0 ] =virtio_bus_get_vdev_features (&dev->bus, - dev->host_features[0 ]); +/* Set default feature bits that are offered by the host. */ +virtio_add_feature (&dev->host_features,VIRTIO_F_NOTIFY_ON_EMPTY ); +virtio_add_feature (&dev->host_features,VIRTIO_F_BAD_FEATURE ); -virtio_add_feature (&dev->host_features[0 ],VIRTIO_F_NOTIFY_ON_EMPTY ); -virtio_add_feature (&dev->host_features[0 ],VIRTIO_F_BAD_FEATURE ); + dev->host_features =virtio_bus_get_vdev_features (&dev->bus, + dev->host_features);css_generate_sch_crws (sch->cssid, sch->ssid, sch->schid, parent->hotplugged,1 );
@@ -777,7 +785,7 @@ static int virtio_ccw_net_init(VirtioCcwDevice *ccw_dev)VirtIONetCcw *dev =VIRTIO_NET_CCW (ccw_dev);DeviceState *vdev =DEVICE (&dev->vdev); -virtio_net_set_config_size (&dev->vdev, ccw_dev->host_features[0 ]); +virtio_net_set_config_size (&dev->vdev, ccw_dev->host_features);virtio_net_set_netclient_name (&dev->vdev, qdev->id,object_get_typename (OBJECT (qdev)));qdev_set_parent_bus (vdev,BUS (&ccw_dev->bus));
@@ -1063,12 +1071,11 @@ static void virtio_ccw_notify(DeviceState *d, uint16_t vector) } } -static unsigned virtio_ccw_get_features (DeviceState *d) +static uint64_t virtio_ccw_get_features (DeviceState *d) {VirtioCcwDevice *dev =VIRTIO_CCW_DEVICE (d); -/* Only the first 32 feature bits are used. */ -return dev->host_features[0 ]; +return dev->host_features; }static void virtio_ccw_reset (DeviceState *d)
@@ -1381,7 +1388,7 @@ static int virtio_ccw_load_config(DeviceState *d, QEMUFile *f)static Property virtio_ccw_net_properties[] = {DEFINE_PROP_STRING ("devno" , VirtioCcwDevice, bus_id), -DEFINE_VIRTIO_NET_FEATURES (VirtioCcwDevice, host_features[0 ]), +DEFINE_VIRTIO_NET_FEATURES (VirtioCcwDevice, host_features),DEFINE_PROP_BIT ("ioeventfd" , VirtioCcwDevice, flags,VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT , true),DEFINE_PROP_END_OF_LIST (),
@@ -1486,7 +1493,7 @@ static const TypeInfo virtio_ccw_balloon = {static Property virtio_ccw_scsi_properties[] = {DEFINE_PROP_STRING ("devno" , VirtioCcwDevice, bus_id), -DEFINE_VIRTIO_SCSI_FEATURES (VirtioCcwDevice, host_features[0 ]), +DEFINE_VIRTIO_SCSI_FEATURES (VirtioCcwDevice, host_features),DEFINE_PROP_BIT ("ioeventfd" , VirtioCcwDevice, flags,VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT , true),DEFINE_PROP_END_OF_LIST (),
@@ -1614,7 +1621,7 @@ static void virtio_ccw_busdev_unplug(HotplugHandler *hotplug_dev, }static Property virtio_ccw_properties[] = { -DEFINE_VIRTIO_COMMON_FEATURES (VirtioCcwDevice, host_features[0 ]), +DEFINE_VIRTIO_COMMON_FEATURES (VirtioCcwDevice, host_features),DEFINE_PROP_END_OF_LIST (), };
hw/s390x/virtio-ccw.h +1 -4
@@ -68,9 +68,6 @@ typedef struct VirtIOCCWDeviceClass {int (*exit)(VirtioCcwDevice *dev); } VirtIOCCWDeviceClass; -/* Change here if we want to support more feature bits. */ -#define VIRTIO_CCW_FEATURE_SIZE 1 -/* Performance improves when virtqueue kick processing is decoupled from the * vcpu thread using ioeventfd for some devices. */ #define VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT 1
@@ -88,7 +85,7 @@ struct VirtioCcwDevice {DeviceState parent_obj;SubchDev *sch;char *bus_id; -uint32_t host_features[VIRTIO_CCW_FEATURE_SIZE ]; +uint64_t host_features;VirtioBusState bus;bool ioeventfd_started;bool ioeventfd_disabled;
hw/scsi/vhost-scsi.c +1 -2
@@ -150,8 +150,7 @@ static void vhost_scsi_stop(VHostSCSI *s)vhost_dev_disable_notifiers (&s->dev, vdev); } -static uint32_t vhost_scsi_get_features (VirtIODevice *vdev, -uint32_t features) +static uint64_t vhost_scsi_get_features (VirtIODevice *vdev,uint64_t features) {VHostSCSI *s =VHOST_SCSI (vdev);
hw/scsi/virtio-scsi.c +2 -2
@@ -627,8 +627,8 @@ static void virtio_scsi_set_config(VirtIODevice *vdev, vs->cdb_size =virtio_ldl_p (vdev, &scsiconf->cdb_size); } -static uint32_t virtio_scsi_get_features (VirtIODevice *vdev, -uint32_t requested_features) +static uint64_t virtio_scsi_get_features (VirtIODevice *vdev, +uint64_t requested_features) {return requested_features; }
hw/virtio/virtio-balloon.c +1 -1
@@ -303,7 +303,7 @@ static void virtio_balloon_set_config(VirtIODevice *vdev, } } -static uint32_t virtio_balloon_get_features (VirtIODevice *vdev,uint32_t f) +static uint64_t virtio_balloon_get_features (VirtIODevice *vdev,uint64_t f) { f |= (1 <<VIRTIO_BALLOON_F_STATS_VQ );return f;
hw/virtio/virtio-bus.c +3 -3
@@ -97,8 +97,8 @@ size_t virtio_bus_get_vdev_config_len(VirtioBusState *bus) }/* Get the features of the plugged device. */ -uint32_t virtio_bus_get_vdev_features (VirtioBusState *bus, -uint32_t requested_features) +uint64_t virtio_bus_get_vdev_features (VirtioBusState *bus, +uint64_t requested_features) {VirtIODevice *vdev =virtio_bus_get_device (bus);VirtioDeviceClass *k;
@@ -110,7 +110,7 @@ uint32_t virtio_bus_get_vdev_features(VirtioBusState *bus, }/* Get bad features of the plugged device. */ -uint32_t virtio_bus_get_vdev_bad_features (VirtioBusState *bus) +uint64_t virtio_bus_get_vdev_bad_features (VirtioBusState *bus) {VirtIODevice *vdev =virtio_bus_get_device (bus);VirtioDeviceClass *k;
hw/virtio/virtio-mmio.c +2 -2
@@ -80,7 +80,7 @@ typedef struct {SysBusDevice parent_obj;MemoryRegion iomem;qemu_irq irq; -uint32_t host_features; +uint64_t host_features;/* Guest accessible state needing migration and reset */ uint32_t host_features_sel;uint32_t guest_features_sel;
@@ -306,7 +306,7 @@ static void virtio_mmio_update_irq(DeviceState *opaque, uint16_t vector)qemu_set_irq (proxy->irq, level); } -static unsigned int virtio_mmio_get_features (DeviceState *opaque) +static uint64_t virtio_mmio_get_features (DeviceState *opaque) {VirtIOMMIOProxy *proxy =VIRTIO_MMIO (opaque);
hw/virtio/virtio-pci.c +2 -1
@@ -478,9 +478,10 @@ static void virtio_write_config(PCIDevice *pci_dev, uint32_t address, } } -static unsigned virtio_pci_get_features (DeviceState *d) +static uint64_t virtio_pci_get_features (DeviceState *d) {VirtIOPCIProxy *proxy =to_virtio_pci_proxy (d); +return proxy->host_features; }
hw/virtio/virtio-pci.h +1 -1
@@ -91,7 +91,7 @@ struct VirtIOPCIProxy {uint32_t flags;uint32_t class_code;uint32_t nvectors; -uint32_t host_features; +uint64_t host_features;bool ioeventfd_disabled;bool ioeventfd_started;VirtIOIRQFD *vector_irqfd;
hw/virtio/virtio-rng.c +1 -1
@@ -99,7 +99,7 @@ static void handle_input(VirtIODevice *vdev, VirtQueue *vq)virtio_rng_process (vrng); } -static uint32_t get_features (VirtIODevice *vdev,uint32_t f) +static uint64_t get_features (VirtIODevice *vdev,uint64_t f) {return f; }
hw/virtio/virtio.c +8 -5
@@ -593,6 +593,7 @@ void virtio_reset(void *opaque) } vdev->guest_features =0 ; + vdev->queue_sel =0 ; vdev->status =0 ; vdev->isr =0 ;
@@ -924,7 +925,8 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)qemu_put_8s (f, &vdev->status);qemu_put_8s (f, &vdev->isr);qemu_put_be16s (f, &vdev->queue_sel); -qemu_put_be32s (f, &vdev->guest_features); +/* XXX features >= 32 */ +qemu_put_be32s (f, (uint32_t *)&vdev->guest_features);qemu_put_be32 (f, vdev->config_len);qemu_put_buffer (f, vdev->config, vdev->config_len);
@@ -958,12 +960,12 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)vmstate_save_state (f, &vmstate_virtio, vdev); } -int virtio_set_features (VirtIODevice *vdev,uint32_t val) +int virtio_set_features (VirtIODevice *vdev,uint64_t val) {BusState *qbus =qdev_get_parent_bus (DEVICE (vdev));VirtioBusClass *vbusk =VIRTIO_BUS_GET_CLASS (qbus);VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (vdev); -uint32_t supported_features = vbusk->get_features (qbus->parent); +uint64_t supported_features = vbusk->get_features (qbus->parent);bool bad = (val & ~supported_features) !=0 ; val &= supported_features;
@@ -980,7 +982,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)int32_t config_len;uint32_t num;uint32_t features; -uint32_t supported_features; +uint64_t supported_features;BusState *qbus =qdev_get_parent_bus (DEVICE (vdev));VirtioBusClass *k =VIRTIO_BUS_GET_CLASS (qbus);VirtioDeviceClass *vdc =VIRTIO_DEVICE_GET_CLASS (vdev);
@@ -1005,9 +1007,10 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) }qemu_get_be32s (f, &features); +/* XXX features >= 32 */ if (virtio_set_features (vdev, features) <0 ) { supported_features = k->get_features (qbus->parent); -error_report ("Features 0x%x unsupported. Allowed features: 0x%x" , +error_report ("Features 0x%x unsupported. Allowed features: 0x%lx" , features, supported_features);return -1 ; }
include/hw/qdev-properties.h +12 -0
@@ -6,6 +6,7 @@/*** qdev-properties.c ***/ extern PropertyInfo qdev_prop_bit; +extern PropertyInfo qdev_prop_bit64;extern PropertyInfo qdev_prop_bool;extern PropertyInfo qdev_prop_uint8;extern PropertyInfo qdev_prop_uint16;
@@ -51,6 +52,17 @@ extern PropertyInfo qdev_prop_arraylen; .defval = (bool)_defval, \ } +#define DEFINE_PROP_BIT64 (_name, _state, _field, _bit, _defval) { \ + .name = (_name), \ + .info = &(qdev_prop_bit64), \ + .bitnr = (_bit), \ + .offset = offsetof(_state, _field) \ + + type_check(uint64_t,typeof_field(_state, _field)), \ + .qtype = QTYPE_QBOOL, \ + .defval = (bool)_defval, \ + } + +#define DEFINE_PROP_BOOL (_name, _state, _field, _defval) { \ .name = (_name), \ .info = &(qdev_prop_bool), \
include/hw/virtio/virtio-bus.h +4 -4
@@ -47,7 +47,7 @@ typedef struct VirtioBusClass {int (*load_config)(DeviceState *d,QEMUFile *f);int (*load_queue)(DeviceState *d,int n,QEMUFile *f);int (*load_done)(DeviceState *d,QEMUFile *f); -unsigned (*get_features)(DeviceState *d); +uint64_t (*get_features)(DeviceState *d);bool (*query_guest_notifiers)(DeviceState *d);int (*set_guest_notifiers)(DeviceState *d,int nvqs,bool assign);int (*set_host_notifier)(DeviceState *d,int n,bool assigned);
@@ -82,10 +82,10 @@ uint16_t virtio_bus_get_vdev_id(VirtioBusState *bus);/* Get the config_len field of the plugged device. */ size_t virtio_bus_get_vdev_config_len (VirtioBusState *bus);/* Get the features of the plugged device. */ -uint32_t virtio_bus_get_vdev_features (VirtioBusState *bus, -uint32_t requested_features); +uint64_t virtio_bus_get_vdev_features (VirtioBusState *bus, +uint64_t requested_features);/* Get bad features of the plugged device. */ -uint32_t virtio_bus_get_vdev_bad_features (VirtioBusState *bus); +uint64_t virtio_bus_get_vdev_bad_features (VirtioBusState *bus);/* Get config of the plugged device. */ void virtio_bus_get_vdev_config (VirtioBusState *bus,uint8_t *config);/* Set config of the plugged device. */
include/hw/virtio/virtio-net.h +23 -23
58 lines not on this page · raw message
include/hw/virtio/virtio-scsi.h +3 -3
@@ -253,11 +253,11 @@ QEMU_BUILD_BUG_ON(offsetof(VirtIOSCSIReq, req.cdb) != DEFINE_PROP_UINT32("cmd_per_lun", _state, _conf_field.cmd_per_lun, 128)#define DEFINE_VIRTIO_SCSI_FEATURES (_state, _feature_field) \ - DEFINE_PROP_BIT("any_layout", _state, _feature_field, \ + DEFINE_PROP_BIT64("any_layout", _state, _feature_field, \ VIRTIO_F_ANY_LAYOUT, true), \ - DEFINE_PROP_BIT("hotplug", _state, _feature_field, VIRTIO_SCSI_F_HOTPLUG, \ + DEFINE_PROP_BIT64("hotplug", _state, _feature_field, VIRTIO_SCSI_F_HOTPLUG, \ true), \ - DEFINE_PROP_BIT("param_change", _state, _feature_field, \ + DEFINE_PROP_BIT64("param_change", _state, _feature_field, \ VIRTIO_SCSI_F_CHANGE, true)typedef void (*HandleOutput )(VirtIODevice *,VirtQueue *);
include/hw/virtio/virtio.h +22 -16
@@ -55,6 +55,12 @@/* A guest should never accept this. It implies negotiation is broken. */ #define VIRTIO_F_BAD_FEATURE 30 +/* v1.0 compliant. */ +#define VIRTIO_F_VERSION_1 32 + +/* The highest feature bit that we support */ +#define VIRTIO_HIGHEST_FEATURE_BIT 32 +/* from Linux's linux/virtio_ring.h */ /* This marks a buffer as continuing via the next field. */
@@ -117,7 +123,7 @@ struct VirtIODeviceuint8_t status;uint8_t isr;uint16_t queue_sel; -uint32_t guest_features; +uint64_t guest_features;size_t config_len;void *config;uint16_t config_vector;
@@ -138,9 +144,9 @@ typedef struct VirtioDeviceClass {/* This is what a VirtioDevice must implement */ DeviceRealize realize;DeviceUnrealize unrealize; -uint32_t (*get_features)(VirtIODevice *vdev,uint32_t requested_features); -uint32_t (*bad_features)(VirtIODevice *vdev); -void (*set_features)(VirtIODevice *vdev,uint32_t val); +uint64_t (*get_features)(VirtIODevice *vdev,uint64_t requested_features); +uint64_t (*bad_features)(VirtIODevice *vdev); +void (*set_features)(VirtIODevice *vdev,uint64_t val);void (*get_config)(VirtIODevice *vdev,uint8_t *config);void (*set_config)(VirtIODevice *vdev,const uint8_t *config);void (*reset)(VirtIODevice *vdev);
@@ -225,7 +231,7 @@ void virtio_queue_set_vector(VirtIODevice *vdev, int n, uint16_t vector);void virtio_set_status (VirtIODevice *vdev,uint8_t val);void virtio_reset (void *opaque);void virtio_update_irq (VirtIODevice *vdev); -int virtio_set_features (VirtIODevice *vdev,uint32_t val); +int virtio_set_features (VirtIODevice *vdev,uint64_t val);/* Base devices. */ typedef struct VirtIOBlkConf VirtIOBlkConf ;
@@ -238,9 +244,9 @@ typedef struct VirtIOSCSIConf VirtIOSCSIConf;typedef struct VirtIORNGConf VirtIORNGConf ;#define DEFINE_VIRTIO_COMMON_FEATURES (_state, _field) \ - DEFINE_PROP_BIT("indirect_desc", _state, _field, \ + DEFINE_PROP_BIT64("indirect_desc", _state, _field, \ VIRTIO_RING_F_INDIRECT_DESC, true), \ - DEFINE_PROP_BIT("event_idx", _state, _field, \ + DEFINE_PROP_BIT64("event_idx", _state, _field, \ VIRTIO_RING_F_EVENT_IDX, true)hwaddr virtio_queue_get_desc_addr (VirtIODevice *vdev,int n);
@@ -266,22 +272,22 @@ void virtio_queue_set_host_notifier_fd_handler(VirtQueue *vq, bool assign,void virtio_queue_notify_vq (VirtQueue *vq);void virtio_irq (VirtQueue *vq); -static inline void virtio_add_feature (uint32_t *features,unsigned int fbit) +static inline void virtio_add_feature (uint64_t *features,unsigned int fbit) { -assert (fbit <32 ); - *features |= (1 << fbit); +assert (fbit <64 ); + *features |= (1ULL << fbit); } -static inline void virtio_clear_feature (uint32_t *features,unsigned int fbit) +static inline void virtio_clear_feature (uint64_t *features,unsigned int fbit) { -assert (fbit <32 ); - *features &= ~(1 << fbit); +assert (fbit <64 ); + *features &= ~(1ULL << fbit); } -static inline bool __virtio_has_feature (uint32_t features,unsigned int fbit) +static inline bool __virtio_has_feature (uint64_t features,unsigned int fbit) { -assert (fbit <32 ); -return !!(features & (1 << fbit)); +assert (fbit <64 ); +return !!(features & (1ULL << fbit)); }static inline bool virtio_has_feature (VirtIODevice *vdev,unsigned int fbit)
Signature · 1 line
1.7.9.5
RFC PATCH v6 6/20 virtio: endianness checks for virtio 1.0 devices
In reply to Cornelia HuckAdd code that checks for the VERSION_1 feature bit in order to make decisions about the device's endianness. This allows us to support transitional devices.
--- hw/virtio/virtio.c | 6 +++++- include/hw/virtio/virtio-access.h | 4 ++++ include/hw/virtio/virtio.h | 8 ++++++-- 3 files changed, 15 insertions(+), 3 deletions(-)
hw/virtio/virtio.c +5 -1
@@ -881,7 +881,11 @@ static bool virtio_device_endian_needed(void *opaque)VirtIODevice *vdev = opaque;assert (vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_UNKNOWN ); -return vdev->device_endian !=virtio_default_endian (); +if (!virtio_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +return vdev->device_endian !=virtio_default_endian (); + } +/* Devices conforming to VIRTIO 1.0 or later are always LE. */ +return vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_LITTLE ; }static const VMStateDescription vmstate_virtio_device_endian = {
include/hw/virtio/virtio-access.h +4 -0
@@ -19,6 +19,10 @@static inline bool virtio_access_is_big_endian (VirtIODevice *vdev) { +if (virtio_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +/* Devices conforming to VIRTIO 1.0 or later are always LE. */ +return false; + }#if defined(TARGET_IS_BIENDIAN )return virtio_is_big_endian (vdev);#elif defined(TARGET_WORDS_BIGENDIAN )
include/hw/virtio/virtio.h +6 -2
@@ -297,7 +297,11 @@ static inline bool virtio_has_feature(VirtIODevice *vdev, unsigned int fbit)static inline bool virtio_is_big_endian (VirtIODevice *vdev) { -assert (vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_UNKNOWN ); -return vdev->device_endian ==VIRTIO_DEVICE_ENDIAN_BIG ; +if (!virtio_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +assert (vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_UNKNOWN ); +return vdev->device_endian ==VIRTIO_DEVICE_ENDIAN_BIG ; + } +/* Devices conforming to VIRTIO 1.0 or later are always LE. */ +return false; }#endif
Signature · 1 line
1.7.9.5
RFC PATCH v6 7/20 virtio: allow virtio-1 queue layout
In reply to Cornelia HuckFor virtio-1 devices, we allow a more complex queue layout that doesn't require descriptor table and rings on a physically-contigous memory area:
add virtio_queue_set_rings() to allow transports to set this up.
--- hw/virtio/virtio-mmio.c | 3 +++ hw/virtio/virtio.c | 53 ++++++++++++++++++++++++++++---------------- include/hw/virtio/virtio.h | 3 +++ 3 files changed, 40 insertions(+), 19 deletions(-)
hw/virtio/virtio-mmio.c +3 -0
@@ -244,8 +244,11 @@ static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value,case VIRTIO_MMIO_QUEUENUM :DPRINTF ("mmio_queue write %d max %d\n" , (int )value,VIRTQUEUE_MAX_SIZE );virtio_queue_set_num (vdev, vdev->queue_sel, value); +/* Note: only call this function for legacy devices */ +virtio_queue_update_rings (vdev, vdev->queue_sel);break ;case VIRTIO_MMIO_QUEUEALIGN : +/* Note: this is only valid for legacy devices */ virtio_queue_set_align (vdev, vdev->queue_sel, value);break ;case VIRTIO_MMIO_QUEUEPFN :
hw/virtio/virtio.c +34 -19
123 lines not on this page · raw message
include/hw/virtio/virtio.h +3 -0
@@ -224,6 +224,9 @@ void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr);hwaddr virtio_queue_get_addr (VirtIODevice *vdev,int n);void virtio_queue_set_num (VirtIODevice *vdev,int n,int num);int virtio_queue_get_num (VirtIODevice *vdev,int n); +void virtio_queue_set_rings (VirtIODevice *vdev,int n,hwaddr desc, +hwaddr avail,hwaddr used); +void virtio_queue_update_rings (VirtIODevice *vdev,int n);void virtio_queue_set_align (VirtIODevice *vdev,int n,int align);void virtio_queue_notify (VirtIODevice *vdev,int n);uint16_t virtio_queue_vector (VirtIODevice *vdev,int n);
Signature · 1 line
1.7.9.5
RFC PATCH v6 8/20 dataplane: allow virtio-1 devices
In reply to Cornelia HuckHandle endianness conversion for virtio-1 virtqueues correctly.
Note that dataplane now needs to be built per-target.
--- hw/block/dataplane/virtio-blk.c | 4 +- hw/scsi/virtio-scsi-dataplane.c | 2 +- hw/virtio/Makefile.objs | 2 +- hw/virtio/dataplane/Makefile.objs | 2 +- hw/virtio/dataplane/vring.c | 86 ++++++++++++++----------- include/hw/virtio/dataplane/vring-accessors.h | 75 +++++++++++++++++++++ include/hw/virtio/dataplane/vring.h | 14 +--- 7 files changed, 131 insertions(+), 54 deletions(-) create mode 100644 include/hw/virtio/dataplane/vring-accessors.h
hw/block/dataplane/virtio-blk.c +3 -1
@@ -16,7 +16,9 @@#include "qemu/iov.h" #include "qemu/thread.h" #include "qemu/error-report.h" +#include "hw/virtio/virtio-access.h" #include "hw/virtio/dataplane/vring.h" +#include "hw/virtio/dataplane/vring-accessors.h" #include "sysemu/block-backend.h" #include "hw/virtio/virtio-blk.h" #include "virtio-blk.h"
@@ -75,7 +77,7 @@ static void complete_request_vring(VirtIOBlockReq *req, unsigned char status)VirtIOBlockDataPlane *s = req->dev->dataplane;stb_p (&req->in->status, status); -vring_push (&req->dev->dataplane->vring, &req->elem, +vring_push (s->vdev, &req->dev->dataplane->vring, &req->elem, req->qiov.size +sizeof (*req->in));/* Suppress notification to guest by BH and its scheduled
hw/scsi/virtio-scsi-dataplane.c +1 -1
@@ -94,7 +94,7 @@ void virtio_scsi_vring_push_notify(VirtIOSCSIReq *req) {VirtIODevice *vdev =VIRTIO_DEVICE (req->vring->parent); -vring_push (&req->vring->vring, &req->elem, +vring_push (vdev, &req->vring->vring, &req->elem, req->qsgl.size + req->resp_iov.size);if (vring_should_notify (vdev, &req->vring->vring)) {
hw/virtio/Makefile.objs +1 -1
@@ -2,7 +2,7 @@ common-obj-y += virtio-rng.o common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o common-obj-y += virtio-bus.o common-obj-y += virtio-mmio.o -common-obj-$(CONFIG_VIRTIO) += dataplane/ +obj-$(CONFIG_VIRTIO) += dataplane/ obj-y += virtio.o virtio-balloon.o obj-$(CONFIG_LINUX) += vhost.o vhost-backend.o vhost-user.o
hw/virtio/dataplane/Makefile.objs +1 -1
@@ -1 +1 @@ -common-obj-y += vring.o +obj-y += vring.o
hw/virtio/dataplane/vring.c +48 -38
239 lines not on this page · raw message
include/hw/virtio/dataplane/vring-accessors.h new file +75 -0
75 lines not on this page · raw message
include/hw/virtio/dataplane/vring.h +2 -12
@@ -31,17 +31,6 @@ typedef struct {bool broken;/* was there a fatal error? */ } Vring; -static inline unsigned int vring_get_num (Vring *vring) -{ -return vring->vr.num; -} - -/* Are there more descriptors available? */ -static inline bool vring_more_avail (Vring *vring) -{ -return vring->vr.avail->idx != vring->last_avail_idx; -} -/* Fail future vring_pop() and vring_push() calls until reset */ static inline void vring_set_broken (Vring *vring) {
@@ -54,6 +43,7 @@ void vring_disable_notification(VirtIODevice *vdev, Vring *vring);bool vring_enable_notification (VirtIODevice *vdev,Vring *vring);bool vring_should_notify (VirtIODevice *vdev,Vring *vring);int vring_pop (VirtIODevice *vdev,Vring *vring,VirtQueueElement *elem); -void vring_push (Vring *vring,VirtQueueElement *elem,int len); +void vring_push (VirtIODevice *vdev,Vring *vring,VirtQueueElement *elem, +int len);#endif /* VRING_H */
Signature · 1 line
1.7.9.5
RFC PATCH v6 9/20 s390x/css: Add a callback for when subchannel gets disabled
In reply to Cornelia HuckFrom: Thomas Huth <[email protected]>
We need a possibility to run code when a subchannel gets disabled. This patch adds the necessary infrastructure.
--- hw/s390x/css.c | 12 ++++++++++++ hw/s390x/css.h | 1 + 2 files changed, 13 insertions(+)
hw/s390x/css.c +12 -0
@@ -588,6 +588,7 @@ int css_do_msch(SubchDev *sch, SCHIB *orig_schib) {SCSW *s = &sch->curr_status.scsw;PMCW *p = &sch->curr_status.pmcw; +uint16_t oldflags;int ret;SCHIB schib;
@@ -610,6 +611,7 @@ int css_do_msch(SubchDev *sch, SCHIB *orig_schib)copy_schib_from_guest (&schib, orig_schib);/* Only update the program-modifiable fields. */ p->intparm = schib.pmcw.intparm; + oldflags = p->flags; p->flags &= ~(PMCW_FLAGS_MASK_ISC |PMCW_FLAGS_MASK_ENA |PMCW_FLAGS_MASK_LM |PMCW_FLAGS_MASK_MME |PMCW_FLAGS_MASK_MP );
@@ -625,6 +627,12 @@ int css_do_msch(SubchDev *sch, SCHIB *orig_schib) (PMCW_CHARS_MASK_MBFC |PMCW_CHARS_MASK_CSENSE ); sch->curr_status.mba = schib.mba; +/* Has the channel been disabled? */ +if (sch->disable_cb && (oldflags &PMCW_FLAGS_MASK_ENA ) !=0 + && (p->flags &PMCW_FLAGS_MASK_ENA ) ==0 ) { + sch->disable_cb (sch); + } + ret =0 ; out:
@@ -1443,6 +1451,10 @@ void css_reset_sch(SubchDev *sch) {PMCW *p = &sch->curr_status.pmcw; +if ((p->flags &PMCW_FLAGS_MASK_ENA ) !=0 && sch->disable_cb) { + sch->disable_cb (sch); + } + p->intparm =0 ; p->flags &= ~(PMCW_FLAGS_MASK_ISC | PMCW_FLAGS_MASK_ENA | PMCW_FLAGS_MASK_LM | PMCW_FLAGS_MASK_MME |
hw/s390x/css.h +1 -0
@@ -81,6 +81,7 @@ struct SubchDev {uint8_t ccw_no_data_cnt;/* transport-provided data: */ int (*ccw_cb) (SubchDev *,CCW1 ); +void (*disable_cb)(SubchDev *);SenseId id;void *driver_data; };
Signature · 1 line
1.7.9.5
RFC PATCH v6 10/20 s390x/virtio-ccw: add virtio set-revision call
In reply to Cornelia HuckFrom: Thomas Huth <[email protected]>
Handle the virtio-ccw revision according to what the guest sets. When revision 1 is selected, we have a virtio-1 standard device with byteswapping for the virtio rings.
When a channel gets disabled, we have to revert to the legacy behavior in case the next user of the device does not negotiate the revision 1 anymore (e.g. the boot firmware uses revision 1, but the operating system only uses the legacy mode).
Note that revisions > 0 are still disabled.
--- hw/s390x/virtio-ccw.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/virtio-ccw.h | 8 ++++++++ 2 files changed, 60 insertions(+)
hw/s390x/virtio-ccw.c +52 -0
@@ -20,9 +20,11 @@#include "hw/virtio/virtio-net.h" #include "hw/sysbus.h" #include "qemu/bitops.h" +#include "hw/virtio/virtio-access.h" #include "hw/virtio/virtio-bus.h" #include "hw/s390x/adapter.h" #include "hw/s390x/s390_flic.h" +#include "linux/virtio_config.h" #include "ioinst.h" #include "css.h"
@@ -260,6 +262,12 @@ typedef struct VirtioThinintInfo {uint8_t isc; }QEMU_PACKED VirtioThinintInfo; +typedef struct VirtioRevInfo { +uint16_t revision; +uint16_t length; +uint8_t data[0 ]; +} QEMU_PACKED VirtioRevInfo; +/* Specify where the virtqueues for the subchannel are in guest memory. */ static int virtio_ccw_set_vqs (SubchDev *sch,uint64_t addr,uint32_t align,uint16_t index,uint16_t num)
@@ -299,6 +307,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) {int ret;VqInfoBlock info; +VirtioRevInfo revinfo;uint8_t status;VirtioFeatDesc features;void *config;
@@ -375,6 +384,13 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) features.features = (uint32_t )dev->host_features; }else if (features.index ==1 ) { features.features = (uint32_t )(dev->host_features >>32 ); +/* +* Don't offer version 1 to the guest if it did not +* negotiate at least revision 1. +*/ +if (dev->revision <=0 ) { + features.features &= ~(1 << (VIRTIO_F_VERSION_1 -32 )); + } }else {/* Return zeroes if the guest supports more feature bits. */ features.features =0 ;
@@ -406,6 +422,13 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) (vdev->guest_features &0xffffffff00000000 ) | features.features); }else if (features.index ==1 ) { +/* +* The guest should not set version 1 if it didn't +* negotiate a revision >= 1. +*/ +if (dev->revision <=0 ) { + features.features &= ~(1 << (VIRTIO_F_VERSION_1 -32 )); + }virtio_set_features (vdev, (vdev->guest_features &0x00000000ffffffff ) | ((uint64_t )features.features <<32 ));
@@ -608,6 +631,25 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) } }break ; +case CCW_CMD_SET_VIRTIO_REV : + len =sizeof (revinfo); +if (ccw.count < len || (check_len && ccw.count > len)) { + ret = -EINVAL ; +break ; + } +if (!ccw.cda) { + ret = -EFAULT ; +break ; + } +cpu_physical_memory_read (ccw.cda, &revinfo, len); +if (dev->revision >=0 || + revinfo.revision >virtio_ccw_rev_max (dev)) { + ret = -ENOSYS ; +break ; + } + ret =0 ; + dev->revision = revinfo.revision; +break ;default : ret = -ENOSYS ;break ;
@@ -615,6 +657,13 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)return ret; } +static void virtio_sch_disable_cb (SubchDev *sch) +{ +VirtioCcwDevice *dev = sch->driver_data; + + dev->revision =-1 ; +} +static int virtio_ccw_device_init (VirtioCcwDevice *dev,VirtIODevice *vdev) {unsigned int cssid =0 ;
@@ -740,6 +789,7 @@ static int virtio_ccw_device_init(VirtioCcwDevice *dev, VirtIODevice *vdev)css_sch_build_virtual_schib (sch,0 ,VIRTIO_CCW_CHPID_TYPE ); sch->ccw_cb = virtio_ccw_cb; + sch->disable_cb = virtio_sch_disable_cb;/* Build senseid data. */ memset (&sch->id,0 ,sizeof (SenseId));
@@ -747,6 +797,8 @@ static int virtio_ccw_device_init(VirtioCcwDevice *dev, VirtIODevice *vdev) sch->id.cu_type =VIRTIO_CCW_CU_TYPE ; sch->id.cu_model = vdev->device_id; + dev->revision =-1 ; +/* Set default feature bits that are offered by the host. */ virtio_add_feature (&dev->host_features,VIRTIO_F_NOTIFY_ON_EMPTY );virtio_add_feature (&dev->host_features,VIRTIO_F_BAD_FEATURE );
hw/s390x/virtio-ccw.h +8 -0
@@ -40,6 +40,7 @@#define CCW_CMD_SET_CONF_IND 0x53#define CCW_CMD_READ_VQ_CONF 0x32#define CCW_CMD_SET_IND_ADAPTER 0x73 +#define CCW_CMD_SET_VIRTIO_REV 0x83#define TYPE_VIRTIO_CCW_DEVICE "virtio-ccw-device"#define VIRTIO_CCW_DEVICE (obj) \
@@ -86,6 +87,7 @@ struct VirtioCcwDevice {SubchDev *sch;char *bus_id;uint64_t host_features; +int revision;VirtioBusState bus;bool ioeventfd_started;bool ioeventfd_disabled;
@@ -99,6 +101,12 @@ struct VirtioCcwDevice {uint64_t ind_bit; }; +/* The maximum virtio revision we support. */ +static inline int virtio_ccw_rev_max (VirtioCcwDevice *dev) +{ +return 0 ; +} +/* virtual css bus type */ typedef struct VirtualCssBus { BusState parent_obj;
Signature · 1 line
1.7.9.5
RFC PATCH v6 11/20 s390x/virtio-ccw: support virtio-1 set_vq format
In reply to Cornelia HuckSupport the new CCW_CMD_SET_VQ format for virtio-1 devices.
While we're at it, refactor the code a bit and enforce big endian fields (which had always been required, even for legacy).
--- hw/s390x/virtio-ccw.c | 114 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 80 insertions(+), 34 deletions(-)
hw/s390x/virtio-ccw.c +80 -34
@@ -238,11 +238,20 @@ VirtualCssBus *virtual_css_bus_init(void) }/* Communication blocks used by several channel commands. */ -typedef struct VqInfoBlock { +typedef struct VqInfoBlockLegacy {uint64_t queue;uint32_t align;uint16_t index;uint16_t num; +} QEMU_PACKED VqInfoBlockLegacy; + +typedef struct VqInfoBlock { +uint64_t desc; +uint32_t res0; +uint16_t index; +uint16_t num; +uint64_t avail; +uint64_t used; } QEMU_PACKED VqInfoBlock; typedef struct VqConfigBlock {
@@ -269,17 +278,20 @@ typedef struct VirtioRevInfo { }QEMU_PACKED VirtioRevInfo;/* Specify where the virtqueues for the subchannel are in guest memory. */ -static int virtio_ccw_set_vqs (SubchDev *sch,uint64_t addr,uint32_t align, -uint16_t index,uint16_t num) +static int virtio_ccw_set_vqs (SubchDev *sch,VqInfoBlock *info, +VqInfoBlockLegacy *linfo) {VirtIODevice *vdev =virtio_ccw_get_vdev (sch); +uint16_t index = info ? info->index : linfo->index; +uint16_t num = info ? info->num : linfo->num; +uint64_t desc = info ? info->desc : linfo->queue;if (index >VIRTIO_PCI_QUEUE_MAX ) {return -EINVAL ; }/* Current code in virtio.c relies on 4K alignment. */ -if (addr && (align !=4096 )) { +if (linfo && desc && (linfo->align !=4096 )) {return -EINVAL ; }
@@ -287,8 +299,12 @@ static int virtio_ccw_set_vqs(SubchDev *sch, uint64_t addr, uint32_t align,return -EINVAL ; } -virtio_queue_set_addr (vdev, index, addr); -if (!addr) { +if (info) { +virtio_queue_set_rings (vdev, index, desc, info->avail, info->used); + }else { +virtio_queue_set_addr (vdev, index, desc); + } +if (!desc) {virtio_queue_set_vector (vdev, index,0 ); }else {/* Fail if we don't have a big enough queue. */
@@ -303,10 +319,66 @@ static int virtio_ccw_set_vqs(SubchDev *sch, uint64_t addr, uint32_t align,return 0 ; } -static int virtio_ccw_cb (SubchDev *sch,CCW1 ccw) +static int virtio_ccw_handle_set_vq (SubchDev *sch,CCW1 ccw,bool check_len, +bool is_legacy) {int ret;VqInfoBlock info; +VqInfoBlockLegacy linfo; +size_t info_len = is_legacy ?sizeof (linfo) :sizeof (info); + +if (check_len) { +if (ccw.count != info_len) { +return -EINVAL ; + } + }else if (ccw.count < info_len) { +/* Can't execute command. */ +return -EINVAL ; + } +if (!ccw.cda) { +return -EFAULT ; + } +if (is_legacy) { + linfo.queue =ldq_be_phys (&address_space_memory, ccw.cda); + linfo.align =ldl_be_phys (&address_space_memory, + ccw.cda +sizeof (linfo.queue)); + linfo.index =lduw_be_phys (&address_space_memory, + ccw.cda +sizeof (linfo.queue) + +sizeof (linfo.align)); + linfo.num =lduw_be_phys (&address_space_memory, + ccw.cda +sizeof (linfo.queue) + +sizeof (linfo.align) + +sizeof (linfo.index)); + ret =virtio_ccw_set_vqs (sch,NULL , &linfo); + }else { + info.desc =ldq_be_phys (&address_space_memory, ccw.cda); + info.index =lduw_be_phys (&address_space_memory, + ccw.cda +sizeof (info.desc) + +sizeof (info.res0)); + info.num =lduw_be_phys (&address_space_memory, + ccw.cda +sizeof (info.desc) + +sizeof (info.res0) + +sizeof (info.index)); + info.avail =ldq_be_phys (&address_space_memory, + ccw.cda +sizeof (info.desc) + +sizeof (info.res0) + +sizeof (info.index) + +sizeof (info.num)); + info.used =ldq_be_phys (&address_space_memory, + ccw.cda +sizeof (info.desc) + +sizeof (info.res0) + +sizeof (info.index) + +sizeof (info.num) + +sizeof (info.avail)); + ret =virtio_ccw_set_vqs (sch, &info,NULL ); + } + sch->curr_status.scsw.count =0 ; +return ret; +} + +static int virtio_ccw_cb (SubchDev *sch,CCW1 ccw) +{ +int ret;VirtioRevInfo revinfo;uint8_t status;VirtioFeatDesc features;
@@ -331,33 +403,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)/* Look at the command. */ switch (ccw.cmd_code) {case CCW_CMD_SET_VQ : -if (check_len) { -if (ccw.count !=sizeof (info)) { - ret = -EINVAL ; -break ; - } - }else if (ccw.count <sizeof (info)) { -/* Can't execute command. */ - ret = -EINVAL ; -break ; - } -if (!ccw.cda) { - ret = -EFAULT ; - }else { - info.queue =ldq_phys (&address_space_memory, ccw.cda); - info.align =ldl_phys (&address_space_memory, - ccw.cda +sizeof (info.queue)); - info.index =lduw_phys (&address_space_memory, - ccw.cda +sizeof (info.queue) - +sizeof (info.align)); - info.num =lduw_phys (&address_space_memory, - ccw.cda +sizeof (info.queue) - +sizeof (info.align) - +sizeof (info.index)); - ret =virtio_ccw_set_vqs (sch, info.queue, info.align, info.index, - info.num); - sch->curr_status.scsw.count =0 ; - } + ret =virtio_ccw_handle_set_vq (sch, ccw, check_len, dev->revision <1 );break ;case CCW_CMD_VDEV_RESET :virtio_ccw_stop_ioeventfd (dev);
Signature · 1 line
1.7.9.5
RFC PATCH v6 12/20 virtio: disallow late feature changes for virtio-1
In reply to Cornelia HuckFor virtio-1 devices, the driver must not attempt to set feature bits after it set FEATURES_OK in the device status. Simply reject it in that case.
--- hw/virtio/virtio.c | 16 ++++++++++++++-- include/hw/virtio/virtio.h | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-)
hw/virtio/virtio.c +14 -2
@@ -978,7 +978,7 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)vmstate_save_state (f, &vmstate_virtio, vdev); } -int virtio_set_features (VirtIODevice *vdev,uint64_t val) +static int __virtio_set_features (VirtIODevice *vdev,uint64_t val) {BusState *qbus =qdev_get_parent_bus (DEVICE (vdev));VirtioBusClass *vbusk =VIRTIO_BUS_GET_CLASS (qbus);
@@ -994,6 +994,18 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t val)return bad ?-1 :0 ; } +int virtio_set_features (VirtIODevice *vdev,uint64_t val) +{ +/* +* The driver must not attempt to set features after feature negotiation +* has finished. +*/ +if (vdev->status &VIRTIO_CONFIG_S_FEATURES_OK ) { +return -EINVAL ; + } +return __virtio_set_features (vdev, val); +} +int virtio_load (VirtIODevice *vdev,QEMUFile *f,int version_id) {int i, ret;
@@ -1026,7 +1038,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)qemu_get_be32s (f, &features);/* XXX features >= 32 */ -if (virtio_set_features (vdev, features) <0 ) { +if (__virtio_set_features (vdev, features) <0 ) { supported_features = k->get_features (qbus->parent);error_report ("Features 0x%x unsupported. Allowed features: 0x%lx" , features, supported_features);
include/hw/virtio/virtio.h +2 -0
@@ -32,6 +32,8 @@#define VIRTIO_CONFIG_S_DRIVER 2/* Driver has used its parts of the config, and is happy */ #define VIRTIO_CONFIG_S_DRIVER_OK 4 +/* Driver has finished configuring features */ +#define VIRTIO_CONFIG_S_FEATURES_OK 8/* We've given up on this device. */ #define VIRTIO_CONFIG_S_FAILED 0x80
Signature · 1 line
1.7.9.5
RFC PATCH v6 13/20 virtio: allow to fail setting status
In reply to Cornelia Huckvirtio-1 allow setting of the FEATURES_OK status bit to fail if the negotiated feature bits are inconsistent: let's fail virtio_set_status() in that case and update virtio-ccw to post an error to the guest.
--- hw/s390x/virtio-ccw.c | 20 ++++++++++++-------- hw/virtio/virtio.c | 24 +++++++++++++++++++++++- include/hw/virtio/virtio.h | 3 ++- 3 files changed, 37 insertions(+), 10 deletions(-)
hw/s390x/virtio-ccw.c +12 -8
@@ -555,15 +555,19 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)if (!(status &VIRTIO_CONFIG_S_DRIVER_OK )) {virtio_ccw_stop_ioeventfd (dev); } -virtio_set_status (vdev, status); -if (vdev->status ==0 ) { -virtio_reset (vdev); - } -if (status &VIRTIO_CONFIG_S_DRIVER_OK ) { -virtio_ccw_start_ioeventfd (dev); +if (virtio_set_status (vdev, status) ==0 ) { +if (vdev->status ==0 ) { +virtio_reset (vdev); + } +if (status &VIRTIO_CONFIG_S_DRIVER_OK ) { +virtio_ccw_start_ioeventfd (dev); + } + sch->curr_status.scsw.count = ccw.count -sizeof (status); + ret =0 ; + }else { +/* Trigger a command reject. */ + ret = -ENOSYS ; } - sch->curr_status.scsw.count = ccw.count -sizeof (status); - ret =0 ; }break ;case CCW_CMD_SET_IND :
hw/virtio/virtio.c +23 -1
@@ -543,15 +543,37 @@ void virtio_update_irq(VirtIODevice *vdev)virtio_notify_vector (vdev,VIRTIO_NO_VECTOR ); } -void virtio_set_status (VirtIODevice *vdev,uint8_t val) +static int virtio_validate_features (VirtIODevice *vdev) +{ +VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (vdev); + +if (k->validate_features) { +return k->validate_features (vdev); + }else { +return 0 ; + } +} + +int virtio_set_status (VirtIODevice *vdev,uint8_t val) {VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (vdev);trace_virtio_set_status (vdev, val); +if (virtio_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +if (!(vdev->status &VIRTIO_CONFIG_S_FEATURES_OK ) && + val &VIRTIO_CONFIG_S_FEATURES_OK ) { +int ret =virtio_validate_features (vdev); + +if (ret) { +return ret; + } + } + }if (k->set_status) { k->set_status (vdev, val); } vdev->status = val; +return 0 ; }bool target_words_bigendian (void );
include/hw/virtio/virtio.h +2 -1
@@ -149,6 +149,7 @@ typedef struct VirtioDeviceClass {uint64_t (*get_features)(VirtIODevice *vdev,uint64_t requested_features);uint64_t (*bad_features)(VirtIODevice *vdev);void (*set_features)(VirtIODevice *vdev,uint64_t val); +int (*validate_features)(VirtIODevice *vdev);void (*get_config)(VirtIODevice *vdev,uint8_t *config);void (*set_config)(VirtIODevice *vdev,const uint8_t *config);void (*reset)(VirtIODevice *vdev);
@@ -233,7 +234,7 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align);void virtio_queue_notify (VirtIODevice *vdev,int n);uint16_t virtio_queue_vector (VirtIODevice *vdev,int n);void virtio_queue_set_vector (VirtIODevice *vdev,int n,uint16_t vector); -void virtio_set_status (VirtIODevice *vdev,uint8_t val); +int virtio_set_status (VirtIODevice *vdev,uint8_t val);void virtio_reset (void *opaque);void virtio_update_irq (VirtIODevice *vdev);int virtio_set_features (VirtIODevice *vdev,uint64_t val);
Signature · 1 line
1.7.9.5
RFC PATCH v6 14/20 s390x/virtio-ccw: enable virtio 1.0
In reply to Cornelia Huckvirtio-ccw should now have everything in place to operate virtio 1.0 devices, so let's enable revision 1.
--- hw/s390x/virtio-ccw.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/s390x/virtio-ccw.h +1 -1
@@ -104,7 +104,7 @@ struct VirtioCcwDevice {/* The maximum virtio revision we support. */ static inline int virtio_ccw_rev_max (VirtioCcwDevice *dev) { -return 0 ; +return dev->host_features & (1ULL <<VIRTIO_F_VERSION_1 ) ?1 :0 ; }/* virtual css bus type */
Signature · 1 line
1.7.9.5
RFC PATCH v6 15/20 virtio-net: no writeable mac for virtio-1
In reply to Cornelia HuckDevices operating as virtio 1.0 may not allow writes to the mac address in config space.
--- hw/net/virtio-net.c | 1 + 1 file changed, 1 insertion(+)
hw/net/virtio-net.c +1 -0
@@ -87,6 +87,7 @@ static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)memcpy (&netcfg, config, n->config_size);if (!virtio_has_feature (vdev,VIRTIO_NET_F_CTRL_MAC_ADDR ) && + !virtio_has_feature (vdev,VIRTIO_F_VERSION_1 ) &&memcmp (netcfg.mac, n->mac,ETH_ALEN )) {memcpy (n->mac, netcfg.mac,ETH_ALEN );qemu_format_nic_info_str (qemu_get_queue (n->nic), n->mac);
Signature · 1 line
1.7.9.5
RFC PATCH v6 16/20 virtio-net: support longer header
In reply to Cornelia Huckvirtio-1 devices always use num_buffers in the header, even if mergeable rx buffers have not been negotiated.
--- hw/net/virtio-net.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
hw/net/virtio-net.c +15 -6
@@ -373,15 +373,21 @@ static int peer_has_ufo(VirtIONet *n)return n->has_ufo; } -static void virtio_net_set_mrg_rx_bufs (VirtIONet *n,int mergeable_rx_bufs) +static void virtio_net_set_mrg_rx_bufs (VirtIONet *n,int mergeable_rx_bufs, +int version_1) {int i;NetClientState *nc; n->mergeable_rx_bufs = mergeable_rx_bufs; - n->guest_hdr_len = n->mergeable_rx_bufs ? -sizeof (struct virtio_net_hdr_mrg_rxbuf ) :sizeof (struct virtio_net_hdr ); +if (version_1) { + n->guest_hdr_len =sizeof (struct virtio_net_hdr_mrg_rxbuf ); + }else { + n->guest_hdr_len = n->mergeable_rx_bufs ? +sizeof (struct virtio_net_hdr_mrg_rxbuf ) : +sizeof (struct virtio_net_hdr ); + }for (i =0 ; i < n->max_queues; i++) { nc =qemu_get_subqueue (n->nic, i);
@@ -525,7 +531,9 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features)virtio_net_set_mrg_rx_bufs (n,__virtio_has_feature (features, -VIRTIO_NET_F_MRG_RXBUF )); +VIRTIO_NET_F_MRG_RXBUF ), +__virtio_has_feature (features, +VIRTIO_F_VERSION_1 ));if (n->has_vnet_hdr) { n->curr_guest_offloads =
@@ -1407,7 +1415,8 @@ static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f,qemu_get_buffer (f, n->mac,ETH_ALEN ); n->vqs[0 ].tx_waiting =qemu_get_be32 (f); -virtio_net_set_mrg_rx_bufs (n,qemu_get_be32 (f)); +virtio_net_set_mrg_rx_bufs (n,qemu_get_be32 (f), +virtio_has_feature (vdev,VIRTIO_F_VERSION_1 ));if (version_id >=3 ) n->status =qemu_get_be16 (f);
@@ -1653,7 +1662,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) n->vqs[0 ].tx_waiting =0 ; n->tx_burst = n->net_conf.txburst; -virtio_net_set_mrg_rx_bufs (n,0 ); +virtio_net_set_mrg_rx_bufs (n,0 ,0 ); n->promisc =1 ;/* for compatibility */ n->mac_table.macs =g_malloc0 (MAC_TABLE_ENTRIES *ETH_ALEN );
Signature · 1 line
1.7.9.5
RFC PATCH v6 17/20 virtio-net: enable virtio 1.0
In reply to Cornelia Huckvirtio-net (non-vhost) now should have everything in place to support virtio 1.0: let's enable the feature bit for it.
Note that VIRTIO_F_VERSION_1 is technically a transport feature; once every device is ready for virtio 1.0, we can move setting this feature bit out of the individual devices.
--- hw/net/virtio-net.c | 1 + 1 file changed, 1 insertion(+)
hw/net/virtio-net.c +1 -0
@@ -473,6 +473,7 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features) }if (!get_vhost_net (nc->peer)) { +virtio_add_feature (&features,VIRTIO_F_VERSION_1 );return features; }return vhost_net_get_features (get_vhost_net (nc->peer), features);
Signature · 1 line
1.7.9.5
RFC PATCH v6 18/20 virtio: support revision-specific features
In reply to Cornelia HuckDevices may support different sets of feature bits depending on which revision they're operating at. Let's give the transport a way to re-query the device about its features when the revision has been changed.
--- hw/s390x/virtio-ccw.c | 12 ++++++++++-- hw/virtio/virtio-bus.c | 14 ++++++++++++-- include/hw/virtio/virtio-bus.h | 3 +++ include/hw/virtio/virtio.h | 3 +++ 4 files changed, 28 insertions(+), 4 deletions(-)
hw/s390x/virtio-ccw.c +10 -2
@@ -699,6 +699,10 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) } ret =0 ; dev->revision = revinfo.revision; +/* Re-evaluate which features the device wants to offer. */ + dev->host_features = +virtio_bus_get_vdev_features_rev (&dev->bus, dev->host_features, + dev->revision >=1 ?1 :0 );break ;default : ret = -ENOSYS ;
@@ -712,6 +716,9 @@ static void virtio_sch_disable_cb(SubchDev *sch)VirtioCcwDevice *dev = sch->driver_data; dev->revision =-1 ; +/* Reset the device's features to legacy. */ + dev->host_features = +virtio_bus_get_vdev_features_rev (&dev->bus, dev->host_features,0 ); }static int virtio_ccw_device_init (VirtioCcwDevice *dev,VirtIODevice *vdev)
@@ -853,8 +860,9 @@ static int virtio_ccw_device_init(VirtioCcwDevice *dev, VirtIODevice *vdev)virtio_add_feature (&dev->host_features,VIRTIO_F_NOTIFY_ON_EMPTY );virtio_add_feature (&dev->host_features,VIRTIO_F_BAD_FEATURE ); - dev->host_features =virtio_bus_get_vdev_features (&dev->bus, - dev->host_features); +/* All devices start in legacy mode. */ + dev->host_features = +virtio_bus_get_vdev_features_rev (&dev->bus, dev->host_features,0 );css_generate_sch_crws (sch->cssid, sch->ssid, sch->schid, parent->hotplugged,1 );
hw/virtio/virtio-bus.c +12 -2
@@ -97,18 +97,28 @@ size_t virtio_bus_get_vdev_config_len(VirtioBusState *bus) }/* Get the features of the plugged device. */ -uint64_t virtio_bus_get_vdev_features (VirtioBusState *bus, -uint64_t requested_features) +uint64_t virtio_bus_get_vdev_features_rev (VirtioBusState *bus, +uint64_t requested_features, +unsigned int revision) {VirtIODevice *vdev =virtio_bus_get_device (bus);VirtioDeviceClass *k;assert (vdev !=NULL ); k =VIRTIO_DEVICE_GET_CLASS (vdev); +if (revision >0 && k->get_features_rev) { +return k->get_features_rev (vdev, requested_features, revision); + }assert (k->get_features !=NULL );return k->get_features (vdev, requested_features); } +uint64_t virtio_bus_get_vdev_features (VirtioBusState *bus, +uint64_t requested_features) +{ +return virtio_bus_get_vdev_features_rev (bus, requested_features,0 ); +} +/* Get bad features of the plugged device. */ uint64_t virtio_bus_get_vdev_bad_features (VirtioBusState *bus) {
include/hw/virtio/virtio-bus.h +3 -0
@@ -84,6 +84,9 @@ size_t virtio_bus_get_vdev_config_len(VirtioBusState *bus);/* Get the features of the plugged device. */ uint64_t virtio_bus_get_vdev_features (VirtioBusState *bus,uint64_t requested_features); +uint64_t virtio_bus_get_vdev_features_rev (VirtioBusState *bus, +uint64_t requested_features, +unsigned int revision);/* Get bad features of the plugged device. */ uint64_t virtio_bus_get_vdev_bad_features (VirtioBusState *bus);/* Get config of the plugged device. */
include/hw/virtio/virtio.h +3 -0
@@ -147,6 +147,9 @@ typedef struct VirtioDeviceClass {DeviceRealize realize;DeviceUnrealize unrealize;uint64_t (*get_features)(VirtIODevice *vdev,uint64_t requested_features); +uint64_t (*get_features_rev)(VirtIODevice *vdev, +uint64_t requested_features, +unsigned int revision);uint64_t (*bad_features)(VirtIODevice *vdev);void (*set_features)(VirtIODevice *vdev,uint64_t val);int (*validate_features)(VirtIODevice *vdev);
Signature · 1 line
1.7.9.5
RFC PATCH v6 19/20 virtio-blk: revision specific feature bits
In reply to Cornelia HuckWire up virtio-blk to provide different feature bit sets depending on whether legacy or v1.0 has been requested.
Note that VERSION_1 is still disabled due to missing ANY_LAYOUT support.
--- hw/block/virtio-blk.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
hw/block/virtio-blk.c +19 -0
@@ -587,6 +587,24 @@ static uint64_t virtio_blk_get_features(VirtIODevice *vdev, uint64_t features)return features; } +static uint64_t virtio_blk_get_features_rev (VirtIODevice *vdev, +uint64_t features, +unsigned int revision) +{ +if (revision ==0 ) { +/* legacy */ +virtio_clear_feature (&features,VIRTIO_F_VERSION_1 ); +return virtio_blk_get_features (vdev, features); + } +/* virtio 1.0 or later */ +virtio_clear_feature (&features,VIRTIO_BLK_F_SCSI ); +virtio_clear_feature (&features,VIRTIO_BLK_F_CONFIG_WCE ); +virtio_clear_feature (&features,VIRTIO_BLK_F_WCE ); +/* we're still missing ANY_LAYOUT */ +/* virtio_add_feature(&features, VIRTIO_F_VERSION_1); */ +return features; +} +static void virtio_blk_set_status (VirtIODevice *vdev,uint8_t status) {VirtIOBlock *s =VIRTIO_BLK (vdev);
@@ -821,6 +839,7 @@ static void virtio_blk_class_init(ObjectClass *klass, void *data) vdc->get_config = virtio_blk_update_config; vdc->set_config = virtio_blk_set_config; vdc->get_features = virtio_blk_get_features; + vdc->get_features_rev = virtio_blk_get_features_rev; vdc->set_status = virtio_blk_set_status; vdc->reset = virtio_blk_reset; vdc->save = virtio_blk_save_device;
Signature · 1 line
1.7.9.5
RFC PATCH v6 20/20 vhost: 64 bit features
In reply to Cornelia HuckMake sure that all vhost interfaces use 64 bit features, as the virtio core does, and make sure to use ULL everywhere possible to be on the safe side.
--- hw/net/vhost_net.c | 12 ++++++------ hw/virtio/vhost.c | 14 +++++++------- include/hw/virtio/vhost.h | 6 +++--- include/net/vhost_net.h | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-)
hw/net/vhost_net.c +6 -6
@@ -107,13 +107,13 @@ static const int *vhost_net_get_feature_bits(struct vhost_net *net)return feature_bits; } -unsigned vhost_net_get_features (struct vhost_net *net,unsigned features) +uint64_t vhost_net_get_features (struct vhost_net *net,uint64_t features) {return vhost_get_features (&net->dev,vhost_net_get_feature_bits (net), features); } -void vhost_net_ack_features (struct vhost_net *net,unsigned features) +void vhost_net_ack_features (struct vhost_net *net,uint64_t features) { net->dev.acked_features = net->dev.backend_features;vhost_ack_features (&net->dev,vhost_net_get_feature_bits (net), features);
@@ -147,7 +147,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options) goto fail; } net->dev.backend_features =qemu_has_vnet_hdr (options->net_backend) - ?0 : (1 <<VHOST_NET_F_VIRTIO_NET_HDR ); + ?0 : (1ULL <<VHOST_NET_F_VIRTIO_NET_HDR ); net->backend = r; }else { net->dev.backend_features =0 ;
@@ -166,7 +166,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)if (backend_kernel) {if (!qemu_has_vnet_hdr_len (options->net_backend,sizeof (struct virtio_net_hdr_mrg_rxbuf ))) { - net->dev.features &= ~(1 <<VIRTIO_NET_F_MRG_RXBUF ); + net->dev.features &= ~(1ULL <<VIRTIO_NET_F_MRG_RXBUF ); }if (~net->dev.features & net->dev.backend_features) { fprintf(stderr, "vhost lacks feature mask %" PRIu64
@@ -423,11 +423,11 @@ void vhost_net_cleanup(struct vhost_net *net) { } -unsigned vhost_net_get_features (struct vhost_net *net,unsigned features) +uint64_t vhost_net_get_features (struct vhost_net *net,uint64_t features) {return features; } -void vhost_net_ack_features (struct vhost_net *net,unsigned features) +void vhost_net_ack_features (struct vhost_net *net,uint64_t features) { }
hw/virtio/vhost.c +7 -7
@@ -551,7 +551,7 @@ static int vhost_dev_set_features(struct vhost_dev *dev, bool enable_log)uint64_t features = dev->acked_features;int r;if (enable_log) { - features |=0x1 <<VHOST_F_LOG_ALL ; + features |=0x1ULL <<VHOST_F_LOG_ALL ; } r = dev->vhost_ops->vhost_call (dev,VHOST_SET_FEATURES , &features);return r <0 ? -errno :0 ;
@@ -860,7 +860,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, .priority = 10 }; hdev->migration_blocker =NULL ; -if (!(hdev->features & (0x1 <<VHOST_F_LOG_ALL ))) { +if (!(hdev->features & (0x1ULL <<VHOST_F_LOG_ALL ))) {error_setg (&hdev->migration_blocker,"Migration disabled: vhost lacks VHOST_F_LOG_ALL feature." );migrate_add_blocker (hdev->migration_blocker);
@@ -1003,12 +1003,12 @@ void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n,assert (r >=0 ); } -unsigned vhost_get_features (struct vhost_dev *hdev,const int *feature_bits, -unsigned features) +uint64_t vhost_get_features (struct vhost_dev *hdev,const int *feature_bits, +uint64_t features) {const int *bit = feature_bits;while (*bit !=VHOST_INVALID_FEATURE_BIT ) { -unsigned bit_mask = (1 << *bit); +uint64_t bit_mask = (1ULL << *bit);if (!(hdev->features & bit_mask)) { features &= ~bit_mask; }
@@ -1018,11 +1018,11 @@ unsigned vhost_get_features(struct vhost_dev *hdev, const int *feature_bits, }void vhost_ack_features (struct vhost_dev *hdev,const int *feature_bits, -unsigned features) +uint64_t features) {const int *bit = feature_bits;while (*bit !=VHOST_INVALID_FEATURE_BIT ) { -unsigned bit_mask = (1 << *bit); +uint64_t bit_mask = (1ULL << *bit);if (features & bit_mask) { hdev->acked_features |= bit_mask; }
include/hw/virtio/vhost.h +3 -3
@@ -72,8 +72,8 @@ bool vhost_virtqueue_pending(struct vhost_dev *hdev, int n);*/ void vhost_virtqueue_mask (struct vhost_dev *hdev,VirtIODevice *vdev,int n,bool mask); -unsigned vhost_get_features (struct vhost_dev *hdev,const int *feature_bits, -unsigned features); +uint64_t vhost_get_features (struct vhost_dev *hdev,const int *feature_bits, +uint64_t features);void vhost_ack_features (struct vhost_dev *hdev,const int *feature_bits, -unsigned features); +uint64_t features);#endif
include/net/vhost_net.h +2 -2
@@ -22,8 +22,8 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs, int total_queues);void vhost_net_cleanup (VHostNetState *net); -unsigned vhost_net_get_features (VHostNetState *net,unsigned features); -void vhost_net_ack_features (VHostNetState *net,unsigned features); +uint64_t vhost_net_get_features (VHostNetState *net,uint64_t features); +void vhost_net_ack_features (VHostNetState *net,uint64_t features);bool vhost_net_virtqueue_pending (VHostNetState *net,int n); void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev,
Signature · 1 line
1.7.9.5
Re: [PATCH RFC v6 03/20] virtio: feature bit manipulation helpers
In reply to Cornelia HuckQuoted 9 lines · On Thu, 11 Dec 2014 14:25:05 +0100 Cornelia Huck <[email protected]>…
Add virtio_{add,clear}_feature helper functions for manipulating a feature bits variable. This has some benefits over open coding:
- add check that the bit is in a sane range
- make it obvious at a glance what is going on
- have a central point to change when we want to extend feature bitsConvert existing code manipulating features to use the new helpers.
Signed-off-by Cornelia Huck <[email protected]>
Quoted 10 lines
--- hw/9pfs/virtio-9p-device.c | 2 +- hw/block/virtio-blk.c | 16 ++++++++-------- hw/char/virtio-serial-bus.c | 2 +- hw/net/virtio-net.c | 34 +++++++++++++++++----------------- hw/s390x/virtio-ccw.c | 4 ++-- hw/virtio/virtio-mmio.c | 2 +- hw/virtio/virtio-pci.c | 4 ++-- include/hw/virtio/virtio.h | 12 ++++++++++++ 8 files changed, 44 insertions(+), 32 deletions(-)
Patch looks fine to me.
Re: [Qemu-devel] [PATCH RFC v6 03/20] virtio: feature bit manipulation helpers
In reply to Cornelia HuckQuoted 9 lines · On Thu, 11 Dec 2014 14:25:05 +0100 Cornelia Huck <[email protected]>…
Add virtio_{add,clear}_feature helper functions for manipulating a feature bits variable. This has some benefits over open coding:
- add check that the bit is in a sane range
- make it obvious at a glance what is going on
- have a central point to change when we want to extend feature bitsConvert existing code manipulating features to use the new helpers.
Signed-off-by Cornelia Huck <[email protected]>
Quoted 10 lines
--- hw/9pfs/virtio-9p-device.c | 2 +- hw/block/virtio-blk.c | 16 ++++++++-------- hw/char/virtio-serial-bus.c | 2 +- hw/net/virtio-net.c | 34 +++++++++++++++++----------------- hw/s390x/virtio-ccw.c | 4 ++-- hw/virtio/virtio-mmio.c | 2 +- hw/virtio/virtio-pci.c | 4 ++-- include/hw/virtio/virtio.h | 12 ++++++++++++ 8 files changed, 44 insertions(+), 32 deletions(-)
Patch looks fine to me.
Re: [PATCH RFC v6 04/20] virtio: add feature checking helpers
In reply to Cornelia HuckQuoted 7 lines · On Thu, 11 Dec 2014 14:25:06 +0100 Cornelia Huck <[email protected]>…
Add a helper function for checking whether a bit is set in the guest features for a vdev as well as one that works on a feature bit set.
Convert code that open-coded this: It cleans up the code and makes it easier to extend the guest feature bits.
Signed-off-by Cornelia Huck <[email protected]>
...
hw/scsi/virtio-scsi.c static int virtio_scsi_parse_req(VirtIOSCSIReq *req, · line 147
Quoted 10 lines
hw/scsi/virtio-scsi.c +1
-1@@ -144,7 +144,7 @@ static int virtio_scsi_parse_req(VirtIOSCSIReq *req,* * TODO: always disable this workaround for virtio 1.0 devices. */ -if ((vdev->guest_features &VIRTIO_F_ANY_LAYOUT ) ==0 ) { +if (!virtio_has_feature (vdev,VIRTIO_F_ANY_LAYOUT )) {
Wait ... this does not only look like a clean-up, but also like a bug-fix to me, since it should have been "(1 << VIRTIO_F_ANY_LAYOUT)" instead of "VIRTIO_F_ANY_LAYOUT" in the original code instead?
So in case this patch queue takes a little bit longer 'til it gets upstream, do we might want to submit a separate patch for fixing this issue first?
Quoted 30 lines
hw/scsi/virtio-scsi.c +3
-3req_size = req->elem.out_sg[0 ].iov_len; resp_size = req->elem.in_sg[0 ].iov_len; }@@ -748,7 +748,7 @@ static void virtio_scsi_change(SCSIBus *bus, SCSIDevice *dev, SCSISense sense)VirtIOSCSI *s =container_of (bus, VirtIOSCSI, bus);VirtIODevice *vdev =VIRTIO_DEVICE (s); -if (((vdev->guest_features >>VIRTIO_SCSI_F_CHANGE ) &1 ) && +if (virtio_has_feature (vdev,VIRTIO_SCSI_F_CHANGE ) && dev->type !=TYPE_ROM ) {virtio_scsi_push_event (s, dev,VIRTIO_SCSI_T_PARAM_CHANGE , sense.asc | (sense.ascq <<8 ));@@ -769,7 +769,7 @@ static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev,blk_op_block_all (sd->conf.blk, s->blocker); } -if ((vdev->guest_features >>VIRTIO_SCSI_F_HOTPLUG ) &1 ) { +if (virtio_has_feature (vdev,VIRTIO_SCSI_F_HOTPLUG )) {virtio_scsi_push_event (s, sd,VIRTIO_SCSI_T_TRANSPORT_RESET ,VIRTIO_SCSI_EVT_RESET_RESCAN );@@ -783,7 +783,7 @@ static void virtio_scsi_hotunplug(HotplugHandler *hotplug_dev, DeviceState *dev,VirtIOSCSI *s =VIRTIO_SCSI (vdev);SCSIDevice *sd =SCSI_DEVICE (dev); -if ((vdev->guest_features >>VIRTIO_SCSI_F_HOTPLUG ) &1 ) { +if (virtio_has_feature (vdev,VIRTIO_SCSI_F_HOTPLUG )) {virtio_scsi_push_event (s, sd,VIRTIO_SCSI_T_TRANSPORT_RESET ,VIRTIO_SCSI_EVT_RESET_REMOVED );
...
Quoted 9 lines
include/hw/virtio/virtio.h +1
-0@@ -278,6 +278,17 @@ static inline void virtio_clear_feature(uint32_t *features, unsigned int fbit) *features &= ~(1 << fbit); } +static inline bool __virtio_has_feature (uint32_t features,unsigned int fbit)
include/hw/virtio/virtio.h static inline void virtio_clear_feature(uint32_t *features, unsigned int fbit) · line 291
Quoted 10 lines
include/hw/virtio/virtio.h +10
-0+{ +assert (fbit <32 ); +return !!(features & (1 << fbit)); +} + +static inline bool virtio_has_feature (VirtIODevice *vdev,unsigned int fbit) +{ +return __virtio_has_feature (vdev->guest_features, fbit); +} +
I've got to say that I'm a little bit unhappy with the naming of the functions - and in contrast to the Linux kernel code, I think it is also quite uncommon in the QEMU sources to use function names with double underscores at the beginning.
Could you maybe rename the second function to "virtio_vdev_has_feature" instead? And then remove the double underscores from the first function?
Thomas
Re: [Qemu-devel] [PATCH RFC v6 04/20] virtio: add feature checking helpers
In reply to Cornelia HuckQuoted 7 lines · On Thu, 11 Dec 2014 14:25:06 +0100 Cornelia Huck <[email protected]>…
Add a helper function for checking whether a bit is set in the guest features for a vdev as well as one that works on a feature bit set.
Convert code that open-coded this: It cleans up the code and makes it easier to extend the guest feature bits.
Signed-off-by Cornelia Huck <[email protected]>
...
hw/scsi/virtio-scsi.c static int virtio_scsi_parse_req(VirtIOSCSIReq *req, · line 147
Quoted 10 lines
hw/scsi/virtio-scsi.c +1
-1@@ -144,7 +144,7 @@ static int virtio_scsi_parse_req(VirtIOSCSIReq *req,* * TODO: always disable this workaround for virtio 1.0 devices. */ -if ((vdev->guest_features &VIRTIO_F_ANY_LAYOUT ) ==0 ) { +if (!virtio_has_feature (vdev,VIRTIO_F_ANY_LAYOUT )) {
Wait ... this does not only look like a clean-up, but also like a bug-fix to me, since it should have been "(1 << VIRTIO_F_ANY_LAYOUT)" instead of "VIRTIO_F_ANY_LAYOUT" in the original code instead?
So in case this patch queue takes a little bit longer 'til it gets upstream, do we might want to submit a separate patch for fixing this issue first?
Quoted 30 lines
hw/scsi/virtio-scsi.c +3
-3req_size = req->elem.out_sg[0 ].iov_len; resp_size = req->elem.in_sg[0 ].iov_len; }@@ -748,7 +748,7 @@ static void virtio_scsi_change(SCSIBus *bus, SCSIDevice *dev, SCSISense sense)VirtIOSCSI *s =container_of (bus, VirtIOSCSI, bus);VirtIODevice *vdev =VIRTIO_DEVICE (s); -if (((vdev->guest_features >>VIRTIO_SCSI_F_CHANGE ) &1 ) && +if (virtio_has_feature (vdev,VIRTIO_SCSI_F_CHANGE ) && dev->type !=TYPE_ROM ) {virtio_scsi_push_event (s, dev,VIRTIO_SCSI_T_PARAM_CHANGE , sense.asc | (sense.ascq <<8 ));@@ -769,7 +769,7 @@ static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev,blk_op_block_all (sd->conf.blk, s->blocker); } -if ((vdev->guest_features >>VIRTIO_SCSI_F_HOTPLUG ) &1 ) { +if (virtio_has_feature (vdev,VIRTIO_SCSI_F_HOTPLUG )) {virtio_scsi_push_event (s, sd,VIRTIO_SCSI_T_TRANSPORT_RESET ,VIRTIO_SCSI_EVT_RESET_RESCAN );@@ -783,7 +783,7 @@ static void virtio_scsi_hotunplug(HotplugHandler *hotplug_dev, DeviceState *dev,VirtIOSCSI *s =VIRTIO_SCSI (vdev);SCSIDevice *sd =SCSI_DEVICE (dev); -if ((vdev->guest_features >>VIRTIO_SCSI_F_HOTPLUG ) &1 ) { +if (virtio_has_feature (vdev,VIRTIO_SCSI_F_HOTPLUG )) {virtio_scsi_push_event (s, sd,VIRTIO_SCSI_T_TRANSPORT_RESET ,VIRTIO_SCSI_EVT_RESET_REMOVED );
...
Quoted 9 lines
include/hw/virtio/virtio.h +1
-0@@ -278,6 +278,17 @@ static inline void virtio_clear_feature(uint32_t *features, unsigned int fbit) *features &= ~(1 << fbit); } +static inline bool __virtio_has_feature (uint32_t features,unsigned int fbit)
include/hw/virtio/virtio.h static inline void virtio_clear_feature(uint32_t *features, unsigned int fbit) · line 291
Quoted 10 lines
include/hw/virtio/virtio.h +10
-0+{ +assert (fbit <32 ); +return !!(features & (1 << fbit)); +} + +static inline bool virtio_has_feature (VirtIODevice *vdev,unsigned int fbit) +{ +return __virtio_has_feature (vdev->guest_features, fbit); +} +
I've got to say that I'm a little bit unhappy with the naming of the functions - and in contrast to the Linux kernel code, I think it is also quite uncommon in the QEMU sources to use function names with double underscores at the beginning.
Could you maybe rename the second function to "virtio_vdev_has_feature" instead? And then remove the double underscores from the first function?
Thomas
Michael S. Tsirkin
maintainerRe: [Qemu-devel] [PATCH RFC v6 04/20] virtio: add feature checking helpers
Quoted 26 lines · Thomas Huth
Quoted 7 lines · On Thu, 11 Dec 2014 14:25:06 +0100 Cornelia Huck <[email protected]>…
Add a helper function for checking whether a bit is set in the guest features for a vdev as well as one that works on a feature bit set.
Convert code that open-coded this: It cleans up the code and makes it easier to extend the guest feature bits.
Signed-off-by Cornelia Huck <[email protected]>...
hw/scsi/virtio-scsi.c static int virtio_scsi_parse_req(VirtIOSCSIReq *req, · line 147
Quoted 10 lines
hw/scsi/virtio-scsi.c +1
-1@@ -144,7 +144,7 @@ static int virtio_scsi_parse_req(VirtIOSCSIReq *req,* * TODO: always disable this workaround for virtio 1.0 devices. */ -if ((vdev->guest_features &VIRTIO_F_ANY_LAYOUT ) ==0 ) { +if (!virtio_has_feature (vdev,VIRTIO_F_ANY_LAYOUT )) {Wait ... this does not only look like a clean-up, but also like a bug-fix to me, since it should have been "(1 <<
VIRTIO_F_ANY_LAYOUT)" instead of "VIRTIO_F_ANY_LAYOUT" in the original code instead?
Quoted 3 lines
So in case this patch queue takes a little bit longer 'til it gets upstream, do we might want to submit a separate patch for fixing this issue first?
Yes, please do.
Quoted 60 lines
Quoted 30 lines
hw/scsi/virtio-scsi.c +3
-3req_size = req->elem.out_sg[0 ].iov_len; resp_size = req->elem.in_sg[0 ].iov_len; }@@ -748,7 +748,7 @@ static void virtio_scsi_change(SCSIBus *bus, SCSIDevice *dev, SCSISense sense)VirtIOSCSI *s =container_of (bus, VirtIOSCSI, bus);VirtIODevice *vdev =VIRTIO_DEVICE (s); -if (((vdev->guest_features >>VIRTIO_SCSI_F_CHANGE ) &1 ) && +if (virtio_has_feature (vdev,VIRTIO_SCSI_F_CHANGE ) && dev->type !=TYPE_ROM ) {virtio_scsi_push_event (s, dev,VIRTIO_SCSI_T_PARAM_CHANGE , sense.asc | (sense.ascq <<8 ));@@ -769,7 +769,7 @@ static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev,blk_op_block_all (sd->conf.blk, s->blocker); } -if ((vdev->guest_features >>VIRTIO_SCSI_F_HOTPLUG ) &1 ) { +if (virtio_has_feature (vdev,VIRTIO_SCSI_F_HOTPLUG )) {virtio_scsi_push_event (s, sd,VIRTIO_SCSI_T_TRANSPORT_RESET ,VIRTIO_SCSI_EVT_RESET_RESCAN );@@ -783,7 +783,7 @@ static void virtio_scsi_hotunplug(HotplugHandler *hotplug_dev, DeviceState *dev,VirtIOSCSI *s =VIRTIO_SCSI (vdev);SCSIDevice *sd =SCSI_DEVICE (dev); -if ((vdev->guest_features >>VIRTIO_SCSI_F_HOTPLUG ) &1 ) { +if (virtio_has_feature (vdev,VIRTIO_SCSI_F_HOTPLUG )) {virtio_scsi_push_event (s, sd,VIRTIO_SCSI_T_TRANSPORT_RESET ,VIRTIO_SCSI_EVT_RESET_REMOVED );...
Quoted 9 lines
include/hw/virtio/virtio.h +1
-0@@ -278,6 +278,17 @@ static inline void virtio_clear_feature(uint32_t *features, unsigned int fbit) *features &= ~(1 << fbit); } +static inline bool __virtio_has_feature (uint32_t features,unsigned int fbit)include/hw/virtio/virtio.h static inline void virtio_clear_feature(uint32_t *features, unsigned int fbit) · line 291
Quoted 10 lines
include/hw/virtio/virtio.h +10
-0+{ +assert (fbit <32 ); +return !!(features & (1 << fbit)); +} + +static inline bool virtio_has_feature (VirtIODevice *vdev,unsigned int fbit) +{ +return __virtio_has_feature (vdev->guest_features, fbit); +} +I've got to say that I'm a little bit unhappy with the naming of the functions - and in contrast to the Linux kernel code, I think it is also quite uncommon in the QEMU sources to use function names with double underscores at the beginning.
Could you maybe rename the second function to "
virtio_vdev_has_feature" instead? And then remove the double underscores from the first function?Thomas
Re: [Qemu-devel] [PATCH RFC v6 04/20] virtio: add feature checking helpers
Quoted 12 lines · On Thu, 11 Dec 2014 19:05:26 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 11 lines · Thomas Huth
Quoted 7 lines · On Thu, 11 Dec 2014 14:25:06 +0100 Cornelia Huck <[email protected]>…
Add a helper function for checking whether a bit is set in the guest features for a vdev as well as one that works on a feature bit set.
Convert code that open-coded this: It cleans up the code and makes it easier to extend the guest feature bits.
Signed-off-by Cornelia Huck <[email protected]>...
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
hw/scsi/virtio-scsi.c +0
-0@@ -144,7 +144,7 @@ static int virtio_scsi_parse_req(VirtIOSCSIReq *req,* Quoted 8 lines
hw/scsi/virtio-scsi.c static int virtio_scsi_parse_req(VirtIOSCSIReq *req, · line 147
Quoted 4 lines
hw/scsi/virtio-scsi.c +1
-1* TODO: always disable this workaround for virtio 1.0 devices. */ -if ((vdev->guest_features &VIRTIO_F_ANY_LAYOUT ) ==0 ) { +if (!virtio_has_feature (vdev,VIRTIO_F_ANY_LAYOUT )) {Wait ... this does not only look like a clean-up, but also like a bug-fix to me, since it should have been "(1 <<
VIRTIO_F_ANY_LAYOUT)" instead of "VIRTIO_F_ANY_LAYOUT" in the original code instead?
I've clearly been looking at this stuff for too long, as I didn't even notice this bug :)
Quoted 6 lines
Quoted 4 lines
So in case this patch queue takes a little bit longer 'til it gets upstream, do we might want to submit a separate patch for fixing this issue first?
Yes, please do.
OK, will send.
Re: [Qemu-devel] [PATCH RFC v6 05/20] virtio: support more feature bits
In reply to Cornelia HuckQuoted 31 lines · On Thu, 11 Dec 2014 14:25:07 +0100 Cornelia Huck <[email protected]>…
With virtio-1, we support more than 32 feature bits. Let's extend both host and guest features to 64, which should suffice for a while.
vhost and migration have been ignored for now.
Signed-off-by Cornelia Huck <[email protected]>--- hw/9pfs/virtio-9p-device.c | 2 +- hw/block/virtio-blk.c | 2 +- hw/char/virtio-serial-bus.c | 2 +- hw/core/qdev-properties.c | 58 +++++++++++++++++++++++++++++++++++++++ hw/net/virtio-net.c | 22 +++++++-------- hw/s390x/s390-virtio-bus.c | 3 +- hw/s390x/s390-virtio-bus.h | 2 +- hw/s390x/virtio-ccw.c | 39 +++++++++++++++----------- hw/s390x/virtio-ccw.h | 5 +--- hw/scsi/vhost-scsi.c | 3 +- hw/scsi/virtio-scsi.c | 4 +-- hw/virtio/virtio-balloon.c | 2 +- hw/virtio/virtio-bus.c | 6 ++-- hw/virtio/virtio-mmio.c | 4 +-- hw/virtio/virtio-pci.c | 3 +- hw/virtio/virtio-pci.h | 2 +- hw/virtio/virtio-rng.c | 2 +- hw/virtio/virtio.c | 13 +++++---- include/hw/qdev-properties.h | 12 ++++++++ include/hw/virtio/virtio-bus.h | 8 +++--- include/hw/virtio/virtio-net.h | 46 +++++++++++++++---------------- include/hw/virtio/virtio-scsi.h | 6 ++-- include/hw/virtio/virtio.h | 38 ++++++++++++++----------- 23 files changed, 184 insertions(+), 100 deletions(-)
...
Quoted 4 lines
hw/net/virtio-net.c +0
-0
...
Quoted 10 lines
hw/net/virtio-net.c +1
-1@@ -514,7 +514,7 @@ static inline uint64_t virtio_net_supported_guest_offloads(VirtIONet *n)return virtio_net_guest_offloads_by_features (vdev->guest_features); } -static void virtio_net_set_features (VirtIODevice *vdev,uint32_t features) +static void virtio_net_set_features (VirtIODevice *vdev,uint64_t features) {VirtIONet *n =VIRTIO_NET (vdev);int i;
hw/net/virtio-net.c static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf, size_t · line 1039
Quoted 5 lines
hw/net/virtio-net.c +1
-1@@ -1036,7 +1036,7 @@ static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf, size_treturn -1 ; error_report("virtio-net unexpected empty queue: " "i %zd mergeable %d offset %zd, size %zd, " - "guest hdr len %zd, host hdr len %zd guest features 0x%x", + "guest hdr len %zd, host hdr len %zd guest features 0x%lx",
I think you need a different format string like PRIx64 here so that the code also works right on a 32-bit system (where long is only 32-bit).
Quoted 3 lines
hw/net/virtio-net.c +0
-0i, n->mergeable_rx_bufs, offset, size, n->guest_hdr_len, n->host_hdr_len, vdev->guest_features);exit (1 );
...
Quoted 21 lines
hw/s390x/virtio-ccw.c +4
-2@@ -371,8 +371,10 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) }else { features.index =ldub_phys (&address_space_memory, ccw.cda +sizeof (features.features)); -if (features.index <ARRAY_SIZE (dev->host_features)) { - features.features = dev->host_features[features.index]; +if (features.index ==0 ) { + features.features = (uint32_t )dev->host_features; + }else if (features.index ==1 ) { + features.features = (uint32_t )(dev->host_features >>32 ); }else {/* Return zeroes if the guest supports more feature bits. */ features.features =0 ;@@ -399,8 +401,14 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) features.index =ldub_phys (&address_space_memory, ccw.cda +sizeof (features.features)); features.features =ldl_le_phys (&address_space_memory, ccw.cda);
hw/s390x/virtio-ccw.c static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) · line 411
Quoted 10 lines
hw/s390x/virtio-ccw.c +8
-2-if (features.index <ARRAY_SIZE (dev->host_features)) { -virtio_set_features (vdev, features.features); +if (features.index ==0 ) { +virtio_set_features (vdev, + (vdev->guest_features &0xffffffff00000000 ) | + features.features); + }else if (features.index ==1 ) { +virtio_set_features (vdev, + (vdev->guest_features &0x00000000ffffffff ) | + ((uint64_t )features.features <<32 ));
The long constants 0xffffffff00000000 and 0x00000000ffffffff should probably get an ULL suffix.
...
hw/virtio/virtio.c void virtio_reset(void *opaque) · line 596
Quoted 9 lines
hw/virtio/virtio.c +1
-0@@ -593,6 +593,7 @@ void virtio_reset(void *opaque) } vdev->guest_features =0 ; +
Unnecessary white space change?
hw/virtio/virtio.c void virtio_save(VirtIODevice *vdev, QEMUFile *f) · line 929
Quoted 10 lines
hw/virtio/virtio.c +2
-1vdev->queue_sel =0 ; vdev->status =0 ; vdev->isr =0 ;@@ -924,7 +925,8 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)qemu_put_8s (f, &vdev->status);qemu_put_8s (f, &vdev->isr);qemu_put_be16s (f, &vdev->queue_sel); -qemu_put_be32s (f, &vdev->guest_features); +/* XXX features >= 32 */ +qemu_put_be32s (f, (uint32_t *)&vdev->guest_features);
Casting a uint64_t* to a uint32_t* here sounds very wrong - this likely only works on little endian sytems, but certainly not on big-endian systems.
If you do not want to extend this for 64-bit right from the beginning, I think you've got to use a temporary 32-bit variable to get this right.
...
hw/virtio/virtio.c int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) · line 1014
Quoted 10 lines
hw/virtio/virtio.c +2
-1@@ -1005,9 +1007,10 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) }qemu_get_be32s (f, &features); +/* XXX features >= 32 */ if (virtio_set_features (vdev, features) <0 ) { supported_features = k->get_features (qbus->parent); -error_report ("Features 0x%x unsupported. Allowed features: 0x%x" , +error_report ("Features 0x%x unsupported. Allowed features: 0x%lx" , features, supported_features);
You'll likely need the PRIx64 format here, too.
Quoted 15 lines
hw/virtio/virtio.c +0
-0return -1 ; }include/hw/qdev-properties.h +1
-0@@ -6,6 +6,7 @@/*** qdev-properties.c ***/ extern PropertyInfo qdev_prop_bit; +extern PropertyInfo qdev_prop_bit64;extern PropertyInfo qdev_prop_bool;extern PropertyInfo qdev_prop_uint8;extern PropertyInfo qdev_prop_uint16;
include/hw/qdev-properties.h extern PropertyInfo qdev_prop_arraylen; · line 57
Quoted 6 lines
include/hw/qdev-properties.h +3
-0@@ -51,6 +52,17 @@ extern PropertyInfo qdev_prop_arraylen; .defval = (bool)_defval, \ } +#define DEFINE_PROP_BIT64 (_name, _state, _field, _bit, _defval) { \ + .name = (_name), \ + .info = &(qdev_prop_bit64), \
No need for the paranthesis around qdev_prop_bit64 here?
include/hw/qdev-properties.h extern PropertyInfo qdev_prop_arraylen; · line 63
Quoted 6 lines
include/hw/qdev-properties.h +6
-0+ .bitnr = (_bit), \ + .offset = offsetof(_state, _field) \ + + type_check(uint64_t,typeof_field(_state, _field)), \ + .qtype = QTYPE_QBOOL, \ + .defval = (bool)_defval, \ + }
Thomas
Re: [Qemu-devel] [PATCH RFC v6 04/20] virtio: add feature checking helpers
In reply to Thomas HuthQuoted 17 lines · On Thu, 11 Dec 2014 15:46:23 +0100 Thomas Huth <[email protected]> wrote:
include/hw/virtio/virtio.h static inline void virtio_clear_feature(uint32_t *features, unsigned int fbit) · line 291
Quoted 11 lines
include/hw/virtio/virtio.h +11
-0+static inline bool __virtio_has_feature (uint32_t features,unsigned int fbit) +{ +assert (fbit <32 ); +return !!(features & (1 << fbit)); +} + +static inline bool virtio_has_feature (VirtIODevice *vdev,unsigned int fbit) +{ +return __virtio_has_feature (vdev->guest_features, fbit); +} +I've got to say that I'm a little bit unhappy with the naming of the functions - and in contrast to the Linux kernel code, I think it is also quite uncommon in the QEMU sources to use function names with double underscores at the beginning.
Quoted 2 lines
Could you maybe rename the second function to "
virtio_vdev_has_feature" instead? And then remove the double underscores from the first function?
Renamed the functions just like this.
Re: [Qemu-devel] [PATCH RFC v6 05/20] virtio: support more feature bits
In reply to Thomas HuthQuoted 10 lines · On Fri, 12 Dec 2014 11:06:40 +0100 Thomas Huth <[email protected]> wrote:
Quoted 6 lines · On Thu, 11 Dec 2014 14:25:07 +0100 Cornelia Huck <[email protected]>…
With virtio-1, we support more than 32 feature bits. Let's extend both host and guest features to 64, which should suffice for a while.
vhost and migration have been ignored for now.
Signed-off-by Cornelia Huck <[email protected]>
Quoted 9 lines
hw/net/virtio-net.c static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf, size_t · line 1039
Quoted 6 lines
hw/net/virtio-net.c +1
-1@@ -1036,7 +1036,7 @@ static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf, size_treturn -1 ; error_report("virtio-net unexpected empty queue: " "i %zd mergeable %d offset %zd, size %zd, " - "guest hdr len %zd, host hdr len %zd guest features 0x%x", + "guest hdr len %zd, host hdr len %zd guest features 0x%lx",I think you need a different format string like PRIx64 here so that the code also works right on a 32-bit system (where long is only 32-bit).
Reminder to self: set up cross-compile again.
Quoted 14 lines
Quoted 14 lines
hw/net/virtio-net.c +3
-2i, n->mergeable_rx_bufs, offset, size, n->guest_hdr_len, n->host_hdr_len, vdev->guest_features);exit (1 );@@ -399,8 +401,14 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) features.index =ldub_phys (&address_space_memory, ccw.cda +sizeof (features.features)); features.features =ldl_le_phys (&address_space_memory, ccw.cda); -if (features.index <ARRAY_SIZE (dev->host_features)) { -virtio_set_features (vdev, features.features); +if (features.index ==0 ) { + virtio_set_features(vdev, + (vdev->guest_features & 0xffffffff00000000) |
Quoted 8 lines
hw/s390x/virtio-ccw.c static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) · line 411
Quoted 5 lines
hw/s390x/virtio-ccw.c +5
-0+ features.features); + }else if (features.index ==1 ) { +virtio_set_features (vdev, + (vdev->guest_features &0x00000000ffffffff ) | + ((uint64_t )features.features <<32 ));The long constants
0xffffffff00000000and0x00000000ffffffffshould probably get an ULL suffix.
Probably.
Quoted 7 lines
hw/virtio/virtio.c void virtio_reset(void *opaque) · line 596
Quoted 5 lines
hw/virtio/virtio.c +1
-0@@ -593,6 +593,7 @@ void virtio_reset(void *opaque) } vdev->guest_features =0 ; +Unnecessary white space change?
Crept in during various rebase sessions :)
Quoted 17 lines
hw/virtio/virtio.c void virtio_save(VirtIODevice *vdev, QEMUFile *f) · line 929
Quoted 11 lines
hw/virtio/virtio.c +2
-1vdev->queue_sel =0 ; vdev->status =0 ; vdev->isr =0 ;@@ -924,7 +925,8 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)qemu_put_8s (f, &vdev->status);qemu_put_8s (f, &vdev->isr);qemu_put_be16s (f, &vdev->queue_sel); -qemu_put_be32s (f, &vdev->guest_features); +/* XXX features >= 32 */ +qemu_put_be32s (f, (uint32_t *)&vdev->guest_features);Casting a uint64_t* to a uint32_t* here sounds very wrong - this likely only works on little endian sytems, but certainly not on big-endian systems.
If you do not want to extend this for 64-bit right from the beginning, I think you've got to use a temporary 32-bit variable to get this right.
Hm... always store the old 32 bits here, then store the new 32 bits later? Should be able to get that compatible.
Quoted 5 lines
include/hw/qdev-properties.h extern PropertyInfo qdev_prop_arraylen; · line 57
Quoted 3 lines
include/hw/qdev-properties.h +3
-0+#define DEFINE_PROP_BIT64 (_name, _state, _field, _bit, _defval) { \ + .name = (_name), \ + .info = &(qdev_prop_bit64), \No need for the paranthesis around
qdev_prop_bit64here?
Straight copy&paste :) I'd prefer to keep the same style for all #defines here.
Quoted 7 lines
Quoted 7 lines
include/hw/qdev-properties.h +6
-0+ .bitnr = (_bit), \ + .offset = offsetof(_state, _field) \ + + type_check(uint64_t,typeof_field(_state, _field)), \ + .qtype = QTYPE_QBOOL, \ + .defval = (bool)_defval, \ + }
Re: [Qemu-devel] [PATCH RFC v6 12/20] virtio: disallow late feature changes for virtio-1
In reply to Cornelia HuckQuoted 15 lines · On Thu, 11 Dec 2014 14:25:14 +0100 Cornelia Huck <[email protected]>…
For virtio-1 devices, the driver must not attempt to set feature bits after it set
FEATURES_OKin the device status. Simply reject it in that case.Signed-off-by Cornelia Huck <[email protected]>--- hw/virtio/virtio.c | 16 ++++++++++++++-- include/hw/virtio/virtio.h | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-)hw/virtio/virtio.c +0
-0
hw/virtio/virtio.c void virtio_save(VirtIODevice *vdev, QEMUFile *f) · line 981
Quoted 5 lines
hw/virtio/virtio.c +1
-1@@ -978,7 +978,7 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)vmstate_save_state (f, &vmstate_virtio, vdev); } -int virtio_set_features (VirtIODevice *vdev,uint64_t val) +static int __virtio_set_features (VirtIODevice *vdev,uint64_t val)
Maybe avoid the double underscores here? But unfortunately, I also fail to come up with a better suggestion for a name here ...
Quoted 6 lines
hw/virtio/virtio.c +0
-0{BusState *qbus =qdev_get_parent_bus (DEVICE (vdev));VirtioBusClass *vbusk =VIRTIO_BUS_GET_CLASS (qbus);@@ -994,6 +994,18 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t val)return bad ?-1 :0 ; }
hw/virtio/virtio.c int virtio_set_features(VirtIODevice *vdev, uint64_t val) · line 1005
Quoted 10 lines
hw/virtio/virtio.c +9
-0+int virtio_set_features (VirtIODevice *vdev,uint64_t val) +{ +/* +* The driver must not attempt to set features after feature negotiation +* has finished. +*/ +if (vdev->status &VIRTIO_CONFIG_S_FEATURES_OK ) { +return -EINVAL ; + }
Hmm, according to your patch description, the FEATURES_OK check only applies to virtio-1.0 devices ... so shouldn't there be a check for virtio-1 here? Or did I miss something?
hw/virtio/virtio.c int virtio_set_features(VirtIODevice *vdev, uint64_t val) · line 1007
Quoted 2 lines
hw/virtio/virtio.c +2
-0+return __virtio_set_features (vdev, val); +}
Thomas
Re: [Qemu-devel] [PATCH RFC v6 12/20] virtio: disallow late feature changes for virtio-1
Quoted 21 lines · On Fri, 12 Dec 2014 11:55:38 +0100 Thomas Huth <[email protected]> wrote:
Quoted 18 lines · On Thu, 11 Dec 2014 14:25:14 +0100 Cornelia Huck <[email protected]>…
For virtio-1 devices, the driver must not attempt to set feature bits after it set
FEATURES_OKin the device status. Simply reject it in that case.Signed-off-by Cornelia Huck <[email protected]>--- hw/virtio/virtio.c | 16 ++++++++++++++-- include/hw/virtio/virtio.h | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-)hw/virtio/virtio.c +0
-0@@ -978,7 +978,7 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)vmstate_save_state (f, &vmstate_virtio, vdev); }
Quoted 5 lines
hw/virtio/virtio.c void virtio_save(VirtIODevice *vdev, QEMUFile *f) · line 981
Quoted 2 lines
hw/virtio/virtio.c +1
-1-int virtio_set_features (VirtIODevice *vdev,uint64_t val) +static int __virtio_set_features (VirtIODevice *vdev,uint64_t val)Maybe avoid the double underscores here? But unfortunately, I also fail to come up with a better suggestion for a name here ...
virtio_set_features_nocheck()?
This function is only called within virtio.c anyway...
Quoted 8 lines
Quoted 8 lines
hw/virtio/virtio.c +0
-0{BusState *qbus =qdev_get_parent_bus (DEVICE (vdev));VirtioBusClass *vbusk =VIRTIO_BUS_GET_CLASS (qbus);@@ -994,6 +994,18 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t val)return bad ?-1 :0 ; }
Quoted 13 lines
hw/virtio/virtio.c int virtio_set_features(VirtIODevice *vdev, uint64_t val) · line 1005
Quoted 9 lines
hw/virtio/virtio.c +9
-0+int virtio_set_features (VirtIODevice *vdev,uint64_t val) +{ +/* +* The driver must not attempt to set features after feature negotiation +* has finished. +*/ +if (vdev->status &VIRTIO_CONFIG_S_FEATURES_OK ) { +return -EINVAL ; + }Hmm, according to your patch description, the
FEATURES_OKcheck only applies to virtio-1.0 devices ... so shouldn't there be a check for virtio-1 here? Or did I miss something?
A device in legacy mode will never have FEATURES_OK set. But it is a bit non-obvious - maybe adding a check for VERSION_1 does not hurt.
Quoted 5 lines
hw/virtio/virtio.c int virtio_set_features(VirtIODevice *vdev, uint64_t val) · line 1007
Quoted 3 lines
hw/virtio/virtio.c +2
-0+return __virtio_set_features (vdev, val); +}Thomas
Thomas Huth
Reviewed-byRe: [Qemu-devel] [PATCH RFC v6 12/20] virtio: disallow late feature changes for virtio-1
Quoted 24 lines · On Fri, 12 Dec 2014 12:18:25 +0100 Cornelia Huck <[email protected]>…
Quoted 21 lines · On Fri, 12 Dec 2014 11:55:38 +0100 Thomas Huth <[email protected]> wrote:
Quoted 18 lines · On Thu, 11 Dec 2014 14:25:14 +0100 Cornelia Huck <[email protected]>…
For virtio-1 devices, the driver must not attempt to set feature bits after it set
FEATURES_OKin the device status. Simply reject it in that case.Signed-off-by Cornelia Huck <[email protected]>--- hw/virtio/virtio.c | 16 ++++++++++++++-- include/hw/virtio/virtio.h | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-)hw/virtio/virtio.c +0
-0@@ -978,7 +978,7 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)vmstate_save_state (f, &vmstate_virtio, vdev); }
Quoted 7 lines
Quoted 5 lines
hw/virtio/virtio.c void virtio_save(VirtIODevice *vdev, QEMUFile *f) · line 981
Quoted 2 lines
hw/virtio/virtio.c +1
-1-int virtio_set_features (VirtIODevice *vdev,uint64_t val) +static int __virtio_set_features (VirtIODevice *vdev,uint64_t val)Maybe avoid the double underscores here? But unfortunately, I also fail to come up with a better suggestion for a name here ...
virtio_set_features_nocheck()?
Sounds ok to me.
Quoted 1 line
This function is only called within
virtio.canyway...
Right, so the double underscores should be ok here, too. (I still do not like them very much, but that's just my personal taste in this case)
Quoted 21 lines
Quoted 7 lines
Quoted 7 lines
hw/virtio/virtio.c +0
-0{BusState *qbus =qdev_get_parent_bus (DEVICE (vdev));VirtioBusClass *vbusk =VIRTIO_BUS_GET_CLASS (qbus);@@ -994,6 +994,18 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t val)return bad ?-1 :0 ; }Quoted 13 lines
hw/virtio/virtio.c int virtio_set_features(VirtIODevice *vdev, uint64_t val) · line 1005
Quoted 9 lines
hw/virtio/virtio.c +9
-0+int virtio_set_features (VirtIODevice *vdev,uint64_t val) +{ +/* +* The driver must not attempt to set features after feature negotiation +* has finished. +*/ +if (vdev->status &VIRTIO_CONFIG_S_FEATURES_OK ) { +return -EINVAL ; + }Hmm, according to your patch description, the
FEATURES_OKcheck only applies to virtio-1.0 devices ... so shouldn't there be a check for virtio-1 here? Or did I miss something?
Quoted 2 lines
A device in legacy mode will never have
FEATURES_OKset. But it is a bit non-obvious - maybe adding a check forVERSION_1does not hurt.
Ah, ok, right, and if it is a legacy device and has FEATURES_OK set, it is certainly a misbehavior wrt the legacy protocol. So it really should be ok or even good to _not_ check for virtio-1.0 here. So sorry for the confusion, I think now the patch is good as it is:
Michael S. Tsirkin
maintainerRe: [Qemu-devel] [PATCH RFC v6 17/20] virtio-net: enable virtio 1.0
In reply to Cornelia HuckQuoted 8 lines · Cornelia Huck
virtio-net (non-vhost) now should have everything in place to support virtio 1.0: let's enable the feature bit for it.
Note that
VIRTIO_F_VERSION_1is technically a transport feature; once every device is ready for virtio 1.0, we can move setting this feature bit out of the individual devices.Signed-off-by Cornelia Huck <[email protected]>
So to use this with e.g. tun, you need to make tun device LE. I posted a kernel patch [email protected] with TUNSETVNETLE/TUNGETVNETLE ioctls to support it.
But you still need to call them in qemu, and disable virtio-1.0 if not there.
Quoted 18 lines
--- hw/net/virtio-net.c | 1 + 1 file changed, 1 insertion(+)hw/net/virtio-net.c +1
-0@@ -473,6 +473,7 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features) }if (!get_vhost_net (nc->peer)) { +virtio_add_feature (&features,VIRTIO_F_VERSION_1 );return features; }return vhost_net_get_features (get_vhost_net (nc->peer), features);Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [PATCH RFC v6 17/20] virtio-net: enable virtio 1.0
Quoted 8 lines · On Tue, 16 Dec 2014 15:10:04 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 7 lines · Cornelia Huck
virtio-net (non-vhost) now should have everything in place to support virtio 1.0: let's enable the feature bit for it.
Note that
VIRTIO_F_VERSION_1is technically a transport feature; once every device is ready for virtio 1.0, we can move setting this feature bit out of the individual devices.
Quoted 8 lines
Quoted 1 line
Signed-off-by Cornelia Huck <[email protected]>So to use this with e.g. tun, you need to make tun device LE. I posted a kernel patch [email protected] with TUNSETVNETLE/TUNGETVNETLE ioctls to support it.
But you still need to call them in qemu, and disable virtio-1.0 if not there.
I had planned on playing with this a bit, but didn't come around to doing it. I'm afraid it will have to wait until next year.
Michael S. Tsirkin
maintainerRe: [Qemu-devel] [PATCH RFC v6 18/20] virtio: support revision-specific features
In reply to Cornelia HuckQuoted 6 lines · Cornelia Huck
Devices may support different sets of feature bits depending on which revision they're operating at. Let's give the transport a way to re-query the device about its features when the revision has been changed.
Signed-off-by Cornelia Huck <[email protected]>
So now we have both get_features and get_features_rev, and it's never clear which revision does host_features refer to. IMHO that's just too messy.
Let's add get_legacy_features and host_legacy_features instead?
Quoted 109 lines
--- hw/s390x/virtio-ccw.c | 12 ++++++++++-- hw/virtio/virtio-bus.c | 14 ++++++++++++-- include/hw/virtio/virtio-bus.h | 3 +++ include/hw/virtio/virtio.h | 3 +++ 4 files changed, 28 insertions(+), 4 deletions(-)hw/s390x/virtio-ccw.c +10
-2@@ -699,6 +699,10 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) } ret =0 ; dev->revision = revinfo.revision; +/* Re-evaluate which features the device wants to offer. */ + dev->host_features = +virtio_bus_get_vdev_features_rev (&dev->bus, dev->host_features, + dev->revision >=1 ?1 :0 );break ;default : ret = -ENOSYS ;@@ -712,6 +716,9 @@ static void virtio_sch_disable_cb(SubchDev *sch)VirtioCcwDevice *dev = sch->driver_data; dev->revision =-1 ; +/* Reset the device's features to legacy. */ + dev->host_features = +virtio_bus_get_vdev_features_rev (&dev->bus, dev->host_features,0 ); }static int virtio_ccw_device_init (VirtioCcwDevice *dev,VirtIODevice *vdev)@@ -853,8 +860,9 @@ static int virtio_ccw_device_init(VirtioCcwDevice *dev, VirtIODevice *vdev)virtio_add_feature (&dev->host_features,VIRTIO_F_NOTIFY_ON_EMPTY );virtio_add_feature (&dev->host_features,VIRTIO_F_BAD_FEATURE ); - dev->host_features =virtio_bus_get_vdev_features (&dev->bus, - dev->host_features); +/* All devices start in legacy mode. */ + dev->host_features = +virtio_bus_get_vdev_features_rev (&dev->bus, dev->host_features,0 );css_generate_sch_crws (sch->cssid, sch->ssid, sch->schid, parent->hotplugged,1 );hw/virtio/virtio-bus.c +12
-2@@ -97,18 +97,28 @@ size_t virtio_bus_get_vdev_config_len(VirtioBusState *bus) }/* Get the features of the plugged device. */ -uint64_t virtio_bus_get_vdev_features (VirtioBusState *bus, -uint64_t requested_features) +uint64_t virtio_bus_get_vdev_features_rev (VirtioBusState *bus, +uint64_t requested_features, +unsigned int revision) {VirtIODevice *vdev =virtio_bus_get_device (bus);VirtioDeviceClass *k;assert (vdev !=NULL ); k =VIRTIO_DEVICE_GET_CLASS (vdev); +if (revision >0 && k->get_features_rev) { +return k->get_features_rev (vdev, requested_features, revision); + }assert (k->get_features !=NULL );return k->get_features (vdev, requested_features); } +uint64_t virtio_bus_get_vdev_features (VirtioBusState *bus, +uint64_t requested_features) +{ +return virtio_bus_get_vdev_features_rev (bus, requested_features,0 ); +} +/* Get bad features of the plugged device. */ uint64_t virtio_bus_get_vdev_bad_features (VirtioBusState *bus) {include/hw/virtio/virtio-bus.h +3
-0@@ -84,6 +84,9 @@ size_t virtio_bus_get_vdev_config_len(VirtioBusState *bus);/* Get the features of the plugged device. */ uint64_t virtio_bus_get_vdev_features (VirtioBusState *bus,uint64_t requested_features); +uint64_t virtio_bus_get_vdev_features_rev (VirtioBusState *bus, +uint64_t requested_features, +unsigned int revision);/* Get bad features of the plugged device. */ uint64_t virtio_bus_get_vdev_bad_features (VirtioBusState *bus);/* Get config of the plugged device. */ include/hw/virtio/virtio.h +3
-0@@ -147,6 +147,9 @@ typedef struct VirtioDeviceClass {DeviceRealize realize;DeviceUnrealize unrealize;uint64_t (*get_features)(VirtIODevice *vdev,uint64_t requested_features); +uint64_t (*get_features_rev)(VirtIODevice *vdev, +uint64_t requested_features, +unsigned int revision);uint64_t (*bad_features)(VirtIODevice *vdev);void (*set_features)(VirtIODevice *vdev,uint64_t val);int (*validate_features)(VirtIODevice *vdev);Signature · 1 line
1.7.9.5
Michael S. Tsirkin
maintainerRe: [Qemu-devel] [PATCH RFC v6 19/20] virtio-blk: revision specific feature bits
In reply to Cornelia HuckQuoted 6 lines · Cornelia Huck
Wire up virtio-blk to provide different feature bit sets depending on whether legacy or v1.0 has been requested.
Note that
VERSION_1is still disabled due to missingANY_LAYOUTsupport.Signed-off-by Cornelia Huck <[email protected]>
So we need some way for devices to tell transports not to negotiate rev 1.
Does clearing VERSION_1 have this effect?
Quoted 43 lines
--- hw/block/virtio-blk.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)hw/block/virtio-blk.c +19
-0@@ -587,6 +587,24 @@ static uint64_t virtio_blk_get_features(VirtIODevice *vdev, uint64_t features)return features; } +static uint64_t virtio_blk_get_features_rev (VirtIODevice *vdev, +uint64_t features, +unsigned int revision) +{ +if (revision ==0 ) { +/* legacy */ +virtio_clear_feature (&features,VIRTIO_F_VERSION_1 ); +return virtio_blk_get_features (vdev, features); + } +/* virtio 1.0 or later */ +virtio_clear_feature (&features,VIRTIO_BLK_F_SCSI ); +virtio_clear_feature (&features,VIRTIO_BLK_F_CONFIG_WCE ); +virtio_clear_feature (&features,VIRTIO_BLK_F_WCE ); +/* we're still missing ANY_LAYOUT */ +/* virtio_add_feature(&features, VIRTIO_F_VERSION_1); */ +return features; +} +static void virtio_blk_set_status (VirtIODevice *vdev,uint8_t status) {VirtIOBlock *s =VIRTIO_BLK (vdev);@@ -821,6 +839,7 @@ static void virtio_blk_class_init(ObjectClass *klass, void *data) vdc->get_config = virtio_blk_update_config; vdc->set_config = virtio_blk_set_config; vdc->get_features = virtio_blk_get_features; + vdc->get_features_rev = virtio_blk_get_features_rev; vdc->set_status = virtio_blk_set_status; vdc->reset = virtio_blk_reset; vdc->save = virtio_blk_save_device;Signature · 1 line
1.7.9.5
Michael S. Tsirkin
maintainerRe: [Qemu-devel] [PATCH RFC v6 13/20] virtio: allow to fail setting status
In reply to Cornelia HuckQuoted 6 lines · Cornelia Huck
virtio-1 allow setting of the
FEATURES_OKstatus bit to fail if the negotiated feature bits are inconsistent: let's failvirtio_set_status()in that case and update virtio-ccw to post an error to the guest.Signed-off-by Cornelia Huck <[email protected]>
Right but a separate validate_features call is awkward. How about we defer virtio_set_features until FEATURES_OK, and teach virtio_set_features that it can fail?
Quoted 104 lines
--- hw/s390x/virtio-ccw.c | 20 ++++++++++++-------- hw/virtio/virtio.c | 24 +++++++++++++++++++++++- include/hw/virtio/virtio.h | 3 ++- 3 files changed, 37 insertions(+), 10 deletions(-)hw/s390x/virtio-ccw.c +12
-8@@ -555,15 +555,19 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)if (!(status &VIRTIO_CONFIG_S_DRIVER_OK )) {virtio_ccw_stop_ioeventfd (dev); } -virtio_set_status (vdev, status); -if (vdev->status ==0 ) { -virtio_reset (vdev); - } -if (status &VIRTIO_CONFIG_S_DRIVER_OK ) { -virtio_ccw_start_ioeventfd (dev); +if (virtio_set_status (vdev, status) ==0 ) { +if (vdev->status ==0 ) { +virtio_reset (vdev); + } +if (status &VIRTIO_CONFIG_S_DRIVER_OK ) { +virtio_ccw_start_ioeventfd (dev); + } + sch->curr_status.scsw.count = ccw.count -sizeof (status); + ret =0 ; + }else { +/* Trigger a command reject. */ + ret = -ENOSYS ; } - sch->curr_status.scsw.count = ccw.count -sizeof (status); - ret =0 ; }break ;case CCW_CMD_SET_IND :hw/virtio/virtio.c +23
-1@@ -543,15 +543,37 @@ void virtio_update_irq(VirtIODevice *vdev)virtio_notify_vector (vdev,VIRTIO_NO_VECTOR ); } -void virtio_set_status (VirtIODevice *vdev,uint8_t val) +static int virtio_validate_features (VirtIODevice *vdev) +{ +VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (vdev); + +if (k->validate_features) { +return k->validate_features (vdev); + }else { +return 0 ; + } +} + +int virtio_set_status (VirtIODevice *vdev,uint8_t val) {VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (vdev);trace_virtio_set_status (vdev, val); +if (virtio_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +if (!(vdev->status &VIRTIO_CONFIG_S_FEATURES_OK ) && + val &VIRTIO_CONFIG_S_FEATURES_OK ) { +int ret =virtio_validate_features (vdev); + +if (ret) { +return ret; + } + } + }if (k->set_status) { k->set_status (vdev, val); } vdev->status = val; +return 0 ; }bool target_words_bigendian (void );include/hw/virtio/virtio.h +2
-1@@ -149,6 +149,7 @@ typedef struct VirtioDeviceClass {uint64_t (*get_features)(VirtIODevice *vdev,uint64_t requested_features);uint64_t (*bad_features)(VirtIODevice *vdev);void (*set_features)(VirtIODevice *vdev,uint64_t val); +int (*validate_features)(VirtIODevice *vdev);void (*get_config)(VirtIODevice *vdev,uint8_t *config);void (*set_config)(VirtIODevice *vdev,const uint8_t *config);void (*reset)(VirtIODevice *vdev);@@ -233,7 +234,7 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align);void virtio_queue_notify (VirtIODevice *vdev,int n);uint16_t virtio_queue_vector (VirtIODevice *vdev,int n);void virtio_queue_set_vector (VirtIODevice *vdev,int n,uint16_t vector); -void virtio_set_status (VirtIODevice *vdev,uint8_t val); +int virtio_set_status (VirtIODevice *vdev,uint8_t val);void virtio_reset (void *opaque);void virtio_update_irq (VirtIODevice *vdev);int virtio_set_features (VirtIODevice *vdev,uint64_t val);Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [PATCH RFC v6 13/20] virtio: allow to fail setting status
Quoted 11 lines · On Tue, 30 Dec 2014 14:25:37 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 6 lines · Cornelia Huck
virtio-1 allow setting of the
FEATURES_OKstatus bit to fail if the negotiated feature bits are inconsistent: let's failvirtio_set_status()in that case and update virtio-ccw to post an error to the guest.Signed-off-by Cornelia Huck <[email protected]>Right but a separate
validate_featurescall is awkward. How about we defervirtio_set_featuresuntilFEATURES_OK, and teachvirtio_set_featuresthat it can fail?
Hm. But we would need to keep virtio_set_features() where it is called now for legacy devices, as they will never see FEATURES_OK, right? So we need to make this depending on revisions (or whatever the equivalent is for pci/mmio), as we cannot check for VERSION_1. Not sure whether this makes the code easier to follow.
Re: [Qemu-devel] [PATCH RFC v6 18/20] virtio: support revision-specific features
In reply to Michael S. TsirkinQuoted 6 lines · On Sun, 28 Dec 2014 10:32:06 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 5 lines · Cornelia Huck
Devices may support different sets of feature bits depending on which revision they're operating at. Let's give the transport a way to re-query the device about its features when the revision has been changed.
Quoted 6 lines
Quoted 1 line
Signed-off-by Cornelia Huck <[email protected]>So now we have both
get_featuresandget_features_rev, and it's never clear which revision doeshost_featuresrefer to. IMHO that's just too messy.
Let's addget_legacy_featuresandhost_legacy_featuresinstead?
I wanted to avoid touching anything that does not support version 1. And this interface might still work for later revisions, no?
Re: [PATCH RFC v6 19/20] virtio-blk: revision specific feature bits
In reply to Michael S. TsirkinQuoted 4 lines · On Sun, 28 Dec 2014 12:24:46 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 3 lines · Cornelia Huck
Wire up virtio-blk to provide different feature bit sets depending on whether legacy or v1.0 has been requested.
Quoted 8 lines
Quoted 3 lines
Note that
VERSION_1is still disabled due to missingANY_LAYOUTsupport.Signed-off-by Cornelia Huck <[email protected]>So we need some way for devices to tell transports not to negotiate rev 1.
Does clearingVERSION_1have this effect?
I just noticed that my patch is running in circles here.
What we need is probably the transport-dependent maximum revision checker (which at least for ccw is acting on a device) pass in the requested revision and check if the feature bits for the revision include VERSION_1. Does that make sense?
Re: [Qemu-devel] [PATCH RFC v6 19/20] virtio-blk: revision specific feature bits
In reply to Michael S. TsirkinQuoted 4 lines · On Sun, 28 Dec 2014 12:24:46 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 3 lines · Cornelia Huck
Wire up virtio-blk to provide different feature bit sets depending on whether legacy or v1.0 has been requested.
Quoted 8 lines
Quoted 3 lines
Note that
VERSION_1is still disabled due to missingANY_LAYOUTsupport.Signed-off-by Cornelia Huck <[email protected]>So we need some way for devices to tell transports not to negotiate rev 1.
Does clearingVERSION_1have this effect?
I just noticed that my patch is running in circles here.
What we need is probably the transport-dependent maximum revision checker (which at least for ccw is acting on a device) pass in the requested revision and check if the feature bits for the revision include VERSION_1. Does that make sense?
Michael S. Tsirkin
maintainerRe: [Qemu-devel] [PATCH RFC v6 13/20] virtio: allow to fail setting status
In reply to Cornelia HuckQuoted 15 lines · Cornelia Huck
Quoted 11 lines · On Tue, 30 Dec 2014 14:25:37 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 6 lines · Cornelia Huck
virtio-1 allow setting of the
FEATURES_OKstatus bit to fail if the negotiated feature bits are inconsistent: let's failvirtio_set_status()in that case and update virtio-ccw to post an error to the guest.Signed-off-by Cornelia Huck <[email protected]>Right but a separate
validate_featurescall is awkward. How about we defervirtio_set_featuresuntilFEATURES_OK, and teachvirtio_set_featuresthat it can fail?
Quoted 6 lines
Hm. But we would need to keep
virtio_set_features()where it is called now for legacy devices, as they will never seeFEATURES_OK, right? So
we need to make this depending on revisions (or whatever the equivalent is for pci/mmio), as we cannot check forVERSION_1. Not sure whether this makes the code easier to follow.
So let's make this a separate callback then.virtio_legacy_set_features?
Michael S. Tsirkin
maintainerRe: [Qemu-devel] [PATCH RFC v6 18/20] virtio: support revision-specific features
In reply to Cornelia HuckQuoted 11 lines · Cornelia Huck
Quoted 8 lines · On Sun, 28 Dec 2014 10:32:06 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 6 lines · Cornelia Huck
Devices may support different sets of feature bits depending on which revision they're operating at. Let's give the transport a way to re-query the device about its features when the revision has been changed.
Signed-off-by Cornelia Huck <[email protected]>
Quoted 7 lines
Quoted 4 lines
So now we have both
get_featuresandget_features_rev, and it's never clear which revision doeshost_featuresrefer to. IMHO that's just too messy.
Let's addget_legacy_featuresandhost_legacy_featuresinstead?I wanted to avoid touching anything that does not support version 1. And this interface might still work for later revisions, no?
We can add _modern_ then, or rename host_features to host_legacy_features everywhere as preparation.
Signature · 1 line
MST
Michael S. Tsirkin
maintainerRe: [Qemu-devel] [PATCH RFC v6 19/20] virtio-blk: revision specific feature bits
In reply to Cornelia HuckQuoted 15 lines · Cornelia Huck
Quoted 4 lines · On Sun, 28 Dec 2014 12:24:46 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 3 lines · Cornelia Huck
Wire up virtio-blk to provide different feature bit sets depending on whether legacy or v1.0 has been requested.
Quoted 8 lines
Quoted 3 lines
Note that
VERSION_1is still disabled due to missingANY_LAYOUTsupport.Signed-off-by Cornelia Huck <[email protected]>So we need some way for devices to tell transports not to negotiate rev 1.
Does clearingVERSION_1have this effect?
Quoted 6 lines
I just noticed that my patch is running in circles here.
What we need is probably the transport-dependent maximum revision checker (which at least for ccw is acting on a device) pass in the requested revision and check if the feature bits for the revision include
VERSION_1. Does that make sense?
Just make devices set 'rev 1 supported' flag?
Re: [Qemu-devel] [PATCH RFC v6 13/20] virtio: allow to fail setting status
In reply to Michael S. TsirkinQuoted 23 lines · On Wed, 7 Jan 2015 21:08:21 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 15 lines · Cornelia Huck
Quoted 11 lines · On Tue, 30 Dec 2014 14:25:37 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 6 lines · Cornelia Huck
virtio-1 allow setting of the
FEATURES_OKstatus bit to fail if the negotiated feature bits are inconsistent: let's failvirtio_set_status()in that case and update virtio-ccw to post an error to the guest.Signed-off-by Cornelia Huck <[email protected]>Right but a separate
validate_featurescall is awkward. How about we defervirtio_set_featuresuntilFEATURES_OK, and teachvirtio_set_featuresthat it can fail?Quoted 6 lines
Hm. But we would need to keep
virtio_set_features()where it is called now for legacy devices, as they will never seeFEATURES_OK, right? So
we need to make this depending on revisions (or whatever the equivalent is for pci/mmio), as we cannot check forVERSION_1. Not sure whether this makes the code easier to follow.
Quoted 2 lines
So let's make this a separate callback then.
virtio_legacy_set_features?
I'm not sure I like that. We'd need to touch every transport, right?
Michael S. Tsirkin
maintainerRe: [Qemu-devel] [PATCH RFC v6 13/20] virtio: allow to fail setting status
Quoted 26 lines · Cornelia Huck
Quoted 23 lines · On Wed, 7 Jan 2015 21:08:21 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 21 lines · Cornelia Huck
Quoted 11 lines · On Tue, 30 Dec 2014 14:25:37 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 6 lines · Cornelia Huck
virtio-1 allow setting of the
FEATURES_OKstatus bit to fail if the negotiated feature bits are inconsistent: let's failvirtio_set_status()in that case and update virtio-ccw to post an error to the guest.Signed-off-by Cornelia Huck <[email protected]>Right but a separate
validate_featurescall is awkward. How about we defervirtio_set_featuresuntilFEATURES_OK, and teachvirtio_set_featuresthat it can fail?Hm. But we would need to keep
virtio_set_features()where it is called now for legacy devices, as they will never seeFEATURES_OK, right? So
we need to make this depending on revisions (or whatever the equivalent is for pci/mmio), as we cannot check forVERSION_1. Not sure whether this makes the code easier to follow.
Quoted 4 lines
Quoted 2 lines
So let's make this a separate callback then.
virtio_legacy_set_features?I'm not sure I like that. We'd need to touch every transport, right?
Yes but there aren't so many.
Re: [Qemu-devel] [PATCH RFC v6 06/20] virtio: endianness checks for virtio 1.0 devices
In reply to Cornelia HuckQuoted 10 lines · Cornelia Huck
Add code that checks for the
VERSION_1feature bit in order to make decisions about the device's endianness. This allows us to support transitional devices.Signed-off-by Cornelia Huck <[email protected]>--- hw/virtio/virtio.c | 6 +++++- include/hw/virtio/virtio-access.h | 4 ++++ include/hw/virtio/virtio.h | 8 ++++++-- 3 files changed, 15 insertions(+), 3 deletions(-)
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 08/20] dataplane: allow virtio-1 devices
In reply to Cornelia HuckQuoted 5 lines · Cornelia Huck
Handle endianness conversion for virtio-1 virtqueues correctly.
Note that dataplane now needs to be built per-target.
Signed-off-by Cornelia Huck <[email protected]>
Quoted 10 lines
--- hw/block/dataplane/virtio-blk.c | 4 +- hw/scsi/virtio-scsi-dataplane.c | 2 +- hw/virtio/Makefile.objs | 2 +- hw/virtio/dataplane/Makefile.objs | 2 +- hw/virtio/dataplane/vring.c | 86 ++++++++++++++----------- include/hw/virtio/dataplane/vring-accessors.h | 75 +++++++++++++++++++++ include/hw/virtio/dataplane/vring.h | 14 +--- 7 files changed, 131 insertions(+), 54 deletions(-) create mode 100644 include/hw/virtio/dataplane/vring-accessors.h
This patch is independent of VIRTIO 1.0 and can be merged separately (faster).
hw/block/dataplane/virtio-blk.c line 21
Quoted 11 lines
hw/block/dataplane/virtio-blk.c +2
-0@@ -16,7 +16,9 @@#include "qemu/iov.h" #include "qemu/thread.h" #include "qemu/error-report.h" +#include "hw/virtio/virtio-access.h" #include "hw/virtio/dataplane/vring.h" +#include "hw/virtio/dataplane/vring-accessors.h"
I like your vring-accessors.h approach better than the inline virtio_ld/st_p() in my patch. Nice.
hw/block/dataplane/virtio-blk.c bool vring_should_notify(VirtIODevice *vdev, Vring *vring) · line 161
Quoted 7 lines
hw/block/dataplane/virtio-blk.c +1
-1@@ -154,15 +157,18 @@ bool vring_should_notify(VirtIODevice *vdev, Vring *vring) } -static int get_desc (Vring *vring,VirtQueueElement *elem, +static int get_desc (VirtIODevice *vdev,Vring *vring,VirtQueueElement *elem,struct vring_desc *desc)
Since we copy in struct vring_desc anyway, it's cleaner to byteswap the fields once instead of remembering to do it each time we need to access a field. The copy_in_vring_desc() function is one thing I prefer I about my patch.
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 09/20] s390x/css: Add a callback for when subchannel gets disabled
In reply to Cornelia HuckQuoted 11 lines · Cornelia Huck
From: Thomas Huth <[email protected]>
We need a possibility to run code when a subchannel gets disabled. This patch adds the necessary infrastructure.
Signed-off-by Thomas Huth <[email protected]>Signed-off-by Cornelia Huck <[email protected]>--- hw/s390x/css.c | 12 ++++++++++++ hw/s390x/css.h | 1 + 2 files changed, 13 insertions(+)
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 10/20] s390x/virtio-ccw: add virtio set-revision call
In reply to Cornelia HuckQuoted 11 lines · Cornelia Huck
From: Thomas Huth <[email protected]>
Handle the virtio-ccw revision according to what the guest sets. When revision 1 is selected, we have a virtio-1 standard device with byteswapping for the virtio rings.
When a channel gets disabled, we have to revert to the legacy behavior in case the next user of the device does not negotiate the revision 1 anymore (e.g. the boot firmware uses revision 1, but the operating system only uses the legacy mode).
Quoted 8 lines
Note that revisions > 0 are still disabled.
Signed-off-by Thomas Huth <[email protected]>Signed-off-by Cornelia Huck <[email protected]>--- hw/s390x/virtio-ccw.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/virtio-ccw.h | 8 ++++++++ 2 files changed, 60 insertions(+)
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 11/20] s390x/virtio-ccw: support virtio-1 set_vq format
In reply to Cornelia HuckQuoted 10 lines · Cornelia Huck
Support the new
CCW_CMD_SET_VQformat for virtio-1 devices.While we're at it, refactor the code a bit and enforce big endian fields (which had always been required, even for legacy).
Reviewed-by Thomas Huth <[email protected]>Signed-off-by Cornelia Huck <[email protected]>--- hw/s390x/virtio-ccw.c | 114 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 80 insertions(+), 34 deletions(-)
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 10/20] s390x/virtio-ccw: add virtio set-revision call
In reply to Cornelia HuckQuoted 7 lines · Cornelia Huck
hw/s390x/virtio-ccw.c +3
-0@@ -608,6 +631,25 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) } }break ; +case CCW_CMD_SET_VIRTIO_REV : + len =sizeof (revinfo); +if (ccw.count < len || (check_len && ccw.count > len)) {
hw/s390x/virtio-ccw.c static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) · line 646
Quoted 10 lines
hw/s390x/virtio-ccw.c +10
-0+ ret = -EINVAL ; +break ; + } +if (!ccw.cda) { + ret = -EFAULT ; +break ; + } +cpu_physical_memory_read (ccw.cda, &revinfo, len); +if (dev->revision >=0 || + revinfo.revision >virtio_ccw_rev_max (dev)) {
In the next patch virtio_ccw_handle_set_vq() uses big-endian memory access functions to load a struct from guest memory.
Here you just copy the struct in without byteswaps.
Are the byteswaps missing here? (I guess this normally runs big-endian guests on big-endian hosts so it's not noticable.)
Stefan
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 12/20] virtio: disallow late feature changes for virtio-1
In reply to Thomas HuthQuoted 33 lines · Thomas Huth
Quoted 30 lines · On Fri, 12 Dec 2014 12:18:25 +0100 Cornelia Huck <[email protected]>…
Quoted 26 lines · On Fri, 12 Dec 2014 11:55:38 +0100 Thomas Huth <[email protected]> wrote:
Quoted 15 lines · On Thu, 11 Dec 2014 14:25:14 +0100 Cornelia Huck <[email protected]>…
For virtio-1 devices, the driver must not attempt to set feature bits after it set
FEATURES_OKin the device status. Simply reject it in that case.Signed-off-by Cornelia Huck <[email protected]>--- hw/virtio/virtio.c | 16 ++++++++++++++-- include/hw/virtio/virtio.h | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-)hw/virtio/virtio.c +0
-0hw/virtio/virtio.c void virtio_save(VirtIODevice *vdev, QEMUFile *f) · line 981
Quoted 5 lines
hw/virtio/virtio.c +1
-1@@ -978,7 +978,7 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)vmstate_save_state (f, &vmstate_virtio, vdev); } -int virtio_set_features (VirtIODevice *vdev,uint64_t val) +static int __virtio_set_features (VirtIODevice *vdev,uint64_t val)Maybe avoid the double underscores here? But unfortunately, I also fail to come up with a better suggestion for a name here ...
Quoted 8 lines
Quoted 1 line
virtio_set_features_nocheck()?Sounds ok to me.
Quoted 1 line
This function is only called within
virtio.canyway...Right, so the double underscores should be ok here, too. (I still do not like them very much, but that's just my personal taste in this case)
C99 "7.1.3 Reserved identifiers" says:
All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use
[by the standard library]
You can use a trailing underscore or useless word like "do", e.g. virtio_do_set_features(), for internal functions.
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 14/20] s390x/virtio-ccw: enable virtio 1.0
In reply to Cornelia HuckQuoted 7 lines · Cornelia Huck
virtio-ccw should now have everything in place to operate virtio 1.0 devices, so let's enable revision 1.
Signed-off-by Cornelia Huck <[email protected]>--- hw/s390x/virtio-ccw.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 15/20] virtio-net: no writeable mac for virtio-1
In reply to Cornelia HuckQuoted 13 lines · Cornelia Huck
Devices operating as virtio 1.0 may not allow writes to the mac address in config space.
Signed-off-by Cornelia Huck <[email protected]>--- hw/net/virtio-net.c | 1 + 1 file changed, 1 insertion(+)hw/net/virtio-net.c +0
-0
hw/net/virtio-net.c static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config) · line 89
Quoted 3 lines
hw/net/virtio-net.c +0
-0@@ -87,6 +87,7 @@ static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)memcpy (&netcfg, config, n->config_size); if (!virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_MAC_ADDR) &&
I don't see VIRTIO_NET_F_CTRL_MAC_ADDR (23) in the VIRTIO 1.0 "5.1.3.1 Legacy Interface: Feature bits" section. Should it be there just so people don't try to reuse bit 23 in the future?
The patch itself:
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 08/20] dataplane: allow virtio-1 devices
In reply to Stefan HajnocziQuoted 17 lines · On Tue, 20 Jan 2015 10:43:31 +0000 Stefan Hajnoczi <[email protected]> wrote:
Quoted 5 lines · Cornelia Huck
Handle endianness conversion for virtio-1 virtqueues correctly.
Note that dataplane now needs to be built per-target.
Signed-off-by Cornelia Huck <[email protected]>Quoted 10 lines
--- hw/block/dataplane/virtio-blk.c | 4 +- hw/scsi/virtio-scsi-dataplane.c | 2 +- hw/virtio/Makefile.objs | 2 +- hw/virtio/dataplane/Makefile.objs | 2 +- hw/virtio/dataplane/vring.c | 86 ++++++++++++++----------- include/hw/virtio/dataplane/vring-accessors.h | 75 +++++++++++++++++++++ include/hw/virtio/dataplane/vring.h | 14 +--- 7 files changed, 131 insertions(+), 54 deletions(-) create mode 100644 include/hw/virtio/dataplane/vring-accessors.h
Quoted 2 lines
This patch is independent of VIRTIO 1.0 and can be merged separately (faster).
Yep, I've pulled it in front of my queue.
Quoted 20 lines
hw/block/dataplane/virtio-blk.c line 21
Quoted 12 lines
hw/block/dataplane/virtio-blk.c +2
-0@@ -16,7 +16,9 @@#include "qemu/iov.h" #include "qemu/thread.h" #include "qemu/error-report.h" +#include "hw/virtio/virtio-access.h" #include "hw/virtio/dataplane/vring.h" +#include "hw/virtio/dataplane/vring-accessors.h" I like your
vring-accessors.happroach better than the inline virtio_ld/st_p() in my patch. Nice.Quoted 4 lines
hw/block/dataplane/virtio-blk.c +0
-0@@ -154,15 +157,18 @@ bool vring_should_notify(VirtIODevice *vdev, Vring *vring) }
Quoted 8 lines
hw/block/dataplane/virtio-blk.c bool vring_should_notify(VirtIODevice *vdev, Vring *vring) · line 161
Quoted 3 lines
hw/block/dataplane/virtio-blk.c +1
-1-static int get_desc (Vring *vring,VirtQueueElement *elem, +static int get_desc (VirtIODevice *vdev,Vring *vring,VirtQueueElement *elem,struct vring_desc *desc)Since we copy in struct
vring_descanyway, it's cleaner to byteswap the fields once instead of remembering to do it each time we need to access a field. Thecopy_in_vring_desc()function is one thing I prefer I about my patch.
Agreed, that makes the code cleaner.
I've prepared a version of this patch using copy_in_vring_desc() and I'll post it when it survives some light testing on my side.
Re: [Qemu-devel] [PATCH RFC v6 16/20] virtio-net: support longer header
In reply to Cornelia Huckhw/net/virtio-net.c static int peer_has_ufo(VirtIONet *n) · line 377
Quoted 11 lines · Cornelia Huck
hw/net/virtio-net.c +2
-1@@ -373,15 +373,21 @@ static int peer_has_ufo(VirtIONet *n)return n->has_ufo; } -static void virtio_net_set_mrg_rx_bufs (VirtIONet *n,int mergeable_rx_bufs) +static void virtio_net_set_mrg_rx_bufs (VirtIONet *n,int mergeable_rx_bufs, +int version_1)
Please use bool, it makes it 100% clear what the meaning of "version_1" is.
s/int/bool/
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 08/20] dataplane: allow virtio-1 devices
In reply to Cornelia HuckQuoted 16 lines · Cornelia Huck
Quoted 5 lines · On Tue, 20 Jan 2015 10:43:31 +0000 Stefan Hajnoczi <[email protected]> wrote:
Quoted 4 lines · Cornelia Huck
(quoted diff) +0
-0@@ -154,15 +157,18 @@ bool vring_should_notify(VirtIODevice *vdev, Vring *vring) }Quoted 8 lines
hw/virtio/dataplane/vring.c bool vring_should_notify(VirtIODevice *vdev, Vring *vring) · line 161
Quoted 3 lines
hw/virtio/dataplane/vring.c +1
-1-static int get_desc (Vring *vring,VirtQueueElement *elem, +static int get_desc (VirtIODevice *vdev,Vring *vring,VirtQueueElement *elem,struct vring_desc *desc)Since we copy in struct
vring_descanyway, it's cleaner to byteswap the fields once instead of remembering to do it each time we need to access a field. Thecopy_in_vring_desc()function is one thing I prefer I about my patch.
Quoted 4 lines
Agreed, that makes the code cleaner.
I've prepared a version of this patch using
copy_in_vring_desc()and I'll post it when it survives some light testing on my side.
Cool, thanks for doing this!
Stefan
Re: [Qemu-devel] [PATCH RFC v6 10/20] s390x/virtio-ccw: add virtio set-revision call
In reply to Stefan HajnocziQuoted 22 lines · On Tue, 20 Jan 2015 11:08:24 +0000 Stefan Hajnoczi <[email protected]> wrote:
Quoted 7 lines · Cornelia Huck
hw/s390x/virtio-ccw.c +3
-0@@ -608,6 +631,25 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) } }break ; +case CCW_CMD_SET_VIRTIO_REV : + len =sizeof (revinfo); +if (ccw.count < len || (check_len && ccw.count > len)) {hw/s390x/virtio-ccw.c static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) · line 646
Quoted 10 lines
hw/s390x/virtio-ccw.c +10
-0+ ret = -EINVAL ; +break ; + } +if (!ccw.cda) { + ret = -EFAULT ; +break ; + } +cpu_physical_memory_read (ccw.cda, &revinfo, len); +if (dev->revision >=0 || + revinfo.revision >virtio_ccw_rev_max (dev)) {In the next patch
virtio_ccw_handle_set_vq()uses big-endian memory access functions to load a struct from guest memory.
Quoted 4 lines
Here you just copy the struct in without byteswaps.
Are the byteswaps missing here? (I guess this normally runs big-endian guests on big-endian hosts so it's not noticable.)
Indeed, these are supposed to be big-endian. I'll double check the other payloads.
Thanks for spotting this!
Re: [Qemu-devel] [PATCH RFC v6 10/20] s390x/virtio-ccw: add virtio set-revision call
Quoted 25 lines · On Wed, 21 Jan 2015 12:23:18 +0100 Cornelia Huck <[email protected]>…
Quoted 22 lines · On Tue, 20 Jan 2015 11:08:24 +0000 Stefan Hajnoczi <[email protected]> wrote:
Quoted 7 lines · Cornelia Huck
hw/s390x/virtio-ccw.c +3
-0@@ -608,6 +631,25 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) } }break ; +case CCW_CMD_SET_VIRTIO_REV : + len =sizeof (revinfo); +if (ccw.count < len || (check_len && ccw.count > len)) {hw/s390x/virtio-ccw.c static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) · line 646
Quoted 10 lines
hw/s390x/virtio-ccw.c +10
-0+ ret = -EINVAL ; +break ; + } +if (!ccw.cda) { + ret = -EFAULT ; +break ; + } +cpu_physical_memory_read (ccw.cda, &revinfo, len); +if (dev->revision >=0 || + revinfo.revision >virtio_ccw_rev_max (dev)) {In the next patch
virtio_ccw_handle_set_vq()uses big-endian memory access functions to load a struct from guest memory.
Quoted 7 lines
Quoted 4 lines
Here you just copy the struct in without byteswaps.
Are the byteswaps missing here? (I guess this normally runs big-endian guests on big-endian hosts so it's not noticable.)
Indeed, these are supposed to be big-endian. I'll double check the other payloads.
Right. Cornelia, can you take care of this or shall I rework the patch?
NB: Actually, there are a couple of "XXX config space endianness" comments in that virtio_ccw_cb() function, so there are likely a bunch of problems when this code should be run on little endian hosts one day. So far, this code only runs with big-endian guests on big-endian hosts since the virtio-ccw machine is currently KVM-only as far as I know, that's likely why nobody complained about this yet.
Thomas
Re: [Qemu-devel] [PATCH RFC v6 10/20] s390x/virtio-ccw: add virtio set-revision call
Quoted 30 lines · On Wed, 21 Jan 2015 12:51:41 +0100 Thomas Huth <[email protected]> wrote:
Quoted 27 lines · On Wed, 21 Jan 2015 12:23:18 +0100 Cornelia Huck <[email protected]>…
Quoted 24 lines · On Tue, 20 Jan 2015 11:08:24 +0000 Stefan Hajnoczi <[email protected]> wrote:
Quoted 7 lines · Cornelia Huck
hw/s390x/virtio-ccw.c +3
-0@@ -608,6 +631,25 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) } }break ; +case CCW_CMD_SET_VIRTIO_REV : + len =sizeof (revinfo); +if (ccw.count < len || (check_len && ccw.count > len)) {hw/s390x/virtio-ccw.c static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) · line 646
Quoted 10 lines
hw/s390x/virtio-ccw.c +10
-0+ ret = -EINVAL ; +break ; + } +if (!ccw.cda) { + ret = -EFAULT ; +break ; + } +cpu_physical_memory_read (ccw.cda, &revinfo, len); +if (dev->revision >=0 || + revinfo.revision >virtio_ccw_rev_max (dev)) {In the next patch
virtio_ccw_handle_set_vq()uses big-endian memory access functions to load a struct from guest memory.Here you just copy the struct in without byteswaps.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Are the byteswaps missing here? (I guess this normally runs big-endian guests on big-endian hosts so it's not noticable.)
Indeed, these are supposed to be big-endian. I'll double check the other payloads.
Right. Cornelia, can you take care of this or shall I rework the patch?
Currently already working on a patch :)
Quoted 6 lines
NB: Actually, there are a couple of "XXX config space endianness" comments in that
virtio_ccw_cb()function, so there are likely a bunch of problems when this code should be run on little endian hosts one day. So far, this code only runs with big-endian guests on big-endian hosts since the virtio-ccw machine is currently KVM-only as far as I know, that's likely why nobody complained about this yet.
The transport can't take care of the config space endianness, this needs to be done by the individual devices. Probably best to simply ditch the comments.
Re: [Qemu-devel] [PATCH RFC v6 16/20] virtio-net: support longer header
In reply to Stefan HajnocziQuoted 9 lines · On Tue, 20 Jan 2015 13:18:14 +0000 Stefan Hajnoczi <[email protected]> wrote:
Quoted 8 lines · Cornelia Huck
hw/net/virtio-net.c +0
-0@@ -373,15 +373,21 @@ static int peer_has_ufo(VirtIONet *n)return n->has_ufo; }
Quoted 8 lines
hw/net/virtio-net.c static int peer_has_ufo(VirtIONet *n) · line 377
Quoted 3 lines
hw/net/virtio-net.c +2
-1-static void virtio_net_set_mrg_rx_bufs (VirtIONet *n,int mergeable_rx_bufs) +static void virtio_net_set_mrg_rx_bufs (VirtIONet *n,int mergeable_rx_bufs, +int version_1)Please use bool, it makes it 100% clear what the meaning of "
version_1" is.s/int/bool/
OK, will change.
Re: [Qemu-devel] [PATCH RFC v6 02/20] virtio: cull virtio_bus_set_vdev_features
In reply to Cornelia HuckQuoted 7 lines · Cornelia Huck
The only user of this function was virtio-ccw, and it should use
virtio_set_features()like everybody else: We need to make sure that bad features are masked out properly, which this function did not do.Reviewed-by Thomas Huth <[email protected]>Signed-off-by Cornelia Huck <[email protected]>
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 03/20] virtio: feature bit manipulation helpers
In reply to Cornelia HuckQuoted 9 lines · Cornelia Huck
Add virtio_{add,clear}_feature helper functions for manipulating a feature bits variable. This has some benefits over open coding:
- add check that the bit is in a sane range
- make it obvious at a glance what is going on
- have a central point to change when we want to extend feature bitsConvert existing code manipulating features to use the new helpers.
Signed-off-by Cornelia Huck <[email protected]>
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 04/20] virtio: add feature checking helpers
In reply to Cornelia HuckQuoted 7 lines · Cornelia Huck
Add a helper function for checking whether a bit is set in the guest features for a vdev as well as one that works on a feature bit set.
Convert code that open-coded this: It cleans up the code and makes it easier to extend the guest feature bits.
Signed-off-by Cornelia Huck <[email protected]>
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 05/20] virtio: support more feature bits
In reply to Cornelia HuckQuoted 5 lines · Cornelia Huck
Quoted 2 lines · On Fri, 12 Dec 2014 11:06:40 +0100 Thomas Huth <[email protected]> wrote:
On Thu, 11 Dec 2014 14:25:07 +0100
Cornelia Huck <[email protected]> wrote:
[snip]
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
vdev->queue_sel = 0; vdev->status = 0; vdev->isr = 0;hw/virtio/virtio.c +0
-1@@ -924,7 +925,8 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)qemu_put_8s (f, &vdev->status);qemu_put_8s (f, &vdev->isr);qemu_put_be16s (f, &vdev->queue_sel); -qemu_put_be32s (f, &vdev->guest_features);Quoted 8 lines
hw/virtio/virtio.c void virtio_save(VirtIODevice *vdev, QEMUFile *f) · line 929
Quoted 2 lines
hw/virtio/virtio.c +2
-0+/* XXX features >= 32 */ +qemu_put_be32s (f, (uint32_t *)&vdev->guest_features);Casting a uint64_t* to a uint32_t* here sounds very wrong - this likely only works on little endian sytems, but certainly not on big-endian systems.
If you do not want to extend this for 64-bit right from the beginning, I think you've got to use a temporary 32-bit variable to get this right.
Quoted 2 lines
Hm... always store the old 32 bits here, then store the new 32 bits later? Should be able to get that compatible.
I think Thomas' point is that since vdev->guest_features has changed to a uint64_t, the "old" bits are now in the second 32-bit half on a BE system.
Or maybe I'm misunderstanding your reply.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 05/20] virtio: support more feature bits
In reply to Cornelia HuckQuoted 4 lines · Cornelia Huck
With virtio-1, we support more than 32 feature bits. Let's extend both host and guest features to 64, which should suffice for a while.
vhost and migration have been ignored for now.
[snip]
include/hw/virtio/virtio.h line 59
Quoted 10 lines
include/hw/virtio/virtio.h +2
-0@@ -55,6 +55,12 @@/* A guest should never accept this. It implies negotiation is broken. */ #define VIRTIO_F_BAD_FEATURE 30 +/* v1.0 compliant. */ +#define VIRTIO_F_VERSION_1 32
This is already in the kernel header, isn't it?
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 06/20] virtio: endianness checks for virtio 1.0 devices
In reply to Cornelia HuckQuoted 16 lines · Cornelia Huck
Add code that checks for the
VERSION_1feature bit in order to make decisions about the device's endianness. This allows us to support transitional devices.Signed-off-by Cornelia Huck <[email protected]>--- hw/virtio/virtio.c | 6 +++++- include/hw/virtio/virtio-access.h | 4 ++++ include/hw/virtio/virtio.h | 8 ++++++-- 3 files changed, 15 insertions(+), 3 deletions(-)hw/virtio/virtio.c +0
-0
hw/virtio/virtio.c static bool virtio_device_endian_needed(void *opaque) · line 888
Quoted 9 lines
hw/virtio/virtio.c +5
-1@@ -881,7 +881,11 @@ static bool virtio_device_endian_needed(void *opaque)VirtIODevice *vdev = opaque;assert (vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_UNKNOWN ); -return vdev->device_endian !=virtio_default_endian (); +if (!virtio_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +return vdev->device_endian !=virtio_default_endian (); + } +/* Devices conforming to VIRTIO 1.0 or later are always LE. */ +return vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_LITTLE ;
This doesn't seem quite right. Since virtio 1.0 is always LE, this should just assert that device_endian == LE and return false, right?
Quoted 26 lines
hw/virtio/virtio.c +0
-0}static const VMStateDescription vmstate_virtio_device_endian = {include/hw/virtio/virtio-access.h +4
-0@@ -19,6 +19,10 @@static inline bool virtio_access_is_big_endian (VirtIODevice *vdev) { +if (virtio_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +/* Devices conforming to VIRTIO 1.0 or later are always LE. */ +return false; + }#if defined(TARGET_IS_BIENDIAN )return virtio_is_big_endian (vdev);#elif defined(TARGET_WORDS_BIGENDIAN )include/hw/virtio/virtio.h +0
-0@@ -297,7 +297,11 @@ static inline bool virtio_has_feature(VirtIODevice *vdev, unsigned int fbit)static inline bool virtio_is_big_endian (VirtIODevice *vdev) {
include/hw/virtio/virtio.h static inline bool virtio_has_feature(VirtIODevice *vdev, unsigned int fbit) · line 307
Quoted 10 lines
include/hw/virtio/virtio.h +6
-2-assert (vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_UNKNOWN ); - return vdev->device_endian == VIRTIO_DEVICE_ENDIAN_BIG; +if (!virtio_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +assert (vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_UNKNOWN ); +return vdev->device_endian ==VIRTIO_DEVICE_ENDIAN_BIG ; + } +/* Devices conforming to VIRTIO 1.0 or later are always LE. */ + return false; }#endif
AFAICT, the only real difference between virtio_is_big_endian() and virtio_access_is_big_endian() is that the latter will become compile-time constant on targets that don't do bi-endian.
With virtio 1.0 support, that's no longer true, so those two macros should just be merged, I think.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 07/20] virtio: allow virtio-1 queue layout
In reply to Cornelia HuckQuoted 16 lines · Cornelia Huck
For virtio-1 devices, we allow a more complex queue layout that doesn't require descriptor table and rings on a physically-contigous memory area:
addvirtio_queue_set_rings()to allow transports to set this up.Signed-off-by Cornelia Huck <[email protected]>--- hw/virtio/virtio-mmio.c | 3 +++ hw/virtio/virtio.c | 53 ++++++++++++++++++++++++++++---------------- include/hw/virtio/virtio.h | 3 +++ 3 files changed, 40 insertions(+), 19 deletions(-)hw/virtio/virtio-mmio.c +0
-0
hw/virtio/virtio-mmio.c static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value, · line 247
Quoted 4 lines
hw/virtio/virtio-mmio.c +1
-0@@ -244,8 +244,11 @@ static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value,case VIRTIO_MMIO_QUEUENUM :DPRINTF ("mmio_queue write %d max %d\n" , (int )value,VIRTQUEUE_MAX_SIZE );virtio_queue_set_num (vdev, vdev->queue_sel, value); +/* Note: only call this function for legacy devices */
It's not clear to me if this is an assertion that this *does* only call the function for legacy devices or a fixme, that it *should* only call the function for legacy devices.
Quoted 20 lines
hw/virtio/virtio-mmio.c +2
-0+virtio_queue_update_rings (vdev, vdev->queue_sel);break ;case VIRTIO_MMIO_QUEUEALIGN : +/* Note: this is only valid for legacy devices */ virtio_queue_set_align (vdev, vdev->queue_sel, value);break ;case VIRTIO_MMIO_QUEUEPFN :hw/virtio/virtio.c +0
-1@@ -69,7 +69,6 @@ typedef struct VRingstruct VirtQueue {VRing vring; -hwaddr pa;uint16_t last_avail_idx;/* Last used index value we have signalled on */ uint16_t signalled_used;
hw/virtio/virtio.c struct VirtQueue · line 94
Quoted 5 lines
hw/virtio/virtio.c +1
-1@@ -92,15 +91,18 @@ struct VirtQueue };/* virt queue functions */ -static void virtqueue_init (VirtQueue *vq) +void virtio_queue_update_rings (VirtIODevice *vdev,int n)
Perhaps something in the name to emphasise that this is only for <v1.0 devices?
Quoted 7 lines
hw/virtio/virtio.c +1
-4{ -hwaddr pa = vq->pa; +VRing *vring = &vdev->vq[n].vring; - vq->vring.desc = pa; - vq->vring.avail = pa + vq->vring.num *sizeof (VRingDesc); - vq->vring.used = vring_align(vq->vring.avail +
hw/virtio/virtio.c struct VirtQueue · line 105
Quoted 10 lines
hw/virtio/virtio.c +8
-2- offsetof(VRingAvail, ring[vq->vring.num]), - vq->vring.align); +if (!vring->desc) { +/* not yet setup -> nothing to do */ +return ; + } + vring->avail = vring->desc + vring->num *sizeof (VRingDesc); + vring->used =vring_align (vring->avail + + offsetof(VRingAvail, ring[vring->num]), + vring->align);
Would it make sense to implement this in terms ofvirtio_queue_set_rings()?
Quoted 116 lines
hw/virtio/virtio.c +24
-11} static inline uint64_t vring_desc_addr(VirtIODevice *vdev, hwaddr desc_pa,@@ -605,7 +607,6 @@ void virtio_reset(void *opaque) vdev->vq[i].vring.avail =0 ; vdev->vq[i].vring.used =0 ; vdev->vq[i].last_avail_idx =0 ; - vdev->vq[i].pa =0 ; vdev->vq[i].vector =VIRTIO_NO_VECTOR ; vdev->vq[i].signalled_used =0 ; vdev->vq[i].signalled_used_valid = false;@@ -708,13 +709,21 @@ void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data)void virtio_queue_set_addr (VirtIODevice *vdev,int n,hwaddr addr) { - vdev->vq[n].pa = addr; -virtqueue_init (&vdev->vq[n]); + vdev->vq[n].vring.desc = addr; +virtio_queue_update_rings (vdev, n); }hwaddr virtio_queue_get_addr (VirtIODevice *vdev,int n) { -return vdev->vq[n].pa; +return vdev->vq[n].vring.desc; +} + +void virtio_queue_set_rings (VirtIODevice *vdev,int n,hwaddr desc, +hwaddr avail,hwaddr used) +{ + vdev->vq[n].vring.desc = desc; + vdev->vq[n].vring.avail = avail; + vdev->vq[n].vring.used = used; }void virtio_queue_set_num (VirtIODevice *vdev,int n,int num)@@ -728,7 +737,6 @@ void virtio_queue_set_num(VirtIODevice *vdev, int n, int num)return ; } vdev->vq[n].vring.num = num; -virtqueue_init (&vdev->vq[n]); }int virtio_queue_get_num (VirtIODevice *vdev,int n)@@ -748,6 +756,11 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align)BusState *qbus =qdev_get_parent_bus (DEVICE (vdev));VirtioBusClass *k =VIRTIO_BUS_GET_CLASS (qbus); +/* virtio-1 compliant devices cannot change the aligment */ +if (virtio_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +error_report ("tried to modify queue alignment for virtio-1 device" ); +return ; + }/* Check that the transport told us it was going to do this * (so a buggy transport will immediately assert rather than * silently failing to migrate this state) @@ -755,7 +768,7 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align)assert (k->has_variable_vring_alignment); vdev->vq[n].vring.align = align; -virtqueue_init (&vdev->vq[n]); +virtio_queue_update_rings (vdev, n); }void virtio_queue_notify_vq (VirtQueue *vq)@@ -949,7 +962,8 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)if (k->has_variable_vring_alignment) {qemu_put_be32 (f, vdev->vq[i].vring.align); } -qemu_put_be64 (f, vdev->vq[i].pa); +/* XXX virtio-1 devices */ +qemu_put_be64 (f, vdev->vq[i].vring.desc);qemu_put_be16s (f, &vdev->vq[i].last_avail_idx);if (k->save_queue) { k->save_queue (qbus->parent, i, f);@@ -1044,13 +1058,14 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)if (k->has_variable_vring_alignment) { vdev->vq[i].vring.align =qemu_get_be32 (f); } - vdev->vq[i].pa =qemu_get_be64 (f); + vdev->vq[i].vring.desc =qemu_get_be64 (f);qemu_get_be16s (f, &vdev->vq[i].last_avail_idx); vdev->vq[i].signalled_used_valid = false; vdev->vq[i].notification = true; -if (vdev->vq[i].pa) { -virtqueue_init (&vdev->vq[i]); +if (vdev->vq[i].vring.desc) { +/* XXX virtio-1 devices */ +virtio_queue_update_rings (vdev, i); }else if (vdev->vq[i].last_avail_idx) { error_report("VQ %d address 0x0 " "inconsistent with Host index 0x%x",@@ -1084,7 +1099,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) }for (i =0 ; i < num; i++) { -if (vdev->vq[i].pa) { +if (vdev->vq[i].vring.desc) {uint16_t nheads; nheads =vring_avail_idx (&vdev->vq[i]) - vdev->vq[i].last_avail_idx;/* Check it isn't doing strange things with descriptor numbers. */ include/hw/virtio/virtio.h +3
-0@@ -224,6 +224,9 @@ void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr);hwaddr virtio_queue_get_addr (VirtIODevice *vdev,int n);void virtio_queue_set_num (VirtIODevice *vdev,int n,int num);int virtio_queue_get_num (VirtIODevice *vdev,int n); +void virtio_queue_set_rings (VirtIODevice *vdev,int n,hwaddr desc, +hwaddr avail,hwaddr used); +void virtio_queue_update_rings (VirtIODevice *vdev,int n);void virtio_queue_set_align (VirtIODevice *vdev,int n,int align);void virtio_queue_notify (VirtIODevice *vdev,int n);uint16_t virtio_queue_vector (VirtIODevice *vdev,int n);
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 08/20] dataplane: allow virtio-1 devices
In reply to Cornelia HuckQuoted 5 lines · Cornelia Huck
Handle endianness conversion for virtio-1 virtqueues correctly.
Note that dataplane now needs to be built per-target.
Signed-off-by Cornelia Huck <[email protected]>
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 12/20] virtio: disallow late feature changes for virtio-1
In reply to Cornelia HuckQuoted 5 lines · Cornelia Huck
For virtio-1 devices, the driver must not attempt to set feature bits after it set
FEATURES_OKin the device status. Simply reject it in that case.Signed-off-by Cornelia Huck <[email protected]>
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 04/20] virtio: add feature checking helpers
In reply to Cornelia HuckQuoted 7 lines · Cornelia Huck
Add a helper function for checking whether a bit is set in the guest features for a vdev as well as one that works on a feature bit set.
Convert code that open-coded this: It cleans up the code and makes it easier to extend the guest feature bits.
Signed-off-by Cornelia Huck <[email protected]>
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH RFC v6 06/20] virtio: endianness checks for virtio 1.0 devices
In reply to Cornelia HuckQuoted 16 lines · Cornelia Huck
Add code that checks for the
VERSION_1feature bit in order to make decisions about the device's endianness. This allows us to support transitional devices.Signed-off-by Cornelia Huck <[email protected]>--- hw/virtio/virtio.c | 6 +++++- include/hw/virtio/virtio-access.h | 4 ++++ include/hw/virtio/virtio.h | 8 ++++++-- 3 files changed, 15 insertions(+), 3 deletions(-)hw/virtio/virtio.c +0
-0
hw/virtio/virtio.c static bool virtio_device_endian_needed(void *opaque) · line 888
Quoted 9 lines
hw/virtio/virtio.c +5
-1@@ -881,7 +881,11 @@ static bool virtio_device_endian_needed(void *opaque)VirtIODevice *vdev = opaque;assert (vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_UNKNOWN ); -return vdev->device_endian !=virtio_default_endian (); +if (!virtio_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +return vdev->device_endian !=virtio_default_endian (); + } +/* Devices conforming to VIRTIO 1.0 or later are always LE. */ +return vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_LITTLE ;
This doesn't seem quite right. Since virtio 1.0 is always LE, this should just assert that device_endian == LE and return false, right?
Quoted 26 lines
hw/virtio/virtio.c +0
-0}static const VMStateDescription vmstate_virtio_device_endian = {include/hw/virtio/virtio-access.h +4
-0@@ -19,6 +19,10 @@static inline bool virtio_access_is_big_endian (VirtIODevice *vdev) { +if (virtio_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +/* Devices conforming to VIRTIO 1.0 or later are always LE. */ +return false; + }#if defined(TARGET_IS_BIENDIAN )return virtio_is_big_endian (vdev);#elif defined(TARGET_WORDS_BIGENDIAN )include/hw/virtio/virtio.h +0
-0@@ -297,7 +297,11 @@ static inline bool virtio_has_feature(VirtIODevice *vdev, unsigned int fbit)static inline bool virtio_is_big_endian (VirtIODevice *vdev) {
include/hw/virtio/virtio.h static inline bool virtio_has_feature(VirtIODevice *vdev, unsigned int fbit) · line 307
Quoted 10 lines
include/hw/virtio/virtio.h +6
-2-assert (vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_UNKNOWN ); - return vdev->device_endian == VIRTIO_DEVICE_ENDIAN_BIG; +if (!virtio_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +assert (vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_UNKNOWN ); +return vdev->device_endian ==VIRTIO_DEVICE_ENDIAN_BIG ; + } +/* Devices conforming to VIRTIO 1.0 or later are always LE. */ + return false; }#endif
AFAICT, the only real difference between virtio_is_big_endian() and virtio_access_is_big_endian() is that the latter will become compile-time constant on targets that don't do bi-endian.
With virtio 1.0 support, that's no longer true, so those two macros should just be merged, I think.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH RFC v6 05/20] virtio: support more feature bits
In reply to Cornelia HuckQuoted 5 lines · Cornelia Huck
Quoted 2 lines · On Fri, 12 Dec 2014 11:06:40 +0100 Thomas Huth <[email protected]> wrote:
On Thu, 11 Dec 2014 14:25:07 +0100
Cornelia Huck <[email protected]> wrote:
[snip]
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
vdev->queue_sel = 0; vdev->status = 0; vdev->isr = 0;hw/virtio/virtio.c +0
-1@@ -924,7 +925,8 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)qemu_put_8s (f, &vdev->status);qemu_put_8s (f, &vdev->isr);qemu_put_be16s (f, &vdev->queue_sel); -qemu_put_be32s (f, &vdev->guest_features);Quoted 8 lines
hw/virtio/virtio.c void virtio_save(VirtIODevice *vdev, QEMUFile *f) · line 929
Quoted 2 lines
hw/virtio/virtio.c +2
-0+/* XXX features >= 32 */ +qemu_put_be32s (f, (uint32_t *)&vdev->guest_features);Casting a uint64_t* to a uint32_t* here sounds very wrong - this likely only works on little endian sytems, but certainly not on big-endian systems.
If you do not want to extend this for 64-bit right from the beginning, I think you've got to use a temporary 32-bit variable to get this right.
Quoted 2 lines
Hm... always store the old 32 bits here, then store the new 32 bits later? Should be able to get that compatible.
I think Thomas' point is that since vdev->guest_features has changed to a uint64_t, the "old" bits are now in the second 32-bit half on a BE system.
Or maybe I'm misunderstanding your reply.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH RFC v6 07/20] virtio: allow virtio-1 queue layout
In reply to Cornelia HuckQuoted 16 lines · Cornelia Huck
For virtio-1 devices, we allow a more complex queue layout that doesn't require descriptor table and rings on a physically-contigous memory area:
addvirtio_queue_set_rings()to allow transports to set this up.Signed-off-by Cornelia Huck <[email protected]>--- hw/virtio/virtio-mmio.c | 3 +++ hw/virtio/virtio.c | 53 ++++++++++++++++++++++++++++---------------- include/hw/virtio/virtio.h | 3 +++ 3 files changed, 40 insertions(+), 19 deletions(-)hw/virtio/virtio-mmio.c +0
-0
hw/virtio/virtio-mmio.c static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value, · line 247
Quoted 4 lines
hw/virtio/virtio-mmio.c +1
-0@@ -244,8 +244,11 @@ static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value,case VIRTIO_MMIO_QUEUENUM :DPRINTF ("mmio_queue write %d max %d\n" , (int )value,VIRTQUEUE_MAX_SIZE );virtio_queue_set_num (vdev, vdev->queue_sel, value); +/* Note: only call this function for legacy devices */
It's not clear to me if this is an assertion that this *does* only call the function for legacy devices or a fixme, that it *should* only call the function for legacy devices.
Quoted 20 lines
hw/virtio/virtio-mmio.c +2
-0+virtio_queue_update_rings (vdev, vdev->queue_sel);break ;case VIRTIO_MMIO_QUEUEALIGN : +/* Note: this is only valid for legacy devices */ virtio_queue_set_align (vdev, vdev->queue_sel, value);break ;case VIRTIO_MMIO_QUEUEPFN :hw/virtio/virtio.c +0
-1@@ -69,7 +69,6 @@ typedef struct VRingstruct VirtQueue {VRing vring; -hwaddr pa;uint16_t last_avail_idx;/* Last used index value we have signalled on */ uint16_t signalled_used;
hw/virtio/virtio.c struct VirtQueue · line 94
Quoted 5 lines
hw/virtio/virtio.c +1
-1@@ -92,15 +91,18 @@ struct VirtQueue };/* virt queue functions */ -static void virtqueue_init (VirtQueue *vq) +void virtio_queue_update_rings (VirtIODevice *vdev,int n)
Perhaps something in the name to emphasise that this is only for <v1.0 devices?
Quoted 7 lines
hw/virtio/virtio.c +1
-4{ -hwaddr pa = vq->pa; +VRing *vring = &vdev->vq[n].vring; - vq->vring.desc = pa; - vq->vring.avail = pa + vq->vring.num *sizeof (VRingDesc); - vq->vring.used = vring_align(vq->vring.avail +
hw/virtio/virtio.c struct VirtQueue · line 105
Quoted 10 lines
hw/virtio/virtio.c +8
-2- offsetof(VRingAvail, ring[vq->vring.num]), - vq->vring.align); +if (!vring->desc) { +/* not yet setup -> nothing to do */ +return ; + } + vring->avail = vring->desc + vring->num *sizeof (VRingDesc); + vring->used =vring_align (vring->avail + + offsetof(VRingAvail, ring[vring->num]), + vring->align);
Would it make sense to implement this in terms ofvirtio_queue_set_rings()?
Quoted 116 lines
hw/virtio/virtio.c +24
-11} static inline uint64_t vring_desc_addr(VirtIODevice *vdev, hwaddr desc_pa,@@ -605,7 +607,6 @@ void virtio_reset(void *opaque) vdev->vq[i].vring.avail =0 ; vdev->vq[i].vring.used =0 ; vdev->vq[i].last_avail_idx =0 ; - vdev->vq[i].pa =0 ; vdev->vq[i].vector =VIRTIO_NO_VECTOR ; vdev->vq[i].signalled_used =0 ; vdev->vq[i].signalled_used_valid = false;@@ -708,13 +709,21 @@ void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data)void virtio_queue_set_addr (VirtIODevice *vdev,int n,hwaddr addr) { - vdev->vq[n].pa = addr; -virtqueue_init (&vdev->vq[n]); + vdev->vq[n].vring.desc = addr; +virtio_queue_update_rings (vdev, n); }hwaddr virtio_queue_get_addr (VirtIODevice *vdev,int n) { -return vdev->vq[n].pa; +return vdev->vq[n].vring.desc; +} + +void virtio_queue_set_rings (VirtIODevice *vdev,int n,hwaddr desc, +hwaddr avail,hwaddr used) +{ + vdev->vq[n].vring.desc = desc; + vdev->vq[n].vring.avail = avail; + vdev->vq[n].vring.used = used; }void virtio_queue_set_num (VirtIODevice *vdev,int n,int num)@@ -728,7 +737,6 @@ void virtio_queue_set_num(VirtIODevice *vdev, int n, int num)return ; } vdev->vq[n].vring.num = num; -virtqueue_init (&vdev->vq[n]); }int virtio_queue_get_num (VirtIODevice *vdev,int n)@@ -748,6 +756,11 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align)BusState *qbus =qdev_get_parent_bus (DEVICE (vdev));VirtioBusClass *k =VIRTIO_BUS_GET_CLASS (qbus); +/* virtio-1 compliant devices cannot change the aligment */ +if (virtio_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +error_report ("tried to modify queue alignment for virtio-1 device" ); +return ; + }/* Check that the transport told us it was going to do this * (so a buggy transport will immediately assert rather than * silently failing to migrate this state) @@ -755,7 +768,7 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align)assert (k->has_variable_vring_alignment); vdev->vq[n].vring.align = align; -virtqueue_init (&vdev->vq[n]); +virtio_queue_update_rings (vdev, n); }void virtio_queue_notify_vq (VirtQueue *vq)@@ -949,7 +962,8 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)if (k->has_variable_vring_alignment) {qemu_put_be32 (f, vdev->vq[i].vring.align); } -qemu_put_be64 (f, vdev->vq[i].pa); +/* XXX virtio-1 devices */ +qemu_put_be64 (f, vdev->vq[i].vring.desc);qemu_put_be16s (f, &vdev->vq[i].last_avail_idx);if (k->save_queue) { k->save_queue (qbus->parent, i, f);@@ -1044,13 +1058,14 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)if (k->has_variable_vring_alignment) { vdev->vq[i].vring.align =qemu_get_be32 (f); } - vdev->vq[i].pa =qemu_get_be64 (f); + vdev->vq[i].vring.desc =qemu_get_be64 (f);qemu_get_be16s (f, &vdev->vq[i].last_avail_idx); vdev->vq[i].signalled_used_valid = false; vdev->vq[i].notification = true; -if (vdev->vq[i].pa) { -virtqueue_init (&vdev->vq[i]); +if (vdev->vq[i].vring.desc) { +/* XXX virtio-1 devices */ +virtio_queue_update_rings (vdev, i); }else if (vdev->vq[i].last_avail_idx) { error_report("VQ %d address 0x0 " "inconsistent with Host index 0x%x",@@ -1084,7 +1099,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) }for (i =0 ; i < num; i++) { -if (vdev->vq[i].pa) { +if (vdev->vq[i].vring.desc) {uint16_t nheads; nheads =vring_avail_idx (&vdev->vq[i]) - vdev->vq[i].last_avail_idx;/* Check it isn't doing strange things with descriptor numbers. */ include/hw/virtio/virtio.h +3
-0@@ -224,6 +224,9 @@ void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr);hwaddr virtio_queue_get_addr (VirtIODevice *vdev,int n);void virtio_queue_set_num (VirtIODevice *vdev,int n,int num);int virtio_queue_get_num (VirtIODevice *vdev,int n); +void virtio_queue_set_rings (VirtIODevice *vdev,int n,hwaddr desc, +hwaddr avail,hwaddr used); +void virtio_queue_update_rings (VirtIODevice *vdev,int n);void virtio_queue_set_align (VirtIODevice *vdev,int n,int align);void virtio_queue_notify (VirtIODevice *vdev,int n);uint16_t virtio_queue_vector (VirtIODevice *vdev,int n);
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH RFC v6 15/20] virtio-net: no writeable mac for virtio-1
In reply to Stefan HajnocziQuoted 16 lines · On Tue, 20 Jan 2015 11:19:47 +0000 Stefan Hajnoczi <[email protected]> wrote:
Quoted 15 lines · Cornelia Huck
Devices operating as virtio 1.0 may not allow writes to the mac address in config space.
Signed-off-by Cornelia Huck <[email protected]>--- hw/net/virtio-net.c | 1 + 1 file changed, 1 insertion(+)hw/net/virtio-net.c +0
-0@@ -87,6 +87,7 @@ static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)memcpy (&netcfg, config, n->config_size);
Quoted 5 lines
hw/net/virtio-net.c static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config) · line 89
Quoted 1 line
hw/net/virtio-net.c +0
-0if (!virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_MAC_ADDR) &&I don't see
VIRTIO_NET_F_CTRL_MAC_ADDR(23) in the VIRTIO 1.0 "5.1.3.1 Legacy Interface: Feature bits" section. Should it be there just so people don't try to reuse bit 23 in the future?
But this isn't a legacy flag. Virtio-1 devices simply may not manipulate the mac address directly even if this feature has not been negotiated.
Quoted 3 lines
The patch itself:
Reviewed-by Stefan Hajnoczi <[email protected]>
Re: [Qemu-devel] [PATCH RFC v6 06/20] virtio: endianness checks for virtio 1.0 devices
In reply to David GibsonQuoted 19 lines · On Thu, 22 Jan 2015 12:54:09 +1100 David Gibson <[email protected]>…
Quoted 18 lines · Cornelia Huck
Add code that checks for the
VERSION_1feature bit in order to make decisions about the device's endianness. This allows us to support transitional devices.Signed-off-by Cornelia Huck <[email protected]>--- hw/virtio/virtio.c | 6 +++++- include/hw/virtio/virtio-access.h | 4 ++++ include/hw/virtio/virtio.h | 8 ++++++-- 3 files changed, 15 insertions(+), 3 deletions(-)hw/virtio/virtio.c +0
-0@@ -881,7 +881,11 @@ static bool virtio_device_endian_needed(void *opaque)VirtIODevice *vdev = opaque;
Quoted 12 lines
hw/virtio/virtio.c static bool virtio_device_endian_needed(void *opaque) · line 888
Quoted 7 lines
hw/virtio/virtio.c +5
-1assert (vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_UNKNOWN ); -return vdev->device_endian !=virtio_default_endian (); +if (!virtio_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +return vdev->device_endian !=virtio_default_endian (); + } +/* Devices conforming to VIRTIO 1.0 or later are always LE. */ +return vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_LITTLE ;This doesn't seem quite right. Since virtio 1.0 is always LE, this should just assert that
device_endian== LE and return false, right?
The device_endian field is ONLY used by devices when the software is legacy.
It is set at device reset time (see virtio_reset()) since we can reasonably assume that when the software changes endianness, it always reset the device before using it again (aka. reboot or kexec).
In the case we would have a BE guest, device_endian would be BE, even if the software is virtio 1.0. So, no, we shouldn't assert.
I had questioned Cornelia about why we care to migrate device_endian when in virtio 1.0 mode. I got these answers:
https://lists.nongnu.org/archive/html/qemu-devel/2014-10/msg03979.html
https://lists.nongnu.org/archive/html/qemu-devel/2014-11/msg03888.html
My understanding is that a transitional device will necessarily be reset if the software changes from legacy to 1.0 or vice-versa. So, yes, I still think virtio_device_endian_needed() should return false.
Quoted 41 lines
Quoted 26 lines
hw/virtio/virtio.c +0
-0}static const VMStateDescription vmstate_virtio_device_endian = {include/hw/virtio/virtio-access.h +4
-0@@ -19,6 +19,10 @@static inline bool virtio_access_is_big_endian (VirtIODevice *vdev) { +if (virtio_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +/* Devices conforming to VIRTIO 1.0 or later are always LE. */ +return false; + }#if defined(TARGET_IS_BIENDIAN )return virtio_is_big_endian (vdev);#elif defined(TARGET_WORDS_BIGENDIAN )include/hw/virtio/virtio.h +0
-0@@ -297,7 +297,11 @@ static inline bool virtio_has_feature(VirtIODevice *vdev, unsigned int fbit)static inline bool virtio_is_big_endian (VirtIODevice *vdev) {include/hw/virtio/virtio.h static inline bool virtio_has_feature(VirtIODevice *vdev, unsigned int fbit) · line 307
Quoted 10 lines
include/hw/virtio/virtio.h +6
-2-assert (vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_UNKNOWN ); - return vdev->device_endian == VIRTIO_DEVICE_ENDIAN_BIG; +if (!virtio_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +assert (vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_UNKNOWN ); +return vdev->device_endian ==VIRTIO_DEVICE_ENDIAN_BIG ; + } +/* Devices conforming to VIRTIO 1.0 or later are always LE. */ + return false; }#endif AFAICT, the only real difference between
virtio_is_big_endian()andvirtio_access_is_big_endian()is that the latter will become compile-time constant on targets that don't do bi-endian.
Quoted 3 lines
With virtio 1.0 support, that's no longer true, so those two macros should just be merged, I think.
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 05/20] virtio: support more feature bits
In reply to David GibsonQuoted 16 lines · On Thu, 22 Jan 2015 12:43:43 +1100 David Gibson <[email protected]>…
Quoted 4 lines · Cornelia Huck
With virtio-1, we support more than 32 feature bits. Let's extend both host and guest features to 64, which should suffice for a while.
vhost and migration have been ignored for now.
[snip]
Quoted 8 lines
include/hw/virtio/virtio.h +0
-0@@ -55,6 +55,12 @@/* A guest should never accept this. It implies negotiation is broken. */ #define VIRTIO_F_BAD_FEATURE 30
Quoted 5 lines
include/hw/virtio/virtio.h line 59
Quoted 2 lines
include/hw/virtio/virtio.h +2
-0+/* v1.0 compliant. */ +#define VIRTIO_F_VERSION_1 32This is already in the kernel header, isn't it?
Yes. But nearly all files include this header but not the kernel header.
Re: [Qemu-devel] [PATCH RFC v6 07/20] virtio: allow virtio-1 queue layout
In reply to David GibsonQuoted 12 lines · On Thu, 22 Jan 2015 13:06:09 +1100 David Gibson <[email protected]>…
Quoted 11 lines · Cornelia Huck
For virtio-1 devices, we allow a more complex queue layout that doesn't require descriptor table and rings on a physically-contigous memory area:
addvirtio_queue_set_rings()to allow transports to set this up.Signed-off-by Cornelia Huck <[email protected]>--- hw/virtio/virtio-mmio.c | 3 +++ hw/virtio/virtio.c | 53 ++++++++++++++++++++++++++++---------------- include/hw/virtio/virtio.h | 3 +++ 3 files changed, 40 insertions(+), 19 deletions(-)
Quoted 13 lines
hw/virtio/virtio-mmio.c static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value, · line 247
Quoted 9 lines
hw/virtio/virtio-mmio.c +1
-0@@ -244,8 +244,11 @@ static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value,case VIRTIO_MMIO_QUEUENUM :DPRINTF ("mmio_queue write %d max %d\n" , (int )value,VIRTQUEUE_MAX_SIZE );virtio_queue_set_num (vdev, vdev->queue_sel, value); +/* Note: only call this function for legacy devices */ It's not clear to me if this is an assertion that this *does* only call the function for legacy devices or a fixme, that it *should* only call the function for legacy devices.
It's more like a note to whoever takes the virtio-mmio legacy device code and writes a virtio-1 virtio-mmio device.
Does
/* Note: this function must only be called for legacy devices */ make that intention clearer?
Quoted 8 lines
Quoted 8 lines
hw/virtio/virtio-mmio.c +2
-0+virtio_queue_update_rings (vdev, vdev->queue_sel);break ;case VIRTIO_MMIO_QUEUEALIGN : +/* Note: this is only valid for legacy devices */ virtio_queue_set_align (vdev, vdev->queue_sel, value);break ;case VIRTIO_MMIO_QUEUEPFN :
(...)
Quoted 6 lines
hw/virtio/virtio-mmio.c
Quoted 3 lines
/* virt queue functions */
hw/virtio/virtio-mmio.c +1
-1-static void virtqueue_init (VirtQueue *vq) +void virtio_queue_update_rings (VirtIODevice *vdev,int n)Perhaps something in the name to emphasise that this is only for <v1.0 devices?
virtio_queue_legacy_update_rings()? Maybe a bit long...
Quoted 19 lines
Quoted 8 lines
{
hw/virtio/virtio-mmio.c +1
-4-hwaddr pa = vq->pa; +VRing *vring = &vdev->vq[n].vring; - vq->vring.desc = pa; - vq->vring.avail = pa + vq->vring.num *sizeof (VRingDesc); - vq->vring.used = vring_align(vq->vring.avail +hw/virtio/virtio-mmio.c
Quoted 10 lines
hw/virtio/virtio-mmio.c +8
-2- offsetof(VRingAvail, ring[vq->vring.num]), - vq->vring.align); +if (!vring->desc) { +/* not yet setup -> nothing to do */ +return ; + } + vring->avail = vring->desc + vring->num *sizeof (VRingDesc); + vring->used =vring_align (vring->avail + + offsetof(VRingAvail, ring[vring->num]), + vring->align);
Quoted 2 lines
Would it make sense to implement this in terms of
virtio_queue_set_rings()?
Perhaps a bit confusing, since that would re-write desc.
Quoted 2 lines
Quoted 2 lines
}
Re: [Qemu-devel] [PATCH RFC v6 05/20] virtio: support more feature bits
In reply to Cornelia HuckQuoted 19 lines · Cornelia Huck
Quoted 16 lines · On Thu, 22 Jan 2015 12:43:43 +1100 David Gibson <[email protected]>…
Quoted 4 lines · Cornelia Huck
With virtio-1, we support more than 32 feature bits. Let's extend both host and guest features to 64, which should suffice for a while.
vhost and migration have been ignored for now.
[snip]
Quoted 8 lines
include/hw/virtio/virtio.h +0
-0@@ -55,6 +55,12 @@/* A guest should never accept this. It implies negotiation is broken. */ #define VIRTIO_F_BAD_FEATURE 30
Quoted 8 lines
Quoted 4 lines
include/hw/virtio/virtio.h line 59
Quoted 2 lines
include/hw/virtio/virtio.h +2
-0+/* v1.0 compliant. */ +#define VIRTIO_F_VERSION_1 32This is already in the kernel header, isn't it?
Yes. But nearly all files include this header but not the kernel header.
Can't you change that? Or this file include the kernel header?
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 07/20] virtio: allow virtio-1 queue layout
In reply to Cornelia HuckQuoted 29 lines · Cornelia Huck
Quoted 12 lines · On Thu, 22 Jan 2015 13:06:09 +1100 David Gibson <[email protected]>…
Quoted 11 lines · Cornelia Huck
For virtio-1 devices, we allow a more complex queue layout that doesn't require descriptor table and rings on a physically-contigous memory area:
addvirtio_queue_set_rings()to allow transports to set this up.Signed-off-by Cornelia Huck <[email protected]>--- hw/virtio/virtio-mmio.c | 3 +++ hw/virtio/virtio.c | 53 ++++++++++++++++++++++++++++---------------- include/hw/virtio/virtio.h | 3 +++ 3 files changed, 40 insertions(+), 19 deletions(-)Quoted 13 lines
hw/virtio/virtio-mmio.c static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value, · line 247
Quoted 9 lines
hw/virtio/virtio-mmio.c +1
-0@@ -244,8 +244,11 @@ static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value,case VIRTIO_MMIO_QUEUENUM :DPRINTF ("mmio_queue write %d max %d\n" , (int )value,VIRTQUEUE_MAX_SIZE );virtio_queue_set_num (vdev, vdev->queue_sel, value); +/* Note: only call this function for legacy devices */ It's not clear to me if this is an assertion that this *does* only call the function for legacy devices or a fixme, that it *should* only call the function for legacy devices.
Quoted 6 lines
It's more like a note to whoever takes the virtio-mmio legacy device code and writes a virtio-1 virtio-mmio device.
Does
/* Note: this function must only be called for legacy devices */ make that intention clearer?
Yes, I think that's better.
Quoted 12 lines
Quoted 9 lines
Quoted 9 lines
hw/virtio/virtio-mmio.c +2
-0+virtio_queue_update_rings (vdev, vdev->queue_sel);break ;case VIRTIO_MMIO_QUEUEALIGN : +/* Note: this is only valid for legacy devices */ virtio_queue_set_align (vdev, vdev->queue_sel, value);break ;case VIRTIO_MMIO_QUEUEPFN :(...)
Quoted 8 lines
Quoted 6 lines
hw/virtio/virtio-mmio.c
Quoted 3 lines
/* virt queue functions */
hw/virtio/virtio-mmio.c +1
-1-static void virtqueue_init (VirtQueue *vq) +void virtio_queue_update_rings (VirtIODevice *vdev,int n)Perhaps something in the name to emphasise that this is only for <v1.0 devices?
virtio_queue_legacy_update_rings()? Maybe a bit long...
There aren't many callers, so I think long is ok in this case.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 05/20] virtio: support more feature bits
In reply to David GibsonHi,
Quoted 26 lines · On Thu, 29 Jan 2015 11:11:32 +1100 David Gibson <[email protected]>…
Quoted 25 lines · Cornelia Huck
Quoted 20 lines · On Thu, 22 Jan 2015 12:43:43 +1100 David Gibson <[email protected]>…
Quoted 4 lines · Cornelia Huck
With virtio-1, we support more than 32 feature bits. Let's extend both host and guest features to 64, which should suffice for a while.
vhost and migration have been ignored for now.
[snip]
include/hw/virtio/virtio.h line 59
Quoted 10 lines
include/hw/virtio/virtio.h +2
-0@@ -55,6 +55,12 @@/* A guest should never accept this. It implies negotiation is broken. */ #define VIRTIO_F_BAD_FEATURE 30 +/* v1.0 compliant. */ +#define VIRTIO_F_VERSION_1 32This is already in the kernel header, isn't it?
Quoted 4 lines
Quoted 2 lines
Yes. But nearly all files include this header but not the kernel header.
Can't you change that? Or this file include the kernel header?
AFAIK non-KVM code should never try to include one of the Linux headers to avoid breaking on non-Linux platforms (for example <linux/types.h> is not available on OS X, see http://patchwork.ozlabs.org/patch/424655/ ). So it's a little bit ugly to define these things twice, but it seems the only way to stay portable.
Thomas
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [Qemu-devel] [PATCH RFC v6 05/20] virtio: support more feature bits
Quoted 35 lines · Thomas Huth
Hi,
Quoted 29 lines · On Thu, 29 Jan 2015 11:11:32 +1100 David Gibson <[email protected]>…
Quoted 27 lines · Cornelia Huck
Quoted 16 lines · On Thu, 22 Jan 2015 12:43:43 +1100 David Gibson <[email protected]>…
Quoted 4 lines · Cornelia Huck
With virtio-1, we support more than 32 feature bits. Let's extend both host and guest features to 64, which should suffice for a while.
vhost and migration have been ignored for now.
[snip]
Quoted 8 lines
include/hw/virtio/virtio.h +0
-0@@ -55,6 +55,12 @@/* A guest should never accept this. It implies negotiation is broken. */ #define VIRTIO_F_BAD_FEATURE 30Quoted 4 lines
include/hw/virtio/virtio.h line 59
Quoted 2 lines
include/hw/virtio/virtio.h +2
-0+/* v1.0 compliant. */ +#define VIRTIO_F_VERSION_1 32This is already in the kernel header, isn't it?
Yes. But nearly all files include this header but not the kernel header.
Quoted 7 lines
Quoted 1 line
Can't you change that? Or this file include the kernel header?
AFAIK non-KVM code should never try to include one of the Linux headers to avoid breaking on non-Linux platforms (for example <
linux/types.h> is not available on OS X, see http://patchwork.ozlabs.org/patch/424655/ ). So it's a little bit ugly to define these things twice, but it seems the only way to stay portable.
Ah, yeah, good point.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerRe: [Qemu-devel] [PATCH RFC v6 05/20] virtio: support more feature bits
Quoted 38 lines · David Gibson
Quoted 37 lines · Thomas Huth
Hi,
Quoted 30 lines · On Thu, 29 Jan 2015 11:11:32 +1100 David Gibson <[email protected]>…
Quoted 19 lines · Cornelia Huck
Quoted 16 lines · On Thu, 22 Jan 2015 12:43:43 +1100 David Gibson <[email protected]>…
Quoted 4 lines · Cornelia Huck
With virtio-1, we support more than 32 feature bits. Let's extend both host and guest features to 64, which should suffice for a while.
vhost and migration have been ignored for now.
[snip]
Quoted 8 lines
include/hw/virtio/virtio.h +0
-0@@ -55,6 +55,12 @@/* A guest should never accept this. It implies negotiation is broken. */ #define VIRTIO_F_BAD_FEATURE 30Quoted 8 lines
Quoted 4 lines
include/hw/virtio/virtio.h line 59
Quoted 2 lines
include/hw/virtio/virtio.h +2
-0+/* v1.0 compliant. */ +#define VIRTIO_F_VERSION_1 32This is already in the kernel header, isn't it?
Yes. But nearly all files include this header but not the kernel header.
Can't you change that? Or this file include the kernel header?
Quoted 7 lines
Quoted 5 lines
AFAIK non-KVM code should never try to include one of the Linux headers to avoid breaking on non-Linux platforms (for example <
linux/types.h> is not available on OS X, see http://patchwork.ozlabs.org/patch/424655/ ). So it's a little bit ugly to define these things twice, but it seems the only way to stay portable.Ah, yeah, good point.
I do intend to write a script to import more headers from linux, changing them on the fly to drop dependency on linux/types.h etc.
If someone wants to beat me to it, so much the better.
Quoted 5 lines
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH RFC v6 18/20] virtio: support revision-specific features
In reply to Michael S. TsirkinQuoted 17 lines · On Wed, 7 Jan 2015 21:10:07 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 16 lines · Cornelia Huck
Quoted 12 lines · On Sun, 28 Dec 2014 10:32:06 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 6 lines · Cornelia Huck
Devices may support different sets of feature bits depending on which revision they're operating at. Let's give the transport a way to re-query the device about its features when the revision has been changed.
Signed-off-by Cornelia Huck <[email protected]>So now we have both
get_featuresandget_features_rev, and it's never clear which revision doeshost_featuresrefer to. IMHO that's just too messy.
Let's addget_legacy_featuresandhost_legacy_featuresinstead?
Quoted 6 lines
Quoted 2 lines
I wanted to avoid touching anything that does not support version 1. And this interface might still work for later revisions, no?
We can add _modern_ then, or rename
host_featurestohost_legacy_featureseverywhere as preparation.
OK, I've ditched the "don't modify old stuff" goal and introduced ->get_features_legacy(). For now, devices will add VERSION_1 in their ->get_features() callback when they support it. (For many devices, this will be the only difference between the two callbacks.)
Two sets of host_features don't make much sense to me.
I've hacked up something and will play with it a bit; I might post a new patch series next week.
Re: [Qemu-devel] [PATCH RFC v6 19/20] virtio-blk: revision specific feature bits
In reply to Michael S. TsirkinQuoted 16 lines · On Wed, 7 Jan 2015 21:11:44 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 15 lines · Cornelia Huck
Quoted 12 lines · On Sun, 28 Dec 2014 12:24:46 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 6 lines · Cornelia Huck
Wire up virtio-blk to provide different feature bit sets depending on whether legacy or v1.0 has been requested.
Note that
VERSION_1is still disabled due to missingANY_LAYOUTsupport.Signed-off-by Cornelia Huck <[email protected]>So we need some way for devices to tell transports not to negotiate rev 1.
Does clearingVERSION_1have this effect?
Quoted 8 lines
Quoted 6 lines
I just noticed that my patch is running in circles here.
What we need is probably the transport-dependent maximum revision checker (which at least for ccw is acting on a device) pass in the requested revision and check if the feature bits for the revision include
VERSION_1. Does that make sense?Just make devices set 'rev 1 supported' flag?
I'm now using the ->get_features() callback to check for VERSION_1 (assuming every device that supports it adds the bit in its callback) and only allow rev 1 if it is present. Will play with this a bit as well.
Michael S. Tsirkin
maintainerRe: [Qemu-devel] [PATCH RFC v6 18/20] virtio: support revision-specific features
In reply to Cornelia HuckQuoted 27 lines · Cornelia Huck
Quoted 17 lines · On Wed, 7 Jan 2015 21:10:07 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 16 lines · Cornelia Huck
Quoted 12 lines · On Sun, 28 Dec 2014 10:32:06 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 6 lines · Cornelia Huck
Devices may support different sets of feature bits depending on which revision they're operating at. Let's give the transport a way to re-query the device about its features when the revision has been changed.
Signed-off-by Cornelia Huck <[email protected]>So now we have both
get_featuresandget_features_rev, and it's never clear which revision doeshost_featuresrefer to. IMHO that's just too messy.
Let's addget_legacy_featuresandhost_legacy_featuresinstead?Quoted 6 lines
Quoted 2 lines
I wanted to avoid touching anything that does not support version 1. And this interface might still work for later revisions, no?
We can add _modern_ then, or rename
host_featurestohost_legacy_featureseverywhere as preparation.
Quoted 6 lines
OK, I've ditched the "don't modify old stuff" goal and introduced ->get_features_legacy(). For now, devices will add
VERSION_1in their ->get_features() callback when they support it. (For many devices, this will be the only difference between the two callbacks.)Two sets of
host_featuresdon't make much sense to me.
It's the most natural implementation given that some features are only set for legacy and some (will be) only for modern interfaces.
But we'll see.
Quoted 2 lines
I've hacked up something and will play with it a bit; I might post a new patch series next week.
Re: [Qemu-devel] [PATCH RFC v6 18/20] virtio: support revision-specific features
Quoted 33 lines · On Sun, 1 Feb 2015 23:29:20 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 32 lines · Cornelia Huck
Quoted 17 lines · On Wed, 7 Jan 2015 21:10:07 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 16 lines · Cornelia Huck
Quoted 12 lines · On Sun, 28 Dec 2014 10:32:06 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 6 lines · Cornelia Huck
Devices may support different sets of feature bits depending on which revision they're operating at. Let's give the transport a way to re-query the device about its features when the revision has been changed.
Signed-off-by Cornelia Huck <[email protected]>So now we have both
get_featuresandget_features_rev, and it's never clear which revision doeshost_featuresrefer to. IMHO that's just too messy.
Let's addget_legacy_featuresandhost_legacy_featuresinstead?Quoted 6 lines
Quoted 2 lines
I wanted to avoid touching anything that does not support version 1. And this interface might still work for later revisions, no?
We can add _modern_ then, or rename
host_featurestohost_legacy_featureseverywhere as preparation.OK, I've ditched the "don't modify old stuff" goal and introduced ->get_features_legacy(). For now, devices will add
VERSION_1in their ->get_features() callback when they support it. (For many devices, this will be the only difference between the two callbacks.)
Quoted 5 lines
Quoted 1 line
Two sets of
host_featuresdon't make much sense to me.It's the most natural implementation given that some features are only set for legacy and some (will be) only for modern interfaces.
We may be talking about different things: There's the host_features field which is referenced by the different device types, and there are the sets of features for legacy or modern devices. These are currently set dynamically in the ->get_features() callbacks, although we could possibly convert them to pre-set values like in the kernel. Then I agree, two sets would be natural. But I'd rather stick with the current method, if only to avoid churn.