Skip to content

Commit 2dd3a8a

Browse files
committed
Merge tag 'perf-tools-fixes-for-v5.17-2022-02-17' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux
Pull perf tools fixes from Arnaldo Carvalho de Melo: - Fix corrupt inject files when only last branch option is enabled with ARM CoreSight ETM - Fix use-after-free for realloc(..., 0) in libsubcmd, found by gcc 12 - Defer freeing string after possible strlen() on it in the BPF loader, found by gcc 12 - Avoid early exit in 'perf trace' due SIGCHLD from non-workload processes - Fix arm64 perf_event_attr 'perf test's wrt --call-graph initialization - Fix libperf 32-bit build for 'perf test' wrt uint64_t printf - Fix perf_cpu_map__for_each_cpu macro in libperf, providing access to the CPU iterator - Sync linux/perf_event.h UAPI with the kernel sources - Update Jiri Olsa's email address in MAINTAINERS * tag 'perf-tools-fixes-for-v5.17-2022-02-17' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux: perf bpf: Defer freeing string after possible strlen() on it perf test: Fix arm64 perf_event_attr tests wrt --call-graph initialization libsubcmd: Fix use-after-free for realloc(..., 0) libperf: Fix perf_cpu_map__for_each_cpu macro perf cs-etm: Fix corrupt inject files when only last branch option is enabled perf cs-etm: No-op refactor of synth opt usage libperf: Fix 32-bit build for tests uint64_t printf tools headers UAPI: Sync linux/perf_event.h with the kernel sources perf trace: Avoid early exit due SIGCHLD from non-workload processes MAINTAINERS: Update Jiri's email address
2 parents edbd6c6 + 31ded15 commit 2dd3a8a

File tree

16 files changed

+77
-32
lines changed

16 files changed

+77
-32
lines changed

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15147,7 +15147,7 @@ M: Ingo Molnar <mingo@redhat.com>
1514715147
M: Arnaldo Carvalho de Melo <acme@kernel.org>
1514815148
R: Mark Rutland <mark.rutland@arm.com>
1514915149
R: Alexander Shishkin <alexander.shishkin@linux.intel.com>
15150-
R: Jiri Olsa <jolsa@redhat.com>
15150+
R: Jiri Olsa <jolsa@kernel.org>
1515115151
R: Namhyung Kim <namhyung@kernel.org>
1515215152
L: linux-perf-users@vger.kernel.org
1515315153
L: linux-kernel@vger.kernel.org

tools/include/uapi/linux/perf_event.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,8 @@ struct perf_event_attr {
465465
/*
466466
* User provided data if sigtrap=1, passed back to user via
467467
* siginfo_t::si_perf_data, e.g. to permit user to identify the event.
468+
* Note, siginfo_t::si_perf_data is long-sized, and sig_data will be
469+
* truncated accordingly on 32 bit architectures.
468470
*/
469471
__u64 sig_data;
470472
};

tools/lib/perf/include/internal/cpumap.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
#define __LIBPERF_INTERNAL_CPUMAP_H
44

55
#include <linux/refcount.h>
6-
7-
/** A wrapper around a CPU to avoid confusion with the perf_cpu_map's map's indices. */
8-
struct perf_cpu {
9-
int cpu;
10-
};
6+
#include <perf/cpumap.h>
117

128
/**
139
* A sized, reference counted, sorted array of integers representing CPU

tools/lib/perf/include/perf/cpumap.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
#include <stdio.h>
88
#include <stdbool.h>
99

10+
/** A wrapper around a CPU to avoid confusion with the perf_cpu_map's map's indices. */
11+
struct perf_cpu {
12+
int cpu;
13+
};
14+
1015
LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void);
1116
LIBPERF_API struct perf_cpu_map *perf_cpu_map__default_new(void);
1217
LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list);

tools/lib/perf/libperf.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ LIBPERF_0.0.1 {
22
global:
33
libperf_init;
44
perf_cpu_map__dummy_new;
5+
perf_cpu_map__default_new;
56
perf_cpu_map__get;
67
perf_cpu_map__put;
78
perf_cpu_map__new;

tools/lib/perf/tests/test-cpumap.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ static int libperf_print(enum libperf_print_level level,
1414
int test_cpumap(int argc, char **argv)
1515
{
1616
struct perf_cpu_map *cpus;
17+
struct perf_cpu cpu;
18+
int idx;
1719

1820
__T_START;
1921

@@ -27,6 +29,15 @@ int test_cpumap(int argc, char **argv)
2729
perf_cpu_map__put(cpus);
2830
perf_cpu_map__put(cpus);
2931

32+
cpus = perf_cpu_map__default_new();
33+
if (!cpus)
34+
return -1;
35+
36+
perf_cpu_map__for_each_cpu(cpu, idx, cpus)
37+
__T("wrong cpu number", cpu.cpu != -1);
38+
39+
perf_cpu_map__put(cpus);
40+
3041
__T_END;
3142
return tests_failed == 0 ? 0 : -1;
3243
}

tools/lib/perf/tests/test-evlist.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0
22
#define _GNU_SOURCE // needed for sched.h to get sched_[gs]etaffinity and CPU_(ZERO,SET)
3+
#include <inttypes.h>
34
#include <sched.h>
45
#include <stdio.h>
56
#include <stdarg.h>
@@ -526,12 +527,12 @@ static int test_stat_multiplexing(void)
526527

527528
min = counts[0].val;
528529
for (i = 0; i < EVENT_NUM; i++) {
529-
__T_VERBOSE("Event %2d -- Raw count = %lu, run = %lu, enable = %lu\n",
530+
__T_VERBOSE("Event %2d -- Raw count = %" PRIu64 ", run = %" PRIu64 ", enable = %" PRIu64 "\n",
530531
i, counts[i].val, counts[i].run, counts[i].ena);
531532

532533
perf_counts_values__scale(&counts[i], true, &scaled);
533534
if (scaled == 1) {
534-
__T_VERBOSE("\t Scaled count = %lu (%.2lf%%, %lu/%lu)\n",
535+
__T_VERBOSE("\t Scaled count = %" PRIu64 " (%.2lf%%, %" PRIu64 "/%" PRIu64 ")\n",
535536
counts[i].val,
536537
(double)counts[i].run / (double)counts[i].ena * 100.0,
537538
counts[i].run, counts[i].ena);

tools/lib/subcmd/subcmd-util.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,8 @@ static NORETURN inline void die(const char *err, ...)
5050
static inline void *xrealloc(void *ptr, size_t size)
5151
{
5252
void *ret = realloc(ptr, size);
53-
if (!ret && !size)
54-
ret = realloc(ptr, 1);
55-
if (!ret) {
56-
ret = realloc(ptr, size);
57-
if (!ret && !size)
58-
ret = realloc(ptr, 1);
59-
if (!ret)
60-
die("Out of memory, realloc failed");
61-
}
53+
if (!ret)
54+
die("Out of memory, realloc failed");
6255
return ret;
6356
}
6457

tools/perf/builtin-trace.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,13 +1536,20 @@ static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp)
15361536
return fprintf(fp, " ? ");
15371537
}
15381538

1539+
static pid_t workload_pid = -1;
15391540
static bool done = false;
15401541
static bool interrupted = false;
15411542

1542-
static void sig_handler(int sig)
1543+
static void sighandler_interrupt(int sig __maybe_unused)
15431544
{
1544-
done = true;
1545-
interrupted = sig == SIGINT;
1545+
done = interrupted = true;
1546+
}
1547+
1548+
static void sighandler_chld(int sig __maybe_unused, siginfo_t *info,
1549+
void *context __maybe_unused)
1550+
{
1551+
if (info->si_pid == workload_pid)
1552+
done = true;
15461553
}
15471554

15481555
static size_t trace__fprintf_comm_tid(struct trace *trace, struct thread *thread, FILE *fp)
@@ -3938,7 +3945,6 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
39383945
bool draining = false;
39393946

39403947
trace->live = true;
3941-
signal(SIGCHLD, sig_handler);
39423948

39433949
if (!trace->raw_augmented_syscalls) {
39443950
if (trace->trace_syscalls && trace__add_syscall_newtp(trace))
@@ -4018,6 +4024,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
40184024
fprintf(trace->output, "Couldn't run the workload!\n");
40194025
goto out_delete_evlist;
40204026
}
4027+
workload_pid = evlist->workload.pid;
40214028
}
40224029

40234030
err = evlist__open(evlist);
@@ -4887,10 +4894,16 @@ int cmd_trace(int argc, const char **argv)
48874894
const char * const trace_subcommands[] = { "record", NULL };
48884895
int err = -1;
48894896
char bf[BUFSIZ];
4897+
struct sigaction sigchld_act;
48904898

48914899
signal(SIGSEGV, sighandler_dump_stack);
48924900
signal(SIGFPE, sighandler_dump_stack);
4893-
signal(SIGINT, sig_handler);
4901+
signal(SIGINT, sighandler_interrupt);
4902+
4903+
memset(&sigchld_act, 0, sizeof(sigchld_act));
4904+
sigchld_act.sa_flags = SA_SIGINFO;
4905+
sigchld_act.sa_sigaction = sighandler_chld;
4906+
sigaction(SIGCHLD, &sigchld_act, NULL);
48944907

48954908
trace.evlist = evlist__new();
48964909
trace.sctbl = syscalltbl__new();

tools/perf/tests/attr/README

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ Following tests are defined (with perf commands):
4545
perf record -d kill (test-record-data)
4646
perf record -F 100 kill (test-record-freq)
4747
perf record -g kill (test-record-graph-default)
48+
perf record -g kill (test-record-graph-default-aarch64)
4849
perf record --call-graph dwarf kill (test-record-graph-dwarf)
4950
perf record --call-graph fp kill (test-record-graph-fp)
51+
perf record --call-graph fp kill (test-record-graph-fp-aarch64)
5052
perf record --group -e cycles,instructions kill (test-record-group)
5153
perf record -e '{cycles,instructions}' kill (test-record-group1)
5254
perf record -e '{cycles/period=1/,instructions/period=2/}:S' kill (test-record-group2)

0 commit comments

Comments
 (0)