[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8c9704c0-532e-4d35-a073-bee771cd78c5@intel.com>
Date: Thu, 12 Oct 2023 17:24:41 -0700
From: "Nambiar, Amritha" <amritha.nambiar@...el.com>
To: Jakub Kicinski <kuba@...nel.org>
CC: <netdev@...r.kernel.org>, <sridhar.samudrala@...el.com>
Subject: Re: [net-next PATCH v4 04/10] netdev-genl: Add netlink framework
functions for queue
On 10/12/2023 4:48 PM, Jakub Kicinski wrote:
> On Wed, 11 Oct 2023 16:54:00 -0700 Nambiar, Amritha wrote:
>>>> +static int netdev_nl_queue_validate(struct net_device *netdev, u32 q_id,
>>>> + u32 q_type)
>>>> +{
>>>> + switch (q_type) {
>>>> + case NETDEV_QUEUE_TYPE_RX:
>>>> + if (q_id >= netdev->real_num_rx_queues)
>>>> + return -EINVAL;
>>>> + return 0;
>>>> + case NETDEV_QUEUE_TYPE_TX:
>>>> + if (q_id >= netdev->real_num_tx_queues)
>>>> + return -EINVAL;
>>>> + return 0;
>>>> + default:
>>>> + return -EOPNOTSUPP;
>>>
>>> Doesn't the netlink policy prevent this already?
>>
>> For this, should I be using "checks: max:" as an attribute property for
>> the 'queue-id' attribute in the yaml. If so, not sure how I can give a
>> custom value (not hard-coded) for max.
>> Or should I include a pre-doit hook.
>
> Weird, I was convinced that if you specify enum by default the code gen
> will automatically generate the range check to make sure that the value
> is within the enum..
>
> Looks like it does, this is the policy, right?
>
> +static const struct nla_policy netdev_queue_get_do_nl_policy[NETDEV_A_QUEUE_QUEUE_TYPE + 1] = {
> + [NETDEV_A_QUEUE_IFINDEX] = NLA_POLICY_MIN(NLA_U32, 1),
> + [NETDEV_A_QUEUE_QUEUE_TYPE] = NLA_POLICY_MAX(NLA_U32, 1),
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Yes, this is the policy. This policy does validate that the max value
for 'queue-type' is within the enum range.
I was thinking your review comment was for the entire
'netdev_nl_queue_validate' function (i.e. if the max queue-id validation
can be handled in the policy as a range with max value for queue-id, and
since max queue-id was not a constant, but varies within the kernel, ex:
netdev->real_num_rx_queues, I was unsure of it...). So, another option I
could come up with for the validation was a 'pre_doit' hook instead of
netdev_nl_queue_validate().
If your comment referred to the enum queue-type range alone, I see,
since the policy handles the max check for queue-type, I can remove the
default case returning EOPNOTSUPP. Correct me if I'm wrong.
Powered by blists - more mailing lists