Skip to content

Commit 6597e8d

Browse files
jdamato-fslykuba-moo
authored andcommitted
netdev-genl: Elide napi_id when not present
There are at least two cases where napi_id may not present and the napi_id should be elided: 1. Queues could be created, but napi_enable may not have been called yet. In this case, there may be a NAPI but it may not have an ID and output of a napi_id should be elided. 2. TX-only NAPIs currently do not have NAPI IDs. If a TX queue happens to be linked with a TX-only NAPI, elide the NAPI ID from the netlink output as a NAPI ID of 0 is not useful for users. Signed-off-by: Joe Damato <[email protected]> Reviewed-by: Sridhar Samudrala <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 71f0dd5 commit 6597e8d

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

include/net/busy_poll.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
*/
2525
#define MIN_NAPI_ID ((unsigned int)(NR_CPUS + 1))
2626

27+
static inline bool napi_id_valid(unsigned int napi_id)
28+
{
29+
return napi_id >= MIN_NAPI_ID;
30+
}
31+
2732
#define BUSY_POLL_BUDGET 8
2833

2934
#ifdef CONFIG_NET_RX_BUSY_POLL

net/core/netdev-genl.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,13 @@ int netdev_nl_napi_set_doit(struct sk_buff *skb, struct genl_info *info)
365365
return err;
366366
}
367367

368+
static int nla_put_napi_id(struct sk_buff *skb, const struct napi_struct *napi)
369+
{
370+
if (napi && napi_id_valid(napi->napi_id))
371+
return nla_put_u32(skb, NETDEV_A_QUEUE_NAPI_ID, napi->napi_id);
372+
return 0;
373+
}
374+
368375
static int
369376
netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev,
370377
u32 q_idx, u32 q_type, const struct genl_info *info)
@@ -386,9 +393,7 @@ netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev,
386393
switch (q_type) {
387394
case NETDEV_QUEUE_TYPE_RX:
388395
rxq = __netif_get_rx_queue(netdev, q_idx);
389-
390-
if (rxq->napi && nla_put_u32(rsp, NETDEV_A_QUEUE_NAPI_ID,
391-
rxq->napi->napi_id))
396+
if (nla_put_napi_id(rsp, rxq->napi))
392397
goto nla_put_failure;
393398

394399
params = &rxq->mp_params;
@@ -398,8 +403,7 @@ netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev,
398403
break;
399404
case NETDEV_QUEUE_TYPE_TX:
400405
txq = netdev_get_tx_queue(netdev, q_idx);
401-
if (txq->napi && nla_put_u32(rsp, NETDEV_A_QUEUE_NAPI_ID,
402-
txq->napi->napi_id))
406+
if (nla_put_napi_id(rsp, txq->napi))
403407
goto nla_put_failure;
404408
}
405409

0 commit comments

Comments
 (0)