Skip to content

Commit d7f5fb3

Browse files
Gerhard Englederdavem330
authored andcommitted
tsnep: Fix mapping for zero copy XDP_TX action
For XDP_TX action xdp_buff is converted to xdp_frame. The conversion is done by xdp_convert_buff_to_frame(). The memory type of the resulting xdp_frame depends on the memory type of the xdp_buff. For page pool based xdp_buff it produces xdp_frame with memory type MEM_TYPE_PAGE_POOL. For zero copy XSK pool based xdp_buff it produces xdp_frame with memory type MEM_TYPE_PAGE_ORDER0. tsnep_xdp_xmit_back() is not prepared for that and uses always the page pool buffer type TSNEP_TX_TYPE_XDP_TX. This leads to invalid mappings and the transmission of undefined data. Improve tsnep_xdp_xmit_back() to use the generic buffer type TSNEP_TX_TYPE_XDP_NDO for zero copy XDP_TX. Fixes: 3fc2333 ("tsnep: Add XDP socket zero-copy RX support") Signed-off-by: Gerhard Engleder <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 010e03d commit d7f5fb3

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

drivers/net/ethernet/engleder/tsnep_main.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -719,17 +719,25 @@ static void tsnep_xdp_xmit_flush(struct tsnep_tx *tx)
719719

720720
static bool tsnep_xdp_xmit_back(struct tsnep_adapter *adapter,
721721
struct xdp_buff *xdp,
722-
struct netdev_queue *tx_nq, struct tsnep_tx *tx)
722+
struct netdev_queue *tx_nq, struct tsnep_tx *tx,
723+
bool zc)
723724
{
724725
struct xdp_frame *xdpf = xdp_convert_buff_to_frame(xdp);
725726
bool xmit;
727+
u32 type;
726728

727729
if (unlikely(!xdpf))
728730
return false;
729731

732+
/* no page pool for zero copy */
733+
if (zc)
734+
type = TSNEP_TX_TYPE_XDP_NDO;
735+
else
736+
type = TSNEP_TX_TYPE_XDP_TX;
737+
730738
__netif_tx_lock(tx_nq, smp_processor_id());
731739

732-
xmit = tsnep_xdp_xmit_frame_ring(xdpf, tx, TSNEP_TX_TYPE_XDP_TX);
740+
xmit = tsnep_xdp_xmit_frame_ring(xdpf, tx, type);
733741

734742
/* Avoid transmit queue timeout since we share it with the slow path */
735743
if (xmit)
@@ -1273,7 +1281,7 @@ static bool tsnep_xdp_run_prog(struct tsnep_rx *rx, struct bpf_prog *prog,
12731281
case XDP_PASS:
12741282
return false;
12751283
case XDP_TX:
1276-
if (!tsnep_xdp_xmit_back(rx->adapter, xdp, tx_nq, tx))
1284+
if (!tsnep_xdp_xmit_back(rx->adapter, xdp, tx_nq, tx, false))
12771285
goto out_failure;
12781286
*status |= TSNEP_XDP_TX;
12791287
return true;
@@ -1323,7 +1331,7 @@ static bool tsnep_xdp_run_prog_zc(struct tsnep_rx *rx, struct bpf_prog *prog,
13231331
case XDP_PASS:
13241332
return false;
13251333
case XDP_TX:
1326-
if (!tsnep_xdp_xmit_back(rx->adapter, xdp, tx_nq, tx))
1334+
if (!tsnep_xdp_xmit_back(rx->adapter, xdp, tx_nq, tx, true))
13271335
goto out_failure;
13281336
*status |= TSNEP_XDP_TX;
13291337
return true;

0 commit comments

Comments
 (0)