From nobody Wed Nov 27 04:56:56 2024 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 217B88F64; Sat, 12 Oct 2024 20:47:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728766058; cv=none; b=mgDxbubhtpb7DzxpOO+4RlYoWt3vKIoduHjVEGBtlx4LgVcrpC7mysbKhROhZu6fPy9K6NQ6cqfMOGvvAijHpXhtIkQVlY2ApNZUMC91CJlYWozDAG0W25TONmu+ubPBfsf9lRF4j0R/vK+owzZgj03HPEQz3mF6s3+A+7tjrJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728766058; c=relaxed/simple; bh=jtMttfkYRg3tbpaJDZGsePrF37CI4jeRKhJvIHU4W0A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PQ6TeuaKfs0evdLGmraeCSJT5aUBE9jNVOHI4k6RnxH7jKuQtH3N0v+db9xbbJ5Cs0yPHd6gE9DDgY98au4cSptnMmojAIZ34VOtAoK8wOXm64mXEjJnVXv0d0MplHbftDn44hyBK6VDgGHAhnolZ6oD2igquwa2Hpf6uTho8fE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 13E0A1063; Sat, 12 Oct 2024 13:48:05 -0700 (PDT) Received: from e132581.cambridge.arm.com (e132581.arm.com [10.2.76.71]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EC3173F5A1; Sat, 12 Oct 2024 13:47:33 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Masami Hiramatsu , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v3 1/3] perf probe: Use the MAX_EVENT_NAME_LEN macro Date: Sat, 12 Oct 2024 21:47:23 +0100 Message-Id: <20241012204725.928794-2-leo.yan@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241012204725.928794-1-leo.yan@arm.com> References: <20241012204725.928794-1-leo.yan@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The MAX_EVENT_NAME_LEN macro has been defined in the kernel. Use the same definition in the tool for more readable. Signed-off-by: Leo Yan Acked-by: Masami Hiramatsu (Google) --- tools/perf/util/probe-event.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index a17c9b8a7a79..061a0412dec2 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -51,6 +51,9 @@ =20 #define PERFPROBE_GROUP "probe" =20 +/* Defined in kernel/trace/trace.h */ +#define MAX_EVENT_NAME_LEN 64 + bool probe_event_dry_run; /* Dry run flag */ struct probe_conf probe_conf =3D { .magic_num =3D DEFAULT_PROBE_MAGIC_NUM = }; =20 @@ -2841,7 +2844,7 @@ static int probe_trace_event__set_name(struct probe_t= race_event *tev, bool allow_suffix) { const char *event, *group; - char buf[64]; + char buf[MAX_EVENT_NAME_LEN]; int ret; =20 /* If probe_event or trace_event already have the name, reuse it */ --=20 2.25.1 From nobody Wed Nov 27 04:56:56 2024 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D719314601C; Sat, 12 Oct 2024 20:47:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728766059; cv=none; b=G2xckJr0qwH79ljRItFRVbehQHJYKiT7yFS5aLnGmk2is8X/qEsGPa0bPr6glTuJ8KdDPvuGbi1zRAAn2BpwlS2SbAgALwHzxhhpR/PQer3KymfHAt3vJgkK7DsJxBa+g8iOxuO5pxlrxh8miNR1L161QC5Pzug76ZQDy/LCUm0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728766059; c=relaxed/simple; bh=mOPPJQdHmP4kUdz8+1BXg5f6hCzDQ0wUTMcLWt7uazA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aiFSfokcPmPjO8jsFJWF7dU9E+jcBFOA7+boqCDWRXcIgH/dRHTptaECOg9TGX0oYZWnmNxv+UrPm7aTypF7y21cmpRP9LhNqQCjl8ztpa2HgFoDP2cmBtaptyu9Dfq4ndMn3v4hebIdhGFakb0jjisHIQkAbUvfgMgc82R1W2g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CB60A15A1; Sat, 12 Oct 2024 13:48:06 -0700 (PDT) Received: from e132581.cambridge.arm.com (e132581.arm.com [10.2.76.71]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id AEDF63F5A1; Sat, 12 Oct 2024 13:47:35 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Masami Hiramatsu , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v3 2/3] perf probe: Check group string length Date: Sat, 12 Oct 2024 21:47:24 +0100 Message-Id: <20241012204725.928794-3-leo.yan@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241012204725.928794-1-leo.yan@arm.com> References: <20241012204725.928794-1-leo.yan@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In the kernel, the probe group string length is limited up to MAX_EVENT_NAME_LEN (including the NULL terminator). Check for this limitation and report an error if it is exceeded. Acked-by: Masami Hiramatsu (Google) Signed-off-by: Leo Yan --- tools/perf/util/probe-event.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 061a0412dec2..224ec6818803 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -2868,6 +2868,12 @@ static int probe_trace_event__set_name(struct probe_= trace_event *tev, else group =3D PERFPROBE_GROUP; =20 + if (strlen(group) >=3D MAX_EVENT_NAME_LEN) { + pr_err("Probe group string=3D'%s' is too long (>=3D %d bytes)\n", + group, MAX_EVENT_NAME_LEN); + return -ENOMEM; + } + /* Get an unused new event name */ ret =3D get_new_event_name(buf, sizeof(buf), event, namelist, tev->point.retprobe, allow_suffix); --=20 2.25.1 From nobody Wed Nov 27 04:56:56 2024 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 74CBC19B3FF; Sat, 12 Oct 2024 20:47:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728766060; cv=none; b=o8XL/AECtY9g1qrPyIiUfJ4FpD1a1aXt8ADFm8NIEkwHHhgkbOR3jlQ4ca3dyorCTel3w/kYQRdkiddOq49K3chkC7ImnTSDH+2f6QV3rb/5wJ827VnVHfL+uVxD1kLZeK/MEcectb9PNDllqzwFqQ8emw3U9JvnIwLRCKNDxO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728766060; c=relaxed/simple; bh=5l6ZNlwBN9y39y6jfRciqxVPgNpcILM3bTvUG22cZZI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EASQtDTWVBivXisZ6MkuF9KmHYoYFeubTs7g80BUrD7DDW8yhdzc8FQNlpfmT/3KUazWeMImcvrDbZx7LphDd+1BXOjG2pyZnn77RDv+5O/sEOkbgKrxpIVeVJCkbFQB/s8Ktk+tnMYiky6wSti0UwVBUBHOQV3DcP6cJONlws4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 85B0BDA7; Sat, 12 Oct 2024 13:48:08 -0700 (PDT) Received: from e132581.cambridge.arm.com (e132581.arm.com [10.2.76.71]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 72C773F5A1; Sat, 12 Oct 2024 13:47:37 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Masami Hiramatsu , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v3 3/3] perf probe: Improve log for long event name failure Date: Sat, 12 Oct 2024 21:47:25 +0100 Message-Id: <20241012204725.928794-4-leo.yan@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241012204725.928794-1-leo.yan@arm.com> References: <20241012204725.928794-1-leo.yan@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If a symbol name is longer than the maximum event length (64 bytes), the perf tool reports error: # perf probe -x test_cpp_mangle --add "this_is_a_very_very_long_print_dat= a_abcdefghijklmnopqrstuvwxyz(int)" snprintf() failed: -7; the event name nbase=3D'this_is_a_very_very_long= _print_data_abcdefghijklmnopqrstuvwxyz(int)' is too long Error: Failed to add events. An information is missed in the log that the symbol name and the event name can be set separately. Especially, this is recommended for adding probe for a long symbol. This commit refines the log for reminding event syntax. After: # perf probe -x test_cpp_mangle --add "this_is_a_very_very_long_print_dat= a_abcdefghijklmnopqrstuvwxyz(int)" snprintf() failed: -7; the event name 'this_is_a_very_very_long_print_d= ata_abcdefghijklmnopqrstuvwxyz(int)' is too long Hint: Set a shorter event with syntax "EVENT=3DPROBEDEF" EVENT: Event name (max length: 64 bytes). Error: Failed to add events. Signed-off-by: Leo Yan Acked-by: Masami Hiramatsu (Google) --- tools/perf/util/probe-event.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 224ec6818803..2a2fc5e78c5c 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -2760,7 +2760,10 @@ static int get_new_event_name(char *buf, size_t len,= const char *base, /* Try no suffix number */ ret =3D e_snprintf(buf, len, "%s%s", nbase, ret_event ? "__return" : ""); if (ret < 0) { - pr_warning("snprintf() failed: %d; the event name nbase=3D'%s' is too lo= ng\n", ret, nbase); + pr_warning("snprintf() failed: %d; the event name '%s' is too long\n" + " Hint: Set a shorter event with syntax \"EVENT=3DPROBEDEF\"\n" + " EVENT: Event name (max length: %d bytes).\n", + ret, nbase, MAX_EVENT_NAME_LEN); goto out; } if (!strlist__has_entry(namelist, buf)) @@ -2780,7 +2783,10 @@ static int get_new_event_name(char *buf, size_t len,= const char *base, for (i =3D 1; i < MAX_EVENT_INDEX; i++) { ret =3D e_snprintf(buf, len, "%s_%d", nbase, i); if (ret < 0) { - pr_debug("snprintf() failed: %d\n", ret); + pr_warning("Add suffix failed: %d; the event name '%s' is too long\n" + " Hint: Set a shorter event with syntax \"EVENT=3DPROBEDEF\"\n" + " EVENT: Event name (max length: %d bytes).\n", + ret, nbase, MAX_EVENT_NAME_LEN); goto out; } if (!strlist__has_entry(namelist, buf)) --=20 2.25.1