netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 0/3] ethtool-netlink bug fixes
@ 2020-08-14 13:16 Maxim Mikityanskiy
  2020-08-14 13:16 ` [PATCH net 1/3] ethtool: Fix preserving of wanted feature bits in netlink interface Maxim Mikityanskiy
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Maxim Mikityanskiy @ 2020-08-14 13:16 UTC (permalink / raw)
  To: David S. Miller, Michal Kubecek, Andrew Lunn
  Cc: Jakub Kicinski, netdev, Maxim Mikityanskiy

This series contains a few bug fixes for ethtool-netlink. These bugs are
specific for the netlink interface, and the legacy ioctl interface is
not affected. These patches aim to have the same behavior in
ethtool-netlink as in the legacy ethtool.

Please also see the sibling series for the userspace tool.

Maxim Mikityanskiy (3):
  ethtool: Fix preserving of wanted feature bits in netlink interface
  ethtool: Account for hw_features in netlink interface
  ethtool: Don't omit the netlink reply if no features were changed

 net/ethtool/features.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

-- 
2.21.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net 1/3] ethtool: Fix preserving of wanted feature bits in netlink interface
  2020-08-14 13:16 [PATCH net 0/3] ethtool-netlink bug fixes Maxim Mikityanskiy
@ 2020-08-14 13:16 ` Maxim Mikityanskiy
  2020-08-14 13:16 ` [PATCH net 2/3] ethtool: Account for hw_features " Maxim Mikityanskiy
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Maxim Mikityanskiy @ 2020-08-14 13:16 UTC (permalink / raw)
  To: David S. Miller, Michal Kubecek, Andrew Lunn
  Cc: Jakub Kicinski, netdev, Maxim Mikityanskiy

Currently, ethtool-netlink calculates new wanted bits as:
(req_wanted & req_mask) | (old_active & ~req_mask)

It completely discards the old wanted bits, so they are forgotten with
the next ethtool command. Sample steps to reproduce:

1. ethtool -k eth0
   tx-tcp-segmentation: on # TSO is on from the beginning
2. ethtool -K eth0 tx off
   tx-tcp-segmentation: off [not requested]
3. ethtool -k eth0
   tx-tcp-segmentation: off [requested on]
4. ethtool -K eth0 rx off # Some change unrelated to TSO
5. ethtool -k eth0
   tx-tcp-segmentation: off # "Wanted on" is forgotten

This commit fixes it by changing the formula to:
(req_wanted & req_mask) | (old_wanted & ~req_mask),
where old_active was replaced by old_wanted to account for the wanted
bits.

The shortcut condition for the case where nothing was changed now
compares wanted bitmasks, instead of wanted to active.

Signed-off-by: Maxim Mikityanskiy <maximmi@mellanox.com>
---
 net/ethtool/features.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/net/ethtool/features.c b/net/ethtool/features.c
index 4e632dc987d8..ec196f0fddc9 100644
--- a/net/ethtool/features.c
+++ b/net/ethtool/features.c
@@ -224,7 +224,9 @@ int ethnl_set_features(struct sk_buff *skb, struct genl_info *info)
 	DECLARE_BITMAP(wanted_diff_mask, NETDEV_FEATURE_COUNT);
 	DECLARE_BITMAP(active_diff_mask, NETDEV_FEATURE_COUNT);
 	DECLARE_BITMAP(old_active, NETDEV_FEATURE_COUNT);
+	DECLARE_BITMAP(old_wanted, NETDEV_FEATURE_COUNT);
 	DECLARE_BITMAP(new_active, NETDEV_FEATURE_COUNT);
+	DECLARE_BITMAP(new_wanted, NETDEV_FEATURE_COUNT);
 	DECLARE_BITMAP(req_wanted, NETDEV_FEATURE_COUNT);
 	DECLARE_BITMAP(req_mask, NETDEV_FEATURE_COUNT);
 	struct nlattr *tb[ETHTOOL_A_FEATURES_MAX + 1];
@@ -250,6 +252,7 @@ int ethnl_set_features(struct sk_buff *skb, struct genl_info *info)
 
 	rtnl_lock();
 	ethnl_features_to_bitmap(old_active, dev->features);
+	ethnl_features_to_bitmap(old_wanted, dev->wanted_features);
 	ret = ethnl_parse_bitset(req_wanted, req_mask, NETDEV_FEATURE_COUNT,
 				 tb[ETHTOOL_A_FEATURES_WANTED],
 				 netdev_features_strings, info->extack);
@@ -261,11 +264,11 @@ int ethnl_set_features(struct sk_buff *skb, struct genl_info *info)
 		goto out_rtnl;
 	}
 
-	/* set req_wanted bits not in req_mask from old_active */
+	/* set req_wanted bits not in req_mask from old_wanted */
 	bitmap_and(req_wanted, req_wanted, req_mask, NETDEV_FEATURE_COUNT);
-	bitmap_andnot(new_active, old_active, req_mask, NETDEV_FEATURE_COUNT);
-	bitmap_or(req_wanted, new_active, req_wanted, NETDEV_FEATURE_COUNT);
-	if (bitmap_equal(req_wanted, old_active, NETDEV_FEATURE_COUNT)) {
+	bitmap_andnot(new_wanted, old_wanted, req_mask, NETDEV_FEATURE_COUNT);
+	bitmap_or(req_wanted, new_wanted, req_wanted, NETDEV_FEATURE_COUNT);
+	if (bitmap_equal(req_wanted, old_wanted, NETDEV_FEATURE_COUNT)) {
 		ret = 0;
 		goto out_rtnl;
 	}
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net 2/3] ethtool: Account for hw_features in netlink interface
  2020-08-14 13:16 [PATCH net 0/3] ethtool-netlink bug fixes Maxim Mikityanskiy
  2020-08-14 13:16 ` [PATCH net 1/3] ethtool: Fix preserving of wanted feature bits in netlink interface Maxim Mikityanskiy
@ 2020-08-14 13:16 ` Maxim Mikityanskiy
  2020-08-14 13:16 ` [PATCH net 3/3] ethtool: Don't omit the netlink reply if no features were changed Maxim Mikityanskiy
  2020-08-14 14:58 ` [PATCH net 0/3] ethtool-netlink bug fixes Florian Fainelli
  3 siblings, 0 replies; 6+ messages in thread
From: Maxim Mikityanskiy @ 2020-08-14 13:16 UTC (permalink / raw)
  To: David S. Miller, Michal Kubecek, Andrew Lunn
  Cc: Jakub Kicinski, netdev, Maxim Mikityanskiy

ethtool-netlink ignores dev->hw_features and may confuse the drivers by
asking them to enable features not in the hw_features bitmask. For
example:

1. ethtool -k eth0
   tls-hw-tx-offload: off [fixed]
2. ethtool -K eth0 tls-hw-tx-offload on
   tls-hw-tx-offload: on
3. ethtool -k eth0
   tls-hw-tx-offload: on [fixed]

Fitler out dev->hw_features from req_wanted to fix it and to resemble
the legacy ethtool behavior.

Signed-off-by: Maxim Mikityanskiy <maximmi@mellanox.com>
---
 net/ethtool/features.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/ethtool/features.c b/net/ethtool/features.c
index ec196f0fddc9..6b288bfd7678 100644
--- a/net/ethtool/features.c
+++ b/net/ethtool/features.c
@@ -273,7 +273,8 @@ int ethnl_set_features(struct sk_buff *skb, struct genl_info *info)
 		goto out_rtnl;
 	}
 
-	dev->wanted_features = ethnl_bitmap_to_features(req_wanted);
+	dev->wanted_features &= ~dev->hw_features;
+	dev->wanted_features |= ethnl_bitmap_to_features(req_wanted) & dev->hw_features;
 	__netdev_update_features(dev);
 	ethnl_features_to_bitmap(new_active, dev->features);
 	mod = !bitmap_equal(old_active, new_active, NETDEV_FEATURE_COUNT);
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net 3/3] ethtool: Don't omit the netlink reply if no features were changed
  2020-08-14 13:16 [PATCH net 0/3] ethtool-netlink bug fixes Maxim Mikityanskiy
  2020-08-14 13:16 ` [PATCH net 1/3] ethtool: Fix preserving of wanted feature bits in netlink interface Maxim Mikityanskiy
  2020-08-14 13:16 ` [PATCH net 2/3] ethtool: Account for hw_features " Maxim Mikityanskiy
@ 2020-08-14 13:16 ` Maxim Mikityanskiy
  2020-08-14 14:58 ` [PATCH net 0/3] ethtool-netlink bug fixes Florian Fainelli
  3 siblings, 0 replies; 6+ messages in thread
From: Maxim Mikityanskiy @ 2020-08-14 13:16 UTC (permalink / raw)
  To: David S. Miller, Michal Kubecek, Andrew Lunn
  Cc: Jakub Kicinski, netdev, Maxim Mikityanskiy

The legacy ethtool userspace tool shows an error when no features could
be changed. It's useful to have a netlink reply to be able to show this
error when __netdev_update_features wasn't called, for example:

1. ethtool -k eth0
   large-receive-offload: off
2. ethtool -K eth0 rx-fcs on
3. ethtool -K eth0 lro on
   Could not change any device features
   rx-lro: off [requested on]
4. ethtool -K eth0 lro on
   # The output should be the same, but without this patch the kernel
   # doesn't send the reply, and ethtool is unable to detect the error.

This commit makes ethtool-netlink always return a reply when requested,
and it still avoids unnecessary calls to __netdev_update_features if the
wanted features haven't changed.

Signed-off-by: Maxim Mikityanskiy <maximmi@mellanox.com>
---
 net/ethtool/features.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/net/ethtool/features.c b/net/ethtool/features.c
index 6b288bfd7678..495635f152ba 100644
--- a/net/ethtool/features.c
+++ b/net/ethtool/features.c
@@ -268,14 +268,11 @@ int ethnl_set_features(struct sk_buff *skb, struct genl_info *info)
 	bitmap_and(req_wanted, req_wanted, req_mask, NETDEV_FEATURE_COUNT);
 	bitmap_andnot(new_wanted, old_wanted, req_mask, NETDEV_FEATURE_COUNT);
 	bitmap_or(req_wanted, new_wanted, req_wanted, NETDEV_FEATURE_COUNT);
-	if (bitmap_equal(req_wanted, old_wanted, NETDEV_FEATURE_COUNT)) {
-		ret = 0;
-		goto out_rtnl;
+	if (!bitmap_equal(req_wanted, old_wanted, NETDEV_FEATURE_COUNT)) {
+		dev->wanted_features &= ~dev->hw_features;
+		dev->wanted_features |= ethnl_bitmap_to_features(req_wanted) & dev->hw_features;
+		__netdev_update_features(dev);
 	}
-
-	dev->wanted_features &= ~dev->hw_features;
-	dev->wanted_features |= ethnl_bitmap_to_features(req_wanted) & dev->hw_features;
-	__netdev_update_features(dev);
 	ethnl_features_to_bitmap(new_active, dev->features);
 	mod = !bitmap_equal(old_active, new_active, NETDEV_FEATURE_COUNT);
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net 0/3] ethtool-netlink bug fixes
  2020-08-14 13:16 [PATCH net 0/3] ethtool-netlink bug fixes Maxim Mikityanskiy
                   ` (2 preceding siblings ...)
  2020-08-14 13:16 ` [PATCH net 3/3] ethtool: Don't omit the netlink reply if no features were changed Maxim Mikityanskiy
@ 2020-08-14 14:58 ` Florian Fainelli
  2020-08-15  3:45   ` David Miller
  3 siblings, 1 reply; 6+ messages in thread
From: Florian Fainelli @ 2020-08-14 14:58 UTC (permalink / raw)
  To: Maxim Mikityanskiy, David S. Miller, Michal Kubecek, Andrew Lunn
  Cc: Jakub Kicinski, netdev



On 8/14/2020 6:16 AM, Maxim Mikityanskiy wrote:
> This series contains a few bug fixes for ethtool-netlink. These bugs are
> specific for the netlink interface, and the legacy ioctl interface is
> not affected. These patches aim to have the same behavior in
> ethtool-netlink as in the legacy ethtool.
> 
> Please also see the sibling series for the userspace tool.

Since you are targeting the net tree, should not those changes also have 
corresponding Fixes tag?

Thanks

> 
> Maxim Mikityanskiy (3):
>    ethtool: Fix preserving of wanted feature bits in netlink interface
>    ethtool: Account for hw_features in netlink interface
>    ethtool: Don't omit the netlink reply if no features were changed
> 
>   net/ethtool/features.c | 19 ++++++++++---------
>   1 file changed, 10 insertions(+), 9 deletions(-)
> 

-- 
Florian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net 0/3] ethtool-netlink bug fixes
  2020-08-14 14:58 ` [PATCH net 0/3] ethtool-netlink bug fixes Florian Fainelli
@ 2020-08-15  3:45   ` David Miller
  0 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2020-08-15  3:45 UTC (permalink / raw)
  To: f.fainelli; +Cc: maximmi, mkubecek, andrew, kuba, netdev

From: Florian Fainelli <f.fainelli@gmail.com>
Date: Fri, 14 Aug 2020 07:58:29 -0700

> 
> 
> On 8/14/2020 6:16 AM, Maxim Mikityanskiy wrote:
>> This series contains a few bug fixes for ethtool-netlink. These bugs
>> are
>> specific for the netlink interface, and the legacy ioctl interface is
>> not affected. These patches aim to have the same behavior in
>> ethtool-netlink as in the legacy ethtool.
>> Please also see the sibling series for the userspace tool.
> 
> Since you are targeting the net tree, should not those changes also
> have corresponding Fixes tag?

Yes, they definitely should.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-08-15 22:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-14 13:16 [PATCH net 0/3] ethtool-netlink bug fixes Maxim Mikityanskiy
2020-08-14 13:16 ` [PATCH net 1/3] ethtool: Fix preserving of wanted feature bits in netlink interface Maxim Mikityanskiy
2020-08-14 13:16 ` [PATCH net 2/3] ethtool: Account for hw_features " Maxim Mikityanskiy
2020-08-14 13:16 ` [PATCH net 3/3] ethtool: Don't omit the netlink reply if no features were changed Maxim Mikityanskiy
2020-08-14 14:58 ` [PATCH net 0/3] ethtool-netlink bug fixes Florian Fainelli
2020-08-15  3:45   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).