From nobody Fri Oct 3 23:20:52 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F6FC13DB9F for ; Sat, 23 Aug 2025 00:32:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755909155; cv=none; b=TKCZONThoayaJTW7HhiEuHcpyeN9o0ri2B5MlkBBot2Z4aqgsPbdT4c4hhJLQrawPhaFM6BSac0yvBU2SUgaBLwbTby+fY/QJON9EP+LecTxGJ+AdqJPAgQg0PlQv86/fmqt9ydgQQuyiGWaiHavlJGxLS59l6DwXFmEx/4r9b0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755909155; c=relaxed/simple; bh=4XYuTBlR6hYwFS1ueXSOzYaxTcNFVQsqr4/c3vmzres=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=fDk+mOZE1kMMfyRu0O0XDhdvDL11hsUJq2Tk0JIrZOnDEb1PupUJKRs8Pt5SJkvmNkLceVPc+Agv0ss/B3hBU0JMk7IYtJxQKvXMTer/e2zHqYA81UiadC8al+2BvERilbvk4f/dkjJ8yT5XGk1znipB508b+Qr6Obur9Ll4RAo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YYfV1iqs; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YYfV1iqs" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-24457ef983fso53505375ad.0 for ; Fri, 22 Aug 2025 17:32:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755909153; x=1756513953; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Ijg4Ede0urfZx4RJgifti/T7L7s4uVTkA9wvhJHnqsE=; b=YYfV1iqs5pb0OBg0tBJiYzaV4wm3vm9zrC73Lq274G2giRvpMbXLcptuXKZXu9VdNj 6udt/JC2LhZQgQIGqlQh4s73gXRQf4O+eIKsCHUietmCvVI3pmsH/8K5s0ebOfibFg3s pPIHikj9h4lyt+0l87fgN7r6hq+zcelrzFE0q2+eP0AY0lTgWgXISjQgbDUR8BLr5LU8 g0fc/bLcmqIT4QwonTwRFA3r0RrZeHo4+MqLEID/gV+S4VwSrxhT+iGLqj+TOVrFBNX0 H/cQtApBnxdBFSHA5ult30m43KtzsFygZEs/WSv44LRlsSkYVpVjKpLqjjjAodbkNAoC G6tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755909153; x=1756513953; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ijg4Ede0urfZx4RJgifti/T7L7s4uVTkA9wvhJHnqsE=; b=XlJ/YnPtsqFiRhhpfRYfFiEMoeQ+GfvksO4xIuwPN2WRlqbvUhsO3b7ElbeGJ4YW45 8nETqAmkDIyXwlgL3Jq6j8CJSVq/Xh6hoF9s1ThhwFCUN7AqX0RWrw2bzYSx4Au/Pmy+ gk/Fv9JKPwp/XTByjKhLWaGmT/n+x1XR49SLxzqXsfLIePz/sUVAzV44uw3OC/JbfIm5 IEF1ak6WTUdjHxv39uDK8TTxjDvWbrGf7L03Yh95PmPFfLxSur4i47VNBEhuqhndmo3O vyj7HhtcDXe+rRMHj/ue616z/z8IDVQJj0vbxsGS9+L2US7Vd+mGeo6cmb3U64YExXKJ rJ6w== X-Forwarded-Encrypted: i=1; AJvYcCXKc7avrPksz01hH608kOFkMStvryoEkaXtPnlhAdNgF2f8nhXzT5hzTqYphFl3ya5KjHd3MxMpWTxdc1s=@vger.kernel.org X-Gm-Message-State: AOJu0YzSMyrzhhAo3guPMdjrdQw25I0JlXAojmKpzAjy9OVGB8Yobtn1 WQ+2KgWCrtCevDHpw/yykf3PJ5ynK5Ael/c2GWPXAPIFJGJIYhkX30Z3pe4FMfHKmrMXDNP7M7S BT35gme8CpQ== X-Google-Smtp-Source: AGHT+IGMYeCxsgrlwx1si54aEYiTjcsFA8gfzIiUxjxIYcOIKjCABHao1VnvVTFQKEPtCEduDnI1c7IR/WiK X-Received: from plcr17.prod.google.com ([2002:a17:903:151:b0:240:285a:2adc]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f54d:b0:246:571:4b21 with SMTP id d9443c01a7336-2462ef49e52mr64510395ad.58.1755909152887; Fri, 22 Aug 2025 17:32:32 -0700 (PDT) Date: Fri, 22 Aug 2025 17:31:58 -0700 In-Reply-To: <20250823003216.733941-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250823003216.733941-1-irogers@google.com> X-Mailer: git-send-email 2.51.0.rc2.233.g662b1ed5c5-goog Message-ID: <20250823003216.733941-3-irogers@google.com> Subject: [PATCH v5 02/19] perf map: Constify objdump offset/address conversion APIs From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Aditya Gupta , "Steinar H. Gunderson" , Charlie Jenkins , Changbin Du , "Masami Hiramatsu (Google)" , James Clark , Kajol Jain , Athira Rajeev , Li Huafei , Dmitry Vyukov , Andi Kleen , Chaitanya S Prakash , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, llvm@lists.linux.dev, Song Liu , bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make the map argument const as the conversion act won't modify the map and this allows other callers to use a const struct map. Signed-off-by: Ian Rogers --- tools/perf/util/map.c | 19 +++++++++++++++---- tools/perf/util/map.h | 6 +++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index b46c68c24d1c..41cdddc987ee 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -513,6 +513,8 @@ void srccode_state_free(struct srccode_state *state) state->line =3D 0; } =20 +static const struct kmap *__map__const_kmap(const struct map *map); + /** * map__rip_2objdump - convert symbol start address to objdump address. * @map: memory map @@ -524,9 +526,9 @@ void srccode_state_free(struct srccode_state *state) * * Return: Address suitable for passing to "objdump --start-address=3D" */ -u64 map__rip_2objdump(struct map *map, u64 rip) +u64 map__rip_2objdump(const struct map *map, u64 rip) { - struct kmap *kmap =3D __map__kmap(map); + const struct kmap *kmap =3D __map__const_kmap(map); const struct dso *dso =3D map__dso(map); =20 /* @@ -569,7 +571,7 @@ u64 map__rip_2objdump(struct map *map, u64 rip) * * Return: Memory address. */ -u64 map__objdump_2mem(struct map *map, u64 ip) +u64 map__objdump_2mem(const struct map *map, u64 ip) { const struct dso *dso =3D map__dso(map); =20 @@ -586,7 +588,7 @@ u64 map__objdump_2mem(struct map *map, u64 ip) } =20 /* convert objdump address to relative address. (To be removed) */ -u64 map__objdump_2rip(struct map *map, u64 ip) +u64 map__objdump_2rip(const struct map *map, u64 ip) { const struct dso *dso =3D map__dso(map); =20 @@ -618,6 +620,15 @@ struct kmap *__map__kmap(struct map *map) return (struct kmap *)(&RC_CHK_ACCESS(map)[1]); } =20 +static const struct kmap *__map__const_kmap(const struct map *map) +{ + const struct dso *dso =3D map__dso(map); + + if (!dso || !dso__kernel(dso)) + return NULL; + return (struct kmap *)(&RC_CHK_ACCESS(map)[1]); +} + struct kmap *map__kmap(struct map *map) { struct kmap *kmap =3D __map__kmap(map); diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index 9cadf533a561..979b3e11b9bc 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h @@ -133,13 +133,13 @@ static inline u64 map__unmap_ip(const struct map *map= , u64 ip_or_rip) } =20 /* rip/ip <-> addr suitable for passing to `objdump --start-address=3D` */ -u64 map__rip_2objdump(struct map *map, u64 rip); +u64 map__rip_2objdump(const struct map *map, u64 rip); =20 /* objdump address -> memory address */ -u64 map__objdump_2mem(struct map *map, u64 ip); +u64 map__objdump_2mem(const struct map *map, u64 ip); =20 /* objdump address -> rip */ -u64 map__objdump_2rip(struct map *map, u64 ip); +u64 map__objdump_2rip(const struct map *map, u64 ip); =20 struct symbol; struct thread; --=20 2.51.0.rc2.233.g662b1ed5c5-goog