From: Dmitry Safonov <dima@arista.com> To: linux-kernel@vger.kernel.org Cc: Dmitry Safonov <0x7f454c46@gmail.com>, Andrei Vagin <avagin@gmail.com>, Dmitry Safonov <dima@arista.com>, Adrian Reber <adrian@lisas.de>, Andrei Vagin <avagin@openvz.org>, Andy Lutomirski <luto@kernel.org>, Arnd Bergmann <arnd@arndb.de>, Christian Brauner <christian.brauner@ubuntu.com>, Cyrill Gorcunov <gorcunov@openvz.org>, "Eric W. Biederman" <ebiederm@xmission.com>, "H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@redhat.com>, Jann Horn <jannh@google.com>, Jeff Dike <jdike@addtoit.com>, Oleg Nesterov <oleg@redhat.com>, Pavel Emelyanov <xemul@virtuozzo.com>, Shuah Khan <shuah@kernel.org>, Thomas Gleixner <tglx@linutronix.de>, Vincenzo Frascino <vincenzo.frascino@arm.com>, containers@lists.linux-foundation.org, criu@openvz.org, linux-api@vger.kernel.org, x86@kernel.org Subject: [PATCHv6 15/36] posix-timers: Make clock_nanosleep() time namespace aware Date: Thu, 15 Aug 2019 17:38:15 +0100 [thread overview] Message-ID: <20190815163836.2927-16-dima@arista.com> (raw) In-Reply-To: <20190815163836.2927-1-dima@arista.com> From: Andrei Vagin <avagin@gmail.com> clock_nanosleep() accepts absolute values of expiration time, if the TIMER_ABSTIME flag is set. This value is in the task time namespace, which has to be converted to the host time namespace. Signed-off-by: Andrei Vagin <avagin@openvz.org> Co-developed-by: Dmitry Safonov <dima@arista.com> Signed-off-by: Dmitry Safonov <dima@arista.com> --- kernel/time/posix-stubs.c | 12 ++++++++++-- kernel/time/posix-timers.c | 21 ++++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/kernel/time/posix-stubs.c b/kernel/time/posix-stubs.c index 2ccefc9ce184..47ee2684d250 100644 --- a/kernel/time/posix-stubs.c +++ b/kernel/time/posix-stubs.c @@ -129,6 +129,7 @@ SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags, struct __kernel_timespec __user *, rmtp) { struct timespec64 t; + ktime_t texp; switch (which_clock) { case CLOCK_REALTIME: @@ -147,7 +148,10 @@ SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags, rmtp = NULL; current->restart_block.nanosleep.type = rmtp ? TT_NATIVE : TT_NONE; current->restart_block.nanosleep.rmtp = rmtp; - return hrtimer_nanosleep(timespec64_to_ktime(t), flags & TIMER_ABSTIME ? + texp = timespec64_to_ktime(t); + if (flags & TIMER_ABSTIME) + texp = timens_ktime_to_host(clockid, texp); + return hrtimer_nanosleep(texp, flags & TIMER_ABSTIME ? HRTIMER_MODE_ABS : HRTIMER_MODE_REL, which_clock); } @@ -215,6 +219,7 @@ SYSCALL_DEFINE4(clock_nanosleep_time32, clockid_t, which_clock, int, flags, struct old_timespec32 __user *, rmtp) { struct timespec64 t; + ktime texp; switch (which_clock) { case CLOCK_REALTIME: @@ -233,7 +238,10 @@ SYSCALL_DEFINE4(clock_nanosleep_time32, clockid_t, which_clock, int, flags, rmtp = NULL; current->restart_block.nanosleep.type = rmtp ? TT_COMPAT : TT_NONE; current->restart_block.nanosleep.compat_rmtp = rmtp; - return hrtimer_nanosleep(timespec64_to_ktime(t), flags & TIMER_ABSTIME ? + texp = timespec64_to_ktime(t); + if (flags & TIMER_ABSTIME) + texp = timens_ktime_to_host(clockid, texp); + return hrtimer_nanosleep(texp, flags & TIMER_ABSTIME ? HRTIMER_MODE_ABS : HRTIMER_MODE_REL, which_clock); } diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index 1f30e3ef0918..c71eedd17c94 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -1227,7 +1227,22 @@ SYSCALL_DEFINE2(clock_getres_time32, clockid_t, which_clock, static int common_nsleep(const clockid_t which_clock, int flags, const struct timespec64 *rqtp) { - return hrtimer_nanosleep(rqtp, flags & TIMER_ABSTIME ? + ktime_t texp = timespec64_to_ktime(*rqtp); + + return hrtimer_nanosleep(texp, flags & TIMER_ABSTIME ? + HRTIMER_MODE_ABS : HRTIMER_MODE_REL, + which_clock); +} + +static int common_nsleep_timens(const clockid_t which_clock, int flags, + const struct timespec64 *rqtp) +{ + ktime_t texp = timespec64_to_ktime(*rqtp); + + if (flags & TIMER_ABSTIME) + texp = timens_ktime_to_host(which_clock, texp); + + return hrtimer_nanosleep(texp, flags & TIMER_ABSTIME ? HRTIMER_MODE_ABS : HRTIMER_MODE_REL, which_clock); } @@ -1308,7 +1323,7 @@ static const struct k_clock clock_monotonic = { .clock_getres = posix_get_hrtimer_res, .clock_get_timespec = posix_get_monotonic_timespec, .clock_get_ktime = posix_get_monotonic_ktime, - .nsleep = common_nsleep, + .nsleep = common_nsleep_timens, .timer_create = common_timer_create, .timer_set = common_timer_set, .timer_get = common_timer_get, @@ -1355,7 +1370,7 @@ static const struct k_clock clock_boottime = { .clock_getres = posix_get_hrtimer_res, .clock_get_ktime = posix_get_boottime_ktime, .clock_get_timespec = posix_get_boottime_timespec, - .nsleep = common_nsleep, + .nsleep = common_nsleep_timens, .timer_create = common_timer_create, .timer_set = common_timer_set, .timer_get = common_timer_get, -- 2.22.0
WARNING: multiple messages have this Message-ID (diff)
From: Dmitry Safonov <dima@arista.com> To: linux-kernel@vger.kernel.org Cc: Dmitry Safonov <0x7f454c46@gmail.com>, Andrei Vagin <avagin@gmail.com>, Dmitry Safonov <dima@arista.com>, Adrian Reber <adrian@lisas.de>, Andrei Vagin <avagin@openvz.org>, Andy Lutomirski <luto@kernel.org>, Arnd Bergmann <arnd@arndb.de>, Christian Brauner <christian.brauner@ubuntu.com>, Cyrill Gorcunov <gorcunov@openvz.org>, "Eric W. Biederman" <ebiederm@xmission.com>, "H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@redhat.com>, Jann Horn <jannh@google.com>, Jeff Dike <jdike@addtoit.com>, Oleg Nesterov <oleg@redhat.com>, Pavel Emelyanov <xemul@virtuozzo.com>, Shuah Khan <shuah@kernel.org>, Thomas Gleixner <tglx@linutronix.de>, Vincenzo Frascino <vincenzo.frascino@arm.com>, containers@lists.linux-foundation.org, criu@openvz.org, linux-api Subject: [PATCHv6 15/36] posix-timers: Make clock_nanosleep() time namespace aware Date: Thu, 15 Aug 2019 17:38:15 +0100 [thread overview] Message-ID: <20190815163836.2927-16-dima@arista.com> (raw) In-Reply-To: <20190815163836.2927-1-dima@arista.com> From: Andrei Vagin <avagin@gmail.com> clock_nanosleep() accepts absolute values of expiration time, if the TIMER_ABSTIME flag is set. This value is in the task time namespace, which has to be converted to the host time namespace. Signed-off-by: Andrei Vagin <avagin@openvz.org> Co-developed-by: Dmitry Safonov <dima@arista.com> Signed-off-by: Dmitry Safonov <dima@arista.com> --- kernel/time/posix-stubs.c | 12 ++++++++++-- kernel/time/posix-timers.c | 21 ++++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/kernel/time/posix-stubs.c b/kernel/time/posix-stubs.c index 2ccefc9ce184..47ee2684d250 100644 --- a/kernel/time/posix-stubs.c +++ b/kernel/time/posix-stubs.c @@ -129,6 +129,7 @@ SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags, struct __kernel_timespec __user *, rmtp) { struct timespec64 t; + ktime_t texp; switch (which_clock) { case CLOCK_REALTIME: @@ -147,7 +148,10 @@ SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags, rmtp = NULL; current->restart_block.nanosleep.type = rmtp ? TT_NATIVE : TT_NONE; current->restart_block.nanosleep.rmtp = rmtp; - return hrtimer_nanosleep(timespec64_to_ktime(t), flags & TIMER_ABSTIME ? + texp = timespec64_to_ktime(t); + if (flags & TIMER_ABSTIME) + texp = timens_ktime_to_host(clockid, texp); + return hrtimer_nanosleep(texp, flags & TIMER_ABSTIME ? HRTIMER_MODE_ABS : HRTIMER_MODE_REL, which_clock); } @@ -215,6 +219,7 @@ SYSCALL_DEFINE4(clock_nanosleep_time32, clockid_t, which_clock, int, flags, struct old_timespec32 __user *, rmtp) { struct timespec64 t; + ktime texp; switch (which_clock) { case CLOCK_REALTIME: @@ -233,7 +238,10 @@ SYSCALL_DEFINE4(clock_nanosleep_time32, clockid_t, which_clock, int, flags, rmtp = NULL; current->restart_block.nanosleep.type = rmtp ? TT_COMPAT : TT_NONE; current->restart_block.nanosleep.compat_rmtp = rmtp; - return hrtimer_nanosleep(timespec64_to_ktime(t), flags & TIMER_ABSTIME ? + texp = timespec64_to_ktime(t); + if (flags & TIMER_ABSTIME) + texp = timens_ktime_to_host(clockid, texp); + return hrtimer_nanosleep(texp, flags & TIMER_ABSTIME ? HRTIMER_MODE_ABS : HRTIMER_MODE_REL, which_clock); } diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index 1f30e3ef0918..c71eedd17c94 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -1227,7 +1227,22 @@ SYSCALL_DEFINE2(clock_getres_time32, clockid_t, which_clock, static int common_nsleep(const clockid_t which_clock, int flags, const struct timespec64 *rqtp) { - return hrtimer_nanosleep(rqtp, flags & TIMER_ABSTIME ? + ktime_t texp = timespec64_to_ktime(*rqtp); + + return hrtimer_nanosleep(texp, flags & TIMER_ABSTIME ? + HRTIMER_MODE_ABS : HRTIMER_MODE_REL, + which_clock); +} + +static int common_nsleep_timens(const clockid_t which_clock, int flags, + const struct timespec64 *rqtp) +{ + ktime_t texp = timespec64_to_ktime(*rqtp); + + if (flags & TIMER_ABSTIME) + texp = timens_ktime_to_host(which_clock, texp); + + return hrtimer_nanosleep(texp, flags & TIMER_ABSTIME ? HRTIMER_MODE_ABS : HRTIMER_MODE_REL, which_clock); } @@ -1308,7 +1323,7 @@ static const struct k_clock clock_monotonic = { .clock_getres = posix_get_hrtimer_res, .clock_get_timespec = posix_get_monotonic_timespec, .clock_get_ktime = posix_get_monotonic_ktime, - .nsleep = common_nsleep, + .nsleep = common_nsleep_timens, .timer_create = common_timer_create, .timer_set = common_timer_set, .timer_get = common_timer_get, @@ -1355,7 +1370,7 @@ static const struct k_clock clock_boottime = { .clock_getres = posix_get_hrtimer_res, .clock_get_ktime = posix_get_boottime_ktime, .clock_get_timespec = posix_get_boottime_timespec, - .nsleep = common_nsleep, + .nsleep = common_nsleep_timens, .timer_create = common_timer_create, .timer_set = common_timer_set, .timer_get = common_timer_get, -- 2.22.0
next prev parent reply other threads:[~2019-08-15 16:40 UTC|newest] Thread overview: 87+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-08-15 16:38 [PATCHv6 00/36] kernel: Introduce Time Namespace Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 01/36] ns: " Dmitry Safonov 2019-08-15 17:19 ` Thomas Gleixner 2019-08-16 6:11 ` Andrei Vagin 2019-08-16 6:34 ` Thomas Gleixner 2019-08-15 16:38 ` [PATCHv6 02/36] timens: Add timens_offsets Dmitry Safonov 2019-08-15 17:21 ` Thomas Gleixner 2019-08-15 16:38 ` [PATCHv6 03/36] posix-clocks: Rename the clock_get() into clock_get_timespec() Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 17:24 ` Thomas Gleixner 2019-08-15 16:38 ` [PATCHv6 04/36] posix-clocks: Rename .clock_get_timespec() callbacks accordingly Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 05/36] alarmtimer: Rename gettime() callback to get_ktime() Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 06/36] alarmtimer: Provide get_timespec() callback Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 07/36] posix-clocks: Introduce clock_get_ktime() callback Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 08/36] posix-timers: Use clock_get_ktime() in common_timer_get() Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 09/36] posix-clocks: Wire up clock_gettime() with timens offsets Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 10/36] kernel: Add do_timens_ktime_to_host() helper Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 17:38 ` Thomas Gleixner 2019-08-15 16:38 ` [PATCHv6 11/36] timerfd: Make timerfd_settime() time namespace aware Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 12/36] posix-timers: Make timer_settime() " Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 13/36] alarmtimer: Make nanosleep " Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 14/36] hrtimers: Prepare hrtimer_nanosleep() for time namespaces Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 17:44 ` Thomas Gleixner 2019-08-15 16:38 ` Dmitry Safonov [this message] 2019-08-15 16:38 ` [PATCHv6 15/36] posix-timers: Make clock_nanosleep() time namespace aware Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 16/36] fd/proc: Respect boottime inside time namespace for /proc/uptime Dmitry Safonov 2019-08-16 0:46 ` Randy Dunlap 2019-08-15 16:38 ` [PATCHv6 17/36] x86/vdso2c: Correct err messages on file opening Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 18/36] x86/vdso2c: Convert iterator to unsigned Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 19/36] x86/vdso/Makefile: Add vobjs32 Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 20/36] x86/vdso: Restrict splitting VVAR VMA Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 21/36] x86/vdso: Rename vdso_image {.data=>.text} Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 22/36] x86/vdso: Add offsets page in vvar Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 19:21 ` Thomas Gleixner 2019-08-16 20:20 ` Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 23/36] x86/vdso: Allocate timens vdso Dmitry Safonov 2019-08-16 15:23 ` Andy Lutomirski 2019-08-16 20:10 ` Thomas Gleixner 2019-08-16 22:47 ` Dmitry Safonov 2019-08-18 16:21 ` Thomas Gleixner 2019-08-18 16:24 ` Thomas Gleixner 2019-08-18 16:29 ` Thomas Gleixner 2019-08-19 14:15 ` Dmitry Safonov 2019-08-19 14:44 ` Thomas Gleixner 2019-08-15 16:38 ` [PATCHv6 24/36] x86/vdso: Switch image on setns()/clone() Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 25/36] vdso: Introduce vdso_static_branch_unlikely() Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 18:03 ` Thomas Gleixner 2019-08-15 16:38 ` [PATCHv6 26/36] x86/vdso2c: Process jump tables Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 27/36] x86/vdso: Enable static branches for the timens vdso Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 28/36] posix-clocks: Add align for timens_offsets Dmitry Safonov 2019-08-15 19:22 ` Thomas Gleixner 2019-08-16 6:36 ` Thomas Gleixner 2019-08-15 16:38 ` [PATCHv6 29/36] fs/proc: Introduce /proc/pid/timens_offsets Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 30/36] selftest/timens: Add Time Namespace test for supported clocks Dmitry Safonov 2019-08-15 23:18 ` shuah 2019-08-16 6:20 ` Andrei Vagin 2019-08-15 16:38 ` [PATCHv6 31/36] selftest/timens: Add a test for timerfd Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 32/36] selftest/timens: Add a test for clock_nanosleep() Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 33/36] selftest/timens: Add procfs selftest Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 34/36] selftest/timens: Add timer offsets test Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 16:38 ` [PATCHv6 35/36] selftests/timens: Add a simple perf test for clock_gettime() Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov 2019-08-15 23:29 ` shuah 2019-08-15 16:38 ` [PATCHv6 36/36] selftest/timens: Check that a right vdso is mapped after fork and exec Dmitry Safonov 2019-08-15 16:38 ` Dmitry Safonov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20190815163836.2927-16-dima@arista.com \ --to=dima@arista.com \ --cc=0x7f454c46@gmail.com \ --cc=adrian@lisas.de \ --cc=arnd@arndb.de \ --cc=avagin@gmail.com \ --cc=avagin@openvz.org \ --cc=christian.brauner@ubuntu.com \ --cc=containers@lists.linux-foundation.org \ --cc=criu@openvz.org \ --cc=ebiederm@xmission.com \ --cc=gorcunov@openvz.org \ --cc=hpa@zytor.com \ --cc=jannh@google.com \ --cc=jdike@addtoit.com \ --cc=linux-api@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=luto@kernel.org \ --cc=mingo@redhat.com \ --cc=oleg@redhat.com \ --cc=shuah@kernel.org \ --cc=tglx@linutronix.de \ --cc=vincenzo.frascino@arm.com \ --cc=x86@kernel.org \ --cc=xemul@virtuozzo.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.