vhost: buffers leak and interface disable upon vring descriptor out of mmap 75/6775/2
authorSteven <sluong@cisco.com>
Fri, 19 May 2017 04:22:00 +0000 (21:22 -0700)
committerJohn Lo <loj@cisco.com>
Sat, 20 May 2017 17:43:12 +0000 (17:43 +0000)
When processing a vring descriptor which is outside of mmap, we disable
the interface and spit a message to shut/no shut the interface. This is
not practical as application using vhost cannot constantly checking the
logs and do the recovery. The proposed fix is to log an error, like
other errors that we encounter.

The other bug is buffer leak in the function rewind. At the end of the
while loop when b_current != b_head, we still have to give back 1 more
buffer or add 1 to rx_buffers_len.

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

index 64d55b6..451ae43 100644 (file)
@@ -1557,6 +1557,7 @@ vhost_user_input_rewind_buffers (vlib_main_t * vm,
       b_current->current_length = 0;
       b_current->flags = 0;
     }
+  cpu->rx_buffers_len++;
 }
 
 static u32
@@ -1735,7 +1736,8 @@ vhost_user_if_input (vlib_main_t * vm,
              desc_current = 0;
              if (PREDICT_FALSE (desc_table == 0))
                {
-                 //FIXME: Handle error by shutdown the queue
+                 vlib_error_count (vm, node->node_index,
+                                   VHOST_USER_INPUT_FUNC_ERROR_MMAP_FAIL, 1);
                  goto out;
                }
            }
@@ -1868,13 +1870,8 @@ vhost_user_if_input (vlib_main_t * vm,
                  (vhost_user_input_copy (vui, vum->cpus[thread_index].copy,
                                          copy_len, &map_hint)))
                {
-                 clib_warning
-                   ("Memory mapping error on interface hw_if_index=%d "
-                    "(Shutting down - Switch interface down and up to restart)",
-                    vui->hw_if_index);
-                 vui->admin_up = 0;
-                 copy_len = 0;
-                 break;
+                 vlib_error_count (vm, node->node_index,
+                                   VHOST_USER_INPUT_FUNC_ERROR_MMAP_FAIL, 1);
                }
              copy_len = 0;
 
@@ -1893,10 +1890,8 @@ vhost_user_if_input (vlib_main_t * vm,
       (vhost_user_input_copy (vui, vum->cpus[thread_index].copy,
                              copy_len, &map_hint)))
     {
-      clib_warning ("Memory mapping error on interface hw_if_index=%d "
-                   "(Shutting down - Switch interface down and up to restart)",
-                   vui->hw_if_index);
-      vui->admin_up = 0;
+      vlib_error_count (vm, node->node_index,
+                       VHOST_USER_INPUT_FUNC_ERROR_MMAP_FAIL, 1);
     }
 
   /* give buffers back to driver */
@@ -2324,10 +2319,8 @@ done:
       (vhost_user_tx_copy (vui, vum->cpus[thread_index].copy,
                           copy_len, &map_hint)))
     {
-      clib_warning ("Memory mapping error on interface hw_if_index=%d "
-                   "(Shutting down - Switch interface down and up to restart)",
-                   vui->hw_if_index);
-      vui->admin_up = 0;
+      vlib_error_count (vm, node->node_index,
+                       VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL, 1);
     }
 
   CLIB_MEMORY_BARRIER ();