From patchwork Tue Sep 6 16:11:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 9317451 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9453C601C0 for ; Tue, 6 Sep 2016 16:19:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D68E28E14 for ; Tue, 6 Sep 2016 16:19:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 71A2D28E21; Tue, 6 Sep 2016 16:19:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1B92628E14 for ; Tue, 6 Sep 2016 16:19:02 +0000 (UTC) Received: from localhost ([::1]:34857 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhJ5R-00046N-AQ for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Sep 2016 12:19:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54020) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhIy3-00078O-6f for qemu-devel@nongnu.org; Tue, 06 Sep 2016 12:11:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhIy2-00077z-1M for qemu-devel@nongnu.org; Tue, 06 Sep 2016 12:11:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40022) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhIy1-00077o-Pe for qemu-devel@nongnu.org; Tue, 06 Sep 2016 12:11:21 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 72F1D80086 for ; Tue, 6 Sep 2016 16:11:21 +0000 (UTC) Received: from max-t460s.redhat.com (vpn1-7-235.ams2.redhat.com [10.36.7.235]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u86GBCoX024070; Tue, 6 Sep 2016 12:11:19 -0400 From: Maxime Coquelin To: mst@redhat.com, qemu-devel@nongnu.org Date: Tue, 6 Sep 2016 18:11:09 +0200 Message-Id: <1473178269-16718-5-git-send-email-maxime.coquelin@redhat.com> In-Reply-To: <1473178269-16718-1-git-send-email-maxime.coquelin@redhat.com> References: <1473178269-16718-1-git-send-email-maxime.coquelin@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 06 Sep 2016 16:11:21 +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 4/4] 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: jasowang@redhat.com, Aaron Conole , Maxime Coquelin Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP If negociated, 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 | 16 ++++++++++++++++ include/hw/virtio/virtio-net.h | 1 + 2 files changed, 17 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 01f1351..0974d87 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -50,6 +50,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)}, {} }; @@ -74,6 +76,10 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) VirtIONet *n = VIRTIO_NET(vdev); struct virtio_net_config netcfg; + if (virtio_vdev_has_feature(vdev, VIRTIO_NET_F_MTU)) { + virtio_stw_p(vdev, &netcfg.mtu, n->mtu); + } + virtio_stw_p(vdev, &netcfg.status, n->status); virtio_stw_p(vdev, &netcfg.max_virtqueue_pairs, n->max_queues); memcpy(netcfg.mac, n->mac, ETH_ALEN); @@ -526,6 +532,7 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features, features |= n->host_features; virtio_add_feature(&features, VIRTIO_NET_F_MAC); + virtio_add_feature(&features, VIRTIO_NET_F_MTU); if (!peer_has_vnet_hdr(n)) { virtio_clear_feature(&features, VIRTIO_NET_F_CSUM); @@ -627,6 +634,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, @@ -1688,6 +1703,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); diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 91ed97c..13b2a8d 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -95,6 +95,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,