linux/Documentation/locking
Ahmed S. Darwish 55f3560df9 seqlock: Extend seqcount API with associated locks
A sequence counter write side critical section must be protected by some
form of locking to serialize writers. If the serialization primitive is
not disabling preemption implicitly, preemption has to be explicitly
disabled before entering the write side critical section.

There is no built-in debugging mechanism to verify that the lock used
for writer serialization is held and preemption is disabled. Some usage
sites like dma-buf have explicit lockdep checks for the writer-side
lock, but this covers only a small portion of the sequence counter usage
in the kernel.

Add new sequence counter types which allows to associate a lock to the
sequence counter at initialization time. The seqcount API functions are
extended to provide appropriate lockdep assertions depending on the
seqcount/lock type.

For sequence counters with associated locks that do not implicitly
disable preemption, preemption protection is enforced in the sequence
counter write side functions. This removes the need to explicitly add
preempt_disable/enable() around the write side critical sections: the
write_begin/end() functions for these new sequence counter types
automatically do this.

Introduce the following seqcount types with associated locks:

     seqcount_spinlock_t
     seqcount_raw_spinlock_t
     seqcount_rwlock_t
     seqcount_mutex_t
     seqcount_ww_mutex_t

Extend the seqcount read and write functions to branch out to the
specific seqcount_LOCKTYPE_t implementation at compile-time. This avoids
kernel API explosion per each new seqcount_LOCKTYPE_t added. Add such
compile-time type detection logic into a new, internal, seqlock header.

Document the proper seqcount_LOCKTYPE_t usage, and rationale, at
Documentation/locking/seqlock.rst.

If lockdep is disabled, this lock association is compiled out and has
neither storage size nor runtime overhead.

Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200720155530.1173732-10-a.darwish@linutronix.de
2020-07-29 16:14:25 +02:00
..
futex-requeue-pi.rst docs: move locking-specific documents to locking/ 2020-05-15 12:05:07 -06:00
hwspinlock.rst docs: move locking-specific documents to locking/ 2020-05-15 12:05:07 -06:00
index.rst Documentation: locking: Describe seqlock design and usage 2020-07-29 16:14:22 +02:00
lockdep-design.rst docs: locking: convert docs to ReST and rename to *.rst 2019-07-15 08:53:27 -03:00
lockstat.rst docs: locking: convert docs to ReST and rename to *.rst 2019-07-15 08:53:27 -03:00
locktorture.rst doc:locking: remove info about old behavior of locktorture 2020-05-05 09:55:58 -06:00
locktypes.rst locking: Introduce local_lock() 2020-05-28 10:31:09 +02:00
mutex-design.rst docs: locking: Replace HTTP links with HTTPS ones 2020-07-16 23:19:51 +02:00
percpu-rw-semaphore.rst docs: move locking-specific documents to locking/ 2020-05-15 12:05:07 -06:00
pi-futex.rst docs: move locking-specific documents to locking/ 2020-05-15 12:05:07 -06:00
preempt-locking.rst docs: move locking-specific documents to locking/ 2020-05-15 12:05:07 -06:00
robust-futex-ABI.rst docs: move locking-specific documents to locking/ 2020-05-15 12:05:07 -06:00
robust-futexes.rst docs: move locking-specific documents to locking/ 2020-05-15 12:05:07 -06:00
rt-mutex-design.rst docs: locking: convert docs to ReST and rename to *.rst 2019-07-15 08:53:27 -03:00
rt-mutex.rst docs: move locking-specific documents to locking/ 2020-05-15 12:05:07 -06:00
seqlock.rst seqlock: Extend seqcount API with associated locks 2020-07-29 16:14:25 +02:00
spinlocks.rst docs/locking: Fix outdated section names 2020-02-05 10:21:12 -07:00
ww-mutex-design.rst docs: locking: convert docs to ReST and rename to *.rst 2019-07-15 08:53:27 -03:00