From owner-svn-src-head@freebsd.org Tue Apr 7 17:06:34 2020 Return-Path: Delivered-To: svn-src-head@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 D0053275E38; Tue, 7 Apr 2020 17:06:34 +0000 (UTC) (envelope-from afedorov@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48xYj65BL8z3xY7; Tue, 7 Apr 2020 17:06:34 +0000 (UTC) (envelope-from afedorov@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id AD4C4D1CD; Tue, 7 Apr 2020 17:06:34 +0000 (UTC) (envelope-from afedorov@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 037H6YFa066371; Tue, 7 Apr 2020 17:06:34 GMT (envelope-from afedorov@FreeBSD.org) Received: (from afedorov@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 037H6XRi066367; Tue, 7 Apr 2020 17:06:33 GMT (envelope-from afedorov@FreeBSD.org) Message-Id: <202004071706.037H6XRi066367@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: afedorov set sender to afedorov@FreeBSD.org using -f From: Aleksandr Fedorov Date: Tue, 7 Apr 2020 17:06:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r359704 - head/usr.sbin/bhyve X-SVN-Group: head X-SVN-Commit-Author: afedorov X-SVN-Commit-Paths: head/usr.sbin/bhyve X-SVN-Commit-Revision: 359704 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Apr 2020 17:06:34 -0000 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); */ #define VIRTIO_NET_F_CSUM (1 << 0) /* host handles partial cksum */ #define VIRTIO_NET_F_GUEST_CSUM (1 << 1) /* guest handles partial cksum */ +#define VIRTIO_NET_F_MTU (1 << 3) /* initial MTU advice */ #define VIRTIO_NET_F_MAC (1 << 5) /* host supplies MAC */ #define VIRTIO_NET_F_GSO_DEPREC (1 << 6) /* deprecated: host handles GSO */ #define VIRTIO_NET_F_GUEST_TSO4 (1 << 7) /* guest can rcv TSOv4 */ @@ -76,6 +77,7 @@ void netbe_rx_enable(net_backend_t *be); #define VIRTIO_NET_F_CTRL_VLAN (1 << 19) /* control channel VLAN filtering */ #define VIRTIO_NET_F_GUEST_ANNOUNCE \ (1 << 21) /* guest can send gratuitous pkts */ +#define VIRTIO_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, &end, 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); int net_parsemac(char *mac_str, uint8_t *mac_addr); +int net_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.c Tue Apr 7 17:05:05 2020 (r359703) +++ head/usr.sbin/bhyve/pci_virtio_net.c Tue 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 (err) break; mac_provided = 1; + } else if (strcmp(key, "mtu") == 0) { + err = net_parsemtu(value, &mtu); + if (err) + break; + + if (mtu < VTNET_MIN_MTU || mtu > VTNET_MAX_MTU) { + err = EINVAL; + errno = EINVAL; + break; + } + mtu_provided = 1; } } @@ -608,6 +627,17 @@ pci_vtnet_init(struct vmctx *ctx, struct pci_devinst * if (!mac_provided) { net_genmac(pi, sc->vsc_config.mac); } + + sc->vsc_config.mtu = mtu; + if (mtu_provided) { + sc->vsc_consts.vc_hv_caps |= VIRTIO_NET_F_MTU; + } + + /* + * Since we do not actually support multiqueue, + * set the maximum virtqueue pairs to 1. + */ + sc->vsc_config.max_virtqueue_pairs = 1; /* initialize config space */ pci_set_cfgdata16(pi, PCIR_DEVICE, VIRTIO_DEV_NET);