diff mbox series

[v2,02/14] futex: Extend the FUTEX2 flags

Message ID 20230807123322.883413972@infradead.org (mailing list archive)
State New
Headers show
Series futex: More futex2 bits | expand

Commit Message

Peter Zijlstra Aug. 7, 2023, 12:18 p.m. UTC
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>
---
 include/uapi/linux/futex.h |   21 ++++++++++++++++++---
 kernel/futex/syscalls.c    |    9 +++++++--
 2 files changed, 25 insertions(+), 5 deletions(-)

Comments

Thomas Gleixner Aug. 7, 2023, 6:56 p.m. UTC | #1
On Mon, Aug 07 2023 at 14:18, Peter Zijlstra wrote:
>  /*
>   * Flags for futex2 syscalls.
> + *
> + * NOTE: these are not pure flags, they can also be seen as:
> + *
> + *   union {
> + *     u32  flags;
> + *     struct {
> + *       u32 size    : 2,
> + *           numa    : 1,
> + *                   : 4,
> + *           private : 1;
> + *     };
> + *   };
>   */

Nice documentation

Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
André Almeida Aug. 8, 2023, 12:02 a.m. UTC | #2
Em 07/08/2023 09:18, Peter Zijlstra escreveu:
> 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: André Almeida <andrealmeid@igalia.com>
diff mbox series

Patch

--- a/include/uapi/linux/futex.h
+++ b/include/uapi/linux/futex.h
@@ -45,17 +45,32 @@ 
 
 /*
  * Flags for futex2 syscalls.
+ *
+ * NOTE: these are not pure flags, they can also be seen as:
+ *
+ *   union {
+ *     u32  flags;
+ *     struct {
+ *       u32 size    : 2,
+ *           numa    : 1,
+ *                   : 4,
+ *           private : 1;
+ *     };
+ *   };
  */
-			/*	0x00 */
-			/*	0x01 */
+#define FUTEX2_SIZE_U8		0x00
+#define FUTEX2_SIZE_U16		0x01
 #define FUTEX2_SIZE_U32		0x02
-			/*	0x04 */
+#define FUTEX2_SIZE_U64		0x03
+#define FUTEX2_NUMA		0x04
 			/*	0x08 */
 			/*	0x10 */
 			/*	0x20 */
 			/*	0x40 */
 #define FUTEX2_PRIVATE		FUTEX_PRIVATE_FLAG
 
+#define FUTEX2_SIZE_MASK	0x03
+
 /* do not use */
 #define FUTEX_32		FUTEX2_SIZE_U32 /* historical accident :-( */
 
--- a/kernel/futex/syscalls.c
+++ b/kernel/futex/syscalls.c
@@ -183,7 +183,7 @@  SYSCALL_DEFINE6(futex, u32 __user *, uad
 	return do_futex(uaddr, op, val, tp, uaddr2, (unsigned long)utime, val3);
 }
 
-#define FUTEX2_VALID_MASK (FUTEX2_SIZE_U32 | FUTEX2_PRIVATE)
+#define FUTEX2_VALID_MASK (FUTEX2_SIZE_MASK | FUTEX2_PRIVATE)
 
 /**
  * futex_parse_waitv - Parse a waitv array from userspace
@@ -207,7 +207,12 @@  static int futex_parse_waitv(struct fute
 		if ((aux.flags & ~FUTEX2_VALID_MASK) || aux.__reserved)
 			return -EINVAL;
 
-		if (!(aux.flags & FUTEX2_SIZE_U32))
+		if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall()) {
+			if ((aux.flags & FUTEX2_SIZE_MASK) == FUTEX2_SIZE_U64)
+				return -EINVAL;
+		}
+
+		if ((aux.flags & FUTEX2_SIZE_MASK) != FUTEX2_SIZE_U32)
 			return -EINVAL;
 
 		futexv[i].w.flags = aux.flags;