Skip to content

Commit 3698452

Browse files
committed
net: page_pool: don't try to stash the napi id
JIRA: https://issues.redhat.com/browse/RHEL-77816 Upstream Status: net.git commit 67e4bb2 Conflicts: - net/core/page_pool_priv.h: context mismatch because of missing upstream commit 8ab79ed ("page_pool: devmem support") commit 67e4bb2 Author: Jakub Kicinski <kuba@kernel.org> Date: Thu Jan 23 15:16:20 2025 -0800 net: page_pool: don't try to stash the napi id Page ppol tried to cache the NAPI ID in page pool info to avoid having a dependency on the life cycle of the NAPI instance. Since commit under Fixes the NAPI ID is not populated until napi_enable() and there's a good chance that page pool is created before NAPI gets enabled. Protect the NAPI pointer with the existing page pool mutex, the reading path already holds it. napi_id itself we need to READ_ONCE(), it's protected by netdev_lock() which are not holding in page pool. Before this patch napi IDs were missing for mlx5: # ./cli.py --spec netlink/specs/netdev.yaml --dump page-pool-get [{'id': 144, 'ifindex': 2, 'inflight': 3072, 'inflight-mem': 12582912}, {'id': 143, 'ifindex': 2, 'inflight': 5568, 'inflight-mem': 22806528}, {'id': 142, 'ifindex': 2, 'inflight': 5120, 'inflight-mem': 20971520}, {'id': 141, 'ifindex': 2, 'inflight': 4992, 'inflight-mem': 20447232}, ... After: [{'id': 144, 'ifindex': 2, 'inflight': 3072, 'inflight-mem': 12582912, 'napi-id': 565}, {'id': 143, 'ifindex': 2, 'inflight': 4224, 'inflight-mem': 17301504, 'napi-id': 525}, {'id': 142, 'ifindex': 2, 'inflight': 4288, 'inflight-mem': 17563648, 'napi-id': 524}, ... Fixes: 86e25f4 ("net: napi: Add napi_config") Reviewed-by: Mina Almasry <almasrymina@google.com> Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com> Link: https://patch.msgid.link/20250123231620.1086401-1-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Davide Caratti <dcaratti@redhat.com>
1 parent b91a38f commit 3698452

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

include/net/page_pool/types.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ struct page_pool {
226226
struct {
227227
struct hlist_node list;
228228
u64 detach_time;
229-
u32 napi_id;
230229
u32 id;
231230
} user;
232231
};

net/core/dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6449,7 +6449,7 @@ EXPORT_SYMBOL(napi_busy_loop);
64496449
static void __napi_hash_add_with_id(struct napi_struct *napi,
64506450
unsigned int napi_id)
64516451
{
6452-
napi->napi_id = napi_id;
6452+
WRITE_ONCE(napi->napi_id, napi_id);
64536453
hlist_add_head_rcu(&napi->napi_hash_node,
64546454
&napi_hash[napi->napi_id % HASH_SIZE(napi_hash)]);
64556455
}

net/core/page_pool.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,9 @@ void page_pool_disable_direct_recycling(struct page_pool *pool)
10281028
WARN_ON(!test_bit(NAPI_STATE_SCHED, &pool->p.napi->state) ||
10291029
READ_ONCE(pool->p.napi->list_owner) != -1);
10301030

1031+
mutex_lock(&page_pools_lock);
10311032
WRITE_ONCE(pool->p.napi, NULL);
1033+
mutex_unlock(&page_pools_lock);
10321034
}
10331035
EXPORT_SYMBOL(page_pool_disable_direct_recycling);
10341036

net/core/page_pool_priv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#ifndef __PAGE_POOL_PRIV_H
44
#define __PAGE_POOL_PRIV_H
55

6+
extern struct mutex page_pools_lock;
7+
68
s32 page_pool_inflight(const struct page_pool *pool, bool strict);
79

810
int page_pool_list(struct page_pool *pool);

net/core/page_pool_user.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <linux/mutex.h>
44
#include <linux/netdevice.h>
55
#include <linux/xarray.h>
6+
#include <net/busy_poll.h>
67
#include <net/net_debug.h>
78
#include <net/page_pool/types.h>
89
#include <net/page_pool/helpers.h>
@@ -12,10 +13,11 @@
1213
#include "netdev-genl-gen.h"
1314

1415
static DEFINE_XARRAY_FLAGS(page_pools, XA_FLAGS_ALLOC1);
15-
/* Protects: page_pools, netdevice->page_pools, pool->slow.netdev, pool->user.
16+
/* Protects: page_pools, netdevice->page_pools, pool->p.napi, pool->slow.netdev,
17+
* pool->user.
1618
* Ordering: inside rtnl_lock
1719
*/
18-
static DEFINE_MUTEX(page_pools_lock);
20+
DEFINE_MUTEX(page_pools_lock);
1921

2022
/* Page pools are only reachable from user space (via netlink) if they are
2123
* linked to a netdev at creation time. Following page pool "visibility"
@@ -213,6 +215,7 @@ page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
213215
const struct genl_info *info)
214216
{
215217
size_t inflight, refsz;
218+
unsigned int napi_id;
216219
void *hdr;
217220

218221
hdr = genlmsg_iput(rsp, info);
@@ -226,8 +229,10 @@ page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
226229
nla_put_u32(rsp, NETDEV_A_PAGE_POOL_IFINDEX,
227230
pool->slow.netdev->ifindex))
228231
goto err_cancel;
229-
if (pool->user.napi_id &&
230-
nla_put_uint(rsp, NETDEV_A_PAGE_POOL_NAPI_ID, pool->user.napi_id))
232+
233+
napi_id = pool->p.napi ? READ_ONCE(pool->p.napi->napi_id) : 0;
234+
if (napi_id >= MIN_NAPI_ID &&
235+
nla_put_uint(rsp, NETDEV_A_PAGE_POOL_NAPI_ID, napi_id))
231236
goto err_cancel;
232237

233238
inflight = page_pool_inflight(pool, false);
@@ -313,8 +318,6 @@ int page_pool_list(struct page_pool *pool)
313318
if (pool->slow.netdev) {
314319
hlist_add_head(&pool->user.list,
315320
&pool->slow.netdev->page_pools);
316-
pool->user.napi_id = pool->p.napi ? pool->p.napi->napi_id : 0;
317-
318321
netdev_nl_page_pool_event(pool, NETDEV_CMD_PAGE_POOL_ADD_NTF);
319322
}
320323

0 commit comments

Comments
 (0)