Skip to content

Commit 46a3ea9

Browse files
Tariq ToukanSaeed Mahameed
authored andcommitted
net/mlx5e: kTLS, Enhance TX resync flow
Once the kTLS TX resync function is called, it used to return a binary value, for success or failure. However, in case the TLS SKB is a retransmission of the connection handshake, it initiates the resync flow (as the tcp seq check holds), while regular packet handle is expected. In this patch, we identify this case and skip the resync operation accordingly. Counters: - Add a counter (tls_skip_no_sync_data) to monitor this. - Bump the dump counters up as they are used more frequently. - Add a missing counter descriptor declaration for tls_resync_bytes in sq_stats_desc. Fixes: d2ead1f ("net/mlx5e: Add kTLS TX HW offload support") Signed-off-by: Tariq Toukan <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent af11a7a commit 46a3ea9

File tree

3 files changed

+51
-33
lines changed

3 files changed

+51
-33
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -185,26 +185,33 @@ struct tx_sync_info {
185185
skb_frag_t frags[MAX_SKB_FRAGS];
186186
};
187187

188-
static bool tx_sync_info_get(struct mlx5e_ktls_offload_context_tx *priv_tx,
189-
u32 tcp_seq, struct tx_sync_info *info)
188+
enum mlx5e_ktls_sync_retval {
189+
MLX5E_KTLS_SYNC_DONE,
190+
MLX5E_KTLS_SYNC_FAIL,
191+
MLX5E_KTLS_SYNC_SKIP_NO_DATA,
192+
};
193+
194+
static enum mlx5e_ktls_sync_retval
195+
tx_sync_info_get(struct mlx5e_ktls_offload_context_tx *priv_tx,
196+
u32 tcp_seq, struct tx_sync_info *info)
190197
{
191198
struct tls_offload_context_tx *tx_ctx = priv_tx->tx_ctx;
199+
enum mlx5e_ktls_sync_retval ret = MLX5E_KTLS_SYNC_DONE;
192200
struct tls_record_info *record;
193201
int remaining, i = 0;
194202
unsigned long flags;
195-
bool ret = true;
196203

197204
spin_lock_irqsave(&tx_ctx->lock, flags);
198205
record = tls_get_record(tx_ctx, tcp_seq, &info->rcd_sn);
199206

200207
if (unlikely(!record)) {
201-
ret = false;
208+
ret = MLX5E_KTLS_SYNC_FAIL;
202209
goto out;
203210
}
204211

205212
if (unlikely(tcp_seq < tls_record_start_seq(record))) {
206-
if (!tls_record_is_start_marker(record))
207-
ret = false;
213+
ret = tls_record_is_start_marker(record) ?
214+
MLX5E_KTLS_SYNC_SKIP_NO_DATA : MLX5E_KTLS_SYNC_FAIL;
208215
goto out;
209216
}
210217

@@ -316,20 +323,26 @@ static void tx_post_fence_nop(struct mlx5e_txqsq *sq)
316323
mlx5e_post_nop_fence(wq, sq->sqn, &sq->pc);
317324
}
318325

319-
static struct sk_buff *
326+
static enum mlx5e_ktls_sync_retval
320327
mlx5e_ktls_tx_handle_ooo(struct mlx5e_ktls_offload_context_tx *priv_tx,
321328
struct mlx5e_txqsq *sq,
322-
struct sk_buff *skb,
329+
int datalen,
323330
u32 seq)
324331
{
325332
struct mlx5e_sq_stats *stats = sq->stats;
326333
struct mlx5_wq_cyc *wq = &sq->wq;
334+
enum mlx5e_ktls_sync_retval ret;
327335
struct tx_sync_info info = {};
328336
u16 contig_wqebbs_room, pi;
329337
u8 num_wqebbs;
330338
int i = 0;
331339

332-
if (!tx_sync_info_get(priv_tx, seq, &info)) {
340+
ret = tx_sync_info_get(priv_tx, seq, &info);
341+
if (unlikely(ret != MLX5E_KTLS_SYNC_DONE)) {
342+
if (ret == MLX5E_KTLS_SYNC_SKIP_NO_DATA) {
343+
stats->tls_skip_no_sync_data++;
344+
return MLX5E_KTLS_SYNC_SKIP_NO_DATA;
345+
}
333346
/* We might get here if a retransmission reaches the driver
334347
* after the relevant record is acked.
335348
* It should be safe to drop the packet in this case
@@ -339,13 +352,8 @@ mlx5e_ktls_tx_handle_ooo(struct mlx5e_ktls_offload_context_tx *priv_tx,
339352
}
340353

341354
if (unlikely(info.sync_len < 0)) {
342-
u32 payload;
343-
int headln;
344-
345-
headln = skb_transport_offset(skb) + tcp_hdrlen(skb);
346-
payload = skb->len - headln;
347-
if (likely(payload <= -info.sync_len))
348-
return skb;
355+
if (likely(datalen <= -info.sync_len))
356+
return MLX5E_KTLS_SYNC_DONE;
349357

350358
stats->tls_drop_bypass_req++;
351359
goto err_out;
@@ -360,7 +368,7 @@ mlx5e_ktls_tx_handle_ooo(struct mlx5e_ktls_offload_context_tx *priv_tx,
360368
*/
361369
if (!info.nr_frags) {
362370
tx_post_fence_nop(sq);
363-
return skb;
371+
return MLX5E_KTLS_SYNC_DONE;
364372
}
365373

366374
num_wqebbs = mlx5e_ktls_dumps_num_wqebbs(sq, info.nr_frags, info.sync_len);
@@ -397,7 +405,7 @@ mlx5e_ktls_tx_handle_ooo(struct mlx5e_ktls_offload_context_tx *priv_tx,
397405
page_ref_add(skb_frag_page(f), n - 1);
398406
}
399407

400-
return skb;
408+
return MLX5E_KTLS_SYNC_DONE;
401409

402410
err_out:
403411
for (; i < info.nr_frags; i++)
@@ -408,8 +416,7 @@ mlx5e_ktls_tx_handle_ooo(struct mlx5e_ktls_offload_context_tx *priv_tx,
408416
*/
409417
put_page(skb_frag_page(&info.frags[i]));
410418

411-
dev_kfree_skb_any(skb);
412-
return NULL;
419+
return MLX5E_KTLS_SYNC_FAIL;
413420
}
414421

415422
struct sk_buff *mlx5e_ktls_handle_tx_skb(struct net_device *netdev,
@@ -445,10 +452,15 @@ struct sk_buff *mlx5e_ktls_handle_tx_skb(struct net_device *netdev,
445452

446453
seq = ntohl(tcp_hdr(skb)->seq);
447454
if (unlikely(priv_tx->expected_seq != seq)) {
448-
skb = mlx5e_ktls_tx_handle_ooo(priv_tx, sq, skb, seq);
449-
if (unlikely(!skb))
455+
enum mlx5e_ktls_sync_retval ret =
456+
mlx5e_ktls_tx_handle_ooo(priv_tx, sq, datalen, seq);
457+
458+
if (likely(ret == MLX5E_KTLS_SYNC_DONE))
459+
*wqe = mlx5e_sq_fetch_wqe(sq, sizeof(**wqe), pi);
460+
else if (ret == MLX5E_KTLS_SYNC_FAIL)
461+
goto err_out;
462+
else /* ret == MLX5E_KTLS_SYNC_SKIP_NO_DATA */
450463
goto out;
451-
*wqe = mlx5e_sq_fetch_wqe(sq, sizeof(**wqe), pi);
452464
}
453465

454466
priv_tx->expected_seq = seq + datalen;

drivers/net/ethernet/mellanox/mlx5/core/en_stats.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ static const struct counter_desc sw_stats_desc[] = {
5252
{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_encrypted_bytes) },
5353
{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_ctx) },
5454
{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_ooo) },
55+
{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_dump_packets) },
56+
{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_dump_bytes) },
5557
{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_resync_bytes) },
58+
{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_skip_no_sync_data) },
5659
{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_drop_no_sync_data) },
5760
{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_drop_bypass_req) },
58-
{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_dump_packets) },
59-
{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_dump_bytes) },
6061
#endif
6162

6263
{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_lro_packets) },
@@ -288,11 +289,12 @@ static void mlx5e_grp_sw_update_stats(struct mlx5e_priv *priv)
288289
s->tx_tls_encrypted_bytes += sq_stats->tls_encrypted_bytes;
289290
s->tx_tls_ctx += sq_stats->tls_ctx;
290291
s->tx_tls_ooo += sq_stats->tls_ooo;
292+
s->tx_tls_dump_bytes += sq_stats->tls_dump_bytes;
293+
s->tx_tls_dump_packets += sq_stats->tls_dump_packets;
291294
s->tx_tls_resync_bytes += sq_stats->tls_resync_bytes;
295+
s->tx_tls_skip_no_sync_data += sq_stats->tls_skip_no_sync_data;
292296
s->tx_tls_drop_no_sync_data += sq_stats->tls_drop_no_sync_data;
293297
s->tx_tls_drop_bypass_req += sq_stats->tls_drop_bypass_req;
294-
s->tx_tls_dump_bytes += sq_stats->tls_dump_bytes;
295-
s->tx_tls_dump_packets += sq_stats->tls_dump_packets;
296298
#endif
297299
s->tx_cqes += sq_stats->cqes;
298300
}
@@ -1472,10 +1474,12 @@ static const struct counter_desc sq_stats_desc[] = {
14721474
{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_encrypted_bytes) },
14731475
{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_ctx) },
14741476
{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_ooo) },
1475-
{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_drop_no_sync_data) },
1476-
{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_drop_bypass_req) },
14771477
{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_dump_packets) },
14781478
{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_dump_bytes) },
1479+
{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_resync_bytes) },
1480+
{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_skip_no_sync_data) },
1481+
{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_drop_no_sync_data) },
1482+
{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_drop_bypass_req) },
14791483
#endif
14801484
{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, csum_none) },
14811485
{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, stopped) },

drivers/net/ethernet/mellanox/mlx5/core/en_stats.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,12 @@ struct mlx5e_sw_stats {
129129
u64 tx_tls_encrypted_bytes;
130130
u64 tx_tls_ctx;
131131
u64 tx_tls_ooo;
132+
u64 tx_tls_dump_packets;
133+
u64 tx_tls_dump_bytes;
132134
u64 tx_tls_resync_bytes;
135+
u64 tx_tls_skip_no_sync_data;
133136
u64 tx_tls_drop_no_sync_data;
134137
u64 tx_tls_drop_bypass_req;
135-
u64 tx_tls_dump_packets;
136-
u64 tx_tls_dump_bytes;
137138
#endif
138139

139140
u64 rx_xsk_packets;
@@ -273,11 +274,12 @@ struct mlx5e_sq_stats {
273274
u64 tls_encrypted_bytes;
274275
u64 tls_ctx;
275276
u64 tls_ooo;
277+
u64 tls_dump_packets;
278+
u64 tls_dump_bytes;
276279
u64 tls_resync_bytes;
280+
u64 tls_skip_no_sync_data;
277281
u64 tls_drop_no_sync_data;
278282
u64 tls_drop_bypass_req;
279-
u64 tls_dump_packets;
280-
u64 tls_dump_bytes;
281283
#endif
282284
/* less likely accessed in data path */
283285
u64 csum_none;

0 commit comments

Comments
 (0)