Skip to contentSkip to conversation

ethtool: fix ethtool msg len calculation for pause stats

PATCH Superseded Jakub Kicinski 2 participants 4 messages Nov 2, 2021

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 ethtool: fix ethtool msg len calculation for pause stats

ETHTOOL_A_PAUSE_STAT_MAX is the MAX attribute id, so we need to subtract non-stats and add one to get a count (IOW -2+1 == -1).

Otherwise we'll see:

ethnl cmd 21: calculated reply length 40, but consumed 52

Fixes 9a27a33027f2 ("ethtool: add standard pause stats")
---
 net/ethtool/pause.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ethtool/pause.c +1 -1
index 9009f412151e..c9171234130b 100644
@@ -57,7 +57,7 @@ static int pause_reply_size(const struct ethnl_req_info *req_base,
 	if (req_base->flags & ETHTOOL_FLAG_STATS)
 		n += nla_total_size(0) +	/* _PAUSE_STATS */
 			nla_total_size_64bit(sizeof(u64)) *
-				(ETHTOOL_A_PAUSE_STAT_MAX - 2);
+				(ETHTOOL_A_PAUSE_STAT_MAX - 1);
 	return n;
 }
 
Signature · 1 line
2.31.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Jakub Kicinski

ETHTOOL_A_PAUSE_STAT_MAX is the MAX attribute id, so we need to subtract non-stats and add one to get a count (IOW -2+1 == -1).

Otherwise we'll see:

  ethnl cmd 21: calculated reply length 40, but consumed 52

Fixes 9a27a33027f2 ("ethtool: add standard pause stats")
Quoted 11 lines

---
 net/ethtool/pause.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
net/ethtool/pause.c +0 -0
index 9009f412151e..c9171234130b 100644
@@ -57,7 +57,7 @@ static int pause_reply_size(const struct
 ethnl_req_info *req_base,
         if (req_base->flags & ETHTOOL_FLAG_STATS)
Quoted 4 lines

                n += nla_total_size(0) +        /* _PAUSE_STATS */ nla_total_size_64bit(sizeof(u64)) * -                               (ETHTOOL_A_PAUSE_STAT_MAX - 2); +                               (ETHTOOL_A_PAUSE_STAT_MAX - 1);

Maybe for net-next we can improve readability here.
Just by staring at these lines, you'd think that this should've been (ETHTOOL_A_PAUSE_STAT_MAX + 1), or even better, just (ETHTOOL_A_PAUSE_STAT_CNT) /* Count of only stats */

maybe we need to separate stats from non-stats, or define ETHTOOL_A_PAUSE_STAT_CNT where it needs to be defined.

author maintainer
#2 lore raw
Quoted 17 lines · On Tue, 2 Nov 2021 16:08:52 +0000 Saeed Mahameed wrote:
Quoted 11 lines
net/ethtool/pause.c +0 -0
index 9009f412151e..c9171234130b 100644
@@ -57,7 +57,7 @@ static int pause_reply_size(const struct
 ethnl_req_info *req_base,
         if (req_base->flags & ETHTOOL_FLAG_STATS)

                n += nla_total_size(0) +        /* _PAUSE_STATS */ nla_total_size_64bit(sizeof(u64)) * -                               (ETHTOOL_A_PAUSE_STAT_MAX - 2); +                               (ETHTOOL_A_PAUSE_STAT_MAX - 1);

Maybe for net-next we can improve readability here.
Just by staring at these lines, you'd think that this should've been (ETHTOOL_A_PAUSE_STAT_MAX + 1), or even better, just (ETHTOOL_A_PAUSE_STAT_CNT) /* Count of only stats */

Quoted 2 lines

maybe we need to separate stats from non-stats, or define ETHTOOL_A_PAUSE_STAT_CNT where it needs to be defined.

Fair point, something like this?

+++ b/include/uapi/linux/ethtool_netlink.h
@@ -411,10 +411,14 @@ enum {
ETHTOOL_A_PAUSE_STAT_TX_FRAMES,
ETHTOOL_A_PAUSE_STAT_RX_FRAMES,

- /* add new constants above here */
+ /* add new constants above here
+ * adjust ETHTOOL_PAUSE_STAT_CNT if adding non-stats!
+ */

        __ETHTOOL_A_PAUSE_STAT_CNT,
        ETHTOOL_A_PAUSE_STAT_MAX = (__ETHTOOL_A_PAUSE_STAT_CNT - 1)

};
+#define ETHTOOL_PAUSE_STAT_CNT (__ETHTOOL_A_PAUSE_STAT_CNT - \
+ ETHTOOL_A_PAUSE_STAT_TX_FRAMES)

/* EEE */

#3 lore raw
Quoted 2 lines · Jakub Kicinski
Quoted 1 line · On Tue, 2 Nov 2021 16:08:52 +0000 Saeed Mahameed wrote:
Quoted 1 line

...

Quoted 6 lines
Quoted 3 lines

maybe we need to separate stats from non-stats, or define ETHTOOL_A_PAUSE_STAT_CNT where it needs to be defined.

Fair point, something like this?

LGTM

Quoted 19 lines

+++ b/include/uapi/linux/ethtool_netlink.h

(quoted diff) +0 -0
@@ -411,10 +411,14 @@ enum {
         ETHTOOL_A_PAUSE_STAT_TX_FRAMES,
         ETHTOOL_A_PAUSE_STAT_RX_FRAMES,


-       /* add new constants above here */
+       /* add new constants above here
+        * adjust ETHTOOL_PAUSE_STAT_CNT if adding non-stats! +        */
        __ETHTOOL_A_PAUSE_STAT_CNT, ETHTOOL_A_PAUSE_STAT_MAX = (__ETHTOOL_A_PAUSE_STAT_CNT - 1) };
+#define ETHTOOL_PAUSE_STAT_CNT (__ETHTOOL_A_PAUSE_STAT_CNT - \
+                                ETHTOOL_A_PAUSE_STAT_TX_FRAMES)
 /* EEE */