[PATCH v2 5/5] perf trace: Add test for enum augmentation

Howard Chu posted 5 patches 1 year, 7 months ago
There is a newer version of this series
[PATCH v2 5/5] perf trace: Add test for enum augmentation
Posted by Howard Chu 1 year, 7 months ago
Check for vmlinux's existence in sysfs as prerequisite.

Add landlock_add_rule.c workload. Trace landlock_add_rule syscall to see
if the output is desirable.

Trace the non-syscall tracepoint 'timer:hrtimer_init' and
'timer:hrtimer_start', see if the 'mode' argument is augmented,
the 'mode' enum argument has the prefix of 'HRTIMER_MODE_'
in its name.

Suggested-by: Arnaldo Carvalho de Melo <acme@kernel.org>
Signed-off-by: Howard Chu <howardchu95@gmail.com>
---
 tools/perf/tests/builtin-test.c               |  1 +
 tools/perf/tests/shell/trace_btf_enum.sh      | 57 +++++++++++++++++++
 tools/perf/tests/tests.h                      |  1 +
 tools/perf/tests/workloads/Build              |  1 +
 .../perf/tests/workloads/landlock_add_rule.c  | 32 +++++++++++
 5 files changed, 92 insertions(+)
 create mode 100755 tools/perf/tests/shell/trace_btf_enum.sh
 create mode 100644 tools/perf/tests/workloads/landlock_add_rule.c

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index c3d84b67ca8e..e83200415ad1 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -152,6 +152,7 @@ static struct test_workload *workloads[] = {
 	&workload__sqrtloop,
 	&workload__brstack,
 	&workload__datasym,
+	&workload__landlock_add_rule,
 };
 
 static int num_subtests(const struct test_suite *t)
diff --git a/tools/perf/tests/shell/trace_btf_enum.sh b/tools/perf/tests/shell/trace_btf_enum.sh
new file mode 100755
index 000000000000..4861983553ab
--- /dev/null
+++ b/tools/perf/tests/shell/trace_btf_enum.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+# perf trace enum augmentation tests
+# SPDX-License-Identifier: GPL-2.0
+
+err=0
+set -e
+
+syscall="landlock_add_rule"
+non_syscall="timer:hrtimer_init,timer:hrtimer_start"
+
+TESTPROG="perf test -w landlock_add_rule"
+
+. "$(dirname $0)"/lib/probe.sh
+skip_if_no_perf_trace || exit 2
+
+check_vmlinux() {
+  echo "Checking if vmlinux exists"
+  if ! ls /sys/kernel/btf/vmlinux 1>/dev/null 2>&1
+  then
+    echo "trace+enum test [Skipped missing vmlinux BTF support]"
+    err=2
+  fi
+}
+
+trace_landlock() {
+  echo "Tracing syscall ${syscall}"
+  if perf trace -e $syscall $TESTPROG 2>&1 | \
+     grep -q -E ".*landlock_add_rule\(ruleset_fd: 11, rule_type: (LANDLOCK_RULE_PATH_BENEATH|LANDLOCK_RULE_NET_PORT), rule_attr: 0x[a-f0-9]+, flags: 45\) = -1.*"
+  then
+    err=0
+  else
+    err=1
+  fi
+}
+
+trace_non_syscall() {
+  echo "Tracing non-syscall tracepoint ${non-syscall}"
+  if perf trace -e $non_syscall --max-events=1 2>&1 | \
+     grep -q -E '.*timer:hrtimer_.*\(.*mode: HRTIMER_MODE_.*\)$'
+  then
+    err=0
+  else
+    err=1
+  fi
+}
+
+check_vmlinux
+
+if [ $err = 0 ]; then
+  trace_landlock
+fi
+
+if [ $err = 0 ]; then
+  trace_non_syscall
+fi
+
+exit $err
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 3aa7701ee0e9..69126299bb08 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -205,6 +205,7 @@ DECLARE_WORKLOAD(leafloop);
 DECLARE_WORKLOAD(sqrtloop);
 DECLARE_WORKLOAD(brstack);
 DECLARE_WORKLOAD(datasym);
+DECLARE_WORKLOAD(landlock_add_rule);
 
 extern const char *dso_to_test;
 extern const char *test_objdump_path;
diff --git a/tools/perf/tests/workloads/Build b/tools/perf/tests/workloads/Build
index a1f34d5861e3..5b12b93ecffa 100644
--- a/tools/perf/tests/workloads/Build
+++ b/tools/perf/tests/workloads/Build
@@ -6,6 +6,7 @@ perf-y += leafloop.o
 perf-y += sqrtloop.o
 perf-y += brstack.o
 perf-y += datasym.o
+perf-y += landlock_add_rule.o
 
 CFLAGS_sqrtloop.o         = -g -O0 -fno-inline -U_FORTIFY_SOURCE
 CFLAGS_leafloop.o         = -g -O0 -fno-inline -fno-omit-frame-pointer -U_FORTIFY_SOURCE
diff --git a/tools/perf/tests/workloads/landlock_add_rule.c b/tools/perf/tests/workloads/landlock_add_rule.c
new file mode 100644
index 000000000000..529b5f1ea5a7
--- /dev/null
+++ b/tools/perf/tests/workloads/landlock_add_rule.c
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#include <linux/compiler.h>
+#include <uapi/asm-generic/unistd.h> // for __NR_landlock_add_rule
+#include <unistd.h>
+#include <linux/landlock.h>
+#include "../tests.h"
+
+static int landlock_add_rule(int argc __maybe_unused, const char **argv __maybe_unused)
+{
+	int fd = 11;
+	int flags = 45;
+
+	struct landlock_path_beneath_attr path_beneath_attr = {
+	    .allowed_access = LANDLOCK_ACCESS_FS_READ_FILE,
+	    .parent_fd = 14,
+	};
+
+	struct landlock_net_port_attr net_port_attr = {
+	    .port = 19,
+	    .allowed_access = LANDLOCK_ACCESS_NET_CONNECT_TCP,
+	};
+
+	syscall(__NR_landlock_add_rule, fd, LANDLOCK_RULE_PATH_BENEATH,
+		&path_beneath_attr, flags);
+
+	syscall(__NR_landlock_add_rule, fd, LANDLOCK_RULE_NET_PORT,
+		&net_port_attr, flags);
+
+	return 0;
+}
+
+DEFINE_WORKLOAD(landlock_add_rule);
-- 
2.45.2
Re: [PATCH v2 5/5] perf trace: Add test for enum augmentation
Posted by kernel test robot 1 year, 7 months ago
Hi Howard,

kernel test robot noticed the following build errors:

[auto build test ERROR on perf-tools-next/perf-tools-next]
[also build test ERROR on next-20240621]
[cannot apply to tip/perf/core perf-tools/perf-tools acme/perf/core linus/master v6.10-rc5]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Howard-Chu/perf-trace-Fix-iteration-of-syscall-ids-in-syscalltbl-entries/20240619-162417
base:   https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git perf-tools-next
patch link:    https://lore.kernel.org/r/20240619082042.4173621-6-howardchu95%40gmail.com
patch subject: [PATCH v2 5/5] perf trace: Add test for enum augmentation
:::::: branch date: 5 days ago
:::::: commit date: 5 days ago
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240625/202406250302.E4WaX9Ud-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/r/202406250302.E4WaX9Ud-lkp@intel.com/

All errors (new ones prefixed by >>):

   Makefile.config:663: No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR
     PERF_VERSION = 6.10.rc1.gf6ac54426465
>> tests/workloads/landlock_add_rule.c:20:24: error: use of undeclared identifier 'LANDLOCK_ACCESS_NET_CONNECT_TCP'
      20 |             .allowed_access = LANDLOCK_ACCESS_NET_CONNECT_TCP,
         |                               ^
>> tests/workloads/landlock_add_rule.c:18:32: error: variable has incomplete type 'struct landlock_net_port_attr'
      18 |         struct landlock_net_port_attr net_port_attr = {
         |                                       ^
   tests/workloads/landlock_add_rule.c:18:9: note: forward declaration of 'struct landlock_net_port_attr'
      18 |         struct landlock_net_port_attr net_port_attr = {
         |                ^
>> tests/workloads/landlock_add_rule.c:26:38: error: use of undeclared identifier 'LANDLOCK_RULE_NET_PORT'
      26 |         syscall(__NR_landlock_add_rule, fd, LANDLOCK_RULE_NET_PORT,
         |                                             ^
   3 errors generated.
   make[8]: *** [tools/build/Makefile.build:105: tools/perf/tests/workloads/landlock_add_rule.o] Error 1
   make[8]: *** Waiting for unfinished jobs....
   make[7]: *** [tools/build/Makefile.build:158: workloads] Error 2
   make[7]: *** Waiting for unfinished jobs....
   make[6]: *** [tools/build/Makefile.build:158: tests] Error 2
   make[6]: *** Waiting for unfinished jobs....
   make[5]: *** [Makefile.perf:727: tools/perf/perf-in.o] Error 2
   make[5]: *** Waiting for unfinished jobs....
   make[4]: *** [Makefile.perf:264: sub-make] Error 2
   make[3]: *** [Makefile:70: all] Error 2


vim +/LANDLOCK_ACCESS_NET_CONNECT_TCP +20 tools/perf/tests/workloads/landlock_add_rule.c

f6ac54426465a5 Howard Chu 2024-06-19   7  
f6ac54426465a5 Howard Chu 2024-06-19   8  static int landlock_add_rule(int argc __maybe_unused, const char **argv __maybe_unused)
f6ac54426465a5 Howard Chu 2024-06-19   9  {
f6ac54426465a5 Howard Chu 2024-06-19  10  	int fd = 11;
f6ac54426465a5 Howard Chu 2024-06-19  11  	int flags = 45;
f6ac54426465a5 Howard Chu 2024-06-19  12  
f6ac54426465a5 Howard Chu 2024-06-19  13  	struct landlock_path_beneath_attr path_beneath_attr = {
f6ac54426465a5 Howard Chu 2024-06-19  14  	    .allowed_access = LANDLOCK_ACCESS_FS_READ_FILE,
f6ac54426465a5 Howard Chu 2024-06-19  15  	    .parent_fd = 14,
f6ac54426465a5 Howard Chu 2024-06-19  16  	};
f6ac54426465a5 Howard Chu 2024-06-19  17  
f6ac54426465a5 Howard Chu 2024-06-19  18  	struct landlock_net_port_attr net_port_attr = {
f6ac54426465a5 Howard Chu 2024-06-19  19  	    .port = 19,
f6ac54426465a5 Howard Chu 2024-06-19 @20  	    .allowed_access = LANDLOCK_ACCESS_NET_CONNECT_TCP,
f6ac54426465a5 Howard Chu 2024-06-19  21  	};
f6ac54426465a5 Howard Chu 2024-06-19  22  
f6ac54426465a5 Howard Chu 2024-06-19  23  	syscall(__NR_landlock_add_rule, fd, LANDLOCK_RULE_PATH_BENEATH,
f6ac54426465a5 Howard Chu 2024-06-19  24  		&path_beneath_attr, flags);
f6ac54426465a5 Howard Chu 2024-06-19  25  
f6ac54426465a5 Howard Chu 2024-06-19  26  	syscall(__NR_landlock_add_rule, fd, LANDLOCK_RULE_NET_PORT,
f6ac54426465a5 Howard Chu 2024-06-19  27  		&net_port_attr, flags);
f6ac54426465a5 Howard Chu 2024-06-19  28  
f6ac54426465a5 Howard Chu 2024-06-19  29  	return 0;
f6ac54426465a5 Howard Chu 2024-06-19  30  }
f6ac54426465a5 Howard Chu 2024-06-19  31  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH v2 5/5] perf trace: Add test for enum augmentation
Posted by Namhyung Kim 1 year, 7 months ago
Hi Howard,

On Wed, Jun 19, 2024 at 04:20:42PM +0800, Howard Chu wrote:
> Check for vmlinux's existence in sysfs as prerequisite.
> 
> Add landlock_add_rule.c workload. Trace landlock_add_rule syscall to see
> if the output is desirable.

Do you expect to add more things to the landlock workload?  I think we
could simply call it landlock.c and probably do other things according
to the argument, if needed (e.g. landlock add).

Thanks,
Namhyung

> 
> Trace the non-syscall tracepoint 'timer:hrtimer_init' and
> 'timer:hrtimer_start', see if the 'mode' argument is augmented,
> the 'mode' enum argument has the prefix of 'HRTIMER_MODE_'
> in its name.
> 
> Suggested-by: Arnaldo Carvalho de Melo <acme@kernel.org>
> Signed-off-by: Howard Chu <howardchu95@gmail.com>
> ---
>  tools/perf/tests/builtin-test.c               |  1 +
>  tools/perf/tests/shell/trace_btf_enum.sh      | 57 +++++++++++++++++++
>  tools/perf/tests/tests.h                      |  1 +
>  tools/perf/tests/workloads/Build              |  1 +
>  .../perf/tests/workloads/landlock_add_rule.c  | 32 +++++++++++
>  5 files changed, 92 insertions(+)
>  create mode 100755 tools/perf/tests/shell/trace_btf_enum.sh
>  create mode 100644 tools/perf/tests/workloads/landlock_add_rule.c
> 
> diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
> index c3d84b67ca8e..e83200415ad1 100644
> --- a/tools/perf/tests/builtin-test.c
> +++ b/tools/perf/tests/builtin-test.c
> @@ -152,6 +152,7 @@ static struct test_workload *workloads[] = {
>  	&workload__sqrtloop,
>  	&workload__brstack,
>  	&workload__datasym,
> +	&workload__landlock_add_rule,
>  };
>  
>  static int num_subtests(const struct test_suite *t)
> diff --git a/tools/perf/tests/shell/trace_btf_enum.sh b/tools/perf/tests/shell/trace_btf_enum.sh
> new file mode 100755
> index 000000000000..4861983553ab
> --- /dev/null
> +++ b/tools/perf/tests/shell/trace_btf_enum.sh
> @@ -0,0 +1,57 @@
> +#!/bin/sh
> +# perf trace enum augmentation tests
> +# SPDX-License-Identifier: GPL-2.0
> +
> +err=0
> +set -e
> +
> +syscall="landlock_add_rule"
> +non_syscall="timer:hrtimer_init,timer:hrtimer_start"
> +
> +TESTPROG="perf test -w landlock_add_rule"
> +
> +. "$(dirname $0)"/lib/probe.sh
> +skip_if_no_perf_trace || exit 2
> +
> +check_vmlinux() {
> +  echo "Checking if vmlinux exists"
> +  if ! ls /sys/kernel/btf/vmlinux 1>/dev/null 2>&1
> +  then
> +    echo "trace+enum test [Skipped missing vmlinux BTF support]"
> +    err=2
> +  fi
> +}
> +
> +trace_landlock() {
> +  echo "Tracing syscall ${syscall}"
> +  if perf trace -e $syscall $TESTPROG 2>&1 | \
> +     grep -q -E ".*landlock_add_rule\(ruleset_fd: 11, rule_type: (LANDLOCK_RULE_PATH_BENEATH|LANDLOCK_RULE_NET_PORT), rule_attr: 0x[a-f0-9]+, flags: 45\) = -1.*"
> +  then
> +    err=0
> +  else
> +    err=1
> +  fi
> +}
> +
> +trace_non_syscall() {
> +  echo "Tracing non-syscall tracepoint ${non-syscall}"
> +  if perf trace -e $non_syscall --max-events=1 2>&1 | \
> +     grep -q -E '.*timer:hrtimer_.*\(.*mode: HRTIMER_MODE_.*\)$'
> +  then
> +    err=0
> +  else
> +    err=1
> +  fi
> +}
> +
> +check_vmlinux
> +
> +if [ $err = 0 ]; then
> +  trace_landlock
> +fi
> +
> +if [ $err = 0 ]; then
> +  trace_non_syscall
> +fi
> +
> +exit $err
> diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
> index 3aa7701ee0e9..69126299bb08 100644
> --- a/tools/perf/tests/tests.h
> +++ b/tools/perf/tests/tests.h
> @@ -205,6 +205,7 @@ DECLARE_WORKLOAD(leafloop);
>  DECLARE_WORKLOAD(sqrtloop);
>  DECLARE_WORKLOAD(brstack);
>  DECLARE_WORKLOAD(datasym);
> +DECLARE_WORKLOAD(landlock_add_rule);
>  
>  extern const char *dso_to_test;
>  extern const char *test_objdump_path;
> diff --git a/tools/perf/tests/workloads/Build b/tools/perf/tests/workloads/Build
> index a1f34d5861e3..5b12b93ecffa 100644
> --- a/tools/perf/tests/workloads/Build
> +++ b/tools/perf/tests/workloads/Build
> @@ -6,6 +6,7 @@ perf-y += leafloop.o
>  perf-y += sqrtloop.o
>  perf-y += brstack.o
>  perf-y += datasym.o
> +perf-y += landlock_add_rule.o
>  
>  CFLAGS_sqrtloop.o         = -g -O0 -fno-inline -U_FORTIFY_SOURCE
>  CFLAGS_leafloop.o         = -g -O0 -fno-inline -fno-omit-frame-pointer -U_FORTIFY_SOURCE
> diff --git a/tools/perf/tests/workloads/landlock_add_rule.c b/tools/perf/tests/workloads/landlock_add_rule.c
> new file mode 100644
> index 000000000000..529b5f1ea5a7
> --- /dev/null
> +++ b/tools/perf/tests/workloads/landlock_add_rule.c
> @@ -0,0 +1,32 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#include <linux/compiler.h>
> +#include <uapi/asm-generic/unistd.h> // for __NR_landlock_add_rule
> +#include <unistd.h>
> +#include <linux/landlock.h>
> +#include "../tests.h"
> +
> +static int landlock_add_rule(int argc __maybe_unused, const char **argv __maybe_unused)
> +{
> +	int fd = 11;
> +	int flags = 45;
> +
> +	struct landlock_path_beneath_attr path_beneath_attr = {
> +	    .allowed_access = LANDLOCK_ACCESS_FS_READ_FILE,
> +	    .parent_fd = 14,
> +	};
> +
> +	struct landlock_net_port_attr net_port_attr = {
> +	    .port = 19,
> +	    .allowed_access = LANDLOCK_ACCESS_NET_CONNECT_TCP,
> +	};
> +
> +	syscall(__NR_landlock_add_rule, fd, LANDLOCK_RULE_PATH_BENEATH,
> +		&path_beneath_attr, flags);
> +
> +	syscall(__NR_landlock_add_rule, fd, LANDLOCK_RULE_NET_PORT,
> +		&net_port_attr, flags);
> +
> +	return 0;
> +}
> +
> +DEFINE_WORKLOAD(landlock_add_rule);
> -- 
> 2.45.2
>
Re: [PATCH v2 5/5] perf trace: Add test for enum augmentation
Posted by Howard Chu 1 year, 7 months ago
Hello Namhyung,

On Sat, Jun 22, 2024 at 12:07 AM Namhyung Kim <namhyung@kernel.org> wrote:
>
> Hi Howard,
>
> On Wed, Jun 19, 2024 at 04:20:42PM +0800, Howard Chu wrote:
> > Check for vmlinux's existence in sysfs as prerequisite.
> >
> > Add landlock_add_rule.c workload. Trace landlock_add_rule syscall to see
> > if the output is desirable.
>
> Do you expect to add more things to the landlock workload?  I think we
> could simply call it landlock.c and probably do other things according
> to the argument, if needed (e.g. landlock add).

Shortening the name is good, I'll change it, thanks. I think
landlock_add_rule is the only syscall that we need currently, for it
contains the only enum argument of all the syscalls. I'll look into
how we can use these arguments, thank you.

Thanks,
Howard

>
> Thanks,
> Namhyung
>
> >
> > Trace the non-syscall tracepoint 'timer:hrtimer_init' and
> > 'timer:hrtimer_start', see if the 'mode' argument is augmented,
> > the 'mode' enum argument has the prefix of 'HRTIMER_MODE_'
> > in its name.
> >
> > Suggested-by: Arnaldo Carvalho de Melo <acme@kernel.org>
> > Signed-off-by: Howard Chu <howardchu95@gmail.com>
> > ---
> >  tools/perf/tests/builtin-test.c               |  1 +
> >  tools/perf/tests/shell/trace_btf_enum.sh      | 57 +++++++++++++++++++
> >  tools/perf/tests/tests.h                      |  1 +
> >  tools/perf/tests/workloads/Build              |  1 +
> >  .../perf/tests/workloads/landlock_add_rule.c  | 32 +++++++++++
> >  5 files changed, 92 insertions(+)
> >  create mode 100755 tools/perf/tests/shell/trace_btf_enum.sh
> >  create mode 100644 tools/perf/tests/workloads/landlock_add_rule.c
> >
> > diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
> > index c3d84b67ca8e..e83200415ad1 100644
> > --- a/tools/perf/tests/builtin-test.c
> > +++ b/tools/perf/tests/builtin-test.c
> > @@ -152,6 +152,7 @@ static struct test_workload *workloads[] = {
> >       &workload__sqrtloop,
> >       &workload__brstack,
> >       &workload__datasym,
> > +     &workload__landlock_add_rule,
> >  };
> >
> >  static int num_subtests(const struct test_suite *t)
> > diff --git a/tools/perf/tests/shell/trace_btf_enum.sh b/tools/perf/tests/shell/trace_btf_enum.sh
> > new file mode 100755
> > index 000000000000..4861983553ab
> > --- /dev/null
> > +++ b/tools/perf/tests/shell/trace_btf_enum.sh
> > @@ -0,0 +1,57 @@
> > +#!/bin/sh
> > +# perf trace enum augmentation tests
> > +# SPDX-License-Identifier: GPL-2.0
> > +
> > +err=0
> > +set -e
> > +
> > +syscall="landlock_add_rule"
> > +non_syscall="timer:hrtimer_init,timer:hrtimer_start"
> > +
> > +TESTPROG="perf test -w landlock_add_rule"
> > +
> > +. "$(dirname $0)"/lib/probe.sh
> > +skip_if_no_perf_trace || exit 2
> > +
> > +check_vmlinux() {
> > +  echo "Checking if vmlinux exists"
> > +  if ! ls /sys/kernel/btf/vmlinux 1>/dev/null 2>&1
> > +  then
> > +    echo "trace+enum test [Skipped missing vmlinux BTF support]"
> > +    err=2
> > +  fi
> > +}
> > +
> > +trace_landlock() {
> > +  echo "Tracing syscall ${syscall}"
> > +  if perf trace -e $syscall $TESTPROG 2>&1 | \
> > +     grep -q -E ".*landlock_add_rule\(ruleset_fd: 11, rule_type: (LANDLOCK_RULE_PATH_BENEATH|LANDLOCK_RULE_NET_PORT), rule_attr: 0x[a-f0-9]+, flags: 45\) = -1.*"
> > +  then
> > +    err=0
> > +  else
> > +    err=1
> > +  fi
> > +}
> > +
> > +trace_non_syscall() {
> > +  echo "Tracing non-syscall tracepoint ${non-syscall}"
> > +  if perf trace -e $non_syscall --max-events=1 2>&1 | \
> > +     grep -q -E '.*timer:hrtimer_.*\(.*mode: HRTIMER_MODE_.*\)$'
> > +  then
> > +    err=0
> > +  else
> > +    err=1
> > +  fi
> > +}
> > +
> > +check_vmlinux
> > +
> > +if [ $err = 0 ]; then
> > +  trace_landlock
> > +fi
> > +
> > +if [ $err = 0 ]; then
> > +  trace_non_syscall
> > +fi
> > +
> > +exit $err
> > diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
> > index 3aa7701ee0e9..69126299bb08 100644
> > --- a/tools/perf/tests/tests.h
> > +++ b/tools/perf/tests/tests.h
> > @@ -205,6 +205,7 @@ DECLARE_WORKLOAD(leafloop);
> >  DECLARE_WORKLOAD(sqrtloop);
> >  DECLARE_WORKLOAD(brstack);
> >  DECLARE_WORKLOAD(datasym);
> > +DECLARE_WORKLOAD(landlock_add_rule);
> >
> >  extern const char *dso_to_test;
> >  extern const char *test_objdump_path;
> > diff --git a/tools/perf/tests/workloads/Build b/tools/perf/tests/workloads/Build
> > index a1f34d5861e3..5b12b93ecffa 100644
> > --- a/tools/perf/tests/workloads/Build
> > +++ b/tools/perf/tests/workloads/Build
> > @@ -6,6 +6,7 @@ perf-y += leafloop.o
> >  perf-y += sqrtloop.o
> >  perf-y += brstack.o
> >  perf-y += datasym.o
> > +perf-y += landlock_add_rule.o
> >
> >  CFLAGS_sqrtloop.o         = -g -O0 -fno-inline -U_FORTIFY_SOURCE
> >  CFLAGS_leafloop.o         = -g -O0 -fno-inline -fno-omit-frame-pointer -U_FORTIFY_SOURCE
> > diff --git a/tools/perf/tests/workloads/landlock_add_rule.c b/tools/perf/tests/workloads/landlock_add_rule.c
> > new file mode 100644
> > index 000000000000..529b5f1ea5a7
> > --- /dev/null
> > +++ b/tools/perf/tests/workloads/landlock_add_rule.c
> > @@ -0,0 +1,32 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +#include <linux/compiler.h>
> > +#include <uapi/asm-generic/unistd.h> // for __NR_landlock_add_rule
> > +#include <unistd.h>
> > +#include <linux/landlock.h>
> > +#include "../tests.h"
> > +
> > +static int landlock_add_rule(int argc __maybe_unused, const char **argv __maybe_unused)
> > +{
> > +     int fd = 11;
> > +     int flags = 45;
> > +
> > +     struct landlock_path_beneath_attr path_beneath_attr = {
> > +         .allowed_access = LANDLOCK_ACCESS_FS_READ_FILE,
> > +         .parent_fd = 14,
> > +     };
> > +
> > +     struct landlock_net_port_attr net_port_attr = {
> > +         .port = 19,
> > +         .allowed_access = LANDLOCK_ACCESS_NET_CONNECT_TCP,
> > +     };
> > +
> > +     syscall(__NR_landlock_add_rule, fd, LANDLOCK_RULE_PATH_BENEATH,
> > +             &path_beneath_attr, flags);
> > +
> > +     syscall(__NR_landlock_add_rule, fd, LANDLOCK_RULE_NET_PORT,
> > +             &net_port_attr, flags);
> > +
> > +     return 0;
> > +}
> > +
> > +DEFINE_WORKLOAD(landlock_add_rule);
> > --
> > 2.45.2
> >
Re: [PATCH v2 5/5] perf trace: Add test for enum augmentation
Posted by Namhyung Kim 1 year, 7 months ago
On Fri, Jun 21, 2024 at 9:43 AM Howard Chu <howardchu95@gmail.com> wrote:
>
> Hello Namhyung,
>
> On Sat, Jun 22, 2024 at 12:07 AM Namhyung Kim <namhyung@kernel.org> wrote:
> >
> > Hi Howard,
> >
> > On Wed, Jun 19, 2024 at 04:20:42PM +0800, Howard Chu wrote:
> > > Check for vmlinux's existence in sysfs as prerequisite.
> > >
> > > Add landlock_add_rule.c workload. Trace landlock_add_rule syscall to see
> > > if the output is desirable.
> >
> > Do you expect to add more things to the landlock workload?  I think we
> > could simply call it landlock.c and probably do other things according
> > to the argument, if needed (e.g. landlock add).
>
> Shortening the name is good, I'll change it, thanks. I think
> landlock_add_rule is the only syscall that we need currently, for it
> contains the only enum argument of all the syscalls. I'll look into
> how we can use these arguments, thank you.

If you don't plan to add something, let's call it landlock.c and forget
about the argument handling for now. :)

But please add a comment in the file that it's just to test BPF
handling of enum arguments.

Thanks,
Namhyung
Re: [PATCH v2 5/5] perf trace: Add test for enum augmentation
Posted by Arnaldo Carvalho de Melo 1 year, 7 months ago
On Wed, Jun 19, 2024 at 04:20:42PM +0800, Howard Chu wrote:
> Check for vmlinux's existence in sysfs as prerequisite.
> 
> Add landlock_add_rule.c workload. Trace landlock_add_rule syscall to see
> if the output is desirable.
> 
> Trace the non-syscall tracepoint 'timer:hrtimer_init' and
> 'timer:hrtimer_start', see if the 'mode' argument is augmented,
> the 'mode' enum argument has the prefix of 'HRTIMER_MODE_'
> in its name.
> 
> Suggested-by: Arnaldo Carvalho de Melo <acme@kernel.org>
> Signed-off-by: Howard Chu <howardchu95@gmail.com>
> ---
>  tools/perf/tests/builtin-test.c               |  1 +
>  tools/perf/tests/shell/trace_btf_enum.sh      | 57 +++++++++++++++++++
>  tools/perf/tests/tests.h                      |  1 +
>  tools/perf/tests/workloads/Build              |  1 +
>  .../perf/tests/workloads/landlock_add_rule.c  | 32 +++++++++++
>  5 files changed, 92 insertions(+)
>  create mode 100755 tools/perf/tests/shell/trace_btf_enum.sh
>  create mode 100644 tools/perf/tests/workloads/landlock_add_rule.c
> 
> diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
> index c3d84b67ca8e..e83200415ad1 100644
> --- a/tools/perf/tests/builtin-test.c
> +++ b/tools/perf/tests/builtin-test.c
> @@ -152,6 +152,7 @@ static struct test_workload *workloads[] = {
>  	&workload__sqrtloop,
>  	&workload__brstack,
>  	&workload__datasym,
> +	&workload__landlock_add_rule,
>  };
>  
>  static int num_subtests(const struct test_suite *t)
> diff --git a/tools/perf/tests/shell/trace_btf_enum.sh b/tools/perf/tests/shell/trace_btf_enum.sh
> new file mode 100755
> index 000000000000..4861983553ab
> --- /dev/null
> +++ b/tools/perf/tests/shell/trace_btf_enum.sh
> @@ -0,0 +1,57 @@
> +#!/bin/sh
> +# perf trace enum augmentation tests
> +# SPDX-License-Identifier: GPL-2.0
> +
> +err=0
> +set -e
> +
> +syscall="landlock_add_rule"
> +non_syscall="timer:hrtimer_init,timer:hrtimer_start"
> +
> +TESTPROG="perf test -w landlock_add_rule"
> +
> +. "$(dirname $0)"/lib/probe.sh
> +skip_if_no_perf_trace || exit 2
> +
> +check_vmlinux() {
> +  echo "Checking if vmlinux exists"
> +  if ! ls /sys/kernel/btf/vmlinux 1>/dev/null 2>&1
> +  then
> +    echo "trace+enum test [Skipped missing vmlinux BTF support]"
> +    err=2
> +  fi
> +}
> +
> +trace_landlock() {
> +  echo "Tracing syscall ${syscall}"
> +  if perf trace -e $syscall $TESTPROG 2>&1 | \
> +     grep -q -E ".*landlock_add_rule\(ruleset_fd: 11, rule_type: (LANDLOCK_RULE_PATH_BENEATH|LANDLOCK_RULE_NET_PORT), rule_attr: 0x[a-f0-9]+, flags: 45\) = -1.*"
> +  then
> +    err=0
> +  else
> +    err=1
> +  fi
> +}
> +
> +trace_non_syscall() {
> +  echo "Tracing non-syscall tracepoint ${non-syscall}"
> +  if perf trace -e $non_syscall --max-events=1 2>&1 | \
> +     grep -q -E '.*timer:hrtimer_.*\(.*mode: HRTIMER_MODE_.*\)$'
> +  then
> +    err=0
> +  else
> +    err=1
> +  fi
> +}
> +
> +check_vmlinux
> +
> +if [ $err = 0 ]; then
> +  trace_landlock
> +fi
> +
> +if [ $err = 0 ]; then
> +  trace_non_syscall
> +fi
> +
> +exit $err
> diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
> index 3aa7701ee0e9..69126299bb08 100644
> --- a/tools/perf/tests/tests.h
> +++ b/tools/perf/tests/tests.h
> @@ -205,6 +205,7 @@ DECLARE_WORKLOAD(leafloop);
>  DECLARE_WORKLOAD(sqrtloop);
>  DECLARE_WORKLOAD(brstack);
>  DECLARE_WORKLOAD(datasym);
> +DECLARE_WORKLOAD(landlock_add_rule);
>  
>  extern const char *dso_to_test;
>  extern const char *test_objdump_path;
> diff --git a/tools/perf/tests/workloads/Build b/tools/perf/tests/workloads/Build
> index a1f34d5861e3..5b12b93ecffa 100644
> --- a/tools/perf/tests/workloads/Build
> +++ b/tools/perf/tests/workloads/Build
> @@ -6,6 +6,7 @@ perf-y += leafloop.o
>  perf-y += sqrtloop.o
>  perf-y += brstack.o
>  perf-y += datasym.o
> +perf-y += landlock_add_rule.o
>  
>  CFLAGS_sqrtloop.o         = -g -O0 -fno-inline -U_FORTIFY_SOURCE
>  CFLAGS_leafloop.o         = -g -O0 -fno-inline -fno-omit-frame-pointer -U_FORTIFY_SOURCE
> diff --git a/tools/perf/tests/workloads/landlock_add_rule.c b/tools/perf/tests/workloads/landlock_add_rule.c
> new file mode 100644
> index 000000000000..529b5f1ea5a7
> --- /dev/null
> +++ b/tools/perf/tests/workloads/landlock_add_rule.c
> @@ -0,0 +1,32 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#include <linux/compiler.h>
> +#include <uapi/asm-generic/unistd.h> // for __NR_landlock_add_rule
> +#include <unistd.h>
> +#include <linux/landlock.h>

This file was introduced on linux in 2021, unsure if it will be present
in some of the older distros we test, I'll check with my container test
suite.

Maybe we'll have to just define those LANDLOCK_ACCESS_FS_READ_FILE,
LANDLOCK_ACCESS_NET_CONNECT_TCP, etc as plain #define to make sure it
builds ok with uCLibc, musl libc and older glibc.

- Arnaldo

> +#include "../tests.h"
> +
> +static int landlock_add_rule(int argc __maybe_unused, const char **argv __maybe_unused)
> +{
> +	int fd = 11;
> +	int flags = 45;
> +
> +	struct landlock_path_beneath_attr path_beneath_attr = {
> +	    .allowed_access = LANDLOCK_ACCESS_FS_READ_FILE,
> +	    .parent_fd = 14,
> +	};
> +
> +	struct landlock_net_port_attr net_port_attr = {
> +	    .port = 19,
> +	    .allowed_access = LANDLOCK_ACCESS_NET_CONNECT_TCP,
> +	};
> +
> +	syscall(__NR_landlock_add_rule, fd, LANDLOCK_RULE_PATH_BENEATH,
> +		&path_beneath_attr, flags);
> +
> +	syscall(__NR_landlock_add_rule, fd, LANDLOCK_RULE_NET_PORT,
> +		&net_port_attr, flags);
> +
> +	return 0;
> +}
> +
> +DEFINE_WORKLOAD(landlock_add_rule);
> -- 
> 2.45.2
>
Re: [PATCH v2 5/5] perf trace: Add test for enum augmentation
Posted by Namhyung Kim 1 year, 7 months ago
Hi,

On Wed, Jun 19, 2024 at 6:51 AM Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
>
> On Wed, Jun 19, 2024 at 04:20:42PM +0800, Howard Chu wrote:
> > Check for vmlinux's existence in sysfs as prerequisite.
> >
> > Add landlock_add_rule.c workload. Trace landlock_add_rule syscall to see
> > if the output is desirable.
> >
> > Trace the non-syscall tracepoint 'timer:hrtimer_init' and
> > 'timer:hrtimer_start', see if the 'mode' argument is augmented,
> > the 'mode' enum argument has the prefix of 'HRTIMER_MODE_'
> > in its name.
> >
> > Suggested-by: Arnaldo Carvalho de Melo <acme@kernel.org>
> > Signed-off-by: Howard Chu <howardchu95@gmail.com>
> > ---
[SNIP]
> > diff --git a/tools/perf/tests/workloads/landlock_add_rule.c b/tools/perf/tests/workloads/landlock_add_rule.c
> > new file mode 100644
> > index 000000000000..529b5f1ea5a7
> > --- /dev/null
> > +++ b/tools/perf/tests/workloads/landlock_add_rule.c
> > @@ -0,0 +1,32 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +#include <linux/compiler.h>
> > +#include <uapi/asm-generic/unistd.h> // for __NR_landlock_add_rule
> > +#include <unistd.h>
> > +#include <linux/landlock.h>
>
> This file was introduced on linux in 2021, unsure if it will be present
> in some of the older distros we test, I'll check with my container test
> suite.
>
> Maybe we'll have to just define those LANDLOCK_ACCESS_FS_READ_FILE,
> LANDLOCK_ACCESS_NET_CONNECT_TCP, etc as plain #define to make sure it
> builds ok with uCLibc, musl libc and older glibc.

Maybe we can check if the syscall number is defined first and
include the landlock header.

#ifdef __NR_landlock_add_rule
#include <linux/landlock.h>
...

Then we need a way to skip the test if it's not defined.

Thanks,
Namhyung


>
> - Arnaldo
>
> > +#include "../tests.h"
> > +
> > +static int landlock_add_rule(int argc __maybe_unused, const char **argv __maybe_unused)
> > +{
> > +     int fd = 11;
> > +     int flags = 45;
> > +
> > +     struct landlock_path_beneath_attr path_beneath_attr = {
> > +         .allowed_access = LANDLOCK_ACCESS_FS_READ_FILE,
> > +         .parent_fd = 14,
> > +     };
> > +
> > +     struct landlock_net_port_attr net_port_attr = {
> > +         .port = 19,
> > +         .allowed_access = LANDLOCK_ACCESS_NET_CONNECT_TCP,
> > +     };
> > +
> > +     syscall(__NR_landlock_add_rule, fd, LANDLOCK_RULE_PATH_BENEATH,
> > +             &path_beneath_attr, flags);
> > +
> > +     syscall(__NR_landlock_add_rule, fd, LANDLOCK_RULE_NET_PORT,
> > +             &net_port_attr, flags);
> > +
> > +     return 0;
> > +}
> > +
> > +DEFINE_WORKLOAD(landlock_add_rule);
> > --
> > 2.45.2
> >
>
Re: [PATCH v2 5/5] perf trace: Add test for enum augmentation
Posted by Howard Chu 1 year, 7 months ago
On Wed, Jun 19, 2024 at 10:37 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> Hi,
>
> On Wed, Jun 19, 2024 at 6:51 AM Arnaldo Carvalho de Melo
> <acme@kernel.org> wrote:
> >
> > On Wed, Jun 19, 2024 at 04:20:42PM +0800, Howard Chu wrote:
> > > Check for vmlinux's existence in sysfs as prerequisite.
> > >
> > > Add landlock_add_rule.c workload. Trace landlock_add_rule syscall to see
> > > if the output is desirable.
> > >
> > > Trace the non-syscall tracepoint 'timer:hrtimer_init' and
> > > 'timer:hrtimer_start', see if the 'mode' argument is augmented,
> > > the 'mode' enum argument has the prefix of 'HRTIMER_MODE_'
> > > in its name.
> > >
> > > Suggested-by: Arnaldo Carvalho de Melo <acme@kernel.org>
> > > Signed-off-by: Howard Chu <howardchu95@gmail.com>
> > > ---
> [SNIP]
> > > diff --git a/tools/perf/tests/workloads/landlock_add_rule.c b/tools/perf/tests/workloads/landlock_add_rule.c
> > > new file mode 100644
> > > index 000000000000..529b5f1ea5a7
> > > --- /dev/null
> > > +++ b/tools/perf/tests/workloads/landlock_add_rule.c
> > > @@ -0,0 +1,32 @@
> > > +/* SPDX-License-Identifier: GPL-2.0 */
> > > +#include <linux/compiler.h>
> > > +#include <uapi/asm-generic/unistd.h> // for __NR_landlock_add_rule
> > > +#include <unistd.h>
> > > +#include <linux/landlock.h>
> >
> > This file was introduced on linux in 2021, unsure if it will be present
> > in some of the older distros we test, I'll check with my container test
> > suite.
> >
> > Maybe we'll have to just define those LANDLOCK_ACCESS_FS_READ_FILE,
> > LANDLOCK_ACCESS_NET_CONNECT_TCP, etc as plain #define to make sure it
> > builds ok with uCLibc, musl libc and older glibc.
>
> Maybe we can check if the syscall number is defined first and
> include the landlock header.
>
> #ifdef __NR_landlock_add_rule
> #include <linux/landlock.h>
> ...
>
> Then we need a way to skip the test if it's not defined.

Thanks for the suggestion. I'll add this to the workload script.

Thanks,
Howard

>
> Thanks,
> Namhyung
>
>
> >
> > - Arnaldo
> >
> > > +#include "../tests.h"
> > > +
> > > +static int landlock_add_rule(int argc __maybe_unused, const char **argv __maybe_unused)
> > > +{
> > > +     int fd = 11;
> > > +     int flags = 45;
> > > +
> > > +     struct landlock_path_beneath_attr path_beneath_attr = {
> > > +         .allowed_access = LANDLOCK_ACCESS_FS_READ_FILE,
> > > +         .parent_fd = 14,
> > > +     };
> > > +
> > > +     struct landlock_net_port_attr net_port_attr = {
> > > +         .port = 19,
> > > +         .allowed_access = LANDLOCK_ACCESS_NET_CONNECT_TCP,
> > > +     };
> > > +
> > > +     syscall(__NR_landlock_add_rule, fd, LANDLOCK_RULE_PATH_BENEATH,
> > > +             &path_beneath_attr, flags);
> > > +
> > > +     syscall(__NR_landlock_add_rule, fd, LANDLOCK_RULE_NET_PORT,
> > > +             &net_port_attr, flags);
> > > +
> > > +     return 0;
> > > +}
> > > +
> > > +DEFINE_WORKLOAD(landlock_add_rule);
> > > --
> > > 2.45.2
> > >
> >