Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1361965rdb; Wed, 6 Dec 2023 17:18:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHsHJTyk8DfCrGbs3qFtJ9sNvn2Y2ByPW72OPQgWrVsDYmhKUKzncddDO9mGvzrHusHWGcn X-Received: by 2002:a05:6a20:c1a6:b0:18b:92b1:37b8 with SMTP id bg38-20020a056a20c1a600b0018b92b137b8mr2083720pzb.33.1701911905270; Wed, 06 Dec 2023 17:18:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701911905; cv=none; d=google.com; s=arc-20160816; b=gpNzfwsfifHlrC4eHe62/l29M2+AsNqnkxpthSViqCOJbJfGNyIRrFDAmWU0RfYzOU UsiMdtg74cNhE8i7n+P+MaAd+If2nDK2fCRKPjMrhyx9+cyDxsIxSsB88LHly/yES/7T U2nn8FwDUi+GuonH9nnG76N202B1CKf8E8arHwY6pFQF7mbaD0BSE6mRoyCDiQ3xNTVc 4I61UArBY5DE4dbzuQaYhsnTJSbX9DqjVe6sI9Ypf6c32k4qGRerohPcx3Jv17YjfJoL ZztYl3E7JwSW/psW+wR64qZBuVIPblmmsI+AWZNaLua6fHzRQ1bSf6lT1L6LaLiurOWO KxAg== 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=AO9qbVdz92aeOF04iN3sGAA+G8iEwxSn4ALkZn1Ljr4=; fh=Io7x3OacpefNRRNKoYAzVE0aWTDwD7FRzyCdD1e3AN4=; b=a05+XkJkqihIx1PXf46yTGoS0ZRga8C+0ubLs7j9D8M84Ish2zkwK4AXk2if2B68Nu 5jVcwOq6RSNGd6h6KJA70WsUKFHyr0uOAQ1ZsUa2V54BtKj/8x6IcfIf/oCRwdG4p8WL k5lL/s7/OSwvhcYL1T9Hb/x/UDYJuIjF+RQ785yLdYos+ip5V6122yxdElOHv9lWo+zE WbjKzIAodySI5H1LUoRHuo6Gcnqd2G/bltdVCDOM+eLhbrVdCDScRdlQ9pYK43Ua0bIj JviMZymw/LI3fOaNiOBzLs6Ag5GDb7c1d5EJP46HkYqDWxAd5aF8V3r3vWzjqXIH+fOv BWZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Zgutos3x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id ea25-20020a056a004c1900b006cda14566f1si259923pfb.150.2023.12.06.17.18.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 17:18:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Zgutos3x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 9378D8022864; Wed, 6 Dec 2023 17:18:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443010AbjLGBSC (ORCPT + 99 others); Wed, 6 Dec 2023 20:18:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442098AbjLGBRq (ORCPT ); Wed, 6 Dec 2023 20:17:46 -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 0156C10F8 for ; Wed, 6 Dec 2023 17:17:47 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5d3eafe3d17so1061777b3.1 for ; Wed, 06 Dec 2023 17:17:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701911866; x=1702516666; 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=AO9qbVdz92aeOF04iN3sGAA+G8iEwxSn4ALkZn1Ljr4=; b=Zgutos3xtH5+U2/BS+FcOeiKpwHPGi2oOXAFzwDqk4105+AxXsU/AymCQlaNemjyK1 IvwbHyf/okcc0jTHW5WFtHu0jJeUQPRZxfIrvzSm8ZlJxwMfM+Mja/NmO0af+i9Yb/5U sz32+03aMZSqt+YeP416/mt3fS3uWtZDKkCZXwrWJkA59KCtIbwwf6PaK6CiSjx4fiV4 hEanIFEPEp65UStVNGdcLT4MVfCrJutdRljADCh6nGuG7hUYZbPQoHWOBY6ZI5sQeNX6 cBEuhJYpkAufuLXqNvR3uoZueLEI+oRFCfMzz1870vQr8P7XX6LaFJUx6ajZr1K7QAMI k5xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701911866; x=1702516666; 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=AO9qbVdz92aeOF04iN3sGAA+G8iEwxSn4ALkZn1Ljr4=; b=F9iP/9axjCiOEJXIRnyn+m8HXKeQoSCbcrZBD4nKQrkQ/W7sWG4xxdgWd5tTzACqAr QouLtzYZOSXOtqp4TipVyCzg40sxRkDpuuo3gUoOAz4oPIsFV9nwp2GDT5OyR4MSRmeO h6P3db9Epvj2e7Dw/IlJlk41OjA6pYecg/FB+3CvmzZC4aya8wOQjgya0n3q5sLrlySG v492oDr4EXaAdFbj0/1oeFgR13P1Y3MdkDX23feL/fSAtQzDNol0M5aA6FIyomIogbx5 6+4CJJGpdery6EjsvusDa1aaHYmtx1QVbJi3oxAuoobaIGTJVcRCs3MA4TyEDEAaZub5 TYaQ== X-Gm-Message-State: AOJu0YzJ77KquXDIzB8JJzewEzVakt7ledERwLsdNoD04pIdCWbdPFK8 qPacKa62U/+w0Z2Yf2P89YYho/7M0/7B X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:35bf:293e:7696:34e9]) (user=irogers job=sendgmr) by 2002:a25:3144:0:b0:db5:4a00:a153 with SMTP id x65-20020a253144000000b00db54a00a153mr42999ybx.4.1701911866495; Wed, 06 Dec 2023 17:17:46 -0800 (PST) Date: Wed, 6 Dec 2023 17:16:42 -0800 In-Reply-To: <20231207011722.1220634-1-irogers@google.com> Message-Id: <20231207011722.1220634-9-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 08/47] perf symbol: 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 groat.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 (groat.vger.email [0.0.0.0]); Wed, 06 Dec 2023 17:18:22 -0800 (PST) Switch do_validate_kcore_modules 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/symbol.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 1cc42b8d8afb..72f03b875478 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -1114,33 +1114,35 @@ int compare_proc_modules(const char *from, const char *to) return ret; } +static int do_validate_kcore_modules_cb(struct map *old_map, void *data) +{ + struct rb_root *modules = data; + struct module_info *mi; + struct dso *dso; + + if (!__map__is_kmodule(old_map)) + return 0; + + dso = map__dso(old_map); + /* Module must be in memory at the same address */ + mi = find_module(dso->short_name, modules); + if (!mi || mi->start != map__start(old_map)) + return -EINVAL; + + return 0; +} + static int do_validate_kcore_modules(const char *filename, struct maps *kmaps) { struct rb_root modules = RB_ROOT; - struct map_rb_node *old_node; int err; err = read_proc_modules(filename, &modules); if (err) return err; - maps__for_each_entry(kmaps, old_node) { - struct map *old_map = old_node->map; - struct module_info *mi; - struct dso *dso; + err = maps__for_each_map(kmaps, do_validate_kcore_modules_cb, &modules); - if (!__map__is_kmodule(old_map)) { - continue; - } - dso = map__dso(old_map); - /* Module must be in memory at the same address */ - mi = find_module(dso->short_name, &modules); - if (!mi || mi->start != map__start(old_map)) { - err = -EINVAL; - goto out; - } - } -out: delete_modules(&modules); return err; } -- 2.43.0.rc2.451.g8631bc7472-goog