28 Feb, 2019

1 commit

  • The patch that frees unused lock classes will modify the behavior of
    lockdep_free_key_range() and lockdep_reset_lock() depending on whether
    or not these functions are called from the context of the lockdep
    selftests. Hence make it easy to detect whether or not lockdep code
    is called from the context of a lockdep selftest.

    Signed-off-by: Bart Van Assche
    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Andrew Morton
    Cc: Johannes Berg
    Cc: Linus Torvalds
    Cc: Paul E. McKenney
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Waiman Long
    Cc: Will Deacon
    Cc: johannes.berg@intel.com
    Cc: tj@kernel.org
    Link: https://lkml.kernel.org/r/20190214230058.196511-10-bvanassche@acm.org
    Signed-off-by: Ingo Molnar

    Bart Van Assche
     

03 Jul, 2018

1 commit

  • The current Wound-Wait mutex algorithm is actually not Wound-Wait but
    Wait-Die. Implement also Wound-Wait as a per-ww-class choice. Wound-Wait
    is, contrary to Wait-Die a preemptive algorithm and is known to generate
    fewer backoffs. Testing reveals that this is true if the
    number of simultaneous contending transactions is small.
    As the number of simultaneous contending threads increases, Wait-Wound
    becomes inferior to Wait-Die in terms of elapsed time.
    Possibly due to the larger number of held locks of sleeping transactions.

    Update documentation and callers.

    Timings using git://people.freedesktop.org/~thomash/ww_mutex_test
    tag patch-18-06-15

    Each thread runs 100000 batches of lock / unlock 800 ww mutexes randomly
    chosen out of 100000. Four core Intel x86_64:

    Algorithm #threads Rollbacks time
    Wound-Wait 4 ~100 ~17s.
    Wait-Die 4 ~150000 ~19s.
    Wound-Wait 16 ~360000 ~109s.
    Wait-Die 16 ~450000 ~82s.

    Cc: Ingo Molnar
    Cc: Jonathan Corbet
    Cc: Gustavo Padovan
    Cc: Maarten Lankhorst
    Cc: Sean Paul
    Cc: David Airlie
    Cc: Davidlohr Bueso
    Cc: "Paul E. McKenney"
    Cc: Josh Triplett
    Cc: Thomas Gleixner
    Cc: Kate Stewart
    Cc: Philippe Ombredanne
    Cc: Greg Kroah-Hartman
    Cc: linux-doc@vger.kernel.org
    Cc: linux-media@vger.kernel.org
    Cc: linaro-mm-sig@lists.linaro.org
    Co-authored-by: Peter Zijlstra
    Signed-off-by: Thomas Hellstrom
    Acked-by: Peter Zijlstra (Intel)
    Acked-by: Ingo Molnar

    Thomas Hellstrom
     

02 Nov, 2017

1 commit

  • Many source files in the tree are missing licensing information, which
    makes it harder for compliance tools to determine the correct license.

    By default all files without license information are under the default
    license of the kernel, which is GPL version 2.

    Update the files which contain no license information with the 'GPL-2.0'
    SPDX license identifier. The SPDX identifier is a legally binding
    shorthand, which can be used instead of the full boiler plate text.

    This patch is based on work done by Thomas Gleixner and Kate Stewart and
    Philippe Ombredanne.

    How this work was done:

    Patches were generated and checked against linux-4.14-rc6 for a subset of
    the use cases:
    - file had no licensing information it it.
    - file was a */uapi/* one with no licensing information in it,
    - file was a */uapi/* one with existing licensing information,

    Further patches will be generated in subsequent months to fix up cases
    where non-standard license headers were used, and references to license
    had to be inferred by heuristics based on keywords.

    The analysis to determine which SPDX License Identifier to be applied to
    a file was done in a spreadsheet of side by side results from of the
    output of two independent scanners (ScanCode & Windriver) producing SPDX
    tag:value files created by Philippe Ombredanne. Philippe prepared the
    base worksheet, and did an initial spot review of a few 1000 files.

    The 4.13 kernel was the starting point of the analysis with 60,537 files
    assessed. Kate Stewart did a file by file comparison of the scanner
    results in the spreadsheet to determine which SPDX license identifier(s)
    to be applied to the file. She confirmed any determination that was not
    immediately clear with lawyers working with the Linux Foundation.

    Criteria used to select files for SPDX license identifier tagging was:
    - Files considered eligible had to be source code files.
    - Make and config files were included as candidates if they contained >5
    lines of source
    - File already had some variant of a license header in it (even if
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

10 Oct, 2017

1 commit

  • The work-around for the expected failure is providing another failure :/

    Only when CONFIG_PROVE_LOCKING=y do we increment unexpected_testcase_failures,
    so only then do we need to decrement, otherwise we'll end up with a negative
    number and that will again trigger a BUG (printout, not crash).

    Reported-by: Fengguang Wu
    Tested-by: Fengguang Wu
    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Fixes: d82fed752942 ("locking/lockdep/selftests: Fix mixed read-write ABBA tests")
    Signed-off-by: Ingo Molnar

    Peter Zijlstra
     

29 Aug, 2017

1 commit

  • Commit:

    e91498589746 ("locking/lockdep/selftests: Add mixed read-write ABBA tests")

    adds an explicit FAILURE to the locking selftest but overlooked the
    fact that this kills lockdep. Fudge the test to avoid this.

    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: hpa@zytor.com
    Link: http://lkml.kernel.org/r/20170828124245.xlo2yshxq2btgmuf@hirez.programming.kicks-ass.net
    Signed-off-by: Ingo Molnar

    Peter Zijlstra
     

25 Aug, 2017

1 commit

  • Currently lockdep has limited support for recursive readers, add a few
    mixed read-write ABBA selftests to show the extend of these
    limitations.

    [ 0.000000] ----------------------------------------------------------------------------
    [ 0.000000] | spin |wlock |rlock |mutex | wsem | rsem |
    [ 0.000000] --------------------------------------------------------------------------

    [ 0.000000] mixed read-lock/lock-write ABBA: |FAILED| | ok |
    [ 0.000000] mixed read-lock/lock-read ABBA: | ok | | ok |
    [ 0.000000] mixed write-lock/lock-write ABBA: | ok | | ok |

    This clearly illustrates the case where lockdep fails to find a
    deadlock.

    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: boqun.feng@gmail.com
    Cc: byungchul.park@lge.com
    Cc: david@fromorbit.com
    Cc: johannes@sipsolutions.net
    Cc: oleg@redhat.com
    Cc: tj@kernel.org
    Signed-off-by: Ingo Molnar

    Peter Zijlstra
     

08 Jun, 2017

2 commits


25 Nov, 2016

1 commit

  • Since the KERN_CONT changes the locking-selftest output is messed up, eg:

    ----------------------------------------------------------------------------
    | spin |wlock |rlock |mutex | wsem | rsem |
    --------------------------------------------------------------------------
    A-A deadlock:
    ok |
    ok |
    ok |
    ok |
    ok |
    ok |

    Use pr_cont() to get it looking normal again:

    ----------------------------------------------------------------------------
    | spin |wlock |rlock |mutex | wsem | rsem |
    --------------------------------------------------------------------------
    A-A deadlock: ok | ok | ok | ok | ok | ok |

    Reported-by: Christian Kujau
    Signed-off-by: Michael Ellerman
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: linuxppc-dev@ozlabs.org
    Link: http://lkml.kernel.org/r/1480027528-934-1-git-send-email-mpe@ellerman.id.au
    Signed-off-by: Ingo Molnar

    Michael Ellerman
     

25 Sep, 2013

1 commit

  • Replace the single preempt_count() 'function' that's an lvalue with
    two proper functions:

    preempt_count() - returns the preempt_count value as rvalue
    preempt_count_set() - Allows setting the preempt-count value

    Also provide preempt_count_ptr() as a convenience wrapper to implement
    all modifying operations.

    Signed-off-by: Peter Zijlstra
    Link: http://lkml.kernel.org/n/tip-orxrbycjozopqfhb4dxdkdvb@git.kernel.org
    [ Fixed build failure. ]
    Signed-off-by: Ingo Molnar

    Peter Zijlstra
     

12 Jul, 2013

1 commit

  • Move the definitions for wound/wait mutexes out to a separate
    header, ww_mutex.h. This reduces clutter in mutex.h, and
    increases readability.

    Suggested-by: Linus Torvalds
    Signed-off-by: Maarten Lankhorst
    Acked-by: Peter Zijlstra
    Acked-by: Rik van Riel
    Acked-by: Maarten Lankhorst
    Cc: Dave Airlie
    Link: http://lkml.kernel.org/r/51D675DC.3000907@canonical.com
    [ Tidied up the code a bit. ]
    Signed-off-by: Ingo Molnar

    Maarten Lankhorst
     

26 Jun, 2013

4 commits

  • When CONFIG_PROVE_LOCKING is not enabled, more tests are
    expected to pass unexpectedly, but there no tests that should
    start to fail that pass with CONFIG_PROVE_LOCKING enabled.

    Signed-off-by: Maarten Lankhorst
    Acked-by: Peter Zijlstra
    Cc: dri-devel@lists.freedesktop.org
    Cc: linaro-mm-sig@lists.linaro.org
    Cc: rostedt@goodmis.org
    Cc: daniel@ffwll.ch
    Cc: Linus Torvalds
    Cc: Andrew Morton
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/20130620113151.4001.77963.stgit@patser
    Signed-off-by: Ingo Molnar

    Maarten Lankhorst
     
  • Signed-off-by: Maarten Lankhorst
    Acked-by: Peter Zijlstra
    Cc: dri-devel@lists.freedesktop.org
    Cc: linaro-mm-sig@lists.linaro.org
    Cc: rostedt@goodmis.org
    Cc: daniel@ffwll.ch
    Cc: Linus Torvalds
    Cc: Andrew Morton
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/20130620113141.4001.54331.stgit@patser
    Signed-off-by: Ingo Molnar

    Maarten Lankhorst
     
  • None of the ww_mutex codepaths should be taken in the 'normal'
    mutex calls. The easiest way to verify this is by using the
    normal mutex calls, and making sure o.ctx is unmodified.

    Signed-off-by: Maarten Lankhorst
    Acked-by: Peter Zijlstra
    Cc: dri-devel@lists.freedesktop.org
    Cc: linaro-mm-sig@lists.linaro.org
    Cc: robclark@gmail.com
    Cc: rostedt@goodmis.org
    Cc: daniel@ffwll.ch
    Cc: Linus Torvalds
    Cc: Andrew Morton
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/20130620113130.4001.45423.stgit@patser
    Signed-off-by: Ingo Molnar

    Maarten Lankhorst
     
  • This stresses the lockdep code in some ways specifically useful
    to ww_mutexes. It adds checks for most of the common locking
    errors.

    Signed-off-by: Maarten Lankhorst
    Acked-by: Peter Zijlstra
    Cc: dri-devel@lists.freedesktop.org
    Cc: linaro-mm-sig@lists.linaro.org
    Cc: robclark@gmail.com
    Cc: rostedt@goodmis.org
    Cc: daniel@ffwll.ch
    Cc: Linus Torvalds
    Cc: Andrew Morton
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/20130620113124.4001.23186.stgit@patser
    Signed-off-by: Ingo Molnar

    Maarten Lankhorst
     

19 Feb, 2013

1 commit

  • To make the lockdep selftest working on RT we need to convert the
    spinlock tests to a raw spinlock. Otherwise we cannot run the irq
    context checks. For mainline this is just annotational as spinlocks
    are mapped to raw_spinlocks anyway.

    Signed-off-by: Yong Zhang
    Link: http://lkml.kernel.org/r/1334559716-18447-2-git-send-email-yong.zhang0@gmail.com
    Signed-off-by: Thomas Gleixner

    Yong Zhang
     

08 Mar, 2012

1 commit


27 May, 2011

1 commit

  • HARDIRQ_ENTER() maps to irq_enter() which calls rcu_irq_enter().
    But HARDIRQ_EXIT() maps to __irq_exit() which doesn't call
    rcu_irq_exit().

    So for every locking selftest that simulates hardirq disabled,
    we create an imbalance in the rcu extended quiescent state
    internal state.

    As a result, after the first missing rcu_irq_exit(), subsequent
    irqs won't exit dyntick-idle mode after leaving the interrupt
    handler. This means that RCU won't see the affected CPU as being
    in an extended quiescent state, resulting in long grace-period
    delays (as in grace periods extending for hours).

    To fix this, just use __irq_enter() to simulate the hardirq
    context. This is sufficient for the locking selftests as we
    don't need to exit any extended quiescent state or perform
    any check that irqs normally do when they wake up from idle.

    As a side effect, this patch makes it possible to restore
    "rcu: Decrease memory-barrier usage based on semi-formal proof",
    which eventually helped finding this bug.

    Reported-and-tested-by: Yinghai Lu
    Signed-off-by: Frederic Weisbecker
    Cc: Paul E. McKenney
    Cc: Ingo Molnar
    Cc: Peter Zijlstra
    Cc: Stable
    Signed-off-by: Paul E. McKenney

    Frederic Weisbecker
     

13 Mar, 2009

1 commit


08 Dec, 2006

1 commit


04 Jul, 2006

3 commits

  • From: Ingo Molnar

    lockdep so far only allowed read-recursion for the same lock instance.
    This is enough in the overwhelming majority of cases, but a hostap case
    triggered and reported by Miles Lane relies on same-class
    different-instance recursion. So we relax the restriction on read-lock
    recursion.

    (This change does not allow rwsem read-recursion, which is still
    forbidden.)

    Signed-off-by: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ingo Molnar
     
  • Do 'make oldconfig' and accept all the defaults for new config options -
    reboot into the kernel and if everything goes well it should boot up fine and
    you should have /proc/lockdep and /proc/lockdep_stats files.

    Typically if the lock validator finds some problem it will print out
    voluminous debug output that begins with "BUG: ..." and which syslog output
    can be used by kernel developers to figure out the precise locking scenario.

    What does the lock validator do? It "observes" and maps all locking rules as
    they occur dynamically (as triggered by the kernel's natural use of spinlocks,
    rwlocks, mutexes and rwsems). Whenever the lock validator subsystem detects a
    new locking scenario, it validates this new rule against the existing set of
    rules. If this new rule is consistent with the existing set of rules then the
    new rule is added transparently and the kernel continues as normal. If the
    new rule could create a deadlock scenario then this condition is printed out.

    When determining validity of locking, all possible "deadlock scenarios" are
    considered: assuming arbitrary number of CPUs, arbitrary irq context and task
    context constellations, running arbitrary combinations of all the existing
    locking scenarios. In a typical system this means millions of separate
    scenarios. This is why we call it a "locking correctness" validator - for all
    rules that are observed the lock validator proves it with mathematical
    certainty that a deadlock could not occur (assuming that the lock validator
    implementation itself is correct and its internal data structures are not
    corrupted by some other kernel subsystem). [see more details and conditionals
    of this statement in include/linux/lockdep.h and
    Documentation/lockdep-design.txt]

    Furthermore, this "all possible scenarios" property of the validator also
    enables the finding of complex, highly unlikely multi-CPU multi-context races
    via single single-context rules, increasing the likelyhood of finding bugs
    drastically. In practical terms: the lock validator already found a bug in
    the upstream kernel that could only occur on systems with 3 or more CPUs, and
    which needed 3 very unlikely code sequences to occur at once on the 3 CPUs.
    That bug was found and reported on a single-CPU system (!). So in essence a
    race will be found "piecemail-wise", triggering all the necessary components
    for the race, without having to reproduce the race scenario itself! In its
    short existence the lock validator found and reported many bugs before they
    actually caused a real deadlock.

    To further increase the efficiency of the validator, the mapping is not per
    "lock instance", but per "lock-class". For example, all struct inode objects
    in the kernel have inode->inotify_mutex. If there are 10,000 inodes cached,
    then there are 10,000 lock objects. But ->inotify_mutex is a single "lock
    type", and all locking activities that occur against ->inotify_mutex are
    "unified" into this single lock-class. The advantage of the lock-class
    approach is that all historical ->inotify_mutex uses are mapped into a single
    (and as narrow as possible) set of locking rules - regardless of how many
    different tasks or inode structures it took to build this set of rules. The
    set of rules persist during the lifetime of the kernel.

    To see the rough magnitude of checking that the lock validator does, here's a
    portion of /proc/lockdep_stats, fresh after bootup:

    lock-classes: 694 [max: 2048]
    direct dependencies: 1598 [max: 8192]
    indirect dependencies: 17896
    all direct dependencies: 16206
    dependency chains: 1910 [max: 8192]
    in-hardirq chains: 17
    in-softirq chains: 105
    in-process chains: 1065
    stack-trace entries: 38761 [max: 131072]
    combined max dependencies: 2033928
    hardirq-safe locks: 24
    hardirq-unsafe locks: 176
    softirq-safe locks: 53
    softirq-unsafe locks: 137
    irq-safe locks: 59
    irq-unsafe locks: 176

    The lock validator has observed 1598 actual single-thread locking patterns,
    and has validated all possible 2033928 distinct locking scenarios.

    More details about the design of the lock validator can be found in
    Documentation/lockdep-design.txt, which can also found at:

    http://redhat.com/~mingo/lockdep-patches/lockdep-design.txt

    [bunk@stusta.de: cleanups]
    Signed-off-by: Ingo Molnar
    Signed-off-by: Arjan van de Ven
    Signed-off-by: Adrian Bunk
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ingo Molnar
     
  • Introduce DEBUG_LOCKING_API_SELFTESTS, which uses the generic lock debugging
    code's silent-failure feature to run a matrix of testcases. There are 210
    testcases currently:

    +-----------------------
    | Locking API testsuite:
    +------------------------------+------+------+------+------+------+------+
    | spin |wlock |rlock |mutex | wsem | rsem |
    -------------------------------+------+------+------+------+------+------+
    A-A deadlock: ok | ok | ok | ok | ok | ok |
    A-B-B-A deadlock: ok | ok | ok | ok | ok | ok |
    A-B-B-C-C-A deadlock: ok | ok | ok | ok | ok | ok |
    A-B-C-A-B-C deadlock: ok | ok | ok | ok | ok | ok |
    A-B-B-C-C-D-D-A deadlock: ok | ok | ok | ok | ok | ok |
    A-B-C-D-B-D-D-A deadlock: ok | ok | ok | ok | ok | ok |
    A-B-C-D-B-C-D-A deadlock: ok | ok | ok | ok | ok | ok |
    double unlock: ok | ok | ok | ok | ok | ok |
    bad unlock order: ok | ok | ok | ok | ok | ok |
    --------------------------------------+------+------+------+------+------+
    recursive read-lock: | ok | | ok |
    --------------------------------------+------+------+------+------+------+
    non-nested unlock: ok | ok | ok | ok |
    --------------------------------------+------+------+------+
    hard-irqs-on + irq-safe-A/12: ok | ok | ok |
    soft-irqs-on + irq-safe-A/12: ok | ok | ok |
    hard-irqs-on + irq-safe-A/21: ok | ok | ok |
    soft-irqs-on + irq-safe-A/21: ok | ok | ok |
    sirq-safe-A => hirqs-on/12: ok | ok | ok |
    sirq-safe-A => hirqs-on/21: ok | ok | ok |
    hard-safe-A + irqs-on/12: ok | ok | ok |
    soft-safe-A + irqs-on/12: ok | ok | ok |
    hard-safe-A + irqs-on/21: ok | ok | ok |
    soft-safe-A + irqs-on/21: ok | ok | ok |
    hard-safe-A + unsafe-B #1/123: ok | ok | ok |
    soft-safe-A + unsafe-B #1/123: ok | ok | ok |
    hard-safe-A + unsafe-B #1/132: ok | ok | ok |
    soft-safe-A + unsafe-B #1/132: ok | ok | ok |
    hard-safe-A + unsafe-B #1/213: ok | ok | ok |
    soft-safe-A + unsafe-B #1/213: ok | ok | ok |
    hard-safe-A + unsafe-B #1/231: ok | ok | ok |
    soft-safe-A + unsafe-B #1/231: ok | ok | ok |
    hard-safe-A + unsafe-B #1/312: ok | ok | ok |
    soft-safe-A + unsafe-B #1/312: ok | ok | ok |
    hard-safe-A + unsafe-B #1/321: ok | ok | ok |
    soft-safe-A + unsafe-B #1/321: ok | ok | ok |
    hard-safe-A + unsafe-B #2/123: ok | ok | ok |
    soft-safe-A + unsafe-B #2/123: ok | ok | ok |
    hard-safe-A + unsafe-B #2/132: ok | ok | ok |
    soft-safe-A + unsafe-B #2/132: ok | ok | ok |
    hard-safe-A + unsafe-B #2/213: ok | ok | ok |
    soft-safe-A + unsafe-B #2/213: ok | ok | ok |
    hard-safe-A + unsafe-B #2/231: ok | ok | ok |
    soft-safe-A + unsafe-B #2/231: ok | ok | ok |
    hard-safe-A + unsafe-B #2/312: ok | ok | ok |
    soft-safe-A + unsafe-B #2/312: ok | ok | ok |
    hard-safe-A + unsafe-B #2/321: ok | ok | ok |
    soft-safe-A + unsafe-B #2/321: ok | ok | ok |
    hard-irq lock-inversion/123: ok | ok | ok |
    soft-irq lock-inversion/123: ok | ok | ok |
    hard-irq lock-inversion/132: ok | ok | ok |
    soft-irq lock-inversion/132: ok | ok | ok |
    hard-irq lock-inversion/213: ok | ok | ok |
    soft-irq lock-inversion/213: ok | ok | ok |
    hard-irq lock-inversion/231: ok | ok | ok |
    soft-irq lock-inversion/231: ok | ok | ok |
    hard-irq lock-inversion/312: ok | ok | ok |
    soft-irq lock-inversion/312: ok | ok | ok |
    hard-irq lock-inversion/321: ok | ok | ok |
    soft-irq lock-inversion/321: ok | ok | ok |
    hard-irq read-recursion/123: ok |
    soft-irq read-recursion/123: ok |
    hard-irq read-recursion/132: ok |
    soft-irq read-recursion/132: ok |
    hard-irq read-recursion/213: ok |
    soft-irq read-recursion/213: ok |
    hard-irq read-recursion/231: ok |
    soft-irq read-recursion/231: ok |
    hard-irq read-recursion/312: ok |
    soft-irq read-recursion/312: ok |
    hard-irq read-recursion/321: ok |
    soft-irq read-recursion/321: ok |
    --------------------------------+-----+----------------
    Good, all 210 testcases passed! |
    --------------------------------+

    Signed-off-by: Ingo Molnar
    Signed-off-by: Arjan van de Ven
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ingo Molnar