Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp559942imp; Thu, 21 Feb 2019 06:52:09 -0800 (PST) X-Google-Smtp-Source: AHgI3IZDlEecUJHH3LFSvYR0kmz1Ao6/f0iKbnc+Ov4eRVBw2s14vigqdsrFpcomWDOauoRKHwBd X-Received: by 2002:a62:6e05:: with SMTP id j5mr41577844pfc.158.1550760729449; Thu, 21 Feb 2019 06:52:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550760729; cv=none; d=google.com; s=arc-20160816; b=TMVnm7zBXnx5G6rXxL07Tgz17PLH8ZDUXa620OtEvQThAqOHT3Bv1iY86UbxdRlj7J tEfAUP2Qqw9V3wjJEgkEFSo5V266nF722XLLGTh1f/xj49wR/wr8DzFV4b8W9twHdYMM YknFZCCxvpRmmIredSYzuHnh1S9HB767dOrHzM2sR/B9sgcevv2w2bslM82aABn32tor /2P8jNSZ+BVLp9YdGXRVaUHPN3jNxwlPm5owbOnHLK+BWiMkBaQ7M/mkjJDrS0LYiegR /Kz2qW6qVysheRknZcywN2tQi62tS8HUUZOvEiruKjRAuVVEOKmwmTr/74JomNcfKZs7 UPkQ== 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=76s1c9mSrrvyfEBsv7YGtPF6gN+rBf4wfYZ1v+JjuOk=; b=RHFIEKHYuQZGY2uSJ6/uV0KJGFZIjs8UUpP6gYsJS/vN4GlCKIEW0SUzPv22H69z4/ B+CZdrO3/Tt3rPiOsBhLOcKpvGGR7xNiEpzk5oCy86IPYdgJf7faHhfDPoeHk+VB4stB kAyOhNwMDODJwc5425j1Whsa+7SEdnHJpKVjUoyU3BWly7xS73KYbogJG9g2wrR5iCcG Po8LxGNE8RZmbVj6wuMHpff4z4WRoJRTVL9ZJY1DaDC2fKJjF/ilAF1mipmKt09uZ0+/ HNvGVzR5Lpyu4Gkj8SzmpvRTofQqhhwlZUPogavCw/xqiZPxIr/jYm7UxavOXVjJoE+B pgHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2PTllSAR; 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 az2si9754875plb.252.2019.02.21.06.51.53; Thu, 21 Feb 2019 06:52:09 -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=2PTllSAR; 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 S1726279AbfBUOi4 (ORCPT + 99 others); Thu, 21 Feb 2019 09:38:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:60728 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728273AbfBUOiu (ORCPT ); Thu, 21 Feb 2019 09:38:50 -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 C372D2075C; Thu, 21 Feb 2019 14:38:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550759929; bh=9+PlzBC69/UN8zQhk8XLfxKfDf+m3nHGTMDhtoGAu1s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2PTllSARWs6VgTGEpXZaF/VpOpOyV/WGffhunbc4fRrUruNCSW6s5+NktVcUmcGM/ S7dpLM3YgD7/gdWI58EGZWk9Dh7Ze+EEVnHwHwtbuEU7WodF9O0ddplz9EXGKjetbm zTRIb2LLzYB51SK1yw5hA/PbxD8xPxLzPPmJ58fw= 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.9 04/20] net: Fix for_each_netdev_feature on Big endian Date: Thu, 21 Feb 2019 15:35:42 +0100 Message-Id: <20190221125242.858818453@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190221125242.153179182@linuxfoundation.org> References: <20190221125242.153179182@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.9-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; @@ -137,8 +138,26 @@ enum { #define NETIF_F_BUSY_POLL __NETIF_F(BUSY_POLL) #define NETIF_F_HW_TC __NETIF_F(HW_TC) -#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 @@ -6909,7 +6909,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)) { @@ -6929,7 +6929,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",