From patchwork Wed Aug 24 15:38:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12953744 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D524EC00140 for ; Wed, 24 Aug 2022 15:39:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238474AbiHXPj2 (ORCPT ); Wed, 24 Aug 2022 11:39:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238454AbiHXPjX (ORCPT ); Wed, 24 Aug 2022 11:39:23 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E51D7F092 for ; Wed, 24 Aug 2022 08:39:22 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-32a115757b6so299894327b3.13 for ; Wed, 24 Aug 2022 08:39:22 -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=xAbfQkbFPDellsaKp24mP9oyoxp7QvISDP34HXAcivU=; b=a2wk7yyHwGIg9lpsjrMBoXBGmUTlnW3gqtujQyK+BxMa4n/0WuJoDBekFkKWNwvK4o YphYU74NwhOc59R6BKbI+akTqgq0EdXZPQUd5+TGk8VmuGjlO/KTXNWYE9ljIAhqa+Wz w8fHpWGql8hcPAnnhaXPcmM8CWtbl+D5qMz39Ci8/FTDJplXmDJHSDS+Es9sjlFBLQWb QshTju5UfzeXpDaT5s8LswU6rfaSr+bOOTR8PRhxJKErIRE9nImFDlfngNpIAp+LzH+V cgnGRMxA+vi7div/DMiNovUVS0skrPaODNSFqGHlnHcB7Q2TztN+RYmC5XHoxT3N11hH GuFw== 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=xAbfQkbFPDellsaKp24mP9oyoxp7QvISDP34HXAcivU=; b=kcBQ/obQgCXgZoWqYNLOX6WQO7m+z18QjxLJUDyGam7GPru0Y8dyCNBIqBS8LHLqCm oIePYndt4xwPsz95/eK1ZrvevC3yb6/BMuIlSMY47fAs6dJkZ4kFGlsSLHoIj2BKCqS/ N2fApdtlIr6LBHhwo+xrlsBkjkVAEAaon9m8Sf75nw1XkbG4iHiaFe+8qQf2WsvD2OIq xyhsv27w9DjdM8ssrM3eYfWiWzZO/l+JdDHn4DF+yWb7ivv9HV9QySTl5xsbFDkCJKao Xq0yzeJ4pOpy47vOozVBxuup+TmBLWXVmHlmk4FV5RmUDXa+nsbyXpvpzzTK5dnfgbQE 9Xhw== X-Gm-Message-State: ACgBeo2UyCqmuMVEEqH0IEV6NA40G4dnP55JSQRD4kp1wHV3XfgaFQri nbdOQVNY0urwoS43YIL3PV+7KkEKyF5A X-Google-Smtp-Source: AA6agR7vrZdDjak13qWKrwy63oS2Xh/EMZv6mckisVInWYa9XhxM8MDPH8MwW5A/nm6WBQKRBgBP3E7h3TuG X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:ab82:a348:500d:1fc4]) (user=irogers job=sendgmr) by 2002:a25:3285:0:b0:690:aa8c:2a55 with SMTP id y127-20020a253285000000b00690aa8c2a55mr30341747yby.255.1661355561255; Wed, 24 Aug 2022 08:39:21 -0700 (PDT) Date: Wed, 24 Aug 2022 08:38:43 -0700 Message-Id: <20220824153901.488576-1-irogers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.37.2.609.g9ff673ca1a-goog Subject: [PATCH v3 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_Almeida?= " , 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_Li=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 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org 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