From owner-svn-src-head@freebsd.org Fri Dec 21 11:50:16 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2C9BA13468A9; Fri, 21 Dec 2018 11:50:16 +0000 (UTC) (envelope-from vmaffione@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 C2A7992E92; Fri, 21 Dec 2018 11:50:15 +0000 (UTC) (envelope-from vmaffione@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 B1135CE70; Fri, 21 Dec 2018 11:50:15 +0000 (UTC) (envelope-from vmaffione@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wBLBoFcU027967; Fri, 21 Dec 2018 11:50:15 GMT (envelope-from vmaffione@FreeBSD.org) Received: (from vmaffione@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wBLBoFEY027965; Fri, 21 Dec 2018 11:50:15 GMT (envelope-from vmaffione@FreeBSD.org) Message-Id: <201812211150.wBLBoFEY027965@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: vmaffione set sender to vmaffione@FreeBSD.org using -f From: Vincenzo Maffione Date: Fri, 21 Dec 2018 11:50:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r342300 - head/sys/dev/netmap X-SVN-Group: head X-SVN-Commit-Author: vmaffione X-SVN-Commit-Paths: head/sys/dev/netmap X-SVN-Commit-Revision: 342300 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: C2A7992E92 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.98)[-0.976,0]; NEURAL_HAM_LONG(-1.00)[-0.999,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] 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: Fri, 21 Dec 2018 11:50:16 -0000 Author: vmaffione Date: Fri Dec 21 11:50:14 2018 New Revision: 342300 URL: https://svnweb.freebsd.org/changeset/base/342300 Log: netmap: move buf_size validation code to its own function This code validates the netmap buf_size against the interface MTU and maximum descriptor size, to make sure the values are consistent. Moving this functionality to its own function is needed because this function is also called by Linux-specific code. MFC after: 3 days Modified: head/sys/dev/netmap/netmap.c head/sys/dev/netmap/netmap_kern.h Modified: head/sys/dev/netmap/netmap.c ============================================================================== --- head/sys/dev/netmap/netmap.c Fri Dec 21 11:32:55 2018 (r342299) +++ head/sys/dev/netmap/netmap.c Fri Dec 21 11:50:14 2018 (r342300) @@ -449,7 +449,7 @@ ports attached to the switch) #include /* bus_dmamap_* */ #include #include -#include /* ETHER_BPF_MTAP */ +#include /* ETHER_BPF_MTAP */ #elif defined(linux) @@ -2117,6 +2117,53 @@ netmap_csb_validate(struct netmap_priv_d *priv, struct return 0; } +/* Ensure that the netmap adapter can support the given MTU. + * @return EINVAL if the na cannot be set to mtu, 0 otherwise. + */ +int +netmap_buf_size_validate(const struct netmap_adapter *na, unsigned mtu) { + unsigned nbs = NETMAP_BUF_SIZE(na); + + if (mtu <= na->rx_buf_maxsize) { + /* The MTU fits a single NIC slot. We only + * Need to check that netmap buffers are + * large enough to hold an MTU. NS_MOREFRAG + * cannot be used in this case. */ + if (nbs < mtu) { + nm_prerr("error: netmap buf size (%u) " + "< device MTU (%u)", nbs, mtu); + return EINVAL; + } + } else { + /* More NIC slots may be needed to receive + * or transmit a single packet. Check that + * the adapter supports NS_MOREFRAG and that + * netmap buffers are large enough to hold + * the maximum per-slot size. */ + if (!(na->na_flags & NAF_MOREFRAG)) { + nm_prerr("error: large MTU (%d) needed " + "but %s does not support " + "NS_MOREFRAG", mtu, + na->ifp->if_xname); + return EINVAL; + } else if (nbs < na->rx_buf_maxsize) { + nm_prerr("error: using NS_MOREFRAG on " + "%s requires netmap buf size " + ">= %u", na->ifp->if_xname, + na->rx_buf_maxsize); + return EINVAL; + } else { + nm_prinf("info: netmap application on " + "%s needs to support " + "NS_MOREFRAG " + "(MTU=%u,netmap_buf_size=%u)", + na->ifp->if_xname, mtu, nbs); + } + } + return 0; +} + + /* * possibly move the interface to netmap-mode. * If success it returns a pointer to netmap_if, otherwise NULL. @@ -2226,11 +2273,10 @@ netmap_do_regif(struct netmap_priv_d *priv, struct net */ if (na->ifp && nm_priv_rx_enabled(priv)) { /* This netmap adapter is attached to an ifnet. */ - unsigned nbs = NETMAP_BUF_SIZE(na); unsigned mtu = nm_os_ifnet_mtu(na->ifp); ND("%s: mtu %d rx_buf_maxsize %d netmap_buf_size %d", - na->name, mtu, na->rx_buf_maxsize, nbs); + na->name, mtu, na->rx_buf_maxsize, NETMAP_BUF_SIZE(na)); if (na->rx_buf_maxsize == 0) { nm_prerr("%s: error: rx_buf_maxsize == 0", na->name); @@ -2238,45 +2284,9 @@ netmap_do_regif(struct netmap_priv_d *priv, struct net goto err_drop_mem; } - if (mtu <= na->rx_buf_maxsize) { - /* The MTU fits a single NIC slot. We only - * Need to check that netmap buffers are - * large enough to hold an MTU. NS_MOREFRAG - * cannot be used in this case. */ - if (nbs < mtu) { - nm_prerr("error: netmap buf size (%u) " - "< device MTU (%u)", nbs, mtu); - error = EINVAL; - goto err_drop_mem; - } - } else { - /* More NIC slots may be needed to receive - * or transmit a single packet. Check that - * the adapter supports NS_MOREFRAG and that - * netmap buffers are large enough to hold - * the maximum per-slot size. */ - if (!(na->na_flags & NAF_MOREFRAG)) { - nm_prerr("error: large MTU (%d) needed " - "but %s does not support " - "NS_MOREFRAG", mtu, - na->ifp->if_xname); - error = EINVAL; - goto err_drop_mem; - } else if (nbs < na->rx_buf_maxsize) { - nm_prerr("error: using NS_MOREFRAG on " - "%s requires netmap buf size " - ">= %u", na->ifp->if_xname, - na->rx_buf_maxsize); - error = EINVAL; - goto err_drop_mem; - } else { - nm_prinf("info: netmap application on " - "%s needs to support " - "NS_MOREFRAG " - "(MTU=%u,netmap_buf_size=%u)", - na->ifp->if_xname, mtu, nbs); - } - } + error = netmap_buf_size_validate(na, mtu); + if (error) + goto err_drop_mem; } /* Modified: head/sys/dev/netmap/netmap_kern.h ============================================================================== --- head/sys/dev/netmap/netmap_kern.h Fri Dec 21 11:32:55 2018 (r342299) +++ head/sys/dev/netmap/netmap_kern.h Fri Dec 21 11:50:14 2018 (r342300) @@ -1454,6 +1454,7 @@ void netmap_set_all_rings(struct netmap_adapter *, int void netmap_disable_all_rings(struct ifnet *); void netmap_enable_all_rings(struct ifnet *); +int netmap_buf_size_validate(const struct netmap_adapter *na, unsigned mtu); int netmap_do_regif(struct netmap_priv_d *priv, struct netmap_adapter *na, uint32_t nr_mode, uint16_t nr_ringid, uint64_t nr_flags); void netmap_do_unregif(struct netmap_priv_d *priv);