From patchwork Thu Dec 7 01:16:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 174832 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4487666vqy; Wed, 6 Dec 2023 17:18:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzGFEqoKSV55Uw6KV+GYglrVJ1g70GP7+2vK1qHU2KZL+4wE/sSrykcO1/WJPVippRsqva X-Received: by 2002:a05:6358:7504:b0:170:61c5:f2fa with SMTP id k4-20020a056358750400b0017061c5f2famr2836568rwg.38.1701911920479; Wed, 06 Dec 2023 17:18:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701911920; cv=none; d=google.com; s=arc-20160816; b=cClHaFSME0H2J7AZS3lwdlmMdVAQsgd1ZUMvIj54XBHz/a/T4wOky6AHAAlaoPEWrf Svktgoi/YO84VsqRXp3HtsUxsHlGfVPB021+JacIZEz3KQJ80XzS0Uq8m88kMvCE41fT WJpam+htkqDcxbsN9fK+SJzY/zlgpxo6KgJvIMRATmQbuUNxuJECLoYR6P6LwFD9Fvvg o52ExooqI2WF/JMR8aU9ReDfA0uPNmb7OR0bn9YSA9qJqup7/QPwZVSY0HdT8UyJkDaO hLUonvMYskOrJ+VyBgjryoH2A9y8Ca4nDzzbDzTGwjCUznXV2fe+TY+l52eB5BD7n+do tBCQ== 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=w2/fI4UKQGbXPKpixoT4A6YY7YN3DKvkLzQPho85kC4=; fh=Io7x3OacpefNRRNKoYAzVE0aWTDwD7FRzyCdD1e3AN4=; b=zkDroLNvbZShkHSgcgRTF+YmkmFOGxj6fBNS0damMMgt5jXVKkeZT2XXevVHnf9KZ3 vNJTCKmOn5h4+2LItFnL67pyg3hmLiqr7783MxfsCWoydcMqR1JPhrHiiXRbGPivkqV/ Utr2ZrPc/qp4i56t0WCiU9ZYcsQ3yozWID18KubOCSUBnXTzRpDaRUj1ARC1i2hZbo8h UFULd2aTe9jGzQ2hd4nmC6kM/EqS9/JP4R/U1B3MYFojSCd9SHMdoIGKBuEijUUBAxoc clmUX/azQXvIdqm/6Cop4rFywIss2Flw4rlhzFCFUqfk9MiuypT7cNxQhbwjZChyd/75 Za2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=fRUXJ7b1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id b4-20020a056a000cc400b006cc04fedeadsi269402pfv.62.2023.12.06.17.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 17:18:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=fRUXJ7b1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 486CA83EE9D4; Wed, 6 Dec 2023 17:18:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442974AbjLGBSU (ORCPT + 99 others); Wed, 6 Dec 2023 20:18:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442968AbjLGBSD (ORCPT ); Wed, 6 Dec 2023 20:18:03 -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 C433010DC for ; Wed, 6 Dec 2023 17:17:54 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5d8da78a5fbso1678847b3.3 for ; Wed, 06 Dec 2023 17:17:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701911873; x=1702516673; 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=w2/fI4UKQGbXPKpixoT4A6YY7YN3DKvkLzQPho85kC4=; b=fRUXJ7b1rScZjQawpLsDkXqYkoCesK1ay2Cb3Uuqx7sFh3E8GqaDMQOg4m8AxChBKA fDVnwgz5MFsMpXSVuAhHi7FdKUr8N2BfHtzAtjhDM8vsgEQOhhdzGfqF8mJElcWzoPv5 m45f2MNX7sVdYlm1HLl2DMVm9t36d59ntu09vM6AO/nlPOu9Edy4/emzPURDDPrFnXoe t+CB0yaYnEFG96jGHAxj7AyuPdh57gZMdnwtxyTQHn24OURM0AEyaw8hxtwEJ9lNZ5Ly fIFvZ15JOaS7Tnt3BJ+UpidFkM6uKNY0VvRIsBN+fgAFxaTh5p+5EeF4ByedjTEPZLV0 irdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701911873; x=1702516673; 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=w2/fI4UKQGbXPKpixoT4A6YY7YN3DKvkLzQPho85kC4=; b=gy03t4QZFBPRUsX6SZPBpLT955M8xVC0KBV5INMhhIBjKLQOc4f7TSJRqI+Xx5+TCy hGKESlVY2f1DitLwJKDk26pQLN3d4uCkASBms8ZBOmgygfL+BeddNxqEYudptuVp2L/4 ieThbwT4P4cYsmzdj7sKhoGSWb1tEv04870B+CjomWNRujHzJXx0rJzZ99tlq2NRqXoZ WDuA1NYP8ka0udfGImmrPVeGuIlzcO5jXkPojPYI9fFAbXsu0166cMmX9jYK0uRgWU01 yjH73eOUIpUxGzkW97TVwhQLrvsIlyJclSbOJiuGjCzLltRslEr3O/2k0DsM7llBbDzA Khwg== X-Gm-Message-State: AOJu0YxHJ0ikHWNmCT1d5PLB6QFcyea/eRLVSZ5Kw9WbTdbfxBoiJBR3 2CsUGnbJRtAREWGdaiUcF2AHDJR9VVaK X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:35bf:293e:7696:34e9]) (user=irogers job=sendgmr) by 2002:a81:b70b:0:b0:5d3:bf64:5e20 with SMTP id v11-20020a81b70b000000b005d3bf645e20mr25066ywh.9.1701911873370; Wed, 06 Dec 2023 17:17:53 -0800 (PST) Date: Wed, 6 Dec 2023 17:16:45 -0800 In-Reply-To: <20231207011722.1220634-1-irogers@google.com> Message-Id: <20231207011722.1220634-12-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 11/47] perf unwind: 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 howler.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 (howler.vger.email [0.0.0.0]); Wed, 06 Dec 2023 17:18:30 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784583994041092142 X-GMAIL-MSGID: 1784583994041092142 Switch read_unwind_spec_eh_frame 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/unwind-libunwind-local.c | 34 +++++++++++++++++------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unwind-libunwind-local.c index c0641882fd2f..228f1565bd0b 100644 --- a/tools/perf/util/unwind-libunwind-local.c +++ b/tools/perf/util/unwind-libunwind-local.c @@ -302,12 +302,31 @@ static int unwind_spec_ehframe(struct dso *dso, struct machine *machine, return 0; } +struct read_unwind_spec_eh_frame_maps_cb_args { + struct dso *dso; + u64 base_addr; +}; + +static int read_unwind_spec_eh_frame_maps_cb(struct map *map, void *data) +{ + + struct read_unwind_spec_eh_frame_maps_cb_args *args = data; + + if (map__dso(map) == args->dso && map__start(map) < args->base_addr) + args->base_addr = map__start(map); + + return 0; +} + + static int read_unwind_spec_eh_frame(struct dso *dso, struct unwind_info *ui, u64 *table_data, u64 *segbase, u64 *fde_count) { - struct map_rb_node *map_node; - u64 base_addr = UINT64_MAX; + struct read_unwind_spec_eh_frame_maps_cb_args args = { + .dso = dso, + .base_addr = UINT64_MAX, + }; int ret, fd; if (dso->data.eh_frame_hdr_offset == 0) { @@ -325,16 +344,11 @@ static int read_unwind_spec_eh_frame(struct dso *dso, struct unwind_info *ui, return -EINVAL; } - maps__for_each_entry(thread__maps(ui->thread), map_node) { - struct map *map = map_node->map; - u64 start = map__start(map); + maps__for_each_map(thread__maps(ui->thread), read_unwind_spec_eh_frame_maps_cb, &args); - if (map__dso(map) == dso && start < base_addr) - base_addr = start; - } - base_addr -= dso->data.elf_base_addr; + args.base_addr -= dso->data.elf_base_addr; /* Address of .eh_frame_hdr */ - *segbase = base_addr + dso->data.eh_frame_hdr_addr; + *segbase = args.base_addr + dso->data.eh_frame_hdr_addr; ret = unwind_spec_ehframe(dso, ui->machine, dso->data.eh_frame_hdr_offset, table_data, fde_count); if (ret)