Christmas 3-serie XDP for idpf (+generic stuff)
Subsystems (11)
Alexander Lobakin
maintainercover Christmas 3-serie XDP for idpf (+generic stuff)
I was highly asked to send this WIP before the holidays to trigger some discussions at least for the generic parts.
This all depends on libie[0] and WB-on-ITR fix[1]. The RFC does not guarantee to work perfectly, but at least regular XDP seems to work for me...
In fact, here are 3 separate series:
* 01-08: convert idpf to libie and make it more sane;
* 09-25: add XDP to idpf;
* 26-34: add XSk to idpf.
Most people may want to be interested only in the following generic changes:
* 11: allow attaching already registered memory models to XDP RxQ info;
* 12-13: generic helpers for adding a frag to &xdp_buff and converting it to an skb;
* 14: get rid of xdp_frame::mem.id, allow mixing pages from different page_pools within one &xdp_buff/&xdp_frame;
* 15: some Page Pool helper;
* 18: it's for libie, but I wanted to talk about XDP_TX bulking;
* 26: same as 13, but for converting XSK &xdp_buff to skb.
The rest is up to you, driver-specific stuff is pretty boring sometimes.
I'll be polishing and finishing this all starting January 3rd and then preparing and sending sane series, some early feedback never hurts tho.
Merry Yule!
[0] https://lore.kernel.org/netdev/[email protected]
[1] https://lore.kernel.org/netdev/[email protected]
Alexander Lobakin (23):
idpf: reuse libie's definitions of parsed ptype structures
idpf: pack &idpf_queue way more efficiently
idpf: remove legacy Page Pool Ethtool stats
libie: support different types of buffers for Rx
idpf: convert header split mode to libie + napi_build_skb()
idpf: use libie Rx buffer management for payload buffer
libie: add Tx buffer completion helpers
idpf: convert to libie Tx buffer completion
bpf, xdp: constify some bpf_prog * function arguments
xdp: constify read-only arguments of some static inline helpers
xdp: allow attaching already registered memory model to xdp_rxq_info
xdp: add generic xdp_buff_add_frag()
xdp: add generic xdp_build_skb_from_buff()
xdp: get rid of xdp_frame::mem.id
page_pool: add inline helper to sync VA for device (for XDP_TX)
jump_label: export static_key_slow_{inc,dec}_cpuslocked()
libie: support native XDP and register memory model
libie: add a couple of XDP helpers
idpf: stop using macros for accessing queue descriptors
idpf: use generic functions to build xdp_buff and skb
idpf: add support for XDP on Rx
idpf: add support for .ndo_xdp_xmit()
xdp: add generic XSk xdp_buff -> skb conversion
Michal Kubiak (11):
idpf: make complq cleaning dependent on scheduling mode
idpf: prepare structures to support xdp
idpf: implement XDP_SETUP_PROG in ndo_bpf for splitq
idpf: add support for sw interrupt
idpf: add relative queue id member to idpf_queue
idpf: add vc functions to manage selected queues
idpf: move search rx and tx queues to header
idpf: add XSk pool initialization
idpf: implement Tx path for AF_XDP
idpf: implement Rx path for AF_XDP
idpf: enable XSk features and ndo_xsk_wakeup
.../net/ethernet/freescale/dpaa/dpaa_eth.c | 2 +- drivers/net/ethernet/intel/Kconfig | 3 +- drivers/net/ethernet/intel/idpf/Makefile | 3 + drivers/net/ethernet/intel/idpf/idpf.h | 91 +- drivers/net/ethernet/intel/idpf/idpf_dev.c | 3 + .../net/ethernet/intel/idpf/idpf_ethtool.c | 74 +- .../net/ethernet/intel/idpf/idpf_lan_txrx.h | 6 +- drivers/net/ethernet/intel/idpf/idpf_lib.c | 40 +- drivers/net/ethernet/intel/idpf/idpf_main.c | 1 + .../ethernet/intel/idpf/idpf_singleq_txrx.c | 221 ++- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 1142 ++++++++-------- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 451 +++---- drivers/net/ethernet/intel/idpf/idpf_vf_dev.c | 3 + .../net/ethernet/intel/idpf/idpf_virtchnl.c | 1132 ++++++++++------ drivers/net/ethernet/intel/idpf/idpf_xdp.c | 522 ++++++++ drivers/net/ethernet/intel/idpf/idpf_xdp.h | 38 + drivers/net/ethernet/intel/idpf/idpf_xsk.c | 1181 +++++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_xsk.h | 30 + drivers/net/ethernet/intel/libie/Makefile | 3 + drivers/net/ethernet/intel/libie/rx.c | 135 +- drivers/net/ethernet/intel/libie/tx.c | 16 + drivers/net/ethernet/intel/libie/xdp.c | 50 + drivers/net/ethernet/intel/libie/xsk.c | 49 + drivers/net/veth.c | 4 +- include/linux/bpf.h | 12 +- include/linux/filter.h | 9 +- include/linux/net/intel/libie/rx.h | 25 +- include/linux/net/intel/libie/tx.h | 94 ++ include/linux/net/intel/libie/xdp.h | 586 ++++++++ include/linux/net/intel/libie/xsk.h | 172 +++ include/linux/netdevice.h | 6 +- include/linux/skbuff.h | 14 +- include/net/page_pool/helpers.h | 32 + include/net/page_pool/types.h | 6 +- include/net/xdp.h | 109 +- kernel/bpf/cpumap.c | 2 +- kernel/bpf/devmap.c | 8 +- kernel/jump_label.c | 2 + net/bpf/test_run.c | 6 +- net/core/dev.c | 8 +- net/core/filter.c | 27 +- net/core/page_pool.c | 31 +- net/core/xdp.c | 189 ++- 43 files changed, 4971 insertions(+), 1567 deletions(-) create mode 100644 drivers/net/ethernet/intel/idpf/idpf_xdp.c create mode 100644 drivers/net/ethernet/intel/idpf/idpf_xdp.h create mode 100644 drivers/net/ethernet/intel/idpf/idpf_xsk.c create mode 100644 drivers/net/ethernet/intel/idpf/idpf_xsk.h create mode 100644 drivers/net/ethernet/intel/libie/tx.c create mode 100644 drivers/net/ethernet/intel/libie/xdp.c create mode 100644 drivers/net/ethernet/intel/libie/xsk.c create mode 100644 include/linux/net/intel/libie/tx.h create mode 100644 include/linux/net/intel/libie/xdp.h create mode 100644 include/linux/net/intel/libie/xsk.h
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 1/34 idpf: reuse libie's definitions of parsed ptype structures
idpf's in-kernel parsed ptype structure is almost identical to the one used in the previous Intel drivers, which means it can be converted to use libie's definitions and even helpers. The only difference is that it doesn't use a constant table, rather than one obtained from the device.
Remove the driver counterpart and use libie's helpers for hashes and checksums. This slightly optimizes skb fields processing due to faster checks.
--- drivers/net/ethernet/intel/Kconfig | 1 + drivers/net/ethernet/intel/idpf/idpf.h | 2 +- drivers/net/ethernet/intel/idpf/idpf_main.c | 1 + .../ethernet/intel/idpf/idpf_singleq_txrx.c | 87 +++++++-------- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 101 ++++++------------ drivers/net/ethernet/intel/idpf/idpf_txrx.h | 88 +-------------- .../net/ethernet/intel/idpf/idpf_virtchnl.c | 54 ++++++---- 7 files changed, 110 insertions(+), 224 deletions(-)
drivers/net/ethernet/intel/Kconfig +1 -0
@@ -378,6 +378,7 @@ config IDPF tristate "Intel(R) Infrastructure Data Path Function Support" depends on PCI_MSI select DIMLIB + select LIBIE select PAGE_POOL select PAGE_POOL_STATS help
drivers/net/ethernet/intel/idpf/idpf.h +1 -1
@@ -385,7 +385,7 @@ struct idpf_vport {u16 num_rxq_grp;struct idpf_rxq_group *rxq_grps;u32 rxq_model; -struct idpf_rx_ptype_decoded rx_ptype_lkup[IDPF_RX_MAX_PTYPE ]; +struct libie_rx_ptype_parsed rx_ptype_lkup[IDPF_RX_MAX_PTYPE ];struct idpf_adapter *adapter;struct net_device *netdev;
drivers/net/ethernet/intel/idpf/idpf_main.c +1 -0
@@ -7,6 +7,7 @@#define DRV_SUMMARY "Intel(R) Infrastructure Data Path Function Linux Driver"MODULE_DESCRIPTION (DRV_SUMMARY ); +MODULE_IMPORT_NS (LIBIE );MODULE_LICENSE ("GPL" );/**
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +39 -48
221 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_txrx.c +30 -71
199 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_txrx.h +5 -83
112 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +33 -21
135 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH RFC net-next 01/34] idpf: reuse libie's definitions of parsed ptype structures
Quoted 140 lines · Alexander Lobakin
idpf's in-kernel parsed ptype structure is almost identical to the one used in the previous Intel drivers, which means it can be converted to use libie's definitions and even helpers. The only difference is that it doesn't use a constant table, rather than one obtained from the device.
Remove the driver counterpart and use libie's helpers for hashes and checksums. This slightly optimizes skb fields processing due to faster checks.Signed-off-by Alexander Lobakin <[email protected]>--- drivers/net/ethernet/intel/Kconfig | 1 + drivers/net/ethernet/intel/idpf/idpf.h | 2 +- drivers/net/ethernet/intel/idpf/idpf_main.c | 1 + .../ethernet/intel/idpf/idpf_singleq_txrx.c | 87 +++++++-------- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 101 ++++++------------ drivers/net/ethernet/intel/idpf/idpf_txrx.h | 88 +-------------- .../net/ethernet/intel/idpf/idpf_virtchnl.c | 54 ++++++---- 7 files changed, 110 insertions(+), 224 deletions(-)drivers/net/ethernet/intel/Kconfig +1
-0@@ -378,6 +378,7 @@ config IDPF tristate "Intel(R) Infrastructure Data Path Function Support" depends on PCI_MSI select DIMLIB + select LIBIE select PAGE_POOL select PAGE_POOL_STATS helpdrivers/net/ethernet/intel/idpf/idpf.h +1
-1@@ -385,7 +385,7 @@ struct idpf_vport {u16 num_rxq_grp;struct idpf_rxq_group *rxq_grps;u32 rxq_model; -struct idpf_rx_ptype_decoded rx_ptype_lkup[IDPF_RX_MAX_PTYPE ]; +struct libie_rx_ptype_parsed rx_ptype_lkup[IDPF_RX_MAX_PTYPE ];struct idpf_adapter *adapter;struct net_device *netdev;drivers/net/ethernet/intel/idpf/idpf_main.c +1
-0@@ -7,6 +7,7 @@#define DRV_SUMMARY "Intel(R) Infrastructure Data Path Function Linux Driver"MODULE_DESCRIPTION (DRV_SUMMARY ); +MODULE_IMPORT_NS (LIBIE );MODULE_LICENSE ("GPL" );/** drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +14
-19@@ -636,75 +636,64 @@ static bool idpf_rx_singleq_is_non_eop(struct idpf_queue *rxq,* @rxq: Rx ring being processed * @skb: skb currently being received and modified * @csum_bits: checksum bits from descriptor -* @ptype: the packet type decoded by hardware +* @parsed: the packet type parsed by hardware * * skb->protocol must be set before this function is called */ static void idpf_rx_singleq_csum (struct idpf_queue *rxq,struct sk_buff *skb, -struct idpf_rx_csum_decoded *csum_bits, -u16 ptype) +struct idpf_rx_csum_decoded csum_bits, +struct libie_rx_ptype_parsed parsed) { -struct idpf_rx_ptype_decoded decoded;bool ipv4, ipv6;/* check if Rx checksum is enabled */ -if (unlikely (!(rxq->vport->netdev->features &NETIF_F_RXCSUM ))) +if (!libie_has_rx_checksum (rxq->vport->netdev, parsed))return ;/* check if HW has decoded the packet and checksum */ -if (unlikely (!(csum_bits->l3l4p))) +if (unlikely (!csum_bits.l3l4p))return ; - decoded = rxq->vport->rx_ptype_lkup[ptype]; -if (unlikely (!(decoded.known && decoded.outer_ip))) +if (unlikely (parsed.outer_ip ==LIBIE_RX_PTYPE_OUTER_L2 ))return ; - ipv4 =IDPF_RX_PTYPE_TO_IPV (&decoded,IDPF_RX_PTYPE_OUTER_IPV4 ); - ipv6 =IDPF_RX_PTYPE_TO_IPV (&decoded,IDPF_RX_PTYPE_OUTER_IPV6 ); + ipv4 = parsed.outer_ip ==LIBIE_RX_PTYPE_OUTER_IPV4 ; + ipv6 = parsed.outer_ip ==LIBIE_RX_PTYPE_OUTER_IPV6 ;/* Check if there were any checksum errors */ -if (unlikely (ipv4 && (csum_bits->ipe || csum_bits->eipe))) +if (unlikely (ipv4 && (csum_bits.ipe || csum_bits.eipe))) goto checksum_fail;/* Device could not do any checksum offload for certain extension * headers as indicated by setting IPV6EXADD bit */ -if (unlikely (ipv6 && csum_bits->ipv6exadd)) +if (unlikely (ipv6 && csum_bits.ipv6exadd))return ;/* check for L4 errors and handle packets that were not able to be * checksummed due to arrival speed */ -if (unlikely (csum_bits->l4e)) +if (unlikely (csum_bits.l4e)) goto checksum_fail; -if (unlikely (csum_bits->nat && csum_bits->eudpe)) +if (unlikely (csum_bits.nat && csum_bits.eudpe)) goto checksum_fail;/* Handle packets that were not able to be checksummed due to arrival * speed, in this case the stack can compute the csum. */ -if (unlikely (csum_bits->pprs)) +if (unlikely (csum_bits.pprs))return ;/* If there is an outer header present that might contain a checksum * we need to bump the checksum level by 1 to reflect the fact that * we are indicating we validated the inner checksum. */ -if (decoded.tunnel_type >=IDPF_RX_PTYPE_TUNNEL_IP_GRENAT ) +if (parsed.tunnel_type >=LIBIE_RX_PTYPE_TUNNEL_IP_GRENAT ) skb->csum_level =1 ; -/* Only report checksum unnecessary for ICMP, TCP, UDP, or SCTP */ -switch (decoded.inner_prot) { -case IDPF_RX_PTYPE_INNER_PROT_ICMP :
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c static bool idpf_rx_singleq_is_non_eop(struct idpf_queue *rxq, · line 696
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +2
-8-case IDPF_RX_PTYPE_INNER_PROT_TCP : -case IDPF_RX_PTYPE_INNER_PROT_UDP : -case IDPF_RX_PTYPE_INNER_PROT_SCTP : - skb->ip_summed =CHECKSUM_UNNECESSARY ; -return ; -default : -return ; - } + skb->ip_summed =CHECKSUM_UNNECESSARY ; +return ;
Is it intentional to change from CHECKSUM_NONE to CHECKSUM_UNNECESSARY in the default case?
I suppose so, as idpf_rx_csum (the splitq equivalent) does the same (bar CHECKSUM_COMPLETE depending on descriptor bit).
Alexander Lobakin
maintainerRe: [PATCH RFC net-next 01/34] idpf: reuse libie's definitions of parsed ptype structures
From: Willem De Bruijn <[email protected]>
Date: Wed, 27 Dec 2023 10:43:34 -0500
Quoted 6 lines
Quoted 5 lines · Alexander Lobakin
idpf's in-kernel parsed ptype structure is almost identical to the one used in the previous Intel drivers, which means it can be converted to use libie's definitions and even helpers. The only difference is that it doesn't use a constant table, rather than one obtained from the device.
[...]
Quoted 67 lines
Quoted 67 lines
static void idpf_rx_singleq_csum(struct
idpf_queue*rxq, structsk_buff*skb,drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +13
-15- struct idpf_rx_csum_decoded *csum_bits, - u16 ptype) +struct idpf_rx_csum_decoded csum_bits, + struct libie_rx_ptype_parsed parsed) { -struct idpf_rx_ptype_decoded decoded; bool ipv4, ipv6;/* check if Rx checksum is enabled */ -if (unlikely (!(rxq->vport->netdev->features &NETIF_F_RXCSUM ))) +if (!libie_has_rx_checksum (rxq->vport->netdev, parsed))return ;/* check if HW has decoded the packet and checksum */ -if (unlikely (!(csum_bits->l3l4p))) +if (unlikely (!csum_bits.l3l4p))return ; - decoded = rxq->vport->rx_ptype_lkup[ptype]; -if (unlikely (!(decoded.known && decoded.outer_ip))) +if (unlikely (parsed.outer_ip ==LIBIE_RX_PTYPE_OUTER_L2 ))return ; - ipv4 =IDPF_RX_PTYPE_TO_IPV (&decoded,IDPF_RX_PTYPE_OUTER_IPV4 ); - ipv6 =IDPF_RX_PTYPE_TO_IPV (&decoded,IDPF_RX_PTYPE_OUTER_IPV6 ); + ipv4 = parsed.outer_ip ==LIBIE_RX_PTYPE_OUTER_IPV4 ; + ipv6 = parsed.outer_ip ==LIBIE_RX_PTYPE_OUTER_IPV6 ;/* Check if there were any checksum errors */ -if (unlikely (ipv4 && (csum_bits->ipe || csum_bits->eipe))) +if (unlikely (ipv4 && (csum_bits.ipe || csum_bits.eipe))) goto checksum_fail;/* Device could not do any checksum offload for certain extension * headers as indicated by setting IPV6EXADD bit */ -if (unlikely (ipv6 && csum_bits->ipv6exadd)) +if (unlikely (ipv6 && csum_bits.ipv6exadd))return ;/* check for L4 errors and handle packets that were not able to be * checksummed due to arrival speed */ -if (unlikely (csum_bits->l4e)) +if (unlikely (csum_bits.l4e)) goto checksum_fail; -if (unlikely (csum_bits->nat && csum_bits->eudpe)) +if (unlikely (csum_bits.nat && csum_bits.eudpe)) goto checksum_fail;/* Handle packets that were not able to be checksummed due to arrival * speed, in this case the stack can compute the csum. */ -if (unlikely (csum_bits->pprs)) +if (unlikely (csum_bits.pprs))return ;/* If there is an outer header present that might contain a checksum * we need to bump the checksum level by 1 to reflect the fact that * we are indicating we validated the inner checksum. */ -if (decoded.tunnel_type >=IDPF_RX_PTYPE_TUNNEL_IP_GRENAT ) +if (parsed.tunnel_type >=LIBIE_RX_PTYPE_TUNNEL_IP_GRENAT ) skb->csum_level =1 ;
Quoted 16 lines
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c static bool idpf_rx_singleq_is_non_eop(struct idpf_queue *rxq, · line 696
Quoted 13 lines
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +2
-11-/* Only report checksum unnecessary for ICMP, TCP, UDP, or SCTP */ -switch (decoded.inner_prot) { -case IDPF_RX_PTYPE_INNER_PROT_ICMP : -case IDPF_RX_PTYPE_INNER_PROT_TCP : -case IDPF_RX_PTYPE_INNER_PROT_UDP : -case IDPF_RX_PTYPE_INNER_PROT_SCTP : - skb->ip_summed =CHECKSUM_UNNECESSARY ; -return ; -default : -return ; - } + skb->ip_summed =CHECKSUM_UNNECESSARY ; +return ;Is it intentional to change from
CHECKSUM_NONEtoCHECKSUM_UNNECESSARYin the default case?
The basic logic wasn't changed. libie_has_rx_checksum() checks if the protocol can be checksummed by HW at the beginning of the function instead of the end (why calculate and check all this if the proto is not supported?).
Quoted 3 lines
I suppose so, as
idpf_rx_csum(the splitq equivalent) does the same (barCHECKSUM_COMPLETEdepending on descriptor bit).
Thanks,
Olek
Alexander Lobakin
maintainerRFC PATCH 2/34 idpf: pack &idpf_queue way more efficiently
In reply to Alexander LobakinCurrently, sizeof(struct idpf_queue) is 32 Kb.
This is due to the 12-bit hashtable declaration at the end of the queue. This HT is needed only for Tx queues when the flow scheduling mode is enabled. But &idpf_queue is unified for all of the queue types, provoking excessive memory usage.
Instead, allocate those hashtables dynamically only when needed at the moment of Tx queues initialization.
Next, reshuffle queue fields to reduce holes and ensure better cacheline locality. Ideally, &idpf_queue must be split into 4, as lots of fields are used only in 1 or 2 types, but for now, just unionize as much as we can.
--- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 58 ++++++++++++----- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 72 ++++++++++++++------- 2 files changed, 91 insertions(+), 39 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_txrx.c +43 -15
@@ -179,6 +179,9 @@ static int idpf_tx_buf_alloc_all(struct idpf_queue *tx_q)for (i =0 ; i < tx_q->desc_count; i++) tx_q->tx_buf[i].compl_tag =IDPF_SPLITQ_TX_INVAL_COMPL_TAG ; +if (!test_bit (__IDPF_Q_FLOW_SCH_EN, tx_q->flags)) +return 0 ; +/* Initialize tx buf stack for out-of-order completions if * flow scheduling offload is enabled */
@@ -801,11 +804,16 @@ static int idpf_rx_desc_alloc_all(struct idpf_vport *vport)*/ static void idpf_txq_group_rel (struct idpf_vport *vport) { +bool split, flow_sch_en;int i, j;if (!vport->txq_grps)return ; + split =idpf_is_queue_model_split (vport->txq_model); + flow_sch_en = !idpf_is_cap_ena (vport->adapter,IDPF_OTHER_CAPS , +VIRTCHNL2_CAP_SPLITQ_QSCHED ); +for (i =0 ; i < vport->num_txq_grp; i++) {struct idpf_txq_group *txq_grp = &vport->txq_grps[i];
@@ -813,8 +821,15 @@ static void idpf_txq_group_rel(struct idpf_vport *vport)kfree (txq_grp->txqs[j]); txq_grp->txqs[j] =NULL ; } + +if (!split) +continue ; +kfree (txq_grp->complq); txq_grp->complq =NULL ; + +if (flow_sch_en) +kfree (txq_grp->hashes); }kfree (vport->txq_grps); vport->txq_grps =NULL ;
@@ -1157,20 +1172,22 @@ static void idpf_rxq_set_descids(struct idpf_vport *vport, struct idpf_queue *q)*/ static int idpf_txq_group_alloc (struct idpf_vport *vport,u16 num_txq) { -bool flow_sch_en; -int err, i; +bool split, flow_sch_en; +int i; vport->txq_grps =kcalloc (vport->num_txq_grp,sizeof (*vport->txq_grps),GFP_KERNEL );if (!vport->txq_grps)return -ENOMEM ; + split =idpf_is_queue_model_split (vport->txq_model); flow_sch_en = !idpf_is_cap_ena (vport->adapter,IDPF_OTHER_CAPS ,VIRTCHNL2_CAP_SPLITQ_QSCHED );for (i =0 ; i < vport->num_txq_grp; i++) {struct idpf_txq_group *tx_qgrp = &vport->txq_grps[i];struct idpf_adapter *adapter = vport->adapter; +struct idpf_txq_hash *hashes;int j; tx_qgrp->vport = vport;
@@ -1179,10 +1196,16 @@ static int idpf_txq_group_alloc(struct idpf_vport *vport, u16 num_txq)for (j =0 ; j < tx_qgrp->num_txq; j++) { tx_qgrp->txqs[j] =kzalloc (sizeof (*tx_qgrp->txqs[j]),GFP_KERNEL ); -if (!tx_qgrp->txqs[j]) { - err = -ENOMEM ; +if (!tx_qgrp->txqs[j]) goto err_alloc; - } + } + +if (split && flow_sch_en) { + hashes =kcalloc (num_txq,sizeof (*hashes),GFP_KERNEL ); +if (!hashes) + goto err_alloc; + + tx_qgrp->hashes = hashes; }for (j =0 ; j < tx_qgrp->num_txq; j++) {
@@ -1194,22 +1217,26 @@ static int idpf_txq_group_alloc(struct idpf_vport *vport, u16 num_txq) q->tx_min_pkt_len =idpf_get_min_tx_pkt_len (adapter); q->vport = vport; q->txq_grp = tx_qgrp; -hash_init (q->sched_buf_hash); -if (flow_sch_en) -set_bit (__IDPF_Q_FLOW_SCH_EN, q->flags); +if (!flow_sch_en) +continue ; + +if (split) { + q->sched_buf_hash = &hashes[j]; +hash_init (q->sched_buf_hash->hash); + } + +set_bit (__IDPF_Q_FLOW_SCH_EN, q->flags); } -if (!idpf_is_queue_model_split (vport->txq_model)) +if (!split)continue ; tx_qgrp->complq =kcalloc (IDPF_COMPLQ_PER_GROUP ,sizeof (*tx_qgrp->complq),GFP_KERNEL ); -if (!tx_qgrp->complq) { - err = -ENOMEM ; +if (!tx_qgrp->complq) goto err_alloc; - } tx_qgrp->complq->dev = &adapter->pdev->dev; tx_qgrp->complq->desc_count = vport->complq_desc_count;
@@ -1225,7 +1252,7 @@ static int idpf_txq_group_alloc(struct idpf_vport *vport, u16 num_txq) err_alloc:idpf_txq_group_rel (vport); -return err; +return -ENOMEM ; }/**
@@ -1512,7 +1539,7 @@ static void idpf_tx_clean_stashed_bufs(struct idpf_queue *txq, u16 compl_tag,struct hlist_node *tmp_buf;/* Buffer completion */ -hash_for_each_possible_safe (txq->sched_buf_hash, stash, tmp_buf, +hash_for_each_possible_safe (txq->sched_buf_hash->hash, stash, tmp_buf, hlist, compl_tag) {if (unlikely (stash->buf.compl_tag != (int )compl_tag))continue ;
@@ -1567,7 +1594,8 @@ static int idpf_stash_flow_sch_buffers(struct idpf_queue *txq, stash->buf.compl_tag = tx_buf->compl_tag;/* Add buffer to buf_hash table to be freed later */ -hash_add (txq->sched_buf_hash, &stash->hlist, stash->buf.compl_tag); +hash_add (txq->sched_buf_hash->hash, &stash->hlist, + stash->buf.compl_tag);memset (tx_buf,0 ,sizeof (struct idpf_tx_buf ));
drivers/net/ethernet/intel/idpf/idpf_txrx.h +48 -24
112 lines not on this page · raw message
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 3/34 idpf: remove legacy Page Pool Ethtool stats
In reply to Alexander LobakinPage Pool Ethtool stats are deprecated since the Netlink Page Pool interface introduction.
idpf receives big changes in Rx buffer management, including &page_pool layout, so keeping these deprecated stats does only harm, not speaking of that CONFIG_IDPF selects CONFIG_PAGE_POOL_STATS unconditionally, while the latter is often turned off for better performance. Remove all the references to PP stats from the Ethtool code. The stats are still available in their full via the generic Netlink interface.
--- drivers/net/ethernet/intel/Kconfig | 1 - .../net/ethernet/intel/idpf/idpf_ethtool.c | 29 +------------------ 2 files changed, 1 insertion(+), 29 deletions(-)
drivers/net/ethernet/intel/Kconfig +0 -1
@@ -380,7 +380,6 @@ config IDPF select DIMLIB select LIBIE select PAGE_POOL - select PAGE_POOL_STATS help This driver supports Intel(R) Infrastructure Data Path Function devices.
drivers/net/ethernet/intel/idpf/idpf_ethtool.c +1 -28
@@ -571,8 +571,6 @@ static void idpf_get_stat_strings(struct net_device *netdev, u8 *data)for (i =0 ; i < vport_config->max_q.max_rxq; i++)idpf_add_qstat_strings (&data, idpf_gstrings_rx_queue_stats,"rx" , i); - -page_pool_ethtool_stats_get_strings (data); }/**
@@ -606,7 +604,6 @@ static int idpf_get_sset_count(struct net_device *netdev, int sset)struct idpf_netdev_priv *np =netdev_priv (netdev);struct idpf_vport_config *vport_config;u16 max_txq, max_rxq; -unsigned int size;if (sset !=ETH_SS_STATS )return -EINVAL ;
@@ -625,11 +622,8 @@ static int idpf_get_sset_count(struct net_device *netdev, int sset) max_txq = vport_config->max_q.max_txq; max_rxq = vport_config->max_q.max_rxq; - size =IDPF_PORT_STATS_LEN + (IDPF_TX_QUEUE_STATS_LEN * max_txq) + +return IDPF_PORT_STATS_LEN + (IDPF_TX_QUEUE_STATS_LEN * max_txq) + (IDPF_RX_QUEUE_STATS_LEN * max_rxq); - size +=page_pool_ethtool_stats_get_count (); - -return size; }/**
@@ -877,7 +871,6 @@ static void idpf_get_ethtool_stats(struct net_device *netdev, {struct idpf_netdev_priv *np =netdev_priv (netdev);struct idpf_vport_config *vport_config; -struct page_pool_stats pp_stats = { };struct idpf_vport *vport;unsigned int total =0 ;unsigned int i, j;
@@ -947,32 +940,12 @@ static void idpf_get_ethtool_stats(struct net_device *netdev,idpf_add_empty_queue_stats (&data, qtype); else idpf_add_queue_stats(&data, rxq); - -/* In splitq mode, don't get page pool stats here since -* the pools are attached to the buffer queues -*/ -if (is_splitq) -continue ; - -if (rxq) -page_pool_get_stats (rxq->pp, &pp_stats); - } - } - -for (i =0 ; i < vport->num_rxq_grp; i++) { -for (j =0 ; j < vport->num_bufqs_per_qgrp; j++) { -struct idpf_queue *rxbufq = - &vport->rxq_grps[i].splitq.bufq_sets[j].bufq; - -page_pool_get_stats (rxbufq->pp, &pp_stats); } }for (; total < vport_config->max_q.max_rxq; total++)idpf_add_empty_queue_stats (&data,VIRTCHNL2_QUEUE_TYPE_RX ); -page_pool_ethtool_stats_get (data, &pp_stats); -rcu_read_unlock ();idpf_vport_ctrl_unlock (netdev);
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 4/34 libie: support different types of buffers for Rx
In reply to Alexander LobakinUnlike previous generations, idpf requires more buffer types for optimal performance. This includes: header buffers, short buffers, and no-overhead buffers (w/o headroom and tailroom, for TCP zerocopy when the header split is enabled).
Introduce libie Rx buffer type and calculate page_pool params accordingly. All the HW-related details like buffer alignment are still accounted. For the header buffers, pick 256 bytes as in most places in the kernel (have you ever seen frames with bigger headers?).
--- drivers/net/ethernet/intel/libie/rx.c | 107 +++++++++++++++++++++++--- include/linux/net/intel/libie/rx.h | 19 +++++ 2 files changed, 115 insertions(+), 11 deletions(-)
drivers/net/ethernet/intel/libie/rx.c +96 -11
@@ -6,14 +6,14 @@/* Rx buffer management */ /** -* libie_rx_hw_len - get the actual buffer size to be passed to HW +* libie_rx_hw_len_mtu - get the actual buffer size to be passed to HW * @pp: &page_pool_params of the netdev to calculate the size for * * Return: HW-writeable length per one buffer to pass it to the HW accounting: * MTU the @dev has, HW required alignment, minimum and maximum allowed values, * and system's page size. */ -static u32 libie_rx_hw_len (const struct page_pool_params *pp) +static u32 libie_rx_hw_len_mtu (const struct page_pool_params *pp) {u32 len;
@@ -24,6 +24,96 @@ static u32 libie_rx_hw_len(const struct page_pool_params *pp)return len; } +/** +* libie_rx_hw_len_truesize - get the short buffer size to be passed to HW +* @pp: &page_pool_params of the netdev to calculate the size for +* @truesize: desired truesize for the buffers +* +* Return: HW-writeable length per one buffer to pass it to the HW ignoring the +* MTU and closest to the passed truesize. Can be used for "short" buffer +* queues to fragment pages more efficiently. +*/ +static u32 libie_rx_hw_len_truesize (const struct page_pool_params *pp, +u32 truesize) +{ +u32 min, len; + + min =SKB_HEAD_ALIGN (pp->offset +LIBIE_RX_BUF_LEN_ALIGN ); + truesize =clamp (roundup_pow_of_two (truesize),roundup_pow_of_two (min), +PAGE_SIZE <<LIBIE_RX_PAGE_ORDER ); + + len =SKB_WITH_OVERHEAD (truesize - pp->offset); + len =ALIGN_DOWN (len,LIBIE_RX_BUF_LEN_ALIGN ); + len =clamp (len,LIBIE_MIN_RX_BUF_LEN , pp->max_len); + +return len; +} + +static void libie_rx_page_pool_params (struct libie_buf_queue *bq, +struct page_pool_params *pp) +{ + pp->offset =LIBIE_SKB_HEADROOM ; +/* HW-writeable / syncable length per one page */ + pp->max_len =LIBIE_RX_BUF_LEN (pp->offset); + +/* HW-writeable length per buffer */ +switch (bq->type) { +case LIBIE_RX_BUF_MTU : + bq->rx_buf_len =libie_rx_hw_len_mtu (pp); +break ; +case LIBIE_RX_BUF_SHORT : + bq->rx_buf_len =libie_rx_hw_len_truesize (pp, bq->truesize); +break ; +case LIBIE_RX_BUF_HDR : + bq->rx_buf_len =ALIGN (LIBIE_MAX_HEAD ,LIBIE_RX_BUF_LEN_ALIGN ); +break ; +default : +break ; + } + +/* Buffer size to allocate */ + bq->truesize =roundup_pow_of_two (SKB_HEAD_ALIGN (pp->offset + + bq->rx_buf_len)); +} + +/** +* libie_rx_page_pool_params_zc - calculate params without the stack overhead +* @bq: buffer queue to calculate the size for +* @pp: &page_pool_params of the netdev +* +* Adjusts the PP params to exclude the stack overhead and sets both the buffer +* lengh and the truesize, which are equal for the data buffers. Note that this +* requires separate header buffers to be always active and account the +* overhead. +* With the MTU == ``PAGE_SIZE``, this allows the kernel to enable the zerocopy +* mode. +*/ +static bool libie_rx_page_pool_params_zc (struct libie_buf_queue *bq, +struct page_pool_params *pp) +{ +u32 mtu; + + pp->offset =0 ; + pp->max_len =PAGE_SIZE <<LIBIE_RX_PAGE_ORDER ; + +switch (bq->type) { +case LIBIE_RX_BUF_MTU : + mtu =READ_ONCE (pp->netdev->mtu); +break ; +case LIBIE_RX_BUF_SHORT : + mtu = bq->truesize; +break ; +default : +return false; + } + + bq->rx_buf_len =clamp (roundup_pow_of_two (mtu),LIBIE_RX_BUF_LEN_ALIGN , + pp->max_len); + bq->truesize = bq->rx_buf_len; + +return true; +} +/** * libie_rx_page_pool_create - create a PP with the default libie settings * @bq: buffer queue struct to fill
@@ -43,17 +133,12 @@ int libie_rx_page_pool_create(struct libie_buf_queue *bq, .netdev = napi->dev, .napi = napi, .dma_dir = DMA_FROM_DEVICE, - .offset = LIBIE_SKB_HEADROOM, }; -/* HW-writeable / syncable length per one page */ - pp.max_len =LIBIE_RX_BUF_LEN (pp.offset); - -/* HW-writeable length per buffer */ - bq->rx_buf_len =libie_rx_hw_len (&pp); -/* Buffer size to allocate */ - bq->truesize =roundup_pow_of_two (SKB_HEAD_ALIGN (pp.offset + - bq->rx_buf_len)); +if (!bq->hsplit) +libie_rx_page_pool_params (bq, &pp); +else if (!libie_rx_page_pool_params_zc (bq, &pp)) +return -EINVAL ; bq->pp =page_pool_create (&pp);
include/linux/net/intel/libie/rx.h +19 -0
@@ -19,6 +19,8 @@#define LIBIE_MAX_HEADROOM LIBIE_SKB_HEADROOM/* Link layer / L2 overhead: Ethernet, 2 VLAN tags (C + S), FCS */ #define LIBIE_RX_LL_LEN (ETH_HLEN + 2 * VLAN_HLEN + ETH_FCS_LEN) +/* Maximum supported L2-L4 header length */ +#define LIBIE_MAX_HEAD 256/* Always use order-0 pages */ #define LIBIE_RX_PAGE_ORDER 0
@@ -64,6 +66,18 @@ struct libie_rx_buffer {u32 truesize; }; +/** +* enum libie_rx_buf_type - enum representing types of Rx buffers +* @LIBIE_RX_BUF_MTU: buffer size is determined by MTU +* @LIBIE_RX_BUF_SHORT: buffer size is smaller than MTU, for short frames +* @LIBIE_RX_BUF_HDR: buffer size is ```LIBIE_MAX_HEAD```-sized, for headers +*/ +enum libie_rx_buf_type { +LIBIE_RX_BUF_MTU =0U , +LIBIE_RX_BUF_SHORT , +LIBIE_RX_BUF_HDR , +}; +/** * struct libie_buf_queue - structure representing a buffer queue * @pp: &page_pool for buffer management
@@ -71,6 +85,8 @@ struct libie_rx_buffer {* @truesize: size to allocate per buffer, w/overhead * @count: number of descriptors/buffers the queue has * @rx_buf_len: HW-writeable length per each buffer +* @type: type of the buffers this queue has +* @hsplit: flag whether header split is enabled */ struct libie_buf_queue {struct page_pool *pp;
@@ -81,6 +97,9 @@ struct libie_buf_queue {/* Cold fields */ u32 rx_buf_len; + enum libie_rx_buf_type type:2; + + bool hsplit:1; }; int libie_rx_page_pool_create(struct libie_buf_queue *bq,
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 5/34 idpf: convert header split mode to libie + napi_build_skb()
In reply to Alexander LobakinCurrently, idpf uses the following model for the header buffers:
* buffers are allocated via dma_alloc_coherent();
* when receiving, napi_alloc_skb() is called and then the header is copied to the newly allocated linear part.
This is far from optimal as DMA coherent zone is slow on many systems and memcpy() neutralizes the idea and benefits of the header split. Instead, use libie to create page_pools for the header buffers, allocate them dynamically and then build an skb via napi_build_skb() around them with no memory copy. With one exception...
When you enable header split, you except you'll always have a separate header buffer, so that you could reserve headroom and tailroom only there and then use full buffers for the data. For example, this is how TCP zerocopy works -- you have to have the payload aligned to PAGE_SIZE. The current hardware running idpf does *not* guarantee that you'll always have headers placed separately. For example, on my setup, even ICMP packets are written as one piece to the data buffers. You can't build a valid skb around a data buffer in this case.
To not complicate things and not lose TCP zerocopy etc., when such thing happens, use the empty header buffer and pull either full frame (if it's short) or the Ethernet header there and build an skb around it. GRO layer will pull more from the data buffer later. This W/A will hopefully be removed one day.
--- .../ethernet/intel/idpf/idpf_singleq_txrx.c | 2 + drivers/net/ethernet/intel/idpf/idpf_txrx.c | 219 +++++++++++------- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 23 +- .../net/ethernet/intel/idpf/idpf_virtchnl.c | 14 +- 4 files changed, 159 insertions(+), 99 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +2 -0
@@ -868,6 +868,8 @@ static void idpf_rx_singleq_process_skb_fields(struct idpf_queue *rx_q,idpf_rx_singleq_flex_hash (rx_q, skb, rx_desc, parsed);idpf_rx_singleq_flex_csum (rx_q, skb, rx_desc, parsed); } + +skb_record_rx_queue (skb, rx_q->idx); }/**
drivers/net/ethernet/intel/idpf/idpf_txrx.c +138 -81
377 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_txrx.h +9 -14
@@ -99,8 +99,6 @@ do { \#define IDPF_RX_BUF_STRIDE 32#define IDPF_RX_BUF_POST_STRIDE 16#define IDPF_LOW_WATERMARK 64 -/* Size of header buffer specifically for header split */ -#define IDPF_HDR_BUF_SIZE 256#define IDPF_PACKET_HDR_PAD \ (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN * 2)#define IDPF_TX_TSO_MIN_MSS 88
@@ -315,16 +313,10 @@ struct idpf_rx_extracted {#define IDPF_TX_MAX_DESC_DATA_ALIGNED \ ALIGN_DOWN(IDPF_TX_MAX_DESC_DATA, IDPF_TX_MAX_READ_REQ_SIZE) -#define IDPF_RX_DMA_ATTR \ - (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING)#define IDPF_RX_DESC (rxq, i) \ (&(((union virtchnl2_rx_desc *)((rxq)->desc_ring))[i])) -struct idpf_rx_buf { -struct page *page; -unsigned int page_offset; -u16 truesize; -}; +#define idpf_rx_buf libie_rx_buffer#define IDPF_RX_MAX_PTYPE_PROTO_IDS 32#define IDPF_RX_MAX_PTYPE_SZ (sizeof(struct virtchnl2_ptype) + \
@@ -627,13 +619,15 @@ struct idpf_queue {union {struct idpf_tx_buf *tx_buf;struct { +struct libie_rx_buffer *hdr_buf;struct idpf_rx_buf *buf; -dma_addr_t hdr_buf_pa; -void *hdr_buf_va; } rx_buf; }; +struct page_pool *hdr_pp;struct page_pool *pp;void *desc_ring; + +u32 hdr_truesize;u16 idx;u16 q_type;u32 q_id;
@@ -885,7 +879,7 @@ static inline dma_addr_t idpf_alloc_page(struct page_pool *pool, unsigned int buf_size) {if (buf_size ==IDPF_RX_BUF_2048 ) - buf->page =page_pool_dev_alloc_frag (pool, &buf->page_offset, + buf->page =page_pool_dev_alloc_frag (pool, &buf->offset, buf_size);else buf->page =page_pool_dev_alloc_pages (pool);
@@ -895,7 +889,7 @@ static inline dma_addr_t idpf_alloc_page(struct page_pool *pool, buf->truesize = buf_size; -return page_pool_get_dma_addr (buf->page) + buf->page_offset + +return page_pool_get_dma_addr (buf->page) + buf->offset + pool->p.offset; }
@@ -922,7 +916,7 @@ static inline void idpf_rx_sync_for_cpu(struct idpf_rx_buf *rx_buf, u32 len)dma_sync_single_range_for_cpu (pp->p.dev,page_pool_get_dma_addr (page), - rx_buf->page_offset + pp->p.offset, len, + rx_buf->offset + pp->p.offset, len,page_pool_get_dma_dir (pp)); }
@@ -970,6 +964,7 @@ void idpf_rx_add_frag(struct idpf_rx_buf *rx_buf, struct sk_buff *skb,struct sk_buff *idpf_rx_construct_skb (struct idpf_queue *rxq,struct idpf_rx_buf *rx_buf,unsigned int size); +struct sk_buff *idpf_rx_build_skb (const struct libie_rx_buffer *buf,u32 size);bool idpf_init_rx_buf_hw_alloc (struct idpf_queue *rxq,struct idpf_rx_buf *buf);void idpf_rx_buf_hw_update (struct idpf_queue *rxq,u32 val); void idpf_tx_buf_hw_update(struct idpf_queue *tx_q, u32 val,
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +10 -4
@@ -1636,32 +1636,38 @@ static int idpf_send_config_rx_queues_msg(struct idpf_vport *vport) num_rxq = rx_qgrp->singleq.num_rxq;for (j =0 ; j < num_rxq; j++, k++) { +const struct idpf_bufq_set *sets;struct idpf_queue *rxq;if (!idpf_is_queue_model_split (vport->rxq_model)) { rxq = rx_qgrp->singleq.rxqs[j]; goto common_qi_fields; } + rxq = &rx_qgrp->splitq.rxq_sets[j]->rxq; - qi[k].rx_bufq1_id = -cpu_to_le16 (rxq->rxq_grp->splitq.bufq_sets[0 ].bufq.q_id); + sets = rxq->rxq_grp->splitq.bufq_sets; + + qi[k].rx_bufq1_id =cpu_to_le16 (sets[0 ].bufq.q_id);if (vport->num_bufqs_per_qgrp >IDPF_SINGLE_BUFQ_PER_RXQ_GRP ) { qi[k].bufq2_ena =IDPF_BUFQ2_ENA ; qi[k].rx_bufq2_id = -cpu_to_le16 (rxq->rxq_grp->splitq.bufq_sets[1 ].bufq.q_id); +cpu_to_le16 (sets[1 ].bufq.q_id); } qi[k].rx_buffer_low_watermark =cpu_to_le16 (rxq->rx_buffer_low_watermark);if (idpf_is_feature_ena (vport,NETIF_F_GRO_HW )) qi[k].qflags |=cpu_to_le16 (VIRTCHNL2_RXQ_RSC ); -common_qi_fields: + rxq->rx_hbuf_size = sets[0 ].bufq.rx_hbuf_size; +if (rxq->rx_hsplit_en) { qi[k].qflags |=cpu_to_le16 (VIRTCHNL2_RXQ_HDR_SPLIT ); qi[k].hdr_buffer_size =cpu_to_le16 (rxq->rx_hbuf_size); } + +common_qi_fields: qi[k].queue_id =cpu_to_le32 (rxq->q_id); qi[k].model =cpu_to_le16 (vport->rxq_model); qi[k].type =cpu_to_le32 (rxq->q_type);
Signature · 1 line
2.43.0
Re: [PATCH RFC net-next 05/34] idpf: convert header split mode to libie + napi_build_skb()
Quoted 8 lines · Alexander Lobakin
Currently, idpf uses the following model for the header buffers:
* buffers are allocated via
dma_alloc_coherent();
* when receiving,napi_alloc_skb()is called and then the header is copied to the newly allocated linear part.This is far from optimal as DMA coherent zone is slow on many systems and
memcpy()neutralizes the idea and benefits of the header split.
Do you have data showing this?
The assumption for the current model is that the headers will be touched shortly after, so the copy just primes the cache.
The single coherently allocated region for all headers reduces IOTLB pressure.
It is possible that the alternative model is faster. But that is not trivially obvious.
I think patches like this can stand on their own. Probably best to leave them out of the dependency series to enable XDP and AF_XDP.
Quoted 18 lines
Instead, use libie to create
page_poolsfor the header buffers, allocate them dynamically and then build an skb vianapi_build_skb()around them with no memory copy. With one exception...
When you enable header split, you except you'll always have a separate header buffer, so that you could reserve headroom and tailroom only there and then use full buffers for the data. For example, this is how TCP zerocopy works -- you have to have the payload aligned toPAGE_SIZE. The current hardware running idpf does *not* guarantee that you'll always have headers placed separately. For example, on my setup, even ICMP packets are written as one piece to the data buffers. You can't build a valid skb around a data buffer in this case.
To not complicate things and not lose TCP zerocopy etc., when such thing happens, use the empty header buffer and pull either full frame (if it's short) or the Ethernet header there and build an skb around it. GRO layer will pull more from the data buffer later. This W/A will hopefully be removed one day.Signed-off-by Alexander Lobakin <[email protected]>
Alexander Lobakin
maintainerRe: [PATCH RFC net-next 05/34] idpf: convert header split mode to libie + napi_build_skb()
From: Willem De Bruijn <[email protected]>
Date: Wed, 27 Dec 2023 10:30:48 -0500
Quoted 11 lines
Quoted 8 lines · Alexander Lobakin
Currently, idpf uses the following model for the header buffers:
* buffers are allocated via
dma_alloc_coherent();
* when receiving,napi_alloc_skb()is called and then the header is copied to the newly allocated linear part.This is far from optimal as DMA coherent zone is slow on many systems and
memcpy()neutralizes the idea and benefits of the header split.Do you have data showing this?
Showing slow coherent DMA or memcpy()?
Try MIPS for the first one.
For the second -- try comparing performance on ice with the "legacy-rx" private flag disabled and enabled.
Quoted 3 lines
The assumption for the current model is that the headers will be touched shortly after, so the copy just primes the cache.
They won't be touched in many cases. E.g. XDP_DROP.
Or headers can be long. memcpy(32) != memcpy(128).
The current model allocates a new skb with a linear part, which is a real memory allocation. napi_build_skb() doesn't allocate anything except struct sk_buff, which is usually available in the NAPI percpu cache. If build_skb() wasn't more effective, it wouldn't be introduced. The current model just assumes default socket traffic with ~40-byte headers and no XDP etc.
Quoted 3 lines
The single coherently allocated region for all headers reduces IOTLB pressure.
page_pool pages are mapped once at allocation.
Quoted 6 lines
It is possible that the alternative model is faster. But that is not trivially obvious.
I think patches like this can stand on their own. Probably best to leave them out of the dependency series to enable XDP and
AF_XDP.
You can't do XDP on DMA coherent zone. To do this memcpy(), you need allocate a new skb with a linear part, which is usually done after XDP, otherwise it's too much overhead and little-to-no benefits comparing to generic skb XDP.
The current idpf code is just not compatible with the XDP code in this series, it's pointless to do double work.
Disabling header split when XDP is enabled (alternative option) means disabling TCP zerocopy and worse performance in general, I don't consider this.
Quoted 18 lines
Quoted 18 lines
Instead, use libie to create
page_poolsfor the header buffers, allocate them dynamically and then build an skb vianapi_build_skb()around them with no memory copy. With one exception...
When you enable header split, you except you'll always have a separate header buffer, so that you could reserve headroom and tailroom only there and then use full buffers for the data. For example, this is how TCP zerocopy works -- you have to have the payload aligned toPAGE_SIZE. The current hardware running idpf does *not* guarantee that you'll always have headers placed separately. For example, on my setup, even ICMP packets are written as one piece to the data buffers. You can't build a valid skb around a data buffer in this case.
To not complicate things and not lose TCP zerocopy etc., when such thing happens, use the empty header buffer and pull either full frame (if it's short) or the Ethernet header there and build an skb around it. GRO layer will pull more from the data buffer later. This W/A will hopefully be removed one day.
Quoted 1 line
Quoted 1 line
Signed-off-by Alexander Lobakin <[email protected]>
Thanks,
Olek
Re: [PATCH RFC net-next 05/34] idpf: convert header split mode to libie + napi_build_skb()
Quoted 53 lines · Alexander Lobakin
From: Willem De Bruijn <[email protected]>
Date: Wed, 27 Dec 2023 10:30:48 -0500Quoted 11 lines
Quoted 8 lines · Alexander Lobakin
Currently, idpf uses the following model for the header buffers:
* buffers are allocated via
dma_alloc_coherent();
* when receiving,napi_alloc_skb()is called and then the header is copied to the newly allocated linear part.This is far from optimal as DMA coherent zone is slow on many systems and
memcpy()neutralizes the idea and benefits of the header split.Do you have data showing this?
Showing slow coherent DMA or
memcpy()?
Try MIPS for the first one.
For the second -- try comparing performance on ice with the "legacy-rx" private flag disabled and enabled.Quoted 3 lines
The assumption for the current model is that the headers will be touched shortly after, so the copy just primes the cache.
They won't be touched in many cases. E.g.
XDP_DROP.
Or headers can be long. memcpy(32) != memcpy(128).
The current model allocates a new skb with a linear part, which is a real memory allocation.napi_build_skb()doesn't allocate anything except structsk_buff, which is usually available in the NAPI percpu cache. Ifbuild_skb()wasn't more effective, it wouldn't be introduced. The current model just assumes default socket traffic with ~40-byte headers and no XDP etc.Quoted 3 lines
The single coherently allocated region for all headers reduces IOTLB pressure.
page_poolpages are mapped once at allocation.Quoted 6 lines
It is possible that the alternative model is faster. But that is not trivially obvious.
I think patches like this can stand on their own. Probably best to leave them out of the dependency series to enable XDP and
AF_XDP.You can't do XDP on DMA coherent zone. To do this
memcpy(), you need allocate a new skb with a linear part, which is usually done after XDP, otherwise it's too much overhead and little-to-no benefits comparing to generic skb XDP.
The current idpf code is just not compatible with the XDP code in this series, it's pointless to do double work.
Quoted 3 lines
Disabling header split when XDP is enabled (alternative option) means disabling TCP zerocopy and worse performance in general, I don't consider this.
My concern is if optimizations for XDP might degrade the TCP/IP common path. XDP_DROP and all of XDP even is a niche feature by comparison.
The current driver behavior was not the first for IDPF, but arrived at based on extensive performance debugging. An earlier iteration used separate header buffers. Switching to a single coherent allocated buffer region significantly increased throughput / narrowed the gap between header-split and non-header-split mode.
I follow your argument and the heuristics are reasonable. My request is only that this decision is based on real data for this driver and modern platforms. We cannot regress TCP/IP hot path performance.
Alexander Lobakin
maintainerRe: [PATCH RFC net-next 05/34] idpf: convert header split mode to libie + napi_build_skb()
From: Willem De Bruijn <[email protected]>
Date: Tue, 09 Jan 2024 08:59:27 -0500
Quoted 54 lines
Quoted 53 lines · Alexander Lobakin
From: Willem De Bruijn <[email protected]>
Date: Wed, 27 Dec 2023 10:30:48 -0500Quoted 11 lines
Quoted 8 lines · Alexander Lobakin
Currently, idpf uses the following model for the header buffers:
* buffers are allocated via
dma_alloc_coherent();
* when receiving,napi_alloc_skb()is called and then the header is copied to the newly allocated linear part.This is far from optimal as DMA coherent zone is slow on many systems and
memcpy()neutralizes the idea and benefits of the header split.Do you have data showing this?
Showing slow coherent DMA or
memcpy()?
Try MIPS for the first one.
For the second -- try comparing performance on ice with the "legacy-rx" private flag disabled and enabled.Quoted 3 lines
The assumption for the current model is that the headers will be touched shortly after, so the copy just primes the cache.
They won't be touched in many cases. E.g.
XDP_DROP.
Or headers can be long. memcpy(32) != memcpy(128).
The current model allocates a new skb with a linear part, which is a real memory allocation.napi_build_skb()doesn't allocate anything except structsk_buff, which is usually available in the NAPI percpu cache. Ifbuild_skb()wasn't more effective, it wouldn't be introduced. The current model just assumes default socket traffic with ~40-byte headers and no XDP etc.Quoted 3 lines
The single coherently allocated region for all headers reduces IOTLB pressure.
page_poolpages are mapped once at allocation.Quoted 6 lines
It is possible that the alternative model is faster. But that is not trivially obvious.
I think patches like this can stand on their own. Probably best to leave them out of the dependency series to enable XDP and
AF_XDP.You can't do XDP on DMA coherent zone. To do this
memcpy(), you need allocate a new skb with a linear part, which is usually done after XDP, otherwise it's too much overhead and little-to-no benefits comparing to generic skb XDP.
The current idpf code is just not compatible with the XDP code in this series, it's pointless to do double work.
Quoted 5 lines
Quoted 3 lines
Disabling header split when XDP is enabled (alternative option) means disabling TCP zerocopy and worse performance in general, I don't consider this.
My concern is if optimizations for XDP might degrade the TCP/IP common
We take care of this. Please don't think that my team allows perf degradation when developing stuff, it's not true.
Quoted 11 lines
path.
XDP_DROPand all of XDP even is a niche feature by comparison.The current driver behavior was not the first for IDPF, but arrived at based on extensive performance debugging. An earlier iteration used separate header buffers. Switching to a single coherent allocated buffer region significantly increased throughput / narrowed the gap between header-split and non-header-split mode.
I follow your argument and the heuristics are reasonable. My request is only that this decision is based on real data for this driver and modern platforms. We cannot regress TCP/IP hot path performance.
Sure, I'll provide numbers in the next iteration. Please go ahead with further review (if you're interested).
Thanks,
Olek
Re: [PATCH RFC net-next 05/34] idpf: convert header split mode to libie + napi_build_skb()
In reply to Alexander LobakinQuoted 17 lines · Alexander Lobakin
Currently, idpf uses the following model for the header buffers:
* buffers are allocated via
dma_alloc_coherent();
* when receiving,napi_alloc_skb()is called and then the header is copied to the newly allocated linear part.This is far from optimal as DMA coherent zone is slow on many systems and
memcpy()neutralizes the idea and benefits of the header split. Instead, use libie to createpage_poolsfor the header buffers, allocate them dynamically and then build an skb vianapi_build_skb()around them with no memory copy. With one exception...
When you enable header split, you except you'll always have a separate header buffer, so that you could reserve headroom and tailroom only there and then use full buffers for the data. For example, this is how TCP zerocopy works -- you have to have the payload aligned toPAGE_SIZE. The current hardware running idpf does *not* guarantee that you'll
Quoted 8 lines
always have headers placed separately. For example, on my setup, even ICMP packets are written as one piece to the data buffers. You can't build a valid skb around a data buffer in this case.
To not complicate things and not lose TCP zerocopy etc., when such thing happens, use the empty header buffer and pull either full frame (if it's short) or the Ethernet header there and build an skb around it. GRO layer will pull more from the data buffer later. This W/A will hopefully be removed one day.
We definitely want performance numbers here, for systems that truly matter.
We spent a lot of time trying to make idpf slightly better than it was, we do not want regressions.
Thank you.
Alexander Lobakin
maintainerRFC PATCH 6/34 idpf: use libie Rx buffer management for payload buffer
In reply to Alexander Lobakinidpf uses Page Pool for data buffers with hardcoded buffer lengths of 4k for "classic" buffers and 2k for "short" ones. This is not flexible and does not ensure optimal memory usage. Why would you need 4k buffers when the MTU is 1500?
Use libie for the data buffers and don't hardcode any buffer sizes. Let them be calculated from the MTU for "classics" and then divide the truesize by 2 for "short" ones. The memory usage is now greatly reduced and 2 buffer queues starts make sense: on frames <= 1024, you'll recycle (and resync) a page only after 4 HW writes rather than two.
--- drivers/net/ethernet/intel/Kconfig | 1 - drivers/net/ethernet/intel/idpf/idpf.h | 1 - .../ethernet/intel/idpf/idpf_singleq_txrx.c | 24 +-- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 194 ++++++------------ drivers/net/ethernet/intel/idpf/idpf_txrx.h | 70 +------ .../net/ethernet/intel/idpf/idpf_virtchnl.c | 8 +- 6 files changed, 88 insertions(+), 210 deletions(-)
drivers/net/ethernet/intel/Kconfig +0 -1
@@ -379,7 +379,6 @@ config IDPF depends on PCI_MSI select DIMLIB select LIBIE - select PAGE_POOL help This driver supports Intel(R) Infrastructure Data Path Function devices.
drivers/net/ethernet/intel/idpf/idpf.h +0 -1
@@ -381,7 +381,6 @@ struct idpf_vport {u32 rxq_desc_count;u8 num_bufqs_per_qgrp;u32 bufq_desc_count[IDPF_MAX_BUFQS_PER_RXQ_GRP ]; -u32 bufq_size[IDPF_MAX_BUFQS_PER_RXQ_GRP ];u16 num_rxq_grp;struct idpf_rxq_group *rxq_grps;u32 rxq_model;
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +12 -12
@@ -883,20 +883,24 @@ bool idpf_rx_singleq_buf_hw_alloc_all(struct idpf_queue *rx_q, u16 cleaned_count) {struct virtchnl2_singleq_rx_buf_desc *desc; +const struct libie_buf_queue bq = { + .pp = rx_q->pp, + .rx_bi = rx_q->rx_buf.buf, + .truesize = rx_q->truesize, + .count = rx_q->desc_count, + };u16 nta = rx_q->next_to_alloc; -struct idpf_rx_buf *buf;if (!cleaned_count)return false; desc =IDPF_SINGLEQ_RX_BUF_DESC (rx_q, nta); - buf = &rx_q->rx_buf.buf[nta]; do { dma_addr_t addr; - addr = idpf_alloc_page(rx_q->pp, buf, rx_q->rx_buf_size); - if (unlikely(addr == DMA_MAPPING_ERROR)) + addr = libie_rx_alloc(&bq, nta); + if (addr == DMA_MAPPING_ERROR) break; /* Refresh the desc even if buffer_addrs didn't change
@@ -906,11 +910,9 @@ bool idpf_rx_singleq_buf_hw_alloc_all(struct idpf_queue *rx_q, desc->hdr_addr =0 ; desc++; - buf++; nta++;if (unlikely (nta == rx_q->desc_count)) { desc =IDPF_SINGLEQ_RX_BUF_DESC (rx_q,0 ); - buf = rx_q->rx_buf.buf; nta =0 ; }
@@ -1031,24 +1033,22 @@ static int idpf_rx_singleq_clean(struct idpf_queue *rx_q, int budget)idpf_rx_singleq_extract_fields (rx_q, rx_desc, &fields); rx_buf = &rx_q->rx_buf.buf[ntc]; -if (!fields.size) { -idpf_rx_put_page (rx_buf); +if (!libie_rx_sync_for_cpu (rx_buf, fields.size)) goto skip_data; - } -idpf_rx_sync_for_cpu (rx_buf, fields.size);if (skb)idpf_rx_add_frag (rx_buf, skb, fields.size);else - skb =idpf_rx_construct_skb (rx_q, rx_buf, fields.size); + skb =idpf_rx_build_skb (rx_buf, fields.size);/* exit if we failed to retrieve a buffer */ if (!skb)break ; skip_data: -IDPF_SINGLEQ_BUMP_RING_IDX (rx_q, ntc); + rx_buf->page =NULL ; +IDPF_SINGLEQ_BUMP_RING_IDX (rx_q, ntc); cleaned_count++;/* skip if it is non EOP desc */
drivers/net/ethernet/intel/idpf/idpf_txrx.c +63 -131
322 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_txrx.h +6 -64
106 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +7 -1
@@ -1647,6 +1647,12 @@ static int idpf_send_config_rx_queues_msg(struct idpf_vport *vport) rxq = &rx_qgrp->splitq.rxq_sets[j]->rxq; sets = rxq->rxq_grp->splitq.bufq_sets; +/* In splitq mode, RXQ buffer size should be +* set to that of the first buffer queue +* associated with this RXQ. +*/ + rxq->rx_buf_size = sets[0 ].bufq.rx_buf_size; + qi[k].rx_bufq1_id =cpu_to_le16 (sets[0 ].bufq.q_id);if (vport->num_bufqs_per_qgrp >IDPF_SINGLE_BUFQ_PER_RXQ_GRP ) { qi[k].bufq2_ena =IDPF_BUFQ2_ENA ;
@@ -3297,7 +3303,7 @@ void idpf_vport_init(struct idpf_vport *vport, struct idpf_vport_max_q *max_q) rss_data->rss_lut_size =le16_to_cpu (vport_msg->rss_lut_size);ether_addr_copy (vport->default_mac_addr, vport_msg->default_mac_addr); - vport->max_mtu =le16_to_cpu (vport_msg->max_mtu) -IDPF_PACKET_HDR_PAD ; + vport->max_mtu =le16_to_cpu (vport_msg->max_mtu) -LIBIE_RX_LL_LEN ;/* Initialize Tx and Rx profiles for Dynamic Interrupt Moderation */ memcpy (vport->rx_itr_profile, rx_itr,IDPF_DIM_PROFILE_SLOTS );
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 7/34 libie: add Tx buffer completion helpers
In reply to Alexander LobakinSoftware-side Tx buffers for storing DMA, frame size, skb pointers etc. are pretty much generic and every driver defines them the same way. The same can be said for software Tx completions -- same napi_consume_skb()s and all that...
Add a couple simple wrappers for doing that to stop repeating the old tale at least within the Intel code.
--- include/linux/net/intel/libie/tx.h | 88 ++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 include/linux/net/intel/libie/tx.h
include/linux/net/intel/libie/tx.h new file +88 -0
@@ -0,0 +1,88 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright(c) 2023 Intel Corporation. */ + +#ifndef __LIBIE_TX_H +#define __LIBIE_TX_H + +#include <linux/net/intel/libie/stats.h> +#include <linux/skbuff.h> + +/** +* enum libie_tx_buf_type - type of &libie_tx_buf to act on Tx completion +* @LIBIE_TX_BUF_EMPTY: unused OR XSk frame, no action required +* @LIBIE_TX_BUF_SLAB: kmalloc-allocated buffer, unmap and kfree() +* @LIBIE_TX_BUF_FRAG: mapped skb OR &xdp_buff frag, only unmap DMA +* @LIBIE_TX_BUF_SKB: &sk_buff, unmap and consume_skb(), update stats +* @LIBIE_TX_BUF_XDP_TX: &skb_shared_info, page_pool_put_full_page(), stats +* @LIBIE_TX_BUF_XDP_XMIT: &xdp_frame, unmap and xdp_return_frame(), stats +* @LIBIE_TX_BUF_XSK_TX: &xdp_buff on XSk queue, xsk_buff_free(), stats +*/ +enum libie_tx_buf_type { +LIBIE_TX_BUF_EMPTY =0U , +LIBIE_TX_BUF_SLAB , +LIBIE_TX_BUF_FRAG , +LIBIE_TX_BUF_SKB , +LIBIE_TX_BUF_XDP_TX , +LIBIE_TX_BUF_XDP_XMIT , +LIBIE_TX_BUF_XSK_TX , +}; + +struct libie_tx_buffer { +void *next_to_watch; +union { +void *raw; +struct sk_buff *skb; +struct skb_shared_info *sinfo; +struct xdp_frame *xdpf; +struct xdp_buff *xdp; + }; + +DEFINE_DMA_UNMAP_ADDR (dma); +DEFINE_DMA_UNMAP_LEN (len); + +u32 bytecount; +u16 gso_segs; +enum libie_tx_buf_type type:16 ; + +union { +int compl_tag; +bool ctx_entry; + }; +}; + +static inline void libie_tx_complete_buf (struct libie_tx_buffer *buf, +struct device *dev,bool napi, +struct libie_sq_onstack_stats *ss) +{ +switch (buf->type) { +case LIBIE_TX_BUF_EMPTY : +return ; +case LIBIE_TX_BUF_SLAB : +case LIBIE_TX_BUF_FRAG : +case LIBIE_TX_BUF_SKB : +dma_unmap_page (dev,dma_unmap_addr (buf, dma), +dma_unmap_len (buf, len), +DMA_TO_DEVICE ); +break ; +default : +break ; + } + +switch (buf->type) { +case LIBIE_TX_BUF_SLAB : +kfree (buf->raw); +break ; +case LIBIE_TX_BUF_SKB : + ss->packets += buf->gso_segs; + ss->bytes += buf->bytecount; + +napi_consume_skb (buf->skb, napi); +break ; +default : +break ; + } + + buf->type =LIBIE_TX_BUF_EMPTY ; +} + +#endif /* __LIBIE_TX_H */
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 8/34 idpf: convert to libie Tx buffer completion
In reply to Alexander Lobakin&idpf_tx_buffer is almost identical to the previous generations, as well as the way it's handled. Moreover, relying on dma_unmap_addr() and !!buf->skb instead of explicit defining of buffer's type was never good. Use the newly added libie helpers to do it properly and reduce the copy-paste around the Tx code.
--- .../ethernet/intel/idpf/idpf_singleq_txrx.c | 38 ++----- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 107 +++--------------- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 43 +------ 3 files changed, 31 insertions(+), 157 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +12 -26
@@ -190,6 +190,7 @@ static void idpf_tx_singleq_map(struct idpf_queue *tx_q,struct idpf_tx_buf *first, struct idpf_tx_offload_params *offloads) { + enum libie_tx_buf_type type = LIBIE_TX_BUF_SKB;u32 offsets = offloads->hdr_offsets;struct idpf_tx_buf *tx_buf = first;struct idpf_base_tx_desc *tx_desc;
@@ -219,6 +220,8 @@ static void idpf_tx_singleq_map(struct idpf_queue *tx_q,if (dma_mapping_error (tx_q->dev, dma))return idpf_tx_dma_map_error (tx_q, skb, first, i); + tx_buf->type = type; +/* record length, and DMA address */ dma_unmap_len_set (tx_buf, len, size);dma_unmap_addr_set (tx_buf, dma, dma);
@@ -270,6 +273,7 @@ static void idpf_tx_singleq_map(struct idpf_queue *tx_q, DMA_TO_DEVICE); tx_buf = &tx_q->tx_buf[i]; + type =LIBIE_TX_BUF_FRAG ; }skb_tx_timestamp (first->skb);
@@ -447,7 +451,7 @@ static bool idpf_tx_singleq_clean(struct idpf_queue *tx_q, int napi_budget, int *cleaned) {unsigned int budget = tx_q->vport->compln_clean_budget; -unsigned int total_bytes =0 , total_pkts =0 ; +struct libie_sq_onstack_stats ss = { };struct idpf_base_tx_desc *tx_desc;s16 ntc = tx_q->next_to_clean;struct idpf_netdev_priv *np;
@@ -495,20 +499,7 @@ static bool idpf_tx_singleq_clean(struct idpf_queue *tx_q, int napi_budget, tx_buf->next_to_watch =NULL ;/* update the statistics for this packet */ - total_bytes += tx_buf->bytecount; - total_pkts += tx_buf->gso_segs; - -napi_consume_skb (tx_buf->skb, napi_budget); - -/* unmap skb header data */ -dma_unmap_single (tx_q->dev, -dma_unmap_addr (tx_buf, dma), -dma_unmap_len (tx_buf, len), -DMA_TO_DEVICE ); - -/* clear tx_buf data */ - tx_buf->skb =NULL ; -dma_unmap_len_set (tx_buf, len,0 ); +libie_tx_complete_buf (tx_buf, tx_q->dev, !!napi_budget, &ss);/* unmap remaining buffers */ while (tx_desc != eop_desc) {
@@ -522,13 +513,8 @@ static bool idpf_tx_singleq_clean(struct idpf_queue *tx_q, int napi_budget, }/* unmap any remaining paged data */ -if (dma_unmap_len (tx_buf, len)) { -dma_unmap_page (tx_q->dev, -dma_unmap_addr (tx_buf, dma), -dma_unmap_len (tx_buf, len), -DMA_TO_DEVICE ); -dma_unmap_len_set (tx_buf, len,0 ); - } +libie_tx_complete_buf (tx_buf, tx_q->dev, !!napi_budget, + &ss); }/* update budget only if we did something */
@@ -548,11 +534,11 @@ static bool idpf_tx_singleq_clean(struct idpf_queue *tx_q, int napi_budget, ntc += tx_q->desc_count; tx_q->next_to_clean = ntc; - *cleaned += total_pkts; + *cleaned += ss.packets;u64_stats_update_begin (&tx_q->stats_sync); -u64_stats_add (&tx_q->q_stats.tx.packets, total_pkts); -u64_stats_add (&tx_q->q_stats.tx.bytes, total_bytes); +u64_stats_add (&tx_q->q_stats.tx.packets, ss.packets); +u64_stats_add (&tx_q->q_stats.tx.bytes, ss.bytes);u64_stats_update_end (&tx_q->stats_sync); vport = tx_q->vport;
@@ -561,7 +547,7 @@ static bool idpf_tx_singleq_clean(struct idpf_queue *tx_q, int napi_budget, dont_wake = np->state != __IDPF_VPORT_UP || !netif_carrier_ok (vport->netdev); -__netif_txq_completed_wake (nq, total_pkts, total_bytes, +__netif_txq_completed_wake (nq, ss.packets, ss.bytes,IDPF_DESC_UNUSED (tx_q),IDPF_TX_WAKE_THRESH , dont_wake);
drivers/net/ethernet/intel/idpf/idpf_txrx.c +16 -91
191 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_txrx.h +3 -40
61 lines not on this page · raw message
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 9/34 bpf, xdp: constify some bpf_prog * function arguments
In reply to Alexander LobakinIn lots of places, bpf_prog pointer is used only for tracing or other stuff that doesn't modify the structure itself. Same for net_device. Address at least some of them and add const attributes there. The object code didn't change, but that may prevent unwanted data modifications and also allow more helpers to have const arguments.
--- include/linux/bpf.h | 12 ++++++------ include/linux/filter.h | 9 +++++---- include/linux/netdevice.h | 6 +++--- kernel/bpf/devmap.c | 8 ++++---- net/core/dev.c | 8 ++++---- net/core/filter.c | 25 ++++++++++++++----------- 6 files changed, 36 insertions(+), 32 deletions(-)
include/linux/bpf.h +6 -6
@@ -2384,10 +2384,10 @@ int dev_map_enqueue(struct bpf_dtab_netdev *dst, struct xdp_frame *xdpf,int dev_map_enqueue_multi (struct xdp_frame *xdpf,struct net_device *dev_rx,struct bpf_map *map,bool exclude_ingress);int dev_map_generic_redirect (struct bpf_dtab_netdev *dst,struct sk_buff *skb, -struct bpf_prog *xdp_prog); +const struct bpf_prog *xdp_prog);int dev_map_redirect_multi (struct net_device *dev,struct sk_buff *skb, -struct bpf_prog *xdp_prog,struct bpf_map *map, -bool exclude_ingress); +const struct bpf_prog *xdp_prog, +struct bpf_map *map,bool exclude_ingress);void __cpu_map_flush (void ); int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_frame *xdpf,
@@ -2632,15 +2632,15 @@ struct sk_buff;static inline int dev_map_generic_redirect (struct bpf_dtab_netdev *dst,struct sk_buff *skb, -struct bpf_prog *xdp_prog) +const struct bpf_prog *xdp_prog) {return 0 ; }static inline int dev_map_redirect_multi (struct net_device *dev,struct sk_buff *skb, -struct bpf_prog *xdp_prog,struct bpf_map *map, -bool exclude_ingress) +const struct bpf_prog *xdp_prog, +struct bpf_map *map,bool exclude_ingress) {return 0 ; }
include/linux/filter.h +5 -4
@@ -1015,17 +1015,18 @@ static inline int xdp_ok_fwd_dev(const struct net_device *fwd,* This does not appear to be a real limitation for existing software. */ int xdp_do_generic_redirect (struct net_device *dev,struct sk_buff *skb, -struct xdp_buff *xdp,struct bpf_prog *prog); +struct xdp_buff *xdp,const struct bpf_prog *prog);int xdp_do_redirect (struct net_device *dev,struct xdp_buff *xdp, -struct bpf_prog *prog); +const struct bpf_prog *prog);int xdp_do_redirect_frame (struct net_device *dev,struct xdp_buff *xdp,struct xdp_frame *xdpf, -struct bpf_prog *prog); +const struct bpf_prog *prog);void xdp_do_flush (void ); -void bpf_warn_invalid_xdp_action (struct net_device *dev,struct bpf_prog *prog,u32 act); +void bpf_warn_invalid_xdp_action (const struct net_device *dev, +const struct bpf_prog *prog,u32 act);#ifdef CONFIG_INET struct sock *bpf_run_sk_reuseport(struct sock_reuseport *reuse, struct sock *sk,
include/linux/netdevice.h +3 -3
@@ -3956,9 +3956,9 @@ static inline void dev_consume_skb_any(struct sk_buff *skb) }u32 bpf_prog_run_generic_xdp (struct sk_buff *skb,struct xdp_buff *xdp, -struct bpf_prog *xdp_prog); -void generic_xdp_tx (struct sk_buff *skb,struct bpf_prog *xdp_prog); -int do_xdp_generic (struct bpf_prog *xdp_prog,struct sk_buff *skb); +const struct bpf_prog *xdp_prog); +void generic_xdp_tx (struct sk_buff *skb,const struct bpf_prog *xdp_prog); +int do_xdp_generic (const struct bpf_prog *xdp_prog,struct sk_buff *skb);int netif_rx (struct sk_buff *skb);int __netif_rx (struct sk_buff *skb);
kernel/bpf/devmap.c +4 -4
@@ -673,7 +673,7 @@ int dev_map_enqueue_multi(struct xdp_frame *xdpf, struct net_device *dev_rx, }int dev_map_generic_redirect (struct bpf_dtab_netdev *dst,struct sk_buff *skb, -struct bpf_prog *xdp_prog) +const struct bpf_prog *xdp_prog) {int err;
@@ -696,7 +696,7 @@ int dev_map_generic_redirect(struct bpf_dtab_netdev *dst, struct sk_buff *skb,static int dev_map_redirect_clone (struct bpf_dtab_netdev *dst,struct sk_buff *skb, -struct bpf_prog *xdp_prog) +const struct bpf_prog *xdp_prog) {struct sk_buff *nskb;int err;
@@ -715,8 +715,8 @@ static int dev_map_redirect_clone(struct bpf_dtab_netdev *dst, }int dev_map_redirect_multi (struct net_device *dev,struct sk_buff *skb, -struct bpf_prog *xdp_prog,struct bpf_map *map, -bool exclude_ingress) +const struct bpf_prog *xdp_prog, +struct bpf_map *map,bool exclude_ingress) { struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map);struct bpf_dtab_netdev *dst, *last_dst =NULL ;
net/core/dev.c +4 -4
@@ -4833,7 +4833,7 @@ static struct netdev_rx_queue *netif_get_rxqueue(struct sk_buff *skb) }u32 bpf_prog_run_generic_xdp (struct sk_buff *skb,struct xdp_buff *xdp, -struct bpf_prog *xdp_prog) +const struct bpf_prog *xdp_prog) {void *orig_data, *orig_data_end, *hard_start;struct netdev_rx_queue *rxqueue;
@@ -4922,7 +4922,7 @@ u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp,static u32 netif_receive_generic_xdp (struct sk_buff *skb,struct xdp_buff *xdp, -struct bpf_prog *xdp_prog) +const struct bpf_prog *xdp_prog) {u32 act =XDP_DROP ;
@@ -4979,7 +4979,7 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb,* and DDOS attacks will be more effective. In-driver-XDP use dedicated TX * queues, so they do not have this starvation issue. */ -void generic_xdp_tx (struct sk_buff *skb,struct bpf_prog *xdp_prog) +void generic_xdp_tx (struct sk_buff *skb,const struct bpf_prog *xdp_prog) {struct net_device *dev = skb->dev;struct netdev_queue *txq;
@@ -5004,7 +5004,7 @@ void generic_xdp_tx(struct sk_buff *skb, struct bpf_prog *xdp_prog)static DEFINE_STATIC_KEY_FALSE (generic_xdp_needed_key); -int do_xdp_generic (struct bpf_prog *xdp_prog,struct sk_buff *skb) +int do_xdp_generic (const struct bpf_prog *xdp_prog,struct sk_buff *skb) {if (xdp_prog) {struct xdp_buff xdp;
net/core/filter.c +14 -11
@@ -4297,9 +4297,9 @@ u32 xdp_master_redirect(struct xdp_buff *xdp)EXPORT_SYMBOL_GPL (xdp_master_redirect);static inline int __xdp_do_redirect_xsk (struct bpf_redirect_info *ri, -struct net_device *dev, +const struct net_device *dev,struct xdp_buff *xdp, -struct bpf_prog *xdp_prog) +const struct bpf_prog *xdp_prog) {enum bpf_map_type map_type = ri->map_type;void *fwd = ri->tgt_value;
@@ -4320,10 +4320,10 @@ static inline int __xdp_do_redirect_xsk(struct bpf_redirect_info *ri,return err; } -static __always_inline int __xdp_do_redirect_frame(struct bpf_redirect_info *ri, -struct net_device *dev, -struct xdp_frame *xdpf, -struct bpf_prog *xdp_prog) +static __always_inline int +__xdp_do_redirect_frame (struct bpf_redirect_info *ri,struct net_device *dev, +struct xdp_frame *xdpf, +const struct bpf_prog *xdp_prog) {enum bpf_map_type map_type = ri->map_type;void *fwd = ri->tgt_value;
@@ -4381,7 +4381,7 @@ static __always_inline int __xdp_do_redirect_frame(struct bpf_redirect_info *ri, }int xdp_do_redirect (struct net_device *dev,struct xdp_buff *xdp, -struct bpf_prog *xdp_prog) +const struct bpf_prog *xdp_prog) {struct bpf_redirect_info *ri =this_cpu_ptr (&bpf_redirect_info);enum bpf_map_type map_type = ri->map_type;
@@ -4395,7 +4395,8 @@ int xdp_do_redirect(struct net_device *dev, struct xdp_buff *xdp,EXPORT_SYMBOL_GPL (xdp_do_redirect);int xdp_do_redirect_frame (struct net_device *dev,struct xdp_buff *xdp, -struct xdp_frame *xdpf,struct bpf_prog *xdp_prog) +struct xdp_frame *xdpf, +const struct bpf_prog *xdp_prog) {struct bpf_redirect_info *ri =this_cpu_ptr (&bpf_redirect_info);enum bpf_map_type map_type = ri->map_type;
@@ -4410,7 +4411,7 @@ EXPORT_SYMBOL_GPL(xdp_do_redirect_frame);static int xdp_do_generic_redirect_map (struct net_device *dev,struct sk_buff *skb,struct xdp_buff *xdp, -struct bpf_prog *xdp_prog, +const struct bpf_prog *xdp_prog,void *fwd,enum bpf_map_type map_type,u32 map_id) {
@@ -4457,7 +4458,8 @@ static int xdp_do_generic_redirect_map(struct net_device *dev, }int xdp_do_generic_redirect (struct net_device *dev,struct sk_buff *skb, -struct xdp_buff *xdp,struct bpf_prog *xdp_prog) +struct xdp_buff *xdp, +const struct bpf_prog *xdp_prog) {struct bpf_redirect_info *ri =this_cpu_ptr (&bpf_redirect_info);enum bpf_map_type map_type = ri->map_type;
@@ -8961,7 +8963,8 @@ static bool xdp_is_valid_access(int off, int size,return __is_valid_xdp_access (off, size); } -void bpf_warn_invalid_xdp_action (struct net_device *dev,struct bpf_prog *prog,u32 act) +void bpf_warn_invalid_xdp_action (const struct net_device *dev, +const struct bpf_prog *prog,u32 act) {const u32 act_max =XDP_REDIRECT ;
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 10/34 xdp: constify read-only arguments of some static inline helpers
In reply to Alexander LobakinLots of read-only helpers for &xdp_buff and &xdp_frame, such as getting the frame length, skb_shared_info etc., don't have their arguments marked with const for no reason. Add the missing annotations to leave less place for mistakes and more for optimization.
--- include/net/xdp.h | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
include/net/xdp.h +17 -12
@@ -88,7 +88,7 @@ struct xdp_buff {u32 flags;/* supported values defined in xdp_buff_flags */ }; -static __always_inline bool xdp_buff_has_frags(struct xdp_buff *xdp) +static __always_inline bool xdp_buff_has_frags(const struct xdp_buff *xdp) {return !!(xdp->flags &XDP_FLAGS_HAS_FRAGS ); }
@@ -103,7 +103,8 @@ static __always_inline void xdp_buff_clear_frags_flag(struct xdp_buff *xdp) xdp->flags &= ~XDP_FLAGS_HAS_FRAGS ; } -static __always_inline bool xdp_buff_is_frag_pfmemalloc(struct xdp_buff *xdp) +static __always_inline bool +xdp_buff_is_frag_pfmemalloc (const struct xdp_buff *xdp) {return !!(xdp->flags &XDP_FLAGS_FRAGS_PF_MEMALLOC ); }
@@ -144,15 +145,16 @@ xdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start, SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))static inline struct skb_shared_info * -xdp_get_shared_info_from_buff (struct xdp_buff *xdp) +xdp_get_shared_info_from_buff (const struct xdp_buff *xdp) {return (struct skb_shared_info *)xdp_data_hard_end (xdp); } -static __always_inline unsigned int xdp_get_buff_len(struct xdp_buff *xdp) +static __always_inline unsigned int +xdp_get_buff_len (const struct xdp_buff *xdp) {unsigned int len = xdp->data_end - xdp->data; -struct skb_shared_info *sinfo; +const struct skb_shared_info *sinfo;if (likely (!xdp_buff_has_frags (xdp))) goto out;
@@ -177,12 +179,13 @@ struct xdp_frame {u32 flags;/* supported values defined in xdp_buff_flags */ }; -static __always_inline bool xdp_frame_has_frags(struct xdp_frame *frame) +static __always_inline bool xdp_frame_has_frags(const struct xdp_frame *frame) {return !!(frame->flags &XDP_FLAGS_HAS_FRAGS ); } -static __always_inline bool xdp_frame_is_frag_pfmemalloc(struct xdp_frame *frame) +static __always_inline bool +xdp_frame_is_frag_pfmemalloc (const struct xdp_frame *frame) {return !!(frame->flags &XDP_FLAGS_FRAGS_PF_MEMALLOC ); }
@@ -201,7 +204,7 @@ static __always_inline void xdp_frame_bulk_init(struct xdp_frame_bulk *bq) }static inline struct skb_shared_info * -xdp_get_shared_info_from_frame (struct xdp_frame *frame) +xdp_get_shared_info_from_frame (const struct xdp_frame *frame) {void *data_hard_start = frame->data - frame->headroom -sizeof (*frame);
@@ -249,7 +252,8 @@ int xdp_alloc_skb_bulk(void **skbs, int n_skb, gfp_t gfp);struct xdp_frame *xdpf_clone (struct xdp_frame *xdpf);static inline -void xdp_convert_frame_to_buff (struct xdp_frame *frame,struct xdp_buff *xdp) +void xdp_convert_frame_to_buff (const struct xdp_frame *frame, +struct xdp_buff *xdp) { xdp->data_hard_start = frame->data - frame->headroom -sizeof (*frame); xdp->data = frame->data;
@@ -260,7 +264,7 @@ void xdp_convert_frame_to_buff(struct xdp_frame *frame, struct xdp_buff *xdp) }static inline -int xdp_update_frame_from_buff (struct xdp_buff *xdp, +int xdp_update_frame_from_buff (const struct xdp_buff *xdp,struct xdp_frame *xdp_frame) {int metasize, headroom;
@@ -317,9 +321,10 @@ void xdp_flush_frame_bulk(struct xdp_frame_bulk *bq);void xdp_return_frame_bulk (struct xdp_frame *xdpf,struct xdp_frame_bulk *bq); -static __always_inline unsigned int xdp_get_frame_len(struct xdp_frame *xdpf) +static __always_inline unsigned int +xdp_get_frame_len (const struct xdp_frame *xdpf) { -struct skb_shared_info *sinfo; +const struct skb_shared_info *sinfo;unsigned int len = xdpf->len;if (likely (!xdp_frame_has_frags (xdpf)))
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 11/34 xdp: allow attaching already registered memory model to xdp_rxq_info
In reply to Alexander LobakinOne may need to register memory model separately from xdp_rxq_info. One simple example may be XDP test run code, but in general, it might be useful when memory model registering is managed by one layer and then XDP RxQ info by a different one.
Allow such scenarios by adding a simple helper which "attaches" an already registered memory model to the desired xdp_rxq_info. As this is mostly needed for Page Pool, add a special function to do that for a &page_pool pointer.
--- include/net/xdp.h | 14 ++++++++++++++ net/bpf/test_run.c | 4 ++-- net/core/xdp.c | 12 ++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-)
include/net/xdp.h +14 -0
@@ -356,6 +356,20 @@ void xdp_rxq_info_unreg_mem_model(struct xdp_rxq_info *xdp_rxq);int xdp_reg_mem_model (struct xdp_mem_info *mem,enum xdp_mem_type type,void *allocator);void xdp_unreg_mem_model (struct xdp_mem_info *mem); +void xdp_rxq_info_attach_page_pool (struct xdp_rxq_info *xdp_rxq, +const struct page_pool *pool); + +static inline void +xdp_rxq_info_attach_mem_model (struct xdp_rxq_info *xdp_rxq, +const struct xdp_mem_info *mem) +{ + xdp_rxq->mem = *mem; +} + +static inline void xdp_rxq_info_detach_mem_model (struct xdp_rxq_info *xdp_rxq) +{ + xdp_rxq->mem = (struct xdp_mem_info ){ }; +}/* Drivers not supporting XDP metadata can use this helper, which * rejects any room expansion for metadata as a result.
net/bpf/test_run.c +2 -2
@@ -194,8 +194,7 @@ static int xdp_test_run_setup(struct xdp_test_data *xdp, struct xdp_buff *orig_c* xdp_mem_info pointing to our page_pool */ xdp_rxq_info_reg (&xdp->rxq, orig_ctx->rxq->dev,0 ,0 ); - xdp->rxq.mem.type =MEM_TYPE_PAGE_POOL ; - xdp->rxq.mem.id = pp->xdp_mem_id; +xdp_rxq_info_attach_page_pool (&xdp->rxq, xdp->pp); xdp->dev = orig_ctx->rxq->dev; xdp->orig_ctx = orig_ctx;
@@ -212,6 +211,7 @@ static int xdp_test_run_setup(struct xdp_test_data *xdp, struct xdp_buff *orig_cstatic void xdp_test_run_teardown (struct xdp_test_data *xdp) { +xdp_rxq_info_detach_mem_model (&xdp->rxq);xdp_unreg_mem_model (&xdp->mem);page_pool_destroy (xdp->pp);kfree (xdp->frames);
net/core/xdp.c +12 -0
@@ -368,6 +368,18 @@ int xdp_rxq_info_reg_mem_model(struct xdp_rxq_info *xdp_rxq,EXPORT_SYMBOL_GPL (xdp_rxq_info_reg_mem_model); +void xdp_rxq_info_attach_page_pool (struct xdp_rxq_info *xdp_rxq, +const struct page_pool *pool) +{ +struct xdp_mem_info mem = { + .type =MEM_TYPE_PAGE_POOL , + .id = pool->xdp_mem_id, + }; + +xdp_rxq_info_attach_mem_model (xdp_rxq, &mem); +} +EXPORT_SYMBOL_GPL (xdp_rxq_info_attach_page_pool); +/* XDP RX runs under NAPI protection, and in different delivery error * scenarios (e.g. queue full), it is possible to return the xdp_frame * while still leveraging this protection. The @napi_direct boolean
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 12/34 xdp: add generic xdp_buff_add_frag()
In reply to Alexander LobakinThe code piece which would attach a frag to &xdp_buff is almost identical across the drivers supporting XDP multi-buffer on Rx. Make it a generic elegant onelner.
Also, I see lots of drivers calculating frags_truesize as xdp->frame_sz * nr_frags. I can't say this is fully correct, since frags might be backed by chunks of different sizes, especially with stuff like the header split. Even page_pool_alloc() can give you two different truesizes on two subsequent requests to allocate the same buffer size. Add a field to &skb_shared_info (unionized as there's no free slot currently on x6_64) to track the "true" truesize. It can be used later when updating an skb.
--- include/linux/skbuff.h | 14 ++++++++++---- include/net/xdp.h | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 5 deletions(-)
include/linux/skbuff.h +10 -4
@@ -598,11 +598,17 @@ struct skb_shared_info {* Warning : all fields before dataref are cleared in __alloc_skb() */ atomic_t dataref; -unsigned int xdp_frags_size; -/* Intermediate layers must ensure that destructor_arg -* remains valid until skb destructor */ -void * destructor_arg; +union { +struct { +unsigned int xdp_frags_size; +u32 xdp_frags_truesize; + }; + +/* Intermediate layers must ensure that destructor_arg +* remains valid until skb destructor */ +void * destructor_arg; + };/* must be last field, see pskb_expand_head() */ skb_frag_t frags[MAX_SKB_FRAGS ];
include/net/xdp.h +35 -1
@@ -165,6 +165,34 @@ xdp_get_buff_len(const struct xdp_buff *xdp)return len; } +static inline bool xdp_buff_add_frag (struct xdp_buff *xdp,struct page *page, +u32 offset,u32 size,u32 truesize) +{ +struct skb_shared_info *sinfo =xdp_get_shared_info_from_buff (xdp); + +if (!xdp_buff_has_frags (xdp)) { + sinfo->nr_frags =0 ; + + sinfo->xdp_frags_size =0 ; + sinfo->xdp_frags_truesize =0 ; + +xdp_buff_set_frags_flag (xdp); + } + +if (unlikely (sinfo->nr_frags ==MAX_SKB_FRAGS )) +return false; + +__skb_fill_page_desc_noacc (sinfo, sinfo->nr_frags++, page, offset, + size); + sinfo->xdp_frags_size += size; + sinfo->xdp_frags_truesize += truesize; + +if (unlikely (page_is_pfmemalloc (page))) +xdp_buff_set_frag_pfmemalloc (xdp); + +return true; +} +struct xdp_frame {void *data;u16 len;
@@ -230,7 +258,13 @@ xdp_update_skb_shared_info(struct sk_buff *skb, u8 nr_frags, unsigned int size, unsigned int truesize, bool pfmemalloc) { - skb_shinfo(skb)->nr_frags = nr_frags; + struct skb_shared_info *sinfo = skb_shinfo(skb); + + sinfo->nr_frags = nr_frags; +/* ``destructor_arg`` is unionized with ``xdp_frags_{,true}size``, +* reset it after that these fields aren't used anymore. +*/ + sinfo->destructor_arg =NULL ; skb->len += size; skb->data_len += size;
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 13/34 xdp: add generic xdp_build_skb_from_buff()
In reply to Alexander LobakinThe code which builds an skb from an &xdp_buff keeps multiplying itself around the drivers with almost no changes. Let's try to stop that by adding a generic function.
There's __xdp_build_skb_from_frame() already, so just convert it to take &xdp_buff instead, while making the original one a wrapper. The original one always took an already allocated skb, allow both variants here -- if no skb passed, which is expected when calling from a driver, pick one via napi_build_skb().
--- include/net/xdp.h | 4 +++ net/core/xdp.c | 89 +++++++++++++++++++++++++++++++---------------- 2 files changed, 63 insertions(+), 30 deletions(-)
include/net/xdp.h +4 -0
@@ -276,6 +276,10 @@ xdp_update_skb_shared_info(struct sk_buff *skb, u8 nr_frags,void xdp_warn (const char *msg,const char *func,const int line);#define XDP_WARN (msg) xdp_warn(msg, __func__, __LINE__) +struct sk_buff *__xdp_build_skb_from_buff (struct sk_buff *skb, +const struct xdp_buff *xdp); +#define xdp_build_skb_from_buff (xdp) __xdp_build_skb_from_buff(NULL, xdp) +struct xdp_frame *xdp_convert_zc_to_xdp_frame (struct xdp_buff *xdp); struct sk_buff *__xdp_build_skb_from_frame(struct xdp_frame *xdpf, struct sk_buff *skb,
net/core/xdp.c +59 -30
113 lines not on this page · raw message
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 14/34 xdp: get rid of xdp_frame::mem.id
In reply to Alexander LobakinInitially, xdp_frame::mem.id was used to search for the corresponding &page_pool to return the page correctly.
However, after that struct page now contains a direct pointer to its PP, further keeping of this field makes no sense. xdp_return_frame_bulk() still uses it to do a lookup, but this is rather a leftover. Remove xdp_frame::mem and replace it with ::mem_type, as only memory type still matters and we need to know it to be able to free the frame correctly.
But the main reason for this change was to allow mixing pages from different &page_pools within one &xdp_buff/&xdp_frame. Why not? Adjust xdp_return_frame_bulk() and page_pool_put_page_bulk(), so that they won't be tied to a particular pool. Let the latter splice the bulk when it encounters a page whichs PP is different and flush it recursively.
As a cute side effect, sizeof(struct xdp_frame) on x86_64 is reduced from 40 to 32 bytes, giving a bit more free headroom in front of the frame.
--- .../net/ethernet/freescale/dpaa/dpaa_eth.c | 2 +- drivers/net/veth.c | 4 +- include/net/page_pool/types.h | 6 +-- include/net/xdp.h | 17 +++---- kernel/bpf/cpumap.c | 2 +- net/bpf/test_run.c | 2 +- net/core/filter.c | 2 +- net/core/page_pool.c | 31 ++++++++++-- net/core/xdp.c | 49 ++++++------------- 9 files changed, 58 insertions(+), 57 deletions(-)
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +1 -1
@@ -2263,7 +2263,7 @@ static int dpaa_a050385_wa_xdpf(struct dpaa_priv *priv, new_xdpf->len = xdpf->len; new_xdpf->headroom = priv->tx_headroom; new_xdpf->frame_sz =DPAA_BP_RAW_SIZE ; - new_xdpf->mem.type =MEM_TYPE_PAGE_ORDER0 ; + new_xdpf->mem_type =MEM_TYPE_PAGE_ORDER0 ;/* Release the initial buffer */ xdp_return_frame_rx_napi (xdpf);
drivers/net/veth.c +2 -2
@@ -633,7 +633,7 @@ static struct xdp_frame *veth_xdp_rcv_one(struct veth_rq *rq,break ;case XDP_TX : orig_frame = *frame; - xdp->rxq->mem = frame->mem; + xdp->rxq->mem.type = frame->mem_type;if (unlikely (veth_xdp_tx (rq, xdp, bq) <0 )) {trace_xdp_exception (rq->dev, xdp_prog, act); frame = &orig_frame;
@@ -645,7 +645,7 @@ static struct xdp_frame *veth_xdp_rcv_one(struct veth_rq *rq, goto xdp_xmit;case XDP_REDIRECT : orig_frame = *frame; - xdp->rxq->mem = frame->mem; + xdp->rxq->mem.type = frame->mem_type;if (xdp_do_redirect (rq->dev, xdp, xdp_prog)) { frame = &orig_frame; stats->rx_drops++;
include/net/page_pool/types.h +2 -4
@@ -222,8 +222,7 @@ void page_pool_unlink_napi(struct page_pool *pool);void page_pool_destroy (struct page_pool *pool);void page_pool_use_xdp_mem (struct page_pool *pool,void (*disconnect)(void *),struct xdp_mem_info *mem); -void page_pool_put_page_bulk (struct page_pool *pool,void **data, -int count); +void page_pool_put_page_bulk (void **data,int count);#else static inline void page_pool_unlink_napi (struct page_pool *pool) {
@@ -239,8 +238,7 @@ static inline void page_pool_use_xdp_mem(struct page_pool *pool, { } -static inline void page_pool_put_page_bulk (struct page_pool *pool,void **data, -int count) +static inline void page_pool_put_page_bulk (void **data,int count) { }#endif
include/net/xdp.h +6 -11
@@ -197,11 +197,8 @@ struct xdp_frame {void *data;u16 len;u16 headroom; -u32 metasize;/* uses lower 8-bits */ -/* Lifetime of xdp_rxq_info is limited to NAPI/enqueue time, -* while mem info is valid on remote CPU. -*/ -struct xdp_mem_info mem; +u16 metasize; + enum xdp_mem_type mem_type:16;struct net_device *dev_rx;/* used by cpumap */ u32 frame_sz;u32 flags;/* supported values defined in xdp_buff_flags */
@@ -221,14 +218,12 @@ xdp_frame_is_frag_pfmemalloc(const struct xdp_frame *frame)#define XDP_BULK_QUEUE_SIZE 16struct xdp_frame_bulk {int count; -void *xa;void *q[XDP_BULK_QUEUE_SIZE ]; }; static __always_inline void xdp_frame_bulk_init(struct xdp_frame_bulk *bq) { -/* bq->count will be zero'ed when bq->xa gets updated */ - bq->xa =NULL ; + bq->count =0 ; } static inline struct skb_shared_info *
@@ -344,13 +339,13 @@ struct xdp_frame *xdp_convert_buff_to_frame(struct xdp_buff *xdp)if (unlikely (xdp_update_frame_from_buff (xdp, xdp_frame) <0 ))return NULL ; -/* rxq only valid until napi_schedule ends, convert to xdp_mem_info */ - xdp_frame->mem = xdp->rxq->mem; +/* rxq only valid until napi_schedule ends, convert to xdp_mem_type */ + xdp_frame->mem_type = xdp->rxq->mem.type;return xdp_frame; } -void __xdp_return (void *data,struct xdp_mem_info *mem,bool napi_direct, +void __xdp_return (void *data,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);
kernel/bpf/cpumap.c +1 -1
@@ -191,7 +191,7 @@ static int cpu_map_bpf_prog_run_xdp(struct bpf_cpu_map_entry *rcpu,int err; rxq.dev = xdpf->dev_rx; - rxq.mem = xdpf->mem; + rxq.mem.type = xdpf->mem_type;/* TODO: report queue_index to xdp_rxq_info */ xdp_convert_frame_to_buff (xdpf, &xdp);
net/bpf/test_run.c +1 -1
@@ -151,7 +151,7 @@ static void xdp_test_run_init_page(struct page *page, void *arg) new_ctx->data = new_ctx->data_meta + meta_len;xdp_update_frame_from_buff (new_ctx, frm); - frm->mem = new_ctx->rxq->mem; + frm->mem_type = new_ctx->rxq->mem.type;memcpy (&head->orig_ctx, new_ctx,sizeof (head->orig_ctx)); }
net/core/filter.c +1 -1
@@ -4114,7 +4114,7 @@ static int bpf_xdp_frags_shrink_tail(struct xdp_buff *xdp, int offset)if (skb_frag_size (frag) == shrink) {struct page *page =skb_frag_page (frag); -__xdp_return (page_address (page), &xdp->rxq->mem, +__xdp_return (page_address (page), xdp->rxq->mem.type, false,NULL ); n_frags_free++; }else {
net/core/page_pool.c +28 -3
@@ -698,9 +698,18 @@ void page_pool_put_unrefed_page(struct page_pool *pool, struct page *page, }EXPORT_SYMBOL (page_pool_put_unrefed_page); +static void page_pool_bulk_splice (struct xdp_frame_bulk *bulk,void *data) +{ +if (unlikely (bulk->count ==ARRAY_SIZE (bulk->q))) { +page_pool_put_page_bulk (bulk->q, bulk->count); + bulk->count =0 ; + } + + bulk->q[bulk->count++] = data; +} +/** * page_pool_put_page_bulk() - release references on multiple pages -* @pool: pool from which pages were allocated * @data: array holding page pointers * @count: number of pages in @data *
@@ -713,12 +722,15 @@ EXPORT_SYMBOL(page_pool_put_unrefed_page);* Please note the caller must not use data area after running * page_pool_put_page_bulk(), as this function overwrites it. */ -void page_pool_put_page_bulk (struct page_pool *pool,void **data, -int count) +void page_pool_put_page_bulk (void **data,int count) { +struct page_pool *pool =NULL ; +struct xdp_frame_bulk sub;int i, bulk_len =0 ;bool in_softirq; +xdp_frame_bulk_init (&sub); +for (i =0 ; i < count; i++) {struct page *page =virt_to_head_page (data[i]);
@@ -726,12 +738,25 @@ void page_pool_put_page_bulk(struct page_pool *pool, void **data,if (!page_pool_is_last_ref (page))continue ; +if (unlikely (!pool)) { + pool = page->pp; + }else if (page->pp != pool) { +/* If the page belongs to a different page_pool, +* splice the array and handle it recursively. +*/ +page_pool_bulk_splice (&sub, data[i]); +continue ; + } + page =__page_pool_put_page (pool, page,-1 , false);/* Approved for bulk recycling in ptr_ring cache */ if (page) data[bulk_len++] = page; } +if (sub.count) +page_pool_put_page_bulk (sub.q, sub.count); +if (unlikely (!bulk_len))return ;
net/core/xdp.c +16 -33
128 lines not on this page · raw message
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 15/34 page_pool: add inline helper to sync VA for device (for XDP_TX)
In reply to Alexander LobakinDrivers using Page Pool for Rx buffers do the same pattern on XDP_TX:
syncing-DMA-for-device and obtaining DMA address for &xdp_buff they are sending.
Add a helper for that to be able to do that in one call in the drivers. I explicitly added bool compound argument and set it to false by
default: only a few drivers, if any, uses high-order pages with Page Pool, so losing cycles on compound_head() looks suboptimal. Drivers can always call the underscored version if needed (for example, pass pool->p.order as the last argument -- will always work).
--- include/net/page_pool/helpers.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
include/net/page_pool/helpers.h +32 -0
@@ -397,6 +397,38 @@ static inline bool page_pool_set_dma_addr(struct page *page, dma_addr_t addr)return false; } +static inline dma_addr_t __page_pool_dma_sync_va_for_device (const void *va, +u32 dma_sync_size, +bool compound) +{ +const struct page_pool *pool; +const struct page *page; +dma_addr_t addr; +u32 offset; + +if (unlikely (compound)) { + page =virt_to_head_page (va); + offset = va -page_address (page); + }else { + page =virt_to_page (va); + offset =offset_in_page (va); + } + + addr =page_pool_get_dma_addr (page) + offset; + pool = page->pp; + +dma_sync_single_for_device (pool->p.dev, addr, dma_sync_size, +page_pool_get_dma_dir (pool)); + +return addr; +} + +static inline dma_addr_t page_pool_dma_sync_va_for_device (const void *va, +u32 dma_sync_size) +{ +return __page_pool_dma_sync_va_for_device (va, dma_sync_size, false); +} +/** * page_pool_dma_sync_for_cpu - sync Rx page for CPU after it's written by HW * @pool: &page_pool the @page belongs to
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 16/34 jump_label: export static_key_slow_{inc,dec}_cpuslocked()
In reply to Alexander LobakinSometimes, there's a need to modify a lot of static keys or modify the same key multiple times in a loop. In that case, it seems more optimal to lock cpu_read_lock once and then call _cpuslocked() variants. The enable/disable functions are already exported, the refcounted counterparts however are not. Fix that to allow modules to save some cycles.
--- kernel/jump_label.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/jump_label.c +2 -0
@@ -177,6 +177,7 @@ bool static_key_slow_inc_cpuslocked(struct static_key *key)jump_label_unlock ();return true; } +EXPORT_SYMBOL_GPL (static_key_slow_inc_cpuslocked);bool static_key_slow_inc (struct static_key *key) {
@@ -304,6 +305,7 @@ void static_key_slow_dec_cpuslocked(struct static_key *key)STATIC_KEY_CHECK_USE (key);__static_key_slow_dec_cpuslocked (key); } +EXPORT_SYMBOL_GPL (static_key_slow_dec_cpuslocked); void __static_key_slow_dec_deferred(struct static_key *key, struct delayed_work *work,
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 17/34 libie: support native XDP and register memory model
In reply to Alexander LobakinExpand libie's Page Pool functionality by adding native XDP support. This means picking the appropriate headroom and DMA direction. Also, register all the created &page_pools as XDP memory models. A driver then can call xdp_rxq_info_attach_page_pool() when registering its RxQ info.
--- drivers/net/ethernet/intel/libie/rx.c | 32 ++++++++++++++++++++++----- include/linux/net/intel/libie/rx.h | 6 ++++- 2 files changed, 32 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/libie/rx.c +27 -5
@@ -52,7 +52,7 @@ static u32 libie_rx_hw_len_truesize(const struct page_pool_params *pp,static void libie_rx_page_pool_params (struct libie_buf_queue *bq,struct page_pool_params *pp) { - pp->offset =LIBIE_SKB_HEADROOM ; + pp->offset = bq->xdp ?LIBIE_XDP_HEADROOM :LIBIE_SKB_HEADROOM ;/* HW-writeable / syncable length per one page */ pp->max_len =LIBIE_RX_BUF_LEN (pp->offset);
@@ -132,17 +132,34 @@ int libie_rx_page_pool_create(struct libie_buf_queue *bq, .dev = napi->dev->dev.parent, .netdev = napi->dev, .napi = napi, - .dma_dir = DMA_FROM_DEVICE, }; +struct xdp_mem_info mem; +struct page_pool *pool; +int ret; + + pp.dma_dir = bq->xdp ?DMA_BIDIRECTIONAL :DMA_FROM_DEVICE ;if (!bq->hsplit)libie_rx_page_pool_params (bq, &pp);else if (!libie_rx_page_pool_params_zc (bq, &pp))return -EINVAL ; - bq->pp =page_pool_create (&pp); + pool =page_pool_create (&pp); +if (IS_ERR (pool)) +return PTR_ERR (pool); + + ret =xdp_reg_mem_model (&mem,MEM_TYPE_PAGE_POOL , pool); +if (ret) + goto err_mem; + + bq->pp = pool; + +return 0 ; -return PTR_ERR_OR_ZERO (bq->pp); +err_mem: +page_pool_destroy (pool); + +return ret; }EXPORT_SYMBOL_NS_GPL (libie_rx_page_pool_create,LIBIE );
@@ -152,7 +169,12 @@ EXPORT_SYMBOL_NS_GPL(libie_rx_page_pool_create, LIBIE);*/ void libie_rx_page_pool_destroy (struct libie_buf_queue *bq) { -page_pool_destroy (bq->pp); +struct xdp_mem_info mem = { + .type =MEM_TYPE_PAGE_POOL , + .id = bq->pp->xdp_mem_id, + }; + +xdp_unreg_mem_model (&mem); bq->pp =NULL ; }EXPORT_SYMBOL_NS_GPL (libie_rx_page_pool_destroy,LIBIE );
include/linux/net/intel/libie/rx.h +5 -1
@@ -15,8 +15,10 @@/* Space reserved in front of each frame */ #define LIBIE_SKB_HEADROOM (NET_SKB_PAD + NET_IP_ALIGN) +#define LIBIE_XDP_HEADROOM (ALIGN(XDP_PACKET_HEADROOM, NET_SKB_PAD) + \ + NET_IP_ALIGN)/* Maximum headroom to calculate max MTU below */ -#define LIBIE_MAX_HEADROOM LIBIE_SKB_HEADROOM +#define LIBIE_MAX_HEADROOM LIBIE_XDP_HEADROOM/* Link layer / L2 overhead: Ethernet, 2 VLAN tags (C + S), FCS */ #define LIBIE_RX_LL_LEN (ETH_HLEN + 2 * VLAN_HLEN + ETH_FCS_LEN)/* Maximum supported L2-L4 header length */
@@ -87,6 +89,7 @@ enum libie_rx_buf_type {* @rx_buf_len: HW-writeable length per each buffer * @type: type of the buffers this queue has * @hsplit: flag whether header split is enabled +* @xdp: flag indicating whether XDP is enabled */ struct libie_buf_queue {struct page_pool *pp;
@@ -100,6 +103,7 @@ struct libie_buf_queue { enum libie_rx_buf_type type:2; bool hsplit:1; + bool xdp:1; }; int libie_rx_page_pool_create(struct libie_buf_queue *bq,
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 18/34 libie: add a couple of XDP helpers
In reply to Alexander Lobakin"Couple" is a bit humbly... Add the following functionality to libie:
* XDP shared queues managing
* XDP_TX bulk sending infra
* .ndo_xdp_xmit() infra
* adding buffers to &xdp_buff
* running XDP prog and managing its verdict
* completing XDP Tx buffers
* ^ repeat everything for XSk
--- drivers/net/ethernet/intel/libie/Makefile | 3 + drivers/net/ethernet/intel/libie/tx.c | 16 + drivers/net/ethernet/intel/libie/xdp.c | 50 ++ drivers/net/ethernet/intel/libie/xsk.c | 49 ++ include/linux/net/intel/libie/tx.h | 6 + include/linux/net/intel/libie/xdp.h | 586 ++++++++++++++++++++++ include/linux/net/intel/libie/xsk.h | 172 +++++++ 7 files changed, 882 insertions(+) create mode 100644 drivers/net/ethernet/intel/libie/tx.c create mode 100644 drivers/net/ethernet/intel/libie/xdp.c create mode 100644 drivers/net/ethernet/intel/libie/xsk.c create mode 100644 include/linux/net/intel/libie/xdp.h create mode 100644 include/linux/net/intel/libie/xsk.h
drivers/net/ethernet/intel/libie/Makefile +3 -0
@@ -5,3 +5,6 @@ obj-$(CONFIG_LIBIE) += libie.o libie-objs += rx.o libie-objs += stats.o +libie-objs += tx.o +libie-objs += xdp.o +libie-objs += xsk.o
drivers/net/ethernet/intel/libie/tx.c new file +16 -0
@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright(c) 2023 Intel Corporation. */ + +#include <linux/net/intel/libie/xdp.h> + +void libie_tx_complete_any (struct libie_tx_buffer *buf,struct device *dev, +struct xdp_frame_bulk *bq,u32 *xdp_tx_active, +struct libie_sq_onstack_stats *ss) +{ +if (buf->type >LIBIE_TX_BUF_SKB ) +libie_xdp_complete_tx_buf (buf, dev, false, bq, xdp_tx_active, + ss); +else +libie_tx_complete_buf (buf, dev, false, ss); +} +EXPORT_SYMBOL_NS_GPL (libie_tx_complete_any,LIBIE );
drivers/net/ethernet/intel/libie/xdp.c new file +50 -0
50 lines not on this page · raw message
drivers/net/ethernet/intel/libie/xsk.c new file +49 -0
49 lines not on this page · raw message
include/linux/net/intel/libie/tx.h +6 -0
@@ -85,4 +85,10 @@ static inline void libie_tx_complete_buf(struct libie_tx_buffer *buf, buf->type = LIBIE_TX_BUF_EMPTY; } +struct xdp_frame_bulk ; + +void libie_tx_complete_any (struct libie_tx_buffer *buf,struct device *dev, +struct xdp_frame_bulk *bq,u32 *xdp_tx_active, +struct libie_sq_onstack_stats *ss); +#endif /* __LIBIE_TX_H */
include/linux/net/intel/libie/xdp.h new file +586 -0
586 lines not on this page · raw message
include/linux/net/intel/libie/xsk.h new file +172 -0
172 lines not on this page · raw message
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 19/34 idpf: stop using macros for accessing queue descriptors
In reply to Alexander LobakinIn C, we have structures and unions.
Casting void * via macros is not only error-prone, but also looks confusing and awful in general.
Replace it with a union and direct array dereferences. Had idpf had separate queue structures, it would look way more elegant -- will do one day.
--- .../ethernet/intel/idpf/idpf_singleq_txrx.c | 20 +++++----- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 30 +++++++-------- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 37 ++++++++----------- 3 files changed, 40 insertions(+), 47 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +10 -10
@@ -206,7 +206,7 @@ static void idpf_tx_singleq_map(struct idpf_queue *tx_q, data_len = skb->data_len; size =skb_headlen (skb); - tx_desc =IDPF_BASE_TX_DESC (tx_q, i); + tx_desc = &tx_q->base_tx[i]; dma =dma_map_single (tx_q->dev, skb->data, size,DMA_TO_DEVICE );
@@ -242,7 +242,7 @@ static void idpf_tx_singleq_map(struct idpf_queue *tx_q, i++;if (i == tx_q->desc_count) { - tx_desc =IDPF_BASE_TX_DESC (tx_q,0 ); + tx_desc = &tx_q->base_tx[0 ]; i =0 ; }
@@ -262,7 +262,7 @@ static void idpf_tx_singleq_map(struct idpf_queue *tx_q, i++;if (i == tx_q->desc_count) { - tx_desc =IDPF_BASE_TX_DESC (tx_q,0 ); + tx_desc = &tx_q->base_tx[0 ]; i =0 ; }
@@ -311,7 +311,7 @@ idpf_tx_singleq_get_ctx_desc(struct idpf_queue *txq)memset (&txq->tx_buf[ntu],0 ,sizeof (struct idpf_tx_buf )); txq->tx_buf[ntu].ctx_entry = true; - ctx_desc =IDPF_BASE_TX_CTX_DESC (txq, ntu); + ctx_desc = &txq->base_ctx[ntu];IDPF_SINGLEQ_BUMP_RING_IDX (txq, ntu); txq->next_to_use = ntu;
@@ -460,7 +460,7 @@ static bool idpf_tx_singleq_clean(struct idpf_queue *tx_q, int napi_budget,struct netdev_queue *nq;bool dont_wake; - tx_desc =IDPF_BASE_TX_DESC (tx_q, ntc); + tx_desc = &tx_q->base_tx[ntc]; tx_buf = &tx_q->tx_buf[ntc]; ntc -= tx_q->desc_count;
@@ -509,7 +509,7 @@ static bool idpf_tx_singleq_clean(struct idpf_queue *tx_q, int napi_budget,if (unlikely (!ntc)) { ntc -= tx_q->desc_count; tx_buf = tx_q->tx_buf; - tx_desc =IDPF_BASE_TX_DESC (tx_q,0 ); + tx_desc = &tx_q->base_tx[0 ]; }/* unmap any remaining paged data */
@@ -527,7 +527,7 @@ static bool idpf_tx_singleq_clean(struct idpf_queue *tx_q, int napi_budget,if (unlikely (!ntc)) { ntc -= tx_q->desc_count; tx_buf = tx_q->tx_buf; - tx_desc =IDPF_BASE_TX_DESC (tx_q,0 ); + tx_desc = &tx_q->base_tx[0 ]; } }while (likely (budget));
@@ -880,7 +880,7 @@ bool idpf_rx_singleq_buf_hw_alloc_all(struct idpf_queue *rx_q,if (!cleaned_count)return false; - desc =IDPF_SINGLEQ_RX_BUF_DESC (rx_q, nta); + desc = &rx_q->single_buf[nta]; do { dma_addr_t addr;
@@ -898,7 +898,7 @@ bool idpf_rx_singleq_buf_hw_alloc_all(struct idpf_queue *rx_q, nta++;if (unlikely (nta == rx_q->desc_count)) { - desc =IDPF_SINGLEQ_RX_BUF_DESC (rx_q,0 ); + desc = &rx_q->single_buf[0 ]; nta =0 ; }
@@ -998,7 +998,7 @@ static int idpf_rx_singleq_clean(struct idpf_queue *rx_q, int budget)struct idpf_rx_buf *rx_buf;/* get the Rx desc from Rx queue based on 'next_to_clean' */ - rx_desc =IDPF_RX_DESC (rx_q, ntc); + rx_desc = &rx_q->rx[ntc];/* status_error_ptype_len will always be zero for unused * descriptors because it's cleared in cleanup, and overlaps
drivers/net/ethernet/intel/idpf/idpf_txrx.c +15 -15
@@ -533,7 +533,7 @@ static bool idpf_rx_post_buf_desc(struct idpf_queue *bufq, u16 buf_id)u16 nta = bufq->next_to_alloc;dma_addr_t addr; - splitq_rx_desc =IDPF_SPLITQ_RX_BUF_DESC (bufq, nta); + splitq_rx_desc = &bufq->split_buf[nta];if (bufq->rx_hsplit_en) { bq.pp = bufq->hdr_pp;
@@ -1560,7 +1560,7 @@ do { \if (unlikely (!(ntc))) { \ ntc -= (txq)->desc_count; \ buf = (txq)->tx_buf; \ - desc =IDPF_FLEX_TX_DESC (txq,0 ); \ + desc = &(txq)->flex_tx[0 ]; \ }else { \ (buf)++; \ (desc)++; \
@@ -1593,8 +1593,8 @@ static void idpf_tx_splitq_clean(struct idpf_queue *tx_q, u16 end,s16 ntc = tx_q->next_to_clean;struct idpf_tx_buf *tx_buf; - tx_desc =IDPF_FLEX_TX_DESC (tx_q, ntc); - next_pending_desc =IDPF_FLEX_TX_DESC (tx_q, end); + tx_desc = &tx_q->flex_tx[ntc]; + next_pending_desc = &tx_q->flex_tx[end]; tx_buf = &tx_q->tx_buf[ntc]; ntc -= tx_q->desc_count;
@@ -1774,7 +1774,7 @@ static bool idpf_tx_clean_complq(struct idpf_queue *complq, int budget,int i; complq_budget = vport->compln_clean_budget; - tx_desc =IDPF_SPLITQ_TX_COMPLQ_DESC (complq, ntc); + tx_desc = &complq->comp[ntc]; ntc -= complq->desc_count; do {
@@ -1840,7 +1840,7 @@ static bool idpf_tx_clean_complq(struct idpf_queue *complq, int budget, ntc++;if (unlikely (!ntc)) { ntc -= complq->desc_count; - tx_desc =IDPF_SPLITQ_TX_COMPLQ_DESC (complq,0 ); + tx_desc = &complq->comp[0 ];change_bit (__IDPF_Q_GEN_CHK, complq->flags); }
@@ -2107,7 +2107,7 @@ void idpf_tx_dma_map_error(struct idpf_queue *txq, struct sk_buff *skb,* used one additional descriptor for a context * descriptor. Reset that here. */ - tx_desc =IDPF_FLEX_TX_DESC (txq, idx); + tx_desc = &txq->flex_tx[idx];memset (tx_desc,0 ,sizeof (struct idpf_flex_tx_ctx_desc ));if (idx ==0 ) idx = txq->desc_count;
@@ -2167,7 +2167,7 @@ static void idpf_tx_splitq_map(struct idpf_queue *tx_q, data_len = skb->data_len; size =skb_headlen (skb); - tx_desc =IDPF_FLEX_TX_DESC (tx_q, i); + tx_desc = &tx_q->flex_tx[i]; dma =dma_map_single (tx_q->dev, skb->data, size,DMA_TO_DEVICE );
@@ -2241,7 +2241,7 @@ static void idpf_tx_splitq_map(struct idpf_queue *tx_q, i++;if (i == tx_q->desc_count) { - tx_desc =IDPF_FLEX_TX_DESC (tx_q,0 ); + tx_desc = &tx_q->flex_tx[0 ]; i =0 ; tx_q->compl_tag_cur_gen =IDPF_TX_ADJ_COMPL_TAG_GEN (tx_q);
@@ -2286,7 +2286,7 @@ static void idpf_tx_splitq_map(struct idpf_queue *tx_q, i++;if (i == tx_q->desc_count) { - tx_desc =IDPF_FLEX_TX_DESC (tx_q,0 ); + tx_desc = &tx_q->flex_tx[0 ]; i =0 ; tx_q->compl_tag_cur_gen =IDPF_TX_ADJ_COMPL_TAG_GEN (tx_q); }
@@ -2520,7 +2520,7 @@ idpf_tx_splitq_get_ctx_desc(struct idpf_queue *txq) txq->tx_buf[i].compl_tag =IDPF_SPLITQ_TX_INVAL_COMPL_TAG ;/* grab the next descriptor */ - desc =IDPF_FLEX_TX_CTX_DESC (txq, i); + desc = &txq->flex_ctx[i]; txq->next_to_use =idpf_tx_splitq_bump_ntu (txq, i);return desc;
@@ -3020,7 +3020,7 @@ static int idpf_rx_splitq_clean(struct idpf_queue *rxq, int budget)u8 rxdid;/* get the Rx desc from Rx queue based on 'next_to_clean' */ - desc =IDPF_RX_DESC (rxq, ntc); + desc = &rxq->rx[ntc]; rx_desc = (struct virtchnl2_rx_flex_desc_adv_nic_3 *)desc;/* This memory barrier is needed to keep us from reading
@@ -3225,11 +3225,11 @@ static void idpf_rx_clean_refillq(struct idpf_queue *bufq,int cleaned =0 ;u16 gen; - buf_desc =IDPF_SPLITQ_RX_BUF_DESC (bufq, bufq_nta); + buf_desc = &bufq->split_buf[bufq_nta];/* make sure we stop at ring wrap in the unlikely case ring is full */ while (likely (cleaned < refillq->desc_count)) { -u16 refill_desc =IDPF_SPLITQ_RX_BI_DESC (refillq, ntc); +u16 refill_desc = refillq->ring[ntc];bool failure; gen =FIELD_GET (IDPF_RX_BI_GEN_M , refill_desc);
@@ -3247,7 +3247,7 @@ static void idpf_rx_clean_refillq(struct idpf_queue *bufq, }if (unlikely (++bufq_nta == bufq->desc_count)) { - buf_desc =IDPF_SPLITQ_RX_BUF_DESC (bufq,0 ); + buf_desc = &bufq->split_buf[0 ]; bufq_nta =0 ; }else { buf_desc++;
drivers/net/ethernet/intel/idpf/idpf_txrx.h +15 -22
@@ -112,24 +112,6 @@ do { \#define IDPF_RXD_EOF_SPLITQ VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_EOF_M#define IDPF_RXD_EOF_SINGLEQ VIRTCHNL2_RX_BASE_DESC_STATUS_EOF_M -#define IDPF_SINGLEQ_RX_BUF_DESC (rxq, i) \ - (&(((struct virtchnl2_singleq_rx_buf_desc *)((rxq)->desc_ring))[i])) -#define IDPF_SPLITQ_RX_BUF_DESC (rxq, i) \ - (&(((struct virtchnl2_splitq_rx_buf_desc *)((rxq)->desc_ring))[i])) -#define IDPF_SPLITQ_RX_BI_DESC (rxq, i) ((((rxq)->ring))[i]) - -#define IDPF_BASE_TX_DESC (txq, i) \ - (&(((struct idpf_base_tx_desc *)((txq)->desc_ring))[i])) -#define IDPF_BASE_TX_CTX_DESC (txq, i) \ - (&(((struct idpf_base_tx_ctx_desc *)((txq)->desc_ring))[i])) -#define IDPF_SPLITQ_TX_COMPLQ_DESC (txcq, i) \ - (&(((struct idpf_splitq_tx_compl_desc *)((txcq)->desc_ring))[i])) - -#define IDPF_FLEX_TX_DESC (txq, i) \ - (&(((union idpf_tx_flex_desc *)((txq)->desc_ring))[i])) -#define IDPF_FLEX_TX_CTX_DESC (txq, i) \ - (&(((struct idpf_flex_tx_ctx_desc *)((txq)->desc_ring))[i])) -#define IDPF_DESC_UNUSED (txq) \ ((((txq)->next_to_clean > (txq)->next_to_use) ? 0 : (txq)->desc_count) + \ (txq)->next_to_clean - (txq)->next_to_use - 1)
@@ -275,9 +257,6 @@ struct idpf_rx_extracted {#define IDPF_TX_MAX_DESC_DATA_ALIGNED \ ALIGN_DOWN(IDPF_TX_MAX_DESC_DATA, IDPF_TX_MAX_READ_REQ_SIZE) -#define IDPF_RX_DESC (rxq, i) \ - (&(((union virtchnl2_rx_desc *)((rxq)->desc_ring))[i])) -#define idpf_rx_buf libie_rx_buffer#define IDPF_RX_MAX_PTYPE_PROTO_IDS 32
@@ -586,7 +565,21 @@ struct idpf_queue {struct page_pool *pp;struct device *dev; }; -void *desc_ring; +union { +union virtchnl2_rx_desc *rx; + +struct virtchnl2_singleq_rx_buf_desc *single_buf; +struct virtchnl2_splitq_rx_buf_desc *split_buf; + +struct idpf_base_tx_desc *base_tx; +struct idpf_base_tx_ctx_desc *base_ctx; +union idpf_tx_flex_desc *flex_tx; +struct idpf_flex_tx_ctx_desc *flex_ctx; + +struct idpf_splitq_tx_compl_desc *comp; + +void *desc_ring; + };u32 hdr_truesize;u32 truesize;
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 20/34 idpf: make complq cleaning dependent on scheduling mode
In reply to Alexander LobakinFrom: Michal Kubiak <[email protected]>
Extend completion queue cleaning function to support queue-based scheduling mode needed for XDP queues.
Add 4-byte descriptor for queue-based scheduling mode and perform some refactoring to extract the common code for both scheduling modes.
Make the completion desc parsing function a static inline, as we'll need it in a different file soon.
--- .../net/ethernet/intel/idpf/idpf_lan_txrx.h | 6 +- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 203 ++++++++++-------- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 44 ++++ 3 files changed, 166 insertions(+), 87 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_lan_txrx.h +5 -1
@@ -184,13 +184,17 @@ struct idpf_base_tx_desc {__le64 qw1;/* type_cmd_offset_bsz_l2tag1 */ };/* read used with buffer queues */ -struct idpf_splitq_tx_compl_desc { +struct idpf_splitq_4b_tx_compl_desc {/* qid=[10:0] comptype=[13:11] rsvd=[14] gen=[15] */ __le16 qid_comptype_gen;union {__le16 q_head;/* Queue head */ __le16 compl_tag;/* Completion tag */ } q_head_compl_tag; +};/* writeback used with completion queues */ + +struct idpf_splitq_tx_compl_desc { +struct idpf_splitq_4b_tx_compl_desc common;u8 ts[3 ];u8 rsvd;/* Reserved */ };/* writeback used with completion queues */
drivers/net/ethernet/intel/idpf/idpf_txrx.c +117 -86
271 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_txrx.h +44 -0
56 lines not on this page · raw message
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 21/34 idpf: prepare structures to support xdp
In reply to Alexander LobakinFrom: Michal Kubiak <[email protected]>
Extend basic structures of the driver (e.g. 'idpf_vport', 'idpf_queue', 'idpf_vport_user_config_data') by adding members necessary to support XDP. Add extra XDP Tx queues needed to support XDP_TX and XDP_REDIRECT actions without interfering a regular Tx traffic.
Also add functions dedicated to support XDP initialization for Rx and Tx queues and call those functions from the existing algorithms of queues configuration.
--- drivers/net/ethernet/intel/idpf/Makefile | 2 + drivers/net/ethernet/intel/idpf/idpf.h | 23 +++ .../net/ethernet/intel/idpf/idpf_ethtool.c | 6 +- drivers/net/ethernet/intel/idpf/idpf_lib.c | 25 ++- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 122 ++++++++++++++- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 24 ++- .../net/ethernet/intel/idpf/idpf_virtchnl.c | 36 +++-- drivers/net/ethernet/intel/idpf/idpf_xdp.c | 147 ++++++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_xdp.h | 15 ++ 9 files changed, 375 insertions(+), 25 deletions(-) create mode 100644 drivers/net/ethernet/intel/idpf/idpf_xdp.c create mode 100644 drivers/net/ethernet/intel/idpf/idpf_xdp.h
drivers/net/ethernet/intel/idpf/Makefile +2 -0
@@ -16,3 +16,5 @@ idpf-y := \ idpf_txrx.o \ idpf_virtchnl.o \ idpf_vf_dev.o + +idpf-objs += idpf_xdp.o
drivers/net/ethernet/intel/idpf/idpf.h +23 -0
@@ -376,6 +376,14 @@ struct idpf_vport {struct idpf_queue **txqs;bool crc_enable; +bool xdpq_share; +u16 num_xdp_txq; +u16 num_xdp_rxq; +u16 num_xdp_complq; +u16 xdp_txq_offset; +u16 xdp_rxq_offset; +u16 xdp_complq_offset; +u16 num_rxq;u16 num_bufq;u32 rxq_desc_count;
@@ -465,8 +473,11 @@ struct idpf_vport_user_config_data {struct idpf_rss_data rss_data;u16 num_req_tx_qs;u16 num_req_rx_qs; +u16 num_req_xdp_qs;u32 num_req_txq_desc;u32 num_req_rxq_desc; +/* Duplicated in queue structure for performance reasons */ +struct bpf_prog *xdp_prog;DECLARE_BITMAP (user_flags, __IDPF_USER_FLAGS_NBITS);struct list_head mac_filter_list; };
@@ -685,6 +696,18 @@ static inline int idpf_is_queue_model_split(u16 q_model)return q_model ==VIRTCHNL2_QUEUE_MODEL_SPLIT ; } +/** +* idpf_xdp_is_prog_ena - check if there is an XDP program on adapter +* @vport: vport to check +*/ +static inline bool idpf_xdp_is_prog_ena (const struct idpf_vport *vport) +{ +if (!vport->adapter) +return false; + +return !!vport->adapter->vport_config[vport->idx]->user_config.xdp_prog; +} +#define idpf_is_cap_ena (adapter, field, flag) \ idpf_is_capability_ena(adapter, false, field, flag)#define idpf_is_cap_ena_all (adapter, field, flag) \
drivers/net/ethernet/intel/idpf/idpf_ethtool.c +4 -2
@@ -186,9 +186,11 @@ static void idpf_get_channels(struct net_device *netdev, {struct idpf_netdev_priv *np =netdev_priv (netdev);struct idpf_vport_config *vport_config; +const struct idpf_vport *vport;u16 num_txq, num_rxq;u16 combined; + vport =idpf_netdev_to_vport (netdev); vport_config = np->adapter->vport_config[np->vport_idx]; num_txq = vport_config->user_config.num_req_tx_qs;
@@ -202,8 +204,8 @@ static void idpf_get_channels(struct net_device *netdev, ch->max_rx = vport_config->max_q.max_rxq; ch->max_tx = vport_config->max_q.max_txq; - ch->max_other =IDPF_MAX_MBXQ ; - ch->other_count =IDPF_MAX_MBXQ ; + ch->max_other =IDPF_MAX_MBXQ + vport->num_xdp_txq; + ch->other_count =IDPF_MAX_MBXQ + vport->num_xdp_txq; ch->combined_count = combined; ch->rx_count = num_rxq - combined;
drivers/net/ethernet/intel/idpf/idpf_lib.c +21 -4
@@ -2,6 +2,7 @@/* Copyright (C) 2023 Intel Corporation */ #include "idpf.h" +#include "idpf_xdp.h" static const struct net_device_ops idpf_netdev_ops_splitq;static const struct net_device_ops idpf_netdev_ops_singleq;
@@ -912,6 +913,7 @@ static void idpf_vport_stop(struct idpf_vport *vport)idpf_remove_features (vport); vport->link_up = false; +idpf_xdp_rxq_info_deinit_all (vport);idpf_vport_intr_deinit (vport);idpf_vport_intr_rel (vport);idpf_vport_queues_rel (vport);
@@ -1299,13 +1301,18 @@ static void idpf_restore_features(struct idpf_vport *vport)*/ static int idpf_set_real_num_queues (struct idpf_vport *vport) { -int err; +int num_txq, err; err =netif_set_real_num_rx_queues (vport->netdev, vport->num_rxq);if (err)return err; -return netif_set_real_num_tx_queues (vport->netdev, vport->num_txq); +if (idpf_xdp_is_prog_ena (vport)) + num_txq = vport->num_txq - vport->num_xdp_txq; +else + num_txq = vport->num_txq; + +return netif_set_real_num_tx_queues (vport->netdev, num_txq); }/**
@@ -1418,18 +1425,26 @@ static int idpf_vport_open(struct idpf_vport *vport, bool alloc_res)idpf_rx_init_buf_tail (vport); + err =idpf_xdp_rxq_info_init_all (vport); +if (err) { +netdev_err (vport->netdev, +"Failed to initialize XDP RxQ info for vport %u: %pe\n" , + vport->vport_id,ERR_PTR (err)); + goto intr_deinit; + } + err =idpf_send_config_queues_msg (vport);if (err) {dev_err (&adapter->pdev->dev,"Failed to configure queues for vport %u, %d\n" , vport->vport_id, err); - goto intr_deinit; + goto rxq_deinit; } err =idpf_send_map_unmap_queue_vector_msg (vport, true);if (err) {dev_err (&adapter->pdev->dev,"Failed to map queue vectors for vport %u: %d\n" , vport->vport_id, err); - goto intr_deinit; + goto rxq_deinit; } err =idpf_send_enable_queues_msg (vport);
@@ -1477,6 +1492,8 @@ static int idpf_vport_open(struct idpf_vport *vport, bool alloc_res)idpf_send_disable_queues_msg (vport); unmap_queue_vectors:idpf_send_map_unmap_queue_vector_msg (vport, false); +rxq_deinit: +idpf_xdp_rxq_info_deinit_all (vport); intr_deinit:idpf_vport_intr_deinit (vport); intr_rel:
drivers/net/ethernet/intel/idpf/idpf_txrx.c +117 -5
229 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_txrx.h +19 -5
@@ -4,8 +4,7 @@#ifndef _IDPF_TXRX_H_#define _IDPF_TXRX_H_ -#include <linux/net/intel/libie/rx.h> -#include <linux/net/intel/libie/tx.h> +#include <linux/net/intel/libie/xdp.h> #include <net/page_pool/helpers.h> #include <net/tcp.h>
@@ -319,6 +318,7 @@ enum idpf_queue_flags_t { __IDPF_Q_FLOW_SCH_EN, __IDPF_Q_SW_MARKER, __IDPF_Q_POLL_MODE, + __IDPF_Q_XDP, __IDPF_Q_FLAGS_NBITS, };
@@ -554,13 +554,20 @@ struct idpf_queue { };void __iomem *tail;union { -struct idpf_tx_buf *tx_buf; +struct { +struct idpf_tx_buf *tx_buf; +struct libie_xdp_sq_lock xdp_lock; + }; +u32 num_xdp_txq;struct {struct libie_rx_buffer *hdr_buf;struct idpf_rx_buf *buf; } rx_buf; }; -struct page_pool *hdr_pp; +union { +struct page_pool *hdr_pp; +struct idpf_queue **xdpqs; + };union {struct page_pool *pp;struct device *dev;
@@ -582,7 +589,10 @@ struct idpf_queue {void *desc_ring; }; -u32 hdr_truesize; +union { +u32 hdr_truesize; +u32 xdp_tx_active; + };u32 truesize;u16 idx;u16 q_type;
@@ -627,8 +637,12 @@ struct idpf_queue {union {/* Rx */ struct { +struct xdp_rxq_info xdp_rxq; + +struct bpf_prog __rcu *xdp_prog;struct sk_buff *skb; }; +/* Tx */ struct {u16 compl_tag_bufid_m;
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +27 -9
@@ -1947,20 +1947,27 @@ int idpf_send_map_unmap_queue_vector_msg(struct idpf_vport *vport, bool map)struct idpf_txq_group *tx_qgrp = &vport->txq_grps[i];for (j =0 ; j < tx_qgrp->num_txq; j++, k++) { +const struct idpf_q_vector *vec; +u32 v_idx, tx_itr_idx; + vqv[k].queue_type =cpu_to_le32 (tx_qgrp->txqs[j]->q_type); vqv[k].queue_id =cpu_to_le32 (tx_qgrp->txqs[j]->q_id); -if (idpf_is_queue_model_split (vport->txq_model)) { - vqv[k].vector_id = -cpu_to_le16 (tx_qgrp->complq->q_vector->v_idx); - vqv[k].itr_idx = -cpu_to_le32 (tx_qgrp->complq->q_vector->tx_itr_idx); +if (idpf_is_queue_model_split (vport->txq_model)) + vec = tx_qgrp->complq->q_vector; +else + vec = tx_qgrp->txqs[j]->q_vector; + +if (vec) { + v_idx = vec->v_idx; + tx_itr_idx = vec->tx_itr_idx; }else { - vqv[k].vector_id = -cpu_to_le16 (tx_qgrp->txqs[j]->q_vector->v_idx); - vqv[k].itr_idx = -cpu_to_le32 (tx_qgrp->txqs[j]->q_vector->tx_itr_idx); + v_idx =0 ; + tx_itr_idx =VIRTCHNL2_ITR_IDX_1 ; } + + vqv[k].vector_id =cpu_to_le16 (v_idx); + vqv[k].itr_idx =cpu_to_le32 (tx_itr_idx); } }
@@ -3253,6 +3260,17 @@ int idpf_vport_alloc_vec_indexes(struct idpf_vport *vport) vec_info.default_vport = vport->default_vport; vec_info.index = vport->idx; +/* Additional XDP Tx queues share the q_vector with regular Tx and Rx +* queues to which they are assigned. Also, XDP shall request additional +* Tx queues via VIRTCHNL. Therefore, to avoid exceeding over +* "vport->q_vector_idxs array", do not request empty q_vectors +* for XDP Tx queues. +*/ +if (idpf_xdp_is_prog_ena (vport)) + vec_info.num_req_vecs =max_t (u16, + vport->num_txq - vport->num_xdp_txq, + vport->num_rxq); + num_alloc_vecs =idpf_req_rel_vector_indexes (vport->adapter, vport->q_vector_idxs, &vec_info);
drivers/net/ethernet/intel/idpf/idpf_xdp.c new file +147 -0
147 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_xdp.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2023 Intel Corporation */ + +#ifndef _IDPF_XDP_H_ +#define _IDPF_XDP_H_ + +struct idpf_vport ; + +int idpf_xdp_rxq_info_init_all (const struct idpf_vport *vport); +void idpf_xdp_rxq_info_deinit_all (const struct idpf_vport *vport); + +void idpf_vport_xdpq_get (const struct idpf_vport *vport); +void idpf_vport_xdpq_put (const struct idpf_vport *vport); + +#endif /* _IDPF_XDP_H_ */
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 22/34 idpf: implement XDP_SETUP_PROG in ndo_bpf for splitq
In reply to Alexander LobakinFrom: Michal Kubiak <[email protected]>
Implement loading the XDP program using ndo_bpf callback for splitq and XDP_SETUP_PROG parameter.
Add functions for stopping, reconfiguring and restarting all queues when needed.
Also, implement the XDP hot swap mechanism when the existing XDP program is replaced by another one (without a necessity of reconfiguring anything).
--- drivers/net/ethernet/intel/idpf/idpf.h | 2 + drivers/net/ethernet/intel/idpf/idpf_lib.c | 5 +- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 5 + drivers/net/ethernet/intel/idpf/idpf_xdp.c | 160 ++++++++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_xdp.h | 7 + 5 files changed, 177 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/idpf/idpf.h +2 -0
@@ -975,6 +975,8 @@ int idpf_set_promiscuous(struct idpf_adapter *adapter, u32 vport_id);int idpf_send_disable_queues_msg (struct idpf_vport *vport);void idpf_vport_init (struct idpf_vport *vport,struct idpf_vport_max_q *max_q); +int idpf_vport_open (struct idpf_vport *vport,bool alloc_res); +void idpf_vport_stop (struct idpf_vport *vport);u32 idpf_get_vport_id (struct idpf_vport *vport);int idpf_vport_queue_ids_init (struct idpf_vport *vport);int idpf_queue_reg_init (struct idpf_vport *vport);
drivers/net/ethernet/intel/idpf/idpf_lib.c +3 -2
@@ -889,7 +889,7 @@ static void idpf_remove_features(struct idpf_vport *vport)* idpf_vport_stop - Disable a vport * @vport: vport to disable */ -static void idpf_vport_stop (struct idpf_vport *vport) +void idpf_vport_stop (struct idpf_vport *vport) {struct idpf_netdev_priv *np =netdev_priv (vport->netdev);
@@ -1369,7 +1369,7 @@ static void idpf_rx_init_buf_tail(struct idpf_vport *vport)* @vport: vport to bring up * @alloc_res: allocate queue resources */ -static int idpf_vport_open (struct idpf_vport *vport,bool alloc_res) +int idpf_vport_open (struct idpf_vport *vport,bool alloc_res) {struct idpf_netdev_priv *np =netdev_priv (vport->netdev);struct idpf_adapter *adapter = vport->adapter;
@@ -2444,6 +2444,7 @@ static const struct net_device_ops idpf_netdev_ops_splitq = { .ndo_get_stats64 = idpf_get_stats64, .ndo_set_features = idpf_set_features, .ndo_tx_timeout = idpf_tx_timeout, + .ndo_bpf = idpf_xdp, };static const struct net_device_ops idpf_netdev_ops_singleq = {
drivers/net/ethernet/intel/idpf/idpf_txrx.c +5 -0
@@ -929,6 +929,8 @@ static void idpf_vport_queue_grp_rel_all(struct idpf_vport *vport)void idpf_vport_queues_rel (struct idpf_vport *vport) {idpf_vport_xdpq_put (vport); +idpf_copy_xdp_prog_to_qs (vport,NULL ); +idpf_tx_desc_rel_all (vport);idpf_rx_desc_rel_all (vport);idpf_vport_queue_grp_rel_all (vport);
@@ -1485,6 +1487,7 @@ static int idpf_vport_queue_grp_alloc_all(struct idpf_vport *vport)*/ int idpf_vport_queues_alloc (struct idpf_vport *vport) { +struct bpf_prog *prog;int err; err =idpf_vport_queue_grp_alloc_all (vport);
@@ -1503,6 +1506,8 @@ int idpf_vport_queues_alloc(struct idpf_vport *vport)if (err) goto err_out; + prog = vport->adapter->vport_config[vport->idx]->user_config.xdp_prog; +idpf_copy_xdp_prog_to_qs (vport, prog);idpf_vport_xdpq_get (vport);return 0 ;
drivers/net/ethernet/intel/idpf/idpf_xdp.c +160 -0
169 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_xdp.h +7 -0
@@ -4,12 +4,19 @@#ifndef _IDPF_XDP_H_#define _IDPF_XDP_H_ +struct bpf_prog ;struct idpf_vport ; +struct net_device ; +struct netdev_bpf ;int idpf_xdp_rxq_info_init_all (const struct idpf_vport *vport);void idpf_xdp_rxq_info_deinit_all (const struct idpf_vport *vport); +void idpf_copy_xdp_prog_to_qs (const struct idpf_vport *vport, +struct bpf_prog *xdp_prog);void idpf_vport_xdpq_get (const struct idpf_vport *vport);void idpf_vport_xdpq_put (const struct idpf_vport *vport); +int idpf_xdp (struct net_device *netdev,struct netdev_bpf *xdp); +#endif /* _IDPF_XDP_H_ */
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 23/34 idpf: use generic functions to build xdp_buff and skb
In reply to Alexander LobakinIn preparation of XDP support, move from having skb as the main frame container during the Rx polling to &xdp_buff.
This allows to use generic and libie helpers for building an XDP buffer and changes the logics: now we try to allocate an skb only when we processed all the descriptors related to the frame.
For sure, &xdp_buff is "a bit" bigger in size comparing to skb pointer to store on the ring, but I already reserved a cacheline-aligned slot for it earlier.
--- .../ethernet/intel/idpf/idpf_singleq_txrx.c | 60 +++------- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 108 ++++-------------- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 5 +- 3 files changed, 41 insertions(+), 132 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +19 -41
@@ -601,14 +601,9 @@ static bool idpf_rx_singleq_test_staterr(const union virtchnl2_rx_desc *rx_desc,/** * idpf_rx_singleq_is_non_eop - process handling of non-EOP buffers -* @rxq: Rx ring being processed * @rx_desc: Rx descriptor for current buffer -* @skb: Current socket buffer containing buffer in progress -* @ntc: next to clean */ -static bool idpf_rx_singleq_is_non_eop (struct idpf_queue *rxq, -union virtchnl2_rx_desc *rx_desc, -struct sk_buff *skb,u16 ntc) +static bool idpf_rx_singleq_is_non_eop (const union virtchnl2_rx_desc *rx_desc) {/* if we are the last buffer then there is nothing else to do */ if (likely (idpf_rx_singleq_test_staterr (rx_desc,IDPF_RXD_EOF_SINGLEQ )))
@@ -843,9 +838,6 @@ static void idpf_rx_singleq_process_skb_fields(struct idpf_queue *rx_q,struct libie_rx_ptype_parsed parsed = rx_q->vport->rx_ptype_lkup[ptype]; -/* modifies the skb - consumes the enet header */ - skb->protocol =eth_type_trans (skb, rx_q->vport->netdev); -/* Check if we're using base mode descriptor IDs */ if (rx_q->rxdids ==VIRTCHNL2_RXDID_1_32B_BASE_M ) {idpf_rx_singleq_base_hash (rx_q, skb, rx_desc, parsed);
@@ -854,8 +846,6 @@ static void idpf_rx_singleq_process_skb_fields(struct idpf_queue *rx_q,idpf_rx_singleq_flex_hash (rx_q, skb, rx_desc, parsed);idpf_rx_singleq_flex_csum (rx_q, skb, rx_desc, parsed); } - -skb_record_rx_queue (skb, rx_q->idx); }/**
@@ -986,16 +976,19 @@ static void idpf_rx_singleq_extract_fields(struct idpf_queue *rx_q,static int idpf_rx_singleq_clean (struct idpf_queue *rx_q,int budget) {unsigned int total_rx_bytes =0 , total_rx_pkts =0 ; -struct sk_buff *skb = rx_q->skb;u16 ntc = rx_q->next_to_clean;u16 cleaned_count =0 ;bool failure = false; +struct xdp_buff xdp; + +libie_xdp_init_buff (&xdp, &rx_q->xdp, &rx_q->xdp_rxq);/* Process Rx packets bounded by budget */ while (likely (total_rx_pkts < (unsigned int )budget)) {struct idpf_rx_extracted fields = { };union virtchnl2_rx_desc *rx_desc;struct idpf_rx_buf *rx_buf; +struct sk_buff *skb;/* get the Rx desc from Rx queue based on 'next_to_clean' */ rx_desc = &rx_q->rx[ntc];
@@ -1019,45 +1012,35 @@ static int idpf_rx_singleq_clean(struct idpf_queue *rx_q, int budget)idpf_rx_singleq_extract_fields (rx_q, rx_desc, &fields); rx_buf = &rx_q->rx_buf.buf[ntc]; -if (!libie_rx_sync_for_cpu (rx_buf, fields.size)) - goto skip_data; - -if (skb) -idpf_rx_add_frag (rx_buf, skb, fields.size); -else - skb =idpf_rx_build_skb (rx_buf, fields.size); - -/* exit if we failed to retrieve a buffer */ -if (!skb) -break ; - -skip_data: +libie_xdp_process_buff (&xdp, rx_buf, fields.size); rx_buf->page =NULL ;IDPF_SINGLEQ_BUMP_RING_IDX (rx_q, ntc); cleaned_count++;/* skip if it is non EOP desc */ -if (idpf_rx_singleq_is_non_eop (rx_q, rx_desc, skb, ntc)) +if (!xdp.data ||idpf_rx_singleq_is_non_eop (rx_desc))continue ;#define IDPF_RXD_ERR_S FIELD_PREP(VIRTCHNL2_RX_BASE_DESC_QW1_ERROR_M, \ VIRTCHNL2_RX_BASE_DESC_ERROR_RXE_M)if (unlikely (idpf_rx_singleq_test_staterr (rx_desc,IDPF_RXD_ERR_S ))) { -dev_kfree_skb_any (skb); - skb =NULL ; -continue ; - } +drop_cont: +xdp_return_buff (&xdp); + xdp.data =NULL ; -/* pad skb if needed (to make valid ethernet frame) */ -if (eth_skb_pad (skb)) { - skb =NULL ;continue ; } -/* probably a little skewed due to removing CRC */ - total_rx_bytes += skb->len; + total_rx_bytes +=xdp_get_buff_len (&xdp); + total_rx_pkts++; + + skb =xdp_build_skb_from_buff (&xdp); +if (unlikely (!skb)) + goto drop_cont; + + xdp.data =NULL ;/* protocol */ idpf_rx_singleq_process_skb_fields(rx_q, skb,
@@ -1065,15 +1048,10 @@ static int idpf_rx_singleq_clean(struct idpf_queue *rx_q, int budget)/* send completed skb up the stack */ napi_gro_receive (&rx_q->q_vector->napi, skb); - skb =NULL ; - -/* update budget accounting */ - total_rx_pkts++; } - rx_q->skb = skb; - rx_q->next_to_clean = ntc; +libie_xdp_save_buff (&rx_q->xdp, &xdp);if (cleaned_count) failure =idpf_rx_singleq_buf_hw_alloc_all (rx_q, cleaned_count);
drivers/net/ethernet/intel/idpf/idpf_txrx.c +21 -87
184 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_txrx.h +1 -4
@@ -640,7 +640,7 @@ struct idpf_queue {struct xdp_rxq_info xdp_rxq;struct bpf_prog __rcu *xdp_prog; -struct sk_buff *skb; +struct xdp_buff xdp; };/* Tx */
@@ -918,9 +918,6 @@ int idpf_config_rss(struct idpf_vport *vport);int idpf_init_rss (struct idpf_vport *vport);void idpf_deinit_rss (struct idpf_vport *vport);int idpf_rx_bufs_init_all (struct idpf_vport *vport); -void idpf_rx_add_frag (struct idpf_rx_buf *rx_buf,struct sk_buff *skb, -unsigned int size); -struct sk_buff *idpf_rx_build_skb (const struct libie_rx_buffer *buf,u32 size);bool idpf_init_rx_buf_hw_alloc (struct idpf_queue *rxq,struct idpf_rx_buf *buf);void idpf_rx_buf_hw_update (struct idpf_queue *rxq,u32 val); void idpf_tx_buf_hw_update(struct idpf_queue *tx_q, u32 val,
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 24/34 idpf: add support for XDP on Rx
In reply to Alexander LobakinUse libie XDP infra to support running XDP program on Rx polling. This includes all of the possible verdicts/actions.
XDP Tx queues are cleaned only in "lazy" mode when there are less than 1/4 free descriptors left on the ring. Some functions are oneliners around libie's __always_inlines, so that the compiler could uninline them when needed.
--- drivers/net/ethernet/intel/idpf/idpf_lib.c | 6 + drivers/net/ethernet/intel/idpf/idpf_txrx.c | 10 +- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 55 ++++++++ drivers/net/ethernet/intel/idpf/idpf_xdp.c | 140 ++++++++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_xdp.h | 20 ++- 5 files changed, 227 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_lib.c +6 -0
@@ -840,6 +840,12 @@ static int idpf_cfg_netdev(struct idpf_vport *vport) netdev->features |= dflt_features; netdev->hw_features |= dflt_features | offloads; netdev->hw_enc_features |= dflt_features | offloads; + +if (idpf_is_queue_model_split (vport->rxq_model)) +xdp_set_features_flag (netdev,NETDEV_XDP_ACT_BASIC | +NETDEV_XDP_ACT_REDIRECT | +NETDEV_XDP_ACT_RX_SG ); +idpf_set_ethtool_ops (netdev);SET_NETDEV_DEV (netdev, &adapter->pdev->dev);
drivers/net/ethernet/intel/idpf/idpf_txrx.c +9 -1
@@ -1522,7 +1522,7 @@ int idpf_vport_queues_alloc(struct idpf_vport *vport)* idpf_tx_handle_sw_marker - Handle queue marker packet * @tx_q: tx queue to handle software marker */ -static void idpf_tx_handle_sw_marker (struct idpf_queue *tx_q) +void idpf_tx_handle_sw_marker (struct idpf_queue *tx_q) {struct idpf_vport *vport = tx_q->vport;int i;
@@ -3045,8 +3045,11 @@ static int idpf_rx_splitq_clean(struct idpf_queue *rxq, int budget)int total_rx_bytes =0 , total_rx_pkts =0 ;struct idpf_queue *rx_bufq =NULL ;u16 ntc = rxq->next_to_clean; +struct libie_xdp_tx_bulk bq;struct xdp_buff xdp; +libie_xdp_tx_init_bulk (&bq, rxq->xdp_prog, rxq->xdp_rxq.dev, + rxq->xdpqs, rxq->num_xdp_txq);libie_xdp_init_buff (&xdp, &rxq->xdp, &rxq->xdp_rxq);/* Process Rx packets bounded by budget */
@@ -3161,6 +3164,9 @@ static int idpf_rx_splitq_clean(struct idpf_queue *rxq, int budget) total_rx_bytes +=xdp_get_buff_len (&xdp); total_rx_pkts++; +if (!idpf_xdp_run_prog (&xdp, &bq)) +continue ; + skb =xdp_build_skb_from_buff (&xdp);if (unlikely (!skb)) {xdp_return_buff (&xdp);
@@ -3182,7 +3188,9 @@ static int idpf_rx_splitq_clean(struct idpf_queue *rxq, int budget) } rxq->next_to_clean = ntc; +libie_xdp_save_buff (&rxq->xdp, &xdp); +idpf_xdp_finalize_rx (&bq);u64_stats_update_begin (&rxq->stats_sync);u64_stats_add (&rxq->q_stats.rx.packets, total_rx_pkts);
drivers/net/ethernet/intel/idpf/idpf_txrx.h +55 -0
66 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_xdp.c +140 -0
146 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_xdp.h +17 -3
@@ -4,10 +4,9 @@#ifndef _IDPF_XDP_H_#define _IDPF_XDP_H_ -struct bpf_prog ; +#include <linux/net/intel/libie/xdp.h> +struct idpf_vport ; -struct net_device ; -struct netdev_bpf ;int idpf_xdp_rxq_info_init_all (const struct idpf_vport *vport);void idpf_xdp_rxq_info_deinit_all (const struct idpf_vport *vport);
@@ -17,6 +16,21 @@ void idpf_copy_xdp_prog_to_qs(const struct idpf_vport *vport,void idpf_vport_xdpq_get (const struct idpf_vport *vport);void idpf_vport_xdpq_put (const struct idpf_vport *vport); +bool __idpf_xdp_run_prog (struct xdp_buff *xdp,struct libie_xdp_tx_bulk *bq); +void __idpf_xdp_finalize_rx (struct libie_xdp_tx_bulk *bq); + +static inline bool idpf_xdp_run_prog (struct xdp_buff *xdp, +struct libie_xdp_tx_bulk *bq) +{ +return bq->prog ?__idpf_xdp_run_prog (xdp, bq) : true; +} + +static inline void idpf_xdp_finalize_rx (struct libie_xdp_tx_bulk *bq) +{ +if (bq->act_mask >=LIBIE_XDP_TX ) +__idpf_xdp_finalize_rx (bq); +} +int idpf_xdp (struct net_device *netdev,struct netdev_bpf *xdp);#endif /* _IDPF_XDP_H_ */
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 25/34 idpf: add support for .ndo_xdp_xmit()
In reply to Alexander LobakinUse libie XDP infra to implement .ndo_xdp_xmit() in idpf. The Tx callbacks are reused from XDP_TX code. XDP redirect target feature is set/cleared depending on the XDP prog presence, as for now we still don't allocate XDP Tx queues when there's no program.
--- drivers/net/ethernet/intel/idpf/idpf_lib.c | 1 + drivers/net/ethernet/intel/idpf/idpf_xdp.c | 34 ++++++++++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_xdp.h | 2 ++ 3 files changed, 37 insertions(+)
drivers/net/ethernet/intel/idpf/idpf_lib.c +1 -0
@@ -2451,6 +2451,7 @@ static const struct net_device_ops idpf_netdev_ops_splitq = { .ndo_set_features = idpf_set_features, .ndo_tx_timeout = idpf_tx_timeout, .ndo_bpf = idpf_xdp, + .ndo_xdp_xmit = idpf_xdp_xmit, };static const struct net_device_ops idpf_netdev_ops_singleq = {
drivers/net/ethernet/intel/idpf/idpf_xdp.c +34 -0
@@ -313,6 +313,35 @@ bool __idpf_xdp_run_prog(struct xdp_buff *xdp, struct libie_xdp_tx_bulk *bq)return libie_xdp_run_prog (xdp, bq, idpf_xdp_tx_flush_bulk); } +/** +* idpf_xdp_xmit - submit packets to xdp ring for transmission +* @dev: netdev +* @n: number of xdp frames to be transmitted +* @frames: xdp frames to be transmitted +* @flags: transmit flags +* +* Returns number of frames successfully sent. Frames that fail are +* free'ed via XDP return API. +* For error cases, a negative errno code is returned and no-frames +* are transmitted (caller must handle freeing frames). +*/ +int idpf_xdp_xmit (struct net_device *dev,int n,struct xdp_frame **frames, +u32 flags) +{ +struct idpf_netdev_priv *np =netdev_priv (dev); +struct idpf_vport *vport = np->vport; + +if (unlikely (!netif_carrier_ok (dev) || !vport->link_up)) +return -ENETDOWN ; +if (unlikely (!idpf_xdp_is_prog_ena (vport))) +return -ENXIO ; + +return libie_xdp_xmit_do_bulk (dev, n, frames, flags, + &vport->txqs[vport->xdp_txq_offset], + vport->num_xdp_txq, idpf_xdp_tx_prep, + idpf_xdp_tx_xmit, idpf_xdp_tx_finalize); +} +/** * idpf_xdp_reconfig_queues - reconfigure queues after the XDP setup * @vport: vport to load or unload XDP for
@@ -410,6 +439,11 @@ idpf_xdp_setup_prog(struct idpf_vport *vport, struct bpf_prog *prog,return err; } +if (prog) +xdp_features_set_redirect_target (vport->netdev, false); +else +xdp_features_clear_redirect_target (vport->netdev); +if (vport_is_up) { err =idpf_vport_open (vport, false);if (err) {
drivers/net/ethernet/intel/idpf/idpf_xdp.h +2 -0
@@ -31,6 +31,8 @@ static inline void idpf_xdp_finalize_rx(struct libie_xdp_tx_bulk *bq) __idpf_xdp_finalize_rx(bq); } +int idpf_xdp_xmit (struct net_device *dev,int n,struct xdp_frame **frames, +u32 flags);int idpf_xdp (struct net_device *netdev,struct netdev_bpf *xdp);#endif /* _IDPF_XDP_H_ */
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 26/34 xdp: add generic XSk xdp_buff -> skb conversion
In reply to Alexander LobakinSame as with converting &xdp_buff to skb on Rx, the code which allocates a new skb and copies the XSk frame there is identical across the drivers, so make it generic.
Note that this time skb_record_rx_queue() is called unconditionally, as it's not intended to call this function with a non-registered RxQ info.
--- include/net/xdp.h | 11 ++++++++++- net/core/xdp.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-)
include/net/xdp.h +10 -1
@@ -273,7 +273,16 @@ void xdp_warn(const char *msg, const char *func, const int line);struct sk_buff *__xdp_build_skb_from_buff (struct sk_buff *skb,const struct xdp_buff *xdp); -#define xdp_build_skb_from_buff (xdp) __xdp_build_skb_from_buff(NULL, xdp) +struct sk_buff *xdp_build_skb_from_zc (struct napi_struct *napi, +struct xdp_buff *xdp); + +static inline struct sk_buff *xdp_build_skb_from_buff (struct xdp_buff *xdp) +{ +if (xdp->rxq->mem.type ==MEM_TYPE_XSK_BUFF_POOL ) +return xdp_build_skb_from_zc (NULL , xdp); + +return __xdp_build_skb_from_buff (NULL , xdp); +}struct xdp_frame *xdp_convert_zc_to_xdp_frame (struct xdp_buff *xdp); struct sk_buff *__xdp_build_skb_from_frame(struct xdp_frame *xdpf,
net/core/xdp.c +41 -0
53 lines not on this page · raw message
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 27/34 idpf: add support for sw interrupt
In reply to Alexander LobakinFrom: Michal Kubiak <[email protected]>
Sometimes, it may be needed to be able to trigger a HW interrupt without a "real" interrupt from the hardware.
Add the corresponding register fields to the register table.
--- drivers/net/ethernet/intel/idpf/idpf_dev.c | 3 +++ drivers/net/ethernet/intel/idpf/idpf_txrx.h | 4 ++++ drivers/net/ethernet/intel/idpf/idpf_vf_dev.c | 3 +++ 3 files changed, 10 insertions(+)
drivers/net/ethernet/intel/idpf/idpf_dev.c +3 -0
@@ -100,6 +100,9 @@ static int idpf_intr_reg_init(struct idpf_vport *vport) intr->dyn_ctl_itridx_s =PF_GLINT_DYN_CTL_ITR_INDX_S ; intr->dyn_ctl_intrvl_s =PF_GLINT_DYN_CTL_INTERVAL_S ; intr->dyn_ctl_wb_on_itr_m =PF_GLINT_DYN_CTL_WB_ON_ITR_M ; + intr->dyn_ctl_swint_trig_m =PF_GLINT_DYN_CTL_SWINT_TRIG_M ; + intr->dyn_ctl_sw_itridx_ena_m = +PF_GLINT_DYN_CTL_SW_ITR_INDX_ENA_M ; spacing =IDPF_ITR_IDX_SPACING (reg_vals[vec_id].itrn_index_spacing,IDPF_PF_ITR_IDX_SPACING );
drivers/net/ethernet/intel/idpf/idpf_txrx.h +4 -0
@@ -347,6 +347,8 @@ struct idpf_vec_regs {* @dyn_ctl_itridx_m: Mask for ITR index * @dyn_ctl_intrvl_s: Register bit offset for ITR interval * @dyn_ctl_wb_on_itr_m: Mask for WB on ITR feature +* @dyn_ctl_swint_trig_m: Mask for SW ITR trigger register +* @dyn_ctl_sw_itridx_ena_m: Mask for SW ITR enable index * @rx_itr: RX ITR register * @tx_itr: TX ITR register * @icr_ena: Interrupt cause register offset
@@ -360,6 +362,8 @@ struct idpf_intr_reg {u32 dyn_ctl_itridx_m;u32 dyn_ctl_intrvl_s;u32 dyn_ctl_wb_on_itr_m; +u32 dyn_ctl_swint_trig_m; +u32 dyn_ctl_sw_itridx_ena_m;void __iomem *rx_itr;void __iomem *tx_itr;void __iomem *icr_ena;
drivers/net/ethernet/intel/idpf/idpf_vf_dev.c +3 -0
@@ -99,6 +99,9 @@ static int idpf_vf_intr_reg_init(struct idpf_vport *vport) intr->dyn_ctl_intena_msk_m =VF_INT_DYN_CTLN_INTENA_MSK_M ; intr->dyn_ctl_itridx_s =VF_INT_DYN_CTLN_ITR_INDX_S ; intr->dyn_ctl_wb_on_itr_m =VF_INT_DYN_CTLN_WB_ON_ITR_M ; + intr->dyn_ctl_itridx_m =VF_INT_DYN_CTLN_ITR_INDX_M ; + intr->dyn_ctl_sw_itridx_ena_m = +VF_INT_DYN_CTLN_SW_ITR_INDX_ENA_M ; spacing =IDPF_ITR_IDX_SPACING (reg_vals[vec_id].itrn_index_spacing,IDPF_VF_ITR_IDX_SPACING );
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 28/34 idpf: add relative queue id member to idpf_queue
In reply to Alexander LobakinFrom: Michal Kubiak <[email protected]>
Relative queue id is one of the required fields of the Tx queue description in VC 2.0 for splitq mode.
In the current VC implementation all Tx queues are configured together, so the relative queue id (the index of the Tx queue in the queue group) can be computed on the fly.
However, such a solution is not flexible because it is not easy to configure a single Tx queue. So, instead, introduce a new structure member in 'idpf_queue' dedicated to storing the relative queue id. Then send that value over the VC.
This patch is the first step in making the existing VC API more flexible to allow configuration of single queues.
--- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 1 + drivers/net/ethernet/intel/idpf/idpf_txrx.h | 2 ++ drivers/net/ethernet/intel/idpf/idpf_virtchnl.c | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/idpf/idpf_txrx.c +1 -0
@@ -1276,6 +1276,7 @@ static int idpf_txq_group_alloc(struct idpf_vport *vport, u16 num_txq) q->tx_min_pkt_len =idpf_get_min_tx_pkt_len (adapter); q->vport = vport; q->txq_grp = tx_qgrp; + q->relative_q_id = j;if (!flow_sch_en)continue ;
drivers/net/ethernet/intel/idpf/idpf_txrx.h +2 -0
@@ -665,6 +665,8 @@ struct idpf_queue {dma_addr_t dma;unsigned int size; + +u32 relative_q_id; }____cacheline_internodealigned_in_smp ;/**
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +2 -1
@@ -1491,7 +1491,8 @@ static int idpf_send_config_tx_queues_msg(struct idpf_vport *vport) qi[k].tx_compl_queue_id =cpu_to_le16 (tx_qgrp->complq->q_id); - qi[k].relative_queue_id =cpu_to_le16 (j); + qi[k].relative_queue_id = +cpu_to_le16 (q->relative_q_id);if (test_bit (__IDPF_Q_FLOW_SCH_EN, q->flags)) qi[k].sched_mode =
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 29/34 idpf: add vc functions to manage selected queues
In reply to Alexander LobakinFrom: Michal Kubiak <[email protected]>
Implement VC functions dedicated to enabling, disabling and configuring randomly selected queues.
Also, refactor the existing implementation to make the code more modular. Introduce new generic functions for sending VC messages consisting of chunks, in order to isolate the sending algorithm and its implementation for specific VC messages.
Finally, rewrite the function for mapping queues to q_vectors using the new modular approach to avoid copying the code that implements the VC message sending algorithm.
--- drivers/net/ethernet/intel/idpf/idpf.h | 9 + .../net/ethernet/intel/idpf/idpf_virtchnl.c | 1085 +++++++++++------ 2 files changed, 693 insertions(+), 401 deletions(-)
drivers/net/ethernet/intel/idpf/idpf.h +9 -0
@@ -982,6 +982,15 @@ int idpf_vport_queue_ids_init(struct idpf_vport *vport);int idpf_queue_reg_init (struct idpf_vport *vport);int idpf_send_config_queues_msg (struct idpf_vport *vport);int idpf_send_enable_queues_msg (struct idpf_vport *vport); +int idpf_send_enable_selected_queues_msg (struct idpf_vport *vport, +struct idpf_queue **qs, +int num_q); +int idpf_send_disable_selected_queues_msg (struct idpf_vport *vport, +struct idpf_queue **qs, +int num_q); +int idpf_send_config_selected_queues_msg (struct idpf_vport *vport, +struct idpf_queue **qs, +int num_q);int idpf_send_create_vport_msg (struct idpf_adapter *adapter,struct idpf_vport_max_q *max_q);int idpf_check_supported_desc_ids (struct idpf_vport *vport);
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +684 -401
1,276 lines not on this page · raw message
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 30/34 idpf: move search rx and tx queues to header
In reply to Alexander LobakinFrom: Michal Kubiak <[email protected]>
Move Rx and Tx queue lookup functions from the ethtool implementation to the idpf header.
Now, those functions can be used globally, including XDP configuration.
--- drivers/net/ethernet/intel/idpf/idpf.h | 41 +++++++++++++++++++ .../net/ethernet/intel/idpf/idpf_ethtool.c | 39 ------------------ 2 files changed, 41 insertions(+), 39 deletions(-)
drivers/net/ethernet/intel/idpf/idpf.h +41 -0
@@ -696,6 +696,47 @@ static inline int idpf_is_queue_model_split(u16 q_model)return q_model ==VIRTCHNL2_QUEUE_MODEL_SPLIT ; } +/** +* idpf_find_rxq - find rxq from q index +* @vport: virtual port associated to queue +* @q_num: q index used to find queue +* +* returns pointer to rx queue +*/ +static inline struct idpf_queue * +idpf_find_rxq (struct idpf_vport *vport,int q_num) +{ +int q_grp, q_idx; + +if (!idpf_is_queue_model_split (vport->rxq_model)) +return vport->rxq_grps->singleq.rxqs[q_num]; + + q_grp = q_num /IDPF_DFLT_SPLITQ_RXQ_PER_GROUP ; + q_idx = q_num %IDPF_DFLT_SPLITQ_RXQ_PER_GROUP ; + +return &vport->rxq_grps[q_grp].splitq.rxq_sets[q_idx]->rxq; +} + +/** +* idpf_find_txq - find txq from q index +* @vport: virtual port associated to queue +* @q_num: q index used to find queue +* +* returns pointer to tx queue +*/ +static inline struct idpf_queue * +idpf_find_txq (struct idpf_vport *vport,int q_num) +{ +int q_grp; + +if (!idpf_is_queue_model_split (vport->txq_model)) +return vport->txqs[q_num]; + + q_grp = q_num /IDPF_DFLT_SPLITQ_TXQ_PER_GROUP ; + +return vport->txq_grps[q_grp].complq; +} +/** * idpf_xdp_is_prog_ena - check if there is an XDP program on adapter * @vport: vport to check
drivers/net/ethernet/intel/idpf/idpf_ethtool.c +0 -39
@@ -953,45 +953,6 @@ static void idpf_get_ethtool_stats(struct net_device *netdev,idpf_vport_ctrl_unlock (netdev); } -/** -* idpf_find_rxq - find rxq from q index -* @vport: virtual port associated to queue -* @q_num: q index used to find queue -* -* returns pointer to rx queue -*/ -static struct idpf_queue *idpf_find_rxq (struct idpf_vport *vport,int q_num) -{ -int q_grp, q_idx; - -if (!idpf_is_queue_model_split (vport->rxq_model)) -return vport->rxq_grps->singleq.rxqs[q_num]; - - q_grp = q_num /IDPF_DFLT_SPLITQ_RXQ_PER_GROUP ; - q_idx = q_num %IDPF_DFLT_SPLITQ_RXQ_PER_GROUP ; - -return &vport->rxq_grps[q_grp].splitq.rxq_sets[q_idx]->rxq; -} - -/** -* idpf_find_txq - find txq from q index -* @vport: virtual port associated to queue -* @q_num: q index used to find queue -* -* returns pointer to tx queue -*/ -static struct idpf_queue *idpf_find_txq (struct idpf_vport *vport,int q_num) -{ -int q_grp; - -if (!idpf_is_queue_model_split (vport->txq_model)) -return vport->txqs[q_num]; - - q_grp = q_num /IDPF_DFLT_SPLITQ_TXQ_PER_GROUP ; - -return vport->txq_grps[q_grp].complq; -} -/** * __idpf_get_q_coalesce - get ITR values for specific queue * @ec: ethtool structure to fill with driver's coalesce settings
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 31/34 idpf: add XSk pool initialization
In reply to Alexander LobakinFrom: Michal Kubiak <[email protected]>
Add functionality to setup an XSk buffer pool, including ability to stop, reconfig and start only selected queues, not the whole device. Pool DMA mapping is managed by libie.
--- drivers/net/ethernet/intel/idpf/Makefile | 1 + drivers/net/ethernet/intel/idpf/idpf.h | 13 + drivers/net/ethernet/intel/idpf/idpf_txrx.c | 14 +- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 6 + drivers/net/ethernet/intel/idpf/idpf_xdp.c | 5 + drivers/net/ethernet/intel/idpf/idpf_xsk.c | 474 ++++++++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_xsk.h | 15 + 7 files changed, 521 insertions(+), 7 deletions(-) create mode 100644 drivers/net/ethernet/intel/idpf/idpf_xsk.c create mode 100644 drivers/net/ethernet/intel/idpf/idpf_xsk.h
drivers/net/ethernet/intel/idpf/Makefile +1 -0
@@ -18,3 +18,4 @@ idpf-y := \ idpf_vf_dev.o idpf-objs += idpf_xdp.o +idpf-objs += idpf_xsk.o
drivers/net/ethernet/intel/idpf/idpf.h +13 -0
@@ -464,6 +464,7 @@ struct idpf_rss_data {* ethtool * @num_req_rxq_desc: Number of user requested RX queue descriptors through * ethtool +* @af_xdp_zc_qps: Mask of queue pairs where the AF_XDP socket is established * @user_flags: User toggled config flags * @mac_filter_list: List of MAC filters *
@@ -480,6 +481,7 @@ struct idpf_vport_user_config_data {struct bpf_prog *xdp_prog;DECLARE_BITMAP (user_flags, __IDPF_USER_FLAGS_NBITS);struct list_head mac_filter_list; +DECLARE_BITMAP (af_xdp_zc_qps,IDPF_LARGE_MAX_Q ); };/**
@@ -959,6 +961,17 @@ static inline void idpf_vport_ctrl_unlock(struct net_device *netdev)mutex_unlock (&np->adapter->vport_ctrl_lock); } +/** +* idpf_vport_ctrl_is_locked - Check if vport control lock is taken +* @netdev: Network interface device structure +*/ +static inline bool idpf_vport_ctrl_is_locked (struct net_device *netdev) +{ +struct idpf_netdev_priv *np =netdev_priv (netdev); + +return mutex_is_locked (&np->adapter->vport_ctrl_lock); +} +void idpf_statistics_task (struct work_struct *work);void idpf_init_task (struct work_struct *work);void idpf_service_task (struct work_struct *work);
drivers/net/ethernet/intel/idpf/idpf_txrx.c +7 -7
@@ -100,7 +100,7 @@ static void idpf_tx_buf_rel_all(struct idpf_queue *txq)* * Free all transmit software resources */ -static void idpf_tx_desc_rel (struct idpf_queue *txq,bool bufq) +void idpf_tx_desc_rel (struct idpf_queue *txq,bool bufq) {if (bufq)idpf_tx_buf_rel_all (txq);
@@ -194,7 +194,7 @@ static int idpf_tx_buf_alloc_all(struct idpf_queue *tx_q)* * Returns 0 on success, negative on failure */ -static int idpf_tx_desc_alloc (struct idpf_queue *tx_q,bool bufq) +int idpf_tx_desc_alloc (struct idpf_queue *tx_q,bool bufq) {struct device *dev = tx_q->dev;u32 desc_sz;
@@ -385,7 +385,7 @@ static void idpf_rx_buf_rel_all(struct idpf_queue *rxq)* * Free a specific rx queue resources */ -static void idpf_rx_desc_rel (struct idpf_queue *rxq,bool bufq,s32 q_model) +void idpf_rx_desc_rel (struct idpf_queue *rxq,bool bufq,s32 q_model) {if (!rxq)return ;
@@ -649,8 +649,7 @@ static int idpf_rx_buf_alloc_all(struct idpf_queue *rxbufq)* * Returns 0 on success, negative on failure */ -static int idpf_rx_bufs_init (struct idpf_queue *rxbufq, -enum libie_rx_buf_type type) +int idpf_rx_bufs_init (struct idpf_queue *rxbufq,enum libie_rx_buf_type type) {struct libie_buf_queue bq = { .truesize = rxbufq->truesize,
@@ -730,7 +729,7 @@ int idpf_rx_bufs_init_all(struct idpf_vport *vport)* * Returns 0 on success, negative on failure */ -static int idpf_rx_desc_alloc (struct idpf_queue *rxq,bool bufq,s32 q_model) +int idpf_rx_desc_alloc (struct idpf_queue *rxq,bool bufq,s32 q_model) {struct device *dev = rxq->dev;
@@ -1870,7 +1869,8 @@ static void idpf_tx_finalize_complq(struct idpf_queue *complq, int ntc, dont_wake = !complq_ok ||IDPF_TX_BUF_RSV_LOW (tx_q) || np->state != __IDPF_VPORT_UP || - !netif_carrier_ok (tx_q->vport->netdev); + !netif_carrier_ok (tx_q->vport->netdev) || +idpf_vport_ctrl_is_locked (tx_q->vport->netdev);/* Check if the TXQ needs to and can be restarted */ __netif_txq_completed_wake(nq, tx_q->cleaned_pkts, tx_q->cleaned_bytes, IDPF_DESC_UNUSED(tx_q), IDPF_TX_WAKE_THRESH,
drivers/net/ethernet/intel/idpf/idpf_txrx.h +6 -0
@@ -519,6 +519,7 @@ union idpf_queue_stats {* @size: Length of descriptor ring in bytes * @dma: Physical address of ring * @desc_ring: Descriptor ring memory +* @xsk_pool: Pointer to a description of a buffer pool for AF_XDP socket * @tx_max_bufs: Max buffers that can be transmitted with scatter-gather * @tx_min_pkt_len: Min supported packet length * @num_completions: Only relevant for TX completion queue. It tracks the
@@ -948,6 +949,11 @@ bool idpf_rx_singleq_buf_hw_alloc_all(struct idpf_queue *rxq, u16 cleaned_count);int idpf_tso (struct sk_buff *skb,struct idpf_tx_offload_params *off);void idpf_tx_handle_sw_marker (struct idpf_queue *tx_q); +int idpf_rx_desc_alloc (struct idpf_queue *rxq,bool bufq,s32 q_model); +void idpf_rx_desc_rel (struct idpf_queue *rxq,bool bufq,s32 q_model); +int idpf_tx_desc_alloc (struct idpf_queue *tx_q,bool bufq); +void idpf_tx_desc_rel (struct idpf_queue *txq,bool bufq); +int idpf_rx_bufs_init (struct idpf_queue *rxbufq,enum libie_rx_buf_type type);/** * idpf_xdpq_update_tail - Updates the XDP Tx queue tail register
drivers/net/ethernet/intel/idpf/idpf_xdp.c +5 -0
@@ -3,6 +3,7 @@#include "idpf.h" #include "idpf_xdp.h" +#include "idpf_xsk.h" static int idpf_rxq_for_each(const struct idpf_vport *vport, int (*fn)(struct idpf_queue *rxq, void *arg),
@@ -472,6 +473,10 @@ int idpf_xdp(struct net_device *netdev, struct netdev_bpf *xdp)case XDP_SETUP_PROG : err =idpf_xdp_setup_prog (vport, xdp->prog, xdp->extack);break ; +case XDP_SETUP_XSK_POOL : + err =idpf_xsk_pool_setup (vport, xdp->xsk.pool, + xdp->xsk.queue_id); +break ;default : err = -EINVAL ; }
drivers/net/ethernet/intel/idpf/idpf_xsk.c new file +474 -0
474 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_xsk.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2023 Intel Corporation */ + +#ifndef _IDPF_XSK_H_ +#define _IDPF_XSK_H_ + +#include <linux/types.h> + +struct idpf_vport ; +struct xsk_buff_pool ; + +int idpf_xsk_pool_setup (struct idpf_vport *vport,struct xsk_buff_pool *pool, +u32 qid); + +#endif /* !_IDPF_XSK_H_ */
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 32/34 idpf: implement Tx path for AF_XDP
In reply to Alexander LobakinFrom: Michal Kubiak <[email protected]>
Implement Tx handling for AF_XDP feature in zero-copy mode using the libie XSk infra.
--- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 44 ++- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 4 + drivers/net/ethernet/intel/idpf/idpf_xsk.c | 318 ++++++++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_xsk.h | 9 + 4 files changed, 361 insertions(+), 14 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_txrx.c +30 -14
@@ -3,6 +3,7 @@#include "idpf.h" #include "idpf_xdp.h" +#include "idpf_xsk.h" /** * idpf_buf_lifo_push - push a buffer pointer onto stack
@@ -55,30 +56,36 @@ void idpf_tx_timeout(struct net_device *netdev, unsigned int txqueue) } } -/** -* idpf_tx_buf_rel_all - Free any empty Tx buffers -* @txq: queue to be cleaned -*/ -static void idpf_tx_buf_rel_all (struct idpf_queue *txq) +static void idpf_tx_buf_clean (struct idpf_queue *txq) {struct libie_sq_onstack_stats ss = { };struct xdp_frame_bulk bq; -u16 i; - -/* Buffers already cleared, nothing to do */ -if (!txq->tx_buf) -return ;xdp_frame_bulk_init (&bq);rcu_read_lock (); -/* Free all the Tx buffer sk_buffs */ -for (i =0 ; i < txq->desc_count; i++) +for (u32 i =0 ; i < txq->desc_count; i++)libie_tx_complete_any (&txq->tx_buf[i], txq->dev, &bq, &txq->xdp_tx_active, &ss);xdp_flush_frame_bulk (&bq);rcu_read_unlock (); +} + +/** +* idpf_tx_buf_rel_all - Free any empty Tx buffers +* @txq: queue to be cleaned +*/ +static void idpf_tx_buf_rel_all (struct idpf_queue *txq) +{ +/* Buffers already cleared, nothing to do */ +if (!txq->tx_buf) +return ; + +if (test_bit (__IDPF_Q_XSK, txq->flags)) +idpf_xsk_clean_xdpq (txq); +else +idpf_tx_buf_clean (txq);kfree (txq->tx_buf); txq->tx_buf =NULL ;
@@ -86,7 +93,7 @@ static void idpf_tx_buf_rel_all(struct idpf_queue *txq)if (!txq->buf_stack.bufs)return ; -for (i =0 ; i < txq->buf_stack.size; i++) +for (u32 i =0 ; i < txq->buf_stack.size; i++)kfree (txq->buf_stack.bufs[i]);kfree (txq->buf_stack.bufs);
@@ -105,6 +112,8 @@ void idpf_tx_desc_rel(struct idpf_queue *txq, bool bufq)if (bufq)idpf_tx_buf_rel_all (txq); +idpf_xsk_clear_queue (txq); +if (!txq->desc_ring)return ;
@@ -196,6 +205,7 @@ static int idpf_tx_buf_alloc_all(struct idpf_queue *tx_q)*/ int idpf_tx_desc_alloc (struct idpf_queue *tx_q,bool bufq) { +enum virtchnl2_queue_type type;struct device *dev = tx_q->dev;u32 desc_sz;int err;
@@ -228,6 +238,10 @@ int idpf_tx_desc_alloc(struct idpf_queue *tx_q, bool bufq) tx_q->next_to_clean =0 ;set_bit (__IDPF_Q_GEN_CHK, tx_q->flags); + type = bufq ?VIRTCHNL2_QUEUE_TYPE_TX : +VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION ; +idpf_xsk_setup_queue (tx_q, type); +return 0 ; err_alloc:
@@ -3802,7 +3816,9 @@ static bool idpf_tx_splitq_clean_all(struct idpf_q_vector *q_vec,for (i =0 ; i < num_txq; i++) {struct idpf_queue *cq = q_vec->tx[i]; -if (!test_bit (__IDPF_Q_XDP, cq->flags)) +if (test_bit (__IDPF_Q_XSK, cq->flags)) + clean_complete &=idpf_xmit_zc (cq); +else if (!test_bit (__IDPF_Q_XDP, cq->flags)) clean_complete &=idpf_tx_clean_complq (cq, budget_per_q, cleaned);
drivers/net/ethernet/intel/idpf/idpf_txrx.h +4 -0
@@ -313,6 +313,7 @@ struct idpf_ptype_state {* @__IDPF_Q_SW_MARKER: Used to indicate TX queue marker completions * @__IDPF_Q_POLL_MODE: Enable poll mode * @__IDPF_Q_FLAGS_NBITS: Must be last +* @__IDPF_Q_XSK: Queue used to handle the AF_XDP socket */ enum idpf_queue_flags_t { __IDPF_Q_GEN_CHK,
@@ -321,6 +322,7 @@ enum idpf_queue_flags_t { __IDPF_Q_SW_MARKER, __IDPF_Q_POLL_MODE, __IDPF_Q_XDP, + __IDPF_Q_XSK, __IDPF_Q_FLAGS_NBITS, };
@@ -574,10 +576,12 @@ struct idpf_queue {union {struct page_pool *hdr_pp;struct idpf_queue **xdpqs; +struct xsk_buff_pool *xsk_tx; };union {struct page_pool *pp;struct device *dev; +struct xsk_buff_pool *xsk_rx; };union {union virtchnl2_rx_desc *rx;
drivers/net/ethernet/intel/idpf/idpf_xsk.c +318 -0
333 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_xsk.h +9 -0
@@ -6,9 +6,18 @@#include <linux/types.h> +enum virtchnl2_queue_type ; + +struct idpf_queue ;struct idpf_vport ;struct xsk_buff_pool ; +void idpf_xsk_setup_queue (struct idpf_queue *q,enum virtchnl2_queue_type t); +void idpf_xsk_clear_queue (struct idpf_queue *q); + +void idpf_xsk_clean_xdpq (struct idpf_queue *xdpq); +bool idpf_xmit_zc (struct idpf_queue *complq); +int idpf_xsk_pool_setup (struct idpf_vport *vport,struct xsk_buff_pool *pool,u32 qid);
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 33/34 idpf: implement Rx path for AF_XDP
In reply to Alexander LobakinFrom: Michal Kubiak <[email protected]>
Implement RX packet processing specific to AF_XDP ZC using the libie XSk infra. XDP_PASS case is implemented using the generic ZC-to-skb conversion function.
--- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 36 +- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 6 + drivers/net/ethernet/intel/idpf/idpf_xdp.c | 44 ++- drivers/net/ethernet/intel/idpf/idpf_xsk.c | 347 ++++++++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_xsk.h | 4 + 5 files changed, 422 insertions(+), 15 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_txrx.c +25 -11
@@ -409,9 +409,13 @@ void idpf_rx_desc_rel(struct idpf_queue *rxq, bool bufq, s32 q_model) rxq->xdp.data =NULL ; } -if (bufq || !idpf_is_queue_model_split (q_model)) +if (bufq &&test_bit (__IDPF_Q_XSK, rxq->flags)) +idpf_xsk_buf_rel (rxq); +else if (bufq || !idpf_is_queue_model_split (q_model))idpf_rx_buf_rel_all (rxq); +idpf_xsk_clear_queue (rxq); + rxq->next_to_alloc =0 ; rxq->next_to_clean =0 ; rxq->next_to_use =0 ;
@@ -674,6 +678,9 @@ int idpf_rx_bufs_init(struct idpf_queue *rxbufq, enum libie_rx_buf_type type) };int ret; +if (test_bit (__IDPF_Q_XSK, rxbufq->flags)) +return idpf_check_alloc_rx_buffers_zc (rxbufq); + ret =libie_rx_page_pool_create (&bq, &rxbufq->q_vector->napi);if (ret)return ret;
@@ -745,6 +752,7 @@ int idpf_rx_bufs_init_all(struct idpf_vport *vport)*/ int idpf_rx_desc_alloc (struct idpf_queue *rxq,bool bufq,s32 q_model) { +enum virtchnl2_queue_type type;struct device *dev = rxq->dev;if (bufq)
@@ -769,6 +777,9 @@ int idpf_rx_desc_alloc(struct idpf_queue *rxq, bool bufq, s32 q_model) rxq->next_to_use =0 ;set_bit (__IDPF_Q_GEN_CHK, rxq->flags); + type = bufq ?VIRTCHNL2_QUEUE_TYPE_RX_BUFFER :VIRTCHNL2_QUEUE_TYPE_RX ; +idpf_xsk_setup_queue (rxq, type); +return 0 ; }
@@ -2788,8 +2799,8 @@ netdev_tx_t idpf_tx_splitq_start(struct sk_buff *skb,* @rx_desc: Receive descriptor * @parsed: parsed Rx packet type related fields */ -static void idpf_rx_hash (struct idpf_queue *rxq,struct sk_buff *skb, -struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc, +static void idpf_rx_hash (const struct idpf_queue *rxq,struct sk_buff *skb, +const struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc,struct libie_rx_ptype_parsed parsed) {u32 hash;
@@ -2865,7 +2876,7 @@ static void idpf_rx_csum(struct idpf_queue *rxq, struct sk_buff *skb,* @csum: structure to extract checksum fields * **/ -static void idpf_rx_splitq_extract_csum_bits (struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc, +static void idpf_rx_splitq_extract_csum_bits (const struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc,struct idpf_rx_csum_decoded *csum) {u8 qword0, qword1;
@@ -2901,7 +2912,7 @@ static void idpf_rx_splitq_extract_csum_bits(struct virtchnl2_rx_flex_desc_adv_n* length and packet type. */ static int idpf_rx_rsc (struct idpf_queue *rxq,struct sk_buff *skb, -struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc, +const struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc,struct libie_rx_ptype_parsed parsed) {u16 rsc_segments, rsc_seg_len;
@@ -2970,9 +2981,8 @@ static int idpf_rx_rsc(struct idpf_queue *rxq, struct sk_buff *skb,* order to populate the hash, checksum, protocol, and * other fields within the skb. */ -static int idpf_rx_process_skb_fields (struct idpf_queue *rxq, -struct sk_buff *skb, -struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc) +int idpf_rx_process_skb_fields (struct idpf_queue *rxq,struct sk_buff *skb, +const struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc) {struct idpf_rx_csum_decoded csum_bits = { };struct libie_rx_ptype_parsed parsed;
@@ -3851,7 +3861,9 @@ static bool idpf_rx_splitq_clean_all(struct idpf_q_vector *q_vec, int budget,struct idpf_queue *rxq = q_vec->rx[i];int pkts_cleaned_per_q; - pkts_cleaned_per_q =idpf_rx_splitq_clean (rxq, budget_per_q); + pkts_cleaned_per_q =test_bit (__IDPF_Q_XSK, rxq->flags) ? +idpf_clean_rx_irq_zc (rxq, budget_per_q) : +idpf_rx_splitq_clean (rxq, budget_per_q);/* if we clean as many as budgeted, we must not be done */ if (pkts_cleaned_per_q >= budget_per_q) clean_complete = false;
@@ -3859,8 +3871,10 @@ static bool idpf_rx_splitq_clean_all(struct idpf_q_vector *q_vec, int budget, } *cleaned = pkts_cleaned; -for (i =0 ; i < q_vec->num_bufq; i++) -idpf_rx_clean_refillq_all (q_vec->bufq[i]); +for (i =0 ; i < q_vec->num_bufq; i++) { +if (!test_bit (__IDPF_Q_XSK, q_vec->bufq[i]->flags)) +idpf_rx_clean_refillq_all (q_vec->bufq[i]); + }return clean_complete; }
drivers/net/ethernet/intel/idpf/idpf_txrx.h +6 -0
@@ -572,6 +572,7 @@ struct idpf_queue {struct libie_rx_buffer *hdr_buf;struct idpf_rx_buf *buf; } rx_buf; +struct xdp_buff **xsk; };union {struct page_pool *hdr_pp;
@@ -951,6 +952,11 @@ netdev_tx_t idpf_tx_singleq_start(struct sk_buff *skb, struct net_device *netdev);bool idpf_rx_singleq_buf_hw_alloc_all (struct idpf_queue *rxq,u16 cleaned_count); + +struct virtchnl2_rx_flex_desc_adv_nic_3 ; + +int idpf_rx_process_skb_fields (struct idpf_queue *rxq,struct sk_buff *skb, +const struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc);int idpf_tso (struct sk_buff *skb,struct idpf_tx_offload_params *off);void idpf_tx_handle_sw_marker (struct idpf_queue *tx_q);int idpf_rx_desc_alloc (struct idpf_queue *rxq,bool bufq,s32 q_model);
drivers/net/ethernet/intel/idpf/idpf_xdp.c +40 -4
79 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_xsk.c +347 -0
371 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_xsk.h +4 -0
@@ -15,7 +15,11 @@ struct xsk_buff_pool;void idpf_xsk_setup_queue (struct idpf_queue *q,enum virtchnl2_queue_type t);void idpf_xsk_clear_queue (struct idpf_queue *q); +int idpf_check_alloc_rx_buffers_zc (struct idpf_queue *rxbufq); +void idpf_xsk_buf_rel (struct idpf_queue *rxbufq);void idpf_xsk_clean_xdpq (struct idpf_queue *xdpq); + +int idpf_clean_rx_irq_zc (struct idpf_queue *rxq,int budget);bool idpf_xmit_zc (struct idpf_queue *complq); int idpf_xsk_pool_setup(struct idpf_vport *vport, struct xsk_buff_pool *pool,
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerRFC PATCH 34/34 idpf: enable XSk features and ndo_xsk_wakeup
In reply to Alexander LobakinFrom: Michal Kubiak <[email protected]>
Now that AF_XDP functionality is fully implemented, advertise XSk XDP feature and add .ndo_xsk_wakeup() callback to be able to use it with this driver.
--- drivers/net/ethernet/intel/idpf/idpf_lib.c | 5 ++- drivers/net/ethernet/intel/idpf/idpf_xsk.c | 42 ++++++++++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_xsk.h | 2 ++ 3 files changed, 48 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/idpf/idpf_lib.c +4 -1
@@ -3,6 +3,7 @@#include "idpf.h" #include "idpf_xdp.h" +#include "idpf_xsk.h" static const struct net_device_ops idpf_netdev_ops_splitq;static const struct net_device_ops idpf_netdev_ops_singleq;
@@ -844,7 +845,8 @@ static int idpf_cfg_netdev(struct idpf_vport *vport)if (idpf_is_queue_model_split (vport->rxq_model))xdp_set_features_flag (netdev,NETDEV_XDP_ACT_BASIC |NETDEV_XDP_ACT_REDIRECT | -NETDEV_XDP_ACT_RX_SG ); +NETDEV_XDP_ACT_RX_SG | +NETDEV_XDP_ACT_XSK_ZEROCOPY );idpf_set_ethtool_ops (netdev);SET_NETDEV_DEV (netdev, &adapter->pdev->dev);
@@ -2452,6 +2454,7 @@ static const struct net_device_ops idpf_netdev_ops_splitq = { .ndo_tx_timeout = idpf_tx_timeout, .ndo_bpf = idpf_xdp, .ndo_xdp_xmit = idpf_xdp_xmit, + .ndo_xsk_wakeup = idpf_xsk_wakeup, };static const struct net_device_ops idpf_netdev_ops_singleq = {
drivers/net/ethernet/intel/idpf/idpf_xsk.c +42 -0
45 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_xsk.h +2 -0
@@ -10,6 +10,7 @@ enum virtchnl2_queue_type;struct idpf_queue ;struct idpf_vport ; +struct net_device ;struct xsk_buff_pool ;void idpf_xsk_setup_queue (struct idpf_queue *q,enum virtchnl2_queue_type t);
@@ -24,5 +25,6 @@ bool idpf_xmit_zc(struct idpf_queue *complq);int idpf_xsk_pool_setup (struct idpf_vport *vport,struct xsk_buff_pool *pool,u32 qid); +int idpf_xsk_wakeup (struct net_device *netdev,u32 qid,u32 flags);#endif /* !_IDPF_XSK_H_ */
Signature · 1 line
2.43.0
Quoted 25 lines · Alexander Lobakin
I was highly asked to send this WIP before the holidays to trigger some discussions at least for the generic parts.
This all depends on libie[0] and WB-on-ITR fix[1]. The RFC does not guarantee to work perfectly, but at least regular XDP seems to work for me...
In fact, here are 3 separate series:
* 01-08: convert idpf to libie and make it more sane;
* 09-25: add XDP to idpf;
* 26-34: add XSk to idpf.Most people may want to be interested only in the following generic changes:
* 11: allow attaching already registered memory models to XDP RxQ info;
* 12-13: generic helpers for adding a frag to&xdp_buffand converting it to an skb;
* 14: get rid ofxdp_frame::mem.id, allow mixing pages from differentpage_poolswithin one &xdp_buff/&xdp_frame;
* 15: some Page Pool helper;
* 18: it's for libie, but I wanted to talk aboutXDP_TXbulking;
* 26: same as 13, but for converting XSK&xdp_buffto skb.The rest is up to you, driver-specific stuff is pretty boring sometimes.
Quoted 7 lines
I'll be polishing and finishing this all starting January 3rd and then preparing and sending sane series, some early feedback never hurts tho.
Merry Yule!
[0] https://lore.kernel.org/netdev/[email protected]
[1] https://lore.kernel.org/netdev/[email protected]
This is great. Thanks for sharing the entire series.
Which SHA1 should we apply this to? I'm having a hard time applying cleanly.
The libie v7 series applied cleanly on bc044ae9d64b. Which I chose only based on the follow-on page pool patch.
But that base commit causes too many conflicts when applying this. Patch 6 had a trivial one in idpf_rx_singleq_clean (skb = rx_q->skb). But patch 14 has so many conflicts in page_pool.c, that I'm clearly on the wrong track trying to fix up manually.
Alexander Lobakin
maintainerFrom: Willem De Bruijn <[email protected]>
Date: Tue, 26 Dec 2023 15:23:41 -0500
Quoted 39 lines
Quoted 25 lines · Alexander Lobakin
I was highly asked to send this WIP before the holidays to trigger some discussions at least for the generic parts.
This all depends on libie[0] and WB-on-ITR fix[1]. The RFC does not guarantee to work perfectly, but at least regular XDP seems to work for me...
In fact, here are 3 separate series:
* 01-08: convert idpf to libie and make it more sane;
* 09-25: add XDP to idpf;
* 26-34: add XSk to idpf.Most people may want to be interested only in the following generic changes:
* 11: allow attaching already registered memory models to XDP RxQ info;
* 12-13: generic helpers for adding a frag to&xdp_buffand converting it to an skb;
* 14: get rid ofxdp_frame::mem.id, allow mixing pages from differentpage_poolswithin one &xdp_buff/&xdp_frame;
* 15: some Page Pool helper;
* 18: it's for libie, but I wanted to talk aboutXDP_TXbulking;
* 26: same as 13, but for converting XSK&xdp_buffto skb.The rest is up to you, driver-specific stuff is pretty boring sometimes.
Quoted 7 lines
I'll be polishing and finishing this all starting January 3rd and then preparing and sending sane series, some early feedback never hurts tho.
Merry Yule!
[0] https://lore.kernel.org/netdev/[email protected]
[1] https://lore.kernel.org/netdev/[email protected]This is great. Thanks for sharing the entire series.
Which SHA1 should we apply this to? I'm having a hard time applying cleanly.
Quoted 7 lines
The libie v7 series applied cleanly on
bc044ae9d64b. Which I chose only based on the follow-on page pool patch.But that base commit causes too many conflicts when applying this. Patch 6 had a trivial one in
idpf_rx_singleq_clean(skb = rx_q->skb). But patch 14 has so many conflicts inpage_pool.c, that I'm clearly on the wrong track trying to fix up manually.
net-next was updated while I was preparing the series. I also did a couple changes in the basic libie code, but a new rev wasn't sent. Please just use my open GH[0].
[0] https://github.com/alobakin/linux/tree/idpf-libie
Thanks,
Olek
Quoted 50 lines · Alexander Lobakin
From: Willem De Bruijn <[email protected]>
Date: Tue, 26 Dec 2023 15:23:41 -0500Quoted 39 lines
Quoted 25 lines · Alexander Lobakin
I was highly asked to send this WIP before the holidays to trigger some discussions at least for the generic parts.
This all depends on libie[0] and WB-on-ITR fix[1]. The RFC does not guarantee to work perfectly, but at least regular XDP seems to work for me...
In fact, here are 3 separate series:
* 01-08: convert idpf to libie and make it more sane;
* 09-25: add XDP to idpf;
* 26-34: add XSk to idpf.Most people may want to be interested only in the following generic changes:
* 11: allow attaching already registered memory models to XDP RxQ info;
* 12-13: generic helpers for adding a frag to&xdp_buffand converting it to an skb;
* 14: get rid ofxdp_frame::mem.id, allow mixing pages from differentpage_poolswithin one &xdp_buff/&xdp_frame;
* 15: some Page Pool helper;
* 18: it's for libie, but I wanted to talk aboutXDP_TXbulking;
* 26: same as 13, but for converting XSK&xdp_buffto skb.The rest is up to you, driver-specific stuff is pretty boring sometimes.
Quoted 7 lines
I'll be polishing and finishing this all starting January 3rd and then preparing and sending sane series, some early feedback never hurts tho.
Merry Yule!
[0] https://lore.kernel.org/netdev/[email protected]
[1] https://lore.kernel.org/netdev/[email protected]This is great. Thanks for sharing the entire series.
Which SHA1 should we apply this to? I'm having a hard time applying cleanly.
Quoted 7 lines
The libie v7 series applied cleanly on
bc044ae9d64b. Which I chose only based on the follow-on page pool patch.But that base commit causes too many conflicts when applying this. Patch 6 had a trivial one in
idpf_rx_singleq_clean(skb = rx_q->skb). But patch 14 has so many conflicts inpage_pool.c, that I'm clearly on the wrong track trying to fix up manually.
Quoted 5 lines
net-next was updated while I was preparing the series. I also did a couple changes in the basic libie code, but a new rev wasn't sent. Please just use my open GH[0].
Even better, thanks. I'll use that to run my basic XSK tests.