Skip to content

Commit d6d08d2

Browse files
author
peterz@infradead.org
committed
futex: Extend the FUTEX2 flags
Add the definition for the missing but always intended extra sizes, and add a NUMA flag for the planned numa extention. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: André Almeida <andrealmeid@igalia.com> Link: https://lore.kernel.org/r/20230921105247.617057368@noisy.programming.kicks-ass.net
1 parent 4923954 commit d6d08d2

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

include/uapi/linux/futex.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,32 @@
4545

4646
/*
4747
* Flags for futex2 syscalls.
48+
*
49+
* NOTE: these are not pure flags, they can also be seen as:
50+
*
51+
* union {
52+
* u32 flags;
53+
* struct {
54+
* u32 size : 2,
55+
* numa : 1,
56+
* : 4,
57+
* private : 1;
58+
* };
59+
* };
4860
*/
49-
/* 0x00 */
50-
/* 0x01 */
61+
#define FUTEX2_SIZE_U8 0x00
62+
#define FUTEX2_SIZE_U16 0x01
5163
#define FUTEX2_SIZE_U32 0x02
52-
/* 0x04 */
64+
#define FUTEX2_SIZE_U64 0x03
65+
#define FUTEX2_NUMA 0x04
5366
/* 0x08 */
5467
/* 0x10 */
5568
/* 0x20 */
5669
/* 0x40 */
5770
#define FUTEX2_PRIVATE FUTEX_PRIVATE_FLAG
5871

72+
#define FUTEX2_SIZE_MASK 0x03
73+
5974
/* do not use */
6075
#define FUTEX_32 FUTEX2_SIZE_U32 /* historical accident :-( */
6176

kernel/futex/syscalls.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
183183
return do_futex(uaddr, op, val, tp, uaddr2, (unsigned long)utime, val3);
184184
}
185185

186-
#define FUTEX2_VALID_MASK (FUTEX2_SIZE_U32 | FUTEX2_PRIVATE)
186+
#define FUTEX2_VALID_MASK (FUTEX2_SIZE_MASK | FUTEX2_PRIVATE)
187187

188188
/**
189189
* futex_parse_waitv - Parse a waitv array from userspace
@@ -207,7 +207,12 @@ static int futex_parse_waitv(struct futex_vector *futexv,
207207
if ((aux.flags & ~FUTEX2_VALID_MASK) || aux.__reserved)
208208
return -EINVAL;
209209

210-
if (!(aux.flags & FUTEX2_SIZE_U32))
210+
if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall()) {
211+
if ((aux.flags & FUTEX2_SIZE_MASK) == FUTEX2_SIZE_U64)
212+
return -EINVAL;
213+
}
214+
215+
if ((aux.flags & FUTEX2_SIZE_MASK) != FUTEX2_SIZE_U32)
211216
return -EINVAL;
212217

213218
futexv[i].w.flags = aux.flags;

0 commit comments

Comments
 (0)