fbnic still handles RX heads by page address, so an XDP-only provider cannot back its RX pool. Let the header page pool take an XDP-only provider, and handle heads as netmem. The payload ring shares that pool, so both rings fill from the provider, and header-split packets reach the program as multi-buffer packets. Skip the prefetch of XDP-only heads, which may cost a page walk. Size the page pool of such a queue in the pages that the rings may post, as the provider checks that size against its chunks. A device that is down creates no page pool on ring changes, so refuse to grow its BDQs with -EBUSY while a queue has such a provider, rather than fail the next open. On a running device, the provider checks the new pool first. Signed-off-by: Björn Töpel --- Notes (v2changes): Changes in v2: - v1 patch 9, "eth: fbnic: Support XDP redirect", was posted to net-next on its own and is a dependency. - Refuse to grow the BDQs while the device is down and a queue has such a provider, as nothing checks them before the next open, and size the page pool for the provider in the pages that the BDQs post (Sashiko). - The message now says that the payload ring shares the header page pool, so both rings fill from the provider. .../net/ethernet/meta/fbnic/fbnic_ethtool.c | 22 ++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 41 +++++++++++-------- drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 8 ++++ 3 files changed, 54 insertions(+), 17 deletions(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c b/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c index 9714a89977fa..3355aadeb8ff 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "fbnic.h" #include "fbnic_netdev.h" @@ -341,6 +342,16 @@ static void fbnic_set_rings(struct fbnic_net *fbn, fbn->hds_thresh = kernel_ring->hds_thresh; } +static bool fbnic_has_xdp_only_mp(struct net_device *netdev) +{ + unsigned int i; + + for (i = 0; i < netdev->real_num_rx_queues; i++) + if (netif_rxq_has_xdp_only_mp(netdev, i)) + return true; + return false; +} + static int fbnic_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring, struct kernel_ethtool_ringparam *kernel_ring, @@ -386,6 +397,17 @@ fbnic_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring, } if (!netif_running(netdev)) { + /* No page pool lets the provider check larger rings before + * the device opens, which would then fail + */ + if (fbnic_bdq_pages(ring->rx_mini_pending, + ring->rx_jumbo_pending) > + fbnic_bdq_pages(fbn->hpq_size, fbn->ppq_size) && + fbnic_has_xdp_only_mp(netdev)) { + NL_SET_ERR_MSG_MOD(extack, + "Cannot grow the BDQs while the device is down and a queue has an XDP-only memory provider"); + return -EBUSY; + } fbnic_set_rings(fbn, ring, kernel_ring); return 0; } diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c index 9525ad2f7e14..22e9fa5f8f15 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c @@ -765,15 +765,14 @@ static void fbnic_page_pool_init(struct fbnic_ring *ring, unsigned int idx, rx_buf->netmem = netmem; } -static struct page * +static netmem_ref fbnic_page_pool_get_head(struct fbnic_q_triad *qt, unsigned int idx) { struct fbnic_rx_buf *rx_buf = &qt->sub0.rx_buf[idx]; rx_buf->pagecnt_bias--; - /* sub0 is always fed system pages, from the NAPI-level page_pool */ - return netmem_to_page(rx_buf->netmem); + return rx_buf->netmem; } static netmem_ref @@ -1001,13 +1000,12 @@ static void fbnic_pkt_prepare(struct fbnic_napi_vector *nv, u64 rcd, unsigned int len = FIELD_GET(FBNIC_RCD_AL_BUFF_LEN_MASK, rcd); unsigned int hdr_pg_idx = fbnic_rcd_bd_idx(&qt->sub0, rcd); unsigned int frame_sz, hdr_pg_start, hdr_pg_end, headroom; - unsigned char *hdr_start; - struct page *page; + netmem_ref netmem; /* data_hard_start should always be NULL when this is called */ WARN_ON_ONCE(pkt->buff.data_hard_start); - page = fbnic_page_pool_get_head(qt, hdr_pg_idx); + netmem = fbnic_page_pool_get_head(qt, hdr_pg_idx); /* Short-cut the end calculation if we know page is fully consumed */ hdr_pg_end = FIELD_GET(FBNIC_RCD_AL_PAGE_FIN, rcd) ? @@ -1020,15 +1018,20 @@ static void fbnic_pkt_prepare(struct fbnic_napi_vector *nv, u64 rcd, hdr_pg_start += fbnic_rcd_bd_page_offset(&qt->sub0, rcd); /* Sync DMA buffer */ - dma_sync_single_range_for_cpu(nv->dev, page_pool_get_dma_addr(page), + dma_sync_single_range_for_cpu(nv->dev, + page_pool_get_dma_addr_netmem(netmem), hdr_pg_start, frame_sz, DMA_BIDIRECTIONAL); /* Build frame around buffer */ - hdr_start = page_address(page) + hdr_pg_start; - net_prefetch(hdr_start + headroom); - xdp_prepare_buff(&pkt->buff, hdr_start, headroom, - len - FBNIC_RX_PAD, true); + xdp_prepare_buff(&pkt->buff, xdp_netmem_address(netmem) + hdr_pg_start, + headroom, len - FBNIC_RX_PAD, true); + pkt->head = netmem; + /* The kernel reads an XDP-only head only if the program does, and a + * prefetch may cost a page walk + */ + if (!netmem_is_net_iov(netmem)) + net_prefetch(pkt->buff.data); pkt->hwtstamp = 0; pkt->add_frag_failed = false; @@ -1072,8 +1075,6 @@ static void fbnic_add_rx_frag(struct fbnic_napi_vector *nv, u64 rcd, static void fbnic_put_pkt_buff(struct fbnic_q_triad *qt, struct fbnic_pkt_buff *pkt, int budget) { - struct page *page; - if (!pkt->buff.data_hard_start) return; @@ -1092,8 +1093,7 @@ static void fbnic_put_pkt_buff(struct fbnic_q_triad *qt, } } - page = virt_to_page(pkt->buff.data_hard_start); - page_pool_put_full_page(qt->sub0.page_pool, page, !!budget); + page_pool_put_full_netmem(qt->sub0.page_pool, pkt->head, !!budget); } static struct sk_buff *fbnic_build_skb(struct fbnic_napi_vector *nv, @@ -1612,7 +1612,8 @@ fbnic_alloc_qt_page_pools(struct fbnic_net *fbn, struct fbnic_q_triad *qt, struct page_pool_params pp_params = { .order = 0, .flags = PP_FLAG_DMA_MAP | - PP_FLAG_DMA_SYNC_DEV, + PP_FLAG_DMA_SYNC_DEV | + PP_FLAG_ALLOW_XDP_ONLY_NETMEM, .pool_size = fbn->hpq_size + fbn->ppq_size, .nid = NUMA_NO_NODE, .dev = fbn->netdev->dev.parent, @@ -1632,8 +1633,14 @@ fbnic_alloc_qt_page_pools(struct fbnic_net *fbn, struct fbnic_q_triad *qt, * NAPI_POLL_WEIGHT possibly make more sense? The question is how * may pages do we need to hold in reserve to get the best return * without hogging too much system memory. + * + * An XDP-only provider checks the size against its chunks, so it + * must see every page that the rings may post. */ - if (pp_params.pool_size > 32768) + if (netif_rxq_has_xdp_only_mp(fbn->netdev, rxq_idx)) + pp_params.pool_size = fbnic_bdq_pages(fbn->hpq_size, + fbn->ppq_size); + else if (pp_params.pool_size > 32768) pp_params.pool_size = 32768; pp = page_pool_create(&pp_params); diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h index a61ac2df7c03..03b668ff8a42 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h @@ -81,6 +81,7 @@ struct fbnic_net; struct fbnic_pkt_buff { struct xdp_buff buff; + netmem_ref head; ktime_t hwtstamp; bool add_frag_failed; }; @@ -185,6 +186,13 @@ static inline u16 fbnic_bd_page_count(const struct fbnic_ring *bdq) return 1U << bdq->bd_page_shift; } +static inline u32 fbnic_bdq_pages(u32 hpq_size, u32 ppq_size) +{ + u32 shift = ilog2(PAGE_SIZE / FBNIC_BD_PAGE_SIZE); + + return (hpq_size >> shift) + (ppq_size >> shift); +} + netdev_tx_t fbnic_xmit_frame(struct sk_buff *skb, struct net_device *dev); netdev_features_t fbnic_features_check(struct sk_buff *skb, struct net_device *dev, -- 2.56.1