Skip to content

Stop lockdep_assert_held*() from assuming lock ownership

Bart Van Assche lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest14 patches 5 repliesIn review
  2. v114 patches 9 repliesSuperseded

Changes in v2 from the cover letter

- In the commit message of patch 8/14 it is now explained why the new macros are introduced.
- lockdep_assume_shared_ctx_held() now calls lockdep_assert_held_read() instead of lockdep_assert_held().

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/14bit_spinlock: Fix the __bitlock() definitioninclude/linux/bit_spinlock.h+1 -10 replies
2/14cleanup: Disable context analysis for __free() helpersinclude/linux/cleanup.h+4 -21 reply
3/14tracing: Disable branch profiling for COMPILE_TEST buildskernel/trace/Kconfig+2 -12 replies
4/14srcu: Remove check from srcu_dereference_check()include/linux/srcu.h+15 -50 replies
5/14futex: Annotate __attach_to_pi_owner() and fixup_pi_*owner()kernel/futex/futex.h kernel/futex/pi.c+5 -10 replies
6/14locking/rwsem: Annotate rwsem internal functions with __must_hold()kernel/locking/rwsem.c+3 -00 replies
7/14nvme-fabrics: Annotate nvmf_lookup_transport() with __must_hold_shared()drivers/nvme/host/fabrics.c+1 -00 replies
8/14lockdep: Introduce lockdep_assume_ctx_held()include/linux/lockdep.h lib/test_context-analysis.c+68 -21 reply
9/14kfence: Use lockdep_assume_ctx_held() in kfence_report_error()mm/kfence/report.c+1 -10 replies
10/14Bluetooth: Add lock context annotations for connection aliasesnet/bluetooth/6lowpan.c net/bluetooth/iso.c net/bluetooth/l2cap_core.c +2 more+31 -310 replies
11/14futex: Verify exit_mutex ownership in futex_exit_recursive()kernel/futex/core.c+1 -11 reply
12/14lockdep: Stop lockdep_assert_held*() from assuming lock ownershipDocumentation/dev-tools/context-analysis.rst include/linux/lockdep.h kernel/locking/rtmutex.c+27 -160 replies
13/14compiler-context-analysis: Split the RCU assertion testslib/test_context-analysis.c+13 -10 replies
14/14rcu: Introduce lockdep_assume_in_rcu_*()Documentation/dev-tools/context-analysis.rst include/linux/rcupdate.h lib/test_context-analysis.c+92 -260 replies

Reviews trailers per patch

2 of 14 patches have a Reviewed-by or Acked-by.

PatchMarco ElverSteven Rostedt
1/14R-b
2/14
3/14A-b
4/14
5/14
6/14
7/14
8/14
9/14
10/14
11/14
12/14
13/14
14/14

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 00/14] Stop lockdep_assert_held*() from assuming lock ownership

Hi Peter and Marco,

Since commit 7c451541743c ("lockdep: Annotate lockdep assertions for context analysis"), lockdep_assert_held*() and lockdep_assert_in_rcu_*() not only verify at runtime that a lock is held but also instruct Clang context analysis to assume that the lock is held. This has the following disadvantages:
- These assertions silence context analysis warnings in functions that lack a __must_hold*() annotation. Hence, the compiler neither reports the missing function annotation nor checks at compile time whether callers hold the lock.
- lockdep_assert_held() makes context analysis assume exclusive lock ownership, even if a reader-writer lock is held in shared mode.
- lockdep_assert_held*() can only be used with lock types that are defined with context_lock_struct().

This patch series removes the context assumptions from the lockdep and RCU assertion macros and introduces separate macros for code that needs to inform context analysis that a lock is held:
- lockdep_assume_ctx_held() and lockdep_assume_shared_ctx_held().
- lockdep_assume_in_rcu_read_lock(), lockdep_assume_in_rcu_read_lock_bh(), lockdep_assume_in_rcu_read_lock_sched() and lockdep_assume_in_rcu_reader().
Unlike the __assume_*() macros, which only inform context analysis, the new lockdep_assume_*() macros also verify the assumption at runtime.

This patch series is organized as follows:
- Patches 1-4 fix issues in the existing context analysis support:
__bitlock() operator precedence, false positives for __free() helpers, enabling WARN_CONTEXT_ANALYSIS_ALL for allmodconfig and allyesconfig builds, and a too strict SRCU reader requirement in srcu_dereference_check().
- Patches 5-7 add __must_hold*() annotations to functions that currently rely on lockdep_assert_held() for context analysis.
- Patch 8 introduces lockdep_assume_ctx_held() and lockdep_assume_shared_ctx_held().
- Patches 9-11 convert code that accesses locks through pointer aliases or that uses __assume_ctx_lock() to lockdep_assume_ctx_held().
- Patch 12 removes the context assumptions from lockdep_assert_held*().
- Patches 13-14 do the same for the RCU assertions and introduce the lockdep_assume_in_rcu_*() macros.

Please consider this patch series for the next merge window.

Thanks,

Bart.

Changes compared to v1:
- In the commit message of patch 8/14 it is now explained why the new macros are introduced.
- lockdep_assume_shared_ctx_held() now calls lockdep_assert_held_read() instead of lockdep_assert_held().

Bart Van Assche (14):
bit_spinlock: Fix the __bitlock() definition
cleanup: Disable context analysis for __free() helpers
tracing: Disable branch profiling for COMPILE_TEST builds
srcu: Remove check from srcu_dereference_check()
futex: Annotate __attach_to_pi_owner() and fixup_pi_*owner() locking/rwsem: Annotate rwsem internal functions with __must_hold()
nvme-fabrics: Annotate nvmf_lookup_transport() with

    __must_hold_shared()

lockdep: Introduce lockdep_assume_ctx_held()
kfence: Use lockdep_assume_ctx_held() in kfence_report_error()
Bluetooth: Add lock context annotations for connection aliases
futex: Verify exit_mutex ownership in futex_exit_recursive()
lockdep: Stop lockdep_assert_held*() from assuming lock ownership
compiler-context-analysis: Split the RCU assertion tests
rcu: Introduce lockdep_assume_in_rcu_*()

 Documentation/dev-tools/context-analysis.rst | 20 +++--
 drivers/nvme/host/fabrics.c                  |  1 +
 include/linux/bit_spinlock.h                 |  2 +-
 include/linux/cleanup.h                      |  6 +-
 include/linux/lockdep.h                      | 72 +++++++++++++++--
 include/linux/rcupdate.h                     | 82 +++++++++++++++++---
 include/linux/srcu.h                         | 20 +++--
 kernel/futex/core.c                          |  2 +-
 kernel/futex/futex.h                         |  3 +-
 kernel/futex/pi.c                            |  3 +
 kernel/locking/rtmutex.c                     |  7 +-
 kernel/locking/rwsem.c                       |  3 +
 kernel/trace/Kconfig                         |  3 +-
 lib/test_context-analysis.c                  | 38 +++++++--
 mm/kfence/report.c                           |  2 +-
 net/bluetooth/6lowpan.c                      |  2 +-
 net/bluetooth/iso.c                          |  8 +-
 net/bluetooth/l2cap_core.c                   | 48 ++++++------
 net/bluetooth/mgmt.c                         |  2 +-
 net/bluetooth/smp.c                          |  2 +-
 20 files changed, 251 insertions(+), 75 deletions(-)