From nobody Sun Feb 8 05:42:06 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 DCFA020B7FD for ; Mon, 28 Apr 2025 21:34:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745876056; cv=none; b=Z+tfZCrWu0GgjfD3PWrcXdOZmIp7UxCzUTK1Q0CP98CypplqFakvtsfN0S/rqQaFBjlM1jMeGg7V+gVmb52RMNVpTp9+PXEyLNJYEeB791Wa4Qz9B/QCMhsCOY0eksZPU7ea4KwkQazOUgEkD4wpm5UYmckgqrR5qUtL2LOYit0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745876056; c=relaxed/simple; bh=LdmURnz0R1a5FVqiI4nFqL5u59jB8oweDiJoAaDInp8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=h9juH5NHcqCB2xKSec+b6JJWKO2CjWawk4+hlwBv0LLkEzoo4G4yNhIe/lnZWmy1SJH3uA02xx8EjLuoPpcSiQSHHvm+agFeaUVQR4fzgD7pxQfFvk8YYzRKY0nkCTiwwdKUl/SXgvEzCDw3tKBEdupriymzUlLWVGuvaYuowBg= 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=Hsn+CXyW; arc=none smtp.client-ip=209.85.216.73 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="Hsn+CXyW" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-3032f4eca83so4822310a91.3 for ; Mon, 28 Apr 2025 14:34:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745876054; x=1746480854; 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=koyWNYDZNjv4brGRecLzxvFP1YjUxm4xs1rsKpWQ/6U=; b=Hsn+CXyWC8Ljh1bq6ZnLwd+REpn1UK4hN1hxEwUoe4zMro/lgMHda1xlVoM5sAXWPv R5Hj5Hl8kXPxdzmjAgxd23Rh6Ybxnti0p5Be+HuqNX7yv4w142X0Jp53uVUDa/BVdBGj 8XbKToNQVH2Vg4QJmC6MWlgO3buMIL6wdwhp8t9cI7Rf4AY0bMsRg0LeFxFqQkstsqNC zUILxhlZa3Y7fQ7C5EQT28XyCp/QhoINIo8KKZe1CJPgs58EDRbhlngo4K31Ejc69G8u WqNdT0AB019rIvGf2r+Yeum0HwzW8UTjsY0fhxDEBjhGLT2TJ0AfOq36OpJ8Oj+BLG5P 25CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745876054; x=1746480854; 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=koyWNYDZNjv4brGRecLzxvFP1YjUxm4xs1rsKpWQ/6U=; b=LdcriWOIHJMnkFG/LLBJvGtci+nUQCqTlU1DkkyO4K6KhrPuVYoh7LIVfeWVR1ht5h BKPHVKUHXh/livbLVn5pQrX5vAlLqyTjBCPH1uenOUzlViWwd0Ef/5bqRXidOGD71WwM Vhssr8Cp3W2udgzDCd3k/dzOHIIEaZOy1rLsAN6qhL2miXJo0EzGvzklkpUlJ3d3ahvd pBn5C8i1pL5Kt5UJhhnFbUmLNNsatkkENAg3+n0VQlvUlpzHbHcZDv+No6Ac+WJLRgyD ZlgPb9NZ4Cqjvlt5MuvlDftn9rxs9d6UqC6uYGcTaTHgivFbNA8KWXkwBubamm833tWl /umw== X-Forwarded-Encrypted: i=1; AJvYcCXUVxos8pdPBTQOg+dyB3bwdZLJIMJPMlqyY4Fzfs93TLVtz2AjGSrbglt8QQ4yv/wYtlnc5chZG2PO0E0=@vger.kernel.org X-Gm-Message-State: AOJu0YyrVajU7xT90eYcvp4y7JNda3/F8DnxJXUll0AW2D5zz3RORXco IxB8YyznkUhb17Z0jHKIb9t7Hd+RdJ7IoPY7QlSPocGWTEKYu3bhmhAhrEbixxv7RysysOB8hOc jV/KnGA== X-Google-Smtp-Source: AGHT+IHPWoz0u7w36m0654PxQqLObpuJBqZKNki39vypWG6RSx0hMOplImILFRIhdHKgwb8mQwcfwXsr87k0 X-Received: from pjbcz3.prod.google.com ([2002:a17:90a:d443:b0:2fa:a101:755]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:586e:b0:2ee:e518:c1cb with SMTP id 98e67ed59e1d1-30a012ecbd8mr16031789a91.7.1745876054164; Mon, 28 Apr 2025 14:34:14 -0700 (PDT) Date: Mon, 28 Apr 2025 14:34:00 -0700 In-Reply-To: <20250428213409.1417584-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: <20250428213409.1417584-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.901.g37484f566f-goog Message-ID: <20250428213409.1417584-2-irogers@google.com> Subject: [PATCH v3 1/9] perf callchain: Always populate the addr_location map when adding IP 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 , Athira Rajeev , Kajol Jain , Li Huafei , "Steinar H. Gunderson" , James Clark , Stephen Brennan , Andi Kleen , Dmitry Vyukov , Zhongqiu Han , Yicong Yang , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Zixian Cai , Steve Clevenger , Thomas Falcon , Martin Liska , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Dropping symbols also meant the callchain maps wasn't populated, but the callchain map is needed to find the DSO. Plumb the symbols option better, falling back to thread__find_map rather than thread__find_symbol when symbols are disabled. Fixes: 02b2705017d2 ("perf callchain: Allow symbols to be optional when res= olving a callchain") Signed-off-by: Ian Rogers --- tools/perf/util/machine.c | 6 ++++-- tools/perf/util/thread.c | 8 ++++++-- tools/perf/util/thread.h | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 2531b373f2cf..b048165b10c1 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -1976,7 +1976,7 @@ static void ip__resolve_ams(struct thread *thread, * Thus, we have to try consecutively until we find a match * or else, the symbol is unknown */ - thread__find_cpumode_addr_location(thread, ip, &al); + thread__find_cpumode_addr_location(thread, ip, /*symbols=3D*/true, &al); =20 ams->addr =3D ip; ams->al_addr =3D al.addr; @@ -2078,7 +2078,7 @@ static int add_callchain_ip(struct thread *thread, al.sym =3D NULL; al.srcline =3D NULL; if (!cpumode) { - thread__find_cpumode_addr_location(thread, ip, &al); + thread__find_cpumode_addr_location(thread, ip, symbols, &al); } else { if (ip >=3D PERF_CONTEXT_MAX) { switch (ip) { @@ -2106,6 +2106,8 @@ static int add_callchain_ip(struct thread *thread, } if (symbols) thread__find_symbol(thread, *cpumode, ip, &al); + else + thread__find_map(thread, *cpumode, ip, &al); } =20 if (al.sym !=3D NULL) { diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 89585f53c1d5..10a01f8fbd40 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -410,7 +410,7 @@ int thread__fork(struct thread *thread, struct thread *= parent, u64 timestamp, bo } =20 void thread__find_cpumode_addr_location(struct thread *thread, u64 addr, - struct addr_location *al) + bool symbols, struct addr_location *al) { size_t i; const u8 cpumodes[] =3D { @@ -421,7 +421,11 @@ void thread__find_cpumode_addr_location(struct thread = *thread, u64 addr, }; =20 for (i =3D 0; i < ARRAY_SIZE(cpumodes); i++) { - thread__find_symbol(thread, cpumodes[i], addr, al); + if (symbols) + thread__find_symbol(thread, cpumodes[i], addr, al); + else + thread__find_map(thread, cpumodes[i], addr, al); + if (al->map) break; } diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index cd574a896418..2b90bbed7a61 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h @@ -126,7 +126,7 @@ struct symbol *thread__find_symbol_fb(struct thread *th= read, u8 cpumode, u64 addr, struct addr_location *al); =20 void thread__find_cpumode_addr_location(struct thread *thread, u64 addr, - struct addr_location *al); + bool symbols, struct addr_location *al); =20 int thread__memcpy(struct thread *thread, struct machine *machine, void *buf, u64 ip, int len, bool *is64bit); --=20 2.49.0.901.g37484f566f-goog From nobody Sun Feb 8 05:42:06 2026 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 B3E7220E6F3 for ; Mon, 28 Apr 2025 21:34:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745876058; cv=none; b=nv4JJ1yvu0ZyeHsyOPbVQ/V/kvdLvitYvxCC6wEM5rA0Wh/UbjYM98IvxkhZX7JO8Vx/0iecuPG6ssGVieagdPkIFqHdRhxsii6vMn/jwu/L3i6BrB5Qz/qE79cXbnycsSKWPoeUUdnx++sphGEWFCJS+frUtzvtWGZdJdmzJrY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745876058; c=relaxed/simple; bh=sNSKisiG1hdsMeqAXMQnBsbK1CE7qqQDhEcMwAn9yhQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=ccNqEk6h2DG8D3yYrtiYHxbnkjwmGHfP0A/KvKpocFL6mV3r/6ouoM9ibS49QUx67EQb71n0r8iYn9XiCeqIswVyTod5C1dDkPiogbKOjuhaWrhZ224lvR6G4wGNTdSyFmWcrjqgalS/6I3Wwlokc1p9oDsX+RxDR0tD30Gjcp4= 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=UVyiYdyO; arc=none smtp.client-ip=209.85.215.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="UVyiYdyO" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b0f807421c9so2934173a12.0 for ; Mon, 28 Apr 2025 14:34:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745876056; x=1746480856; 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=X02HQomgxWR3mWoM82/yA1eUjs3APdARyr9edl1ymiY=; b=UVyiYdyOSxnDxDu2soqu/hFv1RqnaE3Me/dC+DrXORs6CC9cKsHcWPRyLwdMnHdfHU ZyUptv+RZpomP8FJRMSFAeWqa989t3W9qdF20gnD6/VnLb/3zGLFZNqwscFR7Qhx5BJN oQ0/d+YNUVL9hH2W0SPQ06vrZc3BYkec9uTRo+OnoKU1rp5N4YmPIYiNrwLqaV5yHv9y Q07iVPXf5cdke5QEwv/sohQuObpZRpIQbE9n0h3MV6fYAyAmxvkb3g1I0fellZgJdG1l YNVCJ6kKNutLBQwM8eLlYYC/xjytSYz3jZDgrf5KEvVJgMxJGPuHLX+2kS7dgyS3u+44 1hYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745876056; x=1746480856; 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=X02HQomgxWR3mWoM82/yA1eUjs3APdARyr9edl1ymiY=; b=TmQX33IZ5NGpfG7ZiuBBVHFZokAGx62LA8hbgPUa7aeG06qeyVfr729l9AQdJvJOd6 nVYbsPID9jkmHA3fNCDv5GIKefz0aWALOYjYunOOwsQftYJHKVSxThCpm3IjJbYVNpx8 D21jDx23nVaiKEwIWzKgf2voPL6SO0cgNM8e5NKw6IQ637r5EFQ09gkDp6RhP1ayzsi1 nWn0C/T8oAUXPEcnqnxqywcbms9KFAF44V0YTnAlSckZAK5W/j61r/HkIH+StzXMPQyb Kv0a1tVoYQ/g7to8PWkCZ7b4zXizBeb2YpV5kfApQi6ZMATlq2A/sQKmrJPzAjdAh+2M S1IA== X-Forwarded-Encrypted: i=1; AJvYcCWSJS8cboisKP2/pzCln7oVImoiW3mmKluMFOsTjL1TdmjkTYsnTv4/4cPQ4lO2YsnImRpdFciyzlRLx6k=@vger.kernel.org X-Gm-Message-State: AOJu0YxKnWFq38mzakQnL6PS6pw6EA9aUxhsRTMl/OGWaOb1A7vcoROS fF0MIh61mqJBw8GsD6SQVXKEq7q/DTVh1XpoUNL78D2zd85S1F3ihrRFz8KHnUcrrTh6RoiV20K H5sUiYw== X-Google-Smtp-Source: AGHT+IG9piqj3ObQ1uyzi2wTg72pEue4UFNXrJZLmUK2OICKb7nWvOBDj/R3L8x9+9AWxEJhOVRnDHHFPirA X-Received: from pgld6.prod.google.com ([2002:a63:e06:0:b0:b13:7874:b1b3]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:6a03:b0:1f5:80a3:b006 with SMTP id adf61e73a8af0-2095682bb2dmr953425637.21.1745876056067; Mon, 28 Apr 2025 14:34:16 -0700 (PDT) Date: Mon, 28 Apr 2025 14:34:01 -0700 In-Reply-To: <20250428213409.1417584-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: <20250428213409.1417584-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.901.g37484f566f-goog Message-ID: <20250428213409.1417584-3-irogers@google.com> Subject: [PATCH v3 2/9] perf build-id: Reduce size of "size" variable 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 , Athira Rajeev , Kajol Jain , Li Huafei , "Steinar H. Gunderson" , James Clark , Stephen Brennan , Andi Kleen , Dmitry Vyukov , Zhongqiu Han , Yicong Yang , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Zixian Cai , Steve Clevenger , Thomas Falcon , Martin Liska , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Later clean up of the dso_id to include a build_id will suffer from alignment and size issues. The size can only hold up to a value of BUILD_ID_SIZE (20) and the mmap2 event uses a byte for the value. Signed-off-by: Ian Rogers --- tools/perf/util/build-id.h | 2 +- tools/perf/util/synthetic-events.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h index a212497bfdb0..e3e0a446ff0c 100644 --- a/tools/perf/util/build-id.h +++ b/tools/perf/util/build-id.h @@ -13,7 +13,7 @@ =20 struct build_id { u8 data[BUILD_ID_SIZE]; - size_t size; + u8 size; }; =20 struct dso; diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index 2fc4d0537840..68bb7c5fe1b1 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -2248,7 +2248,9 @@ int perf_event__synthesize_build_id(const struct perf= _tool *tool, =20 memset(&ev, 0, len); =20 - ev.build_id.size =3D min(bid->size, sizeof(ev.build_id.build_id)); + ev.build_id.size =3D bid->size; + if (ev.build_id.size > sizeof(ev.build_id.build_id)) + ev.build_id.size =3D sizeof(ev.build_id.build_id); memcpy(ev.build_id.build_id, bid->data, ev.build_id.size); ev.build_id.header.type =3D PERF_RECORD_HEADER_BUILD_ID; ev.build_id.header.misc =3D misc | PERF_RECORD_MISC_BUILD_ID_SIZE; @@ -2308,7 +2310,9 @@ int perf_event__synthesize_mmap2_build_id(const struc= t perf_tool *tool, ev.mmap2.len =3D len; ev.mmap2.pgoff =3D pgoff; =20 - ev.mmap2.build_id_size =3D min(bid->size, sizeof(ev.mmap2.build_id)); + ev.mmap2.build_id_size =3D bid->size; + if (ev.mmap2.build_id_size > sizeof(ev.mmap2.build_id)) + ev.build_id.size =3D sizeof(ev.mmap2.build_id); memcpy(ev.mmap2.build_id, bid->data, ev.mmap2.build_id_size); =20 ev.mmap2.prot =3D prot; --=20 2.49.0.901.g37484f566f-goog From nobody Sun Feb 8 05:42:06 2026 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 B10342101B3 for ; Mon, 28 Apr 2025 21:34:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745876060; cv=none; b=IDrQ2Bq8QZduLhNldBH8Z8o6BwnDEx/3IG63tM8U+Lv1PTLpxxN3etEJBSlZrLXNqEcy9PvXZyN2eQLwbM8FtRd1w8UACIlR84rDeL7dIWBgm+bHAoqVF/ujEcNjfwQWumzCgvnvkoE2X+fK+jTYK1XCXdGya2oZYqPAPr+lt0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745876060; c=relaxed/simple; bh=DT+OD4lOib7IOS4ovH6DPK7Kmbb/+1k3dk49ghgZL+c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=BHLdk9oXETZBRo96ql926s+ghe+uK4wnxFySefpMjad0v8TYHwDm3Y7jkml0qyQkhcziA7rf4MrWj4XG922cnS3sNJrmopQLcj+PhsS/SX3Vcqqy8saCsc3w8PwzqYtTNAvLt0YVQJwxMX7JEccFuFGDwJzB1Mp9ABmqfKsJzko= 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=iyDeuoei; arc=none smtp.client-ip=209.85.215.202 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="iyDeuoei" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-af534e796baso2910342a12.3 for ; Mon, 28 Apr 2025 14:34:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745876058; x=1746480858; 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=fZS1n0db6qQg+ZjsoOF7DP7dvRsPHCjcVpwodHb7LO0=; b=iyDeuoeiBIE3A11AODrCjeEk0v5HkkMkYErgZKuSjmqIJeL/ol9cazt7UYj4zyHFYL SZp2atfdv+2hrkoeuY1iKEWJ7xchEBqVgn5JVhNDD1FAI+71+WGl0IyRqfDXwPTKUCXK wlpRp0gp+B2GetfLSDSoLjEgObDKrp1f0k1agFubhXgX/aS9kVNSqkno1OjcmSWUcF1n W+QMOwkl3+UMmGtA1WSMO4PtpIHxoI5vn/vuL7POnk+e8r/qtkBZ8X7PgFdSPGvx2icu 7Oe4UXVRzPEj4Y81HpzrRzI3qSXEVn/qN/YHXtaxtp3UzuZcFUIEk90BmNybLTRlWmkA 7Iew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745876058; x=1746480858; 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=fZS1n0db6qQg+ZjsoOF7DP7dvRsPHCjcVpwodHb7LO0=; b=t9jv4AghdO7UCvyKcRQUr3SXzrfNkVqW7JfJyhubWmEsTwShN26EkUG8aAVGw1Xwhk x7uyZ06AxTxbdBY/z9WpPMXkIhjM7mIsVpDw6F4XvliAZWTUKLb7EcFg0vTbWGjXmwLG aA+zdm9eSIdXVJsmeTXpgynXlhLchv6LUD9xddd8Ip7qf2Gv/WH8caeEtvhGT0hdyuk5 cRiZpiQZI6Z+z6z62zWYu5DOD//dBlSd4tMRFLfbQJqLO3byB+Z1vKG/ffCGvycby5jG p4hQZqPA1WKDy9lrNx0vXa8+JgUI1QgVdmLuPKhkvb6vvUz+Y/KMzrnu4k8Sah8trZlc 2dJw== X-Forwarded-Encrypted: i=1; AJvYcCXejZyAczx53EKwv6lwkiqBvxy2xdhyQUJhhUtvcAVrAD1qeNbHQwTFi17TMfo9FOAS+8/6GumSzJzoNio=@vger.kernel.org X-Gm-Message-State: AOJu0YxThMN4zgUv9FdgQIFO75GS4/r2qUyEZ3qa1AbufS8TKnOzX4fW qCllrxgFa5N5l2bj4lmzKxmr95YIEt//QAgTGwKDQO5q/sWojHjLbvAxKLh9Gd+ErMu/93BbIUi xSWRLPQ== X-Google-Smtp-Source: AGHT+IHkMEjq/0HiG7c1pF4ho/tCZ2BXVghAmtjMD8gPiMcgBdq5bmFUEr0M1yJwJEodxrYaR2+ePoOYa5W6 X-Received: from pjxx14.prod.google.com ([2002:a17:90b:58ce:b0:2f7:d453:e587]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2e8f:b0:2ff:71ad:e84e with SMTP id 98e67ed59e1d1-30a21550360mr1947861a91.10.1745876057888; Mon, 28 Apr 2025 14:34:17 -0700 (PDT) Date: Mon, 28 Apr 2025 14:34:02 -0700 In-Reply-To: <20250428213409.1417584-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: <20250428213409.1417584-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.901.g37484f566f-goog Message-ID: <20250428213409.1417584-4-irogers@google.com> Subject: [PATCH v3 3/9] perf build-id: Truncate to avoid overflowing the build_id data 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 , Athira Rajeev , Kajol Jain , Li Huafei , "Steinar H. Gunderson" , James Clark , Stephen Brennan , Andi Kleen , Dmitry Vyukov , Zhongqiu Han , Yicong Yang , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Zixian Cai , Steve Clevenger , Thomas Falcon , Martin Liska , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Warning when the build_id data would be overflowed would lead to memory corruption, switch to truncation. Signed-off-by: Ian Rogers --- tools/perf/util/build-id.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index e763e8d99a43..5bc2040bdd0d 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -951,7 +951,10 @@ bool perf_session__read_build_ids(struct perf_session = *session, bool with_hits) =20 void build_id__init(struct build_id *bid, const u8 *data, size_t size) { - WARN_ON(size > BUILD_ID_SIZE); + if (size > BUILD_ID_SIZE) { + pr_debug("Truncating build_id size from %zd\n", size); + size =3D BUILD_ID_SIZE; + } memcpy(bid->data, data, size); bid->size =3D size; } --=20 2.49.0.901.g37484f566f-goog From nobody Sun Feb 8 05:42:06 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 6E19321170D for ; Mon, 28 Apr 2025 21:34:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745876062; cv=none; b=edGyBmIe9WVFkhXauaoh0mB/RuK/2qP6u7HWXbXGfQ/rb2AOHvfKkMfO/hKdLYcRMjSW15rzoWuebIhZQ9ZVDPkl3wwGBgjuIJxkfXSkJZHkLdt+Xu0OJyu+WEO58dnIKaBdHFWHQLzRQb/Xo/hgTA4PrC8I9GJP3ZDz5z9GjQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745876062; c=relaxed/simple; bh=zYAu2MT63gohwkF0a9OTZjiC0Jf6F9/Rrr1ZxbcQb20=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=enV+YgR3WgO1sHfJDS4mSkdXpkCMwlAPb/OWqfTYHqXXjdXBYFoeIb/PBRzbAjIpd73TOYRfFshfMgebYZ1DQcU6KrCzRoUJQMnzNZsigrqC6jIE1PJyr9tW9bHAT6Evd7PUwf/uIIFauGtAIPbZWumclm8qhgZAHSWwOyFuJ9M= 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=itbGMgam; arc=none smtp.client-ip=209.85.216.73 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="itbGMgam" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ff64898e2aso4551751a91.1 for ; Mon, 28 Apr 2025 14:34:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745876060; x=1746480860; 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=PxzvZzaRWKZt0SytMXa4p0ZRgNBd1b+k8eT5N/k7t5c=; b=itbGMgam6tISKcXW+F5HVSj9O0qlta+y4U8otUDssvYW6eov4lEjaQatmmod+N51JI KQCFkM75lDk61dbiqPgCo5pPgUcBmwcDBMGgOjk1GQT9Mp2m9Shxol7CTwqCfPrALXRF DOeBjxIkDTji9ogXUF6NhJQTZzePUSZucx7XH9ZQv3a8eg1g9uExk2qcWBaUWF0LrpSq McOWe1myJzXOvtimJguBH8zYiJWsO4YONIKmy1BHPl/2zkorlYhzAAzoPd+rvV+A7rAF pvvY9BIYb73L2ecIaiLuP1ijALc5PfHtTcKcLkbAK+/ZoGhPuKYKCWqS7Zf7tbpGJkeO zJ2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745876060; x=1746480860; 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=PxzvZzaRWKZt0SytMXa4p0ZRgNBd1b+k8eT5N/k7t5c=; b=fK6S9WDz0jyugdrjYTDU5S67X0Z86cgarT4wcvOATEJCzgEjV0uQsXdJhQvo5tGwkv +U924vZJ3eRtUmV6pGatOnY/FZJp/cbGFdL7YYTaPkuybjOAwrPRdRQ74svEA13Lzdhr GlI6UD7vPfOF6ToxpxftHxY074r0WMzZajC7nigF3JE6kXe/YvBJIQA8zdq1p37HIIj3 T4fxVIpN+GWPTPnxSotRK4GMkrCYfsfGFEhQrtVe2Q+WpUsB0KY41RxTM32qmbiP0AvO /l5Qn0czUwJcCnKYikm8592XjfmNSmwnWw6KyvgAy6u9/d1uuaSUhNMPF/DlLXvYVIpr wwbQ== X-Forwarded-Encrypted: i=1; AJvYcCW5J3U8xXwIkHI/yonbbsmR9aeL0M86jAZwSdA1nUHhPVeALwCAChSB3F4jLSetdwR6Q5uQ9PLOmmPNbHs=@vger.kernel.org X-Gm-Message-State: AOJu0YzA8WQ6ID8pUYq8UAPvhcE0l4eKNkjdnZh0mCnLnw8shPzuVYaP W5lj3lnHdArG4kKS+hL4DeCIPL0bbiBBpZdAGS6b9KHOWR2MU1pv89RAipzSZ654f+aeHStMTw1 +Y1h9xg== X-Google-Smtp-Source: AGHT+IGqrtD+PPURIrJOV0NfnPvWh9gs5GP+FF5U/WOZak/+E0CW38sP2Z8kGDZmcUOlt47CD3BkvaMOMH7o X-Received: from pjd16.prod.google.com ([2002:a17:90b:54d0:b0:2ea:5084:5297]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:35c4:b0:2fa:17e4:b1cf with SMTP id 98e67ed59e1d1-30a2244ac60mr958509a91.2.1745876059699; Mon, 28 Apr 2025 14:34:19 -0700 (PDT) Date: Mon, 28 Apr 2025 14:34:03 -0700 In-Reply-To: <20250428213409.1417584-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: <20250428213409.1417584-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.901.g37484f566f-goog Message-ID: <20250428213409.1417584-5-irogers@google.com> Subject: [PATCH v3 4/9] perf build-id: Change sprintf functions to snprintf 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 , Athira Rajeev , Kajol Jain , Li Huafei , "Steinar H. Gunderson" , James Clark , Stephen Brennan , Andi Kleen , Dmitry Vyukov , Zhongqiu Han , Yicong Yang , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Zixian Cai , Steve Clevenger , Thomas Falcon , Martin Liska , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Pass in a size argument rather than implying all build id strings must be SBUILD_ID_SIZE. Signed-off-by: Ian Rogers --- tools/perf/builtin-buildid-cache.c | 12 +++---- tools/perf/builtin-buildid-list.c | 6 ++-- tools/perf/util/build-id.c | 33 ++++++++----------- tools/perf/util/build-id.h | 6 ++-- tools/perf/util/disasm.c | 2 +- tools/perf/util/dso.c | 4 +-- tools/perf/util/dsos.c | 2 +- tools/perf/util/event.c | 2 +- tools/perf/util/header.c | 2 +- tools/perf/util/map.c | 2 +- tools/perf/util/probe-file.c | 4 +-- .../scripting-engines/trace-event-python.c | 7 ++-- tools/perf/util/symbol.c | 2 +- 13 files changed, 38 insertions(+), 46 deletions(-) diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildi= d-cache.c index b0511d16aeb6..3f7739b21148 100644 --- a/tools/perf/builtin-buildid-cache.c +++ b/tools/perf/builtin-buildid-cache.c @@ -31,7 +31,7 @@ #include #include =20 -static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuil= did) +static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuil= did, size_t sbuildid_size) { char root_dir[PATH_MAX]; char *p; @@ -42,7 +42,7 @@ static int build_id_cache__kcore_buildid(const char *proc= _dir, char *sbuildid) if (!p) return -1; *p =3D '\0'; - return sysfs__sprintf_build_id(root_dir, sbuildid); + return sysfs__snprintf_build_id(root_dir, sbuildid, sbuildid_size); } =20 static int build_id_cache__kcore_dir(char *dir, size_t sz) @@ -128,7 +128,7 @@ static int build_id_cache__add_kcore(const char *filena= me, bool force) return -1; *p =3D '\0'; =20 - if (build_id_cache__kcore_buildid(from_dir, sbuildid) < 0) + if (build_id_cache__kcore_buildid(from_dir, sbuildid, sizeof(sbuildid)) <= 0) return -1; =20 scnprintf(to_dir, sizeof(to_dir), "%s/%s/%s", @@ -187,7 +187,7 @@ static int build_id_cache__add_file(const char *filenam= e, struct nsinfo *nsi) return -1; } =20 - build_id__sprintf(&bid, sbuild_id); + build_id__snprintf(&bid, sbuild_id, sizeof(sbuild_id)); err =3D build_id_cache__add_s(sbuild_id, filename, nsi, false, false); pr_debug("Adding %s %s: %s\n", sbuild_id, filename, @@ -211,7 +211,7 @@ static int build_id_cache__remove_file(const char *file= name, struct nsinfo *nsi) return -1; } =20 - build_id__sprintf(&bid, sbuild_id); + build_id__snprintf(&bid, sbuild_id, sizeof(sbuild_id)); err =3D build_id_cache__remove_s(sbuild_id); pr_debug("Removing %s %s: %s\n", sbuild_id, filename, err ? "FAIL" : "Ok"); @@ -317,7 +317,7 @@ static int build_id_cache__update_file(const char *file= name, struct nsinfo *nsi) } err =3D 0; =20 - build_id__sprintf(&bid, sbuild_id); + build_id__snprintf(&bid, sbuild_id, sizeof(sbuild_id)); if (build_id_cache__cached(sbuild_id)) err =3D build_id_cache__remove_s(sbuild_id); =20 diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid= -list.c index 52dfacaff8e3..ba8ba0303920 100644 --- a/tools/perf/builtin-buildid-list.c +++ b/tools/perf/builtin-buildid-list.c @@ -31,7 +31,7 @@ static int buildid__map_cb(struct map *map, void *arg __m= aybe_unused) =20 memset(bid_buf, 0, sizeof(bid_buf)); if (dso__has_build_id(dso)) - build_id__sprintf(dso__bid_const(dso), bid_buf); + build_id__snprintf(dso__bid_const(dso), bid_buf, sizeof(bid_buf)); printf("%s %16" PRIx64 " %16" PRIx64, bid_buf, map__start(map), map__end(= map)); if (dso_long_name !=3D NULL) printf(" %s", dso_long_name); @@ -57,7 +57,7 @@ static int sysfs__fprintf_build_id(FILE *fp) char sbuild_id[SBUILD_ID_SIZE]; int ret; =20 - ret =3D sysfs__sprintf_build_id("/", sbuild_id); + ret =3D sysfs__snprintf_build_id("/", sbuild_id, sizeof(sbuild_id)); if (ret !=3D sizeof(sbuild_id)) return ret < 0 ? ret : -EINVAL; =20 @@ -69,7 +69,7 @@ static int filename__fprintf_build_id(const char *name, F= ILE *fp) char sbuild_id[SBUILD_ID_SIZE]; int ret; =20 - ret =3D filename__sprintf_build_id(name, sbuild_id); + ret =3D filename__snprintf_build_id(name, sbuild_id, sizeof(sbuild_id)); if (ret !=3D sizeof(sbuild_id)) return ret < 0 ? ret : -EINVAL; =20 diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 5bc2040bdd0d..aa35dceace90 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -67,24 +67,17 @@ int build_id__mark_dso_hit(const struct perf_tool *tool= __maybe_unused, return 0; } =20 -int build_id__sprintf(const struct build_id *build_id, char *bf) +int build_id__snprintf(const struct build_id *build_id, char *bf, size_t b= f_size) { - char *bid =3D bf; - const u8 *raw =3D build_id->data; - size_t i; - - bf[0] =3D 0x0; + size_t offs =3D 0; =20 - for (i =3D 0; i < build_id->size; ++i) { - sprintf(bid, "%02x", *raw); - ++raw; - bid +=3D 2; - } + for (size_t i =3D 0; i < build_id->size && offs < bf_size; ++i) + offs +=3D snprintf(bf + offs, bf_size - offs, "%02x", build_id->data[i]); =20 - return (bid - bf) + 1; + return offs; } =20 -int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id) +int sysfs__snprintf_build_id(const char *root_dir, char *sbuild_id, size_t= sbuild_id_size) { char notes[PATH_MAX]; struct build_id bid; @@ -99,10 +92,10 @@ int sysfs__sprintf_build_id(const char *root_dir, char = *sbuild_id) if (ret < 0) return ret; =20 - return build_id__sprintf(&bid, sbuild_id); + return build_id__snprintf(&bid, sbuild_id, sbuild_id_size); } =20 -int filename__sprintf_build_id(const char *pathname, char *sbuild_id) +int filename__snprintf_build_id(const char *pathname, char *sbuild_id, siz= e_t sbuild_id_size) { struct build_id bid; int ret; @@ -111,7 +104,7 @@ int filename__sprintf_build_id(const char *pathname, ch= ar *sbuild_id) if (ret < 0) return ret; =20 - return build_id__sprintf(&bid, sbuild_id); + return build_id__snprintf(&bid, sbuild_id, sbuild_id_size); } =20 /* asnprintf consolidates asprintf and snprintf */ @@ -212,9 +205,9 @@ static bool build_id_cache__valid_id(char *sbuild_id) return false; =20 if (!strcmp(pathname, DSO__NAME_KALLSYMS)) - ret =3D sysfs__sprintf_build_id("/", real_sbuild_id); + ret =3D sysfs__snprintf_build_id("/", real_sbuild_id, sizeof(real_sbuild= _id)); else if (pathname[0] =3D=3D '/') - ret =3D filename__sprintf_build_id(pathname, real_sbuild_id); + ret =3D filename__snprintf_build_id(pathname, real_sbuild_id, sizeof(rea= l_sbuild_id)); else ret =3D -EINVAL; /* Should we support other special DSO cache? */ if (ret >=3D 0) @@ -243,7 +236,7 @@ char *__dso__build_id_filename(const struct dso *dso, c= har *bf, size_t size, if (!dso__has_build_id(dso)) return NULL; =20 - build_id__sprintf(dso__bid_const(dso), sbuild_id); + build_id__snprintf(dso__bid_const(dso), sbuild_id, sizeof(sbuild_id)); linkname =3D build_id_cache__linkname(sbuild_id, NULL, 0); if (!linkname) return NULL; @@ -769,7 +762,7 @@ static int build_id_cache__add_b(const struct build_id = *bid, { char sbuild_id[SBUILD_ID_SIZE]; =20 - build_id__sprintf(bid, sbuild_id); + build_id__snprintf(bid, sbuild_id, sizeof(sbuild_id)); =20 return __build_id_cache__add_s(sbuild_id, name, nsi, is_kallsyms, is_vdso, proper_name, root_dir); diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h index e3e0a446ff0c..47e621cebe1b 100644 --- a/tools/perf/util/build-id.h +++ b/tools/perf/util/build-id.h @@ -21,10 +21,10 @@ struct feat_fd; struct nsinfo; =20 void build_id__init(struct build_id *bid, const u8 *data, size_t size); -int build_id__sprintf(const struct build_id *build_id, char *bf); +int build_id__snprintf(const struct build_id *build_id, char *bf, size_t b= f_size); bool build_id__is_defined(const struct build_id *bid); -int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id); -int filename__sprintf_build_id(const char *pathname, char *sbuild_id); +int sysfs__snprintf_build_id(const char *root_dir, char *sbuild_id, size_t= sbuild_id_size); +int filename__snprintf_build_id(const char *pathname, char *sbuild_id, siz= e_t sbuild_id_size); char *build_id_cache__kallsyms_path(const char *sbuild_id, char *bf, size_t size); =20 diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index 8f0eb56c6fc6..96e6a5d6eacc 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -1218,7 +1218,7 @@ int symbol__strerror_disassemble(struct map_symbol *m= s, int errnum, char *buf, s char *build_id_msg =3D NULL; =20 if (dso__has_build_id(dso)) { - build_id__sprintf(dso__bid(dso), bf + 15); + build_id__snprintf(dso__bid(dso), bf + 15, sizeof(bf) - 15); build_id_msg =3D bf; } scnprintf(buf, buflen, diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 8619b6eea62d..776506b93b8b 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -217,7 +217,7 @@ int dso__read_binary_type_filename(const struct dso *ds= o, break; } =20 - build_id__sprintf(dso__bid_const(dso), build_id_hex); + build_id__snprintf(dso__bid_const(dso), build_id_hex, sizeof(build_id_he= x)); len =3D __symbol__join_symfs(filename, size, "/usr/lib/debug/.build-id/"= ); snprintf(filename + len, size - len, "%.2s/%s.debug", build_id_hex, build_id_hex + 2); @@ -1697,7 +1697,7 @@ static size_t dso__fprintf_buildid(struct dso *dso, F= ILE *fp) { char sbuild_id[SBUILD_ID_SIZE]; =20 - build_id__sprintf(dso__bid(dso), sbuild_id); + build_id__snprintf(dso__bid(dso), sbuild_id, sizeof(sbuild_id)); return fprintf(fp, "%s", sbuild_id); } =20 diff --git a/tools/perf/util/dsos.c b/tools/perf/util/dsos.c index e0998e2a7c4e..b2172632b3cd 100644 --- a/tools/perf/util/dsos.c +++ b/tools/perf/util/dsos.c @@ -370,7 +370,7 @@ static int dsos__fprintf_buildid_cb(struct dso *dso, vo= id *data) =20 if (args->skip && args->skip(dso, args->parm)) return 0; - build_id__sprintf(dso__bid(dso), sbuild_id); + build_id__snprintf(dso__bid(dso), sbuild_id, sizeof(sbuild_id)); args->ret +=3D fprintf(args->fp, "%-40s %s\n", sbuild_id, dso__long_name(= dso)); return 0; } diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index c23b77f8f854..34176050ebac 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -329,7 +329,7 @@ size_t perf_event__fprintf_mmap2(union perf_event *even= t, FILE *fp) =20 build_id__init(&bid, event->mmap2.build_id, event->mmap2.build_id_size); - build_id__sprintf(&bid, sbuild_id); + build_id__snprintf(&bid, sbuild_id, sizeof(sbuild_id)); =20 return fprintf(fp, " %d/%d: [%#" PRI_lx64 "(%#" PRI_lx64 ") @ %#" PRI_lx= 64 " <%s>]: %c%c%c%c %s\n", diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index e3cdc3b7b4ab..38e903307e8e 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -2291,7 +2291,7 @@ static int __event_process_build_id(struct perf_recor= d_header_build_id *bev, free(m.name); } =20 - build_id__sprintf(dso__bid(dso), sbuild_id); + build_id__snprintf(dso__bid(dso), sbuild_id, sizeof(sbuild_id)); pr_debug("build id event received for %s: %s [%zu]\n", dso__long_name(dso), sbuild_id, size); dso__put(dso); diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index d729438b7d65..0f6b185f9589 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -354,7 +354,7 @@ int map__load(struct map *map) if (dso__has_build_id(dso)) { char sbuild_id[SBUILD_ID_SIZE]; =20 - build_id__sprintf(dso__bid(dso), sbuild_id); + build_id__snprintf(dso__bid(dso), sbuild_id, sizeof(sbuild_id)); pr_debug("%s with build id %s not found", name, sbuild_id); } else pr_debug("Failed to open %s", name); diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c index ec8ac242fedb..5069fb61f48c 100644 --- a/tools/perf/util/probe-file.c +++ b/tools/perf/util/probe-file.c @@ -448,10 +448,10 @@ static int probe_cache__open(struct probe_cache *pcac= he, const char *target, if (!target || !strcmp(target, DSO__NAME_KALLSYMS)) { target =3D DSO__NAME_KALLSYMS; is_kallsyms =3D true; - ret =3D sysfs__sprintf_build_id("/", sbuildid); + ret =3D sysfs__snprintf_build_id("/", sbuildid, sizeof(sbuildid)); } else { nsinfo__mountns_enter(nsi, &nsc); - ret =3D filename__sprintf_build_id(target, sbuildid); + ret =3D filename__snprintf_build_id(target, sbuildid, sizeof(sbuildid)); nsinfo__mountns_exit(&nsc); } =20 diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools= /perf/util/scripting-engines/trace-event-python.c index 520729e78965..68e92552d954 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -780,14 +780,13 @@ static void set_sym_in_dict(PyObject *dict, struct ad= dr_location *al, const char *sym_field, const char *symoff_field, const char *map_pgoff) { - char sbuild_id[SBUILD_ID_SIZE]; - if (al->map) { + char sbuild_id[SBUILD_ID_SIZE]; struct dso *dso =3D map__dso(al->map); =20 pydict_set_item_string_decref(dict, dso_field, _PyUnicode_FromString(dso__name(dso))); - build_id__sprintf(dso__bid(dso), sbuild_id); + build_id__snprintf(dso__bid(dso), sbuild_id, sizeof(sbuild_id)); pydict_set_item_string_decref(dict, dso_bid_field, _PyUnicode_FromString(sbuild_id)); pydict_set_item_string_decref(dict, dso_map_start, @@ -1238,7 +1237,7 @@ static int python_export_dso(struct db_export *dbe, s= truct dso *dso, char sbuild_id[SBUILD_ID_SIZE]; PyObject *t; =20 - build_id__sprintf(dso__bid(dso), sbuild_id); + build_id__snprintf(dso__bid(dso), sbuild_id, sizeof(sbuild_id)); =20 t =3D tuple_new(5); =20 diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 11540219481b..30750ed313ca 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -2143,7 +2143,7 @@ static char *dso__find_kallsyms(struct dso *dso, stru= ct map *map) goto proc_kallsyms; } =20 - build_id__sprintf(dso__bid(dso), sbuild_id); + build_id__snprintf(dso__bid(dso), sbuild_id, sizeof(sbuild_id)); =20 /* Find kallsyms in build-id cache with kcore */ scnprintf(path, sizeof(path), "%s/%s/%s", --=20 2.49.0.901.g37484f566f-goog From nobody Sun Feb 8 05:42:06 2026 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 399CC212FBE for ; Mon, 28 Apr 2025 21:34:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745876063; cv=none; b=gt0n+ZvE7/fd0YeZxqAkloMBCw/iS0ZpHYOw+3IA1/Jb+GcA8USoRqtRoYyjW4ppYqpoMgQChyDtuFC6UniIlZpxMwULmkL22sAIauUuIlkFxH3UM1frDUbeJPIwvyUHAWyDr/y9+ta/1afmJkEtxVLHJdIiV2a9/KJzTUZn8E4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745876063; c=relaxed/simple; bh=HTKDxSb83GljAcKwgB1tWyhvT8jeauFTb7sWIZG+NHI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=pEmU7LbfluIF2uI3+MCa4z2keyoD1aG2O2oRCT4BHWxQ+m0UC4X2EmGkpAGcll9+oF3LE/imvEjwHW70h/ID3Wz4riB9w39l7QvHPubfndyby3CScJjFl/J7Kt93RahgBhGxYyEZP9PhfoYE84a0g+RdWoG7AHuUvILGwPQ52cQ= 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=yu00/8Wk; arc=none smtp.client-ip=209.85.215.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="yu00/8Wk" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-af8d8e0689eso5340627a12.2 for ; Mon, 28 Apr 2025 14:34:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745876061; x=1746480861; 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=NruyO827J8Aq2CmIQSrBjSup56z+26r+Jphuwb//5zM=; b=yu00/8WkEO4Vj92UIDPo6XmZ0pONQmBSPCMLvcdk8p3vEJi6u+UXQs35GduDSHpRh1 jfHRmQufy8QjC3bUkVxtFU+KeUklbn7TA1kOinbMLT+PWu3B/6D2pTI5PwQhOOilNIhD f4MPZYh6IZjem0eJmVKHkieGeUy6+n2qGNAaCu2I48O38YUb+CQaYiAyJyZ+zU9l4LoC i0WDfYVqKUlJKVLbud3YuaPcEfag3wppGB4s8IcB6wo1efRLGVlp6KfPQquZMPZ4bVy+ sI+N0wZmiK1R2PNWO+1/KUiS1VfA6n3xa3m3RSa4MO1OZltOm0HSygYUEMszkwQdRtWH McRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745876061; x=1746480861; 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=NruyO827J8Aq2CmIQSrBjSup56z+26r+Jphuwb//5zM=; b=ka5TmEGx4TEuk4sI8XlzJA+zU8HdAU5jgZHnUiIZo6SJ+g7uBK+CgfAgaK1SZFXmiq q3sJbnx36J7OE4xZAF+B97y9wtXSDjQ2OTbMhA4sHPa2r/3QbFpnQe8WccoG2WdD5FvB yiaL/zDYkQHUeFIYPA1RKNG5SpsLOvQKa3T5AMjS04uInDMQbvBdxu0/mz6S8aLVKjIL j6ZLU2mpWmOtxqn0TvArjtZ0StwrJopQ22x9Lu+QcJ5meL/fHXyuG6/CmLutTJnUF4v6 djj61/VAyjIQNkZyg4LwiORrWc5nVcFGdG+yGgyhz4jVhrVFcZJRAaZjQ2zdPj9/M2pT 3fcQ== X-Forwarded-Encrypted: i=1; AJvYcCUhtRg8eaVBrSx4fNoghxalwadVFxNsVNdQ8pHq+3BR1Q2V1/0CruUW6tNgCKYsJQmukXYufbuiNw1q4wI=@vger.kernel.org X-Gm-Message-State: AOJu0YxhhQ3irgdU/jECgkJfEqNCzOAo1sV7oZOjb84NqqNScRZsx6CN lg9qegG+CbYv43mLF9XCFBgCEArwwyV0Sir2xVdxFlc5vLeHeoRABLC0XuqKI5fDFYYdiaqGRPK MWUUazw== X-Google-Smtp-Source: AGHT+IFr1DUcLf4fJFO8qlUiM8teqy5JWXpOKomw5UGogwqkVc1K1AS6v5CJ/1Z+7wZHpieRsK/3Zo3kT+oD X-Received: from pjm7.prod.google.com ([2002:a17:90b:2fc7:b0:2fa:a101:743]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5185:b0:2ff:6fc3:79c3 with SMTP id 98e67ed59e1d1-30a21552a93mr2262278a91.9.1745876061588; Mon, 28 Apr 2025 14:34:21 -0700 (PDT) Date: Mon, 28 Apr 2025 14:34:04 -0700 In-Reply-To: <20250428213409.1417584-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: <20250428213409.1417584-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.901.g37484f566f-goog Message-ID: <20250428213409.1417584-6-irogers@google.com> Subject: [PATCH v3 5/9] perf build-id: Mark DSO in sample callchains 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 , Athira Rajeev , Kajol Jain , Li Huafei , "Steinar H. Gunderson" , James Clark , Stephen Brennan , Andi Kleen , Dmitry Vyukov , Zhongqiu Han , Yicong Yang , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Zixian Cai , Steve Clevenger , Thomas Falcon , Martin Liska , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Previously only the sample IP's map DSO would be marked hit for the purposes of populating the build ID cache. Walk the call chain to mark all IPs and DSOs. Signed-off-by: Ian Rogers --- tools/perf/util/build-id.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index aa35dceace90..3386fa8e1e7e 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -42,10 +42,20 @@ =20 static bool no_buildid_cache; =20 +static int mark_dso_hit_callback(struct callchain_cursor_node *node, void = *data __maybe_unused) +{ + struct map *map =3D node->ms.map; + + if (map) + dso__set_hit(map__dso(map)); + + return 0; +} + int build_id__mark_dso_hit(const struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel __maybe_unused, + struct evsel *evsel, struct machine *machine) { struct addr_location al; @@ -63,6 +73,11 @@ int build_id__mark_dso_hit(const struct perf_tool *tool = __maybe_unused, dso__set_hit(map__dso(al.map)); =20 addr_location__exit(&al); + + sample__for_each_callchain_node(thread, evsel, sample, PERF_MAX_STACK_DEP= TH, + /*symbols=3D*/false, mark_dso_hit_callback, /*data=3D*/NULL); + + thread__put(thread); return 0; } --=20 2.49.0.901.g37484f566f-goog From nobody Sun Feb 8 05:42:06 2026 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 870A32139B1 for ; Mon, 28 Apr 2025 21:34:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745876066; cv=none; b=hmjdRINzqlzknArrb7pVQTfc9AQGctqRRLyFM1WpNAawqyEY7jwLaxS3SGhyTFZqE+HmHBBYXdV43p1bralDYW10+qirJ0N1FD/ZkC9MMrYyPe85jBr6dODkwRUonao9CdtuuUpEWXxWQNxAXRzcHGhoITMYz7iP9WZSE9jBtw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745876066; c=relaxed/simple; bh=9lFs23nhfZvzu0Mj5gCbGsdPtLWWA75vQnigtb7zG2M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=POAXoKyG1ma51YlOpKJqsGRclw3s/lj+Zo/PlVh/lD8zHfbZ++pVtFpRvSI4fnrjn4Vm6Lj5NnBeIMyEeEeUbGvam1PJMqWFS1X97h1lp47K18uPuMBV5taHK33Ux5ePuFkqB9S+cZ3P4BjnCjNFGq+NJ//+9PRmG2mRqFJYH1c= 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=LDfRaPk3; arc=none smtp.client-ip=209.85.215.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="LDfRaPk3" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-af5156fbe79so6016154a12.1 for ; Mon, 28 Apr 2025 14:34:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745876064; x=1746480864; 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=dzxXgRFN2UGn9FhDNQufHxyUI8OddqfRc8hra+lL44Y=; b=LDfRaPk3iKTtlh/eEAsUOK8KqGwMISjiGPm6iRnX2dL397SEk0ZPJ74Dhcp7m2R+OV 1bzVgb3saTofowqdXcl1yBtfgidkomd7JbjrnuwlxrbPXLYTCgX6GAMkKVC3qv63hvx9 yBWhFuWbqWcJdf3oT4L8SFrk2Ub3AYfkAWA92mWcyvxl+1yx+HxJNojJ6yUTI+3s5teg ixyWlglIYYeIi0FPrXm2NgoMkWHGvTZGWNb/mL1KM+csIvR4KPVIP1vi+Vaq0dkRk3XD MQEyO2yZZJ9WZbEUceFBMZd/2VP82c65oxeNV2sgPhZUA6/9/+9F89mCUEpbG8TJLf2S 1qdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745876064; x=1746480864; 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=dzxXgRFN2UGn9FhDNQufHxyUI8OddqfRc8hra+lL44Y=; b=caOB3cOE1uwHamBlxVNAMIaOeSOkyyVNnkgtbsgMQo+zLCiEsR9aKv9xTkAB0NH2S7 8r4OpBYRKHEHgvE7eHY0fdXeTwudkRlQcIKt8c+lmuVmIw/KbxPVAtBBsBs+0DwMx7qU UEwNjFm/Jw3UvwbD31X/Nb9Gj4GwXBJKDRENJM4q23PyJkqwn8rw7+tjxlTQuN50eZe9 P2KAv1Rb6KsUsPRRFf8mSihTqQZ+pz2iCbiV81lHRDgL02PjdLwjOoLKcmXUXsOI6KRz IUtWa/6lym7SY8ngIK4gyNtRMhomgcnb4pVb2Ths1HPznnW/LS9b4nu1tlXt3ehQrMTU dbTA== X-Forwarded-Encrypted: i=1; AJvYcCXYR1kl4VAjzNAjTy7Nr4Ns+sLazymlbaO1FpY0My2uJ6TGzRMOY01HaQinuJQYQJGiA4CFV6oqRfpXNok=@vger.kernel.org X-Gm-Message-State: AOJu0YwT+XgAU+7Bpm7ldDAoRot8ExiUPO6SFuYcc24idp7KAis9QxGg qQ78ncaHzMmB1bMj38td87s4WWKeDBe7OA1zvqkI7D3GeTrefLbQc37/xDD2F4OXJtmmgjvloyH TuIl+jQ== X-Google-Smtp-Source: AGHT+IHQ+3fvZJZBirX+hKlkf4n2BDlXYbytD3KHk+S5P5S4UjHXnDX8BeCp6mikTekER78DQoH9ifZMgv81 X-Received: from pgar18.prod.google.com ([2002:a05:6a02:2e92:b0:af9:775:2e8b]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:2d27:b0:1f5:60ce:6cc6 with SMTP id adf61e73a8af0-2046a58d8c8mr13745484637.21.1745876063759; Mon, 28 Apr 2025 14:34:23 -0700 (PDT) Date: Mon, 28 Apr 2025 14:34:05 -0700 In-Reply-To: <20250428213409.1417584-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: <20250428213409.1417584-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.901.g37484f566f-goog Message-ID: <20250428213409.1417584-7-irogers@google.com> Subject: [PATCH v3 6/9] perf build-id: Ensure struct build_id is empty before use 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 , Athira Rajeev , Kajol Jain , Li Huafei , "Steinar H. Gunderson" , James Clark , Stephen Brennan , Andi Kleen , Dmitry Vyukov , Zhongqiu Han , Yicong Yang , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Zixian Cai , Steve Clevenger , Thomas Falcon , Martin Liska , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If a build ID is read then not all code paths may ensure it is empty before use. Initialize the build_id to be zero-ed unless there is clear initialization such as a call to build_id__init. Signed-off-by: Ian Rogers --- tools/perf/bench/inject-buildid.c | 2 +- tools/perf/builtin-buildid-cache.c | 8 ++++---- tools/perf/tests/pe-file-parsing.c | 2 +- tools/perf/tests/sdt.c | 2 +- tools/perf/util/build-id.c | 6 +++--- tools/perf/util/debuginfo.c | 2 +- tools/perf/util/probe-event.c | 3 ++- tools/perf/util/probe-finder.c | 3 ++- tools/perf/util/symbol-minimal.c | 2 +- tools/perf/util/symbol.c | 5 +++-- tools/perf/util/synthetic-events.c | 2 +- 11 files changed, 20 insertions(+), 17 deletions(-) diff --git a/tools/perf/bench/inject-buildid.c b/tools/perf/bench/inject-bu= ildid.c index f55c07e4be94..aad572a78d7f 100644 --- a/tools/perf/bench/inject-buildid.c +++ b/tools/perf/bench/inject-buildid.c @@ -80,7 +80,7 @@ static int add_dso(const char *fpath, const struct stat *= sb __maybe_unused, int typeflag, struct FTW *ftwbuf __maybe_unused) { struct bench_dso *dso =3D &dsos[nr_dsos]; - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; =20 if (typeflag =3D=3D FTW_D || typeflag =3D=3D FTW_SL) return 0; diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildi= d-cache.c index 3f7739b21148..e936a34b7d37 100644 --- a/tools/perf/builtin-buildid-cache.c +++ b/tools/perf/builtin-buildid-cache.c @@ -175,7 +175,7 @@ static int build_id_cache__add_kcore(const char *filena= me, bool force) static int build_id_cache__add_file(const char *filename, struct nsinfo *n= si) { char sbuild_id[SBUILD_ID_SIZE]; - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; int err; struct nscookie nsc; =20 @@ -198,7 +198,7 @@ static int build_id_cache__add_file(const char *filenam= e, struct nsinfo *nsi) static int build_id_cache__remove_file(const char *filename, struct nsinfo= *nsi) { char sbuild_id[SBUILD_ID_SIZE]; - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; struct nscookie nsc; =20 int err; @@ -275,7 +275,7 @@ static int build_id_cache__purge_all(void) static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_u= nused) { char filename[PATH_MAX]; - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; =20 if (!dso__build_id_filename(dso, filename, sizeof(filename), false)) return true; @@ -303,7 +303,7 @@ static int build_id_cache__fprintf_missing(struct perf_= session *session, FILE *f static int build_id_cache__update_file(const char *filename, struct nsinfo= *nsi) { char sbuild_id[SBUILD_ID_SIZE]; - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; struct nscookie nsc; =20 int err; diff --git a/tools/perf/tests/pe-file-parsing.c b/tools/perf/tests/pe-file-= parsing.c index fff58b220c07..30c7da79e109 100644 --- a/tools/perf/tests/pe-file-parsing.c +++ b/tools/perf/tests/pe-file-parsing.c @@ -24,7 +24,7 @@ static int run_dir(const char *d) { char filename[PATH_MAX]; char debugfile[PATH_MAX]; - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; char debuglink[PATH_MAX]; char expect_build_id[] =3D { 0x5a, 0x0f, 0xd8, 0x82, 0xb5, 0x30, 0x84, 0x22, diff --git a/tools/perf/tests/sdt.c b/tools/perf/tests/sdt.c index 919712899251..de4c7916b40d 100644 --- a/tools/perf/tests/sdt.c +++ b/tools/perf/tests/sdt.c @@ -28,7 +28,7 @@ static int target_function(void) static int build_id_cache__add_file(const char *filename) { char sbuild_id[SBUILD_ID_SIZE]; - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; int err; =20 err =3D filename__read_build_id(filename, &bid); diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 3386fa8e1e7e..1abd5a670665 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -95,7 +95,7 @@ int build_id__snprintf(const struct build_id *build_id, c= har *bf, size_t bf_size int sysfs__snprintf_build_id(const char *root_dir, char *sbuild_id, size_t= sbuild_id_size) { char notes[PATH_MAX]; - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; int ret; =20 if (!root_dir) @@ -112,7 +112,7 @@ int sysfs__snprintf_build_id(const char *root_dir, char= *sbuild_id, size_t sbuil =20 int filename__snprintf_build_id(const char *pathname, char *sbuild_id, siz= e_t sbuild_id_size) { - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; int ret; =20 ret =3D filename__read_build_id(pathname, &bid); @@ -849,7 +849,7 @@ static int filename__read_build_id_ns(const char *filen= ame, =20 static bool dso__build_id_mismatch(struct dso *dso, const char *name) { - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; bool ret =3D false; =20 mutex_lock(dso__lock(dso)); diff --git a/tools/perf/util/debuginfo.c b/tools/perf/util/debuginfo.c index b5deea7cbdf2..a44c70f93156 100644 --- a/tools/perf/util/debuginfo.c +++ b/tools/perf/util/debuginfo.c @@ -103,7 +103,7 @@ struct debuginfo *debuginfo__new(const char *path) char buf[PATH_MAX], nil =3D '\0'; struct dso *dso; struct debuginfo *dinfo =3D NULL; - struct build_id bid; + struct build_id bid =3D { .size =3D 0}; =20 /* Try to open distro debuginfo files */ dso =3D dso__new(path); diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 307ad6242a4e..3c87aa6f7d3b 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -1063,7 +1063,6 @@ static int sprint_line_description(char *sbuf, size_t= size, struct line_range *l static int __show_line_range(struct line_range *lr, const char *module, bool user) { - struct build_id bid; int l =3D 1; struct int_node *ln; struct debuginfo *dinfo; @@ -1088,6 +1087,8 @@ static int __show_line_range(struct line_range *lr, c= onst char *module, ret =3D -ENOENT; } if (dinfo->build_id) { + struct build_id bid; + build_id__init(&bid, dinfo->build_id, BUILD_ID_SIZE); build_id__sprintf(&bid, sbuild_id); } diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index 3cc7c40f5097..1bbb91758316 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c @@ -848,7 +848,6 @@ static int probe_point_lazy_walker(const char *fname, i= nt lineno, /* Find probe points from lazy pattern */ static int find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *p= f) { - struct build_id bid; char sbuild_id[SBUILD_ID_SIZE] =3D ""; int ret =3D 0; char *fpath; @@ -858,6 +857,8 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, str= uct probe_finder *pf) =20 comp_dir =3D cu_get_comp_dir(&pf->cu_die); if (pf->dbg->build_id) { + struct build_id bid; + build_id__init(&bid, pf->dbg->build_id, BUILD_ID_SIZE); build_id__sprintf(&bid, sbuild_id); } diff --git a/tools/perf/util/symbol-minimal.c b/tools/perf/util/symbol-mini= mal.c index c6f369b5d893..6e3d79730538 100644 --- a/tools/perf/util/symbol-minimal.c +++ b/tools/perf/util/symbol-minimal.c @@ -343,7 +343,7 @@ int dso__load_sym(struct dso *dso, struct map *map __ma= ybe_unused, struct symsrc *runtime_ss __maybe_unused, int kmodule __maybe_unused) { - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; int ret; =20 ret =3D fd__is_64_bit(ss->fd); diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 30750ed313ca..41420d5f4001 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -1804,7 +1804,6 @@ int dso__load(struct dso *dso, struct map *map) struct symsrc *syms_ss =3D NULL, *runtime_ss =3D NULL; bool kmod; bool perfmap; - struct build_id bid; struct nscookie nsc; char newmapname[PATH_MAX]; const char *map_path =3D dso__long_name(dso); @@ -1865,6 +1864,8 @@ int dso__load(struct dso *dso, struct map *map) */ if (!dso__has_build_id(dso) && is_regular_file(dso__long_name(dso))) { + struct build_id bid =3D { .size =3D 0, }; + __symbol__join_symfs(name, PATH_MAX, dso__long_name(dso)); if (filename__read_build_id(name, &bid) > 0) dso__set_build_id(dso, &bid); @@ -2113,7 +2114,7 @@ static bool filename__readable(const char *file) =20 static char *dso__find_kallsyms(struct dso *dso, struct map *map) { - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; char sbuild_id[SBUILD_ID_SIZE]; bool is_host =3D false; char path[PATH_MAX]; diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index 68bb7c5fe1b1..b7ebee95536f 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -368,7 +368,7 @@ static void perf_record_mmap2__read_build_id(struct per= f_record_mmap2 *event, struct machine *machine, bool is_kernel) { - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; struct nsinfo *nsi; struct nscookie nc; struct dso *dso =3D NULL; --=20 2.49.0.901.g37484f566f-goog From nobody Sun Feb 8 05:42:06 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 7BDA52135D1 for ; Mon, 28 Apr 2025 21:34:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745876069; cv=none; b=MmgpeODwI0TNTXl3ggjZGrkKywMWpJ5sPxqo3M3QpY57NP6Xuu9cTWnwNMTrZ02hPvJuf+bdXJrY0/+lSQG9qa69UQVEGnV6dCqpVX1Jh3+fcWbqZnBm2VYSYJLgOz4zRvHaAaxbvqAMQONmHQwaaFT9dFxWKOUKKk6wGHh3cRg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745876069; c=relaxed/simple; bh=edavszNObl52ttZbsH6z6w8LRl60KOZZnXzV8RKUvEg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=EMRzZj2b0/he3dO9UW29jqs6uSkuQazE48umtfZaLRjqS/Dnkfi6bRd9lNDRMI84TxXmQAXB46kJbUr2oAQR0J/jwhO6VMb1WYQ6NtHxMKvvK2/OYqWYdfsjxBGtqLvrgQc6RQpX4W+VGz4vqZ7hO+c3TcMvMb94BzJxKhkwfQk= 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=2WUc+69p; arc=none smtp.client-ip=209.85.216.74 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="2WUc+69p" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-309c6e43a9aso8106961a91.2 for ; Mon, 28 Apr 2025 14:34:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745876066; x=1746480866; 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=JMOyuBW9ivtMh3f7R11P8exZgCF6IN5aJm7uOGR4BTk=; b=2WUc+69pGlulZ9v/t4kC8H8FXCpTOLvhwypY22nFjuWfYqcqlG9TT51j2YdO9LP8xI ZG/5LLN8WA5QRZjU2+8gP7Z/qxpREbvfFE8VeTgXKIOJZzr2PE5621uNvLvk81Z2ZXHR JFAypC7udlYx+8+HdGpj8xcVpshx0FN87e+x5qxYeX89sPrK5E1BQH2+KToUKHPZJvq1 U+OxG0NkiYCSYBztycvKEhXigmi4omTfS8XqByVxtPZXzmD8bP2Q6LjQO5Mf6tPFKThE LXMj+RiKpNLZCyUBifhMa9mZHu9+qu6j6UI/5uOaowliYeYoX6cFeSpyhdcjQrMGj6Bq Sk0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745876066; x=1746480866; 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=JMOyuBW9ivtMh3f7R11P8exZgCF6IN5aJm7uOGR4BTk=; b=iomd5radmAbI+G5E9SVzeopJXH1EIXawTJBzMsMw2eWjkq58TMfN1wEk6ftP2TR0ob CVkZeI8DPDJKs8Ymky0RESL7oyjGhmXXtd5Xx4P/v5Imsyg+Po0FNQHwWXvr0i7gBJuk AmJGl0EqZ0EznaZ/rQ4+4X69X5Q+wExtH1+ur5Muhlr9LskZUC0aeKMla87Gue8qqsxj IyFoc6qSdzSQaNcnxnPXwVMhSye13ghXB3mntRvDVJLynpFeS5uS+yitpEPVRw1Xi3f1 r877FONO0AUdSfScMwgkSpKiZnV2nwgwTDN5PLzqllNQKE9s5q99y+3nsQ1C+hKk7MLH VD8A== X-Forwarded-Encrypted: i=1; AJvYcCV7M9YOYwqM7X6yctdZQqFsxrk7XdWfldraC49FcnktRuuDsenKyUpHwTOs2vckFRaQRO/QCxVEtAjGDJo=@vger.kernel.org X-Gm-Message-State: AOJu0YyjNbMFshkbyrhVe4ucv2K+vYP/6f9i/my6fW64x2czDIoHynA4 rqfoC9dy1TZIXizwtaZFTy6AxBFfeHbP4gjqypA5+pC4HnG4/iUWgNwd/4VYVyJE06/CMLIoKDP 0zdsFmg== X-Google-Smtp-Source: AGHT+IGr1Zf5+C/4y65seakKKdmqX50dLyfcGQdOsiLuMPKc+E/xCzqaBOJMtlQSThoO2xG5Ku+x8eO0D0M3 X-Received: from pjl3.prod.google.com ([2002:a17:90b:2f83:b0:2f8:4024:b59a]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:57e8:b0:2ff:58b8:5c46 with SMTP id 98e67ed59e1d1-30a013275a8mr13333171a91.8.1745876065653; Mon, 28 Apr 2025 14:34:25 -0700 (PDT) Date: Mon, 28 Apr 2025 14:34:06 -0700 In-Reply-To: <20250428213409.1417584-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: <20250428213409.1417584-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.901.g37484f566f-goog Message-ID: <20250428213409.1417584-8-irogers@google.com> Subject: [PATCH v3 7/9] perf dso: Move build_id to dso_id 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 , Athira Rajeev , Kajol Jain , Li Huafei , "Steinar H. Gunderson" , James Clark , Stephen Brennan , Andi Kleen , Dmitry Vyukov , Zhongqiu Han , Yicong Yang , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Zixian Cai , Steve Clevenger , Thomas Falcon , Martin Liska , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The dso_id previously contained the major, minor, inode and inode generation information from a mmap2 event - the inode generation would be zero when reading from /proc/pid/maps. The build_id was in the dso. With build ID mmap2 events these fields wouldn't be initialized which would largely mean the special empty case where any dso would match for equality. This isn't desirable as if a dso is replaced we want the comparison to yield a difference. To support detecting the difference between DSOs based on build_id, move the build_id out of the DSO and into the dso_id. The dso_id is also stored in the DSO so nothing is lost. Capture in the dso_id what parts have been initialized and rename dso_id__inject to dso_id__improve_id so that it is clear the dso_id is being improved upon with additional information. With the build_id in the dso_id, use memcmp to compare for equality. Signed-off-by: Ian Rogers --- tools/perf/builtin-buildid-list.c | 2 +- tools/perf/builtin-inject.c | 36 ++++---- tools/perf/builtin-report.c | 11 ++- tools/perf/include/perf/perf_dlfilter.h | 2 +- tools/perf/tests/symbols.c | 4 +- tools/perf/util/build-id.c | 4 +- tools/perf/util/dso.c | 109 +++++++++++++----------- tools/perf/util/dso.h | 75 ++++++++-------- tools/perf/util/dsos.c | 18 ++-- tools/perf/util/machine.c | 28 +++--- tools/perf/util/map.c | 13 ++- tools/perf/util/map.h | 5 +- tools/perf/util/sort.c | 27 +++--- tools/perf/util/synthetic-events.c | 18 ++-- 14 files changed, 197 insertions(+), 155 deletions(-) diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid= -list.c index ba8ba0303920..151cd84b6dfe 100644 --- a/tools/perf/builtin-buildid-list.c +++ b/tools/perf/builtin-buildid-list.c @@ -31,7 +31,7 @@ static int buildid__map_cb(struct map *map, void *arg __m= aybe_unused) =20 memset(bid_buf, 0, sizeof(bid_buf)); if (dso__has_build_id(dso)) - build_id__snprintf(dso__bid_const(dso), bid_buf, sizeof(bid_buf)); + build_id__snprintf(dso__bid(dso), bid_buf, sizeof(bid_buf)); printf("%s %16" PRIx64 " %16" PRIx64, bid_buf, map__start(map), map__end(= map)); if (dso_long_name !=3D NULL) printf(" %s", dso_long_name); diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 11e49cafa3af..bdd51fc1685c 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -587,15 +587,17 @@ static int perf_event__repipe_mmap2(const struct perf= _tool *tool, struct perf_sample *sample, struct machine *machine) { - struct dso_id id; - struct dso_id *dso_id =3D NULL; + struct dso_id id =3D dso_id_empty; =20 - if (!(event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID)) { + if (event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID) { + build_id__init(&id.build_id, event->mmap2.build_id, event->mmap2.build_i= d_size); + } else { id.maj =3D event->mmap2.maj; id.min =3D event->mmap2.min; id.ino =3D event->mmap2.ino; id.ino_generation =3D event->mmap2.ino_generation; - dso_id =3D &id; + id.mmap2_valid =3D true; + id.mmap2_ino_generation_valid =3D true; } =20 return perf_event__repipe_common_mmap( @@ -603,7 +605,7 @@ static int perf_event__repipe_mmap2(const struct perf_t= ool *tool, event->mmap2.pid, event->mmap2.tid, event->mmap2.start, event->mmap2.len, event->mmap2.pgoff, event->mmap2.flags, event->mmap2.prot, - event->mmap2.filename, dso_id, + event->mmap2.filename, &id, perf_event__process_mmap2); } =20 @@ -671,19 +673,20 @@ static int perf_event__repipe_tracing_data(struct per= f_session *session, static int dso__read_build_id(struct dso *dso) { struct nscookie nsc; + struct build_id bid =3D { .size =3D 0, }; =20 if (dso__has_build_id(dso)) return 0; =20 mutex_lock(dso__lock(dso)); nsinfo__mountns_enter(dso__nsinfo(dso), &nsc); - if (filename__read_build_id(dso__long_name(dso), dso__bid(dso)) > 0) - dso__set_has_build_id(dso); + if (filename__read_build_id(dso__long_name(dso), &bid) > 0) + dso__set_build_id(dso, &bid); else if (dso__nsinfo(dso)) { char *new_name =3D dso__filename_with_chroot(dso, dso__long_name(dso)); =20 - if (new_name && filename__read_build_id(new_name, dso__bid(dso)) > 0) - dso__set_has_build_id(dso); + if (new_name && filename__read_build_id(new_name, &bid) > 0) + dso__set_build_id(dso, &bid); free(new_name); } nsinfo__mountns_exit(&nsc); @@ -732,23 +735,26 @@ static bool perf_inject__lookup_known_build_id(struct= perf_inject *inject, struct dso *dso) { struct str_node *pos; - int bid_len; =20 strlist__for_each_entry(pos, inject->known_build_ids) { + struct build_id bid; const char *build_id, *dso_name; + size_t bid_len; =20 build_id =3D skip_spaces(pos->s); dso_name =3D strchr(build_id, ' '); bid_len =3D dso_name - pos->s; + if (bid_len > sizeof(bid.data)) + bid_len =3D sizeof(bid.data); dso_name =3D skip_spaces(dso_name); if (strcmp(dso__long_name(dso), dso_name)) continue; - for (int ix =3D 0; 2 * ix + 1 < bid_len; ++ix) { - dso__bid(dso)->data[ix] =3D (hex(build_id[2 * ix]) << 4 | - hex(build_id[2 * ix + 1])); + for (size_t ix =3D 0; 2 * ix + 1 < bid_len; ++ix) { + bid.data[ix] =3D (hex(build_id[2 * ix]) << 4 | + hex(build_id[2 * ix + 1])); } - dso__bid(dso)->size =3D bid_len / 2; - dso__set_has_build_id(dso); + bid.size =3D bid_len / 2; + dso__set_build_id(dso, &bid); return true; } return false; diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index f0299c7ee025..98b1f73c28da 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -858,17 +858,24 @@ static int maps__fprintf_task_cb(struct map *map, voi= d *data) struct maps__fprintf_task_args *args =3D data; const struct dso *dso =3D map__dso(map); u32 prot =3D map__prot(map); + const struct dso_id *dso_id =3D dso__id_const(dso); int ret; + char buf[SBUILD_ID_SIZE]; + + if (dso_id->mmap2_valid) + snprintf(buf, sizeof(buf), "%" PRIu64, dso_id->ino); + else + build_id__snprintf(&dso_id->build_id, buf, sizeof(buf)); =20 ret =3D fprintf(args->fp, - "%*s %" PRIx64 "-%" PRIx64 " %c%c%c%c %08" PRIx64 " %" PRIu64 " %s\n", + "%*s %" PRIx64 "-%" PRIx64 " %c%c%c%c %08" PRIx64 " %s %s\n", args->indent, "", map__start(map), map__end(map), prot & PROT_READ ? 'r' : '-', prot & PROT_WRITE ? 'w' : '-', prot & PROT_EXEC ? 'x' : '-', map__flags(map) ? 's' : 'p', map__pgoff(map), - dso__id_const(dso)->ino, dso__name(dso)); + buf, dso__name(dso)); =20 if (ret < 0) return ret; diff --git a/tools/perf/include/perf/perf_dlfilter.h b/tools/perf/include/p= erf/perf_dlfilter.h index 16fc4568ac53..2d3540ed3c58 100644 --- a/tools/perf/include/perf/perf_dlfilter.h +++ b/tools/perf/include/perf/perf_dlfilter.h @@ -87,7 +87,7 @@ struct perf_dlfilter_al { __u8 is_64_bit; /* Only valid if dso is not NULL */ __u8 is_kernel_ip; /* True if in kernel space */ __u32 buildid_size; - __u8 *buildid; + const __u8 *buildid; /* Below members are only populated by resolve_ip() */ __u8 filtered; /* True if this sample event will be filtered out */ const char *comm; diff --git a/tools/perf/tests/symbols.c b/tools/perf/tests/symbols.c index ee20a366f32f..b07fdf831868 100644 --- a/tools/perf/tests/symbols.c +++ b/tools/perf/tests/symbols.c @@ -96,8 +96,8 @@ static int create_map(struct test_info *ti, char *filenam= e, struct map **map_p) dso__put(dso); =20 /* Create a dummy map at 0x100000 */ - *map_p =3D map__new(ti->machine, 0x100000, 0xffffffff, 0, NULL, - PROT_EXEC, 0, NULL, filename, ti->thread); + *map_p =3D map__new(ti->machine, 0x100000, 0xffffffff, 0, &dso_id_empty, + PROT_EXEC, /*flags=3D*/0, filename, ti->thread); if (!*map_p) { pr_debug("Failed to create map!"); return TEST_FAIL; diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 1abd5a670665..e2b295fe4d2f 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -251,7 +251,7 @@ char *__dso__build_id_filename(const struct dso *dso, c= har *bf, size_t size, if (!dso__has_build_id(dso)) return NULL; =20 - build_id__snprintf(dso__bid_const(dso), sbuild_id, sizeof(sbuild_id)); + build_id__snprintf(dso__bid(dso), sbuild_id, sizeof(sbuild_id)); linkname =3D build_id_cache__linkname(sbuild_id, NULL, 0); if (!linkname) return NULL; @@ -334,7 +334,7 @@ static int machine__write_buildid_table_cb(struct dso *= dso, void *data) } =20 in_kernel =3D dso__kernel(dso) || is_kernel_module(name, PERF_RECORD_MISC= _CPUMODE_UNKNOWN); - return write_buildid(name, name_len, dso__bid(dso), args->machine->pid, + return write_buildid(name, name_len, &dso__id(dso)->build_id, args->machi= ne->pid, in_kernel ? args->kmisc : args->umisc, args->fd); } =20 diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 776506b93b8b..075f74c1bdf0 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -217,7 +217,7 @@ int dso__read_binary_type_filename(const struct dso *ds= o, break; } =20 - build_id__snprintf(dso__bid_const(dso), build_id_hex, sizeof(build_id_he= x)); + build_id__snprintf(dso__bid(dso), build_id_hex, sizeof(build_id_hex)); len =3D __symbol__join_symfs(filename, size, "/usr/lib/debug/.build-id/"= ); snprintf(filename + len, size - len, "%.2s/%s.debug", build_id_hex, build_id_hex + 2); @@ -1379,64 +1379,76 @@ static void dso__set_long_name_id(struct dso *dso, = const char *name, bool name_a =20 static int __dso_id__cmp(const struct dso_id *a, const struct dso_id *b) { - if (a->maj > b->maj) return -1; - if (a->maj < b->maj) return 1; + if (a->mmap2_valid && b->mmap2_valid) { + if (a->maj > b->maj) return -1; + if (a->maj < b->maj) return 1; =20 - if (a->min > b->min) return -1; - if (a->min < b->min) return 1; + if (a->min > b->min) return -1; + if (a->min < b->min) return 1; =20 - if (a->ino > b->ino) return -1; - if (a->ino < b->ino) return 1; - - /* - * Synthesized MMAP events have zero ino_generation, avoid comparing - * them with MMAP events with actual ino_generation. - * - * I found it harmful because the mismatch resulted in a new - * dso that did not have a build ID whereas the original dso did have a - * build ID. The build ID was essential because the object was not found - * otherwise. - Adrian - */ - if (a->ino_generation && b->ino_generation) { + if (a->ino > b->ino) return -1; + if (a->ino < b->ino) return 1; + } + if (a->mmap2_ino_generation_valid && b->mmap2_ino_generation_valid) { if (a->ino_generation > b->ino_generation) return -1; if (a->ino_generation < b->ino_generation) return 1; } - + if (build_id__is_defined(&a->build_id) && build_id__is_defined(&b->build_= id)) { + if (a->build_id.size !=3D b->build_id.size) + return a->build_id.size < b->build_id.size ? -1 : 1; + return memcmp(a->build_id.data, b->build_id.data, a->build_id.size); + } return 0; } =20 -bool dso_id__empty(const struct dso_id *id) -{ - if (!id) - return true; - - return !id->maj && !id->min && !id->ino && !id->ino_generation; -} +const struct dso_id dso_id_empty =3D { + { + .maj =3D 0, + .min =3D 0, + .ino =3D 0, + .ino_generation =3D 0, + }, + .mmap2_valid =3D false, + .mmap2_ino_generation_valid =3D false, + { + .size =3D 0, + } +}; =20 -void __dso__inject_id(struct dso *dso, const struct dso_id *id) +void __dso__improve_id(struct dso *dso, const struct dso_id *id) { struct dsos *dsos =3D dso__dsos(dso); struct dso_id *dso_id =3D dso__id(dso); + bool changed =3D false; =20 /* dsos write lock held by caller. */ =20 - dso_id->maj =3D id->maj; - dso_id->min =3D id->min; - dso_id->ino =3D id->ino; - dso_id->ino_generation =3D id->ino_generation; - - if (dsos) + if (id->mmap2_valid && !dso_id->mmap2_valid) { + dso_id->maj =3D id->maj; + dso_id->min =3D id->min; + dso_id->ino =3D id->ino; + dso_id->mmap2_valid =3D true; + changed =3D true; + } + if (id->mmap2_ino_generation_valid && !dso_id->mmap2_ino_generation_valid= ) { + dso_id->ino_generation =3D id->ino_generation; + dso_id->mmap2_ino_generation_valid =3D true; + changed =3D true; + } + if (build_id__is_defined(&id->build_id) && !build_id__is_defined(&dso_id-= >build_id)) { + dso_id->build_id =3D id->build_id; + changed =3D true; + } + if (changed && dsos) dsos->sorted =3D false; } =20 int dso_id__cmp(const struct dso_id *a, const struct dso_id *b) { - /* - * The second is always dso->id, so zeroes if not set, assume passing - * NULL for a means a zeroed id - */ - if (dso_id__empty(a) || dso_id__empty(b)) + if (a =3D=3D &dso_id_empty || b =3D=3D &dso_id_empty) { + /* There is no valid data to compare so the comparison always returns id= entical. */ return 0; + } =20 return __dso_id__cmp(a, b); } @@ -1533,7 +1545,6 @@ struct dso *dso__new_id(const char *name, const struc= t dso_id *id) dso->loaded =3D 0; dso->rel =3D 0; dso->sorted_by_name =3D 0; - dso->has_build_id =3D 0; dso->has_srcline =3D 1; dso->a2l_fails =3D 1; dso->kernel =3D DSO_SPACE__USER; @@ -1638,15 +1649,14 @@ int dso__swap_init(struct dso *dso, unsigned char e= idata) return 0; } =20 -void dso__set_build_id(struct dso *dso, struct build_id *bid) +void dso__set_build_id(struct dso *dso, const struct build_id *bid) { - RC_CHK_ACCESS(dso)->bid =3D *bid; - RC_CHK_ACCESS(dso)->has_build_id =3D 1; + dso__id(dso)->build_id =3D *bid; } =20 -bool dso__build_id_equal(const struct dso *dso, struct build_id *bid) +bool dso__build_id_equal(const struct dso *dso, const struct build_id *bid) { - const struct build_id *dso_bid =3D dso__bid_const(dso); + const struct build_id *dso_bid =3D dso__bid(dso); =20 if (dso_bid->size > bid->size && dso_bid->size =3D=3D BUILD_ID_SIZE) { /* @@ -1665,18 +1675,20 @@ bool dso__build_id_equal(const struct dso *dso, str= uct build_id *bid) void dso__read_running_kernel_build_id(struct dso *dso, struct machine *ma= chine) { char path[PATH_MAX]; + struct build_id bid =3D { .size =3D 0, }; =20 if (machine__is_default_guest(machine)) return; sprintf(path, "%s/sys/kernel/notes", machine->root_dir); - if (sysfs__read_build_id(path, dso__bid(dso)) =3D=3D 0) - dso__set_has_build_id(dso); + sysfs__read_build_id(path, &bid); + dso__set_build_id(dso, &bid); } =20 int dso__kernel_module_get_build_id(struct dso *dso, const char *root_dir) { char filename[PATH_MAX]; + struct build_id bid =3D { .size =3D 0, }; /* * kernel module short names are of the form "[module]" and * we need just "module" here. @@ -1687,9 +1699,8 @@ int dso__kernel_module_get_build_id(struct dso *dso, "%s/sys/module/%.*s/notes/.note.gnu.build-id", root_dir, (int)strlen(name) - 1, name); =20 - if (sysfs__read_build_id(filename, dso__bid(dso)) =3D=3D 0) - dso__set_has_build_id(dso); - + sysfs__read_build_id(filename, &bid); + dso__set_build_id(dso, &bid); return 0; } =20 diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index c87564471f9b..3457d713d3c5 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -185,14 +185,33 @@ enum dso_load_errno { #define DSO__DATA_CACHE_SIZE 4096 #define DSO__DATA_CACHE_MASK ~(DSO__DATA_CACHE_SIZE - 1) =20 -/* - * Data about backing storage DSO, comes from PERF_RECORD_MMAP2 meta events +/** + * struct dso_id + * + * Data about backing storage DSO, comes from PERF_RECORD_MMAP2 meta event= s, + * reading from /proc/pid/maps or synthesis of build_ids from DSOs. Possib= ly + * incomplete at any particular use. */ struct dso_id { - u32 maj; - u32 min; - u64 ino; - u64 ino_generation; + /* Data related to the mmap2 event or read from /proc/pid/maps. */ + struct { + u32 maj; + u32 min; + u64 ino; + u64 ino_generation; + }; + /** @mmap2_valid: Are the maj, min and ino fields valid? */ + bool mmap2_valid; + /** + * @mmap2_ino_generation_valid: Is the ino_generation valid? Generally + * false for /proc/pid/maps mmap event. + */ + bool mmap2_ino_generation_valid; + /** + * @build_id: A possibly populated build_id. build_id__is_defined checks + * whether it is populated. + */ + struct build_id build_id; }; =20 struct dso_cache { @@ -243,7 +262,6 @@ DECLARE_RC_STRUCT(dso) { u64 addr; struct symbol *symbol; } last_find_result; - struct build_id bid; u64 text_offset; u64 text_end; const char *short_name; @@ -276,7 +294,6 @@ DECLARE_RC_STRUCT(dso) { enum dso_swap_type needs_swap:2; bool is_kmod:1; u8 adjust_symbols:1; - u8 has_build_id:1; u8 header_build_id:1; u8 has_srcline:1; u8 hit:1; @@ -292,6 +309,9 @@ DECLARE_RC_STRUCT(dso) { }; =20 extern struct mutex _dso__data_open_lock; +extern const struct dso_id dso_id_empty; + +int dso_id__cmp(const struct dso_id *a, const struct dso_id *b); =20 /* dso__for_each_symbol - iterate over the symbols of given type * @@ -362,31 +382,11 @@ static inline void dso__set_auxtrace_cache(struct dso= *dso, struct auxtrace_cach RC_CHK_ACCESS(dso)->auxtrace_cache =3D cache; } =20 -static inline struct build_id *dso__bid(struct dso *dso) -{ - return &RC_CHK_ACCESS(dso)->bid; -} - -static inline const struct build_id *dso__bid_const(const struct dso *dso) -{ - return &RC_CHK_ACCESS(dso)->bid; -} - static inline struct dso_bpf_prog *dso__bpf_prog(struct dso *dso) { return &RC_CHK_ACCESS(dso)->bpf_prog; } =20 -static inline bool dso__has_build_id(const struct dso *dso) -{ - return RC_CHK_ACCESS(dso)->has_build_id; -} - -static inline void dso__set_has_build_id(struct dso *dso) -{ - RC_CHK_ACCESS(dso)->has_build_id =3D true; -} - static inline bool dso__has_srcline(const struct dso *dso) { return RC_CHK_ACCESS(dso)->has_srcline; @@ -462,6 +462,16 @@ static inline const struct dso_id *dso__id_const(const= struct dso *dso) return &RC_CHK_ACCESS(dso)->id; } =20 +static inline const struct build_id *dso__bid(const struct dso *dso) +{ + return &dso__id_const(dso)->build_id; +} + +static inline bool dso__has_build_id(const struct dso *dso) +{ + return build_id__is_defined(dso__bid(dso)); +} + static inline struct rb_root_cached *dso__inlined_nodes(struct dso *dso) { return &RC_CHK_ACCESS(dso)->inlined_nodes; @@ -699,9 +709,6 @@ static inline void dso__set_text_offset(struct dso *dso= , u64 val) RC_CHK_ACCESS(dso)->text_offset =3D val; } =20 -int dso_id__cmp(const struct dso_id *a, const struct dso_id *b); -bool dso_id__empty(const struct dso_id *id); - struct dso *dso__new_id(const char *name, const struct dso_id *id); struct dso *dso__new(const char *name); void dso__delete(struct dso *dso); @@ -709,7 +716,7 @@ void dso__delete(struct dso *dso); int dso__cmp_id(struct dso *a, struct dso *b); void dso__set_short_name(struct dso *dso, const char *name, bool name_allo= cated); void dso__set_long_name(struct dso *dso, const char *name, bool name_alloc= ated); -void __dso__inject_id(struct dso *dso, const struct dso_id *id); +void __dso__improve_id(struct dso *dso, const struct dso_id *id); =20 int dso__name_len(const struct dso *dso); =20 @@ -739,8 +746,8 @@ void dso__sort_by_name(struct dso *dso); =20 int dso__swap_init(struct dso *dso, unsigned char eidata); =20 -void dso__set_build_id(struct dso *dso, struct build_id *bid); -bool dso__build_id_equal(const struct dso *dso, struct build_id *bid); +void dso__set_build_id(struct dso *dso, const struct build_id *bid); +bool dso__build_id_equal(const struct dso *dso, const struct build_id *bid= ); void dso__read_running_kernel_build_id(struct dso *dso, struct machine *machine); int dso__kernel_module_get_build_id(struct dso *dso, const char *root_dir); diff --git a/tools/perf/util/dsos.c b/tools/perf/util/dsos.c index b2172632b3cd..e239a3fa2896 100644 --- a/tools/perf/util/dsos.c +++ b/tools/perf/util/dsos.c @@ -72,6 +72,7 @@ static int dsos__read_build_ids_cb(struct dso *dso, void = *data) { struct dsos__read_build_ids_cb_args *args =3D data; struct nscookie nsc; + struct build_id bid =3D { .size =3D 0, }; =20 if (args->with_hits && !dso__hit(dso) && !dso__is_vdso(dso)) return 0; @@ -80,15 +81,15 @@ static int dsos__read_build_ids_cb(struct dso *dso, voi= d *data) return 0; } nsinfo__mountns_enter(dso__nsinfo(dso), &nsc); - if (filename__read_build_id(dso__long_name(dso), dso__bid(dso)) > 0) { + if (filename__read_build_id(dso__long_name(dso), &bid) > 0) { + dso__set_build_id(dso, &bid); args->have_build_id =3D true; - dso__set_has_build_id(dso); } else if (errno =3D=3D ENOENT && dso__nsinfo(dso)) { char *new_name =3D dso__filename_with_chroot(dso, dso__long_name(dso)); =20 - if (new_name && filename__read_build_id(new_name, dso__bid(dso)) > 0) { + if (new_name && filename__read_build_id(new_name, &bid) > 0) { + dso__set_build_id(dso, &bid); args->have_build_id =3D true; - dso__set_has_build_id(dso); } free(new_name); } @@ -284,7 +285,7 @@ struct dso *dsos__find(struct dsos *dsos, const char *n= ame, bool cmp_short) struct dso *res; =20 down_read(&dsos->lock); - res =3D __dsos__find_id(dsos, name, NULL, cmp_short, /*write_locked=3D*/f= alse); + res =3D __dsos__find_id(dsos, name, &dso_id_empty, cmp_short, /*write_loc= ked=3D*/false); up_read(&dsos->lock); return res; } @@ -341,8 +342,8 @@ static struct dso *__dsos__findnew_id(struct dsos *dsos= , const char *name, const { struct dso *dso =3D __dsos__find_id(dsos, name, id, false, /*write_locked= =3D*/true); =20 - if (dso && dso_id__empty(dso__id(dso)) && !dso_id__empty(id)) - __dso__inject_id(dso, id); + if (dso) + __dso__improve_id(dso, id); =20 return dso ? dso : __dsos__addnew_id(dsos, name, id); } @@ -433,7 +434,8 @@ struct dso *dsos__findnew_module_dso(struct dsos *dsos, =20 down_write(&dsos->lock); =20 - dso =3D __dsos__find_id(dsos, m->name, NULL, /*cmp_short=3D*/true, /*writ= e_locked=3D*/true); + dso =3D __dsos__find_id(dsos, m->name, &dso_id_empty, /*cmp_short=3D*/tru= e, + /*write_locked=3D*/true); if (dso) { up_write(&dsos->lock); return dso; diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index b048165b10c1..04062148a9ec 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -1696,21 +1696,21 @@ int machine__process_mmap2_event(struct machine *ma= chine, { struct thread *thread; struct map *map; - struct dso_id dso_id =3D { - .maj =3D event->mmap2.maj, - .min =3D event->mmap2.min, - .ino =3D event->mmap2.ino, - .ino_generation =3D event->mmap2.ino_generation, - }; - struct build_id __bid, *bid =3D NULL; + struct dso_id dso_id =3D dso_id_empty; int ret =3D 0; =20 if (dump_trace) perf_event__fprintf_mmap2(event, stdout); =20 if (event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID) { - bid =3D &__bid; - build_id__init(bid, event->mmap2.build_id, event->mmap2.build_id_size); + build_id__init(&dso_id.build_id, event->mmap2.build_id, event->mmap2.bui= ld_id_size); + } else { + dso_id.maj =3D event->mmap2.maj; + dso_id.min =3D event->mmap2.min; + dso_id.ino =3D event->mmap2.ino; + dso_id.ino_generation =3D event->mmap2.ino_generation; + dso_id.mmap2_valid =3D true; + dso_id.mmap2_ino_generation_valid =3D true; } =20 if (sample->cpumode =3D=3D PERF_RECORD_MISC_GUEST_KERNEL || @@ -1722,7 +1722,7 @@ int machine__process_mmap2_event(struct machine *mach= ine, }; =20 strlcpy(xm.name, event->mmap2.filename, KMAP_NAME_LEN); - ret =3D machine__process_kernel_mmap_event(machine, &xm, bid); + ret =3D machine__process_kernel_mmap_event(machine, &xm, &dso_id.build_i= d); if (ret < 0) goto out_problem; return 0; @@ -1736,7 +1736,7 @@ int machine__process_mmap2_event(struct machine *mach= ine, map =3D map__new(machine, event->mmap2.start, event->mmap2.len, event->mmap2.pgoff, &dso_id, event->mmap2.prot, - event->mmap2.flags, bid, + event->mmap2.flags, event->mmap2.filename, thread); =20 if (map =3D=3D NULL) @@ -1794,8 +1794,8 @@ int machine__process_mmap_event(struct machine *machi= ne, union perf_event *event prot =3D PROT_EXEC; =20 map =3D map__new(machine, event->mmap.start, - event->mmap.len, event->mmap.pgoff, - NULL, prot, 0, NULL, event->mmap.filename, thread); + event->mmap.len, event->mmap.pgoff, + &dso_id_empty, prot, /*flags=3D*/0, event->mmap.filename, thread); =20 if (map =3D=3D NULL) goto out_problem_map; @@ -3157,7 +3157,7 @@ struct dso *machine__findnew_dso_id(struct machine *m= achine, const char *filenam =20 struct dso *machine__findnew_dso(struct machine *machine, const char *file= name) { - return machine__findnew_dso_id(machine, filename, NULL); + return machine__findnew_dso_id(machine, filename, &dso_id_empty); } =20 char *machine__resolve_kernel_addr(void *vmachine, unsigned long long *add= rp, char **modp) diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 0f6b185f9589..b46c68c24d1c 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -120,8 +120,8 @@ static void map__init(struct map *map, u64 start, u64 e= nd, u64 pgoff, } =20 struct map *map__new(struct machine *machine, u64 start, u64 len, - u64 pgoff, struct dso_id *id, - u32 prot, u32 flags, struct build_id *bid, + u64 pgoff, const struct dso_id *id, + u32 prot, u32 flags, char *filename, struct thread *thread) { struct map *result; @@ -132,7 +132,7 @@ struct map *map__new(struct machine *machine, u64 start= , u64 len, map =3D zalloc(sizeof(*map)); if (ADD_RC_CHK(result, map)) { char newfilename[PATH_MAX]; - struct dso *dso, *header_bid_dso; + struct dso *dso; int anon, no_dso, vdso, android; =20 android =3D is_android_lib(filename); @@ -189,16 +189,15 @@ struct map *map__new(struct machine *machine, u64 sta= rt, u64 len, dso__set_nsinfo(dso, nsi); mutex_unlock(dso__lock(dso)); =20 - if (build_id__is_defined(bid)) { - dso__set_build_id(dso, bid); - } else { + if (!build_id__is_defined(&id->build_id)) { /* * If the mmap event had no build ID, search for an existing dso from t= he * build ID header by name. Otherwise only the dso loaded at the time of * reading the header will have the build ID set and all future mmaps w= ill * have it missing. */ - header_bid_dso =3D dsos__find(&machine->dsos, filename, false); + struct dso *header_bid_dso =3D dsos__find(&machine->dsos, filename, fal= se); + if (header_bid_dso && dso__header_build_id(header_bid_dso)) { dso__set_build_id(dso, dso__bid(header_bid_dso)); dso__set_header_build_id(dso, 1); diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index 4262f5a143be..9cadf533a561 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h @@ -173,11 +173,10 @@ struct thread; __map__for_each_symbol_by_name(map, sym_name, (pos), idx) =20 struct dso_id; -struct build_id; =20 struct map *map__new(struct machine *machine, u64 start, u64 len, - u64 pgoff, struct dso_id *id, u32 prot, u32 flags, - struct build_id *bid, char *filename, struct thread *thread); + u64 pgoff, const struct dso_id *id, u32 prot, u32 flags, + char *filename, struct thread *thread); struct map *map__new2(u64 start, struct dso *dso); void map__delete(struct map *map); struct map *map__clone(struct map *map); diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 594b75ca95bf..d20b980d5052 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -1709,22 +1709,27 @@ sort__dcacheline_cmp(struct hist_entry *left, struc= t hist_entry *right) if (rc) return rc; /* - * Addresses with no major/minor numbers are assumed to be + * Addresses with no major/minor numbers or build ID are assumed to be * anonymous in userspace. Sort those on pid then address. * * The kernel and non-zero major/minor mapped areas are * assumed to be unity mapped. Sort those on address. */ + if (left->cpumode !=3D PERF_RECORD_MISC_KERNEL && (map__flags(l_map) & MA= P_SHARED) =3D=3D 0) { + const struct dso_id *dso_id =3D dso__id_const(l_dso); =20 - if ((left->cpumode !=3D PERF_RECORD_MISC_KERNEL) && - (!(map__flags(l_map) & MAP_SHARED)) && !dso__id(l_dso)->maj && !dso__= id(l_dso)->min && - !dso__id(l_dso)->ino && !dso__id(l_dso)->ino_generation) { - /* userspace anonymous */ + if (!dso_id->mmap2_valid) + dso_id =3D dso__id_const(r_dso); =20 - if (thread__pid(left->thread) > thread__pid(right->thread)) - return -1; - if (thread__pid(left->thread) < thread__pid(right->thread)) - return 1; + if (!build_id__is_defined(&dso_id->build_id) && + (!dso_id->mmap2_valid || (dso_id->maj =3D=3D 0 && dso_id->min =3D=3D= 0))) { + /* userspace anonymous */ + + if (thread__pid(left->thread) > thread__pid(right->thread)) + return -1; + if (thread__pid(left->thread) < thread__pid(right->thread)) + return 1; + } } =20 addr: @@ -1749,6 +1754,7 @@ static int hist_entry__dcacheline_snprintf(struct his= t_entry *he, char *bf, if (he->mem_info) { struct map *map =3D mem_info__daddr(he->mem_info)->ms.map; struct dso *dso =3D map ? map__dso(map) : NULL; + const struct dso_id *dso_id =3D dso ? dso__id_const(dso) : &dso_id_empty; =20 addr =3D cl_address(mem_info__daddr(he->mem_info)->al_addr, chk_double_c= l); ms =3D &mem_info__daddr(he->mem_info)->ms; @@ -1757,8 +1763,7 @@ static int hist_entry__dcacheline_snprintf(struct his= t_entry *he, char *bf, if ((he->cpumode !=3D PERF_RECORD_MISC_KERNEL) && map && !(map__prot(map) & PROT_EXEC) && (map__flags(map) & MAP_SHARED) && - (dso__id(dso)->maj || dso__id(dso)->min || dso__id(dso)->ino || - dso__id(dso)->ino_generation)) + (!dso_id->mmap2_valid || (dso_id->maj =3D=3D 0 && dso_id->min =3D= =3D 0))) level =3D 's'; else if (!map) level =3D 'X'; diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index b7ebee95536f..69b98023ce74 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -372,7 +372,7 @@ static void perf_record_mmap2__read_build_id(struct per= f_record_mmap2 *event, struct nsinfo *nsi; struct nscookie nc; struct dso *dso =3D NULL; - struct dso_id id; + struct dso_id dso_id =3D dso_id_empty; int rc; =20 if (is_kernel) { @@ -380,12 +380,18 @@ static void perf_record_mmap2__read_build_id(struct p= erf_record_mmap2 *event, goto out; } =20 - id.maj =3D event->maj; - id.min =3D event->min; - id.ino =3D event->ino; - id.ino_generation =3D event->ino_generation; + if (event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID) { + build_id__init(&dso_id.build_id, event->build_id, event->build_id_size); + } else { + dso_id.maj =3D event->maj; + dso_id.min =3D event->min; + dso_id.ino =3D event->ino; + dso_id.ino_generation =3D event->ino_generation; + dso_id.mmap2_valid =3D true; + dso_id.mmap2_ino_generation_valid =3D true; + }; =20 - dso =3D dsos__findnew_id(&machine->dsos, event->filename, &id); + dso =3D dsos__findnew_id(&machine->dsos, event->filename, &dso_id); if (dso && dso__has_build_id(dso)) { bid =3D *dso__bid(dso); rc =3D 0; --=20 2.49.0.901.g37484f566f-goog From nobody Sun Feb 8 05:42:06 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 2EA6E20E323 for ; Mon, 28 Apr 2025 21:34:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745876069; cv=none; b=ZNOlJ8jIDjrEmtsKaxeecUBseRy1aa7WPUszWuxAwSrDBzkwoJeeaTzJ/12NHfkbIG59P1J2I+yfzLZ89bgJP/1QWDwDrM0+w+Ctnz3bBpKACXSKIl1hVfDsN90QfM/M0ke11YT1vn1FfStO4sX/mevvA0GFl9cr1b8ajjdx3Ww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745876069; c=relaxed/simple; bh=V40jgn89oCqUj2APh4IzT55mkyQEVKPYbZ7P8iJSJCA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=T17gQmrvml4lQgR6HvTS3vI9eG68BHKy31H53C68G5oz0l9XDStpgsq45HZjdkFZHynZ7B5ehkgLN6s0RUOfJYdXh2k+hb5ZbnjGxJ+ZTOpWOI1InFYVLtoPlP/1hZLhynidIqnt4dvB1goeF0NhQGTCCGii8pceeh9qKwQUPG4= 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=EOmuHLiX; arc=none smtp.client-ip=209.85.216.73 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="EOmuHLiX" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-30364fc706fso4238940a91.3 for ; Mon, 28 Apr 2025 14:34:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745876067; x=1746480867; 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=xuESyA5cUoWs5jJqB9j/HDlv/ORhTzd9f0YGR++Z5O8=; b=EOmuHLiXyOf9f64AcXuZd4ygYCP3tiD8Uoi12dAox0UBmpa7MGe2FqQkoSdcoHXrXf 2r88IEzI3JwWSyJxUUmlMHJ4nI8wrf0CFsCBwj0iOkMHyApAkhOfBvaAjiQW7alJIeBR n7a14YEqHfJqHm1wQ/D0/4xOJd+f+XOEjDzxdno1JhhQ1m7vZnou6m4mmRYtwcs6wc3V hH0jy8goTL99lth+bWyfsibykAylTSS+wdjCnbeETasx6VBsqZV+Yejf6v1TryIdgvcm kolhWy/duS/H+J1dDbWxF8ioRBXK3kAzOR3F/rFczChqKBblJHKG5WM7z+Bt+4WSKqRo Xyow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745876067; x=1746480867; 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=xuESyA5cUoWs5jJqB9j/HDlv/ORhTzd9f0YGR++Z5O8=; b=pKyOmMNHIcIT93iRBusQUEYbGr0nrpXXcdWRyg+o8ruzgOMKa2OVgBKi7JNeqeKUa3 wfT8W0GGgLkwBLNRAIiXmlu73EK6DDB5AE/KrBzT7bpgSv13iDFGW8Cf7IP3xPgha6D3 FdljbG4FmrNk5gs4qUNQHl2TZPmz2EPGFiedPPPuYw4z6VDvku0Jc1C2YJYKcRXCDYtR 0wvE++BgfNXYRmozaTOolKlAy7aPFGI+SYO1p1Co1ifQk+IAxIFSmhfKDtbBSahDhkhL U6iDtzvwl8AfaS7DJg1MQGtplK8QAgS71rDk9oFEmPmW1/a6XkEVhjrXrqFcVZE51vfI i81A== X-Forwarded-Encrypted: i=1; AJvYcCWP8KidAQZTjc/XsbNcSxke+NXc131Gmp4ikrM1IsSxxSDjPMEthq4kHTNbIR470ycABz1/2+1jeRranLw=@vger.kernel.org X-Gm-Message-State: AOJu0YwN9Yidi1ch6X1cBrPgvZnj0tl8TYPv4QKNRVA/3UeC/Qg9NJ/0 m2U8H5Z1SENRJM59dolcRZcNoO1KfChJup0QforslLwMVKUZzu6QOI98Bp20FyrkGHqN/L6f08y kdWCwEg== X-Google-Smtp-Source: AGHT+IFQ1/vv1A5xPiEdUGqODpwKWqIzLynqCqdF6Urj40CzB1mXE9SuSSMssTrB3nCrHwtPn4/85q2/eLLC X-Received: from pjd16.prod.google.com ([2002:a17:90b:54d0:b0:2ea:5084:5297]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5403:b0:2f9:c139:b61f with SMTP id 98e67ed59e1d1-30a220c4f94mr1392825a91.14.1745876067485; Mon, 28 Apr 2025 14:34:27 -0700 (PDT) Date: Mon, 28 Apr 2025 14:34:07 -0700 In-Reply-To: <20250428213409.1417584-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: <20250428213409.1417584-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.901.g37484f566f-goog Message-ID: <20250428213409.1417584-9-irogers@google.com> Subject: [PATCH v3 8/9] perf jitdump: Directly mark the jitdump DSO 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 , Athira Rajeev , Kajol Jain , Li Huafei , "Steinar H. Gunderson" , James Clark , Stephen Brennan , Andi Kleen , Dmitry Vyukov , Zhongqiu Han , Yicong Yang , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Zixian Cai , Steve Clevenger , Thomas Falcon , Martin Liska , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The DSO being generated was being accessed through a thread's maps, this is unnecessary as the dso can just be directly found. This avoids problems with passing a NULL evsel which may be inspected to determine properties of a callchain when using the buildid DSO marking code. Signed-off-by: Ian Rogers --- tools/perf/util/jitdump.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c index 624964f01b5f..b062b1f234b6 100644 --- a/tools/perf/util/jitdump.c +++ b/tools/perf/util/jitdump.c @@ -14,9 +14,9 @@ #include #include =20 -#include "build-id.h" #include "event.h" #include "debug.h" +#include "dso.h" #include "evlist.h" #include "namespaces.h" #include "symbol.h" @@ -531,9 +531,22 @@ static int jit_repipe_code_load(struct jit_buf_desc *j= d, union jr_entry *jr) /* * mark dso as use to generate buildid in the header */ - if (!ret) - build_id__mark_dso_hit(tool, event, &sample, NULL, jd->machine); - + if (!ret) { + struct dso_id dso_id =3D { + { + .maj =3D event->mmap2.maj, + .min =3D event->mmap2.min, + .ino =3D event->mmap2.ino, + .ino_generation =3D event->mmap2.ino_generation, + }, + .mmap2_valid =3D true, + .mmap2_ino_generation_valid =3D true, + }; + struct dso *dso =3D machine__findnew_dso_id(jd->machine, filename, &dso_= id); + + if (dso) + dso__set_hit(dso); + } out: perf_sample__exit(&sample); free(event); --=20 2.49.0.901.g37484f566f-goog From nobody Sun Feb 8 05:42:06 2026 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (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 1F3BE214A68 for ; Mon, 28 Apr 2025 21:34:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745876071; cv=none; b=tf2ge6otfurnmzYJo5Y2VphCgV7ZmyTw0po/lcx1A/0VlLHUgnF6JpteKMEp+rMC7GQ0joWZaxzzb+2KI0NOCgnl4TxGmHrI5oHxK3EiLtCQFoRuZpBEXjUIGYj4arEPhyxqJDSNvzX8RJpTaOo92R/bVQxFCn4KHOzUZr/X9PU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745876071; c=relaxed/simple; bh=PScFL3QKHD83Kd+8sQnLhjHRKeKqkKT+m+cpgcoH03w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Nl0piOSLlEIjbu2emhgFFdlkMVVUL8J4YZCXz5ajgl/6LdhP+NNNdZrlcwtXFku/YtfUaG3iefjO5gtZXf0i5Ijkl/xA2fTI0gxvNa7M3pz04Tgx8cpy8E3XhoIaqubOzAyrg4DYVlXZZ8Az3CFc7z7xlSSFNjLvdmvFE1QAfU0= 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=ph7B7qQj; arc=none smtp.client-ip=209.85.210.202 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="ph7B7qQj" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-736c1ea954fso2692796b3a.3 for ; Mon, 28 Apr 2025 14:34:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745876069; x=1746480869; 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=HSs+BEdvbnIfY2dq99UXmMP4Buukql0Gb5bTAHvwkAg=; b=ph7B7qQjAbfUgFsmG3luIKpNwWX2iH18m3Ed060jtsRX79wbQP2yqEG8aYXm5gqZxv aiFRInz3GNHnPleU1IQfkpAjGZsnvsrOXMBzxf7xt3PofEHJFU4hiWr7Jfa3kL5ptRHv NwdEjJxiRhgMvyM3swknIffDPcVZTiJF2N6aTqu9WimVepqW9F3xIT9ELF4HB7sEE677 1UebDnwlUfdBj2X1V39FpIf/57KBf8k3KLD0LawTHcVnME1YA7xpQlB2+5Cq1a5B5VPC 73GpDNe/Yrad7+2BNqqP2+5Aag3lR/MNFTIRk3pIEiH3Gts4fPg5ML/GR6BjEoMV5IHY qmlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745876069; x=1746480869; 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=HSs+BEdvbnIfY2dq99UXmMP4Buukql0Gb5bTAHvwkAg=; b=bWa/0aeqxsz4xEW3TOi29dN8hYTlNOsA8wwuI6gGBGVIa0f9DpUdRLL6KiwKbF+1IA E9rHLZ8kYavj5u6azOr/+CGGxbi9Wgw7oqz8aDinqUIU6zulBdumgxNjE8nhyr7OB/lY OTpGVQNXYU4XoEnYIB6/+x9OzQxpkALoFRNULkKA95h//lVp67xwur3TfHUhggUOxXVz 73YarvXnVefbGM1SZAxbzgtBcknuU69Ty0bUizlNlJy4yYM+6WGTKRwNJCJwBmNozIbU xNw1mb9ONuitpKRV9rVukFiwwKUtUcA8/Lg7Ce5nNUkTKvATfpbHAjklgg/zwnWXiGgq ysLA== X-Forwarded-Encrypted: i=1; AJvYcCV9SLZthPQZtmWUFpv6LjJVZjcpgofH3m5zI/HfzSgZ0PeMvV8SK4DRV/FGbfgCwVdVppf7Xa18s7KR39s=@vger.kernel.org X-Gm-Message-State: AOJu0Ywc3/GVSMPgl48z8Mb2nL8xyai46Bl4JPcIdooM1sAPth6TFjKl gp/vMeuh2veLY7Om+lMgkC8IuVHILFP8nald5Bn5Ri04InA5bY+6xKAFzabjCfx7BC/gvW+TPeM IipFWNA== X-Google-Smtp-Source: AGHT+IFcsBuxLiRKFxo6cxliw7p+n3n5l2JnUxq7Z0GFhsWt1MiIhCDgVcaUM/hovjHWg7X6AItekzXO1Bba X-Received: from pfoc2.prod.google.com ([2002:aa7:8802:0:b0:73c:26bd:133c]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:9282:b0:736:5753:12f7 with SMTP id d2e1a72fcca58-74028f9382amr954698b3a.3.1745876069395; Mon, 28 Apr 2025 14:34:29 -0700 (PDT) Date: Mon, 28 Apr 2025 14:34:08 -0700 In-Reply-To: <20250428213409.1417584-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: <20250428213409.1417584-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.901.g37484f566f-goog Message-ID: <20250428213409.1417584-10-irogers@google.com> Subject: [PATCH v3 9/9] perf record: Make --buildid-mmap the default 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 , Athira Rajeev , Kajol Jain , Li Huafei , "Steinar H. Gunderson" , James Clark , Stephen Brennan , Andi Kleen , Dmitry Vyukov , Zhongqiu Han , Yicong Yang , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Zixian Cai , Steve Clevenger , Thomas Falcon , Martin Liska , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Support for build IDs in mmap2 perf events has been present since Linux v5.12: https://lore.kernel.org/lkml/20210219194619.1780437-1-acme@kernel.org/ Build ID mmap events don't avoid the need to inject build IDs for DSO touched by samples as the build ID cache is populated by perf record. They can avoid some cases of symbol mis-resolution caused by the file system changing from when a sample occurred and when the DSO is sought. To disable build ID scanning Unlike the --buildid-mmap option, this doesn't disable the build ID cache but it does disable the processing of samples looking for DSOs to inject build IDs for. To disable the build ID cache the -B (--no-buildid) option should be used. Making this option the default was raised on the list in: https://lore.kernel.org/linux-perf-users/CAP-5=3DfXP7jN_QrGUcd55_QH5J-Y-FCa= J6=3DNaHVtyx0oyNh8_-Q@mail.gmail.com/ Signed-off-by: Ian Rogers --- tools/perf/builtin-record.c | 33 +++++++++++++++++++----------- tools/perf/util/symbol_conf.h | 2 +- tools/perf/util/synthetic-events.c | 16 +++++++-------- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index ba20bf7c011d..7b64013ba8c0 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -169,6 +169,7 @@ struct record { bool no_buildid_cache_set; bool buildid_all; bool buildid_mmap; + bool buildid_mmap_set; bool timestamp_filename; bool timestamp_boundary; bool off_cpu; @@ -1795,6 +1796,7 @@ record__finish_output(struct record *rec) data->dir.files[i].size =3D lseek(data->dir.files[i].fd, 0, SEEK_CUR); } =20 + /* Buildid scanning disabled or build ID in kernel and synthesized map ev= ents. */ if (!rec->no_buildid) { process_buildids(rec); =20 @@ -2966,6 +2968,8 @@ static int perf_record_config(const char *var, const = char *value, void *cb) rec->no_buildid =3D true; else if (!strcmp(value, "mmap")) rec->buildid_mmap =3D true; + else if (!strcmp(value, "no-mmap")) + rec->buildid_mmap =3D false; else return -1; return 0; @@ -3349,6 +3353,7 @@ static struct record record =3D { .ctl_fd_ack =3D -1, .synth =3D PERF_SYNTH_ALL, }, + .buildid_mmap =3D true, }; =20 const char record_callchain_help[] =3D CALLCHAIN_RECORD_HELP @@ -3514,8 +3519,8 @@ static struct option __record_options[] =3D { "file", "vmlinux pathname"), OPT_BOOLEAN(0, "buildid-all", &record.buildid_all, "Record build-id of all DSOs regardless of hits"), - OPT_BOOLEAN(0, "buildid-mmap", &record.buildid_mmap, - "Record build-id in map events"), + OPT_BOOLEAN_SET(0, "buildid-mmap", &record.buildid_mmap, &record.buildid_= mmap_set, + "Legacy record build-id in map events option which is now the default. = Behaves indentically to --no-buildid. Disable with --no-buildid-mmap"), OPT_BOOLEAN(0, "timestamp-filename", &record.timestamp_filename, "append timestamp to output filename"), OPT_BOOLEAN(0, "timestamp-boundary", &record.timestamp_boundary, @@ -4042,19 +4047,23 @@ int cmd_record(int argc, const char **argv) record.opts.record_switch_events =3D true; } =20 + if (!rec->buildid_mmap) { + pr_debug("Disabling build id in synthesized mmap2 events.\n"); + symbol_conf.no_buildid_mmap2 =3D true; + } else if (rec->buildid_mmap_set) { + /* + * Explicitly passing --buildid-mmap disables buildid processing + * and cache generation. + */ + rec->no_buildid =3D true; + } + if (rec->buildid_mmap && !perf_can_record_build_id()) { + pr_warning("Missing support for build id in kernel mmap events. Disable = this warning with --no-buildid-mmap\n"); + rec->buildid_mmap =3D false; + } if (rec->buildid_mmap) { - if (!perf_can_record_build_id()) { - pr_err("Failed: no support to record build id in mmap events, update yo= ur kernel.\n"); - err =3D -EINVAL; - goto out_opts; - } - pr_debug("Enabling build id in mmap2 events.\n"); - /* Enable mmap build id synthesizing. */ - symbol_conf.buildid_mmap2 =3D true; /* Enable perf_event_attr::build_id bit. */ rec->opts.build_id =3D true; - /* Disable build id cache. */ - rec->no_buildid =3D true; } =20 if (rec->opts.record_cgroup && !perf_can_record_cgroup()) { diff --git a/tools/perf/util/symbol_conf.h b/tools/perf/util/symbol_conf.h index cd9aa82c7d5a..7a80d2c14d9b 100644 --- a/tools/perf/util/symbol_conf.h +++ b/tools/perf/util/symbol_conf.h @@ -43,7 +43,7 @@ struct symbol_conf { report_individual_block, inline_name, disable_add2line_warn, - buildid_mmap2, + no_buildid_mmap2, guest_code, lazy_load_kernel_maps, keep_exited_threads, diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index 69b98023ce74..638d7dd7fa4b 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -532,7 +532,7 @@ int perf_event__synthesize_mmap_events(const struct per= f_tool *tool, event->mmap2.pid =3D tgid; event->mmap2.tid =3D pid; =20 - if (symbol_conf.buildid_mmap2) + if (!symbol_conf.no_buildid_mmap2) perf_record_mmap2__read_build_id(&event->mmap2, machine, false); =20 if (perf_tool__process_synth_event(tool, event, machine, process) !=3D 0= ) { @@ -690,7 +690,7 @@ static int perf_event__synthesize_modules_maps_cb(struc= t map *map, void *data) return 0; =20 dso =3D map__dso(map); - if (symbol_conf.buildid_mmap2) { + if (!symbol_conf.no_buildid_mmap2) { size =3D PERF_ALIGN(dso__long_name_len(dso) + 1, sizeof(u64)); event->mmap2.header.type =3D PERF_RECORD_MMAP2; event->mmap2.header.size =3D (sizeof(event->mmap2) - @@ -734,9 +734,9 @@ int perf_event__synthesize_modules(const struct perf_to= ol *tool, perf_event__han .process =3D process, .machine =3D machine, }; - size_t size =3D symbol_conf.buildid_mmap2 - ? sizeof(args.event->mmap2) - : sizeof(args.event->mmap); + size_t size =3D symbol_conf.no_buildid_mmap2 + ? sizeof(args.event->mmap) + : sizeof(args.event->mmap2); =20 args.event =3D zalloc(size + machine->id_hdr_size); if (args.event =3D=3D NULL) { @@ -1124,8 +1124,8 @@ static int __perf_event__synthesize_kernel_mmap(const= struct perf_tool *tool, struct machine *machine) { union perf_event *event; - size_t size =3D symbol_conf.buildid_mmap2 ? - sizeof(event->mmap2) : sizeof(event->mmap); + size_t size =3D symbol_conf.no_buildid_mmap2 ? + sizeof(event->mmap) : sizeof(event->mmap2); struct map *map =3D machine__kernel_map(machine); struct kmap *kmap; int err; @@ -1159,7 +1159,7 @@ static int __perf_event__synthesize_kernel_mmap(const= struct perf_tool *tool, event->header.misc =3D PERF_RECORD_MISC_GUEST_KERNEL; } =20 - if (symbol_conf.buildid_mmap2) { + if (!symbol_conf.no_buildid_mmap2) { size =3D snprintf(event->mmap2.filename, sizeof(event->mmap2.filename), "%s%s", machine->mmap_name, kmap->ref_reloc_sym->name) + 1; size =3D PERF_ALIGN(size, sizeof(u64)); --=20 2.49.0.901.g37484f566f-goog