Skip to content

Commit a7092c8

Browse files
committed
Merge tag 'perf-core-2020-06-01' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf updates from Ingo Molnar: "Kernel side changes: - Add AMD Fam17h RAPL support - Introduce CAP_PERFMON to kernel and user space - Add Zhaoxin CPU support - Misc fixes and cleanups Tooling changes: - perf record: Introduce '--switch-output-event' to use arbitrary events to be setup and read from a side band thread and, when they take place a signal be sent to the main 'perf record' thread, reusing the core for '--switch-output' to take perf.data snapshots from the ring buffer used for '--overwrite', e.g.: # perf record --overwrite -e sched:* \ --switch-output-event syscalls:*connect* \ workload will take perf.data.YYYYMMDDHHMMSS snapshots up to around the connect syscalls. Add '--num-synthesize-threads' option to control degree of parallelism of the synthesize_mmap() code which is scanning /proc/PID/task/PID/maps and can be time consuming. This mimics pre-existing behaviour in 'perf top'. - perf bench: Add a multi-threaded synthesize benchmark and kallsyms parsing benchmark. - Intel PT support: Stitch LBR records from multiple samples to get deeper backtraces, there are caveats, see the csets for details. Allow using Intel PT to synthesize callchains for regular events. Add support for synthesizing branch stacks for regular events (cycles, instructions, etc) from Intel PT data. Misc changes: - Updated perf vendor events for power9 and Coresight. - Add flamegraph.py script via 'perf flamegraph' - Misc other changes, fixes and cleanups - see the Git log for details Also, since over the last couple of years perf tooling has matured and decoupled from the kernel perf changes to a large degree, going forward Arnaldo is going to send perf tooling changes via direct pull requests" * tag 'perf-core-2020-06-01' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (163 commits) perf/x86/rapl: Add AMD Fam17h RAPL support perf/x86/rapl: Make perf_probe_msr() more robust and flexible perf/x86/rapl: Flip logic on default events visibility perf/x86/rapl: Refactor to share the RAPL code between Intel and AMD CPUs perf/x86/rapl: Move RAPL support to common x86 code perf/core: Replace zero-length array with flexible-array perf/x86: Replace zero-length array with flexible-array perf/x86/intel: Add more available bits for OFFCORE_RESPONSE of Intel Tremont perf/x86/rapl: Add Ice Lake RAPL support perf flamegraph: Use /bin/bash for report and record scripts perf cs-etm: Move definition of 'traceid_list' global variable from header file libsymbols kallsyms: Move hex2u64 out of header libsymbols kallsyms: Parse using io api perf bench: Add kallsyms parsing perf: cs-etm: Update to build with latest opencsd version. perf symbol: Fix kernel symbol address display perf inject: Rename perf_evsel__*() operating on 'struct evsel *' to evsel__*() perf annotate: Rename perf_evsel__*() operating on 'struct evsel *' to evsel__*() perf trace: Rename perf_evsel__*() operating on 'struct evsel *' to evsel__*() perf script: Rename perf_evsel__*() operating on 'struct evsel *' to evsel__*() ...
2 parents 69fc06f + 5cde265 commit a7092c8

File tree

194 files changed

+5221
-1993
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+5221
-1993
lines changed

Documentation/admin-guide/perf-security.rst

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.. _perf_security:
22

3-
Perf Events and tool security
3+
Perf events and tool security
44
=============================
55

66
Overview
@@ -42,11 +42,11 @@ categories:
4242
Data that belong to the fourth category can potentially contain
4343
sensitive process data. If PMUs in some monitoring modes capture values
4444
of execution context registers or data from process memory then access
45-
to such monitoring capabilities requires to be ordered and secured
46-
properly. So, perf_events/Perf performance monitoring is the subject for
47-
security access control management [5]_ .
45+
to such monitoring modes requires to be ordered and secured properly.
46+
So, perf_events performance monitoring and observability operations are
47+
the subject for security access control management [5]_ .
4848

49-
perf_events/Perf access control
49+
perf_events access control
5050
-------------------------------
5151

5252
To perform security checks, the Linux implementation splits processes
@@ -66,11 +66,25 @@ into distinct units, known as capabilities [6]_ , which can be
6666
independently enabled and disabled on per-thread basis for processes and
6767
files of unprivileged users.
6868

69-
Unprivileged processes with enabled CAP_SYS_ADMIN capability are treated
69+
Unprivileged processes with enabled CAP_PERFMON capability are treated
7070
as privileged processes with respect to perf_events performance
71-
monitoring and bypass *scope* permissions checks in the kernel.
72-
73-
Unprivileged processes using perf_events system call API is also subject
71+
monitoring and observability operations, thus, bypass *scope* permissions
72+
checks in the kernel. CAP_PERFMON implements the principle of least
73+
privilege [13]_ (POSIX 1003.1e: 2.2.2.39) for performance monitoring and
74+
observability operations in the kernel and provides a secure approach to
75+
perfomance monitoring and observability in the system.
76+
77+
For backward compatibility reasons the access to perf_events monitoring and
78+
observability operations is also open for CAP_SYS_ADMIN privileged
79+
processes but CAP_SYS_ADMIN usage for secure monitoring and observability
80+
use cases is discouraged with respect to the CAP_PERFMON capability.
81+
If system audit records [14]_ for a process using perf_events system call
82+
API contain denial records of acquiring both CAP_PERFMON and CAP_SYS_ADMIN
83+
capabilities then providing the process with CAP_PERFMON capability singly
84+
is recommended as the preferred secure approach to resolve double access
85+
denial logging related to usage of performance monitoring and observability.
86+
87+
Unprivileged processes using perf_events system call are also subject
7488
for PTRACE_MODE_READ_REALCREDS ptrace access mode check [7]_ , whose
7589
outcome determines whether monitoring is permitted. So unprivileged
7690
processes provided with CAP_SYS_PTRACE capability are effectively
@@ -82,14 +96,14 @@ performance analysis of monitored processes or a system. For example,
8296
CAP_SYSLOG capability permits reading kernel space memory addresses from
8397
/proc/kallsyms file.
8498

85-
perf_events/Perf privileged users
99+
Privileged Perf users groups
86100
---------------------------------
87101

88102
Mechanisms of capabilities, privileged capability-dumb files [6]_ and
89-
file system ACLs [10]_ can be used to create a dedicated group of
90-
perf_events/Perf privileged users who are permitted to execute
91-
performance monitoring without scope limits. The following steps can be
92-
taken to create such a group of privileged Perf users.
103+
file system ACLs [10]_ can be used to create dedicated groups of
104+
privileged Perf users who are permitted to execute performance monitoring
105+
and observability without scope limits. The following steps can be
106+
taken to create such groups of privileged Perf users.
93107

94108
1. Create perf_users group of privileged Perf users, assign perf_users
95109
group to Perf tool executable and limit access to the executable for
@@ -108,30 +122,51 @@ taken to create such a group of privileged Perf users.
108122
-rwxr-x--- 2 root perf_users 11M Oct 19 15:12 perf
109123

110124
2. Assign the required capabilities to the Perf tool executable file and
111-
enable members of perf_users group with performance monitoring
125+
enable members of perf_users group with monitoring and observability
112126
privileges [6]_ :
113127

114128
::
115129

116-
# setcap "cap_sys_admin,cap_sys_ptrace,cap_syslog=ep" perf
117-
# setcap -v "cap_sys_admin,cap_sys_ptrace,cap_syslog=ep" perf
130+
# setcap "cap_perfmon,cap_sys_ptrace,cap_syslog=ep" perf
131+
# setcap -v "cap_perfmon,cap_sys_ptrace,cap_syslog=ep" perf
118132
perf: OK
119133
# getcap perf
120-
perf = cap_sys_ptrace,cap_sys_admin,cap_syslog+ep
134+
perf = cap_sys_ptrace,cap_syslog,cap_perfmon+ep
135+
136+
If the libcap installed doesn't yet support "cap_perfmon", use "38" instead,
137+
i.e.:
138+
139+
::
140+
141+
# setcap "38,cap_ipc_lock,cap_sys_ptrace,cap_syslog=ep" perf
142+
143+
Note that you may need to have 'cap_ipc_lock' in the mix for tools such as
144+
'perf top', alternatively use 'perf top -m N', to reduce the memory that
145+
it uses for the perf ring buffer, see the memory allocation section below.
146+
147+
Using a libcap without support for CAP_PERFMON will make cap_get_flag(caps, 38,
148+
CAP_EFFECTIVE, &val) fail, which will lead the default event to be 'cycles:u',
149+
so as a workaround explicitly ask for the 'cycles' event, i.e.:
150+
151+
::
152+
153+
# perf top -e cycles
154+
155+
To get kernel and user samples with a perf binary with just CAP_PERFMON.
121156

122157
As a result, members of perf_users group are capable of conducting
123-
performance monitoring by using functionality of the configured Perf
124-
tool executable that, when executes, passes perf_events subsystem scope
125-
checks.
158+
performance monitoring and observability by using functionality of the
159+
configured Perf tool executable that, when executes, passes perf_events
160+
subsystem scope checks.
126161

127162
This specific access control management is only available to superuser
128163
or root running processes with CAP_SETPCAP, CAP_SETFCAP [6]_
129164
capabilities.
130165

131-
perf_events/Perf unprivileged users
166+
Unprivileged users
132167
-----------------------------------
133168

134-
perf_events/Perf *scope* and *access* control for unprivileged processes
169+
perf_events *scope* and *access* control for unprivileged processes
135170
is governed by perf_event_paranoid [2]_ setting:
136171

137172
-1:
@@ -166,7 +201,7 @@ is governed by perf_event_paranoid [2]_ setting:
166201
perf_event_mlock_kb locking limit is imposed but ignored for
167202
unprivileged processes with CAP_IPC_LOCK capability.
168203

169-
perf_events/Perf resource control
204+
Resource control
170205
---------------------------------
171206

172207
Open file descriptors
@@ -227,4 +262,5 @@ Bibliography
227262
.. [10] `<http://man7.org/linux/man-pages/man5/acl.5.html>`_
228263
.. [11] `<http://man7.org/linux/man-pages/man2/getrlimit.2.html>`_
229264
.. [12] `<http://man7.org/linux/man-pages/man5/limits.conf.5.html>`_
230-
265+
.. [13] `<https://sites.google.com/site/fullycapable>`_
266+
.. [14] `<http://man7.org/linux/man-pages/man8/auditd.8.html>`_

Documentation/admin-guide/sysctl/kernel.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,13 @@ perf_event_paranoid
721721
===================
722722

723723
Controls use of the performance events system by unprivileged
724-
users (without CAP_SYS_ADMIN). The default value is 2.
724+
users (without CAP_PERFMON). The default value is 2.
725+
726+
For backward compatibility reasons access to system performance
727+
monitoring and observability remains open for CAP_SYS_ADMIN
728+
privileged processes but CAP_SYS_ADMIN usage for secure system
729+
performance monitoring and observability operations is discouraged
730+
with respect to CAP_PERFMON use cases.
725731

726732
=== ==================================================================
727733
-1 Allow use of (almost) all events by all users.
@@ -730,13 +736,13 @@ users (without CAP_SYS_ADMIN). The default value is 2.
730736
``CAP_IPC_LOCK``.
731737

732738
>=0 Disallow ftrace function tracepoint by users without
733-
``CAP_SYS_ADMIN``.
739+
``CAP_PERFMON``.
734740

735-
Disallow raw tracepoint access by users without ``CAP_SYS_ADMIN``.
741+
Disallow raw tracepoint access by users without ``CAP_PERFMON``.
736742

737-
>=1 Disallow CPU event access by users without ``CAP_SYS_ADMIN``.
743+
>=1 Disallow CPU event access by users without ``CAP_PERFMON``.
738744

739-
>=2 Disallow kernel profiling by users without ``CAP_SYS_ADMIN``.
745+
>=2 Disallow kernel profiling by users without ``CAP_PERFMON``.
740746
=== ==================================================================
741747

742748

arch/parisc/kernel/perf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ static ssize_t perf_write(struct file *file, const char __user *buf,
300300
else
301301
return -EFAULT;
302302

303-
if (!capable(CAP_SYS_ADMIN))
303+
if (!perfmon_capable())
304304
return -EACCES;
305305

306306
if (count != sizeof(uint32_t))

arch/powerpc/perf/imc-pmu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ static int thread_imc_event_init(struct perf_event *event)
976976
if (event->attr.type != event->pmu->type)
977977
return -ENOENT;
978978

979-
if (!capable(CAP_SYS_ADMIN))
979+
if (!perfmon_capable())
980980
return -EACCES;
981981

982982
/* Sampling not supported */
@@ -1412,7 +1412,7 @@ static int trace_imc_event_init(struct perf_event *event)
14121412
if (event->attr.type != event->pmu->type)
14131413
return -ENOENT;
14141414

1415-
if (!capable(CAP_SYS_ADMIN))
1415+
if (!perfmon_capable())
14161416
return -EACCES;
14171417

14181418
/* Return if this is a couting event */

arch/x86/events/Kconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ config PERF_EVENTS_INTEL_UNCORE
1010
available on NehalemEX and more modern processors.
1111

1212
config PERF_EVENTS_INTEL_RAPL
13-
tristate "Intel rapl performance events"
14-
depends on PERF_EVENTS && CPU_SUP_INTEL && PCI
13+
tristate "Intel/AMD rapl performance events"
14+
depends on PERF_EVENTS && (CPU_SUP_INTEL || CPU_SUP_AMD) && PCI
1515
default y
1616
---help---
17-
Include support for Intel rapl performance events for power
17+
Include support for Intel and AMD rapl performance events for power
1818
monitoring on modern processors.
1919

2020
config PERF_EVENTS_INTEL_CSTATE

arch/x86/events/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
obj-y += core.o probe.o
3+
obj-$(PERF_EVENTS_INTEL_RAPL) += rapl.o
34
obj-y += amd/
45
obj-$(CONFIG_X86_LOCAL_APIC) += msr.o
56
obj-$(CONFIG_CPU_SUP_INTEL) += intel/
7+
obj-$(CONFIG_CPU_SUP_CENTAUR) += zhaoxin/
8+
obj-$(CONFIG_CPU_SUP_ZHAOXIN) += zhaoxin/

arch/x86/events/core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,10 @@ static int __init init_hw_perf_events(void)
18391839
err = amd_pmu_init();
18401840
x86_pmu.name = "HYGON";
18411841
break;
1842+
case X86_VENDOR_ZHAOXIN:
1843+
case X86_VENDOR_CENTAUR:
1844+
err = zhaoxin_pmu_init();
1845+
break;
18421846
default:
18431847
err = -ENOTSUPP;
18441848
}

arch/x86/events/intel/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
obj-$(CONFIG_CPU_SUP_INTEL) += core.o bts.o
33
obj-$(CONFIG_CPU_SUP_INTEL) += ds.o knc.o
44
obj-$(CONFIG_CPU_SUP_INTEL) += lbr.o p4.o p6.o pt.o
5-
obj-$(CONFIG_PERF_EVENTS_INTEL_RAPL) += intel-rapl-perf.o
6-
intel-rapl-perf-objs := rapl.o
75
obj-$(CONFIG_PERF_EVENTS_INTEL_UNCORE) += intel-uncore.o
86
intel-uncore-objs := uncore.o uncore_nhmex.o uncore_snb.o uncore_snbep.o
97
obj-$(CONFIG_PERF_EVENTS_INTEL_CSTATE) += intel-cstate.o

arch/x86/events/intel/bts.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct bts_buffer {
5858
local_t head;
5959
unsigned long end;
6060
void **data_pages;
61-
struct bts_phys buf[0];
61+
struct bts_phys buf[];
6262
};
6363

6464
static struct pmu bts_pmu;

arch/x86/events/intel/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,8 +1892,8 @@ static __initconst const u64 tnt_hw_cache_extra_regs
18921892

18931893
static struct extra_reg intel_tnt_extra_regs[] __read_mostly = {
18941894
/* must define OFFCORE_RSP_X first, see intel_fixup_er() */
1895-
INTEL_UEVENT_EXTRA_REG(0x01b7, MSR_OFFCORE_RSP_0, 0xffffff9fffull, RSP_0),
1896-
INTEL_UEVENT_EXTRA_REG(0x02b7, MSR_OFFCORE_RSP_1, 0xffffff9fffull, RSP_1),
1895+
INTEL_UEVENT_EXTRA_REG(0x01b7, MSR_OFFCORE_RSP_0, 0x800ff0ffffff9fffull, RSP_0),
1896+
INTEL_UEVENT_EXTRA_REG(0x02b7, MSR_OFFCORE_RSP_1, 0xff0ffffff9fffull, RSP_1),
18971897
EVENT_EXTRA_END
18981898
};
18991899

0 commit comments

Comments
 (0)