Skip to contentSkip to conversation

virtio: avoid leading underscores for helpers

PATCH In review Cornelia Huck 3 participants 13 messages Mar 10, 2015 – Mar 13, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio: avoid leading underscores for helpers

Commit ef546f1275f6563e8934dd5e338d29d9f9909ca6 ("virtio: add feature checking helpers") introduced a helper __virtio_has_feature. We don't want to use reserved identifiers, though, so let's rename __virtio_has_feature to virtio_has_feature and virtio_has_feature to virtio_vdev_has_feature.

---
 hw/block/virtio-blk.c       |  5 +++--
 hw/char/virtio-serial-bus.c |  2 +-
 hw/net/virtio-net.c         | 22 +++++++++++-----------
 hw/scsi/virtio-scsi.c       |  8 ++++----
 hw/virtio/dataplane/vring.c | 10 +++++-----
 hw/virtio/virtio-balloon.c  |  2 +-
 hw/virtio/virtio.c          |  8 ++++----
 include/hw/virtio/virtio.h  |  7 ++++---
 8 files changed, 33 insertions(+), 31 deletions(-)
hw/block/virtio-blk.c +3 -2
index 1e5b918..9423d4a 100644
@@ -758,10 +758,11 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
      *
      * s->blk would erroneously be placed in writethrough mode.
      */
-    if (!virtio_has_feature(vdev, VIRTIO_BLK_F_CONFIG_WCE)) {
+    if (!virtio_vdev_has_feature(vdev, VIRTIO_BLK_F_CONFIG_WCE)) {
         aio_context_acquire(blk_get_aio_context(s->blk));
         blk_set_enable_write_cache(s->blk,
-                                   virtio_has_feature(vdev, VIRTIO_BLK_F_WCE));
+                                   virtio_vdev_has_feature(vdev,
+                                                           VIRTIO_BLK_F_WCE));
         aio_context_release(blk_get_aio_context(s->blk));
     }
 }
hw/char/virtio-serial-bus.c +1 -1
index 9a029d2..b820e2c 100644
@@ -75,7 +75,7 @@ static VirtIOSerialPort *find_port_by_name(char *name)
 static bool use_multiport(VirtIOSerial *vser)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(vser);
-    return virtio_has_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT);
+    return virtio_vdev_has_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT);
 }
 
 static size_t write_to_port(VirtIOSerialPort *port,
hw/net/virtio-net.c +11 -11
index 1187ab8..ec25db5 100644
@@ -86,7 +86,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) &&
+    if (!virtio_vdev_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 (!virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VLAN)) {
+    if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_VLAN)) {
         info->vlan = RX_STATE_ALL;
     } else if (!info->vlan_table) {
         info->vlan = RX_STATE_NONE;
@@ -520,11 +520,11 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
     int i;
 
     virtio_net_set_multiqueue(n,
-                              __virtio_has_feature(features, VIRTIO_NET_F_MQ));
+                              virtio_has_feature(features, VIRTIO_NET_F_MQ));
 
     virtio_net_set_mrg_rx_bufs(n,
-                               __virtio_has_feature(features,
-                                                    VIRTIO_NET_F_MRG_RXBUF));
+                               virtio_has_feature(features,
+                                                  VIRTIO_NET_F_MRG_RXBUF));
 
     if (n->has_vnet_hdr) {
         n->curr_guest_offloads =
@@ -541,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 (__virtio_has_feature(features, VIRTIO_NET_F_CTRL_VLAN)) {
+    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);
@@ -588,7 +588,7 @@ static int virtio_net_handle_offloads(VirtIONet *n, uint8_t cmd,
     uint64_t offloads;
     size_t s;
 
-    if (!virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
+    if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
         return VIRTIO_NET_ERR;
     }
 
@@ -1381,7 +1381,7 @@ static void virtio_net_save_device(VirtIODevice *vdev, QEMUFile *f)
         }
     }
 
-    if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
+    if (virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
         qemu_put_be64(f, n->curr_guest_offloads);
     }
 }
@@ -1489,7 +1489,7 @@ static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f,
         }
     }
 
-    if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
+    if (virtio_vdev_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);
@@ -1516,8 +1516,8 @@ static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f,
         qemu_get_subqueue(n->nic, i)->link_down = link_down;
     }
 
-    if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ANNOUNCE) &&
-        virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ)) {
+    if (virtio_vdev_has_feature(vdev, VIRTIO_NET_F_GUEST_ANNOUNCE) &&
+        virtio_vdev_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
index cfb52e8..ca36cfe 100644
@@ -145,7 +145,7 @@ static int virtio_scsi_parse_req(VirtIOSCSIReq *req,
      *
      * TODO: always disable this workaround for virtio 1.0 devices.
      */
-    if (!virtio_has_feature(vdev, VIRTIO_F_ANY_LAYOUT)) {
+    if (!virtio_vdev_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;
     }
@@ -745,7 +745,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 (virtio_has_feature(vdev, VIRTIO_SCSI_F_CHANGE) &&
+    if (virtio_vdev_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,
         aio_context_release(s->ctx);
     }
 
-    if (virtio_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) {
+    if (virtio_vdev_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 (virtio_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) {
+    if (virtio_vdev_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
index 5c7b8c2..023ec83 100644
@@ -105,7 +105,7 @@ void vring_teardown(Vring *vring, VirtIODevice *vdev, int n)
 /* Disable guest->host notifies */
 void vring_disable_notification(VirtIODevice *vdev, Vring *vring)
 {
-    if (!virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
+    if (!virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
         vring_set_used_flags(vdev, vring, VRING_USED_F_NO_NOTIFY);
     }
 }
@@ -116,7 +116,7 @@ void vring_disable_notification(VirtIODevice *vdev, Vring *vring)
  */
 bool vring_enable_notification(VirtIODevice *vdev, Vring *vring)
 {
-    if (virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
+    if (virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
         vring_avail_event(&vring->vr) = vring->vr.avail->idx;
     } else {
         vring_clear_used_flags(vdev, vring, VRING_USED_F_NO_NOTIFY);
@@ -135,12 +135,12 @@ bool vring_should_notify(VirtIODevice *vdev, Vring *vring)
      * interrupts. */
     smp_mb();
 
-    if (virtio_has_feature(vdev, VIRTIO_F_NOTIFY_ON_EMPTY) &&
+    if (virtio_vdev_has_feature(vdev, VIRTIO_F_NOTIFY_ON_EMPTY) &&
         unlikely(!vring_more_avail(vdev, vring))) {
         return true;
     }
 
-    if (!virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
+    if (!virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
         return !(vring_get_avail_flags(vdev, vring) &
                  VRING_AVAIL_F_NO_INTERRUPT);
     }
@@ -401,7 +401,7 @@ int vring_pop(VirtIODevice *vdev, Vring *vring,
 
     /* On success, increment avail index. */
     vring->last_avail_idx++;
-    if (virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
+    if (virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
         vring_avail_event(&vring->vr) = vring->last_avail_idx;
     }
 
hw/virtio/virtio-balloon.c +1 -1
index 95b0643..912609c 100644
@@ -70,7 +70,7 @@ static inline void reset_stats(VirtIOBalloon *dev)
 static bool balloon_stats_supported(const VirtIOBalloon *s)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(s);
-    return virtio_has_feature(vdev, VIRTIO_BALLOON_F_STATS_VQ);
+    return virtio_vdev_has_feature(vdev, VIRTIO_BALLOON_F_STATS_VQ);
 }
 
 static bool balloon_stats_enabled(const VirtIOBalloon *s)
hw/virtio/virtio.c +4 -4
index 3c6e430..a17920f 100644
@@ -217,7 +217,7 @@ static inline void vring_set_avail_event(VirtQueue *vq, uint16_t val)
 void virtio_queue_set_notification(VirtQueue *vq, int enable)
 {
     vq->notification = enable;
-    if (virtio_has_feature(vq->vdev, VIRTIO_RING_F_EVENT_IDX)) {
+    if (virtio_vdev_has_feature(vq->vdev, VIRTIO_RING_F_EVENT_IDX)) {
         vring_set_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 (virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
+    if (virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
         vring_set_avail_event(vq, vq->last_avail_idx);
     }
 
@@ -826,12 +826,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 (virtio_has_feature(vdev, VIRTIO_F_NOTIFY_ON_EMPTY) &&
+    if (virtio_vdev_has_feature(vdev, VIRTIO_F_NOTIFY_ON_EMPTY) &&
         !vq->inuse && vring_avail_idx(vq) == vq->last_avail_idx) {
         return true;
     }
 
-    if (!virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
+    if (!virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
         return !(vring_avail_flags(vq) & VRING_AVAIL_F_NO_INTERRUPT);
     }
 
include/hw/virtio/virtio.h +4 -3
index d95f8b6..28ffdd8 100644
@@ -231,15 +231,16 @@ 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)
+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)
+static inline bool virtio_vdev_has_feature(VirtIODevice *vdev,
+                                           unsigned int fbit)
 {
-    return __virtio_has_feature(vdev->guest_features, fbit);
+    return virtio_has_feature(vdev->guest_features, fbit);
 }
 
 static inline bool virtio_is_big_endian(VirtIODevice *vdev)
Signature · 1 line
2.3.2
#1 lore raw
Quoted 5 lines · Cornelia Huck

Commit ef546f1275f6563e8934dd5e338d29d9f9909ca6 ("virtio: add feature checking helpers") introduced a helper __virtio_has_feature. We don't want to use reserved identifiers, though, so let's rename __virtio_has_feature to virtio_has_feature and virtio_has_feature to virtio_vdev_has_feature.

I don't think it's urgent to fix in master. Let's focus on getting virtio 1.0 branch merged instead.

Quoted 290 lines
---
 hw/block/virtio-blk.c       |  5 +++--
 hw/char/virtio-serial-bus.c |  2 +-
 hw/net/virtio-net.c         | 22 +++++++++++-----------
 hw/scsi/virtio-scsi.c       |  8 ++++----
 hw/virtio/dataplane/vring.c | 10 +++++-----
 hw/virtio/virtio-balloon.c  |  2 +-
 hw/virtio/virtio.c          |  8 ++++----
 include/hw/virtio/virtio.h  |  7 ++++---
 8 files changed, 33 insertions(+), 31 deletions(-)
hw/block/virtio-blk.c +3 -2
index 1e5b918..9423d4a 100644
@@ -758,10 +758,11 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
      *
      * s->blk would erroneously be placed in writethrough mode.
      */
-    if (!virtio_has_feature(vdev, VIRTIO_BLK_F_CONFIG_WCE)) {
+    if (!virtio_vdev_has_feature(vdev, VIRTIO_BLK_F_CONFIG_WCE)) {
         aio_context_acquire(blk_get_aio_context(s->blk));
         blk_set_enable_write_cache(s->blk,
-                                   virtio_has_feature(vdev, VIRTIO_BLK_F_WCE));
+                                   virtio_vdev_has_feature(vdev,
+                                                           VIRTIO_BLK_F_WCE));
         aio_context_release(blk_get_aio_context(s->blk));
     }
 }
hw/char/virtio-serial-bus.c +1 -1
index 9a029d2..b820e2c 100644
@@ -75,7 +75,7 @@ static VirtIOSerialPort *find_port_by_name(char *name)
 static bool use_multiport(VirtIOSerial *vser)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(vser);
-    return virtio_has_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT);
+    return virtio_vdev_has_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT);
 }
 
 static size_t write_to_port(VirtIOSerialPort *port,
hw/net/virtio-net.c +11 -11
index 1187ab8..ec25db5 100644
@@ -86,7 +86,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) &&
+    if (!virtio_vdev_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 (!virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VLAN)) {
+    if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_VLAN)) {
         info->vlan = RX_STATE_ALL;
     } else if (!info->vlan_table) {
         info->vlan = RX_STATE_NONE;
@@ -520,11 +520,11 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
     int i;
 
     virtio_net_set_multiqueue(n,
-                              __virtio_has_feature(features, VIRTIO_NET_F_MQ));
+                              virtio_has_feature(features, VIRTIO_NET_F_MQ));
 
     virtio_net_set_mrg_rx_bufs(n,
-                               __virtio_has_feature(features,
-                                                    VIRTIO_NET_F_MRG_RXBUF));
+                               virtio_has_feature(features,
+                                                  VIRTIO_NET_F_MRG_RXBUF));
 
     if (n->has_vnet_hdr) {
         n->curr_guest_offloads =
@@ -541,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 (__virtio_has_feature(features, VIRTIO_NET_F_CTRL_VLAN)) {
+    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);
@@ -588,7 +588,7 @@ static int virtio_net_handle_offloads(VirtIONet *n, uint8_t cmd,
     uint64_t offloads;
     size_t s;
 
-    if (!virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
+    if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
         return VIRTIO_NET_ERR;
     }
 
@@ -1381,7 +1381,7 @@ static void virtio_net_save_device(VirtIODevice *vdev, QEMUFile *f)
         }
     }
 
-    if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
+    if (virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
         qemu_put_be64(f, n->curr_guest_offloads);
     }
 }
@@ -1489,7 +1489,7 @@ static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f,
         }
     }
 
-    if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
+    if (virtio_vdev_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);
@@ -1516,8 +1516,8 @@ static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f,
         qemu_get_subqueue(n->nic, i)->link_down = link_down;
     }
 
-    if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ANNOUNCE) &&
-        virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ)) {
+    if (virtio_vdev_has_feature(vdev, VIRTIO_NET_F_GUEST_ANNOUNCE) &&
+        virtio_vdev_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
index cfb52e8..ca36cfe 100644
@@ -145,7 +145,7 @@ static int virtio_scsi_parse_req(VirtIOSCSIReq *req,
      *
      * TODO: always disable this workaround for virtio 1.0 devices.
      */
-    if (!virtio_has_feature(vdev, VIRTIO_F_ANY_LAYOUT)) {
+    if (!virtio_vdev_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;
     }
@@ -745,7 +745,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 (virtio_has_feature(vdev, VIRTIO_SCSI_F_CHANGE) &&
+    if (virtio_vdev_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,
         aio_context_release(s->ctx);
     }
 
-    if (virtio_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) {
+    if (virtio_vdev_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 (virtio_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) {
+    if (virtio_vdev_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
index 5c7b8c2..023ec83 100644
@@ -105,7 +105,7 @@ void vring_teardown(Vring *vring, VirtIODevice *vdev, int n)
 /* Disable guest->host notifies */
 void vring_disable_notification(VirtIODevice *vdev, Vring *vring)
 {
-    if (!virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
+    if (!virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
         vring_set_used_flags(vdev, vring, VRING_USED_F_NO_NOTIFY);
     }
 }
@@ -116,7 +116,7 @@ void vring_disable_notification(VirtIODevice *vdev, Vring *vring)
  */
 bool vring_enable_notification(VirtIODevice *vdev, Vring *vring)
 {
-    if (virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
+    if (virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
         vring_avail_event(&vring->vr) = vring->vr.avail->idx;
     } else {
         vring_clear_used_flags(vdev, vring, VRING_USED_F_NO_NOTIFY);
@@ -135,12 +135,12 @@ bool vring_should_notify(VirtIODevice *vdev, Vring *vring)
      * interrupts. */
     smp_mb();
 
-    if (virtio_has_feature(vdev, VIRTIO_F_NOTIFY_ON_EMPTY) &&
+    if (virtio_vdev_has_feature(vdev, VIRTIO_F_NOTIFY_ON_EMPTY) &&
         unlikely(!vring_more_avail(vdev, vring))) {
         return true;
     }
 
-    if (!virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
+    if (!virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
         return !(vring_get_avail_flags(vdev, vring) &
                  VRING_AVAIL_F_NO_INTERRUPT);
     }
@@ -401,7 +401,7 @@ int vring_pop(VirtIODevice *vdev, Vring *vring,
 
     /* On success, increment avail index. */
     vring->last_avail_idx++;
-    if (virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
+    if (virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
         vring_avail_event(&vring->vr) = vring->last_avail_idx;
     }
 
hw/virtio/virtio-balloon.c +1 -1
index 95b0643..912609c 100644
@@ -70,7 +70,7 @@ static inline void reset_stats(VirtIOBalloon *dev)
 static bool balloon_stats_supported(const VirtIOBalloon *s)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(s);
-    return virtio_has_feature(vdev, VIRTIO_BALLOON_F_STATS_VQ);
+    return virtio_vdev_has_feature(vdev, VIRTIO_BALLOON_F_STATS_VQ);
 }
 
 static bool balloon_stats_enabled(const VirtIOBalloon *s)
hw/virtio/virtio.c +4 -4
index 3c6e430..a17920f 100644
@@ -217,7 +217,7 @@ static inline void vring_set_avail_event(VirtQueue *vq, uint16_t val)
 void virtio_queue_set_notification(VirtQueue *vq, int enable)
 {
     vq->notification = enable;
-    if (virtio_has_feature(vq->vdev, VIRTIO_RING_F_EVENT_IDX)) {
+    if (virtio_vdev_has_feature(vq->vdev, VIRTIO_RING_F_EVENT_IDX)) {
         vring_set_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 (virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
+    if (virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
         vring_set_avail_event(vq, vq->last_avail_idx);
     }
 
@@ -826,12 +826,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 (virtio_has_feature(vdev, VIRTIO_F_NOTIFY_ON_EMPTY) &&
+    if (virtio_vdev_has_feature(vdev, VIRTIO_F_NOTIFY_ON_EMPTY) &&
         !vq->inuse && vring_avail_idx(vq) == vq->last_avail_idx) {
         return true;
     }
 
-    if (!virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
+    if (!virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
         return !(vring_avail_flags(vq) & VRING_AVAIL_F_NO_INTERRUPT);
     }
 
include/hw/virtio/virtio.h +4 -3
index d95f8b6..28ffdd8 100644
@@ -231,15 +231,16 @@ 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)
+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)
+static inline bool virtio_vdev_has_feature(VirtIODevice *vdev,
+                                           unsigned int fbit)
 {
-    return __virtio_has_feature(vdev->guest_features, fbit);
+    return virtio_has_feature(vdev->guest_features, fbit);
 }
 
 static inline bool virtio_is_big_endian(VirtIODevice *vdev)
Signature · 1 line
2.3.2
#2 lore raw
Quoted 9 lines · On Tue, 10 Mar 2015 15:12:14 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 5 lines · Cornelia Huck

Commit ef546f1275f6563e8934dd5e338d29d9f9909ca6 ("virtio: add feature checking helpers") introduced a helper __virtio_has_feature. We don't want to use reserved identifiers, though, so let's rename __virtio_has_feature to virtio_has_feature and virtio_has_feature to virtio_vdev_has_feature.

I don't think it's urgent to fix in master. Let's focus on getting virtio 1.0 branch merged instead.

I stumbled over this actually when trying to update my virtio-1 branch. I already did that change there (as promised in <[email protected]>), but it got lost somewhere in my moving chaos.

What's the status of your virtio-1.0 branch? Would it be worthwile for me to rebase on top of it so I can figure out which changes I have not yet sent out?

#3 lore raw
Quoted 13 lines · Cornelia Huck
Quoted 9 lines · On Tue, 10 Mar 2015 15:12:14 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 5 lines · Cornelia Huck

Commit ef546f1275f6563e8934dd5e338d29d9f9909ca6 ("virtio: add feature checking helpers") introduced a helper __virtio_has_feature. We don't want to use reserved identifiers, though, so let's rename __virtio_has_feature to virtio_has_feature and virtio_has_feature to virtio_vdev_has_feature.

I don't think it's urgent to fix in master. Let's focus on getting virtio 1.0 branch merged instead.

Quoted 6 lines

I stumbled over this actually when trying to update my virtio-1 branch. I already did that change there (as promised in <[email protected]>), but it got lost somewhere in my moving chaos.

What's the status of your virtio-1.0 branch?

virtio pci works there too now, so I started looking at upstreaming stuff from that branch. Already did some.

Quoted 3 lines

Would it be worthwile for
me to rebase on top of it so I can figure out which changes I have not yet sent out?

Absolutely.

#4 lore raw
Quoted 21 lines · On Tue, 10 Mar 2015 15:27:24 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 13 lines · Cornelia Huck
Quoted 9 lines · On Tue, 10 Mar 2015 15:12:14 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 5 lines · Cornelia Huck

Commit ef546f1275f6563e8934dd5e338d29d9f9909ca6 ("virtio: add feature checking helpers") introduced a helper __virtio_has_feature. We don't want to use reserved identifiers, though, so let's rename __virtio_has_feature to virtio_has_feature and virtio_has_feature to virtio_vdev_has_feature.

I don't think it's urgent to fix in master. Let's focus on getting virtio 1.0 branch merged instead.

Quoted 6 lines

I stumbled over this actually when trying to update my virtio-1 branch. I already did that change there (as promised in <[email protected]>), but it got lost somewhere in my moving chaos.

What's the status of your virtio-1.0 branch?

Quoted 8 lines

virtio pci works there too now, so I started looking at upstreaming stuff from that branch. Already did some.

Quoted 3 lines

Would it be worthwile for
me to rebase on top of it so I can figure out which changes I have not yet sent out?

Absolutely.

OK, it's actually not that much:

- this change :)
- All ccw accesses are BE (see <[email protected]>). I'll do two
patches: One for the existing ccws which will go via my tree and one for the new set-revision ccw which should be squashed into that patch.
- Use legacy/non-legacy feature bit getters instead of revision-specific ones (see <[email protected]>). Should probably replace the existing patches introducing get_features_rev and using it in virtio-blk.

Also, it seems there are some r-bs that had been given for my patches that are missing on your branch.

#5 lore raw
Quoted 33 lines · Cornelia Huck
Quoted 21 lines · On Tue, 10 Mar 2015 15:27:24 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 13 lines · Cornelia Huck
Quoted 9 lines · On Tue, 10 Mar 2015 15:12:14 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 5 lines · Cornelia Huck

Commit ef546f1275f6563e8934dd5e338d29d9f9909ca6 ("virtio: add feature checking helpers") introduced a helper __virtio_has_feature. We don't want to use reserved identifiers, though, so let's rename __virtio_has_feature to virtio_has_feature and virtio_has_feature to virtio_vdev_has_feature.

I don't think it's urgent to fix in master. Let's focus on getting virtio 1.0 branch merged instead.

Quoted 6 lines

I stumbled over this actually when trying to update my virtio-1 branch. I already did that change there (as promised in <[email protected]>), but it got lost somewhere in my moving chaos.

What's the status of your virtio-1.0 branch?

Quoted 8 lines

virtio pci works there too now, so I started looking at upstreaming stuff from that branch. Already did some.

Quoted 3 lines

Would it be worthwile for
me to rebase on top of it so I can figure out which changes I have not yet sent out?

Absolutely.

Quoted 7 lines

OK, it's actually not that much:

- this change :)
- All ccw accesses are BE (see <[email protected]>). I'll do two
patches: One for the existing ccws which will go via my tree and one for the new set-revision ccw which should be squashed into that patch.

Will rebasing virtio-1.0 on top of master after your patch is upstream do the trick as well?

Quoted 5 lines

- Use legacy/non-legacy feature bit getters instead of revision-specific ones (see <[email protected]>). Should probably replace the existing patches introducing get_features_rev and using it in virtio-blk.

Right, but for that, let's get it all in working order using patches on top, first. Then, re-split logically.

Quoted 2 lines

Also, it seems there are some r-bs that had been given for my patches that are missing on your branch.

I might have missed some - can you hunt up the msg ids?

#6 lore raw
Quoted 36 lines · On Tue, 10 Mar 2015 17:34:27 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 35 lines · Cornelia Huck
Quoted 21 lines · On Tue, 10 Mar 2015 15:27:24 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 13 lines · Cornelia Huck
Quoted 9 lines · On Tue, 10 Mar 2015 15:12:14 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 5 lines · Cornelia Huck

Commit ef546f1275f6563e8934dd5e338d29d9f9909ca6 ("virtio: add feature checking helpers") introduced a helper __virtio_has_feature. We don't want to use reserved identifiers, though, so let's rename __virtio_has_feature to virtio_has_feature and virtio_has_feature to virtio_vdev_has_feature.

I don't think it's urgent to fix in master. Let's focus on getting virtio 1.0 branch merged instead.

Quoted 6 lines

I stumbled over this actually when trying to update my virtio-1 branch. I already did that change there (as promised in <[email protected]>), but it got lost somewhere in my moving chaos.

What's the status of your virtio-1.0 branch?

Quoted 8 lines

virtio pci works there too now, so I started looking at upstreaming stuff from that branch. Already did some.

Quoted 3 lines

Would it be worthwile for
me to rebase on top of it so I can figure out which changes I have not yet sent out?

Absolutely.

OK, it's actually not that much:

Quoted 8 lines
Quoted 5 lines

- this change :)
- All ccw accesses are BE (see <[email protected]>). I'll do two
patches: One for the existing ccws which will go via my tree and one for the new set-revision ccw which should be squashed into that patch.

Will rebasing virtio-1.0 on top of master after your patch is upstream do the trick as well?

set-revision needs to merge the change, I did not introduce generic helpers.

Quoted 9 lines
Quoted 6 lines

- Use legacy/non-legacy feature bit getters instead of revision-specific ones (see <[email protected]>). Should probably replace the existing patches introducing get_features_rev and using it in virtio-blk.

Right, but for that, let's get it all in working order using patches on top, first. Then, re-split logically.

I'll prepare a patch for review.

Quoted 5 lines
Quoted 3 lines

Also, it seems there are some r-bs that had been given for my patches that are missing on your branch.

I might have missed some - can you hunt up the msg ids?

There are at least:

<[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]>

...and some for the virtio patches that are already upstream :(

#7 lore raw

PATCH 1/1 virtio: legacy features callback

Use a "legacy features" instead of a "revision specific" callback.

Updates "virtio: support revision-specific features" and "virtio-blk: revision specific feature bits" as currently in
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git virtio-1.0

---
 hw/9pfs/virtio-9p-device.c     |  5 +++--
 hw/block/virtio-blk.c          | 14 ++++----------
 hw/char/virtio-serial-bus.c    | 22 +++++++++++++++++-----
 hw/net/virtio-net.c            | 31 +++++++++++++++++++++++++++----
 hw/s390x/s390-virtio-bus.c     |  4 ++--
 hw/s390x/virtio-ccw.c          | 12 ++++++------
 hw/s390x/virtio-ccw.h          |  4 ++--
 hw/scsi/virtio-scsi.c          |  8 ++++++++
 hw/virtio/virtio-balloon.c     |  5 +++--
 hw/virtio/virtio-bus.c         | 28 ++++++++++++++++++----------
 hw/virtio/virtio-mmio.c        |  4 ++--
 hw/virtio/virtio-pci.c         |  4 ++--
 hw/virtio/virtio-rng.c         |  7 +++++++
 hw/virtio/virtio.c             | 12 ++++++++++++
 include/hw/virtio/virtio-bus.h |  5 ++---
 include/hw/virtio/virtio.h     |  6 +++---
 16 files changed, 118 insertions(+), 53 deletions(-)
hw/9pfs/virtio-9p-device.c +3 -2
index 60f9ff9..5f0aa99 100644
@@ -21,7 +21,8 @@
 #include "virtio-9p-coth.h"
 #include "hw/virtio/virtio-access.h"
 
-static uint64_t virtio_9p_get_features(VirtIODevice *vdev, uint64_t features)
+static uint64_t virtio_9p_get_features_legacy(VirtIODevice *vdev,
+                                              uint64_t features)
 {
     virtio_add_feature(&features, VIRTIO_9P_MOUNT_TAG);
     return features;
@@ -152,7 +153,7 @@ static void virtio_9p_class_init(ObjectClass *klass, void *data)
     dc->props = virtio_9p_properties;
     set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
     vdc->realize = virtio_9p_device_realize;
-    vdc->get_features = virtio_9p_get_features;
+    vdc->get_features_legacy = virtio_9p_get_features_legacy;
     vdc->get_config = virtio_9p_get_config;
 }
 
hw/block/virtio-blk.c +4 -10
index fdc236a..f8abf40 100644
@@ -564,7 +564,8 @@ static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config)
     aio_context_release(blk_get_aio_context(s->blk));
 }
 
-static uint64_t virtio_blk_get_features(VirtIODevice *vdev, uint64_t features)
+static uint64_t virtio_blk_get_features_legacy(VirtIODevice *vdev,
+                                               uint64_t features)
 {
     VirtIOBlock *s = VIRTIO_BLK(vdev);
 
@@ -587,15 +588,8 @@ 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)
+static uint64_t virtio_blk_get_features(VirtIODevice *vdev, uint64_t features)
 {
-    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);
@@ -839,7 +833,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->get_features_legacy = virtio_blk_get_features_legacy;
     vdc->set_status = virtio_blk_set_status;
     vdc->reset = virtio_blk_reset;
     vdc->save = virtio_blk_save_device;
hw/char/virtio-serial-bus.c +17 -5
index 2d2ed9c..7119f97 100644
@@ -467,18 +467,29 @@ static void handle_input(VirtIODevice *vdev, VirtQueue *vq)
 {
 }
 
-static uint64_t get_features(VirtIODevice *vdev, uint64_t features)
+static uint64_t get_features_common(VirtIOSerial *vser, uint64_t features)
 {
-    VirtIOSerial *vser;
-
-    vser = VIRTIO_SERIAL(vdev);
-
     if (vser->bus.max_nr_ports > 1) {
         virtio_add_feature(&features, VIRTIO_CONSOLE_F_MULTIPORT);
     }
     return features;
 }
 
+static uint64_t get_features(VirtIODevice *vdev, uint64_t features)
+{
+    VirtIOSerial *vser = VIRTIO_SERIAL(vdev);
+
+    /* virtio_add_feature(&features, VIRTIO_F_VERSION_1); */
+    return get_features_common(vser, features);
+}
+
+static uint64_t get_features_legacy(VirtIODevice *vdev, uint64_t features)
+{
+    VirtIOSerial *vser = VIRTIO_SERIAL(vdev);
+
+    return get_features_common(vser, features);
+}
+
 /* Guest requested config info */
 static void get_config(VirtIODevice *vdev, uint8_t *config_data)
 {
@@ -1076,6 +1087,7 @@ static void virtio_serial_class_init(ObjectClass *klass, void *data)
     vdc->realize = virtio_serial_device_realize;
     vdc->unrealize = virtio_serial_device_unrealize;
     vdc->get_features = get_features;
+    vdc->get_features_legacy = get_features_legacy;
     vdc->get_config = get_config;
     vdc->set_status = set_status;
     vdc->reset = vser_reset;
hw/net/virtio-net.c +27 -4
index 5fff769..0f6d283 100644
@@ -448,11 +448,9 @@ static void virtio_net_set_queues(VirtIONet *n)
 
 static void virtio_net_set_multiqueue(VirtIONet *n, int multiqueue);
 
-static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features)
+static uint64_t virtio_net_get_features_common(VirtIONet *n,
+                                               uint64_t features)
 {
-    VirtIONet *n = VIRTIO_NET(vdev);
-    NetClientState *nc = qemu_get_queue(n->nic);
-
     virtio_add_feature(&features, VIRTIO_NET_F_MAC);
 
     if (!peer_has_vnet_hdr(n)) {
@@ -472,6 +470,16 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features)
         virtio_clear_feature(&features, VIRTIO_NET_F_HOST_UFO);
     }
 
+    return 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);
+
+    features = virtio_net_get_features_common(n, features);
+
     if (!get_vhost_net(nc->peer)) {
         virtio_add_feature(&features, VIRTIO_F_VERSION_1);
         return features;
@@ -479,6 +487,20 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features)
     return vhost_net_get_features(get_vhost_net(nc->peer), features);
 }
 
+static uint64_t virtio_net_get_features_legacy(VirtIODevice *vdev,
+                                               uint64_t features)
+{
+    VirtIONet *n = VIRTIO_NET(vdev);
+    NetClientState *nc = qemu_get_queue(n->nic);
+
+    features = virtio_net_get_features_common(n, features);
+
+    if (!get_vhost_net(nc->peer)) {
+        return features;
+    }
+    return vhost_net_get_features(get_vhost_net(nc->peer), features);
+}
+
 static uint64_t virtio_net_bad_features(VirtIODevice *vdev)
 {
     uint64_t features = 0;
@@ -1753,6 +1775,7 @@ static void virtio_net_class_init(ObjectClass *klass, void *data)
     vdc->get_config = virtio_net_get_config;
     vdc->set_config = virtio_net_set_config;
     vdc->get_features = virtio_net_get_features;
+    vdc->get_features_legacy = virtio_net_get_features_legacy;
     vdc->set_features = virtio_net_set_features;
     vdc->bad_features = virtio_net_bad_features;
     vdc->reset = virtio_net_reset;
hw/s390x/s390-virtio-bus.c +2 -2
index 3635909..74cc2ad 100644
@@ -128,8 +128,8 @@ static int s390_virtio_device_init(VirtIOS390Device *dev, VirtIODevice *vdev)
 
     bus->dev_offs += dev_len;
 
-    dev->host_features = virtio_bus_get_vdev_features(&dev->bus,
-                                                      dev->host_features);
+    dev->host_features =
+        virtio_bus_get_vdev_features_legacy(&dev->bus, dev->host_features);
     s390_virtio_device_sync(dev);
     s390_virtio_reset_idx(dev);
     if (dev->qdev.hotplugged) {
hw/s390x/virtio-ccw.c +6 -6
index 8b6b2ab..7359e01 100644
@@ -693,16 +693,16 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
         }
         cpu_physical_memory_read(ccw.cda, &revinfo, len);
         if (dev->revision >= 0 ||
-            revinfo.revision > virtio_ccw_rev_max(dev)) {
+            revinfo.revision > virtio_ccw_rev_max(dev, vdev)) {
             ret = -ENOSYS;
             break;
         }
         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);
+        dev->host_features = dev->revision >= 1 ?
+            virtio_bus_get_vdev_features(&dev->bus, dev->host_features) :
+            virtio_bus_get_vdev_features_legacy(&dev->bus, dev->host_features);
         break;
     default:
         ret = -ENOSYS;
@@ -718,7 +718,7 @@ static void virtio_sch_disable_cb(SubchDev *sch)
     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);
+        virtio_bus_get_vdev_features_legacy(&dev->bus, dev->host_features);
 }
 
 static int virtio_ccw_device_init(VirtioCcwDevice *dev, VirtIODevice *vdev)
@@ -862,7 +862,7 @@ static int virtio_ccw_device_init(VirtioCcwDevice *dev, VirtIODevice *vdev)
 
     /* All devices start in legacy mode. */
     dev->host_features =
-        virtio_bus_get_vdev_features_rev(&dev->bus, dev->host_features, 0);
+        virtio_bus_get_vdev_features_legacy(&dev->bus, dev->host_features);
 
     css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid,
                           parent->hotplugged, 1);
hw/s390x/virtio-ccw.h +2 -2
index 37a9840..89f7685 100644
@@ -102,9 +102,9 @@ struct VirtioCcwDevice {
 };
 
 /* The maximum virtio revision we support. */
-static inline int virtio_ccw_rev_max(VirtioCcwDevice *dev)
+static inline int virtio_ccw_rev_max(VirtioCcwDevice *dev, VirtIODevice *vdev)
 {
-    return dev->host_features & (1ULL << VIRTIO_F_VERSION_1) ? 1 : 0;
+    return virtio_version_1_capable(vdev, dev->host_features) ? 1 : 0;
 }
 
 /* virtual css bus type */
hw/scsi/virtio-scsi.c +8 -0
index 1e7427e..77c451b 100644
@@ -630,6 +630,13 @@ static void virtio_scsi_set_config(VirtIODevice *vdev,
 static uint64_t virtio_scsi_get_features(VirtIODevice *vdev,
                                          uint64_t requested_features)
 {
+    /* virtio_add_feature(&requested_features, VIRTIO_F_VERSION_1); */
+    return requested_features;
+}
+
+static uint64_t virtio_scsi_get_features_legacy(VirtIODevice *vdev,
+                                                uint64_t requested_features)
+{
     return requested_features;
 }
 
@@ -961,6 +968,7 @@ static void virtio_scsi_class_init(ObjectClass *klass, void *data)
     vdc->unrealize = virtio_scsi_device_unrealize;
     vdc->set_config = virtio_scsi_set_config;
     vdc->get_features = virtio_scsi_get_features;
+    vdc->get_features_legacy = virtio_scsi_get_features_legacy;
     vdc->reset = virtio_scsi_reset;
     hc->plug = virtio_scsi_hotplug;
     hc->unplug = virtio_scsi_hotunplug;
hw/virtio/virtio-balloon.c +3 -2
index d2d7c3e..e33b93f 100644
@@ -303,7 +303,8 @@ static void virtio_balloon_set_config(VirtIODevice *vdev,
     }
 }
 
-static uint64_t virtio_balloon_get_features(VirtIODevice *vdev, uint64_t f)
+static uint64_t virtio_balloon_get_features_legacy(VirtIODevice *vdev,
+                                                   uint64_t f)
 {
     f |= (1 << VIRTIO_BALLOON_F_STATS_VQ);
     return f;
@@ -423,7 +424,7 @@ static void virtio_balloon_class_init(ObjectClass *klass, void *data)
     vdc->unrealize = virtio_balloon_device_unrealize;
     vdc->get_config = virtio_balloon_get_config;
     vdc->set_config = virtio_balloon_set_config;
-    vdc->get_features = virtio_balloon_get_features;
+    vdc->get_features_legacy = virtio_balloon_get_features_legacy;
     vdc->save = virtio_balloon_save_device;
     vdc->load = virtio_balloon_load_device;
 }
hw/virtio/virtio-bus.c +18 -10
index 927fa11..e4ab736 100644
@@ -97,26 +97,34 @@ size_t virtio_bus_get_vdev_config_len(VirtioBusState *bus)
 }
 
 /* Get the features of the plugged device. */
-uint64_t virtio_bus_get_vdev_features_rev(VirtioBusState *bus,
-                                          uint64_t requested_features,
-                                          unsigned int revision)
+uint64_t virtio_bus_get_vdev_features(VirtioBusState *bus,
+                                      uint64_t requested_features)
 {
     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) || (k->get_features_legacy != NULL));
+    if (k->get_features) {
+        return k->get_features(vdev, requested_features);
     }
-    assert(k->get_features != NULL);
-    return k->get_features(vdev, requested_features);
+    /* ensure version_1 is cleared on unsupported devices */
+    virtio_clear_feature(&requested_features, VIRTIO_F_VERSION_1);
+    return k->get_features_legacy(vdev, requested_features);
 }
 
-uint64_t virtio_bus_get_vdev_features(VirtioBusState *bus,
-                                      uint64_t requested_features)
+uint64_t virtio_bus_get_vdev_features_legacy(VirtioBusState *bus,
+                                             uint64_t requested_features)
 {
-    return virtio_bus_get_vdev_features_rev(bus, requested_features, 0);
+    VirtIODevice *vdev = virtio_bus_get_device(bus);
+    VirtioDeviceClass *k;
+
+    assert(vdev != NULL);
+    k = VIRTIO_DEVICE_GET_CLASS(vdev);
+    assert(k->get_features_legacy != NULL);
+    virtio_clear_feature(&requested_features, VIRTIO_F_VERSION_1);
+    return k->get_features_legacy(vdev, requested_features);
 }
 
 /* Get bad features of the plugged device. */
hw/virtio/virtio-mmio.c +2 -2
index 0c9b63b..3389b18 100644
@@ -353,8 +353,8 @@ static void virtio_mmio_device_plugged(DeviceState *opaque)
     VirtIOMMIOProxy *proxy = VIRTIO_MMIO(opaque);
 
     virtio_add_feature(&proxy->host_features, VIRTIO_F_NOTIFY_ON_EMPTY);
-    proxy->host_features = virtio_bus_get_vdev_features(&proxy->bus,
-                                                        proxy->host_features);
+    proxy->host_features =
+        virtio_bus_get_vdev_features_legacy(&proxy->bus, proxy->host_features);
 }
 
 static void virtio_mmio_realizefn(DeviceState *d, Error **errp)
hw/virtio/virtio-pci.c +2 -2
index e6b0df4..07a8890 100644
@@ -1414,8 +1414,8 @@ static void virtio_pci_device_plugged(DeviceState *d)
 
     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);
+    proxy->host_features =
+        virtio_bus_get_vdev_features_legacy(bus, proxy->host_features);
 }
 
 static void virtio_pci_device_unplugged(DeviceState *d)
hw/virtio/virtio-rng.c +7 -0
index edd39cc..4634286 100644
@@ -101,6 +101,12 @@ static void handle_input(VirtIODevice *vdev, VirtQueue *vq)
 
 static uint64_t get_features(VirtIODevice *vdev, uint64_t f)
 {
+    /* virtio_add_feature(&f, VIRTIO_F_VERSION_1); */
+    return f;
+}
+
+static uint64_t get_features_legacy(VirtIODevice *vdev, uint64_t f)
+{
     return f;
 }
 
@@ -233,6 +239,7 @@ static void virtio_rng_class_init(ObjectClass *klass, void *data)
     vdc->realize = virtio_rng_device_realize;
     vdc->unrealize = virtio_rng_device_unrealize;
     vdc->get_features = get_features;
+    vdc->get_features_legacy = get_features_legacy;
 }
 
 static void virtio_rng_initfn(Object *obj)
hw/virtio/virtio.c +12 -0
index b098f44..5f13598 100644
@@ -1122,6 +1122,18 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t val)
     return __virtio_set_features(vdev, val);
 }
 
+bool virtio_version_1_capable(VirtIODevice *vdev, uint64_t host_features)
+{
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
+    uint64_t features;
+
+    if (!k->get_features) {
+        return 0;
+    }
+    features = k->get_features(vdev, host_features);
+    return __virtio_has_feature(features, VIRTIO_F_VERSION_1) ? 1 : 0;
+}
+
 int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
 {
     int i, ret;
include/hw/virtio/virtio-bus.h +2 -3
index f0916ef..46721f6 100644
@@ -84,9 +84,8 @@ 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);
+uint64_t virtio_bus_get_vdev_features_legacy(VirtioBusState *bus,
+                                             uint64_t requested_features);
 /* 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 -3
index 7a6a9d1..2dc9ad7 100644
@@ -148,9 +148,8 @@ 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 (*get_features_legacy)(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);
@@ -248,6 +247,7 @@ 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);
+bool virtio_version_1_capable(VirtIODevice *vdev, uint64_t host_features);
 
 /* Base devices.  */
 typedef struct VirtIOBlkConf VirtIOBlkConf;
Signature · 1 line
2.3.2
#8 lore raw

cover virtio-ccw: be accesses

In reply to Cornelia Huck

OK, here's what I have for the virtio-ccw be stuff. Patch 1 will go via s390-next with my next pull request, patch 2 is on top of your current virtio-1.0 branch and should possibly be merged into the patch introducing set-revision.

Cornelia Huck (2):
virtio-ccw: assure BE accesses
virtio-ccw: assure be accesses for set-revision

 hw/s390x/virtio-ccw.c | 37 ++++++++++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 11 deletions(-)
Signature · 1 line
2.1.4
#9 lore raw

PATCH 1/2 virtio-ccw: assure BE accesses

All fields in structures transmitted by ccws are big endian; assure we handle them as such.

---
 hw/s390x/virtio-ccw.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
hw/s390x/virtio-ccw.c +13 -9
index 8b6b2ab..60f8a14 100644
@@ -589,7 +589,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
         if (!ccw.cda) {
             ret = -EFAULT;
         } else {
-            indicators = ldq_phys(&address_space_memory, ccw.cda);
+            indicators = ldq_be_phys(&address_space_memory, ccw.cda);
             dev->indicators = get_indicator(indicators, sizeof(uint64_t));
             sch->curr_status.scsw.count = ccw.count - sizeof(indicators);
             ret = 0;
@@ -609,7 +609,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
         if (!ccw.cda) {
             ret = -EFAULT;
         } else {
-            indicators = ldq_phys(&address_space_memory, ccw.cda);
+            indicators = ldq_be_phys(&address_space_memory, ccw.cda);
             dev->indicators2 = get_indicator(indicators, sizeof(uint64_t));
             sch->curr_status.scsw.count = ccw.count - sizeof(indicators);
             ret = 0;
@@ -629,11 +629,11 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
         if (!ccw.cda) {
             ret = -EFAULT;
         } else {
-            vq_config.index = lduw_phys(&address_space_memory, ccw.cda);
+            vq_config.index = lduw_be_phys(&address_space_memory, ccw.cda);
             vq_config.num_max = virtio_queue_get_num(vdev,
                                                      vq_config.index);
-            stw_phys(&address_space_memory,
-                     ccw.cda + sizeof(vq_config.index), vq_config.num_max);
+            stw_be_phys(&address_space_memory,
+                        ccw.cda + sizeof(vq_config.index), vq_config.num_max);
             sch->curr_status.scsw.count = ccw.count - sizeof(vq_config);
             ret = 0;
         }
@@ -661,13 +661,17 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
             if (!thinint) {
                 ret = -EFAULT;
             } else {
+                uint64_t ind_bit = ldq_be_p(&thinint->ind_bit);
+
                 len = hw_len;
                 dev->summary_indicator =
-                    get_indicator(thinint->summary_indicator, sizeof(uint8_t));
-                dev->indicators = get_indicator(thinint->device_indicator,
-                                                thinint->ind_bit / 8 + 1);
+                    get_indicator(ldq_be_p(&thinint->summary_indicator),
+                                  sizeof(uint8_t));
+                dev->indicators =
+                    get_indicator(ldq_be_p(&thinint->device_indicator),
+                                  ind_bit / 8 + 1);
                 dev->thinint_isc = thinint->isc;
-                dev->routes.adapter.ind_offset = thinint->ind_bit;
+                dev->routes.adapter.ind_offset = ind_bit;
                 dev->routes.adapter.summary_offset = 7;
                 cpu_physical_memory_unmap(thinint, hw_len, 0, hw_len);
                 ret = css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO,
Signature · 1 line
2.1.4
author Applied
#10 lore raw

Re: [Qemu-devel] [PATCH 1/2] virtio-ccw: assure BE accesses

Quoted 9 lines · On Wed, 11 Mar 2015 10:57:50 +0100 Cornelia Huck <[email protected]>…

All fields in structures transmitted by ccws are big endian; assure we handle them as such.

---
 hw/s390x/virtio-ccw.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

Applied to my s390-next branch.

#11 lore raw

PATCH 2/2 virtio-ccw: assure be accesses for set-revision

In reply to Cornelia Huck

All fields in structures transmitted by ccws are big endian; assure we handle them as such for the set-revision ccw as well.

Should be merged into "s390x/virtio-ccw: add virtio set-revision call".

---
 hw/s390x/virtio-ccw.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
hw/s390x/virtio-ccw.c +13 -2
index 60f8a14..a64f116 100644
@@ -687,7 +687,7 @@ 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)) {
+        if (ccw.count < sizeof(revinfo)) {
             ret = -EINVAL;
             break;
         }
@@ -695,7 +695,18 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
             ret = -EFAULT;
             break;
         }
-        cpu_physical_memory_read(ccw.cda, &revinfo, len);
+        revinfo.revision = lduw_be_phys(&address_space_memory, ccw.cda);
+        revinfo.length = lduw_be_phys(&address_space_memory,
+                                   ccw.cda + sizeof(revinfo.revision));
+        if (ccw.count < len + revinfo.length ||
+            (check_len && ccw.count > len + revinfo.length)) {
+            ret = -EINVAL;
+            break;
+        }
+        /*
+         * Once we start to support revisions with additional data, we'll
+         * need to fetch it here. Nothing to do for now, though.
+         */
         if (dev->revision >= 0 ||
             revinfo.revision > virtio_ccw_rev_max(dev)) {
             ret = -ENOSYS;
Signature · 1 line
2.1.4
Reviewed-by on v1 2/2
#12 lore raw

Re: [Qemu-devel] [PATCH 2/2] virtio-ccw: assure be accesses for set-revision

Quoted 34 lines · On Wed, 11 Mar 2015 10:57:51 +0100 Cornelia Huck <[email protected]>…

All fields in structures transmitted by ccws are big endian; assure we handle them as such for the set-revision ccw as well.

Should be merged into "s390x/virtio-ccw: add virtio set-revision call".

---
 hw/s390x/virtio-ccw.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
hw/s390x/virtio-ccw.c +6 -2
index 60f8a14..a64f116 100644
@@ -687,7 +687,7 @@ 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)) {
+        if (ccw.count < sizeof(revinfo)) {
             ret = -EINVAL;
             break;
         }
@@ -695,7 +695,18 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
             ret = -EFAULT;
             break;
         }
-        cpu_physical_memory_read(ccw.cda, &revinfo, len);
+        revinfo.revision = lduw_be_phys(&address_space_memory, ccw.cda);
+        revinfo.length = lduw_be_phys(&address_space_memory,
+                                   ccw.cda + sizeof(revinfo.revision));
+        if (ccw.count < len + revinfo.length ||
+            (check_len && ccw.count > len + revinfo.length)) {

hw/s390x/virtio-ccw.c static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) · line 712

Quoted 10 lines
hw/s390x/virtio-ccw.c +7 -0
+            ret = -EINVAL;
+            break;
+        }
+        /*
+         * Once we start to support revisions with additional data, we'll
+         * need to fetch it here. Nothing to do for now, though.
+         */
         if (dev->revision >= 0 ||
             revinfo.revision > virtio_ccw_rev_max(dev)) {
             ret = -ENOSYS;

Looks fine to me.