perf/core: fix perf_proc_update_handler() bug
PATCH 1/1 perf/core: fix perf_proc_update_handler() bug
The perf_proc_update_handler() handles /proc/sys/kernel/perf_event_max_sample_rate syctl variable. When the PMU IRQ handler timing monitoring is disabled, i.e, when /proc/sys/kernel/perf_cpu_time_max_percent is equal to 0 or 100, then no modification to sysctl_perf_event_sample_rate is allowed to prevent possible hang from wrong values.
The problem is that the test to prevent modification is made after the sysctl variable is modified in perf_proc_update_handler().
You get an error:
$ echo 10001 >/proc/sys/kernel/perf_event_max_sample_rate echo: write error: invalid argument
But the value is still modified causing all sorts of inconsistencies:
$ cat /proc/sys/kernel/perf_event_max_sample_rate 10001
This patch fixes the problem by moving the parsing of the value after the test.
--- kernel/events/core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
kernel/events/core.c +7 -7
@@ -436,18 +436,18 @@ int perf_proc_update_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { - int ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); - -if (ret || !write) -return ret; - + int ret; +int perf_cpu = sysctl_perf_cpu_time_max_percent;/* * If throttling is disabled don't allow the write: */ -if (sysctl_perf_cpu_time_max_percent ==100 || - sysctl_perf_cpu_time_max_percent ==0 ) +if (write && (perf_cpu ==100 || perf_cpu ==0 ))return -EINVAL ; + ret =proc_dointvec_minmax (table, write, buffer, lenp, ppos); +if (ret || !write) +return ret; + max_samples_per_tick =DIV_ROUND_UP (sysctl_perf_event_sample_rate,HZ ); perf_sample_period_ns =NSEC_PER_SEC / sysctl_perf_event_sample_rate;update_perf_cpu_limits ();
Signature · 1 line
2.7.4
Quoted 17 lines · Stephane Eranian
The
perf_proc_update_handler()handles/proc/sys/kernel/perf_event_max_sample_ratesyctl variable. When the PMU IRQ handler timing monitoring is disabled, i.e, when/proc/sys/kernel/perf_cpu_time_max_percentis equal to 0 or 100, then no modification tosysctl_perf_event_sample_rateis allowed to prevent possible hang from wrong values.The problem is that the test to prevent modification is made after the sysctl variable is modified in
perf_proc_update_handler().You get an error:
$ echo 10001 >/proc/sys/kernel/perf_event_max_sample_rate echo: write error: invalid argumentBut the value is still modified causing all sorts of inconsistencies:
Quoted 7 lines
$ cat /proc/sys/kernel/perf_event_max_sample_rate 10001This patch fixes the problem by moving the parsing of the value after the test.
Signed-off-by Stephane Eranian <[email protected]>
Ping.
Quoted 37 lines
--- kernel/events/core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)kernel/events/core.c +7
-8@@ -436,18 +436,18 @@ int perf_proc_update_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { - int ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); - -if (ret || !write) -return ret; - + int ret; +int perf_cpu = sysctl_perf_cpu_time_max_percent;/* * If throttling is disabled don't allow the write: */ -if (sysctl_perf_cpu_time_max_percent ==100 || - sysctl_perf_cpu_time_max_percent ==0 ) +if (write && (perf_cpu ==100 || perf_cpu ==0 ))return -EINVAL ; + ret =proc_dointvec_minmax (table, write, buffer, lenp, ppos); +if (ret || !write) +return ret; + max_samples_per_tick =DIV_ROUND_UP (sysctl_perf_event_sample_rate,HZ ); perf_sample_period_ns =NSEC_PER_SEC / sysctl_perf_event_sample_rate;update_perf_cpu_limits (); --2.7.4
Andi Kleen
Reviewed-byQuoted 21 lines · Stephane Eranian
Quoted 20 lines · Stephane Eranian
The
perf_proc_update_handler()handles/proc/sys/kernel/perf_event_max_sample_ratesyctl variable. When the PMU IRQ handler timing monitoring is disabled, i.e, when/proc/sys/kernel/perf_cpu_time_max_percentis equal to 0 or 100, then no modification tosysctl_perf_event_sample_rateis allowed to prevent possible hang from wrong values.The problem is that the test to prevent modification is made after the sysctl variable is modified in
perf_proc_update_handler().You get an error:
$ echo 10001 >/proc/sys/kernel/perf_event_max_sample_rate echo: write error: invalid argumentBut the value is still modified causing all sorts of inconsistencies:
$ cat /proc/sys/kernel/perf_event_max_sample_rate 10001
Quoted 6 lines
Quoted 4 lines
This patch fixes the problem by moving the parsing of the value after the test.
Signed-off-by Stephane Eranian <[email protected]>Ping.
-Andi
Em Thu, Jan 17, 2019 at 01:03:20PM -0800, Stephane Eranian escreveu:
Quoted 21 lines · Stephane Eranian
Quoted 20 lines
The
perf_proc_update_handler()handles/proc/sys/kernel/perf_event_max_sample_ratesyctl variable. When the PMU IRQ handler timing monitoring is disabled, i.e, when/proc/sys/kernel/perf_cpu_time_max_percentis equal to 0 or 100, then no modification tosysctl_perf_event_sample_rateis allowed to prevent possible hang from wrong values.The problem is that the test to prevent modification is made after the sysctl variable is modified in
perf_proc_update_handler().You get an error:
$ echo 10001 >/proc/sys/kernel/perf_event_max_sample_rate echo: write error: invalid argumentBut the value is still modified causing all sorts of inconsistencies:
$ cat /proc/sys/kernel/perf_event_max_sample_rate 10001
Quoted 6 lines
Quoted 4 lines
This patch fixes the problem by moving the parsing of the value after the test.
Signed-off-by Stephane Eranian <[email protected]>Ping.
Collected the Reviewed-by from Jiri and Andi, reproduced the problem before the patch and I'm testing it to push to Ingo via perf/urgent, thanks for the patch.
- Arnaldo
Quoted 16 lines · Stephane Eranian
The
perf_proc_update_handler()handles/proc/sys/kernel/perf_event_max_sample_ratesyctl variable. When the PMU IRQ handler timing monitoring is disabled, i.e, when/proc/sys/kernel/perf_cpu_time_max_percentis equal to 0 or 100, then no modification tosysctl_perf_event_sample_rateis allowed to prevent possible hang from wrong values.The problem is that the test to prevent modification is made after the sysctl variable is modified in
perf_proc_update_handler().You get an error:
$ echo 10001 >/proc/sys/kernel/perf_event_max_sample_rate echo: write error: invalid argumentBut the value is still modified causing all sorts of inconsistencies:
Quoted 7 lines
$ cat /proc/sys/kernel/perf_event_max_sample_rate 10001This patch fixes the problem by moving the parsing of the value after the test.
Signed-off-by Stephane Eranian <[email protected]>
jirka
Quoted 37 lines
--- kernel/events/core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)kernel/events/core.c +7
-7@@ -436,18 +436,18 @@ int perf_proc_update_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { - int ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); - -if (ret || !write) -return ret; - + int ret; +int perf_cpu = sysctl_perf_cpu_time_max_percent;/* * If throttling is disabled don't allow the write: */ -if (sysctl_perf_cpu_time_max_percent ==100 || - sysctl_perf_cpu_time_max_percent ==0 ) +if (write && (perf_cpu ==100 || perf_cpu ==0 ))return -EINVAL ; + ret =proc_dointvec_minmax (table, write, buffer, lenp, ppos); +if (ret || !write) +return ret; + max_samples_per_tick =DIV_ROUND_UP (sysctl_perf_event_sample_rate,HZ ); perf_sample_period_ns =NSEC_PER_SEC / sysctl_perf_event_sample_rate;update_perf_cpu_limits ();Signature · 1 line
2.7.4
tip-bot for Stephane Eranian
merge bot[tip:perf/urgent] perf core: Fix perf_proc_update_handler() bug
In reply to Stephane Eranianperf core: Fix perf_proc_update_handler() bug
Commit-ID: 1a51c5da5acc6c188c917ba572eebac5f8793432 Gitweb: https://git.kernel.org/tip/1a51c5da5acc6c188c917ba572eebac5f8793432 Author: Stephane Eranian <[email protected]> AuthorDate: Thu, 10 Jan 2019 17:17:16 -0800 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 18 Jan 2019 11:10:38 -0300
perf core: Fix perf_proc_update_handler() bug
The perf_proc_update_handler() handles /proc/sys/kernel/perf_event_max_sample_rate syctl variable. When the PMU IRQ handler timing monitoring is disabled, i.e, when /proc/sys/kernel/perf_cpu_time_max_percent is equal to 0 or 100, then no modification to sysctl_perf_event_sample_rate is allowed to prevent possible hang from wrong values.
The problem is that the test to prevent modification is made after the sysctl variable is modified in perf_proc_update_handler().
You get an error:
$ echo 10001 >/proc/sys/kernel/perf_event_max_sample_rate echo: write error: invalid argument
But the value is still modified causing all sorts of inconsistencies:
$ cat /proc/sys/kernel/perf_event_max_sample_rate 10001
This patch fixes the problem by moving the parsing of the value after the test.
Committer testing:
# echo 100 > /proc/sys/kernel/perf_cpu_time_max_percent # echo 10001 > /proc/sys/kernel/perf_event_max_sample_rate -bash: echo: write error: Invalid argument # cat /proc/sys/kernel/perf_event_max_sample_rate 10001 #
--- kernel/events/core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
kernel/events/core.c +7 -7
@@ -436,18 +436,18 @@ int perf_proc_update_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { - int ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); - -if (ret || !write) -return ret; - + int ret; +int perf_cpu = sysctl_perf_cpu_time_max_percent;/* * If throttling is disabled don't allow the write: */ -if (sysctl_perf_cpu_time_max_percent ==100 || - sysctl_perf_cpu_time_max_percent ==0 ) +if (write && (perf_cpu ==100 || perf_cpu ==0 ))return -EINVAL ; + ret =proc_dointvec_minmax (table, write, buffer, lenp, ppos); +if (ret || !write) +return ret; + max_samples_per_tick =DIV_ROUND_UP (sysctl_perf_event_sample_rate,HZ ); perf_sample_period_ns =NSEC_PER_SEC / sysctl_perf_event_sample_rate;update_perf_cpu_limits ();