[PATCH 1/4] futex: Drop ROBUST_LIST_LIMIT
From: André Almeida
Date: Fri Jan 10 2025 - 15:05:48 EST
ROBUST_LIST_LIMIT was introduced to avoid the kernel get stuck in
circular lists, stopping to handle locks after the limit. This could
cause starvation in applications that have very long lists with valid
and non repetitive elements.
Instead of having a hard limit, rewrite the next pointer list while
walking on it. In this way, if the kernel ever revisits a repetitive
element (characterizing a circular list) the loop will stop.
Signed-off-by: André Almeida <andrealmeid@xxxxxxxxxx>
---
include/uapi/linux/futex.h | 3 +--
kernel/futex/core.c | 13 +++++++------
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/include/uapi/linux/futex.h b/include/uapi/linux/futex.h
index 13903a278b71..4d2cd97a6ce5 100644
--- a/include/uapi/linux/futex.h
+++ b/include/uapi/linux/futex.h
@@ -189,8 +189,7 @@ struct robust_list2_entry {
#define FUTEX_TID_MASK 0x3fffffff
/*
- * This limit protects against a deliberately circular list.
- * (Not worth introducing an rlimit for it)
+ * Deprecated, do not use. There is no limit of items in a list.
*/
#define ROBUST_LIST_LIMIT 2048
diff --git a/kernel/futex/core.c b/kernel/futex/core.c
index f8962bc27c90..772c26901ec6 100644
--- a/kernel/futex/core.c
+++ b/kernel/futex/core.c
@@ -779,7 +779,7 @@ static void exit_robust_list64(struct task_struct *curr,
struct robust_list_head __user *head)
{
struct robust_list __user *entry, *next_entry, *pending;
- unsigned int limit = ROBUST_LIST_LIMIT, pi, pip;
+ unsigned int pi, pip;
unsigned int next_pi;
unsigned long futex_offset;
int rc;
@@ -820,13 +820,14 @@ static void exit_robust_list64(struct task_struct *curr,
}
if (rc)
return;
- entry = next_entry;
- pi = next_pi;
+
/*
- * Avoid excessively long or circular lists:
+ * Avoid circular lists:
*/
- if (!--limit)
- break;
+ put_user(&head->list, &entry->next);
+
+ entry = next_entry;
+ pi = next_pi;
cond_resched();
}
--
2.47.1