Skip to contentSkip to conversation

cxgb4/ch_ktls: Fixes in nic tls code

PATCH Superseded Rohit Maheshwari 2 participants 17 messages Oct 30, 2020 – Nov 4, 2020

Subsystems (4)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover cxgb4/ch_ktls: Fixes in nic tls code

This series helps in fixing multiple nic ktls issues. Series is broken into 10 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 corrects the usage of GFP_KERNEL and replaces it with GFP_ATOMIC.

Patch 5 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 6 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 7 handles the cases where retransmit packet has tls starting exchanges which are prior to tls start marker.

Patch 8 handles the small packet case which has partial TAG bytes only. HW can't handle those, hence using sw crypto for such pkts.

Patch 9 corrects the potential tcb update problem.

Patch 10 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.

Rohit Maheshwari (10):
cxgb4/ch_ktls: decrypted bit is not enough
ch_ktls: Correction in finding correct length
ch_ktls: Update cheksum information
ch_ktls: incorrect use of GFP_KERNEL
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
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 | 772 ++++++++++--------
 .../chelsio/inline_crypto/ch_ktls/chcr_ktls.h |   1 +
 7 files changed, 532 insertions(+), 364 deletions(-)
Signature · 1 line
2.18.1
#1 lore raw

PATCH v4 1/10 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.

Fixes 5a4b9fe7fece ("cxgb4/chcr: complete record tx handling")
---
 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
index a952fe198eb9..7fd264a6d085 100644
@@ -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
index b169776ab484..e2a4941fa802 100644
@@ -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
index a9e9c7ae565d..01bd9c0dfe4e 100644
@@ -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
index 5195f692f14d..43c723c72c61 100644
@@ -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
#2 lore raw

PATCH v4 2/10 ch_ktls: Correction in finding correct length

In reply to Rohit Maheshwari

There is a possibility of linear skbs coming in. Correcting the length extraction logic.

v2->v3:
- Separated un-related changes from this patch.

Fixes 5a4b9fe7fece ("cxgb4/chcr: complete record tx handling")
---
 .../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
index 43c723c72c61..447aec7ae954 100644
@@ -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
#3 lore raw

PATCH v4 3/10 ch_ktls: Update cheksum information

In reply to Rohit Maheshwari

Checksum update was missing in the WR.

Fixes 429765a149f1 ("chcr: handle partial end part of a record")
---
 .../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 21 ++++++++++++-------
 1 file changed, 13 insertions(+), 8 deletions(-)
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +13 -8
index 447aec7ae954..a1448a1b38fd 100644
@@ -947,18 +947,17 @@ 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)
 {
+	u32 ctrl, iplen, maclen, 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);
@@ -997,22 +996,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
#4 lore raw

PATCH v4 4/10 ch_ktls: incorrect use of GFP_KERNEL

In reply to Rohit Maheshwari

Use of GFP_KERNEL under lock is not correct. Replacing it with GFP_ATOMIC.

---
 drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +1 -1
index a1448a1b38fd..379d4d1220b1 100644
@@ -1675,7 +1675,7 @@ static int chcr_end_part_handler(struct chcr_ktls_info *tx_info,
 	} else {
 		dev_kfree_skb_any(skb);
 
-		nskb = alloc_skb(0, GFP_KERNEL);
+		nskb = alloc_skb(0, GFP_ATOMIC);
 		if (!nskb)
 			return NETDEV_TX_BUSY;
 		/* copy complete record in skb */
Signature · 1 line
2.18.1
#5 lore raw

PATCH v4 5/10 cxgb4/ch_ktls: creating skbs causes panic

In reply to Rohit Maheshwari

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_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.

Fixes 429765a149f1 ("chcr: handle partial end part of a record")
---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4.h    |   3 +
 drivers/net/ethernet/chelsio/cxgb4/sge.c      | 108 ++++
 .../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 545 +++++++-----------
 3 files changed, 328 insertions(+), 328 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +3 -0
index 3352dad6ca99..27308600da15 100644
@@ -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 +217 -328

833 lines not on this page · raw message

Signature · 1 line
2.18.1
maintainer
#6 lore raw

Re: [net v4 05/10] cxgb4/ch_ktls: creating skbs causes panic

Quoted 7 lines · On Fri, 30 Oct 2020 23:32:20 +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_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

Quoted 8 lines

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.

You never replied to my question on v2.

If the problem is that the socket gets freed, why don't you make the new skb take a reference on the socket?

650 LoC is really a rather large fix.

#7 lore raw

Re: [net v4 05/10] cxgb4/ch_ktls: creating skbs causes panic

Quoted 16 lines · Jakub Kicinski
Quoted 7 lines · On Fri, 30 Oct 2020 23:32:20 +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_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

Quoted 8 lines

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.

Quoted 6 lines

You never replied to my question on v2.

If the problem is that the socket gets freed, why don't you make the new skb take a reference on the socket?

650 LoC is really a rather large fix.

This whole skb alloc and copy record frags was written under the assumption that there will be zero data copy (no linear skb was expected) but that isn't correct. Continuing with the same change requires more checks and will be more complicated. That's why I made this change. I think using same SKB to send out multiple records is better than allocating new SKB every time.

maintainer
#8 lore raw

Re: [net v4 05/10] cxgb4/ch_ktls: creating skbs causes panic

Quoted 22 lines · On Wed, 4 Nov 2020 22:23:14 +0530 rohit maheshwari wrote:
Quoted 21 lines · Jakub Kicinski
Quoted 7 lines · On Fri, 30 Oct 2020 23:32:20 +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_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

Quoted 8 lines

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.

You never replied to my question on v2.

If the problem is that the socket gets freed, why don't you make the new skb take a reference on the socket?

Quoted 7 lines
Quoted 1 line

650 LoC is really a rather large fix.

This whole skb alloc and copy record frags was written under the assumption that there will be zero data copy (no linear skb was expected) but that isn't correct. Continuing with the same change requires more checks and will be more complicated. That's why I made this change. I think using same SKB to send out multiple records is better than allocating new SKB every time.

Bug fixes are not where code should be restructured.

Please produce a minimal fix.

#9 lore raw

PATCH v4 6/10 ch_ktls: Correction in middle record handling

In reply to Rohit Maheshwari

If 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.

Fixes 5a4b9fe7fece ("cxgb4/chcr: complete record tx handling")
---
 .../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
index e547c6a3045c..2c92ded79b49 100644
@@ -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 */
@@ -1863,7 +1864,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
#10 lore raw

PATCH v4 7/10 ch_ktls: packet handling prior to start marker

In reply to Rohit Maheshwari

There 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.

Fixes 5a4b9fe7fece ("cxgb4/chcr: complete record tx handling")
---
 .../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
index 2c92ded79b49..06a22813f466 100644
@@ -1828,12 +1828,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",
@@ -1877,6 +1871,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
maintainer
#11 lore raw

Re: [net v4 07/10] ch_ktls: packet handling prior to start marker

Quoted 4 lines · On Fri, 30 Oct 2020 23:32:22 +0530 Rohit Maheshwari wrote:

There 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.

By plaintext + finish you mean the start of offload falls in the middle of a TCP skb? That should never happen. We force EOR when we turn on TLS, so you should never see a TCP skb that needs to be half-encrypted.

#12 lore raw

Re: [net v4 07/10] ch_ktls: packet handling prior to start marker

Quoted 8 lines · Jakub Kicinski
Quoted 4 lines · On Fri, 30 Oct 2020 23:32:22 +0530 Rohit Maheshwari wrote:

There 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.

By plaintext + finish you mean the start of offload falls in the middle of a TCP skb? That should never happen. We force EOR when we turn on TLS, so you should never see a TCP skb that needs to be half-encrypted.

This happens when re-transmission is issued on a high load system. First time CCS is and finished message comes to driver one by one. Problem is, if ACK is not received for both these packets, while sending for re-transmission, stack sends both these together. Now the start sequence number will be before the start marker record, but it also holds data for encryption. This is handled in this patch.
Are you saying this should not happen?

maintainer
#13 lore raw

Re: [net v4 07/10] ch_ktls: packet handling prior to start marker

Quoted 9 lines · On Wed, 4 Nov 2020 22:48:22 +0530 rohit maheshwari wrote:
Quoted 8 lines · Jakub Kicinski
Quoted 4 lines · On Fri, 30 Oct 2020 23:32:22 +0530 Rohit Maheshwari wrote:

There 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.

By plaintext + finish you mean the start of offload falls in the middle of a TCP skb? That should never happen. We force EOR when we turn on TLS, so you should never see a TCP skb that needs to be half-encrypted.

Quoted 8 lines

This happens when re-transmission is issued on a high load system. First time CCS is and finished message comes to driver one by one. Problem is, if ACK is not received for both these packets, while sending for re-transmission, stack sends both these together. Now the start sequence number will be before the start marker record, but it also holds data for encryption. This is handled in this patch.
Are you saying this should not happen?

Maybe Eric could help us out - Rohit says that the TCP stack is generating skbs which straddle MSG_EOR on re-transmit. Can this happen / is it correct?

#14 lore raw

PATCH v4 8/10 ch_ktls/cxgb4: handle partial tag alone SKBs

In reply to Rohit Maheshwari

If 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.

Fixes dc05f3df8fac ("chcr: Handle first or middle part of record")
---
 .../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
index 0273f40b85f7..17410fe86626 100644
@@ -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
index e2a4941fa802..1b49f2fa9b18 100644
@@ -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
index c1651b1431a0..18b3b1f02415 100644
@@ -26,6 +26,7 @@
 
 #define CHCR_KTLS_WR_SIZE	(CHCR_PLAIN_TX_DATA_LEN +\
 				 sizeof(struct cpl_tx_sec_pdu))
+#define FALLBACK		35
 
 enum ch_ktls_open_state {
 	CH_KTLS_OPEN_SUCCESS = 0,
Signature · 1 line
2.18.1
#15 lore raw

PATCH v4 9/10 ch_ktls: tcb update fails sometimes

In reply to Rohit Maheshwari

context id and port id should be filled while sending tcb update.

Fixes 5a4b9fe7fece ("cxgb4/chcr: complete record tx handling")
---
 .../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
index c8ce27a589db..08595b0a6b6d 100644
@@ -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
#16 lore raw

PATCH v4 10/10 ch_ktls: stop the txq if reaches threshold

In reply to Rohit Maheshwari

Stop the queue and ask for the credits if queue reaches to threashold.

Fixes 5a4b9fe7fece ("cxgb4/chcr: complete record tx handling")
---
 .../chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +15 -4
index 08595b0a6b6d..369144cca78b 100644
@@ -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);
@@ -963,7 +969,7 @@ 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)
 {
-	u32 ctrl, iplen, maclen, pktlen, ndesc, len16;
+	u32 ctrl, iplen, maclen, pktlen, ndesc, len16, wr_mid = 0;
 	struct fw_eth_tx_pkt_wr *wr;
 	struct cpl_tx_pkt_core *cpl;
 #if IS_ENABLED(CONFIG_IPV6)
@@ -995,6 +1001,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;
 
@@ -1002,7 +1013,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