vhost: use new APIs to handle features
authorYuanhan Liu <yuanhan.liu@linux.intel.com>
Sat, 1 Apr 2017 07:22:41 +0000 (15:22 +0800)
committerYuanhan Liu <yuanhan.liu@linux.intel.com>
Sat, 1 Apr 2017 08:40:13 +0000 (10:40 +0200)
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
examples/tep_termination/main.c
examples/vhost/main.c
lib/librte_vhost/rte_vhost_version.map
lib/librte_vhost/rte_virtio_net.h
lib/librte_vhost/socket.c
lib/librte_vhost/vhost.c
lib/librte_vhost/vhost.h
lib/librte_vhost/vhost_user.c

index 20dafdb..8097dcd 100644 (file)
@@ -1248,12 +1248,14 @@ main(int argc, char *argv[])
                rte_eal_remote_launch(switch_worker,
                        mbuf_pool, lcore_id);
        }
-       rte_vhost_feature_disable(1ULL << VIRTIO_NET_F_MRG_RXBUF);
 
        ret = rte_vhost_driver_register((char *)&dev_basename, 0);
        if (ret != 0)
                rte_exit(EXIT_FAILURE, "failed to register vhost driver.\n");
 
+       rte_vhost_driver_disable_features(dev_basename,
+               1ULL << VIRTIO_NET_F_MRG_RXBUF);
+
        rte_vhost_driver_callback_register(&virtio_net_device_ops);
 
        rte_vhost_driver_session_start();
index 4789947..972a6a8 100644 (file)
@@ -328,16 +328,6 @@ port_init(uint8_t port)
 
        if (port >= rte_eth_dev_count()) return -1;
 
-       if (enable_tx_csum == 0)
-               rte_vhost_feature_disable(1ULL << VIRTIO_NET_F_CSUM);
-
-       if (enable_tso == 0) {
-               rte_vhost_feature_disable(1ULL << VIRTIO_NET_F_HOST_TSO4);
-               rte_vhost_feature_disable(1ULL << VIRTIO_NET_F_HOST_TSO6);
-               rte_vhost_feature_disable(1ULL << VIRTIO_NET_F_GUEST_TSO4);
-               rte_vhost_feature_disable(1ULL << VIRTIO_NET_F_GUEST_TSO6);
-       }
-
        rx_rings = (uint16_t)dev_info.max_rx_queues;
        /* Configure ethernet device. */
        retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);
@@ -531,7 +521,6 @@ us_vhost_parse_args(int argc, char **argv)
                        vmdq_conf_default.rx_adv_conf.vmdq_rx_conf.rx_mode =
                                ETH_VMDQ_ACCEPT_BROADCAST |
                                ETH_VMDQ_ACCEPT_MULTICAST;
-                       rte_vhost_feature_enable(1ULL << VIRTIO_NET_F_CTRL_RX);
 
                        break;
 
@@ -1509,9 +1498,6 @@ main(int argc, char *argv[])
        RTE_LCORE_FOREACH_SLAVE(lcore_id)
                rte_eal_remote_launch(switch_worker, NULL, lcore_id);
 
-       if (mergeable == 0)
-               rte_vhost_feature_disable(1ULL << VIRTIO_NET_F_MRG_RXBUF);
-
        if (client_mode)
                flags |= RTE_VHOST_USER_CLIENT;
 
@@ -1520,13 +1506,38 @@ main(int argc, char *argv[])
 
        /* Register vhost user driver to handle vhost messages. */
        for (i = 0; i < nb_sockets; i++) {
-               ret = rte_vhost_driver_register
-                               (socket_files + i * PATH_MAX, flags);
+               char *file = socket_files + i * PATH_MAX;
+               ret = rte_vhost_driver_register(file, flags);
                if (ret != 0) {
                        unregister_drivers(i);
                        rte_exit(EXIT_FAILURE,
                                "vhost driver register failure.\n");
                }
+               if (mergeable == 0) {
+                       rte_vhost_driver_disable_features(file,
+                               1ULL << VIRTIO_NET_F_MRG_RXBUF);
+               }
+
+               if (enable_tx_csum == 0) {
+                       rte_vhost_driver_disable_features(file,
+                               1ULL << VIRTIO_NET_F_CSUM);
+               }
+
+               if (enable_tso == 0) {
+                       rte_vhost_driver_disable_features(file,
+                               1ULL << VIRTIO_NET_F_HOST_TSO4);
+                       rte_vhost_driver_disable_features(file,
+                               1ULL << VIRTIO_NET_F_HOST_TSO6);
+                       rte_vhost_driver_disable_features(file,
+                               1ULL << VIRTIO_NET_F_GUEST_TSO4);
+                       rte_vhost_driver_disable_features(file,
+                               1ULL << VIRTIO_NET_F_GUEST_TSO6);
+               }
+
+               if (promiscuous) {
+                       rte_vhost_driver_enable_features(file,
+                               1ULL << VIRTIO_NET_F_CTRL_RX);
+               }
        }
 
        rte_vhost_driver_callback_register(&virtio_net_device_ops);
index ca6259c..1150017 100644 (file)
@@ -7,9 +7,6 @@ DPDK_2.0 {
        rte_vhost_driver_session_start;
        rte_vhost_enable_guest_notification;
        rte_vhost_enqueue_burst;
-       rte_vhost_feature_disable;
-       rte_vhost_feature_enable;
-       rte_vhost_feature_get;
 
        local: *;
 };
index 7bb8af6..08bf965 100644 (file)
@@ -70,19 +70,6 @@ struct virtio_net_device_ops {
        void *reserved[5]; /**< Reserved for future extension */
 };
 
-/**
- *  Disable features in feature_mask. Returns 0 on success.
- */
-int rte_vhost_feature_disable(uint64_t feature_mask);
-
-/**
- *  Enable features in feature_mask. Returns 0 on success.
- */
-int rte_vhost_feature_enable(uint64_t feature_mask);
-
-/* Returns currently supported vhost features */
-uint64_t rte_vhost_feature_get(void);
-
 int rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable);
 
 /**
index 53663f4..416b1fd 100644 (file)
@@ -579,7 +579,13 @@ rte_vhost_driver_get_features(const char *path, uint64_t *features)
                *features = vsocket->features;
        pthread_mutex_unlock(&vhost_user.mutex);
 
-       return vsocket ? 0 : -1;
+       if (!vsocket) {
+               RTE_LOG(ERR, VHOST_CONFIG,
+                       "socket file %s is not registered yet.\n", path);
+               return -1;
+       } else {
+               return 0;
+       }
 }
 
 /*
@@ -613,6 +619,21 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
        pthread_mutex_init(&vsocket->conn_mutex, NULL);
        vsocket->dequeue_zero_copy = flags & RTE_VHOST_USER_DEQUEUE_ZERO_COPY;
 
+       /*
+        * Set the supported features correctly for the builtin vhost-user
+        * net driver.
+        *
+        * Applications know nothing about features the builtin virtio net
+        * driver (virtio_net.c) supports, thus it's not possible for them
+        * to invoke rte_vhost_driver_set_features(). To workaround it, here
+        * we set it unconditionally. If the application want to implement
+        * another vhost-user driver (say SCSI), it should call the
+        * rte_vhost_driver_set_features(), which will overwrite following
+        * two values.
+        */
+       vsocket->supported_features = VIRTIO_NET_SUPPORTED_FEATURES;
+       vsocket->features           = VIRTIO_NET_SUPPORTED_FEATURES;
+
        if ((flags & RTE_VHOST_USER_CLIENT) != 0) {
                vsocket->reconnect = !(flags & RTE_VHOST_USER_NO_RECONNECT);
                if (vsocket->reconnect && reconn_tid == 0) {
index dfb08db..7b40a92 100644 (file)
 
 #include "vhost.h"
 
-#define VHOST_USER_F_PROTOCOL_FEATURES 30
-
-/* Features supported by this lib. */
-#define VHOST_SUPPORTED_FEATURES ((1ULL << VIRTIO_NET_F_MRG_RXBUF) | \
-                               (1ULL << VIRTIO_NET_F_CTRL_VQ) | \
-                               (1ULL << VIRTIO_NET_F_CTRL_RX) | \
-                               (1ULL << VIRTIO_NET_F_GUEST_ANNOUNCE) | \
-                               (1ULL << VIRTIO_NET_F_MQ)      | \
-                               (1ULL << VIRTIO_F_VERSION_1)   | \
-                               (1ULL << VHOST_F_LOG_ALL)      | \
-                               (1ULL << VHOST_USER_F_PROTOCOL_FEATURES) | \
-                               (1ULL << VIRTIO_NET_F_HOST_TSO4) | \
-                               (1ULL << VIRTIO_NET_F_HOST_TSO6) | \
-                               (1ULL << VIRTIO_NET_F_CSUM)    | \
-                               (1ULL << VIRTIO_NET_F_GUEST_CSUM) | \
-                               (1ULL << VIRTIO_NET_F_GUEST_TSO4) | \
-                               (1ULL << VIRTIO_NET_F_GUEST_TSO6) | \
-                               (1ULL << VIRTIO_RING_F_INDIRECT_DESC) | \
-                               (1ULL << VIRTIO_NET_F_MTU))
-
-uint64_t VHOST_FEATURES = VHOST_SUPPORTED_FEATURES;
-
 struct virtio_net *vhost_devices[MAX_VHOST_DEVICE];
 
 /* device ops to add/remove device to/from data core. */
@@ -419,26 +397,6 @@ rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable)
        return 0;
 }
 
-uint64_t rte_vhost_feature_get(void)
-{
-       return VHOST_FEATURES;
-}
-
-int rte_vhost_feature_disable(uint64_t feature_mask)
-{
-       VHOST_FEATURES = VHOST_FEATURES & ~feature_mask;
-       return 0;
-}
-
-int rte_vhost_feature_enable(uint64_t feature_mask)
-{
-       if ((feature_mask & VHOST_SUPPORTED_FEATURES) == feature_mask) {
-               VHOST_FEATURES = VHOST_FEATURES | feature_mask;
-               return 0;
-       }
-       return -1;
-}
-
 /*
  * Register ops so that we can add/remove device to data core.
  */
index daa9328..692691b 100644 (file)
@@ -133,6 +133,27 @@ struct vhost_virtqueue {
  #define VIRTIO_F_VERSION_1 32
 #endif
 
+#define VHOST_USER_F_PROTOCOL_FEATURES 30
+
+/* Features supported by this builtin vhost-user net driver. */
+#define VIRTIO_NET_SUPPORTED_FEATURES ((1ULL << VIRTIO_NET_F_MRG_RXBUF) | \
+                               (1ULL << VIRTIO_NET_F_CTRL_VQ) | \
+                               (1ULL << VIRTIO_NET_F_CTRL_RX) | \
+                               (1ULL << VIRTIO_NET_F_GUEST_ANNOUNCE) | \
+                               (1ULL << VIRTIO_NET_F_MQ)      | \
+                               (1ULL << VIRTIO_F_VERSION_1)   | \
+                               (1ULL << VHOST_F_LOG_ALL)      | \
+                               (1ULL << VHOST_USER_F_PROTOCOL_FEATURES) | \
+                               (1ULL << VIRTIO_NET_F_HOST_TSO4) | \
+                               (1ULL << VIRTIO_NET_F_HOST_TSO6) | \
+                               (1ULL << VIRTIO_NET_F_CSUM)    | \
+                               (1ULL << VIRTIO_NET_F_GUEST_CSUM) | \
+                               (1ULL << VIRTIO_NET_F_GUEST_TSO4) | \
+                               (1ULL << VIRTIO_NET_F_GUEST_TSO6) | \
+                               (1ULL << VIRTIO_RING_F_INDIRECT_DESC) | \
+                               (1ULL << VIRTIO_NET_F_MTU))
+
+
 struct guest_page {
        uint64_t guest_phys_addr;
        uint64_t host_phys_addr;
index 1806c0f..65fd0fc 100644 (file)
@@ -147,9 +147,12 @@ vhost_user_reset_owner(struct virtio_net *dev)
  * The features that we support are requested.
  */
 static uint64_t
-vhost_user_get_features(void)
+vhost_user_get_features(struct virtio_net *dev)
 {
-       return VHOST_FEATURES;
+       uint64_t features = 0;
+
+       rte_vhost_driver_get_features(dev->ifname, &features);
+       return features;
 }
 
 /*
@@ -158,7 +161,10 @@ vhost_user_get_features(void)
 static int
 vhost_user_set_features(struct virtio_net *dev, uint64_t features)
 {
-       if (features & ~VHOST_FEATURES)
+       uint64_t vhost_features = 0;
+
+       rte_vhost_driver_get_features(dev->ifname, &vhost_features);
+       if (features & ~vhost_features)
                return -1;
 
        dev->features = features;
@@ -1006,7 +1012,7 @@ vhost_user_msg_handler(int vid, int fd)
 
        switch (msg.request) {
        case VHOST_USER_GET_FEATURES:
-               msg.payload.u64 = vhost_user_get_features();
+               msg.payload.u64 = vhost_user_get_features(dev);
                msg.size = sizeof(msg.payload.u64);
                send_vhost_message(fd, &msg);
                break;