Linux userland API discussions
 help / color / mirror / Atom feed
From: Gabriel Ravier <gabravier@gmail.com>
To: libc-coord@lists.openwall.com,
	"André Almeida" <andrealmeid@igalia.com>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Darren Hart" <dvhart@infradead.org>,
	"Davidlohr Bueso" <dave@stgolabs.net>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
	"Waiman Long" <longman@redhat.com>,
	"Ryan Houdek" <Sonicadvance1@gmail.com>,
	"Florian Weimer" <fweimer@redhat.com>,
	"Thomas Gleixner" <tglx@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-api@vger.kernel.org, kernel-dev@igalia.com
Subject: Re: [libc-coord] [PATCH v9 08/14] futex: Create syscall set_robust_list2()
Date: Sun, 6 Dec 2026 16:47:40 +0100	[thread overview]
Message-ID: <5289de37-6e07-428d-8303-acf3f7c813b1@gmail.com> (raw)
In-Reply-To: <20261204-tonyk-robust_futex-v9-8-743d68d488b5@igalia.com>

On 12/4/26 5:15 PM, André Almeida wrote:
> Emulators (like FEX-Emu, to run x86 apps on top of Aarch64) have two
> special needs about robust lists: to be able to register more than one
> robust list, one of the app being emulated and one list for the emulator
> itself; and to be able to walk 32-bit robust lists on a 64-bit
> platform without compat entry points.
> 
> The current syscall allows one robust list per task (on x86-64, it
> can have two if compat is enabled) and on Aarch64 there's no way to
> parse a 32-bit robust list. The current syscall cannot be expanded to
> solve both needs due to the lack of `flags` argument, so create a new
> syscall, set_robust_list2() with the following signature:
> 
>    sys_set_robust_list2(struct robust_list_head __user *head,
> 		       unsigned int index, unsigned int flags)
> 
> The new syscall allows setting multiple lists per task, of 64-bit or
> 32-bit types. These are the arguments:
> 
>   - `*head` is the same structure used in the current syscall.
>   - `index` is used to set which index of task array of heads to be changed.
>   It should be between zero and the number of elements in the robust list
>   array, [0, robust_list2_list_limit).
>   - `flags` can be used for special operations:
>     - `FUTEX_ROBUST_LIST2_FLAG_NEW_ENTRY`: to avoid conflicts between the
>     app logic and libc, the kernel provides this special flag to get an
>     unused index. `index` must be zero and `head` must point to a valid
>     address. The kernel looks for an empty index, sets `head` there and
>     returns such index.
>     - `FUTEX_ROBUST_LIST2_FLAG_32BIT_ENTRY`: to specify that a given `head`
>     is a 32-bit pointer. The kernel will later call the appropriate
>     function to walk the list in 64-bit kernels. `head` should point to
>     a `struct robust_list_head32`, defined in the uAPI header. Using this
>     flag from a compat app is a no-op, given that the kernel will flag
>     every entry as a 32-bit struct anyway.
>     - Both flags can be combined and used together.
> 
> Kernel is responsible for always providing valid indexes, but userspace is
> responsible for managing such indexes afterwards. Userspace can rewrite any
> index at any given time. Using `head` as `NULL` to a given index makes it
> free to be later returned by the kernel. However, it's invalid to ask for a
> new entry while setting `head` as `NULL`.
> 
> And those are the error return values:
> 
>   - `EINVAL`: for invalid flags, unaligned `head` address, `index` out of
>   range, when `head` is NULL or `index` is not zero when using
>   `FUTEX_ROBUST_LIST2_FLAG_NEW_ENTRY`.
>   - `ENOMEM`: the allocation of the array of robust list heads failed.
>   - `EFAULT`: `head` address can't be accessed.
>   - `ENOSPC`: when `FUTEX_ROBUST_LIST2_FLAG_NEW_ENTRY` is used but there's
>   no empty index available at the moment.
> 
> The array of lists is dynamically allocated on first use, but has a fixed
> size determined by the kernel. Userspace should use sysctl interfaces
> to gather how many `head` indexes are allocated
> (`futex.robust_list2_list_limit`) and how many elements each list can
> handle (`futex.robust_list2_elements_per_list`).
> 
> 8 slots cover the target use case with headroom. However, userspace should
> always check this number and not make assumptions.
> 
> The first two slots are internally reserved for the kernel, to store the
> original syscall robust_list_head's (the native and compat one). Map the
> indexes in such a way that userspace can't touch those indexes with the new
> syscall and needs to use the original syscalls to manipulate such
> addresses.
> 
> The array of lists is destroyed only during task exit. There are no
> guarantees about the order of the lists.
> 
> Signed-off-by: André Almeida <andrealmeid@igalia.com>
> ---
>   include/uapi/linux/futex.h |  7 +++++++
>   kernel/futex/core.c        | 32 ++++++++++++++++++++++++++++++++
>   kernel/futex/futex.h       |  2 ++
>   kernel/futex/syscalls.c    | 30 ++++++++++++++++++++++++++++++
>   4 files changed, 71 insertions(+)
> 
> [...]
>
> diff --git a/kernel/futex/syscalls.c b/kernel/futex/syscalls.c
> index 8e7aec8fe03b..af75ffb70956 100644
> --- a/kernel/futex/syscalls.c
> +++ b/kernel/futex/syscalls.c
> @@ -115,6 +115,36 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
>   	return put_user(head, head_ptr);
>   }
>   
> +SYSCALL_DEFINE3(set_robust_list2, struct robust_list_head * __user, head,

__user should be before the * aiui

> +		unsigned int, index, unsigned int, flags)
> +{
> +	size_t align = sizeof(u64), head_size = sizeof(*head);
> +	bool new = false, compat = false;
> +
> +	if (flags & ~FUTEX_ROBUST_LIST2_FLAGS)
> +		return -EINVAL;
> +
> +	if (flags & FUTEX_ROBUST_LIST2_FLAG_NEW_ENTRY) {
> +		if (index || !head)
> +			return -EINVAL;
> +		new = true;
> +	}
> +
> +	if (flags & FUTEX_ROBUST_LIST2_FLAG_32BIT_ENTRY || in_compat_syscall()) {
> +		compat = true;
> +		align = sizeof(u32);
> +		head_size = sizeof(struct robust_list_head32);
> +	}
> +
> +	if (!IS_ALIGNED((uintptr_t)head, align))
> +		return -EINVAL;
> +
> +	if (head && unlikely(!access_ok(head, head_size)))
> +		return -EFAULT;
> +
> +	return futex_robust_list_install((uintptr_t) head, index, new, compat);
> +}
> +
>   long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
>   		u32 __user *uaddr2, u32 val2, u32 val3)
>   {
> 


  reply	other threads:[~2026-12-06 15:47 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 16:15 [PATCH v9 00/14] futex: Create {set,get}_robust_list2() syscalls André Almeida
2026-12-04 16:15 ` [PATCH v9 01/14] futex: Use explicit sizes for compat_robust_list structs André Almeida
2026-12-04 16:15 ` [PATCH v9 02/14] futex: Make exit_robust_list32() unconditionally available for 64-bit kernels André Almeida
2026-12-04 16:15 ` [PATCH v9 03/14] futex: Give a specific head pointer to exit_robust_list() André Almeida
2026-12-04 16:15 ` [PATCH v9 04/14] futex: Introduce futex_get_robust_lists() and futex_sched_data::robust_lists André Almeida
2026-12-06 15:42   ` [libc-coord] " Gabriel Ravier
2026-12-04 16:15 ` [PATCH v9 05/14] futex: Create exit_robust_lists() for multi-robust list André Almeida
2026-12-05  9:55   ` kernel test robot
2026-12-04 16:15 ` [PATCH v9 06/14] futex: Use the multi-robust list infrastructure for current syscalls André Almeida
2026-12-06 15:18   ` [libc-coord] " Gabriel Ravier
2026-12-06 15:45   ` Gabriel Ravier
2026-12-04 16:15 ` [PATCH v9 07/14] futex: Expose robust_list2 limits via sysctl André Almeida
2026-12-04 16:15 ` [PATCH v9 08/14] futex: Create syscall set_robust_list2() André Almeida
2026-12-06 15:47   ` Gabriel Ravier [this message]
2026-12-04 16:15 ` [PATCH v9 09/14] futex: Make futex_task_robust_list() get list by index André Almeida
2026-12-04 16:15 ` [PATCH v9 10/14] futex: Create get_robust_list2() syscall André Almeida
2026-12-04 16:15 ` [PATCH v9 11/14] futex: Wire up set_robust_list2 syscall André Almeida
2026-12-05  9:55   ` kernel test robot
2026-12-05  9:55   ` kernel test robot
2026-12-04 16:15 ` [PATCH v9 12/14] futex: Wire up get_robust_list2 syscall André Almeida
2026-12-04 16:15 ` [PATCH v9 13/14] selftests/futex: Expand for set_robust_list2() André Almeida
2026-12-06 16:03   ` [libc-coord] " Gabriel Ravier
2026-12-04 16:15 ` [PATCH v9 14/14] selftests/futex: Expand for get_robust_list2() André Almeida
2026-12-06 16:06   ` [libc-coord] " Gabriel Ravier

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 \
    --in-reply-to=5289de37-6e07-428d-8303-acf3f7c813b1@gmail.com \
    --to=gabravier@gmail.com \
    --cc=Sonicadvance1@gmail.com \
    --cc=andrealmeid@igalia.com \
    --cc=arnd@arndb.de \
    --cc=bigeasy@linutronix.de \
    --cc=dave@stgolabs.net \
    --cc=dvhart@infradead.org \
    --cc=fweimer@redhat.com \
    --cc=kernel-dev@igalia.com \
    --cc=libc-coord@lists.openwall.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@kernel.org \
    /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