page_pool: Add callback to init pages when they are allocated
authorToke Høiland-Jørgensen <toke@redhat.com>
Mon, 3 Jan 2022 15:08:07 +0000 (16:08 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 6 Jan 2022 03:46:32 +0000 (19:46 -0800)
Add a new callback function to page_pool that, if set, will be called every
time a new page is allocated. This will be used from bpf_test_run() to
initialise the page data with the data provided by userspace when running
XDP programs with redirect turned on.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
Link: https://lore.kernel.org/bpf/20220103150812.87914-3-toke@redhat.com
include/net/page_pool.h
net/core/page_pool.c

index a408240..d807b68 100644 (file)
@@ -80,6 +80,8 @@ struct page_pool_params {
        enum dma_data_direction dma_dir; /* DMA mapping direction */
        unsigned int    max_len; /* max DMA sync memory size */
        unsigned int    offset;  /* DMA addr offset */
+       void (*init_callback)(struct page *page, void *arg);
+       void *init_arg;
 };
 
 struct page_pool {
index 1a69784..f53786f 100644 (file)
@@ -217,6 +217,8 @@ static void page_pool_set_pp_info(struct page_pool *pool,
 {
        page->pp = pool;
        page->pp_magic |= PP_SIGNATURE;
+       if (pool->p.init_callback)
+               pool->p.init_callback(page, pool->p.init_arg);
 }
 
 static void page_pool_clear_pp_info(struct page *page)