2023-03-10 19:21:09

by Ross Zwisler

[permalink] [raw]
Subject: [PATCH v3 0/3] use canonical ftrace path whenever possible

From: Ross Zwisler <[email protected]>

v2 here:
https://lore.kernel.org/linux-trace-kernel/[email protected]/

Changes since v2:
* Dropped patches that have been accepted into maintainer trees.
* Collected Acked-by and Reviewed-by tags from Paolo, Mukesh and Steven.
Thank you for the reviews!

Ross Zwisler (3):
selftests: use canonical ftrace path
leaking_addresses: also skip canonical ftrace path
tools/kvm_stat: use canonical ftrace path

scripts/leaking_addresses.pl | 1 +
tools/kvm/kvm_stat/kvm_stat | 2 +-
tools/testing/selftests/mm/protection_keys.c | 4 ++--
tools/testing/selftests/user_events/dyn_test.c | 2 +-
tools/testing/selftests/user_events/ftrace_test.c | 10 +++++-----
tools/testing/selftests/user_events/perf_test.c | 8 ++++----
6 files changed, 14 insertions(+), 13 deletions(-)


base-commit: 55a21105ecc156495446d8ae75d7d73f66baed7b
--
2.40.0.rc1.284.g88254d51c5-goog



2023-03-10 19:21:14

by Ross Zwisler

[permalink] [raw]
Subject: [PATCH v3 2/3] leaking_addresses: also skip canonical ftrace path

From: Ross Zwisler <[email protected]>

The canonical location for the tracefs filesystem is at /sys/kernel/tracing.

But, from Documentation/trace/ftrace.rst:

Before 4.1, all ftrace tracing control files were within the debugfs
file system, which is typically located at /sys/kernel/debug/tracing.
For backward compatibility, when mounting the debugfs file system,
the tracefs file system will be automatically mounted at:

/sys/kernel/debug/tracing

scripts/leaking_addresses.pl only skipped this older debugfs path, so
let's add the canonical path as well.

Acked-by: Tycho Andersen <[email protected]>
Signed-off-by: Ross Zwisler <[email protected]>
---
scripts/leaking_addresses.pl | 1 +
1 file changed, 1 insertion(+)

diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl
index 8f636a23bc3f..e695634d153d 100755
--- a/scripts/leaking_addresses.pl
+++ b/scripts/leaking_addresses.pl
@@ -61,6 +61,7 @@ my @skip_abs = (
'/proc/device-tree',
'/proc/1/syscall',
'/sys/firmware/devicetree',
+ '/sys/kernel/tracing/trace_pipe',
'/sys/kernel/debug/tracing/trace_pipe',
'/sys/kernel/security/apparmor/revision');

--
2.40.0.rc1.284.g88254d51c5-goog


2023-03-10 19:21:18

by Ross Zwisler

[permalink] [raw]
Subject: [PATCH v3 3/3] tools/kvm_stat: use canonical ftrace path

From: Ross Zwisler <[email protected]>

The canonical location for the tracefs filesystem is at /sys/kernel/tracing.

But, from Documentation/trace/ftrace.rst:

Before 4.1, all ftrace tracing control files were within the debugfs
file system, which is typically located at /sys/kernel/debug/tracing.
For backward compatibility, when mounting the debugfs file system,
the tracefs file system will be automatically mounted at:

/sys/kernel/debug/tracing

A comment in kvm_stat still refers to this older debugfs path, so let's
update it to avoid confusion.

Acked-by: Paolo Bonzini <[email protected]>
Reviewed-by: Steven Rostedt (Google) <[email protected]>
Reviewed-by: Mukesh Ojha <[email protected]>
Signed-off-by: Ross Zwisler <[email protected]>
---
tools/kvm/kvm_stat/kvm_stat | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
index 6f28180ffeea..15bf00e79e3f 100755
--- a/tools/kvm/kvm_stat/kvm_stat
+++ b/tools/kvm/kvm_stat/kvm_stat
@@ -627,7 +627,7 @@ class TracepointProvider(Provider):
name)'.

All available events have directories under
- /sys/kernel/debug/tracing/events/ which export information
+ /sys/kernel/tracing/events/ which export information
about the specific event. Therefore, listing the dirs gives us
a list of all available events.

--
2.40.0.rc1.284.g88254d51c5-goog


2023-03-10 19:21:21

by Ross Zwisler

[permalink] [raw]
Subject: [PATCH v3 1/3] selftests: use canonical ftrace path

From: Ross Zwisler <[email protected]>

The canonical location for the tracefs filesystem is at /sys/kernel/tracing.

But, from Documentation/trace/ftrace.rst:

Before 4.1, all ftrace tracing control files were within the debugfs
file system, which is typically located at /sys/kernel/debug/tracing.
For backward compatibility, when mounting the debugfs file system,
the tracefs file system will be automatically mounted at:

/sys/kernel/debug/tracing

A few spots in tools/testing/selftests still refer to this older debugfs
path, so let's update them to avoid confusion.

Reviewed-by: Steven Rostedt (Google) <[email protected]>
Reviewed-by: Mukesh Ojha <[email protected]>
Signed-off-by: Ross Zwisler <[email protected]>
---
tools/testing/selftests/mm/protection_keys.c | 4 ++--
tools/testing/selftests/user_events/dyn_test.c | 2 +-
tools/testing/selftests/user_events/ftrace_test.c | 10 +++++-----
tools/testing/selftests/user_events/perf_test.c | 8 ++++----
4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/tools/testing/selftests/mm/protection_keys.c b/tools/testing/selftests/mm/protection_keys.c
index 95f403a0c46d..0381c34fdd56 100644
--- a/tools/testing/selftests/mm/protection_keys.c
+++ b/tools/testing/selftests/mm/protection_keys.c
@@ -98,7 +98,7 @@ int tracing_root_ok(void)
void tracing_on(void)
{
#if CONTROL_TRACING > 0
-#define TRACEDIR "/sys/kernel/debug/tracing"
+#define TRACEDIR "/sys/kernel/tracing"
char pidstr[32];

if (!tracing_root_ok())
@@ -124,7 +124,7 @@ void tracing_off(void)
#if CONTROL_TRACING > 0
if (!tracing_root_ok())
return;
- cat_into_file("0", "/sys/kernel/debug/tracing/tracing_on");
+ cat_into_file("0", "/sys/kernel/tracing/tracing_on");
#endif
}

diff --git a/tools/testing/selftests/user_events/dyn_test.c b/tools/testing/selftests/user_events/dyn_test.c
index d6265d14cd51..8879a7b04c6a 100644
--- a/tools/testing/selftests/user_events/dyn_test.c
+++ b/tools/testing/selftests/user_events/dyn_test.c
@@ -16,7 +16,7 @@

#include "../kselftest_harness.h"

-const char *dyn_file = "/sys/kernel/debug/tracing/dynamic_events";
+const char *dyn_file = "/sys/kernel/tracing/dynamic_events";
const char *clear = "!u:__test_event";

static int Append(const char *value)
diff --git a/tools/testing/selftests/user_events/ftrace_test.c b/tools/testing/selftests/user_events/ftrace_test.c
index 404a2713dcae..a0b2c96eb252 100644
--- a/tools/testing/selftests/user_events/ftrace_test.c
+++ b/tools/testing/selftests/user_events/ftrace_test.c
@@ -16,11 +16,11 @@

#include "../kselftest_harness.h"

-const char *data_file = "/sys/kernel/debug/tracing/user_events_data";
-const char *status_file = "/sys/kernel/debug/tracing/user_events_status";
-const char *enable_file = "/sys/kernel/debug/tracing/events/user_events/__test_event/enable";
-const char *trace_file = "/sys/kernel/debug/tracing/trace";
-const char *fmt_file = "/sys/kernel/debug/tracing/events/user_events/__test_event/format";
+const char *data_file = "/sys/kernel/tracing/user_events_data";
+const char *status_file = "/sys/kernel/tracing/user_events_status";
+const char *enable_file = "/sys/kernel/tracing/events/user_events/__test_event/enable";
+const char *trace_file = "/sys/kernel/tracing/trace";
+const char *fmt_file = "/sys/kernel/tracing/events/user_events/__test_event/format";

static inline int status_check(char *status_page, int status_bit)
{
diff --git a/tools/testing/selftests/user_events/perf_test.c b/tools/testing/selftests/user_events/perf_test.c
index 8b4c7879d5a7..31505642aa9b 100644
--- a/tools/testing/selftests/user_events/perf_test.c
+++ b/tools/testing/selftests/user_events/perf_test.c
@@ -18,10 +18,10 @@

#include "../kselftest_harness.h"

-const char *data_file = "/sys/kernel/debug/tracing/user_events_data";
-const char *status_file = "/sys/kernel/debug/tracing/user_events_status";
-const char *id_file = "/sys/kernel/debug/tracing/events/user_events/__test_event/id";
-const char *fmt_file = "/sys/kernel/debug/tracing/events/user_events/__test_event/format";
+const char *data_file = "/sys/kernel/tracing/user_events_data";
+const char *status_file = "/sys/kernel/tracing/user_events_status";
+const char *id_file = "/sys/kernel/tracing/events/user_events/__test_event/id";
+const char *fmt_file = "/sys/kernel/tracing/events/user_events/__test_event/format";

struct event {
__u32 index;
--
2.40.0.rc1.284.g88254d51c5-goog


2023-03-13 20:57:39

by Ross Zwisler

[permalink] [raw]
Subject: [PATCH bpf-next v4 0/2] use canonical ftrace path whenever possible

From: Ross Zwisler <[email protected]>

v3 here:
https://lore.kernel.org/all/[email protected]/

Changes since v3:
* Added braces around a few multi-line if/else statements (Steven Rostedt)
* Added Reviewed-by from Steven to patch 1
* Rebased onto the current bpf/bpf-next

Ross Zwisler (2):
bpf: use canonical ftrace path
selftests/bpf: use canonical ftrace path

include/uapi/linux/bpf.h | 8 ++++----
samples/bpf/cpustat_kern.c | 4 ++--
samples/bpf/hbm.c | 4 ++--
samples/bpf/ibumad_kern.c | 4 ++--
samples/bpf/lwt_len_hist.sh | 2 +-
samples/bpf/offwaketime_kern.c | 2 +-
samples/bpf/task_fd_query_user.c | 4 ++--
samples/bpf/test_lwt_bpf.sh | 2 +-
samples/bpf/test_overhead_tp.bpf.c | 4 ++--
tools/include/uapi/linux/bpf.h | 8 ++++----
tools/testing/selftests/bpf/get_cgroup_id_user.c | 9 +++++++--
.../selftests/bpf/prog_tests/kprobe_multi_test.c | 7 ++++++-
.../selftests/bpf/prog_tests/task_fd_query_tp.c | 9 +++++++--
.../selftests/bpf/prog_tests/tp_attach_query.c | 9 +++++++--
.../testing/selftests/bpf/prog_tests/trace_printk.c | 10 +++++++---
.../selftests/bpf/prog_tests/trace_vprintk.c | 10 +++++++---
.../selftests/bpf/progs/test_stacktrace_map.c | 2 +-
tools/testing/selftests/bpf/progs/test_tracepoint.c | 2 +-
tools/testing/selftests/bpf/test_ftrace.sh | 7 ++++++-
tools/testing/selftests/bpf/test_tunnel.sh | 13 +++++++++----
tools/testing/selftests/bpf/trace_helpers.c | 8 ++++++--
21 files changed, 85 insertions(+), 43 deletions(-)


base-commit: 22df776a9a866713d9decfb92b633bcfdb571954
--
2.40.0.rc1.284.g88254d51c5-goog


2023-03-13 20:57:44

by Ross Zwisler

[permalink] [raw]
Subject: [PATCH bpf-next v4 1/2] bpf: use canonical ftrace path

From: Ross Zwisler <[email protected]>

The canonical location for the tracefs filesystem is at /sys/kernel/tracing.

But, from Documentation/trace/ftrace.rst:

Before 4.1, all ftrace tracing control files were within the debugfs
file system, which is typically located at /sys/kernel/debug/tracing.
For backward compatibility, when mounting the debugfs file system,
the tracefs file system will be automatically mounted at:

/sys/kernel/debug/tracing

Many comments and samples in the bpf code still refer to this older
debugfs path, so let's update them to avoid confusion. There are a few
spots where the bpf code explicitly checks both tracefs and debugfs
(tools/bpf/bpftool/tracelog.c and tools/lib/api/fs/fs.c) and I've left
those alone so that the tools can continue to work with both paths.

Signed-off-by: Ross Zwisler <[email protected]>
Acked-by: Michael S. Tsirkin <[email protected]>
Reviewed-by: Steven Rostedt (Google) <[email protected]>
---
include/uapi/linux/bpf.h | 8 ++++----
samples/bpf/cpustat_kern.c | 4 ++--
samples/bpf/hbm.c | 4 ++--
samples/bpf/ibumad_kern.c | 4 ++--
samples/bpf/lwt_len_hist.sh | 2 +-
samples/bpf/offwaketime_kern.c | 2 +-
samples/bpf/task_fd_query_user.c | 4 ++--
samples/bpf/test_lwt_bpf.sh | 2 +-
samples/bpf/test_overhead_tp.bpf.c | 4 ++--
tools/include/uapi/linux/bpf.h | 8 ++++----
10 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index d8c534e05b0a..13129df937cd 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1647,17 +1647,17 @@ union bpf_attr {
* Description
* This helper is a "printk()-like" facility for debugging. It
* prints a message defined by format *fmt* (of size *fmt_size*)
- * to file *\/sys/kernel/debug/tracing/trace* from DebugFS, if
+ * to file *\/sys/kernel/tracing/trace* from TraceFS, if
* available. It can take up to three additional **u64**
* arguments (as an eBPF helpers, the total number of arguments is
* limited to five).
*
* Each time the helper is called, it appends a line to the trace.
- * Lines are discarded while *\/sys/kernel/debug/tracing/trace* is
- * open, use *\/sys/kernel/debug/tracing/trace_pipe* to avoid this.
+ * Lines are discarded while *\/sys/kernel/tracing/trace* is
+ * open, use *\/sys/kernel/tracing/trace_pipe* to avoid this.
* The format of the trace is customizable, and the exact output
* one will get depends on the options set in
- * *\/sys/kernel/debug/tracing/trace_options* (see also the
+ * *\/sys/kernel/tracing/trace_options* (see also the
* *README* file under the same directory). However, it usually
* defaults to something like:
*
diff --git a/samples/bpf/cpustat_kern.c b/samples/bpf/cpustat_kern.c
index 5aefd19cdfa1..944f13fe164a 100644
--- a/samples/bpf/cpustat_kern.c
+++ b/samples/bpf/cpustat_kern.c
@@ -76,8 +76,8 @@ struct {

/*
* The trace events for cpu_idle and cpu_frequency are taken from:
- * /sys/kernel/debug/tracing/events/power/cpu_idle/format
- * /sys/kernel/debug/tracing/events/power/cpu_frequency/format
+ * /sys/kernel/tracing/events/power/cpu_idle/format
+ * /sys/kernel/tracing/events/power/cpu_frequency/format
*
* These two events have same format, so define one common structure.
*/
diff --git a/samples/bpf/hbm.c b/samples/bpf/hbm.c
index 516fbac28b71..ff58ec43f56a 100644
--- a/samples/bpf/hbm.c
+++ b/samples/bpf/hbm.c
@@ -65,7 +65,7 @@ static void Usage(void);
static void read_trace_pipe2(void);
static void do_error(char *msg, bool errno_flag);

-#define DEBUGFS "/sys/kernel/debug/tracing/"
+#define TRACEFS "/sys/kernel/tracing/"

static struct bpf_program *bpf_prog;
static struct bpf_object *obj;
@@ -77,7 +77,7 @@ static void read_trace_pipe2(void)
FILE *outf;
char *outFname = "hbm_out.log";

- trace_fd = open(DEBUGFS "trace_pipe", O_RDONLY, 0);
+ trace_fd = open(TRACEFS "trace_pipe", O_RDONLY, 0);
if (trace_fd < 0) {
printf("Error opening trace_pipe\n");
return;
diff --git a/samples/bpf/ibumad_kern.c b/samples/bpf/ibumad_kern.c
index 9b193231024a..f07474c72525 100644
--- a/samples/bpf/ibumad_kern.c
+++ b/samples/bpf/ibumad_kern.c
@@ -39,8 +39,8 @@ struct {
/* Taken from the current format defined in
* include/trace/events/ib_umad.h
* and
- * /sys/kernel/debug/tracing/events/ib_umad/ib_umad_read/format
- * /sys/kernel/debug/tracing/events/ib_umad/ib_umad_write/format
+ * /sys/kernel/tracing/events/ib_umad/ib_umad_read/format
+ * /sys/kernel/tracing/events/ib_umad/ib_umad_write/format
*/
struct ib_umad_rw_args {
u64 pad;
diff --git a/samples/bpf/lwt_len_hist.sh b/samples/bpf/lwt_len_hist.sh
index 7078bfcc4f4d..381b2c634784 100755
--- a/samples/bpf/lwt_len_hist.sh
+++ b/samples/bpf/lwt_len_hist.sh
@@ -5,7 +5,7 @@ NS1=lwt_ns1
VETH0=tst_lwt1a
VETH1=tst_lwt1b
BPF_PROG=lwt_len_hist.bpf.o
-TRACE_ROOT=/sys/kernel/debug/tracing
+TRACE_ROOT=/sys/kernel/tracing

function cleanup {
# To reset saved histogram, remove pinned map
diff --git a/samples/bpf/offwaketime_kern.c b/samples/bpf/offwaketime_kern.c
index eb4d94742e6b..23f12b47e9e5 100644
--- a/samples/bpf/offwaketime_kern.c
+++ b/samples/bpf/offwaketime_kern.c
@@ -110,7 +110,7 @@ static inline int update_counts(void *ctx, u32 pid, u64 delta)
}

#if 1
-/* taken from /sys/kernel/debug/tracing/events/sched/sched_switch/format */
+/* taken from /sys/kernel/tracing/events/sched/sched_switch/format */
struct sched_switch_args {
unsigned long long pad;
char prev_comm[TASK_COMM_LEN];
diff --git a/samples/bpf/task_fd_query_user.c b/samples/bpf/task_fd_query_user.c
index a33d74bd3a4b..1e61f2180470 100644
--- a/samples/bpf/task_fd_query_user.c
+++ b/samples/bpf/task_fd_query_user.c
@@ -235,7 +235,7 @@ static int test_debug_fs_uprobe(char *binary_path, long offset, bool is_return)
struct bpf_link *link;
ssize_t bytes;

- snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/%s_events",
+ snprintf(buf, sizeof(buf), "/sys/kernel/tracing/%s_events",
event_type);
kfd = open(buf, O_WRONLY | O_TRUNC, 0);
CHECK_PERROR_RET(kfd < 0);
@@ -252,7 +252,7 @@ static int test_debug_fs_uprobe(char *binary_path, long offset, bool is_return)
close(kfd);
kfd = -1;

- snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/events/%ss/%s/id",
+ snprintf(buf, sizeof(buf), "/sys/kernel/tracing/events/%ss/%s/id",
event_type, event_alias);
efd = open(buf, O_RDONLY, 0);
CHECK_PERROR_RET(efd < 0);
diff --git a/samples/bpf/test_lwt_bpf.sh b/samples/bpf/test_lwt_bpf.sh
index 2e9f5126963b..0bf2d0f6bf4b 100755
--- a/samples/bpf/test_lwt_bpf.sh
+++ b/samples/bpf/test_lwt_bpf.sh
@@ -21,7 +21,7 @@ IP_LOCAL="192.168.99.1"

PROG_SRC="test_lwt_bpf.c"
BPF_PROG="test_lwt_bpf.o"
-TRACE_ROOT=/sys/kernel/debug/tracing
+TRACE_ROOT=/sys/kernel/tracing
CONTEXT_INFO=$(cat ${TRACE_ROOT}/trace_options | grep context)

function lookup_mac()
diff --git a/samples/bpf/test_overhead_tp.bpf.c b/samples/bpf/test_overhead_tp.bpf.c
index 67cab3881969..8b498328e961 100644
--- a/samples/bpf/test_overhead_tp.bpf.c
+++ b/samples/bpf/test_overhead_tp.bpf.c
@@ -7,7 +7,7 @@
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>

-/* from /sys/kernel/debug/tracing/events/task/task_rename/format */
+/* from /sys/kernel/tracing/events/task/task_rename/format */
struct task_rename {
__u64 pad;
__u32 pid;
@@ -21,7 +21,7 @@ int prog(struct task_rename *ctx)
return 0;
}

-/* from /sys/kernel/debug/tracing/events/fib/fib_table_lookup/format */
+/* from /sys/kernel/tracing/events/fib/fib_table_lookup/format */
struct fib_table_lookup {
__u64 pad;
__u32 tb_id;
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index d8c534e05b0a..13129df937cd 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -1647,17 +1647,17 @@ union bpf_attr {
* Description
* This helper is a "printk()-like" facility for debugging. It
* prints a message defined by format *fmt* (of size *fmt_size*)
- * to file *\/sys/kernel/debug/tracing/trace* from DebugFS, if
+ * to file *\/sys/kernel/tracing/trace* from TraceFS, if
* available. It can take up to three additional **u64**
* arguments (as an eBPF helpers, the total number of arguments is
* limited to five).
*
* Each time the helper is called, it appends a line to the trace.
- * Lines are discarded while *\/sys/kernel/debug/tracing/trace* is
- * open, use *\/sys/kernel/debug/tracing/trace_pipe* to avoid this.
+ * Lines are discarded while *\/sys/kernel/tracing/trace* is
+ * open, use *\/sys/kernel/tracing/trace_pipe* to avoid this.
* The format of the trace is customizable, and the exact output
* one will get depends on the options set in
- * *\/sys/kernel/debug/tracing/trace_options* (see also the
+ * *\/sys/kernel/tracing/trace_options* (see also the
* *README* file under the same directory). However, it usually
* defaults to something like:
*
--
2.40.0.rc1.284.g88254d51c5-goog


2023-03-13 20:57:47

by Ross Zwisler

[permalink] [raw]
Subject: [PATCH bpf-next v4 2/2] selftests/bpf: use canonical ftrace path

From: Ross Zwisler <[email protected]>

The canonical location for the tracefs filesystem is at
/sys/kernel/tracing.

But, from Documentation/trace/ftrace.rst:

Before 4.1, all ftrace tracing control files were within the debugfs
file system, which is typically located at /sys/kernel/debug/tracing.
For backward compatibility, when mounting the debugfs file system,
the tracefs file system will be automatically mounted at:

/sys/kernel/debug/tracing

Many tests in the bpf selftest code still refer to this older debugfs
path, so let's update them to avoid confusion.

Signed-off-by: Ross Zwisler <[email protected]>
Acked-by: Michael S. Tsirkin <[email protected]>
---
tools/testing/selftests/bpf/get_cgroup_id_user.c | 9 +++++++--
.../selftests/bpf/prog_tests/kprobe_multi_test.c | 7 ++++++-
.../selftests/bpf/prog_tests/task_fd_query_tp.c | 9 +++++++--
.../selftests/bpf/prog_tests/tp_attach_query.c | 9 +++++++--
.../testing/selftests/bpf/prog_tests/trace_printk.c | 10 +++++++---
.../selftests/bpf/prog_tests/trace_vprintk.c | 10 +++++++---
.../selftests/bpf/progs/test_stacktrace_map.c | 2 +-
tools/testing/selftests/bpf/progs/test_tracepoint.c | 2 +-
tools/testing/selftests/bpf/test_ftrace.sh | 7 ++++++-
tools/testing/selftests/bpf/test_tunnel.sh | 13 +++++++++----
tools/testing/selftests/bpf/trace_helpers.c | 8 ++++++--
11 files changed, 64 insertions(+), 22 deletions(-)

diff --git a/tools/testing/selftests/bpf/get_cgroup_id_user.c b/tools/testing/selftests/bpf/get_cgroup_id_user.c
index 156743cf5870..aefd83ebdcd7 100644
--- a/tools/testing/selftests/bpf/get_cgroup_id_user.c
+++ b/tools/testing/selftests/bpf/get_cgroup_id_user.c
@@ -86,8 +86,13 @@ int main(int argc, char **argv)
pid = getpid();
bpf_map_update_elem(pidmap_fd, &key, &pid, 0);

- snprintf(buf, sizeof(buf),
- "/sys/kernel/debug/tracing/events/%s/id", probe_name);
+ if (access("/sys/kernel/tracing/trace", F_OK) == 0) {
+ snprintf(buf, sizeof(buf),
+ "/sys/kernel/tracing/events/%s/id", probe_name);
+ } else {
+ snprintf(buf, sizeof(buf),
+ "/sys/kernel/debug/tracing/events/%s/id", probe_name);
+ }
efd = open(buf, O_RDONLY, 0);
if (CHECK(efd < 0, "open", "err %d errno %d\n", efd, errno))
goto close_prog;
diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
index 113dba349a57..22be0a9a5a0a 100644
--- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
@@ -338,7 +338,12 @@ static int get_syms(char ***symsp, size_t *cntp, bool kernel)
* Filtering out duplicates by using hashmap__add, which won't
* add existing entry.
*/
- f = fopen("/sys/kernel/debug/tracing/available_filter_functions", "r");
+
+ if (access("/sys/kernel/tracing/trace", F_OK) == 0)
+ f = fopen("/sys/kernel/tracing/available_filter_functions", "r");
+ else
+ f = fopen("/sys/kernel/debug/tracing/available_filter_functions", "r");
+
if (!f)
return -EINVAL;

diff --git a/tools/testing/selftests/bpf/prog_tests/task_fd_query_tp.c b/tools/testing/selftests/bpf/prog_tests/task_fd_query_tp.c
index c717741bf8b6..c91eda624657 100644
--- a/tools/testing/selftests/bpf/prog_tests/task_fd_query_tp.c
+++ b/tools/testing/selftests/bpf/prog_tests/task_fd_query_tp.c
@@ -17,8 +17,13 @@ static void test_task_fd_query_tp_core(const char *probe_name,
if (CHECK(err, "bpf_prog_test_load", "err %d errno %d\n", err, errno))
goto close_prog;

- snprintf(buf, sizeof(buf),
- "/sys/kernel/debug/tracing/events/%s/id", probe_name);
+ if (access("/sys/kernel/tracing/trace", F_OK) == 0) {
+ snprintf(buf, sizeof(buf),
+ "/sys/kernel/tracing/events/%s/id", probe_name);
+ } else {
+ snprintf(buf, sizeof(buf),
+ "/sys/kernel/debug/tracing/events/%s/id", probe_name);
+ }
efd = open(buf, O_RDONLY, 0);
if (CHECK(efd < 0, "open", "err %d errno %d\n", efd, errno))
goto close_prog;
diff --git a/tools/testing/selftests/bpf/prog_tests/tp_attach_query.c b/tools/testing/selftests/bpf/prog_tests/tp_attach_query.c
index 770fcc3bb1ba..655d69f0ff0b 100644
--- a/tools/testing/selftests/bpf/prog_tests/tp_attach_query.c
+++ b/tools/testing/selftests/bpf/prog_tests/tp_attach_query.c
@@ -16,8 +16,13 @@ void serial_test_tp_attach_query(void)
for (i = 0; i < num_progs; i++)
obj[i] = NULL;

- snprintf(buf, sizeof(buf),
- "/sys/kernel/debug/tracing/events/sched/sched_switch/id");
+ if (access("/sys/kernel/tracing/trace", F_OK) == 0) {
+ snprintf(buf, sizeof(buf),
+ "/sys/kernel/tracing/events/sched/sched_switch/id");
+ } else {
+ snprintf(buf, sizeof(buf),
+ "/sys/kernel/debug/tracing/events/sched/sched_switch/id");
+ }
efd = open(buf, O_RDONLY, 0);
if (CHECK(efd < 0, "open", "err %d errno %d\n", efd, errno))
return;
diff --git a/tools/testing/selftests/bpf/prog_tests/trace_printk.c b/tools/testing/selftests/bpf/prog_tests/trace_printk.c
index cade7f12315f..7b9124d506a5 100644
--- a/tools/testing/selftests/bpf/prog_tests/trace_printk.c
+++ b/tools/testing/selftests/bpf/prog_tests/trace_printk.c
@@ -5,7 +5,8 @@

#include "trace_printk.lskel.h"

-#define TRACEBUF "/sys/kernel/debug/tracing/trace_pipe"
+#define TRACEFS_PIPE "/sys/kernel/tracing/trace_pipe"
+#define DEBUGFS_PIPE "/sys/kernel/debug/tracing/trace_pipe"
#define SEARCHMSG "testing,testing"

void serial_test_trace_printk(void)
@@ -34,8 +35,11 @@ void serial_test_trace_printk(void)
if (!ASSERT_OK(err, "trace_printk__attach"))
goto cleanup;

- fp = fopen(TRACEBUF, "r");
- if (!ASSERT_OK_PTR(fp, "fopen(TRACEBUF)"))
+ if (access(TRACEFS_PIPE, F_OK) == 0)
+ fp = fopen(TRACEFS_PIPE, "r");
+ else
+ fp = fopen(DEBUGFS_PIPE, "r");
+ if (!ASSERT_OK_PTR(fp, "fopen(TRACE_PIPE)"))
goto cleanup;

/* We do not want to wait forever if this test fails... */
diff --git a/tools/testing/selftests/bpf/prog_tests/trace_vprintk.c b/tools/testing/selftests/bpf/prog_tests/trace_vprintk.c
index 7a4e313e8558..44ea2fd88f4c 100644
--- a/tools/testing/selftests/bpf/prog_tests/trace_vprintk.c
+++ b/tools/testing/selftests/bpf/prog_tests/trace_vprintk.c
@@ -5,7 +5,8 @@

#include "trace_vprintk.lskel.h"

-#define TRACEBUF "/sys/kernel/debug/tracing/trace_pipe"
+#define TRACEFS_PIPE "/sys/kernel/tracing/trace_pipe"
+#define DEBUGFS_PIPE "/sys/kernel/debug/tracing/trace_pipe"
#define SEARCHMSG "1,2,3,4,5,6,7,8,9,10"

void serial_test_trace_vprintk(void)
@@ -27,8 +28,11 @@ void serial_test_trace_vprintk(void)
if (!ASSERT_OK(err, "trace_vprintk__attach"))
goto cleanup;

- fp = fopen(TRACEBUF, "r");
- if (!ASSERT_OK_PTR(fp, "fopen(TRACEBUF)"))
+ if (access(TRACEFS_PIPE, F_OK) == 0)
+ fp = fopen(TRACEFS_PIPE, "r");
+ else
+ fp = fopen(DEBUGFS_PIPE, "r");
+ if (!ASSERT_OK_PTR(fp, "fopen(TRACE_PIPE)"))
goto cleanup;

/* We do not want to wait forever if this test fails... */
diff --git a/tools/testing/selftests/bpf/progs/test_stacktrace_map.c b/tools/testing/selftests/bpf/progs/test_stacktrace_map.c
index 728dbd39eff0..47568007b668 100644
--- a/tools/testing/selftests/bpf/progs/test_stacktrace_map.c
+++ b/tools/testing/selftests/bpf/progs/test_stacktrace_map.c
@@ -38,7 +38,7 @@ struct {
__type(value, stack_trace_t);
} stack_amap SEC(".maps");

-/* taken from /sys/kernel/debug/tracing/events/sched/sched_switch/format */
+/* taken from /sys/kernel/tracing/events/sched/sched_switch/format */
struct sched_switch_args {
unsigned long long pad;
char prev_comm[TASK_COMM_LEN];
diff --git a/tools/testing/selftests/bpf/progs/test_tracepoint.c b/tools/testing/selftests/bpf/progs/test_tracepoint.c
index 43bd7a20cc50..4cb8bbb6a320 100644
--- a/tools/testing/selftests/bpf/progs/test_tracepoint.c
+++ b/tools/testing/selftests/bpf/progs/test_tracepoint.c
@@ -4,7 +4,7 @@
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>

-/* taken from /sys/kernel/debug/tracing/events/sched/sched_switch/format */
+/* taken from /sys/kernel/tracing/events/sched/sched_switch/format */
struct sched_switch_args {
unsigned long long pad;
char prev_comm[TASK_COMM_LEN];
diff --git a/tools/testing/selftests/bpf/test_ftrace.sh b/tools/testing/selftests/bpf/test_ftrace.sh
index 20de7bb873bc..f5109eb0e951 100755
--- a/tools/testing/selftests/bpf/test_ftrace.sh
+++ b/tools/testing/selftests/bpf/test_ftrace.sh
@@ -1,6 +1,11 @@
#!/bin/bash

-TR=/sys/kernel/debug/tracing/
+if [[ -e /sys/kernel/tracing/trace ]]; then
+ TR=/sys/kernel/tracing/
+else
+ TR=/sys/kernel/debug/tracing/
+fi
+
clear_trace() { # reset trace output
echo > $TR/trace
}
diff --git a/tools/testing/selftests/bpf/test_tunnel.sh b/tools/testing/selftests/bpf/test_tunnel.sh
index 06857b689c11..2dec7dbf29a2 100755
--- a/tools/testing/selftests/bpf/test_tunnel.sh
+++ b/tools/testing/selftests/bpf/test_tunnel.sh
@@ -571,8 +571,13 @@ setup_xfrm_tunnel()

test_xfrm_tunnel()
{
+ if [[ -e /sys/kernel/tracing/trace ]]; then
+ TRACE=/sys/kernel/tracing/trace
+ else
+ TRACE=/sys/kernel/debug/tracing/trace
+ fi
config_device
- > /sys/kernel/debug/tracing/trace
+ > ${TRACE}
setup_xfrm_tunnel
mkdir -p ${BPF_PIN_TUNNEL_DIR}
bpftool prog loadall ${BPF_FILE} ${BPF_PIN_TUNNEL_DIR}
@@ -581,11 +586,11 @@ test_xfrm_tunnel()
${BPF_PIN_TUNNEL_DIR}/xfrm_get_state
ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
sleep 1
- grep "reqid 1" /sys/kernel/debug/tracing/trace
+ grep "reqid 1" ${TRACE}
check_err $?
- grep "spi 0x1" /sys/kernel/debug/tracing/trace
+ grep "spi 0x1" ${TRACE}
check_err $?
- grep "remote ip 0xac100164" /sys/kernel/debug/tracing/trace
+ grep "remote ip 0xac100164" ${TRACE}
check_err $?
cleanup

diff --git a/tools/testing/selftests/bpf/trace_helpers.c b/tools/testing/selftests/bpf/trace_helpers.c
index 09a16a77bae4..934bf28fc888 100644
--- a/tools/testing/selftests/bpf/trace_helpers.c
+++ b/tools/testing/selftests/bpf/trace_helpers.c
@@ -12,7 +12,8 @@
#include <sys/mman.h>
#include "trace_helpers.h"

-#define DEBUGFS "/sys/kernel/debug/tracing/"
+#define TRACEFS_PIPE "/sys/kernel/tracing/trace_pipe"
+#define DEBUGFS_PIPE "/sys/kernel/debug/tracing/trace_pipe"

#define MAX_SYMS 300000
static struct ksym syms[MAX_SYMS];
@@ -136,7 +137,10 @@ void read_trace_pipe(void)
{
int trace_fd;

- trace_fd = open(DEBUGFS "trace_pipe", O_RDONLY, 0);
+ if (access(TRACEFS_PIPE, F_OK) == 0)
+ trace_fd = open(TRACEFS_PIPE, O_RDONLY, 0);
+ else
+ trace_fd = open(DEBUGFS_PIPE, O_RDONLY, 0);
if (trace_fd < 0)
return;

--
2.40.0.rc1.284.g88254d51c5-goog


2023-03-13 21:02:49

by Ross Zwisler

[permalink] [raw]
Subject: Re: [PATCH bpf-next v4 0/2] use canonical ftrace path whenever possible

On Mon, Mar 13, 2023 at 02:56:26PM -0600, Ross Zwisler wrote:
> From: Ross Zwisler <[email protected]>
>
> v3 here:
> https://lore.kernel.org/all/[email protected]/

Sorry, this should have been:
https://lore.kernel.org/all/[email protected]/

>
> Changes since v3:
> * Added braces around a few multi-line if/else statements (Steven Rostedt)
> * Added Reviewed-by from Steven to patch 1
> * Rebased onto the current bpf/bpf-next
>
> Ross Zwisler (2):
> bpf: use canonical ftrace path
> selftests/bpf: use canonical ftrace path
>
> include/uapi/linux/bpf.h | 8 ++++----
> samples/bpf/cpustat_kern.c | 4 ++--
> samples/bpf/hbm.c | 4 ++--
> samples/bpf/ibumad_kern.c | 4 ++--
> samples/bpf/lwt_len_hist.sh | 2 +-
> samples/bpf/offwaketime_kern.c | 2 +-
> samples/bpf/task_fd_query_user.c | 4 ++--
> samples/bpf/test_lwt_bpf.sh | 2 +-
> samples/bpf/test_overhead_tp.bpf.c | 4 ++--
> tools/include/uapi/linux/bpf.h | 8 ++++----
> tools/testing/selftests/bpf/get_cgroup_id_user.c | 9 +++++++--
> .../selftests/bpf/prog_tests/kprobe_multi_test.c | 7 ++++++-
> .../selftests/bpf/prog_tests/task_fd_query_tp.c | 9 +++++++--
> .../selftests/bpf/prog_tests/tp_attach_query.c | 9 +++++++--
> .../testing/selftests/bpf/prog_tests/trace_printk.c | 10 +++++++---
> .../selftests/bpf/prog_tests/trace_vprintk.c | 10 +++++++---
> .../selftests/bpf/progs/test_stacktrace_map.c | 2 +-
> tools/testing/selftests/bpf/progs/test_tracepoint.c | 2 +-
> tools/testing/selftests/bpf/test_ftrace.sh | 7 ++++++-
> tools/testing/selftests/bpf/test_tunnel.sh | 13 +++++++++----
> tools/testing/selftests/bpf/trace_helpers.c | 8 ++++++--
> 21 files changed, 85 insertions(+), 43 deletions(-)
>
>
> base-commit: 22df776a9a866713d9decfb92b633bcfdb571954
> --
> 2.40.0.rc1.284.g88254d51c5-goog
>

2023-03-13 22:40:00

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH bpf-next v4 2/2] selftests/bpf: use canonical ftrace path

On Mon, 13 Mar 2023 14:56:28 -0600
Ross Zwisler <[email protected]> wrote:

> From: Ross Zwisler <[email protected]>
>
> The canonical location for the tracefs filesystem is at
> /sys/kernel/tracing.
>
> But, from Documentation/trace/ftrace.rst:
>
> Before 4.1, all ftrace tracing control files were within the debugfs
> file system, which is typically located at /sys/kernel/debug/tracing.
> For backward compatibility, when mounting the debugfs file system,
> the tracefs file system will be automatically mounted at:
>
> /sys/kernel/debug/tracing
>
> Many tests in the bpf selftest code still refer to this older debugfs
> path, so let's update them to avoid confusion.
>
> Signed-off-by: Ross Zwisler <[email protected]>
> Acked-by: Michael S. Tsirkin <[email protected]>

Reviewed-by: Steven Rostedt (Google) <[email protected]>

-- Steve

> ---
> tools/testing/selftests/bpf/get_cgroup_id_user.c | 9 +++++++--
> .../selftests/bpf/prog_tests/kprobe_multi_test.c | 7 ++++++-
> .../selftests/bpf/prog_tests/task_fd_query_tp.c | 9 +++++++--
> .../selftests/bpf/prog_tests/tp_attach_query.c | 9 +++++++--
> .../testing/selftests/bpf/prog_tests/trace_printk.c | 10 +++++++---
> .../selftests/bpf/prog_tests/trace_vprintk.c | 10 +++++++---
> .../selftests/bpf/progs/test_stacktrace_map.c | 2 +-
> tools/testing/selftests/bpf/progs/test_tracepoint.c | 2 +-
> tools/testing/selftests/bpf/test_ftrace.sh | 7 ++++++-
> tools/testing/selftests/bpf/test_tunnel.sh | 13 +++++++++----
> tools/testing/selftests/bpf/trace_helpers.c | 8 ++++++--
> 11 files changed, 64 insertions(+), 22 deletions(-)


2023-03-14 05:10:22

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH bpf-next v4 1/2] bpf: use canonical ftrace path

Hello:

This series was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <[email protected]>:

On Mon, 13 Mar 2023 14:56:27 -0600 you wrote:
> From: Ross Zwisler <[email protected]>
>
> The canonical location for the tracefs filesystem is at /sys/kernel/tracing.
>
> But, from Documentation/trace/ftrace.rst:
>
> Before 4.1, all ftrace tracing control files were within the debugfs
> file system, which is typically located at /sys/kernel/debug/tracing.
> For backward compatibility, when mounting the debugfs file system,
> the tracefs file system will be automatically mounted at:
>
> [...]

Here is the summary with links:
- [bpf-next,v4,1/2] bpf: use canonical ftrace path
https://git.kernel.org/bpf/bpf-next/c/27d7fdf06fdb
- [bpf-next,v4,2/2] selftests/bpf: use canonical ftrace path
https://git.kernel.org/bpf/bpf-next/c/ab4c15feb2eb

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html