Skip to content

Commit 32d3766

Browse files
qmonnetAlexei Starovoitov
authored andcommitted
bpftool: Search for tracefs at /sys/kernel/tracing first
With "bpftool prog tracelog", bpftool prints messages from the trace pipe. To do so, it first needs to find the tracefs mount point to open the pipe. Bpftool looks at a few "default" locations, including /sys/kernel/debug/tracing and /sys/kernel/tracing. Some of these locations, namely /tracing and /trace, are not standard. They are in the list because some users used to hardcode the tracing directory to short names; but we have no compelling reason to look at these locations. If we fail to find the tracefs at the default locations, we have an additional step to find it by parsing /proc/mounts anyway, so it's safe to remove these entries from the list of default locations to check. Additionally, Alexei reports that looking for the tracefs at /sys/kernel/debug/tracing may automatically mount the file system under that location, and generate a kernel log message telling that auto-mounting there is deprecated. To avoid this message, let's swap the order for checking the potential mount points: try /sys/kernel/tracing first, which should be the standard location nowadays. The kernel log message may still appear if the tracefs is not mounted on /sys/kernel/tracing when we run bpftool. Reported-by: Alexei Starovoitov <ast@kernel.org> Closes: https://lore.kernel.org/r/CAADnVQLcMi5YQhZKsU4z3S2uVUAGu_62C33G2Zx_ruG3uXa-Ug@mail.gmail.com/ Signed-off-by: Quentin Monnet <qmo@kernel.org> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/r/20250915134209.36568-1-qmo@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent fd2e081 commit 32d3766

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

tools/bpf/bpftool/tracelog.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ find_tracefs_mnt_single(unsigned long magic, char *mnt, const char *mntpt)
5757
static bool get_tracefs_pipe(char *mnt)
5858
{
5959
static const char * const known_mnts[] = {
60-
"/sys/kernel/debug/tracing",
6160
"/sys/kernel/tracing",
62-
"/tracing",
63-
"/trace",
61+
"/sys/kernel/debug/tracing",
6462
};
6563
const char *pipe_name = "/trace_pipe";
6664
const char *fstype = "tracefs";
@@ -95,12 +93,7 @@ static bool get_tracefs_pipe(char *mnt)
9593
return false;
9694

9795
p_info("could not find tracefs, attempting to mount it now");
98-
/* Most of the time, tracefs is automatically mounted by debugfs at
99-
* /sys/kernel/debug/tracing when we try to access it. If we could not
100-
* find it, it is likely that debugfs is not mounted. Let's give one
101-
* attempt at mounting just tracefs at /sys/kernel/tracing.
102-
*/
103-
strcpy(mnt, known_mnts[1]);
96+
strcpy(mnt, known_mnts[0]);
10497
if (mount_tracefs(mnt))
10598
return false;
10699

0 commit comments

Comments
 (0)