netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: Jakub Kicinski <kuba@kernel.org>
Cc: netdev@vger.kernel.org, pabeni@redhat.com, davem@davemloft.net,
	edumazet@google.com, moshe@nvidia.com, saeedm@nvidia.com,
	idosch@nvidia.com, petrm@nvidia.com
Subject: Re: [patch net-next v2 10/11] devlink: introduce dump selector attr and use it for per-instance dumps
Date: Mon, 31 Jul 2023 14:47:08 +0200	[thread overview]
Message-ID: <ZMetTPCZ59rVLNyQ@nanopsycho> (raw)
In-Reply-To: <20230725114044.402450df@kernel.org>

Tue, Jul 25, 2023 at 08:40:44PM CEST, kuba@kernel.org wrote:
>On Thu, 20 Jul 2023 14:18:28 +0200 Jiri Pirko wrote:
>> +static void devlink_nl_policy_cpy(struct nla_policy *policy, unsigned int attr)
>> +{
>> +	memcpy(&policy[attr], &devlink_nl_policy[attr], sizeof(*policy));
>> +}
>> +
>> +static void devlink_nl_dump_selector_policy_init(const struct devlink_cmd *cmd,
>> +						 struct nla_policy *policy)
>> +{
>> +	devlink_nl_policy_cpy(policy, DEVLINK_ATTR_BUS_NAME);
>> +	devlink_nl_policy_cpy(policy, DEVLINK_ATTR_DEV_NAME);
>> +}
>> +
>> +static int devlink_nl_start(struct netlink_callback *cb)
>> +{
>> +	struct devlink_nl_dump_state *state = devlink_dump_state(cb);
>> +	const struct genl_dumpit_info *info = genl_dumpit_info(cb);
>> +	struct nlattr **attrs = info->attrs;
>> +	const struct devlink_cmd *cmd;
>> +	struct nla_policy *policy;
>> +	struct nlattr **selector;
>> +	int err;
>> +
>> +	if (!attrs[DEVLINK_ATTR_DUMP_SELECTOR])
>> +		return 0;
>> +
>> +	selector = kzalloc(sizeof(*selector) * (DEVLINK_ATTR_MAX + 1),
>> +			   GFP_KERNEL);
>> +	if (!selector)
>> +		return -ENOMEM;
>> +	policy = kzalloc(sizeof(*policy) * (DEVLINK_ATTR_MAX + 1), GFP_KERNEL);
>> +	if (!policy) {
>> +		kfree(selector);
>> +		return -ENOMEM;
>> +	}
>> +
>> +	cmd = devl_cmds[info->op.cmd];
>> +	devlink_nl_dump_selector_policy_init(cmd, policy);
>> +	err = nla_parse_nested(selector, DEVLINK_ATTR_MAX,
>> +			       attrs[DEVLINK_ATTR_DUMP_SELECTOR],
>> +			       policy, cb->extack);
>> +	kfree(policy);
>> +	if (err) {
>> +		kfree(selector);
>> +		return err;
>> +	}
>> +
>> +	state->selector = selector;
>> +	return 0;
>> +}
>
>Why not declare a fully nested policy with just the two attrs?

Not sure I follow. But the nest under DEVLINK_ATTR_DUMP_SELECTOR has
its own policy, generated by devlink_nl_dump_selector_policy_init(). I
did it this way instead of separate policy array for 2 reasons:
1) We don't have duplicate and possibly conflicting policies for devlink
   root and selector
2) It is easy for specific object type to pass attrs that are included
   in the policy initialization (see the health reporter extension later
   in this patchset). There are couple of object to benefit from this,
   for example "sb".
3) It is I think a bit nicer for specific object type to pass array of
   attrs, instead of a policy array that would be exported from netlink.c

If you insist on separate policy arrays, I can do it though. I had it
like that initially, I just decided to go this way for the 3 reasons
listed above.


>
>Also - do you know of any userspace which would pass garbage attrs 
>to the dumps? Do we really need to accept all attributes, or can
>we trim the dump policies to what's actually supported?

That's what this patch is doing. It only accepts what the kernel
understands. It gives the object types (as for example health reporter)
option to extend the attr set to accept them into selectors as well, if
they know how to handle them.


>-- 
>pw-bot: cr

  reply	other threads:[~2023-07-31 12:47 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-20 12:18 [patch net-next v2 00/11] devlink: introduce dump selector attr and use it for per-instance dumps Jiri Pirko
2023-07-20 12:18 ` [patch net-next v2 01/11] devlink: parse linecard attr in doit() callbacks Jiri Pirko
2023-07-20 12:18 ` [patch net-next v2 02/11] devlink: parse rate attrs " Jiri Pirko
2023-07-20 12:18 ` [patch net-next v2 03/11] devlink: introduce __devlink_nl_pre_doit() with internal flags as function arg Jiri Pirko
2023-07-20 12:18 ` [patch net-next v2 04/11] devlink: convert port get command to split ops Jiri Pirko
2023-07-20 12:18 ` [patch net-next v2 05/11] devlink: convert health reporter " Jiri Pirko
2023-07-20 12:18 ` [patch net-next v2 06/11] devlink: convert param " Jiri Pirko
2023-07-20 12:18 ` [patch net-next v2 07/11] devlink: convert trap " Jiri Pirko
2023-07-20 12:18 ` [patch net-next v2 08/11] devlink: introduce set of macros and use it for split ops definitions Jiri Pirko
2023-07-25 17:38   ` Jakub Kicinski
2023-07-31 12:21     ` Jiri Pirko
2023-07-31 16:57       ` Jakub Kicinski
2023-08-01  6:41         ` Jiri Pirko
2023-07-20 12:18 ` [patch net-next v2 09/11] devlink: convert rest of the iterator dumpit commands to split ops Jiri Pirko
2023-07-20 12:18 ` [patch net-next v2 10/11] devlink: introduce dump selector attr and use it for per-instance dumps Jiri Pirko
2023-07-25 18:40   ` Jakub Kicinski
2023-07-31 12:47     ` Jiri Pirko [this message]
2023-07-31 17:03       ` Jakub Kicinski
2023-08-01  6:42         ` Jiri Pirko
2023-08-01 15:53           ` Jakub Kicinski
2023-08-02  7:02             ` Jiri Pirko
2023-07-20 12:18 ` [patch net-next v2 11/11] devlink: extend health reporter dump selector by port index Jiri Pirko
2023-07-25 18:48   ` Jakub Kicinski
2023-07-31 12:52     ` Jiri Pirko
2023-07-31 17:06       ` Jakub Kicinski
2023-08-01  6:49         ` Jiri Pirko
2023-08-01 15:56           ` Jakub Kicinski
2023-08-02  7:04             ` Jiri Pirko
2023-07-20 13:55 ` [patch net-next v2 00/11] devlink: introduce dump selector attr and use it for per-instance dumps Petr Machata
2023-07-20 14:27   ` Jiri Pirko
2023-07-20 14:51     ` Petr Machata
2023-07-25  8:07 ` Jiri Pirko
2023-07-25  8:36   ` Paolo Abeni
2023-07-25 15:29     ` Jiri Pirko
2023-07-25 16:39       ` Paolo Abeni

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=ZMetTPCZ59rVLNyQ@nanopsycho \
    --to=jiri@resnulli.us \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=moshe@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=petrm@nvidia.com \
    --cc=saeedm@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).