Skip to content

Commit 2f1e432

Browse files
tohojoborkmann
authored andcommitted
stmmac: Remove rcu_read_lock() around XDP program invocation
The stmmac driver has rcu_read_lock()/rcu_read_unlock() pairs around XDP program invocations. However, the actual lifetime of the objects referred by the XDP program invocation is longer, all the way through to the call to xdp_do_flush(), making the scope of the rcu_read_lock() too small. This turns out to be harmless because it all happens in a single NAPI poll cycle (and thus under local_bh_disable()), but it makes the rcu_read_lock() misleading. Rather than extend the scope of the rcu_read_lock(), just get rid of it entirely. With the addition of RCU annotations to the XDP_REDIRECT map types that take bh execution into account, lockdep even understands this to be safe, so there's really no reason to keep it around. Signed-off-by: Toke Høiland-Jørgensen <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Cc: Giuseppe Cavallaro <[email protected]> Cc: Alexandre Torgue <[email protected]> Cc: Jose Abreu <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 7b6ee87 commit 2f1e432

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4651,7 +4651,6 @@ static int stmmac_xdp_xmit_back(struct stmmac_priv *priv,
46514651
return res;
46524652
}
46534653

4654-
/* This function assumes rcu_read_lock() is held by the caller. */
46554654
static int __stmmac_xdp_run_prog(struct stmmac_priv *priv,
46564655
struct bpf_prog *prog,
46574656
struct xdp_buff *xdp)
@@ -4693,17 +4692,14 @@ static struct sk_buff *stmmac_xdp_run_prog(struct stmmac_priv *priv,
46934692
struct bpf_prog *prog;
46944693
int res;
46954694

4696-
rcu_read_lock();
4697-
46984695
prog = READ_ONCE(priv->xdp_prog);
46994696
if (!prog) {
47004697
res = STMMAC_XDP_PASS;
4701-
goto unlock;
4698+
goto out;
47024699
}
47034700

47044701
res = __stmmac_xdp_run_prog(priv, prog, xdp);
4705-
unlock:
4706-
rcu_read_unlock();
4702+
out:
47074703
return ERR_PTR(-res);
47084704
}
47094705

@@ -4973,10 +4969,8 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)
49734969
buf->xdp->data_end = buf->xdp->data + buf1_len;
49744970
xsk_buff_dma_sync_for_cpu(buf->xdp, rx_q->xsk_pool);
49754971

4976-
rcu_read_lock();
49774972
prog = READ_ONCE(priv->xdp_prog);
49784973
res = __stmmac_xdp_run_prog(priv, prog, buf->xdp);
4979-
rcu_read_unlock();
49804974

49814975
switch (res) {
49824976
case STMMAC_XDP_PASS:

0 commit comments

Comments
 (0)