From patchwork Wed Mar 15 23:31:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarno Rajahalme X-Patchwork-Id: 739475 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vk7Jf25RNz9ryk for ; Thu, 16 Mar 2017 10:35:46 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 609DCBCC; Wed, 15 Mar 2017 23:32:22 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id A686BBC3 for ; Wed, 15 Mar 2017 23:32:21 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 9F09913D for ; Wed, 15 Mar 2017 23:32:20 +0000 (UTC) Received: from mfilter11-d.gandi.net (mfilter11-d.gandi.net [217.70.178.131]) by relay3-d.mail.gandi.net (Postfix) with ESMTP id 6F226A80C1; Thu, 16 Mar 2017 00:32:19 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter11-d.gandi.net Received: from relay3-d.mail.gandi.net ([IPv6:::ffff:217.70.183.195]) by mfilter11-d.gandi.net (mfilter11-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id L1G-mZRpbb63; Thu, 16 Mar 2017 00:32:17 +0100 (CET) X-Originating-IP: 208.91.1.34 Received: from sc9-mailhost1.vmware.com (unknown [208.91.1.34]) (Authenticated sender: jarno@ovn.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id C97A8A80C6; Thu, 16 Mar 2017 00:32:15 +0100 (CET) From: Jarno Rajahalme To: dev@openvswitch.org Date: Wed, 15 Mar 2017 16:31:12 -0700 Message-Id: <1489620689-122370-9-git-send-email-jarno@ovn.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1489620689-122370-1-git-send-email-jarno@ovn.org> References: <1489620689-122370-1-git-send-email-jarno@ovn.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Jarod Wilson Subject: [ovs-dev] [PATCH branch-2.7 08/25] datapath: use core MTU range checking in core net infra X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Jarod Wilson Upstream commit: commit 61e84623ace35ce48975e8f90bbbac7557c43d61 Author: Jarod Wilson Date: Fri Oct 7 22:04:33 2016 -0400 net: centralize net_device min/max MTU checking While looking into an MTU issue with sfc, I started noticing that almost every NIC driver with an ndo_change_mtu function implemented almost exactly the same range checks, and in many cases, that was the only practical thing their ndo_change_mtu function was doing. Quite a few drivers have either 68, 64, 60 or 46 as their minimum MTU value checked, and then various sizes from 1500 to 65535 for their maximum MTU value. We can remove a whole lot of redundant code here if we simple store min_mtu and max_mtu in net_device, and check against those in net/core/dev.c's dev_set_mtu(). In theory, there should be zero functional change with this patch, it just puts the infrastructure in place. Subsequent patches will attempt to start using said infrastructure, with theoretically zero change in functionality. CC: netdev@vger.kernel.org Signed-off-by: Jarod Wilson Signed-off-by: David S. Miller Upstream commit: commit 91572088e3fdbf4fe31cf397926d8b890fdb3237 Author: Jarod Wilson Date: Thu Oct 20 13:55:20 2016 -0400 net: use core MTU range checking in core net infra ... openvswitch: - set min/max_mtu, remove internal_dev_change_mtu - note: max_mtu wasn't checked previously, it's been set to 65535, which is the largest possible size supported ... Signed-off-by: Jarod Wilson Signed-off-by: David S. Miller Signed-off-by: Jarno Rajahalme Upstream commit: commit 425df17ce3a26d98f76e2b6b0af2acf4aeb0b026 Author: Jarno Rajahalme Date: Tue Feb 14 21:16:28 2017 -0800 openvswitch: Set internal device max mtu to ETH_MAX_MTU. Commit 91572088e3fd ("net: use core MTU range checking in core net infra") changed the openvswitch internal device to use the core net infra for controlling the MTU range, but failed to actually set the max_mtu as described in the commit message, which now defaults to ETH_DATA_LEN. This patch fixes this by setting max_mtu to ETH_MAX_MTU after ether_setup() call. Fixes: 91572088e3fd ("net: use core MTU range checking in core net infra") Signed-off-by: Jarno Rajahalme Signed-off-by: David S. Miller This backport detects the new max_mtu field in the struct netdevice and uses the upstream code if it exists, and local backport code if not. The latter case is amended with bounds checks with new upstream macros ETH_MIN_MTU and ETH_MAX_MTU and the corresponding error messages from the upstream commit. Signed-off-by: Jarno Rajahalme Signed-off-by: Joe Stringer --- acinclude.m4 | 2 ++ datapath/linux/compat/include/linux/if_ether.h | 8 ++++++++ datapath/vport-internal_dev.c | 22 +++++++++++++++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index e8b64b5..052a18f 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -510,6 +510,8 @@ AC_DEFUN([OVS_CHECK_LINUX_COMPAT], [ OVS_FIND_PARAM_IFELSE([$KSRC/include/linux/netdevice.h], [netdev_master_upper_dev_link], [upper_priv], [OVS_DEFINE([HAVE_NETDEV_MASTER_UPPER_DEV_LINK_PRIV])]) + OVS_FIND_FIELD_IFELSE([$KSRC/include/linux/netdevice.h], [net_device], + [max_mtu]) OVS_GREP_IFELSE([$KSRC/include/linux/netfilter.h], [nf_hook_state]) OVS_GREP_IFELSE([$KSRC/include/linux/netfilter.h], [nf_register_net_hook]) diff --git a/datapath/linux/compat/include/linux/if_ether.h b/datapath/linux/compat/include/linux/if_ether.h index ac0f1ed..5eb99bc 100644 --- a/datapath/linux/compat/include/linux/if_ether.h +++ b/datapath/linux/compat/include/linux/if_ether.h @@ -3,6 +3,14 @@ #include_next +#ifndef ETH_MIN_MTU +#define ETH_MIN_MTU 68 /* Min IPv4 MTU per RFC791 */ +#endif + +#ifndef ETH_MAX_MTU +#define ETH_MAX_MTU 0xFFFFU /* 65535, same as IP_MAX_MTU */ +#endif + #ifndef ETH_P_802_3_MIN #define ETH_P_802_3_MIN 0x0600 #endif diff --git a/datapath/vport-internal_dev.c b/datapath/vport-internal_dev.c index f0542a5..2988e8c 100644 --- a/datapath/vport-internal_dev.c +++ b/datapath/vport-internal_dev.c @@ -89,14 +89,25 @@ static const struct ethtool_ops internal_dev_ethtool_ops = { .get_link = ethtool_op_get_link, }; -static int internal_dev_change_mtu(struct net_device *netdev, int new_mtu) +#ifndef HAVE_NET_DEVICE_WITH_MAX_MTU +static int internal_dev_change_mtu(struct net_device *dev, int new_mtu) { - if (new_mtu < 68) + if (new_mtu < ETH_MIN_MTU) { + net_err_ratelimited("%s: Invalid MTU %d requested, hw min %d\n", + dev->name, new_mtu, ETH_MIN_MTU); return -EINVAL; + } + + if (new_mtu > ETH_MAX_MTU) { + net_err_ratelimited("%s: Invalid MTU %d requested, hw max %d\n", + dev->name, new_mtu, ETH_MAX_MTU); + return -EINVAL; + } - netdev->mtu = new_mtu; + dev->mtu = new_mtu; return 0; } +#endif static void internal_dev_destructor(struct net_device *dev) { @@ -150,7 +161,9 @@ static const struct net_device_ops internal_dev_netdev_ops = { .ndo_stop = internal_dev_stop, .ndo_start_xmit = internal_dev_xmit, .ndo_set_mac_address = eth_mac_addr, +#ifndef HAVE_NET_DEVICE_WITH_MAX_MTU .ndo_change_mtu = internal_dev_change_mtu, +#endif .ndo_get_stats64 = internal_get_stats, #ifdef HAVE_IFF_PHONY_HEADROOM #ifndef HAVE_NET_DEVICE_OPS_WITH_EXTENDED @@ -169,6 +182,9 @@ static void do_setup(struct net_device *netdev) { ether_setup(netdev); +#ifdef HAVE_NET_DEVICE_WITH_MAX_MTU + netdev->max_mtu = ETH_MAX_MTU; +#endif netdev->netdev_ops = &internal_dev_netdev_ops; netdev->priv_flags &= ~IFF_TX_SKB_SHARING;