[PATCH bpf v1 4/4] selftests/bpf: Add autogenerated tests for raw_tp NULL args

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add bash and python scripts that process the RAW_TP_NULL_ARGS list in
kernel/bpf/btf.c and produce selftests automatically. This is not done
automatically on build as the file requires some human-guided post
processing (like disabling certain tests for which we don't enable
CONFIG options), and only needs to be run once when growing the list.

Once the list generation becomes automatic in kernel/bpf/btf.c, the
script can run on build, or be modified if we support __nullable BTF
type tags in the future to parse them and generate tests accordingly.

The tests basically ensure the pointer is marked or_null_, and likewise
for raw_tp_scalar.c case (where it needs to be marked scalar).

Enable enough config options to cover all but 4 without increasing build
time significantly. By enabling AFS, CACHEFILES, and INFINIBAND, we gain
enough coverage to cover distinct cases and positional arguments.

The config is modified to include some new options to test most options,
but driver tracepoints that include too much stuff are disabled manually
after the script produces it's output.

Whenever adding a new RAW_TP_NULL_ARGS specification or removing one,
the developer can run this script to update the selftest, reject hunks
removing the comments around disabled tracepoints, and accept other
hunks that are relevant for the newly added tracepoint.

There are some tracepoints manually hardcoded in btf_ctx_access that
have an IS_ERR argument type. For now, these are manually encoded in
raw_tp_scalar.c, but if the list grows, we can introduce a new mask
for IS_ERR args, an ERR_ARG() macro, and augment the script to generate
tests for these cases and ensure argument is marked scalar.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx>
---
 tools/testing/selftests/bpf/config            |   5 +
 .../testing/selftests/bpf/gen_raw_tp_null.py  |  58 +++
 .../testing/selftests/bpf/gen_raw_tp_null.sh  |   3 +
 .../selftests/bpf/prog_tests/raw_tp_null.c    |  12 +
 .../testing/selftests/bpf/progs/raw_tp_null.c | 417 ++++++++++++++++++
 .../selftests/bpf/progs/raw_tp_scalar.c       |  24 +
 6 files changed, 519 insertions(+)
 create mode 100755 tools/testing/selftests/bpf/gen_raw_tp_null.py
 create mode 100755 tools/testing/selftests/bpf/gen_raw_tp_null.sh
 create mode 100644 tools/testing/selftests/bpf/prog_tests/raw_tp_null.c
 create mode 100644 tools/testing/selftests/bpf/progs/raw_tp_null.c
 create mode 100644 tools/testing/selftests/bpf/progs/raw_tp_scalar.c

diff --git a/tools/testing/selftests/bpf/config b/tools/testing/selftests/bpf/config
index 4ca84c8d9116..75d3416e2c11 100644
--- a/tools/testing/selftests/bpf/config
+++ b/tools/testing/selftests/bpf/config
@@ -112,3 +112,8 @@ CONFIG_XDP_SOCKETS=y
 CONFIG_XFRM_INTERFACE=y
 CONFIG_TCP_CONG_DCTCP=y
 CONFIG_TCP_CONG_BBR=y
+CONFIG_AFS_FS=y
+CONFIG_FSCACHE=y
+CONFIG_CACHEFILES=y
+CONFIG_CACHEFILES_ONDEMAND=y
+CONFIG_INFINIBAND=y
diff --git a/tools/testing/selftests/bpf/gen_raw_tp_null.py b/tools/testing/selftests/bpf/gen_raw_tp_null.py
new file mode 100755
index 000000000000..4d15a5b92012
--- /dev/null
+++ b/tools/testing/selftests/bpf/gen_raw_tp_null.py
@@ -0,0 +1,58 @@
+#!/usr/bin/python3
+import re
+import sys
+
+def parse_null_args(arg_str):
+    pattern = r'NULL_ARG\((\d+)\)'
+    numbers = []
+    for part in arg_str.split('|'):
+        part = part.strip()
+        match = re.match(pattern, part)
+        if match:
+            numbers.append(int(match.group(1)))
+    return numbers
+
+def parse_tracepoint_line(line):
+    line = line.strip().rstrip(',')
+    match = re.match(r'RAW_TP_NULL_ARGS\(([^,]+),\s*(.*)\)', line)
+
+    if match:
+        tp_name = match.group(1).strip()
+        arg_part = match.group(2).strip()
+        arg_nums = parse_null_args(arg_part)
+        if arg_nums:
+            return tp_name, arg_nums
+    return None, None
+
+def generate_tests(entries):
+    tests = []
+
+    for tp_name, arg_nums in entries:
+        for arg_num in arg_nums:
+            test = ['', 'SEC("tp_btf/' + tp_name + '")',
+                    '__failure __msg("R1 invalid mem access \'trusted_ptr_or_null_\'")',
+                    f'int test_raw_tp_null_{tp_name}_arg_{arg_num}(void *ctx) {{']
+            n = (arg_num - 1) * 8
+            test.append(f'    asm volatile("r1 = *(u64 *)(r1 +{n}); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);')
+            test.extend(['    return 0;', '}'])
+            tests.extend(test)
+    return '\n'.join(tests)
+
+# Read directly from stdin
+entries = []
+for line in sys.stdin:
+    tp_name, arg_num = parse_tracepoint_line(line)
+    if tp_name and arg_num is not None:
+        entries.append((tp_name, arg_num))
+print(
+'''// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
+
+/* WARNING: This file is automatically generated, run gen_raw_tp_null.sh to update! */
+
+#include <vmlinux.h>
+#include <bpf/bpf_tracing.h>
+#include "bpf_misc.h"
+
+char _license[] SEC("license") = "GPL";''')
+print(generate_tests(entries))
diff --git a/tools/testing/selftests/bpf/gen_raw_tp_null.sh b/tools/testing/selftests/bpf/gen_raw_tp_null.sh
new file mode 100755
index 000000000000..1c99757f7baf
--- /dev/null
+++ b/tools/testing/selftests/bpf/gen_raw_tp_null.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+cat ../../../../kernel/bpf/btf.c  | grep RAW_TP_NULL_ARGS | grep -v "define RAW_TP" | ./gen_raw_tp_null.py | tee progs/raw_tp_null.c
diff --git a/tools/testing/selftests/bpf/prog_tests/raw_tp_null.c b/tools/testing/selftests/bpf/prog_tests/raw_tp_null.c
new file mode 100644
index 000000000000..bb5524eabde9
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/raw_tp_null.c
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
+
+#include <test_progs.h>
+#include "raw_tp_null.skel.h"
+#include "raw_tp_scalar.skel.h"
+
+void test_raw_tp_null(void)
+{
+	RUN_TESTS(raw_tp_null);
+	RUN_TESTS(raw_tp_scalar);
+}
diff --git a/tools/testing/selftests/bpf/progs/raw_tp_null.c b/tools/testing/selftests/bpf/progs/raw_tp_null.c
new file mode 100644
index 000000000000..fd4de11b587f
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/raw_tp_null.c
@@ -0,0 +1,417 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
+
+/* WARNING: This file is automatically generated, run gen_raw_tp_null.sh to update! */
+
+#include <vmlinux.h>
+#include <bpf/bpf_tracing.h>
+#include "bpf_misc.h"
+
+char _license[] SEC("license") = "GPL";
+
+SEC("tp_btf/sched_pi_setprio")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_sched_pi_setprio_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/sched_stick_numa")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_sched_stick_numa_arg_3(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +16); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/sched_swap_numa")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_sched_swap_numa_arg_3(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +16); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/afs_make_fs_call")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_afs_make_fs_call_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/afs_make_fs_calli")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_afs_make_fs_calli_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/afs_make_fs_call1")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_afs_make_fs_call1_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/afs_make_fs_call2")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_afs_make_fs_call2_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/afs_protocol_error")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_afs_protocol_error_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/afs_flock_ev")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_afs_flock_ev_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/cachefiles_lookup")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_cachefiles_lookup_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/cachefiles_unlink")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_cachefiles_unlink_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/cachefiles_rename")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_cachefiles_rename_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/cachefiles_prep_read")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_cachefiles_prep_read_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/cachefiles_mark_active")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_cachefiles_mark_active_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/cachefiles_mark_failed")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_cachefiles_mark_failed_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/cachefiles_mark_inactive")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_cachefiles_mark_inactive_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/cachefiles_vfs_error")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_cachefiles_vfs_error_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/cachefiles_io_error")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_cachefiles_io_error_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/cachefiles_ondemand_open")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_cachefiles_ondemand_open_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/cachefiles_ondemand_copen")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_cachefiles_ondemand_copen_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/cachefiles_ondemand_close")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_cachefiles_ondemand_close_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/cachefiles_ondemand_read")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_cachefiles_ondemand_read_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/cachefiles_ondemand_cread")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_cachefiles_ondemand_cread_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/cachefiles_ondemand_fd_write")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_cachefiles_ondemand_fd_write_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/cachefiles_ondemand_fd_release")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_cachefiles_ondemand_fd_release_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/ext4_mballoc_discard")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_ext4_mballoc_discard_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/ext4_mballoc_free")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_ext4_mballoc_free_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/fib_table_lookup")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_fib_table_lookup_arg_3(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +16); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/posix_lock_inode")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_posix_lock_inode_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/fcntl_setlk")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_fcntl_setlk_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/locks_remove_posix")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_locks_remove_posix_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/flock_lock_inode")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_flock_lock_inode_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/break_lease_noblock")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_break_lease_noblock_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/break_lease_block")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_break_lease_block_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/break_lease_unblock")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_break_lease_unblock_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/generic_delete_lease")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_generic_delete_lease_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/time_out_leases")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_time_out_leases_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+/* Disabled due to missing CONFIG
+SEC("tp_btf/host1x_cdma_push_gather")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_host1x_cdma_push_gather_arg_5(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +32); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+*/
+
+SEC("tp_btf/mm_khugepaged_scan_pmd")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_mm_khugepaged_scan_pmd_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/mm_collapse_huge_page_isolate")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_mm_collapse_huge_page_isolate_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/mm_khugepaged_scan_file")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_mm_khugepaged_scan_file_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/mm_khugepaged_collapse_file")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_mm_khugepaged_collapse_file_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/mm_page_alloc")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_mm_page_alloc_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/mm_page_pcpu_drain")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_mm_page_pcpu_drain_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/mm_page_alloc_zone_locked")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_mm_page_alloc_zone_locked_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/netfs_failure")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_netfs_failure_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+/* Disabled due to missing CONFIG
+SEC("tp_btf/device_pm_callback_start")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_device_pm_callback_start_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+*/
+
+SEC("tp_btf/qdisc_dequeue")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_qdisc_dequeue_arg_4(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +24); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/rxrpc_recvdata")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_rxrpc_recvdata_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/rxrpc_resend")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_rxrpc_resend_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+/* Disabled due to missing CONFIG
+SEC("tp_btf/xs_stream_read_data")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_xs_stream_read_data_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+*/
+
+SEC("tp_btf/tcp_send_reset")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_tcp_send_reset_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/tcp_send_reset")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_tcp_send_reset_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+/* Disabled due to missing CONFIG
+SEC("tp_btf/tegra_dma_tx_status")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_tegra_dma_tx_status_arg_3(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +16); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+*/
+
+SEC("tp_btf/tmigr_update_events")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_tmigr_update_events_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/writeback_dirty_folio")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_writeback_dirty_folio_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/folio_wait_writeback")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_folio_wait_writeback_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
diff --git a/tools/testing/selftests/bpf/progs/raw_tp_scalar.c b/tools/testing/selftests/bpf/progs/raw_tp_scalar.c
new file mode 100644
index 000000000000..b44bb9a94305
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/raw_tp_scalar.c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
+
+/* Since we have a couple of cases, we just write this file by hand. */
+
+#include <vmlinux.h>
+#include <bpf/bpf_tracing.h>
+#include "bpf_misc.h"
+
+char _license[] SEC("license") = "GPL";
+
+SEC("tp_btf/mr_integ_alloc")
+__failure __msg("R1 invalid mem access 'scalar'")
+int test_raw_tp_scalar_mr_integ_alloc_arg_4(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +24); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+SEC("tp_btf/cachefiles_lookup")
+__failure __msg("R1 invalid mem access 'scalar'")
+int test_raw_tp_scalar_cachefiles_lookup_arg_3(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +16); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
-- 
2.43.5





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux