Commit c895f6f7 authored by Hendrik Brueckner's avatar Hendrik Brueckner Committed by Daniel Borkmann

bpf: correct broken uapi for BPF_PROG_TYPE_PERF_EVENT program type

Commit 0515e599 ("bpf: introduce BPF_PROG_TYPE_PERF_EVENT
program type") introduced the bpf_perf_event_data structure which
exports the pt_regs structure.  This is OK for multiple architectures
but fail for s390 and arm64 which do not export pt_regs.  Programs
using them, for example, the bpf selftest fail to compile on these
architectures.

For s390, exporting the pt_regs is not an option because s390 wants
to allow changes to it.  For arm64, there is a user_pt_regs structure
that covers parts of the pt_regs structure for use by user space.

To solve the broken uapi for s390 and arm64, introduce an abstract
type for pt_regs and add an asm/bpf_perf_event.h file that concretes
the type.  An asm-generic header file covers the architectures that
export pt_regs today.

The arch-specific enablement for s390 and arm64 follows in separate
commits.
Reported-by: default avatarThomas Richter <tmricht@linux.vnet.ibm.com>
Fixes: 0515e599 ("bpf: introduce BPF_PROG_TYPE_PERF_EVENT program type")
Signed-off-by: default avatarHendrik Brueckner <brueckner@linux.vnet.ibm.com>
Reviewed-and-tested-by: default avatarThomas Richter <tmricht@linux.vnet.ibm.com>
Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent 2391f0b4
# UAPI Header export list # UAPI Header export list
include include/uapi/asm-generic/Kbuild.asm include include/uapi/asm-generic/Kbuild.asm
generic-y += bpf_perf_event.h
...@@ -3,6 +3,7 @@ include include/uapi/asm-generic/Kbuild.asm ...@@ -3,6 +3,7 @@ include include/uapi/asm-generic/Kbuild.asm
generic-y += auxvec.h generic-y += auxvec.h
generic-y += bitsperlong.h generic-y += bitsperlong.h
generic-y += bpf_perf_event.h
generic-y += errno.h generic-y += errno.h
generic-y += fcntl.h generic-y += fcntl.h
generic-y += ioctl.h generic-y += ioctl.h
......
...@@ -7,6 +7,7 @@ generated-y += unistd-oabi.h ...@@ -7,6 +7,7 @@ generated-y += unistd-oabi.h
generated-y += unistd-eabi.h generated-y += unistd-eabi.h
generic-y += bitsperlong.h generic-y += bitsperlong.h
generic-y += bpf_perf_event.h
generic-y += errno.h generic-y += errno.h
generic-y += ioctl.h generic-y += ioctl.h
generic-y += ipcbuf.h generic-y += ipcbuf.h
......
...@@ -3,6 +3,7 @@ include include/uapi/asm-generic/Kbuild.asm ...@@ -3,6 +3,7 @@ include include/uapi/asm-generic/Kbuild.asm
generic-y += auxvec.h generic-y += auxvec.h
generic-y += bitsperlong.h generic-y += bitsperlong.h
generic-y += bpf_perf_event.h
generic-y += errno.h generic-y += errno.h
generic-y += ioctl.h generic-y += ioctl.h
generic-y += ipcbuf.h generic-y += ipcbuf.h
......
...@@ -3,6 +3,7 @@ include include/uapi/asm-generic/Kbuild.asm ...@@ -3,6 +3,7 @@ include include/uapi/asm-generic/Kbuild.asm
generic-y += auxvec.h generic-y += auxvec.h
generic-y += bitsperlong.h generic-y += bitsperlong.h
generic-y += bpf_perf_event.h
generic-y += errno.h generic-y += errno.h
generic-y += fcntl.h generic-y += fcntl.h
generic-y += ioctl.h generic-y += ioctl.h
......
...@@ -3,6 +3,7 @@ include include/uapi/asm-generic/Kbuild.asm ...@@ -3,6 +3,7 @@ include include/uapi/asm-generic/Kbuild.asm
generic-y += auxvec.h generic-y += auxvec.h
generic-y += bitsperlong.h generic-y += bitsperlong.h
generic-y += bpf_perf_event.h
generic-y += errno.h generic-y += errno.h
generic-y += fcntl.h generic-y += fcntl.h
generic-y += ioctl.h generic-y += ioctl.h
......
# UAPI Header export list # UAPI Header export list
include include/uapi/asm-generic/Kbuild.asm include include/uapi/asm-generic/Kbuild.asm
generic-y += bpf_perf_event.h
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
include include/uapi/asm-generic/Kbuild.asm include include/uapi/asm-generic/Kbuild.asm
generic-y += auxvec.h generic-y += auxvec.h
generic-y += bpf_perf_event.h
generic-y += errno.h generic-y += errno.h
generic-y += fcntl.h generic-y += fcntl.h
generic-y += ioctl.h generic-y += ioctl.h
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
include include/uapi/asm-generic/Kbuild.asm include include/uapi/asm-generic/Kbuild.asm
generic-y += auxvec.h generic-y += auxvec.h
generic-y += bpf_perf_event.h
generic-y += errno.h generic-y += errno.h
generic-y += fcntl.h generic-y += fcntl.h
generic-y += ioctl.h generic-y += ioctl.h
......
# UAPI Header export list # UAPI Header export list
include include/uapi/asm-generic/Kbuild.asm include include/uapi/asm-generic/Kbuild.asm
generic-y += bpf_perf_event.h
generic-y += kvm_para.h generic-y += kvm_para.h
# UAPI Header export list # UAPI Header export list
include include/uapi/asm-generic/Kbuild.asm include include/uapi/asm-generic/Kbuild.asm
generic-y += bpf_perf_event.h
generic-y += kvm_para.h generic-y += kvm_para.h
generic-y += siginfo.h generic-y += siginfo.h
...@@ -3,6 +3,7 @@ include include/uapi/asm-generic/Kbuild.asm ...@@ -3,6 +3,7 @@ include include/uapi/asm-generic/Kbuild.asm
generic-y += auxvec.h generic-y += auxvec.h
generic-y += bitsperlong.h generic-y += bitsperlong.h
generic-y += bpf_perf_event.h
generic-y += errno.h generic-y += errno.h
generic-y += ioctl.h generic-y += ioctl.h
generic-y += ipcbuf.h generic-y += ipcbuf.h
......
...@@ -3,6 +3,7 @@ include include/uapi/asm-generic/Kbuild.asm ...@@ -3,6 +3,7 @@ include include/uapi/asm-generic/Kbuild.asm
generic-y += auxvec.h generic-y += auxvec.h
generic-y += bitsperlong.h generic-y += bitsperlong.h
generic-y += bpf_perf_event.h
generic-y += errno.h generic-y += errno.h
generic-y += fcntl.h generic-y += fcntl.h
generic-y += ioctl.h generic-y += ioctl.h
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
include include/uapi/asm-generic/Kbuild.asm include include/uapi/asm-generic/Kbuild.asm
generic-y += bitsperlong.h generic-y += bitsperlong.h
generic-y += bpf_perf_event.h
generic-y += errno.h generic-y += errno.h
generic-y += fcntl.h generic-y += fcntl.h
generic-y += ioctl.h generic-y += ioctl.h
......
# UAPI Header export list # UAPI Header export list
include include/uapi/asm-generic/Kbuild.asm include include/uapi/asm-generic/Kbuild.asm
generic-y += bpf_perf_event.h
generic-y += ipcbuf.h generic-y += ipcbuf.h
# UAPI Header export list # UAPI Header export list
include include/uapi/asm-generic/Kbuild.asm include include/uapi/asm-generic/Kbuild.asm
generic-y += bpf_perf_event.h
generic-y += siginfo.h generic-y += siginfo.h
...@@ -3,6 +3,7 @@ include include/uapi/asm-generic/Kbuild.asm ...@@ -3,6 +3,7 @@ include include/uapi/asm-generic/Kbuild.asm
generic-y += auxvec.h generic-y += auxvec.h
generic-y += bitsperlong.h generic-y += bitsperlong.h
generic-y += bpf_perf_event.h
generic-y += errno.h generic-y += errno.h
generic-y += fcntl.h generic-y += fcntl.h
generic-y += ioctl.h generic-y += ioctl.h
......
...@@ -3,6 +3,7 @@ include include/uapi/asm-generic/Kbuild.asm ...@@ -3,6 +3,7 @@ include include/uapi/asm-generic/Kbuild.asm
generic-y += auxvec.h generic-y += auxvec.h
generic-y += bitsperlong.h generic-y += bitsperlong.h
generic-y += bpf_perf_event.h
generic-y += errno.h generic-y += errno.h
generic-y += fcntl.h generic-y += fcntl.h
generic-y += ioctl.h generic-y += ioctl.h
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
include include/uapi/asm-generic/Kbuild.asm include include/uapi/asm-generic/Kbuild.asm
generic-y += auxvec.h generic-y += auxvec.h
generic-y += bpf_perf_event.h
generic-y += kvm_para.h generic-y += kvm_para.h
generic-y += param.h generic-y += param.h
generic-y += poll.h generic-y += poll.h
......
# UAPI Header export list # UAPI Header export list
include include/uapi/asm-generic/Kbuild.asm include include/uapi/asm-generic/Kbuild.asm
generic-y += bpf_perf_event.h
generic-y += param.h generic-y += param.h
generic-y += poll.h generic-y += poll.h
generic-y += resource.h generic-y += resource.h
......
...@@ -3,6 +3,7 @@ include include/uapi/asm-generic/Kbuild.asm ...@@ -3,6 +3,7 @@ include include/uapi/asm-generic/Kbuild.asm
generic-y += setup.h generic-y += setup.h
generic-y += unistd.h generic-y += unistd.h
generic-y += bpf_perf_event.h
generic-y += errno.h generic-y += errno.h
generic-y += fcntl.h generic-y += fcntl.h
generic-y += ioctl.h generic-y += ioctl.h
......
# UAPI Header export list # UAPI Header export list
include include/uapi/asm-generic/Kbuild.asm include include/uapi/asm-generic/Kbuild.asm
generic-y += bpf_perf_event.h
generic-y += siginfo.h generic-y += siginfo.h
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
include include/uapi/asm-generic/Kbuild.asm include include/uapi/asm-generic/Kbuild.asm
generic-y += bitsperlong.h generic-y += bitsperlong.h
generic-y += bpf_perf_event.h
generic-y += errno.h generic-y += errno.h
generic-y += fcntl.h generic-y += fcntl.h
generic-y += ioctl.h generic-y += ioctl.h
......
# UAPI Header export list # UAPI Header export list
include include/uapi/asm-generic/Kbuild.asm include include/uapi/asm-generic/Kbuild.asm
generic-y += bpf_perf_event.h
generic-y += types.h generic-y += types.h
# UAPI Header export list # UAPI Header export list
include include/uapi/asm-generic/Kbuild.asm include include/uapi/asm-generic/Kbuild.asm
generic-y += bpf_perf_event.h
generic-y += errno.h generic-y += errno.h
generic-y += fcntl.h generic-y += fcntl.h
generic-y += ioctl.h generic-y += ioctl.h
......
...@@ -3,6 +3,7 @@ include include/uapi/asm-generic/Kbuild.asm ...@@ -3,6 +3,7 @@ include include/uapi/asm-generic/Kbuild.asm
generic-y += auxvec.h generic-y += auxvec.h
generic-y += bitsperlong.h generic-y += bitsperlong.h
generic-y += bpf_perf_event.h
generic-y += errno.h generic-y += errno.h
generic-y += fcntl.h generic-y += fcntl.h
generic-y += ioctl.h generic-y += ioctl.h
......
# UAPI Header export list # UAPI Header export list
include include/uapi/asm-generic/Kbuild.asm include include/uapi/asm-generic/Kbuild.asm
generic-y += bpf_perf_event.h
generated-y += unistd_32.h generated-y += unistd_32.h
generated-y += unistd_64.h generated-y += unistd_64.h
generated-y += unistd_x32.h generated-y += unistd_x32.h
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
include include/uapi/asm-generic/Kbuild.asm include include/uapi/asm-generic/Kbuild.asm
generic-y += bitsperlong.h generic-y += bitsperlong.h
generic-y += bpf_perf_event.h
generic-y += errno.h generic-y += errno.h
generic-y += fcntl.h generic-y += fcntl.h
generic-y += ioctl.h generic-y += ioctl.h
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#define _LINUX_PERF_EVENT_H #define _LINUX_PERF_EVENT_H
#include <uapi/linux/perf_event.h> #include <uapi/linux/perf_event.h>
#include <uapi/linux/bpf_perf_event.h>
/* /*
* Kernel-internal data types and definitions: * Kernel-internal data types and definitions:
...@@ -787,7 +788,7 @@ struct perf_output_handle { ...@@ -787,7 +788,7 @@ struct perf_output_handle {
}; };
struct bpf_perf_event_data_kern { struct bpf_perf_event_data_kern {
struct pt_regs *regs; bpf_user_pt_regs_t *regs;
struct perf_sample_data *data; struct perf_sample_data *data;
struct perf_event *event; struct perf_event *event;
}; };
...@@ -1177,6 +1178,9 @@ extern void perf_bp_event(struct perf_event *event, void *data); ...@@ -1177,6 +1178,9 @@ extern void perf_bp_event(struct perf_event *event, void *data);
(user_mode(regs) ? PERF_RECORD_MISC_USER : PERF_RECORD_MISC_KERNEL) (user_mode(regs) ? PERF_RECORD_MISC_USER : PERF_RECORD_MISC_KERNEL)
# define perf_instruction_pointer(regs) instruction_pointer(regs) # define perf_instruction_pointer(regs) instruction_pointer(regs)
#endif #endif
#ifndef perf_arch_bpf_user_pt_regs
# define perf_arch_bpf_user_pt_regs(regs) regs
#endif
static inline bool has_branch_stack(struct perf_event *event) static inline bool has_branch_stack(struct perf_event *event)
{ {
......
#ifndef _UAPI__ASM_GENERIC_BPF_PERF_EVENT_H__
#define _UAPI__ASM_GENERIC_BPF_PERF_EVENT_H__
#include <linux/ptrace.h>
/* Export kernel pt_regs structure */
typedef struct pt_regs bpf_user_pt_regs_t;
#endif /* _UAPI__ASM_GENERIC_BPF_PERF_EVENT_H__ */
...@@ -8,11 +8,10 @@ ...@@ -8,11 +8,10 @@
#ifndef _UAPI__LINUX_BPF_PERF_EVENT_H__ #ifndef _UAPI__LINUX_BPF_PERF_EVENT_H__
#define _UAPI__LINUX_BPF_PERF_EVENT_H__ #define _UAPI__LINUX_BPF_PERF_EVENT_H__
#include <linux/types.h> #include <asm/bpf_perf_event.h>
#include <linux/ptrace.h>
struct bpf_perf_event_data { struct bpf_perf_event_data {
struct pt_regs regs; bpf_user_pt_regs_t regs;
__u64 sample_period; __u64 sample_period;
}; };
......
...@@ -7987,11 +7987,11 @@ static void bpf_overflow_handler(struct perf_event *event, ...@@ -7987,11 +7987,11 @@ static void bpf_overflow_handler(struct perf_event *event,
{ {
struct bpf_perf_event_data_kern ctx = { struct bpf_perf_event_data_kern ctx = {
.data = data, .data = data,
.regs = regs,
.event = event, .event = event,
}; };
int ret = 0; int ret = 0;
ctx.regs = perf_arch_bpf_user_pt_regs(regs);
preempt_disable(); preempt_disable();
if (unlikely(__this_cpu_inc_return(bpf_prog_active) != 1)) if (unlikely(__this_cpu_inc_return(bpf_prog_active) != 1))
goto out; goto out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment