netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	almasrymina@google.com, hawk@kernel.org,
	ilias.apalodimas@linaro.org, dsahern@gmail.com,
	dtatulea@nvidia.com, willemb@google.com,
	Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next v3 08/13] net: page_pool: add netlink notifications for state changes
Date: Tue, 21 Nov 2023 19:44:15 -0800	[thread overview]
Message-ID: <20231122034420.1158898-9-kuba@kernel.org> (raw)
In-Reply-To: <20231122034420.1158898-1-kuba@kernel.org>

Generate netlink notifications about page pool state changes.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 Documentation/netlink/specs/netdev.yaml | 20 ++++++++++++++
 include/uapi/linux/netdev.h             |  4 +++
 net/core/netdev-genl-gen.c              |  1 +
 net/core/netdev-genl-gen.h              |  1 +
 net/core/page_pool_user.c               | 36 +++++++++++++++++++++++++
 5 files changed, 62 insertions(+)

diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml
index 84ca3c2ab872..82fbe81f7a49 100644
--- a/Documentation/netlink/specs/netdev.yaml
+++ b/Documentation/netlink/specs/netdev.yaml
@@ -166,8 +166,28 @@ name: netdev
       dump:
         reply: *pp-reply
       config-cond: page-pool
+    -
+      name: page-pool-add-ntf
+      doc: Notification about page pool appearing.
+      notify: page-pool-get
+      mcgrp: page-pool
+      config-cond: page-pool
+    -
+      name: page-pool-del-ntf
+      doc: Notification about page pool disappearing.
+      notify: page-pool-get
+      mcgrp: page-pool
+      config-cond: page-pool
+    -
+      name: page-pool-change-ntf
+      doc: Notification about page pool configuration being changed.
+      notify: page-pool-get
+      mcgrp: page-pool
+      config-cond: page-pool
 
 mcast-groups:
   list:
     -
       name: mgmt
+    -
+      name: page-pool
diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h
index 176665bcf0da..beb158872226 100644
--- a/include/uapi/linux/netdev.h
+++ b/include/uapi/linux/netdev.h
@@ -79,11 +79,15 @@ enum {
 	NETDEV_CMD_DEV_DEL_NTF,
 	NETDEV_CMD_DEV_CHANGE_NTF,
 	NETDEV_CMD_PAGE_POOL_GET,
+	NETDEV_CMD_PAGE_POOL_ADD_NTF,
+	NETDEV_CMD_PAGE_POOL_DEL_NTF,
+	NETDEV_CMD_PAGE_POOL_CHANGE_NTF,
 
 	__NETDEV_CMD_MAX,
 	NETDEV_CMD_MAX = (__NETDEV_CMD_MAX - 1)
 };
 
 #define NETDEV_MCGRP_MGMT	"mgmt"
+#define NETDEV_MCGRP_PAGE_POOL	"page-pool"
 
 #endif /* _UAPI_LINUX_NETDEV_H */
diff --git a/net/core/netdev-genl-gen.c b/net/core/netdev-genl-gen.c
index 9d34b451cfa7..278b43f5ed50 100644
--- a/net/core/netdev-genl-gen.c
+++ b/net/core/netdev-genl-gen.c
@@ -60,6 +60,7 @@ static const struct genl_split_ops netdev_nl_ops[] = {
 
 static const struct genl_multicast_group netdev_nl_mcgrps[] = {
 	[NETDEV_NLGRP_MGMT] = { "mgmt", },
+	[NETDEV_NLGRP_PAGE_POOL] = { "page-pool", },
 };
 
 struct genl_family netdev_nl_family __ro_after_init = {
diff --git a/net/core/netdev-genl-gen.h b/net/core/netdev-genl-gen.h
index a011d12abff4..738097847100 100644
--- a/net/core/netdev-genl-gen.h
+++ b/net/core/netdev-genl-gen.h
@@ -19,6 +19,7 @@ int netdev_nl_page_pool_get_dumpit(struct sk_buff *skb,
 
 enum {
 	NETDEV_NLGRP_MGMT,
+	NETDEV_NLGRP_PAGE_POOL,
 };
 
 extern struct genl_family netdev_nl_family;
diff --git a/net/core/page_pool_user.c b/net/core/page_pool_user.c
index 24f4e54f6266..35c56fb41c46 100644
--- a/net/core/page_pool_user.c
+++ b/net/core/page_pool_user.c
@@ -135,6 +135,37 @@ page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
 	return -EMSGSIZE;
 }
 
+static void netdev_nl_page_pool_event(const struct page_pool *pool, u32 cmd)
+{
+	struct genl_info info;
+	struct sk_buff *ntf;
+	struct net *net;
+
+	lockdep_assert_held(&page_pools_lock);
+
+	/* 'invisible' page pools don't matter */
+	if (hlist_unhashed(&pool->user.list))
+		return;
+	net = dev_net(pool->slow.netdev);
+
+	if (!genl_has_listeners(&netdev_nl_family, net, NETDEV_NLGRP_PAGE_POOL))
+		return;
+
+	genl_info_init_ntf(&info, &netdev_nl_family, cmd);
+
+	ntf = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
+	if (!ntf)
+		return;
+
+	if (page_pool_nl_fill(ntf, pool, &info)) {
+		nlmsg_free(ntf);
+		return;
+	}
+
+	genlmsg_multicast_netns(&netdev_nl_family, net, ntf,
+				0, NETDEV_NLGRP_PAGE_POOL, GFP_KERNEL);
+}
+
 int netdev_nl_page_pool_get_doit(struct sk_buff *skb, struct genl_info *info)
 {
 	u32 id;
@@ -168,6 +199,8 @@ int page_pool_list(struct page_pool *pool)
 		hlist_add_head(&pool->user.list,
 			       &pool->slow.netdev->page_pools);
 		pool->user.napi_id = pool->p.napi ? pool->p.napi->napi_id : 0;
+
+		netdev_nl_page_pool_event(pool, NETDEV_CMD_PAGE_POOL_ADD_NTF);
 	}
 
 	mutex_unlock(&page_pools_lock);
@@ -181,6 +214,7 @@ int page_pool_list(struct page_pool *pool)
 void page_pool_unlist(struct page_pool *pool)
 {
 	mutex_lock(&page_pools_lock);
+	netdev_nl_page_pool_event(pool, NETDEV_CMD_PAGE_POOL_DEL_NTF);
 	xa_erase(&page_pools, pool->user.id);
 	hlist_del(&pool->user.list);
 	mutex_unlock(&page_pools_lock);
@@ -216,6 +250,8 @@ static void page_pool_unreg_netdev(struct net_device *netdev)
 	last = NULL;
 	hlist_for_each_entry(pool, &netdev->page_pools, user.list) {
 		pool->slow.netdev = lo;
+		netdev_nl_page_pool_event(pool,
+					  NETDEV_CMD_PAGE_POOL_CHANGE_NTF);
 		last = pool;
 	}
 	if (last)
-- 
2.42.0


  parent reply	other threads:[~2023-11-22  3:44 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-22  3:44 [PATCH net-next v3 00/13] net: page_pool: add netlink-based introspection Jakub Kicinski
2023-11-22  3:44 ` [PATCH net-next v3 01/13] net: page_pool: factor out uninit Jakub Kicinski
2023-11-22  8:38   ` Eric Dumazet
2023-11-22 14:15   ` Jesper Dangaard Brouer
2023-11-22  3:44 ` [PATCH net-next v3 02/13] net: page_pool: id the page pools Jakub Kicinski
2023-11-22  8:40   ` Eric Dumazet
2023-11-22 14:16   ` Jesper Dangaard Brouer
2023-11-22  3:44 ` [PATCH net-next v3 03/13] net: page_pool: record pools per netdev Jakub Kicinski
2023-11-22  8:55   ` Eric Dumazet
2023-11-22 15:44     ` Jakub Kicinski
2023-11-22 14:20   ` Jesper Dangaard Brouer
2023-11-22  3:44 ` [PATCH net-next v3 04/13] net: page_pool: stash the NAPI ID for easier access Jakub Kicinski
2023-11-22  8:57   ` Eric Dumazet
2023-11-22 14:21   ` Jesper Dangaard Brouer
2023-11-22  3:44 ` [PATCH net-next v3 05/13] eth: link netdev to page_pools in drivers Jakub Kicinski
2023-11-22  8:59   ` Eric Dumazet
2023-11-22 14:22   ` Jesper Dangaard Brouer
2023-11-22  3:44 ` [PATCH net-next v3 06/13] net: page_pool: add nlspec for basic access to page pools Jakub Kicinski
2023-11-22  9:00   ` Eric Dumazet
2023-11-22 14:24   ` Jesper Dangaard Brouer
2023-11-22  3:44 ` [PATCH net-next v3 07/13] net: page_pool: implement GET in the netlink API Jakub Kicinski
2023-11-22  9:35   ` Eric Dumazet
2023-11-22 14:39   ` Jesper Dangaard Brouer
2023-11-22 16:00     ` Jakub Kicinski
2023-11-22 16:21       ` Jesper Dangaard Brouer
2023-11-22  3:44 ` Jakub Kicinski [this message]
2023-11-22  9:44   ` [PATCH net-next v3 08/13] net: page_pool: add netlink notifications for state changes Eric Dumazet
2023-11-22 14:41   ` Jesper Dangaard Brouer
2023-11-22  3:44 ` [PATCH net-next v3 09/13] net: page_pool: report amount of memory held by page pools Jakub Kicinski
2023-11-22 10:16   ` Eric Dumazet
2023-11-22 16:03     ` Jakub Kicinski
2023-11-22 16:20       ` Eric Dumazet
2023-11-22 15:24   ` Jesper Dangaard Brouer
2023-11-22 16:06     ` Jakub Kicinski
2023-11-22 16:09       ` Jesper Dangaard Brouer
2023-11-22  3:44 ` [PATCH net-next v3 10/13] net: page_pool: report when page pool was destroyed Jakub Kicinski
2023-11-22  9:02   ` Jesper Dangaard Brouer
2023-11-22 10:21   ` Eric Dumazet
2023-11-22  3:44 ` [PATCH net-next v3 11/13] net: page_pool: expose page pool stats via netlink Jakub Kicinski
2023-11-22 10:27   ` Eric Dumazet
2023-11-22 15:51   ` Jesper Dangaard Brouer
2023-11-22  3:44 ` [PATCH net-next v3 12/13] net: page_pool: mute the periodic warning for visible page pools Jakub Kicinski
2023-11-22 13:53   ` Eric Dumazet
2023-11-22 16:06   ` Jesper Dangaard Brouer
2023-11-22  3:44 ` [PATCH net-next v3 13/13] tools: ynl: add sample for getting page-pool information Jakub Kicinski
2023-11-22 16:17   ` Jesper Dangaard Brouer
2023-11-25 20:57 ` [PATCH net-next v3 00/13] net: page_pool: add netlink-based introspection Shakeel Butt
2023-11-26 22:43   ` Jakub Kicinski
2023-11-27  6:54     ` Shakeel Butt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231122034420.1158898-9-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=almasrymina@google.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@gmail.com \
    --cc=dtatulea@nvidia.com \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).