Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3156421rdh; Thu, 28 Sep 2023 04:34:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGvYIbHpkPIaC5/2PrDVAKUJIqR+AXBYl431Uy34Jsei+LtH8FGPS4nRoOMTGIXuhg4He3j X-Received: by 2002:a05:6870:178b:b0:1bf:6ec:dd4d with SMTP id r11-20020a056870178b00b001bf06ecdd4dmr893025oae.28.1695900883727; Thu, 28 Sep 2023 04:34:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695900883; cv=none; d=google.com; s=arc-20160816; b=UV5qGcs3L4vE6uKlymd6O9tY8e5XeK60bhv6cNjaosXdq7e/eVWXFIWa6/Pm9Kbn3/ 0fO9iu6zfRWFfFcYpn4TjMZbIyq8s/IhKdhxhvrQL9lolkkdttjxVe3hp9SYu0AOe0oT fWQmsDEFvG40045YOieFnwCha5+aklenXuyKWTqmJTVrIWJmVCikIWOb9QvHE8unF6St qmUwcAHayhtGXTFOGtECzSaOuJYYNyDGTn9j18KtI36+GbFksuMcwfZXj4bKYfJYuqG5 cNBUjlwCqV7oG7MsNcNWqumN2TGzU/wBnpHBU20lsv0z/Omo3kap/d69KLg9DnfYNGso oKng== 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 Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id s29-20020a63925d000000b0058556272a80si4220518pgn.371.2023.09.28.04.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 04:34:43 -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 DC17C82CC438; Thu, 28 Sep 2023 00:17:26 -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 S231441AbjI1HRL (ORCPT + 99 others); Thu, 28 Sep 2023 03:17:11 -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 Content-Transfer-Encoding: 8bit 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:27 -0700 (PDT) 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 --- 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; } -- 2.34.1