cxgb4/ch_ktls: Fixes in nic tls code
v2 cover cxgb4/ch_ktls: Fixes in nic tls code
This series helps in fixing multiple nic ktls issues. Series is broken into 7 patches.
Patch 1 avoids deciding tls packet based on decrypted bit. If its a retransmit packet which has tls handshake and finish (for encryption), decrypted bit won't be set there, and so we can't rely on decrypted bit.
Patch 2 helps supporting linear skb. SKBs were assumed non-linear. Corrected the length extraction.
Patch 3 fixes kernel panic happening due to creating new skb for each record. As part of fix driver will use same skb to send out one tls record (partial data) of the same SKB.
Patch 4 avoids sending extra data which will be used to make a record 16 byte aligned. We don't need to retransmit those extra few bytes.
Patch 5 handles the cases where retransmit packet has tls starting exchanges which are prior to tls start marker.
Patch 6 handles the small packet case which has partial TAG bytes only. HW can't handle those, hence using sw crypto for such pkts.
Patch 7 corrects the potential tcb update problem.
v1->v2:
- Corrected fixes tag issue.
- Marked chcr_ktls_sw_fallback() static.
Rohit Maheshwari (7):
cxgb4/ch_ktls: decrypted bit is not enough
ch_ktls: Correction in finding correct length
cxgb4/ch_ktls: creating skbs causes panic
ch_ktls: Correction in middle record handling
ch_ktls: packet handling prior to start marker
ch_ktls/cxgb4: handle partial tag alone SKBs
ch_ktls: tcb update fails sometimes
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 3 + .../ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 2 + .../net/ethernet/chelsio/cxgb4/cxgb4_main.c | 3 + .../net/ethernet/chelsio/cxgb4/cxgb4_uld.h | 8 + drivers/net/ethernet/chelsio/cxgb4/sge.c | 111 ++- .../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 785 ++++++++++-------- .../chelsio/inline_crypto/ch_ktls/chcr_ktls.h | 1 + 7 files changed, 543 insertions(+), 370 deletions(-)
Signature · 1 line
2.18.1
PATCH v2 1/7 cxgb4/ch_ktls: decrypted bit is not enough
If skb has retransmit data starting before start marker, e.g. ccs, decrypted bit won't be set for that, and if it has some data to encrypt, then it must be given to crypto ULD. So in place of decrypted, check if socket is tls offloaded. Also, unless skb has some data to encrypt, no need to give it for tls offload handling.
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 3 +++ drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h | 7 +++++++ drivers/net/ethernet/chelsio/cxgb4/sge.c | 3 ++- .../net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 4 ---- 4 files changed, 12 insertions(+), 5 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +3 -0
@@ -1176,6 +1176,9 @@ static u16 cxgb_select_queue(struct net_device *dev, struct sk_buff *skb, txq =netdev_pick_tx (dev, skb, sb_dev);if (xfrm_offload (skb) ||is_ptp_enabled (skb, dev) || skb->encapsulation || +#if IS_ENABLED(CONFIG_CHELSIO_TLS_DEVICE) +cxgb4_is_ktls_skb (skb) || +#endif (proto !=IPPROTO_TCP && proto !=IPPROTO_UDP )) txq = txq % pi->nqsets;
drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h +7 -0
@@ -493,6 +493,13 @@ struct cxgb4_uld_info {#endif }; +#if IS_ENABLED (CONFIG_CHELSIO_TLS_DEVICE ) +static inline bool cxgb4_is_ktls_skb (struct sk_buff *skb) +{ +return skb->sk &&tls_is_sk_tx_device_offloaded (skb->sk); +} +#endif +void cxgb4_uld_enable (struct adapter *adap);void cxgb4_register_uld (enum cxgb4_uld type,const struct cxgb4_uld_info *p);int cxgb4_unregister_uld (enum cxgb4_uld type);
drivers/net/ethernet/chelsio/cxgb4/sge.c +2 -1
@@ -1422,7 +1422,8 @@ static netdev_tx_t cxgb4_eth_xmit(struct sk_buff *skb, struct net_device *dev)#endif /* CHELSIO_IPSEC_INLINE */ #if IS_ENABLED (CONFIG_CHELSIO_TLS_DEVICE ) -if (skb->decrypted) +if (cxgb4_is_ktls_skb (skb) && + (skb->len - (skb_transport_offset (skb) +tcp_hdrlen (skb))))return adap->uld[CXGB4_ULD_KTLS ].tx_handler (skb, dev);#endif /* CHELSIO_TLS_DEVICE */
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +0 -4
@@ -1878,10 +1878,6 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev) mss =skb_is_gso (skb) ?skb_shinfo (skb)->gso_size : skb->data_len; -/* check if we haven't set it for ktls offload */ -if (!skb->sk || !tls_is_sk_tx_device_offloaded (skb->sk)) - goto out; - tls_ctx =tls_get_ctx (skb->sk);if (unlikely (tls_ctx->netdev != dev)) goto out;
Signature · 1 line
2.18.1
Jakub Kicinski
maintainerRe: [net v2 1/7] cxgb4/ch_ktls: decrypted bit is not enough
Quoted 11 lines · On Fri, 23 Oct 2020 11:01:28 +0530 Rohit Maheshwari wrote:
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +3
-0+#if IS_ENABLED (CONFIG_CHELSIO_TLS_DEVICE ) + cxgb4_is_ktls_skb(skb) || +#endif (proto != IPPROTO_TCP && proto != IPPROTO_UDP)) txq = txq % pi->nqsets;drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h +0
-0
drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h struct cxgb4_uld_info { · line 501
Quoted 9 lines
drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h +6
-0@@ -493,6 +493,13 @@ struct cxgb4_uld_info {#endif }; +#if IS_ENABLED (CONFIG_CHELSIO_TLS_DEVICE ) +static inline bool cxgb4_is_ktls_skb (struct sk_buff *skb) +{ +return skb->sk &&tls_is_sk_tx_device_offloaded (skb->sk); +} +#endif
There is no need for those ifdefs.
PATCH v2 2/7 ch_ktls: Correction in finding correct length
In reply to Rohit MaheshwariThere is a possibility of linear skbs coming in. Correcting the length extraction logic.
--- .../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 62 +++++++++++-------- 1 file changed, 37 insertions(+), 25 deletions(-)
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +37 -25
@@ -943,22 +943,21 @@ chcr_ktls_check_tcp_options(struct tcphdr *tcp)* @tx_chan - channel number. * return: NETDEV_TX_OK/NETDEV_TX_BUSY. */ -static int -chcr_ktls_write_tcp_options (struct chcr_ktls_info *tx_info,struct sk_buff *skb, -struct sge_eth_txq *q,uint32_t tx_chan) +static int chcr_ktls_write_tcp_options (struct chcr_ktls_info *tx_info, +struct sk_buff *skb, +struct sge_eth_txq *q,bool fin) { +u32 ctrl, iplen, maclen, wr_mid =0 , pktlen, ndesc, len16;struct fw_eth_tx_pkt_wr *wr;struct cpl_tx_pkt_core *cpl; -u32 ctrl, iplen, maclen;#if IS_ENABLED (CONFIG_IPV6 )struct ipv6hdr *ip6;#endif -unsigned int ndesc;struct tcphdr *tcp; -int len16, pktlen; +u8 buf[150 ] = {0 };struct iphdr *ip;int credits; -u8 buf[150 ]; +u64 cntrl1;void *pos; iplen =skb_network_header_len (skb);
@@ -967,7 +966,7 @@ chcr_ktls_write_tcp_options(struct chcr_ktls_info *tx_info, struct sk_buff *skb,/* packet length = eth hdr len + ip hdr len + tcp hdr len * (including options). */ - pktlen = skb->len - skb->data_len; + pktlen =skb_transport_offset (skb) +tcp_hdrlen (skb); ctrl =sizeof (*cpl) + pktlen; len16 =DIV_ROUND_UP (sizeof (*wr) + ctrl,16 );
@@ -980,6 +979,10 @@ chcr_ktls_write_tcp_options(struct chcr_ktls_info *tx_info, struct sk_buff *skb,return NETDEV_TX_BUSY ; } +if (unlikely (credits <ETHTXQ_STOP_THRES )) { +chcr_eth_txq_stop (q); + wr_mid |=FW_WR_EQUEQ_F |FW_WR_EQUIQ_F ; + } pos = &q->q.desc[q->q.pidx]; wr = pos;
@@ -987,42 +990,51 @@ chcr_ktls_write_tcp_options(struct chcr_ktls_info *tx_info, struct sk_buff *skb, wr->op_immdlen =htonl (FW_WR_OP_V (FW_ETH_TX_PKT_WR ) |FW_WR_IMMDLEN_V (ctrl)); - wr->equiq_to_len16 =htonl (FW_WR_LEN16_V (len16)); + wr->equiq_to_len16 =htonl (wr_mid |FW_WR_LEN16_V (len16)); wr->r3 =0 ; cpl = (void *)(wr +1 );/* CPL header */ - cpl->ctrl0 =htonl (TXPKT_OPCODE_V (CPL_TX_PKT ) |TXPKT_INTF_V (tx_chan) | + cpl->ctrl0 =htonl (TXPKT_OPCODE_V (CPL_TX_PKT ) | +TXPKT_INTF_V (tx_info->tx_chan) |TXPKT_PF_V (tx_info->adap->pf)); cpl->pack =0 ; cpl->len =htons (pktlen); -/* checksum offload */ - cpl->ctrl1 =0 ; - - pos = cpl +1 ;memcpy (buf, skb->data, pktlen);if (tx_info->ip_family ==AF_INET ) {/* we need to correct ip header len */ ip = (struct iphdr *)(buf + maclen); ip->tot_len =htons (pktlen - maclen); + cntrl1 =TXPKT_CSUM_TYPE_V (TX_CSUM_TCPIP );#if IS_ENABLED (CONFIG_IPV6 ) } else { ip6 = (struct ipv6hdr *)(buf + maclen); ip6->payload_len =htons (pktlen - maclen - iplen); + cntrl1 =TXPKT_CSUM_TYPE_V (TX_CSUM_TCPIP6 );#endif } + + cntrl1 |=T6_TXPKT_ETHHDR_LEN_V (maclen -ETH_HLEN ) | +TXPKT_IPHDR_LEN_V (iplen); +/* checksum offload */ + cpl->ctrl1 =cpu_to_be64 (cntrl1); + + pos = cpl +1 ; +/* now take care of the tcp header, if fin is not set then clear push * bit as well, and if fin is set, it will be sent at the last so we * need to update the tcp sequence number as per the last packet. */ tcp = (struct tcphdr *)(buf + maclen + iplen); -if (!tcp->fin) +if (!fin) { tcp->psh =0 ; -else + tcp->fin =0 ; + }else { tcp->seq =htonl (tx_info->prev_seq); + }chcr_copy_to_txd (buf, &q->q, pos, pktlen);
@@ -1860,6 +1872,7 @@ static int chcr_short_record_handler(struct chcr_ktls_info *tx_info,/* nic tls TX handler */ static int chcr_ktls_xmit (struct sk_buff *skb,struct net_device *dev) { +u32 tls_end_offset, tcp_seq, skb_data_len, skb_offset;struct ch_ktls_port_stats_debug *port_stats;struct chcr_ktls_ofld_ctx_tx *tx_ctx;struct ch_ktls_stats_debug *stats;
@@ -1867,7 +1880,6 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev)int data_len, qidx, ret =0 , mss;struct tls_record_info *record;struct chcr_ktls_info *tx_info; -u32 tls_end_offset, tcp_seq;struct tls_context *tls_ctx;struct sk_buff *local_skb;struct sge_eth_txq *q;
@@ -1875,8 +1887,11 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev)unsigned long flags; tcp_seq =ntohl (th->seq); + skb_offset =skb_transport_offset (skb) +tcp_hdrlen (skb); + skb_data_len = skb->len - skb_offset; + data_len = skb_data_len; - mss =skb_is_gso (skb) ?skb_shinfo (skb)->gso_size : skb->data_len; + mss =skb_is_gso (skb) ?skb_shinfo (skb)->gso_size : data_len; tls_ctx =tls_get_ctx (skb->sk);if (unlikely (tls_ctx->netdev != dev))
@@ -1905,8 +1920,7 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev)cxgb4_reclaim_completed_tx (adap, &q->q, true);/* if tcp options are set but finish is not send the options first */ if (!th->fin &&chcr_ktls_check_tcp_options (th)) { - ret =chcr_ktls_write_tcp_options (tx_info, skb, q, - tx_info->tx_chan); + ret =chcr_ktls_write_tcp_options (tx_info, skb, q, false);if (ret)return NETDEV_TX_BUSY ; }
@@ -1922,8 +1936,6 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev)/* copy skb contents into local skb */ chcr_ktls_skb_copy (skb, local_skb); -/* go through the skb and send only one record at a time. */ - data_len = skb->data_len;/* TCP segments can be in received either complete or partial. * chcr_end_part_handler will handle cases if complete record or end * part of the record is received. Incase of partial end part of record,
@@ -2020,15 +2032,15 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev) }while (data_len >0 ); - tx_info->prev_seq =ntohl (th->seq) + skb->data_len; + tx_info->prev_seq =ntohl (th->seq) + skb_data_len;atomic64_inc (&port_stats->ktls_tx_encrypted_packets); -atomic64_add (skb->data_len, &port_stats->ktls_tx_encrypted_bytes); +atomic64_add (skb_data_len, &port_stats->ktls_tx_encrypted_bytes);/* tcp finish is set, send a separate tcp msg including all the options * as well. */ if (th->fin) -chcr_ktls_write_tcp_options (tx_info, skb, q, tx_info->tx_chan); +chcr_ktls_write_tcp_options (tx_info, skb, q, true); out:dev_kfree_skb_any (skb);
Signature · 1 line
2.18.1
Jakub Kicinski
maintainerRe: [net v2 2/7] ch_ktls: Correction in finding correct length
Quoted 89 lines · On Fri, 23 Oct 2020 11:01:29 +0530 Rohit Maheshwari wrote:
There is a possibility of linear skbs coming in. Correcting the length extraction logic.
Fixes 5a4b9fe7fece ("cxgb4/chcr: complete record tx handling")Signed-off-by Rohit Maheshwari <[email protected]>drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +22
-10@@ -980,6 +979,10 @@ chcr_ktls_write_tcp_options(struct chcr_ktls_info *tx_info, struct sk_buff *skb,return NETDEV_TX_BUSY ; } +if (unlikely (credits <ETHTXQ_STOP_THRES )) { +chcr_eth_txq_stop (q); + wr_mid |=FW_WR_EQUEQ_F |FW_WR_EQUIQ_F ; + } pos = &q->q.desc[q->q.pidx]; wr = pos;@@ -987,42 +990,51 @@ chcr_ktls_write_tcp_options(struct chcr_ktls_info *tx_info, struct sk_buff *skb, wr->op_immdlen =htonl (FW_WR_OP_V (FW_ETH_TX_PKT_WR ) |FW_WR_IMMDLEN_V (ctrl)); - wr->equiq_to_len16 =htonl (FW_WR_LEN16_V (len16)); + wr->equiq_to_len16 =htonl (wr_mid |FW_WR_LEN16_V (len16)); wr->r3 =0 ; cpl = (void *)(wr +1 );/* CPL header */ - cpl->ctrl0 =htonl (TXPKT_OPCODE_V (CPL_TX_PKT ) |TXPKT_INTF_V (tx_chan) | + cpl->ctrl0 =htonl (TXPKT_OPCODE_V (CPL_TX_PKT ) | +TXPKT_INTF_V (tx_info->tx_chan) |TXPKT_PF_V (tx_info->adap->pf)); cpl->pack =0 ; cpl->len =htons (pktlen); -/* checksum offload */ - cpl->ctrl1 =0 ; - - pos = cpl +1 ;memcpy (buf, skb->data, pktlen);if (tx_info->ip_family ==AF_INET ) {/* we need to correct ip header len */ ip = (struct iphdr *)(buf + maclen); ip->tot_len =htons (pktlen - maclen); + cntrl1 =TXPKT_CSUM_TYPE_V (TX_CSUM_TCPIP );#if IS_ENABLED (CONFIG_IPV6 ) } else { ip6 = (struct ipv6hdr *)(buf + maclen); ip6->payload_len =htons (pktlen - maclen - iplen); + cntrl1 =TXPKT_CSUM_TYPE_V (TX_CSUM_TCPIP6 );#endif } + + cntrl1 |=T6_TXPKT_ETHHDR_LEN_V (maclen -ETH_HLEN ) | +TXPKT_IPHDR_LEN_V (iplen); +/* checksum offload */ + cpl->ctrl1 =cpu_to_be64 (cntrl1); + + pos = cpl +1 ; +/* now take care of the tcp header, if fin is not set then clear push * bit as well, and if fin is set, it will be sent at the last so we * need to update the tcp sequence number as per the last packet. */ tcp = (struct tcphdr *)(buf + maclen + iplen); -if (!tcp->fin) +if (!fin) { tcp->psh =0 ; -else + tcp->fin =0 ; + }else { tcp->seq =htonl (tx_info->prev_seq); + }chcr_copy_to_txd (buf, &q->q, pos, pktlen);@@ -1905,8 +1920,7 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev)cxgb4_reclaim_completed_tx (adap, &q->q, true);/* if tcp options are set but finish is not send the options first */ if (!th->fin &&chcr_ktls_check_tcp_options (th)) { - ret =chcr_ktls_write_tcp_options (tx_info, skb, q, - tx_info->tx_chan); + ret =chcr_ktls_write_tcp_options (tx_info, skb, q, false);if (ret)return NETDEV_TX_BUSY ; }
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev) · line 2046
Quoted 9 lines
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +1
-1/* tcp finish is set, send a separate tcp msg including all the options * as well. */ if (th->fin) -chcr_ktls_write_tcp_options (tx_info, skb, q, tx_info->tx_chan); +chcr_ktls_write_tcp_options (tx_info, skb, q, true); out:dev_kfree_skb_any (skb);
I don't see how these changes related to a linear skb.
PATCH v2 3/7 cxgb4/ch_ktls: creating skbs causes panic
In reply to Rohit MaheshwariCreating SKB per tls record and freeing the original one causes panic. There will be race if connection reset is requested. By freeing original skb, refcnt will be decremented and that means, there is no pending record to send, and so tls_dev_del will be requested in control path while SKB of related connection is in queue.
Better approach is to use same SKB to send one record (partial
data) at a time. We still have to create a new SKB when partial last part of a record is requested.
This fix introduces new API cxgb4_write_partial_sgl() to send
partial part of skb. Present cxgb4_write_sgl can only provide feasibility to start from an offset which limits to header only and it can write sgls for the whole skb len. But this new API will help in both. It can start from any offset and can end writing in middle of the skb.
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 3 + drivers/net/ethernet/chelsio/cxgb4/sge.c | 108 ++++ .../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 543 +++++++----------- 3 files changed, 327 insertions(+), 327 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +3 -0
@@ -2124,6 +2124,9 @@ void cxgb4_inline_tx_skb(const struct sk_buff *skb, const struct sge_txq *q,void cxgb4_write_sgl (const struct sk_buff *skb,struct sge_txq *q,struct ulptx_sgl *sgl,u64 *end,unsigned int start,const dma_addr_t *addr); +void cxgb4_write_partial_sgl (const struct sk_buff *skb,struct sge_txq *q, +struct ulptx_sgl *sgl,u64 *end, +const dma_addr_t *addr,u32 start,u32 send_len);void cxgb4_ring_tx_db (struct adapter *adap,struct sge_txq *q,int n);int t4_set_vlan_acl (struct adapter *adap,unsigned int mbox,unsigned int vf,u16 vlan);
drivers/net/ethernet/chelsio/cxgb4/sge.c +108 -0
114 lines not on this page · raw message
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +216 -327
831 lines not on this page · raw message
Signature · 1 line
2.18.1
Jakub Kicinski
maintainerRe: [net v2 3/7] cxgb4/ch_ktls: creating skbs causes panic
Quoted 6 lines · On Fri, 23 Oct 2020 11:01:30 +0530 Rohit Maheshwari wrote:
Creating SKB per tls record and freeing the original one causes panic. There will be race if connection reset is requested. By freeing original skb, refcnt will be decremented and that means, there is no pending record to send, and so
tls_dev_delwill be requested in control path while SKB of related connection is in queue.
Can't you make your new skbs take a reference on the socket, then?
Quoted 16 lines
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +7
-1@@ -1672,42 +1572,60 @@ static int chcr_end_part_handler(struct chcr_ktls_info *tx_info,struct tls_record_info *record, u32 tcp_seq, int mss, bool tcp_push_no_fin, struct sge_eth_txq *q, - u32 tls_end_offset, bool last_wr) + u32 tls_end_offset, u32 skb_offset) { struct sk_buff *nskb = NULL; +bool is_last_wr = false; +int ret; + +if (skb_offset + tls_end_offset == skb->len) + is_last_wr = true; +/* check if it is a complete record */ if (tls_end_offset == record->len) {
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c static int chcr_end_part_handler(struct chcr_ktls_info *tx_info, · line 1686
Quoted 10 lines
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +3
-3nskb = skb;atomic64_inc (&tx_info->adap->ch_ktls_stats.ktls_tx_complete_pkts); }else { -dev_kfree_skb_any (skb); - +/* TAG needs to be calculated so, need to send complete record, +* free the original skb and send a new one. +*/ nskb =alloc_skb (0 ,GFP_KERNEL ); -if (!nskb)
Please add a patch that fixes the misuses of GFP_KERNEL as pointed out by Julia. Make it a separate patch in this series, before this one.
PATCH v2 4/7 ch_ktls: Correction in middle record handling
In reply to Rohit MaheshwariIf a record starts in middle, reset TCB UNA so that we could avoid sending out extra packet which is needed to make it 16 byte aligned to start AES CTR.
--- .../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +15 -6
@@ -827,11 +827,11 @@ static void *chcr_write_cpl_set_tcb_ulp(struct chcr_ktls_info *tx_info,*/ static int chcr_ktls_xmit_tcb_cpls (struct chcr_ktls_info *tx_info,struct sge_eth_txq *q,u64 tcp_seq, -u64 tcp_ack,u64 tcp_win) +u64 tcp_ack,u64 tcp_win,bool offset) {bool first_wr = ((tx_info->prev_ack ==0 ) && (tx_info->prev_win ==0 ));struct ch_ktls_port_stats_debug *port_stats; -u32 len, cpl =0 , ndesc, wr_len; +u32 len, cpl =0 , ndesc, wr_len, wr_mid =0 ;struct fw_ulptx_wr *wr;int credits;void *pos;
@@ -847,6 +847,11 @@ static int chcr_ktls_xmit_tcb_cpls(struct chcr_ktls_info *tx_info,return NETDEV_TX_BUSY ; } +if (unlikely (credits <ETHTXQ_STOP_THRES )) { +chcr_eth_txq_stop (q); + wr_mid |=FW_WR_EQUEQ_F |FW_WR_EQUIQ_F ; + } + pos = &q->q.desc[q->q.pidx];/* make space for WR, we'll fill it later when we know all the cpls * being sent out and have complete length.
@@ -862,7 +867,7 @@ static int chcr_ktls_xmit_tcb_cpls(struct chcr_ktls_info *tx_info, cpl++; }/* reset snd una if it's a re-transmit pkt */ -if (tcp_seq != tx_info->prev_seq) { +if (tcp_seq != tx_info->prev_seq || offset) {/* reset snd_una */ port_stats = &tx_info->adap->ch_ktls_stats.ktls_port[tx_info->port_id];
@@ -871,7 +876,8 @@ static int chcr_ktls_xmit_tcb_cpls(struct chcr_ktls_info *tx_info,TCB_SND_UNA_RAW_V (TCB_SND_UNA_RAW_M ), TCB_SND_UNA_RAW_V(0), 0); -atomic64_inc (&port_stats->ktls_tx_ooo); +if (tcp_seq != tx_info->prev_seq) +atomic64_inc (&port_stats->ktls_tx_ooo); cpl++; }/* update ack */
@@ -900,7 +906,8 @@ static int chcr_ktls_xmit_tcb_cpls(struct chcr_ktls_info *tx_info, wr->op_to_compl =htonl (FW_WR_OP_V (FW_ULPTX_WR )); wr->cookie =0 ;/* fill len in wr field */ - wr->flowid_len16 =htonl (FW_WR_LEN16_V (DIV_ROUND_UP (len,16 ))); + wr->flowid_len16 =htonl (wr_mid | +FW_WR_LEN16_V (DIV_ROUND_UP (len,16 ))); ndesc =DIV_ROUND_UP (len,64 );chcr_txq_advance (&q->q, ndesc);
@@ -1869,7 +1876,9 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev) ret =chcr_ktls_xmit_tcb_cpls (tx_info, q, tx_max,ntohl (th->ack_seq), -ntohs (th->window)); +ntohs (th->window), + tls_end_offset != + record->len);if (ret) {spin_unlock_irqrestore (&tx_ctx->base.lock, flags);
Signature · 1 line
2.18.1
PATCH v2 5/7 ch_ktls: packet handling prior to start marker
In reply to Rohit MaheshwariThere could be a case where ACK for tls exchanges prior to start marker is missed out, and by the time tls is offloaded. This pkt should not be discarded and handled carefully. It could be plaintext alone or plaintext + finish as well.
--- .../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-)
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +30 -6
@@ -1841,12 +1841,6 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev) goto out; } -if (unlikely (tls_record_is_start_marker (record))) { -spin_unlock_irqrestore (&tx_ctx->base.lock, flags); -atomic64_inc (&port_stats->ktls_tx_skip_no_sync_data); - goto out; - } - tls_end_offset = record->end_seq - tcp_seq; pr_debug("seq %#x, start %#x end %#x prev %#x, datalen %d offset %d\n",
@@ -1889,6 +1883,36 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev)skb_get (skb); } +if (unlikely (tls_record_is_start_marker (record))) { +atomic64_inc (&port_stats->ktls_tx_skip_no_sync_data); +/* If tls_end_offset < data_len, means there is some +* data after start marker, which needs encryption, send +* plaintext first and take skb refcount. else send out +* complete pkt as plaintext. +*/ +if (tls_end_offset < data_len) +skb_get (skb); +else + tls_end_offset = data_len; + + ret =chcr_ktls_tx_plaintxt (tx_info, skb, tcp_seq, mss, + (!th->fin && th->psh), q, + tls_end_offset, skb_offset); +if (ret) { +/* free the refcount taken earlier */ +if (tls_end_offset < data_len) +dev_kfree_skb_any (skb); +spin_unlock_irqrestore (&tx_ctx->base.lock, + flags); + goto out; + } + + data_len -= tls_end_offset; + tcp_seq = record->end_seq; + skb_offset += tls_end_offset; +continue ; + } +/* if a tls record is finishing in this SKB */ if (tls_end_offset <= data_len) { ret = chcr_end_part_handler(tx_info, skb, record,
Signature · 1 line
2.18.1
PATCH v2 6/7 ch_ktls/cxgb4: handle partial tag alone SKBs
In reply to Rohit MaheshwariIf TCP congestion caused a very small packets which only has some part fo the TAG, and that too is not till the end. HW can't handle such case, so falling back to sw crypto in such cases.
v1->v2:
- Marked chcr_ktls_sw_fallback() static.
--- .../ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 2 + .../net/ethernet/chelsio/cxgb4/cxgb4_uld.h | 1 + .../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 115 +++++++++++++++++- .../chelsio/inline_crypto/ch_ktls/chcr_ktls.h | 1 + 4 files changed, 118 insertions(+), 1 deletion(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c +2 -0
@@ -3573,6 +3573,8 @@ static int chcr_stats_show(struct seq_file *seq, void *v) atomic64_read(&adap->ch_ktls_stats.ktls_tx_complete_pkts));seq_printf (seq,"TX trim pkts : %20llu\n" ,atomic64_read (&adap->ch_ktls_stats.ktls_tx_trimmed_pkts)); +seq_printf (seq,"TX sw fallback : %20llu\n" , +atomic64_read (&adap->ch_ktls_stats.ktls_tx_fallback));while (i <MAX_NPORTS ) { ktls_port = &adap->ch_ktls_stats.ktls_port[i];seq_printf (seq,"Port %d\n" , i);
drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h +1 -0
@@ -388,6 +388,7 @@ struct ch_ktls_stats_debug {atomic64_t ktls_tx_retransmit_pkts;atomic64_t ktls_tx_complete_pkts;atomic64_t ktls_tx_trimmed_pkts; + atomic64_t ktls_tx_fallback; };#endif
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +114 -1
139 lines not on this page · raw message
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.h +1 -0
@@ -26,6 +26,7 @@#define CHCR_KTLS_WR_SIZE (CHCR_PLAIN_TX_DATA_LEN +\ sizeof(struct cpl_tx_sec_pdu)) +#define FALLBACK 35enum ch_ktls_open_state {CH_KTLS_OPEN_SUCCESS =0 ,
Signature · 1 line
2.18.1
PATCH v2 7/7 ch_ktls: tcb update fails sometimes
In reply to Rohit Maheshwaricontext id and port id should be filled while sending tcb update.
--- .../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +8 -4
@@ -733,7 +733,8 @@ static int chcr_ktls_cpl_set_tcb_rpl(struct adapter *adap, unsigned char *input) }static void *__chcr_write_cpl_set_tcb_ulp (struct chcr_ktls_info *tx_info, -u32 tid,void *pos,u16 word,u64 mask, +u32 tid,void *pos,u16 word, +struct sge_eth_txq *q,u64 mask,u64 val,u32 reply) {struct cpl_set_tcb_field_core *cpl;
@@ -742,7 +743,10 @@ static void *__chcr_write_cpl_set_tcb_ulp(struct chcr_ktls_info *tx_info,/* ULP_TXPKT */ txpkt = pos; - txpkt->cmd_dest =htonl (ULPTX_CMD_V (ULP_TX_PKT ) |ULP_TXPKT_DEST_V (0 )); + txpkt->cmd_dest =htonl (ULPTX_CMD_V (ULP_TX_PKT ) | +ULP_TXPKT_CHANNELID_V (tx_info->port_id) | +ULP_TXPKT_FID_V (q->q.cntxt_id) | +ULP_TXPKT_RO_F ); txpkt->len =htonl (DIV_ROUND_UP (CHCR_SET_TCB_FIELD_LEN ,16 ));/* ULPTX_IDATA sub-command */
@@ -797,7 +801,7 @@ static void *chcr_write_cpl_set_tcb_ulp(struct chcr_ktls_info *tx_info, }else {u8 buf[48 ] = {0 }; -__chcr_write_cpl_set_tcb_ulp (tx_info, tid, buf, word, +__chcr_write_cpl_set_tcb_ulp (tx_info, tid, buf, word, q, mask, val, reply); return chcr_copy_to_txd(buf, &q->q, pos,
@@ -805,7 +809,7 @@ static void *chcr_write_cpl_set_tcb_ulp(struct chcr_ktls_info *tx_info, } } - pos =__chcr_write_cpl_set_tcb_ulp (tx_info, tid, pos, word, + pos =__chcr_write_cpl_set_tcb_ulp (tx_info, tid, pos, word, q, mask, val, reply);/* check again if we are at the end of the queue */
Signature · 1 line
2.18.1