Better match vhost-user specification for live migration 04/504/2
authorYoann Desmouceaux <ydesmouc@cisco.com>
Tue, 8 Mar 2016 13:54:28 +0000 (14:54 +0100)
committerGerrit Code Review <gerrit@fd.io>
Mon, 14 Mar 2016 09:13:02 +0000 (09:13 +0000)
The specification requires logging of used vring writes to only happen
when VHOST_VRING_F_LOG flag is present in VHOST_USER_SET_VRING_ADDR
message; take that into account.

Change-Id: I9bf4b9eb43a1783b39909b1a3ea1a3bdf50d91a8
Signed-off-by: Yoann Desmouceaux <ydesmouc@cisco.com>
vnet/vnet/devices/virtio/vhost-user.c
vnet/vnet/devices/virtio/vhost-user.h

index 945f03a..13a8fe1 100644 (file)
@@ -231,6 +231,7 @@ static inline void vhost_user_if_disconnect(vhost_user_intf_t * vui)
     vui->vrings[q].avail = NULL;
     vui->vrings[q].used = NULL;
     vui->vrings[q].log_guest_addr = 0;
+    vui->vrings[q].log_used = 0;
   }
 
   unmap_all_mem_regions(vui);
@@ -259,8 +260,10 @@ always_inline void vhost_user_log_dirty_pages(vhost_user_intf_t * vui,
 }
 
 #define vhost_user_log_dirty_ring(vui, vq, member) \
-  vhost_user_log_dirty_pages(vui, vq->log_guest_addr + offsetof(vring_used_t, member), \
-                             sizeof(vq->used->member))
+  if (PREDICT_FALSE(vq->log_used)) { \
+    vhost_user_log_dirty_pages(vui, vq->log_guest_addr + offsetof(vring_used_t, member), \
+                             sizeof(vq->used->member)); \
+  }
 
 static clib_error_t * vhost_user_socket_read (unix_file_t * uf)
 {
@@ -370,6 +373,7 @@ static clib_error_t * vhost_user_socket_read (unix_file_t * uf)
         vui->vrings[q].avail = 0;
         vui->vrings[q].used = 0;
         vui->vrings[q].log_guest_addr = 0;
+        vui->vrings[q].log_used = 0;
       }
 
       DBG_SOCK("interface %d disconnected", vui->sw_if_index);
@@ -451,6 +455,8 @@ static clib_error_t * vhost_user_socket_read (unix_file_t * uf)
       }
 
       vui->vrings[msg.state.index].log_guest_addr = msg.addr.log_guest_addr;
+      vui->vrings[msg.state.index].log_used =
+          (msg.addr.flags & (1 << VHOST_VRING_F_LOG)) ? 1 : 0;
 
       /* Spec says: If VHOST_USER_F_PROTOCOL_FEATURES has not been negotiated,
        the ring is initialized in an enabled state. */
index 83dbf3e..be01116 100644 (file)
@@ -28,6 +28,7 @@
 
 #define VHOST_USER_PROTOCOL_F_MQ   0
 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD        1
+#define VHOST_VRING_F_LOG 0
 
 #if RTE_VERSION >= RTE_VERSION_NUM(2, 2, 0, 0)
 #define VHOST_USER_F_PROTOCOL_FEATURES  30
@@ -178,6 +179,7 @@ typedef struct {
   int kickfd;
   int errfd;
   u32 enabled;
+  u32 log_used;
   u32 callfd_idx;
   u32 n_since_last_int;
   f64 int_deadline;