diff mbox series

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

Message ID 20201114135126.29462-1-dev@der-flo.net (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series [bpf,perf] ] bpf,perf: return EOPNOTSUPP for attaching 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. 14, 2020, 1:51 p.m. UTC
At the moment it is not possible to attach a bpf handler to a perf event
of type PERF_TYPE_SOFTWARE with a configuration of PERF_COUNT_SW_DUMMY.

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

Comments

Alexei Starovoitov Nov. 14, 2020, 4:07 p.m. UTC | #1
On Sat, Nov 14, 2020 at 5:53 AM Florian Lehner <dev@der-flo.net> wrote:
>
> At the moment it is not possible to attach a bpf handler to a perf event
> of type PERF_TYPE_SOFTWARE with a configuration of PERF_COUNT_SW_DUMMY.

It is possible or it is not possible?

Such "commit log as an abstract statement" patches are a mystery to a reader.
Please explain what problem you're trying to solve and how it's being addressed.

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

Is it a fix or a feature?
If it is a fix please add 'Fixes:' tag.
Florian Lehner Nov. 14, 2020, 6:49 p.m. UTC | #2
On Sat, Nov 14, 2020 at 08:07:29AM -0800, Alexei Starovoitov wrote:
> On Sat, Nov 14, 2020 at 5:53 AM Florian Lehner <dev@der-flo.net> wrote:
> >
> > At the moment it is not possible to attach a bpf handler to a perf event
> > of type PERF_TYPE_SOFTWARE with a configuration of PERF_COUNT_SW_DUMMY.
> 
> It is possible or it is not possible?
> 
> Such "commit log as an abstract statement" patches are a mystery to a reader.
> Please explain what problem you're trying to solve and how it's being addressed.

Perf events of type software/dummy are just placeholder events and don't
require a counting event. So attaching the bpf handler to the
overflow_handler of this event does not trigger the execution of the bpf
handler.
So the idea of this fix was to indicate to the user that attaching a bpf
handler to such a perf event is not (yet) supported.

> > Signed-off-by: Florian Lehner <dev@der-flo.net>
> > ---
> >  kernel/events/core.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > 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;
> 
> Is it a fix or a feature?
> If it is a fix please add 'Fixes:' tag.

I was not sure how to address it and so I have chosen PATCH. As bpf
handlers are still not executed on such events, I also would not call it
a feature.
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);