* [PATCH net-next] net: use napi_id_valid helper
@ 2025-02-12 21:15 Stefano Jordhani
2025-02-12 22:45 ` Joe Damato
2025-02-12 22:52 ` Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Stefano Jordhani @ 2025-02-12 21:15 UTC (permalink / raw)
To: netdev
Cc: Stefano Jordhani, Paolo Abeni, Alexander Viro, Christian Brauner,
Jan Kara, David S. Miller, Eric Dumazet, Jakub Kicinski,
Simon Horman, Jens Axboe, Pavel Begunkov, Kuniyuki Iwashima,
Willem de Bruijn, Björn Töpel, Magnus Karlsson,
Maciej Fijalkowski, Jonathan Lemon, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
Sebastian Andrzej Siewior, Lorenzo Bianconi, Joe Damato,
Alexander Lobakin, Sridhar Samudrala, Xuan Zhuo, Mina Almasry,
open list:FILESYSTEMS (VFS and infrastructure), open list,
open list:IO_URING, open list:XDP SOCKETS (AF_XDP)
In commit 6597e8d35851 ("netdev-genl: Elide napi_id when not present"),
napi_id_valid function was added. Use the helper to refactor open-coded
checks in the source.
Suggested-by: Paolo Abeni <[email protected]>
Signed-off-by: Stefano Jordhani <[email protected]>
---
fs/eventpoll.c | 8 ++++----
include/net/busy_poll.h | 4 ++--
io_uring/napi.c | 4 ++--
net/core/dev.c | 6 +++---
net/core/netdev-genl.c | 2 +-
net/core/page_pool_user.c | 2 +-
net/core/sock.c | 2 +-
net/xdp/xsk.c | 2 +-
8 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 7c0980db77b3..2fecf66661e9 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -447,7 +447,7 @@ static bool ep_busy_loop(struct eventpoll *ep, int nonblock)
if (!budget)
budget = BUSY_POLL_BUDGET;
- if (napi_id >= MIN_NAPI_ID && ep_busy_loop_on(ep)) {
+ if (napi_id_valid(napi_id) && ep_busy_loop_on(ep)) {
napi_busy_loop(napi_id, nonblock ? NULL : ep_busy_loop_end,
ep, prefer_busy_poll, budget);
if (ep_events_available(ep))
@@ -492,7 +492,7 @@ static inline void ep_set_busy_poll_napi_id(struct
epitem *epi)
* or
* Nothing to do if we already have this ID
*/
- if (napi_id < MIN_NAPI_ID || napi_id == ep->napi_id)
+ if (!napi_id_valid(napi_id) || napi_id == ep->napi_id)
return;
/* record NAPI ID for use in next busy poll */
@@ -546,7 +546,7 @@ static void ep_suspend_napi_irqs(struct eventpoll *ep)
{
unsigned int napi_id = READ_ONCE(ep->napi_id);
- if (napi_id >= MIN_NAPI_ID && READ_ONCE(ep->prefer_busy_poll))
+ if (napi_id_valid(napi_id) && READ_ONCE(ep->prefer_busy_poll))
napi_suspend_irqs(napi_id);
}
@@ -554,7 +554,7 @@ static void ep_resume_napi_irqs(struct eventpoll *ep)
{
unsigned int napi_id = READ_ONCE(ep->napi_id);
- if (napi_id >= MIN_NAPI_ID && READ_ONCE(ep->prefer_busy_poll))
+ if (napi_id_valid(napi_id) && READ_ONCE(ep->prefer_busy_poll))
napi_resume_irqs(napi_id);
}
diff --git a/include/net/busy_poll.h b/include/net/busy_poll.h
index 741fa7754700..cab6146a510a 100644
--- a/include/net/busy_poll.h
+++ b/include/net/busy_poll.h
@@ -119,7 +119,7 @@ static inline void sk_busy_loop(struct sock *sk,
int nonblock)
#ifdef CONFIG_NET_RX_BUSY_POLL
unsigned int napi_id = READ_ONCE(sk->sk_napi_id);
- if (napi_id >= MIN_NAPI_ID)
+ if (napi_id_valid(napi_id))
napi_busy_loop(napi_id, nonblock ? NULL : sk_busy_loop_end, sk,
READ_ONCE(sk->sk_prefer_busy_poll),
READ_ONCE(sk->sk_busy_poll_budget) ?: BUSY_POLL_BUDGET);
@@ -134,7 +134,7 @@ static inline void skb_mark_napi_id(struct sk_buff *skb,
/* If the skb was already marked with a valid NAPI ID, avoid overwriting
* it.
*/
- if (skb->napi_id < MIN_NAPI_ID)
+ if (!napi_id_valid(skb->napi_id))
skb->napi_id = napi->napi_id;
#endif
}
diff --git a/io_uring/napi.c b/io_uring/napi.c
index b1ade3fda30f..4a10de03e426 100644
--- a/io_uring/napi.c
+++ b/io_uring/napi.c
@@ -44,7 +44,7 @@ int __io_napi_add_id(struct io_ring_ctx *ctx,
unsigned int napi_id)
struct io_napi_entry *e;
/* Non-NAPI IDs can be rejected. */
- if (napi_id < MIN_NAPI_ID)
+ if (!napi_id_valid(napi_id))
return -EINVAL;
hash_list = &ctx->napi_ht[hash_min(napi_id, HASH_BITS(ctx->napi_ht))];
@@ -87,7 +87,7 @@ static int __io_napi_del_id(struct io_ring_ctx *ctx,
unsigned int napi_id)
struct io_napi_entry *e;
/* Non-NAPI IDs can be rejected. */
- if (napi_id < MIN_NAPI_ID)
+ if (!napi_id_valid(napi_id))
return -EINVAL;
hash_list = &ctx->napi_ht[hash_min(napi_id, HASH_BITS(ctx->napi_ht))];
diff --git a/net/core/dev.c b/net/core/dev.c
index d5ab9a4b318e..bcb266ab2912 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1008,7 +1008,7 @@ struct net_device *dev_get_by_napi_id(unsigned
int napi_id)
WARN_ON_ONCE(!rcu_read_lock_held());
- if (napi_id < MIN_NAPI_ID)
+ if (!napi_id_valid(napi_id))
return NULL;
napi = napi_by_id(napi_id);
@@ -6740,7 +6740,7 @@ static void napi_hash_add(struct napi_struct *napi)
/* 0..NR_CPUS range is reserved for sender_cpu use */
do {
- if (unlikely(++napi_gen_id < MIN_NAPI_ID))
+ if (unlikely(!napi_id_valid(++napi_gen_id)))
napi_gen_id = MIN_NAPI_ID;
} while (napi_by_id(napi_gen_id));
@@ -6911,7 +6911,7 @@ netif_napi_dev_list_add(struct net_device *dev,
struct napi_struct *napi)
higher = &dev->napi_list;
list_for_each_entry(pos, &dev->napi_list, dev_list) {
- if (pos->napi_id >= MIN_NAPI_ID)
+ if (napi_id_valid(pos->napi_id))
pos_id = pos->napi_id;
else if (pos->config)
pos_id = pos->config->napi_id;
diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c
index 0dcd4faefd8d..cdcd39724cb3 100644
--- a/net/core/netdev-genl.c
+++ b/net/core/netdev-genl.c
@@ -267,7 +267,7 @@ netdev_nl_napi_dump_one(struct net_device *netdev,
struct sk_buff *rsp,
prev_id = UINT_MAX;
list_for_each_entry(napi, &netdev->napi_list, dev_list) {
- if (napi->napi_id < MIN_NAPI_ID)
+ if (!napi_id_valid(napi->napi_id))
continue;
/* Dump continuation below depends on the list being sorted */
diff --git a/net/core/page_pool_user.c b/net/core/page_pool_user.c
index 9d8a3d8597fa..c82a95beceff 100644
--- a/net/core/page_pool_user.c
+++ b/net/core/page_pool_user.c
@@ -233,7 +233,7 @@ page_pool_nl_fill(struct sk_buff *rsp, const
struct page_pool *pool,
goto err_cancel;
napi_id = pool->p.napi ? READ_ONCE(pool->p.napi->napi_id) : 0;
- if (napi_id >= MIN_NAPI_ID &&
+ if (napi_id_valid(napi_id) &&
nla_put_uint(rsp, NETDEV_A_PAGE_POOL_NAPI_ID, napi_id))
goto err_cancel;
diff --git a/net/core/sock.c b/net/core/sock.c
index eae2ae70a2e0..84dbdc78dea3 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2041,7 +2041,7 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
v.val = READ_ONCE(sk->sk_napi_id);
/* aggregate non-NAPI IDs down to 0 */
- if (v.val < MIN_NAPI_ID)
+ if (!napi_id_valid(v.val))
v.val = 0;
break;
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 89d2bef96469..0edf25973072 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -875,7 +875,7 @@ static bool xsk_no_wakeup(struct sock *sk)
#ifdef CONFIG_NET_RX_BUSY_POLL
/* Prefer busy-polling, skip the wakeup. */
return READ_ONCE(sk->sk_prefer_busy_poll) && READ_ONCE(sk->sk_ll_usec) &&
- READ_ONCE(sk->sk_napi_id) >= MIN_NAPI_ID;
+ napi_id_valid(READ_ONCE(sk->sk_napi_id));
#else
return false;
#endif
base-commit: 39f54262ba499d862420a97719d2f0eea0cbd394
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net: use napi_id_valid helper
2025-02-12 21:15 [PATCH net-next] net: use napi_id_valid helper Stefano Jordhani
@ 2025-02-12 22:45 ` Joe Damato
2025-02-12 22:52 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Joe Damato @ 2025-02-12 22:45 UTC (permalink / raw)
To: Stefano Jordhani
Cc: netdev, Paolo Abeni, Alexander Viro, Christian Brauner, Jan Kara,
David S. Miller, Eric Dumazet, Jakub Kicinski, Simon Horman,
Jens Axboe, Pavel Begunkov, Kuniyuki Iwashima, Willem de Bruijn,
Björn Töpel, Magnus Karlsson, Maciej Fijalkowski,
Jonathan Lemon, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Sebastian Andrzej Siewior,
Lorenzo Bianconi, Alexander Lobakin, Sridhar Samudrala, Xuan Zhuo,
Mina Almasry, open list:FILESYSTEMS (VFS and infrastructure),
open list, open list:IO_URING, open list:XDP SOCKETS (AF_XDP)
On Wed, Feb 12, 2025 at 04:15:05PM -0500, Stefano Jordhani wrote:
> In commit 6597e8d35851 ("netdev-genl: Elide napi_id when not present"),
> napi_id_valid function was added. Use the helper to refactor open-coded
> checks in the source.
>
> Suggested-by: Paolo Abeni <[email protected]>
> Signed-off-by: Stefano Jordhani <[email protected]>
> ---
> fs/eventpoll.c | 8 ++++----
> include/net/busy_poll.h | 4 ++--
> io_uring/napi.c | 4 ++--
> net/core/dev.c | 6 +++---
> net/core/netdev-genl.c | 2 +-
> net/core/page_pool_user.c | 2 +-
> net/core/sock.c | 2 +-
> net/xdp/xsk.c | 2 +-
> 8 files changed, 15 insertions(+), 15 deletions(-)
Thanks for the cleanup. As far as I can tell, LGTM.
Reviewed-by: Joe Damato <[email protected]>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net: use napi_id_valid helper
2025-02-12 21:15 [PATCH net-next] net: use napi_id_valid helper Stefano Jordhani
2025-02-12 22:45 ` Joe Damato
@ 2025-02-12 22:52 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2025-02-12 22:52 UTC (permalink / raw)
To: Stefano Jordhani, netdev
Cc: Paolo Abeni, Alexander Viro, Christian Brauner, Jan Kara,
David S. Miller, Eric Dumazet, Jakub Kicinski, Simon Horman,
Pavel Begunkov, Kuniyuki Iwashima, Willem de Bruijn,
Björn Töpel, Magnus Karlsson, Maciej Fijalkowski,
Jonathan Lemon, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Sebastian Andrzej Siewior,
Lorenzo Bianconi, Joe Damato, Alexander Lobakin,
Sridhar Samudrala, Xuan Zhuo, Mina Almasry,
open list:FILESYSTEMS (VFS and infrastructure), open list,
open list:IO_URING, open list:XDP SOCKETS (AF_XDP)
On 2/12/25 2:15 PM, Stefano Jordhani wrote:
> In commit 6597e8d35851 ("netdev-genl: Elide napi_id when not present"),
> napi_id_valid function was added. Use the helper to refactor open-coded
> checks in the source.
For the io_uring side:
Reviewed-by: Jens Axboe <[email protected]>
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-12 22:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-12 21:15 [PATCH net-next] net: use napi_id_valid helper Stefano Jordhani
2025-02-12 22:45 ` Joe Damato
2025-02-12 22:52 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox