* [PATCH net v2] ethtool: fix ethtool msg len calculation for pause stats
@ 2021-11-02 22:02 Jakub Kicinski
2021-11-03 3:34 ` Saeed Mahameed
2021-11-03 14:10 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Jakub Kicinski @ 2021-11-02 22:02 UTC (permalink / raw)
To: davem; +Cc: netdev, saeedm, mkubecek, andrew, 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")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
v2: add a define
include/linux/ethtool_netlink.h | 3 +++
include/uapi/linux/ethtool_netlink.h | 4 +++-
net/ethtool/pause.c | 3 +--
3 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/include/linux/ethtool_netlink.h b/include/linux/ethtool_netlink.h
index 1e7bf78cb382..aba348d58ff6 100644
--- a/include/linux/ethtool_netlink.h
+++ b/include/linux/ethtool_netlink.h
@@ -10,6 +10,9 @@
#define __ETHTOOL_LINK_MODE_MASK_NWORDS \
DIV_ROUND_UP(__ETHTOOL_LINK_MODE_MASK_NBITS, 32)
+#define ETHTOOL_PAUSE_STAT_CNT (__ETHTOOL_A_PAUSE_STAT_CNT - \
+ ETHTOOL_A_PAUSE_STAT_TX_FRAMES)
+
enum ethtool_multicast_groups {
ETHNL_MCGRP_MONITOR,
};
diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h
index ca5fbb59fa42..999777d32dcf 100644
--- a/include/uapi/linux/ethtool_netlink.h
+++ b/include/uapi/linux/ethtool_netlink.h
@@ -411,7 +411,9 @@ 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)
};
diff --git a/net/ethtool/pause.c b/net/ethtool/pause.c
index 9009f412151e..ee1e5806bc93 100644
--- a/net/ethtool/pause.c
+++ b/net/ethtool/pause.c
@@ -56,8 +56,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);
+ nla_total_size_64bit(sizeof(u64)) * ETHTOOL_PAUSE_STAT_CNT;
return n;
}
--
2.31.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] ethtool: fix ethtool msg len calculation for pause stats
2021-11-02 22:02 [PATCH net v2] ethtool: fix ethtool msg len calculation for pause stats Jakub Kicinski
@ 2021-11-03 3:34 ` Saeed Mahameed
2021-11-03 14:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Saeed Mahameed @ 2021-11-03 3:34 UTC (permalink / raw)
To: kuba, davem; +Cc: mkubecek, netdev, andrew
On Tue, 2021-11-02 at 15:02 -0700, Jakub Kicinski wrote:
> 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")
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Saeed Mahameed <saeedm@nvidia.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] ethtool: fix ethtool msg len calculation for pause stats
2021-11-02 22:02 [PATCH net v2] ethtool: fix ethtool msg len calculation for pause stats Jakub Kicinski
2021-11-03 3:34 ` Saeed Mahameed
@ 2021-11-03 14:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-11-03 14:10 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: davem, netdev, saeedm, mkubecek, andrew
Hello:
This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:
On Tue, 2 Nov 2021 15:02:36 -0700 you wrote:
> 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
>
> [...]
Here is the summary with links:
- [net,v2] ethtool: fix ethtool msg len calculation for pause stats
https://git.kernel.org/netdev/net/c/1aabe578dd86
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-03 14:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-02 22:02 [PATCH net v2] ethtool: fix ethtool msg len calculation for pause stats Jakub Kicinski
2021-11-03 3:34 ` Saeed Mahameed
2021-11-03 14:10 ` patchwork-bot+netdevbpf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.