From patchwork Thu Dec 7 01:16:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 174835 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4487773vqy; Wed, 6 Dec 2023 17:18:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IG1C0GPxuCNTnslrbqFXSJozFM9k1XkfhJX0oq5P+y8HBkeONlal/Im5XO94X7Aj2Nb2GW7 X-Received: by 2002:a05:6a21:3714:b0:190:230:8ea2 with SMTP id yl20-20020a056a21371400b0019002308ea2mr235905pzb.62.1701911935665; Wed, 06 Dec 2023 17:18:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701911935; cv=none; d=google.com; s=arc-20160816; b=m3UqvR14A0TLA/V+sN+x6/iwitHVEO/MctbtGnV/wqpdnk+kcY+7HKLjNs/MT1Q+A2 4RlxBK/2eOHODlI4+ATEWCSRedyjkpCRzjgf+Rx7nB7NMp4L2IqcKhHj718f0p+XPlzG 2udXM+lMhm1aqVYXKtnn1jydqvoAbn2Y6xyu0UHRu4z8uQH1wwj/DOY56drnMhNXvNTM 8ypYwQq/F6CKm5M2gmPpLIRVKN6JGkehS6LuRya0GhCjuTj/9gDKyUJ8q90cEmRfZC/u Vh2Jnh0jkuhcAF8KFuVwQqcaVoqp3uq7acPNuwVtLcSLCS6zCD61HUVt044eOiBROJiZ c8SA== 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=/sHbkqXu1fUVSCDOGBtyBTb/TcjN5e6RYI3KdCcTGvc=; fh=Io7x3OacpefNRRNKoYAzVE0aWTDwD7FRzyCdD1e3AN4=; b=sXLCiUAWlSTALNuiHZT3SQYPjNkmp+8I98NIGTy7Z5ae84UFl55w0ZfqgZ0b9GEWIV gmsIRsCHpIipLRlXBP6pCmFT9xFDKNuaReUpvMKtD8FDFA9uYtx+IHfnHDFamJRVB8iB L8MuBPx6lxYMQHa1J5VHxXtJ8M5Od4a3lP/CaxupRqwlZsE6z7UyMeEFQnTE4L/TV/SH Tn7Q4sken7dUJYj4PVnGyNgk6H+8aiJPvJOGdJv1FIWajjheg0wkKRgorsVbgMX8UZ/8 +k0U0WIZN36tbGsucDiZqucsuyZ3eOz9WdUfu+JKHAYBN3tr4bdCcLabQ6GK2U0V49uJ 1sTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=lPWCAere; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id bz37-20020a056a02062500b005c668dc2426si235283pgb.176.2023.12.06.17.18.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 17:18:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=lPWCAere; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 4E25A801BCBF; Wed, 6 Dec 2023 17:18:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442951AbjLGBSj (ORCPT + 99 others); Wed, 6 Dec 2023 20:18:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443021AbjLGBSZ (ORCPT ); Wed, 6 Dec 2023 20:18:25 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2133919B7 for ; Wed, 6 Dec 2023 17:18:02 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5d3911218b3so1880597b3.1 for ; Wed, 06 Dec 2023 17:18:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701911875; x=1702516675; 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=/sHbkqXu1fUVSCDOGBtyBTb/TcjN5e6RYI3KdCcTGvc=; b=lPWCAere9A/tqQJb4Z5l4LaSTTwqTXgknJXo8BgtDlT7+pjrDMQuOtG9EKofMJkg1t CtpCTbGz+ViPywB2P82f9qcxD0LG+NQD7/OT2Dkbxqv3+GaoRZ59zUuIIWmiC9kRyLjO TJHlWjqI9UhaCg4VbqqPVqc29zm2Fffa7c1+UjKWqm4er5Xm2WioYzMNKph/AA4BfhoW 3vEyzvguY9SWNLsRJxK+3ApHLIvJ09yWKxX0rrpi8MlGj5Lcvx6GkcxDiO27doaJiN39 yCAj3yQgXayfT5jwXN5dlKJLTSYJOELXp2yZlS7nKzsMgivrB2dpfrvI0YXG5fQrMUcY wtJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701911875; x=1702516675; 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=/sHbkqXu1fUVSCDOGBtyBTb/TcjN5e6RYI3KdCcTGvc=; b=xSA3QZAworlAr3qNWkebCCCF6BV+Ur/zFP33hBELg+XAxZ1paL9aqzIv7XXPzckwcq gecZJvUKp1jzYxNRQm9vpioYrgcp/2no2EoeDVgonIf68NeD5UFLvp3vKS823VlbrWfh Sc+8nsgwydxG4VPs6k4xm90f5qGStULkE0pp9eX67w+N5gaBqqYfaeHqCG+ZB8qhViF5 sVraaZ3XFVwmjUcoqzNuY26ZLYwpSR15hgNuJgKTmFz1EAWWSbXRYYRZN+kxaN/mbHvp U4Tfs/HviPG3nQtflRQ/GmPaV7QBxCz2q1z7OMmn08TtHD4I3eb+Sbg+9WBC7PxoGity zKhg== X-Gm-Message-State: AOJu0Ywk+rxKwf2Yd95WuSGlSBPR/64QvchAaXjhYlSPl/y00ChGZmrz 5FvFneWNRkLR7MHeBY83TDrSTi3rhIBA X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:35bf:293e:7696:34e9]) (user=irogers job=sendgmr) by 2002:a05:690c:2f89:b0:5d4:263e:c819 with SMTP id ew9-20020a05690c2f8900b005d4263ec819mr25058ywb.8.1701911875437; Wed, 06 Dec 2023 17:17:55 -0800 (PST) Date: Wed, 6 Dec 2023 17:16:46 -0800 In-Reply-To: <20231207011722.1220634-1-irogers@google.com> Message-Id: <20231207011722.1220634-13-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 12/47] perf vdso: 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 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=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Wed, 06 Dec 2023 17:18:48 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784584010076733932 X-GMAIL-MSGID: 1784584010076733932 Switch machine__thread_dso_type 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/vdso.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/tools/perf/util/vdso.c b/tools/perf/util/vdso.c index ae3eee69b659..df8963796187 100644 --- a/tools/perf/util/vdso.c +++ b/tools/perf/util/vdso.c @@ -140,23 +140,34 @@ static struct dso *__machine__addnew_vdso(struct machine *machine, const char *s return dso; } +struct machine__thread_dso_type_maps_cb_args { + struct machine *machine; + enum dso_type dso_type; +}; + +static int machine__thread_dso_type_maps_cb(struct map *map, void *data) +{ + struct machine__thread_dso_type_maps_cb_args *args = data; + struct dso *dso = map__dso(map); + + if (!dso || dso->long_name[0] != '/') + return 0; + + args->dso_type = dso__type(dso, args->machine); + return (args->dso_type != DSO__TYPE_UNKNOWN) ? 1 : 0; +} + static enum dso_type machine__thread_dso_type(struct machine *machine, struct thread *thread) { - enum dso_type dso_type = DSO__TYPE_UNKNOWN; - struct map_rb_node *rb_node; - - maps__for_each_entry(thread__maps(thread), rb_node) { - struct dso *dso = map__dso(rb_node->map); + struct machine__thread_dso_type_maps_cb_args args = { + .machine = machine, + .dso_type = DSO__TYPE_UNKNOWN, + }; - if (!dso || dso->long_name[0] != '/') - continue; - dso_type = dso__type(dso, machine); - if (dso_type != DSO__TYPE_UNKNOWN) - break; - } + maps__for_each_map(thread__maps(thread), machine__thread_dso_type_maps_cb, &args); - return dso_type; + return args.dso_type; } #if BITS_PER_LONG == 64