Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD8EC4401 for ; Fri, 26 Aug 2022 16:40:41 +0000 (UTC) Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-31f5960500bso33172167b3.14 for ; Fri, 26 Aug 2022 09:40:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc; bh=x7OCRh/WujRFV4WEHTN0aVfGYVTj+gZ5+QGOawN0UMQ=; b=SNMgfiuxecw2Mr6TA0q7y8uPZF3KtVNwELB22w+RnG5cpZ7Lpmb6hS4TesLt8RM54i sH2ZHH8ekSX5Au2x4wH+4n/IPcNqdkqnuKFL45JCCwJZ6s1wUnUO9skzzcHPX7NOW/rO jDRt5EWg5AJfbIrePjkoQJqcokGlOfpt2/iATWBdE/ESOzEXFTvOJEaw1a/TclcUZIuN iX90tCdmmvleaQWzFD7tXw2DlfPqYpjvOxcUFlHTwcIqBq0MphCcc55Lni0i0kVAUlVf 9y5Zkb141Lv3+QpIvukmcJKuV3lgFJXUzUqu7OTsxdaHqyggwR0R4x4SW06fTTpU8MnV RLRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc; bh=x7OCRh/WujRFV4WEHTN0aVfGYVTj+gZ5+QGOawN0UMQ=; b=xGsrKQypB74pusGGYmnnQPxgBS6PXxrEm8j6GOsIvOK8GgnpWjGP/PZQSJeMoutSxN APCOJxkmR/y64yC2kLcLECGwNgkBDTbZIk+r1HI9Y4dPprq+OuBsSAou/Vv4gpBhDMjV T+x5AfRgJCTAKsvI/gXmQTNKCJ1Zv7r/4oTMqxZyAzxMRy7bQ4YIpnirv/MnED+G1wiR j1DwlHTZuNThO018GNy0s2oUpPlwJ8HVJihIgHYmU6VFcjOv83tbf1qTeVJGidle5aX3 00DUO1xme2cyXZXvOseFNBzJ+y2RqurevM2i+MdRsFfSe3nIg9i1Ulc8zxwMR8RZqRIk /8QA== X-Gm-Message-State: ACgBeo2dcChT9QvZbp5C6bHWngIZ3uz3cg1cDb0fyzAcHUmoeg708Xll Dr5DeRpKbYBLQXFqJowJPZqufB8SZ2Av X-Google-Smtp-Source: AA6agR4eO4PXcKlrllCSwczRZAsAEuS5W9eDVC8xKxGrtreEufZRgpHi5uaPnW8bZ1fF0ROtDj8dA8lTrrbt X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ccb1:c46b:7044:2508]) (user=irogers job=sendgmr) by 2002:a25:53c7:0:b0:695:6af4:a5ed with SMTP id h190-20020a2553c7000000b006956af4a5edmr499951ybb.472.1661532040380; Fri, 26 Aug 2022 09:40:40 -0700 (PDT) Date: Fri, 26 Aug 2022 09:40:09 -0700 Message-Id: <20220826164027.42929-1-irogers@google.com> Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 00/18] Mutex wrapper, locking and memory leak fixes From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Weiguo Li , Athira Rajeev , Thomas Richter , Ravi Bangoria , Dario Petrillo , Hewenliang , yaowenbin , Wenyu Liu , Song Liu , Andrii Nakryiko , Dave Marchevsky , Leo Yan , Kim Phillips , Pavithra Gurushankar , Alexandre Truong , Quentin Monnet , William Cohen , Andres Freund , Adrian Hunter , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Colin Ian King , James Clark , Fangrui Song , Stephane Eranian , Kajol Jain , Alexey Bayduraev , Riccardo Mancini , Andi Kleen , Masami Hiramatsu , Zechuan Chen , Jason Wang , Christophe JAILLET , Remi Bernon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers Content-Type: text/plain; charset="UTF-8" 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. v4. Adds a comment for the trylock result, fixes the new line (missed in v3) and removes two blank lines as suggested by Adrian Hunter. 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 | 108 +++++++++++++++++++ tools/perf/util/probe-event.c | 3 + tools/perf/util/symbol.c | 4 +- tools/perf/util/top.h | 5 +- 41 files changed, 569 insertions(+), 323 deletions(-) create mode 100644 tools/perf/util/mutex.c create mode 100644 tools/perf/util/mutex.h -- 2.37.2.672.g94769d06f0-goog