Skip to content

Commit d2ef6aa

Browse files
kuba-mooPaolo Abeni
authored andcommitted
net: page_pool: add netlink notifications for state changes
Generate netlink notifications about page pool state changes. Reviewed-by: Eric Dumazet <edumazet@google.com> Acked-by: Jesper Dangaard Brouer <hawk@kernel.org> Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 950ab53 commit d2ef6aa

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

Documentation/netlink/specs/netdev.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,28 @@ operations:
166166
dump:
167167
reply: *pp-reply
168168
config-cond: page-pool
169+
-
170+
name: page-pool-add-ntf
171+
doc: Notification about page pool appearing.
172+
notify: page-pool-get
173+
mcgrp: page-pool
174+
config-cond: page-pool
175+
-
176+
name: page-pool-del-ntf
177+
doc: Notification about page pool disappearing.
178+
notify: page-pool-get
179+
mcgrp: page-pool
180+
config-cond: page-pool
181+
-
182+
name: page-pool-change-ntf
183+
doc: Notification about page pool configuration being changed.
184+
notify: page-pool-get
185+
mcgrp: page-pool
186+
config-cond: page-pool
169187

170188
mcast-groups:
171189
list:
172190
-
173191
name: mgmt
192+
-
193+
name: page-pool

include/uapi/linux/netdev.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,15 @@ enum {
7979
NETDEV_CMD_DEV_DEL_NTF,
8080
NETDEV_CMD_DEV_CHANGE_NTF,
8181
NETDEV_CMD_PAGE_POOL_GET,
82+
NETDEV_CMD_PAGE_POOL_ADD_NTF,
83+
NETDEV_CMD_PAGE_POOL_DEL_NTF,
84+
NETDEV_CMD_PAGE_POOL_CHANGE_NTF,
8285

8386
__NETDEV_CMD_MAX,
8487
NETDEV_CMD_MAX = (__NETDEV_CMD_MAX - 1)
8588
};
8689

8790
#define NETDEV_MCGRP_MGMT "mgmt"
91+
#define NETDEV_MCGRP_PAGE_POOL "page-pool"
8892

8993
#endif /* _UAPI_LINUX_NETDEV_H */

net/core/netdev-genl-gen.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ static const struct genl_split_ops netdev_nl_ops[] = {
6060

6161
static const struct genl_multicast_group netdev_nl_mcgrps[] = {
6262
[NETDEV_NLGRP_MGMT] = { "mgmt", },
63+
[NETDEV_NLGRP_PAGE_POOL] = { "page-pool", },
6364
};
6465

6566
struct genl_family netdev_nl_family __ro_after_init = {

net/core/netdev-genl-gen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ int netdev_nl_page_pool_get_dumpit(struct sk_buff *skb,
1919

2020
enum {
2121
NETDEV_NLGRP_MGMT,
22+
NETDEV_NLGRP_PAGE_POOL,
2223
};
2324

2425
extern struct genl_family netdev_nl_family;

net/core/page_pool_user.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,37 @@ page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
135135
return -EMSGSIZE;
136136
}
137137

138+
static void netdev_nl_page_pool_event(const struct page_pool *pool, u32 cmd)
139+
{
140+
struct genl_info info;
141+
struct sk_buff *ntf;
142+
struct net *net;
143+
144+
lockdep_assert_held(&page_pools_lock);
145+
146+
/* 'invisible' page pools don't matter */
147+
if (hlist_unhashed(&pool->user.list))
148+
return;
149+
net = dev_net(pool->slow.netdev);
150+
151+
if (!genl_has_listeners(&netdev_nl_family, net, NETDEV_NLGRP_PAGE_POOL))
152+
return;
153+
154+
genl_info_init_ntf(&info, &netdev_nl_family, cmd);
155+
156+
ntf = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
157+
if (!ntf)
158+
return;
159+
160+
if (page_pool_nl_fill(ntf, pool, &info)) {
161+
nlmsg_free(ntf);
162+
return;
163+
}
164+
165+
genlmsg_multicast_netns(&netdev_nl_family, net, ntf,
166+
0, NETDEV_NLGRP_PAGE_POOL, GFP_KERNEL);
167+
}
168+
138169
int netdev_nl_page_pool_get_doit(struct sk_buff *skb, struct genl_info *info)
139170
{
140171
u32 id;
@@ -168,6 +199,8 @@ int page_pool_list(struct page_pool *pool)
168199
hlist_add_head(&pool->user.list,
169200
&pool->slow.netdev->page_pools);
170201
pool->user.napi_id = pool->p.napi ? pool->p.napi->napi_id : 0;
202+
203+
netdev_nl_page_pool_event(pool, NETDEV_CMD_PAGE_POOL_ADD_NTF);
171204
}
172205

173206
mutex_unlock(&page_pools_lock);
@@ -181,6 +214,7 @@ int page_pool_list(struct page_pool *pool)
181214
void page_pool_unlist(struct page_pool *pool)
182215
{
183216
mutex_lock(&page_pools_lock);
217+
netdev_nl_page_pool_event(pool, NETDEV_CMD_PAGE_POOL_DEL_NTF);
184218
xa_erase(&page_pools, pool->user.id);
185219
hlist_del(&pool->user.list);
186220
mutex_unlock(&page_pools_lock);
@@ -210,6 +244,8 @@ static void page_pool_unreg_netdev(struct net_device *netdev)
210244
last = NULL;
211245
hlist_for_each_entry(pool, &netdev->page_pools, user.list) {
212246
pool->slow.netdev = lo;
247+
netdev_nl_page_pool_event(pool,
248+
NETDEV_CMD_PAGE_POOL_CHANGE_NTF);
213249
last = pool;
214250
}
215251
if (last)

0 commit comments

Comments
 (0)