vhost: Disallow interrupt mode config if driver opts out interrupt support 44/7844/3
authorSteven <sluong@cisco.com>
Sat, 29 Jul 2017 15:56:08 +0000 (08:56 -0700)
committerFlorin Coras <florin.coras@gmail.com>
Thu, 31 Aug 2017 20:48:25 +0000 (20:48 +0000)
According to the spec, supporting interrupt mode from the driver is optional,
not a must. When interrupt mode is configured on the interface, we should
check to make sure that the driver didn't opt out for the kickfd support and
reject the configuration if it did.

Change-Id: I7d3dbaddde65458e1a6a802754a3768ae8685a0e
Signed-off-by: Steven <sluong@cisco.com>
src/vnet/devices/virtio/vhost-user.c
src/vnet/devices/virtio/vhost-user.h

index bfd3e73..5fe378c 100644 (file)
@@ -933,7 +933,7 @@ vhost_user_socket_read (unix_file_t * uf)
          vui->vrings[q].callfd_idx = ~0;
        }
 
-      if (!(msg.u64 & 0x100))
+      if (!(msg.u64 & VHOST_USER_VRING_NOFD_MASK))
        {
          if (number_of_fds != 1)
            {
@@ -965,7 +965,7 @@ vhost_user_socket_read (unix_file_t * uf)
          vui->vrings[q].kickfd_idx = ~0;
        }
 
-      if (!(msg.u64 & 0x100))
+      if (!(msg.u64 & VHOST_USER_VRING_NOFD_MASK))
        {
          if (number_of_fds != 1)
            {
@@ -998,7 +998,7 @@ vhost_user_socket_read (unix_file_t * uf)
       if (vui->vrings[q].errfd != -1)
        close (vui->vrings[q].errfd);
 
-      if (!(msg.u64 & 0x100))
+      if (!(msg.u64 & VHOST_USER_VRING_NOFD_MASK))
        {
          if (number_of_fds != 1)
            goto close_socket;
@@ -2382,6 +2382,11 @@ vhost_user_interface_rx_mode_change (vnet_main_t * vnm, u32 hw_if_index,
   if ((mode == VNET_HW_INTERFACE_RX_MODE_INTERRUPT) ||
       (mode == VNET_HW_INTERFACE_RX_MODE_ADAPTIVE))
     {
+      if (txvq->kickfd_idx == ~0)
+       {
+         // We cannot support interrupt mode if the driver opts out
+         return clib_error_return (0, "Driver does not support interrupt");
+       }
       if (txvq->mode == VNET_HW_INTERFACE_RX_MODE_POLLING)
        {
          vum->ifq_count++;
index ad6c421..ae3b88e 100644 (file)
@@ -23,6 +23,7 @@
 #define VHOST_VRING_IDX_RX(qid)         (2*qid)
 #define VHOST_VRING_IDX_TX(qid)         (2*qid + 1)
 
+#define VHOST_USER_VRING_NOFD_MASK      0x100
 #define VIRTQ_DESC_F_NEXT               1
 #define VIRTQ_DESC_F_INDIRECT           4
 #define VHOST_USER_REPLY_MASK       (0x1 << 2)