diff mbox series

[bpf-next,1/8] page_pool: Add callback to init pages when they are allocated

Message ID 20211202000232.380824-2-toke@redhat.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series Add support for transmitting packets using XDP in bpf_prog_run() | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5997 this patch: 5997
netdev/cc_maintainers success CCed 14 of 14 maintainers
netdev/build_clang success Errors and warnings before: 1044 this patch: 1044
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 6152 this patch: 6152
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 16 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next success VM_Test

Commit Message

Toke Høiland-Jørgensen Dec. 2, 2021, 12:02 a.m. UTC
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>
---
 include/net/page_pool.h | 2 ++
 net/core/page_pool.c    | 2 ++
 2 files changed, 4 insertions(+)

Comments

John Fastabend Dec. 8, 2021, 10:30 p.m. UTC | #1
Toke Høiland-Jørgensen wrote:
> 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>
> ---

LGTM.

Acked-by: John Fastabend <john.fastabend@gmail.com>

>  include/net/page_pool.h | 2 ++
>  net/core/page_pool.c    | 2 ++
>  2 files changed, 4 insertions(+)
> 
> diff --git a/include/net/page_pool.h b/include/net/page_pool.h
> index 3855f069627f..a71201854c41 100644
> --- a/include/net/page_pool.h
> +++ b/include/net/page_pool.h
> @@ -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 {
> diff --git a/net/core/page_pool.c b/net/core/page_pool.c
> index 9b60e4301a44..fb5a90b9d574 100644
> --- a/net/core/page_pool.c
> +++ b/net/core/page_pool.c
> @@ -219,6 +219,8 @@ static void page_pool_set_pp_info(struct page_pool *pool,
>  {
>  	page->pp = pool;
>  	page->pp_magic |= PP_SIGNATURE;
> +	if (unlikely(pool->p.init_callback))
> +		pool->p.init_callback(page, pool->p.init_arg);

already in slow path right? So unlikely in a slow path should not
have any impact on performance is my reading.

>  }
>  
>  static void page_pool_clear_pp_info(struct page *page)
> -- 
> 2.34.0
>
Toke Høiland-Jørgensen Dec. 9, 2021, 4:01 p.m. UTC | #2
John Fastabend <john.fastabend@gmail.com> writes:

> Toke Høiland-Jørgensen wrote:
>> 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>
>> ---
>
> LGTM.
>
> Acked-by: John Fastabend <john.fastabend@gmail.com>
>
>>  include/net/page_pool.h | 2 ++
>>  net/core/page_pool.c    | 2 ++
>>  2 files changed, 4 insertions(+)
>> 
>> diff --git a/include/net/page_pool.h b/include/net/page_pool.h
>> index 3855f069627f..a71201854c41 100644
>> --- a/include/net/page_pool.h
>> +++ b/include/net/page_pool.h
>> @@ -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 {
>> diff --git a/net/core/page_pool.c b/net/core/page_pool.c
>> index 9b60e4301a44..fb5a90b9d574 100644
>> --- a/net/core/page_pool.c
>> +++ b/net/core/page_pool.c
>> @@ -219,6 +219,8 @@ static void page_pool_set_pp_info(struct page_pool *pool,
>>  {
>>  	page->pp = pool;
>>  	page->pp_magic |= PP_SIGNATURE;
>> +	if (unlikely(pool->p.init_callback))
>> +		pool->p.init_callback(page, pool->p.init_arg);
>
> already in slow path right? So unlikely in a slow path should not
> have any impact on performance is my reading.

Yeah, fair point, may have gone a little overboard on the "minimise
impact to existing code" here - will drop.

-Toke
diff mbox series

Patch

diff --git a/include/net/page_pool.h b/include/net/page_pool.h
index 3855f069627f..a71201854c41 100644
--- a/include/net/page_pool.h
+++ b/include/net/page_pool.h
@@ -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 {
diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index 9b60e4301a44..fb5a90b9d574 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -219,6 +219,8 @@  static void page_pool_set_pp_info(struct page_pool *pool,
 {
 	page->pp = pool;
 	page->pp_magic |= PP_SIGNATURE;
+	if (unlikely(pool->p.init_callback))
+		pool->p.init_callback(page, pool->p.init_arg);
 }
 
 static void page_pool_clear_pp_info(struct page *page)