include/net/busy_poll.h | 5 +++++ net/core/netdev-genl.c | 13 +++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-)
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 <jdamato@fastly.com>
---
v3:
- Took Eric's suggested patch to refactor the code to use helpers,
which improves the code quality significantly.
v2: https://lore.kernel.org/netdev/20250203191714.155526-1-jdamato@fastly.com/
- Updated to elide NAPI IDs for RX queues which may have not called
napi_enable yet.
rfc: https://lore.kernel.org/lkml/20250128163038.429864-1-jdamato@fastly.com/
include/net/busy_poll.h | 5 +++++
net/core/netdev-genl.c | 13 +++++++++----
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/include/net/busy_poll.h b/include/net/busy_poll.h
index c39a426ebf52..741fa7754700 100644
--- a/include/net/busy_poll.h
+++ b/include/net/busy_poll.h
@@ -24,6 +24,11 @@
*/
#define MIN_NAPI_ID ((unsigned int)(NR_CPUS + 1))
+static inline bool napi_id_valid(unsigned int napi_id)
+{
+ return napi_id >= MIN_NAPI_ID;
+}
+
#define BUSY_POLL_BUDGET 8
#ifdef CONFIG_NET_RX_BUSY_POLL
diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c
index 715f85c6b62e..5aa3ed870b2c 100644
--- a/net/core/netdev-genl.c
+++ b/net/core/netdev-genl.c
@@ -364,6 +364,13 @@ int netdev_nl_napi_set_doit(struct sk_buff *skb, struct genl_info *info)
return err;
}
+static int nla_put_napi_id(struct sk_buff *skb, const struct napi_struct *napi)
+{
+ if (napi && napi_id_valid(napi->napi_id))
+ return nla_put_u32(skb, NETDEV_A_QUEUE_NAPI_ID, napi->napi_id);
+ return 0;
+}
+
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)
@@ -385,8 +392,7 @@ netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev,
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,
- rxq->napi->napi_id))
+ if (nla_put_napi_id(rsp, rxq->napi))
goto nla_put_failure;
binding = rxq->mp_params.mp_priv;
@@ -397,8 +403,7 @@ netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev,
break;
case NETDEV_QUEUE_TYPE_TX:
txq = netdev_get_tx_queue(netdev, q_idx);
- if (txq->napi && nla_put_u32(rsp, NETDEV_A_QUEUE_NAPI_ID,
- txq->napi->napi_id))
+ if (nla_put_napi_id(rsp, rxq->napi))
goto nla_put_failure;
}
base-commit: c2933b2befe25309f4c5cfbea0ca80909735fd76
--
2.43.0
On Tue, Feb 04, 2025 at 07:27:21PM +0000, Joe Damato wrote: > 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. [...] > binding = rxq->mp_params.mp_priv; > @@ -397,8 +403,7 @@ netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev, > break; > case NETDEV_QUEUE_TYPE_TX: > txq = netdev_get_tx_queue(netdev, q_idx); > - if (txq->napi && nla_put_u32(rsp, NETDEV_A_QUEUE_NAPI_ID, > - txq->napi->napi_id)) > + if (nla_put_napi_id(rsp, rxq->napi)) Err, looks like a typo. Sorry about that, will fix in v4. -- pw-bot: cr
Hi Joe,
kernel test robot noticed the following build warnings:
[auto build test WARNING on c2933b2befe25309f4c5cfbea0ca80909735fd76]
url: https://github.com/intel-lab-lkp/linux/commits/Joe-Damato/netdev-genl-Elide-napi_id-when-not-present/20250205-033024
base: c2933b2befe25309f4c5cfbea0ca80909735fd76
patch link: https://lore.kernel.org/r/20250204192724.199209-1-jdamato%40fastly.com
patch subject: [PATCH net-next v3] netdev-genl: Elide napi_id when not present
config: i386-buildonly-randconfig-004-20250205 (https://download.01.org/0day-ci/archive/20250205/202502051756.62x7XJ1n-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-12) 11.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250205/202502051756.62x7XJ1n-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202502051756.62x7XJ1n-lkp@intel.com/
All warnings (new ones prefixed by >>):
net/core/netdev-genl.c: In function 'netdev_nl_queue_fill_one':
>> net/core/netdev-genl.c:380:30: warning: variable 'txq' set but not used [-Wunused-but-set-variable]
380 | struct netdev_queue *txq;
| ^~~
vim +/txq +380 net/core/netdev-genl.c
4e43e696a7aeb2 Joe Damato 2025-02-04 373
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 374 static int
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 375 netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev,
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 376 u32 q_idx, u32 q_type, const struct genl_info *info)
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 377 {
d0caf9876a1c9f Mina Almasry 2024-09-10 378 struct net_devmem_dmabuf_binding *binding;
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 379 struct netdev_rx_queue *rxq;
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 @380 struct netdev_queue *txq;
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 381 void *hdr;
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 382
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 383 hdr = genlmsg_iput(rsp, info);
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 384 if (!hdr)
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 385 return -EMSGSIZE;
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 386
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 387 if (nla_put_u32(rsp, NETDEV_A_QUEUE_ID, q_idx) ||
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 388 nla_put_u32(rsp, NETDEV_A_QUEUE_TYPE, q_type) ||
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 389 nla_put_u32(rsp, NETDEV_A_QUEUE_IFINDEX, netdev->ifindex))
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 390 goto nla_put_failure;
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 391
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 392 switch (q_type) {
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 393 case NETDEV_QUEUE_TYPE_RX:
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 394 rxq = __netif_get_rx_queue(netdev, q_idx);
4e43e696a7aeb2 Joe Damato 2025-02-04 395 if (nla_put_napi_id(rsp, rxq->napi))
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 396 goto nla_put_failure;
d0caf9876a1c9f Mina Almasry 2024-09-10 397
d0caf9876a1c9f Mina Almasry 2024-09-10 398 binding = rxq->mp_params.mp_priv;
d0caf9876a1c9f Mina Almasry 2024-09-10 399 if (binding &&
d0caf9876a1c9f Mina Almasry 2024-09-10 400 nla_put_u32(rsp, NETDEV_A_QUEUE_DMABUF, binding->id))
d0caf9876a1c9f Mina Almasry 2024-09-10 401 goto nla_put_failure;
d0caf9876a1c9f Mina Almasry 2024-09-10 402
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 403 break;
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 404 case NETDEV_QUEUE_TYPE_TX:
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 405 txq = netdev_get_tx_queue(netdev, q_idx);
4e43e696a7aeb2 Joe Damato 2025-02-04 406 if (nla_put_napi_id(rsp, rxq->napi))
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 407 goto nla_put_failure;
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 408 }
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 409
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 410 genlmsg_end(rsp, hdr);
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 411
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 412 return 0;
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 413
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 414 nla_put_failure:
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 415 genlmsg_cancel(rsp, hdr);
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 416 return -EMSGSIZE;
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 417 }
6b6171db7fc8f7 Amritha Nambiar 2023-12-01 418
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Hi Joe,
kernel test robot noticed the following build warnings:
[auto build test WARNING on c2933b2befe25309f4c5cfbea0ca80909735fd76]
url: https://github.com/intel-lab-lkp/linux/commits/Joe-Damato/netdev-genl-Elide-napi_id-when-not-present/20250205-033024
base: c2933b2befe25309f4c5cfbea0ca80909735fd76
patch link: https://lore.kernel.org/r/20250204192724.199209-1-jdamato%40fastly.com
patch subject: [PATCH net-next v3] netdev-genl: Elide napi_id when not present
config: i386-buildonly-randconfig-006-20250205 (https://download.01.org/0day-ci/archive/20250205/202502051721.hL1sw85A-lkp@intel.com/config)
compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250205/202502051721.hL1sw85A-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202502051721.hL1sw85A-lkp@intel.com/
All warnings (new ones prefixed by >>):
net/core/netdev-genl.c:380:23: warning: variable 'txq' set but not used [-Wunused-but-set-variable]
380 | struct netdev_queue *txq;
| ^
>> net/core/netdev-genl.c:406:28: warning: variable 'rxq' is uninitialized when used here [-Wuninitialized]
406 | if (nla_put_napi_id(rsp, rxq->napi))
| ^~~
net/core/netdev-genl.c:379:29: note: initialize the variable 'rxq' to silence this warning
379 | struct netdev_rx_queue *rxq;
| ^
| = NULL
2 warnings generated.
vim +/rxq +406 net/core/netdev-genl.c
373
374 static int
375 netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev,
376 u32 q_idx, u32 q_type, const struct genl_info *info)
377 {
378 struct net_devmem_dmabuf_binding *binding;
379 struct netdev_rx_queue *rxq;
380 struct netdev_queue *txq;
381 void *hdr;
382
383 hdr = genlmsg_iput(rsp, info);
384 if (!hdr)
385 return -EMSGSIZE;
386
387 if (nla_put_u32(rsp, NETDEV_A_QUEUE_ID, q_idx) ||
388 nla_put_u32(rsp, NETDEV_A_QUEUE_TYPE, q_type) ||
389 nla_put_u32(rsp, NETDEV_A_QUEUE_IFINDEX, netdev->ifindex))
390 goto nla_put_failure;
391
392 switch (q_type) {
393 case NETDEV_QUEUE_TYPE_RX:
394 rxq = __netif_get_rx_queue(netdev, q_idx);
395 if (nla_put_napi_id(rsp, rxq->napi))
396 goto nla_put_failure;
397
398 binding = rxq->mp_params.mp_priv;
399 if (binding &&
400 nla_put_u32(rsp, NETDEV_A_QUEUE_DMABUF, binding->id))
401 goto nla_put_failure;
402
403 break;
404 case NETDEV_QUEUE_TYPE_TX:
405 txq = netdev_get_tx_queue(netdev, q_idx);
> 406 if (nla_put_napi_id(rsp, rxq->napi))
407 goto nla_put_failure;
408 }
409
410 genlmsg_end(rsp, hdr);
411
412 return 0;
413
414 nla_put_failure:
415 genlmsg_cancel(rsp, hdr);
416 return -EMSGSIZE;
417 }
418
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
© 2016 - 2025 Red Hat, Inc.