From mboxrd@z Thu Jan 1 00:00:00 1970 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 6992DC433F5 for ; Tue, 25 Jan 2022 20:47:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232538AbiAYUqt (ORCPT ); Tue, 25 Jan 2022 15:46:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232465AbiAYUqN (ORCPT ); Tue, 25 Jan 2022 15:46:13 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1B6AC06174E for ; Tue, 25 Jan 2022 12:46:12 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id z15-20020a25bb0f000000b00613388c7d99so43863686ybg.8 for ; Tue, 25 Jan 2022 12:46:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=100W4F2SZe3IWptV5RcjIMfgKhxT7aMM0DwnzM2uSwI=; b=AtZRyMJoLmRfImn6GijY+LOfXNuW5R979dWq2WEKkjVF5oC8JztYwcYuD2rH/cYe0p xiYe8ye9PRjpjWl5ItXl+LHdIwsUlUI5120zvJJsZuykYVj1PrfN1GGKtBQ8RcRSfMZq +SOGEc2PV7Wz4dtW5kXTrLPa68rmovr5r4PPcZAHxAYJ0Nd3OcCdvmcFQka3qp3oJBAO RVrxhaRUw4oDWPeJJbj3xxN/7NmqykbwzQwqsaKz79O5kFiAcLAEcHBHnb8cWj1MZVFW FHYtiMjMxghS6EkcvScsLJrBfT5C2ub634yFZs7q7Aq5RV4ZAZpWYfwq1gqr+ZjVinaA l4mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=100W4F2SZe3IWptV5RcjIMfgKhxT7aMM0DwnzM2uSwI=; b=4ylLRcYb7oTap6tQVJzFvhNWJ7qB79C+sbz+la/Rqs0nOhfJV0sMgxIuxVukKqrhjG 0z5HrlDqo7JB87yZUnCJV2zTQpW5/nHonOp70IMLgseyOssFcBTaFcjoY/L4XMcw03xE 6fsKW0AciY7AUET0osIKp/LZWTFw7Rh4Irs+uyTJxAod8NjPq65FCNC7IpwHZdIHrBoR XmetDRy3Ruq5IvM6L9wlBkN/gPqC7a5V5n1rj6dPknGNPyuRJiUNea69nJ3+Vi00hDFr 09sAwUvfN+nBODGFyu7eZ5Hw0UWs9utnQEbGsvq38fQrdImBL3/JdE/Sxl4hbW8uLjot 31jQ== X-Gm-Message-State: AOAM533fbmvyLyLdd27fhcyVG+VmQrdpCCbnRMLayvYAH9tKuE5qSDhi wSxUPPWRhabciEkk71Rml9REAoCD5gNm X-Google-Smtp-Source: ABdhPJz2AIIoZgVx9s5C8xIPQXRhGrzFQOIyFCz9l/0X/Qe4+Z88KgE1Z4u1cAGgzmMAEZwt+iZ+joHSwBBP X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:1a99:924a:8878:c44a]) (user=irogers job=sendgmr) by 2002:a25:a102:: with SMTP id z2mr32541998ybh.100.1643143572035; Tue, 25 Jan 2022 12:46:12 -0800 (PST) Date: Tue, 25 Jan 2022 12:46:00 -0800 In-Reply-To: <20220125204602.4137477-1-irogers@google.com> Message-Id: <20220125204602.4137477-3-irogers@google.com> Mime-Version: 1.0 References: <20220125204602.4137477-1-irogers@google.com> X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog Subject: [PATCH v2 2/4] perf dso: Make lock error check and add BUG_ONs 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?=" , James Clark , John Garry , Riccardo Mancini , Yury Norov , Andy Shevchenko , Andrew Morton , Jin Yao , Adrian Hunter , Leo Yan , Andi Kleen , Thomas Richter , Kan Liang , Madhavan Srinivasan , Shunsuke Nakamura , Song Liu , Masami Hiramatsu , Steven Rostedt , Miaoqian Lin , Stephen Brennan , Kajol Jain , Alexey Bayduraev , German Gomez , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Dumazet , Dmitry Vyukov Cc: eranian@google.com, Ian Rogers Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.org Make the pthread mutex on dso use the error check type. This allows deadlock checking via the return type. Assert the returned value from mutex lock is always 0. Signed-off-by: Ian Rogers --- tools/perf/util/dso.c | 12 +++++++++--- tools/perf/util/symbol.c | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 9cc8a1772b4b..6beccffeef7b 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -784,7 +784,7 @@ dso_cache__free(struct dso *dso) struct rb_root *root = &dso->data.cache; struct rb_node *next = rb_first(root); - pthread_mutex_lock(&dso->lock); + BUG_ON(pthread_mutex_lock(&dso->lock) != 0); while (next) { struct dso_cache *cache; @@ -830,7 +830,7 @@ dso_cache__insert(struct dso *dso, struct dso_cache *new) struct dso_cache *cache; u64 offset = new->offset; - pthread_mutex_lock(&dso->lock); + BUG_ON(pthread_mutex_lock(&dso->lock) != 0); while (*p != NULL) { u64 end; @@ -1259,6 +1259,8 @@ struct dso *dso__new_id(const char *name, struct dso_id *id) struct dso *dso = calloc(1, sizeof(*dso) + strlen(name) + 1); if (dso != NULL) { + pthread_mutexattr_t lock_attr; + strcpy(dso->name, name); if (id) dso->id = *id; @@ -1286,8 +1288,12 @@ struct dso *dso__new_id(const char *name, struct dso_id *id) dso->root = NULL; INIT_LIST_HEAD(&dso->node); INIT_LIST_HEAD(&dso->data.open_entry); - pthread_mutex_init(&dso->lock, NULL); + pthread_mutexattr_init(&lock_attr); + pthread_mutexattr_settype(&lock_attr, PTHREAD_MUTEX_ERRORCHECK); + pthread_mutex_init(&dso->lock, &lock_attr); + pthread_mutexattr_destroy(&lock_attr); refcount_set(&dso->refcnt, 1); + } return dso; diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index b2ed3140a1fa..43f47532696f 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -1783,7 +1783,7 @@ int dso__load(struct dso *dso, struct map *map) } nsinfo__mountns_enter(dso->nsinfo, &nsc); - pthread_mutex_lock(&dso->lock); + BUG_ON(pthread_mutex_lock(&dso->lock) != 0); /* check again under the dso->lock */ if (dso__loaded(dso)) { -- 2.35.0.rc0.227.g00780c9af4-goog