Skip to content

Commit 84d1bb2

Browse files
Tariq ToukanSaeed Mahameed
authored andcommitted
net/mlx5e: kTLS, Limit DUMP wqe size
HW expects the data size in DUMP WQEs to be up to MTU. Make sure they are in range. We elevate the frag page refcount by 'n-1', in addition to the one obtained in tx_sync_info_get(), having an overall of 'n' references. We bulk increments by using a single page_ref_add() command, to optimize perfermance. The refcounts are released one by one, by the corresponding completions. Fixes: d2ead1f ("net/mlx5e: Add kTLS TX HW offload support") Signed-off-by: Tariq Toukan <[email protected]> Reviewed-by: Eran Ben Elisha <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 700ec49 commit 84d1bb2

File tree

5 files changed

+52
-12
lines changed

5 files changed

+52
-12
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ struct mlx5e_txqsq {
410410
struct device *pdev;
411411
__be32 mkey_be;
412412
unsigned long state;
413+
unsigned int hw_mtu;
413414
struct hwtstamp_config *tstamp;
414415
struct mlx5_clock *clock;
415416

drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515
#else
1616
/* TLS offload requires additional stop_room for:
1717
* - a resync SKB.
18-
* kTLS offload requires additional stop_room for:
19-
* - static params WQE,
20-
* - progress params WQE, and
21-
* - resync DUMP per frag.
18+
* kTLS offload requires fixed additional stop_room for:
19+
* - a static params WQE, and a progress params WQE.
20+
* The additional MTU-depending room for the resync DUMP WQEs
21+
* will be calculated and added in runtime.
2222
*/
2323
#define MLX5E_SQ_TLS_ROOM \
2424
(MLX5_SEND_WQE_MAX_WQEBBS + \
25-
MLX5E_KTLS_STATIC_WQEBBS + MLX5E_KTLS_PROGRESS_WQEBBS + \
26-
MAX_SKB_FRAGS * MLX5E_KTLS_DUMP_WQEBBS)
25+
MLX5E_KTLS_STATIC_WQEBBS + MLX5E_KTLS_PROGRESS_WQEBBS)
2726
#endif
2827

2928
#define INL_HDR_START_SZ (sizeof(((struct mlx5_wqe_eth_seg *)NULL)->inline_hdr.start))

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,16 @@ struct sk_buff *mlx5e_ktls_handle_tx_skb(struct net_device *netdev,
9494
void mlx5e_ktls_tx_handle_resync_dump_comp(struct mlx5e_txqsq *sq,
9595
struct mlx5e_tx_wqe_info *wi,
9696
u32 *dma_fifo_cc);
97-
97+
static inline u8
98+
mlx5e_ktls_dumps_num_wqebbs(struct mlx5e_txqsq *sq, unsigned int nfrags,
99+
unsigned int sync_len)
100+
{
101+
/* Given the MTU and sync_len, calculates an upper bound for the
102+
* number of WQEBBs needed for the TX resync DUMP WQEs of a record.
103+
*/
104+
return MLX5E_KTLS_DUMP_WQEBBS *
105+
(nfrags + DIV_ROUND_UP(sync_len, sq->hw_mtu));
106+
}
98107
#else
99108

100109
static inline void mlx5e_ktls_build_netdev(struct mlx5e_priv *priv)

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ mlx5e_ktls_tx_handle_ooo(struct mlx5e_ktls_offload_context_tx *priv_tx,
373373
return skb;
374374
}
375375

376-
num_wqebbs = info.nr_frags * MLX5E_KTLS_DUMP_WQEBBS;
376+
num_wqebbs = mlx5e_ktls_dumps_num_wqebbs(sq, info.nr_frags, info.sync_len);
377377
pi = mlx5_wq_cyc_ctr2ix(wq, sq->pc);
378378
contig_wqebbs_room = mlx5_wq_cyc_get_contig_wqebbs(wq, pi);
379379

@@ -382,14 +382,40 @@ mlx5e_ktls_tx_handle_ooo(struct mlx5e_ktls_offload_context_tx *priv_tx,
382382

383383
tx_post_resync_params(sq, priv_tx, info.rcd_sn);
384384

385-
for (; i < info.nr_frags; i++)
386-
if (tx_post_resync_dump(sq, &info.frags[i], priv_tx->tisn, !i))
387-
goto err_out;
385+
for (; i < info.nr_frags; i++) {
386+
unsigned int orig_fsz, frag_offset = 0, n = 0;
387+
skb_frag_t *f = &info.frags[i];
388+
389+
orig_fsz = skb_frag_size(f);
390+
391+
do {
392+
bool fence = !(i || frag_offset);
393+
unsigned int fsz;
394+
395+
n++;
396+
fsz = min_t(unsigned int, sq->hw_mtu, orig_fsz - frag_offset);
397+
skb_frag_size_set(f, fsz);
398+
if (tx_post_resync_dump(sq, f, priv_tx->tisn, fence)) {
399+
page_ref_add(skb_frag_page(f), n - 1);
400+
goto err_out;
401+
}
402+
403+
skb_frag_off_add(f, fsz);
404+
frag_offset += fsz;
405+
} while (frag_offset < orig_fsz);
406+
407+
page_ref_add(skb_frag_page(f), n - 1);
408+
}
388409

389410
return skb;
390411

391412
err_out:
392413
for (; i < info.nr_frags; i++)
414+
/* The put_page() here undoes the page ref obtained in tx_sync_info_get().
415+
* Page refs obtained for the DUMP WQEs above (by page_ref_add) will be
416+
* released only upon their completions (or in mlx5e_free_txqsq_descs,
417+
* if channel closes).
418+
*/
393419
put_page(skb_frag_page(&info.frags[i]));
394420

395421
dev_kfree_skb_any(skb);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,17 +1128,22 @@ static int mlx5e_alloc_txqsq(struct mlx5e_channel *c,
11281128
sq->txq_ix = txq_ix;
11291129
sq->uar_map = mdev->mlx5e_res.bfreg.map;
11301130
sq->min_inline_mode = params->tx_min_inline_mode;
1131+
sq->hw_mtu = MLX5E_SW2HW_MTU(params, params->sw_mtu);
11311132
sq->stats = &c->priv->channel_stats[c->ix].sq[tc];
11321133
sq->stop_room = MLX5E_SQ_STOP_ROOM;
11331134
INIT_WORK(&sq->recover_work, mlx5e_tx_err_cqe_work);
11341135
if (!MLX5_CAP_ETH(mdev, wqe_vlan_insert))
11351136
set_bit(MLX5E_SQ_STATE_VLAN_NEED_L2_INLINE, &sq->state);
11361137
if (MLX5_IPSEC_DEV(c->priv->mdev))
11371138
set_bit(MLX5E_SQ_STATE_IPSEC, &sq->state);
1139+
#ifdef CONFIG_MLX5_EN_TLS
11381140
if (mlx5_accel_is_tls_device(c->priv->mdev)) {
11391141
set_bit(MLX5E_SQ_STATE_TLS, &sq->state);
1140-
sq->stop_room += MLX5E_SQ_TLS_ROOM;
1142+
sq->stop_room += MLX5E_SQ_TLS_ROOM +
1143+
mlx5e_ktls_dumps_num_wqebbs(sq, MAX_SKB_FRAGS,
1144+
TLS_MAX_PAYLOAD_SIZE);
11411145
}
1146+
#endif
11421147

11431148
param->wq.db_numa_node = cpu_to_node(c->cpu);
11441149
err = mlx5_wq_cyc_create(mdev, &param->wq, sqc_wq, wq, &sq->wq_ctrl);

0 commit comments

Comments
 (0)