From owner-dev-commits-src-main@freebsd.org  Tue Jan 19 05:08:17 2021
Return-Path: <owner-dev-commits-src-main@freebsd.org>
Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
 by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8C7A24E52BA;
 Tue, 19 Jan 2021 05:08:17 +0000 (UTC) (envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org
 [IPv6:2610:1c1:1:606c::19:3])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
 client-signature RSA-PSS (4096 bits) client-digest SHA256)
 (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK))
 by mx1.freebsd.org (Postfix) with ESMTPS id 4DKc9r4zggz4Wy7;
 Tue, 19 Jan 2021 05:08:16 +0000 (UTC) (envelope-from git@FreeBSD.org)
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org
 [IPv6:2610:1c1:1:6068::e6a:5])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
 (Client did not present a certificate)
 by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 32369208E3;
 Tue, 19 Jan 2021 05:08:13 +0000 (UTC) (envelope-from git@FreeBSD.org)
Received: from gitrepo.freebsd.org ([127.0.1.44])
 by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 10J58DRD085786;
 Tue, 19 Jan 2021 05:08:13 GMT (envelope-from git@gitrepo.freebsd.org)
Received: (from git@localhost)
 by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10J58DlF085785;
 Tue, 19 Jan 2021 05:08:13 GMT (envelope-from git)
Date: Tue, 19 Jan 2021 05:08:13 GMT
Message-Id: <202101190508.10J58DlF085785@gitrepo.freebsd.org>
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org,
 dev-commits-src-main@FreeBSD.org
From: Bryan Venteicher <bryanv@FreeBSD.org>
Subject: git: aabdf5b6e8e8 - main - if_vtnet: Support VIRTIO_NET_F_MTU
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: bryanv
X-Git-Repository: src
X-Git-Refname: refs/heads/main
X-Git-Reftype: branch
X-Git-Commit: aabdf5b6e8e82cda0ca2064ef78e2724bd486e7e
Auto-Submitted: auto-generated
X-BeenThere: dev-commits-src-main@freebsd.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: Commit messages for the main branch of the src repository
 <dev-commits-src-main.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/dev-commits-src-main>, 
 <mailto:dev-commits-src-main-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/dev-commits-src-main/>
List-Post: <mailto:dev-commits-src-main@freebsd.org>
List-Help: <mailto:dev-commits-src-main-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main>, 
 <mailto:dev-commits-src-main-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Tue, 19 Jan 2021 05:08:17 -0000

The branch main has been updated by bryanv:

URL: https://cgit.FreeBSD.org/src/commit/?id=aabdf5b6e8e82cda0ca2064ef78e2724bd486e7e

commit aabdf5b6e8e82cda0ca2064ef78e2724bd486e7e
Author:     Bryan Venteicher <bryanv@FreeBSD.org>
AuthorDate: 2021-01-19 04:55:24 +0000
Commit:     Bryan Venteicher <bryanv@FreeBSD.org>
CommitDate: 2021-01-19 04:55:24 +0000

    if_vtnet: Support VIRTIO_NET_F_MTU
    
    This feature lets the guest driver know the maximum MTU size
    supported by the host device. If set, use this to limit the
    acceptable MTUs, and improve how the receive mbuf cluster size
    then is selected.
    
    Reviewed by: grehan (mentor)
    Differential Revision: https://reviews.freebsd.org/D27907
---
 sys/dev/virtio/network/if_vtnet.c    | 15 ++++++++++-----
 sys/dev/virtio/network/if_vtnetvar.h |  2 ++
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/sys/dev/virtio/network/if_vtnet.c b/sys/dev/virtio/network/if_vtnet.c
index d90fd3bc43aa..ca60e51c57d2 100644
--- a/sys/dev/virtio/network/if_vtnet.c
+++ b/sys/dev/virtio/network/if_vtnet.c
@@ -668,6 +668,12 @@ vtnet_setup_features(struct vtnet_softc *sc)
 		sc->vtnet_flags |= VTNET_FLAG_MAC;
 	}
 
+	if (virtio_with_feature(dev, VIRTIO_NET_F_MTU)) {
+		sc->vtnet_max_mtu = virtio_read_dev_config_2(dev,
+		    offsetof(struct virtio_net_config, mtu));
+	} else
+		sc->vtnet_max_mtu = VTNET_MAX_MTU;
+
 	if (virtio_with_feature(dev, VIRTIO_NET_F_MRG_RXBUF)) {
 		sc->vtnet_flags |= VTNET_FLAG_MRG_RXBUFS;
 		sc->vtnet_hdr_size = sizeof(struct virtio_net_hdr_mrg_rxbuf);
@@ -1094,10 +1100,9 @@ vtnet_rx_cluster_size(struct vtnet_softc *sc, int mtu)
 		return (MCLBYTES);
 
 	/*
-	 * Try to scale the receive mbuf cluster size from the MTU. Without
-	 * the GUEST_TSO[46] features, the VirtIO specification says the
-	 * driver must only be able to receive ~1500 byte frames. But if
-	 * jumbo frames can be transmitted then try to receive jumbo.
+	 * Try to scale the receive mbuf cluster size from the MTU. We
+	 * could also use the VQ size to influence the selected size,
+	 * but that would only matter for very small queues.
 	 */
 	if (vtnet_modern(sc)) {
 		MPASS(sc->vtnet_hdr_size == sizeof(struct virtio_net_hdr_v1));
@@ -1128,7 +1133,7 @@ vtnet_ioctl_mtu(struct vtnet_softc *sc, int mtu)
 
 	if (ifp->if_mtu == mtu)
 		return (0);
-	else if (mtu < ETHERMIN || mtu > VTNET_MAX_MTU)
+	else if (mtu < ETHERMIN || mtu > sc->vtnet_max_mtu)
 		return (EINVAL);
 
 	ifp->if_mtu = mtu;
diff --git a/sys/dev/virtio/network/if_vtnetvar.h b/sys/dev/virtio/network/if_vtnetvar.h
index eaf6eaf8d504..29a0dbbb734f 100644
--- a/sys/dev/virtio/network/if_vtnetvar.h
+++ b/sys/dev/virtio/network/if_vtnetvar.h
@@ -164,6 +164,7 @@ struct vtnet_softc {
 	int			 vtnet_tx_intr_thresh;
 	int			 vtnet_tx_nsegs;
 	int			 vtnet_if_flags;
+	int			 vtnet_max_mtu;
 	int			 vtnet_act_vq_pairs;
 	int			 vtnet_max_vq_pairs;
 	int			 vtnet_requested_vq_pairs;
@@ -297,6 +298,7 @@ CTASSERT(sizeof(struct vtnet_mac_filter) <= PAGE_SIZE);
 #define VTNET_COMMON_FEATURES \
     (VIRTIO_NET_F_MAC			| \
      VIRTIO_NET_F_STATUS		| \
+     VIRTIO_NET_F_MTU			| \
      VIRTIO_NET_F_CTRL_VQ		| \
      VIRTIO_NET_F_CTRL_RX		| \
      VIRTIO_NET_F_CTRL_MAC_ADDR		| \