From nobody Wed Nov 27 04:48:13 2024 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D059B19BA6; Sat, 12 Oct 2024 15:44:40 +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=1728747882; cv=none; b=C0g3cDNag97PRggGy0Izs+t0EhUCIZDea6IY7hgIAGomcOrOePKbigyOUE0G2ikqt54OzNQDVHKRdXX8PV47FcaJ709wMSRlE7GZPHIB5ADFB48nbtbk5E4LC6C9FQMuCAWWTJDp1EBQha8eI0rzjJ0d9zEZnH7Zr+qRuc8Fns4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728747882; c=relaxed/simple; bh=jtMttfkYRg3tbpaJDZGsePrF37CI4jeRKhJvIHU4W0A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=StJxw2+VXx6qg+ZNBjFfWb+sz3Szoj9zvIofeDBWmcMGLrBkOi55qpvqo0VlQ9VV3O932WVPzrd55oqHXNprlv6/LTdsgpG2QGC8NPK5D3IMCBcgyf0HBz0n7gY+JxmjDcIHY/SztZSLKgTOVoTOw0cWnBxJBaAuyvO1y2Yqvf4= 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 9A8011063; Sat, 12 Oct 2024 08:45:09 -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 635BD3F58B; Sat, 12 Oct 2024 08:44:38 -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 v2 1/3] perf probe: Use the MAX_EVENT_NAME_LEN macro Date: Sat, 12 Oct 2024 16:44:26 +0100 Message-Id: <20241012154428.888373-2-leo.yan@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241012154428.888373-1-leo.yan@arm.com> References: <20241012154428.888373-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 --- 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:48:13 2024 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 440EE3EA83; Sat, 12 Oct 2024 15:44:42 +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=1728747883; cv=none; b=C0eNr6SRDLWLDT+MOIaERfF6yaV9AZ5VcX8UQIDRwWrf3Ud8vOjmICyfAiTcx9uCVrZtJiyLKgaenMKDP5p42WbIsREijqpjH8Az5l2kzVVN+rIh5md8GOI5w4URgXJSOeXxzCRI7M0hY3STimBg0rwYvT1DJT7AmG8I8JhOTsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728747883; c=relaxed/simple; bh=mOPPJQdHmP4kUdz8+1BXg5f6hCzDQ0wUTMcLWt7uazA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hVMb6syAtZHo97eRYU0TY2diTrwTu12V+raxOIvsHj3bLXIdqETjI7ndBvajY9aKLgxfKd8EtDbtBDjOOMZn1m6kuA8zvIpD0QDo/UjipD4lOeb8jqMhHkewD3KhyWpsJwA0nuOIUYoii1lTrHiBBRzyItAKvENz6rX8cG+e6qo= 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 435CCDA7; Sat, 12 Oct 2024 08:45:11 -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 2780D3F58B; Sat, 12 Oct 2024 08:44:40 -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 v2 2/3] perf probe: Check group string length Date: Sat, 12 Oct 2024 16:44:27 +0100 Message-Id: <20241012154428.888373-3-leo.yan@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241012154428.888373-1-leo.yan@arm.com> References: <20241012154428.888373-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:48:13 2024 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 07D556F2E0; Sat, 12 Oct 2024 15:44:43 +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=1728747885; cv=none; b=thDQyL2v3ZmN2RnASGH7wS0yoXh0hWoG+MM5caaYKWDxYrlZ55okwBO6/qHy51shM6yhT2CjEPHEDXgGynGDMsDmtC3LvRFD7ePhm41Q27VFEYHpjLn/a4U0GUsN8fOngVqriLp24/yLnHxhgoh/LitOCOFLGvVOlc21Kwl1df4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728747885; c=relaxed/simple; bh=uv1AweUXlmSPy9svOaCmEUKMG+vGN4Omv0xBK6O4UNE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=owiFThr4RAaWjbGFcPsZwuEpkQob7D4QEzDR6ZkUXfwRgve7Nf35km2T44hMpmVLj3bTdYJrjvaHSsrz0ngF29zSIEVbifrUTzDEyt2A26HGe4ne5iO7drYv1Jb392TdKYHjEHcoi4D48zvfxJMKm3QCfMiWNf0kLe7g/XhWHcU= 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 F39E11063; Sat, 12 Oct 2024 08:45:12 -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 DFFE93F58B; Sat, 12 Oct 2024 08:44:41 -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 v2 3/3] perf probe: Improve log for long event name failure Date: Sat, 12 Oct 2024 16:44:28 +0100 Message-Id: <20241012154428.888373-4-leo.yan@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241012154428.888373-1-leo.yan@arm.com> References: <20241012154428.888373-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 is too long (>=3D 64 bytes) Try to set event with syntax "[GROUP:]EVENT=3Dthis_is_a_very_very_lon= g_print_data_abcdefghijklmnopqrstuvwxyz(int)" Error: Failed to add events. Signed-off-by: Leo Yan --- tools/perf/util/probe-event.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 224ec6818803..441daf4fb321 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -2760,7 +2760,9 @@ 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 is too long (>=3D %d b= ytes)\n" + " Try to set event with syntax \"[GROUP:]EVENT=3D%s\"\n", + ret, MAX_EVENT_NAME_LEN, nbase); goto out; } if (!strlist__has_entry(namelist, buf)) --=20 2.25.1