Message ID | 20241211172649.761483-10-aleksander.lobakin@intel.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | xdp: a fistful of generic changes pt. II | expand |
On Wed, Dec 11, 2024 at 9:31 AM Alexander Lobakin <aleksander.lobakin@intel.com> wrote: > > Add the following Page Pool netmem wrappers to be able to implement > an MP-agnostic driver: > Sorry, we raced a bit here. Jakub merged my "page_pool_alloc_netmem", which does similar to what this patch does. > * page_pool{,_dev}_alloc_best_fit_netmem() > > Same as page_pool{,_dev}_alloc(). Make the latter a wrapper around > the new helper (as a page is always a netmem, but not vice versa). > 'page_pool_alloc_netmem' is already busy, hence '_best_fit' (which > also says what the helper tries to do). > I freed the page_pool_alloc_netmem name by doing a rename, and now page_pool_alloc_netmem is the netmem counterpart to page_pool_alloc. I did not however add a page_pool_dev_alloc equivalent. > * page_pool_dma_sync_for_cpu_netmem() > > Same as page_pool_dma_sync_for_cpu(). Performs DMA sync only if > the netmem comes from the host. > My series also adds page_pool_dma_sync_netmem_for_cpu, which should be the same as your page_pool_dma_sync_for_cpu_netmem.
From: Mina Almasry <almasrymina@google.com> Date: Fri, 13 Dec 2024 11:13:33 -0800 > On Wed, Dec 11, 2024 at 9:31 AM Alexander Lobakin > <aleksander.lobakin@intel.com> wrote: >> >> Add the following Page Pool netmem wrappers to be able to implement >> an MP-agnostic driver: >> > > Sorry, we raced a bit here. Jakub merged my "page_pool_alloc_netmem", > which does similar to what this patch does. > >> * page_pool{,_dev}_alloc_best_fit_netmem() >> >> Same as page_pool{,_dev}_alloc(). Make the latter a wrapper around >> the new helper (as a page is always a netmem, but not vice versa). >> 'page_pool_alloc_netmem' is already busy, hence '_best_fit' (which >> also says what the helper tries to do). >> > > I freed the page_pool_alloc_netmem name by doing a rename, and now > page_pool_alloc_netmem is the netmem counterpart to page_pool_alloc. I > did not however add a page_pool_dev_alloc equivalent. > >> * page_pool_dma_sync_for_cpu_netmem() >> >> Same as page_pool_dma_sync_for_cpu(). Performs DMA sync only if >> the netmem comes from the host. >> > > My series also adds page_pool_dma_sync_netmem_for_cpu, which should be > the same as your page_pool_dma_sync_for_cpu_netmem. Yep, I saw your changes, rebasing soon. Thanks, Olek
diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h index 26caa2c20912..d75d10678958 100644 --- a/include/net/page_pool/helpers.h +++ b/include/net/page_pool/helpers.h @@ -115,22 +115,22 @@ static inline struct page *page_pool_dev_alloc_frag(struct page_pool *pool, return page_pool_alloc_frag(pool, offset, size, gfp); } -static inline struct page *page_pool_alloc(struct page_pool *pool, - unsigned int *offset, - unsigned int *size, gfp_t gfp) +static inline netmem_ref +page_pool_alloc_best_fit_netmem(struct page_pool *pool, unsigned int *offset, + unsigned int *size, gfp_t gfp) { unsigned int max_size = PAGE_SIZE << pool->p.order; - struct page *page; + netmem_ref netmem; if ((*size << 1) > max_size) { *size = max_size; *offset = 0; - return page_pool_alloc_pages(pool, gfp); + return page_pool_alloc_netmem(pool, gfp); } - page = page_pool_alloc_frag(pool, offset, *size, gfp); - if (unlikely(!page)) - return NULL; + netmem = page_pool_alloc_frag_netmem(pool, offset, *size, gfp); + if (unlikely(!netmem)) + return 0; /* There is very likely not enough space for another fragment, so append * the remaining size to the current fragment to avoid truesize @@ -141,7 +141,25 @@ static inline struct page *page_pool_alloc(struct page_pool *pool, pool->frag_offset = max_size; } - return page; + return netmem; +} + +static inline netmem_ref +page_pool_dev_alloc_best_fit_netmem(struct page_pool *pool, + unsigned int *offset, + unsigned int *size) +{ + gfp_t gfp = GFP_ATOMIC | __GFP_NOWARN; + + return page_pool_alloc_best_fit_netmem(pool, offset, size, gfp); +} + +static inline struct page *page_pool_alloc(struct page_pool *pool, + unsigned int *offset, + unsigned int *size, gfp_t gfp) +{ + return netmem_to_page(page_pool_alloc_best_fit_netmem(pool, offset, + size, gfp)); } /** @@ -440,6 +458,16 @@ static inline void page_pool_dma_sync_for_cpu(const struct page_pool *pool, page_pool_get_dma_dir(pool)); } +static inline void +page_pool_dma_sync_for_cpu_netmem(const struct page_pool *pool, + netmem_ref netmem, u32 offset, + u32 dma_sync_size) +{ + if (!netmem_is_net_iov(netmem)) + page_pool_dma_sync_for_cpu(pool, netmem_to_page(netmem), + offset, dma_sync_size); +} + static inline bool page_pool_put(struct page_pool *pool) { return refcount_dec_and_test(&pool->user_cnt);
Add the following Page Pool netmem wrappers to be able to implement an MP-agnostic driver: * page_pool{,_dev}_alloc_best_fit_netmem() Same as page_pool{,_dev}_alloc(). Make the latter a wrapper around the new helper (as a page is always a netmem, but not vice versa). 'page_pool_alloc_netmem' is already busy, hence '_best_fit' (which also says what the helper tries to do). * page_pool_dma_sync_for_cpu_netmem() Same as page_pool_dma_sync_for_cpu(). Performs DMA sync only if the netmem comes from the host. Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com> --- include/net/page_pool/helpers.h | 46 ++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 9 deletions(-)