Skip to content

Clean up and document RCU-based object protection for XDP and TC BPF

Toke Høiland-Jørgensen bpf intel-wired-lan linux-arm-kernel linux-omap netdev 5 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (refs/heads/master):

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest19 patches 0 repliesApplied 19/19
  2. v419 patches 2 repliesSuperseded
  3. v316 patches 12 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v216 patches3 repliesSuperseded
v117 patches19 repliesSuperseded

Changes in v5 from the cover letter

- Rebase to bpf-next and fix build error

Patches in v5 All 19 applied

#Subject and filesSizeRepliesApplied
1/19rcu: Create an unrcu_pointer() to remove __rcu from a pointerinclude/linux/rcupdate.h+14 -00 repliesApplied
2/19doc: Clarify and expand RCU updaters and corresponding readersDocumentation/RCU/checklist.rst+27 -210 repliesApplied
3/19doc: Give XDP as example of non-obvious RCU reader/updater pairingDocumentation/RCU/checklist.rst+9 -20 repliesApplied
4/19bpf: allow RCU-protected lookups to happen from bh contextkernel/bpf/hashtab.c kernel/bpf/helpers.c kernel/bpf/lpm_trie.c+21 -120 repliesApplied
5/19xdp: add proper __rcu annotations to redirect map entriesinclude/linux/filter.h include/net/xdp_sock.h kernel/bpf/cpumap.c +5 more+83 -540 repliesApplied
6/19sched: remove unneeded rcu_read_lock() around BPF program invocationnet/sched/act_bpf.c net/sched/cls_bpf.c+0 -50 repliesApplied
7/19ena: remove rcu_read_lock() around XDP program invocationdrivers/net/ethernet/amazon/ena/ena_netdev.c+0 -30 repliesApplied
8/19bnxt: remove rcu_read_lock() around XDP program invocationdrivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c+0 -20 repliesApplied
9/19thunderx: remove rcu_read_lock() around XDP program invocationdrivers/net/ethernet/cavium/thunder/nicvf_main.c+0 -20 repliesApplied
10/19freescale: remove rcu_read_lock() around XDP program invocationdrivers/net/ethernet/freescale/dpaa/dpaa_eth.c drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c+1 -100 repliesApplied
11/19net: intel: remove rcu_read_lock() around XDP program invocationdrivers/net/ethernet/intel/i40e/i40e_txrx.c drivers/net/ethernet/intel/i40e/i40e_xsk.c drivers/net/ethernet/intel/ice/ice_txrx.c +6 more+3 -270 repliesApplied
12/19marvell: remove rcu_read_lock() around XDP program invocationdrivers/net/ethernet/marvell/mvneta.c drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c+0 -60 repliesApplied
13/19mlx4: remove rcu_read_lock() around XDP program invocationdrivers/net/ethernet/mellanox/mlx4/en_rx.c+2 -60 repliesApplied
14/19nfp: remove rcu_read_lock() around XDP program invocationdrivers/net/ethernet/netronome/nfp/nfp_net_common.c+0 -20 repliesApplied
15/19qede: remove rcu_read_lock() around XDP program invocationdrivers/net/ethernet/qlogic/qede/qede_fp.c+0 -60 repliesApplied
16/19sfc: remove rcu_read_lock() around XDP program invocationdrivers/net/ethernet/sfc/rx.c+2 -70 repliesApplied
17/19netsec: remove rcu_read_lock() around XDP program invocationdrivers/net/ethernet/socionext/netsec.c+0 -30 repliesApplied
18/19stmmac: remove rcu_read_lock() around XDP program invocationdrivers/net/ethernet/stmicro/stmmac/stmmac_main.c+2 -80 repliesApplied
19/19net: ti: remove rcu_read_lock() around XDP program invocationdrivers/net/ethernet/ti/cpsw_priv.c+2 -80 repliesApplied

Reviews trailers per patch

7 of 19 patches have a Reviewed-by or Acked-by.

PatchJesper Dangaard BrouerMartin KaFai LauCamelia GrozaTariq ToukanIlias ApalodimasSimon HormanEdward CreeGrygorii Strashko
1/19
2/19
3/19
4/19A-b
5/19
6/19
7/19
8/19
9/19
10/19R-b
11/19T-b
12/19
13/19R-b
14/19R-b
15/19
16/19A-b
17/19A-b
18/19
19/19T-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 8 reviewers.

Read the v5 thread

Cover letter [PATCH bpf-next v5 00/19] Clean up and document RCU-based object protection for XDP and TC BPF

During the discussion[0] of Hangbin's multicast patch series, Martin pointed out that the lifetime of the RCU-protected map entries used by XDP_REDIRECT is by no means obvious. I promised to look into cleaning this up, and Paul helpfully provided some hints and a new unrcu_pointer() helper to aid in this.

It seems[1] that back in the early days of XDP, local_bh_disable() did not provide RCU protection, which is why the rcu_read_lock() calls were added to drivers in the first place. But according to Paul[2], in recent kernels a local_bh_disable()/local_bh_enable() pair functions as one big RCU read-side section, so no further protection is needed. This even applies to -rt kernels, which has an explicit rcu_read_lock() in place as part of the local_bh_disable()[3].

This patch series is mostly a documentation exercise, cleaning up the description of the lifetime expectations and adding __rcu annotations so sparse and lockdep can help verify it.

Patches 1-4 are preparatory: Patch 1 adds Paul's unrcu_pointer() helper (which has already been added to his tree), which we need for some of the operations in devmap, patches 2 and 3 update the RCU documentation and patch 4 adds bh context as a valid condition for map lookups. Patch 5 is the main bit that adds the __rcu annotations and updates documentation comments. Finally, patch 6 removes unneeded rcu_read_lock()s from TC BPF, and the rest are patches updating the drivers, with one patch per distinct maintainer.

Unfortunately I don't have any hardware to test any of the driver patches; Jesper helpfully verified that it doesn't break anything on i40e, but the rest of the driver patches are only compile-tested.

[0] https://lore.kernel.org/bpf/[email protected]/
[1] https://lore.kernel.org/bpf/[email protected]/
[2] https://lore.kernel.org/bpf/20210417002301.GO4212@paulmck-ThinkPad-P17-Gen-1/
[3] https://lore.kernel.org/bpf/20210419165837.GA975577@paulmck-ThinkPad-P17-Gen-1/

Changelog:
v5:
- Rebase to bpf-next and fix build error
v4:
- Move comment about RCU protection into core instead of leaving it in drivers
- Also remove rcu_read_lock() around TC BPF program execution
- Fold in a couple of patches from Paul updating the RCU documentation
v3:
- Remove one other unnecessary change to hlist_for_each_entry_rcu()
- Carry forward another ACK
v2:
- Add a comment about RCU protection to the drivers where rcu_read_lock() is removed
- Drop unnecessary patch 3 which changed dev_get_by_index_rcu()
- Add some more text with the history to cover letter
- Fix a few places where the wrong RCU checks were used in cpumap and xskmap code
- Carry forward ACKs

Paul E. McKenney (2):
rcu: Create an unrcu_pointer() to remove __rcu from a pointer
doc: Clarify and expand RCU updaters and corresponding readers

Toke Høiland-Jørgensen (17):
doc: Give XDP as example of non-obvious RCU reader/updater pairing
bpf: allow RCU-protected lookups to happen from bh context
xdp: add proper __rcu annotations to redirect map entries
sched: remove unneeded rcu_read_lock() around BPF program invocation
ena: remove rcu_read_lock() around XDP program invocation
bnxt: remove rcu_read_lock() around XDP program invocation
thunderx: remove rcu_read_lock() around XDP program invocation
freescale: remove rcu_read_lock() around XDP program invocation
net: intel: remove rcu_read_lock() around XDP program invocation
marvell: remove rcu_read_lock() around XDP program invocation
mlx4: remove rcu_read_lock() around XDP program invocation
nfp: remove rcu_read_lock() around XDP program invocation
qede: remove rcu_read_lock() around XDP program invocation
sfc: remove rcu_read_lock() around XDP program invocation
netsec: remove rcu_read_lock() around XDP program invocation
stmmac: remove rcu_read_lock() around XDP program invocation
net: ti: remove rcu_read_lock() around XDP program invocation

 Documentation/RCU/checklist.rst               | 55 ++++++++++++-------
 drivers/net/ethernet/amazon/ena/ena_netdev.c  |  3 -
 drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c |  2 -
 .../net/ethernet/cavium/thunder/nicvf_main.c  |  2 -
 .../net/ethernet/freescale/dpaa/dpaa_eth.c    |  8 +--
 .../net/ethernet/freescale/dpaa2/dpaa2-eth.c  |  3 -
 drivers/net/ethernet/intel/i40e/i40e_txrx.c   |  2 -
 drivers/net/ethernet/intel/i40e/i40e_xsk.c    |  3 -
 drivers/net/ethernet/intel/ice/ice_txrx.c     |  6 +-
 drivers/net/ethernet/intel/ice/ice_xsk.c      |  3 -
 drivers/net/ethernet/intel/igb/igb_main.c     |  2 -
 drivers/net/ethernet/intel/igc/igc_main.c     |  7 +--
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |  2 -
 drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c  |  3 -
 .../net/ethernet/intel/ixgbevf/ixgbevf_main.c |  2 -
 drivers/net/ethernet/marvell/mvneta.c         |  2 -
 .../net/ethernet/marvell/mvpp2/mvpp2_main.c   |  4 --
 drivers/net/ethernet/mellanox/mlx4/en_rx.c    |  8 +--
 .../ethernet/netronome/nfp/nfp_net_common.c   |  2 -
 drivers/net/ethernet/qlogic/qede/qede_fp.c    |  6 --
 drivers/net/ethernet/sfc/rx.c                 |  9 +--
 drivers/net/ethernet/socionext/netsec.c       |  3 -
 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 10 +---
 drivers/net/ethernet/ti/cpsw_priv.c           | 10 +---
 include/linux/filter.h                        |  8 +--
 include/linux/rcupdate.h                      | 14 +++++
 include/net/xdp_sock.h                        |  2 +-
 kernel/bpf/cpumap.c                           | 13 +++--
 kernel/bpf/devmap.c                           | 49 +++++++----------
 kernel/bpf/hashtab.c                          | 21 ++++---
 kernel/bpf/helpers.c                          |  6 +-
 kernel/bpf/lpm_trie.c                         |  6 +-
 net/core/filter.c                             | 28 ++++++++++
 net/sched/act_bpf.c                           |  2 -
 net/sched/cls_bpf.c                           |  3 -
 net/xdp/xsk.c                                 |  4 +-
 net/xdp/xsk.h                                 |  4 +-
 net/xdp/xskmap.c                              | 29 ++++++----
 38 files changed, 164 insertions(+), 182 deletions(-)
Signature · 1 line
2.32.0