netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nambiar, Amritha" <amritha.nambiar@intel.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: <netdev@vger.kernel.org>, <sridhar.samudrala@intel.com>
Subject: Re: [net-next PATCH v4 04/10] netdev-genl: Add netlink framework functions for queue
Date: Wed, 11 Oct 2023 16:54:00 -0700	[thread overview]
Message-ID: <fe26f9b6-ff3d-441d-887d-9f65d44f06d0@intel.com> (raw)
In-Reply-To: <20231010192555.3126ca42@kernel.org>



On 10/10/2023 7:25 PM, Jakub Kicinski wrote:
> On Fri, 06 Oct 2023 02:14:59 -0700 Amritha Nambiar wrote:
>> +static int
>> +netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev,
>> +			 u32 q_idx, u32 q_type, const struct genl_info *info)
>> +{
>> +	struct netdev_rx_queue *rxq;
>> +	struct netdev_queue *txq;
>> +	void *hdr;
>> +
>> +	hdr = genlmsg_iput(rsp, info);
>> +	if (!hdr)
>> +		return -EMSGSIZE;
>> +
>> +	if (nla_put_u32(rsp, NETDEV_A_QUEUE_QUEUE_ID, q_idx))
>> +		goto nla_put_failure;
>> +
>> +	if (nla_put_u32(rsp, NETDEV_A_QUEUE_QUEUE_TYPE, q_type))
>> +		goto nla_put_failure;
>> +
>> +	if (nla_put_u32(rsp, NETDEV_A_QUEUE_IFINDEX, netdev->ifindex))
>> +		goto nla_put_failure;
> 
> You can combine these ifs in a single one using ||
> 
Okay, will fix in v5.

>> +	switch (q_type) {
>> +	case NETDEV_QUEUE_TYPE_RX:
>> +		rxq = __netif_get_rx_queue(netdev, q_idx);
>> +		if (rxq->napi && nla_put_u32(rsp, NETDEV_A_QUEUE_NAPI_ID,
> 
>> +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.

> 
>> +	}
>> +}
> 
>>   int netdev_nl_queue_get_doit(struct sk_buff *skb, struct genl_info *info)
>>   {
>> -	return -EOPNOTSUPP;
>> +	u32 q_id, q_type, ifindex;
>> +	struct net_device *netdev;
>> +	struct sk_buff *rsp;
>> +	int err;
>> +
>> +	if (GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_QUEUE_ID))
>> +		return -EINVAL;
>> +
>> +	if (GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_QUEUE_TYPE))
>> +		return -EINVAL;
>> +
>> +	if (GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFINDEX))
>> +		return -EINVAL;
> 
> You can combine these checks in a single if using ||

Will fix in v5.

> 
>> +	q_id = nla_get_u32(info->attrs[NETDEV_A_QUEUE_QUEUE_ID]);
>> +
>> +	q_type = nla_get_u32(info->attrs[NETDEV_A_QUEUE_QUEUE_TYPE]);
>> +
>> +	ifindex = nla_get_u32(info->attrs[NETDEV_A_QUEUE_IFINDEX]);
> 
> No need for the empty lines between these.

Will fix.

> 
>> +	rsp = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
>> +	if (!rsp)
>> +		return -ENOMEM;
>> +
>> +	rtnl_lock();
>> +
>> +	netdev = __dev_get_by_index(genl_info_net(info), ifindex);
>> +	if (netdev)
>> +		err  = netdev_nl_queue_fill(rsp, netdev, q_id, q_type, info);
> 
> double space after =

Will fix.

> 
>> +	else
>> +		err = -ENODEV;
>> +
>> +	rtnl_unlock();
>> +
>> +	if (err)
>> +		goto err_free_msg;
>> +
>> +	return genlmsg_reply(rsp, info);
>> +
>> +err_free_msg:
>> +	nlmsg_free(rsp);
>> +	return err;
>> +}
>> +
>> +static int
>> +netdev_nl_queue_dump_one(struct net_device *netdev, struct sk_buff *rsp,
>> +			 const struct genl_info *info, unsigned int *start_rx,
>> +			 unsigned int *start_tx)
>> +{
> 
> Hm. Not sure why you don't operate directly on ctx here.
> Why pass the indexes by pointer individually?
> 

Makes sense. Will fix in v5.

>> +	int err = 0;
>> +	int i;
>> +
>> +	for (i = *start_rx; i < netdev->real_num_rx_queues;) {
>> +		err = netdev_nl_queue_fill_one(rsp, netdev, i,
>> +					       NETDEV_QUEUE_TYPE_RX, info);
>> +		if (err)
>> +			goto out_err;
> 
> return, no need to goto if all it does is returns

Will fix.

> 
>> +		*start_rx = i++;
>> +	}
>> +	for (i = *start_tx; i < netdev->real_num_tx_queues;) {
>> +		err = netdev_nl_queue_fill_one(rsp, netdev, i,
>> +					       NETDEV_QUEUE_TYPE_TX, info);
>> +		if (err)
>> +			goto out_err;
>> +		*start_tx = i++;
>> +	}
>> +out_err:
>> +	return err;
>>   }
>>   
>>   int netdev_nl_queue_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
>>   {
>> -	return -EOPNOTSUPP;
>> +	struct netdev_nl_dump_ctx *ctx = netdev_dump_ctx(cb);
>> +	const struct genl_info *info = genl_info_dump(cb);
>> +	struct net *net = sock_net(skb->sk);
>> +	unsigned int rxq_idx = ctx->rxq_idx;
>> +	unsigned int txq_idx = ctx->txq_idx;
>> +	struct net_device *netdev;
>> +	u32 ifindex = 0;
>> +	int err = 0;
>> +
>> +	if (info->attrs[NETDEV_A_QUEUE_IFINDEX])
>> +		ifindex = nla_get_u32(info->attrs[NETDEV_A_QUEUE_IFINDEX]);
>> +
>> +	rtnl_lock();
>> +	if (ifindex) {
>> +		netdev = __dev_get_by_index(net, ifindex);
>> +		if (netdev)
>> +			err = netdev_nl_queue_dump_one(netdev, skb, info,
>> +						       &rxq_idx, &txq_idx);
>> +		else
>> +			err = -ENODEV;
>> +	} else {
>> +		for_each_netdev_dump(net, netdev, ctx->ifindex) {
>> +			err = netdev_nl_queue_dump_one(netdev, skb, info,
>> +						       &rxq_idx, &txq_idx);
>> +
> 
> unnecessary new line

Will fix.

> 
>> +			if (err < 0)
>> +				break;
>> +			if (!err) {
> 
> it only returns 0 or negative errno, doesn't it?
> 
Will fix in v5.

>> +				rxq_idx = 0;
>> +				txq_idx = 0;
>> +			}
>> +		}
>> +	}
>> +	rtnl_unlock();
>> +
>> +	if (err != -EMSGSIZE)
>> +		return err;
>> +
>> +	ctx->rxq_idx = rxq_idx;
>> +	ctx->txq_idx = txq_idx;
>> +	return skb->len;
>>   }
>>   
>>   static int netdev_genl_netdevice_event(struct notifier_block *nb,
>>
> 
> 

  reply	other threads:[~2023-10-11 23:54 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-06  9:14 [net-next PATCH v4 00/10] Introduce queue and NAPI support in netdev-genl (Was: Introduce NAPI queues support) Amritha Nambiar
2023-10-06  9:14 ` [net-next PATCH v4 01/10] netdev-genl: spec: Extend netdev netlink spec in YAML for queue Amritha Nambiar
2023-10-11  2:12   ` Jakub Kicinski
2023-10-11 23:28     ` Nambiar, Amritha
2023-10-06  9:14 ` [net-next PATCH v4 02/10] net: Add queue and napi association Amritha Nambiar
2023-10-11  2:17   ` Jakub Kicinski
2023-10-11 23:36     ` Nambiar, Amritha
2023-10-06  9:14 ` [net-next PATCH v4 03/10] ice: Add support in the driver for associating queue with napi Amritha Nambiar
2023-10-06  9:14 ` [net-next PATCH v4 04/10] netdev-genl: Add netlink framework functions for queue Amritha Nambiar
2023-10-11  2:25   ` Jakub Kicinski
2023-10-11 23:54     ` Nambiar, Amritha [this message]
2023-10-12 23:48       ` Jakub Kicinski
2023-10-13  0:24         ` Nambiar, Amritha
2023-10-13  0:36           ` Jakub Kicinski
2023-10-13  0:40             ` Nambiar, Amritha
2023-10-13  0:44             ` Jakub Kicinski
2023-10-06  9:15 ` [net-next PATCH v4 05/10] netdev-genl: spec: Extend netdev netlink spec in YAML for NAPI Amritha Nambiar
2023-10-06  9:15 ` [net-next PATCH v4 06/10] netdev-genl: Add netlink framework functions for napi Amritha Nambiar
2023-10-11  2:29   ` Jakub Kicinski
2023-10-11 23:55     ` Nambiar, Amritha
2023-10-06  9:15 ` [net-next PATCH v4 07/10] netdev-genl: spec: Add irq in netdev netlink YAML spec Amritha Nambiar
2023-10-06  9:15 ` [net-next PATCH v4 08/10] net: Add NAPI IRQ support Amritha Nambiar
2023-10-06  9:15 ` [net-next PATCH v4 09/10] netdev-genl: spec: Add PID in netdev netlink YAML spec Amritha Nambiar
2023-10-06  9:15 ` [net-next PATCH v4 10/10] netdev-genl: Add PID for the NAPI thread Amritha Nambiar

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=fe26f9b6-ff3d-441d-887d-9f65d44f06d0@intel.com \
    --to=amritha.nambiar@intel.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sridhar.samudrala@intel.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).