[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180919205037.9574-5-dima@arista.com>
Date: Wed, 19 Sep 2018 21:50:21 +0100
From: Dmitry Safonov <dima@...sta.com>
To: linux-kernel@...r.kernel.org
Cc: Dmitry Safonov <0x7f454c46@...il.com>,
Andrei Vagin <avagin@...nvz.org>,
Dmitry Safonov <dima@...sta.com>,
Adrian Reber <adrian@...as.de>,
Andy Lutomirski <luto@...nel.org>,
Christian Brauner <christian.brauner@...ntu.com>,
Cyrill Gorcunov <gorcunov@...nvz.org>,
"Eric W. Biederman" <ebiederm@...ssion.com>,
"H. Peter Anvin" <hpa@...or.com>, Ingo Molnar <mingo@...hat.com>,
Jeff Dike <jdike@...toit.com>, Oleg Nesterov <oleg@...hat.com>,
Pavel Emelyanov <xemul@...tuozzo.com>,
Shuah Khan <shuah@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>,
containers@...ts.linux-foundation.org, criu@...nvz.org,
linux-api@...r.kernel.org, x86@...nel.org
Subject: [RFC 04/20] timens: Introduce CLOCK_BOOTTIME offset
From: Andrei Vagin <avagin@...nvz.org>
Adds boottime virtualisation for time namespace.
Provide clock_set() API to set boottime clock inside ns.
Signed-off-by: Andrei Vagin <avagin@...nvz.org>
Signed-off-by: Dmitry Safonov <dima@...sta.com>
---
include/linux/timens_offsets.h | 1 +
kernel/time/posix-timers.c | 26 ++++++++++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/include/linux/timens_offsets.h b/include/linux/timens_offsets.h
index 248b0c0bb92a..777530c46852 100644
--- a/include/linux/timens_offsets.h
+++ b/include/linux/timens_offsets.h
@@ -4,6 +4,7 @@
struct timens_offsets {
struct timespec64 monotonic_time_offset;
+ struct timespec64 monotonic_boottime_offset;
};
#endif
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 3c1f98760dec..d38835a21c5d 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -276,7 +276,32 @@ static int posix_get_coarse_res(const clockid_t which_clock, struct timespec64 *
static int posix_get_boottime(const clockid_t which_clock, struct timespec64 *tp)
{
+ struct timens_offsets *ns_offsets = current->nsproxy->time_ns->offsets;
+
ktime_get_boottime_ts64(tp);
+
+ if (!ns_offsets)
+ return 0;
+
+ *tp = timespec64_add(*tp, ns_offsets->monotonic_boottime_offset);
+
+ return 0;
+}
+
+static int posix_set_boottime(clockid_t which_clock, const struct timespec64 *tp)
+{
+ struct timens_offsets *ns_offsets = current->nsproxy->time_ns->offsets;
+ struct timespec64 ktp;
+
+ if (!ns_capable(current->nsproxy->time_ns->user_ns, CAP_SYS_TIME))
+ return -EPERM;
+
+ ktime_get_boottime_ts64(&ktp);
+
+ if (ns_offsets)
+ ns_offsets->monotonic_boottime_offset = timespec64_sub(*tp, ktp);
+ else
+ return -EINVAL;
return 0;
}
@@ -1362,6 +1387,7 @@ static const struct k_clock clock_tai = {
static const struct k_clock clock_boottime = {
.clock_getres = posix_get_hrtimer_res,
.clock_get = posix_get_boottime,
+ .clock_set = posix_set_boottime,
.nsleep = common_nsleep,
.timer_create = common_timer_create,
.timer_set = common_timer_set,
--
2.13.6
Powered by blists - more mailing lists