Skip to contentSkip to conversation

posix-timers: Prevents overrun counter overflow, adds DELAYTIMER_MAX

PATCH Superseded Daniel Church 2 participants 4 messages Jan 23, 2015 – Jan 24, 2015

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover posix-timers: Prevents overrun counter overflow, adds DELAYTIMER_MAX

If a timer overruns too many times before a call to timer_getoverrun the overrun count can overflow and go negative. POSIX.1-2001 specification of timer_getoverrun() supports constant DELAYTIMER_MAX which prevents overflow and caps overrun count. Adds delaytimer_max value, caps overrun count, and exposes value to userland via /proc/sys/kernel/delaytimer_max.

Resolves https://bugzilla.kernel.org/show_bug.cgi?id=12665 - POSIX timers API does not support DELAYTIMER_MAX

#1 lore raw

PATCH 1/2 posix-timers: Prevents overrun counter overflow

If a timer overruns too many times before a call to timer_getoverrun the overrun count can overflow and go negative. Adds delaytimer_max value to cap overrun count and prevent overflow.

---
 include/linux/posix-timers.h |  3 +++
 kernel/time/posix-timers.c   | 42 ++++++++++++++++++++++++++++++++++--------
 2 files changed, 37 insertions(+), 8 deletions(-)
include/linux/posix-timers.h +3 -0
index 907f3fd..dc8a1e7 100644
@@ -138,4 +138,7 @@ long clock_nanosleep_restart(struct restart_block *restart_block);
 
 void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new);
 
+#define DELAYTIMER_MAX_DEFAULT 1000000
+extern int delaytimer_max;
+
 #endif
kernel/time/posix-timers.c +34 -8

83 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH 1/2] posix-timers: Prevents overrun counter overflow

kernel/time/posix-timers.c __initcall(init_posix_timers); · line 370

Quoted 10 lines · Daniel Church
kernel/time/posix-timers.c +10 -0
+	overruns = (unsigned int) hrtimer_forward(timer,
+					timer->base->get_time(),
+					timr->it.real.interval);
+	if (overruns >= delaytimer_max ||
+		(timr->it_overrun >= 0 &&
+		 timr->it_overrun >= delaytimer_max - overruns)) {
+		timr->it_overrun = delaytimer_max;
+	} else {
+		timr->it_overrun += overruns;
+	}

We certainly do not add the same logic 3 times via copy and paste. Please make that a proper helper function.

Thanks,

tglx

#3 lore raw

PATCH 2/2 posix-timers: Exposes DELAYTIMER_MAX constant used to govern overruns

In reply to Daniel Church

POSIX.1-2001 specification of timer_getoverrun() supports constant DELAYTIMER_MAX which prevents overflow and caps overrun count. Exposes delaytimer_max value to userland via /proc/sys/kernel/delaytimer_max such that GLIBC can support DELAYTIMER_MAX constant.

---
 kernel/sysctl.c | 8 ++++++++
 1 file changed, 8 insertions(+)
kernel/sysctl.c +8 -0
index 137c7f6..b283808 100644
@@ -63,6 +63,7 @@
 #include <linux/binfmts.h>
 #include <linux/sched/sysctl.h>
 #include <linux/kexec.h>
+#include <linux/posix-timers.h>
 
 #include <asm/uaccess.h>
 #include <asm/processor.h>
@@ -761,6 +762,13 @@ static struct ctl_table kern_table[] = {
 	},
 #endif
 	{
+		.procname	= "delaytimer_max",
+		.data		= &delaytimer_max,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+	},
+	{
 		.procname	= "pid_max",
 		.data		= &pid_max,
 		.maxlen		= sizeof (int),
Signature · 1 line
1.9.1