Commit Graph

14 Commits

Author SHA1 Message Date
Waiman Long ca8db1144f locking/rtmutex: Add a lockdep assert to catch potential nested blocking
JIRA: https://issues.redhat.com/browse/RHEL-28616

commit 45f67f30a22f264bc7a0a61255c2ee1a838e9403
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Fri, 8 Sep 2023 18:22:53 +0200

    locking/rtmutex: Add a lockdep assert to catch potential nested blocking

    There used to be a BUG_ON(current->pi_blocked_on) in the lock acquisition
    functions, but that vanished in one of the rtmutex overhauls.

    Bring it back in form of a lockdep assert to catch code paths which take
    rtmutex based locks with current::pi_blocked_on != NULL.

    Reported-by: Crystal Wood <swood@redhat.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: "Peter Zijlstra (Intel)" <peterz@infradead.org>
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lkml.kernel.org/r/20230908162254.999499-7-bigeasy@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2024-03-27 10:06:01 -04:00
Waiman Long f62c68f20c locking/rtmutex: Use rt_mutex specific scheduler helpers
JIRA: https://issues.redhat.com/browse/RHEL-28616

commit d14f9e930b9073de264c106bf04968286ef9b3a4
Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date:   Fri, 8 Sep 2023 18:22:52 +0200

    locking/rtmutex: Use rt_mutex specific scheduler helpers

    Have rt_mutex use the rt_mutex specific scheduler helpers to avoid
    recursion vs rtlock on the PI state.

    [[ peterz: adapted to new names ]]

    Reported-by: Crystal Wood <swood@redhat.com>
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lkml.kernel.org/r/20230908162254.999499-6-bigeasy@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2024-03-27 10:05:58 -04:00
Waiman Long 0badc86620 Revert "locking/rtmutex: Submit/resume work explicitly before/after blocking"
JIRA: https://issues.redhat.com/browse/RHEL-28616
Upstream Status: RHEL only

Revert linux-rt-devel specific commit a44b38b17bf3 ("locking/rtmutex:
Submit/resume work explicitly before/after blocking") to prepare for
the submission of upstream equivalent.

Signed-off-by: Waiman Long <longman@redhat.com>
2024-03-27 09:56:35 -04:00
Waiman Long 3ad42081d5 Revert "locking/rtmutex: Add a lockdep assert to catch potential nested blocking"
JIRA: https://issues.redhat.com/browse/RHEL-28616
Upstream Status: RHEL only

Revert linux-rt-devel specific commit e2d27efe1923 ("locking/rtmutex:
Add a lockdep assert to catch potential nested blocking") to prepare
for the submission of upstream equivalent.

Signed-off-by: Waiman Long <longman@redhat.com>
2024-03-27 09:56:34 -04:00
Crystal Wood 31f7062808 locking/rtmutex: Add a lockdep assert to catch potential nested blocking
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2218724

Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git

commit e2d27efe19234c94a42e123dc8122c4f13c9a9ab
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Thu Apr 27 13:19:37 2023 +0200

    locking/rtmutex: Add a lockdep assert to catch potential nested blocking

    There used to be a BUG_ON(current->pi_blocked_on) in the lock acquisition
    functions, but that vanished in one of the rtmutex overhauls.

    Bring it back in form of a lockdep assert to catch code paths which take
    rtmutex based locks with current::pi_blocked_on != NULL.

    Reported-by: Crystal Wood <swood@redhat.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Link: https://lore.kernel.org/r/20230427111937.2745231-5-bigeasy@linutronix.de

Signed-off-by: Crystal Wood <swood@redhat.com>
2023-07-18 17:22:36 -05:00
Crystal Wood 2ef9c3d906 locking/rtmutex: Submit/resume work explicitly before/after blocking
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2218724

Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git

commit a44b38b17bf31d90509125a8d34c9ac8f0dcc886
Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date:   Thu Apr 27 13:19:35 2023 +0200

    locking/rtmutex: Submit/resume work explicitly before/after blocking

    schedule() invokes sched_submit_work() before scheduling and
    sched_resume_work() afterwards to ensure that queued block requests are
    flushed and the (IO)worker machineries can instantiate new workers if
    required. This avoids deadlocks and starvation.

    With rt_mutexes this can lead to a subtle problem:

      When rtmutex blocks current::pi_blocked_on points to the rtmutex it
      blocks on. When one of the functions in sched_submit/resume_work() contends
      on a rtmutex based lock then that would corrupt current::pi_blocked_on.

    Let rtmutex and the RT lock variants which are based on it invoke
    sched_submit/resume_work() explicitly before and after the slowpath so
    it's guaranteed that current::pi_blocked_on cannot be corrupted by blocking
    on two locks.

    This does not apply to the PREEMPT_RT variants of spinlock_t and rwlock_t
    as their scheduling slowpath is separate and cannot invoke the work related
    functions due to potential deadlocks anyway.

    [ tglx: Make it explicit and symmetric. Massage changelog ]

    Fixes: e17ba59b7e8e1 ("locking/rtmutex: Guard regular sleeping locks specific functions")
    Reported-by: Crystal Wood <swood@redhat.com>
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Link: https://lore.kernel.org/4b4ab374d3e24e6ea8df5cadc4297619a6d945af.camel@redhat.com
    Link: https://lore.kernel.org/r/20230427111937.2745231-3-bigeasy@linutronix.de

Signed-off-by: Crystal Wood <swood@redhat.com>
2023-07-18 17:22:36 -05:00
Waiman Long 1abcee1a8f locking/rwlocks: introduce write_lock_nested
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2076713

commit 4a57d6bbaecd28c8175dc5da013009e4158018c2
Author: Minchan Kim <minchan@kernel.org>
Date:   Fri, 21 Jan 2022 22:14:10 -0800

    locking/rwlocks: introduce write_lock_nested

    In preparation for converting bit_spin_lock to rwlock in zsmalloc so
    that multiple writers of zspages can run at the same time but those
    zspages are supposed to be different zspage instance.  Thus, it's not
    deadlock.  This patch adds write_lock_nested to support the case for
    LOCKDEP.

    [minchan@kernel.org: fix write_lock_nested for RT]
      Link: https://lkml.kernel.org/r/YZfrMTAXV56HFWJY@google.com
    [bigeasy@linutronix.de: fixup write_lock_nested() implementation]
      Link: https://lkml.kernel.org/r/20211123170134.y6xb7pmpgdn4m3bn@linutronix.de

    Link: https://lkml.kernel.org/r/20211115185909.3949505-8-minchan@kernel.org
    Signed-off-by: Minchan Kim <minchan@kernel.org>
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Tested-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Cc: Mike Galbraith <umgwanakikbuti@gmail.com>
    Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Naresh Kamboju <naresh.kamboju@linaro.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Signed-off-by: Waiman Long <longman@redhat.com>
2022-05-12 08:34:05 -04:00
Patrick Talbert f9a5b7f4d0 Merge: Scheduler RT prerequisites
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/754

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2076594
Tested:  Sanity tested with scheduler stress tests.

This is a handful of commits to help the RT merge. Keeping the differences
as small as possible reduces the maintenance.

Signed-off-by: Phil Auld <pauld@redhat.com>

Approved-by: Fernando Pacheco <fpacheco@redhat.com>
Approved-by: Waiman Long <longman@redhat.com>
Approved-by: Wander Lairson Costa <wander@redhat.com>

Signed-off-by: Patrick Talbert <ptalbert@redhat.com>
2022-05-12 09:28:27 +02:00
Phil Auld 72c2b5b4c5 locking/rt: Take RCU nesting into account for __might_resched()
Bugzilla: https://bugzilla.redhat.com/2076594

commit ef1f4804b27a54da34de6984d16f1fe8f2cc7011
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Thu Sep 23 18:54:46 2021 +0200

    locking/rt: Take RCU nesting into account for __might_resched()

    The general rule that rcu_read_lock() held sections cannot voluntary sleep
    does apply even on RT kernels. Though the substitution of spin/rw locks on
    RT enabled kernels has to be exempt from that rule. On !RT a spin_lock()
    can obviously nest inside a RCU read side critical section as the lock
    acquisition is not going to block, but on RT this is not longer the case
    due to the 'sleeping' spinlock substitution.

    The RT patches contained a cheap hack to ignore the RCU nesting depth in
    might_sleep() checks, which was a pragmatic but incorrect workaround.

    Instead of generally ignoring the RCU nesting depth in __might_sleep() and
    __might_resched() checks, pass the rcu_preempt_depth() via the offsets
    argument to __might_resched() from spin/read/write_lock() which makes the
    checks work correctly even in RCU read side critical sections.

    The actual blocking on such a substituted lock within a RCU read side
    critical section is already handled correctly in __schedule() by treating
    it as a "preemption" of the RCU read side critical section.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lkml.kernel.org/r/20210923165358.368305497@linutronix.de

Signed-off-by: Phil Auld <pauld@redhat.com>
2022-04-19 15:01:34 -04:00
Phil Auld acc9612b04 sched: Clean up the might_sleep() underscore zoo
Bugzilla: https://bugzilla.redhat.com/2076594

commit 874f670e6088d3bff3972ecd44c1cb00610f9183
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Thu Sep 23 18:54:35 2021 +0200

    sched: Clean up the might_sleep() underscore zoo

    __might_sleep() vs. ___might_sleep() is hard to distinguish. Aside of that
    the three underscore variant is exposed to provide a checkpoint for
    rescheduling points which are distinct from blocking points.

    They are semantically a preemption point which means that scheduling is
    state preserving. A real blocking operation, e.g. mutex_lock(), wait*(),
    which cannot preserve a task state which is not equal to RUNNING.

    While technically blocking on a "sleeping" spinlock in RT enabled kernels
    falls into the voluntary scheduling category because it has to wait until
    the contended spin/rw lock becomes available, the RT lock substitution code
    can semantically be mapped to a voluntary preemption because the RT lock
    substitution code and the scheduler are providing mechanisms to preserve
    the task state and to take regular non-lock related wakeups into account.

    Rename ___might_sleep() to __might_resched() to make the distinction of
    these functions clear.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lkml.kernel.org/r/20210923165357.928693482@linutronix.de

Signed-off-by: Phil Auld <pauld@redhat.com>
2022-04-19 15:01:33 -04:00
Phil Auld d857bb519d locking: Remove rt_rwlock_is_contended().
Bugzilla: http://bugzilla.redhat.com/2062831

commit e08f343be00c3fe8f9f6ac58085c81bcdd231fab
Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date:   Mon Nov 29 18:46:45 2021 +0100

    locking: Remove rt_rwlock_is_contended().

    rt_rwlock_is_contended() has no users. It makes no sense to use it as
    rwlock_is_contended() because it is a sleeping lock on RT and
    preemption is possible. It reports always != 0 if used by a writer and
    even if there is a waiter then the lock might not be handed over if
    the current owner has the highest priority.

    Remove rt_rwlock_is_contended().

    Reported-by: kernel test robot <lkp@intel.com>
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lore.kernel.org/r/20211129174654.668506-3-bigeasy@linutronix.de

Signed-off-by: Phil Auld <pauld@redhat.com>
2022-03-28 09:28:36 -04:00
Waiman Long b66b8ee8ef locking/spinlock/rt: Prepare for RT local_lock
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2007032

commit 31552385f8e9d0869117014bf8e55ba0497e3ec8
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Sun, 15 Aug 2021 23:29:27 +0200

    locking/spinlock/rt: Prepare for RT local_lock

    Add the static and runtime initializer mechanics to support the RT variant
    of local_lock, which requires the lock type in the lockdep map to be set
    to LD_LOCK_PERCPU.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Link: https://lore.kernel.org/r/20210815211305.967526724@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2021-09-27 16:19:25 -04:00
Waiman Long f5116e0458 locking/rwlock: Provide RT variant
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2007032

commit 8282947f67345246b4a6344dbceb07484d3d4dad
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Sun, 15 Aug 2021 23:28:28 +0200

    locking/rwlock: Provide RT variant

    Similar to rw_semaphores, on RT the rwlock substitution is not writer fair,
    because it's not feasible to have a writer inherit its priority to
    multiple readers. Readers blocked on a writer follow the normal rules of
    priority inheritance. Like RT spinlocks, RT rwlocks are state preserving
    across the slow lock operations (contended case).

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Link: https://lore.kernel.org/r/20210815211303.882793524@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2021-09-27 16:18:59 -04:00
Waiman Long abbd773e5a locking/spinlock: Provide RT variant
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2007032

commit 0f383b6dc96e976dfbf2721b0bf10bd96103b341
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Sun, 15 Aug 2021 23:28:27 +0200

    locking/spinlock: Provide RT variant

    Provide the actual locking functions which make use of the general and
    spinlock specific rtmutex code.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Link: https://lore.kernel.org/r/20210815211303.826621464@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2021-09-27 16:18:58 -04:00