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, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 04/15] net: page_pool: id the page pools
Date: Tue, 24 Oct 2023 09:02:09 -0700 [thread overview]
Message-ID: <20231024160220.3973311-5-kuba@kernel.org> (raw)
In-Reply-To: <20231024160220.3973311-1-kuba@kernel.org>
To give ourselves the flexibility of creating netlink commands
and ability to refer to page pool instances in uAPIs create
IDs for page pools.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
include/net/page_pool/types.h | 4 ++++
net/core/Makefile | 2 +-
net/core/page_pool.c | 21 +++++++++++++++-----
net/core/page_pool_priv.h | 9 +++++++++
net/core/page_pool_user.c | 36 +++++++++++++++++++++++++++++++++++
5 files changed, 66 insertions(+), 6 deletions(-)
create mode 100644 net/core/page_pool_priv.h
create mode 100644 net/core/page_pool_user.c
diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h
index e1bb92c192de..c19f0df3bf0b 100644
--- a/include/net/page_pool/types.h
+++ b/include/net/page_pool/types.h
@@ -187,6 +187,10 @@ struct page_pool {
/* Slow/Control-path information follows */
struct page_pool_params_slow slow;
+ /* User-facing fields, protected by page_pools_lock */
+ struct {
+ u32 id;
+ } user;
};
struct page *page_pool_alloc_pages(struct page_pool *pool, gfp_t gfp);
diff --git a/net/core/Makefile b/net/core/Makefile
index 0cb734cbc24b..821aec06abf1 100644
--- a/net/core/Makefile
+++ b/net/core/Makefile
@@ -18,7 +18,7 @@ obj-y += dev.o dev_addr_lists.o dst.o netevent.o \
obj-$(CONFIG_NETDEV_ADDR_LIST_TEST) += dev_addr_lists_test.o
obj-y += net-sysfs.o
-obj-$(CONFIG_PAGE_POOL) += page_pool.o
+obj-$(CONFIG_PAGE_POOL) += page_pool.o page_pool_user.o
obj-$(CONFIG_PROC_FS) += net-procfs.o
obj-$(CONFIG_NET_PKTGEN) += pktgen.o
obj-$(CONFIG_NETPOLL) += netpoll.o
diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index 4aed4809b5b4..b3b484fbacae 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -23,6 +23,8 @@
#include <trace/events/page_pool.h>
+#include "page_pool_priv.h"
+
#define DEFER_TIME (msecs_to_jiffies(1000))
#define DEFER_WARN_INTERVAL (60 * HZ)
@@ -260,13 +262,21 @@ struct page_pool *page_pool_create(const struct page_pool_params *params)
return ERR_PTR(-ENOMEM);
err = page_pool_init(pool, params);
- if (err < 0) {
- pr_warn("%s() gave up with errno %d\n", __func__, err);
- kfree(pool);
- return ERR_PTR(err);
- }
+ if (err < 0)
+ goto err_free;
+
+ err = page_pool_list(pool);
+ if (err)
+ goto err_uninit;
return pool;
+
+err_uninit:
+ page_pool_uninit(pool);
+err_free:
+ pr_warn("%s() gave up with errno %d\n", __func__, err);
+ kfree(pool);
+ return ERR_PTR(err);
}
EXPORT_SYMBOL(page_pool_create);
@@ -829,6 +839,7 @@ static void __page_pool_destroy(struct page_pool *pool)
if (pool->disconnect)
pool->disconnect(pool);
+ page_pool_unlist(pool);
page_pool_uninit(pool);
kfree(pool);
}
diff --git a/net/core/page_pool_priv.h b/net/core/page_pool_priv.h
new file mode 100644
index 000000000000..c17ea092b4ab
--- /dev/null
+++ b/net/core/page_pool_priv.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __PAGE_POOL_PRIV_H
+#define __PAGE_POOL_PRIV_H
+
+int page_pool_list(struct page_pool *pool);
+void page_pool_unlist(struct page_pool *pool);
+
+#endif
diff --git a/net/core/page_pool_user.c b/net/core/page_pool_user.c
new file mode 100644
index 000000000000..630d1eeecf2a
--- /dev/null
+++ b/net/core/page_pool_user.c
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/mutex.h>
+#include <linux/xarray.h>
+#include <net/page_pool/types.h>
+
+#include "page_pool_priv.h"
+
+static DEFINE_XARRAY_FLAGS(page_pools, XA_FLAGS_ALLOC1);
+static DEFINE_MUTEX(page_pools_lock);
+
+int page_pool_list(struct page_pool *pool)
+{
+ static u32 id_alloc_next;
+ int err;
+
+ mutex_lock(&page_pools_lock);
+ err = xa_alloc_cyclic(&page_pools, &pool->user.id, pool, xa_limit_32b,
+ &id_alloc_next, GFP_KERNEL);
+ if (err < 0)
+ goto err_unlock;
+
+ mutex_unlock(&page_pools_lock);
+ return 0;
+
+err_unlock:
+ mutex_unlock(&page_pools_lock);
+ return err;
+}
+
+void page_pool_unlist(struct page_pool *pool)
+{
+ mutex_lock(&page_pools_lock);
+ xa_erase(&page_pools, pool->user.id);
+ mutex_unlock(&page_pools_lock);
+}
--
2.41.0
next prev parent reply other threads:[~2023-10-24 16:02 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-24 16:02 [PATCH net-next 00/15] net: page_pool: add netlink-based introspection Jakub Kicinski
2023-10-24 16:02 ` [PATCH net-next 01/15] net: page_pool: split the page_pool_params into fast and slow Jakub Kicinski
2023-11-09 8:13 ` Ilias Apalodimas
2023-10-24 16:02 ` [PATCH net-next 02/15] net: page_pool: avoid touching slow on the fastpath Jakub Kicinski
2023-11-09 9:00 ` Ilias Apalodimas
2023-10-24 16:02 ` [PATCH net-next 03/15] net: page_pool: factor out uninit Jakub Kicinski
2023-10-25 18:33 ` Mina Almasry
2023-10-24 16:02 ` Jakub Kicinski [this message]
2023-10-25 18:49 ` [PATCH net-next 04/15] net: page_pool: id the page pools Mina Almasry
2023-11-09 9:21 ` Ilias Apalodimas
2023-11-09 16:22 ` Jakub Kicinski
2023-11-09 16:48 ` Ilias Apalodimas
2023-10-24 16:02 ` [PATCH net-next 05/15] net: page_pool: record pools per netdev Jakub Kicinski
2023-10-24 17:31 ` David Ahern
2023-10-24 17:49 ` Jakub Kicinski
2023-10-24 19:19 ` David Ahern
2023-10-24 19:45 ` Jakub Kicinski
2023-10-25 19:56 ` Mina Almasry
2023-10-25 20:17 ` Jakub Kicinski
2023-11-09 3:28 ` Mina Almasry
2023-10-24 16:02 ` [PATCH net-next 06/15] net: page_pool: stash the NAPI ID for easier access Jakub Kicinski
2023-10-24 16:02 ` [PATCH net-next 07/15] eth: link netdev to page_pools in drivers Jakub Kicinski
2023-11-09 9:11 ` Ilias Apalodimas
2023-11-09 16:26 ` Jakub Kicinski
2023-11-09 16:51 ` Ilias Apalodimas
2023-10-24 16:02 ` [PATCH net-next 08/15] net: page_pool: add nlspec for basic access to page pools Jakub Kicinski
2023-10-24 16:02 ` [PATCH net-next 09/15] net: page_pool: implement GET in the netlink API Jakub Kicinski
2023-10-25 10:51 ` kernel test robot
2023-10-25 22:08 ` kernel test robot
2023-10-24 16:02 ` [PATCH net-next 10/15] net: page_pool: add netlink notifications for state changes Jakub Kicinski
2023-10-24 16:02 ` [PATCH net-next 11/15] net: page_pool: report amount of memory held by page pools Jakub Kicinski
2023-10-24 16:02 ` [PATCH net-next 12/15] net: page_pool: report when page pool was destroyed Jakub Kicinski
2023-11-09 17:05 ` Dragos Tatulea
2023-10-24 16:02 ` [PATCH net-next 13/15] net: page_pool: expose page pool stats via netlink Jakub Kicinski
2023-10-25 13:50 ` kernel test robot
2023-10-24 16:02 ` [PATCH net-next 14/15] net: page_pool: mute the periodic warning for visible page pools Jakub Kicinski
2023-10-24 16:02 ` [PATCH net-next 15/15] tools: ynl: add sample for getting page-pool information Jakub Kicinski
2023-11-09 8:11 ` [PATCH net-next 00/15] net: page_pool: add netlink-based introspection Ilias Apalodimas
2023-11-09 16:14 ` Jakub Kicinski
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=20231024160220.3973311-5-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=almasrymina@google.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hawk@kernel.org \
--cc=ilias.apalodimas@linaro.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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).