mbox series

[v3,00/18] Mutex wrapper, locking and memory leak fixes

Message ID 20220824153901.488576-1-irogers@google.com (mailing list archive)
Headers show
Series Mutex wrapper, locking and memory leak fixes | expand

Message

Ian Rogers Aug. 24, 2022, 3:38 p.m. UTC
When fixing a locking race and memory leak in:
https://lore.kernel.org/linux-perf-users/20211118193714.2293728-1-irogers@google.com/

It was requested that debug mutex code be separated out into its own
files. This was, in part, done by Pavithra Gurushankar in:
https://lore.kernel.org/lkml/20220727111954.105118-1-gpavithrasha@gmail.com/

These patches fix issues with the previous patches, add in the
original dso->nsinfo fix and then build on our mutex wrapper with
clang's -Wthread-safety analysis. The analysis found missing unlocks
in builtin-sched.c which are fixed and -Wthread-safety is enabled by
default when building with clang.

v3. Adds a missing new line to the error messages and removes the
    pshared argument to mutex_init by having two functions, mutex_init
    and mutex_init_pshared. These changes were suggested by Adrian Hunter.
v2. Breaks apart changes that s/pthread_mutex/mutex/g and the lock
    annotations as requested by Arnaldo and Namhyung. A boolean is
    added to builtin-sched.c to terminate thread funcs rather than
    leaving them blocked on delted mutexes.

Ian Rogers (17):
  perf bench: Update use of pthread mutex/cond
  perf tests: Avoid pthread.h inclusion
  perf hist: Update use of pthread mutex
  perf bpf: Remove unused pthread.h include
  perf lock: Remove unused pthread.h include
  perf record: Update use of pthread mutex
  perf sched: Update use of pthread mutex
  perf ui: Update use of pthread mutex
  perf mmap: Remove unnecessary pthread.h include
  perf dso: Update use of pthread mutex
  perf annotate: Update use of pthread mutex
  perf top: Update use of pthread mutex
  perf dso: Hold lock when accessing nsinfo
  perf mutex: Add thread safety annotations
  perf sched: Fixes for thread safety analysis
  perf top: Fixes for thread safety analysis
  perf build: Enable -Wthread-safety with clang

Pavithra Gurushankar (1):
  perf mutex: Wrapped usage of mutex and cond

 tools/perf/Makefile.config                 |   5 +
 tools/perf/bench/epoll-ctl.c               |  33 +++---
 tools/perf/bench/epoll-wait.c              |  33 +++---
 tools/perf/bench/futex-hash.c              |  33 +++---
 tools/perf/bench/futex-lock-pi.c           |  33 +++---
 tools/perf/bench/futex-requeue.c           |  33 +++---
 tools/perf/bench/futex-wake-parallel.c     |  33 +++---
 tools/perf/bench/futex-wake.c              |  33 +++---
 tools/perf/bench/numa.c                    |  93 ++++++----------
 tools/perf/builtin-inject.c                |   4 +
 tools/perf/builtin-lock.c                  |   1 -
 tools/perf/builtin-record.c                |  13 ++-
 tools/perf/builtin-sched.c                 | 105 +++++++++---------
 tools/perf/builtin-top.c                   |  45 ++++----
 tools/perf/tests/mmap-basic.c              |   2 -
 tools/perf/tests/openat-syscall-all-cpus.c |   2 +-
 tools/perf/tests/perf-record.c             |   2 -
 tools/perf/ui/browser.c                    |  20 ++--
 tools/perf/ui/browsers/annotate.c          |  12 +--
 tools/perf/ui/setup.c                      |   5 +-
 tools/perf/ui/tui/helpline.c               |   5 +-
 tools/perf/ui/tui/progress.c               |   8 +-
 tools/perf/ui/tui/setup.c                  |   8 +-
 tools/perf/ui/tui/util.c                   |  18 ++--
 tools/perf/ui/ui.h                         |   4 +-
 tools/perf/util/Build                      |   1 +
 tools/perf/util/annotate.c                 |  15 +--
 tools/perf/util/annotate.h                 |   4 +-
 tools/perf/util/bpf-event.h                |   1 -
 tools/perf/util/build-id.c                 |  12 ++-
 tools/perf/util/dso.c                      |  19 ++--
 tools/perf/util/dso.h                      |   4 +-
 tools/perf/util/hist.c                     |   6 +-
 tools/perf/util/hist.h                     |   4 +-
 tools/perf/util/map.c                      |   3 +
 tools/perf/util/mmap.h                     |   1 -
 tools/perf/util/mutex.c                    | 119 +++++++++++++++++++++
 tools/perf/util/mutex.h                    | 109 +++++++++++++++++++
 tools/perf/util/probe-event.c              |   3 +
 tools/perf/util/symbol.c                   |   4 +-
 tools/perf/util/top.h                      |   5 +-
 41 files changed, 570 insertions(+), 323 deletions(-)
 create mode 100644 tools/perf/util/mutex.c
 create mode 100644 tools/perf/util/mutex.h

Comments

Adrian Hunter Aug. 25, 2022, 4:14 p.m. UTC | #1
On 25/08/22 15:30, Arnaldo Carvalho de Melo wrote:
> On Wed, Aug 24, 2022, 12:39 PM Ian Rogers <irogers@google.com <mailto:irogers@google.com>> wrote:
> 
>     When fixing a locking race and memory leak in:
>     https://lore.kernel.org/linux-perf-users/20211118193714.2293728-1-irogers@google.com/ <https://lore.kernel.org/linux-perf-users/20211118193714.2293728-1-irogers@google.com/>
> 
>     It was requested that debug mutex code be separated out into its own
>     files. This was, in part, done by Pavithra Gurushankar in:
>     https://lore.kernel.org/lkml/20220727111954.105118-1-gpavithrasha@gmail.com/ <https://lore.kernel.org/lkml/20220727111954.105118-1-gpavithrasha@gmail.com/>
> 
>     These patches fix issues with the previous patches, add in the
>     original dso->nsinfo fix and then build on our mutex wrapper with
>     clang's -Wthread-safety analysis. The analysis found missing unlocks
>     in builtin-sched.c which are fixed and -Wthread-safety is enabled by
>     default when building with clang.
> 
>     v3. Adds a missing new line to the error messages and removes the
>         pshared argument to mutex_init by having two functions, mutex_init
>         and mutex_init_pshared. These changes were suggested by Adrian Hunter.
> 
> 
> Adrian, can I have your Acked-by or, better, Reviewed-by?

Sure, just let me have another look.  Should get to it
tomorrow.

> 
> Thanks, 
> 
> -  Arnaldo 
> 
>     v2. Breaks apart changes that s/pthread_mutex/mutex/g and the lock
>         annotations as requested by Arnaldo and Namhyung. A boolean is
>         added to builtin-sched.c to terminate thread funcs rather than
>         leaving them blocked on delted mutexes.
> 
>     Ian Rogers (17):
>       perf bench: Update use of pthread mutex/cond
>       perf tests: Avoid pthread.h inclusion
>       perf hist: Update use of pthread mutex
>       perf bpf: Remove unused pthread.h include
>       perf lock: Remove unused pthread.h include
>       perf record: Update use of pthread mutex
>       perf sched: Update use of pthread mutex
>       perf ui: Update use of pthread mutex
>       perf mmap: Remove unnecessary pthread.h include
>       perf dso: Update use of pthread mutex
>       perf annotate: Update use of pthread mutex
>       perf top: Update use of pthread mutex
>       perf dso: Hold lock when accessing nsinfo
>       perf mutex: Add thread safety annotations
>       perf sched: Fixes for thread safety analysis
>       perf top: Fixes for thread safety analysis
>       perf build: Enable -Wthread-safety with clang
> 
>     Pavithra Gurushankar (1):
>       perf mutex: Wrapped usage of mutex and cond
> 
>      tools/perf/Makefile.config                 |   5 +
>      tools/perf/bench/epoll-ctl.c               |  33 +++---
>      tools/perf/bench/epoll-wait.c              |  33 +++---
>      tools/perf/bench/futex-hash.c              |  33 +++---
>      tools/perf/bench/futex-lock-pi.c           |  33 +++---
>      tools/perf/bench/futex-requeue.c           |  33 +++---
>      tools/perf/bench/futex-wake-parallel.c     |  33 +++---
>      tools/perf/bench/futex-wake.c              |  33 +++---
>      tools/perf/bench/numa.c                    |  93 ++++++----------
>      tools/perf/builtin-inject.c                |   4 +
>      tools/perf/builtin-lock.c                  |   1 -
>      tools/perf/builtin-record.c                |  13 ++-
>      tools/perf/builtin-sched.c                 | 105 +++++++++---------
>      tools/perf/builtin-top.c                   |  45 ++++----
>      tools/perf/tests/mmap-basic.c              |   2 -
>      tools/perf/tests/openat-syscall-all-cpus.c |   2 +-
>      tools/perf/tests/perf-record.c             |   2 -
>      tools/perf/ui/browser.c                    |  20 ++--
>      tools/perf/ui/browsers/annotate.c          |  12 +--
>      tools/perf/ui/setup.c                      |   5 +-
>      tools/perf/ui/tui/helpline.c               |   5 +-
>      tools/perf/ui/tui/progress.c               |   8 +-
>      tools/perf/ui/tui/setup.c                  |   8 +-
>      tools/perf/ui/tui/util.c                   |  18 ++--
>      tools/perf/ui/ui.h                         |   4 +-
>      tools/perf/util/Build                      |   1 +
>      tools/perf/util/annotate.c                 |  15 +--
>      tools/perf/util/annotate.h                 |   4 +-
>      tools/perf/util/bpf-event.h                |   1 -
>      tools/perf/util/build-id.c                 |  12 ++-
>      tools/perf/util/dso.c                      |  19 ++--
>      tools/perf/util/dso.h                      |   4 +-
>      tools/perf/util/hist.c                     |   6 +-
>      tools/perf/util/hist.h                     |   4 +-
>      tools/perf/util/map.c                      |   3 +
>      tools/perf/util/mmap.h                     |   1 -
>      tools/perf/util/mutex.c                    | 119 +++++++++++++++++++++
>      tools/perf/util/mutex.h                    | 109 +++++++++++++++++++
>      tools/perf/util/probe-event.c              |   3 +
>      tools/perf/util/symbol.c                   |   4 +-
>      tools/perf/util/top.h                      |   5 +-
>      41 files changed, 570 insertions(+), 323 deletions(-)
>      create mode 100644 tools/perf/util/mutex.c
>      create mode 100644 tools/perf/util/mutex.h
> 
>     -- 
>     2.37.2.609.g9ff673ca1a-goog
>
Adrian Hunter Aug. 26, 2022, 12:36 p.m. UTC | #2
On 25/08/22 19:14, Adrian Hunter wrote:
> On 25/08/22 15:30, Arnaldo Carvalho de Melo wrote:
>> On Wed, Aug 24, 2022, 12:39 PM Ian Rogers <irogers@google.com <mailto:irogers@google.com>> wrote:
>>
>>     When fixing a locking race and memory leak in:
>>     https://lore.kernel.org/linux-perf-users/20211118193714.2293728-1-irogers@google.com/ <https://lore.kernel.org/linux-perf-users/20211118193714.2293728-1-irogers@google.com/>
>>
>>     It was requested that debug mutex code be separated out into its own
>>     files. This was, in part, done by Pavithra Gurushankar in:
>>     https://lore.kernel.org/lkml/20220727111954.105118-1-gpavithrasha@gmail.com/ <https://lore.kernel.org/lkml/20220727111954.105118-1-gpavithrasha@gmail.com/>
>>
>>     These patches fix issues with the previous patches, add in the
>>     original dso->nsinfo fix and then build on our mutex wrapper with
>>     clang's -Wthread-safety analysis. The analysis found missing unlocks
>>     in builtin-sched.c which are fixed and -Wthread-safety is enabled by
>>     default when building with clang.
>>
>>     v3. Adds a missing new line to the error messages and removes the
>>         pshared argument to mutex_init by having two functions, mutex_init
>>         and mutex_init_pshared. These changes were suggested by Adrian Hunter.
>>
>>
>> Adrian, can I have your Acked-by or, better, Reviewed-by?
> 
> Sure, just let me have another look.  Should get to it
> tomorrow.

Looks good but a couple of things that need to be fixed up.

> 
>>
>> Thanks, 
>>
>> -  Arnaldo 
>>
>>     v2. Breaks apart changes that s/pthread_mutex/mutex/g and the lock
>>         annotations as requested by Arnaldo and Namhyung. A boolean is
>>         added to builtin-sched.c to terminate thread funcs rather than
>>         leaving them blocked on delted mutexes.
>>
>>     Ian Rogers (17):
>>       perf bench: Update use of pthread mutex/cond
>>       perf tests: Avoid pthread.h inclusion
>>       perf hist: Update use of pthread mutex
>>       perf bpf: Remove unused pthread.h include
>>       perf lock: Remove unused pthread.h include
>>       perf record: Update use of pthread mutex
>>       perf sched: Update use of pthread mutex
>>       perf ui: Update use of pthread mutex
>>       perf mmap: Remove unnecessary pthread.h include
>>       perf dso: Update use of pthread mutex
>>       perf annotate: Update use of pthread mutex
>>       perf top: Update use of pthread mutex
>>       perf dso: Hold lock when accessing nsinfo
>>       perf mutex: Add thread safety annotations
>>       perf sched: Fixes for thread safety analysis
>>       perf top: Fixes for thread safety analysis
>>       perf build: Enable -Wthread-safety with clang
>>
>>     Pavithra Gurushankar (1):
>>       perf mutex: Wrapped usage of mutex and cond
>>
>>      tools/perf/Makefile.config                 |   5 +
>>      tools/perf/bench/epoll-ctl.c               |  33 +++---
>>      tools/perf/bench/epoll-wait.c              |  33 +++---
>>      tools/perf/bench/futex-hash.c              |  33 +++---
>>      tools/perf/bench/futex-lock-pi.c           |  33 +++---
>>      tools/perf/bench/futex-requeue.c           |  33 +++---
>>      tools/perf/bench/futex-wake-parallel.c     |  33 +++---
>>      tools/perf/bench/futex-wake.c              |  33 +++---
>>      tools/perf/bench/numa.c                    |  93 ++++++----------
>>      tools/perf/builtin-inject.c                |   4 +
>>      tools/perf/builtin-lock.c                  |   1 -
>>      tools/perf/builtin-record.c                |  13 ++-
>>      tools/perf/builtin-sched.c                 | 105 +++++++++---------
>>      tools/perf/builtin-top.c                   |  45 ++++----
>>      tools/perf/tests/mmap-basic.c              |   2 -
>>      tools/perf/tests/openat-syscall-all-cpus.c |   2 +-
>>      tools/perf/tests/perf-record.c             |   2 -
>>      tools/perf/ui/browser.c                    |  20 ++--
>>      tools/perf/ui/browsers/annotate.c          |  12 +--
>>      tools/perf/ui/setup.c                      |   5 +-
>>      tools/perf/ui/tui/helpline.c               |   5 +-
>>      tools/perf/ui/tui/progress.c               |   8 +-
>>      tools/perf/ui/tui/setup.c                  |   8 +-
>>      tools/perf/ui/tui/util.c                   |  18 ++--
>>      tools/perf/ui/ui.h                         |   4 +-
>>      tools/perf/util/Build                      |   1 +
>>      tools/perf/util/annotate.c                 |  15 +--
>>      tools/perf/util/annotate.h                 |   4 +-
>>      tools/perf/util/bpf-event.h                |   1 -
>>      tools/perf/util/build-id.c                 |  12 ++-
>>      tools/perf/util/dso.c                      |  19 ++--
>>      tools/perf/util/dso.h                      |   4 +-
>>      tools/perf/util/hist.c                     |   6 +-
>>      tools/perf/util/hist.h                     |   4 +-
>>      tools/perf/util/map.c                      |   3 +
>>      tools/perf/util/mmap.h                     |   1 -
>>      tools/perf/util/mutex.c                    | 119 +++++++++++++++++++++
>>      tools/perf/util/mutex.h                    | 109 +++++++++++++++++++
>>      tools/perf/util/probe-event.c              |   3 +
>>      tools/perf/util/symbol.c                   |   4 +-
>>      tools/perf/util/top.h                      |   5 +-
>>      41 files changed, 570 insertions(+), 323 deletions(-)
>>      create mode 100644 tools/perf/util/mutex.c
>>      create mode 100644 tools/perf/util/mutex.h
>>
>>     -- 
>>     2.37.2.609.g9ff673ca1a-goog
>>
>