Re: [PATCH v8 04/10] futex: Create set_robust_list2() syscall
From: André Almeida
Date: Tue Dec 01 2026 - 13:07:41 EST
Hi Thomas,
Em 30/11/2026 22:27, Thomas Gleixner escreveu:
On Sun, Nov 15 2026 at 14:31, André Almeida wrote:
+enum robust_list2_cmd {
+ FUTEX_ROBUST_LIST_CMD_CREATE_64,
+ FUTEX_ROBUST_LIST_CMD_CREATE_32,
This is a complete misnomer. It does not create a robust list. It
installs a robust list pointer which is handed in from user space.
Agreed, to install (or to set) looks like a better name. I've based the naming (and much of the design bellow) on this email from you: https://lore.kernel.org/all/87zfdto0bv.ffs@tglx/
+ FUTEX_ROBUST_LIST_CMD_MODIFY_64,
+ FUTEX_ROBUST_LIST_CMD_MODIFY_32,
+ FUTEX_ROBUST_LIST_CMD_LIST_LIMIT,
+ FUTEX_ROBUST_LIST_CMD_USER_MAX,
+int futex_robust_list_create(uintptr_t head, enum robust_list2_cmd cmd)
+{
+ uintptr_t *rl = current->futex.robust_lists, entry = FUTEX_ROBUST_LIST_ENTRY_INUSE;
+ unsigned int index;
+
+ if (!rl) {
+ rl = kcalloc(FUTEX_ROBUST_LIST2_MAX_IDX, sizeof(*rl), GFP_KERNEL);
+ if (!rl)
+ return -ENOMEM;
+
+ scoped_guard(mutex, ¤t->futex.exit_mutex) {
+ /* check if another thread set the list before us */
[...]
+ /*
+ * If the list type is the same as the kernel bitness, always
+ * calls exit_robust_list(). exit_robust_list32() is only for
+ * 32-bit lists in a 64-bit kernel.
+ */
You really have a tendency to comment the obvious...
Right, I will be briefer in the comments for the v9.
[...]
+ if (futex_in_32bit_syscall())
+ return -EOPNOTSUPP;
+ align = sizeof(u64);
+ }
+
+ switch (cmd) {
+ case FUTEX_ROBUST_LIST_CMD_CREATE_64:
+ case FUTEX_ROBUST_LIST_CMD_CREATE_32:
+ if (index)
+ return -EINVAL;
This check is pretty pointless because 0 is also a valid index, no?
The idea is that, when issuing a create command, userspace can't choose the index. The idea is to refuse any index to avoid confusion.
[...]
+ return futex_robust_list_modify(entry, cmd, index);
+ case FUTEX_ROBUST_LIST_CMD_LIST_LIMIT:
+ return FUTEX_ROBUST_LISTS_PER_USER;
This does not make sense at all because that's a compile time constant
so it should be read from a sysctl and not be multiplexed into this
syscall just because, no?
Yes, sounds good to me.
+ }
+
+ return -EINVAL;
+}
This whole thing can be simplified so it becomes comprehensible.
SYSCALL_DEFINE4(set_robust_list2, struct robust_list_head * __user, head, unsigned int,
cmd, unsigned int, index, unsigned int, flags)
{
if (flags || cmd >= FUTEX_ROBUST_LIST_CMD_USER_MAX)
return -EINVAL;
size_t align = sizeof(u32);
switch (cmd) {
case FUTEX_ROBUST_LIST_CMD_INSTALL_64:
case FUTEX_ROBUST_LIST_CMD_MODIFY_64:
if (futex_in_32bit_syscall())
return -EOPNOTSUPP;
align = sizeof(u64);
}
if (unlikely(!access_ok(uaddr, align)))
return -EFAULT;
uintptr_t entry = (__force uintptr_t)head;
if (entry % align)
return -EINVAL;
switch (cmd) {
case FUTEX_ROBUST_LIST_CMD_INSTALL_32:
entry |= FUTEX_ROBUST_LIST_ENTRY_32BIT;
fallthrough;
case FUTEX_ROBUST_LIST_CMD_INSTALL_64:
return futex_robust_list_create(entry);
case FUTEX_ROBUST_LIST_CMD_MODIFY_32:
entry |= FUTEX_ROBUST_LIST_ENTRY_32BIT;
fallthrough;
case FUTEX_ROBUST_LIST_CMD_MODIFY_64:
return futex_robust_list_modify(entry, index);
}
return -EINVAL;
}
No?
But I really have to ask how the distinction between INSTALL and MODIFY
is actually valuable.
This whole thing can be made _ONE_ operation, which removes boatloads of
pointless code and solves the install NULL and then modify issue I
pointed out above:
static int __robust_list_install(uintptr_t *rl, , unsigned int idx, uintptr_t entry)
{
rl[idx] = entry & FUTEX_ROBUST_LIST_ENTRY_MASK ? : NULL;
return idx - FUTEX_ROBUST_LIST2_IDX;
}
int robust_list_install(uintptr_t entry, unsigned int idx)
{
uintptr_t *rl = robust_get_lists();
if (!rl)
return -ENOMEM;
// Update an distinct entry?
if (idx != FUTEX_ROBUST_LIST2_NEW_ENTRY) {
if (idx >= FUTEX_ROBUST_LIST2_MAX_USER_IDX)
return -EINVAL;
return __robust_list_install(rl, idx, entry);
}
/* Search for an empty slot */
for (idx = FUTEX_ROBUST_LIST2_IDX; idx < FUTEX_ROBUST_LIST2_MAX_IDX; idx++) {
if (!rl[idx])
return __robust_list_install(rl, idx, entry);
}
return -ENOSPC;
}
Note that this does not care whether there is a bitness mismatch in case
of updating a particular index. Why?
The kernel is not responsible for user space to get its act together
and there is zero impact for the kernel if user space screws that up.
No?
That sounds good to me too. The main concern here is to be able to both the libc and the application to use the same interface without poking each other. If there's a way to userspace to ask for a brand new entry (like you suggested above with FUTEX_ROBUST_LIST2_NEW_ENTRY) that's great and works for me.
That said, the whole ordering approach of this patch set is backwards
and unreviewable.
What you want to do is:
1) Preperatory patches
Patch 02/03 plus patches which change the exit_robust_list()
signature and add missing sanity checks to the existing syscalls.
2) Introduce robust_get_lists() which either returns the existing
robust lists pointer or allocates the robust list array
uintptr_t *robust_get_lists(void)
{
uintptr_t *rl = current->futex.robust_lists;
if (!rl) {
rl = kcalloc(FUTEX_ROBUST_LIST2_MAX_IDX, sizeof(*rl), GFP_KERNEL);
current->futex.robust_lists = rl;
}
return rl;
}
3) Provide the exit() walker for this new thing and invoke it which
will be a NOOP because the list is empty.
4) Use #2/#3 for the existing syscalls and remove the then unused leftovers
SYSCALL_DEFINE2(set_robust_list, struct robust_list_head __user *, head, size_t, len)
{
uintptr_t *rl = robust_get_lists();
if (!rl)
return -ENOMEM;
rl[FUTEX_ROBUST_LIST_NATIVE_IDX] = head;
return 0;
}
...
5/6) Add the new syscalls
7/8) Wire up the syscalls
Thanks again for the valuable feedback and the proposed design, I will work on that for the v9.
Thanks,
tglx