[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230725114044.402450df@kernel.org>
Date: Tue, 25 Jul 2023 11:40:44 -0700
From: Jakub Kicinski <kuba@...nel.org>
To: Jiri Pirko <jiri@...nulli.us>
Cc: netdev@...r.kernel.org, pabeni@...hat.com, davem@...emloft.net,
edumazet@...gle.com, moshe@...dia.com, saeedm@...dia.com,
idosch@...dia.com, petrm@...dia.com
Subject: Re: [patch net-next v2 10/11] devlink: introduce dump selector attr
and use it for per-instance dumps
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?
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?
--
pw-bot: cr
Powered by blists - more mailing lists