Centos-kernel-stream-9/Documentation/locking
Waiman Long 9ae7ca4ed6 locking/mutex: Document that mutex_unlock() is non-atomic
JIRA: https://issues.redhat.com/browse/RHEL-35759

commit a51749ab34d9e5dec548fe38ede7e01e8bb26454
Author: Jann Horn <jannh@google.com>
Date:   Thu, 30 Nov 2023 21:48:17 +0100

    locking/mutex: Document that mutex_unlock() is non-atomic

    I have seen several cases of attempts to use mutex_unlock() to release an
    object such that the object can then be freed by another task.

    This is not safe because mutex_unlock(), in the
    MUTEX_FLAG_WAITERS && !MUTEX_FLAG_HANDOFF case, accesses the mutex
    structure after having marked it as unlocked; so mutex_unlock() requires
    its caller to ensure that the mutex stays alive until mutex_unlock()
    returns.

    If MUTEX_FLAG_WAITERS is set and there are real waiters, those waiters
    have to keep the mutex alive, but we could have a spurious
    MUTEX_FLAG_WAITERS left if an interruptible/killable waiter bailed
    between the points where __mutex_unlock_slowpath() did the cmpxchg
    reading the flags and where it acquired the wait_lock.

    ( With spinlocks, that kind of code pattern is allowed and, from what I
      remember, used in several places in the kernel. )

    Document this, such a semantic difference between mutexes and spinlocks
    is fairly unintuitive.

    [ mingo: Made the changelog a bit more assertive, refined the comments. ]

    Signed-off-by: Jann Horn <jannh@google.com>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Link: https://lore.kernel.org/r/20231130204817.2031407-1-jannh@google.com

Signed-off-by: Waiman Long <longman@redhat.com>
2024-05-22 19:52:16 -04: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 locking/lockdep,doc: Improve readability of the block matrix 2021-05-31 10:14:54 +02:00
lockstat.rst
locktorture.rst docs: RCU: Convert torture.txt to ReST 2020-06-29 11:58:11 -07:00
locktypes.rst Documentation/locking/locktypes: Update migrate_disable() bits. 2022-06-03 17:23:51 +03:00
mutex-design.rst locking/mutex: Document that mutex_unlock() is non-atomic 2024-05-22 19:52:16 -04: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
rt-mutex.rst docs: move locking-specific documents to locking/ 2020-05-15 12:05:07 -06:00
seqlock.rst Documentation: seqlock: s/LOCKTYPE/LOCKNAME/g 2020-12-09 17:08:49 +01:00
spinlocks.rst
ww-mutex-design.rst Documentation: locking: ww-mutex-design: drop duplicated word 2020-07-13 09:48:31 -06:00