Skip to content

Commit d53d4dc

Browse files
mfijalkoanguy11
authored andcommitted
ice: fix truesize operations for PAGE_SIZE >= 8192
When working on multi-buffer packet on arch that has PAGE_SIZE >= 8192, truesize is calculated and stored in xdp_buff::frame_sz per each processed Rx buffer. This means that frame_sz will contain the truesize based on last received buffer, but commit 1dc1a7e ("ice: Centrallize Rx buffer recycling") assumed this value will be constant for each buffer, which breaks the page recycling scheme and mess up the way we update the page::page_offset. To fix this, let us work on constant truesize when PAGE_SIZE >= 8192 instead of basing this on size of a packet read from Rx descriptor. This way we can simplify the code and avoid calculating truesize per each received frame and on top of that when using xdp_update_skb_shared_info(), current formula for truesize update will be valid. This means ice_rx_frame_truesize() can be removed altogether. Furthermore, first call to it within ice_clean_rx_irq() for 4k PAGE_SIZE was redundant as xdp_buff::frame_sz is initialized via xdp_init_buff() in ice_vsi_cfg_rxq(). This should have been removed at the point where xdp_buff struct started to be a member of ice_rx_ring and it was no longer a stack based variable. There are two fixes tags as my understanding is that the first one exposed us to broken truesize and page_offset handling and then second introduced broken skb_shared_info update in ice_{construct,build}_skb(). Reported-and-tested-by: Luiz Capitulino <[email protected]> Closes: https://lore.kernel.org/netdev/[email protected]/ Fixes: 1dc1a7e ("ice: Centrallize Rx buffer recycling") Fixes: 2fba7dc ("ice: Add support for XDP multi-buffer on Rx side") Signed-off-by: Maciej Fijalkowski <[email protected]> Tested-by: Chandan Kumar Rout <[email protected]> (A Contingent Worker at Intel) Signed-off-by: Tony Nguyen <[email protected]>
1 parent b966ad8 commit d53d4dc

File tree

2 files changed

+20
-34
lines changed

2 files changed

+20
-34
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,25 @@ static void ice_xsk_pool_fill_cb(struct ice_rx_ring *ring)
512512
xsk_pool_fill_cb(ring->xsk_pool, &desc);
513513
}
514514

515+
/**
516+
* ice_get_frame_sz - calculate xdp_buff::frame_sz
517+
* @rx_ring: the ring being configured
518+
*
519+
* Return frame size based on underlying PAGE_SIZE
520+
*/
521+
static unsigned int ice_get_frame_sz(struct ice_rx_ring *rx_ring)
522+
{
523+
unsigned int frame_sz;
524+
525+
#if (PAGE_SIZE >= 8192)
526+
frame_sz = rx_ring->rx_buf_len;
527+
#else
528+
frame_sz = ice_rx_pg_size(rx_ring) / 2;
529+
#endif
530+
531+
return frame_sz;
532+
}
533+
515534
/**
516535
* ice_vsi_cfg_rxq - Configure an Rx queue
517536
* @ring: the ring being configured
@@ -576,7 +595,7 @@ static int ice_vsi_cfg_rxq(struct ice_rx_ring *ring)
576595
}
577596
}
578597

579-
xdp_init_buff(&ring->xdp, ice_rx_pg_size(ring) / 2, &ring->xdp_rxq);
598+
xdp_init_buff(&ring->xdp, ice_get_frame_sz(ring), &ring->xdp_rxq);
580599
ring->xdp.data = NULL;
581600
ring->xdp_ext.pkt_ctx = &ring->pkt_ctx;
582601
err = ice_setup_rx_ctx(ring);

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

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -521,30 +521,6 @@ int ice_setup_rx_ring(struct ice_rx_ring *rx_ring)
521521
return -ENOMEM;
522522
}
523523

524-
/**
525-
* ice_rx_frame_truesize
526-
* @rx_ring: ptr to Rx ring
527-
* @size: size
528-
*
529-
* calculate the truesize with taking into the account PAGE_SIZE of
530-
* underlying arch
531-
*/
532-
static unsigned int
533-
ice_rx_frame_truesize(struct ice_rx_ring *rx_ring, const unsigned int size)
534-
{
535-
unsigned int truesize;
536-
537-
#if (PAGE_SIZE < 8192)
538-
truesize = ice_rx_pg_size(rx_ring) / 2; /* Must be power-of-2 */
539-
#else
540-
truesize = rx_ring->rx_offset ?
541-
SKB_DATA_ALIGN(rx_ring->rx_offset + size) +
542-
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) :
543-
SKB_DATA_ALIGN(size);
544-
#endif
545-
return truesize;
546-
}
547-
548524
/**
549525
* ice_run_xdp - Executes an XDP program on initialized xdp_buff
550526
* @rx_ring: Rx ring
@@ -1154,11 +1130,6 @@ int ice_clean_rx_irq(struct ice_rx_ring *rx_ring, int budget)
11541130
bool failure;
11551131
u32 first;
11561132

1157-
/* Frame size depend on rx_ring setup when PAGE_SIZE=4K */
1158-
#if (PAGE_SIZE < 8192)
1159-
xdp->frame_sz = ice_rx_frame_truesize(rx_ring, 0);
1160-
#endif
1161-
11621133
xdp_prog = READ_ONCE(rx_ring->xdp_prog);
11631134
if (xdp_prog) {
11641135
xdp_ring = rx_ring->xdp_ring;
@@ -1217,10 +1188,6 @@ int ice_clean_rx_irq(struct ice_rx_ring *rx_ring, int budget)
12171188
hard_start = page_address(rx_buf->page) + rx_buf->page_offset -
12181189
offset;
12191190
xdp_prepare_buff(xdp, hard_start, offset, size, !!offset);
1220-
#if (PAGE_SIZE > 4096)
1221-
/* At larger PAGE_SIZE, frame_sz depend on len size */
1222-
xdp->frame_sz = ice_rx_frame_truesize(rx_ring, size);
1223-
#endif
12241191
xdp_buff_clear_frags_flag(xdp);
12251192
} else if (ice_add_xdp_frag(rx_ring, xdp, rx_buf, size)) {
12261193
break;

0 commit comments

Comments
 (0)