public inbox for [email protected]
 help / color / mirror / Atom feed
From: Gabriel Krisman Bertazi <[email protected]>
To: Jens Axboe <[email protected]>
Cc: [email protected], [email protected],
	[email protected], [email protected], [email protected]
Subject: Re: [PATCH 03/12] futex: Flag conversion
Date: Wed, 09 Aug 2023 14:04:32 -0400	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]> (Jens Axboe's message of "Fri, 28 Jul 2023 10:42:26 -0600")

Jens Axboe <[email protected]> writes:

> From: Peter Zijlstra <[email protected]>
>
> Futex has 3 sets of flags:
>
>  - legacy futex op bits
>  - futex2 flags
>  - internal flags
>
> Add a few helpers to convert from the API flags into the internal
> flags.
>
> Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
> Signed-off-by: Jens Axboe <[email protected]>
> ---
>  kernel/futex/futex.h    | 64 +++++++++++++++++++++++++++++++++++++++--
>  kernel/futex/syscalls.c | 24 ++++++----------
>  kernel/futex/waitwake.c |  4 +--
>  3 files changed, 72 insertions(+), 20 deletions(-)
>
> diff --git a/kernel/futex/futex.h b/kernel/futex/futex.h
> index b5379c0e6d6d..c0e04599904a 100644
> --- a/kernel/futex/futex.h
> +++ b/kernel/futex/futex.h
> @@ -5,6 +5,7 @@
>  #include <linux/futex.h>
>  #include <linux/rtmutex.h>
>  #include <linux/sched/wake_q.h>
> +#include <linux/compat.h>
>  
>  #ifdef CONFIG_PREEMPT_RT
>  #include <linux/rcuwait.h>
> @@ -16,8 +17,15 @@
>   * Futex flags used to encode options to functions and preserve them across
>   * restarts.
>   */
> +#define FLAGS_SIZE_8		0x00
> +#define FLAGS_SIZE_16		0x01
> +#define FLAGS_SIZE_32		0x02
> +#define FLAGS_SIZE_64		0x03
> +
> +#define FLAGS_SIZE_MASK		0x03
> +
>  #ifdef CONFIG_MMU
> -# define FLAGS_SHARED		0x01
> +# define FLAGS_SHARED		0x10
>  #else
>  /*
>   * NOMMU does not have per process address space. Let the compiler optimize
> @@ -25,8 +33,58 @@
>   */
>  # define FLAGS_SHARED		0x00
>  #endif
> -#define FLAGS_CLOCKRT		0x02
> -#define FLAGS_HAS_TIMEOUT	0x04
> +#define FLAGS_CLOCKRT		0x20
> +#define FLAGS_HAS_TIMEOUT	0x40
> +#define FLAGS_NUMA		0x80
> +
> +/* FUTEX_ to FLAGS_ */
> +static inline unsigned int futex_to_flags(unsigned int op)
> +{
> +	unsigned int flags = FLAGS_SIZE_32;
> +
> +	if (!(op & FUTEX_PRIVATE_FLAG))
> +		flags |= FLAGS_SHARED;
> +
> +	if (op & FUTEX_CLOCK_REALTIME)
> +		flags |= FLAGS_CLOCKRT;
> +
> +	return flags;
> +}
> +
> +/* FUTEX2_ to FLAGS_ */
> +static inline unsigned int futex2_to_flags(unsigned int flags2)
> +{
> +	unsigned int flags = flags2 & FUTEX2_64;

FUTEX2_64 -> FLAGS_SIZE_MASK

> +
> +	if (!(flags2 & FUTEX2_PRIVATE))
> +		flags |= FLAGS_SHARED;
> +
> +	if (flags2 & FUTEX2_NUMA)
> +		flags |= FLAGS_NUMA;
> +
> +	return flags;
> +}
> +
> +static inline bool futex_flags_valid(unsigned int flags)
> +{
> +	/* Only 64bit futexes for 64bit code */
> +	if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall()) {
> +		if ((flags & FLAGS_SIZE_MASK) == FLAGS_SIZE_64)
> +			return false;
> +	}

I read the comment above as '64bit code can only have 64bit futexes',
which is obviously wrong and not what the code is checking.
Something like this would be better:

/* Reject 64bit futexes on !64bit code. */

Or Perhaps make it generic:

/* Don't allow futexes larger than the word size */
  if (futex_size(flags) > (__WORDSIZE/8) || in_compat_syscall())

-- 
Gabriel Krisman Bertazi

  reply	other threads:[~2023-08-09 18:04 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-28 16:42 [PATCHSET v4] Add io_uring futex/futexv support Jens Axboe
2023-07-28 16:42 ` [PATCH 01/12] futex: Clarify FUTEX2 flags Jens Axboe
2023-07-28 16:42 ` [PATCH 02/12] futex: Extend the " Jens Axboe
2023-07-28 16:42 ` [PATCH 03/12] futex: Flag conversion Jens Axboe
2023-08-09 18:04   ` Gabriel Krisman Bertazi [this message]
2023-07-28 16:42 ` [PATCH 04/12] futex: Validate futex value against futex size Jens Axboe
2023-07-28 16:42 ` [PATCH 05/12] futex: move FUTEX2_MASK to futex.h Jens Axboe
2023-07-28 16:42 ` [PATCH 06/12] futex: factor out the futex wake handling Jens Axboe
2023-07-28 16:42 ` [PATCH 07/12] futex: abstract out a __futex_wake_mark() helper Jens Axboe
2023-07-28 16:42 ` [PATCH 08/12] io_uring: add support for futex wake and wait Jens Axboe
2023-07-28 16:42 ` [PATCH 09/12] futex: add wake_data to struct futex_q Jens Axboe
2023-07-28 16:42 ` [PATCH 10/12] futex: make futex_parse_waitv() available as a helper Jens Axboe
2023-07-28 16:42 ` [PATCH 11/12] futex: make the vectored futex operations available Jens Axboe
2023-07-28 16:42 ` [PATCH 12/12] io_uring: add support for vectored futex waits Jens Axboe
2023-07-31 16:06 ` [PATCHSET v4] Add io_uring futex/futexv support Thomas Gleixner
2023-08-06 16:44   ` Jens Axboe
2023-08-07  1:23     ` Thomas Gleixner
2023-08-07 18:23       ` Jens Axboe
2023-08-15  0:12         ` Thomas Gleixner
2023-08-15  0:18           ` Jens Axboe
2023-08-15  0:47             ` Thomas Gleixner
2023-08-15  1:51               ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox