All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
	Boqun Feng <boqun@kernel.org>, Waiman Long <longman@redhat.com>,
	linux-kernel@vger.kernel.org, Marco Elver <elver@google.com>,
	"Paul E . McKenney" <paulmck@kernel.org>,
	Christoph Hellwig <hch@lst.de>,
	Bart Van Assche <bvanassche@acm.org>
Subject: [PATCH v2 00/14] Stop lockdep_assert_held*() from assuming lock ownership
Date: Mon,  9 Nov 2026 11:13:08 -0800	[thread overview]
Message-ID: <cover.1794250850.git.bvanassche@acm.org> (raw)

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(-)


             reply	other threads:[~2026-11-09 19:13 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 19:13 Bart Van Assche [this message]
2026-11-09 19:13 ` [PATCH v2 01/14] bit_spinlock: Fix the __bitlock() definition Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 02/14] cleanup: Disable context analysis for __free() helpers Bart Van Assche
2026-11-11  9:26   ` Marco Elver
2026-11-09 19:13 ` [PATCH v2 03/14] tracing: Disable branch profiling for COMPILE_TEST builds Bart Van Assche
2026-11-10 10:14   ` Steven Rostedt
2026-11-11 10:57   ` Marco Elver
2026-11-09 19:13 ` [PATCH v2 04/14] srcu: Remove check from srcu_dereference_check() Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 05/14] futex: Annotate __attach_to_pi_owner() and fixup_pi_*owner() Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 06/14] locking/rwsem: Annotate rwsem internal functions with __must_hold() Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 07/14] nvme-fabrics: Annotate nvmf_lookup_transport() with __must_hold_shared() Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 08/14] lockdep: Introduce lockdep_assume_ctx_held() Bart Van Assche
2026-11-11 11:04   ` Marco Elver
2026-11-09 19:13 ` [PATCH v2 09/14] kfence: Use lockdep_assume_ctx_held() in kfence_report_error() Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 10/14] Bluetooth: Add lock context annotations for connection aliases Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 11/14] futex: Verify exit_mutex ownership in futex_exit_recursive() Bart Van Assche
2026-11-11 11:01   ` Marco Elver
2026-11-09 19:13 ` [PATCH v2 12/14] lockdep: Stop lockdep_assert_held*() from assuming lock ownership Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 13/14] compiler-context-analysis: Split the RCU assertion tests Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 14/14] rcu: Introduce lockdep_assume_in_rcu_*() Bart Van Assche

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1794250850.git.bvanassche@acm.org \
    --to=bvanassche@acm.org \
    --cc=boqun@kernel.org \
    --cc=elver@google.com \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.