Skip to content

Commit 536b37c

Browse files
kuba-moogregkh
authored andcommitted
net: page_pool: don't try to stash the napi id
[ Upstream commit 67e4bb2 ] 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 <[email protected]> Reviewed-by: Toke Høiland-Jørgensen <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 7ed5254 commit 536b37c

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
@@ -236,7 +236,6 @@ struct page_pool {
236236
struct {
237237
struct hlist_node list;
238238
u64 detach_time;
239-
u32 napi_id;
240239
u32 id;
241240
} user;
242241
};

net/core/dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6573,7 +6573,7 @@ void napi_resume_irqs(unsigned int napi_id)
65736573
static void __napi_hash_add_with_id(struct napi_struct *napi,
65746574
unsigned int napi_id)
65756575
{
6576-
napi->napi_id = napi_id;
6576+
WRITE_ONCE(napi->napi_id, napi_id);
65776577
hlist_add_head_rcu(&napi->napi_hash_node,
65786578
&napi_hash[napi->napi_id % HASH_SIZE(napi_hash)]);
65796579
}

net/core/page_pool.c

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

1111+
mutex_lock(&page_pools_lock);
11111112
WRITE_ONCE(pool->p.napi, NULL);
1113+
mutex_unlock(&page_pools_lock);
11121114
}
11131115
EXPORT_SYMBOL(page_pool_disable_direct_recycling);
11141116

net/core/page_pool_priv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include "netmem_priv.h"
99

10+
extern struct mutex page_pools_lock;
11+
1012
s32 page_pool_inflight(const struct page_pool *pool, bool strict);
1113

1214
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/netdev_rx_queue.h>
89
#include <net/page_pool/helpers.h>
@@ -14,10 +15,11 @@
1415
#include "netdev-genl-gen.h"
1516

1617
static DEFINE_XARRAY_FLAGS(page_pools, XA_FLAGS_ALLOC1);
17-
/* Protects: page_pools, netdevice->page_pools, pool->slow.netdev, pool->user.
18+
/* Protects: page_pools, netdevice->page_pools, pool->p.napi, pool->slow.netdev,
19+
* pool->user.
1820
* Ordering: inside rtnl_lock
1921
*/
20-
static DEFINE_MUTEX(page_pools_lock);
22+
DEFINE_MUTEX(page_pools_lock);
2123

2224
/* Page pools are only reachable from user space (via netlink) if they are
2325
* linked to a netdev at creation time. Following page pool "visibility"
@@ -216,6 +218,7 @@ page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
216218
{
217219
struct net_devmem_dmabuf_binding *binding = pool->mp_priv;
218220
size_t inflight, refsz;
221+
unsigned int napi_id;
219222
void *hdr;
220223

221224
hdr = genlmsg_iput(rsp, info);
@@ -229,8 +232,10 @@ page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
229232
nla_put_u32(rsp, NETDEV_A_PAGE_POOL_IFINDEX,
230233
pool->slow.netdev->ifindex))
231234
goto err_cancel;
232-
if (pool->user.napi_id &&
233-
nla_put_uint(rsp, NETDEV_A_PAGE_POOL_NAPI_ID, pool->user.napi_id))
235+
236+
napi_id = pool->p.napi ? READ_ONCE(pool->p.napi->napi_id) : 0;
237+
if (napi_id >= MIN_NAPI_ID &&
238+
nla_put_uint(rsp, NETDEV_A_PAGE_POOL_NAPI_ID, napi_id))
234239
goto err_cancel;
235240

236241
inflight = page_pool_inflight(pool, false);
@@ -319,8 +324,6 @@ int page_pool_list(struct page_pool *pool)
319324
if (pool->slow.netdev) {
320325
hlist_add_head(&pool->user.list,
321326
&pool->slow.netdev->page_pools);
322-
pool->user.napi_id = pool->p.napi ? pool->p.napi->napi_id : 0;
323-
324327
netdev_nl_page_pool_event(pool, NETDEV_CMD_PAGE_POOL_ADD_NTF);
325328
}
326329

0 commit comments

Comments
 (0)