futex: adjust a futex timeout with a per-timens offset
Subsystems (2)
PATCH 1/2 futex: adjust a futex timeout with a per-timens offset
For all commands except FUTEX_WAIT, timeout is interpreted as an absolute value. This absolute value is inside the task's time namespace and has to be converted to the host's time.
--- kernel/futex.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/futex.c +3 -0
@@ -39,6 +39,7 @@#include <linux/freezer.h> #include <linux/memblock.h> #include <linux/fault-inject.h> +#include <linux/time_namespace.h> #include <asm/futex.h>
@@ -3797,6 +3798,8 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, t =timespec64_to_ktime (ts);if (cmd ==FUTEX_WAIT ) t =ktime_add_safe (ktime_get (), t); +else if (!(cmd &FUTEX_CLOCK_REALTIME )) + t =timens_ktime_to_host (CLOCK_MONOTONIC , t); tp = &t; }/*
Signature · 1 line
2.26.2
PATCH 2/2 selftests/timens: Add a test for futex()
Output on success:
$ ./futex 1..1 ok 1 futex # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
--- tools/testing/selftests/timens/Makefile | 2 +- tools/testing/selftests/timens/futex.c | 107 ++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/timens/futex.c
tools/testing/selftests/timens/Makefile +1 -1
@@ -1,4 +1,4 @@ -TEST_GEN_PROGS := timens timerfd timer clock_nanosleep procfs exec +TEST_GEN_PROGS := timens timerfd timer clock_nanosleep procfs exec futex TEST_GEN_PROGS_EXTENDED := gettime_perf CFLAGS := -Wall -Werror -pthread
tools/testing/selftests/timens/futex.c new file +107 -0
107 lines not on this page · raw message
Signature · 1 line
2.26.2
[tip: timers/urgent] selftests/timens: Add a test for futex()
The following commit has been merged into the timers/urgent branch of tip:
The following commit has been merged into the timers/urgent branch of tip:
Commit-ID: 4cdf42596216e08051c0ccc4c896dcb8b2d22f10 Gitweb: https://git.kernel.org/tip/4cdf42596216e08051c0ccc4c896dcb8b2d22f10 Author: Andrei Vagin <[email protected]> AuthorDate: Thu, 15 Oct 2020 00:29:09 -07:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 15 Oct 2020 11:24:04 +02:00
selftests/timens: Add a test for futex()
Output on success:
$ ./futex 1..1 ok 1 futex # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
--- tools/testing/selftests/timens/Makefile | 2 +- tools/testing/selftests/timens/futex.c | 107 +++++++++++++++++++++++- 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/timens/futex.c
tools/testing/selftests/timens/Makefile +1 -1
@@ -1,4 +1,4 @@ -TEST_GEN_PROGS := timens timerfd timer clock_nanosleep procfs exec +TEST_GEN_PROGS := timens timerfd timer clock_nanosleep procfs exec futex TEST_GEN_PROGS_EXTENDED := gettime_perf CFLAGS := -Wall -Werror -pthread
tools/testing/selftests/timens/futex.c new file +107 -0
107 lines not on this page · raw message
[tip: timers/urgent] futex: Adjust futex absolute timeouts with per-timens offset
In reply to Andrei VaginThe following commit has been merged into the timers/urgent branch of tip:
The following commit has been merged into the timers/urgent branch of tip:
Commit-ID: 06764291690f8650a9f96dea42cc0dd4138d47d5 Gitweb: https://git.kernel.org/tip/06764291690f8650a9f96dea42cc0dd4138d47d5 Author: Andrei Vagin <[email protected]> AuthorDate: Thu, 15 Oct 2020 00:29:08 -07:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 15 Oct 2020 11:24:04 +02:00
futex: Adjust futex absolute timeouts with per-timens offset
For all commands except FUTEX_WAIT, timeout is interpreted as an absolute value. This absolute value is inside the task's time namespace and has to be converted to the host's time.
--- kernel/futex.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/futex.c +3 -0
@@ -39,6 +39,7 @@#include <linux/freezer.h> #include <linux/memblock.h> #include <linux/fault-inject.h> +#include <linux/time_namespace.h> #include <asm/futex.h>
@@ -3797,6 +3798,8 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, t =timespec64_to_ktime (ts);if (cmd ==FUTEX_WAIT ) t =ktime_add_safe (ktime_get (), t); +else if (!(cmd &FUTEX_CLOCK_REALTIME )) + t =timens_ktime_to_host (CLOCK_MONOTONIC , t); tp = &t; }/*
Quoted 9 lines · Andrei Vagin
For all commands except
FUTEX_WAIT, timeout is interpreted as an absolute value. This absolute value is inside the task's time namespace and has to be converted to the host's time.Cc <[email protected]>Fixes 5a590f35add9 ("posix-clocks: Wire up clock_gettime() with timens offsets")Reported-by Hans van der Laan <[email protected]>Signed-off-by Andrei Vagin <[email protected]>[..]
kernel/futex.c SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, · line 3802
Quoted 5 lines
kernel/futex.c +2
-0@@ -3797,6 +3798,8 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, t =timespec64_to_ktime (ts);if (cmd ==FUTEX_WAIT ) t =ktime_add_safe (ktime_get (), t); +else if (!(cmd &FUTEX_CLOCK_REALTIME )) + t =timens_ktime_to_host (CLOCK_MONOTONIC , t);
Err, it probably should be
: else if (!(op & FUTEX_CLOCK_REALTIME))
And there's also
: SYSCALL_DEFINE6(futex_time32, ...)
which wants to be patched.
Thanks,
Dmitry
Quoted 5 lines · Dmitry Safonov
Quoted 4 lines · Andrei Vagin
For all commands except
FUTEX_WAIT, timeout is interpreted as an absolute value. This absolute value is inside the task's time namespace and has to be converted to the host's time.
Quoted 13 lines
kernel/futex.c SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, · line 3802
Quoted 10 lines
Cc <[email protected]>Fixes 5a590f35add9 ("posix-clocks: Wire up clock_gettime() with timens offsets")Reported-by Hans van der Laan <[email protected]>Signed-off-by Andrei Vagin <[email protected]>[..]kernel/futex.c +2
-0@@ -3797,6 +3798,8 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, t =timespec64_to_ktime (ts);if (cmd ==FUTEX_WAIT ) t =ktime_add_safe (ktime_get (), t); +else if (!(cmd &FUTEX_CLOCK_REALTIME )) + t =timens_ktime_to_host (CLOCK_MONOTONIC , t);Err, it probably should be
: else if (!(op &FUTEX_CLOCK_REALTIME))
Duh, you are right. I stared at it for a while and did not spot it.
Quoted 3 lines
And there's also
:SYSCALL_DEFINE6(futex_time32, ...)
which wants to be patched.
Indeed. I zapped the commits.
Thanks,
tglx
Quoted 7 lines · Thomas Gleixner
Quoted 5 lines · Dmitry Safonov
Quoted 4 lines · Andrei Vagin
For all commands except
FUTEX_WAIT, timeout is interpreted as an absolute value. This absolute value is inside the task's time namespace and has to be converted to the host's time.
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Cc <[email protected]>Fixes 5a590f35add9 ("posix-clocks: Wire up clock_gettime() with timens offsets")Reported-by Hans van der Laan <[email protected]>Signed-off-by Andrei Vagin <[email protected]>[..](quoted diff) +0
-0@@ -3797,6 +3798,8 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,Quoted 8 lines
kernel/futex.c SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, · line 3802
Quoted 5 lines
kernel/futex.c +2
-0t =timespec64_to_ktime (ts);if (cmd ==FUTEX_WAIT ) t =ktime_add_safe (ktime_get (), t); +else if (!(cmd &FUTEX_CLOCK_REALTIME )) + t =timens_ktime_to_host (CLOCK_MONOTONIC , t);Err, it probably should be
: else if (!(op &FUTEX_CLOCK_REALTIME))
Dmitry, thank you for catching this.
Quoted 8 lines
Duh, you are right. I stared at it for a while and did not spot it.
Quoted 3 lines
And there's also
:SYSCALL_DEFINE6(futex_time32, ...)
which wants to be patched.Indeed. I zapped the commits.
I sent a new version. This time, I extended the test to check FUTEX_CLOCK_REALTIME and I compiled and run the compat version. Everything works as it should be.
Thanks,
Andrei