Subject: Re: [PATCH net] netlink: Correct offload_xstats size

From: Petr Machata <[email-masked]>
Date: Fri, 13 Oct 2023 14:43:05 +0200

Christoph Paasch <[email-masked]> writes:

> rtnl_offload_xstats_get_size_hw_s_info_one() conditionalizes the
> size-computation for IFLA_OFFLOAD_XSTATS_HW_S_INFO_USED based on whether
> or not the device has offload_xstats enabled.
>
> However, rtnl_offload_xstats_fill_hw_s_info_one() is adding the u8 for
> that field uncondtionally.

> Which didn't happen prior to commit bf9f1baa279f ("net: add dedicated
> kmem_cache for typical/small skb->head") as the skb always was large
> enough.
>
> Cc: Petr Machata <[email-masked]>
> Cc: Eric Dumazet <[email-masked]>
> Fixes: 0e7788fd7622 ("net: rtnetlink: Add UAPI for obtaining L3 offload xstats")
> Signed-off-by: Christoph Paasch <[email-masked]>
> ---
>
> Notes:
>     Another fix would be to make rtnl_offload_xstats_fill_hw_s_info_one()
>     check whether the device has offload_xstats enabled. Let me know if that
>     is a preferred route.

I think I decided that it's going to be useful to get the info always,
but then neglected to update the size computation. So this fix looks
good to me. Also, it maintains the same behavior as before, minus the
size computation bug.

Reviewed-by: Petr Machata <[email-masked]>

>
>  net/core/rtnetlink.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
> index 4a2ec33bfb51..53c377d054f0 100644
> --- a/net/core/rtnetlink.c
> +++ b/net/core/rtnetlink.c
> @@ -5503,13 +5503,11 @@ static unsigned int
>  rtnl_offload_xstats_get_size_hw_s_info_one(const struct net_device *dev,
>  					   enum netdev_offload_xstats_type type)
>  {
> -	bool enabled = netdev_offload_xstats_enabled(dev, type);
> -
>  	return nla_total_size(0) +
>  		/* IFLA_OFFLOAD_XSTATS_HW_S_INFO_REQUEST */
>  		nla_total_size(sizeof(u8)) +
>  		/* IFLA_OFFLOAD_XSTATS_HW_S_INFO_USED */
> -		(enabled ? nla_total_size(sizeof(u8)) : 0) +
> +		nla_total_size(sizeof(u8)) +
>  		0;
>  }