Skip to content

Commit fd867d5

Browse files
jarodwilsondavem330
authored andcommitted
net/core: generic support for disabling netdev features down stack
There are some netdev features, which when disabled on an upper device, such as a bonding master or a bridge, must be disabled and cannot be re-enabled on underlying devices. This is a rework of an earlier more heavy-handed appraoch, which simply disables and prevents re-enabling of netdev features listed in a new define in include/net/netdev_features.h, NETIF_F_UPPER_DISABLES. Any upper device that disables a flag in that feature mask, the disabling will propagate down the stack, and any lower device that has any upper device with one of those flags disabled should not be able to enable said flag. Initially, only LRO is included for proof of concept, and because this code effectively does the same thing as dev_disable_lro(), though it will also activate from the ethtool path, which was one of the goals here. [root@dell-per730-01 ~]# ethtool -k bond0 |grep large large-receive-offload: on [root@dell-per730-01 ~]# ethtool -k p5p1 |grep large large-receive-offload: on [root@dell-per730-01 ~]# ethtool -K bond0 lro off [root@dell-per730-01 ~]# ethtool -k bond0 |grep large large-receive-offload: off [root@dell-per730-01 ~]# ethtool -k p5p1 |grep large large-receive-offload: off dmesg dump: [ 1033.277986] bond0: Disabling feature 0x0000000000008000 on lower dev p5p2. [ 1034.067949] bnx2x 0000:06:00.1 p5p2: using MSI-X IRQs: sp 74 fp[0] 76 ... fp[7] 83 [ 1034.753612] bond0: Disabling feature 0x0000000000008000 on lower dev p5p1. [ 1035.591019] bnx2x 0000:06:00.0 p5p1: using MSI-X IRQs: sp 62 fp[0] 64 ... fp[7] 71 This has been successfully tested with bnx2x, qlcnic and netxen network cards as slaves in a bond interface. Turning LRO on or off on the master also turns it on or off on each of the slaves, new slaves are added with LRO in the same state as the master, and LRO can't be toggled on the slaves. Also, this should largely remove the need for dev_disable_lro(), and most, if not all, of its call sites can be replaced by simply making sure NETIF_F_LRO isn't included in the relevant device's feature flags. Note that this patch is driven by bug reports from users saying it was confusing that bonds and slaves had different settings for the same features, and while it won't be 100% in sync if a lower device doesn't support a feature like LRO, I think this is a good step in the right direction. CC: "David S. Miller" <[email protected]> CC: Eric Dumazet <[email protected]> CC: Jay Vosburgh <[email protected]> CC: Veaceslav Falico <[email protected]> CC: Andy Gospodarek <[email protected]> CC: Jiri Pirko <[email protected]> CC: Nikolay Aleksandrov <[email protected]> CC: Michal Kubecek <[email protected]> CC: Alexander Duyck <[email protected]> CC: [email protected] Signed-off-by: Jarod Wilson <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c238041 commit fd867d5

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

include/linux/netdev_features.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ enum {
125125
#define NETIF_F_HW_L2FW_DOFFLOAD __NETIF_F(HW_L2FW_DOFFLOAD)
126126
#define NETIF_F_BUSY_POLL __NETIF_F(BUSY_POLL)
127127

128+
#define for_each_netdev_feature(mask_addr, feature) \
129+
int bit; \
130+
for_each_set_bit(bit, (unsigned long *)mask_addr, NETDEV_FEATURE_COUNT) \
131+
feature = __NETIF_F_BIT(bit);
132+
128133
/* Features valid for ethtool to change */
129134
/* = all defined minus driver/device-class-related */
130135
#define NETIF_F_NEVER_CHANGE (NETIF_F_VLAN_CHALLENGED | \
@@ -167,6 +172,12 @@ enum {
167172
*/
168173
#define NETIF_F_ALL_FOR_ALL (NETIF_F_NOCACHE_COPY | NETIF_F_FSO)
169174

175+
/*
176+
* If upper/master device has these features disabled, they must be disabled
177+
* on all lower/slave devices as well.
178+
*/
179+
#define NETIF_F_UPPER_DISABLES NETIF_F_LRO
180+
170181
/* changeable features with no special hardware requirements */
171182
#define NETIF_F_SOFT_FEATURES (NETIF_F_GSO | NETIF_F_GRO)
172183

net/core/dev.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6288,6 +6288,44 @@ static void rollback_registered(struct net_device *dev)
62886288
list_del(&single);
62896289
}
62906290

6291+
static netdev_features_t netdev_sync_upper_features(struct net_device *lower,
6292+
struct net_device *upper, netdev_features_t features)
6293+
{
6294+
netdev_features_t upper_disables = NETIF_F_UPPER_DISABLES;
6295+
netdev_features_t feature;
6296+
6297+
for_each_netdev_feature(&upper_disables, feature) {
6298+
if (!(upper->wanted_features & feature)
6299+
&& (features & feature)) {
6300+
netdev_dbg(lower, "Dropping feature %pNF, upper dev %s has it off.\n",
6301+
&feature, upper->name);
6302+
features &= ~feature;
6303+
}
6304+
}
6305+
6306+
return features;
6307+
}
6308+
6309+
static void netdev_sync_lower_features(struct net_device *upper,
6310+
struct net_device *lower, netdev_features_t features)
6311+
{
6312+
netdev_features_t upper_disables = NETIF_F_UPPER_DISABLES;
6313+
netdev_features_t feature;
6314+
6315+
for_each_netdev_feature(&upper_disables, feature) {
6316+
if (!(features & feature) && (lower->features & feature)) {
6317+
netdev_dbg(upper, "Disabling feature %pNF on lower dev %s.\n",
6318+
&feature, lower->name);
6319+
lower->wanted_features &= ~feature;
6320+
netdev_update_features(lower);
6321+
6322+
if (unlikely(lower->features & feature))
6323+
netdev_WARN(upper, "failed to disable %pNF on %s!\n",
6324+
&feature, lower->name);
6325+
}
6326+
}
6327+
}
6328+
62916329
static netdev_features_t netdev_fix_features(struct net_device *dev,
62926330
netdev_features_t features)
62936331
{
@@ -6357,7 +6395,9 @@ static netdev_features_t netdev_fix_features(struct net_device *dev,
63576395

63586396
int __netdev_update_features(struct net_device *dev)
63596397
{
6398+
struct net_device *upper, *lower;
63606399
netdev_features_t features;
6400+
struct list_head *iter;
63616401
int err = 0;
63626402

63636403
ASSERT_RTNL();
@@ -6370,6 +6410,10 @@ int __netdev_update_features(struct net_device *dev)
63706410
/* driver might be less strict about feature dependencies */
63716411
features = netdev_fix_features(dev, features);
63726412

6413+
/* some features can't be enabled if they're off an an upper device */
6414+
netdev_for_each_upper_dev_rcu(dev, upper, iter)
6415+
features = netdev_sync_upper_features(dev, upper, features);
6416+
63736417
if (dev->features == features)
63746418
return 0;
63756419

@@ -6386,6 +6430,12 @@ int __netdev_update_features(struct net_device *dev)
63866430
return -1;
63876431
}
63886432

6433+
/* some features must be disabled on lower devices when disabled
6434+
* on an upper device (think: bonding master or bridge)
6435+
*/
6436+
netdev_for_each_lower_dev(dev, lower, iter)
6437+
netdev_sync_lower_features(dev, lower, features);
6438+
63896439
if (!err)
63906440
dev->features = features;
63916441

0 commit comments

Comments
 (0)