Thread (42 messages) 42 messages, 6 authors, 2019-05-03

Re: [PATCHv3 06/27] posix-timers/timens: Take into account clock offsets

flat view

From: Thomas Gleixner <hidden>
Date: 2019-04-25 21:45:31
Also in: lkml

On Thu, 25 Apr 2019, Dmitry Safonov wrote:
quoted hunk ↗ jump to hunk
From: Andrei Vagin <redacted>

Wire timer_settime() syscall into time namespace virtualization.

Signed-off-by: Andrei Vagin <redacted>
Signed-off-by: Dmitry Safonov <redacted>
---
 kernel/time/alarmtimer.c   | 3 +++
 kernel/time/posix-timers.c | 2 ++
 2 files changed, 5 insertions(+)
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 31f99361342e..23f5c39c8d23 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -26,6 +26,7 @@
 #include <linux/freezer.h>
 #include <linux/compat.h>
 #include <linux/module.h>
+#include <linux/time_namespace.h>
 
 #include "posix-timers.h"
 
@@ -621,6 +622,8 @@ static void alarm_timer_arm(struct k_itimer *timr, ktime_t expires,
 
 	if (!absolute)
 		expires = ktime_add_safe(expires, base->gettime());
+	else
+		expires = timens_ktime_to_host(base->base_clockid, expires);

 	if (sigev_none)
 		alarm->node.expires = expires;
 	else
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index a723e63d55fd..7922731f98cd 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -803,6 +803,8 @@ static void common_hrtimer_arm(struct k_itimer *timr, ktime_t expires,
 
 	if (!absolute)
 		expires = ktime_add_safe(expires, timer->base->get_time());
+	else
+		expires = timens_ktime_to_host(timer->base->clockid, expires);
 	hrtimer_set_expires(timer, expires);
So you have now two places where you do that adjustment. Why? And why in
the timer_arm() callback? The obvious place to do that is in
common_timer_set().

-	expires = timespec64_to_ktime(new_setting->it_value);
+	expires = timespec64_to_host(timr->it_clock, &new_setting->it_value);

static ktime_t timespec64_to_host(clockid_t which, struct timespec64 val)
{
	ktime_t expires = timespec64_to_ktime(val);

#ifdef NAMESPACE
	switch (which) {
	case CLOCK_MONOTONIC:
		return timens_sub_monotonic(expires);
	case CLOCK_BOOTTINE:
	case CLOCK_BOOTTIME_ALARM:
		return timens_sub_boottime(expires);
	}
#endif
	return expires;
}

Thanks,

	tglx
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help