Skip to content

Commit d1bc532

Browse files
magnus-karlssonborkmann
authored andcommitted
i40e: xsk: Move tmp desc array from driver to pool
Move desc_array from the driver to the pool. The reason behind this is that we can then reuse this array as a temporary storage for descriptors in all zero-copy drivers that use the batched interface. This will make it easier to add batching to more drivers. i40e is the only driver that has a batched Tx zero-copy implementation, so no need to touch any other driver. Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: Alexander Lobakin <alexandr.lobakin@intel.com> Link: https://lore.kernel.org/bpf/20220125160446.78976-6-maciej.fijalkowski@intel.com
1 parent 3dd411e commit d1bc532

File tree

8 files changed

+24
-30
lines changed

8 files changed

+24
-30
lines changed

Diff for: drivers/net/ethernet/intel/i40e/i40e_txrx.c

-11
Original file line numberDiff line numberDiff line change
@@ -830,8 +830,6 @@ void i40e_free_tx_resources(struct i40e_ring *tx_ring)
830830
i40e_clean_tx_ring(tx_ring);
831831
kfree(tx_ring->tx_bi);
832832
tx_ring->tx_bi = NULL;
833-
kfree(tx_ring->xsk_descs);
834-
tx_ring->xsk_descs = NULL;
835833

836834
if (tx_ring->desc) {
837835
dma_free_coherent(tx_ring->dev, tx_ring->size,
@@ -1433,13 +1431,6 @@ int i40e_setup_tx_descriptors(struct i40e_ring *tx_ring)
14331431
if (!tx_ring->tx_bi)
14341432
goto err;
14351433

1436-
if (ring_is_xdp(tx_ring)) {
1437-
tx_ring->xsk_descs = kcalloc(I40E_MAX_NUM_DESCRIPTORS, sizeof(*tx_ring->xsk_descs),
1438-
GFP_KERNEL);
1439-
if (!tx_ring->xsk_descs)
1440-
goto err;
1441-
}
1442-
14431434
u64_stats_init(&tx_ring->syncp);
14441435

14451436
/* round up to nearest 4K */
@@ -1463,8 +1454,6 @@ int i40e_setup_tx_descriptors(struct i40e_ring *tx_ring)
14631454
return 0;
14641455

14651456
err:
1466-
kfree(tx_ring->xsk_descs);
1467-
tx_ring->xsk_descs = NULL;
14681457
kfree(tx_ring->tx_bi);
14691458
tx_ring->tx_bi = NULL;
14701459
return -ENOMEM;

Diff for: drivers/net/ethernet/intel/i40e/i40e_txrx.h

-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ struct i40e_ring {
390390
u16 rx_offset;
391391
struct xdp_rxq_info xdp_rxq;
392392
struct xsk_buff_pool *xsk_pool;
393-
struct xdp_desc *xsk_descs; /* For storing descriptors in the AF_XDP ZC path */
394393
} ____cacheline_internodealigned_in_smp;
395394

396395
static inline bool ring_uses_build_skb(struct i40e_ring *ring)

Diff for: drivers/net/ethernet/intel/i40e/i40e_xsk.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -467,11 +467,11 @@ static void i40e_set_rs_bit(struct i40e_ring *xdp_ring)
467467
**/
468468
static bool i40e_xmit_zc(struct i40e_ring *xdp_ring, unsigned int budget)
469469
{
470-
struct xdp_desc *descs = xdp_ring->xsk_descs;
470+
struct xdp_desc *descs = xdp_ring->xsk_pool->tx_descs;
471471
u32 nb_pkts, nb_processed = 0;
472472
unsigned int total_bytes = 0;
473473

474-
nb_pkts = xsk_tx_peek_release_desc_batch(xdp_ring->xsk_pool, descs, budget);
474+
nb_pkts = xsk_tx_peek_release_desc_batch(xdp_ring->xsk_pool, budget);
475475
if (!nb_pkts)
476476
return true;
477477

Diff for: include/net/xdp_sock_drv.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
void xsk_tx_completed(struct xsk_buff_pool *pool, u32 nb_entries);
1515
bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc);
16-
u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, struct xdp_desc *desc, u32 max);
16+
u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, u32 max);
1717
void xsk_tx_release(struct xsk_buff_pool *pool);
1818
struct xsk_buff_pool *xsk_get_pool_from_qid(struct net_device *dev,
1919
u16 queue_id);
@@ -142,8 +142,7 @@ static inline bool xsk_tx_peek_desc(struct xsk_buff_pool *pool,
142142
return false;
143143
}
144144

145-
static inline u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, struct xdp_desc *desc,
146-
u32 max)
145+
static inline u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, u32 max)
147146
{
148147
return 0;
149148
}

Diff for: include/net/xsk_buff_pool.h

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct xsk_buff_pool {
6060
*/
6161
dma_addr_t *dma_pages;
6262
struct xdp_buff_xsk *heads;
63+
struct xdp_desc *tx_descs;
6364
u64 chunk_mask;
6465
u64 addrs_cnt;
6566
u32 free_list_cnt;

Diff for: net/xdp/xsk.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc)
343343
}
344344
EXPORT_SYMBOL(xsk_tx_peek_desc);
345345

346-
static u32 xsk_tx_peek_release_fallback(struct xsk_buff_pool *pool, struct xdp_desc *descs,
347-
u32 max_entries)
346+
static u32 xsk_tx_peek_release_fallback(struct xsk_buff_pool *pool, u32 max_entries)
348347
{
348+
struct xdp_desc *descs = pool->tx_descs;
349349
u32 nb_pkts = 0;
350350

351351
while (nb_pkts < max_entries && xsk_tx_peek_desc(pool, &descs[nb_pkts]))
@@ -355,8 +355,7 @@ static u32 xsk_tx_peek_release_fallback(struct xsk_buff_pool *pool, struct xdp_d
355355
return nb_pkts;
356356
}
357357

358-
u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, struct xdp_desc *descs,
359-
u32 max_entries)
358+
u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, u32 max_entries)
360359
{
361360
struct xdp_sock *xs;
362361
u32 nb_pkts;
@@ -365,7 +364,7 @@ u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, struct xdp_desc *
365364
if (!list_is_singular(&pool->xsk_tx_list)) {
366365
/* Fallback to the non-batched version */
367366
rcu_read_unlock();
368-
return xsk_tx_peek_release_fallback(pool, descs, max_entries);
367+
return xsk_tx_peek_release_fallback(pool, max_entries);
369368
}
370369

371370
xs = list_first_or_null_rcu(&pool->xsk_tx_list, struct xdp_sock, tx_list);
@@ -374,7 +373,7 @@ u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, struct xdp_desc *
374373
goto out;
375374
}
376375

377-
nb_pkts = xskq_cons_peek_desc_batch(xs->tx, descs, pool, max_entries);
376+
nb_pkts = xskq_cons_peek_desc_batch(xs->tx, pool, max_entries);
378377
if (!nb_pkts) {
379378
xs->tx->queue_empty_descs++;
380379
goto out;
@@ -386,7 +385,7 @@ u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, struct xdp_desc *
386385
* packets. This avoids having to implement any buffering in
387386
* the Tx path.
388387
*/
389-
nb_pkts = xskq_prod_reserve_addr_batch(pool->cq, descs, nb_pkts);
388+
nb_pkts = xskq_prod_reserve_addr_batch(pool->cq, pool->tx_descs, nb_pkts);
390389
if (!nb_pkts)
391390
goto out;
392391

Diff for: net/xdp/xsk_buff_pool.c

+7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void xp_destroy(struct xsk_buff_pool *pool)
3737
if (!pool)
3838
return;
3939

40+
kvfree(pool->tx_descs);
4041
kvfree(pool->heads);
4142
kvfree(pool);
4243
}
@@ -58,6 +59,12 @@ struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs,
5859
if (!pool->heads)
5960
goto out;
6061

62+
if (xs->tx) {
63+
pool->tx_descs = kcalloc(xs->tx->nentries, sizeof(*pool->tx_descs), GFP_KERNEL);
64+
if (!pool->tx_descs)
65+
goto out;
66+
}
67+
6168
pool->chunk_mask = ~((u64)umem->chunk_size - 1);
6269
pool->addrs_cnt = umem->size;
6370
pool->heads_cnt = umem->chunks;

Diff for: net/xdp/xsk_queue.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ static inline bool xskq_cons_read_desc(struct xsk_queue *q,
205205
return false;
206206
}
207207

208-
static inline u32 xskq_cons_read_desc_batch(struct xsk_queue *q,
209-
struct xdp_desc *descs,
210-
struct xsk_buff_pool *pool, u32 max)
208+
static inline u32 xskq_cons_read_desc_batch(struct xsk_queue *q, struct xsk_buff_pool *pool,
209+
u32 max)
211210
{
212211
u32 cached_cons = q->cached_cons, nb_entries = 0;
212+
struct xdp_desc *descs = pool->tx_descs;
213213

214214
while (cached_cons != q->cached_prod && nb_entries < max) {
215215
struct xdp_rxtx_ring *ring = (struct xdp_rxtx_ring *)q->ring;
@@ -282,12 +282,12 @@ static inline bool xskq_cons_peek_desc(struct xsk_queue *q,
282282
return xskq_cons_read_desc(q, desc, pool);
283283
}
284284

285-
static inline u32 xskq_cons_peek_desc_batch(struct xsk_queue *q, struct xdp_desc *descs,
286-
struct xsk_buff_pool *pool, u32 max)
285+
static inline u32 xskq_cons_peek_desc_batch(struct xsk_queue *q, struct xsk_buff_pool *pool,
286+
u32 max)
287287
{
288288
u32 entries = xskq_cons_nb_entries(q, max);
289289

290-
return xskq_cons_read_desc_batch(q, descs, pool, entries);
290+
return xskq_cons_read_desc_batch(q, pool, entries);
291291
}
292292

293293
/* To improve performance in the xskq_cons_release functions, only update local state here.

0 commit comments

Comments
 (0)