Skip to contentSkip to conversation

bpf,perf: return EOPNOTSUPP for bpf handler on PERF_COUNT_SW_DUMMY

FIX bpf,perf Florian Lehner 3 participants 4 messages Nov 16, 2020 – Nov 17, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

bpf handlers for perf events other than tracepoints, kprobes or uprobes are attached to the overflow_handler of the perf event.

Perf events of type software/dummy are placeholder events. So when attaching a bpf handle to an overflow_handler of such an event, the bpf handler will not be triggered.

This fix returns the error EOPNOTSUPP to indicate that attaching a bpf handler to a perf event of type software/dummy is not supported.

---
 kernel/events/core.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/events/core.c +4 -0
index da467e1dd49a..4e8846b7ceda 100644
@@ -9668,6 +9668,10 @@ static int perf_event_set_bpf_handler(struct perf_event *event, u32 prog_fd)
 	if (event->prog)
 		return -EEXIST;
 
+	if (event->attr.type == PERF_TYPE_SOFTWARE &&
+	    event->attr.config == PERF_COUNT_SW_DUMMY)
+		return -EOPNOTSUPP;
+
 	prog = bpf_prog_get_type(prog_fd, BPF_PROG_TYPE_PERF_EVENT);
 	if (IS_ERR(prog))
 		return PTR_ERR(prog);
Signature · 1 line
2.28.0
#1 lore raw
Quoted 11 lines · Florian Lehner

bpf handlers for perf events other than tracepoints, kprobes or uprobes are attached to the overflow_handler of the perf event.

Perf events of type software/dummy are placeholder events. So when attaching a bpf handle to an overflow_handler of such an event, the bpf handler will not be triggered.

This fix returns the error EOPNOTSUPP to indicate that attaching a bpf handler to a perf event of type software/dummy is not supported.

It is missing a Fixes tag.

maintainer
#2 lore raw
Quoted 8 lines · Martin KaFai Lau
Quoted 7 lines · Florian Lehner

bpf handlers for perf events other than tracepoints, kprobes or uprobes are attached to the overflow_handler of the perf event.

Perf events of type software/dummy are placeholder events. So when attaching a bpf handle to an overflow_handler of such an event, the bpf handler will not be triggered.

Quoted 5 lines
Quoted 4 lines

This fix returns the error EOPNOTSUPP to indicate that attaching a bpf handler to a perf event of type software/dummy is not supported.

It is missing a Fixes tag.

I don't think it actually fixes anything. worse it could break things.

Atatching a bpf filter to a dummy event is pointless, but harmless. We allow it now, disallowing it will break whatever programs out there are doing harmless silly things.

I really don't see the point of this patch. It grows the kernel code for absolutely no distinguishable benefit.

#3 lore raw
Quoted 15 lines · Peter Zijlstra
Quoted 8 lines · Martin KaFai Lau
Quoted 7 lines · Florian Lehner

bpf handlers for perf events other than tracepoints, kprobes or uprobes are attached to the overflow_handler of the perf event.

Perf events of type software/dummy are placeholder events. So when attaching a bpf handle to an overflow_handler of such an event, the bpf handler will not be triggered.

Quoted 5 lines
Quoted 4 lines

This fix returns the error EOPNOTSUPP to indicate that attaching a bpf handler to a perf event of type software/dummy is not supported.

It is missing a Fixes tag.

Quoted 8 lines

I don't think it actually fixes anything. worse it could break things.

Atatching a bpf filter to a dummy event is pointless, but harmless. We allow it now, disallowing it will break whatever programs out there are doing harmless silly things.

I really don't see the point of this patch. It grows the kernel code for absolutely no distinguishable benefit.

I agree, this fix does not implement the functionality of attaching a bpf handler to a perf event of type software/dummy. Instead it returns an error code and let the user know that this kind of action is not supported (yet).
As a user I would prefer to get an error for something that is pointless than needing to debug why an attached bpf handler is never execute.

Do you think it would be better to improve documentation to point this out? And if so, which documentation would be best to update?