2015-12-18 21:36:53

by Darren Hart

[permalink] [raw]
Subject: [PATCH] futex: Allow FUTEX_CLOCK_REALTIME with FUTEX_WAIT op

While reviewing Michael Kerrisk's recent futex manpage update, I noticed
that we allow the FUTEX_CLOCK_REALTIME flag for FUTEX_WAIT_BITSET but
not for FUTEX_WAIT.

FUTEX_WAIT is treated as a simple version for FUTEX_WAIT_BITSET
internally (with a bitmask of FUTEX_BITSET_MATCH_ANY). As such, I cannot
come up with a reason for this exclusion for FUTEX_WAIT.

This change does modify the behavior of the futex syscall, changing a
call with FUTEX_WAIT | FUTEX_CLOCK_REALTIME from returning -ENOSYS, to be
equivalent to FUTEX_WAIT_BITSET | FUTEX_CLOCK_REALTIME with a bitset of
FUTEX_BITSET_MATCH_ANY.

Cc: Thomas Gleixner <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Davidlohr Bueso <[email protected]>
Reported-by: Michael Kerrisk <[email protected]>
Signed-off-by: Darren Hart <[email protected]>
---
kernel/futex.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/futex.c b/kernel/futex.c
index 684d754..3c8c6d6 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -3046,7 +3046,8 @@ long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,

if (op & FUTEX_CLOCK_REALTIME) {
flags |= FLAGS_CLOCKRT;
- if (cmd != FUTEX_WAIT_BITSET && cmd != FUTEX_WAIT_REQUEUE_PI)
+ if (cmd != FUTEX_WAIT && cmd != FUTEX_WAIT_BITSET && \
+ cmd != FUTEX_WAIT_REQUEUE_PI)
return -ENOSYS;
}

--
2.1.4


--
Darren Hart
Intel Open Source Technology Center


2015-12-19 00:49:34

by Davidlohr Bueso

[permalink] [raw]
Subject: Re: [PATCH] futex: Allow FUTEX_CLOCK_REALTIME with FUTEX_WAIT op

On Fri, 18 Dec 2015, Darren Hart wrote:

>While reviewing Michael Kerrisk's recent futex manpage update, I noticed
>that we allow the FUTEX_CLOCK_REALTIME flag for FUTEX_WAIT_BITSET but
>not for FUTEX_WAIT.
>
>FUTEX_WAIT is treated as a simple version for FUTEX_WAIT_BITSET
>internally (with a bitmask of FUTEX_BITSET_MATCH_ANY). As such, I cannot
>come up with a reason for this exclusion for FUTEX_WAIT.
>
>This change does modify the behavior of the futex syscall, changing a
>call with FUTEX_WAIT | FUTEX_CLOCK_REALTIME from returning -ENOSYS, to be
>equivalent to FUTEX_WAIT_BITSET | FUTEX_CLOCK_REALTIME with a bitset of
>FUTEX_BITSET_MATCH_ANY.
>
>Cc: Thomas Gleixner <[email protected]>
>Cc: Peter Zijlstra <[email protected]>
>Cc: Davidlohr Bueso <[email protected]>
>Reported-by: Michael Kerrisk <[email protected]>
>Signed-off-by: Darren Hart <[email protected]>

Acked-by: Davidlohr Bueso <[email protected]>

Subject: [tip:locking/core] futex: Allow FUTEX_CLOCK_REALTIME with FUTEX_WAIT op

Commit-ID: 337f13046ff03717a9e99675284a817527440a49
Gitweb: http://git.kernel.org/tip/337f13046ff03717a9e99675284a817527440a49
Author: Darren Hart <[email protected]>
AuthorDate: Fri, 18 Dec 2015 13:36:37 -0800
Committer: Thomas Gleixner <[email protected]>
CommitDate: Sun, 20 Dec 2015 12:43:25 +0100

futex: Allow FUTEX_CLOCK_REALTIME with FUTEX_WAIT op

While reviewing Michael Kerrisk's recent futex manpage update, I noticed
that we allow the FUTEX_CLOCK_REALTIME flag for FUTEX_WAIT_BITSET but
not for FUTEX_WAIT.

FUTEX_WAIT is treated as a simple version for FUTEX_WAIT_BITSET
internally (with a bitmask of FUTEX_BITSET_MATCH_ANY). As such, I cannot
come up with a reason for this exclusion for FUTEX_WAIT.

This change does modify the behavior of the futex syscall, changing a
call with FUTEX_WAIT | FUTEX_CLOCK_REALTIME from returning -ENOSYS, to be
equivalent to FUTEX_WAIT_BITSET | FUTEX_CLOCK_REALTIME with a bitset of
FUTEX_BITSET_MATCH_ANY.

Reported-by: Michael Kerrisk <[email protected]>
Signed-off-by: Darren Hart <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Davidlohr Bueso <[email protected]>
Link: http://lkml.kernel.org/r/9f3bdc116d79d23f5ee72ceb9a2a857f5ff8fa29.1450474525.git.dvhart@linux.intel.com
Signed-off-by: Thomas Gleixner <[email protected]>
---
kernel/futex.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/futex.c b/kernel/futex.c
index 461d438..8a310e2 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -3084,7 +3084,8 @@ long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,

if (op & FUTEX_CLOCK_REALTIME) {
flags |= FLAGS_CLOCKRT;
- if (cmd != FUTEX_WAIT_BITSET && cmd != FUTEX_WAIT_REQUEUE_PI)
+ if (cmd != FUTEX_WAIT && cmd != FUTEX_WAIT_BITSET && \
+ cmd != FUTEX_WAIT_REQUEUE_PI)
return -ENOSYS;
}