xdp_return_buff() always releases the fragments and the head with napi_direct = true, which is only valid when the caller runs in the NAPI context that owns the page pool. Drivers also need to release an xdp_buff while tearing down or resetting a queue, where NAPI is not running and direct recycling must be disabled. Split the implementation into __xdp_return_buff(), which takes the napi_direct argument and is exported for drivers, and keep xdp_return_buff() as an inline wrapper that passes true, preserving the behavior of the existing callers. This lets stmmac use the common helper with napi_direct = false on the teardown paths. Signed-off-by: Lorenzo Bianconi --- include/net/xdp.h | 7 ++++++- net/core/xdp.c | 9 +++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/net/xdp.h b/include/net/xdp.h index 3400775d179b..2fc972f71509 100644 --- a/include/net/xdp.h +++ b/include/net/xdp.h @@ -484,7 +484,12 @@ void __xdp_return(netmem_ref netmem, enum xdp_mem_type mem_type, bool napi_direct, struct xdp_buff *xdp); void xdp_return_frame(struct xdp_frame *xdpf); void xdp_return_frame_rx_napi(struct xdp_frame *xdpf); -void xdp_return_buff(struct xdp_buff *xdp); +void __xdp_return_buff(struct xdp_buff *xdp, bool napi_direct); +static inline void xdp_return_buff(struct xdp_buff *xdp) +{ + __xdp_return_buff(xdp, true); +} + void xdp_return_frame_bulk(struct xdp_frame *xdpf, struct xdp_frame_bulk *bq); diff --git a/net/core/xdp.c b/net/core/xdp.c index acad82982d77..1dbcec0b31ff 100644 --- a/net/core/xdp.c +++ b/net/core/xdp.c @@ -546,7 +546,7 @@ void xdp_return_frag(netmem_ref netmem, const struct xdp_buff *xdp) } EXPORT_SYMBOL_GPL(xdp_return_frag); -void xdp_return_buff(struct xdp_buff *xdp) +void __xdp_return_buff(struct xdp_buff *xdp, bool napi_direct) { struct skb_shared_info *sinfo; @@ -556,12 +556,13 @@ void xdp_return_buff(struct xdp_buff *xdp) sinfo = xdp_get_shared_info_from_buff(xdp); for (u32 i = 0; i < sinfo->nr_frags; i++) __xdp_return(skb_frag_netmem(&sinfo->frags[i]), - xdp->rxq->mem.type, true, xdp); + xdp->rxq->mem.type, napi_direct, xdp); out: - __xdp_return(virt_to_netmem(xdp->data), xdp->rxq->mem.type, true, xdp); + __xdp_return(virt_to_netmem(xdp->data), xdp->rxq->mem.type, + napi_direct, xdp); } -EXPORT_SYMBOL_GPL(xdp_return_buff); +EXPORT_SYMBOL_GPL(__xdp_return_buff); void xdp_attachment_setup(struct xdp_attachment_info *info, struct netdev_bpf *bpf) -- 2.56.1