perf: Enforce 1 as lower limit for perf_event_max_sample_rate
authorKnut Petersen <Knut_Petersen@t-online.de>
Wed, 25 Sep 2013 12:29:37 +0000 (14:29 +0200)
committerIngo Molnar <mingo@kernel.org>
Fri, 4 Oct 2013 08:06:07 +0000 (10:06 +0200)
/proc/sys/kernel/perf_event_max_sample_rate will accept
negative values as well as 0.

Negative values are unreasonable, and 0 causes a
divide by zero exception in perf_proc_update_handler.

This patch enforces a lower limit of 1.

Signed-off-by: Knut Petersen <Knut_Petersen@t-online.de>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/5242DB0C.4070005@t-online.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>
kernel/events/core.c
kernel/sysctl.c

index d49a9d29334cc4d67c24bad9814221a0371a6350..b25d65ce71066a7da1fe3b69929565b3c9617b3f 100644 (file)
@@ -193,7 +193,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
                void __user *buffer, size_t *lenp,
                loff_t *ppos)
 {
-       int ret = proc_dointvec(table, write, buffer, lenp, ppos);
+       int ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
 
        if (ret || !write)
                return ret;
index b2f06f3c6a3ff32ec9f8f2b92bea0c4766ac6f7d..2a9db916c3f5fae1eb83fcea8567635a0c34758c 100644 (file)
@@ -1049,6 +1049,7 @@ static struct ctl_table kern_table[] = {
                .maxlen         = sizeof(sysctl_perf_event_sample_rate),
                .mode           = 0644,
                .proc_handler   = perf_proc_update_handler,
+               .extra1         = &one,
        },
        {
                .procname       = "perf_cpu_time_max_percent",