perf build: Update kernel headers
Subsystems (4)
Namhyung Kim
maintainerv3 cover perf build: Update kernel headers
Hello,
This is to update copy of kernel headers for v7.1. I've updated ones in the tools/perf/trace/beauty/ and left others which seem not to affect perf syscall beautifiers. This is suggested by Linus to avoid unnecessary builds of objtool and the kernel.
There are AMD IBS changes that are directly related to perf, but I think Ravi is working on it with other Zen6 changes. So I didn't include it here.
Due to the header file changes, some beautifier scripts for perf trace are updated too. This was detected by Sashiko.
Also I removed the header difference output in the default perf build and added a new make target to check it explicitly.
Thanks,
Namhyung
Namhyung Kim (7):
perf trace: Sync linux/socket.h with the kernel source perf trace: Sync uapi/linux/fs.h with the kernel source perf trace: Sync uapi/linux/mount.h with the kernel source perf trace: Sync uapi/linux/sched.h with the kernel source perf build: Add make check-headers target
perf trace: Add beautifier script for fsmount flags perf trace: Update beautifier script for clone flags
tools/perf/Makefile | 5 ++++- tools/perf/Makefile.perf | 9 +++++++- tools/perf/builtin-trace.c | 9 +++----- tools/perf/trace/beauty/beauty.h | 3 +++ tools/perf/trace/beauty/clone.sh | 4 ++++ tools/perf/trace/beauty/fsmount.c | 18 ++++++++++++++- tools/perf/trace/beauty/fsmount.sh | 11 +++------- tools/perf/trace/beauty/fsmount_attr.sh | 22 +++++++++++++++++++ .../perf/trace/beauty/include/linux/socket.h | 2 +- .../perf/trace/beauty/include/uapi/linux/fs.h | 12 ++++++++++ .../trace/beauty/include/uapi/linux/mount.h | 1 + .../trace/beauty/include/uapi/linux/sched.h | 17 ++++++++++++-- 12 files changed, 93 insertions(+), 20 deletions(-) create mode 100644 tools/perf/trace/beauty/fsmount_attr.sh
Signature · 1 line
2.54.0
Namhyung Kim
maintainerPATCH v3 1/7 perf trace: Sync linux/socket.h with the kernel source
To pick up changes from:
c66e0f453d1afa82 ("net: use ktime_t in struct scm_timestamping_internal")
This would be used to beautify networking syscall arguments and not to affect builds of other tools (e.g. objtool).
Please see tools/include/uapi/README.
--- tools/perf/trace/beauty/include/linux/socket.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/trace/beauty/include/linux/socket.h +1 -1
@@ -415,7 +415,7 @@ struct __kernel_timespec;struct old_timespec32 ;struct scm_timestamping_internal { -struct timespec64 ts[3 ]; +ktime_t ts[3 ]; };extern void put_cmsg_scm_timestamping64 (struct msghdr *msg,struct scm_timestamping_internal *tss);
Signature · 1 line
2.54.0
Namhyung Kim
maintainerPATCH v3 2/7 perf trace: Sync uapi/linux/fs.h with the kernel source
In reply to Namhyung KimTo pick up changes from:
1f662195dbc07a66 ("fs: add generic FS_IOC_SHUTDOWN definitions")
This would be used to beautify filesystem syscall arguments and not to affect builds of other tools (e.g. objtool).
Please see tools/include/uapi/README.
--- tools/perf/trace/beauty/include/uapi/linux/fs.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
tools/perf/trace/beauty/include/uapi/linux/fs.h +12 -0
@@ -657,4 +657,16 @@ struct procmap_query { __u64 build_id_addr; /* in */ }; +/* +* Shutdown the filesystem. +*/ +#define FS_IOC_SHUTDOWN _IOR('X', 125, __u32) + +/* +* Flags for FS_IOC_SHUTDOWN +*/ +#define FS_SHUTDOWN_FLAGS_DEFAULT 0x0 +#define FS_SHUTDOWN_FLAGS_LOGFLUSH 0x1/* flush log but not data*/ +#define FS_SHUTDOWN_FLAGS_NOLOGFLUSH 0x2/* don't flush log nor data */ +#endif /* _UAPI_LINUX_FS_H */
Signature · 1 line
2.54.0
Namhyung Kim
maintainerPATCH v3 3/7 perf trace: Sync uapi/linux/mount.h with the kernel source
In reply to Namhyung KimTo pick up changes from:
5e8969bd19271241 ("mount: add FSMOUNT_NAMESPACE")
This would be used to beautify mount syscall arguments and not to affect builds of other tools (e.g. objtool).
Please see tools/include/uapi/README.
--- tools/perf/trace/beauty/include/uapi/linux/mount.h | 1 + 1 file changed, 1 insertion(+)
tools/perf/trace/beauty/include/uapi/linux/mount.h +1 -0
@@ -110,6 +110,7 @@ enum fsconfig_command {* fsmount() flags. */ #define FSMOUNT_CLOEXEC 0x00000001 +#define FSMOUNT_NAMESPACE 0x00000002/* Create the mount in a new mount namespace */ /* * Mount attributes.
Signature · 1 line
2.54.0
Namhyung Kim
maintainerPATCH v3 4/7 perf trace: Sync uapi/linux/sched.h with the kernel source
In reply to Namhyung KimTo pick up changes from:
9d4e752a24f740b3 ("namespace: allow creating empty mount namespaces") c8134b5f13ae959d ("pidfd: add CLONE_PIDFD_AUTOKILL") 24baca56fafc33d4 ("clone: add CLONE_NNP")
12ae2c81b21cfaa1 ("clone: add CLONE_AUTOREAP") 2e7af192697ef2a7 ("sched/deadline: Add reporting of runtime left & ...")
This would be used to beautify scheduler syscall arguments and not to affect builds of other tools (e.g. objtool).
Please see tools/include/uapi/README.
--- .../trace/beauty/include/uapi/linux/sched.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
tools/perf/trace/beauty/include/uapi/linux/sched.h +15 -2
@@ -34,8 +34,12 @@#define CLONE_IO 0x80000000/* Clone io context */ /* Flags for the clone3() syscall. */ -#define CLONE_CLEAR_SIGHAND 0x100000000ULL/* Clear any signal handler and reset to SIG_DFL. */ -#define CLONE_INTO_CGROUP 0x200000000ULL/* Clone into a specific cgroup given the right permissions. */ +#define CLONE_CLEAR_SIGHAND (1ULL << 32)/* Clear any signal handler and reset to SIG_DFL. */ +#define CLONE_INTO_CGROUP (1ULL << 33)/* Clone into a specific cgroup given the right permissions. */ +#define CLONE_AUTOREAP (1ULL << 34)/* Auto-reap child on exit. */ +#define CLONE_NNP (1ULL << 35)/* Set no_new_privs on child. */ +#define CLONE_PIDFD_AUTOKILL (1ULL << 36)/* Kill child when clone pidfd closes. */ +#define CLONE_EMPTY_MNTNS (1ULL << 37)/* Create an empty mount namespace. */ /* * cloning flags intersect with CSIGNAL so can be used with unshare and clone3
@@ -43,6 +47,12 @@*/ #define CLONE_NEWTIME 0x00000080/* New time namespace */ +/* +* unshare flags share the bit space with clone flags but only apply to the +* unshare syscall: +*/ +#define UNSHARE_EMPTY_MNTNS 0x00100000/* Unshare an empty mount namespace. */ +#ifndef __ASSEMBLY__/** * struct clone_args - arguments for the clone3 syscall
@@ -146,4 +156,7 @@ struct clone_args { SCHED_FLAG_KEEP_ALL | \ SCHED_FLAG_UTIL_CLAMP) +/* Only for sched_getattr() own flag param, if task is SCHED_DEADLINE */ +#define SCHED_GETATTR_FLAG_DL_DYNAMIC 0x01 +#endif /* _UAPI_LINUX_SCHED_H */
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v3 4/7] perf trace: Sync uapi/linux/sched.h with the kernel source
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The perf trace beauty script fails to parse the updated CLONE_ flags. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The perf trace beauty script fails to parse the updated CLONE_ flags. --
commit e023642b20fe09480cd6197b5038b768b3c71c47
Author: Namhyung Kim <[email protected]>
perf trace: Sync uapi/linux/sched.h with the kernel source
This commit updates uapi/linux/sched.h to pick up changes related to clone flags and mount namespaces. This is intended to beautify scheduler syscall arguments in perf trace.
Quoted 4 lines
tools/perf/trace/beauty/include/uapi/linux/sched.h +0
-0
[ ... ]
tools/perf/trace/beauty/include/uapi/linux/sched.h line 42
Quoted 12 lines
tools/perf/trace/beauty/include/uapi/linux/sched.h +6
-2@@ -34,8 +34,12 @@#define CLONE_IO 0x80000000/* Clone io context */ /* Flags for the clone3() syscall. */ -#define CLONE_CLEAR_SIGHAND 0x100000000ULL/* Clear any signal handler and reset to SIG_DFL. */ -#define CLONE_INTO_CGROUP 0x200000000ULL/* Clone into a specific cgroup given the right permissions. */ +#define CLONE_CLEAR_SIGHAND (1ULL << 32)/* Clear any signal handler and reset to SIG_DFL. */ +#define CLONE_INTO_CGROUP (1ULL << 33)/* Clone into a specific cgroup given the right permissions. */ +#define CLONE_AUTOREAP (1ULL << 34)/* Auto-reap child on exit. */ +#define CLONE_NNP (1ULL << 35)/* Set no_new_privs on child. */ +#define CLONE_PIDFD_AUTOKILL (1ULL << 36)/* Kill child when clone pidfd closes. */ +#define CLONE_EMPTY_MNTNS (1ULL << 37)/* Create an empty mount namespace. */
Does this change break the beautifier script that parses these flags?
Looking at tools/perf/trace/beauty/clone.sh, it appears to rely on a regex that strictly matches hex constants like (0x[[:xdigit:]]+). Because the new flags use bit shifts instead of hex values, the grep command in the script might fail to match these lines.
This could result in both the newly added flags and the modified existing flags being silently ignored by the script, causing perf trace to fall back to printing raw hex values instead of the beautified flag names.
I noticed that a fix for this regression was provided later in the patch series in commit 640ffc6a21fbc.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Namhyung Kim
maintainerPATCH v3 5/7 perf build: Add make check-headers target
In reply to Namhyung KimDon't print header differences during the perf build as it's noisy. Mostly people won't care and find it annoying.
As it's to improve perf trace beautifier to catch up new changes mostly in UAPIs, we can make it a separate build target and call it occasionally. Make it and build-test related targets phony.
--- tools/perf/Makefile | 5 ++++- tools/perf/Makefile.perf | 1 - 2 files changed, 4 insertions(+), 2 deletions(-)
tools/perf/Makefile +4 -1
@@ -111,6 +111,9 @@ endif # MAKECMDGOALS build-test-tarball: @$(MAKE) -f tests/make REUSE_FEATURES_DUMP=1 MK=Makefile SET_PARALLEL=1 --no-print-directory out +check-headers: + @./check-headers.sh + # # All other targets get passed through: #
@@ -118,4 +121,4 @@ endif # MAKECMDGOALS $(print_msg) $(make) -.PHONY: tags TAGS FORCE Makefile +.PHONY: tags TAGS FORCE Makefile build-test build-test-tarball check-headers
tools/perf/Makefile.perf +0 -1
@@ -285,7 +285,6 @@ goals := $(filter-out all sub-make, $(MAKECMDGOALS)) $(goals) all: sub-make sub-make: fixdep - @./check-headers.sh $(Q)$(MAKE) FIXDEP_BUILT=1 -f Makefile.perf $(goals) else # force_fixdep
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v3 5/7] perf build: Add make check-headers target
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Stale documentation in tools/include/uapi/README regarding the check-headers.sh mechanism. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Stale documentation in tools/include/uapi/README regarding the check-headers.sh mechanism. --
commit a1e286351cec4f0692528127c5b9fe5ec64aafc6
Author: Namhyung Kim <[email protected]>
perf build: Add make check-headers target
This commit removes the check-headers.sh script from the default perf build process to reduce noise. It instead introduces a separate manual check-headers make target that can be run occasionally.
tools/perf/Makefile.perf goals := $(filter-out all sub-make, $(MAKECMDGOALS)) · line 288
Quoted 9 lines
tools/perf/Makefile.perf +0
-1@@ -285,7 +285,6 @@ goals := $(filter-out all sub-make, $(MAKECMDGOALS)) $(goals) all: sub-make sub-make: fixdep - @./check-headers.sh
This isn't a bug, but does this change leave the documentation in tools/include/uapi/README out of date?
The README currently states that check-headers.sh is "part of the tools/ build process" and describes a "software-enforced copy-on-write mechanism... driven by non-fatal warnings on the tooling side build".
Since the script is now a manual make target rather than running automatically during the default build, should the documentation be updated to reflect this change?
Quoted 1 line
tools/perf/Makefile.perf +0
-0$(Q)$(MAKE) FIXDEP_BUILT=1 -f Makefile.perf $(goals)
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Namhyung Kim
maintainerPATCH v3 6/7 perf trace: Add beautifier script for fsmount flags
In reply to Namhyung KimAnd move the existing one to fsmount_attr.sh to be more precise. Now the fsmount_flags[] is generated from the mount.h like below. The ilog2() + 1 is an existing pattern to handle bit flags.
$ cat tools/perf/trace/beauty/generated/fsmount_arrays.c
static const char *fsmount_flags[] = {
[ilog2(0x00000001) + 1] = "CLOEXEC",
[ilog2(0x00000002) + 1] = "NAMESPACE",
};It was found by Sashiko during the review.
--- tools/perf/Makefile.perf | 8 ++++++++ tools/perf/builtin-trace.c | 9 +++------ tools/perf/trace/beauty/beauty.h | 3 +++ tools/perf/trace/beauty/fsmount.c | 18 +++++++++++++++++- tools/perf/trace/beauty/fsmount.sh | 11 +++-------- tools/perf/trace/beauty/fsmount_attr.sh | 22 ++++++++++++++++++++++ 6 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 tools/perf/trace/beauty/fsmount_attr.sh
tools/perf/Makefile.perf +8 -0
@@ -564,6 +564,12 @@ fsmount_tbls := $(srctree)/tools/perf/trace/beauty/fsmount.sh $(fsmount_arrays): $(beauty_uapi_linux_dir)/mount.h $(fsmount_tbls) $(Q)$(SHELL) '$(fsmount_tbls)' $(beauty_uapi_linux_dir) > $@ +fsmount_attr_arrays := $(beauty_outdir)/fsmount_attr_arrays.c +fsmount_attr_tbls := $(srctree)/tools/perf/trace/beauty/fsmount_attr.sh + +$(fsmount_attr_arrays): $(beauty_uapi_linux_dir)/mount.h $(fsmount_attr_tbls) + $(Q)$(SHELL) '$(fsmount_attr_tbls)' $(beauty_uapi_linux_dir) > $@ + fspick_arrays := $(beauty_outdir)/fspick_arrays.c fspick_tbls := $(srctree)/tools/perf/trace/beauty/fspick.sh
@@ -854,6 +860,7 @@ prepare: $(OUTPUT)PERF-VERSION-FILE archheaders \ $(fadvise_advice_array) \ $(fsconfig_arrays) \ $(fsmount_arrays) \ + $(fsmount_attr_arrays) \ $(fspick_arrays) \ $(pkey_alloc_access_rights_array) \ $(sndrv_pcm_ioctl_array) \
@@ -1301,6 +1308,7 @@ clean:: $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBSYMBOL)-clean $( $(OUTPUT)$(fadvise_advice_array) \ $(OUTPUT)$(fsconfig_arrays) \ $(OUTPUT)$(fsmount_arrays) \ + $(OUTPUT)$(fsmount_attr_arrays) \ $(OUTPUT)$(fspick_arrays) \ $(OUTPUT)$(madvise_behavior_array) \ $(OUTPUT)$(mmap_flags_array) \
tools/perf/builtin-trace.c +3 -6
@@ -771,11 +771,6 @@ static const char *bpf_cmd[] = { }; static DEFINE_STRARRAY(bpf_cmd, "BPF_"); -static const char *fsmount_flags[] = { - [1 ] ="CLOEXEC" , -}; -static DEFINE_STRARRAY(fsmount_flags, "FSMOUNT_"); -#include "trace/beauty/generated/fsconfig_arrays.c" static DEFINE_STRARRAY(fsconfig_cmds, "FSCONFIG_");
@@ -1202,7 +1197,9 @@ static const struct syscall_fmt syscall_fmts[] = { { .name = "fsconfig", .arg = { [1] = STRARRAY(cmd, fsconfig_cmds), }, }, { .name = "fsmount", - .arg = { [1] = STRARRAY_FLAGS(flags, fsmount_flags), + .arg = { [1] = { .scnprintf = SCA_FSMOUNT_FLAGS, /* fsmount_flags */ + .strtoul = STUL_STRARRAYS, + .show_zero = true, }, [2] = { .scnprintf = SCA_FSMOUNT_ATTR_FLAGS, /* attr_flags */ }, }, }, { .name = "fspick", .arg = { [0] = { .scnprintf = SCA_FDAT, /* dfd */ },
tools/perf/trace/beauty/beauty.h +3 -0
@@ -179,6 +179,9 @@ size_t syscall_arg__scnprintf_fcntl_arg(char *bf, size_t size, struct syscall_arsize_t syscall_arg__scnprintf_flock (char *bf,size_t size,struct syscall_arg *arg);#define SCA_FLOCK syscall_arg__scnprintf_flock +size_t syscall_arg__scnprintf_fsmount_flags (char *bf,size_t size,struct syscall_arg *arg); +#define SCA_FSMOUNT_FLAGS syscall_arg__scnprintf_fsmount_flags +size_t syscall_arg__scnprintf_fsmount_attr_flags (char *bf,size_t size,struct syscall_arg *arg);#define SCA_FSMOUNT_ATTR_FLAGS syscall_arg__scnprintf_fsmount_attr_flags
tools/perf/trace/beauty/fsmount.c +17 -1
@@ -16,9 +16,25 @@#define MOUNT_ATTR_RELATIME 0x00000000/* - Update atime relative to mtime/ctime. */ #endif -static size_t fsmount__scnprintf_attr_flags (unsigned long flags,char *bf,size_t size,bool show_prefix) + +static size_t fsmount__scnprintf_flags (unsigned long flags,char *bf,size_t size,bool show_prefix) {#include "trace/beauty/generated/fsmount_arrays.c" + static DEFINE_STRARRAY(fsmount_flags, "FSMOUNT_"); + +return strarray__scnprintf_flags (&strarray__fsmount_flags, bf, size, show_prefix, flags); +} + +size_t syscall_arg__scnprintf_fsmount_flags (char *bf,size_t size,struct syscall_arg *arg) +{ +unsigned long flags = arg->val; + +return fsmount__scnprintf_flags (flags, bf, size, arg->show_string_prefix); +} + +static size_t fsmount__scnprintf_attr_flags (unsigned long flags,char *bf,size_t size,bool show_prefix) +{ +#include "trace/beauty/generated/fsmount_attr_arrays.c" static DEFINE_STRARRAY(fsmount_attr_flags, "MOUNT_ATTR_");size_t printed =0 ;
tools/perf/trace/beauty/fsmount.sh +3 -8
@@ -9,14 +9,9 @@ fi linux_mount=${beauty_uapi_linux_dir}/mount.h -# Remove MOUNT_ATTR_RELATIME as it is zeros, handle it a special way in the beautifier -# Only handle MOUNT_ATTR_ followed by a capital letter/num as __ is special case -# for things like MOUNT_ATTR__ATIME that is a mask for the possible ATIME handling -# bits. Special case it as well in the beautifier - -printf "static const char *fsmount_attr_flags[] = {\n" -regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MOUNT_ATTR_([[:alnum:]][[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*' -grep -E $regex ${linux_mount} | grep -v MOUNT_ATTR_RELATIME | \ +printf "static const char *fsmount_flags[] = {\n" +regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+FSMOUNT_([[:alnum:]][[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*' +grep -E $regex ${linux_mount} | \ sed -r "s/$regex/\2 \1/g" | \ xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n" printf "};\n"
tools/perf/trace/beauty/fsmount_attr.sh new file +22 -0
@@ -0,0 +1,22 @@ +#!/bin/sh +# SPDX-License-Identifier: LGPL-2.1 + +if [ $# -ne 1 ] ; then + beauty_uapi_linux_dir=tools/perf/trace/beauty/include/uapi/linux/ +else + beauty_uapi_linux_dir=$1 +fi + +linux_mount=${beauty_uapi_linux_dir}/mount.h + +# Remove MOUNT_ATTR_RELATIME as it is zeros, handle it a special way in the beautifier +# Only handle MOUNT_ATTR_ followed by a capital letter/num as __ is special case +# for things like MOUNT_ATTR__ATIME that is a mask for the possible ATIME handling +# bits. Special case it as well in the beautifier + +printf "static const char *fsmount_attr_flags[] = {\n" +regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MOUNT_ATTR_([[:alnum:]][[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*' +grep -E $regex ${linux_mount} | grep -v MOUNT_ATTR_RELATIME | \ + sed -r "s/$regex/\2 \1/g" | \ + xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n" +printf "};\n"
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v3 6/7] perf trace: Add beautifier script for fsmount flags
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] NULL pointer dereference when parsing string filters for the `fsmount` syscall flags in `perf…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] NULL pointer dereference when parsing string filters for the fsmount syscall flags in perf trace. --
commit f130ece1ce49e8a473ebf43d62d18d2a42d44946
Author: Namhyung Kim <[email protected]>
perf trace: Add beautifier script for fsmount flags
This commit introduces a beautifier script to generate fsmount_flags[] from mount.h, moving the existing array to fsmount_attr.sh.
Quoted 3 lines
tools/perf/builtin-trace.c +0
-0
[ ... ]
tools/perf/builtin-trace.c static const struct syscall_fmt syscall_fmts[] = { · line 1202
Quoted 8 lines
tools/perf/builtin-trace.c +3
-1@@ -1202,7 +1197,9 @@ static const struct syscall_fmt syscall_fmts[] = { { .name = "fsconfig", .arg = { [1] = STRARRAY(cmd, fsconfig_cmds), }, }, { .name = "fsmount", - .arg = { [1] = STRARRAY_FLAGS(flags, fsmount_flags), + .arg = { [1] = { .scnprintf = SCA_FSMOUNT_FLAGS, /* fsmount_flags */ + .strtoul = STUL_STRARRAYS, + .show_zero = true, },
Could this cause a NULL pointer dereference when parsing string filters?
Because .parm is omitted here, it defaults to NULL. If a user runs a trace command with a string filter like perf trace -e 'fsmount(flags==CLOEXEC)', the STUL_STRARRAYS parser will pass this NULL .parm to strarrays__strtoul(), which will unconditionally dereference sas->nr_entries.
Also, does STUL_STRARRAYS expect a struct strarrays rather than a struct strarray? Since fsmount flags are bitmasks, should this use STUL_STRARRAY_FLAGS along with an exported strarray instead?
Quoted 3 lines
tools/perf/builtin-trace.c +0
-0[2] = { .scnprintf = SCA_FSMOUNT_ATTR_FLAGS, /* attr_flags */ }, }, }, { .name = "fspick", .arg = { [0] = { .scnprintf = SCA_FDAT, /* dfd */ },
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Namhyung Kim
maintainerPATCH v3 7/7 perf trace: Update beautifier script for clone flags
In reply to Namhyung KimAccording to the change in the sched.h, update the script to generate the flags array like below. Note that '+1' is needed to detect bitmask pattern at index 0.
$ cat tools/perf/trace/beauty/generated/clone_flags_array.c
static const char *clone_flags[] = {
[ilog2(0x00000100) + 1] = "VM",
[ilog2(0x00000200) + 1] = "FS",
[ilog2(0x00000400) + 1] = "FILES",
[ilog2(0x00000800) + 1] = "SIGHAND",
[ilog2(0x00001000) + 1] = "PIDFD",
[ilog2(0x00002000) + 1] = "PTRACE",
[ilog2(0x00004000) + 1] = "VFORK",
[ilog2(0x00008000) + 1] = "PARENT",
[ilog2(0x00010000) + 1] = "THREAD",
[ilog2(0x00020000) + 1] = "NEWNS",
[ilog2(0x00040000) + 1] = "SYSVSEM",
[ilog2(0x00080000) + 1] = "SETTLS",
[ilog2(0x00100000) + 1] = "PARENT_SETTID",
[ilog2(0x00200000) + 1] = "CHILD_CLEARTID",
[ilog2(0x00400000) + 1] = "DETACHED",
[ilog2(0x00800000) + 1] = "UNTRACED",
[ilog2(0x01000000) + 1] = "CHILD_SETTID",
[ilog2(0x02000000) + 1] = "NEWCGROUP",
[ilog2(0x04000000) + 1] = "NEWUTS",
[ilog2(0x08000000) + 1] = "NEWIPC",
[ilog2(0x10000000) + 1] = "NEWUSER",
[ilog2(0x20000000) + 1] = "NEWPID",
[ilog2(0x40000000) + 1] = "NEWNET",
[ilog2(0x80000000) + 1] = "IO",
[ilog2(0x00000080) + 1] = "NEWTIME",
[32 + 1] = "CLEAR_SIGHAND",
[33 + 1] = "INTO_CGROUP",
[34 + 1] = "AUTOREAP",
[35 + 1] = "NNP",
[36 + 1] = "PIDFD_AUTOKILL",
[37 + 1] = "EMPTY_MNTNS",
};This was found by Sashiko during review.
--- tools/perf/trace/beauty/clone.sh | 4 ++++ 1 file changed, 4 insertions(+)
tools/perf/trace/beauty/clone.sh +4 -0
@@ -14,4 +14,8 @@ regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+CLONE_([^_]+[[:alnum:]_]+)[[: grep -E $regex ${linux_sched} | \ sed -r "s/$regex/\2 \1/g" | \ xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n" +regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+CLONE_([^_]+[[:alnum:]_]+)[[:space:]]+\(1ULL[[:space:]]*<<[[:space:]]*([[:digit:]]+)\)[[:space:]]*.*' +grep -E $regex ${linux_sched} | \ + sed -r "s/$regex/\2 \1/g" | \ + xargs printf "\t[%s + 1] = \"%s\",\n" printf "};\n"
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v3 7/7] perf trace: Update beautifier script for clone flags
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] Adding 64-bit flag masks introduces an undefined behavior shift overflow on 32-bit platforms…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Adding 64-bit flag masks introduces an undefined behavior shift overflow on 32-bit platforms, causing corrupt perf trace output.
- [Medium] Missing empty input handling in xargs generates a buggy C array entry when compiled against older kernel headers. --
commit 0277447cb377648d9d63a42e778d841a1fdaac29
Author: Namhyung Kim <[email protected]> perf trace: Update beautifier script for clone flags
This commit updates the clone beautifier script to parse newer clone flags that use the 1ULL shift pattern. It extracts 64-bit clone3 flags up to bit 37 to generate the clone_flags array.
[ ... ]
Quoted 9 lines
[ilog2(0x80000000) + 1] = "IO",
[ilog2(0x00000080) + 1] = "NEWTIME",
[32 + 1] = "CLEAR_SIGHAND",
[33 + 1] = "INTO_CGROUP",
[34 + 1] = "AUTOREAP",
[35 + 1] = "NNP",
[36 + 1] = "PIDFD_AUTOKILL",
[37 + 1] = "EMPTY_MNTNS",
};Does this cause undefined behavior on 32-bit platforms?
The generated array now includes entries for bits up to 37. When perf trace consumes this array in strarray__scnprintf_flags(), it computes the bit mask using an unsigned long shift:
unsigned long bit = 1UL << (i - 1);
On 32-bit architectures, unsigned long is 32 bits. Shifting by 32 or more is undefined behavior and often wraps the shift count. This could cause standard 32-bit clone syscalls to falsely match the new 64-bit flag names if the corresponding wrapped lower bit is set, corrupting the tool's output.
tools/perf/trace/beauty/clone.sh regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+CLONE_([^_]+[[:alnum:]_]+)[[: · line 20
Quoted 12 lines
tools/perf/trace/beauty/clone.sh +4
-0@@ -14,4 +14,8 @@ regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+CLONE_([^_]+[[:alnum:]_]+)[[: grep -E $regex ${linux_sched} | \ sed -r "s/$regex/\2 \1/g" | \ xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n" +regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+CLONE_([^_]+[[:alnum:]_]+)[[:space:]]+\(1ULL[[:space:]]*<<[[:space:]]*([[:digit:]]+)\)[[:space:]]*.*' +grep -E $regex ${linux_sched} | \ + sed -r "s/$regex/\2 \1/g" | \ + xargs printf "\t[%s + 1] = \"%s\",\n"
Should this use xargs -r?
If the script is run against older kernel headers that lack the new clone3 flags using the 1ULL shift pattern, grep will yield no output. However, xargs will still execute printf once with empty arguments.
This results in a generated entry of:
[ + 1] = "",
which compiles as index 1 (mapping to bit 0) and could cause perf trace to print confusing empty suffixes for syscalls that set bit 0.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Quoted 12 lines · Namhyung Kim
Hello,
This is to update copy of kernel headers for v7.1. I've updated ones in the
tools/perf/trace/beauty/and left others which seem not to affect perf syscall beautifiers. This is suggested by Linus to avoid unnecessary builds of objtool and the kernel.There are AMD IBS changes that are directly related to perf, but I think Ravi is working on it with other Zen6 changes. So I didn't include it here.
Quoted 8 lines
Due to the header file changes, some beautifier scripts for perf trace are updated too. This was detected by Sashiko.
Also I removed the header difference output in the default perf build and added a new make target to check it explicitly.
Thanks,
Namhyung
There were some issues with sashiko and the reviews are still pending:
https://sashiko.dev/#/patchset/20260510202346.49853-1-namhyung%40kernel.org
Manually looking through the changes they all LGTM so for the series:
Thanks,
Ian
Quoted 27 lines
Namhyung Kim (7):
perf trace: Synclinux/socket.hwith the kernel source perf trace: Syncuapi/linux/fs.hwith the kernel source perf trace: Syncuapi/linux/mount.hwith the kernel source perf trace: Syncuapi/linux/sched.hwith the kernel source perf build: Add make check-headers target
perf trace: Add beautifier script for fsmount flags perf trace: Update beautifier script for clone flagstools/perf/Makefile | 5 ++++- tools/perf/Makefile.perf | 9 +++++++- tools/perf/builtin-trace.c | 9 +++----- tools/perf/trace/beauty/beauty.h | 3 +++ tools/perf/trace/beauty/clone.sh | 4 ++++ tools/perf/trace/beauty/fsmount.c | 18 ++++++++++++++- tools/perf/trace/beauty/fsmount.sh | 11 +++------- tools/perf/trace/beauty/fsmount_attr.sh | 22 +++++++++++++++++++ .../perf/trace/beauty/include/linux/socket.h | 2 +- .../perf/trace/beauty/include/uapi/linux/fs.h | 12 ++++++++++ .../trace/beauty/include/uapi/linux/mount.h | 1 + .../trace/beauty/include/uapi/linux/sched.h | 17 ++++++++++++-- 12 files changed, 93 insertions(+), 20 deletions(-) create mode 100644 tools/perf/trace/beauty/fsmount_attr.sh--
2.54.0