Skip to content

Commit 998ccc3

Browse files
committed
Merge tag 'perf-tools-fixes-for-v6.18-2-2025-11-16' of git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools
Pull perf tools fixes from Arnaldo Carvalho de Melo: - Fix writing bpf_prog (infos|btfs)_cnt to data file, to not generate invalid perf.data files in some corner cases. - Fix 'perf top' segfault by ensuring libbfd is initialized. This is an opt-in feature due to license incompatibilities. - Fix segfault in 'perf lock' due to missing kernel map. - Fix 'perf lock contention' test. - Don't fail fast path detection if binutils-devel isn't available. - Sync KVM's vmx.h with the kernel to pick SEAMCALL exit reason. * tag 'perf-tools-fixes-for-v6.18-2-2025-11-16' of git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools: perf libbfd: Ensure libbfd is initialized prior to use perf test: Fix lock contention test perf lock: Fix segfault due to missing kernel map tools headers UAPI: Sync KVM's vmx.h with the kernel to pick SEAMCALL exit reason perf build: Don't fail fast path feature detection when binutils-devel is not available perf header: Write bpf_prog (infos|btfs)_cnt to data file
2 parents 7ba45f1 + b72b813 commit 998ccc3

File tree

9 files changed

+68
-22
lines changed

9 files changed

+68
-22
lines changed

tools/arch/x86/include/uapi/asm/vmx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
#define EXIT_REASON_TPAUSE 68
9494
#define EXIT_REASON_BUS_LOCK 74
9595
#define EXIT_REASON_NOTIFY 75
96+
#define EXIT_REASON_SEAMCALL 76
9697
#define EXIT_REASON_TDCALL 77
9798
#define EXIT_REASON_MSR_READ_IMM 84
9899
#define EXIT_REASON_MSR_WRITE_IMM 85

tools/build/feature/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ all: $(FILES)
107107
__BUILD = $(CC) $(CFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS)
108108
BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1
109109
BUILD_BFD = $(BUILD) -DPACKAGE='"perf"' -lbfd -ldl
110-
BUILD_ALL = $(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -lslang $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl -lz -llzma -lzstd
110+
BUILD_ALL = $(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -lslang $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -ldl -lz -llzma -lzstd
111111

112112
__BUILDXX = $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(@F)) $(LDFLAGS)
113113
BUILDXX = $(__BUILDXX) > $(@:.bin=.make.output) 2>&1
114114

115115
###############################
116116

117117
$(OUTPUT)test-all.bin:
118-
$(BUILD_ALL) || $(BUILD_ALL) -lopcodes -liberty
118+
$(BUILD_ALL)
119119

120120
$(OUTPUT)test-hello.bin:
121121
$(BUILD)

tools/perf/Makefile.config

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,6 @@ FEATURE_CHECK_LDFLAGS-libpython := $(PYTHON_EMBED_LDOPTS)
354354

355355
FEATURE_CHECK_LDFLAGS-libaio = -lrt
356356

357-
FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl
358-
FEATURE_CHECK_LDFLAGS-disassembler-init-styled = -lbfd -lopcodes -ldl
359-
360357
CORE_CFLAGS += -fno-omit-frame-pointer
361358
CORE_CFLAGS += -Wall
362359
CORE_CFLAGS += -Wextra
@@ -930,6 +927,8 @@ ifdef BUILD_NONDISTRO
930927

931928
ifeq ($(feature-libbfd), 1)
932929
EXTLIBS += -lbfd -lopcodes
930+
FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl
931+
FEATURE_CHECK_LDFLAGS-disassembler-init-styled = -lbfd -lopcodes -ldl
933932
else
934933
# we are on a system that requires -liberty and (maybe) -lz
935934
# to link against -lbfd; test each case individually here

tools/perf/builtin-lock.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,7 @@ static int __cmd_report(bool display_info)
18671867
eops.sample = process_sample_event;
18681868
eops.comm = perf_event__process_comm;
18691869
eops.mmap = perf_event__process_mmap;
1870+
eops.mmap2 = perf_event__process_mmap2;
18701871
eops.namespaces = perf_event__process_namespaces;
18711872
eops.tracing_data = perf_event__process_tracing_data;
18721873
session = perf_session__new(&data, &eops);
@@ -2023,6 +2024,7 @@ static int __cmd_contention(int argc, const char **argv)
20232024
eops.sample = process_sample_event;
20242025
eops.comm = perf_event__process_comm;
20252026
eops.mmap = perf_event__process_mmap;
2027+
eops.mmap2 = perf_event__process_mmap2;
20262028
eops.tracing_data = perf_event__process_tracing_data;
20272029

20282030
perf_env__init(&host_env);

tools/perf/tests/shell/lock_contention.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ cleanup() {
1313
rm -f ${perfdata}
1414
rm -f ${result}
1515
rm -f ${errout}
16-
trap - EXIT TERM INT
16+
trap - EXIT TERM INT ERR
1717
}
1818

1919
trap_cleanup() {
20+
if (( $? == 139 )); then #SIGSEGV
21+
err=1
22+
fi
2023
echo "Unexpected signal in ${FUNCNAME[1]}"
2124
cleanup
2225
exit ${err}
2326
}
24-
trap trap_cleanup EXIT TERM INT
27+
trap trap_cleanup EXIT TERM INT ERR
2528

2629
check() {
2730
if [ "$(id -u)" != 0 ]; then
@@ -145,7 +148,7 @@ test_aggr_cgroup()
145148
fi
146149

147150
# the perf lock contention output goes to the stderr
148-
perf lock con -a -b -g -E 1 -q -- perf bench sched messaging -p > /dev/null 2> ${result}
151+
perf lock con -a -b --lock-cgroup -E 1 -q -- perf bench sched messaging -p > /dev/null 2> ${result}
149152
if [ "$(cat "${result}" | wc -l)" != "1" ]; then
150153
echo "[Fail] BPF result count is not 1:" "$(cat "${result}" | wc -l)"
151154
err=1
@@ -271,15 +274,15 @@ test_cgroup_filter()
271274
return
272275
fi
273276

274-
perf lock con -a -b -g -E 1 -F wait_total -q -- perf bench sched messaging -p > /dev/null 2> ${result}
277+
perf lock con -a -b --lock-cgroup -E 1 -F wait_total -q -- perf bench sched messaging -p > /dev/null 2> ${result}
275278
if [ "$(cat "${result}" | wc -l)" != "1" ]; then
276279
echo "[Fail] BPF result should have a cgroup result:" "$(cat "${result}")"
277280
err=1
278281
exit
279282
fi
280283

281284
cgroup=$(cat "${result}" | awk '{ print $3 }')
282-
perf lock con -a -b -g -E 1 -G "${cgroup}" -q -- perf bench sched messaging -p > /dev/null 2> ${result}
285+
perf lock con -a -b --lock-cgroup -E 1 -G "${cgroup}" -q -- perf bench sched messaging -p > /dev/null 2> ${result}
283286
if [ "$(cat "${result}" | wc -l)" != "1" ]; then
284287
echo "[Fail] BPF result should have a result with cgroup filter:" "$(cat "${cgroup}")"
285288
err=1
@@ -338,4 +341,5 @@ test_aggr_task_stack_filter
338341
test_cgroup_filter
339342
test_csv_output
340343

344+
cleanup
341345
exit ${err}

tools/perf/util/header.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,12 +1022,9 @@ static int write_bpf_prog_info(struct feat_fd *ff,
10221022

10231023
down_read(&env->bpf_progs.lock);
10241024

1025-
if (env->bpf_progs.infos_cnt == 0)
1026-
goto out;
1027-
10281025
ret = do_write(ff, &env->bpf_progs.infos_cnt,
10291026
sizeof(env->bpf_progs.infos_cnt));
1030-
if (ret < 0)
1027+
if (ret < 0 || env->bpf_progs.infos_cnt == 0)
10311028
goto out;
10321029

10331030
root = &env->bpf_progs.infos;
@@ -1067,13 +1064,10 @@ static int write_bpf_btf(struct feat_fd *ff,
10671064

10681065
down_read(&env->bpf_progs.lock);
10691066

1070-
if (env->bpf_progs.btfs_cnt == 0)
1071-
goto out;
1072-
10731067
ret = do_write(ff, &env->bpf_progs.btfs_cnt,
10741068
sizeof(env->bpf_progs.btfs_cnt));
10751069

1076-
if (ret < 0)
1070+
if (ret < 0 || env->bpf_progs.btfs_cnt == 0)
10771071
goto out;
10781072

10791073
root = &env->bpf_progs.btfs;

tools/perf/util/libbfd.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,39 @@ struct a2l_data {
3838
asymbol **syms;
3939
};
4040

41+
static bool perf_bfd_lock(void *bfd_mutex)
42+
{
43+
mutex_lock(bfd_mutex);
44+
return true;
45+
}
46+
47+
static bool perf_bfd_unlock(void *bfd_mutex)
48+
{
49+
mutex_unlock(bfd_mutex);
50+
return true;
51+
}
52+
53+
static void perf_bfd_init(void)
54+
{
55+
static struct mutex bfd_mutex;
56+
57+
mutex_init_recursive(&bfd_mutex);
58+
59+
if (bfd_init() != BFD_INIT_MAGIC) {
60+
pr_err("Error initializing libbfd\n");
61+
return;
62+
}
63+
if (!bfd_thread_init(perf_bfd_lock, perf_bfd_unlock, &bfd_mutex))
64+
pr_err("Error initializing libbfd threading\n");
65+
}
66+
67+
static void ensure_bfd_init(void)
68+
{
69+
static pthread_once_t bfd_init_once = PTHREAD_ONCE_INIT;
70+
71+
pthread_once(&bfd_init_once, perf_bfd_init);
72+
}
73+
4174
static int bfd_error(const char *string)
4275
{
4376
const char *errmsg;
@@ -132,6 +165,7 @@ static struct a2l_data *addr2line_init(const char *path)
132165
bfd *abfd;
133166
struct a2l_data *a2l = NULL;
134167

168+
ensure_bfd_init();
135169
abfd = bfd_openr(path, NULL);
136170
if (abfd == NULL)
137171
return NULL;
@@ -288,6 +322,7 @@ int dso__load_bfd_symbols(struct dso *dso, const char *debugfile)
288322
bfd *abfd;
289323
u64 start, len;
290324

325+
ensure_bfd_init();
291326
abfd = bfd_openr(debugfile, NULL);
292327
if (!abfd)
293328
return -1;
@@ -393,6 +428,7 @@ int libbfd__read_build_id(const char *filename, struct build_id *bid, bool block
393428
if (fd < 0)
394429
return -1;
395430

431+
ensure_bfd_init();
396432
abfd = bfd_fdopenr(filename, /*target=*/NULL, fd);
397433
if (!abfd)
398434
return -1;
@@ -421,6 +457,7 @@ int libbfd_filename__read_debuglink(const char *filename, char *debuglink,
421457
asection *section;
422458
bfd *abfd;
423459

460+
ensure_bfd_init();
424461
abfd = bfd_openr(filename, NULL);
425462
if (!abfd)
426463
return -1;
@@ -480,6 +517,7 @@ int symbol__disassemble_bpf_libbfd(struct symbol *sym __maybe_unused,
480517
memset(tpath, 0, sizeof(tpath));
481518
perf_exe(tpath, sizeof(tpath));
482519

520+
ensure_bfd_init();
483521
bfdf = bfd_openr(tpath, NULL);
484522
if (bfdf == NULL)
485523
abort();

tools/perf/util/mutex.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static void check_err(const char *fn, int err)
1717

1818
#define CHECK_ERR(err) check_err(__func__, err)
1919

20-
static void __mutex_init(struct mutex *mtx, bool pshared)
20+
static void __mutex_init(struct mutex *mtx, bool pshared, bool recursive)
2121
{
2222
pthread_mutexattr_t attr;
2323

@@ -27,21 +27,27 @@ static void __mutex_init(struct mutex *mtx, bool pshared)
2727
/* In normal builds enable error checking, such as recursive usage. */
2828
CHECK_ERR(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK));
2929
#endif
30+
if (recursive)
31+
CHECK_ERR(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE));
3032
if (pshared)
3133
CHECK_ERR(pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED));
32-
3334
CHECK_ERR(pthread_mutex_init(&mtx->lock, &attr));
3435
CHECK_ERR(pthread_mutexattr_destroy(&attr));
3536
}
3637

3738
void mutex_init(struct mutex *mtx)
3839
{
39-
__mutex_init(mtx, /*pshared=*/false);
40+
__mutex_init(mtx, /*pshared=*/false, /*recursive=*/false);
4041
}
4142

4243
void mutex_init_pshared(struct mutex *mtx)
4344
{
44-
__mutex_init(mtx, /*pshared=*/true);
45+
__mutex_init(mtx, /*pshared=*/true, /*recursive=*/false);
46+
}
47+
48+
void mutex_init_recursive(struct mutex *mtx)
49+
{
50+
__mutex_init(mtx, /*pshared=*/false, /*recursive=*/true);
4551
}
4652

4753
void mutex_destroy(struct mutex *mtx)

tools/perf/util/mutex.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ void mutex_init(struct mutex *mtx);
104104
* process-private attribute.
105105
*/
106106
void mutex_init_pshared(struct mutex *mtx);
107+
/* Initializes a mutex that may be recursively held on the same thread. */
108+
void mutex_init_recursive(struct mutex *mtx);
107109
void mutex_destroy(struct mutex *mtx);
108110

109111
void mutex_lock(struct mutex *mtx) EXCLUSIVE_LOCK_FUNCTION(*mtx);

0 commit comments

Comments
 (0)