netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Petr Machata <petrm@nvidia.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, Ido Schimmel <idosch@nvidia.com>,
	David Ahern <dsahern@kernel.org>,
	mlxsw@nvidia.com, "Gustavo A . R . Silva" <gustavoars@kernel.org>
Subject: Re: [PATCH net-next 7/7] net: nexthop: Expose nexthop group HW stats to user space
Date: Tue, 27 Feb 2024 19:56:04 -0800	[thread overview]
Message-ID: <202402271953.18758AD3@keescook> (raw)
In-Reply-To: <001978ea519441f0295912034d00dd1af9eb5b93.1709057158.git.petrm@nvidia.com>

On Tue, Feb 27, 2024 at 07:17:32PM +0100, Petr Machata wrote:
> [...]
> diff --git a/include/net/nexthop.h b/include/net/nexthop.h
> index 20cd337b4a9c..235f94ab16a8 100644
> --- a/include/net/nexthop.h
> +++ b/include/net/nexthop.h
> [...]
> @@ -214,6 +217,17 @@ struct nh_notifier_res_table_info {
>  	struct nh_notifier_single_info nhs[] __counted_by(num_nh_buckets);
>  };
>  
> +struct nh_notifier_grp_hw_stats_entry_info {
> +	u32 id;
> +	u64 packets;
> +};
> +
> +struct nh_notifier_grp_hw_stats_info {
> +	u16 num_nh;
> +	bool hw_stats_used;
> +	struct nh_notifier_grp_hw_stats_entry_info stats[] __counted_by(num_nh);
> +};
> +
>  struct nh_notifier_info {
>  	struct net *net;
>  	struct netlink_ext_ack *extack;
> [...]
> @@ -685,8 +687,95 @@ static void nh_grp_entry_stats_read(struct nh_grp_entry *nhge,
>  	}
>  }
>  
> +static int nh_notifier_grp_hw_stats_init(struct nh_notifier_info *info,
> +					 const struct nexthop *nh)
> +{
> +	struct nh_group *nhg;
> +	int i;
> +
> +	ASSERT_RTNL();
> +	nhg = rtnl_dereference(nh->nh_grp);
> +
> +	info->id = nh->id;
> +	info->type = NH_NOTIFIER_INFO_TYPE_GRP_HW_STATS;
> +	info->nh_grp_hw_stats = kzalloc(struct_size(info->nh_grp_hw_stats,
> +						    stats, nhg->num_nh),
> +					GFP_KERNEL);
> +	if (!info->nh_grp_hw_stats)
> +		return -ENOMEM;
> +
> +	info->nh_grp_hw_stats->num_nh = nhg->num_nh;
> +	for (i = 0; i < nhg->num_nh; i++) {
> +		struct nh_grp_entry *nhge = &nhg->nh_entries[i];
> +
> +		info->nh_grp_hw_stats->stats[i].id = nhge->nh->id;
> +	}

The order of operations using __counted_by looks good to me: allocate,
assign counter (num_nh), access flex array (stats).

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

      parent reply	other threads:[~2024-02-28  3:56 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-27 18:17 [PATCH net-next 0/7] Support for nexthop group statistics Petr Machata
2024-02-27 18:17 ` [PATCH net-next 1/7] net: nexthop: Adjust netlink policy parsing for a new attribute Petr Machata
2024-02-27 18:17 ` [PATCH net-next 2/7] net: nexthop: Add NHA_OP_FLAGS Petr Machata
2024-02-28  3:34   ` Jakub Kicinski
2024-02-28 10:50     ` Petr Machata
2024-02-28 14:48       ` Jakub Kicinski
2024-02-28 15:16         ` Jakub Kicinski
2024-02-28 15:58           ` Petr Machata
2024-02-28 16:42             ` Jakub Kicinski
2024-02-29 14:03               ` Petr Machata
2024-02-27 18:17 ` [PATCH net-next 3/7] net: nexthop: Add nexthop group entry stats Petr Machata
2024-02-28 14:30   ` Simon Horman
2024-02-28 15:57     ` Petr Machata
2024-02-27 18:17 ` [PATCH net-next 4/7] net: nexthop: Expose nexthop group stats to user space Petr Machata
2024-02-28  3:35   ` Jakub Kicinski
2024-02-28 11:24     ` Petr Machata
2024-02-27 18:17 ` [PATCH net-next 5/7] net: nexthop: Add hardware statistics notifications Petr Machata
2024-02-27 18:17 ` [PATCH net-next 6/7] net: nexthop: Add ability to enable / disable hardware statistics Petr Machata
2024-02-27 18:17 ` [PATCH net-next 7/7] net: nexthop: Expose nexthop group HW stats to user space Petr Machata
2024-02-28  3:39   ` Jakub Kicinski
2024-02-28 17:16     ` Petr Machata
2024-02-28  3:56   ` Kees Cook [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202402271953.18758AD3@keescook \
    --to=keescook@chromium.org \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=gustavoars@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=mlxsw@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=petrm@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).