[PATCH v9 04/14] futex: Introduce futex_get_robust_lists() and futex_sched_data::robust_lists

From: André Almeida

Date: Fri Dec 04 2026 - 11:16:10 EST


Add a new field robust_lists to struct futex_sched_data. This field stores
a pointer to an array of robust list head pointers, to support multi-lists
per task.

Create futex_get_robust_lists() to get the robust_lists pointer. If the
list is not yet allocated, try to allocate it. The caller is responsible
for checking if the allocation failed and if it's a NULL pointer.
Allocation is race free giving that this is a per-task data, allocated from
syscall context.

futex_sched_data::robust_lists has two reserved indexes:
`FUTEX_ROBUST_LIST2_NATIVE_IDX` to store the robust list head pointer for
the current syscall set_robust_list() and `FUTEX_ROBUST_LIST2_COMPAT_IDX`
for the compat entry point head pointer. Those elements will be used to
replace futex_sched_data::{robust_list, robust_list32}.

futex_sched_data::robust_lists will be freed in a following commit.

Signed-off-by: André Almeida <andrealmeid@xxxxxxxxxx>
---
include/linux/futex.h | 1 +
include/linux/futex_types.h | 2 ++
kernel/futex/core.c | 12 ++++++++++++
kernel/futex/futex.h | 8 ++++++++
4 files changed, 23 insertions(+)

diff --git a/include/linux/futex.h b/include/linux/futex.h
index 93316876a4ee..0da95f94cfe9 100644
--- a/include/linux/futex.h
+++ b/include/linux/futex.h
@@ -76,6 +76,7 @@ static inline void futex_init_task(struct task_struct *tsk)
#ifdef CONFIG_COMPAT
tsk->futex.robust_list32 = NULL;
#endif
+ tsk->futex.robust_lists = NULL;
}

void futex_exit_recursive(struct task_struct *tsk);
diff --git a/include/linux/futex_types.h b/include/linux/futex_types.h
index f58616d7e20b..20123110c80d 100644
--- a/include/linux/futex_types.h
+++ b/include/linux/futex_types.h
@@ -14,6 +14,7 @@ struct robust_list_head;
* struct futex_sched_data - Futex related per task data
* @robust_list: User space registered robust list pointer
* @robust_list32: User space registered robust list pointer for compat tasks
+ * @robust_lists: List of robust lists heads
* @pi_state_list: List head for Priority Inheritance (PI) state management
* @pi_state_cache: Pointer to cache one PI state object per task
* @exit_mutex: Mutex for serializing exit
@@ -24,6 +25,7 @@ struct futex_sched_data {
#ifdef CONFIG_COMPAT
struct robust_list_head32 __user *robust_list32;
#endif
+ uintptr_t *robust_lists;
struct list_head pi_state_list;
struct futex_pi_state *pi_state_cache;
struct mutex exit_mutex;
diff --git a/kernel/futex/core.c b/kernel/futex/core.c
index bcfa59168911..dc5b6379060e 100644
--- a/kernel/futex/core.c
+++ b/kernel/futex/core.c
@@ -1124,6 +1124,18 @@ static int handle_futex_death(u32 __user *uaddr, struct task_struct *curr,
return 0;
}

+uintptr_t *futex_get_robust_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;
+}
+
/*
* Fetch a robust-list pointer. Bit 0 signals PI futexes:
*/
diff --git a/kernel/futex/futex.h b/kernel/futex/futex.h
index f00f0863ed44..bd552a1ce5f6 100644
--- a/kernel/futex/futex.h
+++ b/kernel/futex/futex.h
@@ -43,6 +43,12 @@
#define FLAGS_ROBUST_UNLOCK 0x0400
#define FLAGS_ROBUST_LIST32 0x0800

+#define FUTEX_ROBUST_LIST2_NATIVE_IDX 0
+#define FUTEX_ROBUST_LIST2_COMPAT_IDX 1
+#define FUTEX_ROBUST_LIST2_IDX 2
+#define FUTEX_ROBUST_LIST2_PER_USER 8
+#define FUTEX_ROBUST_LIST2_MAX_IDX (FUTEX_ROBUST_LIST2_IDX + FUTEX_ROBUST_LIST2_PER_USER)
+
/* FUTEX_ to FLAGS_ */
static inline unsigned int futex_to_flags(unsigned int op)
{
@@ -478,4 +484,6 @@ extern int futex_lock_pi(u32 __user *uaddr, unsigned int flags, ktime_t *time, i

bool futex_robust_list_clear_pending(void __user *pop, unsigned int flags);

+uintptr_t *futex_get_robust_lists(void);
+
#endif /* _FUTEX_H */

--
2.56.1