From patchwork Thu Nov 17 21:58:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 696333 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tKZrd06mvz9t0Z for ; Fri, 18 Nov 2016 09:03:29 +1100 (AEDT) Received: from localhost ([::1]:33461 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c7UmE-0008NO-4i for incoming@patchwork.ozlabs.org; Thu, 17 Nov 2016 17:03:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37715) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c7UhM-0004fk-4N for qemu-devel@nongnu.org; Thu, 17 Nov 2016 16:58:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c7UhL-0007o4-A0 for qemu-devel@nongnu.org; Thu, 17 Nov 2016 16:58:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56076) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c7UhL-0007o0-32 for qemu-devel@nongnu.org; Thu, 17 Nov 2016 16:58:23 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 404E0C009DD8; Thu, 17 Nov 2016 21:58:22 +0000 (UTC) Received: from max-t460s.redhat.com (vpn1-4-86.ams2.redhat.com [10.36.4.86]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uAHLwBQA026526; Thu, 17 Nov 2016 16:58:20 -0500 From: Maxime Coquelin To: mst@redhat.com, aconole@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Date: Thu, 17 Nov 2016 22:58:07 +0100 Message-Id: <1479419887-10515-4-git-send-email-maxime.coquelin@redhat.com> In-Reply-To: <1479419887-10515-1-git-send-email-maxime.coquelin@redhat.com> References: <1479419887-10515-1-git-send-email-maxime.coquelin@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 17 Nov 2016 21:58:22 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v2 3/3] virtio-net: Add MTU feature support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Coquelin , jasowang@redhat.com, yuanhan.liu@linux.intel.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" If negotiated, virtio-net gets the advised MTU from vhost-net, and provides it to the guest through a new virtio_net_config entry. Cc: Michael S. Tsirkin Cc: Aaron Conole --- hw/net/virtio-net.c | 14 ++++++++++++++ include/hw/virtio/virtio-net.h | 1 + 2 files changed, 15 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 5009533..36843fe 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -55,6 +55,8 @@ static VirtIOFeature feature_sizes[] = { .end = endof(struct virtio_net_config, status)}, {.flags = 1 << VIRTIO_NET_F_MQ, .end = endof(struct virtio_net_config, max_virtqueue_pairs)}, + {.flags = 1 << VIRTIO_NET_F_MTU, + .end = endof(struct virtio_net_config, mtu)}, {} }; @@ -81,6 +83,7 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) virtio_stw_p(vdev, &netcfg.status, n->status); virtio_stw_p(vdev, &netcfg.max_virtqueue_pairs, n->max_queues); + virtio_stw_p(vdev, &netcfg.mtu, n->mtu); memcpy(netcfg.mac, n->mac, ETH_ALEN); memcpy(config, &netcfg, n->config_size); } @@ -636,6 +639,14 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features) } else { memset(n->vlans, 0xff, MAX_VLAN >> 3); } + + if (virtio_has_feature(features, VIRTIO_NET_F_MTU)) { + NetClientState *nc = qemu_get_queue(n->nic); + + if (get_vhost_net(nc->peer)) { + n->mtu = vhost_net_get_mtu(get_vhost_net(nc->peer)); + } + } } static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd, @@ -1695,6 +1706,7 @@ static void virtio_net_set_config_size(VirtIONet *n, uint64_t host_features) { int i, config_size = 0; virtio_add_feature(&host_features, VIRTIO_NET_F_MAC); + virtio_add_feature(&host_features, VIRTIO_NET_F_MTU); for (i = 0; feature_sizes[i].flags != 0; i++) { if (host_features & feature_sizes[i].flags) { config_size = MAX(feature_sizes[i].end, config_size); @@ -1922,6 +1934,8 @@ static Property virtio_net_properties[] = { DEFINE_PROP_STRING("tx", VirtIONet, net_conf.tx), DEFINE_PROP_UINT16("rx_queue_size", VirtIONet, net_conf.rx_queue_size, VIRTIO_NET_RX_QUEUE_DEFAULT_SIZE), + DEFINE_PROP_BIT("host_mtu", VirtIONet, host_features, + VIRTIO_NET_F_MTU, true), DEFINE_PROP_END_OF_LIST(), }; diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 0ced975..b6394c8 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -96,6 +96,7 @@ typedef struct VirtIONet { QEMUTimer *announce_timer; int announce_counter; bool needs_vnet_hdr_swap; + uint16_t mtu; } VirtIONet; void virtio_net_set_netclient_name(VirtIONet *n, const char *name,