diff mbox

[v5,1/2] vhost user: add support of live migration

Message ID 1438593754-30005-2-git-send-email-thibaut.collet@6wind.com
State New
Headers show

Commit Message

Thibaut Collet Aug. 3, 2015, 9:22 a.m. UTC
Some vhost user backends are able to support live migration.
To provide this service the following features must be added:
1. Add the VIRTIO_NET_F_GUEST_ANNOUNCE capability to vhost-net when netdev
   backend is vhost-user.
2. Provide a nop receive callback to vhost-user.
   This callback is used only by qemu_announce_self after a migration to send
   fake RARP to avoid network outage for peers talking to the migrated guest.
   - For guest with GUEST_ANNOUNCE capabilities these packets must be discarded,
     GARP are sent by the guest thanks the GUEST_ANNOUNCE.
   - For guest without GUEST_ANNOUNCE capabilities these packets are discarded
     too, migration termination is notified when the guest sends packets.

Signed-off-by: Thibaut Collet <thibaut.collet@6wind.com>
---
 hw/net/vhost_net.c |    2 ++
 net/vhost-user.c   |   25 +++++++++++++++++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)

Comments

Marc-André Lureau Aug. 4, 2015, 5:50 p.m. UTC | #1
Hi Thibaut

On Mon, Aug 3, 2015 at 11:22 AM, Thibaut Collet
<thibaut.collet@6wind.com> wrote:
> Some vhost user backends are able to support live migration.
> To provide this service the following features must be added:
> 1. Add the VIRTIO_NET_F_GUEST_ANNOUNCE capability to vhost-net when netdev
>    backend is vhost-user.
> 2. Provide a nop receive callback to vhost-user.
>    This callback is used only by qemu_announce_self after a migration to send
>    fake RARP to avoid network outage for peers talking to the migrated guest.
>    - For guest with GUEST_ANNOUNCE capabilities these packets must be discarded,
>      GARP are sent by the guest thanks the GUEST_ANNOUNCE.
>    - For guest without GUEST_ANNOUNCE capabilities these packets are discarded
>      too, migration termination is notified when the guest sends packets.
>
> Signed-off-by: Thibaut Collet <thibaut.collet@6wind.com>
> ---
>  hw/net/vhost_net.c |    2 ++
>  net/vhost-user.c   |   25 +++++++++++++++++++++++--
>  2 files changed, 25 insertions(+), 2 deletions(-)
>
> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> index c864237..9850520 100644
> --- a/hw/net/vhost_net.c
> +++ b/hw/net/vhost_net.c
> @@ -85,6 +85,8 @@ static const int user_feature_bits[] = {
>      VIRTIO_NET_F_CTRL_MAC_ADDR,
>      VIRTIO_NET_F_CTRL_GUEST_OFFLOADS,
>
> +    VIRTIO_NET_F_GUEST_ANNOUNCE,
> +
>      VIRTIO_NET_F_MQ,
>
>      VHOST_INVALID_FEATURE_BIT
> diff --git a/net/vhost-user.c b/net/vhost-user.c
> index 93dcecd..2290271 100644
> --- a/net/vhost-user.c
> +++ b/net/vhost-user.c
> @@ -65,6 +65,28 @@ static void vhost_user_stop(VhostUserState *s)
>      s->vhost_net = 0;
>  }
>
> +static ssize_t vhost_user_receive(NetClientState *nc, const uint8_t *buf,
> +                                  size_t size)
> +{
> +    /* A live migration is done. Display an error if the packet is not a RARP.
> +     * RARP are just discarded: guest is already notified about live migration
> +     * by the virtio-net NIC or by the vhost-user backend.
> +     */
> +    if (size != 60) {
> +        static int display_trace = 1;
> +
> +        if (display_trace) {
> +            fprintf(stderr,
> +                    "Vhost user expects only RARP (size 60)."
> +                    "Receives unexpected packets with size %lu\n",
> +                    size);
> +            fflush(stderr);
> +            display_trace = 0;
> +        }
> +    }
> +    return size;
> +}

This warning appears during a dummy boot with vapp: qemu-system-x86_64
-m 512 -object memory-backend-file,id=mem,size=512M,mem-path=/hugetlbfs/,share=on
-numa node,memdev=mem -netdev
vhost-user,id=net0,chardev=chr0,vhostforce -device
virtio-net-pci,netdev=net0 -chardev
socket,id=chr0,path=/tmp/vapp.sock.

I think silentely returning 0 (without warning) is the right way to
keep the packets queued in the ring instead. But I must say I am quite
confused as this is triggered by a VIRTIO_PCI_QUEUE_NOTIFY ioport
write, and I fail to see how vhost-user handles it then without
eventfd kick...

>  static void vhost_user_cleanup(NetClientState *nc)
>  {
>      VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc);
> @@ -90,6 +112,7 @@ static bool vhost_user_has_ufo(NetClientState *nc)
>  static NetClientInfo net_vhost_user_info = {
>          .type = NET_CLIENT_OPTIONS_KIND_VHOST_USER,
>          .size = sizeof(VhostUserState),
> +        .receive = vhost_user_receive,
>          .cleanup = vhost_user_cleanup,
>          .has_vnet_hdr = vhost_user_has_vnet_hdr,
>          .has_ufo = vhost_user_has_ufo,
> @@ -143,8 +166,6 @@ static int net_vhost_user_init(NetClientState *peer, const char *device,
>
>      s = DO_UPCAST(VhostUserState, nc, nc);
>
> -    /* We don't provide a receive callback */
> -    s->nc.receive_disabled = 1;
>      s->chr = chr;
>
>      qemu_chr_add_handlers(s->chr, NULL, NULL, net_vhost_user_event, s);
> --
> 1.7.10.4
>
Thibaut Collet Aug. 5, 2015, 1:38 p.m. UTC | #2
On Tue, Aug 4, 2015 at 7:50 PM, Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
> Hi Thibaut
>
> On Mon, Aug 3, 2015 at 11:22 AM, Thibaut Collet
> <thibaut.collet@6wind.com> wrote:
>> Some vhost user backends are able to support live migration.
>> To provide this service the following features must be added:
>> 1. Add the VIRTIO_NET_F_GUEST_ANNOUNCE capability to vhost-net when netdev
>>    backend is vhost-user.
>> 2. Provide a nop receive callback to vhost-user.
>>    This callback is used only by qemu_announce_self after a migration to send
>>    fake RARP to avoid network outage for peers talking to the migrated guest.
>>    - For guest with GUEST_ANNOUNCE capabilities these packets must be discarded,
>>      GARP are sent by the guest thanks the GUEST_ANNOUNCE.
>>    - For guest without GUEST_ANNOUNCE capabilities these packets are discarded
>>      too, migration termination is notified when the guest sends packets.
>>
>> Signed-off-by: Thibaut Collet <thibaut.collet@6wind.com>
>> ---
>>  hw/net/vhost_net.c |    2 ++
>>  net/vhost-user.c   |   25 +++++++++++++++++++++++--
>>  2 files changed, 25 insertions(+), 2 deletions(-)
>>
>> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
>> index c864237..9850520 100644
>> --- a/hw/net/vhost_net.c
>> +++ b/hw/net/vhost_net.c
>> @@ -85,6 +85,8 @@ static const int user_feature_bits[] = {
>>      VIRTIO_NET_F_CTRL_MAC_ADDR,
>>      VIRTIO_NET_F_CTRL_GUEST_OFFLOADS,
>>
>> +    VIRTIO_NET_F_GUEST_ANNOUNCE,
>> +
>>      VIRTIO_NET_F_MQ,
>>
>>      VHOST_INVALID_FEATURE_BIT
>> diff --git a/net/vhost-user.c b/net/vhost-user.c
>> index 93dcecd..2290271 100644
>> --- a/net/vhost-user.c
>> +++ b/net/vhost-user.c
>> @@ -65,6 +65,28 @@ static void vhost_user_stop(VhostUserState *s)
>>      s->vhost_net = 0;
>>  }
>>
>> +static ssize_t vhost_user_receive(NetClientState *nc, const uint8_t *buf,
>> +                                  size_t size)
>> +{
>> +    /* A live migration is done. Display an error if the packet is not a RARP.
>> +     * RARP are just discarded: guest is already notified about live migration
>> +     * by the virtio-net NIC or by the vhost-user backend.
>> +     */
>> +    if (size != 60) {
>> +        static int display_trace = 1;
>> +
>> +        if (display_trace) {
>> +            fprintf(stderr,
>> +                    "Vhost user expects only RARP (size 60)."
>> +                    "Receives unexpected packets with size %lu\n",
>> +                    size);
>> +            fflush(stderr);
>> +            display_trace = 0;
>> +        }
>> +    }
>> +    return size;
>> +}
>
> This warning appears during a dummy boot with vapp: qemu-system-x86_64
> -m 512 -object memory-backend-file,id=mem,size=512M,mem-path=/hugetlbfs/,share=on
> -numa node,memdev=mem -netdev
> vhost-user,id=net0,chardev=chr0,vhostforce -device
> virtio-net-pci,netdev=net0 -chardev
> socket,id=chr0,path=/tmp/vapp.sock.
>
> I think silentely returning 0 (without warning) is the right way to
> keep the packets queued in the ring instead. But I must say I am quite
> confused as this is triggered by a VIRTIO_PCI_QUEUE_NOTIFY ioport
> write, and I fail to see how vhost-user handles it then without
> eventfd kick...
>
>>  static void vhost_user_cleanup(NetClientState *nc)
>>  {
>>      VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc);
>> @@ -90,6 +112,7 @@ static bool vhost_user_has_ufo(NetClientState *nc)
>>  static NetClientInfo net_vhost_user_info = {
>>          .type = NET_CLIENT_OPTIONS_KIND_VHOST_USER,
>>          .size = sizeof(VhostUserState),
>> +        .receive = vhost_user_receive,
>>          .cleanup = vhost_user_cleanup,
>>          .has_vnet_hdr = vhost_user_has_vnet_hdr,
>>          .has_ufo = vhost_user_has_ufo,
>> @@ -143,8 +166,6 @@ static int net_vhost_user_init(NetClientState *peer, const char *device,
>>
>>      s = DO_UPCAST(VhostUserState, nc, nc);
>>
>> -    /* We don't provide a receive callback */
>> -    s->nc.receive_disabled = 1;
>>      s->chr = chr;
>>
>>      qemu_chr_add_handlers(s->chr, NULL, NULL, net_vhost_user_event, s);
>> --
>> 1.7.10.4
>>
>
>
>
> --
> Marc-André Lureau

Hi,

I have reproduced the issue and the message receive by vhost-user is
quite strange: this message is a virtio header plus a bootp/dhcp
request (I do not understand why there are the virtio header)
With a dummy boot, vhost user backend already receives 4 bootp/dhcp
requests form the bios guest so I do not see any interest to transmit
this request to vhostuser backend.

I suggest to remove the warning and discard the dhcp/bootp request (it
is useless to duplicate bootp/dhcp request)


Thibaut.
diff mbox

Patch

diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index c864237..9850520 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -85,6 +85,8 @@  static const int user_feature_bits[] = {
     VIRTIO_NET_F_CTRL_MAC_ADDR,
     VIRTIO_NET_F_CTRL_GUEST_OFFLOADS,
 
+    VIRTIO_NET_F_GUEST_ANNOUNCE,
+
     VIRTIO_NET_F_MQ,
 
     VHOST_INVALID_FEATURE_BIT
diff --git a/net/vhost-user.c b/net/vhost-user.c
index 93dcecd..2290271 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -65,6 +65,28 @@  static void vhost_user_stop(VhostUserState *s)
     s->vhost_net = 0;
 }
 
+static ssize_t vhost_user_receive(NetClientState *nc, const uint8_t *buf,
+                                  size_t size)
+{
+    /* A live migration is done. Display an error if the packet is not a RARP.
+     * RARP are just discarded: guest is already notified about live migration
+     * by the virtio-net NIC or by the vhost-user backend.
+     */
+    if (size != 60) {
+        static int display_trace = 1;
+
+        if (display_trace) {
+            fprintf(stderr,
+                    "Vhost user expects only RARP (size 60)."
+                    "Receives unexpected packets with size %lu\n",
+                    size);
+            fflush(stderr);
+            display_trace = 0;
+        }
+    }
+    return size;
+}
+
 static void vhost_user_cleanup(NetClientState *nc)
 {
     VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc);
@@ -90,6 +112,7 @@  static bool vhost_user_has_ufo(NetClientState *nc)
 static NetClientInfo net_vhost_user_info = {
         .type = NET_CLIENT_OPTIONS_KIND_VHOST_USER,
         .size = sizeof(VhostUserState),
+        .receive = vhost_user_receive,
         .cleanup = vhost_user_cleanup,
         .has_vnet_hdr = vhost_user_has_vnet_hdr,
         .has_ufo = vhost_user_has_ufo,
@@ -143,8 +166,6 @@  static int net_vhost_user_init(NetClientState *peer, const char *device,
 
     s = DO_UPCAST(VhostUserState, nc, nc);
 
-    /* We don't provide a receive callback */
-    s->nc.receive_disabled = 1;
     s->chr = chr;
 
     qemu_chr_add_handlers(s->chr, NULL, NULL, net_vhost_user_event, s);