From patchwork Thu Mar 7 08:23:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 225764 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 13DB12C038F for ; Thu, 7 Mar 2013 19:33:53 +1100 (EST) Received: from localhost ([::1]:40875 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDWGt-0000QZ-76 for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2013 03:33:51 -0500 Received: from eggs.gnu.org ([208.118.235.92]:49237) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDWGN-0000LB-JP for qemu-devel@nongnu.org; Thu, 07 Mar 2013 03:33:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UDWGM-0007lo-98 for qemu-devel@nongnu.org; Thu, 07 Mar 2013 03:33:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60150) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDWGM-0007lc-2T for qemu-devel@nongnu.org; Thu, 07 Mar 2013 03:33:18 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r278XHk5025207 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 7 Mar 2013 03:33:17 -0500 Received: from amd-6168-8-1.englab.nay.redhat.com (amd-6168-8-1.englab.nay.redhat.com [10.66.104.52]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r278WoIB007225; Thu, 7 Mar 2013 03:33:11 -0500 From: Jason Wang To: aliguori@us.ibm.com, pbonzini@redhat.com, owasserm@redhat.com, qemu-devel@nongnu.org Date: Thu, 7 Mar 2013 16:23:50 +0800 Message-Id: <1362644631-23113-5-git-send-email-jasowang@redhat.com> In-Reply-To: <1362644631-23113-1-git-send-email-jasowang@redhat.com> References: <1362644631-23113-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Jason Wang , mst@redhat.com Subject: [Qemu-devel] [PATCH V7 4/5] virtio-net: notify guest to annouce itself X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org It's hard to track all mac addresses and their configurations (e.g vlan) in qemu. Without those information, it's impossible to build proper garp packet after migration. The only possible solution to this is let guest ( who knew all configurations) to do this. So, this patch introduces a new rw config status bit of virtio-net, VIRTIO_NET_S_ANNOUNCE which is used to notify guest to announce presence of its link through config update interrupt. When gust have done the announcement, it should ack the notification through VIRTIO_NET_CTRL_ANNOUNCE_ACK cmd. This feature is negotiated by a new feature bit VIRTIO_NET_F_ANNOUNCE. Signed-off-by: Jason Wang --- hw/virtio-net.c | 30 ++++++++++++++++++++++++++++++ hw/virtio-net.h | 15 ++++++++++++++- 2 files changed, 44 insertions(+), 1 deletions(-) diff --git a/hw/virtio-net.c b/hw/virtio-net.c index 009f09e..278c42c 100644 --- a/hw/virtio-net.c +++ b/hw/virtio-net.c @@ -610,6 +610,18 @@ static int virtio_net_handle_mq(VirtIONet *n, uint8_t cmd, return VIRTIO_NET_OK; } + +static int virtio_net_handle_announce(VirtIONet *n, uint8_t cmd, + struct iovec *iov, unsigned int iov_cnt) +{ + if (cmd == VIRTIO_NET_CTRL_ANNOUNCE_ACK) { + n->status &= ~VIRTIO_NET_S_ANNOUNCE; + return VIRTIO_NET_OK; + } else { + return VIRTIO_NET_ERR; + } +} + static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) { VirtIONet *n = to_virtio_net(vdev); @@ -639,6 +651,8 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) status = virtio_net_handle_mac(n, ctrl.cmd, iov, iov_cnt); } else if (ctrl.class == VIRTIO_NET_CTRL_VLAN) { status = virtio_net_handle_vlan_table(n, ctrl.cmd, iov, iov_cnt); + } else if (ctrl.class == VIRTIO_NET_CTRL_ANNOUNCE) { + status = virtio_net_handle_announce(n, ctrl.cmd, iov, iov_cnt); } else if (ctrl.class == VIRTIO_NET_CTRL_MQ) { status = virtio_net_handle_mq(n, ctrl.cmd, iov, iov_cnt); } @@ -1275,6 +1289,21 @@ static void virtio_net_cleanup(NetClientState *nc) n->nic = NULL; } +static int virtio_net_announce(NetClientState *nc) +{ + VirtIONet *n = qemu_get_nic_opaque(nc); + + if (n->vdev.guest_features & (0x1 << VIRTIO_NET_F_GUEST_ANNOUNCE) + && n->vdev.guest_features & (0x1 << VIRTIO_NET_F_CTRL_VQ) + && virtio_net_started(n, n->vdev.status)) { + n->status |= VIRTIO_NET_S_ANNOUNCE; + virtio_notify_config(&n->vdev); + return 0; + } + + return -1; +} + static NetClientInfo net_virtio_info = { .type = NET_CLIENT_OPTIONS_KIND_NIC, .size = sizeof(NICState), @@ -1282,6 +1311,7 @@ static NetClientInfo net_virtio_info = { .receive = virtio_net_receive, .cleanup = virtio_net_cleanup, .link_status_changed = virtio_net_set_link_status, + .announce = virtio_net_announce, }; static bool virtio_net_guest_notifier_pending(VirtIODevice *vdev, int idx) diff --git a/hw/virtio-net.h b/hw/virtio-net.h index e654c13..c0f3de5 100644 --- a/hw/virtio-net.h +++ b/hw/virtio-net.h @@ -43,12 +43,13 @@ #define VIRTIO_NET_F_CTRL_RX 18 /* Control channel RX mode support */ #define VIRTIO_NET_F_CTRL_VLAN 19 /* Control channel VLAN filtering */ #define VIRTIO_NET_F_CTRL_RX_EXTRA 20 /* Extra RX mode control support */ +#define VIRTIO_NET_F_GUEST_ANNOUNCE 21 /* Guest can announce itself */ #define VIRTIO_NET_F_MQ 22 /* Device supports Receive Flow * Steering */ - #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ #define VIRTIO_NET_S_LINK_UP 1 /* Link is up */ +#define VIRTIO_NET_S_ANNOUNCE 2 /* Announcement is needed */ #define TX_TIMER_INTERVAL 150000 /* 150 us */ @@ -152,6 +153,17 @@ struct virtio_net_ctrl_mac { #define VIRTIO_NET_CTRL_VLAN_DEL 1 /* + * Control link announce acknowledgement + * + * The command VIRTIO_NET_CTRL_ANNOUNCE_ACK is used to indicate that + * driver has recevied the notification and device would clear the + * VIRTIO_NET_S_ANNOUNCE bit in the status filed after it received + * this command. + */ +#define VIRTIO_NET_CTRL_ANNOUNCE 3 + #define VIRTIO_NET_CTRL_ANNOUNCE_ACK 0 + +/* * Control Multiqueue * * The command VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET @@ -180,6 +192,7 @@ struct virtio_net_ctrl_mq { DEFINE_PROP_BIT("guest_tso6", _state, _field, VIRTIO_NET_F_GUEST_TSO6, true), \ DEFINE_PROP_BIT("guest_ecn", _state, _field, VIRTIO_NET_F_GUEST_ECN, true), \ DEFINE_PROP_BIT("guest_ufo", _state, _field, VIRTIO_NET_F_GUEST_UFO, true), \ + DEFINE_PROP_BIT("guest_announce", _state, _field, VIRTIO_NET_F_GUEST_ANNOUNCE, true), \ DEFINE_PROP_BIT("host_tso4", _state, _field, VIRTIO_NET_F_HOST_TSO4, true), \ DEFINE_PROP_BIT("host_tso6", _state, _field, VIRTIO_NET_F_HOST_TSO6, true), \ DEFINE_PROP_BIT("host_ecn", _state, _field, VIRTIO_NET_F_HOST_ECN, true), \