Skip to content

Commit

Permalink
net: page_pool: id the page pools
Browse files Browse the repository at this point in the history
To give ourselves the flexibility of creating netlink commands
and ability to refer to page pool instances in uAPIs create
IDs for page pools.

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Acked-by: Jesper Dangaard Brouer <hawk@kernel.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
  • Loading branch information
Jakub Kicinski authored and Paolo Abeni committed Nov 28, 2023
1 parent 23cfaf6 commit f17c696
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
4 changes: 4 additions & 0 deletions include/net/page_pool/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion net/core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 16 additions & 5 deletions net/core/page_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -264,13 +266,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);

Expand Down Expand Up @@ -833,6 +843,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);
}
Expand Down
9 changes: 9 additions & 0 deletions net/core/page_pool_priv.h
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions net/core/page_pool_user.c
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit f17c696

Please sign in to comment.