futex: Provide FUTEX_LOCK_PI2 to support clock selection
authorThomas Gleixner <tglx@linutronix.de>
Thu, 22 Apr 2021 19:44:23 +0000 (21:44 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Tue, 22 Jun 2021 14:42:09 +0000 (16:42 +0200)
commitbf22a6976897977b0a3f1aeba6823c959fc4fdae
tree7cc9e19e17e0e2c9812b41e56bc623aea4688c75
parente112c41341c03d9224a9fc522bdb3539bc849b56
futex: Provide FUTEX_LOCK_PI2 to support clock selection

The FUTEX_LOCK_PI futex operand uses a CLOCK_REALTIME based absolute
timeout since it was implemented, but it does not require that the
FUTEX_CLOCK_REALTIME flag is set, because that was introduced later.

In theory as none of the user space implementations can set the
FUTEX_CLOCK_REALTIME flag on this operand, it would be possible to
creatively abuse it and make the meaning invers, i.e. select CLOCK_REALTIME
when not set and CLOCK_MONOTONIC when set. But that's a nasty hackery.

Another option would be to have a new FUTEX_CLOCK_MONOTONIC flag only for
FUTEX_LOCK_PI, but that's also awkward because it does not allow libraries
to handle the timeout clock selection consistently.

So provide a new FUTEX_LOCK_PI2 operand which implements the timeout
semantics which the other operands use and leave FUTEX_LOCK_PI alone.

Reported-by: Kurt Kanzenbach <kurt@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20210422194705.440773992@linutronix.de
include/uapi/linux/futex.h
kernel/futex.c