Commit Graph

13 Commits

Author SHA1 Message Date
Joel Savitz baca3f37f7 locking/rtmutex: Fix task->pi_waiters integrity
JIRA: https://issues.redhat.com/browse/RHEL-5226

commit f7853c34241807bb97673a5e97719123be39a09e
Author: Peter Zijlstra <peterz@infradead.org>
Date:   Fri Jul 7 16:19:09 2023 +0200

    locking/rtmutex: Fix task->pi_waiters integrity

    Henry reported that rt_mutex_adjust_prio_check() has an ordering
    problem and puts the lie to the comment in [7]. Sharing the sort key
    between lock->waiters and owner->pi_waiters *does* create problems,
    since unlike what the comment claims, holding [L] is insufficient.

    Notably, consider:

            A
          /   \
         M1   M2
         |     |
         B     C

    That is, task A owns both M1 and M2, B and C block on them. In this
    case a concurrent chain walk (B & C) will modify their resp. sort keys
    in [7] while holding M1->wait_lock and M2->wait_lock. So holding [L]
    is meaningless, they're different Ls.

    This then gives rise to a race condition between [7] and [11], where
    the requeue of pi_waiters will observe an inconsistent tree order.

            B                               C

      (holds M1->wait_lock,         (holds M2->wait_lock,
       holds B->pi_lock)             holds A->pi_lock)

      [7]
      waiter_update_prio();
      ...
      [8]
      raw_spin_unlock(B->pi_lock);
      ...
      [10]
      raw_spin_lock(A->pi_lock);

                                    [11]
                                    rt_mutex_enqueue_pi();
                                    // observes inconsistent A->pi_waiters
                                    // tree order

    Fixing this means either extending the range of the owner lock from
    [10-13] to [6-13], with the immediate problem that this means [6-8]
    hold both blocked and owner locks, or duplicating the sort key.

    Since the locking in chain walk is horrible enough without having to
    consider pi_lock nesting rules, duplicate the sort key instead.

    By giving each tree their own sort key, the above race becomes
    harmless, if C sees B at the old location, then B will correct things
    (if they need correcting) when it walks up the chain and reaches A.

    Fixes: fb00aca474 ("rtmutex: Turn the plist into an rb-tree")
    Reported-by: Henry Wu <triangletrap12@gmail.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Acked-by: Thomas Gleixner <tglx@linutronix.de>
    Tested-by: Henry Wu <triangletrap12@gmail.com>
    Link: https://lkml.kernel.org/r/20230707161052.GF2883469%40hirez.programming.kicks-ass.net"

Signed-off-by: Joel Savitz <jsavitz@redhat.com>
2024-01-15 10:10:43 -05:00
Eirik Fuller d0f66cd097
locking: revert comment from KRTS JiraReadiness exercise
JIRA: https://issues.redhat.com/browse/RHEL-2256

Upstream Status: RHEL only

This commit reverts the bogus commit from RHEL-981

Signed-off-by: Eirik Fuller <efuller@redhat.com>
2023-09-05 15:49:21 +00:00
John B. Wyatt IV 232481c7e5 locking: 9.3 KRTS JiraReadiness exercise
JIRA: https://issues.redhat.com/browse/RHEL-981

Upstream Status: RHEL only

KRTS needs to check that kernel workflow works correctly with Jira tickets (aka JiraReadiness exercise).

We will create a bogus commit and then revert it.

Signed-off-by: John B. Wyatt IV <jwyatt@redhat.com>
2023-08-10 09:09:17 -04:00
Brian Masney c3a495f437 rtmutex: Add acquire semantics for rtmutex lock acquisition slow path
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=1c0908d8e441631f5b8ba433523cf39339ee2ba0
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2163507
Conflicts: Corrected minor context diff

commit 1c0908d8e441631f5b8ba433523cf39339ee2ba0
Author: Mel Gorman <mgorman@techsingularity.net>
Date:   Fri Dec 2 10:02:23 2022 +0000

    rtmutex: Add acquire semantics for rtmutex lock acquisition slow path

    Jan Kara reported the following bug triggering on 6.0.5-rt14 running dbench
    on XFS on arm64.

     kernel BUG at fs/inode.c:625!
     Internal error: Oops - BUG: 0 [#1] PREEMPT_RT SMP
     CPU: 11 PID: 6611 Comm: dbench Tainted: G            E   6.0.0-rt14-rt+ #1
     pc : clear_inode+0xa0/0xc0
     lr : clear_inode+0x38/0xc0
     Call trace:
      clear_inode+0xa0/0xc0
      evict+0x160/0x180
      iput+0x154/0x240
      do_unlinkat+0x184/0x300
      __arm64_sys_unlinkat+0x48/0xc0
      el0_svc_common.constprop.4+0xe4/0x2c0
      do_el0_svc+0xac/0x100
      el0_svc+0x78/0x200
      el0t_64_sync_handler+0x9c/0xc0
      el0t_64_sync+0x19c/0x1a0

    It also affects 6.1-rc7-rt5 and affects a preempt-rt fork of 5.14 so this
    is likely a bug that existed forever and only became visible when ARM
    support was added to preempt-rt. The same problem does not occur on x86-64
    and he also reported that converting sb->s_inode_wblist_lock to
    raw_spinlock_t makes the problem disappear indicating that the RT spinlock
    variant is the problem.

    Which in turn means that RT mutexes on ARM64 and any other weakly ordered
    architecture are affected by this independent of RT.

    Will Deacon observed:

      "I'd be more inclined to be suspicious of the slowpath tbh, as we need to
       make sure that we have acquire semantics on all paths where the lock can
       be taken. Looking at the rtmutex code, this really isn't obvious to me
       -- for example, try_to_take_rt_mutex() appears to be able to return via
       the 'takeit' label without acquire semantics and it looks like we might
       be relying on the caller's subsequent _unlock_ of the wait_lock for
       ordering, but that will give us release semantics which aren't correct."

    Sebastian Andrzej Siewior prototyped a fix that does work based on that
    comment but it was a little bit overkill and added some fences that should
    not be necessary.

    The lock owner is updated with an IRQ-safe raw spinlock held, but the
    spin_unlock does not provide acquire semantics which are needed when
    acquiring a mutex.

    Adds the necessary acquire semantics for lock owner updates in the slow path
    acquisition and the waiter bit logic.

    It successfully completed 10 iterations of the dbench workload while the
    vanilla kernel fails on the first iteration.

    [ bigeasy@linutronix.de: Initial prototype fix ]

    Fixes: 700318d1d7 ("locking/rtmutex: Use acquire/release semantics")
    Fixes: 23f78d4a03 ("[PATCH] pi-futex: rt mutex core")
    Reported-by: Jan Kara <jack@suse.cz>
    Signed-off-by: Mel Gorman <mgorman@techsingularity.net>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20221202100223.6mevpbl7i6x5udfd@techsingularity.net

Signed-off-by: Brian Masney <bmasney@redhat.com>
2023-01-23 13:03:46 -05:00
Waiman Long 485c33adb8 locking/rtmutex: Add rt_mutex_lock_nest_lock() and rt_mutex_lock_killable().
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2076713

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

    locking/rtmutex: Add rt_mutex_lock_nest_lock() and rt_mutex_lock_killable().

    The locking selftest for ww-mutex expects to operate directly on the
    base-mutex which becomes a rtmutex on PREEMPT_RT.

    Add a rtmutex based implementation of mutex_lock_nest_lock() and
    mutex_lock_killable() named rt_mutex_lock_nest_lock() abd
    rt_mutex_lock_killable().

    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-5-bigeasy@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2022-05-12 08:33:54 -04:00
Waiman Long 9a61bc98bf locking/rtmutex: Prevent lockdep false positive with PI futexes
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2007032

commit 51711e825a6d1b2fe7ca46bb06d08c25d97656ee
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Sun, 15 Aug 2021 23:29:20 +0200

    locking/rtmutex: Prevent lockdep false positive with PI futexes

    On PREEMPT_RT the futex hashbucket spinlock becomes 'sleeping' and rtmutex
    based. That causes a lockdep false positive because some of the futex
    functions invoke spin_unlock(&hb->lock) with the wait_lock of the rtmutex
    associated to the pi_futex held.  spin_unlock() in turn takes wait_lock of
    the rtmutex on which the spinlock is based which makes lockdep notice a
    lock recursion.

    Give the futex/rtmutex wait_lock a separate key.

    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.750701219@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2021-09-27 16:19:22 -04:00
Waiman Long e3bd2040f4 locking/rtmutex: Add mutex variant for RT
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2007032

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

    locking/rtmutex: Add mutex variant for RT

    Add the necessary defines, helpers and API functions for replacing struct mutex on
    a PREEMPT_RT enabled kernel with an rtmutex based variant.

    No functional change when CONFIG_PREEMPT_RT=n

    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.081517417@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2021-09-27 16:19:14 -04:00
Waiman Long 83850b9f0b locking/rtmutex: Extend the rtmutex core to support ww_mutex
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2007032

commit add461325ec5bc39aa619a1bfcde7245e5f31ac7
Author: Peter Zijlstra <peterz@infradead.org>
Date:   Sun, 15 Aug 2021 23:28:58 +0200

    locking/rtmutex: Extend the rtmutex core to support ww_mutex

    Add a ww acquire context pointer to the waiter and various functions and
    add the ww_mutex related invocations to the proper spots in the locking
    code, similar to the mutex based variant.

    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    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/20210815211304.966139174@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2021-09-27 16:19:12 -04:00
Waiman Long 7f6abebfbf locking/rtmutex: Guard regular sleeping locks specific functions
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2007032

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

    locking/rtmutex: Guard regular sleeping locks specific functions

    Guard the regular sleeping lock specific functionality, which is used for
    rtmutex on non-RT enabled kernels and for mutex, rtmutex and semaphores on
    RT enabled kernels so the code can be reused for the RT specific
    implementation of spinlocks and rwlocks in a different compilation unit.

    No functional change.

    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.311535693@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2021-09-27 16:18:51 -04:00
Waiman Long c0e45115f7 locking/rtmutex: Use rt_mutex_wake_q_head
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2007032

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

    locking/rtmutex: Use rt_mutex_wake_q_head

    Prepare for the required state aware handling of waiter wakeups via wake_q
    and switch the rtmutex code over to the rtmutex specific wrapper.

    No functional change.

    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.197113263@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2021-09-27 16:18:50 -04:00
Waiman Long f90139f12c locking/rtmutex: Provide rt_mutex_slowlock_locked()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2007032

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

    locking/rtmutex: Provide rt_mutex_slowlock_locked()

    Split the inner workings of rt_mutex_slowlock() out into a separate
    function, which can be reused by the upcoming RT lock substitutions,
    e.g. for rw_semaphores.

    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/20210815211302.841971086@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2021-09-27 16:18:46 -04:00
Waiman Long 3c29e6cff1 locking/rtmutex: Split out the inner parts of 'struct rtmutex'
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2007032

commit 830e6acc8a1cafe153a0d88f9b2455965b396131
Author: Peter Zijlstra <peterz@infradead.org>
Date:   Sun, 15 Aug 2021 23:27:58 +0200

    locking/rtmutex: Split out the inner parts of 'struct rtmutex'

    RT builds substitutions for rwsem, mutex, spinlock and rwlock around
    rtmutexes. Split the inner working out so each lock substitution can use
    them with the appropriate lockdep annotations. This avoids having an extra
    unused lockdep map in the wrapped rtmutex.

    No functional change.

    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    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/20210815211302.784739994@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2021-09-27 16:18:45 -04:00
Waiman Long 41f37aa11c locking/rtmutex: Split API from implementation
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2007032

commit 531ae4b06a737ed5539cd75dc6f6b9a28f900bba
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Sun, 15 Aug 2021 23:27:57 +0200

    locking/rtmutex: Split API from implementation

    Prepare for reusing the inner functions of rtmutex for RT lock
    substitutions: introduce kernel/locking/rtmutex_api.c and move
    them there.

    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/20210815211302.726560996@linutronix.de

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