svn commit: r368727 - head/sys/netgraph

2020-12-17 Thread Aleksandr Fedorov
Author: afedorov
Date: Thu Dec 17 18:15:07 2020
New Revision: 368727
URL: https://svnweb.freebsd.org/changeset/base/368727

Log:
  [ng_socket] Don't take the SOCKBUF_LOCK() twice in the RX data path.
  
  This is just a minor optimization, but it's sensitive. This gives an 
improvement of 30-50 kpps.
  
  Reviewed by:  kp, markj, glebius, lutz_donnerhacke.de
  Approved by:  vmaffione (mentor)
  Sponsored by: vstack.com
  Differential Revision:https://reviews.freebsd.org/D27382

Modified:
  head/sys/netgraph/ng_socket.c

Modified: head/sys/netgraph/ng_socket.c
==
--- head/sys/netgraph/ng_socket.c   Thu Dec 17 17:21:12 2020
(r368726)
+++ head/sys/netgraph/ng_socket.c   Thu Dec 17 18:15:07 2020
(r368727)
@@ -987,6 +987,8 @@ ngs_rcvmsg(node_p node, item_p item, hook_p lasthook)
m_freem(m);
return (ENOBUFS);
}
+
+   /* sorwakeup_locked () releases the lock internally. */
sorwakeup_locked(so);
 
return (error);
@@ -1025,12 +1027,17 @@ ngs_rcvdata(hook_p hook, item_p item)
addr->sg_data[addrlen] = '\0';
 
/* Try to tell the socket which hook it came in on. */
-   if (sbappendaddr(>so_rcv, (struct sockaddr *)addr, m, NULL) == 0) {
+   SOCKBUF_LOCK(>so_rcv);
+   if (sbappendaddr_locked(>so_rcv, (struct sockaddr *)addr, m,
+   NULL) == 0) {
+   SOCKBUF_UNLOCK(>so_rcv);
m_freem(m);
TRAP_ERROR;
return (ENOBUFS);
}
-   sorwakeup(so);
+
+   /* sorwakeup_locked () releases the lock internally. */
+   sorwakeup_locked(so);
return (0);
 }
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r368720 - head/usr.sbin/bhyve

2020-12-17 Thread Aleksandr Fedorov
Author: afedorov
Date: Thu Dec 17 16:52:40 2020
New Revision: 368720
URL: https://svnweb.freebsd.org/changeset/base/368720

Log:
  [bhyve] virtio-net: Do not allow receiving packets until features have been 
negotiated.
  
  Enforce the requirement that the RX callback cannot be called after a reset 
until the features have been negotiated.
  This fixes a race condition where the receive callback is called during a 
device reset.
  
  Reviewed by:  vmaffione, grehan
  Approved by:  vmaffione (mentor)
  Sponsored by: vstack.com
  Differential Revision:https://reviews.freebsd.org/D27381

Modified:
  head/usr.sbin/bhyve/pci_virtio_net.c

Modified: head/usr.sbin/bhyve/pci_virtio_net.c
==
--- head/usr.sbin/bhyve/pci_virtio_net.cThu Dec 17 15:00:19 2020
(r368719)
+++ head/usr.sbin/bhyve/pci_virtio_net.cThu Dec 17 16:52:40 2020
(r368720)
@@ -111,6 +111,8 @@ struct pci_vtnet_softc {
 
net_backend_t   *vsc_be;
 
+   boolfeatures_negotiated;/* protected by rx_mtx */
+
int resetting;  /* protected by tx_mtx */
 
uint64_tvsc_features;   /* negotiated features */
@@ -176,6 +178,7 @@ pci_vtnet_reset(void *vsc)
 * Receive operation will be enabled again once the guest adds
 * the first receive buffers and kicks us.
 */
+   sc->features_negotiated = false;
netbe_rx_disable(sc->vsc_be);
 
/* Set sc->resetting and give a chance to the TX thread to stop. */
@@ -246,6 +249,12 @@ pci_vtnet_rx(struct pci_vtnet_softc *sc)
struct vqueue_info *vq;
 
vq = >vsc_queues[VTNET_RXQ];
+
+   /* Features must be negotiated */
+   if (!sc->features_negotiated) {
+   return;
+   }
+
for (;;) {
struct virtio_net_rxhdr *hdr;
uint32_t riov_bytes;
@@ -406,8 +415,14 @@ pci_vtnet_ping_rxq(void *vsc, struct vqueue_info *vq)
 
/*
 * A qnotify means that the rx process can now begin.
+* Enable RX only if features are negotiated.
 */
pthread_mutex_lock(>rx_mtx);
+   if (!sc->features_negotiated) {
+   pthread_mutex_unlock(>rx_mtx);
+   return;
+   }
+
vq_kick_disable(vq);
netbe_rx_enable(sc->vsc_be);
pthread_mutex_unlock(>rx_mtx);
@@ -750,6 +765,10 @@ pci_vtnet_neg_features(void *vsc, uint64_t negotiated_
netbe_set_cap(sc->vsc_be, negotiated_features, sc->vhdrlen);
sc->be_vhdrlen = netbe_get_vnet_hdr_len(sc->vsc_be);
assert(sc->be_vhdrlen == 0 || sc->be_vhdrlen == sc->vhdrlen);
+
+   pthread_mutex_lock(>rx_mtx);
+   sc->features_negotiated = true;
+   pthread_mutex_unlock(>rx_mtx);
 }
 
 #ifdef BHYVE_SNAPSHOT
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r361215 - head/usr.sbin/bhyve

2020-05-18 Thread Aleksandr Fedorov
Author: afedorov
Date: Mon May 18 15:03:52 2020
New Revision: 361215
URL: https://svnweb.freebsd.org/changeset/base/361215

Log:
  bhyve(8): Add the netgraph network backend decription to the manpage.
  
  Reviewed by:  vmaffione, bcr
  Approved by:  vmaffione (mentor)
  Sponsored by: vstack.com
  Differential Revision:https://reviews.freebsd.org/D24846

Modified:
  head/usr.sbin/bhyve/bhyve.8

Modified: head/usr.sbin/bhyve/bhyve.8
==
--- head/usr.sbin/bhyve/bhyve.8 Mon May 18 15:02:15 2020(r361214)
+++ head/usr.sbin/bhyve/bhyve.8 Mon May 18 15:03:52 2020(r361215)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd May 5, 2020
+.Dd May 18, 2020
 .Dt BHYVE 8
 .Os
 .Sh NAME
@@ -291,10 +291,11 @@ If
 is not specified, the device emulation has no backend and can be
 considered unconnected.
 .Pp
-Network devices:
+Network backends:
 .Bl -tag -width 10n
 .It Ar tapN Ns Oo , Ns Ar mac=xx:xx:xx:xx:xx:xx Oc Ns Oo , Ns Ar mtu=N Oc
 .It Ar vmnetN Ns Oo , Ns Ar mac=xx:xx:xx:xx:xx:xx Oc Ns Oo , Ns Ar mtu=N Oc
+.It Ar netgraph,path=ADDRESS,peerhook=HOOK Ns Oo , Ns Ar socket=NAME Oc Ns Oo 
, Ns Ar hook=HOOK Oc Ns Oo , Ns Ar mac=xx:xx:xx:xx:xx:xx Oc Ns Oo , Ns Ar mtu=N 
Oc
 .Pp
 If
 .Ar mac
@@ -310,6 +311,27 @@ With virtio-net devices, the
 .Ar mtu
 parameter can be specified to inform the guest about the largest MTU
 that should be allowed, expressed in bytes.
+.Pp
+With netgraph backend, the
+.Ar path
+and
+.Ar peerhook
+parameters must be specified to set the destination node and corresponding 
hook.
+The optional parameters
+.Ar socket
+and
+.Ar hook
+may be used to set the
+.Xr ng_socket 4
+node name and source hook.
+The
+.Ar ADDRESS ,
+.Ar HOOK
+and
+.Ar NAME
+must comply with
+.Xr netgraph 4
+addressing rules.
 .El
 .Pp
 Block storage devices:
@@ -670,6 +692,8 @@ bhyve -c 2 -m 4G -w -H \\
 .Ed
 .Sh SEE ALSO
 .Xr bhyve 4 ,
+.Xr netgraph 4 ,
+.Xr ng_socket 4 ,
 .Xr nmdm 4 ,
 .Xr vmm 4 ,
 .Xr ethers 5 ,
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r361072 - head/usr.sbin/bhyve

2020-05-15 Thread Aleksandr Fedorov
Author: afedorov
Date: Fri May 15 11:03:27 2020
New Revision: 361072
URL: https://svnweb.freebsd.org/changeset/base/361072

Log:
  bhyve: Fix processing of netgraph backend options.
  
  After r360820, additional parameters are passed through the argument 'opts', 
and the name of the backend through the argument 'devname'. So, there is no 
need to skip the backend name from the 'opts' argument.

Modified:
  head/usr.sbin/bhyve/net_backends.c

Modified: head/usr.sbin/bhyve/net_backends.c
==
--- head/usr.sbin/bhyve/net_backends.c  Fri May 15 03:54:25 2020
(r361071)
+++ head/usr.sbin/bhyve/net_backends.c  Fri May 15 11:03:27 2020
(r361072)
@@ -438,8 +438,6 @@ ng_init(struct net_backend *be, const char *devname,
path_provided = 0;
peerhook_provided = 0;
 
-   (void)strsep(, ",");
-
while (ngopts != NULL) {
char *value = ngopts;
char *key;
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r360958 - head/usr.sbin/bhyve

2020-05-12 Thread Aleksandr Fedorov
Author: afedorov
Date: Tue May 12 11:18:14 2020
New Revision: 360958
URL: https://svnweb.freebsd.org/changeset/base/360958

Log:
  Add a new bhyve network backend that allow to connect the VM to the 
netgraph(4) network.
  The backend uses the socket API with the PF_NETGRAPH protocol family, which 
is provided by the ng_socket(4).
  
  To use the new backend, provide the following bhyve option:
  -s X:Y:Z,[virtio-net|e1000],netgraph,socket=[ng_socket 
name],path=[destination node],hook=[our socket src hook],peerhook=[dst node 
hook]
  
  Reviewed by:  vmaffione, lutz_donnerhacke.de
  Approved by:  vmaffione (mentor)
  Sponsored by: vstack.com
  Differential Revision:https://reviews.freebsd.org/D24620

Modified:
  head/usr.sbin/bhyve/Makefile
  head/usr.sbin/bhyve/net_backends.c

Modified: head/usr.sbin/bhyve/Makefile
==
--- head/usr.sbin/bhyve/MakefileTue May 12 09:31:48 2020
(r360957)
+++ head/usr.sbin/bhyve/MakefileTue May 12 11:18:14 2020
(r360958)
@@ -90,6 +90,10 @@ CFLAGS+=-DINET
 .if ${MK_INET6_SUPPORT} != "no"
 CFLAGS+=-DINET6
 .endif
+.if ${MK_NETGRAPH_SUPPORT} != "no"
+CFLAGS+=-DNETGRAPH
+LIBADD+=netgraph
+.endif
 .if ${MK_OPENSSL} == "no"
 CFLAGS+=-DNO_OPENSSL
 .else

Modified: head/usr.sbin/bhyve/net_backends.c
==
--- head/usr.sbin/bhyve/net_backends.c  Tue May 12 09:31:48 2020
(r360957)
+++ head/usr.sbin/bhyve/net_backends.c  Tue May 12 11:18:14 2020
(r360958)
@@ -69,6 +69,11 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 
+#ifdef NETGRAPH
+#include 
+#include 
+#include 
+#endif
 
 #include "debug.h"
 #include "iov.h"
@@ -382,6 +387,194 @@ static struct net_backend vmnet_backend = {
 
 DATA_SET(net_backend_set, tap_backend);
 DATA_SET(net_backend_set, vmnet_backend);
+
+#ifdef NETGRAPH
+
+/*
+ * Netgraph backend
+ */
+
+#define NG_SBUF_MAX_SIZE (4 * 1024 * 1024)
+
+static int
+ng_init(struct net_backend *be, const char *devname,
+const char *opts, net_be_rxeof_t cb, void *param)
+{
+   struct tap_priv *p = (struct tap_priv *)be->opaque;
+   struct ngm_connect ngc;
+   char *ngopts, *tofree;
+   char nodename[NG_NODESIZ];
+   int sbsz;
+   int ctrl_sock;
+   int flags;
+   int path_provided;
+   int peerhook_provided;
+   int socket_provided;
+   unsigned long maxsbsz;
+   size_t msbsz;
+#ifndef WITHOUT_CAPSICUM
+   cap_rights_t rights;
+#endif
+
+   if (cb == NULL) {
+   WPRINTF(("Netgraph backend requires non-NULL callback"));
+   return (-1);
+   }
+
+   be->fd = -1;
+
+   memset(, 0, sizeof(ngc));
+
+   strncpy(ngc.ourhook, "vmlink", NG_HOOKSIZ - 1);
+
+   tofree = ngopts = strdup(opts);
+
+   if (ngopts == NULL) {
+   WPRINTF(("strdup error"));
+   return (-1);
+   }
+
+   socket_provided = 0;
+   path_provided = 0;
+   peerhook_provided = 0;
+
+   (void)strsep(, ",");
+
+   while (ngopts != NULL) {
+   char *value = ngopts;
+   char *key;
+
+   key = strsep(, "=");
+   if (value == NULL)
+   break;
+   ngopts = value;
+   (void) strsep(, ",");
+
+   if (strcmp(key, "socket") == 0) {
+   strncpy(nodename, value, NG_NODESIZ - 1);
+   socket_provided = 1;
+   } else if (strcmp(key, "path") == 0) {
+   strncpy(ngc.path, value, NG_PATHSIZ - 1);
+   path_provided = 1;
+   } else if (strcmp(key, "hook") == 0) {
+   strncpy(ngc.ourhook, value, NG_HOOKSIZ - 1);
+   } else if (strcmp(key, "peerhook") == 0) {
+   strncpy(ngc.peerhook, value, NG_HOOKSIZ - 1);
+   peerhook_provided = 1;
+   }
+   }
+
+   free(tofree);
+
+   if (!path_provided) {
+   WPRINTF(("path must be provided"));
+   return (-1);
+   }
+
+   if (!peerhook_provided) {
+   WPRINTF(("peer hook must be provided"));
+   return (-1);
+   }
+
+   if (NgMkSockNode(socket_provided ? nodename : NULL,
+   _sock, >fd) < 0) {
+   WPRINTF(("can't get Netgraph sockets"));
+   return (-1);
+   }
+
+   if (NgSendMsg(ctrl_sock, ".",
+   NGM_GENERIC_COOKIE,
+   NGM_CONNECT, , sizeof(ngc)) < 0) {
+   WPRINTF(("can't connect to node"));
+   close(ctrl_sock);
+   goto error;
+   }
+
+   close(ctrl_sock);
+
+   flags = fcntl(be->fd, F_GETFL);
+
+   if (flags < 0) {
+   WPRINTF(("can't get socket flags"));
+   goto error;
+   }
+
+   if (fcntl(be->fd, F_SETFL, flags | 

svn commit: r360820 - head/usr.sbin/bhyve

2020-05-08 Thread Aleksandr Fedorov
Author: afedorov
Date: Fri May  8 17:15:54 2020
New Revision: 360820
URL: https://svnweb.freebsd.org/changeset/base/360820

Log:
  bhyve: Pass the full string of options to the network backends.
  
  Reviewed by:  vmaffione
  Approved by:  vmaffione (mentor)
  Sponsored by: vstack.com
  Differential Revision:https://reviews.freebsd.org/D24735

Modified:
  head/usr.sbin/bhyve/net_backends.c
  head/usr.sbin/bhyve/net_backends.h
  head/usr.sbin/bhyve/pci_e82545.c
  head/usr.sbin/bhyve/pci_virtio_net.c

Modified: head/usr.sbin/bhyve/net_backends.c
==
--- head/usr.sbin/bhyve/net_backends.c  Fri May  8 17:01:33 2020
(r360819)
+++ head/usr.sbin/bhyve/net_backends.c  Fri May  8 17:15:54 2020
(r360820)
@@ -91,7 +91,7 @@ struct net_backend {
 * and should not be called by the frontend.
 */
int (*init)(struct net_backend *be, const char *devname,
-   net_be_rxeof_t cb, void *param);
+   const char *opts, net_be_rxeof_t cb, void *param);
void (*cleanup)(struct net_backend *be);
 
/*
@@ -199,7 +199,7 @@ tap_cleanup(struct net_backend *be)
 
 static int
 tap_init(struct net_backend *be, const char *devname,
-net_be_rxeof_t cb, void *param)
+const char *opts, net_be_rxeof_t cb, void *param)
 {
struct tap_priv *priv = (struct tap_priv *)be->opaque;
char tbuf[80];
@@ -473,7 +473,7 @@ netmap_set_cap(struct net_backend *be, uint64_t featur
 
 static int
 netmap_init(struct net_backend *be, const char *devname,
-   net_be_rxeof_t cb, void *param)
+   const char *opts, net_be_rxeof_t cb, void *param)
 {
struct netmap_priv *priv = (struct netmap_priv *)be->opaque;
 
@@ -746,12 +746,22 @@ DATA_SET(net_backend_set, vale_backend);
  * the argument for the callback.
  */
 int
-netbe_init(struct net_backend **ret, const char *devname, net_be_rxeof_t cb,
+netbe_init(struct net_backend **ret, const char *opts, net_be_rxeof_t cb,
 void *param)
 {
struct net_backend **pbe, *nbe, *tbe = NULL;
+   char *devname;
+   char *options;
int err;
 
+   devname = options = strdup(opts);
+
+   if (devname == NULL) {
+   return (-1);
+   }
+
+   devname = strsep(, ",");
+
/*
 * Find the network backend that matches the user-provided
 * device name. net_backend_set is built using a linker set.
@@ -771,8 +781,11 @@ netbe_init(struct net_backend **ret, const char *devna
}
 
*ret = NULL;
-   if (tbe == NULL)
+   if (tbe == NULL) {
+   free(devname);
return (EINVAL);
+   }
+
nbe = calloc(1, sizeof(*nbe) + tbe->priv_size);
*nbe = *tbe;/* copy the template */
nbe->fd = -1;
@@ -781,13 +794,15 @@ netbe_init(struct net_backend **ret, const char *devna
nbe->fe_vnet_hdr_len = 0;
 
/* Initialize the backend. */
-   err = nbe->init(nbe, devname, cb, param);
+   err = nbe->init(nbe, devname, options, cb, param);
if (err) {
+   free(devname);
free(nbe);
return (err);
}
 
*ret = nbe;
+   free(devname);
 
return (0);
 }

Modified: head/usr.sbin/bhyve/net_backends.h
==
--- head/usr.sbin/bhyve/net_backends.h  Fri May  8 17:01:33 2020
(r360819)
+++ head/usr.sbin/bhyve/net_backends.h  Fri May  8 17:15:54 2020
(r360820)
@@ -37,7 +37,7 @@ typedef struct net_backend net_backend_t;
 
 /* Interface between network frontends and the network backends. */
 typedef void (*net_be_rxeof_t)(int, enum ev_type, void *param);
-intnetbe_init(net_backend_t **be, const char *devname, net_be_rxeof_t cb,
+intnetbe_init(net_backend_t **be, const char *opts, net_be_rxeof_t cb,
 void *param);
 void   netbe_cleanup(net_backend_t *be);
 uint64_t netbe_get_cap(net_backend_t *be);

Modified: head/usr.sbin/bhyve/pci_e82545.c
==
--- head/usr.sbin/bhyve/pci_e82545.cFri May  8 17:01:33 2020
(r360819)
+++ head/usr.sbin/bhyve/pci_e82545.cFri May  8 17:15:54 2020
(r360820)
@@ -2281,7 +2281,7 @@ e82545_init(struct vmctx *ctx, struct pci_devinst *pi,
 {
char nstr[80];
struct e82545_softc *sc;
-   char *devname;
+   char *optscopy;
char *vtopts;
int mac_provided;
 
@@ -2332,7 +2332,7 @@ e82545_init(struct vmctx *ctx, struct pci_devinst *pi,
if (opts != NULL) {
int err = 0;
 
-   devname = vtopts = strdup(opts);
+   optscopy = vtopts = strdup(opts);
(void) strsep(, ",");
 
/*
@@ -2357,15 +2357,18 @@ e82545_init(struct vmctx *ctx, struct pci_devinst *pi,
}
}
 
+   

Re: svn commit: r360398 - head/sys/net

2020-04-29 Thread Aleksandr Fedorov


___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r360372 - head/sys/netgraph

2020-04-27 Thread Aleksandr Fedorov
Author: afedorov
Date: Mon Apr 27 10:00:46 2020
New Revision: 360372
URL: https://svnweb.freebsd.org/changeset/base/360372

Log:
  ng_eiface: fix kernel panic due to the racecondition in ng_eiface shutdown.
  
  PR:   244247
  Reported by:  Vladislav V. Prodan 
  Reviewed by:  vmaffione, lutz_donnerhacke.de
  Approved by:  vmaffione (mentor)
  Sponsored by: vstack.com
  Differential Revision:https://reviews.freebsd.org/D24557

Modified:
  head/sys/netgraph/ng_eiface.c

Modified: head/sys/netgraph/ng_eiface.c
==
--- head/sys/netgraph/ng_eiface.c   Mon Apr 27 09:45:19 2020
(r360371)
+++ head/sys/netgraph/ng_eiface.c   Mon Apr 27 10:00:46 2020
(r360372)
@@ -623,8 +623,8 @@ ng_eiface_rmnode(node_p node)
 * hence we have to change the current vnet context here.
 */
CURVNET_SET_QUIET(ifp->if_vnet);
-   ifmedia_removeall(>media);
ether_ifdetach(ifp);
+   ifmedia_removeall(>media);
if_free(ifp);
CURVNET_RESTORE();
free_unr(V_ng_eiface_unit, priv->unit);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r359704 - head/usr.sbin/bhyve

2020-04-07 Thread Aleksandr Fedorov
Author: afedorov
Date: Tue Apr  7 17:06:33 2020
New Revision: 359704
URL: https://svnweb.freebsd.org/changeset/base/359704

Log:
  Add VIRTIO_NET_F_MTU flag support for the bhyve virtio-net device.
  The flag can be enabled using the new 'mtu' option:
  bhyve -s X:Y:Z,virtio-net,[tapN|valeX:N],mtu=9000
  
  Reported by:  vmaffione, jhb
  Approved by:  vmaffione (mentor)
  Differential Revision:https://reviews.freebsd.org/D23971

Modified:
  head/usr.sbin/bhyve/net_backends.h
  head/usr.sbin/bhyve/net_utils.c
  head/usr.sbin/bhyve/net_utils.h
  head/usr.sbin/bhyve/pci_virtio_net.c

Modified: head/usr.sbin/bhyve/net_backends.h
==
--- head/usr.sbin/bhyve/net_backends.h  Tue Apr  7 17:05:05 2020
(r359703)
+++ head/usr.sbin/bhyve/net_backends.h  Tue Apr  7 17:06:33 2020
(r359704)
@@ -59,6 +59,7 @@ void  netbe_rx_enable(net_backend_t *be);
  */
 #defineVIRTIO_NET_F_CSUM   (1 <<  0) /* host handles partial cksum 
*/
 #defineVIRTIO_NET_F_GUEST_CSUM (1 <<  1) /* guest handles partial 
cksum */
+#defineVIRTIO_NET_F_MTU(1 <<  3) /* initial MTU advice */
 #defineVIRTIO_NET_F_MAC(1 <<  5) /* host supplies MAC */
 #defineVIRTIO_NET_F_GSO_DEPREC (1 <<  6) /* deprecated: host handles 
GSO */
 #defineVIRTIO_NET_F_GUEST_TSO4 (1 <<  7) /* guest can rcv TSOv4 */
@@ -76,6 +77,7 @@ void  netbe_rx_enable(net_backend_t *be);
 #defineVIRTIO_NET_F_CTRL_VLAN  (1 << 19) /* control channel VLAN 
filtering */
 #defineVIRTIO_NET_F_GUEST_ANNOUNCE \
(1 << 21) /* guest can send gratuitous pkts */
+#defineVIRTIO_NET_F_MQ (1 << 22) /* host supports multiple VQ 
pairs */
 
 /*
  * Fixed network header size

Modified: head/usr.sbin/bhyve/net_utils.c
==
--- head/usr.sbin/bhyve/net_utils.c Tue Apr  7 17:05:05 2020
(r359703)
+++ head/usr.sbin/bhyve/net_utils.c Tue Apr  7 17:06:33 2020
(r359704)
@@ -31,9 +31,12 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 
+#include 
 #include 
+#include 
 #include 
 #include 
+#include 
 #include 
 
 #include "bhyverun.h"
@@ -59,6 +62,37 @@ net_parsemac(char *mac_str, uint8_t *mac_addr)
memcpy(mac_addr, ea->octet, ETHER_ADDR_LEN);
 
 return (0);
+}
+
+int
+net_parsemtu(const char *mtu_str, unsigned long *mtu)
+{
+   char *end;
+   unsigned long val;
+
+   assert(mtu_str != NULL);
+
+   if (*mtu_str == '-')
+   goto err;
+
+   val = strtoul(mtu_str, , 0);
+
+   if (*end != '\0')
+   goto err;
+
+   if (val == ULONG_MAX)
+   return (ERANGE);
+
+   if (val == 0 && errno == EINVAL)
+   return (EINVAL);
+
+   *mtu = val;
+
+   return (0);
+
+err:
+   errno = EINVAL;
+   return (EINVAL);
 }
 
 void

Modified: head/usr.sbin/bhyve/net_utils.h
==
--- head/usr.sbin/bhyve/net_utils.h Tue Apr  7 17:05:05 2020
(r359703)
+++ head/usr.sbin/bhyve/net_utils.h Tue Apr  7 17:06:33 2020
(r359704)
@@ -35,5 +35,6 @@
 
 void   net_genmac(struct pci_devinst *pi, uint8_t *macaddr);
 intnet_parsemac(char *mac_str, uint8_t *mac_addr);
+intnet_parsemtu(const char *mtu_str, unsigned long *mtu);
 
 #endif /* _NET_UTILS_H_ */

Modified: head/usr.sbin/bhyve/pci_virtio_net.c
==
--- head/usr.sbin/bhyve/pci_virtio_net.cTue Apr  7 17:05:05 2020
(r359703)
+++ head/usr.sbin/bhyve/pci_virtio_net.cTue Apr  7 17:06:33 2020
(r359704)
@@ -67,6 +67,9 @@ __FBSDID("$FreeBSD$");
 
 #define VTNET_MAX_PKT_LEN  (65536 + 64)
 
+#define VTNET_MIN_MTU  ETHERMIN
+#define VTNET_MAX_MTU  65535
+
 #define VTNET_S_HOSTCAPS  \
   ( VIRTIO_NET_F_MAC | VIRTIO_NET_F_STATUS | \
 VIRTIO_F_NOTIFY_ON_EMPTY | VIRTIO_RING_F_INDIRECT_DESC)
@@ -77,6 +80,8 @@ __FBSDID("$FreeBSD$");
 struct virtio_net_config {
uint8_t  mac[6];
uint16_t status;
+   uint16_t max_virtqueue_pairs;
+   uint16_t mtu;
 } __packed;
 
 /*
@@ -532,6 +537,8 @@ pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *
struct pci_vtnet_softc *sc;
char tname[MAXCOMLEN + 1];
int mac_provided;
+   int mtu_provided;
+   unsigned long mtu = ETHERMTU;
 
/*
 * Allocate data structures for further virtio initializations.
@@ -557,6 +564,7 @@ pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *
 * if specified.
 */
mac_provided = 0;
+   mtu_provided = 0;
if (opts != NULL) {
char *devname;
char *vtopts;
@@ -585,6 +593,17 @@ pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *
if