Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp559642imp; Thu, 21 Feb 2019 06:51:50 -0800 (PST) X-Google-Smtp-Source: AHgI3IaW2/z1Ho2hxPAtQc6zj0o3iOGSBZG5Y0wPnpgp6CwrK031wB4LIvB27cog62FxPU+rT/2o X-Received: by 2002:a17:902:b20e:: with SMTP id t14mr39836912plr.97.1550760710343; Thu, 21 Feb 2019 06:51:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550760710; cv=none; d=google.com; s=arc-20160816; b=WT5zlXl4DW7UgxDoLryFhdlRdAnDMqdVBezYSRQMJkp9rGT5SQfwW8FSNeBU69d/ch O4f45kUx5k1yTyA+sZZt8hpWm5Fb3xMlEYAkLvc5aao7wka8ceIyoNN6a6QOsIHFF9mp x1Qdt1c7H3ZwIzaHuLkzakbeeiBPxwQgBG8JPVJSZzDt7GPC8WSAqPmOCdaHgZRLdCca vOLxClFVpwiED8SIuQJOaVGJO8jNqho/HCRMxwSMGVbFZU7at7diR/YYsYGjLYCUS9ke +75IYaqtabU/I1YUXu34VxrKbmnj5Q+yCgQXTiC/SIqKUoSULpgRW6HbgZVgB1Ab3XPM VEzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=f3vKJp+QoG1CaFVzNKcfo6IgjpIbbJmLo/yu0egPR20=; b=QoWa86hljNUl4z/wSx0lmLO1Z7bVsFRSYnF6u8cgcwLtJ5ICUDja+md3L8LaDS8NhU Xjt800HxBhBDACPZlNnwAJyHyNeXQyhW9VbCdW5d8SXwn7SYKwfr/KTgZCbmPfsEe27b SS81h1uR0P/ZyTvbCZFuZB6NP559LgZxkoIZeQHK4MNxl+DaKfZciCeZRn1OW1uo4EFq Umpr4Yzyg9fi7HrgJW0iih2ngUnO1UJrfuhF859R9Lk7Dz9bNrlOXFfxIe2cQIIzQ8XA Bpm2ReYKL0Wai0okUA9Qdtk/xE1vZigSol+5sT8Yx9P8GUGvw9EzDwgMe41anqtHHHnm o2sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ScnYu1nI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j2si18086658pfn.276.2019.02.21.06.51.34; Thu, 21 Feb 2019 06:51:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ScnYu1nI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728574AbfBUOiF (ORCPT + 99 others); Thu, 21 Feb 2019 09:38:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:59588 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727771AbfBUOiD (ORCPT ); Thu, 21 Feb 2019 09:38:03 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5387320838; Thu, 21 Feb 2019 14:38:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550759882; bh=IICRDMRi4U2WO9ovdecDoirhdTVFggtfBkInrveLMV4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ScnYu1nILt7yQYRp0tLgjEsYxGrxFTmq22Q/L/8JvPKusGY1+3mH2LAWNttTdXN16 gRrOHcW47aoajNsJhhjIN63H+WQ37Ai9fZbALAg8jbJSLZjmLbB8nzRrvhr9RPcU6B hW+ULE1FLDgMKG/WpBZJ9CgLpc4wrxDkw1t/U644= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hauke Mehrtens , "David S. Miller" Subject: [PATCH 4.4 04/20] net: Fix for_each_netdev_feature on Big endian Date: Thu, 21 Feb 2019 15:35:34 +0100 Message-Id: <20190221141946.903434630@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190221141946.772985220@linuxfoundation.org> References: <20190221141946.772985220@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hauke Mehrtens [ Upstream commit 3b89ea9c5902acccdbbdec307c85edd1bf52515e ] The features attribute is of type u64 and stored in the native endianes on the system. The for_each_set_bit() macro takes a pointer to a 32 bit array and goes over the bits in this area. On little Endian systems this also works with an u64 as the most significant bit is on the highest address, but on big endian the words are swapped. When we expect bit 15 here we get bit 47 (15 + 32). This patch converts it more or less to its own for_each_set_bit() implementation which works on 64 bit integers directly. This is then completely in host endianness and should work like expected. Fixes: fd867d51f ("net/core: generic support for disabling netdev features down stack") Signed-off-by: Hauke Mehrtens Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/linux/netdev_features.h | 23 +++++++++++++++++++++-- net/core/dev.c | 4 ++-- 2 files changed, 23 insertions(+), 4 deletions(-) --- a/include/linux/netdev_features.h +++ b/include/linux/netdev_features.h @@ -11,6 +11,7 @@ #define _LINUX_NETDEV_FEATURES_H #include +#include typedef u64 netdev_features_t; @@ -125,8 +126,26 @@ enum { #define NETIF_F_HW_L2FW_DOFFLOAD __NETIF_F(HW_L2FW_DOFFLOAD) #define NETIF_F_BUSY_POLL __NETIF_F(BUSY_POLL) -#define for_each_netdev_feature(mask_addr, bit) \ - for_each_set_bit(bit, (unsigned long *)mask_addr, NETDEV_FEATURE_COUNT) +/* Finds the next feature with the highest number of the range of start till 0. + */ +static inline int find_next_netdev_feature(u64 feature, unsigned long start) +{ + /* like BITMAP_LAST_WORD_MASK() for u64 + * this sets the most significant 64 - start to 0. + */ + feature &= ~0ULL >> (-start & ((sizeof(feature) * 8) - 1)); + + return fls64(feature) - 1; +} + +/* This goes for the MSB to the LSB through the set feature bits, + * mask_addr should be a u64 and bit an int + */ +#define for_each_netdev_feature(mask_addr, bit) \ + for ((bit) = find_next_netdev_feature((mask_addr), \ + NETDEV_FEATURE_COUNT); \ + (bit) >= 0; \ + (bit) = find_next_netdev_feature((mask_addr), (bit) - 1)) /* Features valid for ethtool to change */ /* = all defined minus driver/device-class-related */ --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6421,7 +6421,7 @@ static netdev_features_t netdev_sync_upp netdev_features_t feature; int feature_bit; - for_each_netdev_feature(&upper_disables, feature_bit) { + for_each_netdev_feature(upper_disables, feature_bit) { feature = __NETIF_F_BIT(feature_bit); if (!(upper->wanted_features & feature) && (features & feature)) { @@ -6441,7 +6441,7 @@ static void netdev_sync_lower_features(s netdev_features_t feature; int feature_bit; - for_each_netdev_feature(&upper_disables, feature_bit) { + for_each_netdev_feature(upper_disables, feature_bit) { feature = __NETIF_F_BIT(feature_bit); if (!(features & feature) && (lower->features & feature)) { netdev_dbg(upper, "Disabling feature %pNF on lower dev %s.\n",