From patchwork Thu Sep 28 07:16:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 146085 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3280412vqu; Thu, 28 Sep 2023 05:40:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFTv8/ashJTeIZ5SF8nBuLszZ2P1BLDjRhvDAqQ4+jox3Q6ShcoMUmiwURWi+ensJElh8Qn X-Received: by 2002:a05:6358:2496:b0:134:c682:213f with SMTP id m22-20020a056358249600b00134c682213fmr1104036rwc.31.1695904812334; Thu, 28 Sep 2023 05:40:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695904812; cv=none; d=google.com; s=arc-20160816; b=r09WuBha5wJfxMQhLsHwrue+2ieWB5/exJVDcXMrnxqS+S3gEMcG8c4wcMJ813bQda Bs2ggRtdy/fM17SJSElwqEp9m8WgMnfO9tN0JnZJaSDcMpN88aE/TA2e3IbDXR6QrE4s QQaJdRbcScn8wgvAasVFK0T1V9Uf/RHP7N6J8P/O+xi+i3Gidtha3ZswJsjd4++rX93O t+fu/QKpyjRW9hsIK+ZeBz+FyAItIMAIxlP4XHsb00bz30AFld/zpzbOFt7CnfVRzyIM veHaHv+HIDZ4SyDmgtUFR6JswlG6KsfenrkL8sb3+lCMjDvqAmK8hLh/ALtY8/AU14XK ZALA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:organization :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=eS12RfrNzJqWA/QWsuGmGBd6EmHhuAiZLKfd2Zm8xnY=; fh=7ueK1huCq2Lf3LMjc8i3Ob70zhQl+8ZRdqYzG6swRYY=; b=V7gzmt9fjwh6EUMxP6NgwHz8ao3J8KwIKrk3rgl4BIix5+WT20ZiY8XfFMQpAaa+9z J+rQsFodJgRltsTsNWcxTX2iO5Mje4/9jaaIlAk+rb+QiAS3E6kF0Cr/QcKB56CycNuX /Z9h3NPwcgBH/1nX70CqhfZFaDUsWn39t6P26XUYi9lOSTEd+UU5IlYQzF2Jh6xgYr+f pBTwHt3vD45pV8pthxeLkqTV0LVdeyuVK0t3E/XPrvgjPAje6JNawfwRbVjjVPXFp1XW IPZMhIn4ykXYI+sq+hC3DyVTmZmQasE4gPXFLdyjz+LcJnsiEAM2ZF5YqfoOR7pbnOnn cmpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MhF8NNAA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id p19-20020a639513000000b005824bad8f81si11687843pgd.853.2023.09.28.05.40.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 05:40:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MhF8NNAA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 5BD7D82CC431; Thu, 28 Sep 2023 00:17:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231398AbjI1HRM (ORCPT + 20 others); Thu, 28 Sep 2023 03:17:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231828AbjI1HQg (ORCPT ); Thu, 28 Sep 2023 03:16:36 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 542311706; Thu, 28 Sep 2023 00:16:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695885378; x=1727421378; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=c+tVD3/2QI+wf5ggVRUpUIlYuu1vUEYAa5GfXh/vdhU=; b=MhF8NNAAbu/kvAgmfFqZdN55FCycbZgXdGZA3b2pmHKlad1JRdWwUjgZ HBGLDmrdAONULqmpxZ+HMhezW3R3ellTveuIZMttMwodo/hZL/FsuaMEL 0pnlvGfX2ALLJU5zpplzLU4eIiuVFi9Wji3zcA3hMpf5dPJLjW//nGg7q KHPKNICLcrUVg6P0jaN78R/YjXXrfV+WAhP/S7V7tu3pvOS3IsabTCyti Ess6IbrVdvNbjDz26Na2bvQ81fYB3zTsYdmqb+78Ok1JRLyPGlaIhhAK7 E2aX8b+Y9ghHCi+yMUvaHA1JOHTv12trS938QfVY2sP4UgwpixcCFigv/ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="361374281" X-IronPort-AV: E=Sophos;i="6.03,183,1694761200"; d="scan'208";a="361374281" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2023 00:16:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="752868629" X-IronPort-AV: E=Sophos;i="6.03,183,1694761200"; d="scan'208";a="752868629" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.53.62]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2023 00:16:15 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: [PATCH] perf dlfilter: Fix use of addr_location__exit() in dlfilter__object_code() Date: Thu, 28 Sep 2023 10:16:05 +0300 Message-Id: <20230928071605.17624-1-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Thu, 28 Sep 2023 00:17:20 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778285084303086875 X-GMAIL-MSGID: 1778285084303086875 Stop calling addr_location__exit() when addr_location__init() was not called. Fixes: 0dd5041c9a0e ("perf addr_location: Add init/exit/copy functions") Cc: stable@vger.kernel.org Signed-off-by: Adrian Hunter Acked-by: Namhyung Kim --- tools/perf/util/dlfilter.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/tools/perf/util/dlfilter.c b/tools/perf/util/dlfilter.c index 1dbf27822ee2..4a1dc21b0450 100644 --- a/tools/perf/util/dlfilter.c +++ b/tools/perf/util/dlfilter.c @@ -282,13 +282,21 @@ static struct perf_event_attr *dlfilter__attr(void *ctx) return &d->evsel->core.attr; } +static __s32 code_read(__u64 ip, struct map *map, struct machine *machine, void *buf, __u32 len) +{ + u64 offset = map__map_ip(map, ip); + + if (ip + len >= map__end(map)) + len = map__end(map) - ip; + + return dso__data_read_offset(map__dso(map), machine, offset, buf, len); +} + static __s32 dlfilter__object_code(void *ctx, __u64 ip, void *buf, __u32 len) { struct dlfilter *d = (struct dlfilter *)ctx; struct addr_location *al; struct addr_location a; - struct map *map; - u64 offset; __s32 ret; if (!d->ctx_valid) @@ -298,27 +306,17 @@ static __s32 dlfilter__object_code(void *ctx, __u64 ip, void *buf, __u32 len) if (!al) return -1; - map = al->map; - - if (map && ip >= map__start(map) && ip < map__end(map) && + if (al->map && ip >= map__start(al->map) && ip < map__end(al->map) && machine__kernel_ip(d->machine, ip) == machine__kernel_ip(d->machine, d->sample->ip)) - goto have_map; + return code_read(ip, al->map, d->machine, buf, len); addr_location__init(&a); + thread__find_map_fb(al->thread, d->sample->cpumode, ip, &a); - if (!a.map) { - ret = -1; - goto out; - } + ret = a.map ? code_read(ip, a.map, d->machine, buf, len) : -1; - map = a.map; -have_map: - offset = map__map_ip(map, ip); - if (ip + len >= map__end(map)) - len = map__end(map) - ip; - ret = dso__data_read_offset(map__dso(map), d->machine, offset, buf, len); -out: addr_location__exit(&a); + return ret; }