Skip to contentSkip to conversation

ethtool: correct {GS}CHANNELS and {GS}RXFH conflict

PATCH In review Jacob Keller 3 participants 8 messages Feb 9, 2016 – Mar 14, 2016 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover ethtool: correct {GS}CHANNELS and {GS}RXFH conflict

This patch series fixes up ethtool_set_channels operation which allowed modifying the RXFH table indirectly by reducing the number of queues below the current max queue used by the Rx flow table. Most drivers incorrectly allowed this to destroy the Rx flow table and would then start by reinitializing it to default settings. However, drivers are not able to correctly handle the conflict since there was no way to differentiate between the default settings and the user requested explicit settings.

To fix this, implement a new netdev private flag which we use to indicate whether the RXFH has been user configured. If someone has a better alternative of how to store this information, let me know. I am not sure that priv_flags is the best solution but I have not had any better idea.

Secondly, we add a function which just calls the driver's get_rxfh callback to determine the current indirection table. Loop through this and we can determine the current highest queue that will be used by RSS.

Now, modify ethtool_set_channels to add a check ensuring that if (a) we have had rxfh configured by user, (b) we can get the maximum RSS queue currently used, then we ensure that the newly requested Rx count (or combined count) is at least as high as this maximum RSS queue. The reasoning here is that we can always safely increase the number of queues. If we decrease the queues we must ensure that the decrease does not go lower than the highest in-use queue for the Rx flow table.

Drivers may still need to be patched if they currently overwrite the Rx flow table during channel configuration. If the driver currently always resets Rx flow table when increasing number of queues it must be patched to only do this when netif_is_rxfh_configured returns false.

The second patch simply adds a check to ensure that all provided channel counts fit within driver defined maximums.

The third patch fixes fm10k to correctly reconfigure the RSS reta table whenever it is still unconfigured. This means that the default state will provide RSS to every queue. Once the user has configured RXFH, then we should maintain it. In addition, since the case where we must reconfigure the RSS table in this case should now no longer occur, add a dev_err message to indicate the user that we did so.

I have also supplied an ethtool patch to enable setting the default Rx flow indirection table. Without this, current ethtool does not support sending an indir_size of 0, and thus does not correctly support configuring back to the default.

Changes in v2:
* fixed compile error
* fixed incorrect comparison with max_rx_in_use
* adjusted looping over dev_size
* removed inline on function
* dropped patch about separating combined vs asymmetric channels
* verified behavior using fm10k driver

Jacob Keller (3):
ethtool: correctly ensure {GS}CHANNELS doesn't conflict with GS{RXFH}
ethtool: ensure channel counts are within bounds during SCHANNELS
fm10k: don't reinitialize RSS flow table when RXFH configured

 drivers/net/ethernet/intel/fm10k/fm10k_main.c | 10 +++-
 include/linux/netdevice.h                     |  8 +++
 net/core/ethtool.c                            | 71 ++++++++++++++++++++++++++-
 3 files changed, 85 insertions(+), 4 deletions(-)
Signature · 1 line
2.7.0.236.gda096a0.dirty
#1 lore raw

PATCH v2 1/4 ethtool: correctly ensure {GS}CHANNELS doesn't conflict with GS{RXFH}

Ethernet drivers implementing both {GS}RXFH and {GS}CHANNELS ethtool ops incorrectly allow SCHANNELS when it would conflict with the settings from SRXFH. This occurs because it is not possible for drivers to understand whether their Rx flow indirection table has been configured or is in the default state. In addition, drivers currently behave in various ways when increasing the number of Rx channels.

Some drivers will always destroy the Rx flow indirection table when this occurs, whether it has been set by the user or not. Other drivers will attempt to preserve the table even if the user has never modified it from the default driver settings. Neither of these situation is desirable because it leads to unexpected behavior or loss of user configuration.

The correct behavior is to simply return -EINVAL when SCHANNELS would conflict with the current Rx flow table settings. However, it should only do so if the current settings were modified by the user. If we required that the new settings never conflict with the current (default) Rx flow settings, we would force users to first reduce their Rx flow settings and then reduce the number of Rx channels.

This patch proposes a solution implemented in net/core/ethtool.c which ensures that all drivers behave correctly. It checks whether the RXFH table has been configured to non-default settings, and stores this information in a private netdev flag. When the number of channels is requested to change, it first ensures that the current Rx flow table is not going to assign flows to now disabled channels.

---
 include/linux/netdevice.h |  8 +++++++
 net/core/ethtool.c        | 55 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
include/linux/netdevice.h +8 -0
index 289c2314d766..044fa2d88c7f 100644
@@ -1291,6 +1291,7 @@ struct net_device_ops {
  * @IFF_OPENVSWITCH: device is a Open vSwitch master
  * @IFF_L3MDEV_SLAVE: device is enslaved to an L3 master device
  * @IFF_TEAM: device is a team device
+ * @IFF_RXFH_CONFIGURED: device has had Rx Flow indirection table configured
  */
 enum netdev_priv_flags {
 	IFF_802_1Q_VLAN			= 1<<0,
@@ -1318,6 +1319,7 @@ enum netdev_priv_flags {
 	IFF_OPENVSWITCH			= 1<<22,
 	IFF_L3MDEV_SLAVE		= 1<<23,
 	IFF_TEAM			= 1<<24,
+	IFF_RXFH_CONFIGURED		= 1<<25,
 };
 
 #define IFF_802_1Q_VLAN			IFF_802_1Q_VLAN
@@ -1345,6 +1347,7 @@ enum netdev_priv_flags {
 #define IFF_OPENVSWITCH			IFF_OPENVSWITCH
 #define IFF_L3MDEV_SLAVE		IFF_L3MDEV_SLAVE
 #define IFF_TEAM			IFF_TEAM
+#define IFF_RXFH_CONFIGURED		IFF_RXFH_CONFIGURED
 
 /**
  *	struct net_device - The DEVICE structure.
@@ -4045,6 +4048,11 @@ static inline bool netif_is_lag_port(const struct net_device *dev)
 	return netif_is_bond_slave(dev) || netif_is_team_port(dev);
 }
 
+static inline bool netif_is_rxfh_configured(const struct net_device *dev)
+{
+	return dev->priv_flags & IFF_RXFH_CONFIGURED;
+}
+
 /* This device needs to keep skb dst for qdisc enqueue or ndo_start_xmit() */
 static inline void netif_keep_dst(struct net_device *dev)
 {
net/core/ethtool.c +55 -0

85 lines not on this page · raw message

Signature · 1 line
2.7.0.236.gda096a0.dirty
#2 lore raw

PATCH v2 2/4 ethtool: ensure channel counts are within bounds during SCHANNELS

In reply to Jacob Keller

Add a sanity check to ensure that all requested channel sizes are within bounds, which should reduce errors in driver implementation.

---
 net/core/ethtool.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
net/core/ethtool.c +11 -2
index 59aebaf9ed54..dc4f6632f33b 100644
@@ -1274,15 +1274,24 @@ static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
 static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
 						   void __user *useraddr)
 {
-	struct ethtool_channels channels;
+	struct ethtool_channels channels, max;
 	u32 max_rx_in_use = 0;
 
-	if (!dev->ethtool_ops->set_channels)
+	if (!dev->ethtool_ops->set_channels || !dev->ethtool_ops->get_channels)
 		return -EOPNOTSUPP;
 
 	if (copy_from_user(&channels, useraddr, sizeof(channels)))
 		return -EFAULT;
 
+	dev->ethtool_ops->get_channels(dev, &max);
+
+	/* ensure new counts are within the maximums */
+	if ((channels.rx_count > max.max_rx) ||
+	    (channels.tx_count > max.max_tx) ||
+	    (channels.combined_count > max.max_combined) ||
+	    (channels.other_count > max.max_other))
+		return -EINVAL;
+
 	/* ensure the new Rx count fits within the configured Rx flow
 	 * indirection table settings */
 	if (netif_is_rxfh_configured(dev) &&
Signature · 1 line
2.7.0.236.gda096a0.dirty
#3 lore raw

PATCH v2 3/4 fm10k: don't reinitialize RSS flow table when RXFH configured

In reply to Jacob Keller

Also print an error message incase we do have to reconfigure as this should no longer happen anymore due to ethtool changes. If it somehow does occur, user should be made aware of it.

---
 drivers/net/ethernet/intel/fm10k/fm10k_main.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_main.c +8 -2
index 134ce4daa994..4e58f9155883 100644
@@ -1937,8 +1937,10 @@ static void fm10k_init_reta(struct fm10k_intfc *interface)
 	u16 i, rss_i = interface->ring_feature[RING_F_RSS].indices;
 	u32 reta, base;
 
-	/* If the netdev is initialized we have to maintain table if possible */
-	if (interface->netdev->reg_state != NETREG_UNINITIALIZED) {
+	/* If the Rx flow indirection table has been configured manually, we
+	 * need to maintain it when possible.
+	 */
+	if (netif_is_rxfh_configured(interface->netdev)) {
 		for (i = FM10K_RETA_SIZE; i--;) {
 			reta = interface->reta[i];
 			if ((((reta << 24) >> 24) < rss_i) &&
@@ -1946,6 +1948,10 @@ static void fm10k_init_reta(struct fm10k_intfc *interface)
 			    (((reta <<  8) >> 24) < rss_i) &&
 			    (((reta)       >> 24) < rss_i))
 				continue;
+
+			/* this should never happen */
+			dev_err(&interface->pdev->dev,
+				"RSS indirection table assigned flows out of queue bounds. Reconfiguring.\n");
 			goto repopulate_reta;
 		}
 
Signature · 1 line
2.7.0.236.gda096a0.dirty
#4 lore raw

PATCH v2 4/4 ethtool: support setting default Rx flow indirection table

In reply to Jacob Keller
---
 ethtool.8.in |  5 ++++-
 ethtool.c    | 46 ++++++++++++++++++++++++++++++++--------------
 2 files changed, 36 insertions(+), 15 deletions(-)
ethtool.8.in +4 -1
index eeffa70415b5..b7d56fbe4484 100644
@@ -296,7 +296,7 @@ ethtool \- query or control network driver and hardware settings
 .IR N \ |
 .BI weight\  W0
 .IR W1
-.RB ...\ ]
+.RB ...\ | \ default \ ]
 .HP
 .B ethtool \-f|\-\-flash
 .I devname file
@@ -805,6 +805,9 @@ Sets the receive flow hash indirection table to spread flows between
 receive queues according to the given weights.  The sum of the weights
 must be non-zero and must not exceed the size of the indirection table.
 .TP
+.BI default
+Sets the receive flow hash indirection table to its default value.
+.TP
 .B \-f \-\-flash
 Write a firmware image to flash or other non-volatile memory on the
 device.
ethtool.c +32 -14

108 lines not on this page · raw message

Signature · 1 line
2.7.0.236.gda096a0.dirty
maintainer
#5 lore raw
In reply to Jacob Keller

From: Jacob Keller <[email protected]>
Date: Mon, 8 Feb 2016 16:05:02 -0800

Quoted 8 lines

This patch series fixes up ethtool_set_channels operation which allowed modifying the RXFH table indirectly by reducing the number of queues below the current max queue used by the Rx flow table. Most drivers incorrectly allowed this to destroy the Rx flow table and would then start by reinitializing it to default settings. However, drivers are not able to correctly handle the conflict since there was no way to differentiate between the default settings and the user requested explicit settings.

...

Patches 1-3 applied to net-next, thanks.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

Re: [PATCH v2 4/4] ethtool: support setting default Rx flow indirection table

Quoted 5 lines · Jacob E

---

Not sure if there is a mailing list for this, I sent this to the netdev list but forgot to Cc you on the ethtool change.

I haven't been keeping up with netdev for a long time, but I have recently set up filtering by subject so I can keep up with just the ethtool-related messages.  Still, patches for the ethtool command should always be explicitly sent to me.

Quoted 4 lines

Dave applied the
network core patches, but they're more or less useless unless we actually have the ability to request default setting using ethtool (which I extended to support "default" here)

The patch was mangled (word-wrapped and modified white-space) in this message, so I took the version in
<http://article.gmane.org/gmane.linux.network/398404/>.

[...]

Quoted 7 lines
(quoted diff) +0 -0
@@ -3332,7 +3335,7 @@ static int do_srxfh(struct cmd_context *ctx)
  	u32 entry_size = sizeof(rss_head.rss_config[0]);
  	u32 num_weights = 0;

(quoted diff) +1 -1
-	if (ctx->argc < 2)
+	if (ctx->argc < 1)

  exit_bad_args();

[...]

This means we might continue without having the required parameter after "equal", "weight" or "hkey".  But, having said that, since we're only checking once before running the loop, we're already failing to validate that properly.

I've applied this, but could you please send another patch that adds checks on ctx->argc within the loop and test cases in test-cmdline.c?

Ben.

Signature · 2 lines
Ben Hutchings
If at first you don't succeed, you're doing about average.
#8 lore raw

RE: [PATCH v2 4/4] ethtool: support setting default Rx flow indirection table

Quoted 45 lines

-----Original Message-----
From: Ben Hutchings [mailto:[email protected]]
Sent: Sunday, March 13, 2016 9:25 AM
To: Keller, Jacob E <[email protected]>
Cc: netdev <[email protected]>
Subject: Re: [PATCH v2 4/4] ethtool: support setting default Rx flow indirection table

Quoted 5 lines · Jacob E

---

Not sure if there is a mailing list for this, I sent this to the netdev list but forgot to Cc you on the ethtool change.

I haven't been keeping up with netdev for a long time, but I have recently set up filtering by subject so I can keep up with just the ethtool-related messages.  Still, patches for the ethtool command should always be explicitly sent to me.

Quoted 4 lines

Dave applied the
network core patches, but they're more or less useless unless we actually have the ability to request default setting using ethtool (which I extended to support "default" here)

The patch was mangled (word-wrapped and modified white-space) in this message, so I took the version in
<http://article.gmane.org/gmane.linux.network/398404/>.

[...]

Review static int do_srxfh(struct cmd_context *ctx) · line 3339

Quoted 7 lines
(quoted diff) +1 -1
@@ -3332,7 +3335,7 @@ static int do_srxfh(struct cmd_context *ctx)
  	u32 entry_size = sizeof(rss_head.rss_config[0]);
  	u32 num_weights = 0;
 
-	if (ctx->argc < 2)
+	if (ctx->argc < 1)
  		exit_bad_args();

[...]

This means we might continue without having the required parameter after "equal", "weight" or "hkey".  But, having said that, since we're only checking once before running the loop, we're already failing to validate that properly.

Quoted 5 lines

I've applied this, but could you please send another patch that adds checks on ctx->argc within the loop and test cases in test-cmdline.c?

Ben.

Yes. Not sure how the patch got broken for you here, as I sent it using git-send-email. I will send the proposed fix above.

Thanks,
Jake