qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: mst@redhat.com, qemu-devel@nongnu.org
Cc: jasowang@redhat.com, Maxime Coquelin <maxime.coquelin@redhat.com>,
	Aaron Conole <aconole@redhat.com>
Subject: [Qemu-devel] [RFC 4/4] virtio-net: Add MTU feature support
Date: Tue,  6 Sep 2016 18:11:09 +0200	[thread overview]
Message-ID: <1473178269-16718-5-git-send-email-maxime.coquelin@redhat.com> (raw)
In-Reply-To: <1473178269-16718-1-git-send-email-maxime.coquelin@redhat.com>

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 <mst@redhat.com>
Cc: Aaron Conole <aconole@redhat.com
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 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,
-- 
2.7.4

  parent reply	other threads:[~2016-09-06 16:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-06 16:11 [Qemu-devel] [RFC 0/4] virtio-net: Add support to MTU feature Maxime Coquelin
2016-09-06 16:11 ` [Qemu-devel] [RFC 1/4] virtio-net: reuse MTU related bits from Linux header Maxime Coquelin
2016-09-06 16:11 ` [Qemu-devel] [RFC 2/4] vhost-user: Add new protocol feature MTU Maxime Coquelin
2016-09-06 16:11 ` [Qemu-devel] [RFC 3/4] vhost-net: Add new MTU feature support Maxime Coquelin
2016-09-06 16:11 ` Maxime Coquelin [this message]
2016-09-15 22:16   ` [Qemu-devel] [RFC 4/4] virtio-net: Add " Paolo Bonzini
2016-09-16  6:36     ` Maxime Coquelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1473178269-16718-5-git-send-email-maxime.coquelin@redhat.com \
    --to=maxime.coquelin@redhat.com \
    --cc=aconole@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).