Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1362493rdb; Wed, 6 Dec 2023 17:19:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IFmHyIDsaMJqjqlLg12wcjCkDxDytdKCbRMeUFPxlGdsMO1m7Cq9ZmkI7Iu2tF8pJIXTGzg X-Received: by 2002:a17:90a:ca06:b0:286:964d:10d with SMTP id x6-20020a17090aca0600b00286964d010dmr1511122pjt.87.1701911981868; Wed, 06 Dec 2023 17:19:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701911981; cv=none; d=google.com; s=arc-20160816; b=be9sRaVlXr6Ngivvb9cjZzCq0T3OMiSBlI16cyJk0pz4fMwxynnrzTKkpF8YLcpryU FVYea2QUQDmCZvUqKucWTxXOTFYZHzsGw9AZMFHmAkUsv5ywl+/n6mrOJV50A2n9/imS JHVexztl+kxyfqvKgNlqrx+0EIUAtZBjFaVZHei9BZf5bJLJGYQAqQDJxfu7uaHMY1e1 gzhsp2mtOiX4Spddp2fLu4WNjDMocpHwQrAdmxvqTZooADAwJdkzcTqAOCKAL1ao2tII /wbLd+weLHSLmGuR21igdxOZn1mfVL3m0PQr17OBYZxGzEL7IbPVshs/w7D//81UUyOA A7tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=iP54Cr9KwIg5SXZNIJ2CNouxtqfS0z8vptSkYLl8pjs=; fh=Io7x3OacpefNRRNKoYAzVE0aWTDwD7FRzyCdD1e3AN4=; b=QPnJDino7PR2uDijKjX+JUd8o5BIyiHT2g7h93XkdvEAcp0waERtKaSeBwA3tLefK1 KO1tqTER6hVpBAIDupsc2WNQ8T5FlIPs6Ash3cpFSdphuqZFRiZobV3ibMS6mwHM4sNH gprvp/IO7A/wOjhXIMqwcDd25flLk1uMfekfpcQlsc2LO3xWE3FIhev+j2caCjv+5WZN SsQGi+z+agDLd3q+jjjqgCZhJZa9hZfmB2LzCA3Trl+68SwCWk7HRGNffHGxsuTqs13a 9bol7n/u0CLxjm52a78nSax6t1R013iNp7oYR/nHXkK5shI8O19YfszlLCw6EffkBuSJ GYcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=K6Jg92+T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id a2-20020a17090ad80200b002868b9efd49si150927pjv.36.2023.12.06.17.19.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 17:19:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=K6Jg92+T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 290AE81F3238; Wed, 6 Dec 2023 17:19:29 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442017AbjLGBRw (ORCPT + 99 others); Wed, 6 Dec 2023 20:17:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442149AbjLGBRo (ORCPT ); Wed, 6 Dec 2023 20:17:44 -0500 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 5396F10D7 for ; Wed, 6 Dec 2023 17:17:45 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5d8d3271ff5so1698597b3.2 for ; Wed, 06 Dec 2023 17:17:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701911864; x=1702516664; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=iP54Cr9KwIg5SXZNIJ2CNouxtqfS0z8vptSkYLl8pjs=; b=K6Jg92+TTBp3xLM12S1wvjpOrw3T47ou7Idt6HCsWY72f7AFYk1rgmI/UR1CpngO9h ToKjhyCiEUG/IVn8+d5vt+Ft6EWuzvf28XO0RHvhS7+17KvcWRN4Z7lHxNNO9M9b9o0l qiXEYCURU3k1AriVszIjZ5NUjycet2VJgcVKiiEocr/wBGma1BqqjGrs7i1DEkKffGy6 KEpYR7KJ/BTvIA9FMLSZaAZEsiDiFGMDFIsf+71oVXispU1+oiCqluORaz+6xhSoTLoK W5ZBiC7zMzW00JtmXjNtXbeSkU4z+08EggXIA6w2WYNMBOhaS//6+irw/ONm13F9L8eJ c4gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701911864; x=1702516664; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iP54Cr9KwIg5SXZNIJ2CNouxtqfS0z8vptSkYLl8pjs=; b=KwTjdb0yKhtn1uCf+0OA7OUiuXKNCVtO0eY1nix43shUXz742druJAduJFottSnGbZ aVwQlH+5TtJL1NaBisOYUaKjqLC32FZP0AScZVAmAcU+iIsZO+px017TE1qMZuszjV1e PU47JLjkgMSGakJbOmJfNEAReY7jabRdhn7QGi7X/Ge/YYWVk5IQ374O2QA5PM337YoZ k1MBToDl6o+qBpV0rGyNSIaf1/gTpV0+vr4ld1Jum9qGYlVs0D3xS8/XY6IOfFSSuYjE pugIUfEeBg7VLzOPix0N9Fm7sO/swAuMxsQxaxcdDuZFO66f2ZQLtFPpI1W1d4lLo8aT BP0g== X-Gm-Message-State: AOJu0YzmtUUY1oJIeklIdnregu5aOLZqq2CUeTl7dCe1f8xLZGALaQ9D HIluqosJHL34pem7g/QQoZtqU8BnkOUG X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:35bf:293e:7696:34e9]) (user=irogers job=sendgmr) by 2002:a81:ad24:0:b0:5d9:20ac:5126 with SMTP id l36-20020a81ad24000000b005d920ac5126mr26328ywh.4.1701911864205; Wed, 06 Dec 2023 17:17:44 -0800 (PST) Date: Wed, 6 Dec 2023 17:16:41 -0800 In-Reply-To: <20231207011722.1220634-1-irogers@google.com> Message-Id: <20231207011722.1220634-8-irogers@google.com> Mime-Version: 1.0 References: <20231207011722.1220634-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog Subject: [PATCH v6 07/47] perf probe-event: Use function to add missing maps lock From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Nick Terrell , Kan Liang , Andi Kleen , Kajol Jain , Athira Rajeev , Huacai Chen , Masami Hiramatsu , Vincent Whitchurch , "Steinar H. Gunderson" , Liam Howlett , Miguel Ojeda , Colin Ian King , Dmitrii Dolgov <9erthalion6@gmail.com>, Yang Jihong , Ming Wang , James Clark , K Prateek Nayak , Sean Christopherson , Leo Yan , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Li Dong , Sandipan Das , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Guilherme Amadio Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 06 Dec 2023 17:19:29 -0800 (PST) Switch kernel_get_module_map from loop macro maps__for_each_entry to maps__for_each_map function that takes a callback. The function holds the maps lock, which should be held during iteration. Signed-off-by: Ian Rogers --- tools/perf/util/probe-event.c | 40 +++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 1a5b7fa459b2..a1a796043691 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -149,10 +149,32 @@ static int kernel_get_symbol_address_by_name(const char *name, u64 *addr, return 0; } +struct kernel_get_module_map_cb_args { + const char *module; + struct map *result; +}; + +static int kernel_get_module_map_cb(struct map *map, void *data) +{ + struct kernel_get_module_map_cb_args *args = data; + struct dso *dso = map__dso(map); + const char *short_name = dso->short_name; /* short_name is "[module]" */ + u16 short_name_len = dso->short_name_len; + + if (strncmp(short_name + 1, args->module, short_name_len - 2) == 0 && + args->module[short_name_len - 2] == '\0') { + args->result = map__get(map); + return 1; + } + return 0; +} + static struct map *kernel_get_module_map(const char *module) { - struct maps *maps = machine__kernel_maps(host_machine); - struct map_rb_node *pos; + struct kernel_get_module_map_cb_args args = { + .module = module, + .result = NULL, + }; /* A file path -- this is an offline module */ if (module && strchr(module, '/')) @@ -164,19 +186,9 @@ static struct map *kernel_get_module_map(const char *module) return map__get(map); } - maps__for_each_entry(maps, pos) { - /* short_name is "[module]" */ - struct dso *dso = map__dso(pos->map); - const char *short_name = dso->short_name; - u16 short_name_len = dso->short_name_len; + maps__for_each_map(machine__kernel_maps(host_machine), kernel_get_module_map_cb, &args); - if (strncmp(short_name + 1, module, - short_name_len - 2) == 0 && - module[short_name_len - 2] == '\0') { - return map__get(pos->map); - } - } - return NULL; + return args.result; } struct map *get_target_map(const char *target, struct nsinfo *nsi, bool user) -- 2.43.0.rc2.451.g8631bc7472-goog