From owner-svn-src-stable@freebsd.org Mon Dec 24 15:08:21 2018 Return-Path: Delivered-To: svn-src-stable@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 092B61346599; Mon, 24 Dec 2018 15:08:21 +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 9E8DB89682; Mon, 24 Dec 2018 15:08:20 +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 767AE260AD; Mon, 24 Dec 2018 15:08:20 +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 wBOF8K83027531; Mon, 24 Dec 2018 15:08:20 GMT (envelope-from vmaffione@FreeBSD.org) Received: (from vmaffione@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wBOF8K9B027529; Mon, 24 Dec 2018 15:08:20 GMT (envelope-from vmaffione@FreeBSD.org) Message-Id: <201812241508.wBOF8K9B027529@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: vmaffione set sender to vmaffione@FreeBSD.org using -f From: Vincenzo Maffione Date: Mon, 24 Dec 2018 15:08:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r342395 - stable/11/sys/dev/netmap X-SVN-Group: stable-11 X-SVN-Commit-Author: vmaffione X-SVN-Commit-Paths: stable/11/sys/dev/netmap X-SVN-Commit-Revision: 342395 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 9E8DB89682 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; NEURAL_HAM_SHORT(-0.99)[-0.986,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-0.998,0] X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Dec 2018 15:08:21 -0000 Author: vmaffione Date: Mon Dec 24 15:08:19 2018 New Revision: 342395 URL: https://svnweb.freebsd.org/changeset/base/342395 Log: MFC r342300 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. Modified: stable/11/sys/dev/netmap/netmap.c stable/11/sys/dev/netmap/netmap_kern.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/netmap/netmap.c ============================================================================== --- stable/11/sys/dev/netmap/netmap.c Mon Dec 24 15:07:36 2018 (r342394) +++ stable/11/sys/dev/netmap/netmap.c Mon Dec 24 15:08:19 2018 (r342395) @@ -447,7 +447,7 @@ ports attached to the switch) #include /* bus_dmamap_* */ #include #include -#include /* ETHER_BPF_MTAP */ +#include /* ETHER_BPF_MTAP */ #elif defined(linux) @@ -2118,6 +2118,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. @@ -2227,11 +2274,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); @@ -2239,45 +2285,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: stable/11/sys/dev/netmap/netmap_kern.h ============================================================================== --- stable/11/sys/dev/netmap/netmap_kern.h Mon Dec 24 15:07:36 2018 (r342394) +++ stable/11/sys/dev/netmap/netmap_kern.h Mon Dec 24 15:08:19 2018 (r342395) @@ -1452,6 +1452,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);