[PATCH v9 05/14] futex: Create exit_robust_lists() for multi-robust list

From: André Almeida

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


Create function exit_robust_lists() to process task's list of robust lists.
This function processes an array of robust list heads and call the
appropriate function to deal with it, according to the pointer size. The
low bit of each entry indicates whether the list is 32-bit.

Giving that the current syscalls don't use the multi-list array, this
introduction is a no-op and futex::robust_lists is always empty.

Signed-off-by: André Almeida <andrealmeid@xxxxxxxxxx>
---
kernel/futex/core.c | 35 +++++++++++++++++++++++++++++++++++
kernel/futex/futex.h | 6 ++++++
2 files changed, 41 insertions(+)

diff --git a/kernel/futex/core.c b/kernel/futex/core.c
index dc5b6379060e..d15906f3c80c 100644
--- a/kernel/futex/core.c
+++ b/kernel/futex/core.c
@@ -1477,8 +1477,43 @@ void __futex_fixup_robust_unlock(struct pt_regs *regs, struct futex_unlock_cs_ra
}
#endif /* CONFIG_FUTEX_ROBUST_UNLOCK */

+static void exit_robust_lists(struct task_struct *tsk)
+{
+ uintptr_t *rl = tsk->futex.robust_lists;
+ unsigned int idx;
+
+ if (!rl)
+ return;
+
+ tsk->futex.robust_lists = NULL;
+
+ for (idx = 0; idx < FUTEX_ROBUST_LIST2_MAX_IDX; idx++) {
+ uintptr_t entry = rl[idx] & FUTEX_ROBUST_LIST2_ENTRY_MASK;
+
+ if (!entry)
+ continue;
+
+ if (IS_ENABLED(CONFIG_64BIT) && (rl[idx] & FUTEX_ROBUST_LIST2_ENTRY_32BIT)) {
+ struct robust_list_head32 __user *head;
+
+ head = (__force struct robust_list_head32 __user *)entry;
+ exit_robust_list32(tsk, head);
+ } else {
+ struct robust_list_head __user *head;
+
+ head = (__force struct robust_list_head __user *)entry;
+ exit_robust_list(tsk, head);
+ }
+ }
+
+ kfree(rl);
+}
+
static void futex_cleanup(struct task_struct *tsk)
{
+ if (unlikely(tsk->futex.robust_lists))
+ exit_robust_lists(tsk);
+
if (unlikely(tsk->futex.robust_list)) {
exit_robust_list(tsk, tsk->futex.robust_list);
tsk->futex.robust_list = NULL;
diff --git a/kernel/futex/futex.h b/kernel/futex/futex.h
index bd552a1ce5f6..c1da53fd7187 100644
--- a/kernel/futex/futex.h
+++ b/kernel/futex/futex.h
@@ -49,6 +49,12 @@
#define FUTEX_ROBUST_LIST2_PER_USER 8
#define FUTEX_ROBUST_LIST2_MAX_IDX (FUTEX_ROBUST_LIST2_IDX + FUTEX_ROBUST_LIST2_PER_USER)

+/*
+ * List entries without _32BIT flag are using the native machine size
+ */
+#define FUTEX_ROBUST_LIST2_ENTRY_32BIT 0x1UL
+#define FUTEX_ROBUST_LIST2_ENTRY_MASK (~(uintptr_t)FUTEX_ROBUST_LIST2_ENTRY_32BIT)
+
/* FUTEX_ to FLAGS_ */
static inline unsigned int futex_to_flags(unsigned int op)
{

--
2.56.1