diff mbox series

[FIX,bpf,perf] bpf,perf: return EOPNOTSUPP for bpf handler on PERF_COUNT_SW_DUMMY

Message ID 20201116183752.2716-1-dev@der-flo.net (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series [FIX,bpf,perf] bpf,perf: return EOPNOTSUPP for bpf handler on PERF_COUNT_SW_DUMMY | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present fail Series targets non-next tree, but doesn't contain any Fixes tags
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf
netdev/subject_prefix success Link
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 47 this patch: 47
netdev/kdoc success Errors and warnings before: 4 this patch: 4
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 10 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 47 this patch: 47
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Florian Lehner Nov. 16, 2020, 6:37 p.m. UTC
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.

Signed-off-by: Florian Lehner <dev@der-flo.net>
---
 kernel/events/core.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Martin KaFai Lau Nov. 16, 2020, 9:02 p.m. UTC | #1
On Mon, Nov 16, 2020 at 07:37:52PM +0100, Florian Lehner wrote:
> 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.
> 
> Signed-off-by: Florian Lehner <dev@der-flo.net>
It is missing a Fixes tag.
Peter Zijlstra Nov. 17, 2020, 7:53 a.m. UTC | #2
On Mon, Nov 16, 2020 at 01:02:09PM -0800, Martin KaFai Lau wrote:
> On Mon, Nov 16, 2020 at 07:37:52PM +0100, Florian Lehner wrote:
> > 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.
> > 
> > Signed-off-by: Florian Lehner <dev@der-flo.net>
> 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.
Florian Lehner Nov. 17, 2020, 3:39 p.m. UTC | #3
On Tue, Nov 17, 2020 at 08:53:34AM +0100, Peter Zijlstra wrote:
> On Mon, Nov 16, 2020 at 01:02:09PM -0800, Martin KaFai Lau wrote:
> > On Mon, Nov 16, 2020 at 07:37:52PM +0100, Florian Lehner wrote:
> > > 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.
> > > 
> > > Signed-off-by: Florian Lehner <dev@der-flo.net>
> > 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.

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?
diff mbox series

Patch

diff --git a/kernel/events/core.c b/kernel/events/core.c
index da467e1dd49a..4e8846b7ceda 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -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);