Skip to content

Commit 8b3fae3

Browse files
MeghanaMalladiTIkuba-moo
authored andcommitted
net: ti: icssg-prueth: Fix kernel panic during concurrent Tx queue access
Add __netif_tx_lock() to ensure that only one packet is being transmitted at a time to avoid race conditions in the netif_txq struct and prevent packet data corruption. Failing to do so causes kernel panic with the following error: [ 2184.746764] ------------[ cut here ]------------ [ 2184.751412] kernel BUG at lib/dynamic_queue_limits.c:99! [ 2184.756728] Internal error: Oops - BUG: 00000000f2000800 [#1] PREEMPT SMP logs: https://gist.github.com/MeghanaMalladiTI/9c7aa5fc3b7fb03f87c74aad487956e9 The lock is acquired before calling emac_xmit_xdp_frame() and released after the call returns. This ensures that the TX queue is protected from concurrent access during the transmission of XDP frames. Fixes: 62aa324 ("net: ti: icssg-prueth: Add XDP support") Signed-off-by: Meghana Malladi <[email protected]> Reviewed-by: Jacob Keller <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e5641da commit 8b3fae3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

drivers/net/ethernet/ti/icssg/icssg_common.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,8 @@ static u32 emac_run_xdp(struct prueth_emac *emac, struct xdp_buff *xdp,
650650
struct page *page, u32 *len)
651651
{
652652
struct net_device *ndev = emac->ndev;
653+
struct netdev_queue *netif_txq;
654+
int cpu = smp_processor_id();
653655
struct bpf_prog *xdp_prog;
654656
struct xdp_frame *xdpf;
655657
u32 pkt_len = *len;
@@ -669,8 +671,11 @@ static u32 emac_run_xdp(struct prueth_emac *emac, struct xdp_buff *xdp,
669671
goto drop;
670672
}
671673

672-
q_idx = smp_processor_id() % emac->tx_ch_num;
674+
q_idx = cpu % emac->tx_ch_num;
675+
netif_txq = netdev_get_tx_queue(ndev, q_idx);
676+
__netif_tx_lock(netif_txq, cpu);
673677
result = emac_xmit_xdp_frame(emac, xdpf, page, q_idx);
678+
__netif_tx_unlock(netif_txq);
674679
if (result == ICSSG_XDP_CONSUMED) {
675680
ndev->stats.tx_dropped++;
676681
goto drop;

drivers/net/ethernet/ti/icssg/icssg_prueth.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,17 +1075,21 @@ static int emac_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frame
10751075
{
10761076
struct prueth_emac *emac = netdev_priv(dev);
10771077
struct net_device *ndev = emac->ndev;
1078+
struct netdev_queue *netif_txq;
1079+
int cpu = smp_processor_id();
10781080
struct xdp_frame *xdpf;
10791081
unsigned int q_idx;
10801082
int nxmit = 0;
10811083
u32 err;
10821084
int i;
10831085

1084-
q_idx = smp_processor_id() % emac->tx_ch_num;
1086+
q_idx = cpu % emac->tx_ch_num;
1087+
netif_txq = netdev_get_tx_queue(ndev, q_idx);
10851088

10861089
if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
10871090
return -EINVAL;
10881091

1092+
__netif_tx_lock(netif_txq, cpu);
10891093
for (i = 0; i < n; i++) {
10901094
xdpf = frames[i];
10911095
err = emac_xmit_xdp_frame(emac, xdpf, NULL, q_idx);
@@ -1095,6 +1099,7 @@ static int emac_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frame
10951099
}
10961100
nxmit++;
10971101
}
1102+
__netif_tx_unlock(netif_txq);
10981103

10991104
return nxmit;
11001105
}

0 commit comments

Comments
 (0)