1# Copyright 2015 syzkaller project authors. All rights reserved.
2# Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
3
4include <linux/perf_event.h>
5include <linux/hw_breakpoint.h>
6
7resource fd_perf[fd]
8
9perf_event_open(attr ptr[in, perf_event_attr], pid pid, cpu intptr[0:16], group fd_perf[opt], flags flags[perf_flags]) fd_perf
10perf_event_open$cgroup(attr ptr[in, perf_event_attr], fd fd_cgroup, cpu intptr[0:16], group fd_perf[opt], flags flags[perf_flags_cgroup]) fd_perf
11
12ioctl$PERF_EVENT_IOC_ENABLE(fd fd_perf, cmd const[PERF_EVENT_IOC_ENABLE], flags intptr)
13ioctl$PERF_EVENT_IOC_DISABLE(fd fd_perf, cmd const[PERF_EVENT_IOC_DISABLE], flags intptr)
14ioctl$PERF_EVENT_IOC_RESET(fd fd_perf, cmd const[PERF_EVENT_IOC_RESET], flags intptr)
15ioctl$PERF_EVENT_IOC_REFRESH(fd fd_perf, cmd const[PERF_EVENT_IOC_REFRESH], refresh intptr)
16ioctl$PERF_EVENT_IOC_PERIOD(fd fd_perf, cmd const[PERF_EVENT_IOC_PERIOD], period ptr[in, int64])
17ioctl$PERF_EVENT_IOC_ID(fd fd_perf, cmd const[PERF_EVENT_IOC_ID], id ptr[out, int64])
18ioctl$PERF_EVENT_IOC_SET_OUTPUT(fd fd_perf, cmd const[PERF_EVENT_IOC_SET_OUTPUT], other fd_perf)
19ioctl$PERF_EVENT_IOC_SET_FILTER(fd fd_perf, cmd const[PERF_EVENT_IOC_SET_FILTER], filter ptr[in, string])
20ioctl$PERF_EVENT_IOC_SET_BPF(fd fd_perf, cmd const[PERF_EVENT_IOC_SET_BPF], prog fd_bpf_prog)
21ioctl$PERF_EVENT_IOC_PAUSE_OUTPUT(fd fd_perf, cmd const[PERF_EVENT_IOC_PAUSE_OUTPUT], arg boolptr)
22ioctl$PERF_EVENT_IOC_QUERY_BPF(fd fd_perf, cmd const[PERF_EVENT_IOC_QUERY_BPF], arg ptr[in, perf_event_query_bpf])
23ioctl$PERF_EVENT_IOC_MODIFY_ATTRIBUTES(fd fd_perf, cmd const[PERF_EVENT_IOC_MODIFY_ATTRIBUTES], arg ptr[in, perf_event_attr])
24
25perf_flags = PERF_FLAG_FD_NO_GROUP, PERF_FLAG_FD_OUTPUT, PERF_FLAG_FD_CLOEXEC
26perf_flags_cgroup = PERF_FLAG_FD_NO_GROUP, PERF_FLAG_FD_OUTPUT, PERF_FLAG_PID_CGROUP, PERF_FLAG_FD_CLOEXEC
27perf_event_type = PERF_TYPE_HARDWARE, PERF_TYPE_SOFTWARE, PERF_TYPE_TRACEPOINT, PERF_TYPE_HW_CACHE, PERF_TYPE_RAW, PERF_TYPE_BREAKPOINT
28perf_bp_type = HW_BREAKPOINT_EMPTY, HW_BREAKPOINT_R, HW_BREAKPOINT_W, HW_BREAKPOINT_X
29perf_sample_type = PERF_SAMPLE_IP, PERF_SAMPLE_TID, PERF_SAMPLE_TIME, PERF_SAMPLE_ADDR, PERF_SAMPLE_READ, PERF_SAMPLE_CALLCHAIN, PERF_SAMPLE_ID, PERF_SAMPLE_CPU, PERF_SAMPLE_PERIOD, PERF_SAMPLE_STREAM_ID, PERF_SAMPLE_RAW, PERF_SAMPLE_BRANCH_STACK, PERF_SAMPLE_REGS_USER, PERF_SAMPLE_STACK_USER, PERF_SAMPLE_WEIGHT, PERF_SAMPLE_DATA_SRC, PERF_SAMPLE_IDENTIFIER, PERF_SAMPLE_TRANSACTION, PERF_SAMPLE_REGS_INTR, PERF_SAMPLE_PHYS_ADDR
30perf_read_format = PERF_FORMAT_TOTAL_TIME_ENABLED, PERF_FORMAT_TOTAL_TIME_RUNNING, PERF_FORMAT_ID, PERF_FORMAT_GROUP
31perf_branch_sample_type = PERF_SAMPLE_BRANCH_USER, PERF_SAMPLE_BRANCH_KERNEL, PERF_SAMPLE_BRANCH_HV, PERF_SAMPLE_BRANCH_ANY, PERF_SAMPLE_BRANCH_ANY_CALL, PERF_SAMPLE_BRANCH_ANY_RETURN, PERF_SAMPLE_BRANCH_IND_CALL, PERF_SAMPLE_BRANCH_ABORT_TX, PERF_SAMPLE_BRANCH_IN_TX, PERF_SAMPLE_BRANCH_NO_TX, PERF_SAMPLE_BRANCH_COND, PERF_SAMPLE_BRANCH_CALL_STACK, PERF_SAMPLE_BRANCH_IND_JUMP, PERF_SAMPLE_BRANCH_CALL, PERF_SAMPLE_BRANCH_NO_FLAGS, PERF_SAMPLE_BRANCH_NO_CYCLES, PERF_SAMPLE_BRANCH_TYPE_SAVE, PERF_SAMPLE_BRANCH_MAX
32perf_bp_lens = 1, 2, 4, 8
33
34perf_event_attr {
35	type				flags[perf_event_type, int32]
36	size				len[parent, int32]
37#TODO: config can contain lots of various flags depending on type.
38# this is a hacky way to generate something reasonable.
39	config0				int8
40	config1				int8
41	config2				int8
42	config3				int8
43	config4				const[0, int32]
44	sample_freq			int64
45	sample_type			flags[perf_sample_type, int64]
46	read_format			flags[perf_read_format, int64]
47
48	disabled			int64:1
49	inherit				int64:1
50	pinned				int64:1
51	exclusive			int64:1
52	exclude_user			int64:1
53	exclude_kernel			int64:1
54	exclude_hv			int64:1
55	exclude_idle			int64:1
56	mmap				int64:1
57	comm				int64:1
58	freq				int64:1
59	inherit_stat			int64:1
60	enable_on_exec			int64:1
61	task				int64:1
62	watermark			int64:1
63	precise_ip			int64:2
64	mmap_data			int64:1
65	sample_id_all			int64:1
66	exclude_host			int64:1
67	exclude_guest			int64:1
68	exclude_callchain_kernel	int64:1
69	exclude_callchain_user		int64:1
70	mmap2				int64:1
71	comm_exec			int64:1
72	use_clockid			int64:1
73	context_switch			int64:1
74	write_backward			int64:1
75	namespaces			int64:1
76	__reserved_1			const[0, int64:35]
77
78	wakeup_events			int32
79	bp_type				flags[perf_bp_type, int32]
80	bp_config			perf_bp_config
81	branch_sample_type		flags[perf_branch_sample_type, int64]
82	sample_regs_user		int64
83	sample_stack_user		int32
84	clockid				flags[clock_type, int32]
85	sample_regs_intr		int64
86	aux_watermark			int32
87	sample_max_stack		int16
88	__reserved_2			const[0, int16]
89}
90
91perf_bp_config [
92	perf_bp		perf_bp
93	perf_config_ext	perf_config_ext
94]
95
96perf_bp {
97	bp_addr	ptr64[out, int8]
98	bp_len	flags[perf_bp_lens, int64]
99}
100
101perf_config_ext {
102	config1	int64
103	config2	int64
104}
105
106perf_event_query_bpf {
107	ids_len		len[ids, int32]
108	prog_cnt	const[0, int32]
109	ids		array[const[0, int32]]
110}
111