From 5f7bd119f789c2177608328cdeed25a4f22997f8 Mon Sep 17 00:00:00 2001 From: mav Date: Tue, 14 Sep 2010 04:48:04 +0000 Subject: [PATCH] Add some foot shooting protection by checking singlemul value correctness. Rephrase sysctls descriptions. Suggested by: edmaste --- sys/kern/kern_clocksource.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sys/kern/kern_clocksource.c b/sys/kern/kern_clocksource.c index 29304a496cb8..7654acee4e2e 100644 --- a/sys/kern/kern_clocksource.c +++ b/sys/kern/kern_clocksource.c @@ -105,7 +105,7 @@ static int profiling = 0; /* Profiling events enabled. */ static char timername[32]; /* Wanted timer. */ TUNABLE_STR("kern.eventtimer.timer", timername, sizeof(timername)); -static u_int singlemul = 0; /* Multiplier for periodic mode. */ +static int singlemul = 0; /* Multiplier for periodic mode. */ TUNABLE_INT("kern.eventtimer.singlemul", &singlemul); SYSCTL_INT(_kern_eventtimer, OID_AUTO, singlemul, CTLFLAG_RW, &singlemul, 0, "Multiplier for periodic mode"); @@ -425,6 +425,7 @@ setuptimer(void) periodic = 0; else if (!periodic && (timer->et_flags & ET_FLAGS_ONESHOT) == 0) periodic = 1; + singlemul = MIN(MAX(singlemul, 1), 20); freq = hz * singlemul; while (freq < (profiling ? profhz : stathz)) freq += hz; @@ -614,7 +615,7 @@ cpu_initclocks_bsp(void) * We want to run stathz in the neighborhood of 128hz. * We would like profhz to run as often as possible. */ - if (singlemul == 0) { + if (singlemul <= 0 || singlemul > 20) { if (hz >= 1500 || (hz % 128) == 0) singlemul = 1; else if (hz >= 750) @@ -844,7 +845,7 @@ sysctl_kern_eventtimer_timer(SYSCTL_HANDLER_ARGS) } SYSCTL_PROC(_kern_eventtimer, OID_AUTO, timer, CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, - 0, 0, sysctl_kern_eventtimer_timer, "A", "Kernel event timer"); + 0, 0, sysctl_kern_eventtimer_timer, "A", "Chosen event timer"); /* * Report or change the active event timer periodicity. @@ -867,6 +868,6 @@ sysctl_kern_eventtimer_periodic(SYSCTL_HANDLER_ARGS) } SYSCTL_PROC(_kern_eventtimer, OID_AUTO, periodic, CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, - 0, 0, sysctl_kern_eventtimer_periodic, "I", "Kernel event timer periodic"); + 0, 0, sysctl_kern_eventtimer_periodic, "I", "Enable event timer periodic mode"); #endif