* [PATCH net] ethtool: fix ethtool msg len calculation for pause stats
@ 2021-11-02 4:21 Jakub Kicinski
2021-11-02 16:08 ` Saeed Mahameed
0 siblings, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2021-11-02 4:21 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>
---
net/ethtool/pause.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ethtool/pause.c b/net/ethtool/pause.c
index 9009f412151e..c9171234130b 100644
--- a/net/ethtool/pause.c
+++ b/net/ethtool/pause.c
@@ -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;
}
--
2.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net] ethtool: fix ethtool msg len calculation for pause stats
2021-11-02 4:21 [PATCH net] ethtool: fix ethtool msg len calculation for pause stats Jakub Kicinski
@ 2021-11-02 16:08 ` Saeed Mahameed
2021-11-02 18:10 ` Jakub Kicinski
0 siblings, 1 reply; 4+ messages in thread
From: Saeed Mahameed @ 2021-11-02 16:08 UTC (permalink / raw)
To: kuba, davem; +Cc: mkubecek, netdev, andrew
On Mon, 2021-11-01 at 21:21 -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>
> ---
> net/ethtool/pause.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/ethtool/pause.c b/net/ethtool/pause.c
> index 9009f412151e..c9171234130b 100644
> --- a/net/ethtool/pause.c
> +++ b/net/ethtool/pause.c
> @@ -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 */
maybe we need to separate stats from non-stats, or define
ETHTOOL_A_PAUSE_STAT_CNT where it needs to be defined.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] ethtool: fix ethtool msg len calculation for pause stats
2021-11-02 16:08 ` Saeed Mahameed
@ 2021-11-02 18:10 ` Jakub Kicinski
2021-11-02 20:41 ` Saeed Mahameed
0 siblings, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2021-11-02 18:10 UTC (permalink / raw)
To: Saeed Mahameed; +Cc: davem, mkubecek, netdev, andrew
On Tue, 2 Nov 2021 16:08:52 +0000 Saeed Mahameed wrote:
> > diff --git a/net/ethtool/pause.c b/net/ethtool/pause.c
> > index 9009f412151e..c9171234130b 100644
> > --- a/net/ethtool/pause.c
> > +++ b/net/ethtool/pause.c
> > @@ -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 */
>
> 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 */
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] ethtool: fix ethtool msg len calculation for pause stats
2021-11-02 18:10 ` Jakub Kicinski
@ 2021-11-02 20:41 ` Saeed Mahameed
0 siblings, 0 replies; 4+ messages in thread
From: Saeed Mahameed @ 2021-11-02 20:41 UTC (permalink / raw)
To: kuba; +Cc: mkubecek, davem, netdev, andrew
On Tue, 2021-11-02 at 11:10 -0700, Jakub Kicinski wrote:
> On Tue, 2 Nov 2021 16:08:52 +0000 Saeed Mahameed wrote:
> > >
...
> >
> > 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
> +++ 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 */
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-11-02 20:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-02 4:21 [PATCH net] ethtool: fix ethtool msg len calculation for pause stats Jakub Kicinski
2021-11-02 16:08 ` Saeed Mahameed
2021-11-02 18:10 ` Jakub Kicinski
2021-11-02 20:41 ` Saeed Mahameed
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.