2019-10-30 13:48:52

by Alexander Shishkin

[permalink] [raw]
Subject: [PATCH 0/2] perf: Small fixes for the kernel counters

Hi,

As a result of [1] it seems a reasonable thing to do to refuse to create
kernel events with attr.aux_output (2/2). The other one is a comment fix.

[1] https://marc.info/?l=linux-kernel&m=157242901628761&w=2

Alexander Shishkin (2):
perf: Reattach a misplaced comment
perf: Disallow aux_output for kernel events

kernel/events/core.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

--
2.23.0


2019-10-30 13:49:36

by Alexander Shishkin

[permalink] [raw]
Subject: [PATCH 2/2] perf: Disallow aux_output for kernel events

Commit

ab43762ef0109 ("perf: Allow normal events to output AUX data")

added 'aux_output' bit to the attribute structure, which relies on AUX
events and grouping, neither of which is supported for the kernel events.
This notwithstanding, attempts have been made to use it in the kernel
code, suggesting the necessity of an explicit hard -EINVAL.

Fix this by rejecting attributes with aux_output set for kernel events.

Signed-off-by: Alexander Shishkin <[email protected]>
---
kernel/events/core.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index d2f16546a2ab..d31cf601c710 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -11415,6 +11415,13 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,
struct perf_event *event;
int err;

+ /*
+ * Grouping is not supported for kernel events, neither is 'AUX',
+ * make sure the caller's intentions are adjusted.
+ */
+ if (attr->aux_output)
+ return -EINVAL;
+
event = perf_event_alloc(attr, cpu, task, NULL, NULL,
overflow_handler, context, -1);
if (IS_ERR(event)) {
--
2.23.0

2019-10-30 13:49:42

by Alexander Shishkin

[permalink] [raw]
Subject: [PATCH 1/2] perf: Reattach a misplaced comment

A comment is in a wrong place in perf_event_create_kernel_counter().
Fix that.

Signed-off-by: Alexander Shishkin <[email protected]>
---
kernel/events/core.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index cfd89b4a02d8..d2f16546a2ab 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -11415,10 +11415,6 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,
struct perf_event *event;
int err;

- /*
- * Get the target context (task or percpu):
- */
-
event = perf_event_alloc(attr, cpu, task, NULL, NULL,
overflow_handler, context, -1);
if (IS_ERR(event)) {
@@ -11429,6 +11425,9 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,
/* Mark owner so we could distinguish it from user events. */
event->owner = TASK_TOMBSTONE;

+ /*
+ * Get the target context (task or percpu):
+ */
ctx = find_get_context(event->pmu, task, event);
if (IS_ERR(ctx)) {
err = PTR_ERR(ctx);
--
2.23.0

2019-10-31 06:37:52

by Alexander Shishkin

[permalink] [raw]
Subject: Re: [PATCH 2/2] perf: Disallow aux_output for kernel events

Alexander Shishkin <[email protected]> writes:

> + /*
> + * Grouping is not supported for kernel events, neither is 'AUX',
> + * make sure the caller's intentions are adjusted.
> + */
> + if (attr->aux_output)
> + return -EINVAL;

Should have been ERR_PTR(-EINVAL).

From 72e1839403cb10da589873e1e529778e1f087b96 Mon Sep 17 00:00:00 2001
From: Alexander Shishkin <[email protected]>
Date: Wed, 30 Oct 2019 15:27:35 +0200
Subject: [PATCH] perf: Disallow aux_output for kernel events

Commit

ab43762ef0109 ("perf: Allow normal events to output AUX data")

added 'aux_output' bit to the attribute structure, which relies on AUX
events and grouping, neither of which is supported for the kernel events.
This notwithstanding, attempts have been made to use it in the kernel
code, suggesting the necessity of an explicit hard -EINVAL.

Fix this by rejecting attributes with aux_output set for kernel events.

Signed-off-by: Alexander Shishkin <[email protected]>
---
kernel/events/core.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 6d0d4b14f11c..b1aa5237052b 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -11555,6 +11555,13 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,
struct perf_event *event;
int err;

+ /*
+ * Grouping is not supported for kernel events, neither is 'AUX',
+ * make sure the caller's intentions are adjusted.
+ */
+ if (attr->aux_output)
+ return ERR_PTR(-EINVAL);
+
event = perf_event_alloc(attr, cpu, task, NULL, NULL,
overflow_handler, context, -1);
if (IS_ERR(event)) {
--
2.24.0.rc1

2019-11-13 10:09:50

by tip-bot2 for Jacob Pan

[permalink] [raw]
Subject: [tip: perf/urgent] perf/aux: Disallow aux_output for kernel events

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID: dce5affb94eb54edfff17727a6240a6a5d998666
Gitweb: https://git.kernel.org/tip/dce5affb94eb54edfff17727a6240a6a5d998666
Author: Alexander Shishkin <[email protected]>
AuthorDate: Wed, 30 Oct 2019 15:47:31 +02:00
Committer: Ingo Molnar <[email protected]>
CommitterDate: Wed, 13 Nov 2019 08:16:42 +01:00

perf/aux: Disallow aux_output for kernel events

Commit

ab43762ef0109 ("perf: Allow normal events to output AUX data")

added 'aux_output' bit to the attribute structure, which relies on AUX
events and grouping, neither of which is supported for the kernel events.
This notwithstanding, attempts have been made to use it in the kernel
code, suggesting the necessity of an explicit hard -EINVAL.

Fix this by rejecting attributes with aux_output set for kernel events.

Signed-off-by: Alexander Shishkin <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Stephane Eranian <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Vince Weaver <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
kernel/events/core.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index e18d8d3..7655441 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -11331,6 +11331,13 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,
struct perf_event *event;
int err;

+ /*
+ * Grouping is not supported for kernel events, neither is 'AUX',
+ * make sure the caller's intentions are adjusted.
+ */
+ if (attr->aux_output)
+ return ERR_PTR(-EINVAL);
+
event = perf_event_alloc(attr, cpu, task, NULL, NULL,
overflow_handler, context, -1);
if (IS_ERR(event)) {

2019-11-13 10:09:55

by tip-bot2 for Jacob Pan

[permalink] [raw]
Subject: [tip: perf/urgent] perf/core: Reattach a misplaced comment

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID: f25d8ba9e1b204b90fbf55970ea6e68955006068
Gitweb: https://git.kernel.org/tip/f25d8ba9e1b204b90fbf55970ea6e68955006068
Author: Alexander Shishkin <[email protected]>
AuthorDate: Wed, 30 Oct 2019 15:47:30 +02:00
Committer: Ingo Molnar <[email protected]>
CommitterDate: Wed, 13 Nov 2019 08:16:41 +01:00

perf/core: Reattach a misplaced comment

A comment is in a wrong place in perf_event_create_kernel_counter().
Fix that.

Signed-off-by: Alexander Shishkin <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Stephane Eranian <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Vince Weaver <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
kernel/events/core.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index b752bd3..e18d8d3 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -11331,10 +11331,6 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,
struct perf_event *event;
int err;

- /*
- * Get the target context (task or percpu):
- */
-
event = perf_event_alloc(attr, cpu, task, NULL, NULL,
overflow_handler, context, -1);
if (IS_ERR(event)) {
@@ -11345,6 +11341,9 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,
/* Mark owner so we could distinguish it from user events. */
event->owner = TASK_TOMBSTONE;

+ /*
+ * Get the target context (task or percpu):
+ */
ctx = find_get_context(event->pmu, task, event);
if (IS_ERR(ctx)) {
err = PTR_ERR(ctx);