Skip to content

Commit ebc33a3

Browse files
mfijalkoanguy11
authored andcommitted
ice: improve updating ice_{t,r}x_ring::xsk_pool
xsk_buff_pool pointers that ice ring structs hold are updated via ndo_bpf that is executed in process context while it can be read by remote CPU at the same time within NAPI poll. Use synchronize_net() after pointer update and {READ,WRITE}_ONCE() when working with mentioned pointer. Fixes: 2d4238f ("ice: Add support for AF_XDP") Reviewed-by: Shannon Nelson <[email protected]> Tested-by: Chandan Kumar Rout <[email protected]> (A Contingent Worker at Intel) Signed-off-by: Maciej Fijalkowski <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 9da75a5 commit ebc33a3

File tree

6 files changed

+87
-55
lines changed

6 files changed

+87
-55
lines changed

drivers/net/ethernet/intel/ice/ice.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -765,18 +765,17 @@ static inline struct xsk_buff_pool *ice_get_xp_from_qid(struct ice_vsi *vsi,
765765
}
766766

767767
/**
768-
* ice_xsk_pool - get XSK buffer pool bound to a ring
768+
* ice_rx_xsk_pool - assign XSK buff pool to Rx ring
769769
* @ring: Rx ring to use
770770
*
771-
* Returns a pointer to xsk_buff_pool structure if there is a buffer pool
772-
* present, NULL otherwise.
771+
* Sets XSK buff pool pointer on Rx ring.
773772
*/
774-
static inline struct xsk_buff_pool *ice_xsk_pool(struct ice_rx_ring *ring)
773+
static inline void ice_rx_xsk_pool(struct ice_rx_ring *ring)
775774
{
776775
struct ice_vsi *vsi = ring->vsi;
777776
u16 qid = ring->q_index;
778777

779-
return ice_get_xp_from_qid(vsi, qid);
778+
WRITE_ONCE(ring->xsk_pool, ice_get_xp_from_qid(vsi, qid));
780779
}
781780

782781
/**
@@ -801,7 +800,7 @@ static inline void ice_tx_xsk_pool(struct ice_vsi *vsi, u16 qid)
801800
if (!ring)
802801
return;
803802

804-
ring->xsk_pool = ice_get_xp_from_qid(vsi, qid);
803+
WRITE_ONCE(ring->xsk_pool, ice_get_xp_from_qid(vsi, qid));
805804
}
806805

807806
/**

drivers/net/ethernet/intel/ice/ice_base.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ static int ice_vsi_cfg_rxq(struct ice_rx_ring *ring)
536536
return err;
537537
}
538538

539-
ring->xsk_pool = ice_xsk_pool(ring);
539+
ice_rx_xsk_pool(ring);
540540
if (ring->xsk_pool) {
541541
xdp_rxq_info_unreg(&ring->xdp_rxq);
542542

@@ -597,7 +597,7 @@ static int ice_vsi_cfg_rxq(struct ice_rx_ring *ring)
597597
return 0;
598598
}
599599

600-
ok = ice_alloc_rx_bufs_zc(ring, num_bufs);
600+
ok = ice_alloc_rx_bufs_zc(ring, ring->xsk_pool, num_bufs);
601601
if (!ok) {
602602
u16 pf_q = ring->vsi->rxq_map[ring->q_index];
603603

drivers/net/ethernet/intel/ice/ice_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2948,7 +2948,7 @@ static void ice_vsi_rx_napi_schedule(struct ice_vsi *vsi)
29482948
ice_for_each_rxq(vsi, i) {
29492949
struct ice_rx_ring *rx_ring = vsi->rx_rings[i];
29502950

2951-
if (rx_ring->xsk_pool)
2951+
if (READ_ONCE(rx_ring->xsk_pool))
29522952
napi_schedule(&rx_ring->q_vector->napi);
29532953
}
29542954
}

drivers/net/ethernet/intel/ice/ice_txrx.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,10 +1521,11 @@ int ice_napi_poll(struct napi_struct *napi, int budget)
15211521
* budget and be more aggressive about cleaning up the Tx descriptors.
15221522
*/
15231523
ice_for_each_tx_ring(tx_ring, q_vector->tx) {
1524+
struct xsk_buff_pool *xsk_pool = READ_ONCE(tx_ring->xsk_pool);
15241525
bool wd;
15251526

1526-
if (tx_ring->xsk_pool)
1527-
wd = ice_xmit_zc(tx_ring);
1527+
if (xsk_pool)
1528+
wd = ice_xmit_zc(tx_ring, xsk_pool);
15281529
else if (ice_ring_is_xdp(tx_ring))
15291530
wd = true;
15301531
else
@@ -1550,14 +1551,15 @@ int ice_napi_poll(struct napi_struct *napi, int budget)
15501551
budget_per_ring = budget;
15511552

15521553
ice_for_each_rx_ring(rx_ring, q_vector->rx) {
1554+
struct xsk_buff_pool *xsk_pool = READ_ONCE(rx_ring->xsk_pool);
15531555
int cleaned;
15541556

15551557
/* A dedicated path for zero-copy allows making a single
15561558
* comparison in the irq context instead of many inside the
15571559
* ice_clean_rx_irq function and makes the codebase cleaner.
15581560
*/
15591561
cleaned = rx_ring->xsk_pool ?
1560-
ice_clean_rx_irq_zc(rx_ring, budget_per_ring) :
1562+
ice_clean_rx_irq_zc(rx_ring, xsk_pool, budget_per_ring) :
15611563
ice_clean_rx_irq(rx_ring, budget_per_ring);
15621564
work_done += cleaned;
15631565
/* if we clean as many as budgeted, we must not be done */

0 commit comments

Comments
 (0)