cxgb4/ch_ktls: Fixes in nic tls code
v6 cover cxgb4/ch_ktls: Fixes in nic tls code
This series helps in fixing multiple nic ktls issues. Series is broken into 12 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 the checksum offload update in WR.
Patch 4 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 5 fixes the problem of skb data length smaller than remaining data of the record.
Patch 6 fixes the handling of SKBs which has tls header alone pkt, but not starting from beginning.
Patch 7 avoids sending extra data which is used to make a record 16 byte aligned. We don't need to retransmit those extra few bytes.
Patch 8 handles the cases where retransmit packet has tls starting exchanges which are prior to tls start marker.
Patch 9 fixes the problem os skb free before HW knows about tcp FIN.
Patch 10 handles the small packet case which has partial TAG bytes only. HW can't handle those, hence using sw crypto for such pkts.
Patch 11 corrects the potential tcb update problem.
Patch 12 stops the queue if queue reaches threshold value.
v1->v2:
- Corrected fixes tag issue.
- Marked chcr_ktls_sw_fallback() static.
v2->v3:
- Replaced GFP_KERNEL with GFP_ATOMIC.
- Removed mixed fixes.
v3->v4:
- Corrected fixes tag issue.
v4->v5:
- Separated mixed fixes from patch 4.
v5-v6:
- Fixes tag should be at the end.
Rohit Maheshwari (12):
cxgb4/ch_ktls: decrypted bit is not enough
ch_ktls: Correction in finding correct length
ch_ktls: Update cheksum information
cxgb4/ch_ktls: creating skbs causes panic
ch_ktls: Correction in trimmed_len calculation
ch_ktls: missing handling of header alone
ch_ktls: Correction in middle record handling
ch_ktls: packet handling prior to start marker
ch_ktls: don't free skb before sending FIN
ch_ktls/cxgb4: handle partial tag alone SKBs
ch_ktls: tcb update fails sometimes
ch_ktls: stop the txq if reaches threshold
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 3 + .../ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 2 + .../net/ethernet/chelsio/cxgb4/cxgb4_main.c | 1 + .../net/ethernet/chelsio/cxgb4/cxgb4_uld.h | 6 + drivers/net/ethernet/chelsio/cxgb4/sge.c | 111 +++- .../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 582 +++++++++++------- .../chelsio/inline_crypto/ch_ktls/chcr_ktls.h | 1 + 7 files changed, 478 insertions(+), 228 deletions(-)
Signature · 1 line
2.18.1
PATCH v6 1/12 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.
v2->v3:
- Removed ifdef.
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 1 + drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h | 5 +++++ drivers/net/ethernet/chelsio/cxgb4/sge.c | 3 ++- .../net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 4 ---- 4 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +1 -0
@@ -1176,6 +1176,7 @@ 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 || +cxgb4_is_ktls_skb (skb) || (proto !=IPPROTO_TCP && proto !=IPPROTO_UDP )) txq = txq % pi->nqsets;
drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h +5 -0
@@ -493,6 +493,11 @@ struct cxgb4_uld_info {#endif }; +static inline bool cxgb4_is_ktls_skb (struct sk_buff *skb) +{ +return skb->sk &&tls_is_sk_tx_device_offloaded (skb->sk); +} +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
PATCH v6 2/12 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.
v2->v3:
- Separated un-related changes from this patch.
--- .../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +8 -7
@@ -967,7 +967,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 );
@@ -1860,6 +1860,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 +1868,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 +1875,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))
@@ -1922,8 +1925,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,9 +2021,9 @@ 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.
Signature · 1 line
2.18.1
PATCH v6 3/12 ch_ktls: Update cheksum information
In reply to Rohit MaheshwariChecksum update was missing in the WR.
--- .../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +11 -4
@@ -959,6 +959,7 @@ chcr_ktls_write_tcp_options(struct chcr_ktls_info *tx_info, struct sk_buff *skb,struct iphdr *ip;int credits;u8 buf[150 ]; +u64 cntrl1;void *pos; iplen =skb_network_header_len (skb);
@@ -997,22 +998,28 @@ chcr_ktls_write_tcp_options(struct chcr_ktls_info *tx_info, struct sk_buff *skb, 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.
Signature · 1 line
2.18.1
PATCH v6 4/12 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.
v4->v5:
- Removed extra changes.
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 3 + drivers/net/ethernet/chelsio/cxgb4/sge.c | 108 +++++++ .../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 284 +++++++----------- 3 files changed, 226 insertions(+), 169 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 +115 -169
551 lines not on this page · raw message
Signature · 1 line
2.18.1
PATCH v6 5/12 ch_ktls: Correction in trimmed_len calculation
In reply to Rohit Maheshwaritrimmed length calculation goes wrong if skb has only tag part to send. It should be zero if there is no data bytes apart from TAG.
--- .../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +7 -4
@@ -1729,10 +1729,13 @@ static int chcr_short_record_handler(struct chcr_ktls_info *tx_info,if (remaining_record >0 && remaining_record <TLS_CIPHER_AES_GCM_128_TAG_SIZE ) { -int trimmed_len = data_len - - (TLS_CIPHER_AES_GCM_128_TAG_SIZE - remaining_record); -/* don't process the pkt if it is only a partial tag */ -if (data_len <TLS_CIPHER_AES_GCM_128_TAG_SIZE ) +int trimmed_len =0 ; + +if (tls_end_offset >TLS_CIPHER_AES_GCM_128_TAG_SIZE ) + trimmed_len = data_len - + (TLS_CIPHER_AES_GCM_128_TAG_SIZE - + remaining_record); +if (!trimmed_len) goto out;WARN_ON (trimmed_len > data_len);
Signature · 1 line
2.18.1
PATCH v6 6/12 ch_ktls: missing handling of header alone
In reply to Rohit MaheshwariIf an skb has only header part which doesn't start from beginning, is not being handled properly.
--- .../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-)
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +11 -14
@@ -1744,6 +1744,17 @@ static int chcr_short_record_handler(struct chcr_ktls_info *tx_info,atomic64_inc (&tx_info->adap->ch_ktls_stats.ktls_tx_trimmed_pkts); } +/* check if it is only the header part. */ +if (tls_rec_offset + data_len <= (TLS_HEADER_SIZE + tx_info->iv_size)) { +if (chcr_ktls_tx_plaintxt (tx_info, skb, tcp_seq, mss, + tcp_push_no_fin, q, + tx_info->port_id, prior_data, + data_len, skb_offset, prior_data_len)) + goto out; + +return 0 ; + } +/* check if the middle record's start point is 16 byte aligned. CTR * needs 16 byte aligned start point to start encryption. */
@@ -1812,20 +1823,6 @@ static int chcr_short_record_handler(struct chcr_ktls_info *tx_info, goto out;atomic64_inc (&tx_info->adap->ch_ktls_stats.ktls_tx_middle_pkts); }else { -/* Else means, its a partial first part of the record. Check if -* its only the header, don't need to send for encryption then. -*/ -if (data_len <=TLS_HEADER_SIZE + tx_info->iv_size) { -if (chcr_ktls_tx_plaintxt (tx_info, skb, tcp_seq, mss, - tcp_push_no_fin, q, - tx_info->port_id, - prior_data, - data_len, skb_offset, - prior_data_len)) { - goto out; - } -return 0 ; - }atomic64_inc (&tx_info->adap->ch_ktls_stats.ktls_tx_start_pkts); }
Signature · 1 line
2.18.1
PATCH v6 7/12 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.
Check also considers prev_seq, which should be what is actually sent, not the skb data length.
Avoid updating partial TAG to HW at any point of time, that's why we need to check if remaining part is smaller than TAG size, then reset TX_MAX to be TAG starting sequence number.
--- .../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 50 ++++++++++++------- 1 file changed, 31 insertions(+), 19 deletions(-)
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +31 -19
@@ -827,7 +827,7 @@ 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;
@@ -862,7 +862,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 +871,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 */
@@ -1661,11 +1662,6 @@ static int chcr_end_part_handler(struct chcr_ktls_info *tx_info,* accordingly. */ tcp_seq =tls_record_start_seq (record); -/* reset snd una, so the middle record won't send the already -* sent part. -*/ -if (chcr_ktls_update_snd_una (tx_info, q)) - goto out;/* reset skb offset */ skb_offset =0 ;
@@ -1684,6 +1680,7 @@ static int chcr_end_part_handler(struct chcr_ktls_info *tx_info, mss)) { goto out; } + tx_info->prev_seq = record->end_seq;return 0 ; out:dev_kfree_skb_any (nskb);
@@ -1752,6 +1749,7 @@ static int chcr_short_record_handler(struct chcr_ktls_info *tx_info, data_len, skb_offset, prior_data_len)) goto out; + tx_info->prev_seq = tcp_seq + data_len;return 0 ; }
@@ -1832,6 +1830,7 @@ static int chcr_short_record_handler(struct chcr_ktls_info *tx_info, goto out; } + tx_info->prev_seq = tcp_seq + data_len + prior_data_len;return 0 ; out:dev_kfree_skb_any (skb);
@@ -1885,13 +1884,6 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev)if (ret)return NETDEV_TX_BUSY ; } -/* update tcb */ - ret =chcr_ktls_xmit_tcb_cpls (tx_info, q,ntohl (th->seq), -ntohl (th->ack_seq), -ntohs (th->window)); -if (ret) { -return NETDEV_TX_BUSY ; - }/* TCP segments can be in received either complete or partial. * chcr_end_part_handler will handle cases if complete record or end
@@ -1922,6 +1914,30 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev)atomic64_inc (&port_stats->ktls_tx_skip_no_sync_data); goto out; } + tls_end_offset = record->end_seq - tcp_seq; + +pr_debug ("seq 0x%x, end_seq 0x%x prev_seq 0x%x, datalen 0x%x\n" , + tcp_seq, record->end_seq, tx_info->prev_seq, data_len); +/* update tcb for the skb */ +if (skb_data_len == data_len) { +u32 tx_max = tcp_seq; + +if (!tls_record_is_start_marker (record) && + tls_end_offset <TLS_CIPHER_AES_GCM_128_TAG_SIZE ) + tx_max = record->end_seq - +TLS_CIPHER_AES_GCM_128_TAG_SIZE ; + + ret =chcr_ktls_xmit_tcb_cpls (tx_info, q, tx_max, +ntohl (th->ack_seq), +ntohs (th->window), + tls_end_offset != + record->len); +if (ret) { +spin_unlock_irqrestore (&tx_ctx->base.lock, + flags); + goto out; + } + }/* increase page reference count of the record, so that there * won't be any chance of page free in middle if in case stack * receives ACK and try to delete the record.
@@ -1931,10 +1947,7 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev)/* lock cleared */ spin_unlock_irqrestore (&tx_ctx->base.lock, flags); - tls_end_offset = record->end_seq - tcp_seq; -pr_debug ("seq 0x%x, end_seq 0x%x prev_seq 0x%x, datalen 0x%x\n" , - tcp_seq, record->end_seq, tx_info->prev_seq, data_len);/* if a tls record is finishing in this SKB */ if (tls_end_offset <= data_len) { ret = chcr_end_part_handler(tx_info, skb, record,
@@ -1973,7 +1986,6 @@ 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;atomic64_inc (&port_stats->ktls_tx_encrypted_packets);atomic64_add (skb_data_len, &port_stats->ktls_tx_encrypted_bytes);
Signature · 1 line
2.18.1
PATCH v6 8/12 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 | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-)
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +33 -5
@@ -1909,11 +1909,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 0x%x, end_seq 0x%x prev_seq 0x%x, datalen 0x%x\n",
@@ -1938,6 +1933,39 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev) goto out; } } + +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, + tx_info->port_id,NULL , + tls_end_offset, skb_offset, +0 ); + +spin_unlock_irqrestore (&tx_ctx->base.lock, flags); +if (ret) { +/* free the refcount taken earlier */ +if (tls_end_offset < data_len) +dev_kfree_skb_any (skb); + goto out; + } + + data_len -= tls_end_offset; + tcp_seq = record->end_seq; + skb_offset += tls_end_offset; +continue ; + } +/* increase page reference count of the record, so that there * won't be any chance of page free in middle if in case stack * receives ACK and try to delete the record.
Signature · 1 line
2.18.1
PATCH v6 9/12 ch_ktls: don't free skb before sending FIN
In reply to Rohit MaheshwariIf its a last packet and fin is set. Make sure FIN is informed to HW before skb gets freed.
--- .../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +10 -2
@@ -1932,6 +1932,9 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev) flags); goto out; } + +if (th->fin) +skb_get (skb); }if (unlikely (tls_record_is_start_marker (record))) {
@@ -2006,8 +2009,11 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev)__skb_frag_unref (&record->frags[i]); }/* if any failure, come out from the loop. */ -if (ret) +if (ret) { +if (th->fin) +dev_kfree_skb_any (skb);return NETDEV_TX_OK ; + }/* length should never be less than 0 */ WARN_ON (data_len <0 );
@@ -2020,8 +2026,10 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev)/* tcp finish is set, send a separate tcp msg including all the options * as well. */ -if (th->fin) +if (th->fin) {chcr_ktls_write_tcp_options (tx_info, skb, q, tx_info->tx_chan); +dev_kfree_skb_any (skb); + }return NETDEV_TX_OK ; out:
Signature · 1 line
2.18.1
PATCH v6 10/12 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 | 116 +++++++++++++++++- .../chelsio/inline_crypto/ch_ktls/chcr_ktls.h | 1 + 4 files changed, 119 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 +115 -1
140 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 v6 11/12 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
PATCH v6 12/12 ch_ktls: stop the txq if reaches threshold
In reply to Rohit MaheshwariStop the queue and ask for the credits if queue reaches to threashold.
--- .../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +15 -3
@@ -835,7 +835,7 @@ static int chcr_ktls_xmit_tcb_cpls(struct chcr_ktls_info *tx_info, {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;
@@ -851,6 +851,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.
@@ -905,7 +910,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);
@@ -986,6 +992,7 @@ chcr_ktls_write_tcp_options(struct chcr_ktls_info *tx_info, struct sk_buff *skb,struct tcphdr *tcp;int len16, pktlen;struct iphdr *ip; +u32 wr_mid =0 ;int credits;u8 buf[150 ];u64 cntrl1;
@@ -1010,6 +1017,11 @@ 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;
@@ -1017,7 +1029,7 @@ 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 );
Signature · 1 line
2.18.1
Quoted 2 lines · On Mon, 9 Nov 2020 16:21:30 +0530 Rohit Maheshwari wrote:
This series helps in fixing multiple nic ktls issues. Series is broken into 12 patches.
Applied.